From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mailout1.w1.samsung.com (mailout1.w1.samsung.com [210.118.77.11]) by dpdk.org (Postfix) with ESMTP id EBA7C4B79 for ; Thu, 21 Jul 2016 14:13:16 +0200 (CEST) Received: from eucpsbgm1.samsung.com (unknown [203.254.199.244]) by mailout1.w1.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTP id <0OAN00BGZZA4W990@mailout1.w1.samsung.com> for dev@dpdk.org; Thu, 21 Jul 2016 13:13:16 +0100 (BST) X-AuditID: cbfec7f4-f796c6d000001486-2c-5790bc5b1263 Received: from eusync4.samsung.com ( [203.254.199.214]) by eucpsbgm1.samsung.com (EUCPMTA) with SMTP id 77.3C.05254.B5CB0975; Thu, 21 Jul 2016 13:13:15 +0100 (BST) Received: from [106.109.129.180] by eusync4.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTPA id <0OAN000ZQZA2AMB0@eusync4.samsung.com>; Thu, 21 Jul 2016 13:13:15 +0100 (BST) To: Yuanhan Liu References: <1469089275-15209-1-git-send-email-i.maximets@samsung.com> <20160721093714.GD28708@yliu-dev.sh.intel.com> <579099BC.9050603@samsung.com> <20160721101311.GE28708@yliu-dev.sh.intel.com> <5790A5D4.1090703@samsung.com> <5790AEB3.2010708@samsung.com> <20160721114016.GF28708@yliu-dev.sh.intel.com> <5790BBA7.6070202@samsung.com> Cc: dev@dpdk.org, Huawei Xie , Dyasly Sergey , Heetae Ahn , Thomas Monjalon From: Ilya Maximets Message-id: <5790BC5A.2010505@samsung.com> Date: Thu, 21 Jul 2016 15:13:14 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.8.0 MIME-version: 1.0 In-reply-to: <5790BBA7.6070202@samsung.com> Content-type: text/plain; charset=windows-1252 Content-transfer-encoding: 7bit X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrJLMWRmVeSWpSXmKPExsVy+t/xa7rReyaEG3zvsLR492k7k8W0z7fZ LdpnnmWyuNL+k91i8mwpiy+bprNZXJ9wgdWB3eNi/x1Gj18LlrJ6LN7zkslj3slAj74tqxgD WKO4bFJSczLLUov07RK4Mr4vdCnYIFtx93dhA2OjWBcjJ4eEgInE5FfPWSFsMYkL99azdTFy cQgJLGWU6P/+mQXCecEo8X9VJztIlbCAtcS0iS/YQGwRAV2Jp3PWsUIUXWeS6D8xmxnEYRbY yCixYOppsCo2AR2JU6uPMILYvAJaEveXfAazWQRUJc7d/w42VVQgQmLW9h9MEDWCEj8m32MB sTkFtCVeTrsDFOcAGqoncf+iFkiYWUBeYvOat8wTGAVmIemYhVA1C0nVAkbmVYyiqaXJBcVJ 6bmGesWJucWleel6yfm5mxghAf5lB+PiY1aHGAU4GJV4eBNW9ocLsSaWFVfmHmKU4GBWEuHd vGNCuBBvSmJlVWpRfnxRaU5q8SFGaQ4WJXHeubvehwgJpCeWpGanphakFsFkmTg4pRoY/UT+ Nt21zlon3lbiO/O5U6DQBY6K/xqr5l8/LdSWX7xawzKfba4C38/Tt1mq/SXe/T21V9H2SN/U +0cyN8d4h7JdqfCLjVfM9TXZ05YicenLngfF+W1aLBab9pw6+5tBLP7vsvxS99zZwmpGKe+v CRn8jJlboGysUbGt8dDy8O9+AXtM7nIosRRnJBpqMRcVJwIACamFumwCAAA= Subject: Re: [dpdk-dev] [PATCH] vhost: fix connect hang in client mode X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 21 Jul 2016 12:13:17 -0000 On 21.07.2016 15:10, Ilya Maximets wrote: > On 21.07.2016 14:40, Yuanhan Liu wrote: >> On Thu, Jul 21, 2016 at 02:14:59PM +0300, Ilya Maximets wrote: >>>> Hmm, how about this fixup: >>>> ------------------------------------------------------------------------------ >>>> diff --git a/lib/librte_vhost/vhost_user/vhost-net-user.c b/lib/librte_vhost/vhost_user/vhost-net-user.c >>>> index 8626d13..b0f45e6 100644 >>>> --- a/lib/librte_vhost/vhost_user/vhost-net-user.c >>>> +++ b/lib/librte_vhost/vhost_user/vhost-net-user.c >>>> @@ -537,18 +537,7 @@ vhost_user_connect_nonblock(int fd, struct sockaddr *un, size_t sz) >>>> errno = EINVAL; >>>> >>>> ret = connect(fd, un, sz); >>>> - if (ret == -1 && errno != EINPROGRESS) >>>> - return -1; >>>> - if (ret == 0) >>>> - goto connected; >>>> - >>>> - FD_ZERO(&fdset); >>>> - FD_SET(fd, &fdset); >>>> - >>>> - ret = select(fd + 1, NULL, &fdset, NULL, &tv); >>>> - if (!ret) >>>> - errno = ETIMEDOUT; >>>> - if (ret != 1) >>>> + if (ret < 0 && errno != EISCONN) >>>> return -1; >>>> >>>> ret = getsockopt(fd, SOL_SOCKET, SO_ERROR, &so_error, &len); >>>> @@ -558,7 +547,6 @@ vhost_user_connect_nonblock(int fd, struct sockaddr *un, size_t sz) >>>> return -1; >>>> } >>>> >>>> -connected: >>>> flags = fcntl(fd, F_GETFL, 0); >>>> if (flags < 0) { >>>> RTE_LOG(ERR, VHOST_CONFIG, >>>> ------------------------------------------------------------------------------ >>>> ? >>>> >>>> We will not check the EINPROGRESS, but subsequent 'connect()' will return >>>> EISCONN if connection already established. getsockopt() is kept just in >>>> case. Subsequent 'connect()' will happen on the next iteration of >>>> reconnection cycle (1 second sleep). >>> >>> I've sent v2 with this changes. >> >> Thanks. But still, it doesn't look clean to me. I was thinking following >> might be cleaner? >> >> diff --git a/lib/librte_vhost/vhost_user/vhost-net-user.c >> b/lib/librte_vhost/vhost_user/vhost-net-user. >> index f0f92f8..c0ef290 100644 >> --- a/lib/librte_vhost/vhost_user/vhost-net-user.c >> +++ b/lib/librte_vhost/vhost_user/vhost-net-user.c >> @@ -532,6 +532,10 @@ vhost_user_client_reconnect(void *arg __rte_unused) >> reconn != NULL; reconn = next) { >> next = TAILQ_NEXT(reconn, next); >> >> + if (reconn->conn_inprogress) { >> + /* do connect check here */ >> + } >> + >> if (connect(reconn->fd, (struct sockaddr *)&reconn->un, >> sizeof(reconn->un)) < 0) >> continue; >> @@ -605,6 +609,7 @@ vhost_user_create_client(struct vhost_user_socket *vsocket) >> reconn->un = un; >> reconn->fd = fd; >> reconn->vsocket = vsocket; >> + reconn->conn_inprogress = errno == EINPROGRESS; >> pthread_mutex_lock(&reconn_list.mutex); >> TAILQ_INSERT_TAIL(&reconn_list.head, reconn, next); >> pthread_mutex_unlock(&reconn_list.mutex); >> >> It's just a rough diff, hopefully it shows my idea clearly. And of >> course, we should not call connect() anymore when conn_inprogress >> is set. >> >> What do you think of it? > > I found that we can't check connection status without select/poll > on it. 'getsockopt()' will return 0 with no errors if connection > is not still established just like if it was. > So, I think, the first version of this patch is the only > acceptable solution. Sorry, v2 is acceptable too, because it always calls 'connect()'.