]> git.ipfire.org Git - thirdparty/mdadm.git/blobdiff - Detail.c
super1: Avoid if and return on the same line
[thirdparty/mdadm.git] / Detail.c
index 83395f641aa9ca9b170cb6226281e6d883ce9e55..7a984c83b3fb6fb97bb813586fe95b0b4ebd23de 100644 (file)
--- a/Detail.c
+++ b/Detail.c
@@ -1,7 +1,7 @@
 /*
  * mdadm - manage Linux "md" devices aka RAID arrays.
  *
- * Copyright (C) 2001-2012 Neil Brown <neilb@suse.de>
+ * Copyright (C) 2001-2013 Neil Brown <neilb@suse.de>
  *
  *
  *    This program is free software; you can redistribute it and/or modify
@@ -109,7 +109,7 @@ int Detail(char *dev, struct context *c)
        st = super_by_fd(fd, &subarray);
        if (ioctl(fd, GET_ARRAY_INFO, &array) == 0) {
                inactive = 0;
-       } else if (errno == ENODEV) {
+       } else if (errno == ENODEV && sra) {
                array = sra->array;
                inactive = 1;
        } else {
@@ -130,7 +130,7 @@ int Detail(char *dev, struct context *c)
                /* This is a subarray of some container.
                 * We want the name of the container, and the member
                 */
-               int devid = devnm2devid(st->container_devnm);
+               dev_t devid = devnm2devid(st->container_devnm);
                int cfd, err;
 
                member = subarray;
@@ -295,11 +295,12 @@ int Detail(char *dev, struct context *c)
                goto out;
        }
 
-       disks = xmalloc(max_disks * sizeof(mdu_disk_info_t));
-       for (d = 0; d < max_disks; d++) {
+       disks = xmalloc(max_disks * 2 * sizeof(mdu_disk_info_t));
+       for (d = 0; d < max_disks * 2; d++) {
                disks[d].state = (1<<MD_DISK_REMOVED);
                disks[d].major = disks[d].minor = 0;
-               disks[d].number = disks[d].raid_disk = d;
+               disks[d].number = -1;
+               disks[d].raid_disk = d/2;
        }
 
        next = array.raid_disks*2;
@@ -325,9 +326,10 @@ int Detail(char *dev, struct context *c)
                    && disks[disk.raid_disk*2].state == (1<<MD_DISK_REMOVED))
                        disks[disk.raid_disk*2] = disk;
                else if (disk.raid_disk >= 0 && disk.raid_disk < array.raid_disks
-                        && disks[disk.raid_disk*2+1].state == (1<<MD_DISK_REMOVED))
+                        && disks[disk.raid_disk*2+1].state == (1<<MD_DISK_REMOVED)
+                        && !(disk.state & (1<<MD_DISK_JOURNAL)))
                        disks[disk.raid_disk*2+1] = disk;
-               else if (next < max_disks)
+               else if (next < max_disks*2)
                        disks[next++] = disk;
        }
 
@@ -339,7 +341,8 @@ int Detail(char *dev, struct context *c)
                    (disks[d*2+1].state & (1<<MD_DISK_SYNC))) {
                        avail_disks ++;
                        avail[d] = 1;
-               }
+               } else
+                       rv |= !! c->test;
        }
 
        if (c->brief) {
@@ -422,8 +425,9 @@ int Detail(char *dev, struct context *c)
                                else
                                        printf("  Used Dev Size : unknown\n");
                        } else
-                               printf("  Used Dev Size : %d%s\n", array.size,
-                                      human_size((long long)array.size<<10));
+                               printf("  Used Dev Size : %lu%s\n",
+                                      (unsigned long)array.size,
+                                      human_size((unsigned long long)array.size<<10));
                }
                if (array.raid_disks)
                        printf("   Raid Devices : %d\n", array.raid_disks);
@@ -465,8 +469,8 @@ int Detail(char *dev, struct context *c)
                               (!e || (e->percent < 0 && e->percent != RESYNC_PENDING &&
                               e->percent != RESYNC_DELAYED)) ? "" : sync_action[e->resync],
                               larray_size ? "": ", Not Started",
-                              e->percent == RESYNC_DELAYED ? " (DELAYED)": "",
-                              e->percent == RESYNC_PENDING ? " (PENDING)": "");
+                              (e && e->percent == RESYNC_DELAYED) ? " (DELAYED)": "",
+                              (e && e->percent == RESYNC_PENDING) ? " (PENDING)": "");
                } else if (inactive) {
                        printf("          State : inactive\n");
                }
@@ -573,12 +577,12 @@ This is pretty boring
                                char path[200];
                                char vbuf[1024];
                                int nlen = strlen(sra->sys_name);
-                               int devid;
+                               dev_t devid;
                                if (de->d_name[0] == '.')
                                        continue;
                                sprintf(path, "/sys/block/%s/md/metadata_version",
                                        de->d_name);
-                               if (load_sys(path, vbuf) < 0)
+                               if (load_sys(path, vbuf, sizeof(vbuf)) < 0)
                                        continue;
                                if (strncmp(vbuf, "external:", 9) != 0 ||
                                    !is_subarray(vbuf+9) ||
@@ -602,7 +606,7 @@ This is pretty boring
        }
        free(info);
 
-       for (d= 0; d < max_disks; d++) {
+       for (d= 0; d < max_disks * 2; d++) {
                char *dv;
                mdu_disk_info_t disk = disks[d];
 
@@ -616,12 +620,15 @@ This is pretty boring
                        continue;
                if (!c->brief) {
                        if (d == array.raid_disks*2) printf("\n");
-                       if (disk.number < 0)
+                       if (disk.number < 0 && disk.raid_disk < 0)
                                printf("       -   %5d    %5d        -     ",
                                       disk.major, disk.minor);
-                       else if (disk.raid_disk < 0)
+                       else if (disk.raid_disk < 0 || disk.state & (1<<MD_DISK_JOURNAL))
                                printf("   %5d   %5d    %5d        -     ",
                                       disk.number, disk.major, disk.minor);
+                       else if (disk.number < 0)
+                               printf("       -   %5d    %5d    %5d     ",
+                                      disk.major, disk.minor, disk.raid_disk);
                        else
                                printf("   %5d   %5d    %5d    %5d     ",
                                       disk.number, disk.major, disk.minor, disk.raid_disk);
@@ -650,9 +657,10 @@ This is pretty boring
                        }
                        if (disk.state & (1<<MD_DISK_REMOVED)) printf(" removed");
                        if (disk.state & (1<<MD_DISK_WRITEMOSTLY)) printf(" writemostly");
+                       if (disk.state & (1<<MD_DISK_JOURNAL)) printf(" journal");
                        if ((disk.state &
                             ((1<<MD_DISK_ACTIVE)|(1<<MD_DISK_SYNC)
-                             |(1<<MD_DISK_REMOVED)|(1<<MD_DISK_FAULTY)))
+                             |(1<<MD_DISK_REMOVED)|(1<<MD_DISK_FAULTY)|(1<<MD_DISK_JOURNAL)))
                            == 0) {
                                printf(" spare");
                                if (is_26) {
@@ -671,9 +679,6 @@ This is pretty boring
                        }
                }
                if (disk.state == 0) spares++;
-               if (c->test && d < array.raid_disks
-                   && !(disk.state & (1<<MD_DISK_SYNC)))
-                       rv |= 1;
                dv=map_dev_preferred(disk.major, disk.minor, 0, c->prefer);
                if (dv != NULL) {
                        if (c->brief)