Skip to content

Commit 4bd5a5c

Browse files
krisman-at-collaborajankara
authored andcommitted
fanotify: Add helpers to decide whether to report FID/DFID
Now that there is an event that reports FID records even for a zeroed file handle, wrap the logic that deides whether to issue the records into helper functions. This shouldn't have any impact on the code, but simplifies further patches. Link: https://lore.kernel.org/r/[email protected] Reviewed-by: Jan Kara <[email protected]> Signed-off-by: Gabriel Krisman Bertazi <[email protected]> Reviewed-by: Amir Goldstein <[email protected]> Signed-off-by: Jan Kara <[email protected]>
1 parent 2c50694 commit 4bd5a5c

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

fs/notify/fanotify/fanotify.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,16 @@ static inline int fanotify_event_dir_fh_len(struct fanotify_event *event)
264264
return info ? fanotify_info_dir_fh_len(info) : 0;
265265
}
266266

267+
static inline bool fanotify_event_has_object_fh(struct fanotify_event *event)
268+
{
269+
return fanotify_event_object_fh_len(event) > 0;
270+
}
271+
272+
static inline bool fanotify_event_has_dir_fh(struct fanotify_event *event)
273+
{
274+
return fanotify_event_dir_fh_len(event) > 0;
275+
}
276+
267277
struct fanotify_path_event {
268278
struct fanotify_event fae;
269279
struct path path;

fs/notify/fanotify/fanotify_user.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,9 @@ static size_t fanotify_event_len(unsigned int info_mode,
140140
return event_len;
141141

142142
info = fanotify_event_info(event);
143-
dir_fh_len = fanotify_event_dir_fh_len(event);
144-
fh_len = fanotify_event_object_fh_len(event);
145143

146-
if (dir_fh_len) {
144+
if (fanotify_event_has_dir_fh(event)) {
145+
dir_fh_len = fanotify_event_dir_fh_len(event);
147146
event_len += fanotify_fid_info_len(dir_fh_len, info->name_len);
148147
} else if ((info_mode & FAN_REPORT_NAME) &&
149148
(event->mask & FAN_ONDIR)) {
@@ -157,8 +156,10 @@ static size_t fanotify_event_len(unsigned int info_mode,
157156
if (info_mode & FAN_REPORT_PIDFD)
158157
event_len += FANOTIFY_PIDFD_INFO_HDR_LEN;
159158

160-
if (fh_len)
159+
if (fanotify_event_has_object_fh(event)) {
160+
fh_len = fanotify_event_object_fh_len(event);
161161
event_len += fanotify_fid_info_len(fh_len, dot_len);
162+
}
162163

163164
return event_len;
164165
}
@@ -451,7 +452,7 @@ static int copy_info_records_to_user(struct fanotify_event *event,
451452
/*
452453
* Event info records order is as follows: dir fid + name, child fid.
453454
*/
454-
if (fanotify_event_dir_fh_len(event)) {
455+
if (fanotify_event_has_dir_fh(event)) {
455456
info_type = info->name_len ? FAN_EVENT_INFO_TYPE_DFID_NAME :
456457
FAN_EVENT_INFO_TYPE_DFID;
457458
ret = copy_fid_info_to_user(fanotify_event_fsid(event),
@@ -467,7 +468,7 @@ static int copy_info_records_to_user(struct fanotify_event *event,
467468
total_bytes += ret;
468469
}
469470

470-
if (fanotify_event_object_fh_len(event)) {
471+
if (fanotify_event_has_object_fh(event)) {
471472
const char *dot = NULL;
472473
int dot_len = 0;
473474

0 commit comments

Comments
 (0)