Add the "reconfigure wait" and "reconfigure all wait" multipathd
commands. These work just like the non-wait options, but they do not
return until there are no more scheduled reconfigures.

Signed-off-by: Benjamin Marzinski <[email protected]>
---
 multipathd/callbacks.c     |  3 +++
 multipathd/cli.c           |  1 +
 multipathd/cli.h           |  3 +++
 multipathd/cli_handlers.c  | 22 ++++++++++++++++++++--
 multipathd/main.c          | 15 +++++++++++++--
 multipathd/main.h          |  3 ++-
 multipathd/multipathd.8.in | 19 +++++++++++++++++--
 7 files changed, 59 insertions(+), 7 deletions(-)

diff --git a/multipathd/callbacks.c b/multipathd/callbacks.c
index 2027c3a6..60647519 100644
--- a/multipathd/callbacks.c
+++ b/multipathd/callbacks.c
@@ -44,6 +44,9 @@ void init_handler_callbacks(void)
        set_unlocked_handler_callback(VRB_RECONFIGURE, 
HANDLER(cli_reconfigure));
        set_unlocked_handler_callback(VRB_RECONFIGURE | Q1_ALL,
                                      HANDLER(cli_reconfigure_all));
+       set_unlocked_handler_callback(VRB_RECONFIGURE | Q1_WAIT, 
HANDLER(cli_reconfigure_wait));
+       set_unlocked_handler_callback(VRB_RECONFIGURE | Q1_ALL | Q2_WAIT,
+                                     HANDLER(cli_reconfigure_all_wait));
        set_handler_callback(VRB_SUSPEND | Q1_MAP, HANDLER(cli_suspend));
        set_handler_callback(VRB_RESUME | Q1_MAP, HANDLER(cli_resume));
        set_handler_callback(VRB_RESIZE | Q1_MAP, HANDLER(cli_resize));
diff --git a/multipathd/cli.c b/multipathd/cli.c
index 0d679c86..25dce4e5 100644
--- a/multipathd/cli.c
+++ b/multipathd/cli.c
@@ -228,6 +228,7 @@ load_keys (void)
        r += add_key(keys, "setprhold", VRB_SETPRHOLD, 0);
        r += add_key(keys, "unsetprhold", VRB_UNSETPRHOLD, 0);
        r += add_key(keys, "pathlist", KEY_PATHLIST, 1);
+       r += add_key(keys, "wait", KEY_WAIT, 0);
 
        if (r) {
                free_keys(keys);
diff --git a/multipathd/cli.h b/multipathd/cli.h
index 6d599ca7..1c6c42e1 100644
--- a/multipathd/cli.h
+++ b/multipathd/cli.h
@@ -64,6 +64,7 @@ enum {
        KEY_GROUP               = 82,
        KEY_KEY                 = 83,
        KEY_PATHLIST            = 84,
+       KEY_WAIT                = 85,
 };
 
 /*
@@ -85,6 +86,7 @@ enum {
        Q1_ALL                  = KEY_ALL << 8,
        Q1_DAEMON               = KEY_DAEMON << 8,
        Q1_STATUS               = KEY_STATUS << 8,
+       Q1_WAIT                 = KEY_WAIT << 8,
 
        /* byte 2: qualifier 2 */
        Q2_FMT                  = KEY_FMT << 16,
@@ -97,6 +99,7 @@ enum {
        Q2_GROUP                = KEY_GROUP << 16,
        Q2_KEY                  = KEY_KEY << 16,
        Q2_PATHLIST             = KEY_PATHLIST << 16,
+       Q2_WAIT                 = KEY_WAIT << 16,
 
        /* byte 3: qualifier 3 */
        Q3_FMT                  = KEY_FMT << 24,
diff --git a/multipathd/cli_handlers.c b/multipathd/cli_handlers.c
index e5c43bd8..86f050a0 100644
--- a/multipathd/cli_handlers.c
+++ b/multipathd/cli_handlers.c
@@ -1021,7 +1021,7 @@ static int cli_reconfigure(void *v, struct strbuf *reply,
 {
        condlog(2, "reconfigure (operator)");
 
-       schedule_reconfigure(FORCE_RELOAD_WEAK);
+       schedule_reconfigure(FORCE_RELOAD_WEAK, NULL);
        return 0;
 }
 
@@ -1030,7 +1030,25 @@ int cli_reconfigure_all(void *v, struct strbuf *reply,
 {
        condlog(2, "reconfigure all (operator)");
 
-       schedule_reconfigure(FORCE_RELOAD_YES);
+       schedule_reconfigure(FORCE_RELOAD_YES, NULL);
+       return 0;
+}
+
+static int cli_reconfigure_wait(void *v, struct strbuf *reply,
+                               struct list_head *wait_node, void *data)
+{
+       condlog(2, "reconfigure wait (operator)");
+
+       schedule_reconfigure(FORCE_RELOAD_WEAK, wait_node);
+       return 0;
+}
+
+static int cli_reconfigure_all_wait(void *v, struct strbuf *reply,
+                                   struct list_head *wait_node, void *data)
+{
+       condlog(2, "reconfigure all wait (operator)");
+
+       schedule_reconfigure(FORCE_RELOAD_YES, wait_node);
        return 0;
 }
 
diff --git a/multipathd/main.c b/multipathd/main.c
index 1bb8eac8..83773d90 100644
--- a/multipathd/main.c
+++ b/multipathd/main.c
@@ -135,6 +135,8 @@ static enum daemon_status running_state = DAEMON_INIT;
 static bool delayed_reconfig;
 /* Don't access this variable without holding config_lock */
 static enum force_reload_types reconfigure_pending = FORCE_RELOAD_NONE;
+/* Don't access this variable without holding config_lock */
+LIST_HEAD(config_wait_list);
 pid_t daemon_pid;
 static pthread_mutex_t config_lock = PTHREAD_MUTEX_INITIALIZER;
 static pthread_cond_t config_cond;
@@ -336,7 +338,8 @@ void remove_map_callback(struct multipath *mpp)
                unblock_reconfigure();
 }
 
-void schedule_reconfigure(enum force_reload_types requested_type)
+void schedule_reconfigure(enum force_reload_types requested_type,
+                         struct list_head *wait_node)
 {
        pthread_mutex_lock(&config_lock);
        pthread_cleanup_push(config_cleanup, NULL);
@@ -360,6 +363,8 @@ void schedule_reconfigure(enum force_reload_types 
requested_type)
        default:
                break;
        }
+       if (wait_node)
+               wait_for_event(wait_node, &config_wait_list);
        pthread_cleanup_pop(1);
 }
 
@@ -3657,7 +3662,7 @@ handle_signals(bool nonfatal)
                return;
        if (reconfig_sig) {
                condlog(3, "reconfigure (signal)");
-               schedule_reconfigure(FORCE_RELOAD_WEAK);
+               schedule_reconfigure(FORCE_RELOAD_WEAK, NULL);
        }
        if (log_reset_sig) {
                condlog(3, "reset log (signal)");
@@ -4169,6 +4174,12 @@ child (__attribute__((unused)) void *param)
                        pthread_mutex_unlock(&config_lock);
 
                        rc = reconfigure(vecs, reload_type);
+
+                       /* wake up waiters if there are no pending reconfigs */
+                       pthread_mutex_lock(&config_lock);
+                       if (reconfigure_pending == FORCE_RELOAD_NONE)
+                               wakeup_event_waiter(&config_wait_list);
+                       pthread_mutex_unlock(&config_lock);
                } else {
                        pthread_mutex_lock(&config_lock);
                        delayed_reconfig = true;
diff --git a/multipathd/main.h b/multipathd/main.h
index b66208ec..76d09196 100644
--- a/multipathd/main.h
+++ b/multipathd/main.h
@@ -34,7 +34,8 @@ void exit_daemon(void);
 const char *daemon_status(bool *pending_reconfig);
 enum daemon_status wait_for_state_change_if(enum daemon_status oldstate,
                                            unsigned long ms);
-void schedule_reconfigure(enum force_reload_types requested_type);
+void schedule_reconfigure(enum force_reload_types requested_type,
+                         struct list_head *wait_node);
 int need_to_delay_reconfig (struct vectors *);
 int ev_add_path (struct path *, struct vectors *, int);
 int ev_remove_path (struct path *, struct vectors *, int);
diff --git a/multipathd/multipathd.8.in b/multipathd/multipathd.8.in
index 632cbe40..aee67004 100644
--- a/multipathd/multipathd.8.in
+++ b/multipathd/multipathd.8.in
@@ -274,13 +274,28 @@ group index, starting with 1.
 .B reconfigure
 Rereads the configuration, and reloads all changed multipath devices. This
 also happens at startup, when the service is reload, or when a SIGHUP is
-received.
+received. This command schedules the reconfiguration and returns immediately.
+.
+.TP
+.B reconfigure wait
+Rereads the configuration, and reloads all changed multipath devices. This
+also happens at startup, when the service is reload, or when a SIGHUP is
+received. This command waits for for the reconfiguration to complete before
+returning
 .
 .TP
 .B reconfigure all
 Rereads the configuration, and reloads all multipath devices regardless of
 whether or not they have changed. This also happens when \fImultipath -r\fR is
-run.
+run. This command schedules the reconfiguration and returns immediately.
+.
+.TP
+.B reconfigure all wait
+Rereads the configuration, and reloads all multipath devices regardless of
+whether or not they have changed. This also happens when \fImultipath -r\fR is
+run. This command waits for for the reconfiguration to complete before
+returning
+.
 .TP
 .B suspend map|multipath $map
 Sets map $map into suspend state.
-- 
2.56.0


Reply via email to