diff --git a/module/bdev/nvme/bdev_nvme_rpc.c b/module/bdev/nvme/bdev_nvme_rpc.c index 3541b2e96..50e449fcc 100644 --- a/module/bdev/nvme/bdev_nvme_rpc.c +++ b/module/bdev/nvme/bdev_nvme_rpc.c @@ -390,6 +390,16 @@ rpc_bdev_nvme_attach_controller(struct spdk_jsonrpc_request *request, /* This controller already exists. Verify the parameters match sufficiently. */ opts = spdk_nvme_ctrlr_get_opts(ctrlr->ctrlr); + if (strncmp(trid.subnqn, + spdk_nvme_ctrlr_get_transport_id(ctrlr->ctrlr)->subnqn, + SPDK_NVMF_NQN_MAX_LEN) != 0) { + /* Different SUBNQN is not allowed when specifying the same controller name. */ + spdk_jsonrpc_send_error_response_fmt(request, -EINVAL, + "A controller named %s already exists, but uses a different subnqn (%s)\n", + ctx->req.name, spdk_nvme_ctrlr_get_transport_id(ctrlr->ctrlr)->subnqn); + goto cleanup; + } + if (strncmp(ctx->req.opts.hostnqn, opts->hostnqn, SPDK_NVMF_NQN_MAX_LEN) != 0) { /* Different HOSTNQN is not allowed when specifying the same controller name. */ spdk_jsonrpc_send_error_response_fmt(request, -EINVAL, diff --git a/test/nvmf/host/multicontroller.sh b/test/nvmf/host/multicontroller.sh index 86c077341..3a8b077b5 100755 --- a/test/nvmf/host/multicontroller.sh +++ b/test/nvmf/host/multicontroller.sh @@ -24,12 +24,21 @@ nvmftestinit nvmfappstart -m 0xF $rpc_py nvmf_create_transport $NVMF_TRANSPORT_OPTS -u 8192 + $rpc_py bdev_malloc_create $MALLOC_BDEV_SIZE $MALLOC_BLOCK_SIZE -b Malloc0 $rpc_py nvmf_create_subsystem nqn.2016-06.io.spdk:cnode1 -a -s SPDK00000000000001 $rpc_py nvmf_subsystem_add_ns nqn.2016-06.io.spdk:cnode1 Malloc0 + $rpc_py nvmf_subsystem_add_listener nqn.2016-06.io.spdk:cnode1 -t $TEST_TRANSPORT -a $NVMF_FIRST_TARGET_IP -s $NVMF_PORT $rpc_py nvmf_subsystem_add_listener nqn.2016-06.io.spdk:cnode1 -t $TEST_TRANSPORT -a $NVMF_FIRST_TARGET_IP -s $NVMF_SECOND_PORT +$rpc_py bdev_malloc_create $MALLOC_BDEV_SIZE $MALLOC_BLOCK_SIZE -b Malloc1 +$rpc_py nvmf_create_subsystem nqn.2016-06.io.spdk:cnode2 -a -s SPDK00000000000002 +$rpc_py nvmf_subsystem_add_ns nqn.2016-06.io.spdk:cnode2 Malloc1 + +$rpc_py nvmf_subsystem_add_listener nqn.2016-06.io.spdk:cnode2 -t $TEST_TRANSPORT -a $NVMF_FIRST_TARGET_IP -s $NVMF_PORT +$rpc_py nvmf_subsystem_add_listener nqn.2016-06.io.spdk:cnode2 -t $TEST_TRANSPORT -a $NVMF_FIRST_TARGET_IP -s $NVMF_SECOND_PORT + $rootdir/test/bdev/bdevperf/bdevperf -z -r $bdevperf_rpc_sock -q 128 -o 4096 -w write -t 1 -f &> $testdir/try.txt & bdevperf_pid=$! @@ -51,6 +60,10 @@ NOT $rpc_py -s $bdevperf_rpc_sock bdev_nvme_attach_controller -b NVMe0 -t $TEST_ -s $NVMF_PORT -f ipv4 -n nqn.2016-06.io.spdk:cnode1 -i $NVMF_FIRST_TARGET_IP -c $NVMF_HOST_FIRST_PORT \ -q nqn.2021-09-7.io.spdk:00001 +# try to attach with same controller name but different subnqn. Should fail. +NOT $rpc_py -s $bdevperf_rpc_sock bdev_nvme_attach_controller -b NVMe0 -t $TEST_TRANSPORT -a $NVMF_FIRST_TARGET_IP \ + -s $NVMF_PORT -f ipv4 -n nqn.2016-06.io.spdk:cnode2 -i $NVMF_FIRST_TARGET_IP -c $NVMF_HOST_FIRST_PORT + # Add a second path without specifying the host information. Should pass. $rpc_py -s $bdevperf_rpc_sock bdev_nvme_attach_controller -b NVMe0 -t $TEST_TRANSPORT -a $NVMF_FIRST_TARGET_IP \ -s $NVMF_SECOND_PORT -f ipv4 -n nqn.2016-06.io.spdk:cnode1 @@ -76,6 +89,7 @@ $rpc_py -s $bdevperf_rpc_sock bdev_nvme_detach_controller NVMe1 killprocess $bdevperf_pid $rpc_py nvmf_delete_subsystem nqn.2016-06.io.spdk:cnode1 +$rpc_py nvmf_delete_subsystem nqn.2016-06.io.spdk:cnode2 trap - SIGINT SIGTERM EXIT