get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

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

{
    "id": 54956,
    "url": "http://patches.dpdk.org/api/patches/54956/?format=api",
    "web_url": "http://patches.dpdk.org/project/dpdk/patch/1560957293-17294-3-git-send-email-ndragazis@arrikto.com/",
    "project": {
        "id": 1,
        "url": "http://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": "<1560957293-17294-3-git-send-email-ndragazis@arrikto.com>",
    "list_archive_url": "https://inbox.dpdk.org/dev/1560957293-17294-3-git-send-email-ndragazis@arrikto.com",
    "date": "2019-06-19T15:14:27",
    "name": "[02/28] vhost: move socket management code",
    "commit_ref": null,
    "pull_url": null,
    "state": "rfc",
    "archived": true,
    "hash": "1b5400151df41d9f7d8b37460d80861c84950d92",
    "submitter": {
        "id": 1339,
        "url": "http://patches.dpdk.org/api/people/1339/?format=api",
        "name": "Nikos Dragazis",
        "email": "ndragazis@arrikto.com"
    },
    "delegate": {
        "id": 2642,
        "url": "http://patches.dpdk.org/api/users/2642/?format=api",
        "username": "mcoquelin",
        "first_name": "Maxime",
        "last_name": "Coquelin",
        "email": "maxime.coquelin@redhat.com"
    },
    "mbox": "http://patches.dpdk.org/project/dpdk/patch/1560957293-17294-3-git-send-email-ndragazis@arrikto.com/mbox/",
    "series": [
        {
            "id": 5082,
            "url": "http://patches.dpdk.org/api/series/5082/?format=api",
            "web_url": "http://patches.dpdk.org/project/dpdk/list/?series=5082",
            "date": "2019-06-19T15:14:25",
            "name": "vhost: add virtio-vhost-user transport",
            "version": 1,
            "mbox": "http://patches.dpdk.org/series/5082/mbox/"
        }
    ],
    "comments": "http://patches.dpdk.org/api/patches/54956/comments/",
    "check": "fail",
    "checks": "http://patches.dpdk.org/api/patches/54956/checks/",
    "tags": {},
    "related": [],
    "headers": {
        "Return-Path": "<dev-bounces@dpdk.org>",
        "X-Original-To": "patchwork@dpdk.org",
        "Delivered-To": "patchwork@dpdk.org",
        "Received": [
            "from [92.243.14.124] (localhost [127.0.0.1])\n\tby dpdk.org (Postfix) with ESMTP id 33CF51C394;\n\tWed, 19 Jun 2019 17:15:42 +0200 (CEST)",
            "from mx0.arrikto.com (mx0.arrikto.com [212.71.252.59])\n\tby dpdk.org (Postfix) with ESMTP id 86CA21C386\n\tfor <dev@dpdk.org>; Wed, 19 Jun 2019 17:15:37 +0200 (CEST)",
            "from troi.prod.arr (mail.arr [10.99.0.5])\n\tby mx0.arrikto.com (Postfix) with ESMTP id 12940182006;\n\tWed, 19 Jun 2019 18:15:37 +0300 (EEST)",
            "from localhost.localdomain (unknown [10.89.50.133])\n\tby troi.prod.arr (Postfix) with ESMTPSA id 8CB73394;\n\tWed, 19 Jun 2019 18:15:35 +0300 (EEST)"
        ],
        "From": "Nikos Dragazis <ndragazis@arrikto.com>",
        "To": "dev@dpdk.org",
        "Cc": "Maxime Coquelin <maxime.coquelin@redhat.com>,\n\tTiwei Bie <tiwei.bie@intel.com>, Zhihong Wang <zhihong.wang@intel.com>,\n\tStefan Hajnoczi <stefanha@redhat.com>, Wei Wang <wei.w.wang@intel.com>,\n\tStojaczyk Dariusz <dariusz.stojaczyk@intel.com>,\n\tVangelis Koukis <vkoukis@arrikto.com>",
        "Date": "Wed, 19 Jun 2019 18:14:27 +0300",
        "Message-Id": "<1560957293-17294-3-git-send-email-ndragazis@arrikto.com>",
        "X-Mailer": "git-send-email 2.7.4",
        "In-Reply-To": "<1560957293-17294-1-git-send-email-ndragazis@arrikto.com>",
        "References": "<1560957293-17294-1-git-send-email-ndragazis@arrikto.com>",
        "Subject": "[dpdk-dev] [PATCH 02/28] vhost: move socket management code",
        "X-BeenThere": "dev@dpdk.org",
        "X-Mailman-Version": "2.1.15",
        "Precedence": "list",
        "List-Id": "DPDK patches and discussions <dev.dpdk.org>",
        "List-Unsubscribe": "<https://mails.dpdk.org/options/dev>,\n\t<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\t<mailto:dev-request@dpdk.org?subject=subscribe>",
        "Errors-To": "dev-bounces@dpdk.org",
        "Sender": "\"dev\" <dev-bounces@dpdk.org>"
    },
    "content": "The socket.c file serves two purposes:\n1. librte_vhost public API entry points, e.g. rte_vhost_driver_register().\n2. AF_UNIX socket management.\n\nMove AF_UNIX socket code into trans_af_unix.c so that socket.c only\nhandles the librte_vhost public API entry points.  This will make it\npossible to support other transports besides AF_UNIX.\n\nThis patch is a preparatory step that simply moves code from socket.c to\ntrans_af_unix.c unmodified, besides dropping 'static' qualifiers where\nnecessary because socket.c now calls into trans_af_unix.c.\n\nA lot of socket.c state is exposed in vhost.h but this is a temporary\nmeasure and will be cleaned up in later patches.  By simply moving code\nunmodified in this patch it will be easier to review the actual\nrefactoring that follows.\n\nSigned-off-by: Nikos Dragazis <ndragazis@arrikto.com>\nSigned-off-by: Stefan Hajnoczi <stefanha@redhat.com>\n---\n lib/librte_vhost/socket.c        | 549 +--------------------------------------\n lib/librte_vhost/trans_af_unix.c | 485 ++++++++++++++++++++++++++++++++++\n lib/librte_vhost/vhost.h         |  76 ++++++\n 3 files changed, 562 insertions(+), 548 deletions(-)",
    "diff": "diff --git a/lib/librte_vhost/socket.c b/lib/librte_vhost/socket.c\nindex 274988c..a993b67 100644\n--- a/lib/librte_vhost/socket.c\n+++ b/lib/librte_vhost/socket.c\n@@ -4,16 +4,10 @@\n \n #include <stdint.h>\n #include <stdio.h>\n-#include <limits.h>\n #include <stdlib.h>\n #include <unistd.h>\n #include <string.h>\n-#include <sys/types.h>\n-#include <sys/socket.h>\n-#include <sys/un.h>\n #include <sys/queue.h>\n-#include <errno.h>\n-#include <fcntl.h>\n #include <pthread.h>\n \n #include <rte_log.h>\n@@ -22,71 +16,7 @@\n #include \"vhost.h\"\n #include \"vhost_user.h\"\n \n-\n-TAILQ_HEAD(vhost_user_connection_list, vhost_user_connection);\n-\n-/*\n- * Every time rte_vhost_driver_register() is invoked, an associated\n- * vhost_user_socket struct will be created.\n- */\n-struct vhost_user_socket {\n-\tstruct vhost_user_connection_list conn_list;\n-\tpthread_mutex_t conn_mutex;\n-\tchar *path;\n-\tint socket_fd;\n-\tstruct sockaddr_un un;\n-\tbool is_server;\n-\tbool reconnect;\n-\tbool dequeue_zero_copy;\n-\tbool iommu_support;\n-\tbool use_builtin_virtio_net;\n-\n-\t/*\n-\t * The \"supported_features\" indicates the feature bits the\n-\t * vhost driver supports. The \"features\" indicates the feature\n-\t * bits after the rte_vhost_driver_features_disable/enable().\n-\t * It is also the final feature bits used for vhost-user\n-\t * features negotiation.\n-\t */\n-\tuint64_t supported_features;\n-\tuint64_t features;\n-\n-\tuint64_t protocol_features;\n-\n-\t/*\n-\t * Device id to identify a specific backend device.\n-\t * It's set to -1 for the default software implementation.\n-\t * If valid, one socket can have 1 connection only.\n-\t */\n-\tint vdpa_dev_id;\n-\n-\tstruct vhost_device_ops const *notify_ops;\n-};\n-\n-struct vhost_user_connection {\n-\tstruct vhost_user_socket *vsocket;\n-\tint connfd;\n-\tint vid;\n-\n-\tTAILQ_ENTRY(vhost_user_connection) next;\n-};\n-\n-#define MAX_VHOST_SOCKET 1024\n-struct vhost_user {\n-\tstruct vhost_user_socket *vsockets[MAX_VHOST_SOCKET];\n-\tstruct fdset fdset;\n-\tint vsocket_cnt;\n-\tpthread_mutex_t mutex;\n-};\n-\n-#define MAX_VIRTIO_BACKLOG 128\n-\n-static void vhost_user_server_new_connection(int fd, void *data, int *remove);\n-static void vhost_user_read_cb(int fd, void *dat, int *remove);\n-static int create_unix_socket(struct vhost_user_socket *vsocket);\n-static int vhost_user_start_client(struct vhost_user_socket *vsocket);\n-\n-static struct vhost_user vhost_user = {\n+struct vhost_user vhost_user = {\n \t.fdset = {\n \t\t.fd = { [0 ... MAX_FDS - 1] = {-1, NULL, NULL, NULL, 0} },\n \t\t.fd_mutex = PTHREAD_MUTEX_INITIALIZER,\n@@ -97,459 +27,6 @@ static struct vhost_user vhost_user = {\n \t.mutex = PTHREAD_MUTEX_INITIALIZER,\n };\n \n-/*\n- * return bytes# of read on success or negative val on failure. Update fdnum\n- * with number of fds read.\n- */\n-int\n-read_fd_message(int sockfd, char *buf, int buflen, int *fds, int max_fds,\n-\t\tint *fd_num)\n-{\n-\tstruct iovec iov;\n-\tstruct msghdr msgh;\n-\tchar control[CMSG_SPACE(max_fds * sizeof(int))];\n-\tstruct cmsghdr *cmsg;\n-\tint got_fds = 0;\n-\tint ret;\n-\n-\t*fd_num = 0;\n-\n-\tmemset(&msgh, 0, sizeof(msgh));\n-\tiov.iov_base = buf;\n-\tiov.iov_len  = buflen;\n-\n-\tmsgh.msg_iov = &iov;\n-\tmsgh.msg_iovlen = 1;\n-\tmsgh.msg_control = control;\n-\tmsgh.msg_controllen = sizeof(control);\n-\n-\tret = recvmsg(sockfd, &msgh, 0);\n-\tif (ret <= 0) {\n-\t\tRTE_LOG(ERR, VHOST_CONFIG, \"recvmsg failed\\n\");\n-\t\treturn ret;\n-\t}\n-\n-\tif (msgh.msg_flags & (MSG_TRUNC | MSG_CTRUNC)) {\n-\t\tRTE_LOG(ERR, VHOST_CONFIG, \"truncted msg\\n\");\n-\t\treturn -1;\n-\t}\n-\n-\tfor (cmsg = CMSG_FIRSTHDR(&msgh); cmsg != NULL;\n-\t\tcmsg = CMSG_NXTHDR(&msgh, cmsg)) {\n-\t\tif ((cmsg->cmsg_level == SOL_SOCKET) &&\n-\t\t\t(cmsg->cmsg_type == SCM_RIGHTS)) {\n-\t\t\tgot_fds = (cmsg->cmsg_len - CMSG_LEN(0)) / sizeof(int);\n-\t\t\t*fd_num = got_fds;\n-\t\t\tmemcpy(fds, CMSG_DATA(cmsg), got_fds * sizeof(int));\n-\t\t\tbreak;\n-\t\t}\n-\t}\n-\n-\t/* Clear out unused file descriptors */\n-\twhile (got_fds < max_fds)\n-\t\tfds[got_fds++] = -1;\n-\n-\treturn ret;\n-}\n-\n-int\n-send_fd_message(int sockfd, char *buf, int buflen, int *fds, int fd_num)\n-{\n-\n-\tstruct iovec iov;\n-\tstruct msghdr msgh;\n-\tsize_t fdsize = fd_num * sizeof(int);\n-\tchar control[CMSG_SPACE(fdsize)];\n-\tstruct cmsghdr *cmsg;\n-\tint ret;\n-\n-\tmemset(&msgh, 0, sizeof(msgh));\n-\tiov.iov_base = buf;\n-\tiov.iov_len = buflen;\n-\n-\tmsgh.msg_iov = &iov;\n-\tmsgh.msg_iovlen = 1;\n-\n-\tif (fds && fd_num > 0) {\n-\t\tmsgh.msg_control = control;\n-\t\tmsgh.msg_controllen = sizeof(control);\n-\t\tcmsg = CMSG_FIRSTHDR(&msgh);\n-\t\tif (cmsg == NULL) {\n-\t\t\tRTE_LOG(ERR, VHOST_CONFIG, \"cmsg == NULL\\n\");\n-\t\t\terrno = EINVAL;\n-\t\t\treturn -1;\n-\t\t}\n-\t\tcmsg->cmsg_len = CMSG_LEN(fdsize);\n-\t\tcmsg->cmsg_level = SOL_SOCKET;\n-\t\tcmsg->cmsg_type = SCM_RIGHTS;\n-\t\tmemcpy(CMSG_DATA(cmsg), fds, fdsize);\n-\t} else {\n-\t\tmsgh.msg_control = NULL;\n-\t\tmsgh.msg_controllen = 0;\n-\t}\n-\n-\tdo {\n-\t\tret = sendmsg(sockfd, &msgh, MSG_NOSIGNAL);\n-\t} while (ret < 0 && errno == EINTR);\n-\n-\tif (ret < 0) {\n-\t\tRTE_LOG(ERR, VHOST_CONFIG,  \"sendmsg error\\n\");\n-\t\treturn ret;\n-\t}\n-\n-\treturn ret;\n-}\n-\n-static void\n-vhost_user_add_connection(int fd, struct vhost_user_socket *vsocket)\n-{\n-\tint vid;\n-\tsize_t size;\n-\tstruct vhost_user_connection *conn;\n-\tint ret;\n-\n-\tif (vsocket == NULL)\n-\t\treturn;\n-\n-\tconn = malloc(sizeof(*conn));\n-\tif (conn == NULL) {\n-\t\tclose(fd);\n-\t\treturn;\n-\t}\n-\n-\tvid = vhost_new_device();\n-\tif (vid == -1) {\n-\t\tgoto err;\n-\t}\n-\n-\tsize = strnlen(vsocket->path, PATH_MAX);\n-\tvhost_set_ifname(vid, vsocket->path, size);\n-\n-\tvhost_set_builtin_virtio_net(vid, vsocket->use_builtin_virtio_net);\n-\n-\tvhost_attach_vdpa_device(vid, vsocket->vdpa_dev_id);\n-\n-\tif (vsocket->dequeue_zero_copy)\n-\t\tvhost_enable_dequeue_zero_copy(vid);\n-\n-\tRTE_LOG(INFO, VHOST_CONFIG, \"new device, handle is %d\\n\", vid);\n-\n-\tif (vsocket->notify_ops->new_connection) {\n-\t\tret = vsocket->notify_ops->new_connection(vid);\n-\t\tif (ret < 0) {\n-\t\t\tRTE_LOG(ERR, VHOST_CONFIG,\n-\t\t\t\t\"failed to add vhost user connection with fd %d\\n\",\n-\t\t\t\tfd);\n-\t\t\tgoto err_cleanup;\n-\t\t}\n-\t}\n-\n-\tconn->connfd = fd;\n-\tconn->vsocket = vsocket;\n-\tconn->vid = vid;\n-\tret = fdset_add(&vhost_user.fdset, fd, vhost_user_read_cb,\n-\t\t\tNULL, conn);\n-\tif (ret < 0) {\n-\t\tRTE_LOG(ERR, VHOST_CONFIG,\n-\t\t\t\"failed to add fd %d into vhost server fdset\\n\",\n-\t\t\tfd);\n-\n-\t\tif (vsocket->notify_ops->destroy_connection)\n-\t\t\tvsocket->notify_ops->destroy_connection(conn->vid);\n-\n-\t\tgoto err_cleanup;\n-\t}\n-\n-\tpthread_mutex_lock(&vsocket->conn_mutex);\n-\tTAILQ_INSERT_TAIL(&vsocket->conn_list, conn, next);\n-\tpthread_mutex_unlock(&vsocket->conn_mutex);\n-\n-\tfdset_pipe_notify(&vhost_user.fdset);\n-\treturn;\n-\n-err_cleanup:\n-\tvhost_destroy_device(vid);\n-err:\n-\tfree(conn);\n-\tclose(fd);\n-}\n-\n-/* call back when there is new vhost-user connection from client  */\n-static void\n-vhost_user_server_new_connection(int fd, void *dat, int *remove __rte_unused)\n-{\n-\tstruct vhost_user_socket *vsocket = dat;\n-\n-\tfd = accept(fd, NULL, NULL);\n-\tif (fd < 0)\n-\t\treturn;\n-\n-\tRTE_LOG(INFO, VHOST_CONFIG, \"new vhost user connection is %d\\n\", fd);\n-\tvhost_user_add_connection(fd, vsocket);\n-}\n-\n-static void\n-vhost_user_read_cb(int connfd, void *dat, int *remove)\n-{\n-\tstruct vhost_user_connection *conn = dat;\n-\tstruct vhost_user_socket *vsocket = conn->vsocket;\n-\tint ret;\n-\n-\tret = vhost_user_msg_handler(conn->vid, connfd);\n-\tif (ret < 0) {\n-\t\tstruct virtio_net *dev = get_device(conn->vid);\n-\n-\t\tclose(connfd);\n-\t\t*remove = 1;\n-\n-\t\tif (dev)\n-\t\t\tvhost_destroy_device_notify(dev);\n-\n-\t\tif (vsocket->notify_ops->destroy_connection)\n-\t\t\tvsocket->notify_ops->destroy_connection(conn->vid);\n-\n-\t\tvhost_destroy_device(conn->vid);\n-\n-\t\tpthread_mutex_lock(&vsocket->conn_mutex);\n-\t\tTAILQ_REMOVE(&vsocket->conn_list, conn, next);\n-\t\tpthread_mutex_unlock(&vsocket->conn_mutex);\n-\n-\t\tfree(conn);\n-\n-\t\tif (vsocket->reconnect) {\n-\t\t\tcreate_unix_socket(vsocket);\n-\t\t\tvhost_user_start_client(vsocket);\n-\t\t}\n-\t}\n-}\n-\n-static int\n-create_unix_socket(struct vhost_user_socket *vsocket)\n-{\n-\tint fd;\n-\tstruct sockaddr_un *un = &vsocket->un;\n-\n-\tfd = socket(AF_UNIX, SOCK_STREAM, 0);\n-\tif (fd < 0)\n-\t\treturn -1;\n-\tRTE_LOG(INFO, VHOST_CONFIG, \"vhost-user %s: socket created, fd: %d\\n\",\n-\t\tvsocket->is_server ? \"server\" : \"client\", fd);\n-\n-\tif (!vsocket->is_server && fcntl(fd, F_SETFL, O_NONBLOCK)) {\n-\t\tRTE_LOG(ERR, VHOST_CONFIG,\n-\t\t\t\"vhost-user: can't set nonblocking mode for socket, fd: \"\n-\t\t\t\"%d (%s)\\n\", fd, strerror(errno));\n-\t\tclose(fd);\n-\t\treturn -1;\n-\t}\n-\n-\tmemset(un, 0, sizeof(*un));\n-\tun->sun_family = AF_UNIX;\n-\tstrncpy(un->sun_path, vsocket->path, sizeof(un->sun_path));\n-\tun->sun_path[sizeof(un->sun_path) - 1] = '\\0';\n-\n-\tvsocket->socket_fd = fd;\n-\treturn 0;\n-}\n-\n-static int\n-vhost_user_start_server(struct vhost_user_socket *vsocket)\n-{\n-\tint ret;\n-\tint fd = vsocket->socket_fd;\n-\tconst char *path = vsocket->path;\n-\n-\t/*\n-\t * bind () may fail if the socket file with the same name already\n-\t * exists. But the library obviously should not delete the file\n-\t * provided by the user, since we can not be sure that it is not\n-\t * being used by other applications. Moreover, many applications form\n-\t * socket names based on user input, which is prone to errors.\n-\t *\n-\t * The user must ensure that the socket does not exist before\n-\t * registering the vhost driver in server mode.\n-\t */\n-\tret = bind(fd, (struct sockaddr *)&vsocket->un, sizeof(vsocket->un));\n-\tif (ret < 0) {\n-\t\tRTE_LOG(ERR, VHOST_CONFIG,\n-\t\t\t\"failed to bind to %s: %s; remove it and try again\\n\",\n-\t\t\tpath, strerror(errno));\n-\t\tgoto err;\n-\t}\n-\tRTE_LOG(INFO, VHOST_CONFIG, \"bind to %s\\n\", path);\n-\n-\tret = listen(fd, MAX_VIRTIO_BACKLOG);\n-\tif (ret < 0)\n-\t\tgoto err;\n-\n-\tret = fdset_add(&vhost_user.fdset, fd, vhost_user_server_new_connection,\n-\t\t  NULL, vsocket);\n-\tif (ret < 0) {\n-\t\tRTE_LOG(ERR, VHOST_CONFIG,\n-\t\t\t\"failed to add listen fd %d to vhost server fdset\\n\",\n-\t\t\tfd);\n-\t\tgoto err;\n-\t}\n-\n-\treturn 0;\n-\n-err:\n-\tclose(fd);\n-\treturn -1;\n-}\n-\n-struct vhost_user_reconnect {\n-\tstruct sockaddr_un un;\n-\tint fd;\n-\tstruct vhost_user_socket *vsocket;\n-\n-\tTAILQ_ENTRY(vhost_user_reconnect) next;\n-};\n-\n-TAILQ_HEAD(vhost_user_reconnect_tailq_list, vhost_user_reconnect);\n-struct vhost_user_reconnect_list {\n-\tstruct vhost_user_reconnect_tailq_list head;\n-\tpthread_mutex_t mutex;\n-};\n-\n-static struct vhost_user_reconnect_list reconn_list;\n-static pthread_t reconn_tid;\n-\n-static int\n-vhost_user_connect_nonblock(int fd, struct sockaddr *un, size_t sz)\n-{\n-\tint ret, flags;\n-\n-\tret = connect(fd, un, sz);\n-\tif (ret < 0 && errno != EISCONN)\n-\t\treturn -1;\n-\n-\tflags = fcntl(fd, F_GETFL, 0);\n-\tif (flags < 0) {\n-\t\tRTE_LOG(ERR, VHOST_CONFIG,\n-\t\t\t\"can't get flags for connfd %d\\n\", fd);\n-\t\treturn -2;\n-\t}\n-\tif ((flags & O_NONBLOCK) && fcntl(fd, F_SETFL, flags & ~O_NONBLOCK)) {\n-\t\tRTE_LOG(ERR, VHOST_CONFIG,\n-\t\t\t\t\"can't disable nonblocking on fd %d\\n\", fd);\n-\t\treturn -2;\n-\t}\n-\treturn 0;\n-}\n-\n-static void *\n-vhost_user_client_reconnect(void *arg __rte_unused)\n-{\n-\tint ret;\n-\tstruct vhost_user_reconnect *reconn, *next;\n-\n-\twhile (1) {\n-\t\tpthread_mutex_lock(&reconn_list.mutex);\n-\n-\t\t/*\n-\t\t * An equal implementation of TAILQ_FOREACH_SAFE,\n-\t\t * which does not exist on all platforms.\n-\t\t */\n-\t\tfor (reconn = TAILQ_FIRST(&reconn_list.head);\n-\t\t     reconn != NULL; reconn = next) {\n-\t\t\tnext = TAILQ_NEXT(reconn, next);\n-\n-\t\t\tret = vhost_user_connect_nonblock(reconn->fd,\n-\t\t\t\t\t\t(struct sockaddr *)&reconn->un,\n-\t\t\t\t\t\tsizeof(reconn->un));\n-\t\t\tif (ret == -2) {\n-\t\t\t\tclose(reconn->fd);\n-\t\t\t\tRTE_LOG(ERR, VHOST_CONFIG,\n-\t\t\t\t\t\"reconnection for fd %d failed\\n\",\n-\t\t\t\t\treconn->fd);\n-\t\t\t\tgoto remove_fd;\n-\t\t\t}\n-\t\t\tif (ret == -1)\n-\t\t\t\tcontinue;\n-\n-\t\t\tRTE_LOG(INFO, VHOST_CONFIG,\n-\t\t\t\t\"%s: connected\\n\", reconn->vsocket->path);\n-\t\t\tvhost_user_add_connection(reconn->fd, reconn->vsocket);\n-remove_fd:\n-\t\t\tTAILQ_REMOVE(&reconn_list.head, reconn, next);\n-\t\t\tfree(reconn);\n-\t\t}\n-\n-\t\tpthread_mutex_unlock(&reconn_list.mutex);\n-\t\tsleep(1);\n-\t}\n-\n-\treturn NULL;\n-}\n-\n-static int\n-vhost_user_reconnect_init(void)\n-{\n-\tint ret;\n-\n-\tret = pthread_mutex_init(&reconn_list.mutex, NULL);\n-\tif (ret < 0) {\n-\t\tRTE_LOG(ERR, VHOST_CONFIG, \"failed to initialize mutex\");\n-\t\treturn ret;\n-\t}\n-\tTAILQ_INIT(&reconn_list.head);\n-\n-\tret = rte_ctrl_thread_create(&reconn_tid, \"vhost_reconn\", NULL,\n-\t\t\t     vhost_user_client_reconnect, NULL);\n-\tif (ret != 0) {\n-\t\tRTE_LOG(ERR, VHOST_CONFIG, \"failed to create reconnect thread\");\n-\t\tif (pthread_mutex_destroy(&reconn_list.mutex)) {\n-\t\t\tRTE_LOG(ERR, VHOST_CONFIG,\n-\t\t\t\t\"failed to destroy reconnect mutex\");\n-\t\t}\n-\t}\n-\n-\treturn ret;\n-}\n-\n-static int\n-vhost_user_start_client(struct vhost_user_socket *vsocket)\n-{\n-\tint ret;\n-\tint fd = vsocket->socket_fd;\n-\tconst char *path = vsocket->path;\n-\tstruct vhost_user_reconnect *reconn;\n-\n-\tret = vhost_user_connect_nonblock(fd, (struct sockaddr *)&vsocket->un,\n-\t\t\t\t\t  sizeof(vsocket->un));\n-\tif (ret == 0) {\n-\t\tvhost_user_add_connection(fd, vsocket);\n-\t\treturn 0;\n-\t}\n-\n-\tRTE_LOG(WARNING, VHOST_CONFIG,\n-\t\t\"failed to connect to %s: %s\\n\",\n-\t\tpath, strerror(errno));\n-\n-\tif (ret == -2 || !vsocket->reconnect) {\n-\t\tclose(fd);\n-\t\treturn -1;\n-\t}\n-\n-\tRTE_LOG(INFO, VHOST_CONFIG, \"%s: reconnecting...\\n\", path);\n-\treconn = malloc(sizeof(*reconn));\n-\tif (reconn == NULL) {\n-\t\tRTE_LOG(ERR, VHOST_CONFIG,\n-\t\t\t\"failed to allocate memory for reconnect\\n\");\n-\t\tclose(fd);\n-\t\treturn -1;\n-\t}\n-\treconn->un = vsocket->un;\n-\treconn->fd = fd;\n-\treconn->vsocket = vsocket;\n-\tpthread_mutex_lock(&reconn_list.mutex);\n-\tTAILQ_INSERT_TAIL(&reconn_list.head, reconn, next);\n-\tpthread_mutex_unlock(&reconn_list.mutex);\n-\n-\treturn 0;\n-}\n-\n static struct vhost_user_socket *\n find_vhost_user_socket(const char *path)\n {\n@@ -952,30 +429,6 @@ rte_vhost_driver_register(const char *path, uint64_t flags)\n \treturn ret;\n }\n \n-static bool\n-vhost_user_remove_reconnect(struct vhost_user_socket *vsocket)\n-{\n-\tint found = false;\n-\tstruct vhost_user_reconnect *reconn, *next;\n-\n-\tpthread_mutex_lock(&reconn_list.mutex);\n-\n-\tfor (reconn = TAILQ_FIRST(&reconn_list.head);\n-\t     reconn != NULL; reconn = next) {\n-\t\tnext = TAILQ_NEXT(reconn, next);\n-\n-\t\tif (reconn->vsocket == vsocket) {\n-\t\t\tTAILQ_REMOVE(&reconn_list.head, reconn, next);\n-\t\t\tclose(reconn->fd);\n-\t\t\tfree(reconn);\n-\t\t\tfound = true;\n-\t\t\tbreak;\n-\t\t}\n-\t}\n-\tpthread_mutex_unlock(&reconn_list.mutex);\n-\treturn found;\n-}\n-\n /**\n  * Unregister the specified vhost socket\n  */\ndiff --git a/lib/librte_vhost/trans_af_unix.c b/lib/librte_vhost/trans_af_unix.c\nindex 3f0c308..89a5b7d 100644\n--- a/lib/librte_vhost/trans_af_unix.c\n+++ b/lib/librte_vhost/trans_af_unix.c\n@@ -4,7 +4,492 @@\n  * Copyright(c) 2019 Arrikto Inc.\n  */\n \n+#include <fcntl.h>\n+\n+#include <rte_log.h>\n+\n #include \"vhost.h\"\n+#include \"vhost_user.h\"\n+\n+#define MAX_VIRTIO_BACKLOG 128\n+\n+static void vhost_user_read_cb(int connfd, void *dat, int *remove);\n+\n+/*\n+ * return bytes# of read on success or negative val on failure. Update fdnum\n+ * with number of fds read.\n+ */\n+int\n+read_fd_message(int sockfd, char *buf, int buflen, int *fds, int max_fds,\n+\t\tint *fd_num)\n+{\n+\tstruct iovec iov;\n+\tstruct msghdr msgh;\n+\tchar control[CMSG_SPACE(max_fds * sizeof(int))];\n+\tstruct cmsghdr *cmsg;\n+\tint got_fds = 0;\n+\tint ret;\n+\n+\t*fd_num = 0;\n+\n+\tmemset(&msgh, 0, sizeof(msgh));\n+\tiov.iov_base = buf;\n+\tiov.iov_len  = buflen;\n+\n+\tmsgh.msg_iov = &iov;\n+\tmsgh.msg_iovlen = 1;\n+\tmsgh.msg_control = control;\n+\tmsgh.msg_controllen = sizeof(control);\n+\n+\tret = recvmsg(sockfd, &msgh, 0);\n+\tif (ret <= 0) {\n+\t\tRTE_LOG(ERR, VHOST_CONFIG, \"recvmsg failed\\n\");\n+\t\treturn ret;\n+\t}\n+\n+\tif (msgh.msg_flags & (MSG_TRUNC | MSG_CTRUNC)) {\n+\t\tRTE_LOG(ERR, VHOST_CONFIG, \"truncted msg\\n\");\n+\t\treturn -1;\n+\t}\n+\n+\tfor (cmsg = CMSG_FIRSTHDR(&msgh); cmsg != NULL;\n+\t\tcmsg = CMSG_NXTHDR(&msgh, cmsg)) {\n+\t\tif ((cmsg->cmsg_level == SOL_SOCKET) &&\n+\t\t\t(cmsg->cmsg_type == SCM_RIGHTS)) {\n+\t\t\tgot_fds = (cmsg->cmsg_len - CMSG_LEN(0)) / sizeof(int);\n+\t\t\t*fd_num = got_fds;\n+\t\t\tmemcpy(fds, CMSG_DATA(cmsg), got_fds * sizeof(int));\n+\t\t\tbreak;\n+\t\t}\n+\t}\n+\n+\t/* Clear out unused file descriptors */\n+\twhile (got_fds < max_fds)\n+\t\tfds[got_fds++] = -1;\n+\n+\treturn ret;\n+}\n+\n+int\n+send_fd_message(int sockfd, char *buf, int buflen, int *fds, int fd_num)\n+{\n+\tstruct iovec iov;\n+\tstruct msghdr msgh;\n+\tsize_t fdsize = fd_num * sizeof(int);\n+\tchar control[CMSG_SPACE(fdsize)];\n+\tstruct cmsghdr *cmsg;\n+\tint ret;\n+\n+\tmemset(&msgh, 0, sizeof(msgh));\n+\tiov.iov_base = buf;\n+\tiov.iov_len = buflen;\n+\n+\tmsgh.msg_iov = &iov;\n+\tmsgh.msg_iovlen = 1;\n+\n+\tif (fds && fd_num > 0) {\n+\t\tmsgh.msg_control = control;\n+\t\tmsgh.msg_controllen = sizeof(control);\n+\t\tcmsg = CMSG_FIRSTHDR(&msgh);\n+\t\tif (cmsg == NULL) {\n+\t\t\tRTE_LOG(ERR, VHOST_CONFIG, \"cmsg == NULL\\n\");\n+\t\t\terrno = EINVAL;\n+\t\t\treturn -1;\n+\t\t}\n+\t\tcmsg->cmsg_len = CMSG_LEN(fdsize);\n+\t\tcmsg->cmsg_level = SOL_SOCKET;\n+\t\tcmsg->cmsg_type = SCM_RIGHTS;\n+\t\tmemcpy(CMSG_DATA(cmsg), fds, fdsize);\n+\t} else {\n+\t\tmsgh.msg_control = NULL;\n+\t\tmsgh.msg_controllen = 0;\n+\t}\n+\n+\tdo {\n+\t\tret = sendmsg(sockfd, &msgh, MSG_NOSIGNAL);\n+\t} while (ret < 0 && errno == EINTR);\n+\n+\tif (ret < 0) {\n+\t\tRTE_LOG(ERR, VHOST_CONFIG,  \"sendmsg error\\n\");\n+\t\treturn ret;\n+\t}\n+\n+\treturn ret;\n+}\n+\n+static void\n+vhost_user_add_connection(int fd, struct vhost_user_socket *vsocket)\n+{\n+\tint vid;\n+\tsize_t size;\n+\tstruct vhost_user_connection *conn;\n+\tint ret;\n+\n+\tif (vsocket == NULL)\n+\t\treturn;\n+\n+\tconn = malloc(sizeof(*conn));\n+\tif (conn == NULL) {\n+\t\tclose(fd);\n+\t\treturn;\n+\t}\n+\n+\tvid = vhost_new_device();\n+\tif (vid == -1) {\n+\t\tgoto err;\n+\t}\n+\n+\tsize = strnlen(vsocket->path, PATH_MAX);\n+\tvhost_set_ifname(vid, vsocket->path, size);\n+\n+\tvhost_set_builtin_virtio_net(vid, vsocket->use_builtin_virtio_net);\n+\n+\tvhost_attach_vdpa_device(vid, vsocket->vdpa_dev_id);\n+\n+\tif (vsocket->dequeue_zero_copy)\n+\t\tvhost_enable_dequeue_zero_copy(vid);\n+\n+\tRTE_LOG(INFO, VHOST_CONFIG, \"new device, handle is %d\\n\", vid);\n+\n+\tif (vsocket->notify_ops->new_connection) {\n+\t\tret = vsocket->notify_ops->new_connection(vid);\n+\t\tif (ret < 0) {\n+\t\t\tRTE_LOG(ERR, VHOST_CONFIG,\n+\t\t\t\t\"failed to add vhost user connection with fd %d\\n\",\n+\t\t\t\tfd);\n+\t\t\tgoto err_cleanup;\n+\t\t}\n+\t}\n+\n+\tconn->connfd = fd;\n+\tconn->vsocket = vsocket;\n+\tconn->vid = vid;\n+\tret = fdset_add(&vhost_user.fdset, fd, vhost_user_read_cb,\n+\t\t\tNULL, conn);\n+\tif (ret < 0) {\n+\t\tRTE_LOG(ERR, VHOST_CONFIG,\n+\t\t\t\"failed to add fd %d into vhost server fdset\\n\",\n+\t\t\tfd);\n+\n+\t\tif (vsocket->notify_ops->destroy_connection)\n+\t\t\tvsocket->notify_ops->destroy_connection(conn->vid);\n+\n+\t\tgoto err_cleanup;\n+\t}\n+\n+\tpthread_mutex_lock(&vsocket->conn_mutex);\n+\tTAILQ_INSERT_TAIL(&vsocket->conn_list, conn, next);\n+\tpthread_mutex_unlock(&vsocket->conn_mutex);\n+\n+\tfdset_pipe_notify(&vhost_user.fdset);\n+\treturn;\n+\n+err_cleanup:\n+\tvhost_destroy_device(vid);\n+err:\n+\tfree(conn);\n+\tclose(fd);\n+}\n+\n+/* call back when there is new vhost-user connection from client  */\n+static void\n+vhost_user_server_new_connection(int fd, void *dat, int *remove __rte_unused)\n+{\n+\tstruct vhost_user_socket *vsocket = dat;\n+\n+\tfd = accept(fd, NULL, NULL);\n+\tif (fd < 0)\n+\t\treturn;\n+\n+\tRTE_LOG(INFO, VHOST_CONFIG, \"new vhost user connection is %d\\n\", fd);\n+\tvhost_user_add_connection(fd, vsocket);\n+}\n+\n+static void\n+vhost_user_read_cb(int connfd, void *dat, int *remove)\n+{\n+\tstruct vhost_user_connection *conn = dat;\n+\tstruct vhost_user_socket *vsocket = conn->vsocket;\n+\tint ret;\n+\n+\tret = vhost_user_msg_handler(conn->vid, connfd);\n+\tif (ret < 0) {\n+\t\tstruct virtio_net *dev = get_device(conn->vid);\n+\n+\t\tclose(connfd);\n+\t\t*remove = 1;\n+\n+\t\tif (dev)\n+\t\t\tvhost_destroy_device_notify(dev);\n+\n+\t\tif (vsocket->notify_ops->destroy_connection)\n+\t\t\tvsocket->notify_ops->destroy_connection(conn->vid);\n+\n+\t\tvhost_destroy_device(conn->vid);\n+\n+\t\tpthread_mutex_lock(&vsocket->conn_mutex);\n+\t\tTAILQ_REMOVE(&vsocket->conn_list, conn, next);\n+\t\tpthread_mutex_unlock(&vsocket->conn_mutex);\n+\n+\t\tfree(conn);\n+\n+\t\tif (vsocket->reconnect) {\n+\t\t\tcreate_unix_socket(vsocket);\n+\t\t\tvhost_user_start_client(vsocket);\n+\t\t}\n+\t}\n+}\n+\n+int\n+create_unix_socket(struct vhost_user_socket *vsocket)\n+{\n+\tint fd;\n+\tstruct sockaddr_un *un = &vsocket->un;\n+\n+\tfd = socket(AF_UNIX, SOCK_STREAM, 0);\n+\tif (fd < 0)\n+\t\treturn -1;\n+\tRTE_LOG(INFO, VHOST_CONFIG, \"vhost-user %s: socket created, fd: %d\\n\",\n+\t\tvsocket->is_server ? \"server\" : \"client\", fd);\n+\n+\tif (!vsocket->is_server && fcntl(fd, F_SETFL, O_NONBLOCK)) {\n+\t\tRTE_LOG(ERR, VHOST_CONFIG,\n+\t\t\t\"vhost-user: can't set nonblocking mode for socket, fd: \"\n+\t\t\t\"%d (%s)\\n\", fd, strerror(errno));\n+\t\tclose(fd);\n+\t\treturn -1;\n+\t}\n+\n+\tmemset(un, 0, sizeof(*un));\n+\tun->sun_family = AF_UNIX;\n+\tstrncpy(un->sun_path, vsocket->path, sizeof(un->sun_path));\n+\tun->sun_path[sizeof(un->sun_path) - 1] = '\\0';\n+\n+\tvsocket->socket_fd = fd;\n+\treturn 0;\n+}\n+\n+int\n+vhost_user_start_server(struct vhost_user_socket *vsocket)\n+{\n+\tint ret;\n+\tint fd = vsocket->socket_fd;\n+\tconst char *path = vsocket->path;\n+\n+\t/*\n+\t * bind () may fail if the socket file with the same name already\n+\t * exists. But the library obviously should not delete the file\n+\t * provided by the user, since we can not be sure that it is not\n+\t * being used by other applications. Moreover, many applications form\n+\t * socket names based on user input, which is prone to errors.\n+\t *\n+\t * The user must ensure that the socket does not exist before\n+\t * registering the vhost driver in server mode.\n+\t */\n+\tret = bind(fd, (struct sockaddr *)&vsocket->un, sizeof(vsocket->un));\n+\tif (ret < 0) {\n+\t\tRTE_LOG(ERR, VHOST_CONFIG,\n+\t\t\t\"failed to bind to %s: %s; remove it and try again\\n\",\n+\t\t\tpath, strerror(errno));\n+\t\tgoto err;\n+\t}\n+\tRTE_LOG(INFO, VHOST_CONFIG, \"bind to %s\\n\", path);\n+\n+\tret = listen(fd, MAX_VIRTIO_BACKLOG);\n+\tif (ret < 0)\n+\t\tgoto err;\n+\n+\tret = fdset_add(&vhost_user.fdset, fd, vhost_user_server_new_connection,\n+\t\t  NULL, vsocket);\n+\tif (ret < 0) {\n+\t\tRTE_LOG(ERR, VHOST_CONFIG,\n+\t\t\t\"failed to add listen fd %d to vhost server fdset\\n\",\n+\t\t\tfd);\n+\t\tgoto err;\n+\t}\n+\n+\treturn 0;\n+\n+err:\n+\tclose(fd);\n+\treturn -1;\n+}\n+\n+struct vhost_user_reconnect {\n+\tstruct sockaddr_un un;\n+\tint fd;\n+\tstruct vhost_user_socket *vsocket;\n+\n+\tTAILQ_ENTRY(vhost_user_reconnect) next;\n+};\n+\n+TAILQ_HEAD(vhost_user_reconnect_tailq_list, vhost_user_reconnect);\n+struct vhost_user_reconnect_list {\n+\tstruct vhost_user_reconnect_tailq_list head;\n+\tpthread_mutex_t mutex;\n+};\n+\n+static struct vhost_user_reconnect_list reconn_list;\n+pthread_t reconn_tid;\n+\n+static int\n+vhost_user_connect_nonblock(int fd, struct sockaddr *un, size_t sz)\n+{\n+\tint ret, flags;\n+\n+\tret = connect(fd, un, sz);\n+\tif (ret < 0 && errno != EISCONN)\n+\t\treturn -1;\n+\n+\tflags = fcntl(fd, F_GETFL, 0);\n+\tif (flags < 0) {\n+\t\tRTE_LOG(ERR, VHOST_CONFIG,\n+\t\t\t\"can't get flags for connfd %d\\n\", fd);\n+\t\treturn -2;\n+\t}\n+\tif ((flags & O_NONBLOCK) && fcntl(fd, F_SETFL, flags & ~O_NONBLOCK)) {\n+\t\tRTE_LOG(ERR, VHOST_CONFIG,\n+\t\t\t\t\"can't disable nonblocking on fd %d\\n\", fd);\n+\t\treturn -2;\n+\t}\n+\treturn 0;\n+}\n+\n+static void *\n+vhost_user_client_reconnect(void *arg __rte_unused)\n+{\n+\tint ret;\n+\tstruct vhost_user_reconnect *reconn, *next;\n+\n+\twhile (1) {\n+\t\tpthread_mutex_lock(&reconn_list.mutex);\n+\n+\t\t/*\n+\t\t * An equal implementation of TAILQ_FOREACH_SAFE,\n+\t\t * which does not exist on all platforms.\n+\t\t */\n+\t\tfor (reconn = TAILQ_FIRST(&reconn_list.head);\n+\t\t     reconn != NULL; reconn = next) {\n+\t\t\tnext = TAILQ_NEXT(reconn, next);\n+\n+\t\t\tret = vhost_user_connect_nonblock(reconn->fd,\n+\t\t\t\t\t\t(struct sockaddr *)&reconn->un,\n+\t\t\t\t\t\tsizeof(reconn->un));\n+\t\t\tif (ret == -2) {\n+\t\t\t\tclose(reconn->fd);\n+\t\t\t\tRTE_LOG(ERR, VHOST_CONFIG,\n+\t\t\t\t\t\"reconnection for fd %d failed\\n\",\n+\t\t\t\t\treconn->fd);\n+\t\t\t\tgoto remove_fd;\n+\t\t\t}\n+\t\t\tif (ret == -1)\n+\t\t\t\tcontinue;\n+\n+\t\t\tRTE_LOG(INFO, VHOST_CONFIG,\n+\t\t\t\t\"%s: connected\\n\", reconn->vsocket->path);\n+\t\t\tvhost_user_add_connection(reconn->fd, reconn->vsocket);\n+remove_fd:\n+\t\t\tTAILQ_REMOVE(&reconn_list.head, reconn, next);\n+\t\t\tfree(reconn);\n+\t\t}\n+\n+\t\tpthread_mutex_unlock(&reconn_list.mutex);\n+\t\tsleep(1);\n+\t}\n+\n+\treturn NULL;\n+}\n+\n+int\n+vhost_user_reconnect_init(void)\n+{\n+\tint ret;\n+\n+\tret = pthread_mutex_init(&reconn_list.mutex, NULL);\n+\tif (ret < 0) {\n+\t\tRTE_LOG(ERR, VHOST_CONFIG, \"failed to initialize mutex\");\n+\t\treturn ret;\n+\t}\n+\tTAILQ_INIT(&reconn_list.head);\n+\n+\tret = rte_ctrl_thread_create(&reconn_tid, \"vhost_reconn\", NULL,\n+\t\t\t     vhost_user_client_reconnect, NULL);\n+\tif (ret != 0) {\n+\t\tRTE_LOG(ERR, VHOST_CONFIG, \"failed to create reconnect thread\");\n+\t\tif (pthread_mutex_destroy(&reconn_list.mutex)) {\n+\t\t\tRTE_LOG(ERR, VHOST_CONFIG,\n+\t\t\t\t\"failed to destroy reconnect mutex\");\n+\t\t}\n+\t}\n+\n+\treturn ret;\n+}\n+\n+int\n+vhost_user_start_client(struct vhost_user_socket *vsocket)\n+{\n+\tint ret;\n+\tint fd = vsocket->socket_fd;\n+\tconst char *path = vsocket->path;\n+\tstruct vhost_user_reconnect *reconn;\n+\n+\tret = vhost_user_connect_nonblock(fd, (struct sockaddr *)&vsocket->un,\n+\t\t\t\t\t  sizeof(vsocket->un));\n+\tif (ret == 0) {\n+\t\tvhost_user_add_connection(fd, vsocket);\n+\t\treturn 0;\n+\t}\n+\n+\tRTE_LOG(WARNING, VHOST_CONFIG,\n+\t\t\"failed to connect to %s: %s\\n\",\n+\t\tpath, strerror(errno));\n+\n+\tif (ret == -2 || !vsocket->reconnect) {\n+\t\tclose(fd);\n+\t\treturn -1;\n+\t}\n+\n+\tRTE_LOG(INFO, VHOST_CONFIG, \"%s: reconnecting...\\n\", path);\n+\treconn = malloc(sizeof(*reconn));\n+\tif (reconn == NULL) {\n+\t\tRTE_LOG(ERR, VHOST_CONFIG,\n+\t\t\t\"failed to allocate memory for reconnect\\n\");\n+\t\tclose(fd);\n+\t\treturn -1;\n+\t}\n+\treconn->un = vsocket->un;\n+\treconn->fd = fd;\n+\treconn->vsocket = vsocket;\n+\tpthread_mutex_lock(&reconn_list.mutex);\n+\tTAILQ_INSERT_TAIL(&reconn_list.head, reconn, next);\n+\tpthread_mutex_unlock(&reconn_list.mutex);\n+\n+\treturn 0;\n+}\n+\n+bool\n+vhost_user_remove_reconnect(struct vhost_user_socket *vsocket)\n+{\n+\tint found = false;\n+\tstruct vhost_user_reconnect *reconn, *next;\n+\n+\tpthread_mutex_lock(&reconn_list.mutex);\n+\n+\tfor (reconn = TAILQ_FIRST(&reconn_list.head);\n+\t     reconn != NULL; reconn = next) {\n+\t\tnext = TAILQ_NEXT(reconn, next);\n+\n+\t\tif (reconn->vsocket == vsocket) {\n+\t\t\tTAILQ_REMOVE(&reconn_list.head, reconn, next);\n+\t\t\tclose(reconn->fd);\n+\t\t\tfree(reconn);\n+\t\t\tfound = true;\n+\t\t\tbreak;\n+\t\t}\n+\t}\n+\tpthread_mutex_unlock(&reconn_list.mutex);\n+\treturn found;\n+}\n \n static int\n af_unix_vring_call(struct virtio_net *dev __rte_unused,\ndiff --git a/lib/librte_vhost/vhost.h b/lib/librte_vhost/vhost.h\nindex 077f213..c363369 100644\n--- a/lib/librte_vhost/vhost.h\n+++ b/lib/librte_vhost/vhost.h\n@@ -5,6 +5,7 @@\n #ifndef _VHOST_NET_CDEV_H_\n #define _VHOST_NET_CDEV_H_\n #include <stdint.h>\n+#include <stdbool.h>\n #include <stdio.h>\n #include <stdbool.h>\n #include <sys/types.h>\n@@ -13,13 +14,16 @@\n #include <linux/vhost.h>\n #include <linux/virtio_net.h>\n #include <sys/socket.h>\n+#include <sys/un.h> /* TODO remove when trans_af_unix.c refactoring is done */\n #include <linux/if.h>\n+#include <pthread.h>\n \n #include <rte_log.h>\n #include <rte_ether.h>\n #include <rte_rwlock.h>\n #include <rte_malloc.h>\n \n+#include \"fd_man.h\"\n #include \"rte_vhost.h\"\n #include \"rte_vdpa.h\"\n \n@@ -360,6 +364,78 @@ struct virtio_net {\n \tstruct rte_vhost_user_extern_ops extern_ops;\n } __rte_cache_aligned;\n \n+/* The vhost_user, vhost_user_socket, vhost_user_connection, and reconnect\n+ * declarations are temporary measures for moving AF_UNIX code into\n+ * trans_af_unix.c.  They will be cleaned up as socket.c is untangled from\n+ * trans_af_unix.c.\n+ */\n+TAILQ_HEAD(vhost_user_connection_list, vhost_user_connection);\n+\n+/*\n+ * Every time rte_vhost_driver_register() is invoked, an associated\n+ * vhost_user_socket struct will be created.\n+ */\n+struct vhost_user_socket {\n+\tstruct vhost_user_connection_list conn_list;\n+\tpthread_mutex_t conn_mutex;\n+\tchar *path;\n+\tint socket_fd;\n+\tstruct sockaddr_un un;\n+\tbool is_server;\n+\tbool reconnect;\n+\tbool dequeue_zero_copy;\n+\tbool iommu_support;\n+\tbool use_builtin_virtio_net;\n+\n+\t/*\n+\t * The \"supported_features\" indicates the feature bits the\n+\t * vhost driver supports. The \"features\" indicates the feature\n+\t * bits after the rte_vhost_driver_features_disable/enable().\n+\t * It is also the final feature bits used for vhost-user\n+\t * features negotiation.\n+\t */\n+\tuint64_t supported_features;\n+\tuint64_t features;\n+\n+\tuint64_t protocol_features;\n+\n+\t/*\n+\t * Device id to identify a specific backend device.\n+\t * It's set to -1 for the default software implementation.\n+\t * If valid, one socket can have 1 connection only.\n+\t */\n+\tint vdpa_dev_id;\n+\n+\tstruct vhost_device_ops const *notify_ops;\n+};\n+\n+struct vhost_user_connection {\n+\tstruct vhost_user_socket *vsocket;\n+\tint connfd;\n+\tint vid;\n+\n+\tTAILQ_ENTRY(vhost_user_connection) next;\n+};\n+\n+#define MAX_VHOST_SOCKET 1024\n+struct vhost_user {\n+\tstruct vhost_user_socket *vsockets[MAX_VHOST_SOCKET];\n+\tstruct fdset fdset;\n+\tint vsocket_cnt;\n+\tpthread_mutex_t mutex;\n+};\n+\n+extern struct vhost_user vhost_user;\n+\n+int create_unix_socket(struct vhost_user_socket *vsocket);\n+int vhost_user_start_server(struct vhost_user_socket *vsocket);\n+int vhost_user_start_client(struct vhost_user_socket *vsocket);\n+\n+extern pthread_t reconn_tid;\n+\n+int vhost_user_reconnect_init(void);\n+bool vhost_user_remove_reconnect(struct vhost_user_socket *vsocket);\n+\n static __rte_always_inline bool\n vq_is_packed(struct virtio_net *dev)\n {\n",
    "prefixes": [
        "02/28"
    ]
}