]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
Use sysfs info for metadata version info in Detail and elsewhere.
authorNeil Brown <neilb@suse.de>
Fri, 14 Dec 2007 09:15:21 +0000 (20:15 +1100)
committerNeil Brown <neilb@suse.de>
Fri, 14 Dec 2007 09:15:21 +0000 (20:15 +1100)
Detail.c
sysfs.c
util.c

index 5a408ec081c957fbf4f205ce4d230a592955f913..de1f409e8fe8498fc100e963f42f30a7c0095b1c 100644 (file)
--- a/Detail.c
+++ b/Detail.c
@@ -55,6 +55,7 @@ int Detail(char *dev, int brief, int export, int test, char *homehost)
        struct supertype *st = NULL;
        int max_disks = MD_SB_DISKS; /* just a default */
        struct mdinfo info;
+       struct mdinfo *sra;
 
        int rv = test ? 4 : 1;
        int avail_disks = 0;
@@ -88,6 +89,7 @@ int Detail(char *dev, int brief, int export, int test, char *homehost)
                close(fd);
                return rv;
        }
+       sra = sysfs_read(fd, 0, GET_VERSION);
        st = super_by_fd(fd);
 
        if (fstat(fd, &stb) != 0 && !S_ISBLK(stb.st_mode))
@@ -133,19 +135,27 @@ int Detail(char *dev, int brief, int export, int test, char *homehost)
                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 (sra && sra->array.major_version < 0)
+                       printf("MD_METADATA=%s\n", sra->text_version);
+               else
+                       printf("MD_METADATA=%02d.%02d\n",
+                              array.major_version, array.minor_version);
+
                if (st && st->sb)
                        st->ss->export_super(st);
                goto out;
        }
 
-       if (brief)
-               printf("ARRAY %s level=%s metadata=%d.%d num-devices=%d", dev,
+       if (brief) {
+               printf("ARRAY %s level=%s num-devices=%d", dev,
                       c?c:"-unknown-",
-                      array.major_version, array.minor_version,
                       array.raid_disks );
-       else {
+               if (sra && sra->array.major_version < 0)
+                       printf(" metadata=%s", sra->text_version);
+               else
+                       printf(" metadata=%02d.%02d",
+                              array.major_version, array.minor_version);
+       } else {
                mdu_bitmap_file_t bmf;
                unsigned long long larray_size;
                struct mdstat_ent *ms = mdstat_read(0, 0);
@@ -161,10 +171,16 @@ int Detail(char *dev, int brief, int export, int test, char *homehost)
                        larray_size = 0;
 
                printf("%s:\n", dev);
-               printf("        Version : %02d.%02d.%02d\n",
-                      array.major_version, array.minor_version, array.patch_version);
+
+               if (sra && sra->array.major_version < 0)
+                       printf("        Version : %s\n", sra->text_version);
+               else
+                       printf("        Version : %02d.%02d\n",
+                              array.major_version, array.minor_version);
+
                atime = array.ctime;
                printf("  Creation Time : %.24s\n", ctime(&atime));
+               if (array.raid_disks == 0) c = "container";
                printf("     Raid Level : %s\n", c?c:"-unknown-");
                if (larray_size)
                        printf("     Array Size : %llu%s\n", (larray_size>>10), human_size(larray_size));
@@ -185,8 +201,9 @@ int Detail(char *dev, int brief, int export, int test, char *homehost)
                printf("   Raid Devices : %d\n", array.raid_disks);
                printf("  Total Devices : %d\n", array.nr_disks);
                printf("Preferred Minor : %d\n", array.md_minor);
-               printf("    Persistence : Superblock is %spersistent\n",
-                      array.not_persistent?"not ":"");
+               if (sra == NULL || sra->array.major_version >= 0)
+                       printf("    Persistence : Superblock is %spersistent\n",
+                              array.not_persistent?"not ":"");
                printf("\n");
                /* Only try GET_BITMAP_FILE for 0.90.01 and later */
                if (vers >= 9001 &&
@@ -224,7 +241,9 @@ int Detail(char *dev, int brief, int export, int test, char *homehost)
                case 5:
                case 10:
                case 6:
-                       printf("     Chunk Size : %dK\n\n", array.chunk_size/1024);
+                       if (array.chunk_size)
+                               printf("     Chunk Size : %dK\n\n",
+                                      array.chunk_size/1024);
                        break;
                case -1:
                        printf("       Rounding : %dK\n\n", array.chunk_size/1024);
diff --git a/sysfs.c b/sysfs.c
index f198d1646e4930d33f70173d646d33ec900c5bfc..03b09fd84baf849caed42830da12e72775fc7512 100644 (file)
--- a/sysfs.c
+++ b/sysfs.c
@@ -106,7 +106,11 @@ struct mdinfo *sysfs_read(int fd, int devnum, unsigned long options)
                if (strncmp(buf, "none", 4) == 0)
                        sra->array.major_version =
                                sra->array.minor_version = -1;
-               else
+               else if (strncmp(buf, "external:", 9) == 0) {
+                       sra->array.major_version = -1;
+                       sra->array.minor_version = -2;
+                       strcpy(sra->text_version, buf+9);
+               } else
                        sscanf(buf, "%d.%d",
                               &sra->array.major_version,
                               &sra->array.minor_version);
diff --git a/util.c b/util.c
index dd8b176ab43558f6f47fc15520bcc8cde206ced8..1ba236b781c1ad4dc86563e54edea9133aeffcdb 100644 (file)
--- a/util.c
+++ b/util.c
@@ -730,7 +730,7 @@ struct supertype *super_by_fd(int fd)
        int minor;
        struct supertype *st = NULL;
        struct mdinfo *sra;
-       char *verstr = NULL;
+       char *verstr;
        char version[20];
        int i;
 
@@ -739,11 +739,13 @@ struct supertype *super_by_fd(int fd)
        if (sra) {
                vers = sra->array.major_version;
                minor = sra->array.minor_version;
+               verstr = sra->text_version;
        } else {
                if (ioctl(fd, GET_ARRAY_INFO, &array))
                        array.major_version = array.minor_version = 0;
                vers = array.major_version;
                minor = array.minor_version;
+               verstr = "";
        }
 
        if (vers != -1) {