get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

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

{
    "id": 2511,
    "url": "https://patches.dpdk.org/api/patches/2511/?format=api",
    "web_url": "https://patches.dpdk.org/project/dpdk/patch/1422242440-28948-12-git-send-email-huawei.xie@intel.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": "<1422242440-28948-12-git-send-email-huawei.xie@intel.com>",
    "list_archive_url": "https://inbox.dpdk.org/dev/1422242440-28948-12-git-send-email-huawei.xie@intel.com",
    "date": "2015-01-26T03:20:37",
    "name": "[dpdk-dev,RFC,v2,11/14] vhost user memory region map",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": true,
    "hash": "1266e27552783b91da809b14b06a28290a94bfa7",
    "submitter": {
        "id": 16,
        "url": "https://patches.dpdk.org/api/people/16/?format=api",
        "name": "Huawei Xie",
        "email": "huawei.xie@intel.com"
    },
    "delegate": null,
    "mbox": "https://patches.dpdk.org/project/dpdk/patch/1422242440-28948-12-git-send-email-huawei.xie@intel.com/mbox/",
    "series": [],
    "comments": "https://patches.dpdk.org/api/patches/2511/comments/",
    "check": "pending",
    "checks": "https://patches.dpdk.org/api/patches/2511/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 [IPv6:::1])\n\tby dpdk.org (Postfix) with ESMTP id 61CD65ABF;\n\tMon, 26 Jan 2015 04:21:45 +0100 (CET)",
            "from mga01.intel.com (mga01.intel.com [192.55.52.88])\n\tby dpdk.org (Postfix) with ESMTP id 315355A6D\n\tfor <dev@dpdk.org>; Mon, 26 Jan 2015 04:21:40 +0100 (CET)",
            "from orsmga002.jf.intel.com ([10.7.209.21])\n\tby fmsmga101.fm.intel.com with ESMTP; 25 Jan 2015 19:21:39 -0800",
            "from shvmail01.sh.intel.com ([10.239.29.42])\n\tby orsmga002.jf.intel.com with ESMTP; 25 Jan 2015 19:21:38 -0800",
            "from shecgisg003.sh.intel.com (shecgisg003.sh.intel.com\n\t[10.239.29.90])\n\tby shvmail01.sh.intel.com with ESMTP id t0Q3LZaN015297;\n\tMon, 26 Jan 2015 11:21:35 +0800",
            "from shecgisg003.sh.intel.com (localhost [127.0.0.1])\n\tby shecgisg003.sh.intel.com (8.13.6/8.13.6/SuSE Linux 0.8) with ESMTP\n\tid t0Q3LXSb029060; Mon, 26 Jan 2015 11:21:35 +0800",
            "(from hxie5@localhost)\n\tby shecgisg003.sh.intel.com (8.13.6/8.13.6/Submit) id t0Q3LXoR029056; \n\tMon, 26 Jan 2015 11:21:33 +0800"
        ],
        "X-ExtLoop1": "1",
        "X-IronPort-AV": "E=Sophos;i=\"5.09,466,1418112000\"; d=\"scan'208\";a=\"675806188\"",
        "From": "Huawei Xie <huawei.xie@intel.com>",
        "To": "dev@dpdk.org",
        "Date": "Mon, 26 Jan 2015 11:20:37 +0800",
        "Message-Id": "<1422242440-28948-12-git-send-email-huawei.xie@intel.com>",
        "X-Mailer": "git-send-email 1.7.4.1",
        "In-Reply-To": "<1422242440-28948-1-git-send-email-huawei.xie@intel.com>",
        "References": "<1422242440-28948-1-git-send-email-huawei.xie@intel.com>",
        "Subject": "[dpdk-dev] [RFC PATCH v2 11/14] vhost user memory region map",
        "X-BeenThere": "dev@dpdk.org",
        "X-Mailman-Version": "2.1.15",
        "Precedence": "list",
        "List-Id": "patches and discussions about DPDK <dev.dpdk.org>",
        "List-Unsubscribe": "<http://dpdk.org/ml/options/dev>,\n\t<mailto:dev-request@dpdk.org?subject=unsubscribe>",
        "List-Archive": "<http://dpdk.org/ml/archives/dev/>",
        "List-Post": "<mailto:dev@dpdk.org>",
        "List-Help": "<mailto:dev-request@dpdk.org?subject=help>",
        "List-Subscribe": "<http://dpdk.org/ml/listinfo/dev>,\n\t<mailto:dev-request@dpdk.org?subject=subscribe>",
        "Errors-To": "dev-bounces@dpdk.org",
        "Sender": "\"dev\" <dev-bounces@dpdk.org>"
    },
    "content": "Signed-off-by: Huawei Xie <huawei.xie@intel.com>\n---\n lib/librte_vhost/rte_virtio_net.h             |   2 +\n lib/librte_vhost/vhost-net.h                  |   2 -\n lib/librte_vhost/vhost_user/vhost-net-user.h  |   3 +-\n lib/librte_vhost/vhost_user/virtio-net-user.c | 109 ++++++++++++++++++++++++--\n 4 files changed, 104 insertions(+), 12 deletions(-)",
    "diff": "diff --git a/lib/librte_vhost/rte_virtio_net.h b/lib/librte_vhost/rte_virtio_net.h\nindex 0bf07c7..46c2072 100644\n--- a/lib/librte_vhost/rte_virtio_net.h\n+++ b/lib/librte_vhost/rte_virtio_net.h\n@@ -50,6 +50,8 @@\n #include <rte_mempool.h>\n #include <rte_mbuf.h>\n \n+#define VHOST_MEMORY_MAX_NREGIONS 8\n+\n /* Used to indicate that the device is running on a data core */\n #define VIRTIO_DEV_RUNNING 1\n \ndiff --git a/lib/librte_vhost/vhost-net.h b/lib/librte_vhost/vhost-net.h\nindex 3f18f25..94b359f 100644\n--- a/lib/librte_vhost/vhost-net.h\n+++ b/lib/librte_vhost/vhost-net.h\n@@ -43,8 +43,6 @@\n \n #include \"rte_virtio_net.h\"\n \n-#define VHOST_MEMORY_MAX_NREGIONS 8\n-\n extern struct vhost_net_device_ops const *ops;\n \n /* Macros for printing using RTE_LOG */\ndiff --git a/lib/librte_vhost/vhost_user/vhost-net-user.h b/lib/librte_vhost/vhost_user/vhost-net-user.h\nindex 7e6cda4..91e8fc3 100644\n--- a/lib/librte_vhost/vhost_user/vhost-net-user.h\n+++ b/lib/librte_vhost/vhost_user/vhost-net-user.h\n@@ -37,6 +37,7 @@\n #include <stdint.h>\n #include <linux/vhost.h>\n \n+#include \"rte_virtio_net.h\"\n #include \"fd_man.h\"\n \n struct vhost_server {\n@@ -47,8 +48,6 @@ struct vhost_server {\n \n /* refer to hw/virtio/vhost-user.c */\n \n-#define VHOST_MEMORY_MAX_NREGIONS    8\n-\n typedef enum VhostUserRequest {\n \tVHOST_USER_NONE = 0,\n \tVHOST_USER_GET_FEATURES = 1,\ndiff --git a/lib/librte_vhost/vhost_user/virtio-net-user.c b/lib/librte_vhost/vhost_user/virtio-net-user.c\nindex 6601fcd..3481eb8 100644\n--- a/lib/librte_vhost/vhost_user/virtio-net-user.c\n+++ b/lib/librte_vhost/vhost_user/virtio-net-user.c\n@@ -36,7 +36,11 @@\n #include <stdlib.h>\n #include <unistd.h>\n #include <sys/mman.h>\n+#include <sys/types.h>\n+#include <sys/stat.h>\n+#include <unistd.h>\n \n+#include <rte_common.h>\n #include <rte_log.h>\n \n #include \"virtio-net.h\"\n@@ -44,13 +48,59 @@\n #include \"vhost-net-user.h\"\n #include \"vhost-net.h\"\n \n+struct orig_region_map {\n+\tint fd;\n+\tuint64_t mapped_address;\n+\tuint64_t mapped_size;\n+\tuint64_t blksz;\n+};\n+\n+#define orig_region(ptr, nregions) ((struct orig_region_map *)RTE_PTR_ADD(ptr, \\\n+\t\tsizeof(struct virtio_memory) + \\\n+\t\tsizeof(struct virtio_memory_regions) * (nregions)))\n+\n+static uint64_t\n+get_blk_size(int fd)\n+{\n+\tstruct stat stat;\n+\n+\tfstat(fd, &stat);\n+\treturn (uint64_t)stat.st_blksize;\n+}\n+\n int\n user_set_mem_table(struct vhost_device_ctx ctx, struct VhostUserMsg *pmsg)\n {\n-\tunsigned int idx;\n \tstruct VhostUserMemory memory = pmsg->payload.memory;\n \tstruct virtio_memory_regions regions[VHOST_MEMORY_MAX_NREGIONS];\n-\tuint64_t mapped_address, base_address = 0;\n+\tuint64_t mapped_address, mapped_size, base_address = 0;\n+\tstruct virtio_net *dev;\n+\tunsigned int idx = 0;\n+\tstruct orig_region_map tmp[VHOST_MEMORY_MAX_NREGIONS] = {\n+\t\t[0 ... VHOST_MEMORY_MAX_NREGIONS - 1] = { 0 } };\n+\tstruct orig_region_map *region;\n+\tuint64_t alignment;\n+\tint ret;\n+\n+\t/* unmap old memory regions one by one*/\n+\tdev = get_device(ctx);\n+\tif (dev->mem) {\n+\t\tregion = orig_region(dev->mem, dev->mem->nregions);\n+\t\tfor (idx = 0; idx < dev->mem->nregions; idx++) {\n+\t\t\tif (region[idx].mapped_address) {\n+\t\t\t\talignment = region[idx].blksz;\n+\t\t\t\tprintf(\"Freeing %p\\n\",\n+\t\t\t\t\t(void *)(uintptr_t)region[idx].mapped_address);\n+\t\t\t\tret = munmap((void *)RTE_ALIGN_FLOOR(region[idx].mapped_address, alignment),\n+\t\t\t\t\tRTE_ALIGN_CEIL(region[idx].mapped_size, alignment));\n+\t\t\t\tprintf(\"munmap ret= %d\\n\", ret);\n+\t\t\t\tprintf(\"close file %d\\n\", region[idx].fd);\n+\t\t\t\tclose(region[idx].fd);\n+\t\t\t}\n+\t\t}\n+\t\tfree(dev->mem);\n+\t\tdev->mem = NULL;\n+\t}\n \n \tfor (idx = 0; idx < memory.nregions; idx++) {\n \t\tif (memory.regions[idx].guest_phys_addr == 0)\n@@ -73,22 +123,30 @@ user_set_mem_table(struct vhost_device_ctx ctx, struct VhostUserMsg *pmsg)\n \t\t\tmemory.regions[idx].userspace_addr;\n \n \t\t/* This is ugly */\n+\t\tmapped_size = regions[idx].memory_size +\n+\t\t\tmemory.regions[idx].mmap_offset;\n \t\tmapped_address = (uint64_t)(uintptr_t)mmap(NULL,\n-\t\t\tregions[idx].memory_size +\n-\t\t\t\tmemory.regions[idx].mmap_offset,\n+\t\t\tmapped_size,\n \t\t\tPROT_READ | PROT_WRITE, MAP_SHARED,\n \t\t\tpmsg->fds[idx],\n \t\t\t0);\n+\n \t\tRTE_LOG(INFO, VHOST_CONFIG,\n-\t\t\t\"mapped region %d to %p\\n\",\n-\t\t\tidx, (void *)mapped_address);\n+\t\t\t\"mapped region %d fd:%d to %p sz:0x%\"PRIx64\" off:0x%\"PRIx64\"\\n\",\n+\t\t\tidx, pmsg->fds[idx], (void *)mapped_address,\n+\t\t\tmapped_size, memory.regions[idx].mmap_offset);\n \n \t\tif (mapped_address == (uint64_t)(uintptr_t)MAP_FAILED) {\n \t\t\tRTE_LOG(ERR, VHOST_CONFIG,\n \t\t\t\t\"mmap qemu guest failed.\\n\");\n-\t\t\treturn -1;\n+\t\t\tgoto err;\n \t\t}\n \n+\t\ttmp[idx].mapped_address = mapped_address;\n+\t\ttmp[idx].mapped_size = mapped_size;\n+\t\ttmp[idx].blksz = get_blk_size(pmsg->fds[idx]);\n+\t\ttmp[idx].fd = pmsg->fds[idx];\n+\n \t\tmapped_address +=  memory.regions[idx].mmap_offset;\n \n \t\tregions[idx].address_offset = mapped_address -\n@@ -100,10 +158,45 @@ user_set_mem_table(struct vhost_device_ctx ctx, struct VhostUserMsg *pmsg)\n \t\t\t(void *)(uintptr_t)regions[idx].userspace_address,\n \t\t\t regions[idx].memory_size);\n \t}\n+\n \tops->set_mem_table(ctx, regions, memory.nregions);\n+\n+\tif (dev->mem) {\n+\t\tvoid *tmp_mem;\n+\t\ttmp_mem = realloc(dev->mem,\n+\t\t\tsizeof(struct virtio_memory) +\n+\t\t\tsizeof(struct virtio_memory_regions) * memory.nregions +\n+\t\t\tsizeof(struct orig_region_map) * memory.nregions);\n+\t\tif (tmp_mem == NULL)\n+\t\t\tgoto err_realloc;\n+\n+\t\tdev->mem = tmp_mem;\n+\t\tregion = orig_region(dev->mem, memory.nregions);\n+\t\tfor (idx = 0; idx < memory.nregions; idx++) {\n+\t\t\tregion[idx].mapped_address = tmp[idx].mapped_address;\n+\t\t\tregion[idx].mapped_size = tmp[idx].mapped_size;\n+\t\t\tregion[idx].blksz = tmp[idx].blksz;\n+\t\t\tregion[idx].fd = tmp[idx].fd;\n+\t\t}\n+\t} else\n+\t\tgoto err_set_mem_table;\n+\n \treturn 0;\n-}\n \n+err_realloc:\n+\tfree(dev->mem);\n+err_set_mem_table:\n+err:\n+\twhile (idx--) {\n+\t\talignment = tmp[idx].blksz;\n+\t\tmunmap((void *)RTE_ALIGN_FLOOR(\n+\t\t\ttmp[idx].mapped_address, alignment),\n+\t\t\tRTE_ALIGN_CEIL(tmp[idx].mapped_size, alignment));\n+\t\tclose(tmp[idx].fd);\n+\t}\n+\tdev->mem = NULL;\n+\treturn -1;\n+}\n \n static int\n virtio_is_ready(struct virtio_net *dev)\n",
    "prefixes": [
        "dpdk-dev",
        "RFC",
        "v2",
        "11/14"
    ]
}