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 13:27:21 -0500	[thread overview]
Message-ID: <1143829641.8085.7.camel@lade.trondhjem.org> (raw)
In-Reply-To: <E1FPNSB-0005VK-00@dorka.pomaz.szeredi.hu>

On Fri, 2006-03-31 at 19:30 +0200, Miklos Szeredi wrote:
> posix_lock_file() was too cautious, failing operations on OOM, even if
> they didn't actually require an allocation.
> 
> This has the disadvantage, that a failing unlock on process exit could
> lead to a memory leak.  There are two possibilites for this:
> 
> - filesystem implements .lock() and calls back to posix_lock_file().
> On cleanup of files_struct locks_remove_posix() is called which should
> remove all locks belonging to files_struct.  However if filesystem
> calls posix_lock_file() which fails, then those locks will never be
> freed.
> 
> - if a file is closed while a lock is blocked, then after acquiring
> fcntl_setlk() will undo the lock.  But this unlock itself might fail
> on OOM, again possibly leaking the lock.
> 
> The solution is to move the checking of the allocations until after it
> is sure that they will be needed.  This will solve the above problem
> since unlock will always succeed unless it splits an existing region.
> 
> Signed-off-by: Miklos Szeredi <miklos@szeredi.hu>
> 
> Index: linux/fs/locks.c
> ===================================================================
> --- linux.orig/fs/locks.c	2006-03-31 18:55:33.000000000 +0200
> +++ linux/fs/locks.c	2006-03-31 18:55:33.000000000 +0200
> @@ -835,14 +835,7 @@ int __posix_lock_file(struct inode *inod
>  	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.
> -	 * 
>  	 * Find the first old lock with the same owner as the new lock.
>  	 */
>  	
> @@ -939,6 +932,18 @@ int __posix_lock_file(struct inode *inod
>  		before = &fl->fl_next;
>  	}
>  
> +	/*
> +	 * The above code only modifies existing locks in case of
> +	 * merging or replacing.  If new lock(s) need to be inserted
> +	 * all modifications are done bellow this, so it's safe yet to
> +	 * bail out.
> +	 */
> +	error = -ENOLCK; /* "no luck" */
> +	if (!added && request->fl_type != F_UNLCK && !new_fl)
> +		goto out;
> +	if (right && left == right && !new_fl2)
> +		goto out;
> +
>  	error = 0;
>  	if (!added) {
>  		if (request->fl_type == F_UNLCK)

NACK.

This changes the behaviour of F_UNLCK. Currently, if the allocation
fails, the inode locking state remains unchanged. With your change, an
unlock request may end up unlocking part of the inode, but not the rest.

Furthermore, AFAICS you are now able to Oops if (!added && !new_fl).

Cheers,
  Trond


  reply	other threads:[~2006-03-31 18:27 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 [this message]
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
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=1143829641.8085.7.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®