mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Trond Myklebust <trond.myklebust@fys.uio.no>
To: Miklos Szeredi <miklos@szeredi.hu>
Cc: akpm@osdl.org, linux-fsdevel@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH 2/4] locks: don't unnecessarily fail posix lock operations
Date: Fri, 31 Mar 2006 23:30:50 -0500	[thread overview]
Message-ID: <1143865851.8116.30.camel@lade.trondhjem.org> (raw)
In-Reply-To: <E1FPPZK-0005qJ-00@dorka.pomaz.szeredi.hu>

[-- Attachment #1: Type: text/plain, Size: 1538 bytes --]

On Fri, 2006-03-31 at 21:46 +0200, Miklos Szeredi wrote:
> > > In the first case no new locks are needed.  In the second, no locks
> > > are modified prior to the check.
> > 
> > Consider something like
> > 
> > fcntl(SETLK, 0, 100)
> > fcntl(SETLK, 0, 100)
> > fcntl(SETLK, 0, 100)
> 
> Huh?  What is the type of lock in each case.
> 
> But anyway your example is no good.  If the new lock completely covers
> the previous one, then the old lock will simply be adjusted and no new
> lock is inserted.

Slip of the mailer. It posted when I wanted to cancel the mail (I had to
step out for an errand)...

OK. I see what you mean now. Do you agree with the following analysis?

        1) We need 2 extra locks for the case where we
        upgrade/downgrade, a single existing lock and end up splitting
        it.

        2) We need to use 1 extra lock in the case where we unlock and
        split a single existing lock.

        3) We also need to use 1 extra lock in the case where there is
        no existing lock that is contiguous with the region to lock.

In all other cases, we resort to modifying existing locks instead of
using new_fl/new_fl2.

In cases (1) and (2) we do need to modify the existing lock. Since this
is only done after we've set up the extra locks, we're safe.

Could I still suggest a couple of modifications to your patch? Firstly,
we only need to test for 'added' once. Secondly, in cases (2) and (3),
we can still complete the lock despite one of new_fl/new_fl2 failing to
be allocated.

Cheers,
  Trond

[-- Attachment #2: optimise_lock.dif --]
[-- Type: text/plain, Size: 1418 bytes --]

VFS,locks: locks: don't unnecessarily fail posix lock operations

---

 fs/locks.c |   27 ++++++++++++++++++++-------
 1 files changed, 20 insertions(+), 7 deletions(-)

diff --git a/fs/locks.c b/fs/locks.c
index 6ba3756..973c1d9 100644
--- a/fs/locks.c
+++ b/fs/locks.c
@@ -839,10 +839,6 @@ static int __posix_lock_file_conf(struct
 	if (request->fl_flags & FL_ACCESS)
 		goto out;
 
-	error = -ENOLCK; /* "no luck" */
-	if (!(new_fl && new_fl2))
-		goto out;
-
 	/*
 	 * We've allocated the new locks in advance, so there are no
 	 * errors possible (and no blocking operations) from here on.
@@ -943,9 +939,25 @@ static int __posix_lock_file_conf(struct
 		before = &fl->fl_next;
 	}
 
-	error = 0;
-	if (!added) {
-		if (request->fl_type == F_UNLCK)
+	if (request->fl_type == F_UNLCK) {
+		if (!added)
+			goto out;
+		if (!new_fl2 && right && left == right) {
+			new_fl2 = new_fl;
+			error = -ENOLCK;
+			if (!new_fl2)
+				goto out;
+			new_fl = NULL;
+		}
+	} else if (!added) {
+		error = -ENOLCK;
+		if (!new_fl) {
+			new_fl = new_fl2;
+			if (!new_fl)
+				goto out;
+			new_fl2 = NULL;
+		}
+		if (!new_fl2 && right && left == right)
 			goto out;
 		locks_copy_lock(new_fl, request);
 		locks_insert_lock(before, new_fl);
@@ -968,6 +980,7 @@ static int __posix_lock_file_conf(struct
 		left->fl_end = request->fl_start - 1;
 		locks_wake_up_blocks(left);
 	}
+	error = 0;
  out:
 	unlock_kernel();
 	/*

  reply	other threads:[~2006-04-01  4:31 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-03-31 17:26 [PATCH 0/4] locks: cleanups and fixes Miklos Szeredi
2006-03-31 17:28 ` [PATCH 1/4] locks: export raw __posix_lock_file() interface Miklos Szeredi
2006-03-31 17:30 ` [PATCH 2/4] locks: don't unnecessarily fail posix lock operations Miklos Szeredi
2006-03-31 18:27   ` Trond Myklebust
2006-03-31 18:44     ` Trond Myklebust
2006-03-31 19:31       ` Miklos Szeredi
2006-03-31 19:25     ` Miklos Szeredi
2006-03-31 19:40       ` Trond Myklebust
2006-03-31 19:46         ` Miklos Szeredi
2006-04-01  4:30           ` Trond Myklebust [this message]
2006-04-01  6:39             ` Miklos Szeredi
2006-03-31 17:31 ` [PATCH 3/4] locks: don't do unnecessary allocations Miklos Szeredi
2006-03-31 17:33 ` [PATCH 4/4] locks: clean up locks_remove_posix() Miklos Szeredi

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=1143865851.8116.30.camel@lade.trondhjem.org \
    --to=trond.myklebust@fys.uio.no \
    --cc=akpm@osdl.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=miklos@szeredi.hu \
    /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

all inboxes | Powered by JetHome®