dcavalca / rpms / mdadm

Forked from rpms/mdadm 3 years ago
Clone

Blame SOURCES/Get-failed-disk-count-fromarray-state.patch

b7f731
From b13b52c80f3d9e3184ea1d6d39aa7053ef7bae49 Mon Sep 17 00:00:00 2001
b7f731
From: Tomasz Majchrzak <tomasz.majchrzak@intel.com>
b7f731
Date: Wed, 31 May 2017 12:46:57 +0200
b7f731
Subject: [RHEL7.5 PATCH 151/169] Get failed disk count from array state
b7f731
b7f731
Recent commit has changed the way failed disks are counted. It breaks
b7f731
recovery for external metadata arrays as failed disks are not part of
b7f731
the array and have no corresponding entries is sysfs (they are only
b7f731
reported for containers) so degraded arrays show no failed disks.
b7f731
b7f731
Recent commit overwrites GET_DEGRADED result prior to GET_STATE and it
b7f731
is not set again if GET_STATE has not been requested. As GET_STATE
b7f731
provides the same information as GET_DEGRADED, the latter is not needed
b7f731
anymore. Remove GET_DEGRADED option and replace it with GET_STATE
b7f731
option.
b7f731
b7f731
Don't count number of failed disks looking at sysfs entries but
b7f731
calculate it at the end. Do it only for arrays as containers report
b7f731
no disks, just spares.
b7f731
b7f731
Signed-off-by: Tomasz Majchrzak <tomasz.majchrzak@intel.com>
b7f731
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
b7f731
---
b7f731
 Incremental.c | 14 ++++----------
b7f731
 Monitor.c     |  4 ++--
b7f731
 managemon.c   |  4 ++--
b7f731
 mdadm.h       |  1 -
b7f731
 raid6check.c  |  2 +-
b7f731
 sysfs.c       | 18 ++++++++----------
b7f731
 6 files changed, 17 insertions(+), 26 deletions(-)
b7f731
b7f731
diff --git a/Incremental.c b/Incremental.c
b7f731
index 30dc7a2..6cf2174 100644
b7f731
--- a/Incremental.c
b7f731
+++ b/Incremental.c
b7f731
@@ -886,16 +886,10 @@ static int array_try_spare(char *devname, int *dfdp, struct dev_policy *pol,
b7f731
 		}
b7f731
 		sra = sysfs_read(-1, mp->devnm,
b7f731
 				 GET_DEVS|GET_OFFSET|GET_SIZE|GET_STATE|
b7f731
-				 GET_DEGRADED|GET_COMPONENT|GET_VERSION);
b7f731
-		if (!sra) {
b7f731
-			/* Probably a container - no degraded info */
b7f731
-			sra = sysfs_read(-1, mp->devnm,
b7f731
-					 GET_DEVS|GET_OFFSET|GET_SIZE|GET_STATE|
b7f731
-					 GET_COMPONENT|GET_VERSION);
b7f731
-			if (sra)
b7f731
-				sra->array.failed_disks = -1;
b7f731
-		}
b7f731
-		if (!sra)
b7f731
+				 GET_COMPONENT|GET_VERSION);
b7f731
+		if (sra)
b7f731
+			sra->array.failed_disks = -1;
b7f731
+		else
b7f731
 			continue;
b7f731
 		if (st == NULL) {
b7f731
 			int i;
b7f731
diff --git a/Monitor.c b/Monitor.c
b7f731
index 725f47d..bef2f1b 100644
b7f731
--- a/Monitor.c
b7f731
+++ b/Monitor.c
b7f731
@@ -485,8 +485,8 @@ static int check_array(struct state *st, struct mdstat_ent *mdstat,
b7f731
 	if (st->devnm[0] == 0)
b7f731
 		strcpy(st->devnm, fd2devnm(fd));
b7f731
 
b7f731
-	sra = sysfs_read(-1, st->devnm, GET_LEVEL | GET_DISKS | GET_DEGRADED |
b7f731
-			 GET_MISMATCH | GET_DEVS | GET_STATE);
b7f731
+	sra = sysfs_read(-1, st->devnm, GET_LEVEL | GET_DISKS | GET_MISMATCH |
b7f731
+			 GET_DEVS | GET_STATE);
b7f731
 	if (!sra)
b7f731
 		goto disappeared;
b7f731
 
b7f731
diff --git a/managemon.c b/managemon.c
b7f731
index a8df666..68f0c2d 100644
b7f731
--- a/managemon.c
b7f731
+++ b/managemon.c
b7f731
@@ -685,8 +685,8 @@ static void manage_new(struct mdstat_ent *mdstat,
b7f731
 
b7f731
 	mdi = sysfs_read(-1, mdstat->devnm,
b7f731
 			 GET_LEVEL|GET_CHUNK|GET_DISKS|GET_COMPONENT|
b7f731
-			 GET_DEGRADED|GET_SAFEMODE|
b7f731
-			 GET_DEVS|GET_OFFSET|GET_SIZE|GET_STATE|GET_LAYOUT);
b7f731
+			 GET_SAFEMODE|GET_DEVS|GET_OFFSET|GET_SIZE|GET_STATE|
b7f731
+			 GET_LAYOUT);
b7f731
 
b7f731
 	if (!mdi)
b7f731
 		return;
b7f731
diff --git a/mdadm.h b/mdadm.h
b7f731
index ec0a39e..ee9b837 100644
b7f731
--- a/mdadm.h
b7f731
+++ b/mdadm.h
b7f731
@@ -637,7 +637,6 @@ enum sysfs_read_flags {
b7f731
 	GET_MISMATCH	= (1 << 5),
b7f731
 	GET_VERSION	= (1 << 6),
b7f731
 	GET_DISKS	= (1 << 7),
b7f731
-	GET_DEGRADED	= (1 << 8),
b7f731
 	GET_SAFEMODE	= (1 << 9),
b7f731
 	GET_BITMAP_LOCATION = (1 << 10),
b7f731
 
b7f731
diff --git a/raid6check.c b/raid6check.c
b7f731
index 551f835..a8e6005 100644
b7f731
--- a/raid6check.c
b7f731
+++ b/raid6check.c
b7f731
@@ -562,7 +562,7 @@ int main(int argc, char *argv[])
b7f731
 			  GET_LEVEL|
b7f731
 			  GET_LAYOUT|
b7f731
 			  GET_DISKS|
b7f731
-			  GET_DEGRADED |
b7f731
+			  GET_STATE |
b7f731
 			  GET_COMPONENT|
b7f731
 			  GET_CHUNK|
b7f731
 			  GET_DEVS|
b7f731
diff --git a/sysfs.c b/sysfs.c
b7f731
index e47f5e4..78d2b52 100644
b7f731
--- a/sysfs.c
b7f731
+++ b/sysfs.c
b7f731
@@ -162,18 +162,12 @@ struct mdinfo *sysfs_read(int fd, char *devnm, unsigned long options)
b7f731
 			goto abort;
b7f731
 		sra->array.layout = strtoul(buf, NULL, 0);
b7f731
 	}
b7f731
-	if (options & GET_DISKS) {
b7f731
+	if (options & (GET_DISKS|GET_STATE)) {
b7f731
 		strcpy(base, "raid_disks");
b7f731
 		if (load_sys(fname, buf, sizeof(buf)))
b7f731
 			goto abort;
b7f731
 		sra->array.raid_disks = strtoul(buf, NULL, 0);
b7f731
 	}
b7f731
-	if (options & GET_DEGRADED) {
b7f731
-		strcpy(base, "degraded");
b7f731
-		if (load_sys(fname, buf, sizeof(buf)))
b7f731
-			goto abort;
b7f731
-		sra->array.failed_disks = strtoul(buf, NULL, 0);
b7f731
-	}
b7f731
 	if (options & GET_COMPONENT) {
b7f731
 		strcpy(base, "component_size");
b7f731
 		if (load_sys(fname, buf, sizeof(buf)))
b7f731
@@ -359,10 +353,9 @@ struct mdinfo *sysfs_read(int fd, char *devnm, unsigned long options)
b7f731
 			strcpy(dbase, "state");
b7f731
 			if (load_sys(fname, buf, sizeof(buf)))
b7f731
 				goto abort;
b7f731
-			if (strstr(buf, "faulty")) {
b7f731
+			if (strstr(buf, "faulty"))
b7f731
 				dev->disk.state |= (1<
b7f731
-				sra->array.failed_disks++;
b7f731
-			} else {
b7f731
+			else {
b7f731
 				sra->array.working_disks++;
b7f731
 				if (strstr(buf, "in_sync")) {
b7f731
 					dev->disk.state |= (1<
b7f731
@@ -379,6 +372,11 @@ struct mdinfo *sysfs_read(int fd, char *devnm, unsigned long options)
b7f731
 			dev->errors = strtoul(buf, NULL, 0);
b7f731
 		}
b7f731
 	}
b7f731
+
b7f731
+	if ((options & GET_STATE) && sra->array.raid_disks)
b7f731
+		sra->array.failed_disks = sra->array.raid_disks -
b7f731
+			sra->array.active_disks - sra->array.spare_disks;
b7f731
+
b7f731
 	closedir(dir);
b7f731
 	return sra;
b7f731
 
b7f731
-- 
b7f731
2.7.4
b7f731