mdadm/Examine.c

156 lines
3.9 KiB
C
Raw Normal View History

2001-06-08 04:36:23 +02:00
/*
2002-03-08 01:03:52 +01:00
* mdadm - manage Linux "md" devices aka RAID arrays.
2001-06-08 04:36:23 +02:00
*
* Copyright (C) 2001-2006 Neil Brown <neilb@suse.de>
2001-06-08 04:36:23 +02:00
*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* 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
*/
2002-03-08 01:03:52 +01:00
#include "mdadm.h"
2002-03-07 00:17:40 +01:00
#include "dlink.h"
2001-06-08 04:36:23 +02:00
2001-07-26 09:00:09 +02:00
#if ! defined(__BIG_ENDIAN) && ! defined(__LITTLE_ENDIAN)
#error no endian defined
#endif
2001-06-08 04:36:23 +02:00
#include "md_u.h"
#include "md_p.h"
int Examine(mddev_dev_t devlist, int brief, int scan,
int SparcAdjust, struct supertype *forcest,
char *homehost)
2001-06-08 04:36:23 +02:00
{
/* Read the raid superblock from a device and
* display important content.
*
* If cannot be found, print reason: too small, bad magic
*
* Print:
* version, ctime, level, size, raid+spare+
* prefered minor
* uuid
*
* utime, state etc
*
2002-03-08 01:03:52 +01:00
* If (brief) gather devices for same array and just print a mdadm.conf line including devices=
* if devlist==NULL, use conf_get_devs()
2001-06-08 04:36:23 +02:00
*/
2007-12-14 10:13:43 +01:00
int fd;
void *super = NULL;
2002-03-07 00:17:40 +01:00
int rv = 0;
int err = 0;
2001-06-08 04:36:23 +02:00
2002-03-07 00:17:40 +01:00
struct array {
void *super;
struct supertype *st;
struct mdinfo info;
2002-03-07 00:17:40 +01:00
void *devs;
struct array *next;
int spares;
2002-03-07 00:17:40 +01:00
} *arrays = NULL;
for (; devlist ; devlist=devlist->next) {
struct supertype *st = forcest;
fd = dev_open(devlist->devname, O_RDONLY);
2002-03-07 00:17:40 +01:00
if (fd < 0) {
if (!scan) {
2002-03-07 00:17:40 +01:00
fprintf(stderr,Name ": cannot open %s: %s\n",
devlist->devname, strerror(errno));
rv = 1;
}
err = 1;
2002-03-07 00:17:40 +01:00
}
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);
rv = 1;
}
err = 1;
}
2002-03-07 00:17:40 +01:00
close(fd);
}
if (err)
2002-03-07 00:17:40 +01:00
continue;
if (SparcAdjust)
st->ss->update_super(NULL, super, "sparc2.2", devlist->devname, 0, 0, NULL);
2002-03-07 00:17:40 +01:00
/* 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 (st->ss == ap->st->ss && st->ss->compare_super(&ap->super, super)==0)
2002-03-07 00:17:40 +01:00
break;
}
if (!ap) {
ap = malloc(sizeof(*ap));
ap->super = super;
ap->devs = dl_head();
ap->next = arrays;
ap->spares = 0;
ap->st = st;
2002-03-07 00:17:40 +01:00
arrays = ap;
st->ss->getinfo_super(&ap->info, super);
} else {
st->ss->getinfo_super(&ap->info, super);
st->ss->free_super(super);
2002-03-07 00:17:40 +01:00
}
if (!(ap->info.disk.state & MD_DISK_SYNC))
ap->spares++;
2002-03-07 00:17:40 +01:00
d = dl_strdup(devlist->devname);
dl_add(ap->devs, d);
} else {
printf("%s:\n",devlist->devname);
st->ss->examine_super(super, homehost);
st->ss->free_super(super);
2002-05-20 13:17:18 +02:00
}
2001-07-26 09:00:09 +02:00
}
2002-03-07 00:17:40 +01:00
if (brief) {
struct array *ap;
for (ap=arrays; ap; ap=ap->next) {
char sep='=';
char *d;
ap->st->ss->brief_examine_super(ap->super);
if (ap->spares) printf(" spares=%d", ap->spares);
if (brief > 1) {
printf(" devices");
for (d=dl_next(ap->devs); d!= ap->devs; d=dl_next(d)) {
printf("%c%s", sep, d);
sep=',';
}
2002-03-07 00:17:40 +01:00
}
ap->st->ss->free_super(ap->super);
/* FIXME free ap */
if (ap->spares || brief > 1)
printf("\n");
2002-03-07 00:17:40 +01:00
}
2001-06-08 04:36:23 +02:00
}
2002-03-07 00:17:40 +01:00
return rv;
2001-06-08 04:36:23 +02:00
}