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 <vitaliy.mysak@intel.com> Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/444841 Tested-by: SPDK CI Jenkins <sys_sgci@intel.com> Reviewed-by: Darek Stojaczyk <dariusz.stojaczyk@intel.com> Reviewed-by: Jim Harris <james.r.harris@intel.com> Reviewed-by: Tomasz Zawadzki <tomasz.zawadzki@intel.com>
This commit is contained in:
parent
530f481259
commit
bef0c6edd2
@ -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
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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):
|
||||
|
@ -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):
|
||||
|
@ -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"
|
||||
|
@ -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 \
|
||||
|
Loading…
Reference in New Issue
Block a user