public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Luis Henriques <lhenriques@suse.com>
To: Jeff Layton <jlayton@kernel.org>
Cc: Ilya Dryomov <idryomov@gmail.com>,
	ceph-devel@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] ceph: don't return -ESTALE if there's still an open file
Date: Thu, 14 May 2020 13:48:45 +0100	[thread overview]
Message-ID: <20200514124845.GA12559@suse.com> (raw)
In-Reply-To: <8497fe9a11ac1837813ee5f14b6ebae8fa6bf707.camel@kernel.org>

On Thu, May 14, 2020 at 08:10:09AM -0400, Jeff Layton wrote:
> On Thu, 2020-05-14 at 12:14 +0100, Luis Henriques wrote:
> > Similarly to commit 03f219041fdb ("ceph: check i_nlink while converting
> > a file handle to dentry"), this fixes another corner case with
> > name_to_handle_at/open_by_handle_at.  The issue has been detected by
> > xfstest generic/467, when doing:
> > 
> >  - name_to_handle_at("/cephfs/myfile")
> >  - open("/cephfs/myfile")
> >  - unlink("/cephfs/myfile")
> >  - open_by_handle_at()
> > 
> > The call to open_by_handle_at should not fail because the file still
> > exists and we do have a valid handle to it.
> > 
> > Signed-off-by: Luis Henriques <lhenriques@suse.com>
> > ---
> >  fs/ceph/export.c | 13 +++++++++++--
> >  1 file changed, 11 insertions(+), 2 deletions(-)
> > 
> > diff --git a/fs/ceph/export.c b/fs/ceph/export.c
> > index 79dc06881e78..8556df9d94d0 100644
> > --- a/fs/ceph/export.c
> > +++ b/fs/ceph/export.c
> > @@ -171,12 +171,21 @@ struct inode *ceph_lookup_inode(struct super_block *sb, u64 ino)
> >  
> >  static struct dentry *__fh_to_dentry(struct super_block *sb, u64 ino)
> >  {
> > +	struct ceph_inode_info *ci;
> >  	struct inode *inode = __lookup_inode(sb, ino);
> > +
> >  	if (IS_ERR(inode))
> >  		return ERR_CAST(inode);
> >  	if (inode->i_nlink == 0) {
> > -		iput(inode);
> > -		return ERR_PTR(-ESTALE);
> > +		bool is_open;
> > +		ci = ceph_inode(inode);
> > +		spin_lock(&ci->i_ceph_lock);
> > +		is_open = __ceph_is_file_opened(ci);
> > +		spin_unlock(&ci->i_ceph_lock);
> > +		if (!is_open) {
> > +			iput(inode);
> > +			return ERR_PTR(-ESTALE);
> > +		}
> >  	}
> >  	return d_obtain_alias(inode);
> >  }
> 
> Thanks Luis. Out of curiousity, is there any reason we shouldn't ignore
> the i_nlink value here? Does anything obviously break if we do?

Yes, the scenario described in commit 03f219041fdb is still valid, which
is basically the same but without the extra open(2):

  - name_to_handle_at("/cephfs/myfile")
  - unlink("/cephfs/myfile")
  - open_by_handle_at()

The open_by_handle_at man page isn't really clear about these 2 scenarios,
but generic/426 will fail if -ESTALE isn't returned.  Want me to add a
comment to the code, describing these 2 scenarios?

Cheers,
--
Luis

  reply	other threads:[~2020-05-14 12:48 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-14 11:14 [PATCH] ceph: don't return -ESTALE if there's still an open file Luis Henriques
2020-05-14 12:10 ` Jeff Layton
2020-05-14 12:48   ` Luis Henriques [this message]
2020-05-14 13:15     ` Jeff Layton
2020-05-15  6:42       ` Amir Goldstein
2020-05-15 11:15         ` Luis Henriques
2020-05-15 11:38           ` Jeff Layton
2020-05-15 16:56             ` Amir Goldstein
2020-05-15 19:14               ` Jeff Layton
2020-05-16  6:58                 ` Amir Goldstein
2020-05-16 12:10                   ` Jeff Layton
2020-05-18 22:30                 ` Gregory Farnum
2020-05-19  4:00                   ` Amir Goldstein
2020-05-19 10:43                     ` Jeff Layton

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=20200514124845.GA12559@suse.com \
    --to=lhenriques@suse.com \
    --cc=ceph-devel@vger.kernel.org \
    --cc=idryomov@gmail.com \
    --cc=jlayton@kernel.org \
    --cc=linux-kernel@vger.kernel.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