File 0117-container_members_max_degradation-Switch-to-using-sy.patch of Package mdadm.14070

From 74d293a2535ef8726a9d43577dad4a908f471a0e Mon Sep 17 00:00:00 2001
From: Jes Sorensen <jsorensen@fb.com>
Date: Fri, 5 May 2017 12:06:57 -0400
Subject: [PATCH] container_members_max_degradation: Switch to using syfs for
 disk info
Git-commit: 74d293a2535ef8726a9d43577dad4a908f471a0e
Patch-mainline: mdadm-4.0+
References: bsc#1069165, bsc#1069167, bsc#1068030

With sysfs now providing the necessary active_disks info, switch to
sysfs and eliminate one more use of md_get_array_info(). We can do
this unconditionally since we wouldn't get here witout sysfs being
available.

Signed-off-by: Jes Sorensen <jsorensen@fb.com>
Signed-off-by: Coly Li <colyli@suse.de>

---
 Incremental.c | 28 ++++++++++++++--------------
 1 file changed, 14 insertions(+), 14 deletions(-)

diff --git a/Incremental.c b/Incremental.c
index c00a43d..b73eabd 100644
--- a/Incremental.c
+++ b/Incremental.c
@@ -802,27 +802,27 @@ static int count_active(struct supertype *st, struct mdinfo *sra,
 }
 
 /* test if container has degraded member(s) */
-static int container_members_max_degradation(struct map_ent *map, struct map_ent *me)
+static int
+container_members_max_degradation(struct map_ent *map, struct map_ent *me)
 {
-	mdu_array_info_t array;
-	int afd;
-	int max_degraded = 0;
+	struct mdinfo *sra;
+	int degraded, max_degraded = 0;
 
 	for(; map; map = map->next) {
 		if (!metadata_container_matches(map->metadata, me->devnm))
 			continue;
-		afd = open_dev(map->devnm);
-		if (afd < 0)
-			continue;
 		/* most accurate information regarding array degradation */
-		if (md_get_array_info(afd, &array) >= 0) {
-			int degraded = array.raid_disks - array.active_disks -
-				       array.spare_disks;
-			if (degraded > max_degraded)
-				max_degraded = degraded;
-		}
-		close(afd);
+		sra = sysfs_read(-1, map->devnm,
+				 GET_DISKS | GET_DEVS | GET_STATE);
+		if (!sra)
+			continue;
+		degraded = sra->array.raid_disks - sra->array.active_disks -
+			sra->array.spare_disks;
+		if (degraded > max_degraded)
+			max_degraded = degraded;
+		sysfs_free(sra);
 	}
+
 	return max_degraded;
 }
 
-- 
2.13.6

openSUSE Build Service is sponsored by