bdev/nvme: add bdev_nvme_stop_discovery RPC
This RPC will stop the specified discovery service, including detaching from any controllers that were attached as part of that discovery service. Signed-off-by: Jim Harris <james.r.harris@intel.com> Change-Id: I9222876457fc45e1acde680a7bd1925917c22308 Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/10832 Tested-by: SPDK CI Jenkins <sys_sgci@intel.com> Community-CI: Mellanox Build Bot Reviewed-by: Changpeng Liu <changpeng.liu@intel.com> Reviewed-by: Shuhei Matsumoto <smatsumoto@nvidia.com>
This commit is contained in:
parent
1ea419ecd7
commit
932ee64b8f
@ -3123,6 +3123,42 @@ Example response:
|
||||
}
|
||||
~~~
|
||||
|
||||
### bdev_nvme_stop_discovery {#rpc_bdev_nvme_stop_discovery}
|
||||
|
||||
Stop a discovery service. This includes detaching any controllers that were
|
||||
discovered via the service that is being stopped.
|
||||
|
||||
#### Parameters
|
||||
|
||||
Name | Optional | Type | Description
|
||||
-------------------------- | -------- | ----------- | -----------
|
||||
name | Required | string | Name of service to stop
|
||||
|
||||
#### Example
|
||||
|
||||
Example request:
|
||||
|
||||
~~~json
|
||||
{
|
||||
"jsonrpc": "2.0",
|
||||
"method": "bdev_nvme_stop_discovery",
|
||||
"id": 1,
|
||||
"params": {
|
||||
"name": "nvme_auto"
|
||||
}
|
||||
}
|
||||
~~~
|
||||
|
||||
Example response:
|
||||
|
||||
~~~json
|
||||
{
|
||||
"jsonrpc": "2.0",
|
||||
"id": 1,
|
||||
"result": true
|
||||
}
|
||||
~~~
|
||||
|
||||
### bdev_nvme_cuse_register {#rpc_bdev_nvme_cuse_register}
|
||||
|
||||
Register CUSE device on NVMe controller.
|
||||
|
@ -4247,6 +4247,36 @@ bdev_nvme_start_discovery(struct spdk_nvme_transport_id *trid,
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
bdev_nvme_stop_discovery(const char *name, spdk_bdev_nvme_stop_discovery_fn cb_fn, void *cb_ctx)
|
||||
{
|
||||
struct discovery_ctx *ctx;
|
||||
|
||||
TAILQ_FOREACH(ctx, &g_discovery_ctxs, tailq) {
|
||||
if (strcmp(name, ctx->name) == 0) {
|
||||
if (ctx->detach) {
|
||||
return -EALREADY;
|
||||
}
|
||||
ctx->detach = true;
|
||||
ctx->stop_cb_fn = cb_fn;
|
||||
ctx->cb_ctx = cb_ctx;
|
||||
while (!TAILQ_EMPTY(&ctx->ctrlr_ctxs)) {
|
||||
struct discovery_ctrlr_ctx *ctrlr_ctx;
|
||||
struct nvme_path_id path = {};
|
||||
|
||||
ctrlr_ctx = TAILQ_FIRST(&ctx->ctrlr_ctxs);
|
||||
path.trid = ctrlr_ctx->trid;
|
||||
bdev_nvme_delete(ctrlr_ctx->name, &path);
|
||||
TAILQ_REMOVE(&ctx->ctrlr_ctxs, ctrlr_ctx, tailq);
|
||||
free(ctrlr_ctx);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return -ENOENT;
|
||||
}
|
||||
|
||||
static int
|
||||
bdev_nvme_library_init(void)
|
||||
{
|
||||
|
@ -260,6 +260,8 @@ int bdev_nvme_create(struct spdk_nvme_transport_id *trid,
|
||||
int bdev_nvme_start_discovery(struct spdk_nvme_transport_id *trid, const char *base_name,
|
||||
struct spdk_nvme_ctrlr_opts *opts,
|
||||
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);
|
||||
|
||||
struct spdk_nvme_ctrlr *bdev_nvme_get_ctrlr(struct spdk_bdev *bdev);
|
||||
|
||||
|
@ -1696,3 +1696,64 @@ cleanup:
|
||||
}
|
||||
SPDK_RPC_REGISTER("bdev_nvme_start_discovery", rpc_bdev_nvme_start_discovery,
|
||||
SPDK_RPC_RUNTIME)
|
||||
|
||||
struct rpc_bdev_nvme_stop_discovery {
|
||||
char *name;
|
||||
};
|
||||
|
||||
static const struct spdk_json_object_decoder rpc_bdev_nvme_stop_discovery_decoders[] = {
|
||||
{"name", offsetof(struct rpc_bdev_nvme_stop_discovery, name), spdk_json_decode_string},
|
||||
};
|
||||
|
||||
struct rpc_bdev_nvme_stop_discovery_ctx {
|
||||
struct rpc_bdev_nvme_stop_discovery req;
|
||||
struct spdk_jsonrpc_request *request;
|
||||
};
|
||||
|
||||
static void
|
||||
rpc_bdev_nvme_stop_discovery_done(void *cb_ctx)
|
||||
{
|
||||
struct rpc_bdev_nvme_stop_discovery_ctx *ctx = cb_ctx;
|
||||
|
||||
spdk_jsonrpc_send_bool_response(ctx->request, true);
|
||||
free(ctx->req.name);
|
||||
free(ctx);
|
||||
}
|
||||
|
||||
static void
|
||||
rpc_bdev_nvme_stop_discovery(struct spdk_jsonrpc_request *request,
|
||||
const struct spdk_json_val *params)
|
||||
{
|
||||
struct rpc_bdev_nvme_stop_discovery_ctx *ctx;
|
||||
int rc;
|
||||
|
||||
ctx = calloc(1, sizeof(*ctx));
|
||||
if (!ctx) {
|
||||
spdk_jsonrpc_send_error_response(request, -ENOMEM, spdk_strerror(ENOMEM));
|
||||
return;
|
||||
}
|
||||
|
||||
if (spdk_json_decode_object(params, rpc_bdev_nvme_stop_discovery_decoders,
|
||||
SPDK_COUNTOF(rpc_bdev_nvme_stop_discovery_decoders),
|
||||
&ctx->req)) {
|
||||
SPDK_ERRLOG("spdk_json_decode_object failed\n");
|
||||
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INTERNAL_ERROR,
|
||||
"spdk_json_decode_object failed");
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
ctx->request = request;
|
||||
rc = bdev_nvme_stop_discovery(ctx->req.name, rpc_bdev_nvme_stop_discovery_done, ctx);
|
||||
if (rc) {
|
||||
spdk_jsonrpc_send_error_response(request, rc, spdk_strerror(-rc));
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
return;
|
||||
|
||||
cleanup:
|
||||
free(ctx->req.name);
|
||||
free(ctx);
|
||||
}
|
||||
SPDK_RPC_REGISTER("bdev_nvme_stop_discovery", rpc_bdev_nvme_stop_discovery,
|
||||
SPDK_RPC_RUNTIME)
|
||||
|
@ -641,6 +641,13 @@ if __name__ == "__main__":
|
||||
p.add_argument('-q', '--hostnqn', help='NVMe-oF host subnqn')
|
||||
p.set_defaults(func=bdev_nvme_start_discovery)
|
||||
|
||||
def bdev_nvme_stop_discovery(args):
|
||||
rpc.bdev.bdev_nvme_stop_discovery(args.client, name=args.name)
|
||||
|
||||
p = subparsers.add_parser('bdev_nvme_stop_discovery', help='Stop automatic discovery')
|
||||
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_cuse_register(args):
|
||||
rpc.bdev.bdev_nvme_cuse_register(args.client,
|
||||
name=args.name)
|
||||
|
@ -684,6 +684,17 @@ def bdev_nvme_start_discovery(client, name, trtype, traddr, adrfam=None, trsvcid
|
||||
return client.call('bdev_nvme_start_discovery', params)
|
||||
|
||||
|
||||
def bdev_nvme_stop_discovery(client, name):
|
||||
"""Stop a previously started discovery service
|
||||
|
||||
Args:
|
||||
name: name of discovery service to start
|
||||
"""
|
||||
params = {'name': name}
|
||||
|
||||
return client.call('bdev_nvme_stop_discovery', params)
|
||||
|
||||
|
||||
def bdev_nvme_cuse_register(client, name):
|
||||
"""Register CUSE devices on NVMe controller.
|
||||
|
||||
|
@ -103,7 +103,7 @@ $rpc_py nvmf_subsystem_remove_listener ${NQN}0 -t $TEST_TRANSPORT -a $NVMF_FIRST
|
||||
[[ "$(get_bdev_list)" == "nvme0n1 nvme0n2" ]]
|
||||
[[ "$(get_subsystem_paths nvme0)" == "$NVMF_SECOND_PORT" ]]
|
||||
|
||||
$rpc_py nvmf_delete_subsystem ${NQN}0
|
||||
$rpc_py -s $HOST_SOCK bdev_nvme_stop_discovery -b nvme
|
||||
[[ "$(get_subsystem_names)" == "" ]]
|
||||
[[ "$(get_bdev_list)" == "" ]]
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user