Commit 6a29c6a9 authored by Liang Yan's avatar Liang Yan Committed by Tomasz Zawadzki
Browse files

bdev/rbd: add ceph rbd resize function.



Signed-off-by: default avatarLiang Yan <liang.z.yan@intel.com>
Change-Id: Id7f24f1f5e0789ee6d4c07ae7f59cc2d98983e98
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/1766


Reviewed-by: default avatarShuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Reviewed-by: default avatarChangpeng Liu <changpeng.liu@intel.com>
Community-CI: Mellanox Build Bot
Community-CI: Broadcom CI
Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
parent 63db535f
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -80,6 +80,8 @@ A new RPC `thread_get_pollers` has been added to retrieve pollers of SPDK thread

A new RPC `thread_get_io_channels` has been added to retrieve I/O channels of SPDK threads.

A new RPC `bdev_rbd_resize` has been added to resize the Ceph RBD bdev.

### thread

A new function `spdk_thread_lib_init_ext` has been added, and the function
+6 −0
Original line number Diff line number Diff line
@@ -119,6 +119,12 @@ To remove a block device representation use the bdev_rbd_delete command.

`rpc.py bdev_rbd_delete Rbd0`

To resize a bdev use the bdev_rbd_resize command.

`rpc.py bdev_rbd_resize Rbd0 4096`

This command will resize the Rbd0 bdev to 4096 MiB.

# Compression Virtual Bdev Module {#bdev_config_compress}

The compression bdev module can be configured to provide compression/decompression
+43 −0
Original line number Diff line number Diff line
@@ -1998,6 +1998,49 @@ Example response:
}
~~~

## bdev_rbd_resize {#rpc_bdev_rbd_resize}

Resize @ref bdev_config_rbd bdev

This method is available only if SPDK was build with Ceph RBD support.

### Result

`true` if bdev with provided name was resized or `false` otherwise.

### Parameters

Name                    | Optional | Type        | Description
----------------------- | -------- | ----------- | -----------
name                    | Required | string      | Bdev name
new_size                | Required | int         | New bdev size for resize operation in MiB

### Example

Example request:

~~~
{
  "params": {
    "name": "Rbd0"
    "new_size": "4096"
  },
  "jsonrpc": "2.0",
  "method": "bdev_rbd_resize",
  "id": 1
}
~~~

Example response:

~~~
{
  "jsonrpc": "2.0",
  "id": 1,
  "result": true
}
~~~

## bdev_delay_create {#rpc_bdev_delay_create}

Create delay bdev. This bdev type redirects all IO to it's base bdev and inserts a delay on the completion
+1 −1
Original line number Diff line number Diff line
@@ -34,7 +34,7 @@
SPDK_ROOT_DIR := $(abspath $(CURDIR)/../../..)
include $(SPDK_ROOT_DIR)/mk/spdk.common.mk

SO_VER := 2
SO_VER := 3
SO_MINOR := 0
SO_SUFFIX := $(SO_VER).$(SO_MINOR)

+38 −0
Original line number Diff line number Diff line
@@ -783,6 +783,44 @@ spdk_bdev_rbd_delete(struct spdk_bdev *bdev, spdk_delete_rbd_complete cb_fn, voi
	spdk_bdev_unregister(bdev, cb_fn, cb_arg);
}

int
spdk_bdev_rbd_resize(struct spdk_bdev *bdev, const uint64_t new_size_in_mb)
{
	struct spdk_io_channel *ch;
	struct bdev_rbd_io_channel *rbd_io_ch;
	int rc;
	uint64_t new_size_in_byte;
	uint64_t current_size_in_mb;

	if (bdev->module != &rbd_if) {
		return -EINVAL;
	}

	current_size_in_mb = bdev->blocklen * bdev->blockcnt / (1024 * 1024);
	if (current_size_in_mb > new_size_in_mb) {
		SPDK_ERRLOG("The new bdev size must be lager than current bdev size.\n");
		return -EINVAL;
	}

	ch = bdev_rbd_get_io_channel(bdev);
	rbd_io_ch = spdk_io_channel_get_ctx(ch);
	new_size_in_byte = new_size_in_mb * 1024 * 1024;

	rc = rbd_resize(rbd_io_ch->image, new_size_in_byte);
	if (rc != 0) {
		SPDK_ERRLOG("failed to resize the ceph bdev.\n");
		return rc;
	}

	rc = spdk_bdev_notify_blockcnt_change(bdev, new_size_in_byte / bdev->blocklen);
	if (rc != 0) {
		SPDK_ERRLOG("failed to notify block cnt change.\n");
		return rc;
	}

	return rc;
}

static int
bdev_rbd_library_init(void)
{
Loading