diff --git a/examples/Makefile b/examples/Makefile index 25585fb666..26601e4d77 100644 --- a/examples/Makefile +++ b/examples/Makefile @@ -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) diff --git a/examples/nvmf/Makefile b/examples/nvmf/Makefile new file mode 100644 index 0000000000..f340274069 --- /dev/null +++ b/examples/nvmf/Makefile @@ -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 diff --git a/examples/nvmf/nvmf/.gitignore b/examples/nvmf/nvmf/.gitignore new file mode 100644 index 0000000000..461c836767 --- /dev/null +++ b/examples/nvmf/nvmf/.gitignore @@ -0,0 +1 @@ +nvmf diff --git a/examples/nvmf/nvmf/Makefile b/examples/nvmf/nvmf/Makefile new file mode 100644 index 0000000000..70563f1634 --- /dev/null +++ b/examples/nvmf/nvmf/Makefile @@ -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 diff --git a/examples/nvmf/nvmf/README.md b/examples/nvmf/nvmf/README.md new file mode 100644 index 0000000000..830062cb40 --- /dev/null +++ b/examples/nvmf/nvmf/README.md @@ -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" diff --git a/examples/nvmf/nvmf/nvmf.c b/examples/nvmf/nvmf/nvmf.c new file mode 100644 index 0000000000..adc1947052 --- /dev/null +++ b/examples/nvmf/nvmf/nvmf.c @@ -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; +} diff --git a/test/nvmf/nvmf.sh b/test/nvmf/nvmf.sh index 8bb0978469..aac80e5c9c 100755 --- a/test/nvmf/nvmf.sh +++ b/test/nvmf/nvmf.sh @@ -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[@]}" diff --git a/test/nvmf/target/nvmf_example.sh b/test/nvmf/target/nvmf_example.sh new file mode 100755 index 0000000000..14e7596740 --- /dev/null +++ b/test/nvmf/target/nvmf_example.sh @@ -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