get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

GET /api/patches/87329/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 87329,
    "url": "https://patches.dpdk.org/api/patches/87329/?format=api",
    "web_url": "https://patches.dpdk.org/project/dpdk/patch/20210126101639.250481-41-maxime.coquelin@redhat.com/",
    "project": {
        "id": 1,
        "url": "https://patches.dpdk.org/api/projects/1/?format=api",
        "name": "DPDK",
        "link_name": "dpdk",
        "list_id": "dev.dpdk.org",
        "list_email": "dev@dpdk.org",
        "web_url": "http://core.dpdk.org",
        "scm_url": "git://dpdk.org/dpdk",
        "webscm_url": "http://git.dpdk.org/dpdk",
        "list_archive_url": "https://inbox.dpdk.org/dev",
        "list_archive_url_format": "https://inbox.dpdk.org/dev/{}",
        "commit_url_format": ""
    },
    "msgid": "<20210126101639.250481-41-maxime.coquelin@redhat.com>",
    "list_archive_url": "https://inbox.dpdk.org/dev/20210126101639.250481-41-maxime.coquelin@redhat.com",
    "date": "2021-01-26T10:16:35",
    "name": "[v4,40/44] net/virtio: move Vhost-user specifics to its backend",
    "commit_ref": null,
    "pull_url": null,
    "state": "accepted",
    "archived": true,
    "hash": "0e4657cc136c2363d5839ee645a282f2520dae40",
    "submitter": {
        "id": 512,
        "url": "https://patches.dpdk.org/api/people/512/?format=api",
        "name": "Maxime Coquelin",
        "email": "maxime.coquelin@redhat.com"
    },
    "delegate": {
        "id": 2642,
        "url": "https://patches.dpdk.org/api/users/2642/?format=api",
        "username": "mcoquelin",
        "first_name": "Maxime",
        "last_name": "Coquelin",
        "email": "maxime.coquelin@redhat.com"
    },
    "mbox": "https://patches.dpdk.org/project/dpdk/patch/20210126101639.250481-41-maxime.coquelin@redhat.com/mbox/",
    "series": [
        {
            "id": 14950,
            "url": "https://patches.dpdk.org/api/series/14950/?format=api",
            "web_url": "https://patches.dpdk.org/project/dpdk/list/?series=14950",
            "date": "2021-01-26T10:15:55",
            "name": "net/virtio: Virtio PMD rework",
            "version": 4,
            "mbox": "https://patches.dpdk.org/series/14950/mbox/"
        }
    ],
    "comments": "https://patches.dpdk.org/api/patches/87329/comments/",
    "check": "success",
    "checks": "https://patches.dpdk.org/api/patches/87329/checks/",
    "tags": {},
    "related": [],
    "headers": {
        "Return-Path": "<dev-bounces@dpdk.org>",
        "X-Original-To": "patchwork@inbox.dpdk.org",
        "Delivered-To": "patchwork@inbox.dpdk.org",
        "Received": [
            "from mails.dpdk.org (mails.dpdk.org [217.70.189.124])\n\tby inbox.dpdk.org (Postfix) with ESMTP id F3693A052A;\n\tTue, 26 Jan 2021 11:23:38 +0100 (CET)",
            "from [217.70.189.124] (localhost [127.0.0.1])\n\tby mails.dpdk.org (Postfix) with ESMTP id F1F79141441;\n\tTue, 26 Jan 2021 11:18:45 +0100 (CET)",
            "from us-smtp-delivery-124.mimecast.com\n (us-smtp-delivery-124.mimecast.com [216.205.24.124])\n by mails.dpdk.org (Postfix) with ESMTP id E0F11141433\n for <dev@dpdk.org>; Tue, 26 Jan 2021 11:18:41 +0100 (CET)",
            "from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com\n [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id\n us-mta-327-JfmIJhCoOx2FxEQTg8S4eQ-1; Tue, 26 Jan 2021 05:18:37 -0500",
            "from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com\n [10.5.11.11])\n (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits))\n (No client certificate requested)\n by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 47ACE8735C1;\n Tue, 26 Jan 2021 10:18:36 +0000 (UTC)",
            "from max-t490s.redhat.com (unknown [10.36.110.31])\n by smtp.corp.redhat.com (Postfix) with ESMTP id 9DE227216D;\n Tue, 26 Jan 2021 10:18:34 +0000 (UTC)"
        ],
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;\n s=mimecast20190719; t=1611656321;\n h=from:from:reply-to:subject:subject:date:date:message-id:message-id:\n to:to:cc:cc:mime-version:mime-version:content-type:content-type:\n content-transfer-encoding:content-transfer-encoding:\n in-reply-to:in-reply-to:references:references;\n bh=9+8LL5cWkCEo3tkF7Q/5CEomegPhUiaCTRxWROyQPOA=;\n b=VOooCER0jGO+vRa5pfDZTPeuCozqd6fSxffTjrbdZh3Cq4Ne2/F7kz8hH0mIj89Fs1bJ+i\n x4FgR1nSXofLMW1xleNquM4e5mq9Y0jihWg9rWRj7xJSPhaOgMksJrIX3viySHDlF2Edbx\n FqZ0kJU51SNaF07tYwROWxL8A9Ey094=",
        "X-MC-Unique": "JfmIJhCoOx2FxEQTg8S4eQ-1",
        "From": "Maxime Coquelin <maxime.coquelin@redhat.com>",
        "To": "dev@dpdk.org, chenbo.xia@intel.com, olivier.matz@6wind.com,\n amorenoz@redhat.com, david.marchand@redhat.com",
        "Cc": "Maxime Coquelin <maxime.coquelin@redhat.com>",
        "Date": "Tue, 26 Jan 2021 11:16:35 +0100",
        "Message-Id": "<20210126101639.250481-41-maxime.coquelin@redhat.com>",
        "In-Reply-To": "<20210126101639.250481-1-maxime.coquelin@redhat.com>",
        "References": "<20210126101639.250481-1-maxime.coquelin@redhat.com>",
        "MIME-Version": "1.0",
        "X-Scanned-By": "MIMEDefang 2.79 on 10.5.11.11",
        "Authentication-Results": "relay.mimecast.com;\n auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=maxime.coquelin@redhat.com",
        "X-Mimecast-Spam-Score": "0",
        "X-Mimecast-Originator": "redhat.com",
        "Content-Transfer-Encoding": "8bit",
        "Content-Type": "text/plain; charset=\"US-ASCII\"",
        "Subject": "[dpdk-dev] [PATCH v4 40/44] net/virtio: move Vhost-user specifics\n to its backend",
        "X-BeenThere": "dev@dpdk.org",
        "X-Mailman-Version": "2.1.29",
        "Precedence": "list",
        "List-Id": "DPDK patches and discussions <dev.dpdk.org>",
        "List-Unsubscribe": "<https://mails.dpdk.org/options/dev>,\n <mailto:dev-request@dpdk.org?subject=unsubscribe>",
        "List-Archive": "<http://mails.dpdk.org/archives/dev/>",
        "List-Post": "<mailto:dev@dpdk.org>",
        "List-Help": "<mailto:dev-request@dpdk.org?subject=help>",
        "List-Subscribe": "<https://mails.dpdk.org/listinfo/dev>,\n <mailto:dev-request@dpdk.org?subject=subscribe>",
        "Errors-To": "dev-bounces@dpdk.org",
        "Sender": "\"dev\" <dev-bounces@dpdk.org>"
    },
    "content": "This patch moves all the Vhost-user backend specific\nlogic like Vhost FD, listen FD and interrupt handling\nto the vhost-user backend implementation.\n\nIn order to achieve that, new ops are created to update\nthe link status, disconnect and reconnect the server,\nand fetch the link state interrupt FD.\n\nSigned-off-by: Maxime Coquelin <maxime.coquelin@redhat.com>\nReviewed-by: Chenbo Xia <chenbo.xia@intel.com>\n---\n drivers/net/virtio/virtio_user/vhost.h        |   4 +\n drivers/net/virtio/virtio_user/vhost_kernel.c |  18 +-\n drivers/net/virtio/virtio_user/vhost_user.c   | 176 ++++++++++++++---\n drivers/net/virtio/virtio_user/vhost_vdpa.c   |  16 ++\n .../net/virtio/virtio_user/virtio_user_dev.c  | 181 +++++++++++++++---\n .../net/virtio/virtio_user/virtio_user_dev.h  |   9 +-\n drivers/net/virtio/virtio_user_ethdev.c       | 179 +----------------\n 7 files changed, 350 insertions(+), 233 deletions(-)",
    "diff": "diff --git a/drivers/net/virtio/virtio_user/vhost.h b/drivers/net/virtio/virtio_user/vhost.h\nindex fc4f059c02..c49e88036d 100644\n--- a/drivers/net/virtio/virtio_user/vhost.h\n+++ b/drivers/net/virtio/virtio_user/vhost.h\n@@ -82,6 +82,10 @@ struct virtio_user_backend_ops {\n \tint (*enable_qp)(struct virtio_user_dev *dev, uint16_t pair_idx, int enable);\n \tint (*dma_map)(struct virtio_user_dev *dev, void *addr, uint64_t iova, size_t len);\n \tint (*dma_unmap)(struct virtio_user_dev *dev, void *addr, uint64_t iova, size_t len);\n+\tint (*update_link_state)(struct virtio_user_dev *dev);\n+\tint (*server_disconnect)(struct virtio_user_dev *dev);\n+\tint (*server_reconnect)(struct virtio_user_dev *dev);\n+\tint (*get_intr_fd)(struct virtio_user_dev *dev);\n };\n \n extern struct virtio_user_backend_ops virtio_ops_user;\ndiff --git a/drivers/net/virtio/virtio_user/vhost_kernel.c b/drivers/net/virtio/virtio_user/vhost_kernel.c\nindex 26a71ad07b..0d05e7d339 100644\n--- a/drivers/net/virtio/virtio_user/vhost_kernel.c\n+++ b/drivers/net/virtio/virtio_user/vhost_kernel.c\n@@ -459,6 +459,20 @@ vhost_kernel_get_backend_features(uint64_t *features)\n \treturn 0;\n }\n \n+static int\n+vhost_kernel_update_link_state(struct virtio_user_dev *dev __rte_unused)\n+{\n+\t/* Nothing to update (Maybe get TAP interface link state?) */\n+\treturn 0;\n+}\n+\n+static int\n+vhost_kernel_get_intr_fd(struct virtio_user_dev *dev __rte_unused)\n+{\n+\t/* No link state interrupt with Vhost-kernel */\n+\treturn -1;\n+}\n+\n struct virtio_user_backend_ops virtio_ops_kernel = {\n \t.setup = vhost_kernel_setup,\n \t.destroy = vhost_kernel_destroy,\n@@ -475,5 +489,7 @@ struct virtio_user_backend_ops virtio_ops_kernel = {\n \t.set_vring_addr = vhost_kernel_set_vring_addr,\n \t.get_status = vhost_kernel_get_status,\n \t.set_status = vhost_kernel_set_status,\n-\t.enable_qp = vhost_kernel_enable_queue_pair\n+\t.enable_qp = vhost_kernel_enable_queue_pair,\n+\t.update_link_state = vhost_kernel_update_link_state,\n+\t.get_intr_fd = vhost_kernel_get_intr_fd,\n };\ndiff --git a/drivers/net/virtio/virtio_user/vhost_user.c b/drivers/net/virtio/virtio_user/vhost_user.c\nindex 26b8c9e9c9..088aae3aa3 100644\n--- a/drivers/net/virtio/virtio_user/vhost_user.c\n+++ b/drivers/net/virtio/virtio_user/vhost_user.c\n@@ -11,6 +11,7 @@\n #include <string.h>\n #include <errno.h>\n \n+#include <rte_alarm.h>\n #include <rte_string_fns.h>\n #include <rte_fbarray.h>\n \n@@ -18,6 +19,8 @@\n #include \"virtio_user_dev.h\"\n \n struct vhost_user_data {\n+\tint vhostfd;\n+\tint listenfd;\n \tuint64_t protocol_features;\n };\n \n@@ -182,13 +185,14 @@ vhost_user_read(int fd, struct vhost_user_msg *msg)\n static int\n vhost_user_check_reply_ack(struct virtio_user_dev *dev, struct vhost_user_msg *msg)\n {\n+\tstruct vhost_user_data *data = dev->backend_data;\n \tenum vhost_user_request req = msg->request;\n \tint ret;\n \n \tif (!(msg->flags & VHOST_USER_NEED_REPLY_MASK))\n \t\treturn 0;\n \n-\tret = vhost_user_read(dev->vhostfd, msg);\n+\tret = vhost_user_read(data->vhostfd, msg);\n \tif (ret < 0) {\n \t\tPMD_DRV_LOG(ERR, \"Failed to read reply-ack\");\n \t\treturn -1;\n@@ -216,12 +220,13 @@ static int\n vhost_user_set_owner(struct virtio_user_dev *dev)\n {\n \tint ret;\n+\tstruct vhost_user_data *data = dev->backend_data;\n \tstruct vhost_user_msg msg = {\n \t\t.request = VHOST_USER_SET_OWNER,\n \t\t.flags = VHOST_USER_VERSION,\n \t};\n \n-\tret = vhost_user_write(dev->vhostfd, &msg, NULL, 0);\n+\tret = vhost_user_write(data->vhostfd, &msg, NULL, 0);\n \tif (ret < 0) {\n \t\tPMD_DRV_LOG(ERR, \"Failed to set owner\");\n \t\treturn -1;\n@@ -234,16 +239,17 @@ static int\n vhost_user_get_protocol_features(struct virtio_user_dev *dev, uint64_t *features)\n {\n \tint ret;\n+\tstruct vhost_user_data *data = dev->backend_data;\n \tstruct vhost_user_msg msg = {\n \t\t.request = VHOST_USER_GET_PROTOCOL_FEATURES,\n \t\t.flags = VHOST_USER_VERSION,\n \t};\n \n-\tret = vhost_user_write(dev->vhostfd, &msg, NULL, 0);\n+\tret = vhost_user_write(data->vhostfd, &msg, NULL, 0);\n \tif (ret < 0)\n \t\tgoto err;\n \n-\tret = vhost_user_read(dev->vhostfd, &msg);\n+\tret = vhost_user_read(data->vhostfd, &msg);\n \tif (ret < 0)\n \t\tgoto err;\n \n@@ -270,6 +276,7 @@ static int\n vhost_user_set_protocol_features(struct virtio_user_dev *dev, uint64_t features)\n {\n \tint ret;\n+\tstruct vhost_user_data *data = dev->backend_data;\n \tstruct vhost_user_msg msg = {\n \t\t.request = VHOST_USER_SET_PROTOCOL_FEATURES,\n \t\t.flags = VHOST_USER_VERSION,\n@@ -277,7 +284,7 @@ vhost_user_set_protocol_features(struct virtio_user_dev *dev, uint64_t features)\n \t\t.payload.u64 = features,\n \t};\n \n-\tret = vhost_user_write(dev->vhostfd, &msg, NULL, 0);\n+\tret = vhost_user_write(data->vhostfd, &msg, NULL, 0);\n \tif (ret < 0) {\n \t\tPMD_DRV_LOG(ERR, \"Failed to set protocol features\");\n \t\treturn -1;\n@@ -296,11 +303,11 @@ vhost_user_get_features(struct virtio_user_dev *dev, uint64_t *features)\n \t\t.flags = VHOST_USER_VERSION,\n \t};\n \n-\tret = vhost_user_write(dev->vhostfd, &msg, NULL, 0);\n+\tret = vhost_user_write(data->vhostfd, &msg, NULL, 0);\n \tif (ret < 0)\n \t\tgoto err;\n \n-\tret = vhost_user_read(dev->vhostfd, &msg);\n+\tret = vhost_user_read(data->vhostfd, &msg);\n \tif (ret < 0)\n \t\tgoto err;\n \n@@ -344,6 +351,7 @@ static int\n vhost_user_set_features(struct virtio_user_dev *dev, uint64_t features)\n {\n \tint ret;\n+\tstruct vhost_user_data *data = dev->backend_data;\n \tstruct vhost_user_msg msg = {\n \t\t.request = VHOST_USER_SET_FEATURES,\n \t\t.flags = VHOST_USER_VERSION,\n@@ -353,7 +361,7 @@ vhost_user_set_features(struct virtio_user_dev *dev, uint64_t features)\n \n \tmsg.payload.u64 |= dev->device_features & (1ULL << VHOST_USER_F_PROTOCOL_FEATURES);\n \n-\tret = vhost_user_write(dev->vhostfd, &msg, NULL, 0);\n+\tret = vhost_user_write(data->vhostfd, &msg, NULL, 0);\n \tif (ret < 0) {\n \t\tPMD_DRV_LOG(ERR, \"Failed to set features\");\n \t\treturn -1;\n@@ -477,7 +485,7 @@ vhost_user_set_memory_table(struct virtio_user_dev *dev)\n \tmsg.size += sizeof(msg.payload.memory.padding);\n \tmsg.size += fd_num * sizeof(struct vhost_memory_region);\n \n-\tret = vhost_user_write(dev->vhostfd, &msg, fds, fd_num);\n+\tret = vhost_user_write(data->vhostfd, &msg, fds, fd_num);\n \tif (ret < 0)\n \t\tgoto err;\n \n@@ -492,6 +500,7 @@ vhost_user_set_vring(struct virtio_user_dev *dev, enum vhost_user_request req,\n \t\tstruct vhost_vring_state *state)\n {\n \tint ret;\n+\tstruct vhost_user_data *data = dev->backend_data;\n \tstruct vhost_user_msg msg = {\n \t\t.request = req,\n \t\t.flags = VHOST_USER_VERSION,\n@@ -499,7 +508,7 @@ vhost_user_set_vring(struct virtio_user_dev *dev, enum vhost_user_request req,\n \t\t.payload.state = *state,\n \t};\n \n-\tret = vhost_user_write(dev->vhostfd, &msg, NULL, 0);\n+\tret = vhost_user_write(data->vhostfd, &msg, NULL, 0);\n \tif (ret < 0) {\n \t\tPMD_DRV_LOG(ERR, \"Failed to set vring state (request %d)\", req);\n \t\treturn -1;\n@@ -531,6 +540,7 @@ vhost_user_get_vring_base(struct virtio_user_dev *dev, struct vhost_vring_state\n {\n \tint ret;\n \tstruct vhost_user_msg msg;\n+\tstruct vhost_user_data *data = dev->backend_data;\n \tunsigned int index = state->index;\n \n \tret = vhost_user_set_vring(dev, VHOST_USER_GET_VRING_BASE, state);\n@@ -539,7 +549,7 @@ vhost_user_get_vring_base(struct virtio_user_dev *dev, struct vhost_vring_state\n \t\tgoto err;\n \t}\n \n-\tret = vhost_user_read(dev->vhostfd, &msg);\n+\tret = vhost_user_read(data->vhostfd, &msg);\n \tif (ret < 0) {\n \t\tPMD_DRV_LOG(ERR, \"Failed to read reply\");\n \t\tgoto err;\n@@ -575,6 +585,7 @@ vhost_user_set_vring_file(struct virtio_user_dev *dev, enum vhost_user_request r\n \tint ret;\n \tint fd = file->fd;\n \tint num_fd = 0;\n+\tstruct vhost_user_data *data = dev->backend_data;\n \tstruct vhost_user_msg msg = {\n \t\t.request = req,\n \t\t.flags = VHOST_USER_VERSION,\n@@ -587,7 +598,7 @@ vhost_user_set_vring_file(struct virtio_user_dev *dev, enum vhost_user_request r\n \telse\n \t\tmsg.payload.u64 |= VHOST_USER_VRING_NOFD_MASK;\n \n-\tret = vhost_user_write(dev->vhostfd, &msg, &fd, num_fd);\n+\tret = vhost_user_write(data->vhostfd, &msg, &fd, num_fd);\n \tif (ret < 0) {\n \t\tPMD_DRV_LOG(ERR, \"Failed to set vring file (request %d)\", req);\n \t\treturn -1;\n@@ -613,6 +624,7 @@ static int\n vhost_user_set_vring_addr(struct virtio_user_dev *dev, struct vhost_vring_addr *addr)\n {\n \tint ret;\n+\tstruct vhost_user_data *data = dev->backend_data;\n \tstruct vhost_user_msg msg = {\n \t\t.request = VHOST_USER_SET_VRING_ADDR,\n \t\t.flags = VHOST_USER_VERSION,\n@@ -620,7 +632,7 @@ vhost_user_set_vring_addr(struct virtio_user_dev *dev, struct vhost_vring_addr *\n \t\t.payload.addr = *addr,\n \t};\n \n-\tret = vhost_user_write(dev->vhostfd, &msg, NULL, 0);\n+\tret = vhost_user_write(data->vhostfd, &msg, NULL, 0);\n \tif (ret < 0) {\n \t\tPMD_DRV_LOG(ERR, \"Failed to send vring addresses\");\n \t\treturn -1;\n@@ -653,13 +665,13 @@ vhost_user_get_status(struct virtio_user_dev *dev, uint8_t *status)\n \tif (!(data->protocol_features & (1ULL << VHOST_USER_PROTOCOL_F_STATUS)))\n \t\treturn -ENOTSUP;\n \n-\tret = vhost_user_write(dev->vhostfd, &msg, NULL, 0);\n+\tret = vhost_user_write(data->vhostfd, &msg, NULL, 0);\n \tif (ret < 0) {\n \t\tPMD_DRV_LOG(ERR, \"Failed to send request\");\n \t\tgoto err;\n \t}\n \n-\tret = vhost_user_read(dev->vhostfd, &msg);\n+\tret = vhost_user_read(data->vhostfd, &msg);\n \tif (ret < 0) {\n \t\tPMD_DRV_LOG(ERR, \"Failed to recv request\");\n \t\tgoto err;\n@@ -712,7 +724,7 @@ vhost_user_set_status(struct virtio_user_dev *dev, uint8_t status)\n \tif (data->protocol_features & (1ULL << VHOST_USER_PROTOCOL_F_REPLY_ACK))\n \t\tmsg.flags |= VHOST_USER_NEED_REPLY_MASK;\n \n-\tret = vhost_user_write(dev->vhostfd, &msg, NULL, 0);\n+\tret = vhost_user_write(data->vhostfd, &msg, NULL, 0);\n \tif (ret < 0) {\n \t\tPMD_DRV_LOG(ERR, \"Failed to send get status request\");\n \t\treturn -1;\n@@ -723,11 +735,12 @@ vhost_user_set_status(struct virtio_user_dev *dev, uint8_t status)\n \n #define MAX_VIRTIO_USER_BACKLOG 1\n static int\n-virtio_user_start_server(struct virtio_user_dev *dev, struct sockaddr_un *un)\n+vhost_user_start_server(struct virtio_user_dev *dev, struct sockaddr_un *un)\n {\n \tint ret;\n \tint flag;\n-\tint fd = dev->listenfd;\n+\tstruct vhost_user_data *data = dev->backend_data;\n+\tint fd = data->listenfd;\n \n \tret = bind(fd, (struct sockaddr *)un, sizeof(*un));\n \tif (ret < 0) {\n@@ -740,8 +753,8 @@ virtio_user_start_server(struct virtio_user_dev *dev, struct sockaddr_un *un)\n \t\treturn -1;\n \n \tPMD_DRV_LOG(NOTICE, \"(%s) waiting for client connection...\", dev->path);\n-\tdev->vhostfd = accept(fd, NULL, NULL);\n-\tif (dev->vhostfd < 0) {\n+\tdata->vhostfd = accept(fd, NULL, NULL);\n+\tif (data->vhostfd < 0) {\n \t\tPMD_DRV_LOG(ERR, \"Failed to accept initial client connection (%s)\",\n \t\t\t\tstrerror(errno));\n \t\treturn -1;\n@@ -756,6 +769,37 @@ virtio_user_start_server(struct virtio_user_dev *dev, struct sockaddr_un *un)\n \treturn 0;\n }\n \n+static int\n+vhost_user_server_disconnect(struct virtio_user_dev *dev)\n+{\n+\tstruct vhost_user_data *data = dev->backend_data;\n+\n+\tif (data->vhostfd < 0) {\n+\t\tPMD_DRV_LOG(ERR, \"(%s) Expected valid Vhost FD\", dev->path);\n+\t\treturn -1;\n+\t}\n+\n+\tclose(data->vhostfd);\n+\tdata->vhostfd = -1;\n+\n+\treturn 0;\n+}\n+\n+static int\n+vhost_user_server_reconnect(struct virtio_user_dev *dev)\n+{\n+\tstruct vhost_user_data *data = dev->backend_data;\n+\tint fd;\n+\n+\tfd = accept(data->listenfd, NULL, NULL);\n+\tif (fd < 0)\n+\t\treturn -1;\n+\n+\tdata->vhostfd = fd;\n+\n+\treturn 0;\n+}\n+\n /**\n  * Set up environment to talk with a vhost user backend.\n  *\n@@ -781,6 +825,8 @@ vhost_user_setup(struct virtio_user_dev *dev)\n \n \tdev->backend_data = data;\n \n+\tdata->vhostfd = -1;\n+\n \tfd = socket(AF_UNIX, SOCK_STREAM, 0);\n \tif (fd < 0) {\n \t\tPMD_DRV_LOG(ERR, \"socket() error, %s\", strerror(errno));\n@@ -796,8 +842,8 @@ vhost_user_setup(struct virtio_user_dev *dev)\n \tstrlcpy(un.sun_path, dev->path, sizeof(un.sun_path));\n \n \tif (dev->is_server) {\n-\t\tdev->listenfd = fd;\n-\t\tif (virtio_user_start_server(dev, &un) < 0) {\n+\t\tdata->listenfd = fd;\n+\t\tif (vhost_user_start_server(dev, &un) < 0) {\n \t\t\tPMD_DRV_LOG(ERR, \"virtio-user startup fails in server mode\");\n \t\t\tgoto err_socket;\n \t\t}\n@@ -806,7 +852,7 @@ vhost_user_setup(struct virtio_user_dev *dev)\n \t\t\tPMD_DRV_LOG(ERR, \"connect error, %s\", strerror(errno));\n \t\t\tgoto err_socket;\n \t\t}\n-\t\tdev->vhostfd = fd;\n+\t\tdata->vhostfd = fd;\n \t}\n \n \treturn 0;\n@@ -823,11 +869,24 @@ vhost_user_setup(struct virtio_user_dev *dev)\n static int\n vhost_user_destroy(struct virtio_user_dev *dev)\n {\n-\tif (dev->backend_data) {\n-\t\tfree(dev->backend_data);\n-\t\tdev->backend_data = NULL;\n+\tstruct vhost_user_data *data = dev->backend_data;\n+\n+\tif (!data)\n+\t\treturn 0;\n+\n+\tif (data->vhostfd >= 0) {\n+\t\tclose(data->vhostfd);\n+\t\tdata->vhostfd = -1;\n \t}\n \n+\tif (data->listenfd >= 0) {\n+\t\tclose(data->listenfd);\n+\t\tdata->listenfd = -1;\n+\t}\n+\n+\tfree(data);\n+\tdev->backend_data = NULL;\n+\n \treturn 0;\n }\n \n@@ -836,8 +895,12 @@ vhost_user_enable_queue_pair(struct virtio_user_dev *dev,\n \t\t\t     uint16_t pair_idx,\n \t\t\t     int enable)\n {\n+\tstruct vhost_user_data *data = dev->backend_data;\n \tint i;\n \n+\tif (data->vhostfd < 0)\n+\t\treturn 0;\n+\n \tif (dev->qp_enabled[pair_idx] == enable)\n \t\treturn 0;\n \n@@ -863,6 +926,61 @@ vhost_user_get_backend_features(uint64_t *features)\n \treturn 0;\n }\n \n+static int\n+vhost_user_update_link_state(struct virtio_user_dev *dev)\n+{\n+\tstruct vhost_user_data *data = dev->backend_data;\n+\tchar buf[128];\n+\n+\tif (data->vhostfd >= 0) {\n+\t\tint r;\n+\t\tint flags;\n+\n+\t\tflags = fcntl(data->vhostfd, F_GETFL);\n+\t\tif (fcntl(data->vhostfd, F_SETFL, flags | O_NONBLOCK) == -1) {\n+\t\t\tPMD_DRV_LOG(ERR, \"error setting O_NONBLOCK flag\");\n+\t\t\treturn -1;\n+\t\t}\n+\n+\t\tr = recv(data->vhostfd, buf, 128, MSG_PEEK);\n+\t\tif (r == 0 || (r < 0 && errno != EAGAIN)) {\n+\t\t\tdev->net_status &= (~VIRTIO_NET_S_LINK_UP);\n+\t\t\tPMD_DRV_LOG(ERR, \"virtio-user port %u is down\", dev->port_id);\n+\n+\t\t\t/* This function could be called in the process\n+\t\t\t * of interrupt handling, callback cannot be\n+\t\t\t * unregistered here, set an alarm to do it.\n+\t\t\t */\n+\t\t\trte_eal_alarm_set(1, virtio_user_dev_delayed_handler, (void *)dev);\n+\t\t} else {\n+\t\t\tdev->net_status |= VIRTIO_NET_S_LINK_UP;\n+\t\t}\n+\n+\t\tif (fcntl(data->vhostfd, F_SETFL,\n+\t\t\t\t\tflags & ~O_NONBLOCK) == -1) {\n+\t\t\tPMD_DRV_LOG(ERR, \"error clearing O_NONBLOCK flag\");\n+\t\t\treturn -1;\n+\t\t}\n+\t} else if (dev->is_server) {\n+\t\tdev->net_status &= (~VIRTIO_NET_S_LINK_UP);\n+\t\tif (virtio_user_dev_server_reconnect(dev) >= 0)\n+\t\t\tdev->net_status |= VIRTIO_NET_S_LINK_UP;\n+\t}\n+\n+\treturn 0;\n+}\n+\n+static int\n+vhost_user_get_intr_fd(struct virtio_user_dev *dev)\n+{\n+\tstruct vhost_user_data *data = dev->backend_data;\n+\n+\tif (dev->is_server && data->vhostfd == -1)\n+\t\treturn data->listenfd;\n+\n+\treturn data->vhostfd;\n+}\n+\n struct virtio_user_backend_ops virtio_ops_user = {\n \t.setup = vhost_user_setup,\n \t.destroy = vhost_user_destroy,\n@@ -879,5 +997,9 @@ struct virtio_user_backend_ops virtio_ops_user = {\n \t.set_vring_addr = vhost_user_set_vring_addr,\n \t.get_status = vhost_user_get_status,\n \t.set_status = vhost_user_set_status,\n-\t.enable_qp = vhost_user_enable_queue_pair\n+\t.enable_qp = vhost_user_enable_queue_pair,\n+\t.update_link_state = vhost_user_update_link_state,\n+\t.server_disconnect = vhost_user_server_disconnect,\n+\t.server_reconnect = vhost_user_server_reconnect,\n+\t.get_intr_fd = vhost_user_get_intr_fd,\n };\ndiff --git a/drivers/net/virtio/virtio_user/vhost_vdpa.c b/drivers/net/virtio/virtio_user/vhost_vdpa.c\nindex f5a8943993..5e3778b682 100644\n--- a/drivers/net/virtio/virtio_user/vhost_vdpa.c\n+++ b/drivers/net/virtio/virtio_user/vhost_vdpa.c\n@@ -471,6 +471,20 @@ vhost_vdpa_get_backend_features(uint64_t *features)\n \treturn 0;\n }\n \n+static int\n+vhost_vdpa_update_link_state(struct virtio_user_dev *dev __rte_unused)\n+{\n+\t/* Nothing to update (for now?) */\n+\treturn 0;\n+}\n+\n+static int\n+vhost_vdpa_get_intr_fd(struct virtio_user_dev *dev __rte_unused)\n+{\n+\t/* No link state interrupt with Vhost-vDPA */\n+\treturn -1;\n+}\n+\n struct virtio_user_backend_ops virtio_ops_vdpa = {\n \t.setup = vhost_vdpa_setup,\n \t.destroy = vhost_vdpa_destroy,\n@@ -490,4 +504,6 @@ struct virtio_user_backend_ops virtio_ops_vdpa = {\n \t.enable_qp = vhost_vdpa_enable_queue_pair,\n \t.dma_map = vhost_vdpa_dma_map_batch,\n \t.dma_unmap = vhost_vdpa_dma_unmap_batch,\n+\t.update_link_state = vhost_vdpa_update_link_state,\n+\t.get_intr_fd = vhost_vdpa_get_intr_fd,\n };\ndiff --git a/drivers/net/virtio/virtio_user/virtio_user_dev.c b/drivers/net/virtio/virtio_user/virtio_user_dev.c\nindex 215819d46d..7128457e32 100644\n--- a/drivers/net/virtio/virtio_user/virtio_user_dev.c\n+++ b/drivers/net/virtio/virtio_user/virtio_user_dev.c\n@@ -343,11 +343,7 @@ virtio_user_fill_intr_handle(struct virtio_user_dev *dev)\n \teth_dev->intr_handle->type = RTE_INTR_HANDLE_VDEV;\n \t/* For virtio vdev, no need to read counter for clean */\n \teth_dev->intr_handle->efd_counter_size = 0;\n-\teth_dev->intr_handle->fd = -1;\n-\tif (dev->vhostfd >= 0)\n-\t\teth_dev->intr_handle->fd = dev->vhostfd;\n-\telse if (dev->is_server)\n-\t\teth_dev->intr_handle->fd = dev->listenfd;\n+\teth_dev->intr_handle->fd = dev->ops->get_intr_fd(dev);\n \n \treturn 0;\n }\n@@ -404,7 +400,6 @@ virtio_user_dev_setup(struct virtio_user_dev *dev)\n {\n \tuint32_t q;\n \n-\tdev->vhostfd = -1;\n \tdev->vhostfds = NULL;\n \tdev->tapfds = NULL;\n \n@@ -598,15 +593,6 @@ virtio_user_dev_uninit(struct virtio_user_dev *dev)\n \t\tclose(dev->callfds[i]);\n \t\tclose(dev->kickfds[i]);\n \t}\n-\n-\tif (dev->vhostfd >= 0)\n-\t\tclose(dev->vhostfd);\n-\n-\tif (dev->is_server && dev->listenfd >= 0) {\n-\t\tclose(dev->listenfd);\n-\t\tdev->listenfd = -1;\n-\t}\n-\n \tif (dev->vhostfds) {\n \t\tfor (i = 0; i < dev->max_queue_pairs; ++i) {\n \t\t\tclose(dev->vhostfds[i]);\n@@ -637,15 +623,11 @@ virtio_user_handle_mq(struct virtio_user_dev *dev, uint16_t q_pairs)\n \t\treturn -1;\n \t}\n \n-\t/* Server mode can't enable queue pairs if vhostfd is invalid,\n-\t * always return 0 in this case.\n-\t */\n-\tif (!dev->is_server || dev->vhostfd >= 0) {\n-\t\tfor (i = 0; i < q_pairs; ++i)\n-\t\t\tret |= dev->ops->enable_qp(dev, i, 1);\n-\t\tfor (i = q_pairs; i < dev->max_queue_pairs; ++i)\n-\t\t\tret |= dev->ops->enable_qp(dev, i, 0);\n-\t}\n+\tfor (i = 0; i < q_pairs; ++i)\n+\t\tret |= dev->ops->enable_qp(dev, i, 1);\n+\tfor (i = q_pairs; i < dev->max_queue_pairs; ++i)\n+\t\tret |= dev->ops->enable_qp(dev, i, 0);\n+\n \tdev->queue_pairs = q_pairs;\n \n \treturn ret;\n@@ -860,3 +842,154 @@ virtio_user_dev_update_status(struct virtio_user_dev *dev)\n \tpthread_mutex_unlock(&dev->mutex);\n \treturn ret;\n }\n+\n+int\n+virtio_user_dev_update_link_state(struct virtio_user_dev *dev)\n+{\n+\tif (dev->ops->update_link_state)\n+\t\treturn dev->ops->update_link_state(dev);\n+\n+\treturn 0;\n+}\n+\n+static void\n+virtio_user_dev_reset_queues_packed(struct rte_eth_dev *eth_dev)\n+{\n+\tstruct virtio_user_dev *dev = eth_dev->data->dev_private;\n+\tstruct virtio_hw *hw = &dev->hw;\n+\tstruct virtnet_rx *rxvq;\n+\tstruct virtnet_tx *txvq;\n+\tuint16_t i;\n+\n+\t/* Add lock to avoid queue contention. */\n+\trte_spinlock_lock(&hw->state_lock);\n+\thw->started = 0;\n+\n+\t/*\n+\t * Waiting for datapath to complete before resetting queues.\n+\t * 1 ms should be enough for the ongoing Tx/Rx function to finish.\n+\t */\n+\trte_delay_ms(1);\n+\n+\t/* Vring reset for each Tx queue and Rx queue. */\n+\tfor (i = 0; i < eth_dev->data->nb_rx_queues; i++) {\n+\t\trxvq = eth_dev->data->rx_queues[i];\n+\t\tvirtqueue_rxvq_reset_packed(rxvq->vq);\n+\t\tvirtio_dev_rx_queue_setup_finish(eth_dev, i);\n+\t}\n+\n+\tfor (i = 0; i < eth_dev->data->nb_tx_queues; i++) {\n+\t\ttxvq = eth_dev->data->tx_queues[i];\n+\t\tvirtqueue_txvq_reset_packed(txvq->vq);\n+\t}\n+\n+\thw->started = 1;\n+\trte_spinlock_unlock(&hw->state_lock);\n+}\n+\n+void\n+virtio_user_dev_delayed_handler(void *param)\n+{\n+\tstruct virtio_user_dev *dev = param;\n+\tstruct rte_eth_dev *eth_dev = &rte_eth_devices[dev->port_id];\n+\n+\tif (rte_intr_disable(eth_dev->intr_handle) < 0) {\n+\t\tPMD_DRV_LOG(ERR, \"interrupt disable failed\");\n+\t\treturn;\n+\t}\n+\trte_intr_callback_unregister(eth_dev->intr_handle,\n+\t\t\t\t     virtio_interrupt_handler, eth_dev);\n+\tif (dev->is_server) {\n+\t\tif (dev->ops->server_disconnect)\n+\t\t\tdev->ops->server_disconnect(dev);\n+\t\teth_dev->intr_handle->fd = dev->ops->get_intr_fd(dev);\n+\t\trte_intr_callback_register(eth_dev->intr_handle,\n+\t\t\t\t\t   virtio_interrupt_handler, eth_dev);\n+\t\tif (rte_intr_enable(eth_dev->intr_handle) < 0) {\n+\t\t\tPMD_DRV_LOG(ERR, \"interrupt enable failed\");\n+\t\t\treturn;\n+\t\t}\n+\t}\n+}\n+\n+int\n+virtio_user_dev_server_reconnect(struct virtio_user_dev *dev)\n+{\n+\tint ret, old_status;\n+\tstruct rte_eth_dev *eth_dev = &rte_eth_devices[dev->port_id];\n+\tstruct virtio_hw *hw = &dev->hw;\n+\n+\tif (!dev->ops->server_reconnect) {\n+\t\tPMD_DRV_LOG(ERR, \"(%s) Missing server reconnect callback\", dev->path);\n+\t\treturn -1;\n+\t}\n+\n+\tif (dev->ops->server_reconnect(dev)) {\n+\t\tPMD_DRV_LOG(ERR, \"(%s) Reconnect callback call failed\", dev->path);\n+\t\treturn -1;\n+\t}\n+\n+\told_status = dev->status;\n+\n+\tvirtio_reset(hw);\n+\n+\tvirtio_set_status(hw, VIRTIO_CONFIG_STATUS_ACK);\n+\n+\tvirtio_set_status(hw, VIRTIO_CONFIG_STATUS_DRIVER);\n+\n+\tif (dev->ops->get_features(dev, &dev->device_features) < 0) {\n+\t\tPMD_INIT_LOG(ERR, \"get_features failed: %s\",\n+\t\t\t     strerror(errno));\n+\t\treturn -1;\n+\t}\n+\n+\tdev->device_features |= dev->frontend_features;\n+\n+\t/* unmask vhost-user unsupported features */\n+\tdev->device_features &= ~(dev->unsupported_features);\n+\n+\tdev->features &= dev->device_features;\n+\n+\t/* For packed ring, resetting queues is required in reconnection. */\n+\tif (virtio_with_packed_queue(hw) &&\n+\t   (old_status & VIRTIO_CONFIG_STATUS_DRIVER_OK)) {\n+\t\tPMD_INIT_LOG(NOTICE, \"Packets on the fly will be dropped\"\n+\t\t\t\t\" when packed ring reconnecting.\");\n+\t\tvirtio_user_dev_reset_queues_packed(eth_dev);\n+\t}\n+\n+\tvirtio_set_status(hw, VIRTIO_CONFIG_STATUS_FEATURES_OK);\n+\n+\t/* Start the device */\n+\tvirtio_set_status(hw, VIRTIO_CONFIG_STATUS_DRIVER_OK);\n+\tif (!dev->started)\n+\t\treturn -1;\n+\n+\tif (dev->queue_pairs > 1) {\n+\t\tret = virtio_user_handle_mq(dev, dev->queue_pairs);\n+\t\tif (ret != 0) {\n+\t\t\tPMD_INIT_LOG(ERR, \"Fails to enable multi-queue pairs!\");\n+\t\t\treturn -1;\n+\t\t}\n+\t}\n+\tif (eth_dev->data->dev_flags & RTE_ETH_DEV_INTR_LSC) {\n+\t\tif (rte_intr_disable(eth_dev->intr_handle) < 0) {\n+\t\t\tPMD_DRV_LOG(ERR, \"interrupt disable failed\");\n+\t\t\treturn -1;\n+\t\t}\n+\t\trte_intr_callback_unregister(eth_dev->intr_handle,\n+\t\t\t\t\t     virtio_interrupt_handler,\n+\t\t\t\t\t     eth_dev);\n+\n+\t\teth_dev->intr_handle->fd = dev->ops->get_intr_fd(dev);\n+\t\trte_intr_callback_register(eth_dev->intr_handle,\n+\t\t\t\t\t   virtio_interrupt_handler, eth_dev);\n+\n+\t\tif (rte_intr_enable(eth_dev->intr_handle) < 0) {\n+\t\t\tPMD_DRV_LOG(ERR, \"interrupt enable failed\");\n+\t\t\treturn -1;\n+\t\t}\n+\t}\n+\tPMD_INIT_LOG(NOTICE, \"server mode virtio-user reconnection succeeds!\");\n+\treturn 0;\n+}\ndiff --git a/drivers/net/virtio/virtio_user/virtio_user_dev.h b/drivers/net/virtio/virtio_user/virtio_user_dev.h\nindex 7650097b6d..36d2410546 100644\n--- a/drivers/net/virtio/virtio_user/virtio_user_dev.h\n+++ b/drivers/net/virtio/virtio_user/virtio_user_dev.h\n@@ -27,11 +27,11 @@ struct virtio_user_queue {\n struct virtio_user_dev {\n \tstruct virtio_hw hw;\n \tenum virtio_user_backend_type backend_type;\n-\t/* for vhost_user backend */\n-\tint\t\tvhostfd;\n-\tint\t\tlistenfd;   /* listening fd */\n \tbool\t\tis_server;  /* server or client mode */\n \n+\t/* for vhost_vdpa backend */\n+\tint\t\tvhostfd;\n+\n \t/* for vhost_kernel backend */\n \tchar\t\t*ifname;\n \tint\t\t*vhostfds;\n@@ -85,5 +85,8 @@ void virtio_user_handle_cq_packed(struct virtio_user_dev *dev,\n uint8_t virtio_user_handle_mq(struct virtio_user_dev *dev, uint16_t q_pairs);\n int virtio_user_dev_set_status(struct virtio_user_dev *dev, uint8_t status);\n int virtio_user_dev_update_status(struct virtio_user_dev *dev);\n+int virtio_user_dev_update_link_state(struct virtio_user_dev *dev);\n+void virtio_user_dev_delayed_handler(void *param);\n+int virtio_user_dev_server_reconnect(struct virtio_user_dev *dev);\n extern const char * const virtio_user_backend_strings[];\n #endif\ndiff --git a/drivers/net/virtio/virtio_user_ethdev.c b/drivers/net/virtio/virtio_user_ethdev.c\nindex e2c606a838..063a723872 100644\n--- a/drivers/net/virtio/virtio_user_ethdev.c\n+++ b/drivers/net/virtio/virtio_user_ethdev.c\n@@ -28,146 +28,6 @@\n \n #define virtio_user_get_dev(hwp) container_of(hwp, struct virtio_user_dev, hw)\n \n-static void\n-virtio_user_reset_queues_packed(struct rte_eth_dev *eth_dev)\n-{\n-\tstruct virtio_user_dev *dev = eth_dev->data->dev_private;\n-\tstruct virtio_hw *hw = &dev->hw;\n-\tstruct virtnet_rx *rxvq;\n-\tstruct virtnet_tx *txvq;\n-\tuint16_t i;\n-\n-\t/* Add lock to avoid queue contention. */\n-\trte_spinlock_lock(&hw->state_lock);\n-\thw->started = 0;\n-\n-\t/*\n-\t * Waitting for datapath to complete before resetting queues.\n-\t * 1 ms should be enough for the ongoing Tx/Rx function to finish.\n-\t */\n-\trte_delay_ms(1);\n-\n-\t/* Vring reset for each Tx queue and Rx queue. */\n-\tfor (i = 0; i < eth_dev->data->nb_rx_queues; i++) {\n-\t\trxvq = eth_dev->data->rx_queues[i];\n-\t\tvirtqueue_rxvq_reset_packed(rxvq->vq);\n-\t\tvirtio_dev_rx_queue_setup_finish(eth_dev, i);\n-\t}\n-\n-\tfor (i = 0; i < eth_dev->data->nb_tx_queues; i++) {\n-\t\ttxvq = eth_dev->data->tx_queues[i];\n-\t\tvirtqueue_txvq_reset_packed(txvq->vq);\n-\t}\n-\n-\thw->started = 1;\n-\trte_spinlock_unlock(&hw->state_lock);\n-}\n-\n-\n-static int\n-virtio_user_server_reconnect(struct virtio_user_dev *dev)\n-{\n-\tint ret, connectfd, old_status;\n-\tstruct rte_eth_dev *eth_dev = &rte_eth_devices[dev->port_id];\n-\tstruct virtio_hw *hw = &dev->hw;\n-\n-\tconnectfd = accept(dev->listenfd, NULL, NULL);\n-\tif (connectfd < 0)\n-\t\treturn -1;\n-\n-\tdev->vhostfd = connectfd;\n-\told_status = dev->status;\n-\n-\tvirtio_reset(hw);\n-\n-\tvirtio_set_status(hw, VIRTIO_CONFIG_STATUS_ACK);\n-\n-\tvirtio_set_status(hw, VIRTIO_CONFIG_STATUS_DRIVER);\n-\n-\tif (dev->ops->get_features(dev, &dev->device_features) < 0) {\n-\t\tPMD_INIT_LOG(ERR, \"get_features failed: %s\",\n-\t\t\t     strerror(errno));\n-\t\treturn -1;\n-\t}\n-\n-\tdev->device_features |= dev->frontend_features;\n-\n-\t/* umask vhost-user unsupported features */\n-\tdev->device_features &= ~(dev->unsupported_features);\n-\n-\tdev->features &= dev->device_features;\n-\n-\t/* For packed ring, resetting queues is required in reconnection. */\n-\tif (virtio_with_packed_queue(hw) &&\n-\t   (old_status & VIRTIO_CONFIG_STATUS_DRIVER_OK)) {\n-\t\tPMD_INIT_LOG(NOTICE, \"Packets on the fly will be dropped\"\n-\t\t\t\t\" when packed ring reconnecting.\");\n-\t\tvirtio_user_reset_queues_packed(eth_dev);\n-\t}\n-\n-\tvirtio_set_status(hw, VIRTIO_CONFIG_STATUS_FEATURES_OK);\n-\n-\t/* Start the device */\n-\tvirtio_set_status(hw, VIRTIO_CONFIG_STATUS_DRIVER_OK);\n-\tif (!dev->started)\n-\t\treturn -1;\n-\n-\tif (dev->queue_pairs > 1) {\n-\t\tret = virtio_user_handle_mq(dev, dev->queue_pairs);\n-\t\tif (ret != 0) {\n-\t\t\tPMD_INIT_LOG(ERR, \"Fails to enable multi-queue pairs!\");\n-\t\t\treturn -1;\n-\t\t}\n-\t}\n-\tif (eth_dev->data->dev_flags & RTE_ETH_DEV_INTR_LSC) {\n-\t\tif (rte_intr_disable(eth_dev->intr_handle) < 0) {\n-\t\t\tPMD_DRV_LOG(ERR, \"interrupt disable failed\");\n-\t\t\treturn -1;\n-\t\t}\n-\t\trte_intr_callback_unregister(eth_dev->intr_handle,\n-\t\t\t\t\t     virtio_interrupt_handler,\n-\t\t\t\t\t     eth_dev);\n-\t\teth_dev->intr_handle->fd = connectfd;\n-\t\trte_intr_callback_register(eth_dev->intr_handle,\n-\t\t\t\t\t   virtio_interrupt_handler, eth_dev);\n-\n-\t\tif (rte_intr_enable(eth_dev->intr_handle) < 0) {\n-\t\t\tPMD_DRV_LOG(ERR, \"interrupt enable failed\");\n-\t\t\treturn -1;\n-\t\t}\n-\t}\n-\tPMD_INIT_LOG(NOTICE, \"server mode virtio-user reconnection succeeds!\");\n-\treturn 0;\n-}\n-\n-static void\n-virtio_user_delayed_handler(void *param)\n-{\n-\tstruct virtio_hw *hw = (struct virtio_hw *)param;\n-\tstruct rte_eth_dev *eth_dev = &rte_eth_devices[hw->port_id];\n-\tstruct virtio_user_dev *dev = virtio_user_get_dev(hw);\n-\n-\tif (rte_intr_disable(eth_dev->intr_handle) < 0) {\n-\t\tPMD_DRV_LOG(ERR, \"interrupt disable failed\");\n-\t\treturn;\n-\t}\n-\trte_intr_callback_unregister(eth_dev->intr_handle,\n-\t\t\t\t     virtio_interrupt_handler, eth_dev);\n-\tif (dev->is_server) {\n-\t\tif (dev->vhostfd >= 0) {\n-\t\t\tclose(dev->vhostfd);\n-\t\t\tdev->vhostfd = -1;\n-\t\t}\n-\t\teth_dev->intr_handle->fd = dev->listenfd;\n-\t\trte_intr_callback_register(eth_dev->intr_handle,\n-\t\t\t\t\t   virtio_interrupt_handler, eth_dev);\n-\t\tif (rte_intr_enable(eth_dev->intr_handle) < 0) {\n-\t\t\tPMD_DRV_LOG(ERR, \"interrupt enable failed\");\n-\t\t\treturn;\n-\t\t}\n-\t}\n-}\n-\n static void\n virtio_user_read_dev_config(struct virtio_hw *hw, size_t offset,\n \t\t     void *dst, int length)\n@@ -183,44 +43,7 @@ virtio_user_read_dev_config(struct virtio_hw *hw, size_t offset,\n \t}\n \n \tif (offset == offsetof(struct virtio_net_config, status)) {\n-\t\tchar buf[128];\n-\n-\t\tif (dev->vhostfd >= 0) {\n-\t\t\tint r;\n-\t\t\tint flags;\n-\n-\t\t\tflags = fcntl(dev->vhostfd, F_GETFL);\n-\t\t\tif (fcntl(dev->vhostfd, F_SETFL,\n-\t\t\t\t\tflags | O_NONBLOCK) == -1) {\n-\t\t\t\tPMD_DRV_LOG(ERR, \"error setting O_NONBLOCK flag\");\n-\t\t\t\treturn;\n-\t\t\t}\n-\t\t\tr = recv(dev->vhostfd, buf, 128, MSG_PEEK);\n-\t\t\tif (r == 0 || (r < 0 && errno != EAGAIN)) {\n-\t\t\t\tdev->net_status &= (~VIRTIO_NET_S_LINK_UP);\n-\t\t\t\tPMD_DRV_LOG(ERR, \"virtio-user port %u is down\",\n-\t\t\t\t\t    hw->port_id);\n-\n-\t\t\t\t/* This function could be called in the process\n-\t\t\t\t * of interrupt handling, callback cannot be\n-\t\t\t\t * unregistered here, set an alarm to do it.\n-\t\t\t\t */\n-\t\t\t\trte_eal_alarm_set(1,\n-\t\t\t\t\t\t  virtio_user_delayed_handler,\n-\t\t\t\t\t\t  (void *)hw);\n-\t\t\t} else {\n-\t\t\t\tdev->net_status |= VIRTIO_NET_S_LINK_UP;\n-\t\t\t}\n-\t\t\tif (fcntl(dev->vhostfd, F_SETFL,\n-\t\t\t\t\tflags & ~O_NONBLOCK) == -1) {\n-\t\t\t\tPMD_DRV_LOG(ERR, \"error clearing O_NONBLOCK flag\");\n-\t\t\t\treturn;\n-\t\t\t}\n-\t\t} else if (dev->is_server) {\n-\t\t\tdev->net_status &= (~VIRTIO_NET_S_LINK_UP);\n-\t\t\tif (virtio_user_server_reconnect(dev) >= 0)\n-\t\t\t\tdev->net_status |= VIRTIO_NET_S_LINK_UP;\n-\t\t}\n+\t\tvirtio_user_dev_update_link_state(dev);\n \n \t\t*(uint16_t *)dst = dev->net_status;\n \t}\n",
    "prefixes": [
        "v4",
        "40/44"
    ]
}