get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

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

{
    "id": 44292,
    "url": "http://patches.dpdk.org/api/patches/44292/?format=api",
    "web_url": "http://patches.dpdk.org/project/dpdk/patch/20180905042852.6212-3-tiwei.bie@intel.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": "<20180905042852.6212-3-tiwei.bie@intel.com>",
    "list_archive_url": "https://inbox.dpdk.org/dev/20180905042852.6212-3-tiwei.bie@intel.com",
    "date": "2018-09-05T04:28:51",
    "name": "[2/3] net/virtio-user: avoid parsing process mappings",
    "commit_ref": null,
    "pull_url": null,
    "state": "accepted",
    "archived": true,
    "hash": "99ab90632577e3fc3605ab767f11dac64a7af0b2",
    "submitter": {
        "id": 617,
        "url": "http://patches.dpdk.org/api/people/617/?format=api",
        "name": "Tiwei Bie",
        "email": "tiwei.bie@intel.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/20180905042852.6212-3-tiwei.bie@intel.com/mbox/",
    "series": [
        {
            "id": 1180,
            "url": "http://patches.dpdk.org/api/series/1180/?format=api",
            "web_url": "http://patches.dpdk.org/project/dpdk/list/?series=1180",
            "date": "2018-09-05T04:28:49",
            "name": "Some fixes/improvements for virtio-user memory table",
            "version": 1,
            "mbox": "http://patches.dpdk.org/series/1180/mbox/"
        }
    ],
    "comments": "http://patches.dpdk.org/api/patches/44292/comments/",
    "check": "fail",
    "checks": "http://patches.dpdk.org/api/patches/44292/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 7CE664CB5;\n\tWed,  5 Sep 2018 06:31:08 +0200 (CEST)",
            "from mga18.intel.com (mga18.intel.com [134.134.136.126])\n\tby dpdk.org (Postfix) with ESMTP id 4570028FD\n\tfor <dev@dpdk.org>; Wed,  5 Sep 2018 06:31:02 +0200 (CEST)",
            "from fmsmga008.fm.intel.com ([10.253.24.58])\n\tby orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384;\n\t04 Sep 2018 21:31:00 -0700",
            "from btwcube1.sh.intel.com ([10.67.104.194])\n\tby fmsmga008.fm.intel.com with ESMTP; 04 Sep 2018 21:29:49 -0700"
        ],
        "X-Amp-Result": "SKIPPED(no attachment in message)",
        "X-Amp-File-Uploaded": "False",
        "X-ExtLoop1": "1",
        "X-IronPort-AV": "E=Sophos;i=\"5.53,332,1531810800\"; d=\"scan'208\";a=\"68456350\"",
        "From": "Tiwei Bie <tiwei.bie@intel.com>",
        "To": "maxime.coquelin@redhat.com,\n\tzhihong.wang@intel.com,\n\tdev@dpdk.org",
        "Cc": "seanbh@gmail.com,\n\tanatoly.burakov@intel.com",
        "Date": "Wed,  5 Sep 2018 12:28:51 +0800",
        "Message-Id": "<20180905042852.6212-3-tiwei.bie@intel.com>",
        "X-Mailer": "git-send-email 2.18.0",
        "In-Reply-To": "<20180905042852.6212-1-tiwei.bie@intel.com>",
        "References": "<20180905042852.6212-1-tiwei.bie@intel.com>",
        "Subject": "[dpdk-dev] [PATCH 2/3] net/virtio-user: avoid parsing process\n\tmappings",
        "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": "Recently some memory APIs were introduced to allow users to\nget the file descriptor and offset for each memory segment.\nWe can leverage those APIs to get rid of the /proc magic on\nmemory table preparation in vhost-user backend.\n\nSigned-off-by: Tiwei Bie <tiwei.bie@intel.com>\n---\n drivers/net/virtio/virtio_user/vhost_user.c | 211 +++++++++-----------\n 1 file changed, 90 insertions(+), 121 deletions(-)",
    "diff": "diff --git a/drivers/net/virtio/virtio_user/vhost_user.c b/drivers/net/virtio/virtio_user/vhost_user.c\nindex ef6e43df8..8bd49610b 100644\n--- a/drivers/net/virtio/virtio_user/vhost_user.c\n+++ b/drivers/net/virtio/virtio_user/vhost_user.c\n@@ -11,6 +11,9 @@\n #include <string.h>\n #include <errno.h>\n \n+#include <rte_fbarray.h>\n+#include <rte_eal_memconfig.h>\n+\n #include \"vhost.h\"\n #include \"virtio_user_dev.h\"\n \n@@ -121,133 +124,103 @@ vhost_user_read(int fd, struct vhost_user_msg *msg)\n \treturn -1;\n }\n \n-struct hugepage_file_info {\n-\tuint64_t addr;            /**< virtual addr */\n-\tsize_t   size;            /**< the file size */\n-\tchar     path[PATH_MAX];  /**< path to backing file */\n+struct walk_arg {\n+\tstruct vhost_memory *vm;\n+\tint *fds;\n+\tint region_nr;\n };\n \n-/* Two possible options:\n- * 1. Match HUGEPAGE_INFO_FMT to find the file storing struct hugepage_file\n- * array. This is simple but cannot be used in secondary process because\n- * secondary process will close and munmap that file.\n- * 2. Match HUGEFILE_FMT to find hugepage files directly.\n- *\n- * We choose option 2.\n- */\n static int\n-get_hugepage_file_info(struct hugepage_file_info huges[], int max)\n+update_memory_region(const struct rte_memseg_list *msl __rte_unused,\n+\t\tconst struct rte_memseg *ms, void *arg)\n {\n-\tint idx, k, exist;\n-\tFILE *f;\n-\tchar buf[BUFSIZ], *tmp, *tail;\n-\tchar *str_underline, *str_start;\n-\tint huge_index;\n-\tuint64_t v_start, v_end;\n-\tstruct stat stats;\n-\n-\tf = fopen(\"/proc/self/maps\", \"r\");\n-\tif (!f) {\n-\t\tPMD_DRV_LOG(ERR, \"cannot open /proc/self/maps\");\n-\t\treturn -1;\n-\t}\n-\n-\tidx = 0;\n-\twhile (fgets(buf, sizeof(buf), f) != NULL) {\n-\t\tif (sscanf(buf, \"%\" PRIx64 \"-%\" PRIx64, &v_start, &v_end) < 2) {\n-\t\t\tPMD_DRV_LOG(ERR, \"Failed to parse address\");\n-\t\t\tgoto error;\n-\t\t}\n-\n-\t\ttmp = strchr(buf, ' ') + 1; /** skip address */\n-\t\ttmp = strchr(tmp, ' ') + 1; /** skip perm */\n-\t\ttmp = strchr(tmp, ' ') + 1; /** skip offset */\n-\t\ttmp = strchr(tmp, ' ') + 1; /** skip dev */\n-\t\ttmp = strchr(tmp, ' ') + 1; /** skip inode */\n-\t\twhile (*tmp == ' ')         /** skip spaces */\n-\t\t\ttmp++;\n-\t\ttail = strrchr(tmp, '\\n');  /** remove newline if exists */\n-\t\tif (tail)\n-\t\t\t*tail = '\\0';\n-\n-\t\t/* Match HUGEFILE_FMT, aka \"%s/%smap_%d\",\n-\t\t * which is defined in eal_filesystem.h\n-\t\t */\n-\t\tstr_underline = strrchr(tmp, '_');\n-\t\tif (!str_underline)\n-\t\t\tcontinue;\n-\n-\t\tstr_start = str_underline - strlen(\"map\");\n-\t\tif (str_start < tmp)\n-\t\t\tcontinue;\n-\n-\t\tif (sscanf(str_start, \"map_%d\", &huge_index) != 1)\n-\t\t\tcontinue;\n-\n-\t\t/* skip duplicated file which is mapped to different regions */\n-\t\tfor (k = 0, exist = -1; k < idx; ++k) {\n-\t\t\tif (!strcmp(huges[k].path, tmp)) {\n-\t\t\t\texist = k;\n-\t\t\t\tbreak;\n-\t\t\t}\n-\t\t}\n-\t\tif (exist >= 0)\n-\t\t\tcontinue;\n-\n-\t\tif (idx >= max) {\n-\t\t\tPMD_DRV_LOG(ERR, \"Exceed maximum of %d\", max);\n-\t\t\tgoto error;\n-\t\t}\n-\n-\t\thuges[idx].addr = v_start;\n-\t\thuges[idx].size = v_end - v_start; /* To be corrected later */\n-\t\tsnprintf(huges[idx].path, PATH_MAX, \"%s\", tmp);\n-\t\tidx++;\n-\t}\n-\n-\t/* correct the size for files who have many regions */\n-\tfor (k = 0; k < idx; ++k) {\n-\t\tif (stat(huges[k].path, &stats) < 0) {\n-\t\t\tPMD_DRV_LOG(ERR, \"Failed to stat %s, %s\\n\",\n-\t\t\t\t    huges[k].path, strerror(errno));\n-\t\t\tcontinue;\n-\t\t}\n-\t\thuges[k].size = stats.st_size;\n-\t\tPMD_DRV_LOG(INFO, \"file %s, size %zx\\n\",\n-\t\t\t    huges[k].path, huges[k].size);\n-\t}\n-\n-\tfclose(f);\n-\treturn idx;\n-\n-error:\n-\tfclose(f);\n-\treturn -1;\n-}\n-\n-static int\n-prepare_vhost_memory_user(struct vhost_user_msg *msg, int fds[])\n-{\n-\tint i, num;\n-\tstruct hugepage_file_info huges[VHOST_MEMORY_MAX_NREGIONS];\n+\tstruct walk_arg *wa = arg;\n \tstruct vhost_memory_region *mr;\n+\tuint64_t start_addr, end_addr;\n+\tsize_t offset;\n+\tint i, fd;\n \n-\tnum = get_hugepage_file_info(huges, VHOST_MEMORY_MAX_NREGIONS);\n-\tif (num < 0) {\n-\t\tPMD_INIT_LOG(ERR, \"Failed to prepare memory for vhost-user\");\n+\tfd = rte_memseg_get_fd_thread_unsafe(ms);\n+\tif (fd < 0) {\n+\t\tPMD_DRV_LOG(ERR, \"Failed to get fd, ms=%p rte_errno=%d\",\n+\t\t\tms, rte_errno);\n \t\treturn -1;\n \t}\n \n-\tfor (i = 0; i < num; ++i) {\n-\t\tmr = &msg->payload.memory.regions[i];\n-\t\tmr->guest_phys_addr = huges[i].addr; /* use vaddr! */\n-\t\tmr->userspace_addr = huges[i].addr;\n-\t\tmr->memory_size = huges[i].size;\n-\t\tmr->mmap_offset = 0;\n-\t\tfds[i] = open(huges[i].path, O_RDWR);\n+\tif (rte_memseg_get_fd_offset_thread_unsafe(ms, &offset) < 0) {\n+\t\tPMD_DRV_LOG(ERR, \"Failed to get offset, ms=%p rte_errno=%d\",\n+\t\t\tms, rte_errno);\n+\t\treturn -1;\n+\t}\n+\n+\tstart_addr = (uint64_t)(uintptr_t)ms->addr;\n+\tend_addr = start_addr + ms->len;\n+\n+\tfor (i = 0; i < wa->region_nr; i++) {\n+\t\tif (wa->fds[i] != fd)\n+\t\t\tcontinue;\n+\n+\t\tmr = &wa->vm->regions[i];\n+\n+\t\tif (mr->userspace_addr + mr->memory_size < end_addr)\n+\t\t\tmr->memory_size = end_addr - mr->userspace_addr;\n+\n+\t\tif (mr->userspace_addr > start_addr) {\n+\t\t\tmr->userspace_addr = start_addr;\n+\t\t\tmr->guest_phys_addr = start_addr;\n+\t\t}\n+\n+\t\tif (mr->mmap_offset > offset)\n+\t\t\tmr->mmap_offset = offset;\n+\n+\t\tPMD_DRV_LOG(DEBUG, \"index=%d fd=%d offset=0x%\" PRIx64\n+\t\t\t\" addr=0x%\" PRIx64 \" len=%\" PRIu64, i, fd,\n+\t\t\tmr->mmap_offset, mr->userspace_addr,\n+\t\t\tmr->memory_size);\n+\n+\t\treturn 0;\n+\t}\n+\n+\tif (i >= VHOST_MEMORY_MAX_NREGIONS) {\n+\t\tPMD_DRV_LOG(ERR, \"Too many memory regions\");\n+\t\treturn -1;\n \t}\n \n-\tmsg->payload.memory.nregions = num;\n+\tmr = &wa->vm->regions[i];\n+\twa->fds[i] = fd;\n+\n+\tmr->guest_phys_addr = start_addr;\n+\tmr->userspace_addr = start_addr;\n+\tmr->memory_size = ms->len;\n+\tmr->mmap_offset = offset;\n+\n+\tPMD_DRV_LOG(DEBUG, \"index=%d fd=%d offset=0x%\" PRIx64\n+\t\t\" addr=0x%\" PRIx64 \" len=%\" PRIu64, i, fd,\n+\t\tmr->mmap_offset, mr->userspace_addr,\n+\t\tmr->memory_size);\n+\n+\twa->region_nr++;\n+\n+\treturn 0;\n+}\n+\n+static int\n+prepare_vhost_memory_user(struct vhost_user_msg *msg, int fds[])\n+{\n+\tstruct walk_arg wa;\n+\n+\twa.region_nr = 0;\n+\twa.vm = &msg->payload.memory;\n+\twa.fds = fds;\n+\n+\t/*\n+\t * The memory lock has already been taken by memory subsystem\n+\t * or virtio_user_start_device().\n+\t */\n+\tif (rte_memseg_walk_thread_unsafe(update_memory_region, &wa) < 0)\n+\t\treturn -1;\n+\n+\tmsg->payload.memory.nregions = wa.region_nr;\n \tmsg->payload.memory.padding = 0;\n \n \treturn 0;\n@@ -280,7 +253,7 @@ vhost_user_sock(struct virtio_user_dev *dev,\n \tint need_reply = 0;\n \tint fds[VHOST_MEMORY_MAX_NREGIONS];\n \tint fd_num = 0;\n-\tint i, len;\n+\tint len;\n \tint vhostfd = dev->vhostfd;\n \n \tRTE_SET_USED(m);\n@@ -364,10 +337,6 @@ vhost_user_sock(struct virtio_user_dev *dev,\n \t\treturn -1;\n \t}\n \n-\tif (req == VHOST_USER_SET_MEM_TABLE)\n-\t\tfor (i = 0; i < fd_num; ++i)\n-\t\t\tclose(fds[i]);\n-\n \tif (need_reply) {\n \t\tif (vhost_user_read(vhostfd, &msg) < 0) {\n \t\t\tPMD_DRV_LOG(ERR, \"Received msg failed: %s\",\n",
    "prefixes": [
        "2/3"
    ]
}