From 2f600ca75ef5bcfd9a42596b8362c10e6fb2e7f7 Mon Sep 17 00:00:00 2001 From: Jin Yu Date: Wed, 9 Dec 2020 21:57:35 +0800 Subject: [PATCH] virtio-blk: add hotplug rpc Change-Id: I4ed583d91ae9e820be1ee6f4553f29d6650c4922 Signed-off-by: Jin Yu Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/5791 Community-CI: Broadcom CI Tested-by: SPDK CI Jenkins Reviewed-by: Ben Walker Reviewed-by: Changpeng Liu Reviewed-by: Jim Harris --- CHANGELOG.md | 4 +++ doc/jsonrpc.md | 45 ++++++++++++++++++++++++++++ module/bdev/virtio/bdev_virtio_rpc.c | 37 +++++++++++++++++++++++ scripts/rpc.py | 10 +++++++ scripts/rpc/vhost.py | 15 ++++++++++ 5 files changed, 111 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f82fc3442..756a1c46a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,10 @@ ## v21.04: (Upcoming Release) +### virtio + +Add the bdev_virtio_blk_set_hotplug rpc for the virtio blk pci device. + ### ocf Updated OCF submodule to v20.12.2 diff --git a/doc/jsonrpc.md b/doc/jsonrpc.md index 45c2516ee..cfa353364 100644 --- a/doc/jsonrpc.md +++ b/doc/jsonrpc.md @@ -448,6 +448,7 @@ Example response: "bdev_virtio_attach_controller", "bdev_virtio_scsi_get_devices", "bdev_virtio_detach_controller", + "bdev_virtio_blk_set_hotplug", "bdev_aio_delete", "bdev_aio_create", "bdev_split_delete", @@ -4163,6 +4164,50 @@ Example response: } ~~~ +## bdev_virtio_blk_set_hotplug {#rpc_bdev_virtio_blk_set_hotplug} + +Enable/Disable the virtio blk hotplug monitor or change the monitor period time + +### Parameters + +Name | Optional | Type | Description +----------------------- | -------- | ----------- | ----------- +enable | Required | bool | Enable or disable the virtio blk hotplug monitor +period-us | Optional | number | The period time of the monitor + +When the enable is true then the period-us is optional. If user don't set the period time then use the default +value. When the enable is false then the period-us is not required. + +### Result + +True the rpc is successful otherwise false + +### Example + +Example request: + +~~~ +{ + "params": { + "enable": "true", + "period-us": "1000000" + }, + "jsonrpc": "2.0", + "method": "bdev_virtio_blk_set_hotplug", + "id": 1 +} +~~~ + +Example response: + +~~~ +{ + "jsonrpc": "2.0", + "id": 1, + "result": true +} +~~~ + # iSCSI Target {#jsonrpc_components_iscsi_tgt} ## iscsi_set_options method {#rpc_iscsi_set_options} diff --git a/module/bdev/virtio/bdev_virtio_rpc.c b/module/bdev/virtio/bdev_virtio_rpc.c index aee89f010..985110d0e 100644 --- a/module/bdev/virtio/bdev_virtio_rpc.c +++ b/module/bdev/virtio/bdev_virtio_rpc.c @@ -37,12 +37,49 @@ #include "spdk/rpc.h" #include "spdk/util.h" #include "spdk/log.h" +#include "spdk/thread.h" #include "bdev_virtio.h" #define SPDK_VIRTIO_USER_DEFAULT_VQ_COUNT 1 #define SPDK_VIRTIO_USER_DEFAULT_QUEUE_SIZE 512 +struct rpc_bdev_virtio_blk_hotplug { + bool enabled; + uint64_t period_us; +}; + +static const struct spdk_json_object_decoder rpc_bdev_virtio_blk_hotplug_decoders[] = { + {"enable", offsetof(struct rpc_bdev_virtio_blk_hotplug, enabled), spdk_json_decode_bool, false}, + {"period_us", offsetof(struct rpc_bdev_virtio_blk_hotplug, period_us), spdk_json_decode_uint64, true}, +}; + +static void +rpc_bdev_virtio_blk_set_hotplug(struct spdk_jsonrpc_request *request, + const struct spdk_json_val *params) +{ + struct rpc_bdev_virtio_blk_hotplug req = {false, 0}; + int rc; + + if (spdk_json_decode_object(params, rpc_bdev_virtio_blk_hotplug_decoders, + SPDK_COUNTOF(rpc_bdev_virtio_blk_hotplug_decoders), &req)) { + SPDK_ERRLOG("spdk_json_decode_object failed\n"); + rc = -EINVAL; + goto invalid; + } + + rc = bdev_virtio_pci_blk_set_hotplug(req.enabled, req.period_us); + if (rc) { + goto invalid; + } + + spdk_jsonrpc_send_bool_response(request, true); + return; +invalid: + spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, spdk_strerror(-rc)); +} +SPDK_RPC_REGISTER("bdev_virtio_blk_set_hotplug", rpc_bdev_virtio_blk_set_hotplug, SPDK_RPC_RUNTIME) + struct rpc_remove_virtio_dev { char *name; }; diff --git a/scripts/rpc.py b/scripts/rpc.py index d05def0d3..3de543e9e 100755 --- a/scripts/rpc.py +++ b/scripts/rpc.py @@ -2317,6 +2317,16 @@ Format: 'user:u1 secret:s1 muser:mu1 msecret:ms1,user:u2 secret:s2 muser:mu2 mse p.add_argument('name', help='Virtio device name. E.g. VirtioUser0') p.set_defaults(func=bdev_virtio_detach_controller) + def bdev_virtio_blk_set_hotplug(args): + rpc.vhost.bdev_virtio_blk_set_hotplug(args.client, enable=args.enable, period_us=args.period_us) + + p = subparsers.add_parser('bdev_virtio_blk_set_hotplug', help='Set hotplug options for bdev virtio_blk type.') + p.add_argument('-d', '--disable', dest='enable', default=False, action='store_false', help="Disable hotplug (default)") + p.add_argument('-e', '--enable', dest='enable', action='store_true', help="Enable hotplug") + p.add_argument('-r', '--period-us', + help='How often the hotplug is processed for insert and remove events', type=int) + p.set_defaults(func=bdev_virtio_blk_set_hotplug) + # OCSSD def bdev_ocssd_create(args): nsid = int(args.nsid) if args.nsid is not None else None diff --git a/scripts/rpc/vhost.py b/scripts/rpc/vhost.py index 8dc17d07c..01802885e 100644 --- a/scripts/rpc/vhost.py +++ b/scripts/rpc/vhost.py @@ -157,3 +157,18 @@ def bdev_virtio_detach_controller(client, name): def bdev_virtio_scsi_get_devices(client): """Get list of virtio scsi devices.""" return client.call('bdev_virtio_scsi_get_devices') + + +def bdev_virtio_blk_set_hotplug(client, enable, period_us=None): + """Set options for the bdev virtio blk. This is startup command. + + Args: + enable: True to enable hotplug, False to disable. + period_us: how often the hotplug is processed for insert and remove events. Set 0 to reset to default. (optional) + """ + params = {'enable': enable} + + if period_us: + params['period_us'] = period_us + + return client.call('bdev_virtio_blk_set_hotplug', params)