get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

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

{
    "id": 2506,
    "url": "https://patches.dpdk.org/api/patches/2506/?format=api",
    "web_url": "https://patches.dpdk.org/project/dpdk/patch/1422242440-28948-7-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-7-git-send-email-huawei.xie@intel.com>",
    "list_archive_url": "https://inbox.dpdk.org/dev/1422242440-28948-7-git-send-email-huawei.xie@intel.com",
    "date": "2015-01-26T03:20:32",
    "name": "[dpdk-dev,RFC,v2,06/14] copy host_memory_map from virtio-net.c to a new file virtio-net-cdev.c",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": true,
    "hash": "a7f40a80d365a25aad0b8d2be647d5b86e1adddc",
    "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-7-git-send-email-huawei.xie@intel.com/mbox/",
    "series": [],
    "comments": "https://patches.dpdk.org/api/patches/2506/comments/",
    "check": "pending",
    "checks": "https://patches.dpdk.org/api/patches/2506/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 17F735AA1;\n\tMon, 26 Jan 2015 04:21:34 +0100 (CET)",
            "from mga14.intel.com (mga14.intel.com [192.55.52.115])\n\tby dpdk.org (Postfix) with ESMTP id 4D09BCF9\n\tfor <dev@dpdk.org>; Mon, 26 Jan 2015 04:21:15 +0100 (CET)",
            "from orsmga002.jf.intel.com ([10.7.209.21])\n\tby fmsmga103.fm.intel.com with ESMTP; 25 Jan 2015 19:15:13 -0800",
            "from shvmail01.sh.intel.com ([10.239.29.42])\n\tby orsmga002.jf.intel.com with ESMTP; 25 Jan 2015 19:21:12 -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 t0Q3L9Ij014287;\n\tMon, 26 Jan 2015 11:21:09 +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 t0Q3L7xa029025; Mon, 26 Jan 2015 11:21:09 +0800",
            "(from hxie5@localhost)\n\tby shecgisg003.sh.intel.com (8.13.6/8.13.6/Submit) id t0Q3L75b029021; \n\tMon, 26 Jan 2015 11:21:07 +0800"
        ],
        "X-ExtLoop1": "1",
        "X-IronPort-AV": "E=Sophos;i=\"5.09,466,1418112000\"; d=\"scan'208\";a=\"675806104\"",
        "From": "Huawei Xie <huawei.xie@intel.com>",
        "To": "dev@dpdk.org",
        "Date": "Mon, 26 Jan 2015 11:20:32 +0800",
        "Message-Id": "<1422242440-28948-7-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 06/14] copy host_memory_map from\n\tvirtio-net.c to a new file virtio-net-cdev.c",
        "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/vhost_cuse/virtio-net-cdev.c | 258 ++++++++++++++++++++++++++\n 1 file changed, 258 insertions(+)\n create mode 100644 lib/librte_vhost/vhost_cuse/virtio-net-cdev.c",
    "diff": "diff --git a/lib/librte_vhost/vhost_cuse/virtio-net-cdev.c b/lib/librte_vhost/vhost_cuse/virtio-net-cdev.c\nnew file mode 100644\nindex 0000000..fbfc403\n--- /dev/null\n+++ b/lib/librte_vhost/vhost_cuse/virtio-net-cdev.c\n@@ -0,0 +1,258 @@\n+/*-\n+ *   BSD LICENSE\n+ *\n+ *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.\n+ *   All rights reserved.\n+ *\n+ *   Redistribution and use in source and binary forms, with or without\n+ *   modification, are permitted provided that the following conditions\n+ *   are met:\n+ *\n+ *     * Redistributions of source code must retain the above copyright\n+ *       notice, this list of conditions and the following disclaimer.\n+ *     * Redistributions in binary form must reproduce the above copyright\n+ *       notice, this list of conditions and the following disclaimer in\n+ *       the documentation and/or other materials provided with the\n+ *       distribution.\n+ *     * Neither the name of Intel Corporation nor the names of its\n+ *       contributors may be used to endorse or promote products derived\n+ *       from this software without specific prior written permission.\n+ *\n+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n+ *   \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\n+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\n+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\n+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\n+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n+ *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n+ */\n+\n+#include <stdint.h>\n+#include <dirent.h>\n+#include <linux/vhost.h>\n+#include <linux/virtio_net.h>\n+#include <fuse/cuse_lowlevel.h>\n+#include <stddef.h>\n+#include <string.h>\n+#include <stdlib.h>\n+#include <sys/eventfd.h>\n+#include <sys/mman.h>\n+#include <sys/types.h>\n+#include <unistd.h>\n+#include <errno.h>\n+\n+#include <rte_log.h>\n+\n+#include \"vhost-net.h\"\n+\n+/* Line size for reading maps file. */\n+static const uint32_t BUFSIZE = PATH_MAX;\n+\n+/* Size of prot char array in procmap. */\n+#define PROT_SZ 5\n+\n+/* Number of elements in procmap struct. */\n+#define PROCMAP_SZ 8\n+\n+/* Structure containing information gathered from maps file. */\n+struct procmap {\n+\tuint64_t va_start;\t/* Start virtual address in file. */\n+\tuint64_t len;\t\t/* Size of file. */\n+\tuint64_t pgoff;\t\t/* Not used. */\n+\tuint32_t maj;\t\t/* Not used. */\n+\tuint32_t min;\t\t/* Not used. */\n+\tuint32_t ino;\t\t/* Not used. */\n+\tchar prot[PROT_SZ];\t/* Not used. */\n+\tchar fname[PATH_MAX];\t/* File name. */\n+};\n+\n+/*\n+ * Locate the file containing QEMU's memory space and\n+ * map it to our address space.\n+ */\n+static int\n+host_memory_map(struct virtio_net *dev, struct virtio_memory *mem,\n+\tpid_t pid, uint64_t addr)\n+{\n+\tstruct dirent *dptr = NULL;\n+\tstruct procmap procmap;\n+\tDIR *dp = NULL;\n+\tint fd;\n+\tint i;\n+\tchar memfile[PATH_MAX];\n+\tchar mapfile[PATH_MAX];\n+\tchar procdir[PATH_MAX];\n+\tchar resolved_path[PATH_MAX];\n+\tchar *path = NULL;\n+\tFILE *fmap;\n+\tvoid *map;\n+\tuint8_t found = 0;\n+\tchar line[BUFSIZE];\n+\tchar dlm[] = \"-   :   \";\n+\tchar *str, *sp, *in[PROCMAP_SZ];\n+\tchar *end = NULL;\n+\n+\t/* Path where mem files are located. */\n+\tsnprintf(procdir, PATH_MAX, \"/proc/%u/fd/\", pid);\n+\t/* Maps file used to locate mem file. */\n+\tsnprintf(mapfile, PATH_MAX, \"/proc/%u/maps\", pid);\n+\n+\tfmap = fopen(mapfile, \"r\");\n+\tif (fmap == NULL) {\n+\t\tRTE_LOG(ERR, VHOST_CONFIG,\n+\t\t\t\"(%\"PRIu64\") Failed to open maps file for pid %d\\n\",\n+\t\t\tdev->device_fh, pid);\n+\t\treturn -1;\n+\t}\n+\n+\t/* Read through maps file until we find out base_address. */\n+\twhile (fgets(line, BUFSIZE, fmap) != 0) {\n+\t\tstr = line;\n+\t\terrno = 0;\n+\t\t/* Split line into fields. */\n+\t\tfor (i = 0; i < PROCMAP_SZ; i++) {\n+\t\t\tin[i] = strtok_r(str, &dlm[i], &sp);\n+\t\t\tif ((in[i] == NULL) || (errno != 0)) {\n+\t\t\t\tfclose(fmap);\n+\t\t\t\treturn -1;\n+\t\t\t}\n+\t\t\tstr = NULL;\n+\t\t}\n+\n+\t\t/* Convert/Copy each field as needed. */\n+\t\tprocmap.va_start = strtoull(in[0], &end, 16);\n+\t\tif ((in[0] == '\\0') || (end == NULL) || (*end != '\\0') ||\n+\t\t\t(errno != 0)) {\n+\t\t\tfclose(fmap);\n+\t\t\treturn -1;\n+\t\t}\n+\n+\t\tprocmap.len = strtoull(in[1], &end, 16);\n+\t\tif ((in[1] == '\\0') || (end == NULL) || (*end != '\\0') ||\n+\t\t\t(errno != 0)) {\n+\t\t\tfclose(fmap);\n+\t\t\treturn -1;\n+\t\t}\n+\n+\t\tprocmap.pgoff = strtoull(in[3], &end, 16);\n+\t\tif ((in[3] == '\\0') || (end == NULL) || (*end != '\\0') ||\n+\t\t\t(errno != 0)) {\n+\t\t\tfclose(fmap);\n+\t\t\treturn -1;\n+\t\t}\n+\n+\t\tprocmap.maj = strtoul(in[4], &end, 16);\n+\t\tif ((in[4] == '\\0') || (end == NULL) || (*end != '\\0') ||\n+\t\t\t(errno != 0)) {\n+\t\t\tfclose(fmap);\n+\t\t\treturn -1;\n+\t\t}\n+\n+\t\tprocmap.min = strtoul(in[5], &end, 16);\n+\t\tif ((in[5] == '\\0') || (end == NULL) || (*end != '\\0') ||\n+\t\t\t(errno != 0)) {\n+\t\t\tfclose(fmap);\n+\t\t\treturn -1;\n+\t\t}\n+\n+\t\tprocmap.ino = strtoul(in[6], &end, 16);\n+\t\tif ((in[6] == '\\0') || (end == NULL) || (*end != '\\0') ||\n+\t\t\t(errno != 0)) {\n+\t\t\tfclose(fmap);\n+\t\t\treturn -1;\n+\t\t}\n+\n+\t\tmemcpy(&procmap.prot, in[2], PROT_SZ);\n+\t\tmemcpy(&procmap.fname, in[7], PATH_MAX);\n+\n+\t\tif (procmap.va_start == addr) {\n+\t\t\tprocmap.len = procmap.len - procmap.va_start;\n+\t\t\tfound = 1;\n+\t\t\tbreak;\n+\t\t}\n+\t}\n+\tfclose(fmap);\n+\n+\tif (!found) {\n+\t\tRTE_LOG(ERR, VHOST_CONFIG,\n+\t\t\t\"(%\"PRIu64\") Failed to find memory file in pid %d maps file\\n\",\n+\t\t\tdev->device_fh, pid);\n+\t\treturn -1;\n+\t}\n+\n+\t/* Find the guest memory file among the process fds. */\n+\tdp = opendir(procdir);\n+\tif (dp == NULL) {\n+\t\tRTE_LOG(ERR, VHOST_CONFIG,\n+\t\t\t\"(%\"PRIu64\") Cannot open pid %d process directory\\n\",\n+\t\t\tdev->device_fh, pid);\n+\t\treturn -1;\n+\t}\n+\n+\tfound = 0;\n+\n+\t/* Read the fd directory contents. */\n+\twhile (NULL != (dptr = readdir(dp))) {\n+\t\tsnprintf(memfile, PATH_MAX, \"/proc/%u/fd/%s\",\n+\t\t\t\tpid, dptr->d_name);\n+\t\tpath = realpath(memfile, resolved_path);\n+\t\tif ((path == NULL) && (strlen(resolved_path) == 0)) {\n+\t\t\tRTE_LOG(ERR, VHOST_CONFIG,\n+\t\t\t\t\"(%\"PRIu64\") Failed to resolve fd directory\\n\",\n+\t\t\t\tdev->device_fh);\n+\t\t\tclosedir(dp);\n+\t\t\treturn -1;\n+\t\t}\n+\t\tif (strncmp(resolved_path, procmap.fname,\n+\t\t\tstrnlen(procmap.fname, PATH_MAX)) == 0) {\n+\t\t\tfound = 1;\n+\t\t\tbreak;\n+\t\t}\n+\t}\n+\n+\tclosedir(dp);\n+\n+\tif (found == 0) {\n+\t\tRTE_LOG(ERR, VHOST_CONFIG,\n+\t\t\t\"(%\"PRIu64\") Failed to find memory file for pid %d\\n\",\n+\t\t\tdev->device_fh, pid);\n+\t\treturn -1;\n+\t}\n+\t/* Open the shared memory file and map the memory into this process. */\n+\tfd = open(memfile, O_RDWR);\n+\n+\tif (fd == -1) {\n+\t\tRTE_LOG(ERR, VHOST_CONFIG,\n+\t\t\t\"(%\"PRIu64\") Failed to open %s for pid %d\\n\",\n+\t\t\tdev->device_fh, memfile, pid);\n+\t\treturn -1;\n+\t}\n+\n+\tmap = mmap(0, (size_t)procmap.len, PROT_READ|PROT_WRITE,\n+\t\tMAP_POPULATE|MAP_SHARED, fd, 0);\n+\tclose(fd);\n+\n+\tif (map == MAP_FAILED) {\n+\t\tRTE_LOG(ERR, VHOST_CONFIG,\n+\t\t\t\"(%\"PRIu64\") Error mapping the file %s for pid %d\\n\",\n+\t\t\tdev->device_fh, memfile, pid);\n+\t\treturn -1;\n+\t}\n+\n+\t/* Store the memory address and size in the device data structure */\n+\tmem->mapped_address = (uint64_t)(uintptr_t)map;\n+\tmem->mapped_size = procmap.len;\n+\n+\tLOG_DEBUG(VHOST_CONFIG,\n+\t\t\"(%\"PRIu64\") Mem File: %s->%s - Size: %llu - VA: %p\\n\",\n+\t\tdev->device_fh,\n+\t\tmemfile, resolved_path,\n+\t\t(unsigned long long)mem->mapped_size, map);\n+\n+\treturn 0;\n+}\n+\n",
    "prefixes": [
        "dpdk-dev",
        "RFC",
        "v2",
        "06/14"
    ]
}