<font size=2 face="sans-serif">Hello </font><font size=3>Hannes, Ben,</font>
<br><font size=2 face="sans-serif">Could you have </font><font size=2>a
review for this patch, any comment will be highly appreciated.</font><font size=2 face="sans-serif">
</font>
<br>
<br><font size=3>Thanks,</font>
<br><font size=2 face="sans-serif">Tang<br>
</font>
<br>
<br>
<br>
<br><font size=1 color=#5f5f5f face="sans-serif">发件人:    
    </font><font size=1 face="sans-serif">Christophe
Varoqui <christophe.varoqui@opensvc.com></font>
<br><font size=1 color=#5f5f5f face="sans-serif">收件人:    
    </font><font size=1 face="sans-serif">tang.junhui@zte.com.cn,
</font>
<br><font size=1 color=#5f5f5f face="sans-serif">抄送:    
   </font><font size=1 face="sans-serif">Bart Van Assche
<bart.vanassche@sandisk.com>, device-mapper development <dm-devel@redhat.com>,
zhang.kai16@zte.com.cn</font>
<br><font size=1 color=#5f5f5f face="sans-serif">日期:    
    </font><font size=1 face="sans-serif">2016/10/11
14:59</font>
<br><font size=1 color=#5f5f5f face="sans-serif">主题:    
   </font><font size=1 face="sans-serif">Re: [dm-devel]
[PATCH] libmultipath: fix multipath -q command logic</font>
<br><font size=1 color=#5f5f5f face="sans-serif">发件人:    
   </font><font size=1 face="sans-serif">dm-devel-bounces@redhat.com</font>
<br>
<hr noshade>
<br>
<br>
<br><font size=3>Hannes, Ben,</font>
<br>
<br><font size=3>are you ok with the solution to these two issues.</font>
<br><font size=3>Seems sane to me.</font>
<br>
<br><font size=3>Thanks,</font>
<br><font size=3>Christophe</font>
<br>
<br><font size=3>On Tue, Oct 11, 2016 at 8:46 AM, <</font><a href=mailto:tang.junhui@zte.com.cn target=_blank><font size=3 color=blue><u>tang.junhui@zte.com.cn</u></font></a><font size=3>>
wrote:</font>
<br><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=3><br>
<br>
<br>
<br>
</font><font size=1 color=#5f5f5f face="sans-serif"><br>
发件人:         </font><a href=mailto:tang.junhui@zte.com.cn target=_blank><font size=1 color=blue face="sans-serif"><u>tang.junhui@zte.com.cn</u></font></a><font size=3>
</font><font size=1 color=#5f5f5f face="sans-serif"><br>
收件人:         </font><font size=1 face="sans-serif">christophe
varoqui <</font><a href=mailto:christophe.varoqui@free.fr target=_blank><font size=1 color=blue face="sans-serif"><u>christophe.varoqui@free.fr</u></font></a><font size=1 face="sans-serif">>,
</font><font size=1 color=#5f5f5f face="sans-serif"><br>
抄送:        </font><a href="mailto:dm-devel@redhat.com" target=_blank><font size=1 color=blue face="sans-serif"><u>dm-devel@redhat.com</u></font></a><font size=1 face="sans-serif">,
</font><a href=mailto:zhang.kai16@zte.com.cn target=_blank><font size=1 color=blue face="sans-serif"><u>zhang.kai16@zte.com.cn</u></font></a><font size=1 face="sans-serif">,
"tang.junhui" <</font><a href=mailto:tang.junhui@zte.com.cn target=_blank><font size=1 color=blue face="sans-serif"><u>tang.junhui@zte.com.cn</u></font></a><font size=1 face="sans-serif">></font><font size=3>
</font><font size=1 color=#5f5f5f face="sans-serif"><br>
日期:         </font><font size=1 face="sans-serif">2016/08/16
19:33</font><font size=3> </font><font size=1 color=#5f5f5f face="sans-serif"><br>
主题:        </font><font size=1 face="sans-serif">[PATCH]
libmultipath: fix multipath -q command logic</font><font size=3> <br>
</font>
<hr noshade>
<br><font size=3><br>
<br>
</font><tt><font size=2><br>
From: "tang.junhui" <</font></tt><a href=mailto:tang.junhui@zte.com.cn target=_blank><tt><font size=2 color=blue><u>tang.junhui@zte.com.cn</u></font></tt></a><tt><font size=2>><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 <</font></tt><a href=mailto:tang.junhui@zte.com.cn target=_blank><tt><font size=2 color=blue><u>tang.junhui@zte.com.cn</u></font></tt></a><tt><font size=2>><br>
---<br>
libmultipath/configure.c | 85 +++++++++++++++++++++++++++---------------------<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->alias, 0))<br>
-                    
                     
                     
   remove_feature(&mpp->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->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->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>
</font></tt><font size=3><br>
</font>
<br><tt><font size=2>--<br>
dm-devel mailing list<br>
dm-devel@redhat.com<br>
</font></tt><a href="https://www.redhat.com/mailman/listinfo/dm-devel"><tt><font size=2>https://www.redhat.com/mailman/listinfo/dm-devel</font></tt></a>
<br>