]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
md: Don't clear MD_CLOSING until mddev is freed
authorXiao Ni <xni@redhat.com>
Wed, 11 Jun 2025 07:31:07 +0000 (15:31 +0800)
committerYu Kuai <yukuai3@huawei.com>
Sat, 12 Jul 2025 09:51:59 +0000 (17:51 +0800)
UNTIL_STOP is used to avoid mddev is freed on the last close before adding
disks to mddev. And it should be cleared when stopping an array which is
mentioned in commit efeb53c0e572 ("md: Allow md devices to be created by
name."). So reset ->hold_active to 0 in md_clean.

And MD_CLOSING should be kept until mddev is freed to avoid reopen.

Reviewed-by: Yu Kuai <yukuai3@huawei.com>
Signed-off-by: Xiao Ni <xni@redhat.com>
Link: https://lore.kernel.org/linux-raid/20250611073108.25463-3-xni@redhat.com
Signed-off-by: Yu Kuai <yukuai3@huawei.com>
drivers/md/md.c

index 7445e44eabff9545878772d0119b2e37e11dabae..dde3d2bfd34db751c803ed00d2a1600685abd78e 100644 (file)
@@ -6425,15 +6425,10 @@ static void md_clean(struct mddev *mddev)
        mddev->persistent = 0;
        mddev->level = LEVEL_NONE;
        mddev->clevel[0] = 0;
-       /*
-        * Don't clear MD_CLOSING, or mddev can be opened again.
-        * 'hold_active != 0' means mddev is still in the creation
-        * process and will be used later.
-        */
-       if (mddev->hold_active)
-               mddev->flags = 0;
-       else
-               mddev->flags &= BIT_ULL_MASK(MD_CLOSING);
+       /* if UNTIL_STOP is set, it's cleared here */
+       mddev->hold_active = 0;
+       /* Don't clear MD_CLOSING, or mddev can be opened again. */
+       mddev->flags &= BIT_ULL_MASK(MD_CLOSING);
        mddev->sb_flags = 0;
        mddev->ro = MD_RDWR;
        mddev->metadata_type[0] = 0;
@@ -6660,9 +6655,6 @@ static int do_md_stop(struct mddev *mddev, int mode)
                export_array(mddev);
                md_clean(mddev);
                set_bit(MD_DELETED, &mddev->flags);
-
-               if (mddev->hold_active == UNTIL_STOP)
-                       mddev->hold_active = 0;
        }
        md_new_event();
        sysfs_notify_dirent_safe(mddev->sysfs_state);