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)
|
||||
{
|
||||
struct rpc_remove_virtio_dev req = {NULL};
|
||||
int rc;
|
||||
int rc = 0;
|
||||
|
||||
if (spdk_json_decode_object(params, rpc_remove_virtio_dev,
|
||||
SPDK_COUNTOF(rpc_remove_virtio_dev),
|
||||
&req)) {
|
||||
rc = -EINVAL;
|
||||
goto invalid;
|
||||
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INTERNAL_ERROR,
|
||||
"spdk_json_decode_object failed");
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
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) {
|
||||
goto invalid;
|
||||
spdk_jsonrpc_send_error_response(request, rc, spdk_strerror(-rc));
|
||||
}
|
||||
|
||||
free(req.name);
|
||||
|
||||
return;
|
||||
|
||||
invalid:
|
||||
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
|
||||
spdk_strerror(-rc));
|
||||
cleanup:
|
||||
free(req.name);
|
||||
}
|
||||
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));
|
||||
if (!req) {
|
||||
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;
|
||||
}
|
||||
|
||||
if (spdk_json_decode_object(params, rpc_construct_virtio_dev,
|
||||
SPDK_COUNTOF(rpc_construct_virtio_dev),
|
||||
req)) {
|
||||
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, spdk_strerror(EINVAL));
|
||||
goto invalid;
|
||||
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INTERNAL_ERROR,
|
||||
"spdk_json_decode_object failed");
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (strcmp(req->trtype, "pci") == 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_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.");
|
||||
goto invalid;
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (spdk_pci_addr_parse(&pci_addr, req->traddr) != 0) {
|
||||
SPDK_ERRLOG("Invalid PCI address '%s'\n", req->traddr);
|
||||
spdk_jsonrpc_send_error_response_fmt(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
|
||||
"Invalid PCI address '%s'", req->traddr);
|
||||
goto invalid;
|
||||
spdk_jsonrpc_send_error_response_fmt(request, EINVAL, "Invalid PCI address '%s'", req->traddr);
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
pci = true;
|
||||
@ -232,9 +227,8 @@ spdk_rpc_construct_virtio_dev(struct spdk_jsonrpc_request *request,
|
||||
pci = false;
|
||||
} else {
|
||||
SPDK_ERRLOG("Invalid trtype '%s'\n", req->trtype);
|
||||
spdk_jsonrpc_send_error_response_fmt(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
|
||||
"Invalid trtype '%s'", req->trtype);
|
||||
goto invalid;
|
||||
spdk_jsonrpc_send_error_response_fmt(request, EINVAL, "Invalid trtype '%s'", req->trtype);
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
req->request = request;
|
||||
@ -262,13 +256,13 @@ spdk_rpc_construct_virtio_dev(struct spdk_jsonrpc_request *request,
|
||||
}
|
||||
} else {
|
||||
SPDK_ERRLOG("Invalid dev_type '%s'\n", req->dev_type);
|
||||
spdk_jsonrpc_send_error_response_fmt(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
|
||||
"Invalid dev_type '%s'", req->dev_type);
|
||||
goto invalid;
|
||||
spdk_jsonrpc_send_error_response_fmt(request, EINVAL, "Invalid dev_type '%s'", req->dev_type);
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
return;
|
||||
invalid:
|
||||
|
||||
cleanup:
|
||||
free_rpc_construct_virtio_dev(req);
|
||||
}
|
||||
SPDK_RPC_REGISTER("construct_virtio_dev", spdk_rpc_construct_virtio_dev, SPDK_RPC_RUNTIME);
|
||||
|
Loading…
Reference in New Issue
Block a user