bdev/virtio: add more descriptive rpc error messages
Improve error messages where possible. Change-Id: I68b48fd448636412a2b26241c787e7b7826c9a34 Signed-off-by: Karol Latecki <karol.latecki@intel.com> Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/461873 Tested-by: SPDK CI Jenkins <sys_sgci@intel.com> Reviewed-by: Darek Stojaczyk <dariusz.stojaczyk@intel.com> Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
This commit is contained in:
parent
8f44d126b4
commit
46ebf1b1e9
@ -77,13 +77,14 @@ spdk_rpc_remove_virtio_bdev(struct spdk_jsonrpc_request *request,
|
|||||||
const struct spdk_json_val *params)
|
const struct spdk_json_val *params)
|
||||||
{
|
{
|
||||||
struct rpc_remove_virtio_dev req = {NULL};
|
struct rpc_remove_virtio_dev req = {NULL};
|
||||||
int rc;
|
int rc = 0;
|
||||||
|
|
||||||
if (spdk_json_decode_object(params, rpc_remove_virtio_dev,
|
if (spdk_json_decode_object(params, rpc_remove_virtio_dev,
|
||||||
SPDK_COUNTOF(rpc_remove_virtio_dev),
|
SPDK_COUNTOF(rpc_remove_virtio_dev),
|
||||||
&req)) {
|
&req)) {
|
||||||
rc = -EINVAL;
|
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INTERNAL_ERROR,
|
||||||
goto invalid;
|
"spdk_json_decode_object failed");
|
||||||
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
rc = bdev_virtio_blk_dev_remove(req.name, spdk_rpc_remove_virtio_bdev_cb, request);
|
rc = bdev_virtio_blk_dev_remove(req.name, spdk_rpc_remove_virtio_bdev_cb, request);
|
||||||
@ -92,16 +93,10 @@ spdk_rpc_remove_virtio_bdev(struct spdk_jsonrpc_request *request,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (rc != 0) {
|
if (rc != 0) {
|
||||||
goto invalid;
|
spdk_jsonrpc_send_error_response(request, rc, spdk_strerror(-rc));
|
||||||
}
|
}
|
||||||
|
|
||||||
free(req.name);
|
cleanup:
|
||||||
|
|
||||||
return;
|
|
||||||
|
|
||||||
invalid:
|
|
||||||
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
|
|
||||||
spdk_strerror(-rc));
|
|
||||||
free(req.name);
|
free(req.name);
|
||||||
}
|
}
|
||||||
SPDK_RPC_REGISTER("remove_virtio_bdev", spdk_rpc_remove_virtio_bdev, SPDK_RPC_RUNTIME);
|
SPDK_RPC_REGISTER("remove_virtio_bdev", spdk_rpc_remove_virtio_bdev, SPDK_RPC_RUNTIME);
|
||||||
@ -199,30 +194,30 @@ spdk_rpc_construct_virtio_dev(struct spdk_jsonrpc_request *request,
|
|||||||
req = calloc(1, sizeof(*req));
|
req = calloc(1, sizeof(*req));
|
||||||
if (!req) {
|
if (!req) {
|
||||||
SPDK_ERRLOG("calloc() failed\n");
|
SPDK_ERRLOG("calloc() failed\n");
|
||||||
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, spdk_strerror(ENOMEM));
|
spdk_jsonrpc_send_error_response(request, -ENOMEM, spdk_strerror(ENOMEM));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (spdk_json_decode_object(params, rpc_construct_virtio_dev,
|
if (spdk_json_decode_object(params, rpc_construct_virtio_dev,
|
||||||
SPDK_COUNTOF(rpc_construct_virtio_dev),
|
SPDK_COUNTOF(rpc_construct_virtio_dev),
|
||||||
req)) {
|
req)) {
|
||||||
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, spdk_strerror(EINVAL));
|
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INTERNAL_ERROR,
|
||||||
goto invalid;
|
"spdk_json_decode_object failed");
|
||||||
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strcmp(req->trtype, "pci") == 0) {
|
if (strcmp(req->trtype, "pci") == 0) {
|
||||||
if (req->vq_count != 0 || req->vq_size != 0) {
|
if (req->vq_count != 0 || req->vq_size != 0) {
|
||||||
SPDK_ERRLOG("VQ count or size is not allowed for PCI transport type\n");
|
SPDK_ERRLOG("VQ count or size is not allowed for PCI transport type\n");
|
||||||
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
|
spdk_jsonrpc_send_error_response(request, EINVAL,
|
||||||
"vq_count or vq_size is not allowed for PCI transport type.");
|
"vq_count or vq_size is not allowed for PCI transport type.");
|
||||||
goto invalid;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (spdk_pci_addr_parse(&pci_addr, req->traddr) != 0) {
|
if (spdk_pci_addr_parse(&pci_addr, req->traddr) != 0) {
|
||||||
SPDK_ERRLOG("Invalid PCI address '%s'\n", req->traddr);
|
SPDK_ERRLOG("Invalid PCI address '%s'\n", req->traddr);
|
||||||
spdk_jsonrpc_send_error_response_fmt(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
|
spdk_jsonrpc_send_error_response_fmt(request, EINVAL, "Invalid PCI address '%s'", req->traddr);
|
||||||
"Invalid PCI address '%s'", req->traddr);
|
goto cleanup;
|
||||||
goto invalid;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pci = true;
|
pci = true;
|
||||||
@ -232,9 +227,8 @@ spdk_rpc_construct_virtio_dev(struct spdk_jsonrpc_request *request,
|
|||||||
pci = false;
|
pci = false;
|
||||||
} else {
|
} else {
|
||||||
SPDK_ERRLOG("Invalid trtype '%s'\n", req->trtype);
|
SPDK_ERRLOG("Invalid trtype '%s'\n", req->trtype);
|
||||||
spdk_jsonrpc_send_error_response_fmt(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
|
spdk_jsonrpc_send_error_response_fmt(request, EINVAL, "Invalid trtype '%s'", req->trtype);
|
||||||
"Invalid trtype '%s'", req->trtype);
|
goto cleanup;
|
||||||
goto invalid;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
req->request = request;
|
req->request = request;
|
||||||
@ -262,13 +256,13 @@ spdk_rpc_construct_virtio_dev(struct spdk_jsonrpc_request *request,
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
SPDK_ERRLOG("Invalid dev_type '%s'\n", req->dev_type);
|
SPDK_ERRLOG("Invalid dev_type '%s'\n", req->dev_type);
|
||||||
spdk_jsonrpc_send_error_response_fmt(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
|
spdk_jsonrpc_send_error_response_fmt(request, EINVAL, "Invalid dev_type '%s'", req->dev_type);
|
||||||
"Invalid dev_type '%s'", req->dev_type);
|
goto cleanup;
|
||||||
goto invalid;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
invalid:
|
|
||||||
|
cleanup:
|
||||||
free_rpc_construct_virtio_dev(req);
|
free_rpc_construct_virtio_dev(req);
|
||||||
}
|
}
|
||||||
SPDK_RPC_REGISTER("construct_virtio_dev", spdk_rpc_construct_virtio_dev, SPDK_RPC_RUNTIME);
|
SPDK_RPC_REGISTER("construct_virtio_dev", spdk_rpc_construct_virtio_dev, SPDK_RPC_RUNTIME);
|
||||||
|
Loading…
Reference in New Issue
Block a user