get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

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

{
    "id": 54966,
    "url": "http://patches.dpdk.org/api/patches/54966/?format=api",
    "web_url": "http://patches.dpdk.org/project/dpdk/patch/1560957293-17294-13-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-13-git-send-email-ndragazis@arrikto.com>",
    "list_archive_url": "https://inbox.dpdk.org/dev/1560957293-17294-13-git-send-email-ndragazis@arrikto.com",
    "date": "2019-06-19T15:14:37",
    "name": "[12/28] vhost: move slave request fd and lock",
    "commit_ref": null,
    "pull_url": null,
    "state": "rfc",
    "archived": true,
    "hash": "9946a6ecfcd8239071496a8e152351a85f43dc87",
    "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-13-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/54966/comments/",
    "check": "fail",
    "checks": "http://patches.dpdk.org/api/patches/54966/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 CDEDF1C3ED;\n\tWed, 19 Jun 2019 17:16:13 +0200 (CEST)",
            "from mx0.arrikto.com (mx0.arrikto.com [212.71.252.59])\n\tby dpdk.org (Postfix) with ESMTP id 225361C389\n\tfor <dev@dpdk.org>; Wed, 19 Jun 2019 17:15:41 +0200 (CEST)",
            "from troi.prod.arr (mail.arr [10.99.0.5])\n\tby mx0.arrikto.com (Postfix) with ESMTP id E6C1C18200C;\n\tWed, 19 Jun 2019 18:15:40 +0300 (EEST)",
            "from localhost.localdomain (unknown [10.89.50.133])\n\tby troi.prod.arr (Postfix) with ESMTPSA id 34F492B2;\n\tWed, 19 Jun 2019 18:15:40 +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:37 +0300",
        "Message-Id": "<1560957293-17294-13-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 12/28] vhost: move slave request fd and lock",
        "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 slave request file descriptor is specific to the AF_UNIX transport.\nMove this field along with its spinlock out of struct virtio_net and\ninto the trans_af_unix.c private struct vhost_user_connection struct.\nThis implies that we also had to move the associated functions\nsend_vhost_slave_message() and process_slave_message_reply() out of\nvhost_user.c and into trans_af_unix.c. We also moved the spinlock\ninitialization out of vhost_new_connection() and into trans_af_unix.c.\n\nThis change will allow future transports to implement the slave request\nfd without relying on socket I/O.\n\nSigned-off-by: Nikos Dragazis <ndragazis@arrikto.com>\nSigned-off-by: Stefan Hajnoczi <stefanha@redhat.com>\n---\n lib/librte_vhost/trans_af_unix.c | 87 +++++++++++++++++++++++++++++++++++++++-\n lib/librte_vhost/vhost.c         |  4 +-\n lib/librte_vhost/vhost.h         | 41 +++++++++++++++++--\n lib/librte_vhost/vhost_user.c    | 67 ++++---------------------------\n 4 files changed, 132 insertions(+), 67 deletions(-)",
    "diff": "diff --git a/lib/librte_vhost/trans_af_unix.c b/lib/librte_vhost/trans_af_unix.c\nindex c0ba8df..5f9ef5a 100644\n--- a/lib/librte_vhost/trans_af_unix.c\n+++ b/lib/librte_vhost/trans_af_unix.c\n@@ -29,6 +29,8 @@ struct vhost_user_connection {\n \tstruct virtio_net device; /* must be the first field! */\n \tstruct vhost_user_socket *vsocket;\n \tint connfd;\n+\tint slave_req_fd;\n+\trte_spinlock_t slave_req_lock;\n \n \tTAILQ_ENTRY(vhost_user_connection) next;\n };\n@@ -41,6 +43,7 @@ struct af_unix_socket {\n \tstruct sockaddr_un un;\n };\n \n+int read_vhost_message(int sockfd, struct VhostUserMsg *msg);\n static int create_unix_socket(struct vhost_user_socket *vsocket);\n static int vhost_user_start_server(struct vhost_user_socket *vsocket);\n static int vhost_user_start_client(struct vhost_user_socket *vsocket);\n@@ -161,8 +164,71 @@ af_unix_send_reply(struct virtio_net *dev, struct VhostUserMsg *msg)\n static int\n af_unix_send_slave_req(struct virtio_net *dev, struct VhostUserMsg *msg)\n {\n-\treturn send_fd_message(dev->slave_req_fd, msg,\n-\t\t\t       VHOST_USER_HDR_SIZE + msg->size, msg->fds, msg->fd_num);\n+\tstruct vhost_user_connection *conn =\n+\t\tcontainer_of(dev, struct vhost_user_connection, device);\n+\tint ret;\n+\n+\tif (msg->flags & VHOST_USER_NEED_REPLY)\n+\t\trte_spinlock_lock(&conn->slave_req_lock);\n+\n+\tret = send_fd_message(conn->slave_req_fd, msg,\n+\t\t\tVHOST_USER_HDR_SIZE + msg->size, msg->fds, msg->fd_num);\n+\n+\tif (ret < 0 && (msg->flags & VHOST_USER_NEED_REPLY))\n+\t\trte_spinlock_unlock(&conn->slave_req_lock);\n+\n+\treturn ret;\n+}\n+\n+static int\n+af_unix_process_slave_message_reply(struct virtio_net *dev,\n+\t\t\t\t    const struct VhostUserMsg *msg)\n+{\n+\tstruct vhost_user_connection *conn =\n+\t\tcontainer_of(dev, struct vhost_user_connection, device);\n+\tstruct VhostUserMsg msg_reply;\n+\tint ret;\n+\n+\tif ((msg->flags & VHOST_USER_NEED_REPLY) == 0)\n+\t\treturn 0;\n+\n+\tif (read_vhost_message(conn->slave_req_fd, &msg_reply) < 0) {\n+\t\tret = -1;\n+\t\tgoto out;\n+\t}\n+\n+\tif (msg_reply.request.slave != msg->request.slave) {\n+\t\tRTE_LOG(ERR, VHOST_CONFIG,\n+\t\t\t\"Received unexpected msg type (%u), expected %u\\n\",\n+\t\t\tmsg_reply.request.slave, msg->request.slave);\n+\t\tret = -1;\n+\t\tgoto out;\n+\t}\n+\n+\tret = msg_reply.payload.u64 ? -1 : 0;\n+\n+out:\n+\trte_spinlock_unlock(&conn->slave_req_lock);\n+\treturn ret;\n+}\n+\n+static int\n+af_unix_set_slave_req_fd(struct virtio_net *dev, struct VhostUserMsg *msg)\n+{\n+\tstruct vhost_user_connection *conn =\n+\t\tcontainer_of(dev, struct vhost_user_connection, device);\n+\tint fd = msg->fds[0];\n+\n+\tif (fd < 0) {\n+\t\tRTE_LOG(ERR, VHOST_CONFIG,\n+\t\t\t\t\"Invalid file descriptor for slave channel (%d)\\n\",\n+\t\t\t\tfd);\n+\t\treturn -1;\n+\t}\n+\n+\tconn->slave_req_fd = fd;\n+\n+\treturn 0;\n }\n \n static void\n@@ -185,7 +251,9 @@ vhost_user_add_connection(int fd, struct vhost_user_socket *vsocket)\n \n \tconn = container_of(dev, struct vhost_user_connection, device);\n \tconn->connfd = fd;\n+\tconn->slave_req_fd = -1;\n \tconn->vsocket = vsocket;\n+\trte_spinlock_init(&conn->slave_req_lock);\n \n \tsize = strnlen(vsocket->path, PATH_MAX);\n \tvhost_set_ifname(dev->vid, vsocket->path, size);\n@@ -682,6 +750,18 @@ af_unix_socket_start(struct vhost_user_socket *vsocket)\n \t\treturn vhost_user_start_client(vsocket);\n }\n \n+static void\n+af_unix_cleanup_device(struct virtio_net *dev, int destroy __rte_unused)\n+{\n+\tstruct vhost_user_connection *conn =\n+\t\tcontainer_of(dev, struct vhost_user_connection, device);\n+\n+\tif (conn->slave_req_fd >= 0) {\n+\t\tclose(conn->slave_req_fd);\n+\t\tconn->slave_req_fd = -1;\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@@ -697,7 +777,10 @@ const struct vhost_transport_ops af_unix_trans_ops = {\n \t.socket_init = af_unix_socket_init,\n \t.socket_cleanup = af_unix_socket_cleanup,\n \t.socket_start = af_unix_socket_start,\n+\t.cleanup_device = af_unix_cleanup_device,\n \t.vring_call = af_unix_vring_call,\n \t.send_reply = af_unix_send_reply,\n \t.send_slave_req = af_unix_send_slave_req,\n+\t.process_slave_message_reply = af_unix_process_slave_message_reply,\n+\t.set_slave_req_fd = af_unix_set_slave_req_fd,\n };\ndiff --git a/lib/librte_vhost/vhost.c b/lib/librte_vhost/vhost.c\nindex 0fdc54f..5b16390 100644\n--- a/lib/librte_vhost/vhost.c\n+++ b/lib/librte_vhost/vhost.c\n@@ -256,6 +256,8 @@ cleanup_device(struct virtio_net *dev, int destroy)\n \n \tfor (i = 0; i < dev->nr_vring; i++)\n \t\tcleanup_vq(dev->virtqueue[i], destroy);\n+\n+\tdev->trans_ops->cleanup_device(dev, destroy);\n }\n \n void\n@@ -508,11 +510,9 @@ vhost_new_device(const struct vhost_transport_ops *trans_ops)\n \tvhost_devices[i] = dev;\n \tdev->vid = i;\n \tdev->flags = VIRTIO_DEV_BUILTIN_VIRTIO_NET;\n-\tdev->slave_req_fd = -1;\n \tdev->trans_ops = trans_ops;\n \tdev->vdpa_dev_id = -1;\n \tdev->postcopy_ufd = -1;\n-\trte_spinlock_init(&dev->slave_req_lock);\n \n \treturn dev;\n }\ndiff --git a/lib/librte_vhost/vhost.h b/lib/librte_vhost/vhost.h\nindex b20773c..2213fbe 100644\n--- a/lib/librte_vhost/vhost.h\n+++ b/lib/librte_vhost/vhost.h\n@@ -340,6 +340,16 @@ struct vhost_transport_ops {\n \tint (*socket_start)(struct vhost_user_socket *vsocket);\n \n \t/**\n+\t* Free resources associated with this device.\n+\t*\n+\t* @param dev\n+\t*  vhost device\n+\t* @param destroy\n+\t*  0 on device reset, 1 on full cleanup.\n+\t*/\n+\tvoid (*cleanup_device)(struct virtio_net *dev, int destroy);\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@@ -377,6 +387,34 @@ struct vhost_transport_ops {\n \t */\n \tint (*send_slave_req)(struct virtio_net *dev,\n \t\t\t      struct VhostUserMsg *req);\n+\n+\t/**\n+\t * Process the master's reply on a slave request.\n+\t *\n+\t * @param dev\n+\t *  vhost device\n+\t * @param msg\n+\t *  slave request message\n+\t * @return\n+\t *  0 on success, -1 on failure\n+\t */\n+\tint (*process_slave_message_reply)(struct virtio_net *dev,\n+\t\t\t\t\t   const struct VhostUserMsg *msg);\n+\n+\t/**\n+\t * Process VHOST_USER_SET_SLAVE_REQ_FD message.  After this function\n+\t * succeeds send_slave_req() may be called to submit requests to the\n+\t * master.\n+\t *\n+\t * @param dev\n+\t *  vhost device\n+\t * @param msg\n+\t *  message\n+\t * @return\n+\t *  0 on success, -1 on failure\n+\t */\n+\tint (*set_slave_req_fd)(struct virtio_net *dev,\n+\t\t\t\tstruct VhostUserMsg *msg);\n };\n \n /** The traditional AF_UNIX vhost-user protocol transport. */\n@@ -419,9 +457,6 @@ struct virtio_net {\n \tuint32_t\t\tmax_guest_pages;\n \tstruct guest_page       *guest_pages;\n \n-\tint\t\t\tslave_req_fd;\n-\trte_spinlock_t\t\tslave_req_lock;\n-\n \tint\t\t\tpostcopy_ufd;\n \tint\t\t\tpostcopy_listening;\n \ndiff --git a/lib/librte_vhost/vhost_user.c b/lib/librte_vhost/vhost_user.c\nindex 5c12435..a4dcba1 100644\n--- a/lib/librte_vhost/vhost_user.c\n+++ b/lib/librte_vhost/vhost_user.c\n@@ -160,11 +160,6 @@ vhost_backend_cleanup(struct virtio_net *dev)\n \t\tdev->log_addr = 0;\n \t}\n \n-\tif (dev->slave_req_fd >= 0) {\n-\t\tclose(dev->slave_req_fd);\n-\t\tdev->slave_req_fd = -1;\n-\t}\n-\n \tif (dev->postcopy_ufd >= 0) {\n \t\tclose(dev->postcopy_ufd);\n \t\tdev->postcopy_ufd = -1;\n@@ -1549,17 +1544,13 @@ static int\n vhost_user_set_req_fd(struct virtio_net **pdev, struct VhostUserMsg *msg,\n \t\t\tint main_fd __rte_unused)\n {\n+\tint ret;\n \tstruct virtio_net *dev = *pdev;\n-\tint fd = msg->fds[0];\n \n-\tif (fd < 0) {\n-\t\tRTE_LOG(ERR, VHOST_CONFIG,\n-\t\t\t\t\"Invalid file descriptor for slave channel (%d)\\n\",\n-\t\t\t\tfd);\n-\t\treturn RTE_VHOST_MSG_RESULT_ERR;\n-\t}\n+\tret = dev->trans_ops->set_slave_req_fd(dev, msg);\n \n-\tdev->slave_req_fd = fd;\n+\tif (ret < 0)\n+\t\treturn RTE_VHOST_MSG_RESULT_ERR;\n \n \treturn RTE_VHOST_MSG_RESULT_OK;\n }\n@@ -1778,21 +1769,6 @@ send_vhost_reply(struct virtio_net *dev, struct VhostUserMsg *msg)\n \treturn dev->trans_ops->send_reply(dev, msg);\n }\n \n-static int\n-send_vhost_slave_message(struct virtio_net *dev, struct VhostUserMsg *msg)\n-{\n-\tint ret;\n-\n-\tif (msg->flags & VHOST_USER_NEED_REPLY)\n-\t\trte_spinlock_lock(&dev->slave_req_lock);\n-\n-\tret = dev->trans_ops->send_slave_req(dev, msg);\n-\tif (ret < 0 && (msg->flags & VHOST_USER_NEED_REPLY))\n-\t\trte_spinlock_unlock(&dev->slave_req_lock);\n-\n-\treturn ret;\n-}\n-\n /*\n  * Allocate a queue pair if it hasn't been allocated yet\n  */\n@@ -2069,35 +2045,6 @@ vhost_user_msg_handler(int vid, int fd, const struct VhostUserMsg *msg_)\n \treturn 0;\n }\n \n-static int process_slave_message_reply(struct virtio_net *dev,\n-\t\t\t\t       const struct VhostUserMsg *msg)\n-{\n-\tstruct VhostUserMsg msg_reply;\n-\tint ret;\n-\n-\tif ((msg->flags & VHOST_USER_NEED_REPLY) == 0)\n-\t\treturn 0;\n-\n-\tif (read_vhost_message(dev->slave_req_fd, &msg_reply) < 0) {\n-\t\tret = -1;\n-\t\tgoto out;\n-\t}\n-\n-\tif (msg_reply.request.slave != msg->request.slave) {\n-\t\tRTE_LOG(ERR, VHOST_CONFIG,\n-\t\t\t\"Received unexpected msg type (%u), expected %u\\n\",\n-\t\t\tmsg_reply.request.slave, msg->request.slave);\n-\t\tret = -1;\n-\t\tgoto out;\n-\t}\n-\n-\tret = msg_reply.payload.u64 ? -1 : 0;\n-\n-out:\n-\trte_spinlock_unlock(&dev->slave_req_lock);\n-\treturn ret;\n-}\n-\n int\n vhost_user_iotlb_miss(struct virtio_net *dev, uint64_t iova, uint8_t perm)\n {\n@@ -2113,7 +2060,7 @@ vhost_user_iotlb_miss(struct virtio_net *dev, uint64_t iova, uint8_t perm)\n \t\t},\n \t};\n \n-\tret = send_vhost_slave_req(dev, &msg);\n+\tret = dev->trans_ops->send_slave_req(dev, &msg);\n \tif (ret < 0) {\n \t\tRTE_LOG(ERR, VHOST_CONFIG,\n \t\t\t\t\"Failed to send IOTLB miss message (%d)\\n\",\n@@ -2148,14 +2095,14 @@ static int vhost_user_slave_set_vring_host_notifier(struct virtio_net *dev,\n \t\tmsg.fd_num = 1;\n \t}\n \n-\tret = send_vhost_slave_message(dev, &msg);\n+\tret = dev->trans_ops->send_slave_req(dev, &msg);\n \tif (ret < 0) {\n \t\tRTE_LOG(ERR, VHOST_CONFIG,\n \t\t\t\"Failed to set host notifier (%d)\\n\", ret);\n \t\treturn ret;\n \t}\n \n-\treturn process_slave_message_reply(dev, &msg);\n+\treturn dev->trans_ops->process_slave_message_reply(dev, &msg);\n }\n \n int rte_vhost_host_notifier_ctrl(int vid, bool enable)\n",
    "prefixes": [
        "12/28"
    ]
}