lib/cuse: provide proper error codes up to RPC

This patch adjusts several return codes to provide
more than just -1.

Along with fix to json rpc error print,
where negative error code was passed to spdk_strerror().
Resulting in unkown error being reported.

Signed-off-by: Tomasz Zawadzki <tomasz.zawadzki@intel.com>
Change-Id: I254f6d716d0ce587f88cc658163ba049378f3b2f
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/1915
Community-CI: Mellanox Build Bot
Community-CI: Broadcom CI
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
This commit is contained in:
Tomasz Zawadzki 2020-04-16 09:46:58 -04:00 committed by Jim Harris
parent 5340d17823
commit ef6ffb39d6
3 changed files with 13 additions and 11 deletions

View File

@ -695,13 +695,14 @@ cuse_nvme_ns_start(struct cuse_device *ctrlr_device, uint32_t nsid, const char *
if (rv < 0) {
SPDK_ERRLOG("Device name too long.\n");
free(ns_device);
return -1;
return -ENAMETOOLONG;
}
if (pthread_create(&ns_device->tid, NULL, cuse_thread, ns_device)) {
rv = pthread_create(&ns_device->tid, NULL, cuse_thread, ns_device);
if (rv != 0) {
SPDK_ERRLOG("pthread_create failed\n");
free(ns_device);
return -1;
return -rv;
}
TAILQ_INSERT_TAIL(&ctrlr_device->ns_devices, ns_device, tailq);
@ -806,7 +807,7 @@ nvme_cuse_start(struct spdk_nvme_ctrlr *ctrlr)
g_ctrlr_started = spdk_bit_array_create(128);
if (g_ctrlr_started == NULL) {
SPDK_ERRLOG("Cannot create bit array\n");
return -1;
return -ENOMEM;
}
}
@ -838,9 +839,10 @@ nvme_cuse_start(struct spdk_nvme_ctrlr *ctrlr)
snprintf(ctrlr_device->dev_name, sizeof(ctrlr_device->dev_name), "spdk/nvme%d",
ctrlr_device->index);
if (pthread_create(&ctrlr_device->tid, NULL, cuse_thread, ctrlr_device)) {
rv = pthread_create(&ctrlr_device->tid, NULL, cuse_thread, ctrlr_device);
if (rv != 0) {
SPDK_ERRLOG("pthread_create failed\n");
rv = -1;
rv = -rv;
goto err3;
}
TAILQ_INSERT_TAIL(&g_ctrlr_ctx_head, ctrlr_device, tailq);
@ -852,10 +854,10 @@ nvme_cuse_start(struct spdk_nvme_ctrlr *ctrlr)
continue;
}
if (cuse_nvme_ns_start(ctrlr_device, nsid, ctrlr_device->dev_name) < 0) {
rv = cuse_nvme_ns_start(ctrlr_device, nsid, ctrlr_device->dev_name);
if (rv < 0) {
SPDK_ERRLOG("Cannot start CUSE namespace device.");
cuse_nvme_ctrlr_stop(ctrlr_device);
rv = -1;
goto err3;
}
}

View File

@ -136,7 +136,7 @@ nvme_io_msg_ctrlr_register(struct spdk_nvme_ctrlr *ctrlr,
if (ctrlr->external_io_msgs_qpair == NULL) {
SPDK_ERRLOG("spdk_nvme_ctrlr_alloc_io_qpair() failed\n");
spdk_ring_free(ctrlr->external_io_msgs);
return -1;
return -ENOMEM;
}
STAILQ_INSERT_TAIL(&ctrlr->io_producers, io_msg_producer, link);

View File

@ -83,8 +83,8 @@ spdk_rpc_nvme_cuse_register(struct spdk_jsonrpc_request *request,
rc = spdk_nvme_cuse_register(bdev_ctrlr->ctrlr);
if (rc) {
SPDK_ERRLOG("Failed to register CUSE devices\n");
spdk_jsonrpc_send_error_response(request, -rc, spdk_strerror(rc));
SPDK_ERRLOG("Failed to register CUSE devices: %s\n", spdk_strerror(-rc));
spdk_jsonrpc_send_error_response(request, rc, spdk_strerror(-rc));
goto cleanup;
}