Re: [PATCH 4/5] net/virtio-user: add lsc support with vhost-user adapter
From: Yuanhan Liu <hidden>
Date: 2017-03-17 08:31:11
On Fri, Mar 03, 2017 at 05:56:42PM +0000, Jianfeng Tan wrote:
quoted hunk ↗ jump to hunk
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 <redacted> 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