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
|
|
|
*
|
2002-03-07 00:17:40 +01:00
|
|
|
* Copyright (C) 2001-2002 Neil Brown <neilb@cse.unsw.edu.au>
|
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"
|
2002-05-20 13:17:18 +02:00
|
|
|
int Examine(mddev_dev_t devlist, int brief, int scan, int SparcAdjust)
|
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=
|
2002-03-07 00:17:40 +01:00
|
|
|
* if devlist==NULL, use conf_get_devs(
|
2001-06-08 04:36:23 +02:00
|
|
|
*/
|
2002-03-07 00:17:40 +01:00
|
|
|
int fd;
|
2001-06-08 04:36:23 +02:00
|
|
|
time_t atime;
|
|
|
|
mdp_super_t super;
|
|
|
|
int d;
|
2001-06-14 07:33:53 +02:00
|
|
|
char *c;
|
2002-03-07 00:17:40 +01:00
|
|
|
int rv = 0;
|
|
|
|
int err;
|
2003-10-29 00:20:01 +01:00
|
|
|
int spares = 0;
|
2001-06-08 04:36:23 +02:00
|
|
|
|
2002-03-07 00:17:40 +01:00
|
|
|
struct array {
|
|
|
|
mdp_super_t super;
|
|
|
|
void *devs;
|
|
|
|
struct array *next;
|
|
|
|
} *arrays = NULL;
|
|
|
|
|
|
|
|
for (; devlist ; devlist=devlist->next) {
|
|
|
|
fd = open(devlist->devname, O_RDONLY);
|
|
|
|
if (fd < 0) {
|
|
|
|
if (!scan)
|
|
|
|
fprintf(stderr,Name ": cannot open %s: %s\n",
|
|
|
|
devlist->devname, strerror(errno));
|
|
|
|
err = 1;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
err = load_super(fd, &super);
|
|
|
|
close(fd);
|
|
|
|
}
|
|
|
|
if (err && (brief||scan))
|
|
|
|
continue;
|
|
|
|
if (err) rv =1;
|
|
|
|
switch(err) {
|
|
|
|
case 1:
|
|
|
|
fprintf(stderr, Name ": cannot find device size for %s: %s\n",
|
|
|
|
devlist->devname, strerror(errno));
|
|
|
|
continue;
|
|
|
|
case 2:
|
2001-06-14 07:33:53 +02:00
|
|
|
/* fprintf(stderr, Name ": %s is too small for md: size is %ld sectors\n",
|
2002-03-07 00:17:40 +01:00
|
|
|
devlist->devname, size);
|
2001-06-08 04:36:23 +02:00
|
|
|
*/
|
2002-03-07 00:17:40 +01:00
|
|
|
fprintf(stderr, Name ": %s is too small for md\n",
|
|
|
|
devlist->devname);
|
|
|
|
continue;
|
|
|
|
case 3:
|
|
|
|
fprintf(stderr, Name ": Cannot seek to superblock on %s: %s\n",
|
|
|
|
devlist->devname, strerror(errno));
|
|
|
|
continue;
|
|
|
|
case 4:
|
|
|
|
fprintf(stderr, Name ": Cannot read superblock on %s\n",
|
|
|
|
devlist->devname);
|
|
|
|
continue;
|
|
|
|
case 5:
|
|
|
|
fprintf(stderr, Name ": No super block found on %s (Expected magic %08x, got %08x)\n",
|
|
|
|
devlist->devname, MD_SB_MAGIC, super.md_magic);
|
|
|
|
continue;
|
|
|
|
case 6:
|
|
|
|
fprintf(stderr, Name ": Cannot interpret superblock on %s - version is %d\n",
|
|
|
|
devlist->devname, super.major_version);
|
|
|
|
continue;
|
|
|
|
}
|
2001-06-08 04:36:23 +02:00
|
|
|
|
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 (compare_super(&ap->super, &super)==0)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (!ap) {
|
|
|
|
ap = malloc(sizeof(*ap));
|
|
|
|
ap->super = super;
|
|
|
|
ap->devs = dl_head();
|
|
|
|
ap->next = arrays;
|
|
|
|
arrays = ap;
|
|
|
|
}
|
|
|
|
d = dl_strdup(devlist->devname);
|
|
|
|
dl_add(ap->devs, d);
|
|
|
|
} else {
|
|
|
|
printf("%s:\n",devlist->devname);
|
|
|
|
printf(" Magic : %08x\n", super.md_magic);
|
|
|
|
printf(" Version : %02d.%02d.%02d\n", super.major_version, super.minor_version,
|
|
|
|
super.patch_version);
|
|
|
|
if (super.minor_version >= 90)
|
|
|
|
printf(" UUID : %08x:%08x:%08x:%08x\n", super.set_uuid0, super.set_uuid1,
|
|
|
|
super.set_uuid2, super.set_uuid3);
|
|
|
|
else
|
|
|
|
printf(" UUID : %08x\n", super.set_uuid0);
|
2001-06-08 04:36:23 +02:00
|
|
|
|
2002-03-07 00:17:40 +01:00
|
|
|
atime = super.ctime;
|
|
|
|
printf(" Creation Time : %.24s\n", ctime(&atime));
|
|
|
|
c=map_num(pers, super.level);
|
|
|
|
printf(" Raid Level : %s\n", c?c:"-unknown-");
|
2004-11-01 05:49:34 +01:00
|
|
|
if (super.level <= 0)
|
|
|
|
printf(" Device Size : %u%s\n", super.size, human_size((long long)super.size<<10));
|
2002-04-11 03:36:14 +02:00
|
|
|
printf(" Raid Devices : %d\n", super.raid_disks);
|
|
|
|
printf(" Total Devices : %d\n", super.nr_disks);
|
2002-03-07 00:17:40 +01:00
|
|
|
printf("Preferred Minor : %d\n", super.md_minor);
|
|
|
|
printf("\n");
|
|
|
|
atime = super.utime;
|
|
|
|
printf(" Update Time : %.24s\n", ctime(&atime));
|
2004-06-04 14:03:19 +02:00
|
|
|
printf(" State : %s\n",
|
|
|
|
(super.state&(1<<MD_SB_CLEAN))?"clean":"dirty");
|
2002-04-11 03:36:14 +02:00
|
|
|
printf(" Active Devices : %d\n", super.active_disks);
|
|
|
|
printf("Working Devices : %d\n", super.working_disks);
|
|
|
|
printf(" Failed Devices : %d\n", super.failed_disks);
|
|
|
|
printf(" Spare Devices : %d\n", super.spare_disks);
|
2002-03-07 00:17:40 +01:00
|
|
|
if (calc_sb_csum(&super) == super.sb_csum)
|
|
|
|
printf(" Checksum : %x - correct\n", super.sb_csum);
|
|
|
|
else
|
2004-01-22 03:10:29 +01:00
|
|
|
printf(" Checksum : %x - expected %lx\n", super.sb_csum, calc_sb_csum(&super));
|
2002-05-20 13:17:18 +02:00
|
|
|
if (SparcAdjust) {
|
|
|
|
/* 2.2 sparc put the events in the wrong place
|
|
|
|
* So we copy the tail of the superblock
|
|
|
|
* up 4 bytes before continuing
|
|
|
|
*/
|
|
|
|
__u32 *sb32 = (__u32*)&super;
|
|
|
|
memcpy(sb32+MD_SB_GENERIC_CONSTANT_WORDS+7,
|
|
|
|
sb32+MD_SB_GENERIC_CONSTANT_WORDS+7+1,
|
2003-02-12 01:17:26 +01:00
|
|
|
(MD_SB_WORDS - (MD_SB_GENERIC_CONSTANT_WORDS+7+1))*4);
|
2002-05-20 13:17:18 +02:00
|
|
|
printf (" --- adjusting superblock for 2.2/sparc compatability ---\n");
|
|
|
|
}
|
2002-03-07 00:17:40 +01:00
|
|
|
printf(" Events : %d.%d\n", super.events_hi, super.events_lo);
|
2004-08-11 04:16:01 +02:00
|
|
|
if (super.events_hi == super.cp_events_hi &&
|
|
|
|
super.events_lo == super.cp_events_lo &&
|
|
|
|
super.recovery_cp > 0 &&
|
|
|
|
(super.state & (1<<MD_SB_CLEAN)) == 0 )
|
|
|
|
printf("Sync checkpoint : %d KB (%d%%)\n", super.recovery_cp/2, super.recovery_cp/(super.size/100*2));
|
2002-03-07 00:17:40 +01:00
|
|
|
printf("\n");
|
|
|
|
if (super.level == 5) {
|
|
|
|
c = map_num(r5layout, super.layout);
|
|
|
|
printf(" Layout : %s\n", c?c:"-unknown-");
|
|
|
|
}
|
2004-08-11 04:16:01 +02:00
|
|
|
if (super.level == 10)
|
|
|
|
printf(" Layout : near=%d, far=%d\n",
|
|
|
|
super.layout&255, (super.layout>>8) & 255);
|
|
|
|
|
2002-03-07 00:17:40 +01:00
|
|
|
switch(super.level) {
|
|
|
|
case 0:
|
|
|
|
case 4:
|
|
|
|
case 5:
|
|
|
|
printf(" Chunk Size : %dK\n", super.chunk_size/1024);
|
|
|
|
break;
|
|
|
|
case -1:
|
|
|
|
printf(" Rounding : %dK\n", super.chunk_size/1024);
|
|
|
|
break;
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
printf("\n");
|
2002-04-11 03:36:14 +02:00
|
|
|
printf(" Number Major Minor RaidDevice State\n");
|
2002-03-07 00:17:40 +01:00
|
|
|
for (d= -1; d<(signed int)(super.raid_disks+super.spare_disks); d++) {
|
|
|
|
mdp_disk_t *dp;
|
|
|
|
char *dv;
|
|
|
|
char nb[5];
|
|
|
|
if (d>=0) dp = &super.disks[d];
|
|
|
|
else dp = &super.this_disk;
|
|
|
|
sprintf(nb, "%4d", d);
|
|
|
|
printf("%4s %5d %5d %5d %5d ", d < 0 ? "this" : nb,
|
|
|
|
dp->number, dp->major, dp->minor, dp->raid_disk);
|
|
|
|
if (dp->state & (1<<MD_DISK_FAULTY)) printf(" faulty");
|
|
|
|
if (dp->state & (1<<MD_DISK_ACTIVE)) printf(" active");
|
|
|
|
if (dp->state & (1<<MD_DISK_SYNC)) printf(" sync");
|
|
|
|
if (dp->state & (1<<MD_DISK_REMOVED)) printf(" removed");
|
2003-10-29 00:20:01 +01:00
|
|
|
if (dp->state == 0) { printf(" spare"); spares++; }
|
2002-03-07 00:17:40 +01:00
|
|
|
if ((dv=map_dev(dp->major, dp->minor)))
|
|
|
|
printf(" %s", dv);
|
|
|
|
printf("\n");
|
2004-08-11 04:16:01 +02:00
|
|
|
if (d == -1) printf("\n");
|
2002-03-07 00:17:40 +01:00
|
|
|
}
|
|
|
|
}
|
2002-05-20 13:17:18 +02:00
|
|
|
if (SparcAdjust == 2) {
|
|
|
|
printf(" ----- updating superblock on device ----\n");
|
|
|
|
fd = open(devlist->devname, O_RDWR);
|
|
|
|
if (fd < 0) {
|
|
|
|
fprintf(stderr, Name ": cannot open %s to update superblock: %s\n",
|
|
|
|
devlist->devname, strerror(errno));
|
|
|
|
err = 1;
|
|
|
|
} else {
|
|
|
|
super.sb_csum = calc_sb_csum(&super);
|
|
|
|
if (store_super(fd, &super)) {
|
|
|
|
fprintf(stderr, Name ": Count not re-write superblock on %s\n",
|
|
|
|
devlist->devname);
|
|
|
|
err = 1;
|
|
|
|
}
|
|
|
|
close(fd);
|
|
|
|
}
|
|
|
|
}
|
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 *c=map_num(pers, ap->super.level);
|
|
|
|
char *d;
|
2004-06-04 14:03:19 +02:00
|
|
|
printf("ARRAY %s level=%s num-devices=%d UUID=",
|
|
|
|
get_md_name(ap->super.md_minor),
|
|
|
|
c?c:"-unknown-", ap->super.raid_disks);
|
2003-10-29 00:20:01 +01:00
|
|
|
if (spares) printf(" spares=%d", spares);
|
2002-03-07 00:17:40 +01:00
|
|
|
if (ap->super.minor_version >= 90)
|
|
|
|
printf("%08x:%08x:%08x:%08x", ap->super.set_uuid0, ap->super.set_uuid1,
|
|
|
|
ap->super.set_uuid2, ap->super.set_uuid3);
|
|
|
|
else
|
|
|
|
printf("%08x", ap->super.set_uuid0);
|
|
|
|
printf("\n devices");
|
|
|
|
for (d=dl_next(ap->devs); d!= ap->devs; d=dl_next(d)) {
|
|
|
|
printf("%c%s", sep, d);
|
|
|
|
sep=',';
|
|
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
}
|
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
|
|
|
}
|