linux-f2fs-devel.lists.sourceforge.net archive mirror
 help / color / mirror / Atom feed
From: Jaegeuk Kim <jaegeuk@kernel.org>
To: Chao Yu <yuchao0@huawei.com>
Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org,
	linux-f2fs-devel@lists.sourceforge.net, stable@vger.kernel.org
Subject: Re: [f2fs-dev] [PATCH] f2fs: fix multiple f2fs_add_link() calls having same name
Date: Tue, 14 Feb 2017 17:39:47 -0800	[thread overview]
Message-ID: <20170215013947.GA5332@jaegeuk.local> (raw)
In-Reply-To: <4fb2c86e-a50c-512f-2fa7-964540101138@huawei.com>

On 02/15, Chao Yu wrote:
> On 2017/2/15 2:03, Jaegeuk Kim wrote:
> > VFS uses f2fs_lookup() to decide f2fs_add_link() call during file creation.
> > But, if there is a race condition, f2fs_add_link() can be called multiple
> > times, resulting in multiple dentries with a same name. This patches fixes
> > it by adding __f2fs_find_entry() in f2fs_add_link() path.
> 
> As during ->lookup, i_mutex will be held all the time, so there is no race
> condition in between different file creators?

Hehe, yup.
I dropped this patch.

Thanks,

> 
> Thanks,
> 
> > 
> > Cc: <stable@vger.kernel.org>
> > Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
> > ---
> >  fs/f2fs/dir.c | 14 ++++++++++++--
> >  1 file changed, 12 insertions(+), 2 deletions(-)
> > 
> > diff --git a/fs/f2fs/dir.c b/fs/f2fs/dir.c
> > index 827c5daef4fc..bc7c48839bec 100644
> > --- a/fs/f2fs/dir.c
> > +++ b/fs/f2fs/dir.c
> > @@ -643,14 +643,24 @@ int __f2fs_add_link(struct inode *dir, const struct qstr *name,
> >  				struct inode *inode, nid_t ino, umode_t mode)
> >  {
> >  	struct fscrypt_name fname;
> > +	struct page *page;
> > +	struct f2fs_dir_entry *de;
> >  	int err;
> >  
> >  	err = fscrypt_setup_filename(dir, name, 0, &fname);
> >  	if (err)
> >  		return err;
> >  
> > -	err = __f2fs_do_add_link(dir, &fname, inode, ino, mode);
> > -
> > +	de = __f2fs_find_entry(dir, &fname, &page);
> > +	if (de) {
> > +		f2fs_dentry_kunmap(dir, page);
> > +		f2fs_put_page(page, 0);
> > +		err = -EEXIST;
> > +	} else if (!IS_ERR(page)) {
> > +		err = __f2fs_do_add_link(dir, &fname, inode, ino, mode);
> > +	} else {
> > +		err = PTR_ERR(page);
> > +	}
> >  	fscrypt_free_filename(&fname);
> >  	return err;
> >  }
> > 

  reply	other threads:[~2017-02-15  1:39 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-14 18:03 [PATCH] f2fs: fix multiple f2fs_add_link() calls having same name Jaegeuk Kim
2017-02-15  1:18 ` [f2fs-dev] " Chao Yu
2017-02-15  1:39   ` Jaegeuk Kim [this message]
2017-02-16  1:16     ` Jaegeuk Kim
2017-02-16  3:37       ` Chao Yu
2017-02-16 17:28         ` Jaegeuk Kim

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=20170215013947.GA5332@jaegeuk.local \
    --to=jaegeuk@kernel.org \
    --cc=linux-f2fs-devel@lists.sourceforge.net \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=yuchao0@huawei.com \
    /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).