Skip to content

Commit d809daf

Browse files
amir73iljankara
authored andcommitted
fanotify: generalize test for FAN_REPORT_FID
As preparation for new flags that report fids, define a bit set of flags for a group reporting fids, currently containing the only bit FAN_REPORT_FID. Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Amir Goldstein <[email protected]> Signed-off-by: Jan Kara <[email protected]>
1 parent 6ad1aad commit d809daf

File tree

3 files changed

+16
-12
lines changed

3 files changed

+16
-12
lines changed

fs/notify/fanotify/fanotify.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -207,13 +207,14 @@ static u32 fanotify_group_event_mask(struct fsnotify_group *group,
207207
__u32 test_mask, user_mask = FANOTIFY_OUTGOING_EVENTS |
208208
FANOTIFY_EVENT_FLAGS;
209209
const struct path *path = fsnotify_data_path(data, data_type);
210+
unsigned int fid_mode = FAN_GROUP_FLAG(group, FANOTIFY_FID_BITS);
210211
struct fsnotify_mark *mark;
211212
int type;
212213

213214
pr_debug("%s: report_mask=%x mask=%x data=%p data_type=%d\n",
214215
__func__, iter_info->report_mask, event_mask, data, data_type);
215216

216-
if (!FAN_GROUP_FLAG(group, FAN_REPORT_FID)) {
217+
if (!fid_mode) {
217218
/* Do we have path to open a file descriptor? */
218219
if (!path)
219220
return 0;
@@ -264,7 +265,7 @@ static u32 fanotify_group_event_mask(struct fsnotify_group *group,
264265
* fanotify_alloc_event() when group is reporting fid as indication
265266
* that event happened on child.
266267
*/
267-
if (FAN_GROUP_FLAG(group, FAN_REPORT_FID)) {
268+
if (fid_mode) {
268269
/* Do not report event flags without any event */
269270
if (!(test_mask & ~FANOTIFY_EVENT_FLAGS))
270271
return 0;
@@ -424,6 +425,7 @@ static struct fanotify_event *fanotify_alloc_event(struct fsnotify_group *group,
424425
gfp_t gfp = GFP_KERNEL_ACCOUNT;
425426
struct inode *id = fanotify_fid_inode(mask, data, data_type, dir);
426427
const struct path *path = fsnotify_data_path(data, data_type);
428+
unsigned int fid_mode = FAN_GROUP_FLAG(group, FANOTIFY_FID_BITS);
427429
bool name_event = false;
428430

429431
/*
@@ -444,7 +446,7 @@ static struct fanotify_event *fanotify_alloc_event(struct fsnotify_group *group,
444446
event = fanotify_alloc_perm_event(path, gfp);
445447
} else if (name_event && file_name) {
446448
event = fanotify_alloc_name_event(id, fsid, file_name, gfp);
447-
} else if (FAN_GROUP_FLAG(group, FAN_REPORT_FID)) {
449+
} else if (fid_mode) {
448450
event = fanotify_alloc_fid_event(id, fsid, gfp);
449451
} else {
450452
event = fanotify_alloc_path_event(path, gfp);
@@ -551,7 +553,7 @@ static int fanotify_handle_event(struct fsnotify_group *group, u32 mask,
551553
return 0;
552554
}
553555

554-
if (FAN_GROUP_FLAG(group, FAN_REPORT_FID)) {
556+
if (FAN_GROUP_FLAG(group, FANOTIFY_FID_BITS)) {
555557
fsid = fanotify_get_fsid(iter_info);
556558
/* Racing with mark destruction or creation? */
557559
if (!fsid.val[0] && !fsid.val[1])

fs/notify/fanotify/fanotify_user.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ static struct fanotify_event *get_one_event(struct fsnotify_group *group,
100100
if (fsnotify_notify_queue_is_empty(group))
101101
goto out;
102102

103-
if (FAN_GROUP_FLAG(group, FAN_REPORT_FID)) {
103+
if (FAN_GROUP_FLAG(group, FANOTIFY_FID_BITS)) {
104104
event_size += fanotify_event_info_len(
105105
FANOTIFY_E(fsnotify_peek_first_event(group)));
106106
}
@@ -882,7 +882,7 @@ SYSCALL_DEFINE2(fanotify_init, unsigned int, flags, unsigned int, event_f_flags)
882882
return -EINVAL;
883883
}
884884

885-
if ((flags & FAN_REPORT_FID) &&
885+
if ((flags & FANOTIFY_FID_BITS) &&
886886
(flags & FANOTIFY_CLASS_BITS) != FAN_CLASS_NOTIF)
887887
return -EINVAL;
888888

@@ -1040,7 +1040,7 @@ static int do_fanotify_mark(int fanotify_fd, unsigned int flags, __u64 mask,
10401040
__kernel_fsid_t __fsid, *fsid = NULL;
10411041
u32 valid_mask = FANOTIFY_EVENTS | FANOTIFY_EVENT_FLAGS;
10421042
unsigned int mark_type = flags & FANOTIFY_MARK_TYPE_BITS;
1043-
unsigned int obj_type;
1043+
unsigned int obj_type, fid_mode;
10441044
int ret;
10451045

10461046
pr_debug("%s: fanotify_fd=%d flags=%x dfd=%d pathname=%p mask=%llx\n",
@@ -1113,9 +1113,9 @@ static int do_fanotify_mark(int fanotify_fd, unsigned int flags, __u64 mask,
11131113
* inode events are not supported on a mount mark, because they do not
11141114
* carry enough information (i.e. path) to be filtered by mount point.
11151115
*/
1116+
fid_mode = FAN_GROUP_FLAG(group, FANOTIFY_FID_BITS);
11161117
if (mask & FANOTIFY_INODE_EVENTS &&
1117-
(!FAN_GROUP_FLAG(group, FAN_REPORT_FID) ||
1118-
mark_type == FAN_MARK_MOUNT))
1118+
(!fid_mode || mark_type == FAN_MARK_MOUNT))
11191119
goto fput_and_out;
11201120

11211121
if (flags & FAN_MARK_FLUSH) {
@@ -1140,7 +1140,7 @@ static int do_fanotify_mark(int fanotify_fd, unsigned int flags, __u64 mask,
11401140
goto path_put_and_out;
11411141
}
11421142

1143-
if (FAN_GROUP_FLAG(group, FAN_REPORT_FID)) {
1143+
if (fid_mode) {
11441144
ret = fanotify_test_fid(&path, &__fsid);
11451145
if (ret)
11461146
goto path_put_and_out;

include/linux/fanotify.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@
1818
#define FANOTIFY_CLASS_BITS (FAN_CLASS_NOTIF | FAN_CLASS_CONTENT | \
1919
FAN_CLASS_PRE_CONTENT)
2020

21-
#define FANOTIFY_INIT_FLAGS (FANOTIFY_CLASS_BITS | \
22-
FAN_REPORT_TID | FAN_REPORT_FID | \
21+
#define FANOTIFY_FID_BITS (FAN_REPORT_FID)
22+
23+
#define FANOTIFY_INIT_FLAGS (FANOTIFY_CLASS_BITS | FANOTIFY_FID_BITS | \
24+
FAN_REPORT_TID | \
2325
FAN_CLOEXEC | FAN_NONBLOCK | \
2426
FAN_UNLIMITED_QUEUE | FAN_UNLIMITED_MARKS)
2527

0 commit comments

Comments
 (0)