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

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>

authored by

Amir Goldstein and committed by
Jan Kara
f3010343 867a448d

+15 -14
+6 -6
fs/notify/mark.c
··· 574 574 static int fsnotify_add_mark_list(struct fsnotify_mark *mark, 575 575 fsnotify_connp_t *connp, 576 576 unsigned int obj_type, 577 - int allow_dups, __kernel_fsid_t *fsid) 577 + int add_flags, __kernel_fsid_t *fsid) 578 578 { 579 579 struct fsnotify_mark *lmark, *last = NULL; 580 580 struct fsnotify_mark_connector *conn; ··· 633 633 634 634 if ((lmark->group == mark->group) && 635 635 (lmark->flags & FSNOTIFY_MARK_FLAG_ATTACHED) && 636 - !allow_dups) { 636 + !(mark->group->flags & FSNOTIFY_GROUP_DUPS)) { 637 637 err = -EEXIST; 638 638 goto out_err; 639 639 } ··· 668 668 */ 669 669 int fsnotify_add_mark_locked(struct fsnotify_mark *mark, 670 670 fsnotify_connp_t *connp, unsigned int obj_type, 671 - int allow_dups, __kernel_fsid_t *fsid) 671 + int add_flags, __kernel_fsid_t *fsid) 672 672 { 673 673 struct fsnotify_group *group = mark->group; 674 674 int ret = 0; ··· 688 688 fsnotify_get_mark(mark); /* for g_list */ 689 689 spin_unlock(&mark->lock); 690 690 691 - ret = fsnotify_add_mark_list(mark, connp, obj_type, allow_dups, fsid); 691 + ret = fsnotify_add_mark_list(mark, connp, obj_type, add_flags, fsid); 692 692 if (ret) 693 693 goto err; 694 694 ··· 708 708 } 709 709 710 710 int fsnotify_add_mark(struct fsnotify_mark *mark, fsnotify_connp_t *connp, 711 - unsigned int obj_type, int allow_dups, 711 + unsigned int obj_type, int add_flags, 712 712 __kernel_fsid_t *fsid) 713 713 { 714 714 int ret; 715 715 struct fsnotify_group *group = mark->group; 716 716 717 717 mutex_lock(&group->mark_mutex); 718 - ret = fsnotify_add_mark_locked(mark, connp, obj_type, allow_dups, fsid); 718 + ret = fsnotify_add_mark_locked(mark, connp, obj_type, add_flags, fsid); 719 719 mutex_unlock(&group->mark_mutex); 720 720 return ret; 721 721 }
+7 -6
include/linux/fsnotify_backend.h
··· 211 211 bool shutdown; /* group is being shut down, don't queue more events */ 212 212 213 213 #define FSNOTIFY_GROUP_USER 0x01 /* user allocated group */ 214 + #define FSNOTIFY_GROUP_DUPS 0x02 /* allow multiple marks per object */ 214 215 int flags; 215 216 216 217 /* stores all fastpath marks assoc with this group so they can be cleaned on unregister */ ··· 642 641 /* attach the mark to the object */ 643 642 extern int fsnotify_add_mark(struct fsnotify_mark *mark, 644 643 fsnotify_connp_t *connp, unsigned int obj_type, 645 - int allow_dups, __kernel_fsid_t *fsid); 644 + int add_flags, __kernel_fsid_t *fsid); 646 645 extern int fsnotify_add_mark_locked(struct fsnotify_mark *mark, 647 646 fsnotify_connp_t *connp, 648 - unsigned int obj_type, int allow_dups, 647 + unsigned int obj_type, int add_flags, 649 648 __kernel_fsid_t *fsid); 650 649 651 650 /* attach the mark to the inode */ 652 651 static inline int fsnotify_add_inode_mark(struct fsnotify_mark *mark, 653 652 struct inode *inode, 654 - int allow_dups) 653 + int add_flags) 655 654 { 656 655 return fsnotify_add_mark(mark, &inode->i_fsnotify_marks, 657 - FSNOTIFY_OBJ_TYPE_INODE, allow_dups, NULL); 656 + FSNOTIFY_OBJ_TYPE_INODE, add_flags, NULL); 658 657 } 659 658 static inline int fsnotify_add_inode_mark_locked(struct fsnotify_mark *mark, 660 659 struct inode *inode, 661 - int allow_dups) 660 + int add_flags) 662 661 { 663 662 return fsnotify_add_mark_locked(mark, &inode->i_fsnotify_marks, 664 - FSNOTIFY_OBJ_TYPE_INODE, allow_dups, 663 + FSNOTIFY_OBJ_TYPE_INODE, add_flags, 665 664 NULL); 666 665 } 667 666
+2 -2
kernel/audit_fsnotify.c
··· 100 100 audit_update_mark(audit_mark, dentry->d_inode); 101 101 audit_mark->rule = krule; 102 102 103 - ret = fsnotify_add_inode_mark(&audit_mark->mark, inode, true); 103 + ret = fsnotify_add_inode_mark(&audit_mark->mark, inode, 0); 104 104 if (ret < 0) { 105 105 fsnotify_put_mark(&audit_mark->mark); 106 106 audit_mark = ERR_PTR(ret); ··· 182 182 static int __init audit_fsnotify_init(void) 183 183 { 184 184 audit_fsnotify_group = fsnotify_alloc_group(&audit_mark_fsnotify_ops, 185 - 0); 185 + FSNOTIFY_GROUP_DUPS); 186 186 if (IS_ERR(audit_fsnotify_group)) { 187 187 audit_fsnotify_group = NULL; 188 188 audit_panic("cannot create audit fsnotify group");