]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
Manage: improve error message when given a non-block device.
authorNeilBrown <neilb@suse.de>
Wed, 24 Oct 2012 01:51:14 +0000 (12:51 +1100)
committerNeilBrown <neilb@suse.de>
Wed, 24 Oct 2012 01:51:14 +0000 (12:51 +1100)
As dev_open uses O_DIRECT it will fail on directories and such.
So we never get to report that it isn't a block device.

So do a 'stat' earlier and if it is a block device, report the
error there.

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

index 832e84ce6051f8c4f1b784d1f0b46c987bdcaae3..8ed1a1a7fe34b9c220e9363df36d522fe49ea38d 100644 (file)
--- a/Manage.c
+++ b/Manage.c
@@ -1205,10 +1205,22 @@ int Manage_subdevs(char *devname, int fd,
                                }
                        }
                } else {
+                       if (stat(dv->devname, &stb) != 0) {
+                               pr_err("Cannot find %s: %s\n",
+                                      dv->devname, strerror(errno));
+                               goto abort;
+                       }
+                       if ((stb.st_mode & S_IFMT) != S_IFBLK) {
+                               if (dv->disposition == 'M')
+                                       /* non-fatal. Also improbable */
+                                       continue;
+                               pr_err("%s is not a block device.\n",
+                                       dv->devname);
+                               goto abort;
+                       }
                        tfd = dev_open(dv->devname, O_RDONLY);
-                       if (tfd < 0 && dv->disposition == 'r' &&
-                           lstat(dv->devname, &stb) == 0)
-                               /* Be happy, the lstat worked, that is
+                       if (tfd < 0 && dv->disposition == 'r')
+                               /* Be happy, the stat worked, that is
                                 * enough for --remove
                                 */
                                ;
@@ -1219,22 +1231,13 @@ int Manage_subdevs(char *devname, int fd,
                                        if (dv->disposition == 'M')
                                                /* non-fatal */
                                                continue;
-                                       pr_err("cannot find %s: %s\n",
+                                       pr_err("Cannot open %s: %s\n",
                                                dv->devname, strerror(errno));
                                        goto abort;
                                }
                                close(tfd);
                                tfd = -1;
                        }
-                       if ((stb.st_mode & S_IFMT) != S_IFBLK) {
-                               if (dv->disposition == 'M')
-                                       /* non-fatal. Also improbable */
-                                       continue;
-                               pr_err("%s is not a "
-                                       "block device.\n",
-                                       dv->devname);
-                               goto abort;
-                       }
                }
                switch(dv->disposition){
                default: