diff --git a/CHANGELOG.md b/CHANGELOG.md index 9f85733e3..ae19ceeb8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,17 @@ a null name parameter and will return the only available target. The majority of the NVMe-oF RPCs now accept an optional tgt_name parameter. This will allow those RPCs to work with applications that create more than one target. +Three new NVMe-oF RPCs have been added `nvmf_create_target`, `nvmf_delete_target`, and +`nvmf_get_targets`. These new RPCs provide a basic interface for managing multiple target +objects. In SPDK the target object defines a unique discovery service. As of this release, +these RPCs are not intended to be used with the in-tree SPDK target applications, spdk_tgt and +nvmf_tgt, which use a single, global target structure. As such, they are not included in scripts/rpc.py + +Three new header functions have also been added to help deal with multiple targets. +`spdk_nvmf_tgt_get_name` takes a target pointer as an argument and returns its human readable name. +`spdk_nvmf_get_first_target` takes no arguments and returns the first target in the global list. +`spdk_nvmf_get_next_tgt` takes a target pointer as an argument and returns the next one in the global list. + ### bdev A new spdk_bdev_open_ext function has been added and spdk_bdev_open function has been deprecated. diff --git a/lib/nvmf/nvmf_rpc.c b/lib/nvmf/nvmf_rpc.c index f6c432b92..77c75ee19 100644 --- a/lib/nvmf/nvmf_rpc.c +++ b/lib/nvmf/nvmf_rpc.c @@ -1501,6 +1501,36 @@ spdk_rpc_nvmf_delete_target(struct spdk_jsonrpc_request *request, } SPDK_RPC_REGISTER("nvmf_delete_target", spdk_rpc_nvmf_delete_target, SPDK_RPC_RUNTIME); +static void +spdk_rpc_nvmf_get_targets(struct spdk_jsonrpc_request *request, + const struct spdk_json_val *params) +{ + struct spdk_json_write_ctx *w; + struct spdk_nvmf_tgt *tgt; + const char *name; + + if (params != NULL) { + spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, + "nvmf_get_targets has no parameters."); + return; + } + + w = spdk_jsonrpc_begin_result(request); + spdk_json_write_array_begin(w); + + tgt = spdk_nvmf_get_first_tgt(); + + while (tgt != NULL) { + name = spdk_nvmf_tgt_get_name(tgt); + spdk_json_write_string(w, name); + tgt = spdk_nvmf_get_next_tgt(tgt); + } + + spdk_json_write_array_end(w); + spdk_jsonrpc_end_result(request, w); +} +SPDK_RPC_REGISTER("nvmf_get_targets", spdk_rpc_nvmf_get_targets, SPDK_RPC_RUNTIME); + struct nvmf_rpc_create_transport_ctx { char *trtype; char *tgt_name; diff --git a/scripts/rpc/nvmf.py b/scripts/rpc/nvmf.py index a8920d5d3..eecfb9b20 100644 --- a/scripts/rpc/nvmf.py +++ b/scripts/rpc/nvmf.py @@ -75,6 +75,16 @@ def nvmf_delete_target(client, return client.call("nvmf_delete_target", params) +def nvmf_get_targets(client): + """Get a list of all the NVMe-oF targets in this application + + Returns: + An array of target names. + """ + + return client.call("nvmf_get_targets") + + def nvmf_create_transport(client, trtype, tgt_name=None,