]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
Detail: handle non-existent arrays better.
authorNeilBrown <neilb@suse.com>
Mon, 27 Mar 2017 03:36:56 +0000 (14:36 +1100)
committerJes Sorensen <Jes.Sorensen@gmail.com>
Tue, 28 Mar 2017 18:33:48 +0000 (14:33 -0400)
If you call "mdadm --detail" with a device file for an array which
doesn't exist, such as by
  mknod /dev/md57 b 9 57
  mdadm --detail /dev/md57

you get an unhelpful message about and inactive RAID0, and return
status is '0'.  This is confusing.

So catch this possibility and print a more useful message, and
return a non-zero status.

Signed-off-by: NeilBrown <neilb@suse.com>
Signed-off-by: Jes Sorensen <Jes.Sorensen@gmail.com>
Detail.c

index cb337947ac56392faa2396dc5b285361ab9fa211..3d928553e5dab31e85ef6f8349a499f21edfb725 100644 (file)
--- a/Detail.c
+++ b/Detail.c
@@ -110,6 +110,14 @@ int Detail(char *dev, struct context *c)
        if (ioctl(fd, GET_ARRAY_INFO, &array) == 0) {
                inactive = 0;
        } else if (errno == ENODEV && sra) {
+               if (sra->array.major_version == -1 &&
+                   sra->array.minor_version == -1 &&
+                   sra->devs == NULL) {
+                       pr_err("Array associated with md device %s does not exist.\n", dev);
+                       close(fd);
+                       sysfs_free(sra);
+                       return rv;
+               }
                array = sra->array;
                inactive = 1;
        } else {