Message ID | 20211019000015.1666608-24-krisman@collabora.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | file system-wide error monitoring | expand |
On Tue, Oct 19, 2021 at 3:03 AM Gabriel Krisman Bertazi <krisman@collabora.com> wrote: > > fanotify_error_event would duplicate this sequence of declarations that > already exist elsewhere with a slight different size. Create a helper > macro to avoid code duplication. > > Suggested-by: Jan Kara <jack@suse.cz> > Signed-off-by: Gabriel Krisman Bertazi <krisman@collabora.com> > Reviewed-by: Amir Goldstein <amir73il@gmail.com> with minor nit > --- > Among the suggestions, I think this is simpler because it avoids > deep nesting the variable-sized attribute, which would have been hidden > inside fee->ffe->object_fh.buf. > > It also avoids touching the allocators, which are nicely hidden inside > helper KMEM_CACHE() macros that hides several parameters. I like this option best as well. > --- > fs/notify/fanotify/fanotify.h | 13 ++++++++++--- > 1 file changed, 10 insertions(+), 3 deletions(-) > > diff --git a/fs/notify/fanotify/fanotify.h b/fs/notify/fanotify/fanotify.h > index 2b032b79d5b0..a5e81d759f65 100644 > --- a/fs/notify/fanotify/fanotify.h > +++ b/fs/notify/fanotify/fanotify.h > @@ -171,12 +171,19 @@ static inline void fanotify_init_event(struct fanotify_event *event, > event->pid = NULL; > } > > +#define FANOTIFY_INLINE_FH(size) \ > +struct { \ > + struct fanotify_fh object_fh; \ > + /* Space for object_fh.buf[] - access with fanotify_fh_buf() */ \ > + unsigned char _inline_fh_buf[(size)]; \ > +} > + > struct fanotify_fid_event { > struct fanotify_event fae; > __kernel_fsid_t fsid; > - struct fanotify_fh object_fh; > - /* Reserve space in object_fh.buf[] - access with fanotify_fh_buf() */ > - unsigned char _inline_fh_buf[FANOTIFY_INLINE_FH_LEN]; > + > + /* This must be the last element of the structure. */ > + FANOTIFY_INLINE_FH(FANOTIFY_INLINE_FH_LEN); > }; It's not true that is must be the last element. this is only true for struct fanotify_fh with zero size buf[]. Thanks, Amir.
On Mon 18-10-21 21:00:06, Gabriel Krisman Bertazi wrote: > fanotify_error_event would duplicate this sequence of declarations that > already exist elsewhere with a slight different size. Create a helper > macro to avoid code duplication. > > Suggested-by: Jan Kara <jack@suse.cz> > Signed-off-by: Gabriel Krisman Bertazi <krisman@collabora.com> > > --- > Among the suggestions, I think this is simpler because it avoids > deep nesting the variable-sized attribute, which would have been hidden > inside fee->ffe->object_fh.buf. One nit from me as well :) > +#define FANOTIFY_INLINE_FH(size) \ > +struct { \ > + struct fanotify_fh object_fh; \ > + /* Space for object_fh.buf[] - access with fanotify_fh_buf() */ \ > + unsigned char _inline_fh_buf[(size)]; \ > +} > + Can the macro perhaps take the name of the fanotify_fh member it creates? Like: #define FANOTIFY_INLINE_FH(name, size) Harcoding _inline_fh_buf is fine since it isn't ever used directly but hardcoding object_fh looks ugly to me. With that improved feel free to add: Reviewed-by: Jan Kara <jack@suse.cz> Honza
diff --git a/fs/notify/fanotify/fanotify.h b/fs/notify/fanotify/fanotify.h index 2b032b79d5b0..a5e81d759f65 100644 --- a/fs/notify/fanotify/fanotify.h +++ b/fs/notify/fanotify/fanotify.h @@ -171,12 +171,19 @@ static inline void fanotify_init_event(struct fanotify_event *event, event->pid = NULL; } +#define FANOTIFY_INLINE_FH(size) \ +struct { \ + struct fanotify_fh object_fh; \ + /* Space for object_fh.buf[] - access with fanotify_fh_buf() */ \ + unsigned char _inline_fh_buf[(size)]; \ +} + struct fanotify_fid_event { struct fanotify_event fae; __kernel_fsid_t fsid; - struct fanotify_fh object_fh; - /* Reserve space in object_fh.buf[] - access with fanotify_fh_buf() */ - unsigned char _inline_fh_buf[FANOTIFY_INLINE_FH_LEN]; + + /* This must be the last element of the structure. */ + FANOTIFY_INLINE_FH(FANOTIFY_INLINE_FH_LEN); }; static inline struct fanotify_fid_event *
fanotify_error_event would duplicate this sequence of declarations that already exist elsewhere with a slight different size. Create a helper macro to avoid code duplication. Suggested-by: Jan Kara <jack@suse.cz> Signed-off-by: Gabriel Krisman Bertazi <krisman@collabora.com> --- Among the suggestions, I think this is simpler because it avoids deep nesting the variable-sized attribute, which would have been hidden inside fee->ffe->object_fh.buf. It also avoids touching the allocators, which are nicely hidden inside helper KMEM_CACHE() macros that hides several parameters. --- fs/notify/fanotify/fanotify.h | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-)