dcavalca / rpms / mdadm

Forked from rpms/mdadm 3 years ago
Clone

Blame SOURCES/Query-Use-sysfs-to-obtain-data-if-possible.patch

2c1b57
From f22d6cde7c7e4be38230ac4c51c3af850ed1614e Mon Sep 17 00:00:00 2001
2c1b57
From: Jes Sorensen <jsorensen@fb.com>
2c1b57
Date: Thu, 13 Apr 2017 12:20:46 -0400
2c1b57
Subject: [RHEL7.5 PATCH 080/169] Query: Use sysfs to obtain data if
2c1b57
 possible
2c1b57
2c1b57
Use sysfs to obtain leve, raid_disks, and spare_disks. If sysfs fails,
2c1b57
fall back to calling the ioctl via md_get_array_info().
2c1b57
2c1b57
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2c1b57
---
2c1b57
 Query.c | 32 ++++++++++++++++++++++----------
2c1b57
 1 file changed, 22 insertions(+), 10 deletions(-)
2c1b57
2c1b57
diff --git a/Query.c b/Query.c
2c1b57
index 0d18da4..b761c47 100644
2c1b57
--- a/Query.c
2c1b57
+++ b/Query.c
2c1b57
@@ -35,7 +35,9 @@ int Query(char *dev)
2c1b57
 	int fd;
2c1b57
 	int ioctlerr, staterr;
2c1b57
 	int superror;
2c1b57
+	int level, raid_disks, spare_disks;
2c1b57
 	struct mdinfo info;
2c1b57
+	struct mdinfo *sra;
2c1b57
 	mdu_array_info_t array;
2c1b57
 	struct supertype *st = NULL;
2c1b57
 	unsigned long long larray_size;
2c1b57
@@ -50,16 +52,28 @@ int Query(char *dev)
2c1b57
 		return 1;
2c1b57
 	}
2c1b57
 
2c1b57
-	if (md_get_array_info(fd, &array) < 0)
2c1b57
-		ioctlerr = errno;
2c1b57
-	else
2c1b57
-		ioctlerr = 0;
2c1b57
-
2c1b57
 	if (fstat(fd, &stb) < 0)
2c1b57
 		staterr = errno;
2c1b57
 	else
2c1b57
 		staterr = 0;
2c1b57
 
2c1b57
+	ioctlerr = 0;
2c1b57
+
2c1b57
+	sra = sysfs_read(fd, dev, GET_DISKS | GET_LEVEL | GET_DEVS | GET_STATE);
2c1b57
+	if (sra) {
2c1b57
+		level = sra->array.level;
2c1b57
+		raid_disks = sra->array.raid_disks;
2c1b57
+		spare_disks = sra->array.spare_disks;
2c1b57
+	} else {
2c1b57
+		if (md_get_array_info(fd, &array) < 0) {
2c1b57
+			ioctlerr = errno;
2c1b57
+		} else {
2c1b57
+			level = array.level;
2c1b57
+			raid_disks = array.raid_disks;
2c1b57
+			spare_disks = array.spare_disks;
2c1b57
+		}
2c1b57
+	}
2c1b57
+
2c1b57
 	if (!ioctlerr && !staterr) {
2c1b57
 		if (!get_dev_size(fd, NULL, &larray_size))
2c1b57
 			larray_size = 0;
2c1b57
@@ -75,11 +89,9 @@ int Query(char *dev)
2c1b57
 		       dev, strerror(ioctlerr));
2c1b57
 	else {
2c1b57
 		printf("%s: %s %s %d devices, %d spare%s. Use mdadm --detail for more detail.\n",
2c1b57
-		       dev,
2c1b57
-		       human_size_brief(larray_size,IEC),
2c1b57
-		       map_num(pers, array.level),
2c1b57
-		       array.raid_disks,
2c1b57
-		       array.spare_disks, array.spare_disks==1?"":"s");
2c1b57
+		       dev, human_size_brief(larray_size,IEC),
2c1b57
+		       map_num(pers, level), raid_disks,
2c1b57
+		       spare_disks, spare_disks == 1 ? "" : "s");
2c1b57
 	}
2c1b57
 	st = guess_super(fd);
2c1b57
 	if (st && st->ss->compare_super != NULL)
2c1b57
-- 
2c1b57
2.7.4
2c1b57