]> git.ipfire.org Git - thirdparty/mdadm.git/blobdiff - Detail.c
Explain the read-balancing algorithm for RAID1 better in md.4
[thirdparty/mdadm.git] / Detail.c
index ca34f1d48f125618bf33b554c7c96385296772d9..ed100fa1bbba104507884cd6c8e86d5ce1571877 100644 (file)
--- a/Detail.c
+++ b/Detail.c
@@ -31,7 +31,7 @@
 #include       "md_p.h"
 #include       "md_u.h"
 
-int Detail(char *dev, int brief, int test, char *homehost)
+int Detail(char *dev, int brief, int export, int test, char *homehost)
 {
        /*
         * Print out details for an md array by using
@@ -58,6 +58,8 @@ int Detail(char *dev, int brief, 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",
@@ -128,7 +130,19 @@ int Detail(char *dev, int brief, int test, char *homehost)
 
        /* Ok, we have some info to print... */
        c = map_num(pers, array.level);
-       if (brief) 
+
+       if (export) {
+               if (c)
+                       printf("MD_LEVEL=%s\n", c);
+               printf("MD_DEVICES=%d\n", array.raid_disks);
+               printf("MD_METADATA=%d.%d\n", array.major_version,
+                      array.minor_version);
+               if (super)
+                       st->ss->export_super(super);
+               goto out;
+       }
+
+       if (brief)
                printf("ARRAY %s level=%s num-devices=%d", dev, c?c:"-unknown-",array.raid_disks );
        else {
                mdu_bitmap_file_t bmf;
@@ -290,6 +304,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];
@@ -336,10 +351,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) {
@@ -360,7 +378,12 @@ This is pretty boring
 
        if (brief > 1 && devices) printf("\n   devices=%s", devices);
        if (brief) printf("\n");
-       if (test && (rv&2)) rv &= ~1;
+       if (test &&
+           !enough(array.level, array.raid_disks, array.layout,
+                   1, avail, avail_disks))
+               rv = 2;
+
+out:
        close(fd);
        return rv;
 }