]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
Make return code for "--detail --test" more reliable.
authorNeil Brown <neilb@suse.de>
Mon, 21 May 2007 04:25:50 +0000 (14:25 +1000)
committerNeil Brown <neilb@suse.de>
Mon, 21 May 2007 04:25:50 +0000 (14:25 +1000)
Missing devices as well as failed devices cause an error.

ChangeLog
Detail.c
mdadm.8

index 2d81c3da7842538ba029c67ac910c0f019b17bdd..d92f5ef00de22adc363e40389f3c959e6544cb16 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -8,6 +8,8 @@ Changes Prior to this release
     -   Various manpage updates.
     -   Make "--grow --add" for linear arrays really work.
     -   --auto-detect to trigger in-kernel autodetect.
+    -   Make return code for "--detail --test" more reliable.  Missing
+       devices as well as failed devices cause an error.
 
 Changes Prior to 2.6.1 release
     -   --monitor was producing some meaningless warnings due to a bug.
index 58de67e1cd34d9ff25cca91891a5252d431f92d9..0ed81d121fc9e01f39439f3faeb1d9301c835826 100644 (file)
--- a/Detail.c
+++ b/Detail.c
@@ -58,6 +58,8 @@ int Detail(char *dev, int brief, int export, int test, char *homehost)
 
        void *super = NULL;
        int rv = test ? 4 : 1;
+       int avail_disks = 0;
+       char *avail;
 
        if (fd < 0) {
                fprintf(stderr, Name ": cannot open %s: %s\n",
@@ -301,6 +303,7 @@ This is pretty boring
                        disks[next++] = disk;
        }
 
+       avail = calloc(array.raid_disks, 1);
        for (d= 0; d < max_disks; d++) {
                char *dv;
                mdu_disk_info_t disk = disks[d];
@@ -347,10 +350,13 @@ This is pretty boring
                        }
                }
                if (disk.state == 0) spares++;
-               if (test && d < array.raid_disks && disk.state & (1<<MD_DISK_FAULTY)) {
-                       if ((rv & 1) && (array.level ==4 || array.level == 5))
-                               rv |= 2;
+               if (test && d < array.raid_disks
+                   && !(disk.state & (1<<MD_DISK_SYNC)))
                        rv |= 1;
+               if (d < array.raid_disks
+                   && (disk.state & (1<<MD_DISK_SYNC))) {
+                       avail_disks ++;
+                       avail[d] = 1;
                }
                if ((dv=map_dev(disk.major, disk.minor, 0))) {
                        if (brief) {
@@ -372,7 +378,11 @@ This is pretty boring
        if (brief > 1 && devices) printf("\n   devices=%s", devices);
        if (brief) printf("\n");
 out:
-       if (test && (rv&2)) rv &= ~1;
+       if (test &&
+           !enough(array.level, array.raid_disks, array.layout,
+                   1, avail, avail_disks))
+               rv = 2;
+
        close(fd);
        return rv;
 }
diff --git a/mdadm.8 b/mdadm.8
index e70a1a92cb53201319c5d1eafda3bb61571872c1..0d3adfc37d5b80e78520f68af86962a5b5d1e896 100644 (file)
--- a/mdadm.8
+++ b/mdadm.8
@@ -1457,8 +1457,7 @@ The array is functioning normally.
 The array has at least one failed device.
 .TP
 2
-The array has multiple failed devices and hence is unusable (raid4 or
-raid5).
+The array has multiple failed devices such that it is unusable.
 .TP
 4
 There was an error while trying to get information about the device.