/*
* mdmon - monitor external metadata arrays
*
- * Copyright (C) 2007-2008 Neil Brown <neilb@suse.de>
- * Copyright (C) 2007-2008 Intel Corporation
+ * Copyright (C) 2007-2009 Neil Brown <neilb@suse.de>
+ * Copyright (C) 2007-2009 Intel Corporation
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
return n;
}
-int get_resync_start(struct active_array *a)
+static unsigned long long read_resync_start(int fd)
{
char buf[30];
int n;
- n = read_attr(buf, 30, a->resync_start_fd);
+ n = read_attr(buf, 30, fd);
if (n <= 0)
- return n;
+ return 0;
+ if (strncmp(buf, "none", 4) == 0)
+ return MaxSector;
+ else
+ return strtoull(buf, NULL, 10);
+}
- a->resync_start = strtoull(buf, NULL, 10);
+static unsigned long long read_sync_completed(int fd)
+{
+ unsigned long long val;
+ char buf[50];
+ int n;
+ char *ep;
- return 1;
-}
+ n = read_attr(buf, 50, fd);
+ if (n <= 0)
+ return 0;
+ buf[n] = 0;
+ val = strtoull(buf, &ep, 0);
+ if (ep == buf || (*ep != 0 && *ep != '\n' && *ep != ' '))
+ return 0;
+ return val;
+}
static enum array_state read_state(int fd)
{
static int read_and_act(struct active_array *a)
{
+ unsigned long long sync_completed;
int check_degraded = 0;
int deactivate = 0;
struct mdinfo *mdi;
a->curr_state = read_state(a->info.state_fd);
a->curr_action = read_action(a->action_fd);
+ a->info.resync_start = read_resync_start(a->resync_start_fd);
+ sync_completed = read_sync_completed(a->sync_completed_fd);
for (mdi = a->info.devs; mdi ; mdi = mdi->next) {
mdi->next_state = 0;
- if (mdi->state_fd >= 0)
+ if (mdi->state_fd >= 0) {
+ mdi->recovery_start = read_resync_start(mdi->recovery_fd);
mdi->curr_state = read_dev_state(mdi->state_fd);
+ }
}
if (a->curr_state <= inactive &&
a->prev_state > inactive) {
/* array has been stopped */
- get_resync_start(a);
a->container->ss->set_array_state(a, 1);
a->next_state = clear;
deactivate = 1;
}
if (a->curr_state == write_pending) {
- get_resync_start(a);
a->container->ss->set_array_state(a, 0);
a->next_state = active;
dirty = 1;
dirty = 1;
}
if (a->curr_state == clean) {
- get_resync_start(a);
a->container->ss->set_array_state(a, 1);
}
if (a->curr_state == active ||
/* explicit request for readonly array. Leave it alone */
;
} else {
- get_resync_start(a);
if (a->container->ss->set_array_state(a, 2))
a->next_state = read_auto; /* array is clean */
else {
* until the array goes inactive or readonly though.
* Just check if we need to fiddle spares.
*/
- get_resync_start(a);
a->container->ss->set_array_state(a, a->curr_state <= clean);
check_degraded = 1;
}
}
}
+ /* Check for recovery checkpoint notifications. We need to be a
+ * minimum distance away from the last checkpoint to prevent
+ * over checkpointing. Note reshape checkpointing is not
+ * handled here.
+ */
+ if (sync_completed > a->last_checkpoint &&
+ sync_completed - a->last_checkpoint > a->info.component_size >> 4 &&
+ a->curr_action > reshape) {
+ /* A (non-reshape) sync_action has reached a checkpoint.
+ * Record the updated position in the metadata
+ */
+ a->last_checkpoint = sync_completed;
+ a->container->ss->set_array_state(a, a->curr_state <= clean);
+ } else if (sync_completed > a->last_checkpoint)
+ a->last_checkpoint = sync_completed;
+
a->container->ss->sync_metadata(a->container);
dprintf("%s(%d): state:%s action:%s next(", __func__, a->info.container_member,
array_states[a->curr_state], sync_actions[a->curr_action]);
add_fd(&rfds, &maxfd, a->info.state_fd);
add_fd(&rfds, &maxfd, a->action_fd);
+ add_fd(&rfds, &maxfd, a->sync_completed_fd);
for (mdi = a->info.devs ; mdi ; mdi = mdi->next)
add_fd(&rfds, &maxfd, mdi->state_fd);
dprintf("caught sigterm, all clean... exiting\n");
else
dprintf("no arrays to monitor... exiting\n");
- remove_pidfile(container->devname);
+ if (!sigterm)
+ /* On SIGTERM, someone (the take-over mdmon) will
+ * clean up
+ */
+ remove_pidfile(container->devname);
exit_now = 1;
signal_manager();
exit(0);
sigprocmask(SIG_UNBLOCK, NULL, &set);
sigdelset(&set, SIGUSR1);
monitor_loop_cnt |= 1;
- rv = pselect(maxfd+1, &rfds, NULL, NULL, NULL, &set);
+ rv = pselect(maxfd+1, NULL, NULL, &rfds, NULL, &set);
monitor_loop_cnt += 1;
if (rv == -1 && errno == EINTR)
rv = 0;