From bef0c6edd2a7909e34c64849a4c736130f95bfa0 Mon Sep 17 00:00:00 2001 From: Vitaliy Mysak Date: Mon, 11 Mar 2019 17:16:32 +0000 Subject: [PATCH] ocf: rpc: extend get_ocf_bdevs for multicore cases Extend existing get_ocf_bdevs call to make it easier to get information about attached cores. Implementation is based adding additional optional argument "name" to existing call. Based on "name" bdevs are filtered. Backward compatability of RPC interface is preserved. This patch also adds tests for the case when name is given. Change-Id: I4300ebe37e936bc5cca8e066b5f09db462a87cf7 Signed-off-by: Vitaliy Mysak Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/444841 Tested-by: SPDK CI Jenkins Reviewed-by: Darek Stojaczyk Reviewed-by: Jim Harris Reviewed-by: Tomasz Zawadzki --- doc/jsonrpc.md | 4 +- lib/bdev/ocf/vbdev_ocf_rpc.c | 61 ++++++++++++++++++++++++-- scripts/rpc.py | 4 +- scripts/rpc/bdev.py | 8 +++- test/ocf/management/create-destruct.sh | 11 +++-- test/ocf/management/multicore.sh | 11 +++-- 6 files changed, 83 insertions(+), 16 deletions(-) diff --git a/doc/jsonrpc.md b/doc/jsonrpc.md index 26c61f288..0ecf62844 100644 --- a/doc/jsonrpc.md +++ b/doc/jsonrpc.md @@ -1067,7 +1067,9 @@ Get list of OCF devices including unregistered ones. ### Parameters -This method has no parameters. +Name | Optional | Type | Description +----------------------- | -------- | ----------- | ----------- +name | Optional | string | Name of OCF vbdev or name of cache device or name of core device ### Response diff --git a/lib/bdev/ocf/vbdev_ocf_rpc.c b/lib/bdev/ocf/vbdev_ocf_rpc.c index f17510c8a..86f601b41 100644 --- a/lib/bdev/ocf/vbdev_ocf_rpc.c +++ b/lib/bdev/ocf/vbdev_ocf_rpc.c @@ -219,10 +219,39 @@ end: } SPDK_RPC_REGISTER("get_ocf_stats", spdk_rpc_get_ocf_stats, SPDK_RPC_RUNTIME) +/* Structure to hold the parameters for this RPC method. */ +struct rpc_get_ocf_bdevs { + char *name; +}; + +static void +free_rpc_get_ocf_bdevs(struct rpc_get_ocf_bdevs *r) +{ + free(r->name); +} + +/* Structure to decode the input parameters for this RPC method. */ +static const struct spdk_json_object_decoder rpc_get_ocf_bdevs_decoders[] = { + {"name", offsetof(struct rpc_get_ocf_bdevs, name), spdk_json_decode_string, true}, +}; + +struct get_bdevs_ctx { + char *name; + struct spdk_json_write_ctx *w; +}; + static void get_bdevs_fn(struct vbdev_ocf *vbdev, void *ctx) { - struct spdk_json_write_ctx *w = ctx; + struct get_bdevs_ctx *cctx = ctx; + struct spdk_json_write_ctx *w = cctx->w; + + if (cctx->name != NULL && + strcmp(vbdev->name, cctx->name) && + strcmp(vbdev->cache.name, cctx->name) && + strcmp(vbdev->core.name, cctx->name)) { + return; + } spdk_json_write_object_begin(w); spdk_json_write_named_string(w, "name", vbdev->name); @@ -245,16 +274,40 @@ static void spdk_rpc_get_ocf_bdevs(struct spdk_jsonrpc_request *request, const struct spdk_json_val *params) { struct spdk_json_write_ctx *w; + struct rpc_get_ocf_bdevs req = {NULL}; + struct get_bdevs_ctx cctx; + + if (params && spdk_json_decode_object(params, rpc_get_ocf_bdevs_decoders, + SPDK_COUNTOF(rpc_get_ocf_bdevs_decoders), + &req)) { + spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, + "Invalid parameters"); + goto end; + } + + if (req.name) { + if (!(vbdev_ocf_get_by_name(req.name) || vbdev_ocf_get_base_by_name(req.name))) { + spdk_jsonrpc_send_error_response(request, + SPDK_JSONRPC_ERROR_INVALID_PARAMS, + spdk_strerror(ENODEV)); + goto end; + } + } w = spdk_jsonrpc_begin_result(request); if (w == NULL) { return; } - spdk_json_write_array_begin(w); - vbdev_ocf_foreach(get_bdevs_fn, w); - spdk_json_write_array_end(w); + cctx.name = req.name; + cctx.w = w; + spdk_json_write_array_begin(w); + vbdev_ocf_foreach(get_bdevs_fn, &cctx); + spdk_json_write_array_end(w); spdk_jsonrpc_end_result(request, w); + +end: + free_rpc_get_ocf_bdevs(&req); } SPDK_RPC_REGISTER("get_ocf_bdevs", spdk_rpc_get_ocf_bdevs, SPDK_RPC_RUNTIME) diff --git a/scripts/rpc.py b/scripts/rpc.py index 8f1d678d3..0d3db5c9d 100755 --- a/scripts/rpc.py +++ b/scripts/rpc.py @@ -185,9 +185,11 @@ if __name__ == "__main__": p.set_defaults(func=get_ocf_stats) def get_ocf_bdevs(args): - print_dict(rpc.bdev.get_ocf_bdevs(args.client)) + print_dict(rpc.bdev.get_ocf_bdevs(args.client, + name=args.name)) p = subparsers.add_parser('get_ocf_bdevs', help='Get list of OCF devices including unregistered ones') + p.add_argument('name', nargs='?', default=None, help='name of OCF vbdev or name of cache device or name of core device (optional)') p.set_defaults(func=get_ocf_bdevs) def construct_malloc_bdev(args): diff --git a/scripts/rpc/bdev.py b/scripts/rpc/bdev.py index 088c48ceb..02db75cf8 100644 --- a/scripts/rpc/bdev.py +++ b/scripts/rpc/bdev.py @@ -85,15 +85,19 @@ def get_ocf_stats(client, name): return client.call('get_ocf_stats', params) -def get_ocf_bdevs(client): +def get_ocf_bdevs(client, name=None): """Get list of OCF devices including unregistered ones Args: + name: name of OCF vbdev or name of cache device or name of core device (optional) Returns: Array of OCF devices with their current status """ - return client.call('get_ocf_bdevs', None) + params = None + if name: + params = {'name': name} + return client.call('get_ocf_bdevs', params) def construct_malloc_bdev(client, num_blocks, block_size, name=None, uuid=None): diff --git a/test/ocf/management/create-destruct.sh b/test/ocf/management/create-destruct.sh index 72b6c8ed5..0ed70ba18 100755 --- a/test/ocf/management/create-destruct.sh +++ b/test/ocf/management/create-destruct.sh @@ -27,8 +27,11 @@ $rpc_py construct_malloc_bdev 101 512 -b Malloc1 $rpc_py construct_ocf_bdev PartCache wt Malloc0 NonExisting -$rpc_py get_ocf_bdevs | jq -e \ - 'map(select(.name == "PartCache")) | .[0] | .started == false and .cache.attached and .core.attached == false' +$rpc_py get_ocf_bdevs PartCache | jq -e \ + '.[0] | .started == false and .cache.attached and .core.attached == false' + +$rpc_py get_ocf_bdevs NonExisting | jq -e \ + '.[0] | .name == "PartCache"' if ! bdev_check_claimed Malloc0; then >&2 echo "Base device expected to be claimed now" @@ -43,8 +46,8 @@ fi $rpc_py construct_ocf_bdev FullCache wt Malloc0 Malloc1 -$rpc_py get_ocf_bdevs | jq -e \ - 'map(select(.name == "FullCache")) | .[0] | .started and .cache.attached and .core.attached' +$rpc_py get_ocf_bdevs FullCache | jq -e \ + '.[0] | .started and .cache.attached and .core.attached' if ! (bdev_check_claimed Malloc0 && bdev_check_claimed Malloc1); then >&2 echo "Base devices expected to be claimed now" diff --git a/test/ocf/management/multicore.sh b/test/ocf/management/multicore.sh index f955745a5..99ac8d654 100755 --- a/test/ocf/management/multicore.sh +++ b/test/ocf/management/multicore.sh @@ -42,13 +42,13 @@ $rpc_py get_ocf_bdevs | jq -e \ $rpc_py delete_ocf_bdev C2 -$rpc_py get_ocf_bdevs | jq -e \ - 'any(select(.name == "C1" and .started))' +$rpc_py get_ocf_bdevs C1 | jq -e \ + '.[0] | .started' $rpc_py construct_ocf_bdev C2 wt Cache Core1 -$rpc_py get_ocf_bdevs | jq -e \ - 'any(select(.name == "C2" and .started))' +$rpc_py get_ocf_bdevs C2 | jq -e \ + '.[0] | .started' # Normal shutdown @@ -64,6 +64,9 @@ $rpc_py construct_malloc_bdev 1 512 -b Core $rpc_py construct_ocf_bdev C1 wt Cache Malloc $rpc_py construct_ocf_bdev C2 wt Cache Core +$rpc_py get_ocf_bdevs Cache | jq \ + 'length == 2' + $rpc_py delete_malloc_bdev Cache $rpc_py get_ocf_bdevs | jq -e \