]> git.ipfire.org Git - thirdparty/mdadm.git/blobdiff - Detail.c
mdadm: improve the dlm locking mechanism for clustered raid
[thirdparty/mdadm.git] / Detail.c
index 2332b8526c0f59c63160894888793409de0862ef..4dcf81ddba73200aff32221b2b7c500d83eb2672 100644 (file)
--- a/Detail.c
+++ b/Detail.c
@@ -80,13 +80,15 @@ int Detail(char *dev, struct context *c)
        char *avail = NULL;
        int external;
        int inactive;
+       int is_container = 0;
 
        if (fd < 0) {
                pr_err("cannot open %s: %s\n",
                        dev, strerror(errno));
                return rv;
        }
-       sra = sysfs_read(fd, NULL, GET_VERSION | GET_DEVS | GET_ARRAY_STATE);
+       sra = sysfs_read(fd, NULL, GET_VERSION | GET_DEVS |
+                       GET_ARRAY_STATE | GET_STATE);
        if (!sra) {
                if (md_get_array_info(fd, &array)) {
                        pr_err("%s does not appear to be an md device\n", dev);
@@ -96,8 +98,7 @@ int Detail(char *dev, struct context *c)
        }
        external = (sra != NULL && sra->array.major_version == -1 &&
                    sra->array.minor_version == -2);
-       inactive = (sra->array_state == ARRAY_ACTIVE ||
-                   sra->array_state == ARRAY_CLEAR);
+       inactive = (sra != NULL && !md_array_is_active(sra));
        st = super_by_fd(fd, &subarray);
        if (md_get_array_info(fd, &array)) {
                if (errno == ENODEV) {
@@ -119,6 +120,8 @@ int Detail(char *dev, struct context *c)
                }
        }
 
+       if (array.raid_disks == 0 && external)
+               is_container = 1;
        if (fstat(fd, &stb) != 0 && !S_ISBLK(stb.st_mode))
                stb.st_rdev = 0;
        rv = 0;
@@ -228,7 +231,7 @@ int Detail(char *dev, struct context *c)
                                printf("MD_LEVEL=%s\n", str);
                        printf("MD_DEVICES=%d\n", array.raid_disks);
                } else {
-                       if (!inactive)
+                       if (is_container)
                                printf("MD_LEVEL=container\n");
                        printf("MD_DEVICES=%d\n", array.nr_disks);
                }
@@ -314,11 +317,10 @@ int Detail(char *dev, struct context *c)
        next = array.raid_disks * 2;
        if (inactive) {
                struct mdinfo *mdi;
-               if (sra != NULL)
-                       for (mdi = sra->devs; mdi; mdi = mdi->next) {
-                               disks[next++] = mdi->disk;
-                               disks[next - 1].number = -1;
-                       }
+               for (mdi = sra->devs; mdi; mdi = mdi->next) {
+                       disks[next++] = mdi->disk;
+                       disks[next - 1].number = -1;
+               }
        } else for (d = 0; d < max_disks; d++) {
                mdu_disk_info_t disk;
                disk.number = d;
@@ -358,13 +360,16 @@ int Detail(char *dev, struct context *c)
 
        if (c->brief) {
                mdu_bitmap_file_t bmf;
-               printf("%sARRAY %s", inactive ? "INACTIVE-":"", dev);
+               if (inactive && !is_container)
+                       printf("INACTIVE-ARRAY %s", dev);
+               else
+                       printf("ARRAY %s", dev);
                if (c->verbose > 0) {
                        if (array.raid_disks)
                                printf(" level=%s num-devices=%d",
                                       str ? str : "-unknown-",
                                       array.raid_disks);
-                       else if (!inactive)
+                       else if (is_container)
                                printf(" level=container num-devices=%d",
                                       array.nr_disks);
                        else
@@ -417,7 +422,7 @@ int Detail(char *dev, struct context *c)
                atime = array.ctime;
                if (atime)
                        printf("     Creation Time : %.24s\n", ctime(&atime));
-               if (array.raid_disks == 0 && external)
+               if (is_container)
                        str = "container";
                if (str)
                        printf("        Raid Level : %s\n", str);
@@ -490,7 +495,7 @@ int Detail(char *dev, struct context *c)
                               " (DELAYED)": "",
                               (e && e->percent == RESYNC_PENDING) ?
                               " (PENDING)": "");
-               } else if (inactive) {
+               } else if (inactive && !is_container) {
                        printf("             State : inactive\n");
                }
                if (array.raid_disks)