Skip to content

Commit 1c9007d

Browse files
amir73iljankara
authored andcommitted
fsnotify: separate mark iterator type from object type enum
They are two different types that use the same enum, so this confusing. Use the object type to indicate the type of object mark is attached to and the iter type to indicate the type of watch. A group can have two different watches of the same object type (parent and child watches) that match the same event. Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Amir Goldstein <[email protected]> Signed-off-by: Jan Kara <[email protected]>
1 parent ad69cd9 commit 1c9007d

File tree

4 files changed

+42
-27
lines changed

4 files changed

+42
-27
lines changed

fs/notify/fanotify/fanotify.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ static u32 fanotify_group_event_mask(struct fsnotify_group *group,
299299
return 0;
300300
}
301301

302-
fsnotify_foreach_obj_type(type) {
302+
fsnotify_foreach_iter_type(type) {
303303
if (!fsnotify_iter_should_report_type(iter_info, type))
304304
continue;
305305
mark = iter_info->marks[type];
@@ -318,7 +318,7 @@ static u32 fanotify_group_event_mask(struct fsnotify_group *group,
318318
* If the event is on a child and this mark is on a parent not
319319
* watching children, don't send it!
320320
*/
321-
if (type == FSNOTIFY_OBJ_TYPE_PARENT &&
321+
if (type == FSNOTIFY_ITER_TYPE_PARENT &&
322322
!(mark->mask & FS_EVENT_ON_CHILD))
323323
continue;
324324

@@ -746,7 +746,7 @@ static __kernel_fsid_t fanotify_get_fsid(struct fsnotify_iter_info *iter_info)
746746
int type;
747747
__kernel_fsid_t fsid = {};
748748

749-
fsnotify_foreach_obj_type(type) {
749+
fsnotify_foreach_iter_type(type) {
750750
struct fsnotify_mark_connector *conn;
751751

752752
if (!fsnotify_iter_should_report_type(iter_info, type))

fs/notify/fsnotify.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ static int send_to_group(__u32 mask, const void *data, int data_type,
330330

331331
/* clear ignored on inode modification */
332332
if (mask & FS_MODIFY) {
333-
fsnotify_foreach_obj_type(type) {
333+
fsnotify_foreach_iter_type(type) {
334334
if (!fsnotify_iter_should_report_type(iter_info, type))
335335
continue;
336336
mark = iter_info->marks[type];
@@ -340,7 +340,7 @@ static int send_to_group(__u32 mask, const void *data, int data_type,
340340
}
341341
}
342342

343-
fsnotify_foreach_obj_type(type) {
343+
fsnotify_foreach_iter_type(type) {
344344
if (!fsnotify_iter_should_report_type(iter_info, type))
345345
continue;
346346
mark = iter_info->marks[type];
@@ -405,7 +405,7 @@ static unsigned int fsnotify_iter_select_report_types(
405405
int type;
406406

407407
/* Choose max prio group among groups of all queue heads */
408-
fsnotify_foreach_obj_type(type) {
408+
fsnotify_foreach_iter_type(type) {
409409
mark = iter_info->marks[type];
410410
if (mark &&
411411
fsnotify_compare_groups(max_prio_group, mark->group) > 0)
@@ -417,7 +417,7 @@ static unsigned int fsnotify_iter_select_report_types(
417417

418418
/* Set the report mask for marks from same group as max prio group */
419419
iter_info->report_mask = 0;
420-
fsnotify_foreach_obj_type(type) {
420+
fsnotify_foreach_iter_type(type) {
421421
mark = iter_info->marks[type];
422422
if (mark &&
423423
fsnotify_compare_groups(max_prio_group, mark->group) == 0)
@@ -435,7 +435,7 @@ static void fsnotify_iter_next(struct fsnotify_iter_info *iter_info)
435435
{
436436
int type;
437437

438-
fsnotify_foreach_obj_type(type) {
438+
fsnotify_foreach_iter_type(type) {
439439
if (fsnotify_iter_should_report_type(iter_info, type))
440440
iter_info->marks[type] =
441441
fsnotify_next_mark(iter_info->marks[type]);
@@ -519,18 +519,18 @@ int fsnotify(__u32 mask, const void *data, int data_type, struct inode *dir,
519519

520520
iter_info.srcu_idx = srcu_read_lock(&fsnotify_mark_srcu);
521521

522-
iter_info.marks[FSNOTIFY_OBJ_TYPE_SB] =
522+
iter_info.marks[FSNOTIFY_ITER_TYPE_SB] =
523523
fsnotify_first_mark(&sb->s_fsnotify_marks);
524524
if (mnt) {
525-
iter_info.marks[FSNOTIFY_OBJ_TYPE_VFSMOUNT] =
525+
iter_info.marks[FSNOTIFY_ITER_TYPE_VFSMOUNT] =
526526
fsnotify_first_mark(&mnt->mnt_fsnotify_marks);
527527
}
528528
if (inode) {
529-
iter_info.marks[FSNOTIFY_OBJ_TYPE_INODE] =
529+
iter_info.marks[FSNOTIFY_ITER_TYPE_INODE] =
530530
fsnotify_first_mark(&inode->i_fsnotify_marks);
531531
}
532532
if (parent) {
533-
iter_info.marks[FSNOTIFY_OBJ_TYPE_PARENT] =
533+
iter_info.marks[FSNOTIFY_ITER_TYPE_PARENT] =
534534
fsnotify_first_mark(&parent->i_fsnotify_marks);
535535
}
536536

fs/notify/mark.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ bool fsnotify_prepare_user_wait(struct fsnotify_iter_info *iter_info)
353353
{
354354
int type;
355355

356-
fsnotify_foreach_obj_type(type) {
356+
fsnotify_foreach_iter_type(type) {
357357
/* This can fail if mark is being removed */
358358
if (!fsnotify_get_mark_safe(iter_info->marks[type])) {
359359
__release(&fsnotify_mark_srcu);
@@ -382,7 +382,7 @@ void fsnotify_finish_user_wait(struct fsnotify_iter_info *iter_info)
382382
int type;
383383

384384
iter_info->srcu_idx = srcu_read_lock(&fsnotify_mark_srcu);
385-
fsnotify_foreach_obj_type(type)
385+
fsnotify_foreach_iter_type(type)
386386
fsnotify_put_mark_wake(iter_info->marks[type]);
387387
}
388388

include/linux/fsnotify_backend.h

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -337,10 +337,25 @@ static inline struct fs_error_report *fsnotify_data_error_report(
337337
}
338338
}
339339

340+
/*
341+
* Index to merged marks iterator array that correlates to a type of watch.
342+
* The type of watched object can be deduced from the iterator type, but not
343+
* the other way around, because an event can match different watched objects
344+
* of the same object type.
345+
* For example, both parent and child are watching an object of type inode.
346+
*/
347+
enum fsnotify_iter_type {
348+
FSNOTIFY_ITER_TYPE_INODE,
349+
FSNOTIFY_ITER_TYPE_VFSMOUNT,
350+
FSNOTIFY_ITER_TYPE_SB,
351+
FSNOTIFY_ITER_TYPE_PARENT,
352+
FSNOTIFY_ITER_TYPE_COUNT
353+
};
354+
355+
/* The type of object that a mark is attached to */
340356
enum fsnotify_obj_type {
341357
FSNOTIFY_OBJ_TYPE_ANY = -1,
342358
FSNOTIFY_OBJ_TYPE_INODE,
343-
FSNOTIFY_OBJ_TYPE_PARENT,
344359
FSNOTIFY_OBJ_TYPE_VFSMOUNT,
345360
FSNOTIFY_OBJ_TYPE_SB,
346361
FSNOTIFY_OBJ_TYPE_COUNT,
@@ -353,46 +368,46 @@ static inline bool fsnotify_valid_obj_type(unsigned int obj_type)
353368
}
354369

355370
struct fsnotify_iter_info {
356-
struct fsnotify_mark *marks[FSNOTIFY_OBJ_TYPE_COUNT];
371+
struct fsnotify_mark *marks[FSNOTIFY_ITER_TYPE_COUNT];
357372
unsigned int report_mask;
358373
int srcu_idx;
359374
};
360375

361376
static inline bool fsnotify_iter_should_report_type(
362-
struct fsnotify_iter_info *iter_info, int type)
377+
struct fsnotify_iter_info *iter_info, int iter_type)
363378
{
364-
return (iter_info->report_mask & (1U << type));
379+
return (iter_info->report_mask & (1U << iter_type));
365380
}
366381

367382
static inline void fsnotify_iter_set_report_type(
368-
struct fsnotify_iter_info *iter_info, int type)
383+
struct fsnotify_iter_info *iter_info, int iter_type)
369384
{
370-
iter_info->report_mask |= (1U << type);
385+
iter_info->report_mask |= (1U << iter_type);
371386
}
372387

373388
static inline void fsnotify_iter_set_report_type_mark(
374-
struct fsnotify_iter_info *iter_info, int type,
389+
struct fsnotify_iter_info *iter_info, int iter_type,
375390
struct fsnotify_mark *mark)
376391
{
377-
iter_info->marks[type] = mark;
378-
iter_info->report_mask |= (1U << type);
392+
iter_info->marks[iter_type] = mark;
393+
iter_info->report_mask |= (1U << iter_type);
379394
}
380395

381396
#define FSNOTIFY_ITER_FUNCS(name, NAME) \
382397
static inline struct fsnotify_mark *fsnotify_iter_##name##_mark( \
383398
struct fsnotify_iter_info *iter_info) \
384399
{ \
385-
return (iter_info->report_mask & (1U << FSNOTIFY_OBJ_TYPE_##NAME)) ? \
386-
iter_info->marks[FSNOTIFY_OBJ_TYPE_##NAME] : NULL; \
400+
return (iter_info->report_mask & (1U << FSNOTIFY_ITER_TYPE_##NAME)) ? \
401+
iter_info->marks[FSNOTIFY_ITER_TYPE_##NAME] : NULL; \
387402
}
388403

389404
FSNOTIFY_ITER_FUNCS(inode, INODE)
390405
FSNOTIFY_ITER_FUNCS(parent, PARENT)
391406
FSNOTIFY_ITER_FUNCS(vfsmount, VFSMOUNT)
392407
FSNOTIFY_ITER_FUNCS(sb, SB)
393408

394-
#define fsnotify_foreach_obj_type(type) \
395-
for (type = 0; type < FSNOTIFY_OBJ_TYPE_COUNT; type++)
409+
#define fsnotify_foreach_iter_type(type) \
410+
for (type = 0; type < FSNOTIFY_ITER_TYPE_COUNT; type++)
396411

397412
/*
398413
* fsnotify_connp_t is what we embed in objects which connector can be attached

0 commit comments

Comments
 (0)