]> git.ipfire.org Git - thirdparty/mdadm.git/blobdiff - Examine.c
Add mbr pseudo metadata handler.
[thirdparty/mdadm.git] / Examine.c
index 806c55240f64cbf349fdc481c7200b35cf86ec5e..01838c8b48d3307c3350cbd6efe2a1fe73519f67 100644 (file)
--- a/Examine.c
+++ b/Examine.c
@@ -1,7 +1,7 @@
 /*
  * mdadm - manage Linux "md" devices aka RAID arrays.
  *
- * Copyright (C) 2001-2006 Neil Brown <neilb@suse.de>
+ * Copyright (C) 2001-2009 Neil Brown <neilb@suse.de>
  *
  *
  *    This program is free software; you can redistribute it and/or modify
  *    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  *
  *    Author: Neil Brown
- *    Email: <neilb@cse.unsw.edu.au>
- *    Paper: Neil Brown
- *           School of Computer Science and Engineering
- *           The University of New South Wales
- *           Sydney, 2052
- *           Australia
+ *    Email: <neilb@suse.de>
  */
 
 #include       "mdadm.h"
@@ -35,7 +30,7 @@
 #endif
 #include       "md_u.h"
 #include       "md_p.h"
-int Examine(mddev_dev_t devlist, int brief, int scan,
+int Examine(mddev_dev_t devlist, int brief, int export, int scan,
            int SparcAdjust, struct supertype *forcest,
            char *homehost)
 {
@@ -56,12 +51,10 @@ int Examine(mddev_dev_t devlist, int brief, int scan,
         * if devlist==NULL, use conf_get_devs()
         */
        int fd;
-       void *super = NULL;
        int rv = 0;
        int err = 0;
 
        struct array {
-               void *super;
                struct supertype *st;
                struct mdinfo info;
                void *devs;
@@ -70,7 +63,7 @@ int Examine(mddev_dev_t devlist, int brief, int scan,
        } *arrays = NULL;
 
        for (; devlist ; devlist=devlist->next) {
-               struct supertype *st = forcest;
+               struct supertype *st;
 
                fd = dev_open(devlist->devname, O_RDONLY);
                if (fd < 0) {
@@ -82,10 +75,14 @@ int Examine(mddev_dev_t devlist, int brief, int scan,
                        err = 1;
                }
                else {
-                       if (!st)
+                       if (forcest)
+                               st = dup_super(forcest);
+                       else
                                st = guess_super(fd);
                        if (st)
-                               err = st->ss->load_super(st, fd, &super, (brief||scan)?NULL:devlist->devname);
+                               err = st->ss->load_super(st, fd,
+                                                        (brief||scan) ? NULL
+                                                          :devlist->devname);
                        else {
                                if (!brief) {
                                        fprintf(stderr, Name ": No md superblock detected on %s.\n", devlist->devname);
@@ -99,10 +96,15 @@ int Examine(mddev_dev_t devlist, int brief, int scan,
                        continue;
 
                if (SparcAdjust)
-                       st->ss->update_super(st, NULL, super, "sparc2.2",
+                       st->ss->update_super(st, NULL, "sparc2.2",
                                             devlist->devname, 0, 0, NULL);
                /* Ok, its good enough to try, though the checksum could be wrong */
-               if (brief) {
+
+               if (brief && st->ss->brief_examine_super == NULL) {
+                       if (!scan)
+                               fprintf(stderr, Name ": No brief listing for %s on %s\n",
+                                       st->ss->name, devlist->devname);
+               } else if (brief) {
                        struct array *ap;
                        char *d;
                        for (ap=arrays; ap; ap=ap->next) {
@@ -112,25 +114,26 @@ int Examine(mddev_dev_t devlist, int brief, int scan,
                        }
                        if (!ap) {
                                ap = malloc(sizeof(*ap));
-                               ap->super = super;
                                ap->devs = dl_head();
                                ap->next = arrays;
                                ap->spares = 0;
                                ap->st = st;
                                arrays = ap;
-                               st->ss->getinfo_super(st, &ap->info, super);
-                       } else {
-                               st->ss->getinfo_super(st, &ap->info, super);
-                               st->ss->free_super(st, super);
-                       }
-                       if (!(ap->info.disk.state & MD_DISK_SYNC))
+                               st->ss->getinfo_super(st, &ap->info);
+                       } else
+                               st->ss->getinfo_super(st, &ap->info);
+                       if (!st->loaded_container &&
+                           !(ap->info.disk.state & (1<<MD_DISK_SYNC)))
                                ap->spares++;
                        d = dl_strdup(devlist->devname);
                        dl_add(ap->devs, d);
+               } else if (export) {
+                       if (st->ss->export_examine_super)
+                               st->ss->export_examine_super(st);
                } else {
                        printf("%s:\n",devlist->devname);
-                       st->ss->examine_super(st, super, homehost);
-                       st->ss->free_super(st, super);
+                       st->ss->examine_super(st, homehost);
+                       st->ss->free_super(st);
                }
        }
        if (brief) {
@@ -138,16 +141,24 @@ int Examine(mddev_dev_t devlist, int brief, int scan,
                for (ap=arrays; ap; ap=ap->next) {
                        char sep='=';
                        char *d;
-                       ap->st->ss->brief_examine_super(ap->st, ap->super);
-                       if (ap->spares) printf("   spares=%d", ap->spares);
+                       int newline = 0;
+
+                       ap->st->ss->brief_examine_super(ap->st, brief > 1);
+                       if (ap->spares)
+                               newline += printf("   spares=%d", ap->spares);
                        if (brief > 1) {
-                               printf("   devices");
+                               newline += printf("   devices");
                                for (d=dl_next(ap->devs); d!= ap->devs; d=dl_next(d)) {
                                        printf("%c%s", sep, d);
                                        sep=',';
                                }
                        }
-                       ap->st->ss->free_super(ap->st, ap->super);
+                       if (ap->st->ss->brief_examine_subarrays) {
+                               if (newline)
+                                       printf("\n");
+                               ap->st->ss->brief_examine_subarrays(ap->st, brief > 1);
+                       }
+                       ap->st->ss->free_super(ap->st);
                        /* FIXME free ap */
                        if (ap->spares || brief > 1)
                                printf("\n");