dcavalca / rpms / mdadm

Forked from rpms/mdadm 3 years ago
Clone

Blame SOURCES/util-Introduce6-md_array_active-helper.patch

2c1b57
From 3ab8f4bf33d906cb1084f7b4036556bfb4bb73ec Mon Sep 17 00:00:00 2001
2c1b57
From: Jes Sorensen <jsorensen@fb.com>
2c1b57
Date: Thu, 13 Apr 2017 13:30:17 -0400
2c1b57
Subject: [RHEL7.5 PATCH 082/169] util: Introduce md_array_active() helper
2c1b57
2c1b57
Rather than querying md_get_array_info() to determine whether an array
2c1b57
is valid, do the work in md_array_active() using sysfs, and fall back
2c1b57
on md_get_array_info() if sysfs fails.
2c1b57
2c1b57
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2c1b57
---
2c1b57
 Query.c |  5 +++--
2c1b57
 mdadm.h |  1 +
2c1b57
 util.c  | 27 +++++++++++++++++++++++++++
2c1b57
 3 files changed, 31 insertions(+), 2 deletions(-)
2c1b57
2c1b57
diff --git a/Query.c b/Query.c
2c1b57
index b761c47..4dec9f5 100644
2c1b57
--- a/Query.c
2c1b57
+++ b/Query.c
2c1b57
@@ -38,7 +38,6 @@ int Query(char *dev)
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
 	struct stat stb;
2c1b57
@@ -65,6 +64,8 @@ int Query(char *dev)
2c1b57
 		raid_disks = sra->array.raid_disks;
2c1b57
 		spare_disks = sra->array.spare_disks;
2c1b57
 	} else {
2c1b57
+		mdu_array_info_t array;
2c1b57
+
2c1b57
 		if (md_get_array_info(fd, &array) < 0) {
2c1b57
 			ioctlerr = errno;
2c1b57
 		} else {
2c1b57
@@ -111,7 +112,7 @@ int Query(char *dev)
2c1b57
 			disc.number = info.disk.number;
2c1b57
 			activity = "undetected";
2c1b57
 			if (mddev && (fd = open(mddev, O_RDONLY))>=0) {
2c1b57
-				if (md_get_array_info(fd, &array) >= 0) {
2c1b57
+				if (md_array_active(fd)) {
2c1b57
 					if (md_get_disk_info(fd, &disc) >= 0 &&
2c1b57
 					    makedev((unsigned)disc.major,(unsigned)disc.minor) == stb.st_rdev)
2c1b57
 						activity = "active";
2c1b57
diff --git a/mdadm.h b/mdadm.h
2c1b57
index a379973..f6e97fd 100644
2c1b57
--- a/mdadm.h
2c1b57
+++ b/mdadm.h
2c1b57
@@ -1415,6 +1415,7 @@ extern int Dump_metadata(char *dev, char *dir, struct context *c,
2c1b57
 extern int Restore_metadata(char *dev, char *dir, struct context *c,
2c1b57
 			    struct supertype *st, int only);
2c1b57
 
2c1b57
+int md_array_active(int fd);
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 a695c45..3adc675 100644
2c1b57
--- a/util.c
2c1b57
+++ b/util.c
2c1b57
@@ -200,6 +200,33 @@ out:
2c1b57
 	return ret;
2c1b57
 }
2c1b57
 
2c1b57
+int md_array_active(int fd)
2c1b57
+{
2c1b57
+	struct mdinfo *sra;
2c1b57
+	struct mdu_array_info_s array;
2c1b57
+	int ret;
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
+			ret = -ENODEV;
2c1b57
+
2c1b57
+		free(sra);
2c1b57
+	} else {
2c1b57
+		/*
2c1b57
+		 * GET_ARRAY_INFO doesn't provide access to the proper state
2c1b57
+		 * information, so fallback to a basic check for raid_disks != 0
2c1b57
+		 */
2c1b57
+		ret = ioctl(fd, GET_ARRAY_INFO, &array);
2c1b57
+	}
2c1b57
+
2c1b57
+	return !ret;
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