You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
100 lines
2.8 KiB
100 lines
2.8 KiB
6 years ago
|
From 3ab8f4bf33d906cb1084f7b4036556bfb4bb73ec Mon Sep 17 00:00:00 2001
|
||
|
From: Jes Sorensen <jsorensen@fb.com>
|
||
|
Date: Thu, 13 Apr 2017 13:30:17 -0400
|
||
|
Subject: [RHEL7.5 PATCH 082/169] util: Introduce md_array_active() helper
|
||
|
|
||
|
Rather than querying md_get_array_info() to determine whether an array
|
||
|
is valid, do the work in md_array_active() using sysfs, and fall back
|
||
|
on md_get_array_info() if sysfs fails.
|
||
|
|
||
|
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
|
||
|
---
|
||
|
Query.c | 5 +++--
|
||
|
mdadm.h | 1 +
|
||
|
util.c | 27 +++++++++++++++++++++++++++
|
||
|
3 files changed, 31 insertions(+), 2 deletions(-)
|
||
|
|
||
|
diff --git a/Query.c b/Query.c
|
||
|
index b761c47..4dec9f5 100644
|
||
|
--- a/Query.c
|
||
|
+++ b/Query.c
|
||
|
@@ -38,7 +38,6 @@ int Query(char *dev)
|
||
|
int level, raid_disks, spare_disks;
|
||
|
struct mdinfo info;
|
||
|
struct mdinfo *sra;
|
||
|
- mdu_array_info_t array;
|
||
|
struct supertype *st = NULL;
|
||
|
unsigned long long larray_size;
|
||
|
struct stat stb;
|
||
|
@@ -65,6 +64,8 @@ int Query(char *dev)
|
||
|
raid_disks = sra->array.raid_disks;
|
||
|
spare_disks = sra->array.spare_disks;
|
||
|
} else {
|
||
|
+ mdu_array_info_t array;
|
||
|
+
|
||
|
if (md_get_array_info(fd, &array) < 0) {
|
||
|
ioctlerr = errno;
|
||
|
} else {
|
||
|
@@ -111,7 +112,7 @@ int Query(char *dev)
|
||
|
disc.number = info.disk.number;
|
||
|
activity = "undetected";
|
||
|
if (mddev && (fd = open(mddev, O_RDONLY))>=0) {
|
||
|
- if (md_get_array_info(fd, &array) >= 0) {
|
||
|
+ if (md_array_active(fd)) {
|
||
|
if (md_get_disk_info(fd, &disc) >= 0 &&
|
||
|
makedev((unsigned)disc.major,(unsigned)disc.minor) == stb.st_rdev)
|
||
|
activity = "active";
|
||
|
diff --git a/mdadm.h b/mdadm.h
|
||
|
index a379973..f6e97fd 100644
|
||
|
--- a/mdadm.h
|
||
|
+++ b/mdadm.h
|
||
|
@@ -1415,6 +1415,7 @@ extern int Dump_metadata(char *dev, char *dir, struct context *c,
|
||
|
extern int Restore_metadata(char *dev, char *dir, struct context *c,
|
||
|
struct supertype *st, int only);
|
||
|
|
||
|
+int md_array_active(int fd);
|
||
|
int md_get_array_info(int fd, struct mdu_array_info_s *array);
|
||
|
int md_set_array_info(int fd, struct mdu_array_info_s *array);
|
||
|
int md_get_disk_info(int fd, struct mdu_disk_info_s *disk);
|
||
|
diff --git a/util.c b/util.c
|
||
|
index a695c45..3adc675 100644
|
||
|
--- a/util.c
|
||
|
+++ b/util.c
|
||
|
@@ -200,6 +200,33 @@ out:
|
||
|
return ret;
|
||
|
}
|
||
|
|
||
|
+int md_array_active(int fd)
|
||
|
+{
|
||
|
+ struct mdinfo *sra;
|
||
|
+ struct mdu_array_info_s array;
|
||
|
+ int ret;
|
||
|
+
|
||
|
+ sra = sysfs_read(fd, NULL, GET_ARRAY_STATE);
|
||
|
+ if (sra) {
|
||
|
+ if (sra->array_state != ARRAY_CLEAR &&
|
||
|
+ sra->array_state != ARRAY_INACTIVE &&
|
||
|
+ sra->array_state != ARRAY_UNKNOWN_STATE)
|
||
|
+ ret = 0;
|
||
|
+ else
|
||
|
+ ret = -ENODEV;
|
||
|
+
|
||
|
+ free(sra);
|
||
|
+ } else {
|
||
|
+ /*
|
||
|
+ * GET_ARRAY_INFO doesn't provide access to the proper state
|
||
|
+ * information, so fallback to a basic check for raid_disks != 0
|
||
|
+ */
|
||
|
+ ret = ioctl(fd, GET_ARRAY_INFO, &array);
|
||
|
+ }
|
||
|
+
|
||
|
+ return !ret;
|
||
|
+}
|
||
|
+
|
||
|
/*
|
||
|
* Get array info from the kernel. Longer term we want to deprecate the
|
||
|
* ioctl and get it from sysfs.
|
||
|
--
|
||
|
2.7.4
|
||
|
|