virtio_blk: added virtio_blk_get_transports RPC
This patch adds virtio_blk_get_transports matching the virtio_blk_create_transport RPC. Allowing for querying existing virtio_blk transports and displaying their options. Signed-off-by: Krystyna Szybalska <krystyna.szybalska@gmail.com> Change-Id: I0ec49c5f2ad11962feb5087dd376407ad125c349 Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/16303 Reviewed-by: Konrad Sztyber <konrad.sztyber@intel.com> Reviewed-by: Tomasz Zawadzki <tomasz.zawadzki@intel.com> Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
This commit is contained in:
parent
e64728f092
commit
537929e1d4
@ -8911,6 +8911,43 @@ Example response:
|
||||
}
|
||||
~~~
|
||||
|
||||
### virtio_blk_get_transports {#rpc_virtio_blk_get_transports}
|
||||
|
||||
#### Parameters
|
||||
|
||||
The user may specify no parameters in order to list all transports,
|
||||
or a transport name may be specified.
|
||||
|
||||
Name | Optional | Type | Description
|
||||
--------------------------- | -------- | ------------| -----------
|
||||
name | Optional | string | Transport name.
|
||||
|
||||
#### Example
|
||||
|
||||
Example request:
|
||||
|
||||
~~~json
|
||||
{
|
||||
"jsonrpc": "2.0",
|
||||
"method": "virtio_blk_get_transports",
|
||||
"id": 1
|
||||
}
|
||||
~~~
|
||||
|
||||
Example response:
|
||||
|
||||
~~~json
|
||||
{
|
||||
"jsonrpc": "2.0",
|
||||
"id": 1,
|
||||
"result": [
|
||||
{
|
||||
"name": "vhost_user_blk"
|
||||
}
|
||||
]
|
||||
}
|
||||
~~~
|
||||
|
||||
### vhost_create_blk_controller {#rpc_vhost_create_blk_controller}
|
||||
|
||||
Create vhost block controller
|
||||
|
@ -13,6 +13,8 @@
|
||||
#include "spdk/barrier.h"
|
||||
#include "spdk/vhost.h"
|
||||
#include "vhost_internal.h"
|
||||
#include "spdk/queue.h"
|
||||
|
||||
|
||||
static struct spdk_cpuset g_vhost_core_mask;
|
||||
|
||||
@ -450,6 +452,46 @@ virtio_blk_transport_create(const char *transport_name,
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct spdk_virtio_blk_transport *
|
||||
virtio_blk_transport_get_first(void)
|
||||
{
|
||||
return TAILQ_FIRST(&g_virtio_blk_transports);
|
||||
}
|
||||
|
||||
struct spdk_virtio_blk_transport *
|
||||
virtio_blk_transport_get_next(struct spdk_virtio_blk_transport *transport)
|
||||
{
|
||||
return TAILQ_NEXT(transport, tailq);
|
||||
}
|
||||
|
||||
void
|
||||
virtio_blk_transport_dump_opts(struct spdk_virtio_blk_transport *transport,
|
||||
struct spdk_json_write_ctx *w)
|
||||
{
|
||||
spdk_json_write_object_begin(w);
|
||||
|
||||
spdk_json_write_named_string(w, "name", transport->ops->name);
|
||||
|
||||
if (transport->ops->dump_opts) {
|
||||
transport->ops->dump_opts(transport, w);
|
||||
}
|
||||
|
||||
spdk_json_write_object_end(w);
|
||||
}
|
||||
|
||||
struct spdk_virtio_blk_transport *
|
||||
virtio_blk_tgt_get_transport(const char *transport_name)
|
||||
{
|
||||
struct spdk_virtio_blk_transport *transport;
|
||||
|
||||
TAILQ_FOREACH(transport, &g_virtio_blk_transports, tailq) {
|
||||
if (strcasecmp(transport->ops->name, transport_name) == 0) {
|
||||
return transport;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int
|
||||
virtio_blk_transport_destroy(struct spdk_virtio_blk_transport *transport,
|
||||
spdk_vhost_fini_cb cb_fn)
|
||||
|
@ -586,7 +586,12 @@ void virtio_blk_transport_register(const struct spdk_virtio_blk_transport_ops *o
|
||||
int virtio_blk_transport_create(const char *transport_name, const struct spdk_json_val *params);
|
||||
int virtio_blk_transport_destroy(struct spdk_virtio_blk_transport *transport,
|
||||
spdk_vhost_fini_cb cb_fn);
|
||||
|
||||
struct spdk_virtio_blk_transport *virtio_blk_transport_get_first(void);
|
||||
struct spdk_virtio_blk_transport *virtio_blk_transport_get_next(
|
||||
struct spdk_virtio_blk_transport *transport);
|
||||
void virtio_blk_transport_dump_opts(struct spdk_virtio_blk_transport *transport,
|
||||
struct spdk_json_write_ctx *w);
|
||||
struct spdk_virtio_blk_transport *virtio_blk_tgt_get_transport(const char *transport_name);
|
||||
const struct spdk_virtio_blk_transport_ops *virtio_blk_get_transport_ops(
|
||||
const char *transport_name);
|
||||
|
||||
|
@ -10,7 +10,7 @@
|
||||
#include "spdk/util.h"
|
||||
#include "spdk/string.h"
|
||||
#include "spdk/env.h"
|
||||
|
||||
#include "spdk/log.h"
|
||||
#include "spdk/scsi.h"
|
||||
#include "spdk/vhost.h"
|
||||
#include "vhost_internal.h"
|
||||
@ -472,6 +472,60 @@ invalid:
|
||||
SPDK_RPC_REGISTER("vhost_controller_set_coalescing", rpc_vhost_controller_set_coalescing,
|
||||
SPDK_RPC_RUNTIME)
|
||||
|
||||
struct rpc_get_transport {
|
||||
char *name;
|
||||
};
|
||||
|
||||
static const struct spdk_json_object_decoder rpc_get_transport_decoders[] = {
|
||||
{"name", offsetof(struct rpc_get_transport, name), spdk_json_decode_string, true},
|
||||
};
|
||||
|
||||
static void
|
||||
rpc_virtio_blk_get_transports(struct spdk_jsonrpc_request *request,
|
||||
const struct spdk_json_val *params)
|
||||
{
|
||||
struct rpc_get_transport req = { 0 };
|
||||
struct spdk_json_write_ctx *w;
|
||||
struct spdk_virtio_blk_transport *transport = NULL;
|
||||
|
||||
if (params) {
|
||||
if (spdk_json_decode_object(params, rpc_get_transport_decoders,
|
||||
SPDK_COUNTOF(rpc_get_transport_decoders),
|
||||
&req)) {
|
||||
SPDK_ERRLOG("spdk_json_decode_object failed\n");
|
||||
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, "Invalid parameters");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (req.name) {
|
||||
transport = virtio_blk_tgt_get_transport(req.name);
|
||||
if (transport == NULL) {
|
||||
SPDK_ERRLOG("transport '%s' does not exist\n", req.name);
|
||||
spdk_jsonrpc_send_error_response(request, -ENODEV, spdk_strerror(ENODEV));
|
||||
free(req.name);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
w = spdk_jsonrpc_begin_result(request);
|
||||
spdk_json_write_array_begin(w);
|
||||
|
||||
if (transport) {
|
||||
virtio_blk_transport_dump_opts(transport, w);
|
||||
} else {
|
||||
for (transport = virtio_blk_transport_get_first(); transport != NULL;
|
||||
transport = virtio_blk_transport_get_next(transport)) {
|
||||
virtio_blk_transport_dump_opts(transport, w);
|
||||
}
|
||||
}
|
||||
|
||||
spdk_json_write_array_end(w);
|
||||
spdk_jsonrpc_end_result(request, w);
|
||||
free(req.name);
|
||||
}
|
||||
SPDK_RPC_REGISTER("virtio_blk_get_transports", rpc_virtio_blk_get_transports, SPDK_RPC_RUNTIME)
|
||||
|
||||
struct rpc_virtio_blk_create_transport {
|
||||
char *name;
|
||||
};
|
||||
|
@ -20,6 +20,23 @@ def vhost_controller_set_coalescing(client, ctrlr, delay_base_us, iops_threshold
|
||||
return client.call('vhost_controller_set_coalescing', params)
|
||||
|
||||
|
||||
def virtio_blk_get_transports(client, name=None):
|
||||
"""Get list of virtio-blk transports.
|
||||
Args:
|
||||
name: name of the virtio-blk transport (optional).
|
||||
|
||||
Returns:
|
||||
List of virtio-blk transport objects.
|
||||
"""
|
||||
|
||||
params = {}
|
||||
|
||||
if name:
|
||||
params['name'] = name
|
||||
|
||||
return client.call('virtio_blk_get_transports', params)
|
||||
|
||||
|
||||
def virtio_blk_create_transport(client, **params):
|
||||
"""Create virtio blk transport.
|
||||
Args:
|
||||
|
@ -2601,6 +2601,13 @@ Format: 'user:u1 secret:s1 muser:mu1 msecret:ms1,user:u2 secret:s2 muser:mu2 mse
|
||||
p.add_argument('name', help='transport name')
|
||||
p.set_defaults(func=virtio_blk_create_transport)
|
||||
|
||||
def virtio_blk_get_transports(args):
|
||||
print_dict(rpc.vhost.virtio_blk_get_transports(args.client, name=args.name))
|
||||
|
||||
p = subparsers.add_parser('virtio_blk_get_transports', help='Display virtio-blk transports or requested transport')
|
||||
p.add_argument('--name', help='Transport name (optional)', type=str)
|
||||
p.set_defaults(func=virtio_blk_get_transports)
|
||||
|
||||
def vhost_create_scsi_controller(args):
|
||||
rpc.vhost.vhost_create_scsi_controller(args.client,
|
||||
ctrlr=args.ctrlr,
|
||||
|
Loading…
Reference in New Issue
Block a user