]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
start resync when transitioning from initial readonly state
authorDan Williams <dan.j.williams@intel.com>
Thu, 15 May 2008 06:48:39 +0000 (16:48 +1000)
committerNeil Brown <neilb@suse.de>
Thu, 15 May 2008 06:48:39 +0000 (16:48 +1000)
From: Dan Williams <dan.j.williams@intel.com>

mdadm handles setting resync_start, monitor uses this value to determine
whether to set the 'active' or 'readauto' state.

Signed-off-by: Dan Williams <dan.j.williams@intel.com>
managemon.c
mdmon.h
monitor.c

index ee4ee2b91eca83232a1f8a1cb853f8bcdd4e7438..14e7184b0359801dd5fd9b25b3c674011635d177 100644 (file)
@@ -232,6 +232,7 @@ static void manage_new(struct mdstat_ent *mdstat,
        }
        new->action_fd = sysfs_open(new->devnum, NULL, "sync_action");
        new->info.state_fd = sysfs_open(new->devnum, NULL, "array_state");
+       new->resync_start_fd = sysfs_open(new->devnum, NULL, "resync_start");
        new->sync_pos_fd = sysfs_open(new->devnum, NULL, "sync_completed");
        new->sync_pos = 0;
 
diff --git a/mdmon.h b/mdmon.h
index 497bbec2445e1946c57dbe767d24d3325d71351b..3886b09eaaf10d65c548c69c41fb2d21083167f4 100644 (file)
--- a/mdmon.h
+++ b/mdmon.h
@@ -12,6 +12,7 @@ struct active_array {
 
        int action_fd;
        int sync_pos_fd;
+       int resync_start_fd;
 
        enum array_state prev_state, curr_state, next_state;
        enum sync_action prev_action, curr_action, next_action;
@@ -19,6 +20,7 @@ struct active_array {
        int devnum;
 
        unsigned long long sync_pos;
+       unsigned long long resync_start;
 };
 
 
index 38725d1817149063f8b86de59192148c93e472a8..8f5ad46f767b591327249b40a021f6cb9c5a7282 100644 (file)
--- a/monitor.c
+++ b/monitor.c
@@ -64,6 +64,19 @@ static int get_sync_pos(struct active_array *a)
        return 1;
 }
 
+static int get_resync_start(struct active_array *a)
+{
+       char buf[30];
+       int n;
+
+       n = read_attr(buf, 30, a->resync_start_fd);
+       if (n <= 0)
+               return n;
+
+       a->resync_start = strtoull(buf, NULL, 10);
+
+       return 1;
+}
 
 static int attr_match(const char *attr, const char *str)
 {
@@ -191,12 +204,10 @@ int read_dev_state(int fd)
  *    Start recovery.
  *
  *  deal with resync
- *    This only happens on finding a new array....
- *      Maybe this is done by mdadm before passing the array to us?
- *
- *    If array is 'clean' but metadata is 'dirty', start a resync
- *    and mark array as 'dirty'.
- *
+ *    This only happens on finding a new array... mdadm will have set
+ *    'resync_start' to the correct value.  If 'resync_start' indicates that an
+ *    resync needs to occur set the array to the 'active' state rather than the
+ *    initial read-auto state.
  *
  *
  *
@@ -252,7 +263,13 @@ static int read_and_act(struct active_array *a)
                 * read-auto is OK. FIXME what if we really want
                 * readonly ???
                 */
-               a->next_state = read_auto;
+               get_resync_start(a);
+               if (a->resync_start == ~0ULL)
+                       a->next_state = read_auto; /* array is clean */
+               else {
+                       a->container->ss->mark_dirty(a);
+                       a->next_state = active;
+               }
        }
 
        if (a->curr_action == idle &&