X-Git-Url: http://git.ipfire.org/?p=thirdparty%2Fmdadm.git;a=blobdiff_plain;f=Examine.c;h=ffca9ca5f9d615721b68db3a9af0a1d2eda57788;hp=8081b66079b2d318e105d5976fcd587f045bcb0b;hb=3a3716107b614f679a4ea224e5bb882739d81cf9;hpb=f9ce90ba509d0b624cc38635861b9c27550fbefc diff --git a/Examine.c b/Examine.c index 8081b660..ffca9ca5 100644 --- a/Examine.c +++ b/Examine.c @@ -1,7 +1,7 @@ /* * mdadm - manage Linux "md" devices aka RAID arrays. * - * Copyright (C) 2001-2002 Neil Brown + * Copyright (C) 2001-2009 Neil Brown * * * This program is free software; you can redistribute it and/or modify @@ -19,12 +19,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * Author: Neil Brown - * Email: - * Paper: Neil Brown - * School of Computer Science and Engineering - * The University of New South Wales - * Sydney, 2052 - * Australia + * Email: */ #include "mdadm.h" @@ -35,7 +30,9 @@ #endif #include "md_u.h" #include "md_p.h" -int Examine(mddev_dev_t devlist, int brief, int scan, int SparcAdjust) +int Examine(struct mddev_dev *devlist, int brief, int export, int scan, + int SparcAdjust, struct supertype *forcest, + char *homehost) { /* Read the raid superblock from a device and @@ -51,16 +48,14 @@ 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 fd; 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,58 +63,92 @@ 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; + int have_container = 0; - 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)); + rv = 1; + } err = 1; } else { - ss = guess_super(fd, devlist->devname); - if (ss) - err = ss->load_super(fd, &super, (brief||scan)?NULL:devlist->devname); - else + int container = 0; + if (forcest) + st = dup_super(forcest); + else if (must_be_container(fd)) { + /* might be a container */ + st = super_by_fd(fd, NULL); + container = 1; + } else + st = guess_super(fd); + if (st) { + err = 1; + if (!container) + err = st->ss->load_super(st, fd, + (brief||scan) ? NULL + :devlist->devname); + if (err && st->ss->load_container) { + err = st->ss->load_container(st, fd, + (brief||scan) ? NULL + :devlist->devname); + if (!err) + have_container = 1; + } + } else { + if (!brief) { + fprintf(stderr, Name ": No md superblock detected on %s.\n", devlist->devname); + rv = 1; + } err = 1; + } close(fd); } if (err) continue; - if (err) rv =1; if (SparcAdjust) - ss->update_super(NULL, super, "sparc2.2", devlist->devname, 0); + 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) { - if (ss == ap->ss && ss->compare_super(&ap->super, super)==0) + if (st->ss == ap->st->ss && + st->ss->compare_super(ap->st, st)==0) break; } if (!ap) { ap = malloc(sizeof(*ap)); - ap->super = super; ap->devs = dl_head(); ap->next = arrays; ap->spares = 0; - ap->ss = ss; + ap->st = st; arrays = ap; - ss->getinfo_super(&ap->info, super); - } else { - ss->getinfo_super(&ap->info, super); - free(super); - } - if (!(ap->info.disk.state & MD_DISK_SYNC)) + st->ss->getinfo_super(st, &ap->info, NULL); + } else + st->ss->getinfo_super(st, &ap->info, NULL); + if (!have_container && + !(ap->info.disk.state & (1<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); - ss->examine_super(super); - free(super); + st->ss->examine_super(st, homehost); + st->ss->free_super(st); } } if (brief) { @@ -127,16 +156,27 @@ 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); - 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=','; + 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) { + newline += printf(" devices"); + for (d=dl_next(ap->devs); d!= ap->devs; d=dl_next(d)) { + printf("%c%s", sep, d); + sep=','; + } + } + if (ap->st->ss->brief_examine_subarrays) { + if (newline) + printf("\n"); + ap->st->ss->brief_examine_subarrays(ap->st, brief > 1); } - free(ap->super); + ap->st->ss->free_super(ap->st); /* FIXME free ap */ - printf("\n"); + if (ap->spares || brief > 1) + printf("\n"); } } return rv;