X-Git-Url: https://git.whamcloud.com/?a=blobdiff_plain;f=lnet%2Futils%2Flnetconfig%2Fliblnetconfig.c;h=bb35de5565ce75cdadfaa400df583a85e3399a69;hb=dd0f5728b26bc343dd39f8d4d5eec628410a7dc6;hp=c182e6c96748f465f533ce7f5c413a992536fc8f;hpb=00e73d22f04f440ac81281f584445e258269f654;p=fs%2Flustre-release.git diff --git a/lnet/utils/lnetconfig/liblnetconfig.c b/lnet/utils/lnetconfig/liblnetconfig.c index c182e6c..bb35de5 100644 --- a/lnet/utils/lnetconfig/liblnetconfig.c +++ b/lnet/utils/lnetconfig/liblnetconfig.c @@ -1859,6 +1859,29 @@ int lustre_lnet_config_max_intf(int max, int seq_no, struct cYAML **err_rc) return rc; } +int lustre_lnet_config_discovery(int enable, int seq_no, struct cYAML **err_rc) +{ + int rc = LUSTRE_CFG_RC_NO_ERR; + char err_str[LNET_MAX_STR_LEN]; + char val[LNET_MAX_STR_LEN]; + + snprintf(err_str, sizeof(err_str), "\"success\""); + + snprintf(val, sizeof(val), "%u", (enable) ? 0 : 1); + + rc = write_sysfs_file(modparam_path, "lnet_peer_discovery_disabled", val, + 1, strlen(val) + 1); + if (rc) + snprintf(err_str, sizeof(err_str), + "\"cannot configure discovery: %s\"", + strerror(errno)); + + cYAML_build_error(rc, seq_no, ADD_CMD, "discovery", err_str, err_rc); + + return rc; + +} + int lustre_lnet_config_numa_range(int range, int seq_no, struct cYAML **err_rc) { struct lnet_ioctl_set_value data; @@ -2094,22 +2117,23 @@ int lustre_lnet_show_peer(char *knid, int detail, int seq_no, struct lnet_ioctl_peer_cfg peer_info; struct lnet_peer_ni_credit_info *lpni_cri; struct lnet_ioctl_element_stats *lpni_stats; - int rc = LUSTRE_CFG_RC_OUT_OF_MEM, ncpt = 0, i = 0, j = 0; + lnet_nid_t *nidp; + int rc = LUSTRE_CFG_RC_OUT_OF_MEM; + int i; + int j; int l_errno = 0; + __u32 count; + __u32 size; struct cYAML *root = NULL, *peer = NULL, *peer_ni = NULL, *first_seq = NULL, *peer_root = NULL, *tmp = NULL; char err_str[LNET_MAX_STR_LEN]; - lnet_nid_t prev_primary_nid = LNET_NID_ANY, primary_nid = LNET_NID_ANY; - int data_size = sizeof(*lpni_cri) + sizeof(*lpni_stats); - char *data = malloc(data_size); - bool new_peer = true; + lnet_process_id_t *list = NULL; + void *data = NULL; + void *lpni_data; snprintf(err_str, sizeof(err_str), "\"out of memory\""); - if (data == NULL) - goto out; - /* create struct cYAML root object */ root = cYAML_create_object(NULL, NULL); if (root == NULL) @@ -2119,69 +2143,121 @@ int lustre_lnet_show_peer(char *knid, int detail, int seq_no, if (peer_root == NULL) goto out; - if (knid != NULL) - primary_nid = libcfs_str2nid(knid); - - do { - for (i = 0;; i++) { - memset(data, 0, data_size); + count = 1000; + size = count * sizeof(lnet_process_id_t); + list = malloc(size); + if (list == NULL) { + l_errno = ENOMEM; + goto out; + } + if (knid != NULL) { + list[0].nid = libcfs_str2nid(knid); + count = 1; + } else { + for (;;) { memset(&peer_info, 0, sizeof(peer_info)); LIBCFS_IOC_INIT_V2(peer_info, prcfg_hdr); peer_info.prcfg_hdr.ioc_len = sizeof(peer_info); - peer_info.prcfg_count = i; - peer_info.prcfg_bulk = (void *)data; - peer_info.prcfg_size = data_size; - - rc = l_ioctl(LNET_DEV_ID, - IOC_LIBCFS_GET_PEER_NI, &peer_info); - if (rc != 0) { - l_errno = errno; + peer_info.prcfg_size = size; + peer_info.prcfg_bulk = list; + + l_errno = 0; + rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_PEER_LIST, + &peer_info); + count = peer_info.prcfg_count; + if (rc == 0) break; + l_errno = errno; + if (l_errno != E2BIG) { + snprintf(err_str, + sizeof(err_str), + "\"cannot get peer list: %s\"", + strerror(l_errno)); + rc = -l_errno; + goto out; } + free(list); + size = peer_info.prcfg_size; + list = malloc(size); + if (list == NULL) { + l_errno = ENOMEM; + goto out; + } + } + } - if (primary_nid != LNET_NID_ANY && - primary_nid != peer_info.prcfg_prim_nid) - continue; + size = 4096; + data = malloc(size); + if (data == NULL) { + l_errno = ENOMEM; + goto out; + } + for (i = 0; i < count; i++) { + for (;;) { + memset(&peer_info, 0, sizeof(peer_info)); + LIBCFS_IOC_INIT_V2(peer_info, prcfg_hdr); + peer_info.prcfg_hdr.ioc_len = sizeof(peer_info); + peer_info.prcfg_prim_nid = list[i].nid; + peer_info.prcfg_size = size; + peer_info.prcfg_bulk = data; + + l_errno = 0; + rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_PEER_NI, + &peer_info); + if (rc == 0) + break; + l_errno = errno; + if (l_errno != E2BIG) { + snprintf(err_str, + sizeof(err_str), + "\"cannot get peer information: %s\"", + strerror(l_errno)); + rc = -l_errno; + goto out; + } + free(data); + size = peer_info.prcfg_size; + data = malloc(size); + if (data == NULL) { + l_errno = ENOMEM; + goto out; + } + } - lpni_cri = peer_info.prcfg_bulk; - lpni_stats = peer_info.prcfg_bulk + sizeof(*lpni_cri); + peer = cYAML_create_seq_item(peer_root); + if (peer == NULL) + goto out; - peer = cYAML_create_seq_item(peer_root); - if (peer == NULL) - goto out; + if (first_seq == NULL) + first_seq = peer; - if (peer_info.prcfg_prim_nid != prev_primary_nid) { - prev_primary_nid = peer_info.prcfg_prim_nid; - new_peer = true; - } + lnet_nid_t pnid = peer_info.prcfg_prim_nid; + if (cYAML_create_string(peer, "primary nid", + libcfs_nid2str(pnid)) + == NULL) + goto out; + if (cYAML_create_string(peer, "Multi-Rail", + peer_info.prcfg_mr ? "True" : "False") + == NULL) + goto out; - if (new_peer) { - lnet_nid_t pnid = peer_info.prcfg_prim_nid; - if (cYAML_create_string(peer, "primary nid", - libcfs_nid2str(pnid)) - == NULL) - goto out; - if (cYAML_create_string(peer, "Multi-Rail", - peer_info.prcfg_mr ? - "True" : "False") - == NULL) - goto out; - tmp = cYAML_create_seq(peer, "peer ni"); - if (tmp == NULL) - goto out; - new_peer = false; - } + tmp = cYAML_create_seq(peer, "peer ni"); + if (tmp == NULL) + goto out; - if (first_seq == NULL) - first_seq = peer; + lpni_data = data; + for (j = 0; j < peer_info.prcfg_count; j++) { + nidp = lpni_data; + lpni_cri = (void*)nidp + sizeof(nidp); + lpni_stats = (void *)lpni_cri + sizeof(*lpni_cri); + lpni_data = (void *)lpni_stats + sizeof(*lpni_stats); peer_ni = cYAML_create_seq_item(tmp); if (peer_ni == NULL) goto out; if (cYAML_create_string(peer_ni, "nid", - libcfs_nid2str - (peer_info.prcfg_cfg_nid)) + libcfs_nid2str(*nidp)) == NULL) goto out; @@ -2242,18 +2318,118 @@ int lustre_lnet_show_peer(char *knid, int detail, int seq_no, lpni_cri->cr_refcount) == NULL) goto out; } + } + + /* print output iff show_rc is not provided */ + if (show_rc == NULL) + cYAML_print_tree(root); + + snprintf(err_str, sizeof(err_str), "\"success\""); + rc = LUSTRE_CFG_RC_NO_ERR; + +out: + free(list); + free(data); + if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR) { + cYAML_free_tree(root); + } else if (show_rc != NULL && *show_rc != NULL) { + struct cYAML *show_node; + /* find the peer node, if one doesn't exist then + * insert one. Otherwise add to the one there + */ + show_node = cYAML_get_object_item(*show_rc, + "peer"); + if (show_node != NULL && cYAML_is_sequence(show_node)) { + cYAML_insert_child(show_node, first_seq); + free(peer_root); + free(root); + } else if (show_node == NULL) { + cYAML_insert_sibling((*show_rc)->cy_child, + peer_root); + free(root); + } else { + cYAML_free_tree(root); + } + } else { + *show_rc = root; + } + + cYAML_build_error(rc, seq_no, SHOW_CMD, "peer", err_str, + err_rc); + + return rc; +} + +int lustre_lnet_list_peer(int seq_no, + struct cYAML **show_rc, struct cYAML **err_rc) +{ + struct lnet_ioctl_peer_cfg peer_info; + int rc = LUSTRE_CFG_RC_OUT_OF_MEM; + __u32 count; + __u32 size; + int i = 0; + int l_errno = 0; + struct cYAML *root = NULL, *list_root = NULL, *first_seq = NULL; + char err_str[LNET_MAX_STR_LEN]; + lnet_process_id_t *list = NULL; + + snprintf(err_str, sizeof(err_str), + "\"out of memory\""); + + memset(&peer_info, 0, sizeof(peer_info)); + + /* create struct cYAML root object */ + root = cYAML_create_object(NULL, NULL); + if (root == NULL) + goto out; + + list_root = cYAML_create_seq(root, "peer list"); + if (list_root == NULL) + goto out; + + count = 1000; + size = count * sizeof(lnet_process_id_t); + list = malloc(size); + if (list == NULL) { + l_errno = ENOMEM; + goto out; + } + for (;;) { + LIBCFS_IOC_INIT_V2(peer_info, prcfg_hdr); + peer_info.prcfg_hdr.ioc_len = sizeof(peer_info); + peer_info.prcfg_size = size; + peer_info.prcfg_bulk = list; - if (l_errno != ENOENT) { + l_errno = 0; + rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_PEER_LIST, &peer_info); + count = peer_info.prcfg_count; + if (rc == 0) + break; + l_errno = errno; + if (l_errno != E2BIG) { snprintf(err_str, sizeof(err_str), - "\"cannot get peer information: %s\"", + "\"cannot get peer list: %s\"", strerror(l_errno)); rc = -l_errno; goto out; } + free(list); + size = peer_info.prcfg_size; + list = malloc(size); + if (list == NULL) { + l_errno = ENOMEM; + goto out; + } + } - j++; - } while (j < ncpt); + /* count is now the actual number of ids in the list. */ + for (i = 0; i < count; i++) { + if (cYAML_create_string(list_root, "nid", + libcfs_nid2str(list[i].nid)) + == NULL) + goto out; + } /* print output iff show_rc is not provided */ if (show_rc == NULL) @@ -2263,6 +2439,8 @@ int lustre_lnet_show_peer(char *knid, int detail, int seq_no, rc = LUSTRE_CFG_RC_NO_ERR; out: + if (list != NULL) + free(list); if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR) { cYAML_free_tree(root); } else if (show_rc != NULL && *show_rc != NULL) { @@ -2274,11 +2452,11 @@ out: "peer"); if (show_node != NULL && cYAML_is_sequence(show_node)) { cYAML_insert_child(show_node, first_seq); - free(peer_root); + free(list_root); free(root); } else if (show_node == NULL) { cYAML_insert_sibling((*show_rc)->cy_child, - peer_root); + list_root); free(root); } else { cYAML_free_tree(root); @@ -2358,6 +2536,61 @@ out: return rc; } +int lustre_lnet_show_discovery(int seq_no, struct cYAML **show_rc, + struct cYAML **err_rc) +{ + int rc = LUSTRE_CFG_RC_OUT_OF_MEM; + char val[LNET_MAX_STR_LEN]; + __u32 discovery; + char err_str[LNET_MAX_STR_LEN]; + struct cYAML *root = NULL, *global = NULL; + + snprintf(err_str, sizeof(err_str), "\"out of memory\""); + + rc = read_sysfs_file(modparam_path, "lnet_peer_discovery_disabled", val, + 1, sizeof(val)); + if (rc) { + snprintf(err_str, sizeof(err_str), + "\"cannot get discovery value: %d\"", rc); + goto out; + } + + /* + * the sysfs parameter read indicates if discovery is disabled, + * but we report if discovery is enabled. + */ + discovery = !atoi(val); + + root = cYAML_create_object(NULL, NULL); + if (root == NULL) + goto out; + + global = cYAML_create_object(root, "global"); + if (global == NULL) + goto out; + + if (cYAML_create_number(global, "discovery", + discovery) == NULL) + goto out; + + if (show_rc == NULL) + cYAML_print_tree(root); + + snprintf(err_str, sizeof(err_str), "\"success\""); +out: + if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR) { + cYAML_free_tree(root); + } else if (show_rc != NULL && *show_rc != NULL) { + add_to_global(*show_rc, global, root); + } else { + *show_rc = root; + } + + cYAML_build_error(rc, seq_no, SHOW_CMD, "global", err_str, err_rc); + + return rc; +} + int lustre_lnet_show_numa_range(int seq_no, struct cYAML **show_rc, struct cYAML **err_rc) { @@ -3178,7 +3411,7 @@ static int handle_yaml_config_global_settings(struct cYAML *tree, struct cYAML **show_rc, struct cYAML **err_rc) { - struct cYAML *max_intf, *numa, *seq_no; + struct cYAML *max_intf, *numa, *discovery, *seq_no; int rc = 0; seq_no = cYAML_get_object_item(tree, "seq_no"); @@ -3196,6 +3429,13 @@ static int handle_yaml_config_global_settings(struct cYAML *tree, : -1, err_rc); + discovery = cYAML_get_object_item(tree, "discovery"); + if (discovery) + rc = lustre_lnet_config_discovery(discovery->cy_valueint, + seq_no ? seq_no->cy_valueint + : -1, + err_rc); + return rc; } @@ -3203,7 +3443,7 @@ static int handle_yaml_del_global_settings(struct cYAML *tree, struct cYAML **show_rc, struct cYAML **err_rc) { - struct cYAML *max_intf, *numa, *seq_no; + struct cYAML *max_intf, *numa, *discovery, *seq_no; int rc = 0; seq_no = cYAML_get_object_item(tree, "seq_no"); @@ -3221,6 +3461,14 @@ static int handle_yaml_del_global_settings(struct cYAML *tree, : -1, err_rc); + /* peer discovery is enabled by default */ + discovery = cYAML_get_object_item(tree, "discovery"); + if (discovery) + rc = lustre_lnet_config_discovery(1, + seq_no ? seq_no->cy_valueint + : -1, + err_rc); + return rc; } @@ -3228,7 +3476,7 @@ static int handle_yaml_show_global_settings(struct cYAML *tree, struct cYAML **show_rc, struct cYAML **err_rc) { - struct cYAML *max_intf, *numa, *seq_no; + struct cYAML *max_intf, *numa, *discovery, *seq_no; int rc = 0; seq_no = cYAML_get_object_item(tree, "seq_no"); @@ -3244,6 +3492,12 @@ static int handle_yaml_show_global_settings(struct cYAML *tree, : -1, show_rc, err_rc); + discovery = cYAML_get_object_item(tree, "discovery"); + if (discovery) + rc = lustre_lnet_show_discovery(seq_no ? seq_no->cy_valueint + : -1, + show_rc, err_rc); + return rc; }