multipath: don't start multipathd unnecessarily
authorMartin Wilck <mwilck@suse.com>
Thu, 28 Jun 2018 10:34:45 +0000 (12:34 +0200)
committerChristophe Varoqui <christophe.varoqui@opensvc.com>
Mon, 2 Jul 2018 10:00:30 +0000 (12:00 +0200)
When multipathd is off, but systemd is monitoring the multipathd socket,
mpath_connect() has the side effect of starting multipathd. That's
superfluous if we aren't going to pass the command at hand to multipathd.
So, only try to open the socket if the command at hand is a candidate
for delegation.

Note: Despite this, some day in the future, we may decide to delegate
almost everything to multipathd.

Fixes: 506d253b "multipath: delegate dangerous commands to multipathd"
Signed-off-by: Martin Wilck <mwilck@suse.com>
multipath/main.c

index ed4f40e..a0f3bde 100644 (file)
@@ -803,10 +803,6 @@ int delegate_to_multipathd(enum mpath_cmds cmd, const char *dev,
        char command[1024], *p, *reply = NULL;
        int n, r = 0;
 
-       fd = mpath_connect();
-       if (fd == -1)
-               return 0;
-
        p = command;
        *p = '\0';
        n = sizeof(command);
@@ -819,7 +815,12 @@ int delegate_to_multipathd(enum mpath_cmds cmd, const char *dev,
        if (strlen(command) == 0)
                /* No command found, no need to delegate */
                return 0;
-       else if (p >= command + sizeof(command)) {
+
+       fd = mpath_connect();
+       if (fd == -1)
+               return 0;
+
+       if (p >= command + sizeof(command)) {
                condlog(0, "internal error - command buffer overflow");
                r = -1;
                goto out;