nvmf: allow to query only specified transport
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: Ie1af1cb4778edd265914bbfdc2777f66c6c76572 Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/9362 Reviewed-by: Tomasz Zawadzki <tomasz.zawadzki@intel.com> Reviewed-by: Ben Walker <benjamin.walker@intel.com> Community-CI: Broadcom CI <spdk-ci.pdl@broadcom.com> Community-CI: Mellanox Build Bot Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
This commit is contained in:
parent
1227342cd4
commit
fb335cb29c
@ -6767,9 +6767,13 @@ Example response:
|
||||
|
||||
#### Parameters
|
||||
|
||||
The user may specify no parameters in order to list all transports, or a transport may be
|
||||
specified by type.
|
||||
|
||||
Name | Optional | Type | Description
|
||||
--------------------------- | -------- | ------------| -----------
|
||||
tgt_name | Optional | string | Parent NVMe-oF target name.
|
||||
trtype | Optional | string | Transport type.
|
||||
|
||||
#### Example
|
||||
|
||||
|
@ -2009,10 +2009,12 @@ rpc_nvmf_create_transport(struct spdk_jsonrpc_request *request,
|
||||
SPDK_RPC_REGISTER("nvmf_create_transport", rpc_nvmf_create_transport, SPDK_RPC_RUNTIME)
|
||||
|
||||
struct rpc_get_transport {
|
||||
char *trtype;
|
||||
char *tgt_name;
|
||||
};
|
||||
|
||||
static const struct spdk_json_object_decoder rpc_get_transport_decoders[] = {
|
||||
{"trtype", offsetof(struct rpc_get_transport, trtype), spdk_json_decode_string, true},
|
||||
{"tgt_name", offsetof(struct rpc_get_transport, tgt_name), spdk_json_decode_string, true},
|
||||
};
|
||||
|
||||
@ -2022,7 +2024,7 @@ rpc_nvmf_get_transports(struct spdk_jsonrpc_request *request,
|
||||
{
|
||||
struct rpc_get_transport req = { 0 };
|
||||
struct spdk_json_write_ctx *w;
|
||||
struct spdk_nvmf_transport *transport;
|
||||
struct spdk_nvmf_transport *transport = NULL;
|
||||
struct spdk_nvmf_tgt *tgt;
|
||||
|
||||
if (params) {
|
||||
@ -2039,19 +2041,37 @@ rpc_nvmf_get_transports(struct spdk_jsonrpc_request *request,
|
||||
if (!tgt) {
|
||||
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INTERNAL_ERROR,
|
||||
"Unable to find a target.");
|
||||
free(req.trtype);
|
||||
free(req.tgt_name);
|
||||
return;
|
||||
}
|
||||
|
||||
if (req.trtype) {
|
||||
transport = spdk_nvmf_tgt_get_transport(tgt, req.trtype);
|
||||
if (transport == NULL) {
|
||||
SPDK_ERRLOG("transport '%s' does not exist\n", req.trtype);
|
||||
spdk_jsonrpc_send_error_response(request, -ENODEV, spdk_strerror(ENODEV));
|
||||
free(req.trtype);
|
||||
free(req.tgt_name);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
w = spdk_jsonrpc_begin_result(request);
|
||||
spdk_json_write_array_begin(w);
|
||||
transport = spdk_nvmf_transport_get_first(tgt);
|
||||
while (transport) {
|
||||
|
||||
if (transport) {
|
||||
nvmf_transport_dump_opts(transport, w, false);
|
||||
transport = spdk_nvmf_transport_get_next(transport);
|
||||
} else {
|
||||
for (transport = spdk_nvmf_transport_get_first(tgt); transport != NULL;
|
||||
transport = spdk_nvmf_transport_get_next(transport)) {
|
||||
nvmf_transport_dump_opts(transport, w, false);
|
||||
}
|
||||
}
|
||||
|
||||
spdk_json_write_array_end(w);
|
||||
spdk_jsonrpc_end_result(request, w);
|
||||
free(req.trtype);
|
||||
free(req.tgt_name);
|
||||
}
|
||||
SPDK_RPC_REGISTER("nvmf_get_transports", rpc_nvmf_get_transports, SPDK_RPC_RUNTIME)
|
||||
|
@ -1942,10 +1942,11 @@ Format: 'user:u1 secret:s1 muser:mu1 msecret:ms1,user:u2 secret:s2 muser:mu2 mse
|
||||
p.set_defaults(func=nvmf_create_transport)
|
||||
|
||||
def nvmf_get_transports(args):
|
||||
print_dict(rpc.nvmf.nvmf_get_transports(args.client, tgt_name=args.tgt_name))
|
||||
print_dict(rpc.nvmf.nvmf_get_transports(args.client, trtype=args.trtype, tgt_name=args.tgt_name))
|
||||
|
||||
p = subparsers.add_parser('nvmf_get_transports', aliases=['get_nvmf_transports'],
|
||||
help='Display nvmf transports')
|
||||
help='Display nvmf transports or required transport')
|
||||
p.add_argument('--trtype', help='Transport type (optional)')
|
||||
p.add_argument('-t', '--tgt-name', help='The name of the parent NVMe-oF target (optional)', type=str)
|
||||
p.set_defaults(func=nvmf_get_transports)
|
||||
|
||||
|
@ -134,9 +134,10 @@ def nvmf_create_transport(client, **params):
|
||||
|
||||
|
||||
@deprecated_alias('get_nvmf_transports')
|
||||
def nvmf_get_transports(client, tgt_name=None):
|
||||
def nvmf_get_transports(client, trtype=None, tgt_name=None):
|
||||
"""Get list of NVMe-oF transports.
|
||||
Args:
|
||||
trtype: Transport type (optional; if omitted, query all transports).
|
||||
tgt_name: name of the parent NVMe-oF target (optional).
|
||||
|
||||
Returns:
|
||||
@ -146,9 +147,10 @@ def nvmf_get_transports(client, tgt_name=None):
|
||||
params = {}
|
||||
|
||||
if tgt_name:
|
||||
params = {
|
||||
'tgt_name': tgt_name,
|
||||
}
|
||||
params['tgt_name'] = tgt_name
|
||||
|
||||
if trtype:
|
||||
params['trtype'] = trtype
|
||||
|
||||
return client.call('nvmf_get_transports', params)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user