]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
Detail: export MD_UUID from mapfile
authorDan Williams <dan.j.williams@intel.com>
Wed, 14 Oct 2009 00:41:57 +0000 (17:41 -0700)
committerDan Williams <dan.j.williams@intel.com>
Wed, 14 Oct 2009 00:41:57 +0000 (17:41 -0700)
The load_super() from an mdadm --detail call may race against an mdmon
update.  When this happens the load_super sees an inconsistent metadata
block and returns an error.  The fallback path to use the map file
contents lacks uuid reporting, so provide __fname_from_uuid for
generically printing a uuid.

Reported-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
Detail.c
mdadm.h
util.c

index 001012a211cb38e85c8499222a0a0756f8f880ee..1598a4252cd5d50698b327acb89feb3bc2333788 100644 (file)
--- a/Detail.c
+++ b/Detail.c
@@ -194,7 +194,12 @@ int Detail(char *dev, int brief, int export, int test, char *homehost)
                                st->ss->export_detail_super(st);
                } else {
                        struct map_ent *mp, *map = NULL;
                                st->ss->export_detail_super(st);
                } else {
                        struct map_ent *mp, *map = NULL;
+                       char nbuf[64];
                        mp = map_by_devnum(&map, fd2devnum(fd));
                        mp = map_by_devnum(&map, fd2devnum(fd));
+                       if (mp) {
+                               __fname_from_uuid(mp->uuid, 0, nbuf, ':');
+                               printf("MD_UUID=%s\n", nbuf+5);
+                       }
                        if (mp && mp->path &&
                            strncmp(mp->path, "/dev/md/", 8) == 0)
                                printf("MD_DEVNAME=%s\n", mp->path+8);
                        if (mp && mp->path &&
                            strncmp(mp->path, "/dev/md/", 8) == 0)
                                printf("MD_DEVNAME=%s\n", mp->path+8);
diff --git a/mdadm.h b/mdadm.h
index 04b87b829d365786d909a483196d5fb5972845bb..8212a2c46f060215800d78cc693bc5dd7ea90009 100644 (file)
--- a/mdadm.h
+++ b/mdadm.h
@@ -810,6 +810,7 @@ extern void uuid_from_super(int uuid[4], mdp_super_t *super);
 extern const int uuid_match_any[4];
 extern int same_uuid(int a[4], int b[4], int swapuuid);
 extern void copy_uuid(void *a, int b[4], int swapuuid);
 extern const int uuid_match_any[4];
 extern int same_uuid(int a[4], int b[4], int swapuuid);
 extern void copy_uuid(void *a, int b[4], int swapuuid);
+extern char *__fname_from_uuid(int id[4], int swap, char *buf, char sep);
 extern char *fname_from_uuid(struct supertype *st,
                             struct mdinfo *info, char *buf, char sep);
 extern unsigned long calc_csum(void *super, int bytes);
 extern char *fname_from_uuid(struct supertype *st,
                             struct mdinfo *info, char *buf, char sep);
 extern unsigned long calc_csum(void *super, int bytes);
diff --git a/util.c b/util.c
index 4ccb1bbf9f07e122a99f1c349ad546516dea9c0e..98aedd080fc9237bb44f1b500f9235f7f19b69cc 100644 (file)
--- a/util.c
+++ b/util.c
@@ -269,17 +269,15 @@ void copy_uuid(void *a, int b[4], int swapuuid)
                memcpy(a, b, 16);
 }
 
                memcpy(a, b, 16);
 }
 
-char *fname_from_uuid(struct supertype *st, struct mdinfo *info, char *buf, char sep)
+char *__fname_from_uuid(int id[4], int swap, char *buf, char sep)
 {
        int i, j;
 {
        int i, j;
-       int id;
        char uuid[16];
        char *c = buf;
        strcpy(c, "UUID-");
        c += strlen(c);
        char uuid[16];
        char *c = buf;
        strcpy(c, "UUID-");
        c += strlen(c);
-       copy_uuid(uuid, info->uuid, st->ss->swapuuid);
+       copy_uuid(uuid, id, swap);
        for (i = 0; i < 4; i++) {
        for (i = 0; i < 4; i++) {
-               id = uuid[i];
                if (i)
                        *c++ = sep;
                for (j = 3; j >= 0; j--) {
                if (i)
                        *c++ = sep;
                for (j = 3; j >= 0; j--) {
@@ -288,6 +286,12 @@ char *fname_from_uuid(struct supertype *st, struct mdinfo *info, char *buf, char
                }
        }
        return buf;
                }
        }
        return buf;
+
+}
+
+char *fname_from_uuid(struct supertype *st, struct mdinfo *info, char *buf, char sep)
+{
+       return __fname_from_uuid(info->uuid, st->ss->swapuuid, buf, sep);
 }
 
 #ifndef MDASSEMBLE
 }
 
 #ifndef MDASSEMBLE