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

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.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
ad69cd99 5472f14a

+32 -33
+4 -4
fs/notify/fanotify/fanotify_user.c
··· 1057 1057 1058 1058 static struct fsnotify_mark *fanotify_add_new_mark(struct fsnotify_group *group, 1059 1059 fsnotify_connp_t *connp, 1060 - unsigned int type, 1060 + unsigned int obj_type, 1061 1061 __kernel_fsid_t *fsid) 1062 1062 { 1063 1063 struct ucounts *ucounts = group->fanotify_data.ucounts; ··· 1080 1080 } 1081 1081 1082 1082 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); 1084 1084 if (ret) { 1085 1085 fsnotify_put_mark(mark); 1086 1086 goto out_dec_ucounts; ··· 1105 1105 } 1106 1106 1107 1107 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, 1109 1109 __u32 mask, unsigned int flags, 1110 1110 __kernel_fsid_t *fsid) 1111 1111 { ··· 1116 1116 mutex_lock(&group->mark_mutex); 1117 1117 fsn_mark = fsnotify_find_mark(connp, group); 1118 1118 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); 1120 1120 if (IS_ERR(fsn_mark)) { 1121 1121 mutex_unlock(&group->mark_mutex); 1122 1122 return PTR_ERR(fsn_mark);
+1 -1
fs/notify/group.c
··· 58 58 fsnotify_group_stop_queueing(group); 59 59 60 60 /* 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); 62 62 63 63 /* 64 64 * Some marks can still be pinned when waiting for response from
+15 -12
fs/notify/mark.c
··· 496 496 } 497 497 498 498 static int fsnotify_attach_connector_to_object(fsnotify_connp_t *connp, 499 - unsigned int type, 499 + unsigned int obj_type, 500 500 __kernel_fsid_t *fsid) 501 501 { 502 502 struct inode *inode = NULL; ··· 507 507 return -ENOMEM; 508 508 spin_lock_init(&conn->lock); 509 509 INIT_HLIST_HEAD(&conn->list); 510 - conn->type = type; 510 + conn->type = obj_type; 511 511 conn->obj = connp; 512 512 /* Cache fsid of filesystem containing the object */ 513 513 if (fsid) { ··· 572 572 * priority, highest number first, and then by the group's location in memory. 573 573 */ 574 574 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, 576 577 int allow_dups, __kernel_fsid_t *fsid) 577 578 { 578 579 struct fsnotify_mark *lmark, *last = NULL; ··· 581 580 int cmp; 582 581 int err = 0; 583 582 584 - if (WARN_ON(!fsnotify_valid_obj_type(type))) 583 + if (WARN_ON(!fsnotify_valid_obj_type(obj_type))) 585 584 return -EINVAL; 586 585 587 586 /* Backend is expected to check for zero fsid (e.g. tmpfs) */ ··· 593 592 conn = fsnotify_grab_connector(connp); 594 593 if (!conn) { 595 594 spin_unlock(&mark->lock); 596 - err = fsnotify_attach_connector_to_object(connp, type, fsid); 595 + err = fsnotify_attach_connector_to_object(connp, obj_type, 596 + fsid); 597 597 if (err) 598 598 return err; 599 599 goto restart; ··· 667 665 * event types should be delivered to which group. 668 666 */ 669 667 int fsnotify_add_mark_locked(struct fsnotify_mark *mark, 670 - fsnotify_connp_t *connp, unsigned int type, 668 + fsnotify_connp_t *connp, unsigned int obj_type, 671 669 int allow_dups, __kernel_fsid_t *fsid) 672 670 { 673 671 struct fsnotify_group *group = mark->group; ··· 688 686 fsnotify_get_mark(mark); /* for g_list */ 689 687 spin_unlock(&mark->lock); 690 688 691 - ret = fsnotify_add_mark_list(mark, connp, type, allow_dups, fsid); 689 + ret = fsnotify_add_mark_list(mark, connp, obj_type, allow_dups, fsid); 692 690 if (ret) 693 691 goto err; 694 692 ··· 708 706 } 709 707 710 708 int fsnotify_add_mark(struct fsnotify_mark *mark, fsnotify_connp_t *connp, 711 - unsigned int type, int allow_dups, __kernel_fsid_t *fsid) 709 + unsigned int obj_type, int allow_dups, 710 + __kernel_fsid_t *fsid) 712 711 { 713 712 int ret; 714 713 struct fsnotify_group *group = mark->group; 715 714 716 715 mutex_lock(&group->mark_mutex); 717 - ret = fsnotify_add_mark_locked(mark, connp, type, allow_dups, fsid); 716 + ret = fsnotify_add_mark_locked(mark, connp, obj_type, allow_dups, fsid); 718 717 mutex_unlock(&group->mark_mutex); 719 718 return ret; 720 719 } ··· 750 747 751 748 /* Clear any marks in a group with given type mask */ 752 749 void fsnotify_clear_marks_by_group(struct fsnotify_group *group, 753 - unsigned int type_mask) 750 + unsigned int obj_type) 754 751 { 755 752 struct fsnotify_mark *lmark, *mark; 756 753 LIST_HEAD(to_free); 757 754 struct list_head *head = &to_free; 758 755 759 756 /* Skip selection step if we want to clear all marks. */ 760 - if (type_mask == FSNOTIFY_OBJ_ALL_TYPES_MASK) { 757 + if (obj_type == FSNOTIFY_OBJ_TYPE_ANY) { 761 758 head = &group->marks_list; 762 759 goto clear; 763 760 } ··· 772 769 */ 773 770 mutex_lock_nested(&group->mark_mutex, SINGLE_DEPTH_NESTING); 774 771 list_for_each_entry_safe(mark, lmark, &group->marks_list, g_list) { 775 - if ((1U << mark->connector->type) & type_mask) 772 + if (mark->connector->type == obj_type) 776 773 list_move(&mark->g_list, &to_free); 777 774 } 778 775 mutex_unlock(&group->mark_mutex);
+12 -16
include/linux/fsnotify_backend.h
··· 338 338 } 339 339 340 340 enum fsnotify_obj_type { 341 + FSNOTIFY_OBJ_TYPE_ANY = -1, 341 342 FSNOTIFY_OBJ_TYPE_INODE, 342 343 FSNOTIFY_OBJ_TYPE_PARENT, 343 344 FSNOTIFY_OBJ_TYPE_VFSMOUNT, ··· 347 346 FSNOTIFY_OBJ_TYPE_DETACHED = FSNOTIFY_OBJ_TYPE_COUNT 348 347 }; 349 348 350 - #define FSNOTIFY_OBJ_TYPE_INODE_FL (1U << FSNOTIFY_OBJ_TYPE_INODE) 351 - #define FSNOTIFY_OBJ_TYPE_PARENT_FL (1U << FSNOTIFY_OBJ_TYPE_PARENT) 352 - #define FSNOTIFY_OBJ_TYPE_VFSMOUNT_FL (1U << FSNOTIFY_OBJ_TYPE_VFSMOUNT) 353 - #define FSNOTIFY_OBJ_TYPE_SB_FL (1U << FSNOTIFY_OBJ_TYPE_SB) 354 - #define FSNOTIFY_OBJ_ALL_TYPES_MASK ((1U << FSNOTIFY_OBJ_TYPE_COUNT) - 1) 355 - 356 - static inline bool fsnotify_valid_obj_type(unsigned int type) 349 + static inline bool fsnotify_valid_obj_type(unsigned int obj_type) 357 350 { 358 - return (type < FSNOTIFY_OBJ_TYPE_COUNT); 351 + return (obj_type < FSNOTIFY_OBJ_TYPE_COUNT); 359 352 } 360 353 361 354 struct fsnotify_iter_info { ··· 382 387 static inline struct fsnotify_mark *fsnotify_iter_##name##_mark( \ 383 388 struct fsnotify_iter_info *iter_info) \ 384 389 { \ 385 - return (iter_info->report_mask & FSNOTIFY_OBJ_TYPE_##NAME##_FL) ? \ 390 + return (iter_info->report_mask & (1U << FSNOTIFY_OBJ_TYPE_##NAME)) ? \ 386 391 iter_info->marks[FSNOTIFY_OBJ_TYPE_##NAME] : NULL; \ 387 392 } 388 393 ··· 599 604 __kernel_fsid_t *fsid); 600 605 /* attach the mark to the object */ 601 606 extern int fsnotify_add_mark(struct fsnotify_mark *mark, 602 - fsnotify_connp_t *connp, unsigned int type, 607 + fsnotify_connp_t *connp, unsigned int obj_type, 603 608 int allow_dups, __kernel_fsid_t *fsid); 604 609 extern int fsnotify_add_mark_locked(struct fsnotify_mark *mark, 605 610 fsnotify_connp_t *connp, 606 - unsigned int type, int allow_dups, 611 + unsigned int obj_type, int allow_dups, 607 612 __kernel_fsid_t *fsid); 608 613 609 614 /* attach the mark to the inode */ ··· 632 637 extern void fsnotify_free_mark(struct fsnotify_mark *mark); 633 638 /* Wait until all marks queued for destruction are destroyed */ 634 639 extern void fsnotify_wait_marks_destroyed(void); 635 - /* run all the marks in a group, and clear all of the marks attached to given object type */ 636 - extern void fsnotify_clear_marks_by_group(struct fsnotify_group *group, unsigned int type); 640 + /* Clear all of the marks of a group attached to a given object type */ 641 + extern void fsnotify_clear_marks_by_group(struct fsnotify_group *group, 642 + unsigned int obj_type); 637 643 /* run all the marks in a group, and clear all of the vfsmount marks */ 638 644 static inline void fsnotify_clear_vfsmount_marks_by_group(struct fsnotify_group *group) 639 645 { 640 - fsnotify_clear_marks_by_group(group, FSNOTIFY_OBJ_TYPE_VFSMOUNT_FL); 646 + fsnotify_clear_marks_by_group(group, FSNOTIFY_OBJ_TYPE_VFSMOUNT); 641 647 } 642 648 /* run all the marks in a group, and clear all of the inode marks */ 643 649 static inline void fsnotify_clear_inode_marks_by_group(struct fsnotify_group *group) 644 650 { 645 - fsnotify_clear_marks_by_group(group, FSNOTIFY_OBJ_TYPE_INODE_FL); 651 + fsnotify_clear_marks_by_group(group, FSNOTIFY_OBJ_TYPE_INODE); 646 652 } 647 653 /* run all the marks in a group, and clear all of the sn marks */ 648 654 static inline void fsnotify_clear_sb_marks_by_group(struct fsnotify_group *group) 649 655 { 650 - fsnotify_clear_marks_by_group(group, FSNOTIFY_OBJ_TYPE_SB_FL); 656 + fsnotify_clear_marks_by_group(group, FSNOTIFY_OBJ_TYPE_SB); 651 657 } 652 658 extern void fsnotify_get_mark(struct fsnotify_mark *mark); 653 659 extern void fsnotify_put_mark(struct fsnotify_mark *mark);