diff --git a/doc/jsonrpc.md b/doc/jsonrpc.md index e5da55592..55ea6680c 100644 --- a/doc/jsonrpc.md +++ b/doc/jsonrpc.md @@ -3344,6 +3344,43 @@ Example response: } ~~~ +### bdev_nvme_get_discovery_info {#rpc_bdev_nvme_get_discovery_info} + +Get information about the discovery service. + +#### Example + +Example request: +~~~json +{ + "jsonrpc": "2.0", + "method": "bdev_nvme_get_discovery_info", + "id": 1 +} +~~~ + +Example response: + +~~~json +{ + "jsonrpc": "2.0", + "id": 1, + "result": [ + { + "name": "nvme-disc", + "trid": { + "trtype": "TCP", + "adrfam": "IPv4", + "traddr": "127.0.0.1", + "trsvcid": "8009", + "subnqn": "nqn.2014-08.org.nvmexpress.discovery" + }, + "referrals": [] + } + ] +} +~~~ + ### bdev_nvme_get_io_paths {#rpc_bdev_nvme_get_io_paths} Display all or the specified NVMe bdev's active I/O paths. diff --git a/module/bdev/nvme/bdev_nvme.c b/module/bdev/nvme/bdev_nvme.c index d8afa1637..64f001012 100644 --- a/module/bdev/nvme/bdev_nvme.c +++ b/module/bdev/nvme/bdev_nvme.c @@ -6500,4 +6500,34 @@ nvme_io_path_info_json(struct spdk_json_write_ctx *w, struct nvme_io_path *io_pa spdk_json_write_object_end(w); } +void +bdev_nvme_get_discovery_info(struct spdk_json_write_ctx *w) +{ + struct discovery_ctx *ctx; + struct discovery_entry_ctx *entry_ctx; + + spdk_json_write_array_begin(w); + TAILQ_FOREACH(ctx, &g_discovery_ctxs, tailq) { + spdk_json_write_object_begin(w); + spdk_json_write_named_string(w, "name", ctx->name); + + spdk_json_write_named_object_begin(w, "trid"); + nvme_bdev_dump_trid_json(&ctx->trid, w); + spdk_json_write_object_end(w); + + spdk_json_write_named_array_begin(w, "referrals"); + TAILQ_FOREACH(entry_ctx, &ctx->discovery_entry_ctxs, tailq) { + spdk_json_write_object_begin(w); + spdk_json_write_named_object_begin(w, "trid"); + nvme_bdev_dump_trid_json(&entry_ctx->trid, w); + spdk_json_write_object_end(w); + spdk_json_write_object_end(w); + } + spdk_json_write_array_end(w); + + spdk_json_write_object_end(w); + } + spdk_json_write_array_end(w); +} + SPDK_LOG_REGISTER_COMPONENT(bdev_nvme) diff --git a/module/bdev/nvme/bdev_nvme.h b/module/bdev/nvme/bdev_nvme.h index 9d64eb194..69b1f4109 100644 --- a/module/bdev/nvme/bdev_nvme.h +++ b/module/bdev/nvme/bdev_nvme.h @@ -300,6 +300,7 @@ int bdev_nvme_start_discovery(struct spdk_nvme_transport_id *trid, const char *b spdk_bdev_nvme_start_discovery_fn cb_fn, void *cb_ctx); int bdev_nvme_stop_discovery(const char *name, spdk_bdev_nvme_stop_discovery_fn cb_fn, void *cb_ctx); +void bdev_nvme_get_discovery_info(struct spdk_json_write_ctx *w); struct spdk_nvme_ctrlr *bdev_nvme_get_ctrlr(struct spdk_bdev *bdev); diff --git a/module/bdev/nvme/bdev_nvme_rpc.c b/module/bdev/nvme/bdev_nvme_rpc.c index 75bba0d7e..64d4db230 100644 --- a/module/bdev/nvme/bdev_nvme_rpc.c +++ b/module/bdev/nvme/bdev_nvme_rpc.c @@ -1766,6 +1766,19 @@ cleanup: SPDK_RPC_REGISTER("bdev_nvme_stop_discovery", rpc_bdev_nvme_stop_discovery, SPDK_RPC_RUNTIME) +static void +rpc_bdev_nvme_get_discovery_info(struct spdk_jsonrpc_request *request, + const struct spdk_json_val *params) +{ + struct spdk_json_write_ctx *w; + + w = spdk_jsonrpc_begin_result(request); + bdev_nvme_get_discovery_info(w); + spdk_jsonrpc_end_result(request, w); +} +SPDK_RPC_REGISTER("bdev_nvme_get_discovery_info", rpc_bdev_nvme_get_discovery_info, + SPDK_RPC_RUNTIME) + enum error_injection_cmd_type { NVME_ADMIN_CMD = 1, NVME_IO_CMD, diff --git a/python/spdk/rpc/bdev.py b/python/spdk/rpc/bdev.py index 99104bf65..b8174b20b 100644 --- a/python/spdk/rpc/bdev.py +++ b/python/spdk/rpc/bdev.py @@ -811,6 +811,12 @@ def bdev_nvme_stop_discovery(client, name): return client.call('bdev_nvme_stop_discovery', params) +def bdev_nvme_get_discovery_info(client): + """Get information about the automatic discovery + """ + return client.call('bdev_nvme_get_discovery_info') + + def bdev_nvme_get_io_paths(client, name): """Display all or the specified NVMe bdev's active I/O paths diff --git a/scripts/rpc.py b/scripts/rpc.py index f43b5c2b6..035da08d6 100755 --- a/scripts/rpc.py +++ b/scripts/rpc.py @@ -761,6 +761,12 @@ if __name__ == "__main__": p.add_argument('-b', '--name', help="Name of the service to stop", required=True) p.set_defaults(func=bdev_nvme_stop_discovery) + def bdev_nvme_get_discovery_info(args): + print_dict(rpc.bdev.bdev_nvme_get_discovery_info(args.client)) + + p = subparsers.add_parser('bdev_nvme_get_discovery_info', help='Get information about the automatic discovery') + p.set_defaults(func=bdev_nvme_get_discovery_info) + def bdev_nvme_get_io_paths(args): print_dict(rpc.bdev.bdev_nvme_get_io_paths(args.client, name=args.name))