linux-um.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: Viacheslav Dubeyko <Slava.Dubeyko@ibm.com>
To: "neilb@suse.de" <neilb@suse.de>
Cc: "brauner@kernel.org" <brauner@kernel.org>,
	Xiubo Li <xiubli@redhat.com>,
	"idryomov@gmail.com" <idryomov@gmail.com>,
	Olga Kornievskaia <okorniev@redhat.com>,
	"linux-cifs@vger.kernel.org" <linux-cifs@vger.kernel.org>,
	"Dai.Ngo@oracle.com" <Dai.Ngo@oracle.com>,
	"linux-um@lists.infradead.org" <linux-um@lists.infradead.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"johannes@sipsolutions.net" <johannes@sipsolutions.net>,
	"chuck.lever@oracle.com" <chuck.lever@oracle.com>,
	"jlayton@kernel.org" <jlayton@kernel.org>,
	"anna@kernel.org" <anna@kernel.org>,
	"miklos@szeredi.hu" <miklos@szeredi.hu>,
	"trondmy@kernel.org" <trondmy@kernel.org>,
	"viro@zeniv.linux.org.uk" <viro@zeniv.linux.org.uk>,
	"jack@suse.cz" <jack@suse.cz>, "tom@talpey.com" <tom@talpey.com>,
	"richard@nod.at" <richard@nod.at>,
	"anton.ivanov@cambridgegreys.com"
	<anton.ivanov@cambridgegreys.com>,
	"linux-fsdevel@vger.kernel.org" <linux-fsdevel@vger.kernel.org>,
	"netfs@lists.linux.dev" <netfs@lists.linux.dev>,
	"linux-nfs@vger.kernel.org" <linux-nfs@vger.kernel.org>,
	"ceph-devel@vger.kernel.org" <ceph-devel@vger.kernel.org>,
	"senozhatsky@chromium.org" <senozhatsky@chromium.org>
Subject: RE:  [PATCH 3/6] ceph: return the correct dentry on mkdir
Date: Mon, 24 Feb 2025 22:09:21 +0000	[thread overview]
Message-ID: <f7d3e39f5ced7832d451de172004172b59a994eb.camel@ibm.com> (raw)
In-Reply-To: <174036334830.74271.5394074407973955108@noble.neil.brown.name>

On Mon, 2025-02-24 at 13:15 +1100, NeilBrown wrote:
> On Fri, 21 Feb 2025, Viacheslav Dubeyko wrote:
> > On Fri, 2025-02-21 at 10:36 +1100, NeilBrown wrote:
> > > ceph already splices the correct dentry (in splice_dentry()) from the
> > > result of mkdir but does nothing more with it.
> > > 
> > > Now that ->mkdir can return a dentry, return the correct dentry.
> > > 
> > > Signed-off-by: NeilBrown <neilb@suse.de>
> > > ---
> > >  fs/ceph/dir.c | 9 ++++++++-
> > >  1 file changed, 8 insertions(+), 1 deletion(-)
> > > 
> > > diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
> > > index 39e0f240de06..c1a1c168bb27 100644
> > > --- a/fs/ceph/dir.c
> > > +++ b/fs/ceph/dir.c
> > > @@ -1099,6 +1099,7 @@ static struct dentry *ceph_mkdir(struct mnt_idmap *idmap, struct inode *dir,
> > >  	struct ceph_client *cl = mdsc->fsc->client;
> > >  	struct ceph_mds_request *req;
> > >  	struct ceph_acl_sec_ctx as_ctx = {};
> > > +	struct dentry *ret = NULL;
> > 
> > I believe that it makes sense to initialize pointer by error here and always
> > return ret as output. If something goes wrong in the logic, then we already have
> > error.
> 
> I'm not certain that I understand, but I have made a change which seems
> to be consistent with the above and included it below.  Please let me
> know if it is what you intended.
> 
> > 
> > >  	int err;
> > >  	int op;
> > >  
> > > @@ -1166,14 +1167,20 @@ static struct dentry *ceph_mkdir(struct mnt_idmap *idmap, struct inode *dir,
> > >  	    !req->r_reply_info.head->is_dentry)
> > >  		err = ceph_handle_notrace_create(dir, dentry);
> > >  out_req:
> > > +	if (!err && req->r_dentry != dentry)
> > > +		/* Some other dentry was spliced in */
> > > +		ret = dget(req->r_dentry);
> > >  	ceph_mdsc_put_request(req);
> > >  out:
> > >  	if (!err)
> > > +		/* Should this use 'ret' ?? */
> > 
> > Could we make a decision should or shouldn't? :)
> > It looks not good to leave this comment instead of proper implementation. Do we
> > have some obstacles to make this decision?
> 
> I suspect we should use ret, but I didn't want to make a change which
> wasn't directly required by my needed.  So I highlighted this which
> looks to me like a possible bug, hoping that someone more familiar with
> the code would give an opinion.  Do you agree that 'ret' (i.e.
> ->r_dentry) should be used when ret is not NULL?
> 

I think if we are going to return ret as a dentry, then it makes sense to call
the ceph_init_inode_acls() for d_inode(ret). I don't see the point to call
ceph_init_inode_acls() for d_inode(dentry) then.

> > 
> > >  		ceph_init_inode_acls(d_inode(dentry), &as_ctx);
> > >  	else
> > >  		d_drop(dentry);
> > >  	ceph_release_acl_sec_ctx(&as_ctx);
> > > -	return ERR_PTR(err);
> > > +	if (err)
> > > +		return ERR_PTR(err);
> > > +	return ret;
> > 
> > What's about this?
> > 
> > return err ? ERR_PTR(err) : ret;
> 
> We could do that, but you said above that you thought we should always
> return 'ret' - which does make some sense.
> 
> What do you think of the following alternate patch?
> 

Patch looks good to me. Thanks.

Reviewed-by: Viacheslav Dubeyko <Slava.Dubeyko@ibm.com>

> Thanks,
> NeilBrown
> 
> diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
> index 39e0f240de06..d2e5c557df83 100644
> --- a/fs/ceph/dir.c
> +++ b/fs/ceph/dir.c
> @@ -1099,6 +1099,7 @@ static struct dentry *ceph_mkdir(struct mnt_idmap *idmap, struct inode *dir,
>  	struct ceph_client *cl = mdsc->fsc->client;
>  	struct ceph_mds_request *req;
>  	struct ceph_acl_sec_ctx as_ctx = {};
> +	struct dentry *ret;
>  	int err;
>  	int op;
>  
> @@ -1116,32 +1117,32 @@ static struct dentry *ceph_mkdir(struct mnt_idmap *idmap, struct inode *dir,
>  		      ceph_vinop(dir), dentry, dentry, mode);
>  		op = CEPH_MDS_OP_MKDIR;
>  	} else {
> -		err = -EROFS;
> +		ret = ERR_PTR(-EROFS);
>  		goto out;
>  	}
>  
>  	if (op == CEPH_MDS_OP_MKDIR &&
>  	    ceph_quota_is_max_files_exceeded(dir)) {
> -		err = -EDQUOT;
> +		ret = ERR_PTR(-EDQUOT);
>  		goto out;
>  	}
>  	if ((op == CEPH_MDS_OP_MKSNAP) && IS_ENCRYPTED(dir) &&
>  	    !fscrypt_has_encryption_key(dir)) {
> -		err = -ENOKEY;
> +		ret = ERR_PTR(-ENOKEY);
>  		goto out;
>  	}
>  
>  
>  	req = ceph_mdsc_create_request(mdsc, op, USE_AUTH_MDS);
>  	if (IS_ERR(req)) {
> -		err = PTR_ERR(req);
> +		ret = ERR_CAST(req);
>  		goto out;
>  	}
>  
>  	mode |= S_IFDIR;
>  	req->r_new_inode = ceph_new_inode(dir, dentry, &mode, &as_ctx);
>  	if (IS_ERR(req->r_new_inode)) {
> -		err = PTR_ERR(req->r_new_inode);
> +		ret = ERR_CAST(req->r_new_inode);
>  		req->r_new_inode = NULL;
>  		goto out_req;
>  	}
> @@ -1165,15 +1166,23 @@ static struct dentry *ceph_mkdir(struct mnt_idmap *idmap, struct inode *dir,
>  	    !req->r_reply_info.head->is_target &&
>  	    !req->r_reply_info.head->is_dentry)
>  		err = ceph_handle_notrace_create(dir, dentry);
> +	ret = ERR_PTR(err);
>  out_req:
> +	if (!IS_ERR(ret) && req->r_dentry != dentry)
> +		/* Some other dentry was spliced in */
> +		ret = dget(req->r_dentry);
>  	ceph_mdsc_put_request(req);
>  out:
> -	if (!err)
> -		ceph_init_inode_acls(d_inode(dentry), &as_ctx);
> -	else
> +	if (!IS_ERR(ret)) {
> +		if (ret)
> +			ceph_init_inode_acls(d_inode(ret), &as_ctx);
> +		else
> +			ceph_init_inode_acls(d_inode(dentry), &as_ctx);
> +	} else {
>  		d_drop(dentry);
> +	}
>  	ceph_release_acl_sec_ctx(&as_ctx);
> -	return ERR_PTR(err);
> +	return ret;
>  }
>  
>  static int ceph_link(struct dentry *old_dentry, struct inode *dir,
> 

Thanks,
Slava.


  reply	other threads:[~2025-02-24 22:09 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-20 23:36 [PATCH 0/6] Change ->mkdir() and vfs_mkdir() to return a dentry NeilBrown
2025-02-20 23:36 ` [PATCH 1/6] Change inode_operations.mkdir to return struct dentry * NeilBrown
2025-02-22  4:19   ` Al Viro
2025-02-24  1:34     ` NeilBrown
2025-02-24  2:09       ` Al Viro
2025-02-24  3:09         ` NeilBrown
2025-02-24 15:56           ` Trond Myklebust
2025-02-26  2:09             ` NeilBrown
2025-02-26  2:34               ` Trond Myklebust
2025-02-26  3:18                 ` NeilBrown
2025-02-26  3:35                   ` Al Viro
2025-02-22  4:56   ` Al Viro
2025-02-20 23:36 ` [PATCH 2/6] hostfs: store inode in dentry after mkdir if possible NeilBrown
2025-02-21 13:17   ` Jeff Layton
2025-02-20 23:36 ` [PATCH 3/6] ceph: return the correct dentry on mkdir NeilBrown
2025-02-21  1:48   ` Viacheslav Dubeyko
2025-02-24  2:15     ` NeilBrown
2025-02-24 22:09       ` Viacheslav Dubeyko [this message]
2025-02-24 22:53         ` Jeff Layton
2025-02-24 23:29         ` NeilBrown
2025-02-21 13:31   ` Jeff Layton
2025-02-20 23:36 ` [PATCH 4/6] fuse: return correct dentry for ->mkdir NeilBrown
2025-02-21 13:39   ` Jeff Layton
2025-02-22  4:24   ` Al Viro
2025-02-24  2:26     ` NeilBrown
2025-02-24  2:53       ` Al Viro
2025-02-20 23:36 ` [PATCH 5/6] nfs: change mkdir inode_operation to return alternate dentry if needed NeilBrown
2025-02-22  4:41   ` Al Viro
2025-02-24  2:41     ` NeilBrown
2025-02-20 23:36 ` [PATCH 6/6] VFS: Change vfs_mkdir() to return the dentry NeilBrown
2025-02-21 14:25   ` Jeff Layton
2025-02-22  0:32   ` Chuck Lever
2025-02-24  2:51     ` NeilBrown
2025-02-24 14:22       ` Chuck Lever
  -- strict thread matches above, loose matches on Subject: below --
2025-02-27  1:32 [PATCH 0/6 v2] Change ->mkdir() and vfs_mkdir() to return a dentry NeilBrown
2025-02-27  1:32 ` [PATCH 3/6] ceph: return the correct dentry on mkdir NeilBrown
2025-02-27 19:01   ` Christian Brauner

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=f7d3e39f5ced7832d451de172004172b59a994eb.camel@ibm.com \
    --to=slava.dubeyko@ibm.com \
    --cc=Dai.Ngo@oracle.com \
    --cc=anna@kernel.org \
    --cc=anton.ivanov@cambridgegreys.com \
    --cc=brauner@kernel.org \
    --cc=ceph-devel@vger.kernel.org \
    --cc=chuck.lever@oracle.com \
    --cc=idryomov@gmail.com \
    --cc=jack@suse.cz \
    --cc=jlayton@kernel.org \
    --cc=johannes@sipsolutions.net \
    --cc=linux-cifs@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-nfs@vger.kernel.org \
    --cc=linux-um@lists.infradead.org \
    --cc=miklos@szeredi.hu \
    --cc=neilb@suse.de \
    --cc=netfs@lists.linux.dev \
    --cc=okorniev@redhat.com \
    --cc=richard@nod.at \
    --cc=senozhatsky@chromium.org \
    --cc=tom@talpey.com \
    --cc=trondmy@kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    --cc=xiubli@redhat.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).