summaryrefslogtreecommitdiffstats
path: root/Query.c
diff options
context:
space:
mode:
authorJes Sorensen <jsorensen@fb.com>2017-04-13 18:20:46 +0200
committerJes Sorensen <jsorensen@fb.com>2017-04-13 18:20:46 +0200
commitf22d6cde7c7e4be38230ac4c51c3af850ed1614e (patch)
treedc40b3ce86e7f53636b77b9125f95c5e507d1f94 /Query.c
parentQuery: Handle error returned by fstat() (diff)
downloadmdadm-f22d6cde7c7e4be38230ac4c51c3af850ed1614e.tar.xz
mdadm-f22d6cde7c7e4be38230ac4c51c3af850ed1614e.zip
Query: Use sysfs to obtain data if possible
Use sysfs to obtain leve, raid_disks, and spare_disks. If sysfs fails, fall back to calling the ioctl via md_get_array_info(). Signed-off-by: Jes Sorensen <jsorensen@fb.com>
Diffstat (limited to 'Query.c')
-rw-r--r--Query.c32
1 files changed, 22 insertions, 10 deletions
diff --git a/Query.c b/Query.c
index 0d18da4e..b761c470 100644
--- a/Query.c
+++ b/Query.c
@@ -35,7 +35,9 @@ int Query(char *dev)
int fd;
int ioctlerr, staterr;
int superror;
+ int level, raid_disks, spare_disks;
struct mdinfo info;
+ struct mdinfo *sra;
mdu_array_info_t array;
struct supertype *st = NULL;
unsigned long long larray_size;
@@ -50,16 +52,28 @@ int Query(char *dev)
return 1;
}
- if (md_get_array_info(fd, &array) < 0)
- ioctlerr = errno;
- else
- ioctlerr = 0;
-
if (fstat(fd, &stb) < 0)
staterr = errno;
else
staterr = 0;
+ ioctlerr = 0;
+
+ sra = sysfs_read(fd, dev, GET_DISKS | GET_LEVEL | GET_DEVS | GET_STATE);
+ if (sra) {
+ level = sra->array.level;
+ raid_disks = sra->array.raid_disks;
+ spare_disks = sra->array.spare_disks;
+ } else {
+ if (md_get_array_info(fd, &array) < 0) {
+ ioctlerr = errno;
+ } else {
+ level = array.level;
+ raid_disks = array.raid_disks;
+ spare_disks = array.spare_disks;
+ }
+ }
+
if (!ioctlerr && !staterr) {
if (!get_dev_size(fd, NULL, &larray_size))
larray_size = 0;
@@ -75,11 +89,9 @@ int Query(char *dev)
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,IEC),
- map_num(pers, array.level),
- array.raid_disks,
- array.spare_disks, array.spare_disks==1?"":"s");
+ dev, human_size_brief(larray_size,IEC),
+ map_num(pers, level), raid_disks,
+ spare_disks, spare_disks == 1 ? "" : "s");
}
st = guess_super(fd);
if (st && st->ss->compare_super != NULL)