]> git.ipfire.org Git - thirdparty/mdadm.git/blobdiff - managemon.c
Allow passing metadata update to the monitor.
[thirdparty/mdadm.git] / managemon.c
index 4b06778e356403332f5bdaae28ed01c35a140900..167d176b01c01682e0e1019f5b9bde9f093ad28a 100644 (file)
@@ -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)