]> git.ipfire.org Git - thirdparty/mdadm.git/blobdiff - Detail.c
mdadm: add map_num_s()
[thirdparty/mdadm.git] / Detail.c
index ad56344f24f4460cd182da37e64911f2d0970d25..ce7a844543181df1d1ed274a3ebeac46324a5dd8 100644 (file)
--- a/Detail.c
+++ b/Detail.c
@@ -66,11 +66,11 @@ int Detail(char *dev, struct context *c)
        int spares = 0;
        struct stat stb;
        int failed = 0;
-       struct supertype *st;
+       struct supertype *st = NULL;
        char *subarray = NULL;
        int max_disks = MD_SB_DISKS; /* just a default */
        struct mdinfo *info = NULL;
-       struct mdinfo *sra;
+       struct mdinfo *sra = NULL;
        struct mdinfo *subdev;
        char *member = NULL;
        char *container = NULL;
@@ -93,8 +93,7 @@ int Detail(char *dev, struct context *c)
        if (!sra) {
                if (md_get_array_info(fd, &array)) {
                        pr_err("%s does not appear to be an md device\n", dev);
-                       close(fd);
-                       return rv;
+                       goto out;
                }
        }
        external = (sra != NULL && sra->array.major_version == -1 &&
@@ -108,16 +107,13 @@ int Detail(char *dev, struct context *c)
                            sra->devs == NULL) {
                                pr_err("Array associated with md device %s does not exist.\n",
                                       dev);
-                               close(fd);
-                               sysfs_free(sra);
-                               return rv;
+                               goto out;
                        }
                        array = sra->array;
                } else {
                        pr_err("cannot get array detail for %s: %s\n",
                               dev, strerror(errno));
-                       close(fd);
-                       return rv;
+                       goto out;
                }
        }
 
@@ -355,14 +351,14 @@ int Detail(char *dev, struct context *c)
        avail = xcalloc(array.raid_disks, 1);
 
        for (d = 0; d < array.raid_disks; d++) {
-               char *dv, *dv_rep;
-               dv = map_dev_preferred(disks[d*2].major,
-                               disks[d*2].minor, 0, c->prefer);
-               dv_rep = map_dev_preferred(disks[d*2+1].major,
-                               disks[d*2+1].minor, 0, c->prefer);
-
-               if ((dv && (disks[d*2].state & (1<<MD_DISK_SYNC))) ||
-                   (dv_rep && (disks[d*2+1].state & (1<<MD_DISK_SYNC)))) {
+               char dv[PATH_MAX], dv_rep[PATH_MAX];
+               snprintf(dv, PATH_MAX, "/sys/dev/block/%d:%d",
+                       disks[d*2].major, disks[d*2].minor);
+               snprintf(dv_rep, PATH_MAX, "/sys/dev/block/%d:%d",
+                       disks[d*2+1].major, disks[d*2+1].minor);
+
+               if ((is_dev_alive(dv) && (disks[d*2].state & (1<<MD_DISK_SYNC))) ||
+                   (is_dev_alive(dv_rep) && (disks[d*2+1].state & (1<<MD_DISK_SYNC)))) {
                        avail_disks ++;
                        avail[d] = 1;
                } else
@@ -499,8 +495,8 @@ int Detail(char *dev, struct context *c)
                        if (array.state & (1 << MD_SB_CLEAN)) {
                                if ((array.level == 0) ||
                                    (array.level == LEVEL_LINEAR))
-                                       arrayst = map_num(sysfs_array_states,
-                                                         sra->array_state);
+                                       arrayst = map_num_s(sysfs_array_states,
+                                                              sra->array_state);
                                else
                                        arrayst = "clean";
                        } else {
@@ -827,10 +823,12 @@ out:
        close(fd);
        free(subarray);
        free(avail);
-       for (d = 0; d < n_devices; d++)
-               free(devices[d]);
+       if (devices)
+               for (d = 0; d < n_devices; d++)
+                       free(devices[d]);
        free(devices);
        sysfs_free(sra);
+       free(st);
        return rv;
 }