]> git.ipfire.org Git - thirdparty/mdadm.git/blobdiff - monitor.c
Factor out add-disk code
[thirdparty/mdadm.git] / monitor.c
index a1d87e1d1e65ccf716a00c3a1a235a1f55dc226c..bd67e1ad1e29798a117181cacc4c5d51ad89164e 100644 (file)
--- a/monitor.c
+++ b/monitor.c
@@ -47,7 +47,6 @@ static int read_attr(char *buf, int len, int fd)
        return n;
 }
 
-
 int get_resync_start(struct active_array *a)
 {
        char buf[30];
@@ -62,30 +61,6 @@ int get_resync_start(struct active_array *a)
        return 1;
 }
 
-static int attr_match(const char *attr, const char *str)
-{
-       /* See if attr, read from a sysfs file, matches
-        * str.  They must either be the same, or attr can
-        * have a trailing newline or comma
-        */
-       while (*attr && *str && *attr == *str) {
-               attr++;
-               str++;
-       }
-
-       if (*str || (*attr && *attr != ',' && *attr != '\n'))
-               return 0;
-       return 1;
-}
-
-static int match_word(const char *word, char **list)
-{
-       int n;
-       for (n=0; list[n]; n++)
-               if (attr_match(word, list[n]))
-                       break;
-       return n;
-}
 
 static enum array_state read_state(int fd)
 {
@@ -94,7 +69,7 @@ static enum array_state read_state(int fd)
 
        if (n <= 0)
                return bad_word;
-       return (enum array_state) match_word(buf, array_states);
+       return (enum array_state) sysfs_match_word(buf, array_states);
 }
 
 static enum sync_action read_action( int fd)
@@ -104,7 +79,7 @@ static enum sync_action read_action( int fd)
 
        if (n <= 0)
                return bad_action;
-       return (enum sync_action) match_word(buf, sync_actions);
+       return (enum sync_action) sysfs_match_word(buf, sync_actions);
 }
 
 int read_dev_state(int fd)
@@ -119,15 +94,15 @@ int read_dev_state(int fd)
 
        cp = buf;
        while (cp) {
-               if (attr_match(cp, "faulty"))
+               if (sysfs_attr_match(cp, "faulty"))
                        rv |= DS_FAULTY;
-               if (attr_match(cp, "in_sync"))
+               if (sysfs_attr_match(cp, "in_sync"))
                        rv |= DS_INSYNC;
-               if (attr_match(cp, "write_mostly"))
+               if (sysfs_attr_match(cp, "write_mostly"))
                        rv |= DS_WRITE_MOSTLY;
-               if (attr_match(cp, "spare"))
+               if (sysfs_attr_match(cp, "spare"))
                        rv |= DS_SPARE;
-               if (attr_match(cp, "blocked"))
+               if (sysfs_attr_match(cp, "blocked"))
                        rv |= DS_BLOCKED;
                cp = strchr(cp, ',');
                if (cp)
@@ -309,7 +284,8 @@ static int read_and_act(struct active_array *a)
        }
 
        a->container->ss->sync_metadata(a->container);
-       dprintf("%s: update[%d]: (", __func__, a->info.container_member);
+       dprintf("%s(%d): state:%s action:%s next(", __func__, a->info.container_member,
+               array_states[a->curr_state], sync_actions[a->curr_action]);
 
        /* Effect state changes in the array */
        if (a->next_state != bad_word) {
@@ -318,7 +294,7 @@ static int read_and_act(struct active_array *a)
        }
        if (a->next_action != bad_action) {
                write_attr(sync_actions[a->next_action], a->action_fd);
-               dprintf(" action:%s", array_states[a->next_state]);
+               dprintf(" action:%s", sync_actions[a->next_action]);
        }
        for (mdi = a->info.devs; mdi ; mdi = mdi->next) {
                if (mdi->next_state & DS_UNBLOCK) {