]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
mdadm/Manage: Clear superblock if adding new device fails
authorXiao Ni <xni@redhat.com>
Fri, 18 Oct 2024 08:48:16 +0000 (16:48 +0800)
committerMariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
Fri, 18 Oct 2024 12:50:01 +0000 (14:50 +0200)
The superblock is kept if adding new device fails. It should clear the
superblock if it fails to add a new disk.

Signed-off-by: Xiao Ni <xni@redhat.com>
Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
Manage.c

index 246ef3194aaaf69b8fe86e5f117357422d593490..8c58683b83c1f1b1fbe63a783708b6cfe9623f24 100644 (file)
--- a/Manage.c
+++ b/Manage.c
@@ -793,6 +793,7 @@ int Manage_add(int fd, int tfd, struct mddev_dev *dv,
        int j;
        mdu_disk_info_t disc;
        struct map_ent *map = NULL;
+       bool add_new_super = false;
 
        if (!get_dev_size(tfd, dv->devname, &ldsize)) {
                if (dv->disposition == 'M')
@@ -1011,6 +1012,7 @@ int Manage_add(int fd, int tfd, struct mddev_dev *dv,
                        goto unlock;
                if (tst->ss->write_init_super(tst))
                        goto unlock;
+               add_new_super = true;
        } else if (dv->disposition == 'A') {
                /*  this had better be raid1.
                 * As we are "--re-add"ing we must find a spare slot
@@ -1078,6 +1080,8 @@ int Manage_add(int fd, int tfd, struct mddev_dev *dv,
        map_unlock(&map);
        return 1;
 unlock:
+       if (add_new_super)
+               Kill(dv->devname, tst, 0, -1, 0);
        map_unlock(&map);
        return -1;
 }