Re: [PATCH 07/23] md/md-bitmap: delay registration of bitmap_ops until creating bitmap

From: Hannes Reinecke
Date: Tue May 27 2025 - 04:54:13 EST


On 5/27/25 09:53, Yu Kuai wrote:
Hi,

在 2025/05/27 14:13, Hannes Reinecke 写道:
On 5/24/25 08:13, Yu Kuai wrote:
From: Yu Kuai <yukuai3@xxxxxxxxxx>

Currently bitmap_ops is registered while allocating mddev, this is fine
when there is only one bitmap_ops, however, after introduing a new
bitmap_ops, user space need a time window to choose which bitmap_ops to
use while creating new array.

[ .. ]
@@ -6093,11 +6104,6 @@ struct mddev *md_alloc(dev_t dev, char *name)
          return ERR_PTR(error);
      }
-    if (md_bitmap_registered(mddev) && mddev->bitmap_ops->group)
-        if (sysfs_create_group(&mddev->kobj, mddev->bitmap_ops->group))
-            pr_warn("md: cannot register extra bitmap attributes for %s\n",
-                mdname(mddev));
-
      kobject_uevent(&mddev->kobj, KOBJ_ADD);
      mddev->sysfs_state = sysfs_get_dirent_safe(mddev->kobj.sd, "array_state");
      mddev->sysfs_level = sysfs_get_dirent_safe(mddev->kobj.sd, "level");

But now you've killed udev event processing.
Once the 'add' event is sent _all_ sysfs attributes must be present,
otherwise you'll have a race condition where udev is checking for
attributes which are present only later.

So when moving things around ensure to move the kobject_uevent() call, too.

I do not expect the bitmap entries are checked by udev, otherwise this
set can introduce regressions since the bitmap entries are no longer
existed after using the new biltmap.

And the above KOBJ_ADD uevent is used for mddev->kobj, right? In this
case, we're creating new entries under mddev->kobj, should this be
KOBJ_CHANGE?

Yes, please.

Cheers,

Hannes
--
Dr. Hannes Reinecke Kernel Storage Architect
hare@xxxxxxx +49 911 74053 688
SUSE Software Solutions GmbH, Frankenstr. 146, 90461 Nürnberg
HRB 36809 (AG Nürnberg), GF: I. Totev, A. McDonald, W. Knoblich