All of lore.kernel.org
 help / color / mirror / Atom feed
From: Yuanhan Liu <yuanhan.liu@linux.intel.com>
To: Ilya Maximets <i.maximets@samsung.com>
Cc: dev@dpdk.org, Huawei Xie <huawei.xie@intel.com>,
	Dyasly Sergey <s.dyasly@samsung.com>,
	Heetae Ahn <heetae82.ahn@samsung.com>,
	Thomas Monjalon <thomas.monjalon@6wind.com>
Subject: Re: [PATCH] vhost: fix connect hang in client mode
Date: Thu, 21 Jul 2016 19:40:16 +0800	[thread overview]
Message-ID: <20160721114016.GF28708@yliu-dev.sh.intel.com> (raw)
In-Reply-To: <5790AEB3.2010708@samsung.com>

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?

	--yliu

  reply	other threads:[~2016-07-21 11:36 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-07-21  8:21 [PATCH] vhost: fix connect hang in client mode Ilya Maximets
2016-07-21  9:37 ` Yuanhan Liu
2016-07-21  9:45   ` Ilya Maximets
2016-07-21 10:13     ` Yuanhan Liu
2016-07-21 10:37       ` Ilya Maximets
2016-07-21 11:14         ` Ilya Maximets
2016-07-21 11:40           ` Yuanhan Liu [this message]
2016-07-21 12:10             ` Ilya Maximets
2016-07-21 12:13               ` Ilya Maximets
2016-07-21 12:35                 ` Yuanhan Liu
2016-07-21 12:42                   ` Ilya Maximets
2016-07-21 12:58                     ` Yuanhan Liu
2016-07-21 12:58                       ` Ilya Maximets
2016-07-21 13:10                         ` Yuanhan Liu
2016-07-21 11:12 ` [PATCH v2] " Ilya Maximets
2016-07-21 13:19 ` [PATCH v3] " Ilya Maximets
2016-07-21 13:35   ` Yuanhan Liu
2016-07-21 13:43     ` Ilya Maximets
2016-07-21 13:56       ` Yuanhan Liu
2016-07-21 22:21     ` Thomas Monjalon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20160721114016.GF28708@yliu-dev.sh.intel.com \
    --to=yuanhan.liu@linux.intel.com \
    --cc=dev@dpdk.org \
    --cc=heetae82.ahn@samsung.com \
    --cc=huawei.xie@intel.com \
    --cc=i.maximets@samsung.com \
    --cc=s.dyasly@samsung.com \
    --cc=thomas.monjalon@6wind.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.