dcavalca / rpms / mdadm

Forked from rpms/mdadm 3 years ago
Clone
Blob Blame History Raw
From f22d6cde7c7e4be38230ac4c51c3af850ed1614e Mon Sep 17 00:00:00 2001
From: Jes Sorensen <jsorensen@fb.com>
Date: Thu, 13 Apr 2017 12:20:46 -0400
Subject: [RHEL7.5 PATCH 080/169] 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>
---
 Query.c | 32 ++++++++++++++++++++++----------
 1 file changed, 22 insertions(+), 10 deletions(-)

diff --git a/Query.c b/Query.c
index 0d18da4..b761c47 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)
-- 
2.7.4