From 3c8c4ce346edbe4d6bdf35aae3959f329a2b652d Mon Sep 17 00:00:00 2001 From: Pawel Kaminski Date: Sun, 21 Jul 2019 16:38:11 -0400 Subject: [PATCH] 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 Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/462773 Tested-by: SPDK CI Jenkins Reviewed-by: Karol Latecki Reviewed-by: Shuhei Matsumoto Reviewed-by: Darek Stojaczyk --- lib/net/interface.c | 4 ++-- lib/net/net_rpc.c | 28 ++++++++++++++++++++++++---- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/lib/net/interface.c b/lib/net/interface.c index 5102695b72..7bf01bad80 100644 --- a/lib/net/interface.c +++ b/lib/net/interface.c @@ -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. */ diff --git a/lib/net/net_rpc.c b/lib/net/net_rpc.c index d2b8e9e470..d73aa8a45b 100644 --- a/lib/net/net_rpc.c +++ b/lib/net/net_rpc.c @@ -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)