get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

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

{
    "id": 2501,
    "url": "https://patches.dpdk.org/api/patches/2501/?format=api",
    "web_url": "https://patches.dpdk.org/project/dpdk/patch/1422242440-28948-3-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-3-git-send-email-huawei.xie@intel.com>",
    "list_archive_url": "https://inbox.dpdk.org/dev/1422242440-28948-3-git-send-email-huawei.xie@intel.com",
    "date": "2015-01-26T03:20:28",
    "name": "[dpdk-dev,RFC,v2,02/14] create vhost_cuse sub-directory create vhost_cuse directory move vhost-net-cdev.c to vhost_cuse directory",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": true,
    "hash": "a451df37256d4873a389c55c9cd5a3533f2390f3",
    "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-3-git-send-email-huawei.xie@intel.com/mbox/",
    "series": [],
    "comments": "https://patches.dpdk.org/api/patches/2501/comments/",
    "check": "pending",
    "checks": "https://patches.dpdk.org/api/patches/2501/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 264D35A75;\n\tMon, 26 Jan 2015 04:21:01 +0100 (CET)",
            "from mga09.intel.com (mga09.intel.com [134.134.136.24])\n\tby dpdk.org (Postfix) with ESMTP id 2F8DA5A6D\n\tfor <dev@dpdk.org>; Mon, 26 Jan 2015 04:20:57 +0100 (CET)",
            "from orsmga003.jf.intel.com ([10.7.209.27])\n\tby orsmga102.jf.intel.com with ESMTP; 25 Jan 2015 19:17:46 -0800",
            "from shvmail01.sh.intel.com ([10.239.29.42])\n\tby orsmga003.jf.intel.com with ESMTP; 25 Jan 2015 19:13:55 -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 t0Q3KqEb013350;\n\tMon, 26 Jan 2015 11:20:52 +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 t0Q3KooI028997; Mon, 26 Jan 2015 11:20:52 +0800",
            "(from hxie5@localhost)\n\tby shecgisg003.sh.intel.com (8.13.6/8.13.6/Submit) id t0Q3Ko78028993; \n\tMon, 26 Jan 2015 11:20:50 +0800"
        ],
        "X-ExtLoop1": "1",
        "X-IronPort-AV": "E=Sophos;i=\"5.09,466,1418112000\"; d=\"scan'208\";a=\"517464991\"",
        "From": "Huawei Xie <huawei.xie@intel.com>",
        "To": "dev@dpdk.org",
        "Date": "Mon, 26 Jan 2015 11:20:28 +0800",
        "Message-Id": "<1422242440-28948-3-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 02/14] create vhost_cuse sub-directory\n\tcreate vhost_cuse directory move vhost-net-cdev.c to\n\tvhost_cuse directory",
        "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": "vhost-cuse functionality will be divided into two parts:\n\tcuse driver specific logic and common logic.\n\ncuse driver specific logic will be in vhost_cuse logic.\nvhost ioctl message is pre-processed there and then sent to virtio-net\nmodule if necessary.\n\nvirtio-net provides common message handling for both vhost-cuse and vhost-user.\n\nSigned-off-by: Huawei Xie <huawei.xie@intel.com>\n---\n lib/librte_vhost/Makefile                    |   4 +-\n lib/librte_vhost/vhost-net-cdev.c            | 389 ---------------------------\n lib/librte_vhost/vhost_cuse/vhost-net-cdev.c | 389 +++++++++++++++++++++++++++\n 3 files changed, 391 insertions(+), 391 deletions(-)\n delete mode 100644 lib/librte_vhost/vhost-net-cdev.c\n create mode 100644 lib/librte_vhost/vhost_cuse/vhost-net-cdev.c",
    "diff": "diff --git a/lib/librte_vhost/Makefile b/lib/librte_vhost/Makefile\nindex c008d64..0b2f08f 100644\n--- a/lib/librte_vhost/Makefile\n+++ b/lib/librte_vhost/Makefile\n@@ -34,10 +34,10 @@ include $(RTE_SDK)/mk/rte.vars.mk\n # library name\n LIB = librte_vhost.a\n \n-CFLAGS += $(WERROR_FLAGS) -I$(SRCDIR) -O3 -D_FILE_OFFSET_BITS=64 -lfuse\n+CFLAGS += $(WERROR_FLAGS) -I$(SRCDIR) -I vhost_cuse -O3 -D_FILE_OFFSET_BITS=64 -lfuse\n LDFLAGS += -lfuse\n # all source are stored in SRCS-y\n-SRCS-$(CONFIG_RTE_LIBRTE_VHOST) := vhost-net-cdev.c virtio-net.c vhost_rxtx.c\n+SRCS-$(CONFIG_RTE_LIBRTE_VHOST) := vhost_cuse/vhost-net-cdev.c virtio-net.c vhost_rxtx.c\n \n # install includes\n SYMLINK-$(CONFIG_RTE_LIBRTE_VHOST)-include += rte_virtio_net.h\ndiff --git a/lib/librte_vhost/vhost-net-cdev.c b/lib/librte_vhost/vhost-net-cdev.c\ndeleted file mode 100644\nindex 57c76cb..0000000\n--- a/lib/librte_vhost/vhost-net-cdev.c\n+++ /dev/null\n@@ -1,389 +0,0 @@\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 <errno.h>\n-#include <fuse/cuse_lowlevel.h>\n-#include <linux/limits.h>\n-#include <linux/vhost.h>\n-#include <stdint.h>\n-#include <string.h>\n-#include <unistd.h>\n-\n-#include <rte_ethdev.h>\n-#include <rte_log.h>\n-#include <rte_string_fns.h>\n-#include <rte_virtio_net.h>\n-\n-#include \"vhost-net-cdev.h\"\n-\n-#define FUSE_OPT_DUMMY \"\\0\\0\"\n-#define FUSE_OPT_FORE  \"-f\\0\\0\"\n-#define FUSE_OPT_NOMULTI \"-s\\0\\0\"\n-\n-static const uint32_t default_major = 231;\n-static const uint32_t default_minor = 1;\n-static const char cuse_device_name[] = \"/dev/cuse\";\n-static const char default_cdev[] = \"vhost-net\";\n-\n-static struct fuse_session *session;\n-static struct vhost_net_device_ops const *ops;\n-\n-/*\n- * Returns vhost_device_ctx from given fuse_req_t. The index is populated later\n- * when the device is added to the device linked list.\n- */\n-static struct vhost_device_ctx\n-fuse_req_to_vhost_ctx(fuse_req_t req, struct fuse_file_info *fi)\n-{\n-\tstruct vhost_device_ctx ctx;\n-\tstruct fuse_ctx const *const req_ctx = fuse_req_ctx(req);\n-\n-\tctx.pid = req_ctx->pid;\n-\tctx.fh = fi->fh;\n-\n-\treturn ctx;\n-}\n-\n-/*\n- * When the device is created in QEMU it gets initialised here and\n- * added to the device linked list.\n- */\n-static void\n-vhost_net_open(fuse_req_t req, struct fuse_file_info *fi)\n-{\n-\tstruct vhost_device_ctx ctx = fuse_req_to_vhost_ctx(req, fi);\n-\tint err = 0;\n-\n-\terr = ops->new_device(ctx);\n-\tif (err == -1) {\n-\t\tfuse_reply_err(req, EPERM);\n-\t\treturn;\n-\t}\n-\n-\tfi->fh = err;\n-\n-\tRTE_LOG(INFO, VHOST_CONFIG,\n-\t\t\"(%\"PRIu64\") Device configuration started\\n\", fi->fh);\n-\tfuse_reply_open(req, fi);\n-}\n-\n-/*\n- * When QEMU is shutdown or killed the device gets released.\n- */\n-static void\n-vhost_net_release(fuse_req_t req, struct fuse_file_info *fi)\n-{\n-\tint err = 0;\n-\tstruct vhost_device_ctx ctx = fuse_req_to_vhost_ctx(req, fi);\n-\n-\tops->destroy_device(ctx);\n-\tRTE_LOG(INFO, VHOST_CONFIG, \"(%\"PRIu64\") Device released\\n\", ctx.fh);\n-\tfuse_reply_err(req, err);\n-}\n-\n-/*\n- * Boilerplate code for CUSE IOCTL\n- * Implicit arguments: ctx, req, result.\n- */\n-#define VHOST_IOCTL(func) do {\t\\\n-\tresult = (func)(ctx);\t\\\n-\tfuse_reply_ioctl(req, result, NULL, 0);\t\\\n-} while (0)\n-\n-/*\n- * Boilerplate IOCTL RETRY\n- * Implicit arguments: req.\n- */\n-#define VHOST_IOCTL_RETRY(size_r, size_w) do {\t\\\n-\tstruct iovec iov_r = { arg, (size_r) };\t\\\n-\tstruct iovec iov_w = { arg, (size_w) };\t\\\n-\tfuse_reply_ioctl_retry(req, &iov_r,\t\\\n-\t\t(size_r) ? 1 : 0, &iov_w, (size_w) ? 1 : 0);\\\n-} while (0)\n-\n-/*\n- * Boilerplate code for CUSE Read IOCTL\n- * Implicit arguments: ctx, req, result, in_bufsz, in_buf.\n- */\n-#define VHOST_IOCTL_R(type, var, func) do {\t\\\n-\tif (!in_bufsz) {\t\\\n-\t\tVHOST_IOCTL_RETRY(sizeof(type), 0);\\\n-\t} else {\t\\\n-\t\t(var) = *(const type*)in_buf;\t\\\n-\t\tresult = func(ctx, &(var));\t\\\n-\t\tfuse_reply_ioctl(req, result, NULL, 0);\\\n-\t}\t\\\n-} while (0)\n-\n-/*\n- * Boilerplate code for CUSE Write IOCTL\n- * Implicit arguments: ctx, req, result, out_bufsz.\n- */\n-#define VHOST_IOCTL_W(type, var, func) do {\t\\\n-\tif (!out_bufsz) {\t\\\n-\t\tVHOST_IOCTL_RETRY(0, sizeof(type));\\\n-\t} else {\t\\\n-\t\tresult = (func)(ctx, &(var));\\\n-\t\tfuse_reply_ioctl(req, result, &(var), sizeof(type));\\\n-\t} \\\n-} while (0)\n-\n-/*\n- * Boilerplate code for CUSE Read/Write IOCTL\n- * Implicit arguments: ctx, req, result, in_bufsz, in_buf.\n- */\n-#define VHOST_IOCTL_RW(type1, var1, type2, var2, func) do {\t\\\n-\tif (!in_bufsz) {\t\\\n-\t\tVHOST_IOCTL_RETRY(sizeof(type1), sizeof(type2));\\\n-\t} else {\t\\\n-\t\t(var1) = *(const type1*) (in_buf);\t\\\n-\t\tresult = (func)(ctx, (var1), &(var2));\t\\\n-\t\tfuse_reply_ioctl(req, result, &(var2), sizeof(type2));\\\n-\t}\t\\\n-} while (0)\n-\n-/*\n- * The IOCTLs are handled using CUSE/FUSE in userspace. Depending on the type\n- * of IOCTL a buffer is requested to read or to write. This request is handled\n- * by FUSE and the buffer is then given to CUSE.\n- */\n-static void\n-vhost_net_ioctl(fuse_req_t req, int cmd, void *arg,\n-\t\tstruct fuse_file_info *fi, __rte_unused unsigned flags,\n-\t\tconst void *in_buf, size_t in_bufsz, size_t out_bufsz)\n-{\n-\tstruct vhost_device_ctx ctx = fuse_req_to_vhost_ctx(req, fi);\n-\tstruct vhost_vring_file file;\n-\tstruct vhost_vring_state state;\n-\tstruct vhost_vring_addr addr;\n-\tuint64_t features;\n-\tuint32_t index;\n-\tint result = 0;\n-\n-\tswitch (cmd) {\n-\tcase VHOST_NET_SET_BACKEND:\n-\t\tLOG_DEBUG(VHOST_CONFIG,\n-\t\t\t\"(%\"PRIu64\") IOCTL: VHOST_NET_SET_BACKEND\\n\", ctx.fh);\n-\t\tVHOST_IOCTL_R(struct vhost_vring_file, file, ops->set_backend);\n-\t\tbreak;\n-\n-\tcase VHOST_GET_FEATURES:\n-\t\tLOG_DEBUG(VHOST_CONFIG,\n-\t\t\t\"(%\"PRIu64\") IOCTL: VHOST_GET_FEATURES\\n\", ctx.fh);\n-\t\tVHOST_IOCTL_W(uint64_t, features, ops->get_features);\n-\t\tbreak;\n-\n-\tcase VHOST_SET_FEATURES:\n-\t\tLOG_DEBUG(VHOST_CONFIG,\n-\t\t\t\"(%\"PRIu64\") IOCTL: VHOST_SET_FEATURES\\n\", ctx.fh);\n-\t\tVHOST_IOCTL_R(uint64_t, features, ops->set_features);\n-\t\tbreak;\n-\n-\tcase VHOST_RESET_OWNER:\n-\t\tLOG_DEBUG(VHOST_CONFIG,\n-\t\t\t\"(%\"PRIu64\") IOCTL: VHOST_RESET_OWNER\\n\", ctx.fh);\n-\t\tVHOST_IOCTL(ops->reset_owner);\n-\t\tbreak;\n-\n-\tcase VHOST_SET_OWNER:\n-\t\tLOG_DEBUG(VHOST_CONFIG,\n-\t\t\t\"(%\"PRIu64\") IOCTL: VHOST_SET_OWNER\\n\", ctx.fh);\n-\t\tVHOST_IOCTL(ops->set_owner);\n-\t\tbreak;\n-\n-\tcase VHOST_SET_MEM_TABLE:\n-\t\t/*TODO fix race condition.*/\n-\t\tLOG_DEBUG(VHOST_CONFIG,\n-\t\t\t\"(%\"PRIu64\") IOCTL: VHOST_SET_MEM_TABLE\\n\", ctx.fh);\n-\t\tstatic struct vhost_memory mem_temp;\n-\n-\t\tswitch (in_bufsz) {\n-\t\tcase 0:\n-\t\t\tVHOST_IOCTL_RETRY(sizeof(struct vhost_memory), 0);\n-\t\t\tbreak;\n-\n-\t\tcase sizeof(struct vhost_memory):\n-\t\t\tmem_temp = *(const struct vhost_memory *) in_buf;\n-\n-\t\t\tif (mem_temp.nregions > 0) {\n-\t\t\t\tVHOST_IOCTL_RETRY(sizeof(struct vhost_memory) +\n-\t\t\t\t\t(sizeof(struct vhost_memory_region) *\n-\t\t\t\t\t\tmem_temp.nregions), 0);\n-\t\t\t} else {\n-\t\t\t\tresult = -1;\n-\t\t\t\tfuse_reply_ioctl(req, result, NULL, 0);\n-\t\t\t}\n-\t\t\tbreak;\n-\n-\t\tdefault:\n-\t\t\tresult = ops->set_mem_table(ctx,\n-\t\t\t\t\tin_buf, mem_temp.nregions);\n-\t\t\tif (result)\n-\t\t\t\tfuse_reply_err(req, EINVAL);\n-\t\t\telse\n-\t\t\t\tfuse_reply_ioctl(req, result, NULL, 0);\n-\t\t}\n-\t\tbreak;\n-\n-\tcase VHOST_SET_VRING_NUM:\n-\t\tLOG_DEBUG(VHOST_CONFIG,\n-\t\t\t\"(%\"PRIu64\") IOCTL: VHOST_SET_VRING_NUM\\n\", ctx.fh);\n-\t\tVHOST_IOCTL_R(struct vhost_vring_state, state,\n-\t\t\tops->set_vring_num);\n-\t\tbreak;\n-\n-\tcase VHOST_SET_VRING_BASE:\n-\t\tLOG_DEBUG(VHOST_CONFIG,\n-\t\t\t\"(%\"PRIu64\") IOCTL: VHOST_SET_VRING_BASE\\n\", ctx.fh);\n-\t\tVHOST_IOCTL_R(struct vhost_vring_state, state,\n-\t\t\tops->set_vring_base);\n-\t\tbreak;\n-\n-\tcase VHOST_GET_VRING_BASE:\n-\t\tLOG_DEBUG(VHOST_CONFIG,\n-\t\t\t\"(%\"PRIu64\") IOCTL: VHOST_GET_VRING_BASE\\n\", ctx.fh);\n-\t\tVHOST_IOCTL_RW(uint32_t, index,\n-\t\t\tstruct vhost_vring_state, state, ops->get_vring_base);\n-\t\tbreak;\n-\n-\tcase VHOST_SET_VRING_ADDR:\n-\t\tLOG_DEBUG(VHOST_CONFIG,\n-\t\t\t\"(%\"PRIu64\") IOCTL: VHOST_SET_VRING_ADDR\\n\", ctx.fh);\n-\t\tVHOST_IOCTL_R(struct vhost_vring_addr, addr,\n-\t\t\tops->set_vring_addr);\n-\t\tbreak;\n-\n-\tcase VHOST_SET_VRING_KICK:\n-\t\tLOG_DEBUG(VHOST_CONFIG,\n-\t\t\t\"(%\"PRIu64\") IOCTL: VHOST_SET_VRING_KICK\\n\", ctx.fh);\n-\t\tVHOST_IOCTL_R(struct vhost_vring_file, file,\n-\t\t\tops->set_vring_kick);\n-\t\tbreak;\n-\n-\tcase VHOST_SET_VRING_CALL:\n-\t\tLOG_DEBUG(VHOST_CONFIG,\n-\t\t\t\"(%\"PRIu64\") IOCTL: VHOST_SET_VRING_CALL\\n\", ctx.fh);\n-\t\tVHOST_IOCTL_R(struct vhost_vring_file, file,\n-\t\t\tops->set_vring_call);\n-\t\tbreak;\n-\n-\tdefault:\n-\t\tRTE_LOG(ERR, VHOST_CONFIG,\n-\t\t\t\"(%\"PRIu64\") IOCTL: DOESN NOT EXIST\\n\", ctx.fh);\n-\t\tresult = -1;\n-\t\tfuse_reply_ioctl(req, result, NULL, 0);\n-\t}\n-\n-\tif (result < 0)\n-\t\tLOG_DEBUG(VHOST_CONFIG,\n-\t\t\t\"(%\"PRIu64\") IOCTL: FAIL\\n\", ctx.fh);\n-\telse\n-\t\tLOG_DEBUG(VHOST_CONFIG,\n-\t\t\t\"(%\"PRIu64\") IOCTL: SUCCESS\\n\", ctx.fh);\n-}\n-\n-/*\n- * Structure handling open, release and ioctl function pointers is populated.\n- */\n-static const struct cuse_lowlevel_ops vhost_net_ops = {\n-\t.open\t\t= vhost_net_open,\n-\t.release\t= vhost_net_release,\n-\t.ioctl\t\t= vhost_net_ioctl,\n-};\n-\n-/*\n- * cuse_info is populated and used to register the cuse device.\n- * vhost_net_device_ops are also passed when the device is registered in app.\n- */\n-int\n-rte_vhost_driver_register(const char *dev_name)\n-{\n-\tstruct cuse_info cuse_info;\n-\tchar device_name[PATH_MAX] = \"\";\n-\tchar char_device_name[PATH_MAX] = \"\";\n-\tconst char *device_argv[] = { device_name };\n-\n-\tchar fuse_opt_dummy[] = FUSE_OPT_DUMMY;\n-\tchar fuse_opt_fore[] = FUSE_OPT_FORE;\n-\tchar fuse_opt_nomulti[] = FUSE_OPT_NOMULTI;\n-\tchar *fuse_argv[] = {fuse_opt_dummy, fuse_opt_fore, fuse_opt_nomulti};\n-\n-\tif (access(cuse_device_name, R_OK | W_OK) < 0) {\n-\t\tRTE_LOG(ERR, VHOST_CONFIG,\n-\t\t\t\"char device %s can't be accessed, maybe not exist\\n\",\n-\t\t\tcuse_device_name);\n-\t\treturn -1;\n-\t}\n-\n-\t/*\n-\t * The device name is created. This is passed to QEMU so that it can\n-\t * register the device with our application.\n-\t */\n-\tsnprintf(device_name, PATH_MAX, \"DEVNAME=%s\", dev_name);\n-\tsnprintf(char_device_name, PATH_MAX, \"/dev/%s\", dev_name);\n-\n-\t/* Check if device already exists. */\n-\tif (access(char_device_name, F_OK) != -1) {\n-\t\tRTE_LOG(ERR, VHOST_CONFIG,\n-\t\t\t\"char device %s already exists\\n\", char_device_name);\n-\t\treturn -1;\n-\t}\n-\n-\tmemset(&cuse_info, 0, sizeof(cuse_info));\n-\tcuse_info.dev_major = default_major;\n-\tcuse_info.dev_minor = default_minor;\n-\tcuse_info.dev_info_argc = 1;\n-\tcuse_info.dev_info_argv = device_argv;\n-\tcuse_info.flags = CUSE_UNRESTRICTED_IOCTL;\n-\n-\tops = get_virtio_net_callbacks();\n-\n-\tsession = cuse_lowlevel_setup(3, fuse_argv,\n-\t\t\t&cuse_info, &vhost_net_ops, 0, NULL);\n-\tif (session == NULL)\n-\t\treturn -1;\n-\n-\treturn 0;\n-}\n-\n-/**\n- * The CUSE session is launched allowing the application to receive open,\n- * release and ioctl calls.\n- */\n-int\n-rte_vhost_driver_session_start(void)\n-{\n-\tfuse_session_loop(session);\n-\n-\treturn 0;\n-}\ndiff --git a/lib/librte_vhost/vhost_cuse/vhost-net-cdev.c b/lib/librte_vhost/vhost_cuse/vhost-net-cdev.c\nnew file mode 100644\nindex 0000000..57c76cb\n--- /dev/null\n+++ b/lib/librte_vhost/vhost_cuse/vhost-net-cdev.c\n@@ -0,0 +1,389 @@\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 <errno.h>\n+#include <fuse/cuse_lowlevel.h>\n+#include <linux/limits.h>\n+#include <linux/vhost.h>\n+#include <stdint.h>\n+#include <string.h>\n+#include <unistd.h>\n+\n+#include <rte_ethdev.h>\n+#include <rte_log.h>\n+#include <rte_string_fns.h>\n+#include <rte_virtio_net.h>\n+\n+#include \"vhost-net-cdev.h\"\n+\n+#define FUSE_OPT_DUMMY \"\\0\\0\"\n+#define FUSE_OPT_FORE  \"-f\\0\\0\"\n+#define FUSE_OPT_NOMULTI \"-s\\0\\0\"\n+\n+static const uint32_t default_major = 231;\n+static const uint32_t default_minor = 1;\n+static const char cuse_device_name[] = \"/dev/cuse\";\n+static const char default_cdev[] = \"vhost-net\";\n+\n+static struct fuse_session *session;\n+static struct vhost_net_device_ops const *ops;\n+\n+/*\n+ * Returns vhost_device_ctx from given fuse_req_t. The index is populated later\n+ * when the device is added to the device linked list.\n+ */\n+static struct vhost_device_ctx\n+fuse_req_to_vhost_ctx(fuse_req_t req, struct fuse_file_info *fi)\n+{\n+\tstruct vhost_device_ctx ctx;\n+\tstruct fuse_ctx const *const req_ctx = fuse_req_ctx(req);\n+\n+\tctx.pid = req_ctx->pid;\n+\tctx.fh = fi->fh;\n+\n+\treturn ctx;\n+}\n+\n+/*\n+ * When the device is created in QEMU it gets initialised here and\n+ * added to the device linked list.\n+ */\n+static void\n+vhost_net_open(fuse_req_t req, struct fuse_file_info *fi)\n+{\n+\tstruct vhost_device_ctx ctx = fuse_req_to_vhost_ctx(req, fi);\n+\tint err = 0;\n+\n+\terr = ops->new_device(ctx);\n+\tif (err == -1) {\n+\t\tfuse_reply_err(req, EPERM);\n+\t\treturn;\n+\t}\n+\n+\tfi->fh = err;\n+\n+\tRTE_LOG(INFO, VHOST_CONFIG,\n+\t\t\"(%\"PRIu64\") Device configuration started\\n\", fi->fh);\n+\tfuse_reply_open(req, fi);\n+}\n+\n+/*\n+ * When QEMU is shutdown or killed the device gets released.\n+ */\n+static void\n+vhost_net_release(fuse_req_t req, struct fuse_file_info *fi)\n+{\n+\tint err = 0;\n+\tstruct vhost_device_ctx ctx = fuse_req_to_vhost_ctx(req, fi);\n+\n+\tops->destroy_device(ctx);\n+\tRTE_LOG(INFO, VHOST_CONFIG, \"(%\"PRIu64\") Device released\\n\", ctx.fh);\n+\tfuse_reply_err(req, err);\n+}\n+\n+/*\n+ * Boilerplate code for CUSE IOCTL\n+ * Implicit arguments: ctx, req, result.\n+ */\n+#define VHOST_IOCTL(func) do {\t\\\n+\tresult = (func)(ctx);\t\\\n+\tfuse_reply_ioctl(req, result, NULL, 0);\t\\\n+} while (0)\n+\n+/*\n+ * Boilerplate IOCTL RETRY\n+ * Implicit arguments: req.\n+ */\n+#define VHOST_IOCTL_RETRY(size_r, size_w) do {\t\\\n+\tstruct iovec iov_r = { arg, (size_r) };\t\\\n+\tstruct iovec iov_w = { arg, (size_w) };\t\\\n+\tfuse_reply_ioctl_retry(req, &iov_r,\t\\\n+\t\t(size_r) ? 1 : 0, &iov_w, (size_w) ? 1 : 0);\\\n+} while (0)\n+\n+/*\n+ * Boilerplate code for CUSE Read IOCTL\n+ * Implicit arguments: ctx, req, result, in_bufsz, in_buf.\n+ */\n+#define VHOST_IOCTL_R(type, var, func) do {\t\\\n+\tif (!in_bufsz) {\t\\\n+\t\tVHOST_IOCTL_RETRY(sizeof(type), 0);\\\n+\t} else {\t\\\n+\t\t(var) = *(const type*)in_buf;\t\\\n+\t\tresult = func(ctx, &(var));\t\\\n+\t\tfuse_reply_ioctl(req, result, NULL, 0);\\\n+\t}\t\\\n+} while (0)\n+\n+/*\n+ * Boilerplate code for CUSE Write IOCTL\n+ * Implicit arguments: ctx, req, result, out_bufsz.\n+ */\n+#define VHOST_IOCTL_W(type, var, func) do {\t\\\n+\tif (!out_bufsz) {\t\\\n+\t\tVHOST_IOCTL_RETRY(0, sizeof(type));\\\n+\t} else {\t\\\n+\t\tresult = (func)(ctx, &(var));\\\n+\t\tfuse_reply_ioctl(req, result, &(var), sizeof(type));\\\n+\t} \\\n+} while (0)\n+\n+/*\n+ * Boilerplate code for CUSE Read/Write IOCTL\n+ * Implicit arguments: ctx, req, result, in_bufsz, in_buf.\n+ */\n+#define VHOST_IOCTL_RW(type1, var1, type2, var2, func) do {\t\\\n+\tif (!in_bufsz) {\t\\\n+\t\tVHOST_IOCTL_RETRY(sizeof(type1), sizeof(type2));\\\n+\t} else {\t\\\n+\t\t(var1) = *(const type1*) (in_buf);\t\\\n+\t\tresult = (func)(ctx, (var1), &(var2));\t\\\n+\t\tfuse_reply_ioctl(req, result, &(var2), sizeof(type2));\\\n+\t}\t\\\n+} while (0)\n+\n+/*\n+ * The IOCTLs are handled using CUSE/FUSE in userspace. Depending on the type\n+ * of IOCTL a buffer is requested to read or to write. This request is handled\n+ * by FUSE and the buffer is then given to CUSE.\n+ */\n+static void\n+vhost_net_ioctl(fuse_req_t req, int cmd, void *arg,\n+\t\tstruct fuse_file_info *fi, __rte_unused unsigned flags,\n+\t\tconst void *in_buf, size_t in_bufsz, size_t out_bufsz)\n+{\n+\tstruct vhost_device_ctx ctx = fuse_req_to_vhost_ctx(req, fi);\n+\tstruct vhost_vring_file file;\n+\tstruct vhost_vring_state state;\n+\tstruct vhost_vring_addr addr;\n+\tuint64_t features;\n+\tuint32_t index;\n+\tint result = 0;\n+\n+\tswitch (cmd) {\n+\tcase VHOST_NET_SET_BACKEND:\n+\t\tLOG_DEBUG(VHOST_CONFIG,\n+\t\t\t\"(%\"PRIu64\") IOCTL: VHOST_NET_SET_BACKEND\\n\", ctx.fh);\n+\t\tVHOST_IOCTL_R(struct vhost_vring_file, file, ops->set_backend);\n+\t\tbreak;\n+\n+\tcase VHOST_GET_FEATURES:\n+\t\tLOG_DEBUG(VHOST_CONFIG,\n+\t\t\t\"(%\"PRIu64\") IOCTL: VHOST_GET_FEATURES\\n\", ctx.fh);\n+\t\tVHOST_IOCTL_W(uint64_t, features, ops->get_features);\n+\t\tbreak;\n+\n+\tcase VHOST_SET_FEATURES:\n+\t\tLOG_DEBUG(VHOST_CONFIG,\n+\t\t\t\"(%\"PRIu64\") IOCTL: VHOST_SET_FEATURES\\n\", ctx.fh);\n+\t\tVHOST_IOCTL_R(uint64_t, features, ops->set_features);\n+\t\tbreak;\n+\n+\tcase VHOST_RESET_OWNER:\n+\t\tLOG_DEBUG(VHOST_CONFIG,\n+\t\t\t\"(%\"PRIu64\") IOCTL: VHOST_RESET_OWNER\\n\", ctx.fh);\n+\t\tVHOST_IOCTL(ops->reset_owner);\n+\t\tbreak;\n+\n+\tcase VHOST_SET_OWNER:\n+\t\tLOG_DEBUG(VHOST_CONFIG,\n+\t\t\t\"(%\"PRIu64\") IOCTL: VHOST_SET_OWNER\\n\", ctx.fh);\n+\t\tVHOST_IOCTL(ops->set_owner);\n+\t\tbreak;\n+\n+\tcase VHOST_SET_MEM_TABLE:\n+\t\t/*TODO fix race condition.*/\n+\t\tLOG_DEBUG(VHOST_CONFIG,\n+\t\t\t\"(%\"PRIu64\") IOCTL: VHOST_SET_MEM_TABLE\\n\", ctx.fh);\n+\t\tstatic struct vhost_memory mem_temp;\n+\n+\t\tswitch (in_bufsz) {\n+\t\tcase 0:\n+\t\t\tVHOST_IOCTL_RETRY(sizeof(struct vhost_memory), 0);\n+\t\t\tbreak;\n+\n+\t\tcase sizeof(struct vhost_memory):\n+\t\t\tmem_temp = *(const struct vhost_memory *) in_buf;\n+\n+\t\t\tif (mem_temp.nregions > 0) {\n+\t\t\t\tVHOST_IOCTL_RETRY(sizeof(struct vhost_memory) +\n+\t\t\t\t\t(sizeof(struct vhost_memory_region) *\n+\t\t\t\t\t\tmem_temp.nregions), 0);\n+\t\t\t} else {\n+\t\t\t\tresult = -1;\n+\t\t\t\tfuse_reply_ioctl(req, result, NULL, 0);\n+\t\t\t}\n+\t\t\tbreak;\n+\n+\t\tdefault:\n+\t\t\tresult = ops->set_mem_table(ctx,\n+\t\t\t\t\tin_buf, mem_temp.nregions);\n+\t\t\tif (result)\n+\t\t\t\tfuse_reply_err(req, EINVAL);\n+\t\t\telse\n+\t\t\t\tfuse_reply_ioctl(req, result, NULL, 0);\n+\t\t}\n+\t\tbreak;\n+\n+\tcase VHOST_SET_VRING_NUM:\n+\t\tLOG_DEBUG(VHOST_CONFIG,\n+\t\t\t\"(%\"PRIu64\") IOCTL: VHOST_SET_VRING_NUM\\n\", ctx.fh);\n+\t\tVHOST_IOCTL_R(struct vhost_vring_state, state,\n+\t\t\tops->set_vring_num);\n+\t\tbreak;\n+\n+\tcase VHOST_SET_VRING_BASE:\n+\t\tLOG_DEBUG(VHOST_CONFIG,\n+\t\t\t\"(%\"PRIu64\") IOCTL: VHOST_SET_VRING_BASE\\n\", ctx.fh);\n+\t\tVHOST_IOCTL_R(struct vhost_vring_state, state,\n+\t\t\tops->set_vring_base);\n+\t\tbreak;\n+\n+\tcase VHOST_GET_VRING_BASE:\n+\t\tLOG_DEBUG(VHOST_CONFIG,\n+\t\t\t\"(%\"PRIu64\") IOCTL: VHOST_GET_VRING_BASE\\n\", ctx.fh);\n+\t\tVHOST_IOCTL_RW(uint32_t, index,\n+\t\t\tstruct vhost_vring_state, state, ops->get_vring_base);\n+\t\tbreak;\n+\n+\tcase VHOST_SET_VRING_ADDR:\n+\t\tLOG_DEBUG(VHOST_CONFIG,\n+\t\t\t\"(%\"PRIu64\") IOCTL: VHOST_SET_VRING_ADDR\\n\", ctx.fh);\n+\t\tVHOST_IOCTL_R(struct vhost_vring_addr, addr,\n+\t\t\tops->set_vring_addr);\n+\t\tbreak;\n+\n+\tcase VHOST_SET_VRING_KICK:\n+\t\tLOG_DEBUG(VHOST_CONFIG,\n+\t\t\t\"(%\"PRIu64\") IOCTL: VHOST_SET_VRING_KICK\\n\", ctx.fh);\n+\t\tVHOST_IOCTL_R(struct vhost_vring_file, file,\n+\t\t\tops->set_vring_kick);\n+\t\tbreak;\n+\n+\tcase VHOST_SET_VRING_CALL:\n+\t\tLOG_DEBUG(VHOST_CONFIG,\n+\t\t\t\"(%\"PRIu64\") IOCTL: VHOST_SET_VRING_CALL\\n\", ctx.fh);\n+\t\tVHOST_IOCTL_R(struct vhost_vring_file, file,\n+\t\t\tops->set_vring_call);\n+\t\tbreak;\n+\n+\tdefault:\n+\t\tRTE_LOG(ERR, VHOST_CONFIG,\n+\t\t\t\"(%\"PRIu64\") IOCTL: DOESN NOT EXIST\\n\", ctx.fh);\n+\t\tresult = -1;\n+\t\tfuse_reply_ioctl(req, result, NULL, 0);\n+\t}\n+\n+\tif (result < 0)\n+\t\tLOG_DEBUG(VHOST_CONFIG,\n+\t\t\t\"(%\"PRIu64\") IOCTL: FAIL\\n\", ctx.fh);\n+\telse\n+\t\tLOG_DEBUG(VHOST_CONFIG,\n+\t\t\t\"(%\"PRIu64\") IOCTL: SUCCESS\\n\", ctx.fh);\n+}\n+\n+/*\n+ * Structure handling open, release and ioctl function pointers is populated.\n+ */\n+static const struct cuse_lowlevel_ops vhost_net_ops = {\n+\t.open\t\t= vhost_net_open,\n+\t.release\t= vhost_net_release,\n+\t.ioctl\t\t= vhost_net_ioctl,\n+};\n+\n+/*\n+ * cuse_info is populated and used to register the cuse device.\n+ * vhost_net_device_ops are also passed when the device is registered in app.\n+ */\n+int\n+rte_vhost_driver_register(const char *dev_name)\n+{\n+\tstruct cuse_info cuse_info;\n+\tchar device_name[PATH_MAX] = \"\";\n+\tchar char_device_name[PATH_MAX] = \"\";\n+\tconst char *device_argv[] = { device_name };\n+\n+\tchar fuse_opt_dummy[] = FUSE_OPT_DUMMY;\n+\tchar fuse_opt_fore[] = FUSE_OPT_FORE;\n+\tchar fuse_opt_nomulti[] = FUSE_OPT_NOMULTI;\n+\tchar *fuse_argv[] = {fuse_opt_dummy, fuse_opt_fore, fuse_opt_nomulti};\n+\n+\tif (access(cuse_device_name, R_OK | W_OK) < 0) {\n+\t\tRTE_LOG(ERR, VHOST_CONFIG,\n+\t\t\t\"char device %s can't be accessed, maybe not exist\\n\",\n+\t\t\tcuse_device_name);\n+\t\treturn -1;\n+\t}\n+\n+\t/*\n+\t * The device name is created. This is passed to QEMU so that it can\n+\t * register the device with our application.\n+\t */\n+\tsnprintf(device_name, PATH_MAX, \"DEVNAME=%s\", dev_name);\n+\tsnprintf(char_device_name, PATH_MAX, \"/dev/%s\", dev_name);\n+\n+\t/* Check if device already exists. */\n+\tif (access(char_device_name, F_OK) != -1) {\n+\t\tRTE_LOG(ERR, VHOST_CONFIG,\n+\t\t\t\"char device %s already exists\\n\", char_device_name);\n+\t\treturn -1;\n+\t}\n+\n+\tmemset(&cuse_info, 0, sizeof(cuse_info));\n+\tcuse_info.dev_major = default_major;\n+\tcuse_info.dev_minor = default_minor;\n+\tcuse_info.dev_info_argc = 1;\n+\tcuse_info.dev_info_argv = device_argv;\n+\tcuse_info.flags = CUSE_UNRESTRICTED_IOCTL;\n+\n+\tops = get_virtio_net_callbacks();\n+\n+\tsession = cuse_lowlevel_setup(3, fuse_argv,\n+\t\t\t&cuse_info, &vhost_net_ops, 0, NULL);\n+\tif (session == NULL)\n+\t\treturn -1;\n+\n+\treturn 0;\n+}\n+\n+/**\n+ * The CUSE session is launched allowing the application to receive open,\n+ * release and ioctl calls.\n+ */\n+int\n+rte_vhost_driver_session_start(void)\n+{\n+\tfuse_session_loop(session);\n+\n+\treturn 0;\n+}\n",
    "prefixes": [
        "dpdk-dev",
        "RFC",
        "v2",
        "02/14"
    ]
}