aio: add aio bdev rescan feature

Signed-off-by: shuochen0311 <shuo.chen@databricks.com>
Change-Id: I7f2788640a56d1e1bc8b7b311622628e8a6be56e
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/11084
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Shuhei Matsumoto <smatsumoto@nvidia.com>
Community-CI: Mellanox Build Bot
Community-CI: Broadcom CI <spdk-ci.pdl@broadcom.com>
This commit is contained in:
shuochen0311 2022-01-13 20:37:36 +00:00 committed by Tomasz Zawadzki
parent 765cf74d07
commit b635d19a26
7 changed files with 128 additions and 0 deletions

View File

@ -21,6 +21,10 @@ is fabric or not.
API `spdk_nvme_poll_group_remove` was limited to be available only for a
disconnected qpair in the group.
### bdev_aio
Added `bdev_aio_rescan` RPC to allow rescaning the size of aio bdev
### bdev
The NVMe bdev module supports multipath and improved I/O error resiliency.

View File

@ -2813,6 +2813,41 @@ Example response:
}
~~~
### bdev_aio_rescan {#rpc_bdev_aio_rescan}
Rescan the size of @ref bdev_config_aio.
#### Parameters
Name | Optional | Type | Description
----------------------- | -------- | ----------- | -----------
name | Required | string | Bdev name
#### Example
Example request:
~~json
{
"params": {
"name": "Aio0"
},
"jsonrpc": "2.0",
"method": "bdev_aio_rescan",
"id": 1
}
~~
Example response:
~~json
{
"jsonrpc": "2.0",
"id": 1,
"result": true
}
~~
### bdev_aio_delete {#rpc_bdev_aio_delete}
Delete @ref bdev_config_aio.

View File

@ -820,6 +820,38 @@ error_return:
return rc;
}
int
bdev_aio_rescan(struct spdk_bdev *bdev)
{
struct file_disk *fdisk;
uint64_t disk_size, blockcnt;
int rc;
if (!bdev || bdev->module != &aio_if) {
return -ENODEV;
}
fdisk = SPDK_CONTAINEROF(bdev, struct file_disk, disk);
disk_size = spdk_fd_get_size(fdisk->fd);
blockcnt = disk_size / fdisk->disk.blocklen;
if (fdisk->disk.blockcnt != blockcnt) {
SPDK_NOTICELOG("AIO device is resized: bdev name %s, old block count %" PRIu64 ", new block count %"
PRIu64 "\n",
fdisk->filename,
fdisk->disk.blockcnt,
blockcnt);
rc = spdk_bdev_notify_blockcnt_change(&fdisk->disk, blockcnt);
if (rc != 0) {
SPDK_ERRLOG("Could not change num blocks for aio bdev: name %s, errno: %d.\n",
fdisk->filename, rc);
return rc;
}
}
return 0;
}
struct delete_aio_bdev_ctx {
delete_aio_bdev_complete cb_fn;
void *cb_arg;

View File

@ -41,6 +41,7 @@ typedef void (*delete_aio_bdev_complete)(void *cb_arg, int bdeverrno);
int create_aio_bdev(const char *name, const char *filename, uint32_t block_size);
int bdev_aio_rescan(struct spdk_bdev *bdev);
void bdev_aio_delete(struct spdk_bdev *bdev, delete_aio_bdev_complete cb_fn, void *cb_arg);
#endif /* SPDK_BDEV_AIO_H */

View File

@ -111,6 +111,44 @@ rpc_bdev_aio_create(struct spdk_jsonrpc_request *request,
SPDK_RPC_REGISTER("bdev_aio_create", rpc_bdev_aio_create, SPDK_RPC_RUNTIME)
SPDK_RPC_REGISTER_ALIAS_DEPRECATED(bdev_aio_create, construct_aio_bdev)
struct rpc_rescan_aio {
char *name;
};
static const struct spdk_json_object_decoder rpc_rescan_aio_decoders[] = {
{"name", offsetof(struct rpc_rescan_aio, name), spdk_json_decode_string},
};
static void
rpc_bdev_aio_rescan(struct spdk_jsonrpc_request *request,
const struct spdk_json_val *params)
{
struct rpc_rescan_aio req = {NULL};
struct spdk_bdev *bdev;
int bdeverrno;
if (spdk_json_decode_object(params, rpc_rescan_aio_decoders,
SPDK_COUNTOF(rpc_rescan_aio_decoders),
&req)) {
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INTERNAL_ERROR,
"spdk_json_decode_object failed");
goto cleanup;
}
bdev = spdk_bdev_get_by_name(req.name);
if (bdev == NULL) {
spdk_jsonrpc_send_error_response(request, -ENODEV, spdk_strerror(ENODEV));
goto cleanup;
}
bdeverrno = bdev_aio_rescan(bdev);
spdk_jsonrpc_send_bool_response(request, bdeverrno);
cleanup:
free(req.name);
}
SPDK_RPC_REGISTER("bdev_aio_rescan", rpc_bdev_aio_rescan, SPDK_RPC_RUNTIME)
struct rpc_delete_aio {
char *name;
};

View File

@ -426,6 +426,14 @@ if __name__ == "__main__":
p.add_argument('block_size', help='Block size for this bdev', type=int, nargs='?', default=0)
p.set_defaults(func=bdev_aio_create)
def bdev_aio_rescan(args):
print_json(rpc.bdev.bdev_aio_rescan(args.client,
name=args.name))
p = subparsers.add_parser('bdev_aio_rescan', help='Rescan a bdev size with aio backend')
p.add_argument('name', help='Block device name')
p.set_defaults(func=bdev_aio_rescan)
def bdev_aio_delete(args):
rpc.bdev.bdev_aio_delete(args.client,
name=args.name)

View File

@ -386,6 +386,16 @@ def bdev_aio_create(client, filename, name, block_size=None):
return client.call('bdev_aio_create', params)
def bdev_aio_rescan(client, name):
"""Rescan a Linux AIO block device.
Args:
bdev_name: name of aio bdev to delete
"""
params = {'name': name}
return client.call('bdev_aio_rescan', params)
@deprecated_alias('delete_aio_bdev')
def bdev_aio_delete(client, name):
"""Remove aio bdev from the system.