locks: move i_lock acquisition into generic_*_lease handlers
authorJeff Layton <jlayton@primarydata.com>
Fri, 22 Aug 2014 22:50:48 +0000 (18:50 -0400)
committerJeff Layton <jlayton@primarydata.com>
Tue, 9 Sep 2014 20:01:38 +0000 (16:01 -0400)
Now that we have a saner internal API for managing leases, we no longer
need to mandate that the inode->i_lock be held over most of the lease
code. Push it down into generic_add_lease and generic_delete_lease.

Signed-off-by: Jeff Layton <jlayton@primarydata.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Documentation/filesystems/Locking
Documentation/filesystems/vfs.txt
fs/locks.c

index 3d92049ae71dd5589f73cb24cfa02e3fd11c838b..4af288e38f138f0864865b01096bdd38fc5ad76e 100644 (file)
@@ -472,8 +472,6 @@ locking rules:
        All may block except for ->setlease.
        No VFS locks held on entry except for ->setlease.
 
-->setlease has the file_list_lock held and must not sleep.
-
 ->llseek() locking has moved from llseek to the individual llseek
 implementations.  If your fs is not using generic_file_llseek, you
 need to acquire and release the appropriate locks in your ->llseek().
@@ -496,6 +494,10 @@ components. And there are other reasons why the current interface is a mess...
 ->read on directories probably must go away - we should just enforce -EISDIR
 in sys_read() and friends.
 
+->setlease operations should call generic_setlease() before or after setting
+the lease within the individual filesystem to record the result of the
+operation
+
 --------------------------- dquot_operations -------------------------------
 prototypes:
        int (*write_dquot) (struct dquot *);
index 28ebd49f169f17ef8012631afae37098c7ce29bd..8be1ea3bdd5ae83f190bd19c99c05cef7cfe0f82 100644 (file)
@@ -895,8 +895,9 @@ otherwise noted.
   splice_read: called by the VFS to splice data from file to a pipe. This
               method is used by the splice(2) system call
 
-  setlease: called by the VFS to set or release a file lock lease.
-           setlease has the file_lock_lock held and must not sleep.
+  setlease: called by the VFS to set or release a file lock lease. setlease
+           implementations should call generic_setlease to record or remove
+           the lease in the inode after setting it.
 
   fallocate: called by the VFS to preallocate blocks or punch a hole.
 
index a237ba632e8d93dea4d7d4b42fcef196d081f011..eb463257f8678aa5f5e81f4be80dae28d3f43266 100644 (file)
@@ -1330,6 +1330,8 @@ static void time_out_leases(struct inode *inode)
        struct file_lock **before;
        struct file_lock *fl;
 
+       lockdep_assert_held(&inode->i_lock);
+
        before = &inode->i_flock;
        while ((fl = *before) && IS_LEASE(fl) && lease_breaking(fl)) {
                trace_time_out_leases(inode, fl);
@@ -1590,6 +1592,8 @@ generic_add_lease(struct file *filp, long arg, struct file_lock **flp, void **pr
                return -EINVAL;
        }
 
+       spin_lock(&inode->i_lock);
+       time_out_leases(inode);
        error = check_conflicting_open(dentry, arg);
        if (error)
                goto out;
@@ -1655,6 +1659,7 @@ out_setup:
        if (lease->fl_lmops->lm_setup)
                lease->fl_lmops->lm_setup(lease, priv);
 out:
+       spin_unlock(&inode->i_lock);
        if (is_deleg)
                mutex_unlock(&inode->i_mutex);
        if (!error && !my_before)
@@ -1672,6 +1677,7 @@ static int generic_delete_lease(struct file *filp)
        struct dentry *dentry = filp->f_path.dentry;
        struct inode *inode = dentry->d_inode;
 
+       spin_lock(&inode->i_lock);
        for (before = &inode->i_flock;
                        ((fl = *before) != NULL) && IS_LEASE(fl);
                        before = &fl->fl_next) {
@@ -1681,6 +1687,7 @@ static int generic_delete_lease(struct file *filp)
        trace_generic_delete_lease(inode, fl);
        if (fl)
                error = fl->fl_lmops->lm_change(before, F_UNLCK);
+       spin_unlock(&inode->i_lock);
        return error;
 }
 
@@ -1694,8 +1701,6 @@ static int generic_delete_lease(struct file *filp)
  *
  *     The (input) flp->fl_lmops->lm_break function is required
  *     by break_lease().
- *
- *     Called with inode->i_lock held.
  */
 int generic_setlease(struct file *filp, long arg, struct file_lock **flp,
                        void **priv)
@@ -1712,8 +1717,6 @@ int generic_setlease(struct file *filp, long arg, struct file_lock **flp,
        if (error)
                return error;
 
-       time_out_leases(inode);
-
        switch (arg) {
        case F_UNLCK:
                return generic_delete_lease(filp);
@@ -1750,16 +1753,10 @@ EXPORT_SYMBOL(generic_setlease);
 int
 vfs_setlease(struct file *filp, long arg, struct file_lock **lease, void **priv)
 {
-       struct inode *inode = file_inode(filp);
-       int error;
-
-       spin_lock(&inode->i_lock);
        if (filp->f_op->setlease)
-               error = filp->f_op->setlease(filp, arg, lease, priv);
+               return filp->f_op->setlease(filp, arg, lease, priv);
        else
-               error = generic_setlease(filp, arg, lease, priv);
-       spin_unlock(&inode->i_lock);
-       return error;
+               return generic_setlease(filp, arg, lease, priv);
 }
 EXPORT_SYMBOL_GPL(vfs_setlease);