mdadm/Detail.c

234 lines
6.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
*
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"
2001-06-08 04:36:23 +02:00
#include "md_p.h"
#include "md_u.h"
2003-10-29 00:20:01 +01:00
int Detail(char *dev, int brief, int test)
2001-06-08 04:36:23 +02:00
{
/*
* Print out details for an md array by using
* GET_ARRAY_INFO and GET_DISK_INFO ioctl calls
*/
int fd = open(dev, O_RDONLY, 0);
int vers;
mdu_array_info_t array;
int d;
time_t atime;
2001-06-14 07:33:53 +02:00
char *c;
2003-03-03 00:11:38 +01:00
char *devices = NULL;
2003-10-29 00:20:01 +01:00
int spares = 0;
2004-06-04 14:03:19 +02:00
struct stat stb;
2001-06-08 04:36:23 +02:00
2001-07-26 09:00:09 +02:00
mdp_super_t super;
int have_super = 0;
2003-10-29 00:20:01 +01:00
int rv = test ? 4 : 1;
2001-07-26 09:00:09 +02:00
2001-06-08 04:36:23 +02:00
if (fd < 0) {
2001-06-14 07:33:53 +02:00
fprintf(stderr, Name ": cannot open %s: %s\n",
2001-06-08 04:36:23 +02:00
dev, strerror(errno));
2003-10-29 00:20:01 +01:00
return rv;
2001-06-08 04:36:23 +02:00
}
vers = md_get_version(fd);
if (vers < 0) {
2001-06-14 07:33:53 +02:00
fprintf(stderr, Name ": %s does not appear to be an md device\n",
2001-06-08 04:36:23 +02:00
dev);
close(fd);
2003-10-29 00:20:01 +01:00
return rv;
2001-06-08 04:36:23 +02:00
}
2001-06-14 07:33:53 +02:00
if (vers < 9000) {
fprintf(stderr, Name ": cannot get detail for md device %s: driver version too old.\n",
2001-06-08 04:36:23 +02:00
dev);
close(fd);
2003-10-29 00:20:01 +01:00
return rv;
2001-06-08 04:36:23 +02:00
}
if (ioctl(fd, GET_ARRAY_INFO, &array)<0) {
if (errno == ENODEV)
2001-06-14 07:33:53 +02:00
fprintf(stderr, Name ": md device %s does not appear to be active.\n",
2001-06-08 04:36:23 +02:00
dev);
else
2001-06-14 07:33:53 +02:00
fprintf(stderr, Name ": cannot get array detail for %s: %s\n",
2001-06-08 04:36:23 +02:00
dev, strerror(errno));
close(fd);
2003-10-29 00:20:01 +01:00
return rv;
2001-06-08 04:36:23 +02:00
}
2004-06-04 14:03:19 +02:00
if (fstat(fd, &stb) != 0 && !S_ISBLK(stb.st_mode))
stb.st_rdev = 0;
2003-10-29 00:20:01 +01:00
rv = 0;
2001-06-08 04:36:23 +02:00
/* Ok, we have some info to print... */
2001-06-14 07:33:53 +02:00
c = map_num(pers, array.level);
2002-03-07 00:17:40 +01:00
if (brief)
2002-04-11 03:36:14 +02:00
printf("ARRAY %s level=%s num-devices=%d", dev, c?c:"-unknown-",array.raid_disks );
2002-03-07 00:17:40 +01:00
else {
2002-04-04 03:58:32 +02:00
unsigned long array_size;
unsigned long long larray_size;
2004-06-04 14:03:19 +02:00
struct mdstat_ent *ms = mdstat_read(0);
struct mdstat_ent *e;
int devnum = array.md_minor;
if (MAJOR(stb.st_rdev) != MD_MAJOR)
devnum = -1 - devnum;
for (e=ms; e; e=e->next)
if (e->devnum == devnum)
break;
2002-03-20 23:39:50 +01:00
#ifdef BLKGETSIZE64
2002-03-15 06:21:36 +01:00
if (ioctl(fd, BLKGETSIZE64, &larray_size)==0)
;
2002-03-20 23:39:50 +01:00
else
#endif
2002-04-11 03:36:14 +02:00
if (ioctl(fd, BLKGETSIZE, &array_size)==0) {
larray_size = array_size;
larray_size <<= 9;
}
2002-03-15 06:21:36 +01:00
else larray_size = 0;
2002-03-07 00:17:40 +01:00
printf("%s:\n", dev);
printf(" Version : %02d.%02d.%02d\n",
array.major_version, array.minor_version, array.patch_version);
atime = array.ctime;
printf(" Creation Time : %.24s\n", ctime(&atime));
printf(" Raid Level : %s\n", c?c:"-unknown-");
2002-03-15 06:21:36 +01:00
if (larray_size)
2004-06-04 14:03:19 +02:00
printf(" Array Size : %llu%s\n", (larray_size>>10), human_size(larray_size));
2002-03-07 00:17:40 +01:00
if (array.level >= 1)
2002-03-15 06:21:36 +01:00
printf(" Device Size : %d%s\n", array.size, human_size((long long)array.size<<10));
2002-04-11 03:36:14 +02:00
printf(" Raid Devices : %d\n", array.raid_disks);
printf(" Total Devices : %d\n", array.nr_disks);
2002-03-07 00:17:40 +01:00
printf("Preferred Minor : %d\n", array.md_minor);
2002-04-11 03:36:14 +02:00
printf(" Persistence : Superblock is %spersistent\n",
2002-03-07 00:17:40 +01:00
array.not_persistent?"not ":"");
printf("\n");
atime = array.utime;
printf(" Update Time : %.24s\n", ctime(&atime));
2004-06-04 14:03:19 +02:00
printf(" State : %s%s%s\n",
2002-03-07 00:17:40 +01:00
(array.state&(1<<MD_SB_CLEAN))?"clean":"dirty",
2004-06-04 14:03:19 +02:00
array.active_disks < array.raid_disks? ", degraded":"",
(e && e->percent >= 0) ? ", recovering": "");
2002-04-11 03:36:14 +02:00
printf(" Active Devices : %d\n", array.active_disks);
printf("Working Devices : %d\n", array.working_disks);
printf(" Failed Devices : %d\n", array.failed_disks);
printf(" Spare Devices : %d\n", array.spare_disks);
2002-03-07 00:17:40 +01:00
printf("\n");
if (array.level == 5) {
c = map_num(r5layout, array.layout);
printf(" Layout : %s\n", c?c:"-unknown-");
}
switch (array.level) {
case 0:
case 4:
case 5:
printf(" Chunk Size : %dK\n", array.chunk_size/1024);
break;
case -1:
printf(" Rounding : %dK\n", array.chunk_size/1024);
break;
default: break;
}
2001-07-26 09:00:09 +02:00
2002-03-07 00:17:40 +01:00
printf("\n");
2004-06-04 14:03:19 +02:00
if (e && e->percent >= 0)
printf(" Rebuild Status : %d%% complete\n\n", e->percent);
free_mdstat(ms);
2002-04-11 03:36:14 +02:00
printf(" Number Major Minor RaidDevice State\n");
2002-03-07 00:17:40 +01:00
}
2002-04-04 03:58:32 +02:00
for (d= 0; d<MD_SB_DISKS; d++) {
2001-06-08 04:36:23 +02:00
mdu_disk_info_t disk;
2001-07-26 09:00:09 +02:00
char *dv;
2001-06-08 04:36:23 +02:00
disk.number = d;
if (ioctl(fd, GET_DISK_INFO, &disk) < 0) {
2002-04-04 03:58:32 +02:00
if (d < array.raid_disks)
2002-04-11 03:36:14 +02:00
fprintf(stderr, Name ": cannot get device detail for device %d: %s\n",
2002-04-04 03:58:32 +02:00
d, strerror(errno));
2001-06-08 04:36:23 +02:00
continue;
}
2002-04-04 03:58:32 +02:00
if (d >= array.raid_disks &&
disk.major == 0 &&
disk.minor == 0)
continue;
2002-03-07 00:17:40 +01:00
if (!brief) {
printf(" %5d %5d %5d %5d ",
disk.number, disk.major, disk.minor, disk.raid_disk);
if (disk.state & (1<<MD_DISK_FAULTY)) printf(" faulty");
if (disk.state & (1<<MD_DISK_ACTIVE)) printf(" active");
if (disk.state & (1<<MD_DISK_SYNC)) printf(" sync");
if (disk.state & (1<<MD_DISK_REMOVED)) printf(" removed");
2003-10-29 00:20:01 +01:00
if (disk.state == 0) { printf(" spare"); spares++; }
}
if (test && d < array.raid_disks && disk.state & (1<<MD_DISK_FAULTY)) {
if ((rv & 1) && (array.level ==4 || array.level == 5))
rv |= 2;
rv |= 1;
2002-03-07 00:17:40 +01:00
}
2001-07-26 09:00:09 +02:00
if ((dv=map_dev(disk.major, disk.minor))) {
2003-03-03 00:11:38 +01:00
if (brief) {
if (devices) {
devices = realloc(devices,
strlen(devices)+1+strlen(dv)+1);
strcat(strcat(devices,","),dv);
} else
devices = strdup(dv);
} else
printf(" %s", dv);
2003-02-12 01:17:26 +01:00
if (!have_super && (disk.state & (1<<MD_DISK_ACTIVE))) {
2002-03-07 00:17:40 +01:00
/* try to read the superblock from this device
* to get more info
*/
int fd = open(dv, O_RDONLY);
if (fd >=0 &&
load_super(fd, &super) ==0 &&
2004-01-22 03:10:29 +01:00
(unsigned long)super.ctime == (unsigned long)array.ctime &&
(unsigned int)super.level == (unsigned int)array.level)
2002-03-07 00:17:40 +01:00
have_super = 1;
}
2001-07-26 09:00:09 +02:00
}
2002-03-07 00:17:40 +01:00
if (!brief) printf("\n");
2001-06-08 04:36:23 +02:00
}
2003-10-29 00:20:01 +01:00
if (spares && brief) printf(" spares=%d", spares);
2001-07-26 09:00:09 +02:00
if (have_super) {
2002-03-07 00:17:40 +01:00
if (brief) printf(" UUID=");
else printf(" UUID : ");
2001-07-26 09:00:09 +02:00
if (super.minor_version >= 90)
2002-03-07 00:17:40 +01:00
printf("%08x:%08x:%08x:%08x", super.set_uuid0, super.set_uuid1,
super.set_uuid2, super.set_uuid3);
else
printf("%08x", super.set_uuid0);
2003-02-12 01:17:26 +01:00
if (!brief)
printf("\n Events : %d.%d\n", super.events_hi, super.events_lo);
2001-07-26 09:00:09 +02:00
}
2003-03-03 00:11:38 +01:00
if (brief && devices) printf("\n devices=%s", devices);
2002-03-07 00:17:40 +01:00
if (brief) printf("\n");
2003-10-29 00:20:01 +01:00
if (test && (rv&2)) rv &= ~1;
return rv;
2001-06-08 04:36:23 +02:00
}