]> git.ipfire.org Git - thirdparty/mdadm.git/blobdiff - Examine.c
Allow autoassembly to choose it's own name for the array.
[thirdparty/mdadm.git] / Examine.c
index 8081b66079b2d318e105d5976fcd587f045bcb0b..8a8f8f4461aef2b379d64c77d3842b892190986b 100644 (file)
--- a/Examine.c
+++ b/Examine.c
@@ -1,7 +1,7 @@
 /*
  * mdadm - manage Linux "md" devices aka RAID arrays.
  *
- * Copyright (C) 2001-2002 Neil Brown <neilb@cse.unsw.edu.au>
+ * Copyright (C) 2001-2006 Neil Brown <neilb@suse.de>
  *
  *
  *    This program is free software; you can redistribute it and/or modify
@@ -35,7 +35,9 @@
 #endif
 #include       "md_u.h"
 #include       "md_p.h"
-int Examine(mddev_dev_t devlist, int brief, int scan, int SparcAdjust)
+int Examine(mddev_dev_t devlist, int brief, int scan,
+           int SparcAdjust, struct supertype *forcest,
+           char *homehost)
 {
 
        /* Read the raid superblock from a device and
@@ -51,16 +53,16 @@ int Examine(mddev_dev_t devlist, int brief, int scan, int SparcAdjust)
         *   utime, state etc
         *
         * If (brief) gather devices for same array and just print a mdadm.conf line including devices=
-        * if devlist==NULL, use conf_get_devs(
+        * if devlist==NULL, use conf_get_devs()
         */
        int fd; 
        void *super = NULL;
        int rv = 0;
-       int err;
+       int err = 0;
 
        struct array {
                void *super;
-               struct superswitch *ss;
+               struct supertype *st;
                struct mdinfo info;
                void *devs;
                struct array *next;
@@ -68,35 +70,41 @@ int Examine(mddev_dev_t devlist, int brief, int scan, int SparcAdjust)
        } *arrays = NULL;
 
        for (; devlist ; devlist=devlist->next) {
-               struct superswitch *ss;
+               struct supertype *st = forcest;
 
-               fd = open(devlist->devname, O_RDONLY);
+               fd = dev_open(devlist->devname, O_RDONLY);
                if (fd < 0) {
-                       if (!scan)
+                       if (!scan) {
                                fprintf(stderr,Name ": cannot open %s: %s\n",
                                        devlist->devname, strerror(errno));
-                       err = 1;
+                               err = 1;
+                       }
                }
                else {
-                       ss = guess_super(fd, devlist->devname);
-                       if (ss)
-                               err = ss->load_super(fd, &super, (brief||scan)?NULL:devlist->devname);
-                       else
+                       if (!st)
+                               st = guess_super(fd);
+                       if (st)
+                               err = st->ss->load_super(st, fd, &super, (brief||scan)?NULL:devlist->devname);
+                       else {
+                               if (!brief)
+                                       fprintf(stderr, Name ": No md superblock detected on %s.\n", devlist->devname);
                                err = 1;
+                       }
                        close(fd);
                }
-               if (err)
+               if (err) {
+                       rv = 1;
                        continue;
-               if (err) rv =1;
+               }
 
                if (SparcAdjust)
-                       ss->update_super(NULL, super, "sparc2.2", devlist->devname, 0);
+                       st->ss->update_super(NULL, super, "sparc2.2", devlist->devname, 0, 0, NULL);
                /* Ok, its good enough to try, though the checksum could be wrong */
                if (brief) {
                        struct array *ap;
                        char *d;
                        for (ap=arrays; ap; ap=ap->next) {
-                               if (ss == ap->ss && ss->compare_super(&ap->super, super)==0)
+                               if (st->ss == ap->st->ss && st->ss->compare_super(&ap->super, super)==0)
                                        break;
                        }
                        if (!ap) {
@@ -105,11 +113,11 @@ int Examine(mddev_dev_t devlist, int brief, int scan, int SparcAdjust)
                                ap->devs = dl_head();
                                ap->next = arrays;
                                ap->spares = 0;
-                               ap->ss = ss;
+                               ap->st = st;
                                arrays = ap;
-                               ss->getinfo_super(&ap->info, super);
+                               st->ss->getinfo_super(&ap->info, super);
                        } else {
-                               ss->getinfo_super(&ap->info, super);
+                               st->ss->getinfo_super(&ap->info, super);
                                free(super);
                        }
                        if (!(ap->info.disk.state & MD_DISK_SYNC))
@@ -118,7 +126,7 @@ int Examine(mddev_dev_t devlist, int brief, int scan, int SparcAdjust)
                        dl_add(ap->devs, d);
                } else {
                        printf("%s:\n",devlist->devname);
-                       ss->examine_super(super);
+                       st->ss->examine_super(super, homehost);
                        free(super);
                }
        }
@@ -127,16 +135,19 @@ int Examine(mddev_dev_t devlist, int brief, int scan, int SparcAdjust)
                for (ap=arrays; ap; ap=ap->next) {
                        char sep='=';
                        char *d;
-                       ap->ss->brief_examine_super(ap->super);
+                       ap->st->ss->brief_examine_super(ap->super);
                        if (ap->spares) printf("   spares=%d", ap->spares);
-                       printf("   devices");
-                       for (d=dl_next(ap->devs); d!= ap->devs; d=dl_next(d)) {
-                               printf("%c%s", sep, d);
-                               sep=',';
+                       if (brief > 1) {
+                               printf("   devices");
+                               for (d=dl_next(ap->devs); d!= ap->devs; d=dl_next(d)) {
+                                       printf("%c%s", sep, d);
+                                       sep=',';
+                               }
                        }
                        free(ap->super);
                        /* FIXME free ap */
-                       printf("\n");
+                       if (ap->spares || brief > 1)
+                               printf("\n");
                }
        }
        return rv;