diff mbox series

[1/2] mdadm/Manage: Clear superblock if adding new device fails

Message ID 20241018082203.59963-2-xni@redhat.com (mailing list archive)
State Superseded
Headers show
Series mdadm: minor fixes | expand

Checks

Context Check Description
mdraidci/vmtest-md-6_13-PR fail merge-conflict

Commit Message

Xiao Ni Oct. 18, 2024, 8:22 a.m. UTC
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>
---
 Manage.c | 4 ++++
 1 file changed, 4 insertions(+)
diff mbox series

Patch

diff --git a/Manage.c b/Manage.c
index 246ef3194aaa..a1eb0d6740b4 100644
--- 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;
+	int add_new_super = 0;
 
 	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 = 1;
 	} 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;
 }