vhost: rpc: add an optional parameter -n/--name for get_vhost_controllers
User can use this optional parameter to get the information of specific vhost controller. Change-Id: I3911c6c7d4e7b75e82277d1e4690d5e40019aa06 Signed-off-by: wuzhouhui <wuzhouhui@kingsoft.com> Reviewed-on: https://review.gerrithub.io/425451 Reviewed-by: Darek Stojaczyk <dariusz.stojaczyk@intel.com> Reviewed-by: Jim Harris <james.r.harris@intel.com> Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com> Chandler-Test-Pool: SPDK Automated Test System <sys_sgsw@intel.com> Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
This commit is contained in:
parent
90051287d8
commit
74a28c199f
@ -3635,15 +3635,21 @@ Example response:
|
|||||||
|
|
||||||
## get_vhost_controllers {#rpc_get_vhost_controllers}
|
## get_vhost_controllers {#rpc_get_vhost_controllers}
|
||||||
|
|
||||||
Display information about all vhost controllers.
|
Display information about all or specific vhost controller(s).
|
||||||
|
|
||||||
### Parameters
|
### Parameters
|
||||||
|
|
||||||
This method has no parameters.
|
The user may specify no parameters in order to list all controllers, or a controller may be
|
||||||
|
specified by name.
|
||||||
|
|
||||||
|
Name | Optional | Type | Description
|
||||||
|
----------------------- | -------- | ----------- | -----------
|
||||||
|
name | Optional | string | Vhost controller name
|
||||||
|
|
||||||
|
|
||||||
### Response {#rpc_get_vhost_controllers_response}
|
### Response {#rpc_get_vhost_controllers_response}
|
||||||
|
|
||||||
Response is an array of objects describing each controllers. Common fields are:
|
Response is an array of objects describing requested controller(s). Common fields are:
|
||||||
|
|
||||||
Name | Type | Description
|
Name | Type | Description
|
||||||
----------------------- | ----------- | -----------
|
----------------------- | ----------- | -----------
|
||||||
|
@ -451,16 +451,39 @@ invalid:
|
|||||||
SPDK_RPC_REGISTER("remove_vhost_controller", spdk_rpc_remove_vhost_controller, SPDK_RPC_RUNTIME)
|
SPDK_RPC_REGISTER("remove_vhost_controller", spdk_rpc_remove_vhost_controller, SPDK_RPC_RUNTIME)
|
||||||
|
|
||||||
struct rpc_get_vhost_ctrlrs {
|
struct rpc_get_vhost_ctrlrs {
|
||||||
|
char *name;
|
||||||
struct spdk_json_write_ctx *w;
|
struct spdk_json_write_ctx *w;
|
||||||
struct spdk_jsonrpc_request *request;
|
struct spdk_jsonrpc_request *request;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static void
|
||||||
|
_spdk_rpc_get_vhost_controller(struct spdk_json_write_ctx *w, struct spdk_vhost_dev *vdev)
|
||||||
|
{
|
||||||
|
uint32_t delay_base_us, iops_threshold;
|
||||||
|
|
||||||
|
spdk_vhost_get_coalescing(vdev, &delay_base_us, &iops_threshold);
|
||||||
|
|
||||||
|
spdk_json_write_object_begin(w);
|
||||||
|
|
||||||
|
spdk_json_write_named_string(w, "ctrlr", spdk_vhost_dev_get_name(vdev));
|
||||||
|
spdk_json_write_named_string_fmt(w, "cpumask", "0x%s", spdk_cpuset_fmt(vdev->cpumask));
|
||||||
|
spdk_json_write_named_uint32(w, "delay_base_us", delay_base_us);
|
||||||
|
spdk_json_write_named_uint32(w, "iops_threshold", iops_threshold);
|
||||||
|
spdk_json_write_named_string(w, "socket", vdev->path);
|
||||||
|
|
||||||
|
spdk_json_write_named_object_begin(w, "backend_specific");
|
||||||
|
spdk_vhost_dump_info_json(vdev, w);
|
||||||
|
spdk_json_write_object_end(w);
|
||||||
|
|
||||||
|
spdk_json_write_object_end(w);
|
||||||
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
spdk_rpc_get_vhost_controllers_cb(struct spdk_vhost_dev *vdev, void *arg)
|
spdk_rpc_get_vhost_controllers_cb(struct spdk_vhost_dev *vdev, void *arg)
|
||||||
{
|
{
|
||||||
struct rpc_get_vhost_ctrlrs *ctx = arg;
|
struct rpc_get_vhost_ctrlrs *ctx = arg;
|
||||||
uint32_t delay_base_us, iops_threshold;
|
|
||||||
|
|
||||||
|
assert(ctx->name == NULL);
|
||||||
|
|
||||||
if (vdev == NULL) {
|
if (vdev == NULL) {
|
||||||
spdk_json_write_array_end(ctx->w);
|
spdk_json_write_array_end(ctx->w);
|
||||||
@ -469,24 +492,43 @@ spdk_rpc_get_vhost_controllers_cb(struct spdk_vhost_dev *vdev, void *arg)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
spdk_vhost_get_coalescing(vdev, &delay_base_us, &iops_threshold);
|
_spdk_rpc_get_vhost_controller(ctx->w, vdev);
|
||||||
|
|
||||||
spdk_json_write_object_begin(ctx->w);
|
|
||||||
|
|
||||||
spdk_json_write_named_string(ctx->w, "ctrlr", spdk_vhost_dev_get_name(vdev));
|
|
||||||
spdk_json_write_named_string_fmt(ctx->w, "cpumask", "0x%s", spdk_cpuset_fmt(vdev->cpumask));
|
|
||||||
spdk_json_write_named_uint32(ctx->w, "delay_base_us", delay_base_us);
|
|
||||||
spdk_json_write_named_uint32(ctx->w, "iops_threshold", iops_threshold);
|
|
||||||
spdk_json_write_named_string(ctx->w, "socket", vdev->path);
|
|
||||||
|
|
||||||
spdk_json_write_named_object_begin(ctx->w, "backend_specific");
|
|
||||||
spdk_vhost_dump_info_json(vdev, ctx->w);
|
|
||||||
spdk_json_write_object_end(ctx->w);
|
|
||||||
|
|
||||||
spdk_json_write_object_end(ctx->w);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
spdk_rpc_get_vhost_controller_cb(struct spdk_vhost_dev *vdev, void *arg)
|
||||||
|
{
|
||||||
|
struct rpc_get_vhost_ctrlrs *ctx = arg;
|
||||||
|
|
||||||
|
assert(ctx->name != NULL);
|
||||||
|
|
||||||
|
if (vdev == NULL) {
|
||||||
|
spdk_jsonrpc_send_error_response(ctx->request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
|
||||||
|
spdk_strerror(ENODEV));
|
||||||
|
goto free_name_ctx;
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx->w = spdk_jsonrpc_begin_result(ctx->request);
|
||||||
|
if (ctx->w == NULL) {
|
||||||
|
goto free_name_ctx;
|
||||||
|
}
|
||||||
|
|
||||||
|
spdk_json_write_array_begin(ctx->w);
|
||||||
|
_spdk_rpc_get_vhost_controller(ctx->w, vdev);
|
||||||
|
spdk_json_write_array_end(ctx->w);
|
||||||
|
|
||||||
|
spdk_jsonrpc_end_result(ctx->request, ctx->w);
|
||||||
|
|
||||||
|
free_name_ctx:
|
||||||
|
free(ctx->name);
|
||||||
|
free(ctx);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static const struct spdk_json_object_decoder rpc_get_vhost_ctrlrs_decoders[] = {
|
||||||
|
{"name", offsetof(struct rpc_get_vhost_ctrlrs, name), spdk_json_decode_string, true},
|
||||||
|
};
|
||||||
|
|
||||||
static void
|
static void
|
||||||
spdk_rpc_get_vhost_controllers(struct spdk_jsonrpc_request *request,
|
spdk_rpc_get_vhost_controllers(struct spdk_jsonrpc_request *request,
|
||||||
@ -495,12 +537,6 @@ spdk_rpc_get_vhost_controllers(struct spdk_jsonrpc_request *request,
|
|||||||
struct rpc_get_vhost_ctrlrs *ctx;
|
struct rpc_get_vhost_ctrlrs *ctx;
|
||||||
struct spdk_json_write_ctx *w;
|
struct spdk_json_write_ctx *w;
|
||||||
|
|
||||||
if (params != NULL) {
|
|
||||||
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
|
|
||||||
"get_vhost_controllers requires no parameters");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
ctx = calloc(1, sizeof(*ctx));
|
ctx = calloc(1, sizeof(*ctx));
|
||||||
if (ctx == NULL) {
|
if (ctx == NULL) {
|
||||||
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INTERNAL_ERROR,
|
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INTERNAL_ERROR,
|
||||||
@ -508,6 +544,21 @@ spdk_rpc_get_vhost_controllers(struct spdk_jsonrpc_request *request,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (params && spdk_json_decode_object(params, rpc_get_vhost_ctrlrs_decoders,
|
||||||
|
SPDK_COUNTOF(rpc_get_vhost_ctrlrs_decoders), ctx)) {
|
||||||
|
SPDK_ERRLOG("spdk_json_decode_object failed\n");
|
||||||
|
free(ctx);
|
||||||
|
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
|
||||||
|
"Invalid parameters");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ctx->name) {
|
||||||
|
ctx->request = request;
|
||||||
|
spdk_vhost_call_external_event(ctx->name, spdk_rpc_get_vhost_controller_cb, ctx);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
w = spdk_jsonrpc_begin_result(request);
|
w = spdk_jsonrpc_begin_result(request);
|
||||||
if (w == NULL) {
|
if (w == NULL) {
|
||||||
free(ctx);
|
free(ctx);
|
||||||
|
@ -1632,9 +1632,10 @@ Format: 'user:u1 secret:s1 muser:mu1 msecret:ms1,user:u2 secret:s2 muser:mu2 mse
|
|||||||
|
|
||||||
@call_cmd
|
@call_cmd
|
||||||
def get_vhost_controllers(args):
|
def get_vhost_controllers(args):
|
||||||
print_dict(rpc.vhost.get_vhost_controllers(args.client))
|
print_dict(rpc.vhost.get_vhost_controllers(args.client, args.name))
|
||||||
|
|
||||||
p = subparsers.add_parser('get_vhost_controllers', help='List vhost controllers')
|
p = subparsers.add_parser('get_vhost_controllers', help='List all or specific vhost controller(s)')
|
||||||
|
p.add_argument('-n', '--name', help="Name of vhost controller", required=False)
|
||||||
p.set_defaults(func=get_vhost_controllers)
|
p.set_defaults(func=get_vhost_controllers)
|
||||||
|
|
||||||
@call_cmd
|
@call_cmd
|
||||||
|
@ -106,12 +106,19 @@ def construct_vhost_blk_controller(client, ctrlr, dev_name, cpumask=None, readon
|
|||||||
return client.call('construct_vhost_blk_controller', params)
|
return client.call('construct_vhost_blk_controller', params)
|
||||||
|
|
||||||
|
|
||||||
def get_vhost_controllers(client):
|
def get_vhost_controllers(client, name=None):
|
||||||
"""Get list of configured vhost controllers.
|
"""Get information about configured vhost controllers.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
name: controller name to query (optional; if omitted, query all controllers)
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
List of vhost controllers.
|
List of vhost controllers.
|
||||||
"""
|
"""
|
||||||
return client.call('get_vhost_controllers')
|
params = {}
|
||||||
|
if name:
|
||||||
|
params['name'] = name
|
||||||
|
return client.call('get_vhost_controllers', params)
|
||||||
|
|
||||||
|
|
||||||
def remove_vhost_controller(client, ctrlr):
|
def remove_vhost_controller(client, ctrlr):
|
||||||
|
Loading…
Reference in New Issue
Block a user