multipathd: make DAEMON_SHUTDOWN a terminal state
authorMartin Wilck <mwilck@suse.com>
Fri, 2 Nov 2018 12:24:01 +0000 (13:24 +0100)
committerChristophe Varoqui <christophe.varoqui@opensvc.com>
Wed, 14 Nov 2018 07:22:28 +0000 (08:22 +0100)
It can happen that, before the main thread reacts on DAEMON_SHUTDOWN
and starts cancelling threads, another thread resets the state to
something else. Fix that.

Reviewed-by: Benjamin Marzinski <bmarzins@redhat.com>
Signed-off-by: Martin Wilck <mwilck@suse.com>
multipathd/cli_handlers.c
multipathd/main.c

index 4aea4ce..a0d57a5 100644 (file)
@@ -1124,12 +1124,17 @@ cli_switch_group(void * v, char ** reply, int * len, void * data)
 int
 cli_reconfigure(void * v, char ** reply, int * len, void * data)
 {
+       int rc;
+
        condlog(2, "reconfigure (operator)");
 
-       if (set_config_state(DAEMON_CONFIGURE) == ETIMEDOUT) {
+       rc = set_config_state(DAEMON_CONFIGURE); 
+       if (rc == ETIMEDOUT) {
                condlog(2, "timeout starting reconfiguration");
                return 1;
-       }
+       } else if (rc == EINVAL)
+               /* daemon shutting down */
+               return 1;
        return 0;
 }
 
index 9052b56..3cccc9f 100644 (file)
@@ -209,7 +209,7 @@ static void config_cleanup(void *arg)
 
 static void __post_config_state(enum daemon_status state)
 {
-       if (state != running_state) {
+       if (state != running_state && running_state != DAEMON_SHUTDOWN) {
                enum daemon_status old_state = running_state;
 
                running_state = state;
@@ -237,7 +237,9 @@ int set_config_state(enum daemon_status state)
        if (running_state != state) {
                enum daemon_status old_state = running_state;
 
-               if (running_state != DAEMON_IDLE) {
+               if (running_state == DAEMON_SHUTDOWN)
+                       rc = EINVAL;
+               else if (running_state != DAEMON_IDLE) {
                        struct timespec ts;
 
                        clock_gettime(CLOCK_MONOTONIC, &ts);
@@ -2212,7 +2214,9 @@ checkerloop (void *ap)
                if (rc == ETIMEDOUT) {
                        condlog(4, "timeout waiting for DAEMON_IDLE");
                        continue;
-               }
+               } else if (rc == EINVAL)
+                       /* daemon shutdown */
+                       break;
 
                pthread_cleanup_push(cleanup_lock, &vecs->lock);
                lock(&vecs->lock);