All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Luís Henriques" <lhenriques@suse.de>
To: Jeff Layton <jlayton@kernel.org>
Cc: ceph-devel@vger.kernel.org, idryomov@gmail.com, xiubli@redhat.com
Subject: Re: [PATCH] ceph: discard r_new_inode if open O_CREAT opened existing inode
Date: Thu, 31 Mar 2022 10:49:00 +0100	[thread overview]
Message-ID: <87y20qpi43.fsf@brahms.olymp> (raw)
In-Reply-To: <7cb4898491f262fd1ecf411f055a00927ebc13b4.camel@kernel.org> (Jeff Layton's message of "Wed, 30 Mar 2022 15:13:09 -0400")

Jeff Layton <jlayton@kernel.org> writes:

> On Wed, 2022-03-30 at 15:04 -0400, Jeff Layton wrote:
>> When we do an unchecked create, we optimistically pre-create an inode
>> and populate it, including its fscrypt context. It's possible though
>> that we'll end up opening an existing inode, in which case the
>> precreated inode will have a crypto context that doesn't match the
>> existing data.
>> 
>> If we're issuing an O_CREAT open and find an existing inode, just
>> discard the precreated inode and create a new one to ensure the context
>> is properly set.
>> 
>> Cc: Luís Henriques <lhenriques@suse.de>
>> Signed-off-by: Jeff Layton <jlayton@kernel.org>
>> ---
>>  fs/ceph/mds_client.c | 10 ++++++++--
>>  1 file changed, 8 insertions(+), 2 deletions(-)
>> 
>> diff --git a/fs/ceph/mds_client.c b/fs/ceph/mds_client.c
>> index 840a60b812fc..b03128fdbb07 100644
>> --- a/fs/ceph/mds_client.c
>> +++ b/fs/ceph/mds_client.c
>> @@ -3504,13 +3504,19 @@ static void handle_reply(struct ceph_mds_session *session, struct ceph_msg *msg)
>>  	/* Must find target inode outside of mutexes to avoid deadlocks */
>>  	rinfo = &req->r_reply_info;
>>  	if ((err >= 0) && rinfo->head->is_target) {
>> -		struct inode *in;
>> +		struct inode *in = xchg(&req->r_new_inode, NULL);
>>  		struct ceph_vino tvino = {
>>  			.ino  = le64_to_cpu(rinfo->targeti.in->ino),
>>  			.snap = le64_to_cpu(rinfo->targeti.in->snapid)
>>  		};
>>  
>> -		in = ceph_get_inode(mdsc->fsc->sb, tvino, xchg(&req->r_new_inode, NULL));
>> +		/* If we ended up opening an existing inode, discard r_new_inode */
>> +		if (req->r_op == CEPH_MDS_OP_CREATE && !req->r_reply_info.has_create_ino) {
>> +			iput(in);
>> +			in = NULL;
>> +		}
>> +
>> +		in = ceph_get_inode(mdsc->fsc->sb, tvino, in);
>>  		if (IS_ERR(in)) {
>>  			err = PTR_ERR(in);
>>  			mutex_lock(&session->s_mutex);
>
> Forgot to mention that this one is for the fscrypt pile. This patch
> fixes generic/595 for me.

Wow!  I must say it: the issue is very far from the places I was looking
at.  Thanks!

Reviewed-and-tested-by: Luís Henriques <lhenriques@suse.de>

Cheers,
-- 
Luís

  reply	other threads:[~2022-03-31  9:48 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-30 19:04 [PATCH] ceph: discard r_new_inode if open O_CREAT opened existing inode Jeff Layton
2022-03-30 19:13 ` Jeff Layton
2022-03-31  9:49   ` Luís Henriques [this message]
2022-03-31  1:47 ` Xiubo Li
2022-03-31  9:53   ` Jeff Layton
2022-04-01  0:50     ` Xiubo Li

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=87y20qpi43.fsf@brahms.olymp \
    --to=lhenriques@suse.de \
    --cc=ceph-devel@vger.kernel.org \
    --cc=idryomov@gmail.com \
    --cc=jlayton@kernel.org \
    --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 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.