]> git.ipfire.org Git - thirdparty/mdadm.git/blobdiff - Manage.c
imsm: kill "auto=" in brief_examine_super_imsm
[thirdparty/mdadm.git] / Manage.c
index 9424650301ddef0d7f44c4ccc94c78b891106f4c..65235bc1836f5e02c22c3e703cea2f39789b8023 100644 (file)
--- a/Manage.c
+++ b/Manage.c
@@ -150,10 +150,12 @@ static void remove_devices(int devnum, char *path)
        for (part = 0; part < 16; part++) {
                if (part) {
                        sprintf(be, "p%d", part);
-                       if (isdigit(pe[-1]))
-                               sprintf(pe, "p%d", part);
-                       else
-                               sprintf(pe, "%d", part);
+                       if (path) {
+                               if (isdigit(pe[-1]))
+                                       sprintf(pe, "p%d", part);
+                               else
+                                       sprintf(pe, "%d", part);
+                       }
                }
                /* FIXME test if really is md device ?? */
                unlink(base);
@@ -586,6 +588,11 @@ int Manage_subdevs(char *devname, int fd,
                                                                fprintf(stderr, Name ": re-added %s\n", dv->devname);
                                                        continue;
                                                }
+                                               if (errno == ENOMEM || errno == EROFS) {
+                                                       fprintf(stderr, Name ": add new device failed for %s: %s\n",
+                                                               dv->devname, strerror(errno));
+                                                       return 1;
+                                               }
                                                /* fall back on normal-add */
                                        }
                                }
@@ -622,8 +629,11 @@ int Manage_subdevs(char *devname, int fd,
                                if (dv->writemostly == 1)
                                        disc.state |= 1 << MD_DISK_WRITEMOSTLY;
                                dfd = open(dv->devname, O_RDWR | O_EXCL|O_DIRECT);
-                               tst->ss->add_to_super(tst, &disc, dfd,
-                                                     dv->devname);
+                               if (tst->ss->add_to_super(tst, &disc, dfd,
+                                                         dv->devname)) {
+                                       close(dfd);
+                                       return 1;
+                               }
                                /* write_init_super will close 'dfd' */
                                if (tst->ss->external)
                                        /* mdmon will write the metadata */
@@ -697,7 +707,7 @@ int Manage_subdevs(char *devname, int fd,
                                tst->ss->getinfo_super(tst, &new_mdi);
                                new_mdi.disk.major = disc.major;
                                new_mdi.disk.minor = disc.minor;
-                               if (sysfs_add_disk(sra, &new_mdi) != 0) {
+                               if (sysfs_add_disk(sra, &new_mdi, 0) != 0) {
                                        fprintf(stderr, Name ": add new device to external metadata"
                                                " failed for %s\n", dv->devname);
                                        close(container_fd);
@@ -741,7 +751,14 @@ int Manage_subdevs(char *devname, int fd,
                                                " to container - odd\n");
                                        return 1;
                                }
-                               if (!sysfs_unique_holder(dnum, stb.st_rdev)) {
+                               /* in the detached case it is not possible to
+                                * check if we are the unique holder, so just
+                                * rely on the 'detached' checks
+                                */
+                               if (strcmp(dv->devname, "detached") == 0 ||
+                                   sysfs_unique_holder(dnum, stb.st_rdev))
+                                       /* pass */;
+                               else {
                                        fprintf(stderr, Name
                                                ": %s is %s, cannot remove.\n",
                                                dnprintable,