dcavalca / rpms / mdadm

Forked from rpms/mdadm 3 years ago
Clone

Blame SOURCES/Detail-correct-outputfor-active-arrays.patch

b7f731
From a822017f30e0dadc60a687900c2aa4da32e09a93 Mon Sep 17 00:00:00 2001
b7f731
From: Mariusz Tkaczyk <mariusz.tkaczyk@intel.com>
b7f731
Date: Thu, 10 Aug 2017 11:43:48 +0200
b7f731
Subject: [RHEL7.5 PATCH 162/169] Detail: correct output for active arrays
b7f731
b7f731
The check for inactive array is incorrect as it compares it against
b7f731
active array. Introduce a new function md_is_array_active so the check
b7f731
is consistent across the code.
b7f731
b7f731
As the output contains list of disks in the array include this
b7f731
information in sysfs read.
b7f731
b7f731
Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@intel.com>
b7f731
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
b7f731
---
b7f731
 Detail.c | 15 +++++++--------
b7f731
 mdadm.h  |  1 +
b7f731
 util.c   | 15 +++++++++------
b7f731
 3 files changed, 17 insertions(+), 14 deletions(-)
b7f731
b7f731
diff --git a/Detail.c b/Detail.c
b7f731
index 2332b85..2c9fb24 100644
b7f731
--- a/Detail.c
b7f731
+++ b/Detail.c
b7f731
@@ -86,7 +86,8 @@ int Detail(char *dev, struct context *c)
b7f731
 			dev, strerror(errno));
b7f731
 		return rv;
b7f731
 	}
b7f731
-	sra = sysfs_read(fd, NULL, GET_VERSION | GET_DEVS | GET_ARRAY_STATE);
b7f731
+	sra = sysfs_read(fd, NULL, GET_VERSION | GET_DEVS |
b7f731
+			GET_ARRAY_STATE | GET_STATE);
b7f731
 	if (!sra) {
b7f731
 		if (md_get_array_info(fd, &array)) {
b7f731
 			pr_err("%s does not appear to be an md device\n", dev);
b7f731
@@ -96,8 +97,7 @@ int Detail(char *dev, struct context *c)
b7f731
 	}
b7f731
 	external = (sra != NULL && sra->array.major_version == -1 &&
b7f731
 		    sra->array.minor_version == -2);
b7f731
-	inactive = (sra->array_state == ARRAY_ACTIVE ||
b7f731
-		    sra->array_state == ARRAY_CLEAR);
b7f731
+	inactive = (sra != NULL && !md_array_is_active(sra));
b7f731
 	st = super_by_fd(fd, &subarray);
b7f731
 	if (md_get_array_info(fd, &array)) {
b7f731
 		if (errno == ENODEV) {
b7f731
@@ -314,11 +314,10 @@ int Detail(char *dev, struct context *c)
b7f731
 	next = array.raid_disks * 2;
b7f731
 	if (inactive) {
b7f731
 		struct mdinfo *mdi;
b7f731
-		if (sra != NULL)
b7f731
-			for (mdi = sra->devs; mdi; mdi = mdi->next) {
b7f731
-				disks[next++] = mdi->disk;
b7f731
-				disks[next - 1].number = -1;
b7f731
-			}
b7f731
+		for (mdi = sra->devs; mdi; mdi = mdi->next) {
b7f731
+			disks[next++] = mdi->disk;
b7f731
+			disks[next - 1].number = -1;
b7f731
+		}
b7f731
 	} else for (d = 0; d < max_disks; d++) {
b7f731
 		mdu_disk_info_t disk;
b7f731
 		disk.number = d;
b7f731
diff --git a/mdadm.h b/mdadm.h
b7f731
index ee9b837..191ae8f 100644
b7f731
--- a/mdadm.h
b7f731
+++ b/mdadm.h
b7f731
@@ -1425,6 +1425,7 @@ extern int Restore_metadata(char *dev, char *dir, struct context *c,
b7f731
 
b7f731
 int md_array_valid(int fd);
b7f731
 int md_array_active(int fd);
b7f731
+int md_array_is_active(struct mdinfo *info);
b7f731
 int md_get_array_info(int fd, struct mdu_array_info_s *array);
b7f731
 int md_set_array_info(int fd, struct mdu_array_info_s *array);
b7f731
 int md_get_disk_info(int fd, struct mdu_disk_info_s *disk);
b7f731
diff --git a/util.c b/util.c
b7f731
index 8eeb509..c1c8509 100644
b7f731
--- a/util.c
b7f731
+++ b/util.c
b7f731
@@ -228,15 +228,11 @@ int md_array_active(int fd)
b7f731
 {
b7f731
 	struct mdinfo *sra;
b7f731
 	struct mdu_array_info_s array;
b7f731
-	int ret;
b7f731
+	int ret = 0;
b7f731
 
b7f731
 	sra = sysfs_read(fd, NULL, GET_ARRAY_STATE);
b7f731
 	if (sra) {
b7f731
-		if (sra->array_state != ARRAY_CLEAR &&
b7f731
-		    sra->array_state != ARRAY_INACTIVE &&
b7f731
-		    sra->array_state != ARRAY_UNKNOWN_STATE)
b7f731
-			ret = 0;
b7f731
-		else
b7f731
+		if (!md_array_is_active(sra))
b7f731
 			ret = -ENODEV;
b7f731
 
b7f731
 		free(sra);
b7f731
@@ -251,6 +247,13 @@ int md_array_active(int fd)
b7f731
 	return !ret;
b7f731
 }
b7f731
 
b7f731
+int md_array_is_active(struct mdinfo *info)
b7f731
+{
b7f731
+	return (info->array_state != ARRAY_CLEAR &&
b7f731
+		info->array_state != ARRAY_INACTIVE &&
b7f731
+		info->array_state != ARRAY_UNKNOWN_STATE);
b7f731
+}
b7f731
+
b7f731
 /*
b7f731
  * Get array info from the kernel. Longer term we want to deprecate the
b7f731
  * ioctl and get it from sysfs.
b7f731
-- 
b7f731
2.7.4
b7f731