Skip to content

Commit ad69cd9

Browse files
amir73iljankara
authored andcommitted
fsnotify: clarify object type argument
In preparation for separating object type from iterator type, rename some 'type' arguments in functions to 'obj_type' and remove the unused interface to clear marks by object type mask. Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Amir Goldstein <[email protected]> Signed-off-by: Jan Kara <[email protected]>
1 parent 5472f14 commit ad69cd9

File tree

4 files changed

+32
-33
lines changed

4 files changed

+32
-33
lines changed

fs/notify/fanotify/fanotify_user.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1057,7 +1057,7 @@ static __u32 fanotify_mark_add_to_mask(struct fsnotify_mark *fsn_mark,
10571057

10581058
static struct fsnotify_mark *fanotify_add_new_mark(struct fsnotify_group *group,
10591059
fsnotify_connp_t *connp,
1060-
unsigned int type,
1060+
unsigned int obj_type,
10611061
__kernel_fsid_t *fsid)
10621062
{
10631063
struct ucounts *ucounts = group->fanotify_data.ucounts;
@@ -1080,7 +1080,7 @@ static struct fsnotify_mark *fanotify_add_new_mark(struct fsnotify_group *group,
10801080
}
10811081

10821082
fsnotify_init_mark(mark, group);
1083-
ret = fsnotify_add_mark_locked(mark, connp, type, 0, fsid);
1083+
ret = fsnotify_add_mark_locked(mark, connp, obj_type, 0, fsid);
10841084
if (ret) {
10851085
fsnotify_put_mark(mark);
10861086
goto out_dec_ucounts;
@@ -1105,7 +1105,7 @@ static int fanotify_group_init_error_pool(struct fsnotify_group *group)
11051105
}
11061106

11071107
static int fanotify_add_mark(struct fsnotify_group *group,
1108-
fsnotify_connp_t *connp, unsigned int type,
1108+
fsnotify_connp_t *connp, unsigned int obj_type,
11091109
__u32 mask, unsigned int flags,
11101110
__kernel_fsid_t *fsid)
11111111
{
@@ -1116,7 +1116,7 @@ static int fanotify_add_mark(struct fsnotify_group *group,
11161116
mutex_lock(&group->mark_mutex);
11171117
fsn_mark = fsnotify_find_mark(connp, group);
11181118
if (!fsn_mark) {
1119-
fsn_mark = fanotify_add_new_mark(group, connp, type, fsid);
1119+
fsn_mark = fanotify_add_new_mark(group, connp, obj_type, fsid);
11201120
if (IS_ERR(fsn_mark)) {
11211121
mutex_unlock(&group->mark_mutex);
11221122
return PTR_ERR(fsn_mark);

fs/notify/group.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ void fsnotify_destroy_group(struct fsnotify_group *group)
5858
fsnotify_group_stop_queueing(group);
5959

6060
/* Clear all marks for this group and queue them for destruction */
61-
fsnotify_clear_marks_by_group(group, FSNOTIFY_OBJ_ALL_TYPES_MASK);
61+
fsnotify_clear_marks_by_group(group, FSNOTIFY_OBJ_TYPE_ANY);
6262

6363
/*
6464
* Some marks can still be pinned when waiting for response from

fs/notify/mark.c

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,7 @@ int fsnotify_compare_groups(struct fsnotify_group *a, struct fsnotify_group *b)
496496
}
497497

498498
static int fsnotify_attach_connector_to_object(fsnotify_connp_t *connp,
499-
unsigned int type,
499+
unsigned int obj_type,
500500
__kernel_fsid_t *fsid)
501501
{
502502
struct inode *inode = NULL;
@@ -507,7 +507,7 @@ static int fsnotify_attach_connector_to_object(fsnotify_connp_t *connp,
507507
return -ENOMEM;
508508
spin_lock_init(&conn->lock);
509509
INIT_HLIST_HEAD(&conn->list);
510-
conn->type = type;
510+
conn->type = obj_type;
511511
conn->obj = connp;
512512
/* Cache fsid of filesystem containing the object */
513513
if (fsid) {
@@ -572,15 +572,16 @@ static struct fsnotify_mark_connector *fsnotify_grab_connector(
572572
* priority, highest number first, and then by the group's location in memory.
573573
*/
574574
static int fsnotify_add_mark_list(struct fsnotify_mark *mark,
575-
fsnotify_connp_t *connp, unsigned int type,
575+
fsnotify_connp_t *connp,
576+
unsigned int obj_type,
576577
int allow_dups, __kernel_fsid_t *fsid)
577578
{
578579
struct fsnotify_mark *lmark, *last = NULL;
579580
struct fsnotify_mark_connector *conn;
580581
int cmp;
581582
int err = 0;
582583

583-
if (WARN_ON(!fsnotify_valid_obj_type(type)))
584+
if (WARN_ON(!fsnotify_valid_obj_type(obj_type)))
584585
return -EINVAL;
585586

586587
/* Backend is expected to check for zero fsid (e.g. tmpfs) */
@@ -592,7 +593,8 @@ static int fsnotify_add_mark_list(struct fsnotify_mark *mark,
592593
conn = fsnotify_grab_connector(connp);
593594
if (!conn) {
594595
spin_unlock(&mark->lock);
595-
err = fsnotify_attach_connector_to_object(connp, type, fsid);
596+
err = fsnotify_attach_connector_to_object(connp, obj_type,
597+
fsid);
596598
if (err)
597599
return err;
598600
goto restart;
@@ -665,7 +667,7 @@ static int fsnotify_add_mark_list(struct fsnotify_mark *mark,
665667
* event types should be delivered to which group.
666668
*/
667669
int fsnotify_add_mark_locked(struct fsnotify_mark *mark,
668-
fsnotify_connp_t *connp, unsigned int type,
670+
fsnotify_connp_t *connp, unsigned int obj_type,
669671
int allow_dups, __kernel_fsid_t *fsid)
670672
{
671673
struct fsnotify_group *group = mark->group;
@@ -686,7 +688,7 @@ int fsnotify_add_mark_locked(struct fsnotify_mark *mark,
686688
fsnotify_get_mark(mark); /* for g_list */
687689
spin_unlock(&mark->lock);
688690

689-
ret = fsnotify_add_mark_list(mark, connp, type, allow_dups, fsid);
691+
ret = fsnotify_add_mark_list(mark, connp, obj_type, allow_dups, fsid);
690692
if (ret)
691693
goto err;
692694

@@ -706,13 +708,14 @@ int fsnotify_add_mark_locked(struct fsnotify_mark *mark,
706708
}
707709

708710
int fsnotify_add_mark(struct fsnotify_mark *mark, fsnotify_connp_t *connp,
709-
unsigned int type, int allow_dups, __kernel_fsid_t *fsid)
711+
unsigned int obj_type, int allow_dups,
712+
__kernel_fsid_t *fsid)
710713
{
711714
int ret;
712715
struct fsnotify_group *group = mark->group;
713716

714717
mutex_lock(&group->mark_mutex);
715-
ret = fsnotify_add_mark_locked(mark, connp, type, allow_dups, fsid);
718+
ret = fsnotify_add_mark_locked(mark, connp, obj_type, allow_dups, fsid);
716719
mutex_unlock(&group->mark_mutex);
717720
return ret;
718721
}
@@ -747,14 +750,14 @@ EXPORT_SYMBOL_GPL(fsnotify_find_mark);
747750

748751
/* Clear any marks in a group with given type mask */
749752
void fsnotify_clear_marks_by_group(struct fsnotify_group *group,
750-
unsigned int type_mask)
753+
unsigned int obj_type)
751754
{
752755
struct fsnotify_mark *lmark, *mark;
753756
LIST_HEAD(to_free);
754757
struct list_head *head = &to_free;
755758

756759
/* Skip selection step if we want to clear all marks. */
757-
if (type_mask == FSNOTIFY_OBJ_ALL_TYPES_MASK) {
760+
if (obj_type == FSNOTIFY_OBJ_TYPE_ANY) {
758761
head = &group->marks_list;
759762
goto clear;
760763
}
@@ -769,7 +772,7 @@ void fsnotify_clear_marks_by_group(struct fsnotify_group *group,
769772
*/
770773
mutex_lock_nested(&group->mark_mutex, SINGLE_DEPTH_NESTING);
771774
list_for_each_entry_safe(mark, lmark, &group->marks_list, g_list) {
772-
if ((1U << mark->connector->type) & type_mask)
775+
if (mark->connector->type == obj_type)
773776
list_move(&mark->g_list, &to_free);
774777
}
775778
mutex_unlock(&group->mark_mutex);

include/linux/fsnotify_backend.h

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,7 @@ static inline struct fs_error_report *fsnotify_data_error_report(
338338
}
339339

340340
enum fsnotify_obj_type {
341+
FSNOTIFY_OBJ_TYPE_ANY = -1,
341342
FSNOTIFY_OBJ_TYPE_INODE,
342343
FSNOTIFY_OBJ_TYPE_PARENT,
343344
FSNOTIFY_OBJ_TYPE_VFSMOUNT,
@@ -346,15 +347,9 @@ enum fsnotify_obj_type {
346347
FSNOTIFY_OBJ_TYPE_DETACHED = FSNOTIFY_OBJ_TYPE_COUNT
347348
};
348349

349-
#define FSNOTIFY_OBJ_TYPE_INODE_FL (1U << FSNOTIFY_OBJ_TYPE_INODE)
350-
#define FSNOTIFY_OBJ_TYPE_PARENT_FL (1U << FSNOTIFY_OBJ_TYPE_PARENT)
351-
#define FSNOTIFY_OBJ_TYPE_VFSMOUNT_FL (1U << FSNOTIFY_OBJ_TYPE_VFSMOUNT)
352-
#define FSNOTIFY_OBJ_TYPE_SB_FL (1U << FSNOTIFY_OBJ_TYPE_SB)
353-
#define FSNOTIFY_OBJ_ALL_TYPES_MASK ((1U << FSNOTIFY_OBJ_TYPE_COUNT) - 1)
354-
355-
static inline bool fsnotify_valid_obj_type(unsigned int type)
350+
static inline bool fsnotify_valid_obj_type(unsigned int obj_type)
356351
{
357-
return (type < FSNOTIFY_OBJ_TYPE_COUNT);
352+
return (obj_type < FSNOTIFY_OBJ_TYPE_COUNT);
358353
}
359354

360355
struct fsnotify_iter_info {
@@ -387,7 +382,7 @@ static inline void fsnotify_iter_set_report_type_mark(
387382
static inline struct fsnotify_mark *fsnotify_iter_##name##_mark( \
388383
struct fsnotify_iter_info *iter_info) \
389384
{ \
390-
return (iter_info->report_mask & FSNOTIFY_OBJ_TYPE_##NAME##_FL) ? \
385+
return (iter_info->report_mask & (1U << FSNOTIFY_OBJ_TYPE_##NAME)) ? \
391386
iter_info->marks[FSNOTIFY_OBJ_TYPE_##NAME] : NULL; \
392387
}
393388

@@ -604,11 +599,11 @@ extern int fsnotify_get_conn_fsid(const struct fsnotify_mark_connector *conn,
604599
__kernel_fsid_t *fsid);
605600
/* attach the mark to the object */
606601
extern int fsnotify_add_mark(struct fsnotify_mark *mark,
607-
fsnotify_connp_t *connp, unsigned int type,
602+
fsnotify_connp_t *connp, unsigned int obj_type,
608603
int allow_dups, __kernel_fsid_t *fsid);
609604
extern int fsnotify_add_mark_locked(struct fsnotify_mark *mark,
610605
fsnotify_connp_t *connp,
611-
unsigned int type, int allow_dups,
606+
unsigned int obj_type, int allow_dups,
612607
__kernel_fsid_t *fsid);
613608

614609
/* attach the mark to the inode */
@@ -637,22 +632,23 @@ extern void fsnotify_detach_mark(struct fsnotify_mark *mark);
637632
extern void fsnotify_free_mark(struct fsnotify_mark *mark);
638633
/* Wait until all marks queued for destruction are destroyed */
639634
extern void fsnotify_wait_marks_destroyed(void);
640-
/* run all the marks in a group, and clear all of the marks attached to given object type */
641-
extern void fsnotify_clear_marks_by_group(struct fsnotify_group *group, unsigned int type);
635+
/* Clear all of the marks of a group attached to a given object type */
636+
extern void fsnotify_clear_marks_by_group(struct fsnotify_group *group,
637+
unsigned int obj_type);
642638
/* run all the marks in a group, and clear all of the vfsmount marks */
643639
static inline void fsnotify_clear_vfsmount_marks_by_group(struct fsnotify_group *group)
644640
{
645-
fsnotify_clear_marks_by_group(group, FSNOTIFY_OBJ_TYPE_VFSMOUNT_FL);
641+
fsnotify_clear_marks_by_group(group, FSNOTIFY_OBJ_TYPE_VFSMOUNT);
646642
}
647643
/* run all the marks in a group, and clear all of the inode marks */
648644
static inline void fsnotify_clear_inode_marks_by_group(struct fsnotify_group *group)
649645
{
650-
fsnotify_clear_marks_by_group(group, FSNOTIFY_OBJ_TYPE_INODE_FL);
646+
fsnotify_clear_marks_by_group(group, FSNOTIFY_OBJ_TYPE_INODE);
651647
}
652648
/* run all the marks in a group, and clear all of the sn marks */
653649
static inline void fsnotify_clear_sb_marks_by_group(struct fsnotify_group *group)
654650
{
655-
fsnotify_clear_marks_by_group(group, FSNOTIFY_OBJ_TYPE_SB_FL);
651+
fsnotify_clear_marks_by_group(group, FSNOTIFY_OBJ_TYPE_SB);
656652
}
657653
extern void fsnotify_get_mark(struct fsnotify_mark *mark);
658654
extern void fsnotify_put_mark(struct fsnotify_mark *mark);

0 commit comments

Comments
 (0)