get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

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

{
    "id": 87328,
    "url": "https://patches.dpdk.org/api/patches/87328/?format=api",
    "web_url": "https://patches.dpdk.org/project/dpdk/patch/20210126101639.250481-42-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-42-maxime.coquelin@redhat.com>",
    "list_archive_url": "https://inbox.dpdk.org/dev/20210126101639.250481-42-maxime.coquelin@redhat.com",
    "date": "2021-01-26T10:16:36",
    "name": "[v4,41/44] net/virtio: move Vhost-kernel data to its backend",
    "commit_ref": null,
    "pull_url": null,
    "state": "accepted",
    "archived": true,
    "hash": "6b7c7ef9f7c08cf847eca083f3c194d1db5a597f",
    "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-42-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/87328/comments/",
    "check": "success",
    "checks": "https://patches.dpdk.org/api/patches/87328/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 C296AA052A;\n\tTue, 26 Jan 2021 11:23:27 +0100 (CET)",
            "from [217.70.189.124] (localhost [127.0.0.1])\n\tby mails.dpdk.org (Postfix) with ESMTP id 2DF84141437;\n\tTue, 26 Jan 2021 11:18:44 +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 3A19414139C\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-495-yS2nIk6aNTKPQcD7xAngMA-1; Tue, 26 Jan 2021 05:18:39 -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 D658A18C8C0D;\n Tue, 26 Jan 2021 10:18:37 +0000 (UTC)",
            "from max-t490s.redhat.com (unknown [10.36.110.31])\n by smtp.corp.redhat.com (Postfix) with ESMTP id 6A54E6F45C;\n Tue, 26 Jan 2021 10:18:36 +0000 (UTC)"
        ],
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;\n s=mimecast20190719; t=1611656320;\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=E1MjiQc01gsh7EHYwWW7xMD+m8bBR9OGXEh89cGVv64=;\n b=dCmKAnDP25qgq3BvKV2KScJFZFRepWRd+JPyxunO8McZ7LRq19otdivSwO6QC3tJUXqPLj\n P5usfzVQl9vyRak/tmD2gtf89v1hOxiTsVBxTVcqtVOZnzqdSg9n8BuXbTPbo2T5GxtOHc\n aQRTAGpOj7M8LT2Y5I6GTKD2TVaTmNM=",
        "X-MC-Unique": "yS2nIk6aNTKPQcD7xAngMA-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:36 +0100",
        "Message-Id": "<20210126101639.250481-42-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 41/44] net/virtio: move Vhost-kernel data to\n 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": "As done earlier for Vhost-user, this patch moves the\nVhost-Kernel specific data to its backend file.\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_kernel.c | 106 +++++++++++++++---\n .../net/virtio/virtio_user/virtio_user_dev.c  |  43 ++-----\n .../net/virtio/virtio_user/virtio_user_dev.h  |   7 +-\n 3 files changed, 98 insertions(+), 58 deletions(-)",
    "diff": "diff --git a/drivers/net/virtio/virtio_user/vhost_kernel.c b/drivers/net/virtio/virtio_user/vhost_kernel.c\nindex 0d05e7d339..768db55a6c 100644\n--- a/drivers/net/virtio/virtio_user/vhost_kernel.c\n+++ b/drivers/net/virtio/virtio_user/vhost_kernel.c\n@@ -14,6 +14,11 @@\n #include \"virtio_user_dev.h\"\n #include \"vhost_kernel_tap.h\"\n \n+struct vhost_kernel_data {\n+\tint *vhostfds;\n+\tint *tapfds;\n+};\n+\n struct vhost_memory_kernel {\n \tuint32_t nregions;\n \tuint32_t padding;\n@@ -96,7 +101,9 @@ vhost_kernel_ioctl(int fd, uint64_t request, void *arg)\n static int\n vhost_kernel_set_owner(struct virtio_user_dev *dev)\n {\n-\treturn vhost_kernel_ioctl(dev->vhostfds[0], VHOST_SET_OWNER, NULL);\n+\tstruct vhost_kernel_data *data = dev->backend_data;\n+\n+\treturn vhost_kernel_ioctl(data->vhostfds[0], VHOST_SET_OWNER, NULL);\n }\n \n static int\n@@ -104,8 +111,9 @@ vhost_kernel_get_features(struct virtio_user_dev *dev, uint64_t *features)\n {\n \tint ret;\n \tunsigned int tap_features;\n+\tstruct vhost_kernel_data *data = dev->backend_data;\n \n-\tret = vhost_kernel_ioctl(dev->vhostfds[0], VHOST_GET_FEATURES, features);\n+\tret = vhost_kernel_ioctl(data->vhostfds[0], VHOST_GET_FEATURES, features);\n \tif (ret < 0) {\n \t\tPMD_DRV_LOG(ERR, \"Failed to get features\");\n \t\treturn -1;\n@@ -138,6 +146,8 @@ vhost_kernel_get_features(struct virtio_user_dev *dev, uint64_t *features)\n static int\n vhost_kernel_set_features(struct virtio_user_dev *dev, uint64_t features)\n {\n+\tstruct vhost_kernel_data *data = dev->backend_data;\n+\n \t/* We don't need memory protection here */\n \tfeatures &= ~(1ULL << VIRTIO_F_IOMMU_PLATFORM);\n \t/* VHOST kernel does not know about below flags */\n@@ -145,7 +155,7 @@ vhost_kernel_set_features(struct virtio_user_dev *dev, uint64_t features)\n \tfeatures &= ~VHOST_KERNEL_HOST_OFFLOADS_MASK;\n \tfeatures &= ~(1ULL << VIRTIO_NET_F_MQ);\n \n-\treturn vhost_kernel_ioctl(dev->vhostfds[0], VHOST_SET_FEATURES, &features);\n+\treturn vhost_kernel_ioctl(data->vhostfds[0], VHOST_SET_FEATURES, &features);\n }\n \n static int\n@@ -185,6 +195,7 @@ add_memseg_list(const struct rte_memseg_list *msl, void *arg)\n static int\n vhost_kernel_set_memory_table(struct virtio_user_dev *dev)\n {\n+\tstruct vhost_kernel_data *data = dev->backend_data;\n \tstruct vhost_memory_kernel *vm;\n \tint ret;\n \n@@ -205,7 +216,7 @@ vhost_kernel_set_memory_table(struct virtio_user_dev *dev)\n \tif (ret < 0)\n \t\tgoto err_free;\n \n-\tret = vhost_kernel_ioctl(dev->vhostfds[0], VHOST_SET_MEM_TABLE, vm);\n+\tret = vhost_kernel_ioctl(data->vhostfds[0], VHOST_SET_MEM_TABLE, vm);\n \tif (ret < 0)\n \t\tgoto err_free;\n \n@@ -224,9 +235,10 @@ vhost_kernel_set_vring(struct virtio_user_dev *dev, uint64_t req, struct vhost_v\n {\n \tint ret, fd;\n \tunsigned int index = state->index;\n+\tstruct vhost_kernel_data *data = dev->backend_data;\n \n \t/* Convert from queue index to queue-pair & offset */\n-\tfd = dev->vhostfds[state->index / 2];\n+\tfd = data->vhostfds[state->index / 2];\n \tstate->index %= 2;\n \n \tret = vhost_kernel_ioctl(fd, req, state);\n@@ -265,9 +277,10 @@ vhost_kernel_set_vring_file(struct virtio_user_dev *dev, uint64_t req,\n {\n \tint ret, fd;\n \tunsigned int index = file->index;\n+\tstruct vhost_kernel_data *data = dev->backend_data;\n \n \t/* Convert from queue index to queue-pair & offset */\n-\tfd = dev->vhostfds[file->index / 2];\n+\tfd = data->vhostfds[file->index / 2];\n \tfile->index %= 2;\n \n \tret = vhost_kernel_ioctl(fd, req, file);\n@@ -299,9 +312,10 @@ vhost_kernel_set_vring_addr(struct virtio_user_dev *dev, struct vhost_vring_addr\n {\n \tint ret, fd;\n \tunsigned int index = addr->index;\n+\tstruct vhost_kernel_data *data = dev->backend_data;\n \n \t/* Convert from queue index to queue-pair & offset */\n-\tfd = dev->vhostfds[addr->index / 2];\n+\tfd = data->vhostfds[addr->index / 2];\n \taddr->index %= 2;\n \n \tret = vhost_kernel_ioctl(fd, VHOST_SET_VRING_ADDR, addr);\n@@ -339,27 +353,82 @@ static int\n vhost_kernel_setup(struct virtio_user_dev *dev)\n {\n \tint vhostfd;\n-\tuint32_t i;\n+\tuint32_t q, i;\n+\tstruct vhost_kernel_data *data;\n+\n+\tdata = malloc(sizeof(*data));\n+\tif (!data) {\n+\t\tPMD_INIT_LOG(ERR, \"(%s) Failed to allocate Vhost-kernel data\", dev->path);\n+\t\treturn -1;\n+\t}\n+\n+\tdata->vhostfds = malloc(dev->max_queue_pairs * sizeof(int));\n+\tif (!data->vhostfds) {\n+\t\tPMD_INIT_LOG(ERR, \"(%s) Failed to allocate Vhost FDs\", dev->path);\n+\t\tgoto err_data;\n+\t}\n+\tdata->tapfds = malloc(dev->max_queue_pairs * sizeof(int));\n+\tif (!data->tapfds) {\n+\t\tPMD_INIT_LOG(ERR, \"(%s) Failed to allocate TAP FDs\", dev->path);\n+\t\tgoto err_vhostfds;\n+\t}\n+\n+\tfor (q = 0; q < dev->max_queue_pairs; ++q) {\n+\t\tdata->vhostfds[q] = -1;\n+\t\tdata->tapfds[q] = -1;\n+\t}\n \n \tget_vhost_kernel_max_regions();\n \n \tfor (i = 0; i < dev->max_queue_pairs; ++i) {\n \t\tvhostfd = open(dev->path, O_RDWR);\n \t\tif (vhostfd < 0) {\n-\t\t\tPMD_DRV_LOG(ERR, \"fail to open %s, %s\",\n-\t\t\t\t    dev->path, strerror(errno));\n-\t\t\treturn -1;\n+\t\t\tPMD_DRV_LOG(ERR, \"fail to open %s, %s\", dev->path, strerror(errno));\n+\t\t\tgoto err_tapfds;\n \t\t}\n \n-\t\tdev->vhostfds[i] = vhostfd;\n+\t\tdata->vhostfds[i] = vhostfd;\n \t}\n \n+\tdev->backend_data = data;\n+\n \treturn 0;\n+\n+err_tapfds:\n+\tfor (i = 0; i < dev->max_queue_pairs; i++)\n+\t\tif (data->vhostfds[i] >= 0)\n+\t\t\tclose(data->vhostfds[i]);\n+\n+\tfree(data->tapfds);\n+err_vhostfds:\n+\tfree(data->vhostfds);\n+err_data:\n+\tfree(data);\n+\n+\treturn -1;\n }\n \n static int\n-vhost_kernel_destroy(struct virtio_user_dev *dev __rte_unused)\n+vhost_kernel_destroy(struct virtio_user_dev *dev)\n {\n+\tstruct vhost_kernel_data *data = dev->backend_data;\n+\tuint32_t i;\n+\n+\tif (!data)\n+\t\treturn 0;\n+\n+\tfor (i = 0; i < dev->max_queue_pairs; ++i) {\n+\t\tif (data->vhostfds[i] >= 0)\n+\t\t\tclose(data->vhostfds[i]);\n+\t\tif (data->tapfds[i] >= 0)\n+\t\t\tclose(data->tapfds[i]);\n+\t}\n+\n+\tfree(data->vhostfds);\n+\tfree(data->tapfds);\n+\tfree(data);\n+\tdev->backend_data = NULL;\n+\n \treturn 0;\n }\n \n@@ -395,14 +464,15 @@ vhost_kernel_enable_queue_pair(struct virtio_user_dev *dev,\n \tint vhostfd;\n \tint tapfd;\n \tint req_mq = (dev->max_queue_pairs > 1);\n+\tstruct vhost_kernel_data *data = dev->backend_data;\n \n-\tvhostfd = dev->vhostfds[pair_idx];\n+\tvhostfd = data->vhostfds[pair_idx];\n \n \tif (dev->qp_enabled[pair_idx] == enable)\n \t\treturn 0;\n \n \tif (!enable) {\n-\t\ttapfd = dev->tapfds[pair_idx];\n+\t\ttapfd = data->tapfds[pair_idx];\n \t\tif (vhost_kernel_set_backend(vhostfd, -1) < 0) {\n \t\t\tPMD_DRV_LOG(ERR, \"fail to set backend for vhost kernel\");\n \t\t\treturn -1;\n@@ -415,8 +485,8 @@ vhost_kernel_enable_queue_pair(struct virtio_user_dev *dev,\n \t\treturn 0;\n \t}\n \n-\tif (dev->tapfds[pair_idx] >= 0) {\n-\t\ttapfd = dev->tapfds[pair_idx];\n+\tif (data->tapfds[pair_idx] >= 0) {\n+\t\ttapfd = data->tapfds[pair_idx];\n \t\tif (vhost_kernel_tap_set_offload(tapfd, dev->features) == -1)\n \t\t\treturn -1;\n \t\tif (req_mq && vhost_kernel_tap_set_queue(tapfd, true) < 0) {\n@@ -439,7 +509,7 @@ vhost_kernel_enable_queue_pair(struct virtio_user_dev *dev,\n \t\treturn -1;\n \t}\n \n-\tdev->tapfds[pair_idx] = tapfd;\n+\tdata->tapfds[pair_idx] = tapfd;\n \n set_backend:\n \tif (vhost_kernel_set_backend(vhostfd, tapfd) < 0) {\ndiff --git a/drivers/net/virtio/virtio_user/virtio_user_dev.c b/drivers/net/virtio/virtio_user/virtio_user_dev.c\nindex 7128457e32..a1e32158bb 100644\n--- a/drivers/net/virtio/virtio_user/virtio_user_dev.c\n+++ b/drivers/net/virtio/virtio_user/virtio_user_dev.c\n@@ -398,11 +398,6 @@ virtio_user_mem_event_cb(enum rte_mem_event type __rte_unused,\n static int\n virtio_user_dev_setup(struct virtio_user_dev *dev)\n {\n-\tuint32_t q;\n-\n-\tdev->vhostfds = NULL;\n-\tdev->tapfds = NULL;\n-\n \tif (dev->is_server) {\n \t\tif (dev->backend_type != VIRTIO_USER_BACKEND_VHOST_USER) {\n \t\t\tPMD_DRV_LOG(ERR, \"Server mode only supports vhost-user!\");\n@@ -410,34 +405,21 @@ virtio_user_dev_setup(struct virtio_user_dev *dev)\n \t\t}\n \t}\n \n-\tif (dev->backend_type == VIRTIO_USER_BACKEND_VHOST_USER) {\n+\tswitch (dev->backend_type) {\n+\tcase VIRTIO_USER_BACKEND_VHOST_USER:\n \t\tdev->ops = &virtio_ops_user;\n-\t} else if (dev->backend_type ==\n-\t\t\tVIRTIO_USER_BACKEND_VHOST_KERNEL) {\n+\t\tbreak;\n+\tcase VIRTIO_USER_BACKEND_VHOST_KERNEL:\n \t\tdev->ops = &virtio_ops_kernel;\n-\n-\t\tdev->vhostfds = malloc(dev->max_queue_pairs *\n-\t\t\t\tsizeof(int));\n-\t\tdev->tapfds = malloc(dev->max_queue_pairs *\n-\t\t\t\tsizeof(int));\n-\t\tif (!dev->vhostfds || !dev->tapfds) {\n-\t\t\tPMD_INIT_LOG(ERR, \"(%s) Failed to allocate FDs\", dev->path);\n-\t\t\treturn -1;\n-\t\t}\n-\n-\t\tfor (q = 0; q < dev->max_queue_pairs; ++q) {\n-\t\t\tdev->vhostfds[q] = -1;\n-\t\t\tdev->tapfds[q] = -1;\n-\t\t}\n-\t} else if (dev->backend_type ==\n-\t\t\tVIRTIO_USER_BACKEND_VHOST_VDPA) {\n+\t\tbreak;\n+\tcase VIRTIO_USER_BACKEND_VHOST_VDPA:\n \t\tdev->ops = &virtio_ops_vdpa;\n-\t} else {\n+\t\tbreak;\n+\tdefault:\n \t\tPMD_DRV_LOG(ERR, \"(%s) Unknown backend type\", dev->path);\n \t\treturn -1;\n \t}\n \n-\n \tif (dev->ops->setup(dev) < 0) {\n \t\tPMD_INIT_LOG(ERR, \"(%s) Failed to setup backend\\n\", dev->path);\n \t\treturn -1;\n@@ -593,15 +575,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-\tif (dev->vhostfds) {\n-\t\tfor (i = 0; i < dev->max_queue_pairs; ++i) {\n-\t\t\tclose(dev->vhostfds[i]);\n-\t\t\tif (dev->tapfds[i] >= 0)\n-\t\t\t\tclose(dev->tapfds[i]);\n-\t\t}\n-\t\tfree(dev->vhostfds);\n-\t\tfree(dev->tapfds);\n-\t}\n \n \tfree(dev->ifname);\n \ndiff --git a/drivers/net/virtio/virtio_user/virtio_user_dev.h b/drivers/net/virtio/virtio_user/virtio_user_dev.h\nindex 36d2410546..36a9cadcad 100644\n--- a/drivers/net/virtio/virtio_user/virtio_user_dev.h\n+++ b/drivers/net/virtio/virtio_user/virtio_user_dev.h\n@@ -32,11 +32,6 @@ struct virtio_user_dev {\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-\tint\t\t*tapfds;\n-\n \t/* for both vhost_user and vhost_kernel */\n \tint\t\tcallfds[VIRTIO_MAX_VIRTQUEUES];\n \tint\t\tkickfds[VIRTIO_MAX_VIRTQUEUES];\n@@ -56,6 +51,8 @@ struct virtio_user_dev {\n \tuint16_t\tport_id;\n \tuint8_t\t\tmac_addr[RTE_ETHER_ADDR_LEN];\n \tchar\t\tpath[PATH_MAX];\n+\tchar\t\t*ifname;\n+\n \tunion {\n \t\tstruct vring\t\tvrings[VIRTIO_MAX_VIRTQUEUES];\n \t\tstruct vring_packed\tpacked_vrings[VIRTIO_MAX_VIRTQUEUES];\n",
    "prefixes": [
        "v4",
        "41/44"
    ]
}