bdev/rpc: Add descriptive error messages for malloc bdevs

Provide more error codes and/or messages then just a
generic "32602 invalid parameters" error.

Change-Id: I1777f454faef336b10af24dda50a2d5b5e73727f
Signed-off-by: Karol Latecki <karol.latecki@intel.com>
Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/459948
Reviewed-by: Vitaliy Mysak <vitaliy.mysak@intel.com>
Reviewed-by: Darek Stojaczyk <dariusz.stojaczyk@intel.com>
Reviewed-by: Changpeng Liu <changpeng.liu@intel.com>
Reviewed-by: Tomasz Zawadzki <tomasz.zawadzki@intel.com>
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
This commit is contained in:
Karol Latecki 2019-07-01 13:05:24 +02:00 committed by Changpeng Liu
parent 772db556af
commit 5e28673bc5
3 changed files with 41 additions and 29 deletions

View File

@ -390,21 +390,22 @@ static const struct spdk_bdev_fn_table malloc_fn_table = {
.write_config_json = bdev_malloc_write_json_config, .write_config_json = bdev_malloc_write_json_config,
}; };
struct spdk_bdev *create_malloc_disk(const char *name, const struct spdk_uuid *uuid, int
uint64_t num_blocks, uint32_t block_size) create_malloc_disk(struct spdk_bdev **bdev, const char *name, const struct spdk_uuid *uuid,
uint64_t num_blocks, uint32_t block_size)
{ {
struct malloc_disk *mdisk; struct malloc_disk *mdisk;
int rc; int rc;
if (num_blocks == 0) { if (num_blocks == 0) {
SPDK_ERRLOG("Disk must be more than 0 blocks\n"); SPDK_ERRLOG("Disk num_blocks must be greater than 0");
return NULL; return -EINVAL;
} }
mdisk = calloc(1, sizeof(*mdisk)); mdisk = calloc(1, sizeof(*mdisk));
if (!mdisk) { if (!mdisk) {
SPDK_ERRLOG("mdisk calloc() failed\n"); SPDK_ERRLOG("mdisk calloc() failed\n");
return NULL; return -ENOMEM;
} }
/* /*
@ -418,7 +419,7 @@ struct spdk_bdev *create_malloc_disk(const char *name, const struct spdk_uuid *u
if (!mdisk->malloc_buf) { if (!mdisk->malloc_buf) {
SPDK_ERRLOG("malloc_buf spdk_zmalloc() failed\n"); SPDK_ERRLOG("malloc_buf spdk_zmalloc() failed\n");
malloc_disk_free(mdisk); malloc_disk_free(mdisk);
return NULL; return -ENOMEM;
} }
if (name) { if (name) {
@ -430,7 +431,7 @@ struct spdk_bdev *create_malloc_disk(const char *name, const struct spdk_uuid *u
} }
if (!mdisk->disk.name) { if (!mdisk->disk.name) {
malloc_disk_free(mdisk); malloc_disk_free(mdisk);
return NULL; return -ENOMEM;
} }
mdisk->disk.product_name = "Malloc disk"; mdisk->disk.product_name = "Malloc disk";
@ -450,12 +451,14 @@ struct spdk_bdev *create_malloc_disk(const char *name, const struct spdk_uuid *u
rc = spdk_bdev_register(&mdisk->disk); rc = spdk_bdev_register(&mdisk->disk);
if (rc) { if (rc) {
malloc_disk_free(mdisk); malloc_disk_free(mdisk);
return NULL; return rc;
} }
*bdev = &(mdisk->disk);
TAILQ_INSERT_TAIL(&g_malloc_disks, mdisk, link); TAILQ_INSERT_TAIL(&g_malloc_disks, mdisk, link);
return &mdisk->disk; return rc;
} }
void void
@ -490,10 +493,9 @@ static int bdev_malloc_initialize(void)
} }
size = (uint64_t)LunSizeInMB * 1024 * 1024; size = (uint64_t)LunSizeInMB * 1024 * 1024;
for (i = 0; i < NumberOfLuns; i++) { for (i = 0; i < NumberOfLuns; i++) {
bdev = create_malloc_disk(NULL, NULL, size / BlockSize, BlockSize); rc = create_malloc_disk(&bdev, NULL, NULL, size / BlockSize, BlockSize);
if (bdev == NULL) { if (rc) {
SPDK_ERRLOG("Could not create malloc disk\n"); SPDK_ERRLOG("Could not create malloc disk\n");
rc = EINVAL;
goto end; goto end;
} }
} }

View File

@ -40,8 +40,8 @@
typedef void (*spdk_delete_malloc_complete)(void *cb_arg, int bdeverrno); typedef void (*spdk_delete_malloc_complete)(void *cb_arg, int bdeverrno);
struct spdk_bdev *create_malloc_disk(const char *name, const struct spdk_uuid *uuid, int create_malloc_disk(struct spdk_bdev **bdev, const char *name, const struct spdk_uuid *uuid,
uint64_t num_blocks, uint32_t block_size); uint64_t num_blocks, uint32_t block_size);
void delete_malloc_disk(struct spdk_bdev *bdev, spdk_delete_malloc_complete cb_fn, void *cb_arg); void delete_malloc_disk(struct spdk_bdev *bdev, spdk_delete_malloc_complete cb_fn, void *cb_arg);

View File

@ -68,24 +68,36 @@ spdk_rpc_construct_malloc_bdev(struct spdk_jsonrpc_request *request,
struct spdk_uuid *uuid = NULL; struct spdk_uuid *uuid = NULL;
struct spdk_uuid decoded_uuid; struct spdk_uuid decoded_uuid;
struct spdk_bdev *bdev; struct spdk_bdev *bdev;
int rc = 0;
if (spdk_json_decode_object(params, rpc_construct_malloc_decoders, if (spdk_json_decode_object(params, rpc_construct_malloc_decoders,
SPDK_COUNTOF(rpc_construct_malloc_decoders), SPDK_COUNTOF(rpc_construct_malloc_decoders),
&req)) { &req)) {
SPDK_DEBUGLOG(SPDK_LOG_BDEV_MALLOC, "spdk_json_decode_object failed\n"); SPDK_DEBUGLOG(SPDK_LOG_BDEV_MALLOC, "spdk_json_decode_object failed\n");
goto invalid; spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INTERNAL_ERROR,
"spdk_json_decode_object failed");
goto cleanup;
}
if (req.num_blocks == 0) {
spdk_jsonrpc_send_error_response(request, -EINVAL,
"Disk num_blocks must be greater than 0");
goto cleanup;
} }
if (req.uuid) { if (req.uuid) {
if (spdk_uuid_parse(&decoded_uuid, req.uuid)) { if (spdk_uuid_parse(&decoded_uuid, req.uuid)) {
goto invalid; spdk_jsonrpc_send_error_response(request, -EINVAL,
"Failed to parse bdev UUID");
goto cleanup;
} }
uuid = &decoded_uuid; uuid = &decoded_uuid;
} }
bdev = create_malloc_disk(req.name, uuid, req.num_blocks, req.block_size); rc = create_malloc_disk(&bdev, req.name, uuid, req.num_blocks, req.block_size);
if (bdev == NULL) { if (rc) {
goto invalid; spdk_jsonrpc_send_error_response(request, rc, spdk_strerror(-rc));
goto cleanup;
} }
free_rpc_construct_malloc(&req); free_rpc_construct_malloc(&req);
@ -99,9 +111,8 @@ spdk_rpc_construct_malloc_bdev(struct spdk_jsonrpc_request *request,
spdk_jsonrpc_end_result(request, w); spdk_jsonrpc_end_result(request, w);
return; return;
invalid: cleanup:
free_rpc_construct_malloc(&req); free_rpc_construct_malloc(&req);
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, "Invalid parameters");
} }
SPDK_RPC_REGISTER("construct_malloc_bdev", spdk_rpc_construct_malloc_bdev, SPDK_RPC_RUNTIME) SPDK_RPC_REGISTER("construct_malloc_bdev", spdk_rpc_construct_malloc_bdev, SPDK_RPC_RUNTIME)
@ -140,21 +151,21 @@ spdk_rpc_delete_malloc_bdev(struct spdk_jsonrpc_request *request,
{ {
struct rpc_delete_malloc req = {NULL}; struct rpc_delete_malloc req = {NULL};
struct spdk_bdev *bdev; struct spdk_bdev *bdev;
int rc;
if (spdk_json_decode_object(params, rpc_delete_malloc_decoders, if (spdk_json_decode_object(params, rpc_delete_malloc_decoders,
SPDK_COUNTOF(rpc_delete_malloc_decoders), SPDK_COUNTOF(rpc_delete_malloc_decoders),
&req)) { &req)) {
SPDK_DEBUGLOG(SPDK_LOG_BDEV_MALLOC, "spdk_json_decode_object failed\n"); SPDK_DEBUGLOG(SPDK_LOG_BDEV_MALLOC, "spdk_json_decode_object failed\n");
rc = -EINVAL; spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INTERNAL_ERROR,
goto invalid; "spdk_json_decode_object failed");
goto cleanup;
} }
bdev = spdk_bdev_get_by_name(req.name); bdev = spdk_bdev_get_by_name(req.name);
if (bdev == NULL) { if (bdev == NULL) {
SPDK_INFOLOG(SPDK_LOG_BDEV_MALLOC, "bdev '%s' does not exist\n", req.name); SPDK_INFOLOG(SPDK_LOG_BDEV_MALLOC, "bdev '%s' does not exist\n", req.name);
rc = -ENODEV; spdk_jsonrpc_send_error_response(request, -ENODEV, spdk_strerror(ENODEV));
goto invalid; goto cleanup;
} }
delete_malloc_disk(bdev, _spdk_rpc_delete_malloc_bdev_cb, request); delete_malloc_disk(bdev, _spdk_rpc_delete_malloc_bdev_cb, request);
@ -163,8 +174,7 @@ spdk_rpc_delete_malloc_bdev(struct spdk_jsonrpc_request *request,
return; return;
invalid: cleanup:
free_rpc_delete_malloc(&req); free_rpc_delete_malloc(&req);
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, spdk_strerror(-rc));
} }
SPDK_RPC_REGISTER("delete_malloc_bdev", spdk_rpc_delete_malloc_bdev, SPDK_RPC_RUNTIME) SPDK_RPC_REGISTER("delete_malloc_bdev", spdk_rpc_delete_malloc_bdev, SPDK_RPC_RUNTIME)