Commit ad69cd99 authored by Amir Goldstein's avatar Amir Goldstein Committed by Jan Kara

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/20211129201537.1932819-2-amir73il@gmail.comSigned-off-by: default avatarAmir Goldstein <amir73il@gmail.com>
Signed-off-by: default avatarJan Kara <jack@suse.cz>
parent 5472f14a
...@@ -1057,7 +1057,7 @@ static __u32 fanotify_mark_add_to_mask(struct fsnotify_mark *fsn_mark, ...@@ -1057,7 +1057,7 @@ static __u32 fanotify_mark_add_to_mask(struct fsnotify_mark *fsn_mark,
static struct fsnotify_mark *fanotify_add_new_mark(struct fsnotify_group *group, static struct fsnotify_mark *fanotify_add_new_mark(struct fsnotify_group *group,
fsnotify_connp_t *connp, fsnotify_connp_t *connp,
unsigned int type, unsigned int obj_type,
__kernel_fsid_t *fsid) __kernel_fsid_t *fsid)
{ {
struct ucounts *ucounts = group->fanotify_data.ucounts; struct ucounts *ucounts = group->fanotify_data.ucounts;
...@@ -1080,7 +1080,7 @@ static struct fsnotify_mark *fanotify_add_new_mark(struct fsnotify_group *group, ...@@ -1080,7 +1080,7 @@ static struct fsnotify_mark *fanotify_add_new_mark(struct fsnotify_group *group,
} }
fsnotify_init_mark(mark, group); fsnotify_init_mark(mark, group);
ret = fsnotify_add_mark_locked(mark, connp, type, 0, fsid); ret = fsnotify_add_mark_locked(mark, connp, obj_type, 0, fsid);
if (ret) { if (ret) {
fsnotify_put_mark(mark); fsnotify_put_mark(mark);
goto out_dec_ucounts; goto out_dec_ucounts;
...@@ -1105,7 +1105,7 @@ static int fanotify_group_init_error_pool(struct fsnotify_group *group) ...@@ -1105,7 +1105,7 @@ static int fanotify_group_init_error_pool(struct fsnotify_group *group)
} }
static int fanotify_add_mark(struct fsnotify_group *group, static int fanotify_add_mark(struct fsnotify_group *group,
fsnotify_connp_t *connp, unsigned int type, fsnotify_connp_t *connp, unsigned int obj_type,
__u32 mask, unsigned int flags, __u32 mask, unsigned int flags,
__kernel_fsid_t *fsid) __kernel_fsid_t *fsid)
{ {
...@@ -1116,7 +1116,7 @@ static int fanotify_add_mark(struct fsnotify_group *group, ...@@ -1116,7 +1116,7 @@ static int fanotify_add_mark(struct fsnotify_group *group,
mutex_lock(&group->mark_mutex); mutex_lock(&group->mark_mutex);
fsn_mark = fsnotify_find_mark(connp, group); fsn_mark = fsnotify_find_mark(connp, group);
if (!fsn_mark) { if (!fsn_mark) {
fsn_mark = fanotify_add_new_mark(group, connp, type, fsid); fsn_mark = fanotify_add_new_mark(group, connp, obj_type, fsid);
if (IS_ERR(fsn_mark)) { if (IS_ERR(fsn_mark)) {
mutex_unlock(&group->mark_mutex); mutex_unlock(&group->mark_mutex);
return PTR_ERR(fsn_mark); return PTR_ERR(fsn_mark);
......
...@@ -58,7 +58,7 @@ void fsnotify_destroy_group(struct fsnotify_group *group) ...@@ -58,7 +58,7 @@ void fsnotify_destroy_group(struct fsnotify_group *group)
fsnotify_group_stop_queueing(group); fsnotify_group_stop_queueing(group);
/* Clear all marks for this group and queue them for destruction */ /* Clear all marks for this group and queue them for destruction */
fsnotify_clear_marks_by_group(group, FSNOTIFY_OBJ_ALL_TYPES_MASK); fsnotify_clear_marks_by_group(group, FSNOTIFY_OBJ_TYPE_ANY);
/* /*
* Some marks can still be pinned when waiting for response from * Some marks can still be pinned when waiting for response from
......
...@@ -496,7 +496,7 @@ int fsnotify_compare_groups(struct fsnotify_group *a, struct fsnotify_group *b) ...@@ -496,7 +496,7 @@ int fsnotify_compare_groups(struct fsnotify_group *a, struct fsnotify_group *b)
} }
static int fsnotify_attach_connector_to_object(fsnotify_connp_t *connp, static int fsnotify_attach_connector_to_object(fsnotify_connp_t *connp,
unsigned int type, unsigned int obj_type,
__kernel_fsid_t *fsid) __kernel_fsid_t *fsid)
{ {
struct inode *inode = NULL; struct inode *inode = NULL;
...@@ -507,7 +507,7 @@ static int fsnotify_attach_connector_to_object(fsnotify_connp_t *connp, ...@@ -507,7 +507,7 @@ static int fsnotify_attach_connector_to_object(fsnotify_connp_t *connp,
return -ENOMEM; return -ENOMEM;
spin_lock_init(&conn->lock); spin_lock_init(&conn->lock);
INIT_HLIST_HEAD(&conn->list); INIT_HLIST_HEAD(&conn->list);
conn->type = type; conn->type = obj_type;
conn->obj = connp; conn->obj = connp;
/* Cache fsid of filesystem containing the object */ /* Cache fsid of filesystem containing the object */
if (fsid) { if (fsid) {
...@@ -572,7 +572,8 @@ static struct fsnotify_mark_connector *fsnotify_grab_connector( ...@@ -572,7 +572,8 @@ static struct fsnotify_mark_connector *fsnotify_grab_connector(
* priority, highest number first, and then by the group's location in memory. * priority, highest number first, and then by the group's location in memory.
*/ */
static int fsnotify_add_mark_list(struct fsnotify_mark *mark, static int fsnotify_add_mark_list(struct fsnotify_mark *mark,
fsnotify_connp_t *connp, unsigned int type, fsnotify_connp_t *connp,
unsigned int obj_type,
int allow_dups, __kernel_fsid_t *fsid) int allow_dups, __kernel_fsid_t *fsid)
{ {
struct fsnotify_mark *lmark, *last = NULL; struct fsnotify_mark *lmark, *last = NULL;
...@@ -580,7 +581,7 @@ static int fsnotify_add_mark_list(struct fsnotify_mark *mark, ...@@ -580,7 +581,7 @@ static int fsnotify_add_mark_list(struct fsnotify_mark *mark,
int cmp; int cmp;
int err = 0; int err = 0;
if (WARN_ON(!fsnotify_valid_obj_type(type))) if (WARN_ON(!fsnotify_valid_obj_type(obj_type)))
return -EINVAL; return -EINVAL;
/* Backend is expected to check for zero fsid (e.g. tmpfs) */ /* 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, ...@@ -592,7 +593,8 @@ static int fsnotify_add_mark_list(struct fsnotify_mark *mark,
conn = fsnotify_grab_connector(connp); conn = fsnotify_grab_connector(connp);
if (!conn) { if (!conn) {
spin_unlock(&mark->lock); spin_unlock(&mark->lock);
err = fsnotify_attach_connector_to_object(connp, type, fsid); err = fsnotify_attach_connector_to_object(connp, obj_type,
fsid);
if (err) if (err)
return err; return err;
goto restart; goto restart;
...@@ -665,7 +667,7 @@ static int fsnotify_add_mark_list(struct fsnotify_mark *mark, ...@@ -665,7 +667,7 @@ static int fsnotify_add_mark_list(struct fsnotify_mark *mark,
* event types should be delivered to which group. * event types should be delivered to which group.
*/ */
int fsnotify_add_mark_locked(struct fsnotify_mark *mark, int fsnotify_add_mark_locked(struct fsnotify_mark *mark,
fsnotify_connp_t *connp, unsigned int type, fsnotify_connp_t *connp, unsigned int obj_type,
int allow_dups, __kernel_fsid_t *fsid) int allow_dups, __kernel_fsid_t *fsid)
{ {
struct fsnotify_group *group = mark->group; struct fsnotify_group *group = mark->group;
...@@ -686,7 +688,7 @@ int fsnotify_add_mark_locked(struct fsnotify_mark *mark, ...@@ -686,7 +688,7 @@ int fsnotify_add_mark_locked(struct fsnotify_mark *mark,
fsnotify_get_mark(mark); /* for g_list */ fsnotify_get_mark(mark); /* for g_list */
spin_unlock(&mark->lock); spin_unlock(&mark->lock);
ret = fsnotify_add_mark_list(mark, connp, type, allow_dups, fsid); ret = fsnotify_add_mark_list(mark, connp, obj_type, allow_dups, fsid);
if (ret) if (ret)
goto err; goto err;
...@@ -706,13 +708,14 @@ int fsnotify_add_mark_locked(struct fsnotify_mark *mark, ...@@ -706,13 +708,14 @@ int fsnotify_add_mark_locked(struct fsnotify_mark *mark,
} }
int fsnotify_add_mark(struct fsnotify_mark *mark, fsnotify_connp_t *connp, int fsnotify_add_mark(struct fsnotify_mark *mark, fsnotify_connp_t *connp,
unsigned int type, int allow_dups, __kernel_fsid_t *fsid) unsigned int obj_type, int allow_dups,
__kernel_fsid_t *fsid)
{ {
int ret; int ret;
struct fsnotify_group *group = mark->group; struct fsnotify_group *group = mark->group;
mutex_lock(&group->mark_mutex); mutex_lock(&group->mark_mutex);
ret = fsnotify_add_mark_locked(mark, connp, type, allow_dups, fsid); ret = fsnotify_add_mark_locked(mark, connp, obj_type, allow_dups, fsid);
mutex_unlock(&group->mark_mutex); mutex_unlock(&group->mark_mutex);
return ret; return ret;
} }
...@@ -747,14 +750,14 @@ EXPORT_SYMBOL_GPL(fsnotify_find_mark); ...@@ -747,14 +750,14 @@ EXPORT_SYMBOL_GPL(fsnotify_find_mark);
/* Clear any marks in a group with given type mask */ /* Clear any marks in a group with given type mask */
void fsnotify_clear_marks_by_group(struct fsnotify_group *group, void fsnotify_clear_marks_by_group(struct fsnotify_group *group,
unsigned int type_mask) unsigned int obj_type)
{ {
struct fsnotify_mark *lmark, *mark; struct fsnotify_mark *lmark, *mark;
LIST_HEAD(to_free); LIST_HEAD(to_free);
struct list_head *head = &to_free; struct list_head *head = &to_free;
/* Skip selection step if we want to clear all marks. */ /* Skip selection step if we want to clear all marks. */
if (type_mask == FSNOTIFY_OBJ_ALL_TYPES_MASK) { if (obj_type == FSNOTIFY_OBJ_TYPE_ANY) {
head = &group->marks_list; head = &group->marks_list;
goto clear; goto clear;
} }
...@@ -769,7 +772,7 @@ void fsnotify_clear_marks_by_group(struct fsnotify_group *group, ...@@ -769,7 +772,7 @@ void fsnotify_clear_marks_by_group(struct fsnotify_group *group,
*/ */
mutex_lock_nested(&group->mark_mutex, SINGLE_DEPTH_NESTING); mutex_lock_nested(&group->mark_mutex, SINGLE_DEPTH_NESTING);
list_for_each_entry_safe(mark, lmark, &group->marks_list, g_list) { list_for_each_entry_safe(mark, lmark, &group->marks_list, g_list) {
if ((1U << mark->connector->type) & type_mask) if (mark->connector->type == obj_type)
list_move(&mark->g_list, &to_free); list_move(&mark->g_list, &to_free);
} }
mutex_unlock(&group->mark_mutex); mutex_unlock(&group->mark_mutex);
......
...@@ -338,6 +338,7 @@ static inline struct fs_error_report *fsnotify_data_error_report( ...@@ -338,6 +338,7 @@ static inline struct fs_error_report *fsnotify_data_error_report(
} }
enum fsnotify_obj_type { enum fsnotify_obj_type {
FSNOTIFY_OBJ_TYPE_ANY = -1,
FSNOTIFY_OBJ_TYPE_INODE, FSNOTIFY_OBJ_TYPE_INODE,
FSNOTIFY_OBJ_TYPE_PARENT, FSNOTIFY_OBJ_TYPE_PARENT,
FSNOTIFY_OBJ_TYPE_VFSMOUNT, FSNOTIFY_OBJ_TYPE_VFSMOUNT,
...@@ -346,15 +347,9 @@ enum fsnotify_obj_type { ...@@ -346,15 +347,9 @@ enum fsnotify_obj_type {
FSNOTIFY_OBJ_TYPE_DETACHED = FSNOTIFY_OBJ_TYPE_COUNT FSNOTIFY_OBJ_TYPE_DETACHED = FSNOTIFY_OBJ_TYPE_COUNT
}; };
#define FSNOTIFY_OBJ_TYPE_INODE_FL (1U << FSNOTIFY_OBJ_TYPE_INODE) static inline bool fsnotify_valid_obj_type(unsigned int obj_type)
#define FSNOTIFY_OBJ_TYPE_PARENT_FL (1U << FSNOTIFY_OBJ_TYPE_PARENT)
#define FSNOTIFY_OBJ_TYPE_VFSMOUNT_FL (1U << FSNOTIFY_OBJ_TYPE_VFSMOUNT)
#define FSNOTIFY_OBJ_TYPE_SB_FL (1U << FSNOTIFY_OBJ_TYPE_SB)
#define FSNOTIFY_OBJ_ALL_TYPES_MASK ((1U << FSNOTIFY_OBJ_TYPE_COUNT) - 1)
static inline bool fsnotify_valid_obj_type(unsigned int type)
{ {
return (type < FSNOTIFY_OBJ_TYPE_COUNT); return (obj_type < FSNOTIFY_OBJ_TYPE_COUNT);
} }
struct fsnotify_iter_info { struct fsnotify_iter_info {
...@@ -387,7 +382,7 @@ static inline void fsnotify_iter_set_report_type_mark( ...@@ -387,7 +382,7 @@ static inline void fsnotify_iter_set_report_type_mark(
static inline struct fsnotify_mark *fsnotify_iter_##name##_mark( \ static inline struct fsnotify_mark *fsnotify_iter_##name##_mark( \
struct fsnotify_iter_info *iter_info) \ struct fsnotify_iter_info *iter_info) \
{ \ { \
return (iter_info->report_mask & FSNOTIFY_OBJ_TYPE_##NAME##_FL) ? \ return (iter_info->report_mask & (1U << FSNOTIFY_OBJ_TYPE_##NAME)) ? \
iter_info->marks[FSNOTIFY_OBJ_TYPE_##NAME] : NULL; \ iter_info->marks[FSNOTIFY_OBJ_TYPE_##NAME] : NULL; \
} }
...@@ -604,11 +599,11 @@ extern int fsnotify_get_conn_fsid(const struct fsnotify_mark_connector *conn, ...@@ -604,11 +599,11 @@ extern int fsnotify_get_conn_fsid(const struct fsnotify_mark_connector *conn,
__kernel_fsid_t *fsid); __kernel_fsid_t *fsid);
/* attach the mark to the object */ /* attach the mark to the object */
extern int fsnotify_add_mark(struct fsnotify_mark *mark, extern int fsnotify_add_mark(struct fsnotify_mark *mark,
fsnotify_connp_t *connp, unsigned int type, fsnotify_connp_t *connp, unsigned int obj_type,
int allow_dups, __kernel_fsid_t *fsid); int allow_dups, __kernel_fsid_t *fsid);
extern int fsnotify_add_mark_locked(struct fsnotify_mark *mark, extern int fsnotify_add_mark_locked(struct fsnotify_mark *mark,
fsnotify_connp_t *connp, fsnotify_connp_t *connp,
unsigned int type, int allow_dups, unsigned int obj_type, int allow_dups,
__kernel_fsid_t *fsid); __kernel_fsid_t *fsid);
/* attach the mark to the inode */ /* attach the mark to the inode */
...@@ -637,22 +632,23 @@ extern void fsnotify_detach_mark(struct fsnotify_mark *mark); ...@@ -637,22 +632,23 @@ extern void fsnotify_detach_mark(struct fsnotify_mark *mark);
extern void fsnotify_free_mark(struct fsnotify_mark *mark); extern void fsnotify_free_mark(struct fsnotify_mark *mark);
/* Wait until all marks queued for destruction are destroyed */ /* Wait until all marks queued for destruction are destroyed */
extern void fsnotify_wait_marks_destroyed(void); extern void fsnotify_wait_marks_destroyed(void);
/* run all the marks in a group, and clear all of the marks attached to given object type */ /* Clear all of the marks of a group attached to a given object type */
extern void fsnotify_clear_marks_by_group(struct fsnotify_group *group, unsigned int type); extern void fsnotify_clear_marks_by_group(struct fsnotify_group *group,
unsigned int obj_type);
/* run all the marks in a group, and clear all of the vfsmount marks */ /* run all the marks in a group, and clear all of the vfsmount marks */
static inline void fsnotify_clear_vfsmount_marks_by_group(struct fsnotify_group *group) static inline void fsnotify_clear_vfsmount_marks_by_group(struct fsnotify_group *group)
{ {
fsnotify_clear_marks_by_group(group, FSNOTIFY_OBJ_TYPE_VFSMOUNT_FL); fsnotify_clear_marks_by_group(group, FSNOTIFY_OBJ_TYPE_VFSMOUNT);
} }
/* run all the marks in a group, and clear all of the inode marks */ /* run all the marks in a group, and clear all of the inode marks */
static inline void fsnotify_clear_inode_marks_by_group(struct fsnotify_group *group) static inline void fsnotify_clear_inode_marks_by_group(struct fsnotify_group *group)
{ {
fsnotify_clear_marks_by_group(group, FSNOTIFY_OBJ_TYPE_INODE_FL); fsnotify_clear_marks_by_group(group, FSNOTIFY_OBJ_TYPE_INODE);
} }
/* run all the marks in a group, and clear all of the sn marks */ /* run all the marks in a group, and clear all of the sn marks */
static inline void fsnotify_clear_sb_marks_by_group(struct fsnotify_group *group) static inline void fsnotify_clear_sb_marks_by_group(struct fsnotify_group *group)
{ {
fsnotify_clear_marks_by_group(group, FSNOTIFY_OBJ_TYPE_SB_FL); fsnotify_clear_marks_by_group(group, FSNOTIFY_OBJ_TYPE_SB);
} }
extern void fsnotify_get_mark(struct fsnotify_mark *mark); extern void fsnotify_get_mark(struct fsnotify_mark *mark);
extern void fsnotify_put_mark(struct fsnotify_mark *mark); extern void fsnotify_put_mark(struct fsnotify_mark *mark);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment