All of lore.kernel.org
 help / color / mirror / Atom feed
From: Brian Foster <bfoster@redhat.com>
To: Maxim Patlasov <MPatlasov@parallels.com>
Cc: miklos@szeredi.hu, fuse-devel@lists.sourceforge.net,
	avati@redhat.com, linux-kernel@vger.kernel.org, devel@openvz.org
Subject: Re: [PATCH] fuse: hold i_mutex in fuse_file_fallocate()
Date: Wed, 12 Jun 2013 07:40:22 -0400	[thread overview]
Message-ID: <51B85E26.8000303@redhat.com> (raw)
In-Reply-To: <20130611105714.24455.38409.stgit@maximpc.sw.ru>

On 06/11/2013 06:59 AM, Maxim Patlasov wrote:
> Changing size of a file on server and local update (fuse_write_update_size)
> should be always protected by inode->i_mutex. Otherwise a race like this is
> possible:
> 
> 1. Process 'A' calls fallocate(2) to extend file (~FALLOC_FL_KEEP_SIZE).
> fuse_file_fallocate() sends FUSE_FALLOCATE request to the server.
> 2. Process 'B' performs ordinary buffered write(2) with a length big enough
> to extend the file beyond "offset + length" of fallocate call.
> 3. Process 'A' resumes execution of fuse_file_fallocate() and calls
> fuse_write_update_size(inode, offset + length). But 'offset + length' was
> obsoleted by write from previous step.
> 

Hi Maxim,

Doesn't fuse_write_update_size() already handle this particular case by
only ever extending the size?

Brian

> Signed-off-by: Maxim V. Patlasov <MPatlasov@parallels.com>
> ---
>  fs/fuse/file.c |   10 ++++++----
>  1 files changed, 6 insertions(+), 4 deletions(-)
> 
> diff --git a/fs/fuse/file.c b/fs/fuse/file.c
> index e570081..8dfbf7d 100644
> --- a/fs/fuse/file.c
> +++ b/fs/fuse/file.c
> @@ -2470,14 +2470,16 @@ static long fuse_file_fallocate(struct file *file, int mode, loff_t offset,
>  		.mode = mode
>  	};
>  	int err;
> +	bool lock_inode = !(mode & FALLOC_FL_KEEP_SIZE) ||
> +			   (mode & FALLOC_FL_PUNCH_HOLE);
>  
>  	if (fc->no_fallocate)
>  		return -EOPNOTSUPP;
>  
> -	if (mode & FALLOC_FL_PUNCH_HOLE) {
> +	if (lock_inode)
>  		mutex_lock(&inode->i_mutex);
> +	if (mode & FALLOC_FL_PUNCH_HOLE)
>  		fuse_set_nowrite(inode);
> -	}
>  
>  	req = fuse_get_req_nopages(fc);
>  	if (IS_ERR(req)) {
> @@ -2511,10 +2513,10 @@ static long fuse_file_fallocate(struct file *file, int mode, loff_t offset,
>  	fuse_invalidate_attr(inode);
>  
>  out:
> -	if (mode & FALLOC_FL_PUNCH_HOLE) {
> +	if (mode & FALLOC_FL_PUNCH_HOLE)
>  		fuse_release_nowrite(inode);
> +	if (lock_inode)
>  		mutex_unlock(&inode->i_mutex);
> -	}
>  
>  	return err;
>  }
> 


  reply	other threads:[~2013-06-12 11:36 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-06-11 10:59 [PATCH] fuse: hold i_mutex in fuse_file_fallocate() Maxim Patlasov
2013-06-12 11:40 ` Brian Foster [this message]
2013-06-12 18:56   ` Anand Avati
2013-06-12 19:04 ` Anand Avati
2013-06-13  7:15   ` Maxim Patlasov

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=51B85E26.8000303@redhat.com \
    --to=bfoster@redhat.com \
    --cc=MPatlasov@parallels.com \
    --cc=avati@redhat.com \
    --cc=devel@openvz.org \
    --cc=fuse-devel@lists.sourceforge.net \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.