nvmf_example: add an nvmf example

use the nvmf lib to add an nvmf example which
doesn't use the spdk app framework. It can show
how to use the nvmf lib to build your own nvmf target.

We encouage you to use the RPC cmds so this example will
not supply the configuration file. You can read the
README.md to get the steps how to build your nvmf target
and test the IO status.

Change-Id: I8d175934f7364d40fb44d36e85c31d8ea5063654
Signed-off-by: JinYu <jin.yu@intel.com>
Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/468457
Community-CI: Broadcom SPDK FC-NVMe CI <spdk-ci.pdl@broadcom.com>
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
Reviewed-by: Changpeng Liu <changpeng.liu@intel.com>
Reviewed-by: GangCao <gang.cao@intel.com>
This commit is contained in:
JinYu 2019-08-26 17:21:54 +08:00 committed by Tomasz Zawadzki
parent 83bcd693b0
commit b9793e6809
8 changed files with 271 additions and 1 deletions

View File

@ -34,7 +34,7 @@
SPDK_ROOT_DIR := $(abspath $(CURDIR)/..)
include $(SPDK_ROOT_DIR)/mk/spdk.common.mk
DIRS-y += bdev blob ioat nvme sock vmd
DIRS-y += bdev blob ioat nvme sock vmd nvmf
.PHONY: all clean $(DIRS-y)

44
examples/nvmf/Makefile Normal file
View File

@ -0,0 +1,44 @@
#
# BSD LICENSE
#
# Copyright (c) Intel Corporation.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in
# the documentation and/or other materials provided with the
# distribution.
# * Neither the name of Intel Corporation nor the names of its
# contributors may be used to endorse or promote products derived
# from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
SPDK_ROOT_DIR := $(abspath $(CURDIR)/../..)
include $(SPDK_ROOT_DIR)/mk/spdk.common.mk
DIRS-y += nvmf
.PHONY: all clean $(DIRS-y)
all: $(DIRS-y)
clean: $(DIRS-y)
include $(SPDK_ROOT_DIR)/mk/spdk.subdirs.mk

1
examples/nvmf/nvmf/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
nvmf

View File

@ -0,0 +1,44 @@
#
# BSD LICENSE
#
# Copyright (c) Intel Corporation.
# Copyright (c) 2015-2016, Micron Technology, Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in
# the documentation and/or other materials provided with the
# distribution.
# * Neither the name of Intel Corporation nor the names of its
# contributors may be used to endorse or promote products derived
# from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
SPDK_ROOT_DIR := $(abspath $(CURDIR)/../../..)
include $(SPDK_ROOT_DIR)/mk/spdk.common.mk
include $(SPDK_ROOT_DIR)/mk/spdk.modules.mk
APP := nvmf
C_SRCS := nvmf.c
SPDK_LIB_LIST = $(ALL_MODULES_LIST)
SPDK_LIB_LIST += nvmf thread util bdev conf copy rpc jsonrpc json log sock trace notify
include $(SPDK_ROOT_DIR)/mk/spdk.app.mk

View File

@ -0,0 +1,30 @@
NVMe-oF target without SPDK event framework
============================================================================================================
# Overview
This example is used to show how to use the nvmf lib. In this example we want to encourage user
to use RPC cmd so we would only support RPC style.
# Usage:
This example's usage is very similar with nvmf_tgt, difference is that you must use the RPC cmd
to setup the nvmf target.
First, start this example app. You can use the -m to specify how many cores you want to use.
The other parameters you can use -h to show.
./nvmf -m 0xf -r /var/tmp/spdk.sock
Then, you need to use the RPC cmd to config the nvmf target. You can use the -h to get how many
RPC cmd you can use. As this example is about nvmf so I think you can focus on the nvmf cmds and
the bdev cmds.
./scripts/rpc.py -h
Next, You should use the RPC cmd to setup nvmf target.
./scripts/rpc.py nvmf_create_transport -t RDMA -g nvmf_example
./scripts/rpc.py nvmf_create_subsystem -t nvmf_example -s SPDK00000000000001 -a -m 32 nqn.2016-06.io.spdk:cnode1
./scripts/rpc.py bdev_malloc_create -b Malloc1 128 512
./scripts/rpc.py nvmf_subsystem_add_ns -t nvmf_example nqn.2016-06.io.spdk:cnode1 Malloc1
./scripts/rpc.py nvmf_subsystem_add_listener -t rdma -f Ipv4 -a 192.168.0.10 -s 4420 -p nvmf_example nqn.2016-06.io.spdk:cnode1
Last, start the initiator to connect the nvmf example target and test the IOs
$ROOT_SPDK/example/nvme/perf/perf -q 64 -o 4095 -w randrw -M 30 -l -t 60 \
-r "trtype:RDMA adrfam:IPv4 traddr:192.168.0.10 trsvcid:4420 subnqn:nqn.2016-06.io.spdk:cnode1"

116
examples/nvmf/nvmf/nvmf.c Normal file
View File

@ -0,0 +1,116 @@
/*-
* BSD LICENSE
*
* Copyright (c) Intel Corporation.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Intel Corporation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "spdk/stdinc.h"
#include "spdk/env.h"
#include "spdk/event.h"
#include "spdk/string.h"
static const char *g_rpc_addr = SPDK_DEFAULT_RPC_ADDR;
static void
usage(char *program_name)
{
printf("%s options", program_name);
printf("\n");
printf("\t[-h show this usage]\n");
printf("\t[-i shared memory ID (optional)]\n");
printf("\t[-m core mask for DPDK]\n");
printf("\t[-r RPC listen address (default /var/tmp/spdk.sock)]\n");
printf("\t[-s memory size in MB for DPDK (default: 0MB)]\n");
printf("\t[-u disable PCI access]\n");
}
static int
parse_args(int argc, char **argv, struct spdk_env_opts *opts)
{
int op;
long int value;
while ((op = getopt(argc, argv, "i:m:r:s:u:h")) != -1) {
switch (op) {
case 'i':
value = spdk_strtol(optarg, 10);
if (value < 0) {
fprintf(stderr, "converting a string to integer failed\n");
return -EINVAL;
}
opts->shm_id = value;
break;
case 'm':
opts->core_mask = optarg;
break;
case 'r':
g_rpc_addr = optarg;
break;
case 's':
value = spdk_strtol(optarg, 10);
if (value < 0) {
fprintf(stderr, "converting a string to integer failed\n");
return -EINVAL;
}
opts->mem_size = value;
break;
case 'u':
opts->no_pci = true;
break;
case 'h':
default:
usage(argv[0]);
return 1;
}
}
return 0;
}
int main(int argc, char **argv)
{
int rc;
struct spdk_env_opts opts;
spdk_env_opts_init(&opts);
opts.name = "nvmf-example";
rc = parse_args(argc, argv, &opts);
if (rc != 0) {
return rc;
}
if (spdk_env_init(&opts) < 0) {
fprintf(stderr, "unable to initialize SPDK env\n");
return -EINVAL;
}
return rc;
}

View File

@ -13,6 +13,7 @@ trap "exit 1" SIGINT SIGTERM EXIT
TEST_ARGS=( "$@" )
run_test suite "nvmf_example" test/nvmf/target/nvmf_example.sh "${TEST_ARGS[@]}"
run_test suite "nvmf_filesystem" test/nvmf/target/filesystem.sh "${TEST_ARGS[@]}"
run_test suite "nvmf_discovery" test/nvmf/target/discovery.sh "${TEST_ARGS[@]}"
run_test suite "nvmf_connect_disconnect" test/nvmf/target/connect_disconnect.sh "${TEST_ARGS[@]}"

View File

@ -0,0 +1,34 @@
#!/usr/bin/env bash
testdir=$(readlink -f $(dirname $0))
rootdir=$(readlink -f $testdir/../../..)
source $rootdir/test/common/autotest_common.sh
source $rootdir/test/nvmf/common.sh
rpc_py="$rootdir/scripts/rpc.py"
function build_nvmf_example_args()
{
if [ $SPDK_RUN_NON_ROOT -eq 1 ]; then
echo "sudo -u $(logname) ./examples/nvmf/nvmf/nvmf -i $NVMF_APP_SHM_ID"
else
echo "./examples/nvmf/nvmf/nvmf -i $NVMF_APP_SHM_ID"
fi
}
NVMF_EXAMPLE="$(build_nvmf_example_args)"
function nvmfexamplestart()
{
timing_enter start_nvmf_example
$NVMF_EXAMPLE $1
nvmfpid=$!
timing_exit start_nvmf_example
}
timing_enter nvmf_example_test
nvmftestinit
nvmfexamplestart "-m 0xF"
nvmftestfini
timing_exit nvmf_example_test