get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

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

{
    "id": 54958,
    "url": "http://patches.dpdk.org/api/patches/54958/?format=api",
    "web_url": "http://patches.dpdk.org/project/dpdk/patch/1560957293-17294-5-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-5-git-send-email-ndragazis@arrikto.com>",
    "list_archive_url": "https://inbox.dpdk.org/dev/1560957293-17294-5-git-send-email-ndragazis@arrikto.com",
    "date": "2019-06-19T15:14:29",
    "name": "[04/28] vhost: move socket fd and un sockaddr",
    "commit_ref": null,
    "pull_url": null,
    "state": "rfc",
    "archived": true,
    "hash": "c21d249765fc72d7b49c69619dc31bb38010e8ea",
    "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-5-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/54958/comments/",
    "check": "fail",
    "checks": "http://patches.dpdk.org/api/patches/54958/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 DDA111C3A3;\n\tWed, 19 Jun 2019 17:15:47 +0200 (CEST)",
            "from mx0.arrikto.com (mx0.arrikto.com [212.71.252.59])\n\tby dpdk.org (Postfix) with ESMTP id ECC6E1C388\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 BC560182008;\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 2350B32C;\n\tWed, 19 Jun 2019 18:15:37 +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:29 +0300",
        "Message-Id": "<1560957293-17294-5-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 04/28] vhost: move socket fd and un sockaddr",
        "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 file descriptor and AF_UNIX sockaddr are specific to the\nAF_UNIX transport, so move them into trans_af_unix.c.\n\nIn order to do this, we need to begin defining the vhost_transport_ops\ninterface that will allow librte_vhost to support multiple transports.\nThis patch adds socket_init() and socket_cleanup() to\nvhost_transport_ops.\n\nSigned-off-by: Nikos Dragazis <ndragazis@arrikto.com>\nSigned-off-by: Stefan Hajnoczi <stefanha@redhat.com>\n---\n lib/librte_vhost/socket.c        | 11 ++------\n lib/librte_vhost/trans_af_unix.c | 55 ++++++++++++++++++++++++++++++++--------\n lib/librte_vhost/vhost.h         | 30 ++++++++++++++++++----\n 3 files changed, 72 insertions(+), 24 deletions(-)",
    "diff": "diff --git a/lib/librte_vhost/socket.c b/lib/librte_vhost/socket.c\nindex 60d3546..3b5608c 100644\n--- a/lib/librte_vhost/socket.c\n+++ b/lib/librte_vhost/socket.c\n@@ -408,7 +408,7 @@ rte_vhost_driver_register(const char *path, uint64_t flags)\n \t} else {\n \t\tvsocket->is_server = true;\n \t}\n-\tret = create_unix_socket(vsocket);\n+\tret = trans_ops->socket_init(vsocket, flags);\n \tif (ret < 0) {\n \t\tgoto out_mutex;\n \t}\n@@ -480,14 +480,7 @@ rte_vhost_driver_unregister(const char *path)\n \t\t\t}\n \t\t\tpthread_mutex_unlock(&vsocket->conn_mutex);\n \n-\t\t\tif (vsocket->is_server) {\n-\t\t\t\tfdset_del(&vhost_user.fdset,\n-\t\t\t\t\t\tvsocket->socket_fd);\n-\t\t\t\tclose(vsocket->socket_fd);\n-\t\t\t\tunlink(path);\n-\t\t\t} else if (vsocket->reconnect) {\n-\t\t\t\tvhost_user_remove_reconnect(vsocket);\n-\t\t\t}\n+\t\t\tvsocket->trans_ops->socket_cleanup(vsocket);\n \n \t\t\tpthread_mutex_destroy(&vsocket->conn_mutex);\n \t\t\tvhost_user_socket_mem_free(vsocket);\ndiff --git a/lib/librte_vhost/trans_af_unix.c b/lib/librte_vhost/trans_af_unix.c\nindex 4de2579..f23bb9c 100644\n--- a/lib/librte_vhost/trans_af_unix.c\n+++ b/lib/librte_vhost/trans_af_unix.c\n@@ -4,6 +4,8 @@\n  * Copyright(c) 2019 Arrikto Inc.\n  */\n \n+#include <sys/socket.h>\n+#include <sys/un.h>\n #include <fcntl.h>\n \n #include <rte_log.h>\n@@ -15,8 +17,11 @@\n \n struct af_unix_socket {\n \tstruct vhost_user_socket socket; /* must be the first field! */\n+\tint socket_fd;\n+\tstruct sockaddr_un un;\n };\n \n+static int create_unix_socket(struct vhost_user_socket *vsocket);\n static void vhost_user_read_cb(int connfd, void *dat, int *remove);\n \n /*\n@@ -244,11 +249,13 @@ vhost_user_read_cb(int connfd, void *dat, int *remove)\n \t}\n }\n \n-int\n+static int\n create_unix_socket(struct vhost_user_socket *vsocket)\n {\n+\tstruct af_unix_socket *af_vsocket =\n+\t\tcontainer_of(vsocket, struct af_unix_socket, socket);\n \tint fd;\n-\tstruct sockaddr_un *un = &vsocket->un;\n+\tstruct sockaddr_un *un = &af_vsocket->un;\n \n \tfd = socket(AF_UNIX, SOCK_STREAM, 0);\n \tif (fd < 0)\n@@ -269,15 +276,17 @@ create_unix_socket(struct vhost_user_socket *vsocket)\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+\taf_vsocket->socket_fd = fd;\n \treturn 0;\n }\n \n int\n vhost_user_start_server(struct vhost_user_socket *vsocket)\n {\n+\tstruct af_unix_socket *af_vsocket =\n+\t\tcontainer_of(vsocket, struct af_unix_socket, socket);\n \tint ret;\n-\tint fd = vsocket->socket_fd;\n+\tint fd = af_vsocket->socket_fd;\n \tconst char *path = vsocket->path;\n \n \t/*\n@@ -290,7 +299,7 @@ vhost_user_start_server(struct vhost_user_socket *vsocket)\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+\tret = bind(fd, (struct sockaddr *)&af_vsocket->un, sizeof(af_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@@ -432,13 +441,15 @@ vhost_user_reconnect_init(void)\n int\n vhost_user_start_client(struct vhost_user_socket *vsocket)\n {\n+\tstruct af_unix_socket *af_vsocket =\n+\t\tcontainer_of(vsocket, struct af_unix_socket, socket);\n \tint ret;\n-\tint fd = vsocket->socket_fd;\n+\tint fd = af_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+\tret = vhost_user_connect_nonblock(fd, (struct sockaddr *)&af_vsocket->un,\n+\t\t\t\t\t  sizeof(af_vsocket->un));\n \tif (ret == 0) {\n \t\tvhost_user_add_connection(fd, vsocket);\n \t\treturn 0;\n@@ -461,7 +472,7 @@ vhost_user_start_client(struct vhost_user_socket *vsocket)\n \t\tclose(fd);\n \t\treturn -1;\n \t}\n-\treconn->un = vsocket->un;\n+\treconn->un = af_vsocket->un;\n \treconn->fd = fd;\n \treconn->vsocket = vsocket;\n \tpthread_mutex_lock(&reconn_list.mutex);\n@@ -471,7 +482,7 @@ vhost_user_start_client(struct vhost_user_socket *vsocket)\n \treturn 0;\n }\n \n-bool\n+static bool\n vhost_user_remove_reconnect(struct vhost_user_socket *vsocket)\n {\n \tint found = false;\n@@ -496,6 +507,28 @@ vhost_user_remove_reconnect(struct vhost_user_socket *vsocket)\n }\n \n static int\n+af_unix_socket_init(struct vhost_user_socket *vsocket,\n+\t\t    uint64_t flags __rte_unused)\n+{\n+\treturn create_unix_socket(vsocket);\n+}\n+\n+static void\n+af_unix_socket_cleanup(struct vhost_user_socket *vsocket)\n+{\n+\tstruct af_unix_socket *af_vsocket =\n+\t\tcontainer_of(vsocket, struct af_unix_socket, socket);\n+\n+\tif (vsocket->is_server) {\n+\t\tfdset_del(&vhost_user.fdset, af_vsocket->socket_fd);\n+\t\tclose(af_vsocket->socket_fd);\n+\t\tunlink(vsocket->path);\n+\t} else if (vsocket->reconnect) {\n+\t\tvhost_user_remove_reconnect(vsocket);\n+\t}\n+}\n+\n+static int\n af_unix_vring_call(struct virtio_net *dev __rte_unused,\n \t\t   struct vhost_virtqueue *vq)\n {\n@@ -506,5 +539,7 @@ af_unix_vring_call(struct virtio_net *dev __rte_unused,\n \n const struct vhost_transport_ops af_unix_trans_ops = {\n \t.socket_size = sizeof(struct af_unix_socket),\n+\t.socket_init = af_unix_socket_init,\n+\t.socket_cleanup = af_unix_socket_cleanup,\n \t.vring_call = af_unix_vring_call,\n };\ndiff --git a/lib/librte_vhost/vhost.h b/lib/librte_vhost/vhost.h\nindex 9615392..40b5c25 100644\n--- a/lib/librte_vhost/vhost.h\n+++ b/lib/librte_vhost/vhost.h\n@@ -14,7 +14,6 @@\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@@ -291,6 +290,7 @@ struct guest_page {\n };\n \n struct virtio_net;\n+struct vhost_user_socket;\n \n /**\n  * A structure containing function pointers for transport-specific operations.\n@@ -300,6 +300,30 @@ struct vhost_transport_ops {\n \tsize_t socket_size;\n \n \t/**\n+\t * Initialize a vhost-user socket that is being created by\n+\t * rte_vhost_driver_register().  This function checks that the flags\n+\t * are valid but does not establish a vhost-user connection.\n+\t *\n+\t * @param vsocket\n+\t *  new socket\n+\t * @param flags\n+\t *  flags argument from rte_vhost_driver_register()\n+\t * @return\n+\t *  0 on success, -1 on failure\n+\t */\n+\tint (*socket_init)(struct vhost_user_socket *vsocket, uint64_t flags);\n+\n+\t/**\n+\t * Free resources associated with a socket, including any established\n+\t * connections.  This function calls vhost_destroy_device() to destroy\n+\t * established connections for this socket.\n+\t *\n+\t * @param vsocket\n+\t *  vhost socket\n+\t */\n+\tvoid (*socket_cleanup)(struct vhost_user_socket *vsocket);\n+\n+\t/**\n \t * Notify the guest that used descriptors have been added to the vring.\n \t * The VRING_AVAIL_F_NO_INTERRUPT flag and event idx have already been checked\n \t * so this function just needs to perform the notification.\n@@ -387,8 +411,6 @@ 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@@ -436,14 +458,12 @@ struct vhost_user {\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",
    "prefixes": [
        "04/28"
    ]
}