summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Query.c5
-rw-r--r--mdadm.h1
-rw-r--r--util.c27
3 files changed, 31 insertions, 2 deletions
diff --git a/Query.c b/Query.c
index b761c470..4dec9f51 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 a3799733..f6e97fdb 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 a695c45b..3adc675a 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.