Commit 2f600ca7 authored by Jin Yu's avatar Jin Yu Committed by Jim Harris
Browse files

virtio-blk: add hotplug rpc



Change-Id: I4ed583d91ae9e820be1ee6f4553f29d6650c4922
Signed-off-by: default avatarJin Yu <jin.yu@intel.com>
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/5791


Community-CI: Broadcom CI
Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarBen Walker <benjamin.walker@intel.com>
Reviewed-by: default avatarChangpeng Liu <changpeng.liu@intel.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
parent ebea4dd6
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -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
+45 −0
Original line number Diff line number Diff line
@@ -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}
+37 −0
Original line number Diff line number Diff line
@@ -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;
};
+10 −0
Original line number Diff line number Diff line
@@ -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
+15 −0
Original line number Diff line number Diff line
@@ -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)