X-Git-Url: http://git.ipfire.org/?p=thirdparty%2Fmdadm.git;a=blobdiff_plain;f=Examine.c;h=7013480d6dd80846cc2f464d3ba23c9e8e21284d;hp=6131e3679e43d087fb2ac355d057ef8d47ba6fff;hb=b06815989179e0f153e44e4336290e655edce9a1;hpb=e7b84f9d5029338980d99d04b479ce814d4c4fcb diff --git a/Examine.c b/Examine.c index 6131e367..7013480d 100644 --- a/Examine.c +++ b/Examine.c @@ -1,7 +1,7 @@ /* * mdadm - manage Linux "md" devices aka RAID arrays. * - * Copyright (C) 2001-2009 Neil Brown + * Copyright (C) 2001-2013 Neil Brown * * * This program is free software; you can redistribute it and/or modify @@ -30,9 +30,9 @@ #endif #include "md_u.h" #include "md_p.h" -int Examine(struct mddev_dev *devlist, int brief, int export, int scan, - int SparcAdjust, struct supertype *forcest, - char *homehost) +int Examine(struct mddev_dev *devlist, + struct context *c, + struct supertype *forcest) { /* Read the raid superblock from a device and @@ -47,12 +47,12 @@ int Examine(struct mddev_dev *devlist, int brief, int export, int scan, * * utime, state etc * - * If (brief) gather devices for same array and just print a mdadm.conf line including devices= + * If (brief) gather devices for same array and just print a mdadm.conf + * line including devices= * if devlist==NULL, use conf_get_devs() */ int fd; int rv = 0; - int err = 0; struct array { struct supertype *st; @@ -62,75 +62,79 @@ int Examine(struct mddev_dev *devlist, int brief, int export, int scan, int spares; } *arrays = NULL; - for (; devlist ; devlist=devlist->next) { + for (; devlist ; devlist = devlist->next) { struct supertype *st; int have_container = 0; + int err = 0; + int container = 0; fd = dev_open(devlist->devname, O_RDONLY); if (fd < 0) { - if (!scan) { + if (!c->scan) { pr_err("cannot open %s: %s\n", devlist->devname, strerror(errno)); rv = 1; } - err = 1; + continue; } - 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; - st->ignore_hw_compat = 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; - } - st->ignore_hw_compat = 0; - } else { - if (!brief) { - pr_err("No md superblock detected on %s.\n", devlist->devname); - rv = 1; - } - err = 1; + + 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; + st->ignore_hw_compat = 1; + if (!container) + err = st->ss->load_super(st, fd, + (c->brief||c->scan) ? NULL + :devlist->devname); + if (err && st->ss->load_container) { + err = st->ss->load_container(st, fd, + (c->brief||c->scan) ? NULL + :devlist->devname); + if (!err) + have_container = 1; } - close(fd); + st->ignore_hw_compat = 0; + } else { + if (!c->brief) { + pr_err("No md superblock detected on %s.\n", devlist->devname); + rv = 1; + } + err = 1; } - if (err) + close(fd); + + if (err) { + if (st) + st->ss->free_super(st); continue; + } - if (SparcAdjust) + if (c->SparcAdjust) 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 && st->ss->brief_examine_super == NULL) { - if (!scan) + if (c->brief && st->ss->brief_examine_super == NULL) { + if (!c->scan) pr_err("No brief listing for %s on %s\n", - st->ss->name, devlist->devname); - } else if (brief) { + st->ss->name, devlist->devname); + } else if (c->brief) { struct array *ap; char *d; - for (ap=arrays; ap; ap=ap->next) { + for (ap = arrays; ap; ap = ap->next) { if (st->ss == ap->st->ss && - st->ss->compare_super(ap->st, st)==0) + st->ss->compare_super(ap->st, st) == 0) break; } if (!ap) { - ap = malloc(sizeof(*ap)); + ap = xmalloc(sizeof(*ap)); ap->devs = dl_head(); ap->next = arrays; ap->spares = 0; @@ -144,29 +148,31 @@ int Examine(struct mddev_dev *devlist, int brief, int export, int scan, ap->spares++; d = dl_strdup(devlist->devname); dl_add(ap->devs, d); - } else if (export) { + } else if (c->export) { if (st->ss->export_examine_super) st->ss->export_examine_super(st); st->ss->free_super(st); } else { printf("%s:\n",devlist->devname); - st->ss->examine_super(st, homehost); + st->ss->examine_super(st, c->homehost); st->ss->free_super(st); } } - if (brief) { + if (c->brief) { struct array *ap; - for (ap=arrays; ap; ap=ap->next) { + for (ap = arrays; ap; ap = ap->next) { char sep='='; char *d; int newline = 0; - ap->st->ss->brief_examine_super(ap->st, brief > 1); + ap->st->ss->brief_examine_super(ap->st, c->verbose > 0); if (ap->spares) newline += printf(" spares=%d", ap->spares); - if (brief > 1) { + if (c->verbose > 0) { newline += printf(" devices"); - for (d=dl_next(ap->devs); d!= ap->devs; d=dl_next(d)) { + for (d = dl_next(ap->devs); + d != ap->devs; + d=dl_next(d)) { printf("%c%s", sep, d); sep=','; } @@ -174,13 +180,49 @@ int Examine(struct mddev_dev *devlist, int brief, int export, int scan, if (ap->st->ss->brief_examine_subarrays) { if (newline) printf("\n"); - ap->st->ss->brief_examine_subarrays(ap->st, brief > 1); + ap->st->ss->brief_examine_subarrays(ap->st, c->verbose); } ap->st->ss->free_super(ap->st); /* FIXME free ap */ - if (ap->spares || brief > 1) + if (ap->spares || c->verbose > 0) printf("\n"); } } return rv; } + +int ExamineBadblocks(char *devname, int brief, struct supertype *forcest) +{ + int fd = dev_open(devname, O_RDONLY); + struct supertype *st = forcest; + int err = 1; + + if (fd < 0) { + pr_err("cannot open %s: %s\n", devname, strerror(errno)); + return 1; + } + if (!st) + st = guess_super(fd); + if (!st) { + if (!brief) + pr_err("No md superblock detected on %s\n", devname); + goto out; + } + if (!st->ss->examine_badblocks) { + pr_err("%s metadata does not support badblocks\n", st->ss->name); + goto out; + } + err = st->ss->load_super(st, fd, brief ? NULL : devname); + if (err) + goto out; + err = st->ss->examine_badblocks(st, fd, devname); + +out: + if (fd >= 0) + close(fd); + if (st) { + st->ss->free_super(st); + free(st); + } + return err; +}