dcavalca / rpms / mdadm

Forked from rpms/mdadm 3 years ago
Clone

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

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