diff mbox series

[2/2] shmem: allow reporting fanotify events with file handles on tmpfs

Message ID 20210322173944.449469-3-amir73il@gmail.com (mailing list archive)
State New, archived
Headers show
Series Better fanotify support for tmpfs | expand

Commit Message

Amir Goldstein March 22, 2021, 5:39 p.m. UTC
Since kernel v5.1, fanotify_init(2) supports the flag FAN_REPORT_FID
for identifying objects using file handle and fsid in events.

fanotify_mark(2) fails with -ENODEV when trying to set a mark on
filesystems that report null f_fsid in stasfs(2).

Use the digest of uuid as f_fsid for tmpfs to uniquely identify tmpfs
objects as best as possible and allow setting an fanotify mark that
reports events with file handles on tmpfs.

Signed-off-by: Amir Goldstein <amir73il@gmail.com>
---
 mm/shmem.c | 3 +++
 1 file changed, 3 insertions(+)

Comments

Jan Kara March 25, 2021, 3 p.m. UTC | #1
On Mon 22-03-21 19:39:44, Amir Goldstein wrote:
> Since kernel v5.1, fanotify_init(2) supports the flag FAN_REPORT_FID
> for identifying objects using file handle and fsid in events.
> 
> fanotify_mark(2) fails with -ENODEV when trying to set a mark on
> filesystems that report null f_fsid in stasfs(2).
> 
> Use the digest of uuid as f_fsid for tmpfs to uniquely identify tmpfs
> objects as best as possible and allow setting an fanotify mark that
> reports events with file handles on tmpfs.
> 
> Signed-off-by: Amir Goldstein <amir73il@gmail.com>

Hugh, any opinion on this patch?

								Honza

> ---
>  mm/shmem.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/mm/shmem.c b/mm/shmem.c
> index b2db4ed0fbc7..162d8f8993bb 100644
> --- a/mm/shmem.c
> +++ b/mm/shmem.c
> @@ -2846,6 +2846,9 @@ static int shmem_statfs(struct dentry *dentry, struct kstatfs *buf)
>  		buf->f_ffree = sbinfo->free_inodes;
>  	}
>  	/* else leave those fields 0 like simple_statfs */
> +
> +	buf->f_fsid = uuid_to_fsid(dentry->d_sb->s_uuid.b);
> +
>  	return 0;
>  }
>  
> -- 
> 2.25.1
>
Amir Goldstein April 16, 2021, 9:59 a.m. UTC | #2
On Thu, Mar 25, 2021 at 5:00 PM Jan Kara <jack@suse.cz> wrote:
>
> On Mon 22-03-21 19:39:44, Amir Goldstein wrote:
> > Since kernel v5.1, fanotify_init(2) supports the flag FAN_REPORT_FID
> > for identifying objects using file handle and fsid in events.
> >
> > fanotify_mark(2) fails with -ENODEV when trying to set a mark on
> > filesystems that report null f_fsid in stasfs(2).
> >
> > Use the digest of uuid as f_fsid for tmpfs to uniquely identify tmpfs
> > objects as best as possible and allow setting an fanotify mark that
> > reports events with file handles on tmpfs.
> >
> > Signed-off-by: Amir Goldstein <amir73il@gmail.com>
>
> Hugh, any opinion on this patch?
>
>                                                                 Honza
>
> > ---
> >  mm/shmem.c | 3 +++
> >  1 file changed, 3 insertions(+)
> >
> > diff --git a/mm/shmem.c b/mm/shmem.c
> > index b2db4ed0fbc7..162d8f8993bb 100644
> > --- a/mm/shmem.c
> > +++ b/mm/shmem.c
> > @@ -2846,6 +2846,9 @@ static int shmem_statfs(struct dentry *dentry, struct kstatfs *buf)
> >               buf->f_ffree = sbinfo->free_inodes;
> >       }
> >       /* else leave those fields 0 like simple_statfs */
> > +
> > +     buf->f_fsid = uuid_to_fsid(dentry->d_sb->s_uuid.b);
> > +
> >       return 0;
> >  }
> >


Ping.

Hugh, are you ok with this change?

Thanks,
Amir.
Hugh Dickins April 17, 2021, 3:54 a.m. UTC | #3
On Fri, 16 Apr 2021, Amir Goldstein wrote:
> On Thu, Mar 25, 2021 at 5:00 PM Jan Kara <jack@suse.cz> wrote:
> >
> > On Mon 22-03-21 19:39:44, Amir Goldstein wrote:
> > > Since kernel v5.1, fanotify_init(2) supports the flag FAN_REPORT_FID
> > > for identifying objects using file handle and fsid in events.
> > >
> > > fanotify_mark(2) fails with -ENODEV when trying to set a mark on
> > > filesystems that report null f_fsid in stasfs(2).
> > >
> > > Use the digest of uuid as f_fsid for tmpfs to uniquely identify tmpfs
> > > objects as best as possible and allow setting an fanotify mark that
> > > reports events with file handles on tmpfs.
> > >
> > > Signed-off-by: Amir Goldstein <amir73il@gmail.com>
> >
> > Hugh, any opinion on this patch?
> >
> >                                                                 Honza
> >
> > > ---
> > >  mm/shmem.c | 3 +++
> > >  1 file changed, 3 insertions(+)
> > >
> > > diff --git a/mm/shmem.c b/mm/shmem.c
> > > index b2db4ed0fbc7..162d8f8993bb 100644
> > > --- a/mm/shmem.c
> > > +++ b/mm/shmem.c
> > > @@ -2846,6 +2846,9 @@ static int shmem_statfs(struct dentry *dentry, struct kstatfs *buf)
> > >               buf->f_ffree = sbinfo->free_inodes;
> > >       }
> > >       /* else leave those fields 0 like simple_statfs */
> > > +
> > > +     buf->f_fsid = uuid_to_fsid(dentry->d_sb->s_uuid.b);
> > > +
> > >       return 0;
> > >  }
> > >
> 
> 
> Ping.
> 
> Hugh, are you ok with this change?
> 
> Thanks,
> Amir.

Yes, apologies for my delay to you, Amir and Jan:
sure I'm ok with this change, and thank you for taking care of tmpfs.

Acked-by: Hugh Dickins <hughd@google.com>

But you have more valuable acks on this little series already,
so don't bother rebasing some tree to add mine in now.  I don't yet
see the uuid_to_fsid() 1/2 which this depends on in linux-next, and
fear that's my fault for holding you back: sorry, please go ahead now.

Hugh
Jan Kara April 19, 2021, 8:34 a.m. UTC | #4
On Fri 16-04-21 20:54:46, Hugh Dickins wrote:
> On Fri, 16 Apr 2021, Amir Goldstein wrote:
> > On Thu, Mar 25, 2021 at 5:00 PM Jan Kara <jack@suse.cz> wrote:
> > >
> > > On Mon 22-03-21 19:39:44, Amir Goldstein wrote:
> > > > Since kernel v5.1, fanotify_init(2) supports the flag FAN_REPORT_FID
> > > > for identifying objects using file handle and fsid in events.
> > > >
> > > > fanotify_mark(2) fails with -ENODEV when trying to set a mark on
> > > > filesystems that report null f_fsid in stasfs(2).
> > > >
> > > > Use the digest of uuid as f_fsid for tmpfs to uniquely identify tmpfs
> > > > objects as best as possible and allow setting an fanotify mark that
> > > > reports events with file handles on tmpfs.
> > > >
> > > > Signed-off-by: Amir Goldstein <amir73il@gmail.com>
> > >
> > > Hugh, any opinion on this patch?
> > >
> > >                                                                 Honza
> > >
> > > > ---
> > > >  mm/shmem.c | 3 +++
> > > >  1 file changed, 3 insertions(+)
> > > >
> > > > diff --git a/mm/shmem.c b/mm/shmem.c
> > > > index b2db4ed0fbc7..162d8f8993bb 100644
> > > > --- a/mm/shmem.c
> > > > +++ b/mm/shmem.c
> > > > @@ -2846,6 +2846,9 @@ static int shmem_statfs(struct dentry *dentry, struct kstatfs *buf)
> > > >               buf->f_ffree = sbinfo->free_inodes;
> > > >       }
> > > >       /* else leave those fields 0 like simple_statfs */
> > > > +
> > > > +     buf->f_fsid = uuid_to_fsid(dentry->d_sb->s_uuid.b);
> > > > +
> > > >       return 0;
> > > >  }
> > > >
> > 
> > 
> > Ping.
> > 
> > Hugh, are you ok with this change?
> > 
> > Thanks,
> > Amir.
> 
> Yes, apologies for my delay to you, Amir and Jan:
> sure I'm ok with this change, and thank you for taking care of tmpfs.
> 
> Acked-by: Hugh Dickins <hughd@google.com>

Thanks for the ack Hugh!

> But you have more valuable acks on this little series already,
> so don't bother rebasing some tree to add mine in now.  I don't yet
> see the uuid_to_fsid() 1/2 which this depends on in linux-next, and
> fear that's my fault for holding you back: sorry, please go ahead now.

Yeah, I was reluctant to push this patch without your ack and honestly I
forgot about the first patch while waiting for your ack. Anyway, both
patches are now in my tree and since Linus tagged rc8 and they are
nobrainers, I plan to push them to Linus for the next merge window.

								Honza
diff mbox series

Patch

diff --git a/mm/shmem.c b/mm/shmem.c
index b2db4ed0fbc7..162d8f8993bb 100644
--- a/mm/shmem.c
+++ b/mm/shmem.c
@@ -2846,6 +2846,9 @@  static int shmem_statfs(struct dentry *dentry, struct kstatfs *buf)
 		buf->f_ffree = sbinfo->free_inodes;
 	}
 	/* else leave those fields 0 like simple_statfs */
+
+	buf->f_fsid = uuid_to_fsid(dentry->d_sb->s_uuid.b);
+
 	return 0;
 }