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

Configure Feed

Select the types of activity you want to include in your feed.

md/md-bitmap: split bitmap sysfs groups

Split the classic bitmap sysfs files into a common bitmap group with
the location attribute and a separate internal bitmap group for the
remaining files.

At the same time, convert bitmap operations from a single sysfs group
to a sysfs group array so backends can share part of their sysfs
layout while adding backend-specific attributes separately.

Switch the bitmap sysfs helpers to use sysfs_update_groups() for the
add and update path, and remove groups in reverse order so shared named
groups are unmerged before the last group removes the directory.

Also make bitmap operation lookup depend only on the currently selected
bitmap id matching the installed backend. This prepares the lookup path
for a later registered none backend.

Reviewed-by: Su Yue <glass.su@suse.com>
Link: https://lore.kernel.org/r/20260425024615.1696892-3-yukuai@fnnas.com
Signed-off-by: Yu Kuai <yukuai@fnnas.com>

+40 -13
+19 -4
drivers/md/md-bitmap.c
··· 2955 2955 __ATTR(max_backlog_used, S_IRUGO | S_IWUSR, 2956 2956 behind_writes_used_show, behind_writes_used_reset); 2957 2957 2958 - static struct attribute *md_bitmap_attrs[] = { 2958 + static struct attribute *md_bitmap_common_attrs[] = { 2959 2959 &bitmap_location.attr, 2960 + NULL 2961 + }; 2962 + 2963 + static struct attribute *md_bitmap_internal_attrs[] = { 2960 2964 &bitmap_space.attr, 2961 2965 &bitmap_timeout.attr, 2962 2966 &bitmap_backlog.attr, ··· 2971 2967 NULL 2972 2968 }; 2973 2969 2974 - static struct attribute_group md_bitmap_group = { 2970 + static struct attribute_group md_bitmap_common_group = { 2975 2971 .name = "bitmap", 2976 - .attrs = md_bitmap_attrs, 2972 + .attrs = md_bitmap_common_attrs, 2973 + }; 2974 + 2975 + static struct attribute_group md_bitmap_internal_group = { 2976 + .name = "bitmap", 2977 + .attrs = md_bitmap_internal_attrs, 2978 + }; 2979 + 2980 + static const struct attribute_group *bitmap_groups[] = { 2981 + &md_bitmap_common_group, 2982 + &md_bitmap_internal_group, 2983 + NULL, 2977 2984 }; 2978 2985 2979 2986 static struct bitmap_operations bitmap_ops = { ··· 3028 3013 .set_pages = bitmap_set_pages, 3029 3014 .free = md_bitmap_free, 3030 3015 3031 - .group = &md_bitmap_group, 3016 + .groups = bitmap_groups, 3032 3017 }; 3033 3018 3034 3019 int md_bitmap_init(void)
+1 -1
drivers/md/md-bitmap.h
··· 125 125 void (*set_pages)(void *data, unsigned long pages); 126 126 void (*free)(void *data); 127 127 128 - struct attribute_group *group; 128 + const struct attribute_group **groups; 129 129 }; 130 130 131 131 /* the bitmap API */
+6 -1
drivers/md/md-llbitmap.c
··· 1738 1738 .attrs = md_llbitmap_attrs, 1739 1739 }; 1740 1740 1741 + static const struct attribute_group *md_llbitmap_groups[] = { 1742 + &md_llbitmap_group, 1743 + NULL, 1744 + }; 1745 + 1741 1746 static struct bitmap_operations llbitmap_ops = { 1742 1747 .head = { 1743 1748 .type = MD_BITMAP, ··· 1779 1774 .dirty_bits = llbitmap_dirty_bits, 1780 1775 .write_all = llbitmap_write_all, 1781 1776 1782 - .group = &md_llbitmap_group, 1777 + .groups = md_llbitmap_groups, 1783 1778 }; 1784 1779 1785 1780 int md_llbitmap_init(void)
+14 -7
drivers/md/md.c
··· 681 681 682 682 static void md_bitmap_sysfs_add(struct mddev *mddev) 683 683 { 684 - if (sysfs_create_group(&mddev->kobj, mddev->bitmap_ops->group)) 684 + if (sysfs_update_groups(&mddev->kobj, mddev->bitmap_ops->groups)) 685 685 pr_warn("md: cannot register extra bitmap attributes for %s\n", 686 686 mdname(mddev)); 687 687 else ··· 694 694 695 695 static void md_bitmap_sysfs_del(struct mddev *mddev) 696 696 { 697 - sysfs_remove_group(&mddev->kobj, mddev->bitmap_ops->group); 697 + int nr_groups = 0; 698 + 699 + for (nr_groups = 0; mddev->bitmap_ops->groups[nr_groups]; nr_groups++) 700 + ; 701 + 702 + while (--nr_groups >= 1) 703 + sysfs_unmerge_group(&mddev->kobj, 704 + mddev->bitmap_ops->groups[nr_groups]); 705 + sysfs_remove_group(&mddev->kobj, mddev->bitmap_ops->groups[0]); 698 706 } 699 707 700 708 static bool mddev_set_bitmap_ops_nosysfs(struct mddev *mddev) 701 709 { 702 - struct bitmap_operations *old = mddev->bitmap_ops; 703 710 struct md_submodule_head *head; 704 711 705 - if (mddev->bitmap_id == ID_BITMAP_NONE || 706 - (old && old->head.id == mddev->bitmap_id)) 712 + if (mddev->bitmap_ops && 713 + mddev->bitmap_ops->head.id == mddev->bitmap_id) 707 714 return true; 708 715 709 716 xa_lock(&md_submodule); ··· 6588 6581 if (err) 6589 6582 return err; 6590 6583 6591 - if (!mddev_is_dm(mddev) && mddev->bitmap_ops->group) 6584 + if (!mddev_is_dm(mddev) && mddev->bitmap_ops->groups) 6592 6585 md_bitmap_sysfs_add(mddev); 6593 6586 6594 6587 return 0; ··· 6606 6599 static void md_bitmap_destroy(struct mddev *mddev) 6607 6600 { 6608 6601 if (!mddev_is_dm(mddev) && mddev->bitmap_ops && 6609 - mddev->bitmap_ops->group) 6602 + mddev->bitmap_ops->groups) 6610 6603 md_bitmap_sysfs_del(mddev); 6611 6604 6612 6605 md_bitmap_destroy_nosysfs(mddev);