All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC PATCH] vfs: allow ->atomic_open() on positive
@ 2022-05-19 14:43 Miklos Szeredi
  2022-05-19 20:09 ` Vivek Goyal
  2022-05-20  4:07 ` Al Viro
  0 siblings, 2 replies; 7+ messages in thread
From: Miklos Szeredi @ 2022-05-19 14:43 UTC (permalink / raw)
  To: Al Viro; +Cc: linux-fsdevel, Vivek Goyal, Dharmendra Singh, Bernd Schubert

Hi Al,

Do you see anything bad with allowing ->atomic_open() to take a positive dentry
and possibly invalidate it after it does the atomic LOOKUP/CREATE+OPEN?

It looks wrong not to allow optimizing away the roundtrip associated with
revalidation when we do allow optimizing away the roundtrip for the initial
lookup in the same situation.

Thanks,
Miklos


diff --git a/fs/namei.c b/fs/namei.c
index 509657fdf4f5..d35b5cbf7f64 100644
--- a/fs/namei.c
+++ b/fs/namei.c
@@ -3267,7 +3267,7 @@ static struct dentry *lookup_open(struct nameidata *nd, struct file *file,
 		dput(dentry);
 		dentry = NULL;
 	}
-	if (dentry->d_inode) {
+	if (dentry->d_inode && !d_atomic_open(dentry)) {
 		/* Cached positive dentry: will open in f_op->open */
 		return dentry;
 	}
diff --git a/include/linux/dcache.h b/include/linux/dcache.h
index f5bba51480b2..da681bdbc34e 100644
--- a/include/linux/dcache.h
+++ b/include/linux/dcache.h
@@ -208,6 +208,7 @@ struct dentry_operations {
 #define DCACHE_NOKEY_NAME		0x02000000 /* Encrypted name encoded without key */
 #define DCACHE_OP_REAL			0x04000000
 
+#define DCACHE_ATOMIC_OPEN		0x08000000 /* Always use ->atomic_open() to open this file */
 #define DCACHE_PAR_LOOKUP		0x10000000 /* being looked up (with parent locked shared) */
 #define DCACHE_DENTRY_CURSOR		0x20000000
 #define DCACHE_NORCU			0x40000000 /* No RCU delay for freeing */
@@ -446,6 +447,11 @@ static inline bool d_is_positive(const struct dentry *dentry)
 	return !d_is_negative(dentry);
 }
 
+static inline bool d_atomic_open(const struct dentry *dentry)
+{
+	return dentry->d_flags & DCACHE_ATOMIC_OPEN;
+}
+
 /**
  * d_really_is_negative - Determine if a dentry is really negative (ignoring fallthroughs)
  * @dentry: The dentry in question

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [RFC PATCH] vfs: allow ->atomic_open() on positive
  2022-05-19 14:43 [RFC PATCH] vfs: allow ->atomic_open() on positive Miklos Szeredi
@ 2022-05-19 20:09 ` Vivek Goyal
  2022-05-19 20:43   ` Bernd Schubert
  2022-05-20  6:48   ` Miklos Szeredi
  2022-05-20  4:07 ` Al Viro
  1 sibling, 2 replies; 7+ messages in thread
From: Vivek Goyal @ 2022-05-19 20:09 UTC (permalink / raw)
  To: Miklos Szeredi; +Cc: Al Viro, linux-fsdevel, Dharmendra Singh, Bernd Schubert

On Thu, May 19, 2022 at 04:43:58PM +0200, Miklos Szeredi wrote:
> Hi Al,
> 
> Do you see anything bad with allowing ->atomic_open() to take a positive dentry
> and possibly invalidate it after it does the atomic LOOKUP/CREATE+OPEN?
> 
> It looks wrong not to allow optimizing away the roundtrip associated with
> revalidation when we do allow optimizing away the roundtrip for the initial
> lookup in the same situation.
> 
> Thanks,
> Miklos
> 
> 
> diff --git a/fs/namei.c b/fs/namei.c
> index 509657fdf4f5..d35b5cbf7f64 100644
> --- a/fs/namei.c
> +++ b/fs/namei.c
> @@ -3267,7 +3267,7 @@ static struct dentry *lookup_open(struct nameidata *nd, struct file *file,
>  		dput(dentry);
>  		dentry = NULL;
>  	}
> -	if (dentry->d_inode) {
> +	if (dentry->d_inode && !d_atomic_open(dentry)) {
>  		/* Cached positive dentry: will open in f_op->open */
>  		return dentry;

Hi Miklos,

I see that lookup_open() calls d_revalidate() first. So basically
idea is that fuse ->.d_revalidate will skip LOOKUP needed to make sure
dentry is still valid (Only if atomic lookup+open is implemented) and
return 1 claiming dentry is valid.

And later in ->atomic_open(), it will either open the file or 
get an error and invalidate dentry. Hence will save one LOOKUP in
success case. Do I understand the intent right?

Thanks
Vivek

>  	}
> diff --git a/include/linux/dcache.h b/include/linux/dcache.h
> index f5bba51480b2..da681bdbc34e 100644
> --- a/include/linux/dcache.h
> +++ b/include/linux/dcache.h
> @@ -208,6 +208,7 @@ struct dentry_operations {
>  #define DCACHE_NOKEY_NAME		0x02000000 /* Encrypted name encoded without key */
>  #define DCACHE_OP_REAL			0x04000000
>  
> +#define DCACHE_ATOMIC_OPEN		0x08000000 /* Always use ->atomic_open() to open this file */
>  #define DCACHE_PAR_LOOKUP		0x10000000 /* being looked up (with parent locked shared) */
>  #define DCACHE_DENTRY_CURSOR		0x20000000
>  #define DCACHE_NORCU			0x40000000 /* No RCU delay for freeing */
> @@ -446,6 +447,11 @@ static inline bool d_is_positive(const struct dentry *dentry)
>  	return !d_is_negative(dentry);
>  }
>  
> +static inline bool d_atomic_open(const struct dentry *dentry)
> +{
> +	return dentry->d_flags & DCACHE_ATOMIC_OPEN;
> +}
> +
>  /**
>   * d_really_is_negative - Determine if a dentry is really negative (ignoring fallthroughs)
>   * @dentry: The dentry in question
> 


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [RFC PATCH] vfs: allow ->atomic_open() on positive
  2022-05-19 20:09 ` Vivek Goyal
@ 2022-05-19 20:43   ` Bernd Schubert
  2022-05-19 20:50     ` Vivek Goyal
  2022-05-20  6:48   ` Miklos Szeredi
  1 sibling, 1 reply; 7+ messages in thread
From: Bernd Schubert @ 2022-05-19 20:43 UTC (permalink / raw)
  To: Vivek Goyal, Miklos Szeredi; +Cc: Al Viro, linux-fsdevel, Dharmendra Singh



On 5/19/22 22:09, Vivek Goyal wrote:
> On Thu, May 19, 2022 at 04:43:58PM +0200, Miklos Szeredi wrote:
>> Hi Al,
>>
>> Do you see anything bad with allowing ->atomic_open() to take a positive dentry
>> and possibly invalidate it after it does the atomic LOOKUP/CREATE+OPEN?
>>
>> It looks wrong not to allow optimizing away the roundtrip associated with
>> revalidation when we do allow optimizing away the roundtrip for the initial
>> lookup in the same situation.
>>
>> Thanks,
>> Miklos
>>
>>
>> diff --git a/fs/namei.c b/fs/namei.c
>> index 509657fdf4f5..d35b5cbf7f64 100644
>> --- a/fs/namei.c
>> +++ b/fs/namei.c
>> @@ -3267,7 +3267,7 @@ static struct dentry *lookup_open(struct nameidata *nd, struct file *file,
>>   		dput(dentry);
>>   		dentry = NULL;
>>   	}
>> -	if (dentry->d_inode) {
>> +	if (dentry->d_inode && !d_atomic_open(dentry)) {
>>   		/* Cached positive dentry: will open in f_op->open */
>>   		return dentry;
> 
> Hi Miklos,
> 
> I see that lookup_open() calls d_revalidate() first. So basically
> idea is that fuse ->.d_revalidate will skip LOOKUP needed to make sure
> dentry is still valid (Only if atomic lookup+open is implemented) and
> return 1 claiming dentry is valid.
> 
> And later in ->atomic_open(), it will either open the file or
> get an error and invalidate dentry. Hence will save one LOOKUP in
> success case. Do I understand the intent right?

Yeah, I think Dharmendra and I had internally already debated over this. 
In order to reduce complexity for the patches we preferred to go without 
vfs modifications.

I assume the patch is a follow up to this comment
https://lore.kernel.org/all/20220517100744.26849-1-dharamhans87@gmail.com/T/#m8bd440ddea4c135688c829f34e93371e861ba9fa


Thanks,
Bernd

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [RFC PATCH] vfs: allow ->atomic_open() on positive
  2022-05-19 20:43   ` Bernd Schubert
@ 2022-05-19 20:50     ` Vivek Goyal
  0 siblings, 0 replies; 7+ messages in thread
From: Vivek Goyal @ 2022-05-19 20:50 UTC (permalink / raw)
  To: Bernd Schubert; +Cc: Miklos Szeredi, Al Viro, linux-fsdevel, Dharmendra Singh

On Thu, May 19, 2022 at 10:43:54PM +0200, Bernd Schubert wrote:
> 
> 
> On 5/19/22 22:09, Vivek Goyal wrote:
> > On Thu, May 19, 2022 at 04:43:58PM +0200, Miklos Szeredi wrote:
> > > Hi Al,
> > > 
> > > Do you see anything bad with allowing ->atomic_open() to take a positive dentry
> > > and possibly invalidate it after it does the atomic LOOKUP/CREATE+OPEN?
> > > 
> > > It looks wrong not to allow optimizing away the roundtrip associated with
> > > revalidation when we do allow optimizing away the roundtrip for the initial
> > > lookup in the same situation.
> > > 
> > > Thanks,
> > > Miklos
> > > 
> > > 
> > > diff --git a/fs/namei.c b/fs/namei.c
> > > index 509657fdf4f5..d35b5cbf7f64 100644
> > > --- a/fs/namei.c
> > > +++ b/fs/namei.c
> > > @@ -3267,7 +3267,7 @@ static struct dentry *lookup_open(struct nameidata *nd, struct file *file,
> > >   		dput(dentry);
> > >   		dentry = NULL;
> > >   	}
> > > -	if (dentry->d_inode) {
> > > +	if (dentry->d_inode && !d_atomic_open(dentry)) {
> > >   		/* Cached positive dentry: will open in f_op->open */
> > >   		return dentry;
> > 
> > Hi Miklos,
> > 
> > I see that lookup_open() calls d_revalidate() first. So basically
> > idea is that fuse ->.d_revalidate will skip LOOKUP needed to make sure
> > dentry is still valid (Only if atomic lookup+open is implemented) and
> > return 1 claiming dentry is valid.
> > 
> > And later in ->atomic_open(), it will either open the file or
> > get an error and invalidate dentry. Hence will save one LOOKUP in
> > success case. Do I understand the intent right?
> 
> Yeah, I think Dharmendra and I had internally already debated over this. In
> order to reduce complexity for the patches we preferred to go without vfs
> modifications.

Fair enough. It is not trivial to be able to see all the paths and make
sure none of these paths is broken.

> 
> I assume the patch is a follow up to this comment
> https://lore.kernel.org/all/20220517100744.26849-1-dharamhans87@gmail.com/T/#m8bd440ddea4c135688c829f34e93371e861ba9fa
> 

Yes looks like. There are too many paths here and being able to wrap
one's head around all the paths is not trivial. Thankfully miklos
has summarized it here.

https://lore.kernel.org/all/20220517100744.26849-1-dharamhans87@gmail.com/T/#m90f64cd8c8fff70e2fba2b551ae01d0d47b3337e

Thanks
Vivek


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [RFC PATCH] vfs: allow ->atomic_open() on positive
  2022-05-19 14:43 [RFC PATCH] vfs: allow ->atomic_open() on positive Miklos Szeredi
  2022-05-19 20:09 ` Vivek Goyal
@ 2022-05-20  4:07 ` Al Viro
  2022-05-20  6:44   ` Miklos Szeredi
  1 sibling, 1 reply; 7+ messages in thread
From: Al Viro @ 2022-05-20  4:07 UTC (permalink / raw)
  To: Miklos Szeredi
  Cc: linux-fsdevel, Vivek Goyal, Dharmendra Singh, Bernd Schubert

On Thu, May 19, 2022 at 04:43:58PM +0200, Miklos Szeredi wrote:
> Hi Al,
> 
> Do you see anything bad with allowing ->atomic_open() to take a positive dentry
> and possibly invalidate it after it does the atomic LOOKUP/CREATE+OPEN?
> 
> It looks wrong not to allow optimizing away the roundtrip associated with
> revalidation when we do allow optimizing away the roundtrip for the initial
> lookup in the same situation.

Details, please - what will your ->atomic_open() do in that case?

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [RFC PATCH] vfs: allow ->atomic_open() on positive
  2022-05-20  4:07 ` Al Viro
@ 2022-05-20  6:44   ` Miklos Szeredi
  0 siblings, 0 replies; 7+ messages in thread
From: Miklos Szeredi @ 2022-05-20  6:44 UTC (permalink / raw)
  To: Al Viro; +Cc: linux-fsdevel, Vivek Goyal, Dharmendra Singh, Bernd Schubert

On Fri, 20 May 2022 at 06:07, Al Viro <viro@zeniv.linux.org.uk> wrote:
>
> On Thu, May 19, 2022 at 04:43:58PM +0200, Miklos Szeredi wrote:
> > Hi Al,
> >
> > Do you see anything bad with allowing ->atomic_open() to take a positive dentry
> > and possibly invalidate it after it does the atomic LOOKUP/CREATE+OPEN?
> >
> > It looks wrong not to allow optimizing away the roundtrip associated with
> > revalidation when we do allow optimizing away the roundtrip for the initial
> > lookup in the same situation.
>
> Details, please - what will your ->atomic_open() do in that case?

It will do an open-by-name or create-and-open depending on the flags.
It will return whether the file was created or not.

If created, then the old positive is obviously stale, so it will be
invalidated and a new one allocated.

If not created, then check whether it's the same inode (same as in
->d_revalidate()) and if not, invalidate & allocate new dentry.

Thanks,
Miklos

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [RFC PATCH] vfs: allow ->atomic_open() on positive
  2022-05-19 20:09 ` Vivek Goyal
  2022-05-19 20:43   ` Bernd Schubert
@ 2022-05-20  6:48   ` Miklos Szeredi
  1 sibling, 0 replies; 7+ messages in thread
From: Miklos Szeredi @ 2022-05-20  6:48 UTC (permalink / raw)
  To: Vivek Goyal; +Cc: Al Viro, linux-fsdevel, Dharmendra Singh, Bernd Schubert

On Thu, 19 May 2022 at 22:09, Vivek Goyal <vgoyal@redhat.com> wrote:
>
> On Thu, May 19, 2022 at 04:43:58PM +0200, Miklos Szeredi wrote:
> > Hi Al,
> >
> > Do you see anything bad with allowing ->atomic_open() to take a positive dentry
> > and possibly invalidate it after it does the atomic LOOKUP/CREATE+OPEN?
> >
> > It looks wrong not to allow optimizing away the roundtrip associated with
> > revalidation when we do allow optimizing away the roundtrip for the initial
> > lookup in the same situation.
> >
> > Thanks,
> > Miklos
> >
> >
> > diff --git a/fs/namei.c b/fs/namei.c
> > index 509657fdf4f5..d35b5cbf7f64 100644
> > --- a/fs/namei.c
> > +++ b/fs/namei.c
> > @@ -3267,7 +3267,7 @@ static struct dentry *lookup_open(struct nameidata *nd, struct file *file,
> >               dput(dentry);
> >               dentry = NULL;
> >       }
> > -     if (dentry->d_inode) {
> > +     if (dentry->d_inode && !d_atomic_open(dentry)) {
> >               /* Cached positive dentry: will open in f_op->open */
> >               return dentry;
>
> Hi Miklos,
>
> I see that lookup_open() calls d_revalidate() first. So basically
> idea is that fuse ->.d_revalidate will skip LOOKUP needed to make sure
> dentry is still valid (Only if atomic lookup+open is implemented) and
> return 1 claiming dentry is valid.

Yes.

> And later in ->atomic_open(), it will either open the file or
> get an error and invalidate dentry. Hence will save one LOOKUP in
> success case. Do I understand the intent right?

It should not fail in the stale dentry case either, just merge the
revalidation into ->atomic_open().

Thanks,
Miklos

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2022-05-20  6:48 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-19 14:43 [RFC PATCH] vfs: allow ->atomic_open() on positive Miklos Szeredi
2022-05-19 20:09 ` Vivek Goyal
2022-05-19 20:43   ` Bernd Schubert
2022-05-19 20:50     ` Vivek Goyal
2022-05-20  6:48   ` Miklos Szeredi
2022-05-20  4:07 ` Al Viro
2022-05-20  6:44   ` Miklos Szeredi

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.