X-Git-Url: https://git.whamcloud.com/?a=blobdiff_plain;f=lnet%2Futils%2Flnetconfig%2Fliblnetconfig.c;h=46c00f0cfe0d00c002f48fe62bd2155a28b26572;hb=53cc2a1fe6befcd51826a9b42e8dff9cc33ee8a3;hp=f96db1b11c1c44bcf4427a35043465337a2d0986;hpb=0f753ead66cb0bd924ccb656f1a742a0db46038d;p=fs%2Flustre-release.git diff --git a/lnet/utils/lnetconfig/liblnetconfig.c b/lnet/utils/lnetconfig/liblnetconfig.c index f96db1b..46c00f0 100644 --- a/lnet/utils/lnetconfig/liblnetconfig.c +++ b/lnet/utils/lnetconfig/liblnetconfig.c @@ -18,7 +18,7 @@ * * LGPL HEADER END * - * Copyright (c) 2013, Intel Corporation. + * Copyright (c) 2014, Intel Corporation. * * Author: * Amir Shehata @@ -264,6 +264,7 @@ int lustre_lnet_show_route(char *nw, char *gw, int hops, int prio, int detail, struct cYAML *root = NULL, *route = NULL, *item = NULL; struct cYAML *first_seq = NULL; char err_str[LNET_MAX_STR_LEN]; + bool exist = false; snprintf(err_str, sizeof(err_str), "\"out of memory\""); @@ -352,6 +353,7 @@ int lustre_lnet_show_route(char *nw, char *gw, int hops, int prio, int detail, /* default rc to -1 incase we hit the goto */ rc = -1; + exist = true; item = cYAML_create_seq_item(route); if (item == NULL) @@ -404,7 +406,7 @@ int lustre_lnet_show_route(char *nw, char *gw, int hops, int prio, int detail, snprintf(err_str, sizeof(err_str), "\"success\""); out: - if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR) { + if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR || !exist) { cYAML_free_tree(root); } else if (show_rc != NULL && *show_rc != NULL) { struct cYAML *show_node; @@ -558,8 +560,9 @@ int lustre_lnet_show_net(char *nw, int detail, int seq_no, *item = NULL, *first_seq = NULL; int str_buf_len = LNET_MAX_SHOW_NUM_CPT * 2; char str_buf[str_buf_len]; - char *pos = str_buf; + char *pos; char err_str[LNET_MAX_STR_LEN]; + bool exist = false; snprintf(err_str, sizeof(err_str), "\"out of memory\""); @@ -589,6 +592,10 @@ int lustre_lnet_show_net(char *nw, int detail, int seq_no, goto out; for (i = 0;; i++) { + pos = str_buf; + + memset(buf, 0, sizeof(*data) + sizeof(*net_config)); + LIBCFS_IOC_INIT_V2(*data, cfg_hdr); /* * set the ioc_len to the proper value since INIT assumes @@ -609,6 +616,7 @@ int lustre_lnet_show_net(char *nw, int detail, int seq_no, /* default rc to -1 in case we hit the goto */ rc = -1; + exist = true; net_config = (struct lnet_ioctl_net_config *)data->cfg_bulk; @@ -621,7 +629,13 @@ int lustre_lnet_show_net(char *nw, int detail, int seq_no, first_seq = item; if (cYAML_create_string(item, - "nid", + "net", + libcfs_net2str( + LNET_NIDNET(data->cfg_nid))) + == NULL) + goto out; + + if (cYAML_create_string(item, "nid", libcfs_nid2str(data->cfg_nid)) == NULL) goto out; @@ -653,6 +667,8 @@ int lustre_lnet_show_net(char *nw, int detail, int seq_no, } if (detail) { + char *limit; + tunables = cYAML_create_object(item, "tunables"); if (tunables == NULL) goto out; @@ -678,15 +694,21 @@ int lustre_lnet_show_net(char *nw, int detail, int seq_no, net_max_tx_credits) == NULL) goto out; + /* out put the CPTs in the format: "[x,x,x,...]" */ + limit = str_buf + str_buf_len - 3; + pos += snprintf(pos, limit - pos, "\"["); for (j = 0 ; data->cfg_ncpts > 1 && - j < data->cfg_ncpts; j++) { - pos += snprintf(str_buf, - str_buf + str_buf_len - pos, - " %d", net_config->ni_cpts[j]); + j < data->cfg_ncpts && + pos < limit; j++) { + pos += snprintf(pos, limit - pos, + "%d", net_config->ni_cpts[j]); + if ((j + 1) < data->cfg_ncpts) + pos += snprintf(pos, limit - pos, ","); } + pos += snprintf(pos, 3, "]\""); if (data->cfg_ncpts > 1 && - cYAML_create_string(tunables, "CPTs", + cYAML_create_string(tunables, "CPT", str_buf) == NULL) goto out; } @@ -708,7 +730,7 @@ int lustre_lnet_show_net(char *nw, int detail, int seq_no, snprintf(err_str, sizeof(err_str), "\"success\""); out: - if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR) { + if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR || !exist) { cYAML_free_tree(root); } else if (show_rc != NULL && *show_rc != NULL) { struct cYAML *show_node; @@ -814,9 +836,10 @@ int lustre_lnet_show_routing(int seq_no, struct cYAML **show_rc, struct cYAML *root = NULL, *pools_node = NULL, *type_node = NULL, *item = NULL, *cpt = NULL, *first_seq = NULL; - int i; + int i, j; char err_str[LNET_MAX_STR_LEN]; char node_name[LNET_MAX_STR_LEN]; + bool exist = false; snprintf(err_str, sizeof(err_str), "\"out of memory\""); @@ -844,6 +867,8 @@ int lustre_lnet_show_routing(int seq_no, struct cYAML **show_rc, if (rc != 0) break; + exist = true; + pool_cfg = (struct lnet_ioctl_pool_cfg *)data->cfg_bulk; snprintf(node_name, sizeof(node_name), "cpt[%d]", i); @@ -859,24 +884,24 @@ int lustre_lnet_show_routing(int seq_no, struct cYAML **show_rc, goto out; /* create the tree and print */ - for (i = 0; i < LNET_NRBPOOLS; i++) { - type_node = cYAML_create_object(cpt, pools[i]); + for (j = 0; j < LNET_NRBPOOLS; j++) { + type_node = cYAML_create_object(cpt, pools[j]); if (type_node == NULL) goto out; if (cYAML_create_number(type_node, "npages", - pool_cfg->pl_pools[i].pl_npages) + pool_cfg->pl_pools[j].pl_npages) == NULL) goto out; if (cYAML_create_number(type_node, "nbuffers", - pool_cfg->pl_pools[i]. + pool_cfg->pl_pools[j]. pl_nbuffers) == NULL) goto out; if (cYAML_create_number(type_node, "credits", - pool_cfg->pl_pools[i]. + pool_cfg->pl_pools[j]. pl_credits) == NULL) goto out; if (cYAML_create_number(type_node, "mincredits", - pool_cfg->pl_pools[i]. + pool_cfg->pl_pools[j]. pl_mincredits) == NULL) goto out; } @@ -910,7 +935,7 @@ int lustre_lnet_show_routing(int seq_no, struct cYAML **show_rc, out: free(buf); - if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR) { + if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR || !exist) { cYAML_free_tree(root); } else if (show_rc != NULL && *show_rc != NULL) { struct cYAML *show_node; @@ -957,8 +982,8 @@ int lustre_lnet_show_peer_credits(int seq_no, struct cYAML **show_rc, goto out; peer_root = cYAML_create_seq(root, "peer"); - if (peer_root == NULL) - goto out; + if (peer_root == NULL) + goto out; do { for (i = 0;; i++) { @@ -1243,7 +1268,7 @@ static int handle_yaml_config_net(struct cYAML *tree, struct cYAML **show_rc, peer_buf_cr = cYAML_get_object_item(tunables, "peer_buffer_credits"); credits = cYAML_get_object_item(tunables, "credits"); - smp = cYAML_get_object_item(tunables, "SMP"); + smp = cYAML_get_object_item(tunables, "CPT"); } seq_no = cYAML_get_object_item(tree, "seq_no"); @@ -1493,32 +1518,13 @@ static int lustre_yaml_cb_helper(char *f, struct lookup_cmd_hdlr_tbl *table, while ((head = cYAML_get_next_seq_item(child, &item)) != NULL) { rc = cb(head, show_rc, err_rc); - /* if processing fails or no cb is found - * then fail */ - if (rc != LUSTRE_CFG_RC_NO_ERR) { - snprintf(err_str, sizeof(err_str), - "\"Failed to process request: " - "'%s' [%d, %p]\"", - head->cy_string, rc, cb); - cYAML_build_error( - LUSTRE_CFG_RC_BAD_PARAM, -1, - "yaml", "helper", err_str, - err_rc); + if (rc != LUSTRE_CFG_RC_NO_ERR) return_rc = rc; - } } } else { rc = cb(child, show_rc, err_rc); - /* if processing fails or no cb is found then fail */ - if (rc != LUSTRE_CFG_RC_NO_ERR) { - snprintf(err_str, sizeof(err_str), - "\"Failed to process request: '%s'" - " [%d, %p]\"", - child->cy_string, rc, cb); - cYAML_build_error(LUSTRE_CFG_RC_BAD_PARAM, -1, - "yaml", "helper", err_str, err_rc); + if (rc != LUSTRE_CFG_RC_NO_ERR) return_rc = rc; - } } item = NULL; child = child->cy_next;