]> git.ipfire.org Git - thirdparty/mdadm.git/blobdiff - Manage.c
wait_for improvement.
[thirdparty/mdadm.git] / Manage.c
index 7855e21aa561b5320a08aa0ec5f23f8360aa236a..7afd89b7ce7b56c81aa6871ed8c149961cf02382 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);
@@ -260,8 +262,11 @@ int Manage_runstop(char *devname, int fd, int runstop, int quiet)
                        return 1;
                }
                /* prior to 2.6.28, KOBJ_CHANGE was not sent when an md array
-                * was stopped, so We'll do it here just to be sure.
+                * was stopped, so We'll do it here just to be sure.  Drop any
+                * partitions as well...
                 */
+               if (fd >= 0)
+                       ioctl(fd, BLKRRPART, 0);
                if (mdi)
                        sysfs_uevent(mdi, "change");
 
@@ -619,8 +624,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 */
@@ -738,7 +746,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,