linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jeff Layton <jlayton@primarydata.com>
To: linux-fsdevel@vger.kernel.org
Cc: bfields@fieldses.org, hch@infradead.org,
	cluster-devel@redhat.com, linux-cifs@vger.kernel.org,
	linux-nfs@vger.kernel.org
Subject: [PATCH 08/10] locks: move i_lock acquisition into generic_*_lease handlers
Date: Sat, 23 Aug 2014 10:41:16 -0400	[thread overview]
Message-ID: <1408804878-1331-9-git-send-email-jlayton@primarydata.com> (raw)
In-Reply-To: <1408804878-1331-1-git-send-email-jlayton@primarydata.com>

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.

With this change ->setlease calls can now block, which is a necessary
(but not sufficient!) step toward allowing leases to work with
distributed filesystems.

Signed-off-by: Jeff Layton <jlayton@primarydata.com>
---
 fs/locks.c | 29 +++++++++++++++--------------
 1 file changed, 15 insertions(+), 14 deletions(-)

diff --git a/fs/locks.c b/fs/locks.c
index b35b706c05fe..49210d5cbf41 100644
--- a/fs/locks.c
+++ b/fs/locks.c
@@ -1335,6 +1335,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);
@@ -1595,6 +1597,9 @@ generic_add_lease(struct file *filp, long arg, struct file_lock **flp, void **au
 		return -EINVAL;
 	}
 
+	spin_lock(&inode->i_lock);
+	time_out_leases(inode);
+
 	error = check_conflicting_open(dentry, arg);
 	if (error)
 		goto out;
@@ -1660,6 +1665,7 @@ out_setup:
 	if (lease->fl_lmops->lm_setup)
 		lease->fl_lmops->lm_setup(lease, aux);
 out:
+	spin_unlock(&inode->i_lock);
 	if (is_deleg)
 		mutex_unlock(&inode->i_mutex);
 	if (!error && !my_before)
@@ -1672,18 +1678,22 @@ out_unlink:
 
 static int generic_delete_lease(struct file *filp)
 {
+	int error = -EAGAIN;
 	struct file_lock *fl, **before;
 	struct dentry *dentry = filp->f_path.dentry;
 	struct inode *inode = dentry->d_inode;
 
+	spin_lock(&inode->i_lock);
+	time_out_leases(inode);
 	for (before = &inode->i_flock;
 			((fl = *before) != NULL) && IS_LEASE(fl);
 			before = &fl->fl_next) {
 		if (fl->fl_file != filp)
 			continue;
-		return fl->fl_lmops->lm_change(before, F_UNLCK);
+		error = fl->fl_lmops->lm_change(before, F_UNLCK);
 	}
-	return -EAGAIN;
+	spin_unlock(&inode->i_lock);
+	return error;
 }
 
 /**
@@ -1702,8 +1712,7 @@ static int generic_delete_lease(struct file *filp)
 int generic_setlease(struct file *filp, long arg, struct file_lock **flp,
 			void **aux)
 {
-	struct dentry *dentry = filp->f_path.dentry;
-	struct inode *inode = dentry->d_inode;
+	struct inode *inode = file_inode(filp);
 	int error;
 
 	if ((!uid_eq(current_fsuid(), inode->i_uid)) && !capable(CAP_LEASE))
@@ -1714,8 +1723,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);
@@ -1759,16 +1766,10 @@ EXPORT_SYMBOL(generic_setlease);
 int
 vfs_setlease(struct file *filp, long arg, struct file_lock **lease, void **aux)
 {
-	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, aux);
+		return filp->f_op->setlease(filp, arg, lease, aux);
 	else
-		error = generic_setlease(filp, arg, lease, aux);
-	spin_unlock(&inode->i_lock);
-	return error;
+		return generic_setlease(filp, arg, lease, aux);
 }
 EXPORT_SYMBOL_GPL(vfs_setlease);
 
-- 
1.9.3


  parent reply	other threads:[~2014-08-23 14:41 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-08-23 14:41 [PATCH 00/10] locks/nfsd: internal lease API overhaul Jeff Layton
2014-08-23 14:41 ` [PATCH 04/10] locks: clean up vfs_setlease kerneldoc comments Jeff Layton
2014-08-24 15:51   ` Christoph Hellwig
     [not found]     ` <20140824155117.GC15908-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org>
2014-08-25 20:11       ` J. Bruce Fields
2014-08-23 14:41 ` [PATCH 07/10] locks: define a lm_setup handler for leases Jeff Layton
     [not found]   ` <1408804878-1331-8-git-send-email-jlayton-7I+n7zu2hftEKMMhf/gKZA@public.gmane.org>
2014-08-24 15:58     ` Christoph Hellwig
2014-08-25  1:19       ` Jeff Layton
2014-08-26 13:58         ` Christoph Hellwig
2014-08-23 14:41 ` Jeff Layton [this message]
     [not found]   ` <1408804878-1331-9-git-send-email-jlayton-7I+n7zu2hftEKMMhf/gKZA@public.gmane.org>
2014-08-24 16:06     ` [PATCH 08/10] locks: move i_lock acquisition into generic_*_lease handlers Christoph Hellwig
     [not found]       ` <20140824160634.GG15908-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org>
2014-08-24 16:11         ` Christoph Hellwig
     [not found]           ` <20140824161134.GJ15908-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org>
2014-08-31 14:51             ` Jeff Layton
2014-08-25  1:36         ` Jeff Layton
     [not found] ` <1408804878-1331-1-git-send-email-jlayton-7I+n7zu2hftEKMMhf/gKZA@public.gmane.org>
2014-08-23 14:41   ` [PATCH 01/10] locks: close potential race in lease_get_mtime Jeff Layton
     [not found]     ` <1408804878-1331-2-git-send-email-jlayton-7I+n7zu2hftEKMMhf/gKZA@public.gmane.org>
2014-08-24 15:48       ` Christoph Hellwig
2014-08-25 20:01     ` J. Bruce Fields
2014-08-23 14:41   ` [PATCH 02/10] nfsd: fix potential lease memory leak in nfs4_setlease Jeff Layton
     [not found]     ` <1408804878-1331-3-git-send-email-jlayton-7I+n7zu2hftEKMMhf/gKZA@public.gmane.org>
2014-08-24 15:48       ` Christoph Hellwig
2014-08-23 14:41   ` [PATCH 03/10] locks: generic_delete_lease doesn't need a file_lock at all Jeff Layton
     [not found]     ` <1408804878-1331-4-git-send-email-jlayton-7I+n7zu2hftEKMMhf/gKZA@public.gmane.org>
2014-08-24  1:27       ` Christoph Hellwig
     [not found]         ` <20140824012757.GA21609-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org>
2014-08-24 10:09           ` Jeff Layton
2014-08-23 14:41   ` [PATCH 05/10] nfsd: don't keep a pointer to the lease in nfs4_file Jeff Layton
     [not found]     ` <1408804878-1331-6-git-send-email-jlayton-7I+n7zu2hftEKMMhf/gKZA@public.gmane.org>
2014-08-24 15:51       ` Christoph Hellwig
2014-08-23 14:41   ` [PATCH 06/10] locks: plumb an "aux" pointer into the setlease routines Jeff Layton
     [not found]     ` <1408804878-1331-7-git-send-email-jlayton-7I+n7zu2hftEKMMhf/gKZA@public.gmane.org>
2014-08-24  1:33       ` Christoph Hellwig
     [not found]         ` <20140824013305.GB21609-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org>
2014-08-24 10:08           ` Jeff Layton
     [not found]             ` <20140824060801.5402880c-08S845evdOaAjSkqwZiSMmfYqLom42DlXqFh9Ls21Oc@public.gmane.org>
2014-08-24 15:54               ` Christoph Hellwig
2014-08-25 20:28       ` J. Bruce Fields
     [not found]         ` <20140825202852.GD21957-uC3wQj2KruNg9hUCZPvPmw@public.gmane.org>
2014-08-26 10:53           ` Jeff Layton
2014-08-23 14:41   ` [PATCH 09/10] locks: move freeing of leases outside of i_lock Jeff Layton
     [not found]     ` <1408804878-1331-10-git-send-email-jlayton-7I+n7zu2hftEKMMhf/gKZA@public.gmane.org>
2014-08-24 16:08       ` Christoph Hellwig
     [not found]         ` <20140824160804.GH15908-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org>
2014-08-25  1:35           ` Jeff Layton
2014-08-23 14:41   ` [PATCH 10/10] locks: update Documentation/filesystems with lease API changes Jeff Layton
2014-08-24 16:10   ` [PATCH 00/10] locks/nfsd: internal lease API overhaul Christoph Hellwig
     [not found]     ` <20140824161046.GI15908-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org>
2014-08-25  1:43       ` Jeff Layton
     [not found]         ` <20140824214301.61019123-08S845evdOaAjSkqwZiSMmfYqLom42DlXqFh9Ls21Oc@public.gmane.org>
2014-08-26 13:59           ` Christoph Hellwig

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1408804878-1331-9-git-send-email-jlayton@primarydata.com \
    --to=jlayton@primarydata.com \
    --cc=bfields@fieldses.org \
    --cc=cluster-devel@redhat.com \
    --cc=hch@infradead.org \
    --cc=linux-cifs@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-nfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).