* [PATCH] Detail: correct output for active arrays
@ 2017-08-10 9:43 Mariusz Tkaczyk
2017-08-16 8:20 ` Jes Sorensen
0 siblings, 1 reply; 2+ messages in thread
From: Mariusz Tkaczyk @ 2017-08-10 9:43 UTC (permalink / raw)
To: linux-raid; +Cc: jes.sorensen, Mariusz Tkaczyk
The check for inactive array is incorrect as it compares it against
active array. Introduce a new function md_is_array_active so the check
is consistent across the code.
As the output contains list of disks in the array include this
information in sysfs read.
Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@intel.com>
---
Detail.c | 15 +++++++--------
mdadm.h | 1 +
util.c | 15 +++++++++------
3 files changed, 17 insertions(+), 14 deletions(-)
diff --git a/Detail.c b/Detail.c
index 2332b85..2c9fb24 100644
--- a/Detail.c
+++ b/Detail.c
@@ -86,7 +86,8 @@ int Detail(char *dev, struct context *c)
dev, strerror(errno));
return rv;
}
- sra = sysfs_read(fd, NULL, GET_VERSION | GET_DEVS | GET_ARRAY_STATE);
+ sra = sysfs_read(fd, NULL, GET_VERSION | GET_DEVS |
+ GET_ARRAY_STATE | GET_STATE);
if (!sra) {
if (md_get_array_info(fd, &array)) {
pr_err("%s does not appear to be an md device\n", dev);
@@ -96,8 +97,7 @@ int Detail(char *dev, struct context *c)
}
external = (sra != NULL && sra->array.major_version == -1 &&
sra->array.minor_version == -2);
- inactive = (sra->array_state == ARRAY_ACTIVE ||
- sra->array_state == ARRAY_CLEAR);
+ inactive = (sra != NULL && !md_array_is_active(sra));
st = super_by_fd(fd, &subarray);
if (md_get_array_info(fd, &array)) {
if (errno == ENODEV) {
@@ -314,11 +314,10 @@ int Detail(char *dev, struct context *c)
next = array.raid_disks * 2;
if (inactive) {
struct mdinfo *mdi;
- if (sra != NULL)
- for (mdi = sra->devs; mdi; mdi = mdi->next) {
- disks[next++] = mdi->disk;
- disks[next - 1].number = -1;
- }
+ for (mdi = sra->devs; mdi; mdi = mdi->next) {
+ disks[next++] = mdi->disk;
+ disks[next - 1].number = -1;
+ }
} else for (d = 0; d < max_disks; d++) {
mdu_disk_info_t disk;
disk.number = d;
diff --git a/mdadm.h b/mdadm.h
index ee9b837..191ae8f 100644
--- a/mdadm.h
+++ b/mdadm.h
@@ -1425,6 +1425,7 @@ extern int Restore_metadata(char *dev, char *dir, struct context *c,
int md_array_valid(int fd);
int md_array_active(int fd);
+int md_array_is_active(struct mdinfo *info);
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 8eeb509..c1c8509 100644
--- a/util.c
+++ b/util.c
@@ -228,15 +228,11 @@ int md_array_active(int fd)
{
struct mdinfo *sra;
struct mdu_array_info_s array;
- int ret;
+ int ret = 0;
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
+ if (!md_array_is_active(sra))
ret = -ENODEV;
free(sra);
@@ -251,6 +247,13 @@ int md_array_active(int fd)
return !ret;
}
+int md_array_is_active(struct mdinfo *info)
+{
+ return (info->array_state != ARRAY_CLEAR &&
+ info->array_state != ARRAY_INACTIVE &&
+ info->array_state != ARRAY_UNKNOWN_STATE);
+}
+
/*
* Get array info from the kernel. Longer term we want to deprecate the
* ioctl and get it from sysfs.
--
1.8.3.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] Detail: correct output for active arrays
2017-08-10 9:43 [PATCH] Detail: correct output for active arrays Mariusz Tkaczyk
@ 2017-08-16 8:20 ` Jes Sorensen
0 siblings, 0 replies; 2+ messages in thread
From: Jes Sorensen @ 2017-08-16 8:20 UTC (permalink / raw)
To: Mariusz Tkaczyk, linux-raid
On 08/10/2017 05:43 AM, Mariusz Tkaczyk wrote:
> The check for inactive array is incorrect as it compares it against
> active array. Introduce a new function md_is_array_active so the check
> is consistent across the code.
>
> As the output contains list of disks in the array include this
> information in sysfs read.
>
> Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@intel.com>
> ---
> Detail.c | 15 +++++++--------
> mdadm.h | 1 +
> util.c | 15 +++++++++------
> 3 files changed, 17 insertions(+), 14 deletions(-)
Applied!
Thanks,
Jes
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2017-08-16 8:20 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-08-10 9:43 [PATCH] Detail: correct output for active arrays Mariusz Tkaczyk
2017-08-16 8:20 ` Jes Sorensen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).