From mboxrd@z Thu Jan 1 00:00:00 1970 From: Yuanhan Liu Subject: Re: [PATCH 4/5] net/virtio-user: add lsc support with vhost-user adapter Date: Fri, 17 Mar 2017 16:29:12 +0800 Message-ID: <20170317082912.GI18844@yliu-dev.sh.intel.com> References: <1488563803-87754-1-git-send-email-jianfeng.tan@intel.com> <1488563803-87754-5-git-send-email-jianfeng.tan@intel.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: dev@dpdk.org, david.marchand@6wind.com To: Jianfeng Tan Return-path: Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by dpdk.org (Postfix) with ESMTP id 8F1575A8D for ; Fri, 17 Mar 2017 09:31:11 +0100 (CET) Content-Disposition: inline In-Reply-To: <1488563803-87754-5-git-send-email-jianfeng.tan@intel.com> List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" On Fri, Mar 03, 2017 at 05:56:42PM +0000, Jianfeng Tan wrote: > So far, virtio-user with vhost-user as the backend can only support > client mode. So when vhost user backend is down, i.e., unix socket > connection is broken and cannot be re-connected. We will force the > link state to be down. > > Signed-off-by: Jianfeng Tan > static void > virtio_user_read_dev_config(struct virtio_hw *hw, size_t offset, > void *dst, int length) > @@ -63,8 +77,27 @@ virtio_user_read_dev_config(struct virtio_hw *hw, size_t offset, > return; > } > > - if (offset == offsetof(struct virtio_net_config, status)) > + if (offset == offsetof(struct virtio_net_config, status)) { > + char buf[128]; > + > + if (dev->vhostfd >= 0) { > + int flags; > + int r; > + > + flags = fcntl(dev->vhostfd, F_GETFL); > + fcntl(dev->vhostfd, F_SETFL, flags | O_NONBLOCK); > + r = recv(dev->vhostfd, buf, 128, 0); I think you need specify flag MSG_PEEK, to not consume the data if there any? --yliu > + if (r == 0 || (r < 0 && errno != EAGAIN)) { > + dev->status &= (~VIRTIO_NET_S_LINK_UP); > + /* link can never be up again */ > + rte_eal_alarm_set(1, virtio_user_delayed_handler, (void *)hw); > + } else { > + dev->status |= VIRTIO_NET_S_LINK_UP; > + } > + fcntl(dev->vhostfd, F_SETFL, flags & (~O_NONBLOCK)); > + } > *(uint16_t *)dst = dev->status; > + } > > if (offset == offsetof(struct virtio_net_config, max_virtqueue_pairs)) > *(uint16_t *)dst = dev->max_queue_pairs; > -- > 2.7.4