From 37870a2d44e12e4d0332cb0dea57c972daad5b1b Mon Sep 17 00:00:00 2001 From: "J. Bruce Fields" Date: Wed, 21 Feb 2007 00:58:50 -0500 Subject: [PATCH] --- yaml --- r: 54487 b: refs/heads/master c: 3ee17abd14c728d4e0ca7a991c58f2250cb091af h: refs/heads/master i: 54485: 52019fa1fd66b17a3140e284ccf836f299fb5c1d 54483: ca2aa1770af94255417a4eab5a21e0380c84a8d8 54479: 245c41aad5d2294ddd1f3a9336e636cc30943c2b v: v3 --- [refs] | 2 +- trunk/fs/locks.c | 38 +++++++++++++++++++++++++------------- trunk/include/linux/fs.h | 1 + 3 files changed, 27 insertions(+), 14 deletions(-) diff --git a/[refs] b/[refs] index 35a2cb73dd31..6652646604c7 100644 --- a/[refs] +++ b/[refs] @@ -1,2 +1,2 @@ --- -refs/heads/master: 9d6a8c5c213e34c475e72b245a8eb709258e968c +refs/heads/master: 3ee17abd14c728d4e0ca7a991c58f2250cb091af diff --git a/trunk/fs/locks.c b/trunk/fs/locks.c index 749a0dc7cd4b..a31648e3ec1b 100644 --- a/trunk/fs/locks.c +++ b/trunk/fs/locks.c @@ -1611,6 +1611,24 @@ asmlinkage long sys_flock(unsigned int fd, unsigned int cmd) return error; } +/** + * vfs_test_lock - test file byte range lock + * @filp: The file to test lock for + * @fl: The lock to test + * @conf: Place to return a copy of the conflicting lock, if found + * + * Returns -ERRNO on failure. Indicates presence of conflicting lock by + * setting conf->fl_type to something other than F_UNLCK. + */ +int vfs_test_lock(struct file *filp, struct file_lock *fl) +{ + if (filp->f_op && filp->f_op->lock) + return filp->f_op->lock(filp, F_GETLK, fl); + posix_test_lock(filp, fl); + return 0; +} +EXPORT_SYMBOL_GPL(vfs_test_lock); + static int posix_lock_to_flock(struct flock *flock, struct file_lock *fl) { flock->l_pid = fl->fl_pid; @@ -1663,12 +1681,9 @@ int fcntl_getlk(struct file *filp, struct flock __user *l) if (error) goto out; - if (filp->f_op && filp->f_op->lock) { - error = filp->f_op->lock(filp, F_GETLK, &file_lock); - if (error < 0) - goto out; - } else - posix_test_lock(filp, &file_lock); + error = vfs_test_lock(filp, &file_lock); + if (error) + goto out; flock.l_type = file_lock.fl_type; if (file_lock.fl_type != F_UNLCK) { @@ -1797,13 +1812,10 @@ int fcntl_getlk64(struct file *filp, struct flock64 __user *l) if (error) goto out; - if (filp->f_op && filp->f_op->lock) { - error = filp->f_op->lock(filp, F_GETLK, &file_lock); - if (error < 0) - goto out; - } else - posix_test_lock(filp, &file_lock); - + error = vfs_test_lock(filp, &file_lock); + if (error) + goto out; + flock.l_type = file_lock.fl_type; if (file_lock.fl_type != F_UNLCK) posix_lock_to_flock64(&flock, &file_lock); diff --git a/trunk/include/linux/fs.h b/trunk/include/linux/fs.h index 9e1ddffe3884..2a2a43988f50 100644 --- a/trunk/include/linux/fs.h +++ b/trunk/include/linux/fs.h @@ -856,6 +856,7 @@ extern int posix_lock_file_conf(struct file *, struct file_lock *, struct file_l extern int posix_lock_file(struct file *, struct file_lock *); extern int posix_lock_file_wait(struct file *, struct file_lock *); extern int posix_unblock_lock(struct file *, struct file_lock *); +extern int vfs_test_lock(struct file *, struct file_lock *); extern int flock_lock_file_wait(struct file *filp, struct file_lock *fl); extern int __break_lease(struct inode *inode, unsigned int flags); extern void lease_get_mtime(struct inode *, struct timespec *time);