<div dir="ltr">Hannes, Ben,<div><br></div><div>are you ok with the solution to these two issues.</div><div>Seems sane to me.</div><div><br></div><div>Thanks,</div><div>Christophe</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Oct 11, 2016 at 8:46 AM, <span dir="ltr"><<a href="mailto:tang.junhui@zte.com.cn" target="_blank">tang.junhui@zte.com.cn</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><font size="2">Please have a review</font><font size="2" face="sans-serif">
for this patch, any comment will be highly appreciated.</font><font size="2" face="sans-serif"><br>
</font>
<br>
<br>
<br>
<br><font size="1" color="#5f5f5f" face="sans-serif">发件人:
</font><font size="1" face="sans-serif"><a href="mailto:tang.junhui@zte.com.cn" target="_blank">tang.junhui@zte.com.cn</a></font>
<br><font size="1" color="#5f5f5f" face="sans-serif">收件人:
</font><font size="1" face="sans-serif">christophe
varoqui <<a href="mailto:christophe.varoqui@free.fr" target="_blank">christophe.varoqui@free.fr</a>>, </font>
<br><font size="1" color="#5f5f5f" face="sans-serif">抄送:
</font><font size="1" face="sans-serif"><a href="mailto:dm-devel@redhat.com" target="_blank">dm-devel@redhat.com</a>,
<a href="mailto:zhang.kai16@zte.com.cn" target="_blank">zhang.kai16@zte.com.cn</a>, "tang.junhui" <<a href="mailto:tang.junhui@zte.com.cn" target="_blank">tang.junhui@zte.com.cn</a>></font>
<br><font size="1" color="#5f5f5f" face="sans-serif">日期:
</font><font size="1" face="sans-serif">2016/08/16
19:33</font>
<br><font size="1" color="#5f5f5f" face="sans-serif">主题:
</font><font size="1" face="sans-serif">[PATCH] libmultipath:
fix multipath -q command logic</font>
<br>
<hr noshade><div class="HOEnZb"><div class="h5">
<br>
<br>
<br><tt><font size="2">From: "tang.junhui" <<a href="mailto:tang.junhui@zte.com.cn" target="_blank">tang.junhui@zte.com.cn</a>><br>
<br>
multipath judged whether multipathd service in running by check_daemon()
when executing<br>
mutipath commands, check_daemon() try to connect to the multipathd service
and execute<br>
"show dameon" command. The expected result is that the command
will be failed when the<br>
service is not running, however, mpath_connect() will activate the multipathd
service when<br>
the service is not running, so check_daemon() always return with true.
Another problem is that<br>
multipath command with -q parameter is not processed in coalesce_paths().
This patch fix for<br>
those two problems.<br>
<br>
Signed-off-by: tang.junhui <<a href="mailto:tang.junhui@zte.com.cn" target="_blank">tang.junhui@zte.com.cn</a>><br>
---<br>
libmultipath/configure.c | 85 +++++++++++++++++++++++++++---<wbr>------------------<br>
1 file changed, 48 insertions(+), 37 deletions(-)<br>
<br>
diff --git a/libmultipath/configure.c b/libmultipath/configure.c<br>
index 707e6be..d8a17a6 100644<br>
--- a/libmultipath/configure.c<br>
+++ b/libmultipath/configure.c<br>
@@ -715,36 +715,36 @@ deadmap (struct multipath * mpp)<br>
return
1; /* dead */<br>
}<br>
<br>
-int check_daemon(void)<br>
+static int<br>
+check_daemon(void)<br>
{<br>
int
fd;<br>
-
char *reply;<br>
-
int ret = 0;<br>
-
unsigned int timeout;<br>
-
struct config *conf;<br>
-<br>
-
fd = mpath_connect();<br>
-
if (fd == -1)<br>
-
return
0;<br>
+
struct flock lock;<br>
<br>
-
if (send_packet(fd, "show daemon") != 0)<br>
-
goto
out;<br>
-
conf = get_multipath_config();<br>
-
timeout = conf->uxsock_timeout;<br>
-
put_multipath_config(conf);<br>
-
if (recv_packet(fd, &reply, timeout) != 0)<br>
-
goto
out;<br>
-<br>
-
if (strstr(reply, "shutdown"))<br>
-
goto
out_free;<br>
-<br>
-
ret = 1;<br>
+
fd = open(DEFAULT_PIDFILE, O_RDONLY);<br>
+
if (fd < 0) {<br>
+
if
(errno == ENOENT)<br>
+
return 0;<br>
+
if
(errno == EMFILE)<br>
+
condlog(0, "failed to open file, increase max_fds at %s", DEFAULT_CONFIGFILE);<br>
+
else<br>
+
condlog(0, "can not open pidfile %s: %s", DEFAULT_PIDFILE, strerror(errno));<br>
+
return
-1;<br>
+
}<br>
<br>
-out_free:<br>
-
FREE(reply);<br>
-out:<br>
-
mpath_disconnect(fd);<br>
-
return ret;<br>
+
lock.l_type = F_WRLCK;<br>
+
lock.l_start = 0;<br>
+
lock.l_whence = SEEK_SET;<br>
+
lock.l_len = 0;<br>
+
if (fcntl(fd, F_GETLK, &lock) < 0) {<br>
+
condlog(0,
"can not get file locker, %s: %s", DEFAULT_PIDFILE, strerror(errno));<br>
+
close(fd);<br>
+
return
-1;<br>
+
}<br>
+
close(fd);<br>
+
if (lock.l_type == F_UNLCK)<br>
+
return
0;<br>
+
return 1;<br>
}<br>
<br>
extern int<br>
@@ -873,17 +873,28 @@ coalesce_paths (struct vectors * vecs, vector newmp,
char * refwwid, int force_r<br>
if (r == DOMAP_DRY)<br>
continue;<br>
<br>
-
conf
= get_multipath_config();<br>
-
allow_queueing
= conf->allow_queueing;<br>
-
put_multipath_config(conf);<br>
-
if
(!is_daemon && !allow_queueing && !check_daemon()) {<br>
-
if (mpp->no_path_retry != NO_PATH_RETRY_UNDEF &&<br>
-
mpp->no_path_retry != NO_PATH_RETRY_FAIL)<br>
-
condlog(3,
"%s: multipathd not running, unset "<br>
-
"queue_if_no_path feature", mpp->alias);<br>
-
if (!dm_queue_if_no_path(mpp-><wbr>alias, 0))<br>
-
remove_feature(&mpp-><wbr>features,<br>
-
"queue_if_no_path");<br>
+
/*
run as multipath command and the service is not running */<br>
+
if
(!is_daemon && !check_daemon()) {<br>
+
conf = get_multipath_config();<br>
+
allow_queueing = conf->allow_queueing;<br>
+
put_multipath_config(conf);<br>
+
/* no -q choice */<br>
+
if (!allow_queueing) {<br>
+
if
(mpp->no_path_retry != NO_PATH_RETRY_UNDEF &&<br>
+
mpp->no_path_retry != NO_PATH_RETRY_FAIL)<br>
+
condlog(3, "%s: multipathd not running, unset "<br>
+
"queue_if_no_path
feature", mpp->alias);<br>
+
if
(!dm_queue_if_no_path(mpp-><wbr>alias, 0))<br>
+
remove_feature(&mpp->features,<br>
+
"queue_if_no_path");<br>
+
} else { /* with -q choice */<br>
+
if
(mpp->no_path_retry == NO_PATH_RETRY_UNDEF ||<br>
+
mpp->no_path_retry == NO_PATH_RETRY_FAIL)<br>
+
condlog(3, "%s: multipathd not running, set "<br>
+
"queue_if_no_path
feature", mpp->alias);<br>
+
if
(!dm_queue_if_no_path(mpp-><wbr>alias, 1))<br>
+
add_feature(&mpp->features, "queue_if_no_path");<br>
+
}<br>
}<br>
else if (mpp->no_path_retry != NO_PATH_RETRY_UNDEF) {<br>
if
(mpp->no_path_retry == NO_PATH_RETRY_FAIL) {<br>
-- <br>
2.8.1.windows.1<br>
<br>
</font></tt>
<br>
</div></div></blockquote></div><br></div>