From: Matthew Bobrowski <repnop@google.com>
To: Amir Goldstein <amir73il@gmail.com>
Cc: Jan Kara <jack@suse.cz>,
Christian Brauner <christian.brauner@ubuntu.com>,
linux-fsdevel <linux-fsdevel@vger.kernel.org>,
Linux API <linux-api@vger.kernel.org>
Subject: Re: [PATCH v3 4/5] fanotify/fanotify_user.c: introduce a generic info record copying helper
Date: Tue, 27 Jul 2021 22:57:37 +1000 [thread overview]
Message-ID: <YQACwX4i1UjWqtfZ@google.com> (raw)
In-Reply-To: <CAOQ4uxhnCk+FXK_e_GA=jC_0HWO+3ZdwHSi=zCa2Kpb0NDxBSg@mail.gmail.com>
On Tue, Jul 27, 2021 at 11:16:33AM +0300, Amir Goldstein wrote:
> On Wed, Jul 21, 2021 at 9:35 AM Amir Goldstein <amir73il@gmail.com> wrote:
> >
> > On Wed, Jul 21, 2021 at 9:18 AM Matthew Bobrowski <repnop@google.com> wrote:
> > >
> > > The copy_info_records_to_user() helper allows for the separation of
> > > info record copying routines/conditionals from copy_event_to_user(),
> > > which reduces the overall clutter within this function. This becomes
> > > especially true as we start introducing additional info records in the
> > > future i.e. struct fanotify_event_info_pidfd. On success, this helper
> > > returns the total amount of bytes that have been copied into the user
> > > supplied buffer and on error, a negative value is returned to the
> > > caller.
> > >
> > > The newly defined macro FANOTIFY_INFO_MODES can be used to obtain info
> > > record types that have been enabled for a specific notification
> > > group. This macro becomes useful in the subsequent patch when the
> > > FAN_REPORT_PIDFD initialization flag is introduced.
> > >
> > > Signed-off-by: Matthew Bobrowski <repnop@google.com>
> > Reviewed-by: Amir Goldstein <amir73il@gmail.com>
> >
> > > ---
> > > fs/notify/fanotify/fanotify_user.c | 155 ++++++++++++++++-------------
> > > include/linux/fanotify.h | 2 +
> > > 2 files changed, 90 insertions(+), 67 deletions(-)
> > >
> > > diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
> > > index 182fea255376..d19f70b2c24c 100644
> > > --- a/fs/notify/fanotify/fanotify_user.c
> > > +++ b/fs/notify/fanotify/fanotify_user.c
> > > @@ -173,7 +173,7 @@ static struct fanotify_event *get_one_event(struct fsnotify_group *group,
> > > size_t event_size = FAN_EVENT_METADATA_LEN;
> > > struct fanotify_event *event = NULL;
> > > struct fsnotify_event *fsn_event;
> > > - unsigned int fid_mode = FAN_GROUP_FLAG(group, FANOTIFY_FID_BITS);
> > > + unsigned int info_mode = FAN_GROUP_FLAG(group, FANOTIFY_INFO_MODES);
> > >
> > > pr_debug("%s: group=%p count=%zd\n", __func__, group, count);
> > >
> > > @@ -183,8 +183,8 @@ static struct fanotify_event *get_one_event(struct fsnotify_group *group,
> > > goto out;
> > >
> > > event = FANOTIFY_E(fsn_event);
> > > - if (fid_mode)
> > > - event_size += fanotify_event_info_len(fid_mode, event);
> > > + if (info_mode)
> > > + event_size += fanotify_event_info_len(info_mode, event);
> > >
> > > if (event_size > count) {
> > > event = ERR_PTR(-EINVAL);
> > > @@ -401,6 +401,86 @@ static int copy_fid_info_to_user(__kernel_fsid_t *fsid, struct fanotify_fh *fh,
> > > return info_len;
> > > }
> > >
> > > +static int copy_info_records_to_user(struct fanotify_event *event,
> > > + struct fanotify_info *info,
> > > + unsigned int info_mode,
> > > + char __user *buf, size_t count)
> > > +{
> > > + int ret, total_bytes = 0, info_type = 0;
> > > + unsigned int fid_mode = info_mode & FANOTIFY_FID_BITS;
> > > +
> > > + /*
> > > + * Event info records order is as follows: dir fid + name, child fid.
> > > + */
> > > + if (fanotify_event_dir_fh_len(event)) {
> > > + info_type = info->name_len ? FAN_EVENT_INFO_TYPE_DFID_NAME :
> > > + FAN_EVENT_INFO_TYPE_DFID;
> > > + ret = copy_fid_info_to_user(fanotify_event_fsid(event),
> > > + fanotify_info_dir_fh(info),
> > > + info_type,
> > > + fanotify_info_name(info),
> > > + info->name_len, buf, count);
> > > + if (ret < 0)
> > > + return ret;
> > > +
> > > + buf += ret;
> > > + count -= ret;
> > > + total_bytes += ret;
> > > + }
> > > +
> > > + if (fanotify_event_object_fh_len(event)) {
> > > + const char *dot = NULL;
> > > + int dot_len = 0;
> > > +
> > > + if (fid_mode == FAN_REPORT_FID || info_type) {
> > > + /*
> > > + * With only group flag FAN_REPORT_FID only type FID is
> > > + * reported. Second info record type is always FID.
> > > + */
> > > + info_type = FAN_EVENT_INFO_TYPE_FID;
> > > + } else if ((fid_mode & FAN_REPORT_NAME) &&
> > > + (event->mask & FAN_ONDIR)) {
> > > + /*
> > > + * With group flag FAN_REPORT_NAME, if name was not
> > > + * recorded in an event on a directory, report the name
> > > + * "." with info type DFID_NAME.
> > > + */
> > > + info_type = FAN_EVENT_INFO_TYPE_DFID_NAME;
> > > + dot = ".";
> > > + dot_len = 1;
> > > + } else if ((event->mask & ALL_FSNOTIFY_DIRENT_EVENTS) ||
> > > + (event->mask & FAN_ONDIR)) {
> > > + /*
> > > + * With group flag FAN_REPORT_DIR_FID, a single info
> > > + * record has type DFID for directory entry
> > > + * modificatio\ n event and for event on a directory.
>
> Just notices this typo in the copied comment:
> modificatio\ n
>
> And for the next posting, please remove the mention of fanotify_user.c from
> the commit title - it adds no information and clutters the git oneline log.
> This concerns patch 3/5 as well. It does NOT concern the kernel/pid.c patches.
Noted.
/M
next prev parent reply other threads:[~2021-07-27 12:57 UTC|newest]
Thread overview: 41+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-07-21 6:17 [PATCH v3 0/5] Add pidfd support to the fanotify API Matthew Bobrowski
2021-07-21 6:17 ` [PATCH v3 1/5] kernel/pid.c: remove static qualifier from pidfd_create() Matthew Bobrowski
2021-07-21 6:17 ` [PATCH v3 2/5] kernel/pid.c: implement additional checks upon pidfd_create() parameters Matthew Bobrowski
2021-07-21 6:18 ` [PATCH v3 3/5] fanotify/fanotify_user.c: minor cosmetic adjustments to fid labels Matthew Bobrowski
2021-07-21 6:34 ` Amir Goldstein
2021-07-21 6:18 ` [PATCH v3 4/5] fanotify/fanotify_user.c: introduce a generic info record copying helper Matthew Bobrowski
2021-07-21 6:35 ` Amir Goldstein
2021-07-27 8:16 ` Amir Goldstein
2021-07-27 12:57 ` Matthew Bobrowski [this message]
2021-07-21 6:19 ` [PATCH v3 5/5] fanotify: add pidfd support to the fanotify API Matthew Bobrowski
2021-07-21 7:05 ` Amir Goldstein
2021-07-26 23:04 ` Matthew Bobrowski
2021-07-27 0:23 ` Jann Horn
2021-07-27 4:19 ` Amir Goldstein
2021-07-27 5:10 ` Matthew Bobrowski
2021-07-27 7:03 ` Amir Goldstein
2021-07-27 8:22 ` Christian Brauner
2021-07-27 8:29 ` Christian Brauner
2021-07-29 13:39 ` Jan Kara
2021-07-29 15:13 ` Amir Goldstein
2021-07-30 5:03 ` Amir Goldstein
2021-08-02 12:34 ` Jan Kara
2021-08-02 14:38 ` Amir Goldstein
2021-08-02 20:10 ` Jan Kara
2021-08-03 1:29 ` Matthew Bobrowski
2021-08-03 5:51 ` Amir Goldstein
2021-08-03 9:46 ` Christian Brauner
2021-08-03 9:37 ` Christian Brauner
2021-08-03 10:07 ` Amir Goldstein
2021-08-03 14:04 ` Jan Kara
2021-08-04 3:46 ` Matthew Bobrowski
2021-08-04 12:39 ` Jan Kara
2021-08-05 5:51 ` Matthew Bobrowski
2021-08-05 8:55 ` Jan Kara
2021-08-03 13:39 ` Jan Kara
2021-07-27 12:54 ` Matthew Bobrowski
2021-07-29 22:48 ` Matthew Bobrowski
2021-07-21 7:06 ` [PATCH v3 0/5] Add " Amir Goldstein
2021-07-26 23:07 ` Matthew Bobrowski
2021-07-27 0:16 ` Matthew Bobrowski
2021-07-29 13:40 ` Jan Kara
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=YQACwX4i1UjWqtfZ@google.com \
--to=repnop@google.com \
--cc=amir73il@gmail.com \
--cc=christian.brauner@ubuntu.com \
--cc=jack@suse.cz \
--cc=linux-api@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
/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.