fsnotify: make allow_dups a property of the group
Instead of passing the allow_dups argument to fsnotify_add_mark() as an argument, define the group flag FSNOTIFY_GROUP_DUPS to express the allow_dups behavior and set this behavior at group creation time for all calls of fsnotify_add_mark(). Rename the allow_dups argument to generic add_flags argument for future use. Link: https://lore.kernel.org/r/20220422120327.3459282-6-amir73il@gmail.com Suggested-by: Jan Kara <jack@suse.cz> Signed-off-by: Amir Goldstein <amir73il@gmail.com> Signed-off-by: Jan Kara <jack@suse.cz>
This commit is contained in:
parent
867a448d58
commit
f3010343d9
|
@ -574,7 +574,7 @@ static struct fsnotify_mark_connector *fsnotify_grab_connector(
|
||||||
static int fsnotify_add_mark_list(struct fsnotify_mark *mark,
|
static int fsnotify_add_mark_list(struct fsnotify_mark *mark,
|
||||||
fsnotify_connp_t *connp,
|
fsnotify_connp_t *connp,
|
||||||
unsigned int obj_type,
|
unsigned int obj_type,
|
||||||
int allow_dups, __kernel_fsid_t *fsid)
|
int add_flags, __kernel_fsid_t *fsid)
|
||||||
{
|
{
|
||||||
struct fsnotify_mark *lmark, *last = NULL;
|
struct fsnotify_mark *lmark, *last = NULL;
|
||||||
struct fsnotify_mark_connector *conn;
|
struct fsnotify_mark_connector *conn;
|
||||||
|
@ -633,7 +633,7 @@ static int fsnotify_add_mark_list(struct fsnotify_mark *mark,
|
||||||
|
|
||||||
if ((lmark->group == mark->group) &&
|
if ((lmark->group == mark->group) &&
|
||||||
(lmark->flags & FSNOTIFY_MARK_FLAG_ATTACHED) &&
|
(lmark->flags & FSNOTIFY_MARK_FLAG_ATTACHED) &&
|
||||||
!allow_dups) {
|
!(mark->group->flags & FSNOTIFY_GROUP_DUPS)) {
|
||||||
err = -EEXIST;
|
err = -EEXIST;
|
||||||
goto out_err;
|
goto out_err;
|
||||||
}
|
}
|
||||||
|
@ -668,7 +668,7 @@ static int fsnotify_add_mark_list(struct fsnotify_mark *mark,
|
||||||
*/
|
*/
|
||||||
int fsnotify_add_mark_locked(struct fsnotify_mark *mark,
|
int fsnotify_add_mark_locked(struct fsnotify_mark *mark,
|
||||||
fsnotify_connp_t *connp, unsigned int obj_type,
|
fsnotify_connp_t *connp, unsigned int obj_type,
|
||||||
int allow_dups, __kernel_fsid_t *fsid)
|
int add_flags, __kernel_fsid_t *fsid)
|
||||||
{
|
{
|
||||||
struct fsnotify_group *group = mark->group;
|
struct fsnotify_group *group = mark->group;
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
@ -688,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, obj_type, allow_dups, fsid);
|
ret = fsnotify_add_mark_list(mark, connp, obj_type, add_flags, fsid);
|
||||||
if (ret)
|
if (ret)
|
||||||
goto err;
|
goto err;
|
||||||
|
|
||||||
|
@ -708,14 +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 obj_type, int allow_dups,
|
unsigned int obj_type, int add_flags,
|
||||||
__kernel_fsid_t *fsid)
|
__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, obj_type, allow_dups, fsid);
|
ret = fsnotify_add_mark_locked(mark, connp, obj_type, add_flags, fsid);
|
||||||
mutex_unlock(&group->mark_mutex);
|
mutex_unlock(&group->mark_mutex);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
|
@ -211,6 +211,7 @@ struct fsnotify_group {
|
||||||
bool shutdown; /* group is being shut down, don't queue more events */
|
bool shutdown; /* group is being shut down, don't queue more events */
|
||||||
|
|
||||||
#define FSNOTIFY_GROUP_USER 0x01 /* user allocated group */
|
#define FSNOTIFY_GROUP_USER 0x01 /* user allocated group */
|
||||||
|
#define FSNOTIFY_GROUP_DUPS 0x02 /* allow multiple marks per object */
|
||||||
int flags;
|
int flags;
|
||||||
|
|
||||||
/* stores all fastpath marks assoc with this group so they can be cleaned on unregister */
|
/* stores all fastpath marks assoc with this group so they can be cleaned on unregister */
|
||||||
|
@ -641,26 +642,26 @@ extern int fsnotify_get_conn_fsid(const struct fsnotify_mark_connector *conn,
|
||||||
/* 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 obj_type,
|
fsnotify_connp_t *connp, unsigned int obj_type,
|
||||||
int allow_dups, __kernel_fsid_t *fsid);
|
int add_flags, __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 obj_type, int allow_dups,
|
unsigned int obj_type, int add_flags,
|
||||||
__kernel_fsid_t *fsid);
|
__kernel_fsid_t *fsid);
|
||||||
|
|
||||||
/* attach the mark to the inode */
|
/* attach the mark to the inode */
|
||||||
static inline int fsnotify_add_inode_mark(struct fsnotify_mark *mark,
|
static inline int fsnotify_add_inode_mark(struct fsnotify_mark *mark,
|
||||||
struct inode *inode,
|
struct inode *inode,
|
||||||
int allow_dups)
|
int add_flags)
|
||||||
{
|
{
|
||||||
return fsnotify_add_mark(mark, &inode->i_fsnotify_marks,
|
return fsnotify_add_mark(mark, &inode->i_fsnotify_marks,
|
||||||
FSNOTIFY_OBJ_TYPE_INODE, allow_dups, NULL);
|
FSNOTIFY_OBJ_TYPE_INODE, add_flags, NULL);
|
||||||
}
|
}
|
||||||
static inline int fsnotify_add_inode_mark_locked(struct fsnotify_mark *mark,
|
static inline int fsnotify_add_inode_mark_locked(struct fsnotify_mark *mark,
|
||||||
struct inode *inode,
|
struct inode *inode,
|
||||||
int allow_dups)
|
int add_flags)
|
||||||
{
|
{
|
||||||
return fsnotify_add_mark_locked(mark, &inode->i_fsnotify_marks,
|
return fsnotify_add_mark_locked(mark, &inode->i_fsnotify_marks,
|
||||||
FSNOTIFY_OBJ_TYPE_INODE, allow_dups,
|
FSNOTIFY_OBJ_TYPE_INODE, add_flags,
|
||||||
NULL);
|
NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -100,7 +100,7 @@ struct audit_fsnotify_mark *audit_alloc_mark(struct audit_krule *krule, char *pa
|
||||||
audit_update_mark(audit_mark, dentry->d_inode);
|
audit_update_mark(audit_mark, dentry->d_inode);
|
||||||
audit_mark->rule = krule;
|
audit_mark->rule = krule;
|
||||||
|
|
||||||
ret = fsnotify_add_inode_mark(&audit_mark->mark, inode, true);
|
ret = fsnotify_add_inode_mark(&audit_mark->mark, inode, 0);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
fsnotify_put_mark(&audit_mark->mark);
|
fsnotify_put_mark(&audit_mark->mark);
|
||||||
audit_mark = ERR_PTR(ret);
|
audit_mark = ERR_PTR(ret);
|
||||||
|
@ -182,7 +182,7 @@ static const struct fsnotify_ops audit_mark_fsnotify_ops = {
|
||||||
static int __init audit_fsnotify_init(void)
|
static int __init audit_fsnotify_init(void)
|
||||||
{
|
{
|
||||||
audit_fsnotify_group = fsnotify_alloc_group(&audit_mark_fsnotify_ops,
|
audit_fsnotify_group = fsnotify_alloc_group(&audit_mark_fsnotify_ops,
|
||||||
0);
|
FSNOTIFY_GROUP_DUPS);
|
||||||
if (IS_ERR(audit_fsnotify_group)) {
|
if (IS_ERR(audit_fsnotify_group)) {
|
||||||
audit_fsnotify_group = NULL;
|
audit_fsnotify_group = NULL;
|
||||||
audit_panic("cannot create audit fsnotify group");
|
audit_panic("cannot create audit fsnotify group");
|
||||||
|
|
Loading…
Reference in New Issue