bdev/aio: An error code can be returned via the rpc interface.

When we create AIO using the RPC interface, we can use the error
message to return to determine what exceptions have occurred.

Change-Id: I537f1a7d1053dcc27960de004fd0b4aea49919e9
Signed-off-by: Tianyu yang <yangtianyu2@huawei.com>
Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/452313
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Darek Stojaczyk <dariusz.stojaczyk@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
This commit is contained in:
Tianyu yang 2019-04-28 14:35:58 +08:00 committed by Jim Harris
parent 3c45798173
commit a8b8badb3c
3 changed files with 28 additions and 17 deletions

View File

@ -580,7 +580,7 @@ bdev_aio_group_destroy_cb(void *io_device, void *ctx_buf)
spdk_poller_unregister(&ch->poller);
}
struct spdk_bdev *
int
create_aio_bdev(const char *name, const char *filename, uint32_t block_size)
{
struct file_disk *fdisk;
@ -591,16 +591,18 @@ create_aio_bdev(const char *name, const char *filename, uint32_t block_size)
fdisk = calloc(1, sizeof(*fdisk));
if (!fdisk) {
SPDK_ERRLOG("Unable to allocate enough memory for aio backend\n");
return NULL;
return -ENOMEM;
}
fdisk->filename = strdup(filename);
if (!fdisk->filename) {
rc = -ENOMEM;
goto error_return;
}
if (bdev_aio_open(fdisk)) {
SPDK_ERRLOG("Unable to open file %s. fd: %d errno: %d\n", filename, fdisk->fd, errno);
rc = -errno;
goto error_return;
}
@ -608,6 +610,7 @@ create_aio_bdev(const char *name, const char *filename, uint32_t block_size)
fdisk->disk.name = strdup(name);
if (!fdisk->disk.name) {
rc = -ENOMEM;
goto error_return;
}
fdisk->disk.product_name = "AIO disk";
@ -620,6 +623,7 @@ create_aio_bdev(const char *name, const char *filename, uint32_t block_size)
/* User did not specify block size - use autodetected block size. */
if (detected_block_size == 0) {
SPDK_ERRLOG("Block size could not be auto-detected\n");
rc = -EINVAL;
goto error_return;
}
fdisk->block_size_override = false;
@ -629,6 +633,7 @@ create_aio_bdev(const char *name, const char *filename, uint32_t block_size)
SPDK_ERRLOG("Specified block size %" PRIu32 " is smaller than "
"auto-detected block size %" PRIu32 "\n",
block_size, detected_block_size);
rc = -EINVAL;
goto error_return;
} else if (detected_block_size != 0 && block_size != detected_block_size) {
SPDK_WARNLOG("Specified block size %" PRIu32 " does not match "
@ -640,11 +645,13 @@ create_aio_bdev(const char *name, const char *filename, uint32_t block_size)
if (block_size < 512) {
SPDK_ERRLOG("Invalid block size %" PRIu32 " (must be at least 512).\n", block_size);
rc = -EINVAL;
goto error_return;
}
if (!spdk_u32_is_pow2(block_size)) {
SPDK_ERRLOG("Invalid block size %" PRIu32 " (must be a power of 2.)\n", block_size);
rc = -EINVAL;
goto error_return;
}
@ -654,6 +661,7 @@ create_aio_bdev(const char *name, const char *filename, uint32_t block_size)
if (disk_size % fdisk->disk.blocklen != 0) {
SPDK_ERRLOG("Disk size %" PRIu64 " is not a multiple of block size %" PRIu32 "\n",
disk_size, fdisk->disk.blocklen);
rc = -EINVAL;
goto error_return;
}
@ -672,12 +680,12 @@ create_aio_bdev(const char *name, const char *filename, uint32_t block_size)
}
TAILQ_INSERT_TAIL(&g_aio_disk_head, fdisk, link);
return &fdisk->disk;
return 0;
error_return:
bdev_aio_close(fdisk);
aio_free_disk(fdisk);
return NULL;
return rc;
}
struct delete_aio_bdev_ctx {
@ -720,7 +728,7 @@ bdev_aio_initialize(void)
{
size_t i;
struct spdk_conf_section *sp;
struct spdk_bdev *bdev;
int rc = 0;
TAILQ_INIT(&g_aio_disk_head);
spdk_io_device_register(&aio_if, bdev_aio_group_create_cb, bdev_aio_group_destroy_cb,
@ -763,9 +771,9 @@ bdev_aio_initialize(void)
block_size = (uint32_t)tmp;
}
bdev = create_aio_bdev(name, file, block_size);
if (!bdev) {
SPDK_ERRLOG("Unable to create AIO bdev from file %s\n", file);
rc = create_aio_bdev(name, file, block_size);
if (rc) {
SPDK_ERRLOG("Unable to create AIO bdev from file %s, err is %s\n", file, spdk_strerror(-rc));
i++;
continue;
}

View File

@ -39,7 +39,7 @@
typedef void (*delete_aio_bdev_complete)(void *cb_arg, int bdeverrno);
struct spdk_bdev *create_aio_bdev(const char *name, const char *filename, uint32_t block_size);
int create_aio_bdev(const char *name, const char *filename, uint32_t block_size);
void delete_aio_bdev(struct spdk_bdev *bdev, delete_aio_bdev_complete cb_fn, void *cb_arg);

View File

@ -62,37 +62,40 @@ spdk_rpc_construct_aio_bdev(struct spdk_jsonrpc_request *request,
{
struct rpc_construct_aio req = {};
struct spdk_json_write_ctx *w;
struct spdk_bdev *bdev;
int rc = 0;
if (spdk_json_decode_object(params, rpc_construct_aio_decoders,
SPDK_COUNTOF(rpc_construct_aio_decoders),
&req)) {
SPDK_ERRLOG("spdk_json_decode_object failed\n");
rc = -EINVAL;
goto invalid;
}
if (req.filename == NULL) {
rc = -EINVAL;
goto invalid;
}
bdev = create_aio_bdev(req.name, req.filename, req.block_size);
if (bdev == NULL) {
rc = create_aio_bdev(req.name, req.filename, req.block_size);
if (rc) {
goto invalid;
}
free_rpc_construct_aio(&req);
w = spdk_jsonrpc_begin_result(request);
if (w == NULL) {
return;
goto cleanup;
}
spdk_json_write_string(w, spdk_bdev_get_name(bdev));
spdk_json_write_string(w, req.name);
spdk_jsonrpc_end_result(request, w);
return;
goto cleanup;
invalid:
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, "Invalid parameters");
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, spdk_strerror(-rc));
cleanup:
free_rpc_construct_aio(&req);
}
SPDK_RPC_REGISTER("construct_aio_bdev", spdk_rpc_construct_aio_bdev, SPDK_RPC_RUNTIME)