get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

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

{
    "id": 26623,
    "url": "http://patches.dpdk.org/api/patches/26623/?format=api",
    "web_url": "http://patches.dpdk.org/project/dpdk/patch/1499487291-17053-1-git-send-email-changpeng.liu@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": "<1499487291-17053-1-git-send-email-changpeng.liu@intel.com>",
    "list_archive_url": "https://inbox.dpdk.org/dev/1499487291-17053-1-git-send-email-changpeng.liu@intel.com",
    "date": "2017-07-08T04:14:51",
    "name": "[dpdk-dev,v2] examples/vhost: introduce a new vhost-user-scsi sample application",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": true,
    "hash": "802d9615a8362d9e003c2283b18c61b5fa589487",
    "submitter": {
        "id": 565,
        "url": "http://patches.dpdk.org/api/people/565/?format=api",
        "name": "Liu, Changpeng",
        "email": "changpeng.liu@intel.com"
    },
    "delegate": {
        "id": 355,
        "url": "http://patches.dpdk.org/api/users/355/?format=api",
        "username": "yliu",
        "first_name": "Yuanhan",
        "last_name": "Liu",
        "email": "yuanhan.liu@linux.intel.com"
    },
    "mbox": "http://patches.dpdk.org/project/dpdk/patch/1499487291-17053-1-git-send-email-changpeng.liu@intel.com/mbox/",
    "series": [],
    "comments": "http://patches.dpdk.org/api/patches/26623/comments/",
    "check": "fail",
    "checks": "http://patches.dpdk.org/api/patches/26623/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 5E0872BFF;\n\tFri,  7 Jul 2017 05:56:56 +0200 (CEST)",
            "from mga09.intel.com (mga09.intel.com [134.134.136.24])\n\tby dpdk.org (Postfix) with ESMTP id 83E792C8\n\tfor <dev@dpdk.org>; Fri,  7 Jul 2017 05:56:53 +0200 (CEST)",
            "from fmsmga002.fm.intel.com ([10.253.24.26])\n\tby orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384;\n\t06 Jul 2017 20:56:52 -0700",
            "from fedora.sh.intel.com ([10.67.112.210])\n\tby fmsmga002.fm.intel.com with ESMTP; 06 Jul 2017 20:56:50 -0700"
        ],
        "X-ExtLoop1": "1",
        "X-IronPort-AV": "E=Sophos; i=\"5.40,320,1496127600\"; d=\"scan'208\";\n\ta=\"1192403129\"",
        "From": "Changpeng Liu <changpeng.liu@intel.com>",
        "To": "dev@dpdk.org",
        "Cc": "changpeng.liu@intel.com",
        "Date": "Sat,  8 Jul 2017 12:14:51 +0800",
        "Message-Id": "<1499487291-17053-1-git-send-email-changpeng.liu@intel.com>",
        "X-Mailer": "git-send-email 1.9.3",
        "In-Reply-To": "<1498728512-12728-1-git-send-email-changpeng.liu@intel.com>",
        "References": "<1498728512-12728-1-git-send-email-changpeng.liu@intel.com>",
        "Subject": "[dpdk-dev] [PATCH v2] examples/vhost: introduce a new\n\tvhost-user-scsi sample application",
        "X-BeenThere": "dev@dpdk.org",
        "X-Mailman-Version": "2.1.15",
        "Precedence": "list",
        "List-Id": "DPDK patches and discussions <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-user protocol is common to many virtio devices, such as\nvirtio_net/virtio_scsi/virtio_blk. Since DPDK vhost library\nremoved the NET specific data structures, the vhost library\nis common to other virtio devices, such as virtio-scsi.\n\nHere we introduce a simple memory based block device that\ncan be presented to Guest VM through vhost-user-scsi-pci\ncontroller. Similar with vhost-net, the sample application\nwill process the I/Os sent via virt rings.\n\nSigned-off-by: Changpeng Liu <changpeng.liu@intel.com>\n---\n MAINTAINERS                             |   2 +\n doc/guides/sample_app_ug/vhost_scsi.rst | 110 +++++++\n examples/Makefile                       |   2 +-\n examples/vhost_scsi/Makefile            |  59 ++++\n examples/vhost_scsi/scsi.c              | 507 ++++++++++++++++++++++++++++++++\n examples/vhost_scsi/scsi_spec.h         | 488 ++++++++++++++++++++++++++++++\n examples/vhost_scsi/vhost_scsi.c        | 472 +++++++++++++++++++++++++++++\n examples/vhost_scsi/vhost_scsi.h        | 250 ++++++++++++++++\n 8 files changed, 1889 insertions(+), 1 deletion(-)\n create mode 100644 doc/guides/sample_app_ug/vhost_scsi.rst\n create mode 100644 examples/vhost_scsi/Makefile\n create mode 100644 examples/vhost_scsi/scsi.c\n create mode 100644 examples/vhost_scsi/scsi_spec.h\n create mode 100644 examples/vhost_scsi/vhost_scsi.c\n create mode 100644 examples/vhost_scsi/vhost_scsi.h",
    "diff": "diff --git a/MAINTAINERS b/MAINTAINERS\nindex b4424ea..b1cc956 100644\n--- a/MAINTAINERS\n+++ b/MAINTAINERS\n@@ -434,6 +434,8 @@ F: lib/librte_vhost/\n F: doc/guides/prog_guide/vhost_lib.rst\n F: examples/vhost/\n F: doc/guides/sample_app_ug/vhost.rst\n+F: examples/vhost_scsi/\n+F: doc/guides/sample_app_ug/vhost_scsi.rst\n \n Vhost PMD\n M: Tetsuya Mukawa <mtetsuyah@gmail.com>\ndiff --git a/doc/guides/sample_app_ug/vhost_scsi.rst b/doc/guides/sample_app_ug/vhost_scsi.rst\nnew file mode 100644\nindex 0000000..44d99c9\n--- /dev/null\n+++ b/doc/guides/sample_app_ug/vhost_scsi.rst\n@@ -0,0 +1,110 @@\n+\n+..  BSD LICENSE\n+    Copyright(c) 2010-2017 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+Vhost_scsi Sample Application\n+========================\n+\n+The vhost_scsi sample application implemented a simple SCSI block device,\n+which used as the  backend of Qemu vhost-user-scsi device. Users can extend\n+the exist example to use other type of block device(e.g. AIO) besides\n+memory based block device. Similar with vhost-user-net device, the sample\n+application used domain socket to communicate with Qemu, and the virtio\n+ring was processed by vhost_scsi sample application.\n+\n+Testing steps\n+-------------\n+\n+This section shows the steps how to start a VM with the block device as\n+fast data path for critical application.\n+\n+Build\n+~~~~~\n+\n+Follow the *Getting Started Guide for Linux* on generic info about\n+environment setup and building DPDK from source.\n+\n+In this example, you need build DPDK both on the host and inside guest.\n+Also, you need build this example.\n+\n+.. code-block:: console\n+\n+    export RTE_SDK=/path/to/dpdk_source\n+    export RTE_TARGET=x86_64-native-linuxapp-gcc\n+\n+    cd ${RTE_SDK}/examples/vhost_scsi\n+    make\n+\n+\n+Start the vhost_scsi example\n+~~~~~~~~~~~~~~~~~~~~~~~~~\n+\n+.. code-block:: console\n+\n+        ./vhost_scsi -m 1024\n+\n+.. _vhost_scsi_app_run_vm:\n+\n+Start the VM\n+~~~~~~~~~~~~\n+\n+.. code-block:: console\n+\n+    qemu-system-x86_64 -machine accel=kvm \\\n+        -m $mem -object memory-backend-file,id=mem,size=$mem,\\\n+        mem-path=/dev/hugepages,share=on -numa node,memdev=mem \\\n+        -drive file=os.img,if=none,id=disk \\\n+        -device ide-hd,drive=disk,bootindex=0 \\\n+        -chardev socket,id=char0,path=/tmp/vhost.socket \\\n+        -device vhost-user-scsi-pci,chardev=char0,bootindex=2 \\\n+        ...\n+\n+.. note::\n+    You must check whether your Qemu can support \"vhost-user-scsi\" or not,\n+    Qemu v2.9.50 or newer version is required.\n+\n+Vhost_scsi Common Issues\n+-------------\n+\n+* vhost_scsi can not start with block size 512 Bytes:\n+\n+  Currently DPDK vhost library was designed for NET device(althrough the APIs\n+  are generic now), for 512 Bytes block device, Qemu BIOS(x86 BIOS Enhanced\n+  Disk Device) will enumerate all block device and do some IOs to those block\n+  devices with 512 Bytes sector size. DPDK vhost library can not process such\n+  scenarios(both BIOS and OS will enumerate the block device), so as a\n+  workaround, the vhost_scsi example application hardcoded the block size\n+  with 4096 Bytes.\n+\n+* vhost_scsi can only support the block device as fast data disk(non OS image):\n+\n+  Make sure ``bootindex=2`` Qemu option is given to vhost-user-scsi-pci device.\n+\ndiff --git a/examples/Makefile b/examples/Makefile\nindex c0e9c3b..05986b6 100644\n--- a/examples/Makefile\n+++ b/examples/Makefile\n@@ -88,7 +88,7 @@ ifeq ($(CONFIG_RTE_LIBRTE_HASH),y)\n DIRS-$(CONFIG_RTE_LIBRTE_VHOST) += tep_termination\n endif\n DIRS-$(CONFIG_RTE_LIBRTE_TIMER) += timer\n-DIRS-$(CONFIG_RTE_LIBRTE_VHOST) += vhost\n+DIRS-$(CONFIG_RTE_LIBRTE_VHOST) += vhost vhost_scsi\n DIRS-$(CONFIG_RTE_LIBRTE_XEN_DOM0) += vhost_xen\n DIRS-y += vmdq\n DIRS-y += vmdq_dcb\ndiff --git a/examples/vhost_scsi/Makefile b/examples/vhost_scsi/Makefile\nnew file mode 100644\nindex 0000000..0306a6a\n--- /dev/null\n+++ b/examples/vhost_scsi/Makefile\n@@ -0,0 +1,59 @@\n+#   BSD LICENSE\n+#\n+#   Copyright(c) 2010-2017 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+ifeq ($(RTE_SDK),)\n+$(error \"Please define RTE_SDK environment variable\")\n+endif\n+\n+# Default target, can be overridden by command line or environment\n+RTE_TARGET ?= x86_64-native-linuxapp-gcc\n+\n+include $(RTE_SDK)/mk/rte.vars.mk\n+\n+ifneq ($(CONFIG_RTE_EXEC_ENV),\"linuxapp\")\n+$(info This application can only operate in a linuxapp environment, \\\n+please change the definition of the RTE_TARGET environment variable)\n+all:\n+else\n+\n+# binary name\n+APP = vhost-scsi\n+\n+# all source are stored in SRCS-y\n+SRCS-y := scsi.c vhost_scsi.c\n+\n+CFLAGS += -O2 -D_FILE_OFFSET_BITS=64\n+CFLAGS += $(WERROR_FLAGS)\n+CFLAGS += -D_GNU_SOURCE\n+\n+include $(RTE_SDK)/mk/rte.extapp.mk\n+\n+endif\ndiff --git a/examples/vhost_scsi/scsi.c b/examples/vhost_scsi/scsi.c\nnew file mode 100644\nindex 0000000..21f88ad\n--- /dev/null\n+++ b/examples/vhost_scsi/scsi.c\n@@ -0,0 +1,507 @@\n+/*-\n+ *   BSD LICENSE\n+ *\n+ *   Copyright(c) 2010-2017 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 <stdio.h>\n+#include <stdint.h>\n+#include <unistd.h>\n+#include <assert.h>\n+#include <ctype.h>\n+#include <string.h>\n+#include <stddef.h>\n+\n+#include <rte_atomic.h>\n+#include <rte_cycles.h>\n+#include <rte_log.h>\n+#include <rte_malloc.h>\n+\n+#include \"vhost_scsi.h\"\n+#include \"scsi_spec.h\"\n+\n+#define INQ_OFFSET(field) (offsetof(struct scsi_cdb_inquiry_data, field) + \\\n+\t\t\t  sizeof(((struct scsi_cdb_inquiry_data *)0x0)->field))\n+\n+static void\n+vhost_strcpy_pad(void *dst, const char *src, size_t size, int pad)\n+{\n+\tsize_t len;\n+\n+\tlen = strlen(src);\n+\tif (len < size) {\n+\t\tmemcpy(dst, src, len);\n+\t\tmemset((char *)dst + len, pad, size - len);\n+\t} else {\n+\t\tmemcpy(dst, src, size);\n+\t}\n+}\n+\n+static int\n+vhost_hex2bin(char ch)\n+{\n+\tif ((ch >= '0') && (ch <= '9'))\n+\t\treturn ch - '0';\n+\tch = tolower(ch);\n+\tif ((ch >= 'a') && (ch <= 'f'))\n+\t\treturn ch - 'a' + 10;\n+\treturn (int)ch;\n+}\n+\n+static void\n+vhost_bdev_scsi_set_local_naa(char *name, uint8_t *buf)\n+{\n+\tint i, value, count = 0;\n+\tuint64_t naa, local_value;\n+\n+\tfor (i = 0; (i < 16) && (name[i] != '\\0'); i++) {\n+\t\tvalue = vhost_hex2bin(name[i]);\n+\t\tif (i % 2)\n+\t\t\tbuf[count++] |= value << 4;\n+\t\telse\n+\t\t\tbuf[count] = value;\n+\t}\n+\t/* NAA locally assigned filed */\n+\tnaa = 0x3;\n+\tlocal_value = *(uint64_t *)buf;\n+\tlocal_value = (naa << 60) | (local_value >> 4);\n+\tto_be64((void *)buf, local_value);\n+}\n+\n+static void\n+scsi_task_build_sense_data(struct vhost_scsi_task *task, int sk,\n+\t\t\t   int asc, int ascq)\n+{\n+\tuint8_t *cp;\n+\tint resp_code;\n+\n+\tresp_code = 0x70; /* Current + Fixed format */\n+\n+\t/* Sense Data */\n+\tcp = (uint8_t *)task->resp->sense;\n+\n+\t/* VALID(7) RESPONSE CODE(6-0) */\n+\tcp[0] = 0x80 | resp_code;\n+\t/* Obsolete */\n+\tcp[1] = 0;\n+\t/* FILEMARK(7) EOM(6) ILI(5) SENSE KEY(3-0) */\n+\tcp[2] = sk & 0xf;\n+\t/* INFORMATION */\n+\tmemset(&cp[3], 0, 4);\n+\n+\t/* ADDITIONAL SENSE LENGTH */\n+\tcp[7] = 10;\n+\n+\t/* COMMAND-SPECIFIC INFORMATION */\n+\tmemset(&cp[8], 0, 4);\n+\t/* ADDITIONAL SENSE CODE */\n+\tcp[12] = asc;\n+\t/* ADDITIONAL SENSE CODE QUALIFIER */\n+\tcp[13] = ascq;\n+\t/* FIELD REPLACEABLE UNIT CODE */\n+\tcp[14] = 0;\n+\n+\t/* SKSV(7) SENSE KEY SPECIFIC(6-0,7-0,7-0) */\n+\tcp[15] = 0;\n+\tcp[16] = 0;\n+\tcp[17] = 0;\n+\n+\t/* SenseLength */\n+\ttask->resp->sense_len = 18;\n+}\n+\n+static void\n+scsi_task_set_status(struct vhost_scsi_task *task, int sc, int sk,\n+\t\t     int asc, int ascq)\n+{\n+\tif (sc == SCSI_STATUS_CHECK_CONDITION)\n+\t\tscsi_task_build_sense_data(task, sk, asc, ascq);\n+\ttask->resp->status = sc;\n+}\n+\n+static int\n+vhost_bdev_scsi_inquiry_command(struct vhost_block_dev *bdev,\n+\t\t\t\tstruct vhost_scsi_task *task)\n+{\n+\tint hlen = 0;\n+\tuint32_t alloc_len = 0;\n+\tuint16_t len = 0;\n+\tint pc;\n+\tint pd;\n+\tint evpd;\n+\tint i;\n+\tuint8_t *buf;\n+\tstruct scsi_cdb_inquiry *inq;\n+\n+\tinq = (struct scsi_cdb_inquiry *)task->req->cdb;\n+\n+\tassert(task->iovs_cnt == 1);\n+\n+\t/* At least 36Bytes for inquiry command */\n+\tif (task->data_len < 0x24)\n+\t\tgoto inq_error;\n+\n+\tpd = SPC_PERIPHERAL_DEVICE_TYPE_DISK;\n+\tpc = inq->page_code;\n+\tevpd = inq->evpd & 0x1;\n+\n+\tif (!evpd && pc)\n+\t\tgoto inq_error;\n+\n+\tif (evpd) {\n+\t\tstruct scsi_vpd_page *vpage = (struct scsi_vpd_page *)\n+\t\t\t\t\t      task->iovs[0].iov_base;\n+\n+\t\t/* PERIPHERAL QUALIFIER(7-5) PERIPHERAL DEVICE TYPE(4-0) */\n+\t\tvpage->peripheral = pd;\n+\t\t/* PAGE CODE */\n+\t\tvpage->page_code = pc;\n+\n+\t\tswitch (pc) {\n+\t\tcase SPC_VPD_SUPPORTED_VPD_PAGES:\n+\t\t\thlen = 4;\n+\t\t\tvpage->params[0] = SPC_VPD_SUPPORTED_VPD_PAGES;\n+\t\t\tvpage->params[1] = SPC_VPD_UNIT_SERIAL_NUMBER;\n+\t\t\tvpage->params[2] = SPC_VPD_DEVICE_IDENTIFICATION;\n+\t\t\tlen = 3;\n+\t\t\t/* PAGE LENGTH */\n+\t\t\tto_be16(vpage->alloc_len, len);\n+\t\tbreak;\n+\t\tcase SPC_VPD_UNIT_SERIAL_NUMBER:\n+\t\t\thlen = 4;\n+\t\t\tstrncpy((char *)vpage->params, bdev->name, 32);\n+\t\t\tto_be16(vpage->alloc_len, 32);\n+\t\tbreak;\n+\t\tcase SPC_VPD_DEVICE_IDENTIFICATION:\n+\t\t\tbuf = vpage->params;\n+\t\t\tstruct scsi_desig_desc *desig;\n+\n+\t\t\thlen = 4;\n+\t\t\t/* NAA designator */\n+\t\t\tdesig = (struct scsi_desig_desc *)buf;\n+\t\t\tdesig->code_set = SPC_VPD_CODE_SET_BINARY;\n+\t\t\tdesig->protocol_id = SPC_PROTOCOL_IDENTIFIER_ISCSI;\n+\t\t\tdesig->type = SPC_VPD_IDENTIFIER_TYPE_NAA;\n+\t\t\tdesig->association = SPC_VPD_ASSOCIATION_LOGICAL_UNIT;\n+\t\t\tdesig->reserved0 = 0;\n+\t\t\tdesig->piv = 1;\n+\t\t\tdesig->reserved1 = 0;\n+\t\t\tdesig->len = 8;\n+\t\t\tvhost_bdev_scsi_set_local_naa(bdev->name, desig->desig);\n+\t\t\tlen = sizeof(struct scsi_desig_desc) + 8;\n+\n+\t\t\tbuf += sizeof(struct scsi_desig_desc) + desig->len;\n+\n+\t\t\t/* T10 Vendor ID designator */\n+\t\t\tdesig = (struct scsi_desig_desc *)buf;\n+\t\t\tdesig->code_set = SPC_VPD_CODE_SET_ASCII;\n+\t\t\tdesig->protocol_id = SPC_PROTOCOL_IDENTIFIER_ISCSI;\n+\t\t\tdesig->type = SPC_VPD_IDENTIFIER_TYPE_T10_VENDOR_ID;\n+\t\t\tdesig->association = SPC_VPD_ASSOCIATION_LOGICAL_UNIT;\n+\t\t\tdesig->reserved0 = 0;\n+\t\t\tdesig->piv = 1;\n+\t\t\tdesig->reserved1 = 0;\n+\t\t\tdesig->len = 8 + 16 + 32;\n+\t\t\tstrncpy((char *)desig->desig, \"INTEL\", 8);\n+\t\t\tvhost_strcpy_pad((char *)&desig->desig[8],\n+\t\t\t\t\t bdev->product_name, 16, ' ');\n+\t\t\tstrncpy((char *)&desig->desig[24], bdev->name, 32);\n+\t\t\tlen += sizeof(struct scsi_desig_desc) + 8 + 16 + 32;\n+\n+\t\t\tbuf += sizeof(struct scsi_desig_desc) + desig->len;\n+\n+\t\t\t/* SCSI Device Name designator */\n+\t\t\tdesig = (struct scsi_desig_desc *)buf;\n+\t\t\tdesig->code_set = SPC_VPD_CODE_SET_UTF8;\n+\t\t\tdesig->protocol_id = SPC_PROTOCOL_IDENTIFIER_ISCSI;\n+\t\t\tdesig->type = SPC_VPD_IDENTIFIER_TYPE_SCSI_NAME;\n+\t\t\tdesig->association = SPC_VPD_ASSOCIATION_TARGET_DEVICE;\n+\t\t\tdesig->reserved0 = 0;\n+\t\t\tdesig->piv = 1;\n+\t\t\tdesig->reserved1 = 0;\n+\t\t\tdesig->len = snprintf((char *)desig->desig,\n+\t\t\t\t\t      255, \"%s\", bdev->name);\n+\t\t\tlen += sizeof(struct scsi_desig_desc) + desig->len;\n+\n+\t\t\tbuf += sizeof(struct scsi_desig_desc) + desig->len;\n+\t\t\tto_be16(vpage->alloc_len, len);\n+\t\t\tbreak;\n+\t\tdefault:\n+\t\t\tgoto inq_error;\n+\t\t}\n+\n+\t} else {\n+\t\tstruct scsi_cdb_inquiry_data *inqdata =\n+\t\t\t(struct scsi_cdb_inquiry_data *)task->iovs[0].iov_base;\n+\t\t/* Standard INQUIRY data */\n+\t\t/* PERIPHERAL QUALIFIER(7-5) PERIPHERAL DEVICE TYPE(4-0) */\n+\t\tinqdata->peripheral = pd;\n+\n+\t\t/* RMB(7) */\n+\t\tinqdata->rmb = 0;\n+\n+\t\t/* VERSION */\n+\t\t/* See SPC3/SBC2/MMC4/SAM2 for more details */\n+\t\tinqdata->version = SPC_VERSION_SPC3;\n+\n+\t\t/* NORMACA(5) HISUP(4) RESPONSE DATA FORMAT(3-0) */\n+\t\t/* format 2 */ /* hierarchical support */\n+\t\tinqdata->response = 2 | 1 << 4;\n+\n+\t\thlen = 5;\n+\n+\t\t/* SCCS(7) ACC(6) TPGS(5-4) 3PC(3) PROTECT(0) */\n+\t\t/* Not support TPGS */\n+\t\tinqdata->flags = 0;\n+\n+\t\t/* MULTIP */\n+\t\tinqdata->flags2 = 0x10;\n+\n+\t\t/* WBUS16(5) SYNC(4) LINKED(3) CMDQUE(1) VS(0) */\n+\t\t/* CMDQUE */\n+\t\tinqdata->flags3 = 0x2;\n+\n+\t\t/* T10 VENDOR IDENTIFICATION */\n+\t\tstrncpy((char *)inqdata->t10_vendor_id, \"INTEL\", 8);\n+\n+\t\t/* PRODUCT IDENTIFICATION */\n+\t\tstrncpy((char *)inqdata->product_id, bdev->product_name, 16);\n+\n+\t\t/* PRODUCT REVISION LEVEL */\n+\t\tstrncpy((char *)inqdata->product_rev, \"0001\", 4);\n+\n+\t\t/* Standard inquiry data ends here. Only populate\n+\t\t * remaining fields if alloc_len indicates enough\n+\t\t * space to hold it.\n+\t\t */\n+\t\tlen = INQ_OFFSET(product_rev) - 5;\n+\n+\t\tif (alloc_len >= INQ_OFFSET(vendor)) {\n+\t\t\t/* Vendor specific */\n+\t\t\tmemset(inqdata->vendor, 0x20, 20);\n+\t\t\tlen += sizeof(inqdata->vendor);\n+\t\t}\n+\n+\t\tif (alloc_len >= INQ_OFFSET(ius)) {\n+\t\t\t/* CLOCKING(3-2) QAS(1) IUS(0) */\n+\t\t\tinqdata->ius = 0;\n+\t\t\tlen += sizeof(inqdata->ius);\n+\t\t}\n+\n+\t\tif (alloc_len >= INQ_OFFSET(reserved)) {\n+\t\t\t/* Reserved */\n+\t\t\tinqdata->reserved = 0;\n+\t\t\tlen += sizeof(inqdata->reserved);\n+\t\t}\n+\n+\t\t/* VERSION DESCRIPTOR 1-8 */\n+\t\tif (alloc_len >= INQ_OFFSET(reserved) + 2) {\n+\t\t\tto_be16(&inqdata->desc[0], 0x0960);\n+\t\t\tlen += 2;\n+\t\t}\n+\n+\t\tif (alloc_len >= INQ_OFFSET(reserved) + 4) {\n+\t\t\t/* SPC-3 (no version claimed) */\n+\t\t\tto_be16(&inqdata->desc[2], 0x0300);\n+\t\t\tlen += 2;\n+\t\t}\n+\n+\t\tif (alloc_len >= INQ_OFFSET(reserved) + 6) {\n+\t\t\t/* SBC-2 (no version claimed) */\n+\t\t\tto_be16(&inqdata->desc[4], 0x320);\n+\t\t\tlen += 2;\n+\t\t}\n+\n+\t\tif (alloc_len >= INQ_OFFSET(reserved) + 8) {\n+\t\t\t/* SAM-2 (no version claimed) */\n+\t\t\tto_be16(&inqdata->desc[6], 0x0040);\n+\t\t\tlen += 2;\n+\t\t}\n+\n+\t\tif (alloc_len > INQ_OFFSET(reserved) + 8) {\n+\t\t\ti = alloc_len - (INQ_OFFSET(reserved) + 8);\n+\t\t\tif (i > 30)\n+\t\t\t\ti = 30;\n+\t\t\tmemset(&inqdata->desc[8], 0, i);\n+\t\t\tlen += i;\n+\t\t}\n+\n+\t\t/* ADDITIONAL LENGTH */\n+\t\tinqdata->add_len = len;\n+\t}\n+\n+\t/* STATUS GOOD */\n+\tscsi_task_set_status(task, SCSI_STATUS_GOOD, 0, 0, 0);\n+\treturn hlen + len;\n+\n+inq_error:\n+\tscsi_task_set_status(task, SCSI_STATUS_CHECK_CONDITION,\n+\t\t\t\t     SCSI_SENSE_ILLEGAL_REQUEST,\n+\t\t\t\t     SCSI_ASC_INVALID_FIELD_IN_CDB,\n+\t\t\t\t     SCSI_ASCQ_CAUSE_NOT_REPORTABLE);\n+\treturn 0;\n+}\n+\n+static int\n+vhost_bdev_scsi_readwrite(struct vhost_block_dev *bdev,\n+\t\t\t  struct vhost_scsi_task *task,\n+\t\t\t  uint64_t lba, __rte_unused uint32_t xfer_len)\n+{\n+\tuint32_t i;\n+\tuint64_t offset;\n+\tuint32_t nbytes = 0;\n+\n+\toffset = lba * bdev->blocklen;\n+\n+\tfor (i = 0; i < task->iovs_cnt; i++) {\n+\t\tif (task->dxfer_dir == SCSI_DIR_TO_DEV)\n+\t\t\tmemcpy(bdev->data + offset, task->iovs[i].iov_base,\n+\t\t\t       task->iovs[i].iov_len);\n+\t\telse\n+\t\t\tmemcpy(task->iovs[i].iov_base, bdev->data + offset,\n+\t\t\t       task->iovs[i].iov_len);\n+\t\toffset += task->iovs[i].iov_len;\n+\t\tnbytes += task->iovs[i].iov_len;\n+\t}\n+\n+\treturn nbytes;\n+}\n+\n+static int\n+vhost_bdev_scsi_process_block(struct vhost_block_dev *bdev,\n+\t\t\t      struct vhost_scsi_task *task)\n+{\n+\tuint64_t lba;\n+\tuint32_t xfer_len;\n+\tuint8_t *cdb = (uint8_t *)task->req->cdb;\n+\n+\tswitch (cdb[0]) {\n+\tcase SBC_READ_6:\n+\tcase SBC_WRITE_6:\n+\t\tlba = (uint64_t)cdb[1] << 16;\n+\t\tlba |= (uint64_t)cdb[2] << 8;\n+\t\tlba |= (uint64_t)cdb[3];\n+\t\txfer_len = cdb[4];\n+\t\tif (xfer_len == 0)\n+\t\t\txfer_len = 256;\n+\t\treturn vhost_bdev_scsi_readwrite(bdev, task, lba, xfer_len);\n+\n+\tcase SBC_READ_10:\n+\tcase SBC_WRITE_10:\n+\t\tlba = from_be32(&cdb[2]);\n+\t\txfer_len = from_be16(&cdb[7]);\n+\t\treturn vhost_bdev_scsi_readwrite(bdev, task, lba, xfer_len);\n+\n+\tcase SBC_READ_12:\n+\tcase SBC_WRITE_12:\n+\t\tlba = from_be32(&cdb[2]);\n+\t\txfer_len = from_be32(&cdb[6]);\n+\t\treturn vhost_bdev_scsi_readwrite(bdev, task, lba, xfer_len);\n+\n+\tcase SBC_READ_16:\n+\tcase SBC_WRITE_16:\n+\t\tlba = from_be64(&cdb[2]);\n+\t\txfer_len = from_be32(&cdb[10]);\n+\t\treturn vhost_bdev_scsi_readwrite(bdev, task, lba, xfer_len);\n+\n+\tcase SBC_READ_CAPACITY_10: {\n+\t\tuint8_t buffer[8];\n+\n+\t\tif (bdev->blockcnt - 1 > 0xffffffffULL)\n+\t\t\tmemset(buffer, 0xff, 4);\n+\t\telse\n+\t\t\tto_be32(buffer, bdev->blockcnt - 1);\n+\t\tto_be32(&buffer[4], bdev->blocklen);\n+\t\tmemcpy(task->iovs[0].iov_base, buffer, sizeof(buffer));\n+\t\ttask->resp->status = SCSI_STATUS_GOOD;\n+\t\treturn sizeof(buffer);\n+\t}\n+\n+\tcase SBC_SYNCHRONIZE_CACHE_10:\n+\tcase SBC_SYNCHRONIZE_CACHE_16:\n+\t\ttask->resp->status = SCSI_STATUS_GOOD;\n+\t\treturn 0;\n+\t}\n+\n+\tscsi_task_set_status(task, SCSI_STATUS_CHECK_CONDITION,\n+\t\t\t     SCSI_SENSE_ILLEGAL_REQUEST,\n+\t\t\t     SCSI_ASC_INVALID_FIELD_IN_CDB,\n+\t\t\t     SCSI_ASCQ_CAUSE_NOT_REPORTABLE);\n+\treturn 0;\n+}\n+\n+int\n+vhost_bdev_process_scsi_commands(struct vhost_block_dev *bdev,\n+\t\t\t\t struct vhost_scsi_task *task)\n+{\n+\tint len;\n+\tuint8_t *data;\n+\tuint64_t fmt_lun = 0;\n+\tconst uint8_t *lun;\n+\tuint8_t *cdb = (uint8_t *)task->req->cdb;\n+\n+\tlun = (const uint8_t *)task->req->lun;\n+\t/* only 1 LUN supported */\n+\tif (lun[0] != 1 || lun[1] >= 1)\n+\t\treturn -1;\n+\n+\tswitch (cdb[0]) {\n+\tcase SPC_INQUIRY:\n+\t\tlen = vhost_bdev_scsi_inquiry_command(bdev, task);\n+\t\ttask->data_len = len;\n+\tbreak;\n+\tcase SPC_REPORT_LUNS:\n+\t\tdata = (uint8_t *)task->iovs[0].iov_base;\n+\t\tfmt_lun |= (0x0ULL & 0x00ffULL) << 48;\n+\t\tto_be64((void *)&data[8], fmt_lun);\n+\t\tto_be32((void *)data, 8);\n+\t\ttask->data_len = 16;\n+\t\tscsi_task_set_status(task, SCSI_STATUS_GOOD, 0, 0, 0);\n+\tbreak;\n+\tcase SPC_MODE_SELECT_6:\n+\tcase SPC_MODE_SELECT_10:\n+\t\t/* TODO: Add SCSI Commands support */\n+\t\tscsi_task_set_status(task, SCSI_STATUS_GOOD, 0, 0, 0);\n+\tbreak;\n+\tcase SPC_MODE_SENSE_6:\n+\tcase SPC_MODE_SENSE_10:\n+\t\t/* TODO: Add SCSI Commands support */\n+\t\tscsi_task_set_status(task, SCSI_STATUS_GOOD, 0, 0, 0);\n+\tbreak;\n+\tcase SPC_TEST_UNIT_READY:\n+\t\tscsi_task_set_status(task, SCSI_STATUS_GOOD, 0, 0, 0);\n+\tbreak;\n+\tdefault:\n+\t\tlen = vhost_bdev_scsi_process_block(bdev, task);\n+\t\ttask->data_len = len;\n+\t}\n+\n+\treturn 0;\n+}\ndiff --git a/examples/vhost_scsi/scsi_spec.h b/examples/vhost_scsi/scsi_spec.h\nnew file mode 100644\nindex 0000000..0474d92\n--- /dev/null\n+++ b/examples/vhost_scsi/scsi_spec.h\n@@ -0,0 +1,488 @@\n+/*-\n+ *   BSD LICENSE\n+ *\n+ *   Copyright (c) Intel Corporation.\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+#ifndef _SCSI_SPEC_H\n+#define _SCSI_SPEC_H\n+\n+#include <stdint.h>\n+\n+enum scsi_group_code {\n+\tSCSI_6BYTE_CMD = 0x00,\n+\tSCSI_10BYTE_CMD = 0x20,\n+\tSCSI_10BYTE_CMD2 = 0x40,\n+\tSCSI_16BYTE_CMD = 0x80,\n+\tSCSI_12BYTE_CMD = 0xa0,\n+};\n+\n+#define SCSI_GROUP_MASK\t0xe0\n+#define SCSI_OPCODE_MASK\t0x1f\n+\n+enum scsi_status {\n+\tSCSI_STATUS_GOOD = 0x00,\n+\tSCSI_STATUS_CHECK_CONDITION = 0x02,\n+\tSCSI_STATUS_CONDITION_MET = 0x04,\n+\tSCSI_STATUS_BUSY = 0x08,\n+\tSCSI_STATUS_INTERMEDIATE = 0x10,\n+\tSCSI_STATUS_INTERMEDIATE_CONDITION_MET = 0x14,\n+\tSCSI_STATUS_RESERVATION_CONFLICT = 0x18,\n+\tSCSI_STATUS_Obsolete = 0x22,\n+\tSCSI_STATUS_TASK_SET_FULL = 0x28,\n+\tSCSI_STATUS_ACA_ACTIVE = 0x30,\n+\tSCSI_STATUS_TASK_ABORTED = 0x40,\n+};\n+\n+enum scsi_sense {\n+\tSCSI_SENSE_NO_SENSE = 0x00,\n+\tSCSI_SENSE_RECOVERED_ERROR = 0x01,\n+\tSCSI_SENSE_NOT_READY = 0x02,\n+\tSCSI_SENSE_MEDIUM_ERROR = 0x03,\n+\tSCSI_SENSE_HARDWARE_ERROR = 0x04,\n+\tSCSI_SENSE_ILLEGAL_REQUEST = 0x05,\n+\tSCSI_SENSE_UNIT_ATTENTION = 0x06,\n+\tSCSI_SENSE_DATA_PROTECT = 0x07,\n+\tSCSI_SENSE_BLANK_CHECK = 0x08,\n+\tSCSI_SENSE_VENDOR_SPECIFIC = 0x09,\n+\tSCSI_SENSE_COPY_ABORTED = 0x0a,\n+\tSCSI_SENSE_ABORTED_COMMAND = 0x0b,\n+\tSCSI_SENSE_VOLUME_OVERFLOW = 0x0d,\n+\tSCSI_SENSE_MISCOMPARE = 0x0e,\n+};\n+\n+enum scsi_asc {\n+\tSCSI_ASC_NO_ADDITIONAL_SENSE = 0x00,\n+\tSCSI_ASC_PERIPHERAL_DEVICE_WRITE_FAULT = 0x03,\n+\tSCSI_ASC_LOGICAL_UNIT_NOT_READY = 0x04,\n+\tSCSI_ASC_WARNING = 0x0b,\n+\tSCSI_ASC_LOGICAL_BLOCK_GUARD_CHECK_FAILED = 0x10,\n+\tSCSI_ASC_LOGICAL_BLOCK_APP_TAG_CHECK_FAILED = 0x10,\n+\tSCSI_ASC_LOGICAL_BLOCK_REF_TAG_CHECK_FAILED = 0x10,\n+\tSCSI_ASC_UNRECOVERED_READ_ERROR = 0x11,\n+\tSCSI_ASC_MISCOMPARE_DURING_VERIFY_OPERATION = 0x1d,\n+\tSCSI_ASC_INVALID_COMMAND_OPERATION_CODE = 0x20,\n+\tSCSI_ASC_ACCESS_DENIED = 0x20,\n+\tSCSI_ASC_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE = 0x21,\n+\tSCSI_ASC_INVALID_FIELD_IN_CDB = 0x24,\n+\tSCSI_ASC_LOGICAL_UNIT_NOT_SUPPORTED = 0x25,\n+\tSCSI_ASC_WRITE_PROTECTED = 0x27,\n+\tSCSI_ASC_FORMAT_COMMAND_FAILED = 0x31,\n+\tSCSI_ASC_INTERNAL_TARGET_FAILURE = 0x44,\n+};\n+\n+enum scsi_ascq {\n+\tSCSI_ASCQ_CAUSE_NOT_REPORTABLE = 0x00,\n+\tSCSI_ASCQ_BECOMING_READY = 0x01,\n+\tSCSI_ASCQ_FORMAT_COMMAND_FAILED = 0x01,\n+\tSCSI_ASCQ_LOGICAL_BLOCK_GUARD_CHECK_FAILED = 0x01,\n+\tSCSI_ASCQ_LOGICAL_BLOCK_APP_TAG_CHECK_FAILED = 0x02,\n+\tSCSI_ASCQ_NO_ACCESS_RIGHTS = 0x02,\n+\tSCSI_ASCQ_LOGICAL_BLOCK_REF_TAG_CHECK_FAILED = 0x03,\n+\tSCSI_ASCQ_POWER_LOSS_EXPECTED = 0x08,\n+\tSCSI_ASCQ_INVALID_LU_IDENTIFIER = 0x09,\n+};\n+\n+enum spc_opcode {\n+\t/* SPC3 related */\n+\tSPC_ACCESS_CONTROL_IN = 0x86,\n+\tSPC_ACCESS_CONTROL_OUT = 0x87,\n+\tSPC_EXTENDED_COPY = 0x83,\n+\tSPC_INQUIRY = 0x12,\n+\tSPC_LOG_SELECT = 0x4c,\n+\tSPC_LOG_SENSE = 0x4d,\n+\tSPC_MODE_SELECT_6 = 0x15,\n+\tSPC_MODE_SELECT_10 = 0x55,\n+\tSPC_MODE_SENSE_6 = 0x1a,\n+\tSPC_MODE_SENSE_10 = 0x5a,\n+\tSPC_PERSISTENT_RESERVE_IN = 0x5e,\n+\tSPC_PERSISTENT_RESERVE_OUT = 0x5f,\n+\tSPC_PREVENT_ALLOW_MEDIUM_REMOVAL = 0x1e,\n+\tSPC_READ_ATTRIBUTE = 0x8c,\n+\tSPC_READ_BUFFER = 0x3c,\n+\tSPC_RECEIVE_COPY_RESULTS = 0x84,\n+\tSPC_RECEIVE_DIAGNOSTIC_RESULTS = 0x1c,\n+\tSPC_REPORT_LUNS = 0xa0,\n+\tSPC_REQUEST_SENSE = 0x03,\n+\tSPC_SEND_DIAGNOSTIC = 0x1d,\n+\tSPC_TEST_UNIT_READY = 0x00,\n+\tSPC_WRITE_ATTRIBUTE = 0x8d,\n+\tSPC_WRITE_BUFFER = 0x3b,\n+\n+\tSPC_SERVICE_ACTION_IN_12 = 0xab,\n+\tSPC_SERVICE_ACTION_OUT_12 = 0xa9,\n+\tSPC_SERVICE_ACTION_IN_16 = 0x9e,\n+\tSPC_SERVICE_ACTION_OUT_16 = 0x9f,\n+\n+\tSPC_VARIABLE_LENGTH = 0x7f,\n+\n+\tSPC_MO_CHANGE_ALIASES = 0x0b,\n+\tSPC_MO_SET_DEVICE_IDENTIFIER = 0x06,\n+\tSPC_MO_SET_PRIORITY = 0x0e,\n+\tSPC_MO_SET_TARGET_PORT_GROUPS = 0x0a,\n+\tSPC_MO_SET_TIMESTAMP = 0x0f,\n+\tSPC_MI_REPORT_ALIASES = 0x0b,\n+\tSPC_MI_REPORT_DEVICE_IDENTIFIER = 0x05,\n+\tSPC_MI_REPORT_PRIORITY = 0x0e,\n+\tSPC_MI_REPORT_SUPPORTED_OPERATION_CODES = 0x0c,\n+\tSPC_MI_REPORT_SUPPORTED_TASK_MANAGEMENT_FUNCTIONS = 0x0d,\n+\tSPC_MI_REPORT_TARGET_PORT_GROUPS = 0x0a,\n+\tSPC_MI_REPORT_TIMESTAMP = 0x0f,\n+\n+\t/* SPC2 related (Obsolete) */\n+\tSPC2_RELEASE_6 = 0x17,\n+\tSPC2_RELEASE_10 = 0x57,\n+\tSPC2_RESERVE_6 = 0x16,\n+\tSPC2_RESERVE_10 = 0x56,\n+};\n+\n+enum scc_opcode {\n+\tSCC_MAINTENANCE_IN = 0xa3,\n+\tSCC_MAINTENANCE_OUT = 0xa4,\n+};\n+\n+enum sbc_opcode {\n+\tSBC_COMPARE_AND_WRITE = 0x89,\n+\tSBC_FORMAT_UNIT = 0x04,\n+\tSBC_GET_LBA_STATUS = 0x0012009e,\n+\tSBC_ORWRITE_16 = 0x8b,\n+\tSBC_PRE_FETCH_10 = 0x34,\n+\tSBC_PRE_FETCH_16 = 0x90,\n+\tSBC_READ_6 = 0x08,\n+\tSBC_READ_10 = 0x28,\n+\tSBC_READ_12 = 0xa8,\n+\tSBC_READ_16 = 0x88,\n+\tSBC_READ_ATTRIBUTE = 0x8c,\n+\tSBC_READ_BUFFER = 0x3c,\n+\tSBC_READ_CAPACITY_10 = 0x25,\n+\tSBC_READ_DEFECT_DATA_10 = 0x37,\n+\tSBC_READ_DEFECT_DATA_12 = 0xb7,\n+\tSBC_READ_LONG_10 = 0x3e,\n+\tSBC_REASSIGN_BLOCKS = 0x07,\n+\tSBC_SANITIZE = 0x48,\n+\tSBC_START_STOP_UNIT = 0x1b,\n+\tSBC_SYNCHRONIZE_CACHE_10 = 0x35,\n+\tSBC_SYNCHRONIZE_CACHE_16 = 0x91,\n+\tSBC_UNMAP = 0x42,\n+\tSBC_VERIFY_10 = 0x2f,\n+\tSBC_VERIFY_12 = 0xaf,\n+\tSBC_VERIFY_16 = 0x8f,\n+\tSBC_WRITE_6 = 0x0a,\n+\tSBC_WRITE_10 = 0x2a,\n+\tSBC_WRITE_12 = 0xaa,\n+\tSBC_WRITE_16 = 0x8a,\n+\tSBC_WRITE_AND_VERIFY_10 = 0x2e,\n+\tSBC_WRITE_AND_VERIFY_12 = 0xae,\n+\tSBC_WRITE_AND_VERIFY_16 = 0x8e,\n+\tSBC_WRITE_LONG_10 = 0x3f,\n+\tSBC_WRITE_SAME_10 = 0x41,\n+\tSBC_WRITE_SAME_16 = 0x93,\n+\tSBC_XDREAD_10 = 0x52,\n+\tSBC_XDWRITE_10 = 0x50,\n+\tSBC_XDWRITEREAD_10 = 0x53,\n+\tSBC_XPWRITE_10 = 0x51,\n+\n+\tSBC_SAI_READ_CAPACITY_16 = 0x10,\n+\tSBC_SAI_READ_LONG_16 = 0x11,\n+\tSBC_SAO_WRITE_LONG_16 = 0x11,\n+\n+\tSBC_VL_READ_32 = 0x0009,\n+\tSBC_VL_VERIFY_32 = 0x000a,\n+\tSBC_VL_WRITE_32 = 0x000b,\n+\tSBC_VL_WRITE_AND_VERIFY_32 = 0x000c,\n+\tSBC_VL_WRITE_SAME_32 = 0x000d,\n+\tSBC_VL_XDREAD_32 = 0x0003,\n+\tSBC_VL_XDWRITE_32 = 0x0004,\n+\tSBC_VL_XDWRITEREAD_32 = 0x0007,\n+\tSBC_VL_XPWRITE_32 = 0x0006,\n+};\n+\n+enum mmc_opcode {\n+\t/* MMC6 */\n+\tMMC_READ_DISC_STRUCTURE = 0xad,\n+\n+\t/* MMC4 */\n+\tMMC_BLANK = 0xa1,\n+\tMMC_CLOSE_TRACK_SESSION = 0x5b,\n+\tMMC_ERASE_10 = 0x2c,\n+\tMMC_FORMAT_UNIT = 0x04,\n+\tMMC_GET_CONFIGURATION = 0x46,\n+\tMMC_GET_EVENT_STATUS_NOTIFICATION = 0x4a,\n+\tMMC_GET_PERFORMANCE = 0xac,\n+\tMMC_INQUIRY = 0x12,\n+\tMMC_LOAD_UNLOAD_MEDIUM = 0xa6,\n+\tMMC_MECHANISM_STATUS = 0xbd,\n+\tMMC_MODE_SELECT_10 = 0x55,\n+\tMMC_MODE_SENSE_10 = 0x5a,\n+\tMMC_PAUSE_RESUME = 0x4b,\n+\tMMC_PLAY_AUDIO_10 = 0x45,\n+\tMMC_PLAY_AUDIO_12 = 0xa5,\n+\tMMC_PLAY_AUDIO_MSF = 0x47,\n+\tMMC_PREVENT_ALLOW_MEDIUM_REMOVAL = 0x1e,\n+\tMMC_READ_10 = 0x28,\n+\tMMC_READ_12 = 0xa8,\n+\tMMC_READ_BUFFER = 0x3c,\n+\tMMC_READ_BUFFER_CAPACITY = 0x5c,\n+\tMMC_READ_CAPACITY = 0x25,\n+\tMMC_READ_CD = 0xbe,\n+\tMMC_READ_CD_MSF = 0xb9,\n+\tMMC_READ_DISC_INFORMATION = 0x51,\n+\tMMC_READ_DVD_STRUCTURE = 0xad,\n+\tMMC_READ_FORMAT_CAPACITIES = 0x23,\n+\tMMC_READ_SUB_CHANNEL = 0x42,\n+\tMMC_READ_TOC_PMA_ATIP = 0x43,\n+\tMMC_READ_TRACK_INFORMATION = 0x52,\n+\tMMC_REPAIR_TRACK = 0x58,\n+\tMMC_REPORT_KEY = 0xa4,\n+\tMMC_REQUEST_SENSE = 0x03,\n+\tMMC_RESERVE_TRACK = 0x53,\n+\tMMC_SCAN = 0xba,\n+\tMMC_SEEK_10 = 0x2b,\n+\tMMC_SEND_CUE_SHEET = 0x5d,\n+\tMMC_SEND_DVD_STRUCTURE = 0xbf,\n+\tMMC_SEND_KEY = 0xa3,\n+\tMMC_SEND_OPC_INFORMATION = 0x54,\n+\tMMC_SET_CD_SPEED = 0xbb,\n+\tMMC_SET_READ_AHEAD = 0xa7,\n+\tMMC_SET_STREAMING = 0xb6,\n+\tMMC_START_STOP_UNIT = 0x1b,\n+\tMMC_STOP_PLAY_SCAN = 0x4e,\n+\tMMC_SYNCHRONIZE_CACHE = 0x35,\n+\tMMC_TEST_UNIT_READY = 0x00,\n+\tMMC_VERIFY_10 = 0x2f,\n+\tMMC_WRITE_10 = 0xa2,\n+\tMMC_WRITE_12 = 0xaa,\n+\tMMC_WRITE_AND_VERIFY_10 = 0x2e,\n+\tMMC_WRITE_BUFFER = 0x3b,\n+};\n+\n+enum ssc_opcode {\n+\tSSC_ERASE_6 = 0x19,\n+\tSSC_FORMAT_MEDIUM = 0x04,\n+\tSSC_LOAD_UNLOAD = 0x1b,\n+\tSSC_LOCATE_10 = 0x2b,\n+\tSSC_LOCATE_16 = 0x92,\n+\tSSC_MOVE_MEDIUM_ATTACHED = 0xa7,\n+\tSSC_READ_6 = 0x08,\n+\tSSC_READ_BLOCK_LIMITS = 0x05,\n+\tSSC_READ_ELEMENT_STATUS_ATTACHED = 0xb4,\n+\tSSC_READ_POSITION = 0x34,\n+\tSSC_READ_REVERSE_6 = 0x0f,\n+\tSSC_RECOVER_BUFFERED_DATA = 0x14,\n+\tSSC_REPORT_DENSITY_SUPPORT = 0x44,\n+\tSSC_REWIND = 0x01,\n+\tSSC_SET_CAPACITY = 0x0b,\n+\tSSC_SPACE_6 = 0x11,\n+\tSSC_SPACE_16 = 0x91,\n+\tSSC_VERIFY_6 = 0x13,\n+\tSSC_WRITE_6 = 0x0a,\n+\tSSC_WRITE_FILEMARKS_6 = 0x10,\n+};\n+\n+enum spc_vpd {\n+\tSPC_VPD_DEVICE_IDENTIFICATION = 0x83,\n+\tSPC_VPD_EXTENDED_INQUIRY_DATA = 0x86,\n+\tSPC_VPD_MANAGEMENT_NETWORK_ADDRESSES = 0x85,\n+\tSPC_VPD_MODE_PAGE_POLICY = 0x87,\n+\tSPC_VPD_SCSI_PORTS = 0x88,\n+\tSPC_VPD_SOFTWARE_INTERFACE_IDENTIFICATION = 0x84,\n+\tSPC_VPD_SUPPORTED_VPD_PAGES = 0x00,\n+\tSPC_VPD_UNIT_SERIAL_NUMBER = 0x80,\n+\tSPC_VPD_BLOCK_LIMITS = 0xb0,\n+\tSPC_VPD_BLOCK_DEV_CHARS = 0xb1,\n+\tSPC_VPD_BLOCK_THIN_PROVISION = 0xb2,\n+};\n+\n+enum {\n+\tSPC_PERIPHERAL_DEVICE_TYPE_DISK = 0x00,\n+\tSPC_PERIPHERAL_DEVICE_TYPE_TAPE = 0x01,\n+\tSPC_PERIPHERAL_DEVICE_TYPE_DVD = 0x05,\n+\tSPC_PERIPHERAL_DEVICE_TYPE_CHANGER = 0x08,\n+\n+\tSPC_VERSION_NONE = 0x00,\n+\tSPC_VERSION_SPC = 0x03,\n+\tSPC_VERSION_SPC2 = 0x04,\n+\tSPC_VERSION_SPC3 = 0x05,\n+\tSPC_VERSION_SPC4 = 0x06,\n+\n+\tSPC_PROTOCOL_IDENTIFIER_FC = 0x00,\n+\tSPC_PROTOCOL_IDENTIFIER_PSCSI = 0x01,\n+\tSPC_PROTOCOL_IDENTIFIER_SSA = 0x02,\n+\tSPC_PROTOCOL_IDENTIFIER_IEEE1394 = 0x03,\n+\tSPC_PROTOCOL_IDENTIFIER_RDMA = 0x04,\n+\tSPC_PROTOCOL_IDENTIFIER_ISCSI = 0x05,\n+\tSPC_PROTOCOL_IDENTIFIER_SAS = 0x06,\n+\tSPC_PROTOCOL_IDENTIFIER_ADT = 0x07,\n+\tSPC_PROTOCOL_IDENTIFIER_ATA = 0x08,\n+\n+\tSPC_VPD_CODE_SET_BINARY = 0x01,\n+\tSPC_VPD_CODE_SET_ASCII = 0x02,\n+\tSPC_VPD_CODE_SET_UTF8 = 0x03,\n+\n+\tSPC_VPD_ASSOCIATION_LOGICAL_UNIT = 0x00,\n+\tSPC_VPD_ASSOCIATION_TARGET_PORT = 0x01,\n+\tSPC_VPD_ASSOCIATION_TARGET_DEVICE = 0x02,\n+\n+\tSPC_VPD_IDENTIFIER_TYPE_VENDOR_SPECIFIC = 0x00,\n+\tSPC_VPD_IDENTIFIER_TYPE_T10_VENDOR_ID = 0x01,\n+\tSPC_VPD_IDENTIFIER_TYPE_EUI64 = 0x02,\n+\tSPC_VPD_IDENTIFIER_TYPE_NAA = 0x03,\n+\tSPC_VPD_IDENTIFIER_TYPE_RELATIVE_TARGET_PORT = 0x04,\n+\tSPC_VPD_IDENTIFIER_TYPE_TARGET_PORT_GROUP = 0x05,\n+\tSPC_VPD_IDENTIFIER_TYPE_LOGICAL_UNIT_GROUP = 0x06,\n+\tSPC_VPD_IDENTIFIER_TYPE_MD5_LOGICAL_UNIT = 0x07,\n+\tSPC_VPD_IDENTIFIER_TYPE_SCSI_NAME = 0x08,\n+};\n+\n+struct scsi_cdb_inquiry {\n+\tuint8_t opcode;\n+\tuint8_t evpd;\n+\tuint8_t page_code;\n+\tuint8_t alloc_len[2];\n+\tuint8_t control;\n+};\n+\n+struct scsi_cdb_inquiry_data {\n+\tuint8_t peripheral;\n+\tuint8_t rmb;\n+\tuint8_t version;\n+\tuint8_t response;\n+\tuint8_t add_len;\n+\tuint8_t flags;\n+\tuint8_t flags2;\n+\tuint8_t flags3;\n+\tuint8_t t10_vendor_id[8];\n+\tuint8_t product_id[16];\n+\tuint8_t product_rev[4];\n+\tuint8_t vendor[20];\n+\tuint8_t ius;\n+\tuint8_t reserved;\n+\tuint8_t desc[];\n+};\n+\n+struct scsi_vpd_page {\n+\tuint8_t peripheral;\n+\tuint8_t page_code;\n+\tuint8_t alloc_len[2];\n+\tuint8_t params[];\n+};\n+\n+#define SCSI_VEXT_REF_CHK\t\t0x01\n+#define SCSI_VEXT_APP_CHK\t\t0x02\n+#define SCSI_VEXT_GRD_CHK\t\t0x04\n+#define SCSI_VEXT_SIMPSUP\t\t0x01\n+#define SCSI_VEXT_ORDSUP\t\t0x02\n+#define SCSI_VEXT_HEADSUP\t\t0x04\n+#define SCSI_VEXT_PRIOR_SUP\t0x08\n+#define SCSI_VEXT_GROUP_SUP\t0x10\n+#define SCSI_VEXT_UASK_SUP\t\t0x20\n+#define SCSI_VEXT_V_SUP\t\t0x01\n+#define SCSI_VEXT_NV_SUP\t\t0x02\n+#define SCSI_VEXT_CRD_SUP\t\t0x04\n+#define SCSI_VEXT_WU_SUP\t\t0x08\n+\n+struct scsi_vpd_ext_inquiry {\n+\tuint8_t peripheral;\n+\tuint8_t page_code;\n+\tuint8_t alloc_len[2];\n+\tuint8_t check;\n+\tuint8_t sup;\n+\tuint8_t sup2;\n+\tuint8_t luiclr;\n+\tuint8_t cbcs;\n+\tuint8_t micro_dl;\n+\tuint8_t reserved[54];\n+};\n+\n+#define SPC_VPD_DESIG_PIV\t0x80\n+\n+/* designation descriptor */\n+struct scsi_desig_desc {\n+\tuint8_t code_set\t: 4;\n+\tuint8_t protocol_id\t: 4;\n+\tuint8_t type\t\t: 4;\n+\tuint8_t association\t: 2;\n+\tuint8_t reserved0\t: 1;\n+\tuint8_t piv\t\t: 1;\n+\tuint8_t reserved1;\n+\tuint8_t\tlen;\n+\tuint8_t desig[];\n+};\n+\n+/* mode page policy descriptor */\n+struct scsi_mpage_policy_desc {\n+\tuint8_t page_code;\n+\tuint8_t sub_page_code;\n+\tuint8_t policy;\n+\tuint8_t reserved;\n+};\n+\n+/* target port descriptor */\n+struct scsi_tgt_port_desc {\n+\tuint8_t code_set;\n+\tuint8_t desig_type;\n+\tuint8_t reserved;\n+\tuint8_t\tlen;\n+\tuint8_t designator[];\n+};\n+\n+/* SCSI port designation descriptor */\n+struct scsi_port_desc {\n+\tuint16_t reserved;\n+\tuint16_t rel_port_id;\n+\tuint16_t reserved2;\n+\tuint16_t init_port_len;\n+\tuint16_t init_port_id;\n+\tuint16_t reserved3;\n+\tuint16_t tgt_desc_len;\n+\tuint8_t tgt_desc[];\n+};\n+\n+/* SCSI UNMAP block descriptor */\n+struct scsi_unmap_bdesc {\n+\t/* UNMAP LOGICAL BLOCK ADDRESS */\n+\tuint64_t lba;\n+\n+\t/* NUMBER OF LOGICAL BLOCKS */\n+\tuint32_t block_count;\n+\n+\t/* RESERVED */\n+\tuint32_t reserved;\n+};\n+\n+#define SCSI_UNMAP_LBPU\t\t\t\t(1 << 7)\n+#define SCSI_UNMAP_LBPWS\t\t\t(1 << 6)\n+#define SCSI_UNMAP_LBPWS10\t\t\t(1 << 5)\n+\n+#define SCSI_UNMAP_FULL_PROVISIONING\t0x00\n+#define SCSI_UNMAP_RESOURCE_PROVISIONING\t0x01\n+#define SCSI_UNMAP_THIN_PROVISIONING\t0x02\n+\n+#endif /* _SCSI_SPEC_H */\ndiff --git a/examples/vhost_scsi/vhost_scsi.c b/examples/vhost_scsi/vhost_scsi.c\nnew file mode 100644\nindex 0000000..160c2e0\n--- /dev/null\n+++ b/examples/vhost_scsi/vhost_scsi.c\n@@ -0,0 +1,472 @@\n+/*-\n+ *   BSD LICENSE\n+ *\n+ *   Copyright(c) 2010-2017 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 <unistd.h>\n+#include <stdbool.h>\n+#include <signal.h>\n+#include <assert.h>\n+#include <semaphore.h>\n+#include <linux/virtio_scsi.h>\n+#include <linux/virtio_ring.h>\n+\n+#include <rte_atomic.h>\n+#include <rte_cycles.h>\n+#include <rte_log.h>\n+#include <rte_malloc.h>\n+#include <rte_vhost.h>\n+\n+#include \"vhost_scsi.h\"\n+#include \"scsi_spec.h\"\n+\n+#define VIRTIO_SCSI_FEATURES ((1 << VIRTIO_F_NOTIFY_ON_EMPTY) |\\\n+\t\t\t      (1 << VIRTIO_RING_F_EVENT_IDX) |\\\n+\t\t\t      (1 << VIRTIO_SCSI_F_INOUT) |\\\n+\t\t\t      (1 << VIRTIO_SCSI_F_CHANGE))\n+\n+/* Path to folder where character device will be created. Can be set by user. */\n+static char dev_pathname[PATH_MAX] = \"\";\n+\n+static struct vhost_scsi_ctrlr *g_vhost_ctrlr;\n+static int g_should_stop;\n+static sem_t exit_sem;\n+\n+#define NUM_OF_SCSI_QUEUES 3\n+\n+static struct vhost_scsi_ctrlr *\n+vhost_scsi_ctrlr_find(__rte_unused const char *ctrlr_name)\n+{\n+\t/* currently we only support 1 socket file fd */\n+\treturn g_vhost_ctrlr;\n+}\n+\n+static uint64_t gpa_to_vva(int vid, uint64_t gpa)\n+{\n+\tchar path[PATH_MAX];\n+\tstruct vhost_scsi_ctrlr *ctrlr;\n+\tint ret = 0;\n+\n+\tret = rte_vhost_get_ifname(vid, path, PATH_MAX);\n+\tif (ret) {\n+\t\tfprintf(stderr, \"Cannot get socket name\\n\");\n+\t\tassert(ret != 0);\n+\t}\n+\n+\tctrlr = vhost_scsi_ctrlr_find(path);\n+\tif (!ctrlr) {\n+\t\tfprintf(stderr, \"Controller is not ready\\n\");\n+\t\tassert(ctrlr != NULL);\n+\t}\n+\n+\tassert(ctrlr->mem != NULL);\n+\n+\treturn rte_vhost_gpa_to_vva(ctrlr->mem, gpa);\n+}\n+\n+static struct vring_desc *\n+descriptor_get_next(struct vring_desc *vq_desc, struct vring_desc *cur_desc)\n+{\n+\treturn &vq_desc[cur_desc->next];\n+}\n+\n+static bool\n+descriptor_has_next(struct vring_desc *cur_desc)\n+{\n+\treturn !!(cur_desc->flags & VRING_DESC_F_NEXT);\n+}\n+\n+static bool\n+descriptor_is_wr(struct vring_desc *cur_desc)\n+{\n+\treturn !!(cur_desc->flags & VRING_DESC_F_WRITE);\n+}\n+\n+static void\n+submit_completion(struct vhost_scsi_task *task)\n+{\n+\tstruct rte_vhost_vring *vq;\n+\tstruct vring_used *used;\n+\n+\tvq = task->vq;\n+\tused = vq->used;\n+\t/* Fill out the next entry in the \"used\" ring.  id = the\n+\t * index of the descriptor that contained the SCSI request.\n+\t * len = the total amount of data transferred for the SCSI\n+\t * request. We must report the correct len, for variable\n+\t * length SCSI CDBs, where we may return less data than\n+\t * allocated by the guest VM.\n+\t */\n+\tused->ring[used->idx & (vq->size - 1)].id = task->req_idx;\n+\tused->ring[used->idx & (vq->size - 1)].len = task->data_len;\n+\tused->idx++;\n+\n+\t/* Send an interrupt back to the guest VM so that it knows\n+\t * a completion is ready to be processed.\n+\t */\n+\teventfd_write(vq->callfd, (eventfd_t)1);\n+}\n+\n+static void\n+vhost_process_read_payload_chain(struct vhost_scsi_task *task)\n+{\n+\tvoid *data;\n+\n+\ttask->iovs_cnt = 0;\n+\ttask->resp = (void *)gpa_to_vva(task->bdev->vid, task->desc->addr);\n+\n+\twhile (descriptor_has_next(task->desc)) {\n+\t\ttask->desc = descriptor_get_next(task->vq->desc, task->desc);\n+\t\tdata = (void *)gpa_to_vva(task->bdev->vid, task->desc->addr);\n+\t\ttask->iovs[task->iovs_cnt].iov_base = data;\n+\t\ttask->iovs[task->iovs_cnt].iov_len = task->desc->len;\n+\t\ttask->data_len += task->desc->len;\n+\t\ttask->iovs_cnt++;\n+\t}\n+}\n+\n+static void\n+vhost_process_write_payload_chain(struct vhost_scsi_task *task)\n+{\n+\tvoid *data;\n+\n+\ttask->iovs_cnt = 0;\n+\n+\tdo {\n+\t\tdata = (void *)gpa_to_vva(task->bdev->vid, task->desc->addr);\n+\t\ttask->iovs[task->iovs_cnt].iov_base = data;\n+\t\ttask->iovs[task->iovs_cnt].iov_len = task->desc->len;\n+\t\ttask->data_len += task->desc->len;\n+\t\ttask->iovs_cnt++;\n+\t\ttask->desc = descriptor_get_next(task->vq->desc, task->desc);\n+\t} while (descriptor_has_next(task->desc));\n+\n+\ttask->resp = (void *)gpa_to_vva(task->bdev->vid, task->desc->addr);\n+}\n+\n+static struct vhost_block_dev *\n+vhost_scsi_bdev_construct(const char *bdev_name, const char *bdev_serial,\n+\t\t\t  uint32_t blk_size, uint64_t blk_cnt,\n+\t\t\t  bool wce_enable)\n+{\n+\tstruct vhost_block_dev *bdev;\n+\n+\tbdev = rte_zmalloc(NULL, sizeof(*bdev), RTE_CACHE_LINE_SIZE);\n+\tif (!bdev)\n+\t\treturn NULL;\n+\n+\tstrncpy(bdev->name, bdev_name, sizeof(bdev->name));\n+\tstrncpy(bdev->product_name, bdev_serial, sizeof(bdev->product_name));\n+\tbdev->blocklen = blk_size;\n+\tbdev->blockcnt = blk_cnt;\n+\tbdev->write_cache = wce_enable;\n+\n+\t/* use memory as disk storage space */\n+\tbdev->data = rte_zmalloc(NULL, blk_cnt * blk_size, 0);\n+\tif (!bdev->data) {\n+\t\tfprintf(stderr, \"no enough reseverd huge memory for disk\\n\");\n+\t\treturn NULL;\n+\t}\n+\n+\treturn bdev;\n+}\n+\n+static void\n+process_requestq(struct vhost_scsi_ctrlr *ctrlr, uint32_t q_idx)\n+{\n+\tint ret;\n+\tstruct vhost_scsi_queue *scsi_vq;\n+\tstruct rte_vhost_vring *vq;\n+\n+\tscsi_vq = &ctrlr->bdev->queues[q_idx];\n+\tvq = &scsi_vq->vq;\n+\tret = rte_vhost_get_vhost_vring(ctrlr->bdev->vid, q_idx, vq);\n+\tassert(ret == 0);\n+\n+\twhile (vq->avail->idx != scsi_vq->last_used_idx) {\n+\t\tint req_idx;\n+\t\tuint16_t last_idx;\n+\t\tstruct vhost_scsi_task *task;\n+\n+\t\tlast_idx = scsi_vq->last_used_idx & (vq->size - 1);\n+\t\treq_idx = vq->avail->ring[last_idx];\n+\n+\t\ttask = rte_zmalloc(NULL, sizeof(*task), 0);\n+\t\tassert(task != NULL);\n+\n+\t\ttask->ctrlr = ctrlr;\n+\t\ttask->bdev = ctrlr->bdev;\n+\t\ttask->vq = vq;\n+\t\ttask->req_idx = req_idx;\n+\t\ttask->desc = &task->vq->desc[task->req_idx];\n+\n+\t\t/* does not support indirect descriptors */\n+\t\tassert((task->desc->flags & VRING_DESC_F_INDIRECT) == 0);\n+\t\tscsi_vq->last_used_idx++;\n+\n+\t\ttask->req = (void *)gpa_to_vva(task->bdev->vid,\n+\t\t\t\t\t       task->desc->addr);\n+\n+\t\ttask->desc = descriptor_get_next(task->vq->desc, task->desc);\n+\t\tif (!descriptor_has_next(task->desc)) {\n+\t\t\ttask->dxfer_dir = SCSI_DIR_NONE;\n+\t\t\ttask->resp = (void *)gpa_to_vva(task->bdev->vid,\n+\t\t\t\t\t\t\ttask->desc->addr);\n+\n+\t\t} else if (!descriptor_is_wr(task->desc)) {\n+\t\t\ttask->dxfer_dir = SCSI_DIR_TO_DEV;\n+\t\t\tvhost_process_write_payload_chain(task);\n+\t\t} else {\n+\t\t\ttask->dxfer_dir = SCSI_DIR_FROM_DEV;\n+\t\t\tvhost_process_read_payload_chain(task);\n+\t\t}\n+\n+\t\tret = vhost_bdev_process_scsi_commands(ctrlr->bdev, task);\n+\t\tif (ret) {\n+\t\t\t/* invalid response */\n+\t\t\ttask->resp->response = VIRTIO_SCSI_S_BAD_TARGET;\n+\t\t} else {\n+\t\t\t/* successfully */\n+\t\t\ttask->resp->response = VIRTIO_SCSI_S_OK;\n+\t\t\ttask->resp->status = 0;\n+\t\t}\n+\t\tsubmit_completion(task);\n+\t\trte_free(task);\n+\t}\n+}\n+\n+/* Main framework for processing IOs */\n+static void *\n+ctrlr_worker(void *arg)\n+{\n+\tuint32_t idx, num;\n+\tstruct vhost_scsi_ctrlr *ctrlr = (struct vhost_scsi_ctrlr *)arg;\n+\tcpu_set_t cpuset;\n+\tpthread_t thread;\n+\n+\tthread = pthread_self();\n+\tCPU_ZERO(&cpuset);\n+\tCPU_SET(0, &cpuset);\n+\tpthread_setaffinity_np(thread, sizeof(cpu_set_t), &cpuset);\n+\n+\tnum =  rte_vhost_get_vring_num(ctrlr->bdev->vid);\n+\tfprintf(stdout, \"Ctrlr Worker Thread Started with %u Vring\\n\", num);\n+\n+\tif (num != NUM_OF_SCSI_QUEUES) {\n+\t\tfprintf(stderr, \"Only 1 IO queue are supported\\n\");\n+\t\texit(0);\n+\t}\n+\n+\twhile (!g_should_stop && ctrlr->bdev != NULL) {\n+\t\t/* At least 3 vrings, currently only can support 1 IO queue\n+\t\t * Queue 2 for IO queue, does not support TMF and hotplug\n+\t\t * for the example application now\n+\t\t */\n+\t\tfor (idx = 2; idx < num; idx++)\n+\t\t\tprocess_requestq(ctrlr, idx);\n+\t}\n+\n+\tfprintf(stdout, \"Ctrlr Worker Thread Exiting\\n\");\n+\tsem_post(&exit_sem);\n+\treturn NULL;\n+}\n+\n+static int\n+new_device(int vid)\n+{\n+\tchar path[PATH_MAX];\n+\tstruct vhost_scsi_ctrlr *ctrlr;\n+\tstruct vhost_scsi_queue *scsi_vq;\n+\tstruct rte_vhost_vring *vq;\n+\tpthread_t tid;\n+\tint i, ret;\n+\n+\tret = rte_vhost_get_ifname(vid, path, PATH_MAX);\n+\tif (ret) {\n+\t\tfprintf(stderr, \"Cannot get socket name\\n\");\n+\t\treturn -1;\n+\t}\n+\n+\tctrlr = vhost_scsi_ctrlr_find(path);\n+\tif (!ctrlr) {\n+\t\tfprintf(stderr, \"Controller is not ready\\n\");\n+\t\treturn -1;\n+\t}\n+\n+\tret = rte_vhost_get_mem_table(vid, &ctrlr->mem);\n+\tif (ret) {\n+\t\tfprintf(stderr, \"Get Controller memory region failed\\n\");\n+\t\treturn -1;\n+\t}\n+\tassert(ctrlr->mem != NULL);\n+\n+\t/* hardcoded block device information with 128MiB */\n+\tctrlr->bdev = vhost_scsi_bdev_construct(\"malloc0\", \"vhost_scsi_malloc0\",\n+\t\t\t\t\t\t4096, 32768, 0);\n+\tif (!ctrlr->bdev)\n+\t\treturn -1;\n+\n+\tctrlr->bdev->vid = vid;\n+\n+\t/* Disable Notifications */\n+\tfor (i = 0; i < NUM_OF_SCSI_QUEUES; i++) {\n+\t\trte_vhost_enable_guest_notification(vid, i, 0);\n+\t\t/* restore used index */\n+\t\tscsi_vq = &ctrlr->bdev->queues[i];\n+\t\tvq = &scsi_vq->vq;\n+\t\tret = rte_vhost_get_vhost_vring(ctrlr->bdev->vid, i, vq);\n+\t\tassert(ret == 0);\n+\t\tscsi_vq->last_used_idx = vq->used->idx;\n+\t\tscsi_vq->last_avail_idx = vq->used->idx;\n+\t}\n+\n+\tg_should_stop = 0;\n+\tfprintf(stdout, \"New Device %s, Device ID %d\\n\", path, vid);\n+\tif (pthread_create(&tid, NULL, &ctrlr_worker, ctrlr) < 0) {\n+\t\tfprintf(stderr, \"Worker Thread Started Failed\\n\");\n+\t\treturn -1;\n+\t}\n+\tpthread_detach(tid);\n+\treturn 0;\n+}\n+\n+static void\n+destroy_device(int vid)\n+{\n+\tchar path[PATH_MAX];\n+\tstruct vhost_scsi_ctrlr *ctrlr;\n+\n+\trte_vhost_get_ifname(vid, path, PATH_MAX);\n+\tfprintf(stdout, \"Destroy %s Device ID %d\\n\", path, vid);\n+\tctrlr = vhost_scsi_ctrlr_find(path);\n+\tif (!ctrlr) {\n+\t\tfprintf(stderr, \"Destroy Ctrlr Failed\\n\");\n+\t\treturn;\n+\t}\n+\tctrlr->bdev = NULL;\n+\tg_should_stop = 1;\n+\n+\tsem_wait(&exit_sem);\n+}\n+\n+static const struct vhost_device_ops vhost_scsi_device_ops = {\n+\t.new_device =  new_device,\n+\t.destroy_device = destroy_device,\n+};\n+\n+static struct vhost_scsi_ctrlr *\n+vhost_scsi_ctrlr_construct(const char *ctrlr_name)\n+{\n+\tint ret;\n+\tstruct vhost_scsi_ctrlr *ctrlr;\n+\tchar *path;\n+\tchar cwd[PATH_MAX];\n+\n+\t/* always use current directory */\n+\tpath = getcwd(cwd, PATH_MAX);\n+\tif (!path) {\n+\t\tfprintf(stderr, \"Cannot get current working directory\\n\");\n+\t\treturn NULL;\n+\t}\n+\tsnprintf(dev_pathname, sizeof(dev_pathname), \"%s/%s\", path, ctrlr_name);\n+\n+\tif (access(dev_pathname, F_OK) != -1) {\n+\t\tif (unlink(dev_pathname) != 0)\n+\t\t\trte_exit(EXIT_FAILURE, \"Cannot remove %s.\\n\",\n+\t\t\t\t dev_pathname);\n+\t}\n+\n+\tfprintf(stdout, \"socket file: %s\\n\", dev_pathname);\n+\n+\tif (rte_vhost_driver_register(dev_pathname, 0) != 0) {\n+\t\tfprintf(stderr, \"socket %s already exists\\n\", dev_pathname);\n+\t\treturn NULL;\n+\t}\n+\n+\tret = rte_vhost_driver_set_features(dev_pathname, VIRTIO_SCSI_FEATURES);\n+\tif (ret) {\n+\t\tfprintf(stderr, \"Set vhost driver features failed\\n\");\n+\t\treturn NULL;\n+\t}\n+\n+\tctrlr = rte_zmalloc(NULL, sizeof(*ctrlr), RTE_CACHE_LINE_SIZE);\n+\tif (!ctrlr)\n+\t\treturn NULL;\n+\n+\tctrlr->name = strdup(ctrlr_name);\n+\n+\trte_vhost_driver_callback_register(dev_pathname,\n+\t\t\t\t\t   &vhost_scsi_device_ops);\n+\n+\treturn ctrlr;\n+}\n+\n+static void\n+signal_handler(__rte_unused int signum)\n+{\n+\n+\tif (access(dev_pathname, F_OK) == 0)\n+\t\tunlink(dev_pathname);\n+\texit(0);\n+}\n+\n+int main(int argc, char *argv[])\n+{\n+\tint ret;\n+\n+\tsignal(SIGINT, signal_handler);\n+\n+\t/* init EAL */\n+\tret = rte_eal_init(argc, argv);\n+\tif (ret < 0)\n+\t\trte_exit(EXIT_FAILURE, \"Error with EAL initialization\\n\");\n+\n+\tg_vhost_ctrlr = vhost_scsi_ctrlr_construct(\"vhost.socket\");\n+\tif (g_vhost_ctrlr == NULL) {\n+\t\tfprintf(stderr, \"Construct vhost scsi controller failed\\n\");\n+\t\treturn 0;\n+\t}\n+\n+\tif (sem_init(&exit_sem, 0, 0) < 0) {\n+\t\tfprintf(stderr, \"Error init exit_sem\\n\");\n+\t\treturn -1;\n+\t}\n+\n+\trte_vhost_driver_start(dev_pathname);\n+\n+\t/* loop for exit the application */\n+\twhile (1)\n+\t\tsleep(1);\n+\n+\treturn 0;\n+}\n+\ndiff --git a/examples/vhost_scsi/vhost_scsi.h b/examples/vhost_scsi/vhost_scsi.h\nnew file mode 100644\nindex 0000000..b5340cc\n--- /dev/null\n+++ b/examples/vhost_scsi/vhost_scsi.h\n@@ -0,0 +1,250 @@\n+/*-\n+ *   BSD LICENSE\n+ *\n+ *   Copyright(c) 2010-2017 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+#ifndef _VHOST_SCSI_H_\n+#define _VHOST_SCSI_H_\n+\n+#include <sys/uio.h>\n+#include <stdint.h>\n+#include <linux/virtio_scsi.h>\n+#include <linux/virtio_ring.h>\n+\n+#include <rte_vhost.h>\n+\n+static inline uint16_t\n+from_be16(const void *ptr)\n+{\n+\tconst uint8_t *tmp = (const uint8_t *)ptr;\n+\n+\treturn (((uint16_t)tmp[0] << 8) | tmp[1]);\n+}\n+\n+static inline void\n+to_be16(void *out, uint16_t in)\n+{\n+\tuint8_t *tmp = (uint8_t *)out;\n+\n+\ttmp[0] = (in >> 8) & 0xFF;\n+\ttmp[1] = in & 0xFF;\n+}\n+\n+static inline uint32_t\n+from_be32(const void *ptr)\n+{\n+\tconst uint8_t *tmp = (const uint8_t *)ptr;\n+\n+\treturn (((uint32_t)tmp[0] << 24) |\n+\t\t((uint32_t)tmp[1] << 16) |\n+\t\t((uint32_t)tmp[2] << 8) |\n+\t\t((uint32_t)tmp[3]));\n+}\n+\n+static inline void\n+to_be32(void *out, uint32_t in)\n+{\n+\tuint8_t *tmp = (uint8_t *)out;\n+\n+\ttmp[0] = (in >> 24) & 0xFF;\n+\ttmp[1] = (in >> 16) & 0xFF;\n+\ttmp[2] = (in >> 8) & 0xFF;\n+\ttmp[3] = in & 0xFF;\n+}\n+\n+static inline uint64_t\n+from_be64(const void *ptr)\n+{\n+\tconst uint8_t *tmp = (const uint8_t *)ptr;\n+\n+\treturn (((uint64_t)tmp[0] << 56) |\n+\t\t((uint64_t)tmp[1] << 48) |\n+\t\t((uint64_t)tmp[2] << 40) |\n+\t\t((uint64_t)tmp[3] << 32) |\n+\t\t((uint64_t)tmp[4] << 24) |\n+\t\t((uint64_t)tmp[5] << 16) |\n+\t\t((uint64_t)tmp[6] << 8) |\n+\t\t((uint64_t)tmp[7]));\n+}\n+\n+static inline void\n+to_be64(void *out, uint64_t in)\n+{\n+\tuint8_t *tmp = (uint8_t *)out;\n+\n+\ttmp[0] = (in >> 56) & 0xFF;\n+\ttmp[1] = (in >> 48) & 0xFF;\n+\ttmp[2] = (in >> 40) & 0xFF;\n+\ttmp[3] = (in >> 32) & 0xFF;\n+\ttmp[4] = (in >> 24) & 0xFF;\n+\ttmp[5] = (in >> 16) & 0xFF;\n+\ttmp[6] = (in >> 8) & 0xFF;\n+\ttmp[7] = in & 0xFF;\n+}\n+\n+static inline uint16_t\n+from_le16(const void *ptr)\n+{\n+\tconst uint8_t *tmp = (const uint8_t *)ptr;\n+\n+\treturn (((uint16_t)tmp[1] << 8) | tmp[0]);\n+}\n+\n+static inline void\n+to_le16(void *out, uint16_t in)\n+{\n+\tuint8_t *tmp = (uint8_t *)out;\n+\n+\ttmp[1] = (in >> 8) & 0xFF;\n+\ttmp[0] = in & 0xFF;\n+}\n+\n+static inline uint32_t\n+from_le32(const void *ptr)\n+{\n+\tconst uint8_t *tmp = (const uint8_t *)ptr;\n+\n+\treturn (((uint32_t)tmp[3] << 24) |\n+\t\t((uint32_t)tmp[2] << 16) |\n+\t\t((uint32_t)tmp[1] << 8) |\n+\t\t((uint32_t)tmp[0]));\n+}\n+\n+static inline void\n+to_le32(void *out, uint32_t in)\n+{\n+\tuint8_t *tmp = (uint8_t *)out;\n+\n+\ttmp[3] = (in >> 24) & 0xFF;\n+\ttmp[2] = (in >> 16) & 0xFF;\n+\ttmp[1] = (in >> 8) & 0xFF;\n+\ttmp[0] = in & 0xFF;\n+}\n+\n+static inline uint64_t\n+from_le64(const void *ptr)\n+{\n+\tconst uint8_t *tmp = (const uint8_t *)ptr;\n+\n+\treturn (((uint64_t)tmp[7] << 56) |\n+\t\t((uint64_t)tmp[6] << 48) |\n+\t\t((uint64_t)tmp[5] << 40) |\n+\t\t((uint64_t)tmp[4] << 32) |\n+\t\t((uint64_t)tmp[3] << 24) |\n+\t\t((uint64_t)tmp[2] << 16) |\n+\t\t((uint64_t)tmp[1] << 8) |\n+\t\t((uint64_t)tmp[0]));\n+}\n+\n+static inline void\n+to_le64(void *out, uint64_t in)\n+{\n+\tuint8_t *tmp = (uint8_t *)out;\n+\n+\ttmp[7] = (in >> 56) & 0xFF;\n+\ttmp[6] = (in >> 48) & 0xFF;\n+\ttmp[5] = (in >> 40) & 0xFF;\n+\ttmp[4] = (in >> 32) & 0xFF;\n+\ttmp[3] = (in >> 24) & 0xFF;\n+\ttmp[2] = (in >> 16) & 0xFF;\n+\ttmp[1] = (in >> 8) & 0xFF;\n+\ttmp[0] = in & 0xFF;\n+}\n+\n+struct vaddr_region {\n+\tvoid *vaddr;\n+\tuint64_t len;\n+};\n+\n+struct vhost_scsi_queue {\n+\tstruct rte_vhost_vring vq;\n+\tuint16_t last_avail_idx;\n+\tuint16_t last_used_idx;\n+};\n+\n+struct vhost_block_dev {\n+\t/** ID for vhost library. */\n+\tint vid;\n+\t/** Queues for the block device */\n+\tstruct vhost_scsi_queue queues[8];\n+\t/** Unique name for this block device. */\n+\tchar name[64];\n+\n+\t/** Unique product name for this kind of block device. */\n+\tchar product_name[256];\n+\n+\t/** Size in bytes of a logical block for the backend */\n+\tuint32_t blocklen;\n+\n+\t/** Number of blocks */\n+\tuint64_t blockcnt;\n+\n+\t/** write cache enabled, not used at the moment */\n+\tint write_cache;\n+\n+\t/** use memory as disk storage space */\n+\tuint8_t *data;\n+};\n+\n+struct vhost_scsi_ctrlr {\n+\tchar *name;\n+\t/** Only support 1 LUN for the example */\n+\tstruct vhost_block_dev *bdev;\n+\t/** VM memory region */\n+\tstruct rte_vhost_memory *mem;\n+} __rte_cache_aligned;\n+\n+#define VHOST_SCSI_MAX_IOVS 128\n+\n+enum scsi_data_dir {\n+\tSCSI_DIR_NONE = 0,\n+\tSCSI_DIR_TO_DEV = 1,\n+\tSCSI_DIR_FROM_DEV = 2,\n+};\n+\n+struct vhost_scsi_task {\n+\tint req_idx;\n+\tuint32_t dxfer_dir;\n+\tuint32_t data_len;\n+\tstruct virtio_scsi_cmd_req *req;\n+\tstruct virtio_scsi_cmd_resp *resp;\n+\tstruct iovec iovs[VHOST_SCSI_MAX_IOVS];\n+\tuint32_t iovs_cnt;\n+\tstruct vring_desc *desc;\n+\tstruct rte_vhost_vring *vq;\n+\tstruct vhost_block_dev *bdev;\n+\tstruct vhost_scsi_ctrlr *ctrlr;\n+};\n+\n+int vhost_bdev_process_scsi_commands(struct vhost_block_dev *bdev,\n+\t\t\t\t     struct vhost_scsi_task *task);\n+\n+#endif /* _VHOST_SCSI_H_ */\n",
    "prefixes": [
        "dpdk-dev",
        "v2"
    ]
}