nvmf: allow to query only specified subsystem

Similar is already done for json-rpc bdev_get_bdevs, it might be
useful for the upper layer which has no interest in all but only
in one specified.

Signed-off-by: Jacek Kalwas <jacek.kalwas@intel.com>
Change-Id: I25f7d20ff953e612d7982207d57607f1c3bbaa90
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/9361
Community-CI: Broadcom CI <spdk-ci.pdl@broadcom.com>
Community-CI: Mellanox Build Bot
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Tomasz Zawadzki <tomasz.zawadzki@intel.com>
Reviewed-by: Aleksey Marchuk <alexeymar@mellanox.com>
This commit is contained in:
Jacek Kalwas 2021-09-01 06:26:30 -04:00 committed by Tomasz Zawadzki
parent bf22ddc60f
commit dfafab22af
3 changed files with 33 additions and 10 deletions

View File

@ -185,10 +185,12 @@ decode_ns_uuid(const struct spdk_json_val *val, void *out)
}
struct rpc_get_subsystem {
char *nqn;
char *tgt_name;
};
static const struct spdk_json_object_decoder rpc_get_subsystem_decoders[] = {
{"nqn", offsetof(struct rpc_get_subsystem, nqn), spdk_json_decode_string, true},
{"tgt_name", offsetof(struct rpc_get_subsystem, tgt_name), spdk_json_decode_string, true},
};
@ -308,7 +310,7 @@ rpc_nvmf_get_subsystems(struct spdk_jsonrpc_request *request,
{
struct rpc_get_subsystem req = { 0 };
struct spdk_json_write_ctx *w;
struct spdk_nvmf_subsystem *subsystem;
struct spdk_nvmf_subsystem *subsystem = NULL;
struct spdk_nvmf_tgt *tgt;
if (params) {
@ -326,19 +328,37 @@ rpc_nvmf_get_subsystems(struct spdk_jsonrpc_request *request,
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INTERNAL_ERROR,
"Unable to find a target.");
free(req.tgt_name);
free(req.nqn);
return;
}
if (req.nqn) {
subsystem = spdk_nvmf_tgt_find_subsystem(tgt, req.nqn);
if (!subsystem) {
SPDK_ERRLOG("subsystem '%s' does not exist\n", req.nqn);
spdk_jsonrpc_send_error_response(request, -ENODEV, spdk_strerror(ENODEV));
free(req.tgt_name);
free(req.nqn);
return;
}
}
w = spdk_jsonrpc_begin_result(request);
spdk_json_write_array_begin(w);
subsystem = spdk_nvmf_subsystem_get_first(tgt);
while (subsystem) {
if (subsystem) {
dump_nvmf_subsystem(w, subsystem);
subsystem = spdk_nvmf_subsystem_get_next(subsystem);
} else {
for (subsystem = spdk_nvmf_subsystem_get_first(tgt); subsystem != NULL;
subsystem = spdk_nvmf_subsystem_get_next(subsystem)) {
dump_nvmf_subsystem(w, subsystem);
}
}
spdk_json_write_array_end(w);
spdk_jsonrpc_end_result(request, w);
free(req.tgt_name);
free(req.nqn);
}
SPDK_RPC_REGISTER("nvmf_get_subsystems", rpc_nvmf_get_subsystems, SPDK_RPC_RUNTIME)
SPDK_RPC_REGISTER_ALIAS_DEPRECATED(nvmf_get_subsystems, get_nvmf_subsystems)

View File

@ -1948,10 +1948,11 @@ Format: 'user:u1 secret:s1 muser:mu1 msecret:ms1,user:u2 secret:s2 muser:mu2 mse
p.set_defaults(func=nvmf_get_transports)
def nvmf_get_subsystems(args):
print_dict(rpc.nvmf.nvmf_get_subsystems(args.client, tgt_name=args.tgt_name))
print_dict(rpc.nvmf.nvmf_get_subsystems(args.client, nqn=args.nqn, tgt_name=args.tgt_name))
p = subparsers.add_parser('nvmf_get_subsystems', aliases=['get_nvmf_subsystems'],
help='Display nvmf subsystems')
help='Display nvmf subsystems or required subsystem')
p.add_argument('nqn', help='Subsystem NQN (optional)', nargs="?", default=None)
p.add_argument('-t', '--tgt_name', help='The name of the parent NVMe-oF target (optional)', type=str)
p.set_defaults(func=nvmf_get_subsystems)

View File

@ -153,9 +153,10 @@ def nvmf_get_transports(client, tgt_name=None):
@deprecated_alias('get_nvmf_subsystems')
def nvmf_get_subsystems(client, tgt_name=None):
def nvmf_get_subsystems(client, nqn=None, tgt_name=None):
"""Get list of NVMe-oF subsystems.
Args:
nqn: Subsystem NQN (optional; if omitted, query all subsystems).
tgt_name: name of the parent NVMe-oF target (optional).
Returns:
@ -165,9 +166,10 @@ def nvmf_get_subsystems(client, tgt_name=None):
params = {}
if tgt_name:
params = {
'tgt_name': tgt_name,
}
params['tgt_name'] = tgt_name
if nqn:
params['nqn'] = nqn
return client.call('nvmf_get_subsystems', params)