]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
Manage: fix removal of non-existent devices.
authorNeilBrown <neilb@suse.de>
Mon, 11 Aug 2014 00:30:42 +0000 (10:30 +1000)
committerNeilBrown <neilb@suse.de>
Mon, 11 Aug 2014 00:34:41 +0000 (10:34 +1000)
"--remove detached" and others stopped working a while
back when I refactored some code.
For 'remove' and  'fail', the device may not exist so
if it is  "MM:mm", (e.g. added by "detached"), just parse
out the numbers.

Reported-by: Killian De Volder <killian.de.volder@megasoft.be>
Signed-off-by: NeilBrown <neilb@suse.de>
Manage.c

index 3bbdffb8d69fdfc9027af0f84bd25fb97ba14ebf..206f34efcc07a548e0d95c00341ca48c7ae6dcc3 100644 (file)
--- a/Manage.c
+++ b/Manage.c
@@ -1298,6 +1298,7 @@ int Manage_subdevs(char *devname, int fd,
        for (dv = devlist; dv; dv = dv->next) {
                unsigned long rdev = 0; /* device to add/remove etc */
                int rv;
+               int mj,mn;
 
                if (strcmp(dv->devname, "failed") == 0 ||
                    strcmp(dv->devname, "faulty") == 0) {
@@ -1390,7 +1391,6 @@ int Manage_subdevs(char *devname, int fd,
                        sysfd = sysfs_open(fd2devnm(fd), dname, "block/dev");
                        if (sysfd >= 0) {
                                char dn[20];
-                               int mj,mn;
                                if (sysfs_fd_get_str(sysfd, dn, 20) > 0 &&
                                    sscanf(dn, "%d:%d", &mj,&mn) == 2) {
                                        rdev = makedev(mj,mn);
@@ -1408,6 +1408,12 @@ int Manage_subdevs(char *devname, int fd,
                                        goto abort;
                                }
                        }
+               } else if ((dv->disposition == 'r' || dv->disposition == 'f')
+                          && get_maj_min(dv->devname, &mj, &mn)) {
+                       /* for 'fail' and 'remove', the device might
+                        * not exist.
+                        */
+                       rdev = makedev(mj, mn);
                } else {
                        struct stat stb;
                        tfd = dev_open(dv->devname, O_RDONLY);