get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

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

{
    "id": 131515,
    "url": "http://patches.dpdk.org/api/patches/131515/?format=api",
    "web_url": "http://patches.dpdk.org/project/dpdk/patch/20230918015750.438462-2-lulu@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": "<20230918015750.438462-2-lulu@redhat.com>",
    "list_archive_url": "https://inbox.dpdk.org/dev/20230918015750.438462-2-lulu@redhat.com",
    "date": "2023-09-18T01:57:49",
    "name": "[RFC,v1,1/2] vduse: add mapping process in vduse create and destroy",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": true,
    "hash": "520528636023d32559a9b2ef979c33c38bbdfbe6",
    "submitter": {
        "id": 3189,
        "url": "http://patches.dpdk.org/api/people/3189/?format=api",
        "name": "Cindy Lu",
        "email": "lulu@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/20230918015750.438462-2-lulu@redhat.com/mbox/",
    "series": [
        {
            "id": 29529,
            "url": "http://patches.dpdk.org/api/series/29529/?format=api",
            "web_url": "http://patches.dpdk.org/project/dpdk/list/?series=29529",
            "date": "2023-09-18T01:57:48",
            "name": "Vduse: Add support for reconncect",
            "version": 1,
            "mbox": "http://patches.dpdk.org/series/29529/mbox/"
        }
    ],
    "comments": "http://patches.dpdk.org/api/patches/131515/comments/",
    "check": "pending",
    "checks": "http://patches.dpdk.org/api/patches/131515/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 0FC8B425C8;\n\tMon, 18 Sep 2023 03:58:11 +0200 (CEST)",
            "from mails.dpdk.org (localhost [127.0.0.1])\n\tby mails.dpdk.org (Postfix) with ESMTP id E2909402E7;\n\tMon, 18 Sep 2023 03:58:09 +0200 (CEST)",
            "from us-smtp-delivery-124.mimecast.com\n (us-smtp-delivery-124.mimecast.com [170.10.129.124])\n by mails.dpdk.org (Postfix) with ESMTP id 96854402E2\n for <dev@dpdk.org>; Mon, 18 Sep 2023 03:58:08 +0200 (CEST)",
            "from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com\n [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS\n (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id\n us-mta-593-qYAFvONEPWCDWL0LT4ZvEA-1; Sun, 17 Sep 2023 21:58:05 -0400",
            "from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com\n [10.11.54.2])\n (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))\n (No client certificate requested)\n by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A3018945920;\n Mon, 18 Sep 2023 01:58:04 +0000 (UTC)",
            "from server.redhat.com (unknown [10.72.112.11])\n by smtp.corp.redhat.com (Postfix) with ESMTP id 21FE440C6EA8;\n Mon, 18 Sep 2023 01:58:01 +0000 (UTC)"
        ],
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;\n s=mimecast20190719; t=1695002288;\n h=from:from:reply-to:subject:subject:date:date:message-id:message-id:\n to:to: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=oLqpefYIrDypwuq0TFjUvQ/V0rlbYOtyFLlA4n9oiRE=;\n b=Liub11aerAUXeM6whO9SfSOn3In5k1J/KfiXQvi27zGrO5WJIinBuf3gey3yl7ifG4RdMn\n ZIMweTkmJV3YMBAf6Hsl6/VXEM+Lz6WQx/BZ6Cmc8AIkbjNhVTeYBzEsfuHvz5YzJKjpHA\n vzbGCxt+QJOcnNh3/vHR2t2PmMeUPoM=",
        "X-MC-Unique": "qYAFvONEPWCDWL0LT4ZvEA-1",
        "From": "Cindy Lu <lulu@redhat.com>",
        "To": "lulu@redhat.com, jasowang@redhat.com, xieyongji@bytedance.com,\n dev@dpdk.org, maxime.coquelin@redhat.com",
        "Subject": "[RFC v1 1/2] vduse: add mapping process in vduse create and destroy",
        "Date": "Mon, 18 Sep 2023 09:57:49 +0800",
        "Message-Id": "<20230918015750.438462-2-lulu@redhat.com>",
        "In-Reply-To": "<20230918015750.438462-1-lulu@redhat.com>",
        "References": "<20230918015750.438462-1-lulu@redhat.com>",
        "MIME-Version": "1.0",
        "X-Scanned-By": "MIMEDefang 3.1 on 10.11.54.2",
        "X-Mimecast-Spam-Score": "0",
        "X-Mimecast-Originator": "redhat.com",
        "Content-Type": "text/plain; charset=UTF-8",
        "Content-Transfer-Encoding": "8bit",
        "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"
    },
    "content": "the change in the creation process is add\n1> check if we need to do reconnect\n2> Use ioctl get the reconnect info (size and max page number) from kernel\n3> mapping 1 page for reconnect  status + vq_numbers pages for every vqs,\nThe change in the destroy process is the add the related unmap process\n\nSigned-off-by: Cindy Lu <lulu@redhat.com>\n---\n lib/vhost/vduse.c | 148 ++++++++++++++++++++++++++++++++++++----------\n lib/vhost/vhost.h |  21 +++++++\n 2 files changed, 138 insertions(+), 31 deletions(-)",
    "diff": "diff --git a/lib/vhost/vduse.c b/lib/vhost/vduse.c\nindex 4f36277d3b..4b9bfdbe73 100644\n--- a/lib/vhost/vduse.c\n+++ b/lib/vhost/vduse.c\n@@ -376,6 +376,19 @@ vduse_device_create(const char *path)\n \tuint64_t features = VDUSE_NET_SUPPORTED_FEATURES;\n \tstruct vduse_dev_config *dev_config = NULL;\n \tconst char *name = path + strlen(\"/dev/vduse/\");\n+\tchar reconnect_dev[PATH_MAX];\n+\tstruct vhost_reconnect_data *log = NULL;\n+\tstruct vduse_reconnect_mmap_info mmap_info;\n+\tbool reconnect = false;\n+\n+\tret = snprintf(reconnect_dev, sizeof(reconnect_dev), \"%s/%s\", \"/dev/vduse\", name);\n+\tif (access(reconnect_dev, F_OK) == 0) {\n+\t\treconnect = true;\n+\t\tVHOST_LOG_CONFIG(name, INFO, \"Device already exists, reconnecting...\\n\");\n+\t} else {\n+\t\treconnect = false;\n+\t\tVHOST_LOG_CONFIG(name, ERR, \"device %s not exists, creating...\\n\", reconnect_dev);\n+\t}\n \n \t/* If first device, create events dispatcher thread */\n \tif (vduse_events_thread == false) {\n@@ -407,16 +420,8 @@ vduse_device_create(const char *path)\n \t}\n \n \tif (ioctl(control_fd, VDUSE_SET_API_VERSION, &ver)) {\n-\t\tVHOST_LOG_CONFIG(name, ERR, \"Failed to set API version: %\" PRIu64 \": %s\\n\",\n-\t\t\t\tver, strerror(errno));\n-\t\tret = -1;\n-\t\tgoto out_ctrl_close;\n-\t}\n-\n-\tdev_config = malloc(offsetof(struct vduse_dev_config, config) +\n-\t\t\tsizeof(vnet_config));\n-\tif (!dev_config) {\n-\t\tVHOST_LOG_CONFIG(name, ERR, \"Failed to allocate VDUSE config\\n\");\n+\t\tVHOST_LOG_CONFIG(name, ERR, \"Failed to set API version: %\" PRIu64 \": %s\\n\", ver,\n+\t\t\t\t strerror(errno));\n \t\tret = -1;\n \t\tgoto out_ctrl_close;\n \t}\n@@ -424,7 +429,7 @@ vduse_device_create(const char *path)\n \tret = rte_vhost_driver_get_queue_num(path, &max_queue_pairs);\n \tif (ret < 0) {\n \t\tVHOST_LOG_CONFIG(name, ERR, \"Failed to get max queue pairs\\n\");\n-\t\tgoto out_free;\n+\t\tgoto out_ctrl_close;\n \t}\n \n \tVHOST_LOG_CONFIG(path, INFO, \"VDUSE max queue pairs: %u\\n\", max_queue_pairs);\n@@ -435,23 +440,34 @@ vduse_device_create(const char *path)\n \telse\n \t\ttotal_queues += 1; /* Includes ctrl queue */\n \n-\tvnet_config.max_virtqueue_pairs = max_queue_pairs;\n-\tmemset(dev_config, 0, sizeof(struct vduse_dev_config));\n-\n-\tstrncpy(dev_config->name, name, VDUSE_NAME_MAX - 1);\n-\tdev_config->device_id = VIRTIO_ID_NET;\n-\tdev_config->vendor_id = 0;\n-\tdev_config->features = features;\n-\tdev_config->vq_num = total_queues;\n-\tdev_config->vq_align = sysconf(_SC_PAGE_SIZE);\n-\tdev_config->config_size = sizeof(struct virtio_net_config);\n-\tmemcpy(dev_config->config, &vnet_config, sizeof(vnet_config));\n+\tif (reconnect != true) {\n+\t\tdev_config =\n+\t\t\tmalloc(offsetof(struct vduse_dev_config, config) + sizeof(vnet_config));\n+\t\tif (!dev_config) {\n+\t\t\tVHOST_LOG_CONFIG(name, ERR, \"Failed to allocate VDUSE config\\n\");\n+\t\t\tret = -1;\n+\t\t\tgoto out_ctrl_close;\n+\t\t}\n \n-\tret = ioctl(control_fd, VDUSE_CREATE_DEV, dev_config);\n-\tif (ret < 0) {\n-\t\tVHOST_LOG_CONFIG(name, ERR, \"Failed to create VDUSE device: %s\\n\",\n-\t\t\t\tstrerror(errno));\n-\t\tgoto out_free;\n+\t\tvnet_config.max_virtqueue_pairs = max_queue_pairs;\n+\t\tmemset(dev_config, 0, sizeof(struct vduse_dev_config));\n+\n+\t\tstrncpy(dev_config->name, name, VDUSE_NAME_MAX - 1);\n+\t\tdev_config->device_id = VIRTIO_ID_NET;\n+\t\tdev_config->vendor_id = 0;\n+\t\tdev_config->features = features;\n+\t\tdev_config->vq_num = total_queues;\n+\t\tdev_config->vq_align = sysconf(_SC_PAGE_SIZE);\n+\t\tdev_config->config_size = sizeof(struct virtio_net_config);\n+\t\tmemcpy(dev_config->config, &vnet_config, sizeof(vnet_config));\n+\n+\t\tret = ioctl(control_fd, VDUSE_CREATE_DEV, dev_config);\n+\t\tfree(dev_config);\n+\t\tif (ret < 0) {\n+\t\t\tVHOST_LOG_CONFIG(name, ERR, \"Failed to create VDUSE device: %s\\n\",\n+\t\t\t\t\t strerror(errno));\n+\t\t\tgoto out_ctrl_close;\n+\t\t}\n \t}\n \n \tdev_fd = open(path, O_RDWR);\n@@ -485,10 +501,45 @@ vduse_device_create(const char *path)\n \tstrncpy(dev->ifname, path, IF_NAME_SZ - 1);\n \tdev->vduse_ctrl_fd = control_fd;\n \tdev->vduse_dev_fd = dev_fd;\n+\n+\tret = ioctl(dev_fd, VDUSE_GET_RECONNECT_INFO, &mmap_info);\n+\tif (ret < 0) {\n+\t\tVHOST_LOG_CONFIG(name, ERR, \"Failed to get reconnect info VDUSE device: %s\\n\",\n+\t\t\t\t strerror(errno));\n+\t\tgoto out_dev_close;\n+\t}\n+\n+\tlog = (struct vhost_reconnect_data *)mmap(NULL, mmap_info.size, PROT_READ | PROT_WRITE,\n+\t\t\t\t\t\t  MAP_SHARED, dev->vduse_dev_fd, 0);\n+\tif (log == MAP_FAILED) {\n+\t\tVHOST_LOG_CONFIG(name, ERR, \"Failed to mapping vduse reconnect data\\n\");\n+\t\tgoto out_dev_close;\n+\t}\n+\n+\tdev->log = log;\n+\tlog->mmap_size = mmap_info.size;\n+\tlog->max_index = mmap_info.max_index;\n+\n+\tif (reconnect == true) {\n+\t\tdev->status = dev->log->status;\n+\t\tlog->version = VHOST_VDUSE_API_VERSION;\n+\t\tlog->reconnect_time += 1;\n+\t\tmemcpy(&log->config, &vnet_config, sizeof(vnet_config));\n+\t\tlog->nr_vrings = total_queues;\n+\t}\n+\n \tvhost_setup_virtio_net(dev->vid, true, true, true, true);\n \n+\tif (total_queues > log->max_index - 1) {\n+\t\tVHOST_LOG_CONFIG(name, ERR, \"The max vring number %d lager then %d\\n\", total_queues,\n+\t\t\t\t log->max_index - 1);\n+\t\tgoto out_dev_close;\n+\t}\n+\n \tfor (i = 0; i < total_queues; i++) {\n \t\tstruct vduse_vq_config vq_cfg = { 0 };\n+\t\tstruct vhost_reconnect_vring *log_vq;\n+\t\tstruct vhost_virtqueue *vq;\n \n \t\tret = alloc_vring_queue(dev, i);\n \t\tif (ret) {\n@@ -496,6 +547,23 @@ vduse_device_create(const char *path)\n \t\t\tgoto out_dev_destroy;\n \t\t}\n \n+\t\tlog_vq = (struct vhost_reconnect_vring *)mmap(NULL, log->mmap_size,\n+\t\t\t\t\t\t\t      PROT_READ | PROT_WRITE, MAP_SHARED,\n+\t\t\t\t\t\t\t      dev->vduse_dev_fd,\n+\t\t\t\t\t\t\t      (i + 1) * log->mmap_size);\n+\t\tif (log_vq == MAP_FAILED) {\n+\t\t\tVHOST_LOG_CONFIG(name, ERR, \"Failed to mapping vring %d reconnect data\\n\",\n+\t\t\t\t\t i);\n+\n+\t\t\tgoto out_dev_destroy;\n+\t\t}\n+\n+\t\tvq = dev->virtqueue[i];\n+\t\tvq->log = log_vq;\n+\t\tlog_vq->reconnect_time++;\n+\t\tif (reconnect)\n+\t\t\tcontinue;\n+\n \t\tvq_cfg.index = i;\n \t\tvq_cfg.max_size = 1024;\n \n@@ -516,7 +584,8 @@ vduse_device_create(const char *path)\n \t}\n \tfdset_pipe_notify(&vduse.fdset);\n \n-\tfree(dev_config);\n+\tif (reconnect && dev->status & VIRTIO_DEVICE_STATUS_DRIVER_OK)\n+\t\tvduse_device_start(dev, true);\n \n \treturn 0;\n \n@@ -526,8 +595,6 @@ vduse_device_create(const char *path)\n \tif (dev_fd >= 0)\n \t\tclose(dev_fd);\n \tioctl(control_fd, VDUSE_DESTROY_DEV, name);\n-out_free:\n-\tfree(dev_config);\n out_ctrl_close:\n \tclose(control_fd);\n \n@@ -553,7 +620,26 @@ vduse_device_destroy(const char *path)\n \n \tif (vid == RTE_MAX_VHOST_DEVICE)\n \t\treturn -1;\n-\n+\tif (dev->log) {\n+\t\tfor (uint32_t i = 0; i < dev->log->nr_vrings; i++) {\n+\t\t\tstruct vhost_virtqueue *vq;\n+\n+\t\t\tvq = dev->virtqueue[i];\n+\t\t\tret = munmap(vq->log, dev->log->mmap_size);\n+\t\t\tif (ret) {\n+\t\t\t\tVHOST_LOG_CONFIG(name, ERR, \"Failed to unmap device %s vq %d: %s\\n\",\n+\t\t\t\t\t\t path, i, strerror(errno));\n+\t\t\t\tret = -1;\n+\t\t\t}\n+\t\t}\n+\t\tret = munmap(dev->log, dev->log->mmap_size);\n+\t\tif (ret) {\n+\t\t\tVHOST_LOG_CONFIG(name, ERR, \"Failed to unmap device %s dev status: %s\\n\",\n+\t\t\t\t\t path, strerror(errno));\n+\t\t\tret = -1;\n+\t\t}\n+\t}\n+\tdev->log = NULL;\n \tif (dev->cvq && dev->cvq->kickfd >= 0) {\n \t\tfdset_del(&vduse.fdset, dev->cvq->kickfd);\n \t\tfdset_pipe_notify(&vduse.fdset);\ndiff --git a/lib/vhost/vhost.h b/lib/vhost/vhost.h\nindex c8f2a0d43a..85f225651b 100644\n--- a/lib/vhost/vhost.h\n+++ b/lib/vhost/vhost.h\n@@ -19,6 +19,7 @@\n #include <rte_ether.h>\n #include <rte_malloc.h>\n #include <rte_dmadev.h>\n+#include <linux/vduse.h>\n \n #include \"rte_vhost.h\"\n #include \"vdpa_driver.h\"\n@@ -265,6 +266,18 @@ struct vhost_async {\n \t};\n };\n \n+struct vhost_reconnect_data {\n+\tuint16_t index;\n+\tuint32_t reconnect_time;\n+\tuint32_t version;\n+\tuint64_t features;\n+\tuint8_t status;\n+\tstruct virtio_net_config config;\n+\tuint32_t nr_vrings;\n+\tuint32_t mmap_size;\n+\tuint32_t max_index;\n+};\n+\n /**\n  * Structure contains variables relevant to RX/TX virtqueues.\n  */\n@@ -344,6 +357,8 @@ struct vhost_virtqueue {\n \n \tstruct vhost_vring_addr ring_addrs;\n \tstruct virtqueue_stats\tstats;\n+\n+\tstruct vhost_reconnect_vring *log;\n } __rte_cache_aligned;\n \n /* Virtio device status as per Virtio specification */\n@@ -537,6 +552,8 @@ struct virtio_net {\n \tstruct rte_vhost_user_extern_ops extern_ops;\n \n \tstruct vhost_backend_ops *backend_ops;\n+\n+\tstruct vhost_reconnect_data *log;\n } __rte_cache_aligned;\n \n static inline void\n@@ -582,6 +599,10 @@ vq_inc_last_avail_packed(struct vhost_virtqueue *vq, uint16_t num)\n \t\tvq->avail_wrap_counter ^= 1;\n \t\tvq->last_avail_idx -= vq->size;\n \t}\n+\tif (vq->log) {\n+\t\tvq->log->last_avail_idx = vq->last_avail_idx;\n+\t\tvq->log->avail_wrap_counter = vq->avail_wrap_counter;\n+\t}\n }\n \n void __vhost_log_cache_write(struct virtio_net *dev,\n",
    "prefixes": [
        "RFC",
        "v1",
        "1/2"
    ]
}