linux-nfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "J. Bruce Fields" <bfields@redhat.com>
To: linux-fsdevel@vger.kernel.org
Cc: Jeremy Allison <jra@samba.org>,
	samba-technical@lists.samba.org, linux-nfs@vger.kernel.org,
	Volker Lendecke <Volker.Lendecke@SerNet.DE>,
	Casey Bodley <cbodley@citi.umich.edu>,
	"J. Bruce Fields" <bfields@redhat.com>
Subject: [PATCH 4/4] locks: setlease cleanup
Date: Fri, 19 Aug 2011 12:07:51 -0400	[thread overview]
Message-ID: <1313770071-353-4-git-send-email-bfields@redhat.com> (raw)
In-Reply-To: <20110819160416.GC30856@fieldses.org>

There's an incorrect comment here.  Also clean up the logic: the
"rdlease" and "wrlease" locals are confusingly named, and don't really
add anything since we can make a decision as soon as we hit one of these
cases.

Signed-off-by: J. Bruce Fields <bfields@redhat.com>
---
 fs/locks.c |   33 +++++++++++++++++----------------
 1 files changed, 17 insertions(+), 16 deletions(-)

diff --git a/fs/locks.c b/fs/locks.c
index c525aa4..9b8408e 100644
--- a/fs/locks.c
+++ b/fs/locks.c
@@ -1368,7 +1368,7 @@ int generic_setlease(struct file *filp, long arg, struct file_lock **flp)
 	struct file_lock *fl, **before, **my_before = NULL, *lease;
 	struct dentry *dentry = filp->f_path.dentry;
 	struct inode *inode = dentry->d_inode;
-	int error, rdlease_count = 0, wrlease_count = 0;
+	int error;
 
 	lease = *flp;
 
@@ -1404,27 +1404,28 @@ int generic_setlease(struct file *filp, long arg, struct file_lock **flp)
 	 * then the file is not open by anyone (including us)
 	 * except for this filp.
 	 */
+	error = -EAGAIN;
 	for (before = &inode->i_flock;
 			((fl = *before) != NULL) && IS_LEASE(fl);
 			before = &fl->fl_next) {
-		if (fl->fl_file == filp)
+		if (fl->fl_file == filp) {
 			my_before = before;
-		else if (fl->fl_flags & FL_UNLOCK_PENDING)
-			/*
-			 * Someone is in the process of opening this
-			 * file for writing so we may not take an
-			 * exclusive lease on it.
-			 */
-			wrlease_count++;
-		else
-			rdlease_count++;
+			continue;
+		}
+		/*
+		 * No exclusive leases if someone else has a lease on
+		 * this file:
+		 */
+		if (arg == F_WRLCK)
+			goto out;
+		/*
+		 * Modifying our existing lease is OK, but no getting a
+		 * new lease if someone else is opening for write:
+		 */
+		if (fl->fl_flags & FL_UNLOCK_PENDING)
+			goto out;
 	}
 
-	error = -EAGAIN;
-	if ((arg == F_RDLCK && (wrlease_count > 0)) ||
-	    (arg == F_WRLCK && ((rdlease_count + wrlease_count) > 0)))
-		goto out;
-
 	if (my_before != NULL) {
 		error = lease->fl_lmops->lm_change(my_before, arg);
 		if (!error)
-- 
1.7.4.1


  parent reply	other threads:[~2011-08-19 16:07 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-06-09 23:16 [PATCH] locks: breaking read lease should not block read open J. Bruce Fields
2011-06-10  7:56 ` Volker Lendecke
2011-06-10 13:48   ` J. Bruce Fields
2011-07-21  0:07     ` J. Bruce Fields
2011-07-21  0:15       ` Jeremy Allison
2011-07-21 16:35         ` J. Bruce Fields
2011-07-29  2:27           ` J. Bruce Fields
2011-07-29  2:29             ` [PATCH 1/3] locks: minor lease cleanup J. Bruce Fields
2011-07-29  2:29               ` [PATCH 2/3] locks: move F_INPROGRESS from fl_type to fl_flags field J. Bruce Fields
2011-07-29  2:30                 ` [PATCH 3/3] locks: fix tracking of inprogress lease breaks J. Bruce Fields
2011-08-19 16:04             ` [PATCH] locks: breaking read lease should not block read open J. Bruce Fields
2011-08-19 16:07               ` [PATCH 1/4] locks: minor lease cleanup J. Bruce Fields
2011-08-19 16:07               ` [PATCH 2/4] locks: move F_INPROGRESS from fl_type to fl_flags field J. Bruce Fields
2011-08-19 16:07               ` [PATCH 3/4] locks: fix tracking of inprogress lease breaks J. Bruce Fields
2011-08-19 16:07               ` J. Bruce Fields [this message]
2011-08-19 19:08       ` [PATCH] locks: breaking read lease should not block read open Jamie Lokier
2011-08-21 16:50         ` J. Bruce Fields
2011-11-21 12:46           ` Jamie Lokier
2011-11-22 21:44             ` J. Bruce Fields
2011-11-23  0:30               ` Jamie Lokier
2011-11-23 19:08                 ` J. Bruce Fields

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=1313770071-353-4-git-send-email-bfields@redhat.com \
    --to=bfields@redhat.com \
    --cc=Volker.Lendecke@SerNet.DE \
    --cc=cbodley@citi.umich.edu \
    --cc=jra@samba.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-nfs@vger.kernel.org \
    --cc=samba-technical@lists.samba.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).