Skip to content

Commit e55c34a

Browse files
bcodding-rhJeff Layton
authored and
Jeff Layton
committed
locks: introduce locks_lock_inode_wait()
Users of the locks API commonly call either posix_lock_file_wait() or flock_lock_file_wait() depending upon the lock type. Add a new function locks_lock_inode_wait() which will check and call the correct function for the type of lock passed in. Signed-off-by: Benjamin Coddington <bcodding@redhat.com> Signed-off-by: Jeff Layton <jeff.layton@primarydata.com>
1 parent 6ca7d91 commit e55c34a

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

fs/locks.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1881,6 +1881,30 @@ int flock_lock_inode_wait(struct inode *inode, struct file_lock *fl)
18811881
}
18821882
EXPORT_SYMBOL(flock_lock_inode_wait);
18831883

1884+
/**
1885+
* locks_lock_inode_wait - Apply a lock to an inode
1886+
* @inode: inode of the file to apply to
1887+
* @fl: The lock to be applied
1888+
*
1889+
* Apply a POSIX or FLOCK style lock request to an inode.
1890+
*/
1891+
int locks_lock_inode_wait(struct inode *inode, struct file_lock *fl)
1892+
{
1893+
int res = 0;
1894+
switch (fl->fl_flags & (FL_POSIX|FL_FLOCK)) {
1895+
case FL_POSIX:
1896+
res = posix_lock_inode_wait(inode, fl);
1897+
break;
1898+
case FL_FLOCK:
1899+
res = flock_lock_inode_wait(inode, fl);
1900+
break;
1901+
default:
1902+
BUG();
1903+
}
1904+
return res;
1905+
}
1906+
EXPORT_SYMBOL(locks_lock_inode_wait);
1907+
18841908
/**
18851909
* sys_flock: - flock() system call.
18861910
* @fd: the file descriptor to lock.

include/linux/fs.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1059,6 +1059,7 @@ extern int vfs_test_lock(struct file *, struct file_lock *);
10591059
extern int vfs_lock_file(struct file *, unsigned int, struct file_lock *, struct file_lock *);
10601060
extern int vfs_cancel_lock(struct file *filp, struct file_lock *fl);
10611061
extern int flock_lock_inode_wait(struct inode *inode, struct file_lock *fl);
1062+
extern int locks_lock_inode_wait(struct inode *inode, struct file_lock *fl);
10621063
extern int __break_lease(struct inode *inode, unsigned int flags, unsigned int type);
10631064
extern void lease_get_mtime(struct inode *, struct timespec *time);
10641065
extern int generic_setlease(struct file *, long, struct file_lock **, void **priv);
@@ -1177,6 +1178,11 @@ static inline int flock_lock_inode_wait(struct inode *inode,
11771178
return -ENOLCK;
11781179
}
11791180

1181+
static inline int locks_lock_inode_wait(struct inode *inode, struct file_lock *fl)
1182+
{
1183+
return -ENOLCK;
1184+
}
1185+
11801186
static inline int __break_lease(struct inode *inode, unsigned int mode, unsigned int type)
11811187
{
11821188
return 0;
@@ -1225,6 +1231,11 @@ static inline int flock_lock_file_wait(struct file *filp, struct file_lock *fl)
12251231
return flock_lock_inode_wait(file_inode(filp), fl);
12261232
}
12271233

1234+
static inline int locks_lock_file_wait(struct file *filp, struct file_lock *fl)
1235+
{
1236+
return locks_lock_inode_wait(file_inode(filp), fl);
1237+
}
1238+
12281239
struct fasync_struct {
12291240
spinlock_t fa_lock;
12301241
int magic;

0 commit comments

Comments
 (0)