Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

fsnotify: pass flags argument to fsnotify_alloc_group()

Add flags argument to fsnotify_alloc_group(), define and use the flag
FSNOTIFY_GROUP_USER in inotify and fanotify instead of the helper
fsnotify_alloc_user_group() to indicate user allocation.

Although the flag FSNOTIFY_GROUP_USER is currently not used after group
allocation, we store the flags argument in the group struct for future
use of other group flags.

Link: https://lore.kernel.org/r/20220422120327.3459282-5-amir73il@gmail.com
Signed-off-by: Amir Goldstein <amir73il@gmail.com>
Signed-off-by: Jan Kara <jack@suse.cz>

authored by

Amir Goldstein and committed by
Jan Kara
867a448d 623af4f5

+26 -21
+2 -1
fs/nfsd/filecache.c
··· 678 678 goto out_shrinker; 679 679 } 680 680 681 - nfsd_file_fsnotify_group = fsnotify_alloc_group(&nfsd_file_fsnotify_ops); 681 + nfsd_file_fsnotify_group = fsnotify_alloc_group(&nfsd_file_fsnotify_ops, 682 + 0); 682 683 if (IS_ERR(nfsd_file_fsnotify_group)) { 683 684 pr_err("nfsd: unable to create fsnotify group: %ld\n", 684 685 PTR_ERR(nfsd_file_fsnotify_group));
+1 -1
fs/notify/dnotify/dnotify.c
··· 401 401 SLAB_PANIC|SLAB_ACCOUNT); 402 402 dnotify_mark_cache = KMEM_CACHE(dnotify_mark, SLAB_PANIC|SLAB_ACCOUNT); 403 403 404 - dnotify_group = fsnotify_alloc_group(&dnotify_fsnotify_ops); 404 + dnotify_group = fsnotify_alloc_group(&dnotify_fsnotify_ops, 0); 405 405 if (IS_ERR(dnotify_group)) 406 406 panic("unable to allocate fsnotify group for dnotify\n"); 407 407 dnotify_sysctl_init();
+2 -1
fs/notify/fanotify/fanotify_user.c
··· 1355 1355 f_flags |= O_NONBLOCK; 1356 1356 1357 1357 /* fsnotify_alloc_group takes a ref. Dropped in fanotify_release */ 1358 - group = fsnotify_alloc_user_group(&fanotify_fsnotify_ops); 1358 + group = fsnotify_alloc_group(&fanotify_fsnotify_ops, 1359 + FSNOTIFY_GROUP_USER); 1359 1360 if (IS_ERR(group)) { 1360 1361 return PTR_ERR(group); 1361 1362 }
+9 -12
fs/notify/group.c
··· 112 112 EXPORT_SYMBOL_GPL(fsnotify_put_group); 113 113 114 114 static struct fsnotify_group *__fsnotify_alloc_group( 115 - const struct fsnotify_ops *ops, gfp_t gfp) 115 + const struct fsnotify_ops *ops, 116 + int flags, gfp_t gfp) 116 117 { 117 118 struct fsnotify_group *group; 118 119 ··· 134 133 INIT_LIST_HEAD(&group->marks_list); 135 134 136 135 group->ops = ops; 136 + group->flags = flags; 137 137 138 138 return group; 139 139 } ··· 142 140 /* 143 141 * Create a new fsnotify_group and hold a reference for the group returned. 144 142 */ 145 - struct fsnotify_group *fsnotify_alloc_group(const struct fsnotify_ops *ops) 143 + struct fsnotify_group *fsnotify_alloc_group(const struct fsnotify_ops *ops, 144 + int flags) 146 145 { 147 - return __fsnotify_alloc_group(ops, GFP_KERNEL); 146 + gfp_t gfp = (flags & FSNOTIFY_GROUP_USER) ? GFP_KERNEL_ACCOUNT : 147 + GFP_KERNEL; 148 + 149 + return __fsnotify_alloc_group(ops, flags, gfp); 148 150 } 149 151 EXPORT_SYMBOL_GPL(fsnotify_alloc_group); 150 - 151 - /* 152 - * Create a new fsnotify_group and hold a reference for the group returned. 153 - */ 154 - struct fsnotify_group *fsnotify_alloc_user_group(const struct fsnotify_ops *ops) 155 - { 156 - return __fsnotify_alloc_group(ops, GFP_KERNEL_ACCOUNT); 157 - } 158 - EXPORT_SYMBOL_GPL(fsnotify_alloc_user_group); 159 152 160 153 int fsnotify_fasync(int fd, struct file *file, int on) 161 154 {
+2 -1
fs/notify/inotify/inotify_user.c
··· 656 656 struct fsnotify_group *group; 657 657 struct inotify_event_info *oevent; 658 658 659 - group = fsnotify_alloc_user_group(&inotify_fsnotify_ops); 659 + group = fsnotify_alloc_group(&inotify_fsnotify_ops, 660 + FSNOTIFY_GROUP_USER); 660 661 if (IS_ERR(group)) 661 662 return group; 662 663
+6 -2
include/linux/fsnotify_backend.h
··· 210 210 unsigned int priority; 211 211 bool shutdown; /* group is being shut down, don't queue more events */ 212 212 213 + #define FSNOTIFY_GROUP_USER 0x01 /* user allocated group */ 214 + int flags; 215 + 213 216 /* stores all fastpath marks assoc with this group so they can be cleaned on unregister */ 214 217 struct mutex mark_mutex; /* protect marks_list */ 215 218 atomic_t user_waits; /* Number of tasks waiting for user ··· 546 543 /* called from fsnotify listeners, such as fanotify or dnotify */ 547 544 548 545 /* create a new group */ 549 - extern struct fsnotify_group *fsnotify_alloc_group(const struct fsnotify_ops *ops); 550 - extern struct fsnotify_group *fsnotify_alloc_user_group(const struct fsnotify_ops *ops); 546 + extern struct fsnotify_group *fsnotify_alloc_group( 547 + const struct fsnotify_ops *ops, 548 + int flags); 551 549 /* get reference to a group */ 552 550 extern void fsnotify_get_group(struct fsnotify_group *group); 553 551 /* drop reference on a group from fsnotify_alloc_group */
+2 -1
kernel/audit_fsnotify.c
··· 181 181 182 182 static int __init audit_fsnotify_init(void) 183 183 { 184 - audit_fsnotify_group = fsnotify_alloc_group(&audit_mark_fsnotify_ops); 184 + audit_fsnotify_group = fsnotify_alloc_group(&audit_mark_fsnotify_ops, 185 + 0); 185 186 if (IS_ERR(audit_fsnotify_group)) { 186 187 audit_fsnotify_group = NULL; 187 188 audit_panic("cannot create audit fsnotify group");
+1 -1
kernel/audit_tree.c
··· 1074 1074 1075 1075 audit_tree_mark_cachep = KMEM_CACHE(audit_tree_mark, SLAB_PANIC); 1076 1076 1077 - audit_tree_group = fsnotify_alloc_group(&audit_tree_ops); 1077 + audit_tree_group = fsnotify_alloc_group(&audit_tree_ops, 0); 1078 1078 if (IS_ERR(audit_tree_group)) 1079 1079 audit_panic("cannot initialize fsnotify group for rectree watches"); 1080 1080
+1 -1
kernel/audit_watch.c
··· 493 493 494 494 static int __init audit_watch_init(void) 495 495 { 496 - audit_watch_group = fsnotify_alloc_group(&audit_watch_fsnotify_ops); 496 + audit_watch_group = fsnotify_alloc_group(&audit_watch_fsnotify_ops, 0); 497 497 if (IS_ERR(audit_watch_group)) { 498 498 audit_watch_group = NULL; 499 499 audit_panic("cannot create audit fsnotify group");