diff mbox series

[02/10] fsnotify: create helpers to get sb and connp from object

Message ID 20240317184154.1200192-3-amir73il@gmail.com (mailing list archive)
State New
Headers show
Series Further reduce overhead of fsnotify permission hooks | expand

Commit Message

Amir Goldstein March 17, 2024, 6:41 p.m. UTC
In preparation to passing an object pointer to add/remove/find mark
helpers, create helpers to get sb and connp by object type.

Signed-off-by: Amir Goldstein <amir73il@gmail.com>
---
 fs/notify/fsnotify.h | 14 ++++++++++++++
 fs/notify/mark.c     | 14 ++++++++++++++
 2 files changed, 28 insertions(+)

Comments

Christian Brauner March 20, 2024, 8:28 a.m. UTC | #1
On Sun, Mar 17, 2024 at 08:41:46PM +0200, Amir Goldstein wrote:
> In preparation to passing an object pointer to add/remove/find mark
> helpers, create helpers to get sb and connp by object type.
> 
> Signed-off-by: Amir Goldstein <amir73il@gmail.com>
> ---
>  fs/notify/fsnotify.h | 14 ++++++++++++++
>  fs/notify/mark.c     | 14 ++++++++++++++
>  2 files changed, 28 insertions(+)
> 
> diff --git a/fs/notify/fsnotify.h b/fs/notify/fsnotify.h
> index fde74eb333cc..87456ce40364 100644
> --- a/fs/notify/fsnotify.h
> +++ b/fs/notify/fsnotify.h
> @@ -27,6 +27,20 @@ static inline struct super_block *fsnotify_conn_sb(
>  	return container_of(conn->obj, struct super_block, s_fsnotify_marks);
>  }
>  
> +static inline struct super_block *fsnotify_object_sb(void *obj, int obj_type)

If I read correctly, then in some places you use unsigned int obj_type
and here you use int obj_type. The best option would likely be to just
introduce an enum fsnotify_obj_type either in this series or in a
follow-up series.
Amir Goldstein March 20, 2024, 8:34 a.m. UTC | #2
On Wed, Mar 20, 2024 at 10:29 AM Christian Brauner <brauner@kernel.org> wrote:
>
> On Sun, Mar 17, 2024 at 08:41:46PM +0200, Amir Goldstein wrote:
> > In preparation to passing an object pointer to add/remove/find mark
> > helpers, create helpers to get sb and connp by object type.
> >
> > Signed-off-by: Amir Goldstein <amir73il@gmail.com>
> > ---
> >  fs/notify/fsnotify.h | 14 ++++++++++++++
> >  fs/notify/mark.c     | 14 ++++++++++++++
> >  2 files changed, 28 insertions(+)
> >
> > diff --git a/fs/notify/fsnotify.h b/fs/notify/fsnotify.h
> > index fde74eb333cc..87456ce40364 100644
> > --- a/fs/notify/fsnotify.h
> > +++ b/fs/notify/fsnotify.h
> > @@ -27,6 +27,20 @@ static inline struct super_block *fsnotify_conn_sb(
> >       return container_of(conn->obj, struct super_block, s_fsnotify_marks);
> >  }
> >
> > +static inline struct super_block *fsnotify_object_sb(void *obj, int obj_type)
>
> If I read correctly, then in some places you use unsigned int obj_type
> and here you use int obj_type. The best option would likely be to just
> introduce an enum fsnotify_obj_type either in this series or in a
> follow-up series.

Good point.

There is an enum already but we do not use it.
Jan, WDYT?

Thanks,
Amir.
Jan Kara March 20, 2024, 9:57 a.m. UTC | #3
On Wed 20-03-24 10:34:45, Amir Goldstein wrote:
> On Wed, Mar 20, 2024 at 10:29 AM Christian Brauner <brauner@kernel.org> wrote:
> >
> > On Sun, Mar 17, 2024 at 08:41:46PM +0200, Amir Goldstein wrote:
> > > In preparation to passing an object pointer to add/remove/find mark
> > > helpers, create helpers to get sb and connp by object type.
> > >
> > > Signed-off-by: Amir Goldstein <amir73il@gmail.com>
> > > ---
> > >  fs/notify/fsnotify.h | 14 ++++++++++++++
> > >  fs/notify/mark.c     | 14 ++++++++++++++
> > >  2 files changed, 28 insertions(+)
> > >
> > > diff --git a/fs/notify/fsnotify.h b/fs/notify/fsnotify.h
> > > index fde74eb333cc..87456ce40364 100644
> > > --- a/fs/notify/fsnotify.h
> > > +++ b/fs/notify/fsnotify.h
> > > @@ -27,6 +27,20 @@ static inline struct super_block *fsnotify_conn_sb(
> > >       return container_of(conn->obj, struct super_block, s_fsnotify_marks);
> > >  }
> > >
> > > +static inline struct super_block *fsnotify_object_sb(void *obj, int obj_type)
> >
> > If I read correctly, then in some places you use unsigned int obj_type
> > and here you use int obj_type. The best option would likely be to just
> > introduce an enum fsnotify_obj_type either in this series or in a
> > follow-up series.
> 
> Good point.
> 
> There is an enum already but we do not use it.
> Jan, WDYT?

Yeah. So far we just use enum fsnotify_obj_type to define values but don't
use it as a type itself. I guess it would be worthy cleanup but not in this
series. Here I guess we could just use the enum instead of introducing new
functions taking 'int' argument.

								Honza
diff mbox series

Patch

diff --git a/fs/notify/fsnotify.h b/fs/notify/fsnotify.h
index fde74eb333cc..87456ce40364 100644
--- a/fs/notify/fsnotify.h
+++ b/fs/notify/fsnotify.h
@@ -27,6 +27,20 @@  static inline struct super_block *fsnotify_conn_sb(
 	return container_of(conn->obj, struct super_block, s_fsnotify_marks);
 }
 
+static inline struct super_block *fsnotify_object_sb(void *obj, int obj_type)
+{
+	switch (obj_type) {
+	case FSNOTIFY_OBJ_TYPE_INODE:
+		return ((struct inode *)obj)->i_sb;
+	case FSNOTIFY_OBJ_TYPE_VFSMOUNT:
+		return ((struct vfsmount *)obj)->mnt_sb;
+	case FSNOTIFY_OBJ_TYPE_SB:
+		return (struct super_block *)obj;
+	default:
+		return NULL;
+	}
+}
+
 static inline struct super_block *fsnotify_connector_sb(
 				struct fsnotify_mark_connector *conn)
 {
diff --git a/fs/notify/mark.c b/fs/notify/mark.c
index 8339d77b1aa2..95bcd818ae96 100644
--- a/fs/notify/mark.c
+++ b/fs/notify/mark.c
@@ -97,6 +97,20 @@  void fsnotify_get_mark(struct fsnotify_mark *mark)
 	refcount_inc(&mark->refcnt);
 }
 
+static fsnotify_connp_t *fsnotify_object_connp(void *obj, int obj_type)
+{
+	switch (obj_type) {
+	case FSNOTIFY_OBJ_TYPE_INODE:
+		return &((struct inode *)obj)->i_fsnotify_marks;
+	case FSNOTIFY_OBJ_TYPE_VFSMOUNT:
+		return &real_mount(obj)->mnt_fsnotify_marks;
+	case FSNOTIFY_OBJ_TYPE_SB:
+		return &((struct super_block *)obj)->s_fsnotify_marks;
+	default:
+		return NULL;
+	}
+}
+
 static __u32 *fsnotify_conn_mask_p(struct fsnotify_mark_connector *conn)
 {
 	if (conn->type == FSNOTIFY_OBJ_TYPE_INODE)