get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

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

{
    "id": 85562,
    "url": "http://patches.dpdk.org/api/patches/85562/?format=api",
    "web_url": "http://patches.dpdk.org/project/dpdk/patch/20201220211405.313012-40-maxime.coquelin@redhat.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": "<20201220211405.313012-40-maxime.coquelin@redhat.com>",
    "list_archive_url": "https://inbox.dpdk.org/dev/20201220211405.313012-40-maxime.coquelin@redhat.com",
    "date": "2020-12-20T21:14:04",
    "name": "[39/40] net/virtio: move Vhost-kernel data to its backend",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": true,
    "hash": "591911ccfce443fe2340a3f54d0bf224500c3f19",
    "submitter": {
        "id": 512,
        "url": "http://patches.dpdk.org/api/people/512/?format=api",
        "name": "Maxime Coquelin",
        "email": "maxime.coquelin@redhat.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/20201220211405.313012-40-maxime.coquelin@redhat.com/mbox/",
    "series": [
        {
            "id": 14390,
            "url": "http://patches.dpdk.org/api/series/14390/?format=api",
            "web_url": "http://patches.dpdk.org/project/dpdk/list/?series=14390",
            "date": "2020-12-20T21:13:25",
            "name": "net/virtio: Virtio PMD rework",
            "version": 1,
            "mbox": "http://patches.dpdk.org/series/14390/mbox/"
        }
    ],
    "comments": "http://patches.dpdk.org/api/patches/85562/comments/",
    "check": "success",
    "checks": "http://patches.dpdk.org/api/patches/85562/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 dpdk.org (dpdk.org [92.243.14.124])\n\tby inbox.dpdk.org (Postfix) with ESMTP id B9767A09FD;\n\tSun, 20 Dec 2020 22:26:09 +0100 (CET)",
            "from [92.243.14.124] (localhost [127.0.0.1])\n\tby dpdk.org (Postfix) with ESMTP id 64431CEF4;\n\tSun, 20 Dec 2020 22:16:54 +0100 (CET)",
            "from us-smtp-delivery-124.mimecast.com\n (us-smtp-delivery-124.mimecast.com [63.128.21.124])\n by dpdk.org (Postfix) with ESMTP id EDDC0CEF4\n for <dev@dpdk.org>; Sun, 20 Dec 2020 22:16:52 +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-436-r5dpp9QPM82CG26bRra4Mg-1; Sun, 20 Dec 2020 16:16:49 -0500",
            "from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com\n [10.5.11.12])\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 B2F8C805EF2;\n Sun, 20 Dec 2020 21:16:48 +0000 (UTC)",
            "from max-t490s.redhat.com (unknown [10.36.110.43])\n by smtp.corp.redhat.com (Postfix) with ESMTP id 0F5BE60C43;\n Sun, 20 Dec 2020 21:16:46 +0000 (UTC)"
        ],
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;\n s=mimecast20190719; t=1608499011;\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=AjK9vAD8Iqn/DPPcUZTKj9bIBq7JhCZPgKj/Bwk9XPY=;\n b=Y3YToF/kTbQCcK/gESkmC1npFQOg3Hfxf14jRv9/1VPmdaBeEsKhYdwAH93eZrp/tCksul\n lGTj9Mcn8BcuwDudl39ujZ0NT5Qdkd1XOmpPIA0pWjFJTaWhxDlVtj5GQbO+Ilk4SwXaUH\n gv6R+QHEKULuCO6o8H2T2vQ4kV6I1/g=",
        "X-MC-Unique": "r5dpp9QPM82CG26bRra4Mg-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": "Sun, 20 Dec 2020 22:14:04 +0100",
        "Message-Id": "<20201220211405.313012-40-maxime.coquelin@redhat.com>",
        "In-Reply-To": "<20201220211405.313012-1-maxime.coquelin@redhat.com>",
        "References": "<20201220211405.313012-1-maxime.coquelin@redhat.com>",
        "MIME-Version": "1.0",
        "X-Scanned-By": "MIMEDefang 2.79 on 10.5.11.12",
        "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 39/40] net/virtio: move Vhost-kernel data to its\n\tbackend",
        "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 <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>\n---\n drivers/net/virtio/virtio_user/vhost_kernel.c | 78 +++++++++++++++----\n .../net/virtio/virtio_user/virtio_user_dev.c  | 43 ++--------\n .../net/virtio/virtio_user/virtio_user_dev.h  |  7 +-\n 3 files changed, 72 insertions(+), 56 deletions(-)",
    "diff": "diff --git a/drivers/net/virtio/virtio_user/vhost_kernel.c b/drivers/net/virtio/virtio_user/vhost_kernel.c\nindex 0ba37b23dc..b8f5391733 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 \tuint32_t 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 \tuint32_t 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 \tuint32_t 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,19 +353,37 @@ 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+\tdata->tapfds = malloc(dev->max_queue_pairs * sizeof(int));\n+\tif (!data->vhostfds || !data->tapfds) {\n+\t\tPMD_INIT_LOG(ERR, \"(%s) Failed to allocate FDs\", dev->path);\n+\t\treturn -1;\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\tPMD_DRV_LOG(ERR, \"fail to open %s, %s\", dev->path, strerror(errno));\n \t\t\treturn -1;\n \t\t}\n \n-\t\tdev->vhostfds[i] = vhostfd;\n+\t\tdata->vhostfds[i] = vhostfd;\n \t}\n \n \treturn 0;\n@@ -360,6 +392,19 @@ vhost_kernel_setup(struct virtio_user_dev *dev)\n static int\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+\tfor (i = 0; i < dev->max_queue_pairs; ++i) {\n+\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+\n \treturn 0;\n }\n \n@@ -395,14 +440,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 +461,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 +485,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 93a9ce2cd2..154aecc209 100644\n--- a/drivers/net/virtio/virtio_user/virtio_user_dev.c\n+++ b/drivers/net/virtio/virtio_user/virtio_user_dev.c\n@@ -397,11 +397,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@@ -409,34 +404,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@@ -592,15 +574,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 a429dcc57c..5a2c9d38dd 100644\n--- a/drivers/net/virtio/virtio_user/virtio_user_dev.h\n+++ b/drivers/net/virtio/virtio_user/virtio_user_dev.h\n@@ -31,11 +31,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@@ -55,6 +50,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": [
        "39/40"
    ]
}