net/rpc: Add logs with more information about rpc error.

Now if rpc fails ambiguous logs are printed.
Use more descriptive errors.

Change-Id: Ia70cacd4699fb2e421334db177b9510626997378
Signed-off-by: Pawel Kaminski <pawelx.kaminski@intel.com>
Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/462773
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Karol Latecki <karol.latecki@intel.com>
Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Reviewed-by: Darek Stojaczyk <dariusz.stojaczyk@intel.com>
This commit is contained in:
Pawel Kaminski 2019-07-21 16:38:11 -04:00 committed by Darek Stojaczyk
parent 2b483475d9
commit 3c8c4ce346
2 changed files with 26 additions and 6 deletions

View File

@ -336,13 +336,13 @@ static int netlink_addr_msg(uint32_t ifc_idx, uint32_t ip_address, uint32_t crea
struct rtattr *rta;
if (spdk_interface_available(ifc_idx)) {
return -1;
return -ENODEV;
}
fd = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
if (fd < 0) {
SPDK_ERRLOG("socket failed!\n");
return -1;
return errno;
}
/* setup local address & bind using this address. */

View File

@ -63,15 +63,26 @@ spdk_rpc_add_ip_address(struct spdk_jsonrpc_request *request,
{
struct rpc_ip_address req = {};
struct spdk_json_write_ctx *w;
int ret_val = 0;
if (spdk_json_decode_object(params, rpc_ip_address_decoders,
SPDK_COUNTOF(rpc_ip_address_decoders),
&req)) {
SPDK_DEBUGLOG(SPDK_LOG_NET, "spdk_json_decode_object failed\n");
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INTERNAL_ERROR,
"spdk_json_decode_object failed");
goto invalid;
}
if (spdk_interface_add_ip_address(req.ifc_index, req.ip_address)) {
ret_val = spdk_interface_add_ip_address(req.ifc_index, req.ip_address);
if (ret_val) {
if (ret_val == -ENODEV) {
spdk_jsonrpc_send_error_response_fmt(request, SPDK_JSONRPC_ERROR_INVALID_STATE,
"Interface %d not available", req.ifc_index);
} else {
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INTERNAL_ERROR,
strerror(ret_val));
}
goto invalid;
}
@ -83,7 +94,6 @@ spdk_rpc_add_ip_address(struct spdk_jsonrpc_request *request,
return;
invalid:
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, "Invalid parameters");
free_rpc_ip_address(&req);
}
SPDK_RPC_REGISTER("add_ip_address", spdk_rpc_add_ip_address, SPDK_RPC_RUNTIME)
@ -94,15 +104,26 @@ spdk_rpc_delete_ip_address(struct spdk_jsonrpc_request *request,
{
struct rpc_ip_address req = {};
struct spdk_json_write_ctx *w;
int ret_val = 0;
if (spdk_json_decode_object(params, rpc_ip_address_decoders,
SPDK_COUNTOF(rpc_ip_address_decoders),
&req)) {
SPDK_DEBUGLOG(SPDK_LOG_NET, "spdk_json_decode_object failed\n");
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INTERNAL_ERROR,
"spdk_json_decode_object failed");
goto invalid;
}
if (spdk_interface_delete_ip_address(req.ifc_index, req.ip_address)) {
ret_val = spdk_interface_delete_ip_address(req.ifc_index, req.ip_address);
if (ret_val) {
if (ret_val == -ENODEV) {
spdk_jsonrpc_send_error_response_fmt(request, SPDK_JSONRPC_ERROR_INVALID_STATE,
"Interface %d not available", req.ifc_index);
} else {
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INTERNAL_ERROR,
strerror(ret_val));
}
goto invalid;
}
@ -114,7 +135,6 @@ spdk_rpc_delete_ip_address(struct spdk_jsonrpc_request *request,
return;
invalid:
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, "Invalid parameters");
free_rpc_ip_address(&req);
}
SPDK_RPC_REGISTER("delete_ip_address", spdk_rpc_delete_ip_address, SPDK_RPC_RUNTIME)