From: Amir Shehata Date: Tue, 28 Jul 2015 22:55:05 +0000 (-0700) Subject: LU-6090 lnet: save errno between function calls X-Git-Tag: 2.7.58~12 X-Git-Url: https://git.whamcloud.com/?p=fs%2Flustre-release.git;a=commitdiff_plain;h=f6c886e36d0729b0791e393386e0b4b9c571ce30 LU-6090 lnet: save errno between function calls errno can be overwritten by functions like snprintf even if it succeeded, so save the errno when needed. Signed-off-by: Amir Shehata Change-Id: I9a47267851f7c102727f8653a3a3727047f33186 Reviewed-on: http://review.whamcloud.com/15783 Tested-by: Jenkins Reviewed-by: John L. Hammond Tested-by: Maloo Reviewed-by: Dmitry Eremin Reviewed-by: Oleg Drokin --- diff --git a/lnet/utils/lnetconfig/liblnetconfig.c b/lnet/utils/lnetconfig/liblnetconfig.c index 7923ccb..33083e2 100644 --- a/lnet/utils/lnetconfig/liblnetconfig.c +++ b/lnet/utils/lnetconfig/liblnetconfig.c @@ -78,7 +78,6 @@ int lustre_lnet_config_ni_system(bool up, bool load_ni_from_mod, opc = up ? IOC_LIBCFS_CONFIGURE : IOC_LIBCFS_UNCONFIGURE; rc = l_ioctl(LNET_DEV_ID, opc, &data); - if (rc != 0) { snprintf(err_str, sizeof(err_str), @@ -174,10 +173,10 @@ int lustre_lnet_config_route(char *nw, char *gw, int hops, int prio, rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_ADD_ROUTE, &data); if (rc != 0) { + rc = -errno; snprintf(err_str, sizeof(err_str), "\"cannot add route: %s\"", strerror(errno)); - rc = -errno; goto out; } @@ -243,10 +242,10 @@ int lustre_lnet_del_route(char *nw, char *gw, rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_DEL_ROUTE, &data); if (rc != 0) { + rc = -errno; snprintf(err_str, sizeof(err_str), "\"cannot delete route: %s\"", strerror(errno)); - rc = -errno; goto out; } @@ -263,6 +262,7 @@ int lustre_lnet_show_route(char *nw, char *gw, int hops, int prio, int detail, struct lnet_ioctl_config_data data; lnet_nid_t gateway_nid; int rc = LUSTRE_CFG_RC_OUT_OF_MEM; + int l_errno = 0; __u32 net = LNET_NIDNET(LNET_NID_ANY); int i; struct cYAML *root = NULL, *route = NULL, *item = NULL; @@ -335,8 +335,10 @@ int lustre_lnet_show_route(char *nw, char *gw, int hops, int prio, int detail, data.cfg_count = i; rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_ROUTE, &data); - if (rc != 0) + if (rc != 0) { + l_errno = errno; break; + } /* filter on provided data */ if (net != LNET_NIDNET(LNET_NID_ANY) && @@ -398,12 +400,12 @@ int lustre_lnet_show_route(char *nw, char *gw, int hops, int prio, int detail, if (show_rc == NULL) cYAML_print_tree(root); - if (errno != ENOENT) { + if (l_errno != ENOENT) { snprintf(err_str, sizeof(err_str), "\"cannot get routes: %s\"", - strerror(errno)); - rc = -errno; + strerror(l_errno)); + rc = -l_errno; goto out; } else rc = LUSTRE_CFG_RC_NO_ERR; @@ -445,7 +447,7 @@ int lustre_lnet_config_net(char *net, char *intf, char *ip2net, { struct lnet_ioctl_config_data data; char buf[LNET_MAX_STR_LEN]; - int rc = LUSTRE_CFG_RC_NO_ERR, num_of_nets = 0; + int rc = LUSTRE_CFG_RC_NO_ERR; char err_str[LNET_MAX_STR_LEN]; snprintf(err_str, sizeof(err_str), "\"success\""); @@ -492,17 +494,16 @@ int lustre_lnet_config_net(char *net, char *intf, char *ip2net, data.cfg_config_u.cfg_net.net_peer_rtr_credits = peer_buf_cr; data.cfg_config_u.cfg_net.net_max_tx_credits = credits; - num_of_nets = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_ADD_NET, &data); - if (num_of_nets < 0) { + rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_ADD_NET, &data); + if (rc < 0) { + rc = -errno; snprintf(err_str, sizeof(err_str), "\"cannot add network: %s\"", strerror(errno)); - rc = -errno; } out: - cYAML_build_error((num_of_nets > 0) ? num_of_nets : rc, - seq_no, ADD_CMD, "net", err_str, err_rc); + cYAML_build_error(rc, seq_no, ADD_CMD, "net", err_str, err_rc); return rc; } @@ -538,10 +539,10 @@ int lustre_lnet_del_net(char *nw, int seq_no, struct cYAML **err_rc) rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_DEL_NET, &data); if (rc != 0) { + rc = -errno; snprintf(err_str, sizeof(err_str), "\"cannot delete network: %s\"", strerror(errno)); - rc = -errno; goto out; } @@ -559,6 +560,7 @@ int lustre_lnet_show_net(char *nw, int detail, int seq_no, struct lnet_ioctl_net_config *net_config; __u32 net = LNET_NIDNET(LNET_NID_ANY); int rc = LUSTRE_CFG_RC_OUT_OF_MEM, i, j; + int l_errno = 0; struct cYAML *root = NULL, *tunables = NULL, *net_node = NULL, *interfaces = NULL, *item = NULL, *first_seq = NULL; @@ -610,8 +612,10 @@ int lustre_lnet_show_net(char *nw, int detail, int seq_no, data->cfg_count = i; rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_NET, data); - if (rc != 0) + if (rc != 0) { + l_errno = errno; break; + } /* filter on provided data */ if (net != LNET_NIDNET(LNET_NID_ANY) && @@ -722,12 +726,12 @@ int lustre_lnet_show_net(char *nw, int detail, int seq_no, if (show_rc == NULL) cYAML_print_tree(root); - if (errno != ENOENT) { + if (l_errno != ENOENT) { snprintf(err_str, sizeof(err_str), "\"cannot get networks: %s\"", - strerror(errno)); - rc = -errno; + strerror(l_errno)); + rc = -l_errno; goto out; } else rc = LUSTRE_CFG_RC_NO_ERR; @@ -775,11 +779,11 @@ int lustre_lnet_enable_routing(int enable, int seq_no, struct cYAML **err_rc) rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_CONFIG_RTR, &data); if (rc != 0) { + rc = -errno; snprintf(err_str, sizeof(err_str), "\"cannot %s routing %s\"", (enable) ? "enable" : "disable", strerror(errno)); - rc = -errno; goto out; } @@ -816,10 +820,10 @@ int lustre_lnet_config_buffers(int tiny, int small, int large, int seq_no, rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_ADD_BUF, &data); if (rc != 0) { + rc = -errno; snprintf(err_str, sizeof(err_str), "\"cannot configure buffers: %s\"", strerror(errno)); - rc = -errno; goto out; } @@ -835,6 +839,7 @@ int lustre_lnet_show_routing(int seq_no, struct cYAML **show_rc, struct lnet_ioctl_config_data *data; struct lnet_ioctl_pool_cfg *pool_cfg = NULL; int rc = LUSTRE_CFG_RC_OUT_OF_MEM; + int l_errno = 0; char *buf; char *pools[LNET_NRBPOOLS] = {"tiny", "small", "large"}; struct cYAML *root = NULL, *pools_node = NULL, @@ -868,8 +873,10 @@ int lustre_lnet_show_routing(int seq_no, struct cYAML **show_rc, data->cfg_count = i; rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_BUF, data); - if (rc != 0) + if (rc != 0) { + l_errno = errno; break; + } exist = true; @@ -924,12 +931,12 @@ int lustre_lnet_show_routing(int seq_no, struct cYAML **show_rc, if (show_rc == NULL) cYAML_print_tree(root); - if (errno != ENOENT) { + if (l_errno != ENOENT) { snprintf(err_str, sizeof(err_str), "\"cannot get routing information: %s\"", - strerror(errno)); - rc = -errno; + strerror(l_errno)); + rc = -l_errno; goto out; } else rc = LUSTRE_CFG_RC_NO_ERR; @@ -972,6 +979,7 @@ int lustre_lnet_show_peer_credits(int seq_no, struct cYAML **show_rc, { struct lnet_ioctl_peer peer_info; int rc = LUSTRE_CFG_RC_OUT_OF_MEM, ncpt = 0, i = 0, j = 0; + int l_errno = 0; struct cYAML *root = NULL, *peer = NULL, *first_seq = NULL, *peer_root = NULL; char err_str[LNET_MAX_STR_LEN]; @@ -996,8 +1004,10 @@ int lustre_lnet_show_peer_credits(int seq_no, struct cYAML **show_rc, peer_info.pr_lnd_u.pr_peer_credits.cr_ncpt = j; rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_PEER_INFO, &peer_info); - if (rc != 0) + if (rc != 0) { + l_errno = errno; break; + } if (ncpt_set != 0) { ncpt = peer_info.pr_lnd_u.pr_peer_credits. @@ -1066,12 +1076,12 @@ int lustre_lnet_show_peer_credits(int seq_no, struct cYAML **show_rc, goto out; } - if (errno != ENOENT) { + if (l_errno != ENOENT) { snprintf(err_str, sizeof(err_str), "\"cannot get peer information: %s\"", - strerror(errno)); - rc = -errno; + strerror(l_errno)); + rc = -l_errno; goto out; } @@ -1121,6 +1131,7 @@ int lustre_lnet_show_stats(int seq_no, struct cYAML **show_rc, { struct lnet_ioctl_lnet_stats data; int rc = LUSTRE_CFG_RC_OUT_OF_MEM; + int l_errno; char err_str[LNET_MAX_STR_LEN]; struct cYAML *root = NULL, *stats = NULL; @@ -1130,11 +1141,12 @@ int lustre_lnet_show_stats(int seq_no, struct cYAML **show_rc, rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_LNET_STATS, &data); if (rc != 0) { + l_errno = errno; snprintf(err_str, sizeof(err_str), "\"cannot get lnet statistics: %s\"", - strerror(errno)); - rc = -errno; + strerror(l_errno)); + rc = -l_errno; goto out; }