get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

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

{
    "id": 1153,
    "url": "https://patches.dpdk.org/api/patches/1153/?format=api",
    "web_url": "https://patches.dpdk.org/project/dpdk/patch/1415272471-3299-4-git-send-email-mukawa@igel.co.jp/",
    "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": "<1415272471-3299-4-git-send-email-mukawa@igel.co.jp>",
    "list_archive_url": "https://inbox.dpdk.org/dev/1415272471-3299-4-git-send-email-mukawa@igel.co.jp",
    "date": "2014-11-06T11:14:27",
    "name": "[dpdk-dev,RFC,3/7] lib/librte_vhost: Add an abstraction layer tointerpret messages",
    "commit_ref": null,
    "pull_url": null,
    "state": "rfc",
    "archived": true,
    "hash": "541ef5da63e3904764550c61fcf1424fbde55ed7",
    "submitter": {
        "id": 64,
        "url": "https://patches.dpdk.org/api/people/64/?format=api",
        "name": "Tetsuya Mukawa",
        "email": "mukawa@igel.co.jp"
    },
    "delegate": null,
    "mbox": "https://patches.dpdk.org/project/dpdk/patch/1415272471-3299-4-git-send-email-mukawa@igel.co.jp/mbox/",
    "series": [],
    "comments": "https://patches.dpdk.org/api/patches/1153/comments/",
    "check": "pending",
    "checks": "https://patches.dpdk.org/api/patches/1153/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 DF9187F34;\n\tThu,  6 Nov 2014 12:05:48 +0100 (CET)",
            "from mail-pd0-f175.google.com (mail-pd0-f175.google.com\n\t[209.85.192.175]) by dpdk.org (Postfix) with ESMTP id 5AED47E80\n\tfor <dev@dpdk.org>; Thu,  6 Nov 2014 12:05:35 +0100 (CET)",
            "by mail-pd0-f175.google.com with SMTP id y13so966246pdi.6\n\tfor <dev@dpdk.org>; Thu, 06 Nov 2014 03:15:01 -0800 (PST)",
            "from localhost.localdomain (napt.igel.co.jp. [219.106.231.132])\n\tby mx.google.com with ESMTPSA id\n\tjc3sm5652315pbb.49.2014.11.06.03.14.59 for <multiple recipients>\n\t(version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128);\n\tThu, 06 Nov 2014 03:15:01 -0800 (PST)"
        ],
        "X-Google-DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20130820;\n\th=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to\n\t:references;\n\tbh=hswaiklQIU4i23qjRNaOTURbXPWBWnZF1kdnqblBDyQ=;\n\tb=g2bLhZ9PD9SJa8fMpSlaI8J//prX6hdOArNgmTweUhmdAFlUvl9OoYGz7O6gAHtdzg\n\t8AUJOqWdPAgcUALMllcwnDTi0E2Vm7yporve3gIko01ay34KM004nlcgUe5/Ps8/cVza\n\t709cPGoD4/cCbyb4AQM0xKoMgZq6zGsIwhLgfj1ToUYfvk3miSQoSUapPuls8SMtrK7j\n\tijL1wsAKtmkPwDWu8lOtfyhtRmeix4fTaNK6eBq3tc7SiwDgzlS+3/kondZS3pghu064\n\tvskXH/zjnFRnYJKZzuSb20ajUUb0wzrRrIsR5TNqnR0vcOJutvdhumdhfVMc5ptC54w2\n\tV1ug==",
        "X-Gm-Message-State": "ALoCoQkO+WueDt3qO/nZwCWRSDNOK9f0G3aBEgZjMo2blp4boM8clFAYKPb+xustP2WzTMHXplLb",
        "X-Received": "by 10.70.5.130 with SMTP id s2mr3683000pds.17.1415272501829;\n\tThu, 06 Nov 2014 03:15:01 -0800 (PST)",
        "From": "Tetsuya Mukawa <mukawa@igel.co.jp>",
        "To": "dev@dpdk.org",
        "Date": "Thu,  6 Nov 2014 20:14:27 +0900",
        "Message-Id": "<1415272471-3299-4-git-send-email-mukawa@igel.co.jp>",
        "X-Mailer": "git-send-email 1.9.1",
        "In-Reply-To": "<1415272471-3299-1-git-send-email-mukawa@igel.co.jp>",
        "References": "<1415272471-3299-1-git-send-email-mukawa@igel.co.jp>",
        "Cc": "nakajima.yoshihiro@lab.ntt.co.jp, masutani.hitoshi@lab.ntt.co.jp",
        "Subject": "[dpdk-dev] [RFC PATCH 3/7] lib/librte_vhost: Add an abstraction\n\tlayer tointerpret messages",
        "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": "This patch adds an abstraction layer to interpret messages from QEMU.\nThis abstraction layer is needed because there are differences in\nmessage formats between vhost-cuse and vhost-user.\n\nSigned-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>\n---\n lib/librte_vhost/vhost-net-cdev.c  |   2 +-\n lib/librte_vhost/vhost-net.h       |   3 +-\n lib/librte_vhost/virtio-net-cdev.c | 492 +++++++++++++++++++++++++++++++++++++\n lib/librte_vhost/virtio-net.c      | 484 ++----------------------------------\n 4 files changed, 517 insertions(+), 464 deletions(-)\n create mode 100644 lib/librte_vhost/virtio-net-cdev.c",
    "diff": "diff --git a/lib/librte_vhost/vhost-net-cdev.c b/lib/librte_vhost/vhost-net-cdev.c\nindex 83e1d14..12d0f68 100644\n--- a/lib/librte_vhost/vhost-net-cdev.c\n+++ b/lib/librte_vhost/vhost-net-cdev.c\n@@ -342,7 +342,7 @@ vhost_cuse_driver_register(struct vhost_driver *drv)\n \tcuse_info.dev_info_argv = device_argv;\n \tcuse_info.flags = CUSE_UNRESTRICTED_IOCTL;\n \n-\tops = get_virtio_net_callbacks();\n+\tops = get_virtio_net_callbacks(drv->type);\n \n \tdrv->session = cuse_lowlevel_setup(3, fuse_argv,\n \t\t\t\t&cuse_info, &vhost_net_ops, 0, NULL);\ndiff --git a/lib/librte_vhost/vhost-net.h b/lib/librte_vhost/vhost-net.h\nindex 03a5c57..09a99ce 100644\n--- a/lib/librte_vhost/vhost-net.h\n+++ b/lib/librte_vhost/vhost-net.h\n@@ -109,5 +109,6 @@ struct vhost_net_device_ops {\n };\n \n \n-struct vhost_net_device_ops const *get_virtio_net_callbacks(void);\n+struct vhost_net_device_ops const *get_virtio_net_callbacks(\n+\t\tvhost_driver_type_t type);\n #endif /* _VHOST_NET_CDEV_H_ */\ndiff --git a/lib/librte_vhost/virtio-net-cdev.c b/lib/librte_vhost/virtio-net-cdev.c\nnew file mode 100644\nindex 0000000..f225bf5\n--- /dev/null\n+++ b/lib/librte_vhost/virtio-net-cdev.c\n@@ -0,0 +1,492 @@\n+/*-\n+ *   BSD LICENSE\n+ *\n+ *   Copyright(c) 2014 IGEL Co.,Ltd. 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 IGEL 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 <dirent.h>\n+#include <sys/ioctl.h>\n+#include <sys/mman.h>\n+#include <unistd.h>\n+\n+#include <rte_virtio_net.h>\n+\n+#include \"vhost-net.h\"\n+#include \"eventfd_link/eventfd_link.h\"\n+\n+const char eventfd_cdev[] = \"/dev/eventfd-link\";\n+\n+/* Line size for reading maps file. */\n+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\tva_start;\t/* Start virtual address in file. */\n+\tuint64_t\tva_end;\t\t/* End virtual address in file. */\n+\tuint64_t\tlen;\t\t/* Size of file. */\n+\tuint64_t\tpgoff;\t\t/* Not used. */\n+\tuint32_t\tmaj;\t\t/* Not used. */\n+\tuint32_t\tmin;\t\t/* Not used. */\n+\tuint32_t\tino;\t\t/* Not used. */\n+\tchar\t\tprot[PROT_SZ];\t/* Not used. */\n+\tchar\t\tfname[PATH_MAX];/* File name. */\n+};\n+\n+/*\n+ * Locate the file containing QEMU's memory space and 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\t\t*fmap;\n+\tvoid\t\t*map;\n+\tuint8_t\t\tfound = 0;\n+\tchar\t\tline[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 in to 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') || (errno != 0)) {\n+\t\t\tfclose(fmap);\n+\t\t\treturn -1;\n+\t\t}\n+\n+\t\tprocmap.va_end = strtoull(in[1], &end, 16);\n+\t\tif ((in[1] == '\\0') || (end == NULL) || (*end != '\\0') || (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') || (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') || (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') || (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') || (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) && (procmap.va_end >= addr)) {\n+\t\t\tprocmap.len = procmap.va_end - 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, \"(%\"PRIu64\") Failed to find memory file in pid %d maps file\\n\", dev->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, \"(%\"PRIu64\") Cannot open pid %d process directory\\n\", dev->device_fh, pid);\n+\t\treturn -1;\n+\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) {\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, \"(%\"PRIu64\") Failed to find memory file for pid %d\\n\", dev->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, \"(%\"PRIu64\") Failed to open %s for pid %d\\n\", dev->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\t\tMAP_POPULATE|MAP_SHARED, fd, 0);\n+\tclose(fd);\n+\n+\tif (map == MAP_FAILED) {\n+\t\tRTE_LOG(ERR, VHOST_CONFIG, \"(%\"PRIu64\") Error mapping the file %s for pid %d\\n\",  dev->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, \"(%\"PRIu64\") Mem File: %s->%s - Size: %llu - VA: %p\\n\", dev->device_fh,\n+\t\tmemfile, resolved_path, (long long unsigned)mem->mapped_size, map);\n+\n+\treturn 0;\n+}\n+\n+/*\n+ * Called from CUSE IOCTL: VHOST_SET_MEM_TABLE\n+ * This function creates and populates the memory structure for the device. This includes\n+ * storing offsets used to translate buffer addresses.\n+ */\n+static int\n+cuse_set_mem_table(struct vhost_device_ctx ctx, const void *mem_regions_addr,\n+\tuint32_t nregions)\n+{\n+\tstruct virtio_net *dev;\n+\tstruct vhost_memory_region *mem_regions;\n+\tstruct virtio_memory *mem;\n+\tuint64_t size = offsetof(struct vhost_memory, regions);\n+\tuint32_t regionidx, valid_regions;\n+\n+\tdev = get_device(ctx);\n+\tif (dev == NULL)\n+\t\treturn -1;\n+\n+\tif (dev->mem) {\n+\t\tmunmap((void *)(uintptr_t)dev->mem->mapped_address,\n+\t\t\t(size_t)dev->mem->mapped_size);\n+\t\tfree(dev->mem);\n+\t}\n+\n+\t/* Malloc the memory structure depending on the number of regions. */\n+\tmem = calloc(1, sizeof(struct virtio_memory) +\n+\t\t(sizeof(struct virtio_memory_regions) * nregions));\n+\tif (mem == NULL) {\n+\t\tRTE_LOG(ERR, VHOST_CONFIG, \"(%\"PRIu64\") Failed to allocate memory for dev->mem.\\n\", dev->device_fh);\n+\t\treturn -1;\n+\t}\n+\n+\tmem->nregions = nregions;\n+\n+\tmem_regions = (void *)(uintptr_t)\n+\t\t\t((uint64_t)(uintptr_t)mem_regions_addr + size);\n+\n+\tfor (regionidx = 0; regionidx < mem->nregions; regionidx++) {\n+\t\t/* Populate the region structure for each region. */\n+\t\tmem->regions[regionidx].guest_phys_address =\n+\t\t\tmem_regions[regionidx].guest_phys_addr;\n+\t\tmem->regions[regionidx].guest_phys_address_end =\n+\t\t\tmem->regions[regionidx].guest_phys_address +\n+\t\t\tmem_regions[regionidx].memory_size;\n+\t\tmem->regions[regionidx].memory_size =\n+\t\t\tmem_regions[regionidx].memory_size;\n+\t\tmem->regions[regionidx].userspace_address =\n+\t\t\tmem_regions[regionidx].userspace_addr;\n+\n+\t\tLOG_DEBUG(VHOST_CONFIG, \"(%\"PRIu64\") REGION: %u - GPA: %p - QEMU VA: %p - SIZE (%\"PRIu64\")\\n\", dev->device_fh,\n+\t\t\t\tregionidx, (void *)(uintptr_t)mem->regions[regionidx].guest_phys_address,\n+\t\t\t\t(void *)(uintptr_t)mem->regions[regionidx].userspace_address,\n+\t\t\t\tmem->regions[regionidx].memory_size);\n+\n+\t\t/*set the base address mapping*/\n+\t\tif (mem->regions[regionidx].guest_phys_address == 0x0) {\n+\t\t\tmem->base_address = mem->regions[regionidx].userspace_address;\n+\t\t\t/* Map VM memory file */\n+\t\t\tif (host_memory_map(dev, mem, ctx.pid, mem->base_address) != 0) {\n+\t\t\t\tfree(mem);\n+\t\t\t\treturn -1;\n+\t\t\t}\n+\t\t}\n+\t}\n+\n+\t/* Check that we have a valid base address. */\n+\tif (mem->base_address == 0) {\n+\t\tRTE_LOG(ERR, VHOST_CONFIG, \"(%\"PRIu64\") Failed to find base address of qemu memory file.\\n\", dev->device_fh);\n+\t\tfree(mem);\n+\t\treturn -1;\n+\t}\n+\n+\t/* Check if all of our regions have valid mappings. Usually one does not exist in the QEMU memory file. */\n+\tvalid_regions = mem->nregions;\n+\tfor (regionidx = 0; regionidx < mem->nregions; regionidx++) {\n+\t\tif ((mem->regions[regionidx].userspace_address < mem->base_address) ||\n+\t\t\t(mem->regions[regionidx].userspace_address > (mem->base_address + mem->mapped_size)))\n+\t\t\t\tvalid_regions--;\n+\t}\n+\n+\t/* If a region does not have a valid mapping we rebuild our memory struct to contain only valid entries. */\n+\tif (valid_regions != mem->nregions) {\n+\t\tLOG_DEBUG(VHOST_CONFIG, \"(%\"PRIu64\") Not all memory regions exist in the QEMU mem file. Re-populating mem structure\\n\",\n+\t\t\tdev->device_fh);\n+\n+\t\t/* Re-populate the memory structure with only valid regions. Invalid regions are over-written with memmove. */\n+\t\tvalid_regions = 0;\n+\n+\t\tfor (regionidx = mem->nregions; 0 != regionidx--;) {\n+\t\t\tif ((mem->regions[regionidx].userspace_address < mem->base_address) ||\n+\t\t\t\t\t(mem->regions[regionidx].userspace_address > (mem->base_address + mem->mapped_size))) {\n+\t\t\t\tmemmove(&mem->regions[regionidx], &mem->regions[regionidx + 1],\n+\t\t\t\t\tsizeof(struct virtio_memory_regions) * valid_regions);\n+\t\t\t} else {\n+\t\t\t\tvalid_regions++;\n+\t\t\t}\n+\t\t}\n+\t}\n+\tmem->nregions = valid_regions;\n+\tdev->mem = mem;\n+\n+\t/*\n+\t * Calculate the address offset for each region. This offset is used to identify the vhost virtual address\n+\t * corresponding to a QEMU guest physical address.\n+\t */\n+\tfor (regionidx = 0; regionidx < dev->mem->nregions; regionidx++) {\n+\t\tdev->mem->regions[regionidx].address_offset = dev->mem->regions[regionidx].userspace_address - dev->mem->base_address\n+\t\t\t+ dev->mem->mapped_address - dev->mem->regions[regionidx].guest_phys_address;\n+\n+\t}\n+\treturn 0;\n+}\n+\n+/*\n+ * Called from CUSE IOCTL: VHOST_GET_VRING_BASE\n+ * We send the virtio device our available ring last used index.\n+ */\n+static int\n+cuse_get_vring_base(struct vhost_device_ctx ctx, uint32_t index,\n+\tstruct vhost_vring_state *state)\n+{\n+\tstruct virtio_net *dev;\n+\n+\tdev = get_device(ctx);\n+\tif (dev == NULL)\n+\t\treturn -1;\n+\n+\tstate->index = index;\n+\t/* State->index refers to the queue index. The TX queue is 1, RX queue is 0. */\n+\tstate->num = dev->virtqueue[state->index]->last_used_idx;\n+\n+\treturn 0;\n+}\n+\n+/*\n+ * This function uses the eventfd_link kernel module to copy an eventfd file descriptor\n+ * provided by QEMU in to our process space.\n+ */\n+static int\n+eventfd_copy(struct virtio_net *dev, struct eventfd_copy *eventfd_copy)\n+{\n+\tint eventfd_link, ret;\n+\n+\t/* Open the character device to the kernel module. */\n+\teventfd_link = open(eventfd_cdev, O_RDWR);\n+\tif (eventfd_link < 0) {\n+\t\tRTE_LOG(ERR, VHOST_CONFIG, \"(%\"PRIu64\") eventfd_link module is not loaded\\n\",  dev->device_fh);\n+\t\treturn -1;\n+\t}\n+\n+\t/* Call the IOCTL to copy the eventfd. */\n+\tret = ioctl(eventfd_link, EVENTFD_COPY, eventfd_copy);\n+\tclose(eventfd_link);\n+\n+\tif (ret < 0) {\n+\t\tRTE_LOG(ERR, VHOST_CONFIG, \"(%\"PRIu64\") EVENTFD_COPY ioctl failed\\n\",  dev->device_fh);\n+\t\treturn -1;\n+\t}\n+\n+\n+\treturn 0;\n+}\n+\n+/*\n+ * Called from CUSE IOCTL: VHOST_SET_VRING_CALL\n+ * The virtio device sends an eventfd to interrupt the guest. This fd gets copied in\n+ * to our process space.\n+ */\n+static int\n+cuse_set_vring_call(struct vhost_device_ctx ctx, struct vhost_vring_file *file)\n+{\n+\tstruct virtio_net *dev;\n+\tstruct eventfd_copy     eventfd_kick;\n+\tstruct vhost_virtqueue *vq;\n+\n+\tdev = get_device(ctx);\n+\tif (dev == NULL)\n+\t\treturn -1;\n+\n+\t/* file->index refers to the queue index. The TX queue is 1, RX queue is 0. */\n+\tvq = dev->virtqueue[file->index];\n+\n+\tif (vq->kickfd)\n+\t\tclose((int)vq->kickfd);\n+\n+\t/* Populate the eventfd_copy structure and call eventfd_copy. */\n+\tvq->kickfd = eventfd(0, EFD_NONBLOCK | EFD_CLOEXEC);\n+\teventfd_kick.source_fd = vq->kickfd;\n+\teventfd_kick.target_fd = file->fd;\n+\teventfd_kick.target_pid = ctx.pid;\n+\n+\tif (eventfd_copy(dev, &eventfd_kick))\n+\t\treturn -1;\n+\n+\treturn 0;\n+}\n+\n+/*\n+ * Called from CUSE IOCTL: VHOST_SET_VRING_KICK\n+ * The virtio device sends an eventfd that it can use to notify us. This fd gets copied in\n+ * to our process space.\n+ */\n+static int\n+cuse_set_vring_kick(struct vhost_device_ctx ctx, struct vhost_vring_file *file)\n+{\n+\tstruct virtio_net *dev;\n+\tstruct eventfd_copy eventfd_call;\n+\tstruct vhost_virtqueue *vq;\n+\n+\tdev = get_device(ctx);\n+\tif (dev == NULL)\n+\t\treturn -1;\n+\n+\t/* file->index refers to the queue index. The TX queue is 1, RX queue is 0. */\n+\tvq = dev->virtqueue[file->index];\n+\n+\tif (vq->callfd)\n+\t\tclose((int)vq->callfd);\n+\n+\t/* Populate the eventfd_copy structure and call eventfd_copy. */\n+\tvq->callfd = eventfd(0, EFD_NONBLOCK | EFD_CLOEXEC);\n+\teventfd_call.source_fd = vq->callfd;\n+\teventfd_call.target_fd = file->fd;\n+\teventfd_call.target_pid = ctx.pid;\n+\n+\tif (eventfd_copy(dev, &eventfd_call))\n+\t\treturn -1;\n+\n+\treturn 0;\n+}\n+\n+/*\n+ * Function pointers are set for the device operations to allow CUSE to call functions\n+ * when an IOCTL, device_add or device_release is received.\n+ */\n+static const struct vhost_net_device_ops vhost_cuse_device_ops = {\n+\t.new_device = new_device,\n+\t.destroy_device = destroy_device,\n+\n+\t.get_features = get_features,\n+\t.set_features = set_features,\n+\n+\t.set_mem_table = cuse_set_mem_table,\n+\n+\t.set_vring_num = set_vring_num,\n+\t.set_vring_addr = set_vring_addr,\n+\t.set_vring_base = set_vring_base,\n+\t.get_vring_base = cuse_get_vring_base,\n+\n+\t.set_vring_kick = cuse_set_vring_kick,\n+\t.set_vring_call = cuse_set_vring_call,\n+\n+\t.set_backend = set_backend,\n+\n+\t.set_owner = set_owner,\n+\t.reset_owner = reset_owner,\n+};\ndiff --git a/lib/librte_vhost/virtio-net.c b/lib/librte_vhost/virtio-net.c\nindex 1dee1d8..985c66b 100644\n--- a/lib/librte_vhost/virtio-net.c\n+++ b/lib/librte_vhost/virtio-net.c\n@@ -50,7 +50,6 @@\n #include <rte_virtio_net.h>\n \n #include \"vhost-net.h\"\n-#include \"eventfd_link/eventfd_link.h\"\n \n /**\n  * Device linked list structure for configuration.\n@@ -60,8 +59,6 @@ struct virtio_net_config_ll {\n \tstruct virtio_net_config_ll\t*next;\t/* Next entry on linked list.*/\n };\n \n-const char eventfd_cdev[] = \"/dev/eventfd-link\";\n-\n /* device ops to add/remove device to data core. */\n static struct virtio_net_device_ops const *notify_ops;\n /* Root address of the linked list in the configuration core. */\n@@ -71,28 +68,6 @@ static struct virtio_net_config_ll\t*ll_root;\n #define VHOST_SUPPORTED_FEATURES (1ULL << VIRTIO_NET_F_MRG_RXBUF)\n static uint64_t VHOST_FEATURES = VHOST_SUPPORTED_FEATURES;\n \n-/* Line size for reading maps file. */\n-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\tva_start;\t/* Start virtual address in file. */\n-\tuint64_t\tva_end;\t\t/* End virtual address in file. */\n-\tuint64_t\tlen;\t\t/* Size of file. */\n-\tuint64_t\tpgoff;\t\t/* Not used. */\n-\tuint32_t\tmaj;\t\t/* Not used. */\n-\tuint32_t\tmin;\t\t/* Not used. */\n-\tuint32_t\tino;\t\t/* Not used. */\n-\tchar\t\tprot[PROT_SZ];\t/* Not used. */\n-\tchar\t\tfname[PATH_MAX];/* File name. */\n-};\n-\n /*\n  * Converts QEMU virtual address to Vhost virtual address. This function is used\n  * to convert the ring addresses to our address space.\n@@ -119,173 +94,6 @@ qva_to_vva(struct virtio_net *dev, uint64_t qemu_va)\n }\n \n /*\n- * Locate the file containing QEMU's memory space and 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\t\t*fmap;\n-\tvoid\t\t*map;\n-\tuint8_t\t\tfound = 0;\n-\tchar\t\tline[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 in to 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') || (errno != 0)) {\n-\t\t\tfclose(fmap);\n-\t\t\treturn -1;\n-\t\t}\n-\n-\t\tprocmap.va_end = strtoull(in[1], &end, 16);\n-\t\tif ((in[1] == '\\0') || (end == NULL) || (*end != '\\0') || (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') || (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') || (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') || (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') || (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) && (procmap.va_end >= addr)) {\n-\t\t\tprocmap.len = procmap.va_end - 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, \"(%\"PRIu64\") Failed to find memory file in pid %d maps file\\n\", dev->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, \"(%\"PRIu64\") Cannot open pid %d process directory\\n\", dev->device_fh, pid);\n-\t\treturn -1;\n-\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) {\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, \"(%\"PRIu64\") Failed to find memory file for pid %d\\n\", dev->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, \"(%\"PRIu64\") Failed to open %s for pid %d\\n\", dev->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\t\tMAP_POPULATE|MAP_SHARED, fd, 0);\n-\tclose(fd);\n-\n-\tif (map == MAP_FAILED) {\n-\t\tRTE_LOG(ERR, VHOST_CONFIG, \"(%\"PRIu64\") Error mapping the file %s for pid %d\\n\",  dev->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, \"(%\"PRIu64\") Mem File: %s->%s - Size: %llu - VA: %p\\n\", dev->device_fh,\n-\t\tmemfile, resolved_path, (long long unsigned)mem->mapped_size, map);\n-\n-\treturn 0;\n-}\n-\n-/*\n  * Retrieves an entry from the devices configuration linked list.\n  */\n static struct virtio_net_config_ll *\n@@ -439,7 +247,7 @@ init_device(struct virtio_net *dev)\n }\n \n /*\n- * Function is called from the CUSE open function. The device structure is\n+ * Function is called from the open function. The device structure is\n  * initialised and a new entry is added to the device configuration linked\n  * list.\n  */\n@@ -492,7 +300,7 @@ new_device(struct vhost_device_ctx ctx)\n }\n \n /*\n- * Function is called from the CUSE release function. This function will cleanup\n+ * Function is called from the release function. This function will cleanup\n  * the device and remove it from device configuration linked list.\n  */\n static void\n@@ -521,7 +329,7 @@ destroy_device(struct vhost_device_ctx ctx)\n }\n \n /*\n- * Called from CUSE IOCTL: VHOST_SET_OWNER\n+ * Called from IOCTL: VHOST_SET_OWNER\n  * This function just returns success at the moment unless the device hasn't been initialised.\n  */\n static int\n@@ -537,7 +345,7 @@ set_owner(struct vhost_device_ctx ctx)\n }\n \n /*\n- * Called from CUSE IOCTL: VHOST_RESET_OWNER\n+ * Called from IOCTL: VHOST_RESET_OWNER\n  */\n static int\n reset_owner(struct vhost_device_ctx ctx)\n@@ -553,7 +361,7 @@ reset_owner(struct vhost_device_ctx ctx)\n }\n \n /*\n- * Called from CUSE IOCTL: VHOST_GET_FEATURES\n+ * Called from IOCTL: VHOST_GET_FEATURES\n  * The features that we support are requested.\n  */\n static int\n@@ -571,7 +379,7 @@ get_features(struct vhost_device_ctx ctx, uint64_t *pu)\n }\n \n /*\n- * Called from CUSE IOCTL: VHOST_SET_FEATURES\n+ * Called from IOCTL: VHOST_SET_FEATURES\n  * We receive the negotiated set of features supported by us and the virtio device.\n  */\n static int\n@@ -605,123 +413,8 @@ set_features(struct vhost_device_ctx ctx, uint64_t *pu)\n \treturn 0;\n }\n \n-\n-/*\n- * Called from CUSE IOCTL: VHOST_SET_MEM_TABLE\n- * This function creates and populates the memory structure for the device. This includes\n- * storing offsets used to translate buffer addresses.\n- */\n-static int\n-set_mem_table(struct vhost_device_ctx ctx, const void *mem_regions_addr,\n-\tuint32_t nregions)\n-{\n-\tstruct virtio_net *dev;\n-\tstruct vhost_memory_region *mem_regions;\n-\tstruct virtio_memory *mem;\n-\tuint64_t size = offsetof(struct vhost_memory, regions);\n-\tuint32_t regionidx, valid_regions;\n-\n-\tdev = get_device(ctx);\n-\tif (dev == NULL)\n-\t\treturn -1;\n-\n-\tif (dev->mem) {\n-\t\tmunmap((void *)(uintptr_t)dev->mem->mapped_address,\n-\t\t\t(size_t)dev->mem->mapped_size);\n-\t\tfree(dev->mem);\n-\t}\n-\n-\t/* Malloc the memory structure depending on the number of regions. */\n-\tmem = calloc(1, sizeof(struct virtio_memory) +\n-\t\t(sizeof(struct virtio_memory_regions) * nregions));\n-\tif (mem == NULL) {\n-\t\tRTE_LOG(ERR, VHOST_CONFIG, \"(%\"PRIu64\") Failed to allocate memory for dev->mem.\\n\", dev->device_fh);\n-\t\treturn -1;\n-\t}\n-\n-\tmem->nregions = nregions;\n-\n-\tmem_regions = (void *)(uintptr_t)\n-\t\t\t((uint64_t)(uintptr_t)mem_regions_addr + size);\n-\n-\tfor (regionidx = 0; regionidx < mem->nregions; regionidx++) {\n-\t\t/* Populate the region structure for each region. */\n-\t\tmem->regions[regionidx].guest_phys_address =\n-\t\t\tmem_regions[regionidx].guest_phys_addr;\n-\t\tmem->regions[regionidx].guest_phys_address_end =\n-\t\t\tmem->regions[regionidx].guest_phys_address +\n-\t\t\tmem_regions[regionidx].memory_size;\n-\t\tmem->regions[regionidx].memory_size =\n-\t\t\tmem_regions[regionidx].memory_size;\n-\t\tmem->regions[regionidx].userspace_address =\n-\t\t\tmem_regions[regionidx].userspace_addr;\n-\n-\t\tLOG_DEBUG(VHOST_CONFIG, \"(%\"PRIu64\") REGION: %u - GPA: %p - QEMU VA: %p - SIZE (%\"PRIu64\")\\n\", dev->device_fh,\n-\t\t\t\tregionidx, (void *)(uintptr_t)mem->regions[regionidx].guest_phys_address,\n-\t\t\t\t(void *)(uintptr_t)mem->regions[regionidx].userspace_address,\n-\t\t\t\tmem->regions[regionidx].memory_size);\n-\n-\t\t/*set the base address mapping*/\n-\t\tif (mem->regions[regionidx].guest_phys_address == 0x0) {\n-\t\t\tmem->base_address = mem->regions[regionidx].userspace_address;\n-\t\t\t/* Map VM memory file */\n-\t\t\tif (host_memory_map(dev, mem, ctx.pid, mem->base_address) != 0) {\n-\t\t\t\tfree(mem);\n-\t\t\t\treturn -1;\n-\t\t\t}\n-\t\t}\n-\t}\n-\n-\t/* Check that we have a valid base address. */\n-\tif (mem->base_address == 0) {\n-\t\tRTE_LOG(ERR, VHOST_CONFIG, \"(%\"PRIu64\") Failed to find base address of qemu memory file.\\n\", dev->device_fh);\n-\t\tfree(mem);\n-\t\treturn -1;\n-\t}\n-\n-\t/* Check if all of our regions have valid mappings. Usually one does not exist in the QEMU memory file. */\n-\tvalid_regions = mem->nregions;\n-\tfor (regionidx = 0; regionidx < mem->nregions; regionidx++) {\n-\t\tif ((mem->regions[regionidx].userspace_address < mem->base_address) ||\n-\t\t\t(mem->regions[regionidx].userspace_address > (mem->base_address + mem->mapped_size)))\n-\t\t\t\tvalid_regions--;\n-\t}\n-\n-\t/* If a region does not have a valid mapping we rebuild our memory struct to contain only valid entries. */\n-\tif (valid_regions != mem->nregions) {\n-\t\tLOG_DEBUG(VHOST_CONFIG, \"(%\"PRIu64\") Not all memory regions exist in the QEMU mem file. Re-populating mem structure\\n\",\n-\t\t\tdev->device_fh);\n-\n-\t\t/* Re-populate the memory structure with only valid regions. Invalid regions are over-written with memmove. */\n-\t\tvalid_regions = 0;\n-\n-\t\tfor (regionidx = mem->nregions; 0 != regionidx--;) {\n-\t\t\tif ((mem->regions[regionidx].userspace_address < mem->base_address) ||\n-\t\t\t\t\t(mem->regions[regionidx].userspace_address > (mem->base_address + mem->mapped_size))) {\n-\t\t\t\tmemmove(&mem->regions[regionidx], &mem->regions[regionidx + 1],\n-\t\t\t\t\tsizeof(struct virtio_memory_regions) * valid_regions);\n-\t\t\t} else {\n-\t\t\t\tvalid_regions++;\n-\t\t\t}\n-\t\t}\n-\t}\n-\tmem->nregions = valid_regions;\n-\tdev->mem = mem;\n-\n-\t/*\n-\t * Calculate the address offset for each region. This offset is used to identify the vhost virtual address\n-\t * corresponding to a QEMU guest physical address.\n-\t */\n-\tfor (regionidx = 0; regionidx < dev->mem->nregions; regionidx++) {\n-\t\tdev->mem->regions[regionidx].address_offset = dev->mem->regions[regionidx].userspace_address - dev->mem->base_address\n-\t\t\t+ dev->mem->mapped_address - dev->mem->regions[regionidx].guest_phys_address;\n-\n-\t}\n-\treturn 0;\n-}\n-\n /*\n- * Called from CUSE IOCTL: VHOST_SET_VRING_NUM\n+ * Called from IOCTL: VHOST_SET_VRING_NUM\n  * The virtio device sends us the size of the descriptor ring.\n  */\n static int\n@@ -740,7 +433,7 @@ set_vring_num(struct vhost_device_ctx ctx, struct vhost_vring_state *state)\n }\n \n /*\n- * Called from CUSE IOCTL: VHOST_SET_VRING_ADDR\n+ * Called from IOCTL: VHOST_SET_VRING_ADDR\n  * The virtio device sends us the desc, used and avail ring addresses. This function\n  * then converts these to our address space.\n  */\n@@ -784,7 +477,7 @@ set_vring_addr(struct vhost_device_ctx ctx, struct vhost_vring_addr *addr)\n }\n \n /*\n- * Called from CUSE IOCTL: VHOST_SET_VRING_BASE\n+ * Called from IOCTL: VHOST_SET_VRING_BASE\n  * The virtio device sends us the available ring last used index.\n  */\n static int\n@@ -804,125 +497,7 @@ set_vring_base(struct vhost_device_ctx ctx, struct vhost_vring_state *state)\n }\n \n /*\n- * Called from CUSE IOCTL: VHOST_GET_VRING_BASE\n- * We send the virtio device our available ring last used index.\n- */\n-static int\n-get_vring_base(struct vhost_device_ctx ctx, uint32_t index,\n-\tstruct vhost_vring_state *state)\n-{\n-\tstruct virtio_net *dev;\n-\n-\tdev = get_device(ctx);\n-\tif (dev == NULL)\n-\t\treturn -1;\n-\n-\tstate->index = index;\n-\t/* State->index refers to the queue index. The TX queue is 1, RX queue is 0. */\n-\tstate->num = dev->virtqueue[state->index]->last_used_idx;\n-\n-\treturn 0;\n-}\n-\n-/*\n- * This function uses the eventfd_link kernel module to copy an eventfd file descriptor\n- * provided by QEMU in to our process space.\n- */\n-static int\n-eventfd_copy(struct virtio_net *dev, struct eventfd_copy *eventfd_copy)\n-{\n-\tint eventfd_link, ret;\n-\n-\t/* Open the character device to the kernel module. */\n-\teventfd_link = open(eventfd_cdev, O_RDWR);\n-\tif (eventfd_link < 0) {\n-\t\tRTE_LOG(ERR, VHOST_CONFIG, \"(%\"PRIu64\") eventfd_link module is not loaded\\n\",  dev->device_fh);\n-\t\treturn -1;\n-\t}\n-\n-\t/* Call the IOCTL to copy the eventfd. */\n-\tret = ioctl(eventfd_link, EVENTFD_COPY, eventfd_copy);\n-\tclose(eventfd_link);\n-\n-\tif (ret < 0) {\n-\t\tRTE_LOG(ERR, VHOST_CONFIG, \"(%\"PRIu64\") EVENTFD_COPY ioctl failed\\n\",  dev->device_fh);\n-\t\treturn -1;\n-\t}\n-\n-\n-\treturn 0;\n-}\n-\n-/*\n- * Called from CUSE IOCTL: VHOST_SET_VRING_CALL\n- * The virtio device sends an eventfd to interrupt the guest. This fd gets copied in\n- * to our process space.\n- */\n-static int\n-set_vring_call(struct vhost_device_ctx ctx, struct vhost_vring_file *file)\n-{\n-\tstruct virtio_net *dev;\n-\tstruct eventfd_copy\teventfd_kick;\n-\tstruct vhost_virtqueue *vq;\n-\n-\tdev = get_device(ctx);\n-\tif (dev == NULL)\n-\t\treturn -1;\n-\n-\t/* file->index refers to the queue index. The TX queue is 1, RX queue is 0. */\n-\tvq = dev->virtqueue[file->index];\n-\n-\tif (vq->kickfd)\n-\t\tclose((int)vq->kickfd);\n-\n-\t/* Populate the eventfd_copy structure and call eventfd_copy. */\n-\tvq->kickfd = eventfd(0, EFD_NONBLOCK | EFD_CLOEXEC);\n-\teventfd_kick.source_fd = vq->kickfd;\n-\teventfd_kick.target_fd = file->fd;\n-\teventfd_kick.target_pid = ctx.pid;\n-\n-\tif (eventfd_copy(dev, &eventfd_kick))\n-\t\treturn -1;\n-\n-\treturn 0;\n-}\n-\n-/*\n- * Called from CUSE IOCTL: VHOST_SET_VRING_KICK\n- * The virtio device sends an eventfd that it can use to notify us. This fd gets copied in\n- * to our process space.\n- */\n-static int\n-set_vring_kick(struct vhost_device_ctx ctx, struct vhost_vring_file *file)\n-{\n-\tstruct virtio_net *dev;\n-\tstruct eventfd_copy eventfd_call;\n-\tstruct vhost_virtqueue *vq;\n-\n-\tdev = get_device(ctx);\n-\tif (dev == NULL)\n-\t\treturn -1;\n-\n-\t/* file->index refers to the queue index. The TX queue is 1, RX queue is 0. */\n-\tvq = dev->virtqueue[file->index];\n-\n-\tif (vq->callfd)\n-\t\tclose((int)vq->callfd);\n-\n-\t/* Populate the eventfd_copy structure and call eventfd_copy. */\n-\tvq->callfd = eventfd(0, EFD_NONBLOCK | EFD_CLOEXEC);\n-\teventfd_call.source_fd = vq->callfd;\n-\teventfd_call.target_fd = file->fd;\n-\teventfd_call.target_pid = ctx.pid;\n-\n-\tif (eventfd_copy(dev, &eventfd_call))\n-\t\treturn -1;\n-\n-\treturn 0;\n-}\n-\n-/*\n- * Called from CUSE IOCTL: VHOST_NET_SET_BACKEND\n+ * Called from IOCTL: VHOST_NET_SET_BACKEND\n  * To complete device initialisation when the virtio driver is loaded we are provided with a\n  * valid fd for a tap device (not used by us). If this happens then we can add the device to a\n  * data core. When the virtio driver is removed we get fd=-1. At that point we remove the device\n@@ -953,39 +528,24 @@ set_backend(struct vhost_device_ctx ctx, struct vhost_vring_file *file)\n }\n \n /*\n- * Function pointers are set for the device operations to allow CUSE to call functions\n- * when an IOCTL, device_add or device_release is received.\n+ * Include cuse depend functions and definitions.\n  */\n-static const struct vhost_net_device_ops vhost_device_ops = {\n-\t.new_device = new_device,\n-\t.destroy_device = destroy_device,\n-\n-\t.get_features = get_features,\n-\t.set_features = set_features,\n-\n-\t.set_mem_table = set_mem_table,\n-\n-\t.set_vring_num = set_vring_num,\n-\t.set_vring_addr = set_vring_addr,\n-\t.set_vring_base = set_vring_base,\n-\t.get_vring_base = get_vring_base,\n-\n-\t.set_vring_kick = set_vring_kick,\n-\t.set_vring_call = set_vring_call,\n-\n-\t.set_backend = set_backend,\n-\n-\t.set_owner = set_owner,\n-\t.reset_owner = reset_owner,\n-};\n+#include \"virtio-net-cdev.c\"\n \n /*\n- * Called by main to setup callbacks when registering CUSE device.\n+ * Called by main to setup callbacks when registering device.\n  */\n struct vhost_net_device_ops const *\n-get_virtio_net_callbacks(void)\n+get_virtio_net_callbacks(vhost_driver_type_t type)\n {\n-\treturn &vhost_device_ops;\n+\tswitch (type) {\n+\tcase VHOST_DRV_CUSE:\n+\t\treturn &vhost_cuse_device_ops;\n+\tdefault:\n+\t\tbreak;\n+\t}\n+\n+\treturn NULL;\n }\n \n int rte_vhost_enable_guest_notification(struct virtio_net *dev,\n",
    "prefixes": [
        "dpdk-dev",
        "RFC",
        "3/7"
    ]
}