From 2e735d198233a67f305862f72e3a5d0f0c3c548c Mon Sep 17 00:00:00 2001 From: Neil Brown Date: Thu, 12 Jun 2008 10:13:23 +1000 Subject: Allow passing metadata update to the monitor. Code in manager can now just call queue_metadata_update with a (freeable) buf holding the update, and it will get passed to the monitor and written out. --- managemon.c | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'managemon.c') diff --git a/managemon.c b/managemon.c index 4b06778..167d176 100644 --- a/managemon.c +++ b/managemon.c @@ -151,6 +151,45 @@ static void replace_array(struct supertype *container, write_wakeup(container); } +struct metadata_update *update_queue = NULL; +struct metadata_update *update_queue_handled = NULL; +struct metadata_update *update_queue_pending = NULL; + +void check_update_queue(struct supertype *container) +{ + while (update_queue_handled) { + struct metadata_update *this = update_queue_handled; + update_queue_handled = this->next; + free(this->buf); + free(this); + } + if (update_queue == NULL && + update_queue_pending) { + update_queue = update_queue_pending; + update_queue_pending = NULL; + write_wakeup(container); + } +} + +void queue_metadata_update(struct metadata_update *mu) +{ + struct metadata_update **qp; + + qp = &update_queue_pending; + while (*qp) + qp = & ((*qp)->next); + *qp = mu; +} + +void wait_update_handled(void) +{ + /* Wait for any pending update to be handled by monitor. + * i.e. wait until update_queue is NULL + */ + while (update_queue) + usleep(100 * 1000); +} + static void manage_container(struct mdstat_ent *mdstat, struct supertype *container) { @@ -404,6 +443,8 @@ void do_manager(struct supertype *container) remove_old(); + check_update_queue(container); + manager_ready = 1; sigprocmask(SIG_SETMASK, &block, &orig); if (woke == 0) -- cgit