2002-04-04 03:58:32 +02:00
|
|
|
/*
|
|
|
|
* mdadm - manage Linux "md" devices aka RAID arrays.
|
|
|
|
*
|
2006-05-19 07:25:11 +02:00
|
|
|
* Copyright (C) 2002-2006 Neil Brown <neilb@suse.de>
|
2002-04-04 03:58:32 +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
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "mdadm.h"
|
|
|
|
#include "md_p.h"
|
|
|
|
#include "md_u.h"
|
|
|
|
|
|
|
|
int Query(char *dev)
|
|
|
|
{
|
|
|
|
/* Give a brief description of the device,
|
|
|
|
* whether it is an md device and whether it has
|
|
|
|
* a superblock
|
|
|
|
*/
|
|
|
|
int fd = open(dev, O_RDONLY, 0);
|
|
|
|
int vers;
|
|
|
|
int ioctlerr;
|
|
|
|
int superror, superrno;
|
2005-05-04 01:44:18 +02:00
|
|
|
struct mdinfo info;
|
2002-04-04 03:58:32 +02:00
|
|
|
mdu_array_info_t array;
|
2005-05-04 01:44:18 +02:00
|
|
|
void *super;
|
2005-05-04 01:44:40 +02:00
|
|
|
struct supertype *st = NULL;
|
2005-05-04 01:44:18 +02:00
|
|
|
|
2002-04-04 03:58:32 +02:00
|
|
|
unsigned long long larray_size;
|
|
|
|
unsigned long array_size;
|
|
|
|
struct stat stb;
|
|
|
|
char *mddev;
|
|
|
|
mdu_disk_info_t disc;
|
|
|
|
char *activity;
|
|
|
|
|
|
|
|
if (fd < 0){
|
|
|
|
fprintf(stderr, Name ": cannot open %s: %s\n",
|
|
|
|
dev, strerror(errno));
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
vers = md_get_version(fd);
|
|
|
|
if (ioctl(fd, GET_ARRAY_INFO, &array)<0)
|
|
|
|
ioctlerr = errno;
|
|
|
|
else ioctlerr = 0;
|
|
|
|
|
|
|
|
fstat(fd, &stb);
|
|
|
|
|
|
|
|
if (vers>=9000 && !ioctlerr) {
|
|
|
|
#ifdef BLKGETSIZE64
|
|
|
|
if (ioctl(fd, BLKGETSIZE64, &larray_size)==0)
|
|
|
|
;
|
|
|
|
else
|
|
|
|
#endif
|
2002-04-11 03:36:14 +02:00
|
|
|
if (ioctl(fd, BLKGETSIZE, &array_size)==0) {
|
|
|
|
larray_size = array_size;
|
|
|
|
larray_size <<= 9;
|
|
|
|
} else larray_size = 0;
|
2002-04-04 03:58:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (vers < 0)
|
|
|
|
printf("%s: is not an md array\n", dev);
|
|
|
|
else if (vers < 9000)
|
|
|
|
printf("%s: is an md device, but kernel cannot provide details\n", dev);
|
|
|
|
else if (ioctlerr == ENODEV)
|
|
|
|
printf("%s: is an md device which is not active\n", dev);
|
|
|
|
else if (ioctlerr)
|
|
|
|
printf("%s: is an md device, but gives \"%s\" when queried\n",
|
|
|
|
dev, strerror(ioctlerr));
|
|
|
|
else {
|
|
|
|
printf("%s: %s %s %d devices, %d spare%s. Use mdadm --detail for more detail.\n",
|
|
|
|
dev,
|
|
|
|
human_size_brief(larray_size),
|
|
|
|
map_num(pers, array.level),
|
|
|
|
array.raid_disks,
|
|
|
|
array.spare_disks, array.spare_disks==1?"":"s");
|
|
|
|
}
|
2005-05-04 01:44:40 +02:00
|
|
|
st = guess_super(fd);
|
|
|
|
if (st) {
|
|
|
|
superror = st->ss->load_super(st, fd, &super, dev);
|
2005-05-04 01:44:32 +02:00
|
|
|
superrno = errno;
|
|
|
|
} else
|
|
|
|
superror = -1;
|
2005-05-04 01:44:18 +02:00
|
|
|
close(fd);
|
|
|
|
if (superror == 0) {
|
2002-04-04 03:58:32 +02:00
|
|
|
/* array might be active... */
|
2006-03-27 06:34:38 +02:00
|
|
|
st->ss->getinfo_super(&info, super);
|
2005-07-18 03:30:42 +02:00
|
|
|
if (st->ss->major == 0) {
|
|
|
|
mddev = get_md_name(info.array.md_minor);
|
|
|
|
disc.number = info.disk.number;
|
|
|
|
activity = "undetected";
|
|
|
|
if (mddev && (fd = open(mddev, O_RDONLY))>=0) {
|
|
|
|
if (md_get_version(fd) >= 9000 &&
|
|
|
|
ioctl(fd, GET_ARRAY_INFO, &array)>= 0) {
|
|
|
|
if (ioctl(fd, GET_DISK_INFO, &disc) >= 0 &&
|
|
|
|
makedev((unsigned)disc.major,(unsigned)disc.minor) == stb.st_rdev)
|
|
|
|
activity = "active";
|
|
|
|
else
|
|
|
|
activity = "mismatch";
|
|
|
|
}
|
|
|
|
close(fd);
|
2002-04-04 03:58:32 +02:00
|
|
|
}
|
2005-07-18 03:30:42 +02:00
|
|
|
} else {
|
|
|
|
activity = "unknown";
|
|
|
|
mddev = "array";
|
2002-04-04 03:58:32 +02:00
|
|
|
}
|
2005-07-18 03:30:42 +02:00
|
|
|
printf("%s: device %d in %d device %s %s %s. Use mdadm --examine for more detail.\n",
|
2002-04-04 03:58:32 +02:00
|
|
|
dev,
|
2005-05-04 01:44:18 +02:00
|
|
|
info.disk.number, info.array.raid_disks,
|
2002-04-04 03:58:32 +02:00
|
|
|
activity,
|
2005-05-04 01:44:18 +02:00
|
|
|
map_num(pers, info.array.level),
|
2005-07-18 03:30:42 +02:00
|
|
|
mddev);
|
2006-05-26 03:40:53 +02:00
|
|
|
if (st->ss->major == 0)
|
|
|
|
put_md_name(mddev);
|
2002-04-04 03:58:32 +02:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|