]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
sysfs: Parse array_state in sysfs_read()
authorJes Sorensen <jsorensen@fb.com>
Thu, 20 Apr 2017 03:27:58 +0000 (23:27 -0400)
committerJes Sorensen <jsorensen@fb.com>
Thu, 20 Apr 2017 04:12:27 +0000 (00:12 -0400)
Rather than copying in the array_state string, parse it and use an
enum to indicate the state.

Signed-off-by: Jes Sorensen <jsorensen@fb.com>
Manage.c
maps.c
mdadm.h
sysfs.c

index bb84d28409bb2a86533b1602e4bbace8d5f854cf..8966e3368d1e3c7b47de9d6a19e93b5aadf46351 100644 (file)
--- a/Manage.c
+++ b/Manage.c
@@ -929,7 +929,7 @@ int Manage_add(int fd, int tfd, struct mddev_dev *dv,
                        return -1;
                }
 
-               if (strncmp(mdp->sysfs_array_state, "readonly", 8) != 0) {
+               if (mdp->array_state != ARRAY_READONLY) {
                        sysfs_free(mdp);
                        pr_err("%s is not readonly, cannot add journal.\n", devname);
                        return -1;
diff --git a/maps.c b/maps.c
index d9ee7de440ce5d72f2a73b2ad0ba2eb859bebc4d..a8a4639a84ec3246d62f3912daca5c1da028edd9 100644 (file)
--- a/maps.c
+++ b/maps.c
@@ -139,6 +139,23 @@ mapping_t consistency_policies[] = {
        { NULL, 0}
 };
 
+mapping_t sysfs_array_states[] = {
+       /*
+        * Beware map_name() uses strcmp() so active-idle must come before
+        * active, to be detected correctly.
+        */
+       { "active-idle", ARRAY_ACTIVE_IDLE },
+       { "active", ARRAY_ACTIVE },
+       { "clear", ARRAY_CLEAR },
+       { "inactive", ARRAY_INACTIVE },
+       { "suspended", ARRAY_SUSPENDED },
+       { "readonly", ARRAY_READONLY },
+       { "read-auto", ARRAY_READ_AUTO },
+       { "clean", ARRAY_CLEAN },
+       { "write-pending", ARRAY_WRITE_PENDING },
+       { NULL, 0 }
+};
+
 char *map_num(mapping_t *map, int num)
 {
        while (map->name) {
diff --git a/mdadm.h b/mdadm.h
index f1f643c794d4b36fb1065d3450ab24d4aaa488db..a3799733a4d9f11d65160b49c366caac79602bb4 100644 (file)
--- a/mdadm.h
+++ b/mdadm.h
@@ -335,8 +335,18 @@ struct mdinfo {
        int prev_state, curr_state, next_state;
 
        /* info read from sysfs */
-       char            sysfs_array_state[20];
-
+       enum {
+               ARRAY_CLEAR,
+               ARRAY_INACTIVE,
+               ARRAY_SUSPENDED,
+               ARRAY_READONLY,
+               ARRAY_READ_AUTO,
+               ARRAY_CLEAN,
+               ARRAY_ACTIVE,
+               ARRAY_WRITE_PENDING,
+               ARRAY_ACTIVE_IDLE,
+               ARRAY_UNKNOWN_STATE,
+       } array_state;
        struct md_bb bb;
 };
 
@@ -716,7 +726,8 @@ extern int restore_stripes(int *dest, unsigned long long *offsets,
 
 extern char *map_num(mapping_t *map, int num);
 extern int map_name(mapping_t *map, char *name);
-extern mapping_t r5layout[], r6layout[], pers[], modes[], faultylayout[], consistency_policies[];
+extern mapping_t r5layout[], r6layout[], pers[], modes[], faultylayout[];
+extern mapping_t consistency_policies[], sysfs_array_states[];
 
 extern char *map_dev_preferred(int major, int minor, int create,
                               char *prefer);
diff --git a/sysfs.c b/sysfs.c
index 51deb2376f3cd85c87ba66ec8a27ae01347f5751..c6df9b06cd7988ce9c44bc4b2c0dcefc6db3e97a 100644 (file)
--- a/sysfs.c
+++ b/sysfs.c
@@ -247,11 +247,12 @@ struct mdinfo *sysfs_read(int fd, char *devnm, unsigned long options)
 
        if (options & GET_ARRAY_STATE) {
                strcpy(base, "array_state");
-               if (load_sys(fname, sra->sysfs_array_state,
-                            sizeof(sra->sysfs_array_state)))
+               if (load_sys(fname, buf, sizeof(buf)))
                        goto abort;
-       } else
-               sra->sysfs_array_state[0] = 0;
+               sra->array_state = map_name(sysfs_array_states, buf);
+               if (sra->array_state == UnSet)
+                       sra->array_state = ARRAY_UNKNOWN_STATE;
+       }
 
        if (options & GET_CONSISTENCY_POLICY) {
                strcpy(base, "consistency_policy");