]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
Manage: fix regression on removing detached devices.
authorNeilBrown <neilb@suse.de>
Wed, 3 Mar 2010 02:16:24 +0000 (13:16 +1100)
committerNeilBrown <neilb@suse.de>
Wed, 3 Mar 2010 02:16:24 +0000 (13:16 +1100)
If /dev is static, a name may remain there after the
device has been detached from the system.
Using 'mdadm' to remove such a device from the array
should still work (even though "mdadm --remove detached"
might be preferred).

So when processing a device for '-r', don't insist on
being able to open the device.

Signed-off-by: NeilBrown <neilb@suse.de>
Manage.c

index 749fa7c1b8f8b83676e2b5f45c27d83ee2a4666d..6d94836f230c24c0b87d7f049047daee047c1b7a 100644 (file)
--- a/Manage.c
+++ b/Manage.c
@@ -425,14 +425,22 @@ int Manage_subdevs(char *devname, int fd,
                        j = 0;
 
                        tfd = dev_open(dv->devname, O_RDONLY);
-                       if (tfd < 0 || fstat(tfd, &stb) != 0) {
-                               fprintf(stderr, Name ": cannot find %s: %s\n",
-                                       dv->devname, strerror(errno));
-                               if (tfd >= 0)
-                                       close(tfd);
-                               return 1;
+                       if (tfd < 0 && dv->disposition == 'r' &&
+                           lstat(dv->devname, &stb) == 0)
+                               /* Be happy, the lstat worked, that is
+                                * enough for --remove
+                                */
+                               ;
+                       else {
+                               if (tfd < 0 || fstat(tfd, &stb) != 0) {
+                                       fprintf(stderr, Name ": cannot find %s: %s\n",
+                                               dv->devname, strerror(errno));
+                                       if (tfd >= 0)
+                                               close(tfd);
+                                       return 1;
+                               }
+                               close(tfd);
                        }
-                       close(tfd);
                        if ((stb.st_mode & S_IFMT) != S_IFBLK) {
                                fprintf(stderr, Name ": %s is not a "
                                        "block device.\n",