]> pilppa.com Git - linux-2.6-omap-h63xx.git/commitdiff
locks: factor out generic/filesystem switch from setlock code
authorMarc Eshel <eshel@almaden.ibm.com>
Thu, 18 Jan 2007 20:08:55 +0000 (15:08 -0500)
committerJ. Bruce Fields <bfields@citi.umich.edu>
Sun, 6 May 2007 22:08:49 +0000 (18:08 -0400)
Factor out the code that switches between generic and filesystem-specific lock
methods; eventually we want to call this from lock managers (lockd and nfsd)
too; currently they only call the generic methods.

This patch does that for all the setlk code.

Signed-off-by: Marc Eshel <eshel@almaden.ibm.com>
Signed-off-by: "J. Bruce Fields" <bfields@citi.umich.edu>
fs/locks.c
include/linux/fs.h

index a31648e3ec1b397fb43b062d1208a7329a81df93..f4fd1515b6e2e0912d9eb1b7563223ed3c40e2df 100644 (file)
@@ -1698,6 +1698,21 @@ out:
        return error;
 }
 
+/**
+ * vfs_lock_file - file byte range lock
+ * @filp: The file to apply the lock to
+ * @cmd: type of locking operation (F_SETLK, F_GETLK, etc.)
+ * @fl: The lock to be applied
+ */
+int vfs_lock_file(struct file *filp, unsigned int cmd, struct file_lock *fl)
+{
+       if (filp->f_op && filp->f_op->lock)
+               return filp->f_op->lock(filp, cmd, fl);
+       else
+               return posix_lock_file(filp, fl);
+}
+EXPORT_SYMBOL_GPL(vfs_lock_file);
+
 /* Apply the lock described by l to an open file descriptor.
  * This implements both the F_SETLK and F_SETLKW commands of fcntl().
  */
@@ -1760,21 +1775,17 @@ again:
        if (error)
                goto out;
 
-       if (filp->f_op && filp->f_op->lock != NULL)
-               error = filp->f_op->lock(filp, cmd, file_lock);
-       else {
-               for (;;) {
-                       error = posix_lock_file(filp, file_lock);
-                       if (error != -EAGAIN || cmd == F_SETLK)
-                               break;
-                       error = wait_event_interruptible(file_lock->fl_wait,
-                                       !file_lock->fl_next);
-                       if (!error)
-                               continue;
-
-                       locks_delete_block(file_lock);
+       for (;;) {
+               error = vfs_lock_file(filp, cmd, file_lock);
+               if (error != -EAGAIN || cmd == F_SETLK)
                        break;
-               }
+               error = wait_event_interruptible(file_lock->fl_wait,
+                               !file_lock->fl_next);
+               if (!error)
+                       continue;
+
+               locks_delete_block(file_lock);
+               break;
        }
 
        /*
@@ -1890,21 +1901,17 @@ again:
        if (error)
                goto out;
 
-       if (filp->f_op && filp->f_op->lock != NULL)
-               error = filp->f_op->lock(filp, cmd, file_lock);
-       else {
-               for (;;) {
-                       error = posix_lock_file(filp, file_lock);
-                       if (error != -EAGAIN || cmd == F_SETLK64)
-                               break;
-                       error = wait_event_interruptible(file_lock->fl_wait,
-                                       !file_lock->fl_next);
-                       if (!error)
-                               continue;
-
-                       locks_delete_block(file_lock);
+       for (;;) {
+               error = vfs_lock_file(filp, cmd, file_lock);
+               if (error != -EAGAIN || cmd == F_SETLK64)
                        break;
-               }
+               error = wait_event_interruptible(file_lock->fl_wait,
+                               !file_lock->fl_next);
+               if (!error)
+                       continue;
+
+               locks_delete_block(file_lock);
+               break;
        }
 
        /*
@@ -1949,10 +1956,7 @@ void locks_remove_posix(struct file *filp, fl_owner_t owner)
        lock.fl_ops = NULL;
        lock.fl_lmops = NULL;
 
-       if (filp->f_op && filp->f_op->lock != NULL)
-               filp->f_op->lock(filp, F_SETLK, &lock);
-       else
-               posix_lock_file(filp, &lock);
+       vfs_lock_file(filp, F_SETLK, &lock);
 
        if (lock.fl_ops && lock.fl_ops->fl_release_private)
                lock.fl_ops->fl_release_private(&lock);
index 2a2a43988f507bcb4a402a9713871ddf08030ef1..1d5ccdd7c68dc2295199cfad14cf2128ae336914 100644 (file)
@@ -857,6 +857,7 @@ 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 vfs_lock_file(struct file *, unsigned int, 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);