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: factor bitmap creation away from sysfs handling

Factor bitmap creation and destruction into helpers that do not touch
bitmap sysfs registration.

This prepares the bitmap sysfs rework so callers such as the sysfs
bitmap location path can create or destroy a bitmap backend without
coupling that to sysfs group lifetime management.

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

+49 -29
+49 -29
drivers/md/md.c
··· 679 679 680 680 static void no_op(struct percpu_ref *r) {} 681 681 682 - static bool mddev_set_bitmap_ops(struct mddev *mddev) 682 + static void md_bitmap_sysfs_add(struct mddev *mddev) 683 + { 684 + if (sysfs_create_group(&mddev->kobj, mddev->bitmap_ops->group)) 685 + pr_warn("md: cannot register extra bitmap attributes for %s\n", 686 + mdname(mddev)); 687 + else 688 + /* 689 + * Inform user with KOBJ_CHANGE about new bitmap 690 + * attributes. 691 + */ 692 + kobject_uevent(&mddev->kobj, KOBJ_CHANGE); 693 + } 694 + 695 + static void md_bitmap_sysfs_del(struct mddev *mddev) 696 + { 697 + sysfs_remove_group(&mddev->kobj, mddev->bitmap_ops->group); 698 + } 699 + 700 + static bool mddev_set_bitmap_ops_nosysfs(struct mddev *mddev) 683 701 { 684 702 struct bitmap_operations *old = mddev->bitmap_ops; 685 703 struct md_submodule_head *head; ··· 721 703 722 704 mddev->bitmap_ops = (void *)head; 723 705 xa_unlock(&md_submodule); 724 - 725 - if (!mddev_is_dm(mddev) && mddev->bitmap_ops->group) { 726 - if (sysfs_create_group(&mddev->kobj, mddev->bitmap_ops->group)) 727 - pr_warn("md: cannot register extra bitmap attributes for %s\n", 728 - mdname(mddev)); 729 - else 730 - /* 731 - * Inform user with KOBJ_CHANGE about new bitmap 732 - * attributes. 733 - */ 734 - kobject_uevent(&mddev->kobj, KOBJ_CHANGE); 735 - } 736 706 return true; 737 707 738 708 err: 739 709 xa_unlock(&md_submodule); 740 710 return false; 741 - } 742 - 743 - static void mddev_clear_bitmap_ops(struct mddev *mddev) 744 - { 745 - if (!mddev_is_dm(mddev) && mddev->bitmap_ops && 746 - mddev->bitmap_ops->group) 747 - sysfs_remove_group(&mddev->kobj, mddev->bitmap_ops->group); 748 - 749 - mddev->bitmap_ops = NULL; 750 711 } 751 712 752 713 int mddev_init(struct mddev *mddev) ··· 6528 6531 return id; 6529 6532 } 6530 6533 6531 - static int md_bitmap_create(struct mddev *mddev) 6534 + static int md_bitmap_create_nosysfs(struct mddev *mddev) 6532 6535 { 6533 6536 enum md_submodule_id orig_id = mddev->bitmap_id; 6534 6537 enum md_submodule_id sb_id; ··· 6537 6540 if (mddev->bitmap_id == ID_BITMAP_NONE) 6538 6541 return -EINVAL; 6539 6542 6540 - if (!mddev_set_bitmap_ops(mddev)) 6543 + if (!mddev_set_bitmap_ops_nosysfs(mddev)) 6541 6544 return -ENOENT; 6542 6545 6543 6546 err = mddev->bitmap_ops->create(mddev); ··· 6549 6552 * doesn't match, and mdadm is not the latest version to set 6550 6553 * bitmap_type, set bitmap_ops based on the disk version. 6551 6554 */ 6552 - mddev_clear_bitmap_ops(mddev); 6555 + mddev->bitmap_ops = NULL; 6553 6556 6554 6557 sb_id = md_bitmap_get_id_from_sb(mddev); 6555 6558 if (sb_id == ID_BITMAP_NONE || sb_id == orig_id) ··· 6559 6562 mdname(mddev), orig_id, sb_id); 6560 6563 6561 6564 mddev->bitmap_id = sb_id; 6562 - if (!mddev_set_bitmap_ops(mddev)) { 6565 + if (!mddev_set_bitmap_ops_nosysfs(mddev)) { 6563 6566 mddev->bitmap_id = orig_id; 6564 6567 return -ENOENT; 6565 6568 } 6566 6569 6567 6570 err = mddev->bitmap_ops->create(mddev); 6568 6571 if (err) { 6569 - mddev_clear_bitmap_ops(mddev); 6572 + mddev->bitmap_ops = NULL; 6570 6573 mddev->bitmap_id = orig_id; 6571 6574 } 6572 6575 6573 6576 return err; 6574 6577 } 6575 6578 6576 - static void md_bitmap_destroy(struct mddev *mddev) 6579 + static int md_bitmap_create(struct mddev *mddev) 6580 + { 6581 + int err; 6582 + 6583 + err = md_bitmap_create_nosysfs(mddev); 6584 + if (err) 6585 + return err; 6586 + 6587 + if (!mddev_is_dm(mddev) && mddev->bitmap_ops->group) 6588 + md_bitmap_sysfs_add(mddev); 6589 + 6590 + return 0; 6591 + } 6592 + 6593 + static void md_bitmap_destroy_nosysfs(struct mddev *mddev) 6577 6594 { 6578 6595 if (!md_bitmap_registered(mddev)) 6579 6596 return; 6580 6597 6581 6598 mddev->bitmap_ops->destroy(mddev); 6582 - mddev_clear_bitmap_ops(mddev); 6599 + mddev->bitmap_ops = NULL; 6600 + } 6601 + 6602 + static void md_bitmap_destroy(struct mddev *mddev) 6603 + { 6604 + if (!mddev_is_dm(mddev) && mddev->bitmap_ops && 6605 + mddev->bitmap_ops->group) 6606 + md_bitmap_sysfs_del(mddev); 6607 + 6608 + md_bitmap_destroy_nosysfs(mddev); 6583 6609 } 6584 6610 6585 6611 int md_run(struct mddev *mddev)