+ if (cYAML_create_number(peer_ni, "min_tx_credits",
+ lpni_cri->cr_peer_min_tx_credits)
+ == NULL)
+ goto out;
+
+ if (cYAML_create_number(peer_ni, "tx_q_num_of_buf",
+ lpni_cri->cr_peer_tx_qnob)
+ == NULL)
+ goto out;
+
+ if (cYAML_create_number(peer_ni, "available_rtr_credits",
+ lpni_cri->cr_peer_rtr_credits)
+ == NULL)
+ goto out;
+
+ if (cYAML_create_number(peer_ni, "min_rtr_credits",
+ lpni_cri->cr_peer_min_rtr_credits)
+ == NULL)
+ goto out;
+
+ if (cYAML_create_number(peer_ni, "refcount",
+ lpni_cri->cr_refcount) == NULL)
+ goto out;
+
+ statistics = cYAML_create_object(peer_ni, "statistics");
+ if (statistics == NULL)
+ goto out;
+
+ if (cYAML_create_number(statistics, "send_count",
+ lpni_stats->iel_send_count)
+ == NULL)
+ goto out;
+
+ if (cYAML_create_number(statistics, "recv_count",
+ lpni_stats->iel_recv_count)
+ == NULL)
+ goto out;
+
+ if (cYAML_create_number(statistics, "drop_count",
+ lpni_stats->iel_drop_count)
+ == NULL)
+ goto out;
+
+ if (detail < 2)
+ continue;
+
+ for (k = 0; k < 3; k++) {
+ struct lnet_ioctl_comm_count *counts;
+
+ msg_statistics = cYAML_create_object(peer_ni,
+ (char *) gmsg_stat_names[k]);
+ if (msg_statistics == NULL)
+ goto out;
+
+ counts = get_counts(msg_stats, k);
+ if (counts == NULL)
+ goto out;
+
+ if (!add_msg_stats_to_yaml_blk(msg_statistics,
+ counts))
+ goto out;
+ }
+
+ yhstats = cYAML_create_object(peer_ni, "health stats");
+ if (!yhstats)
+ goto out;
+ if (cYAML_create_number(yhstats, "health value",
+ hstats->hlpni_health_value)
+ == NULL)
+ goto out;
+ if (cYAML_create_number(yhstats, "dropped",
+ hstats->hlpni_remote_dropped)
+ == NULL)
+ goto out;
+ if (cYAML_create_number(yhstats, "timeout",
+ hstats->hlpni_remote_timeout)
+ == NULL)
+ goto out;
+ if (cYAML_create_number(yhstats, "error",
+ hstats->hlpni_remote_error)
+ == NULL)
+ goto out;
+ if (cYAML_create_number(yhstats, "network timeout",
+ hstats->hlpni_network_timeout)
+ == 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 || !exist) {
+ 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];
+ struct lnet_process_id *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(struct lnet_process_id);
+ 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;
+
+ 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;
+ }
+ }
+
+ /* 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)
+ cYAML_print_tree(root);
+
+ snprintf(err_str, sizeof(err_str), "\"success\"");
+ 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) {
+ 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(list_root);
+ free(root);
+ } else if (show_node == NULL) {
+ cYAML_insert_sibling((*show_rc)->cy_child,
+ list_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;
+}
+
+static void add_to_global(struct cYAML *show_rc, struct cYAML *node,
+ struct cYAML *root)
+{
+ struct cYAML *show_node;
+
+ show_node = cYAML_get_object_item(show_rc, "global");
+ if (show_node != NULL)
+ cYAML_insert_sibling(show_node->cy_child,
+ node->cy_child);
+ else
+ cYAML_insert_sibling(show_rc->cy_child,
+ node);
+ free(root);
+}
+
+static int build_global_yaml_entry(char *err_str, int err_len, int seq_no,
+ char *name, __u32 value,
+ struct cYAML **show_rc,
+ struct cYAML **err_rc, int err)
+{
+ int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
+ struct cYAML *root = NULL, *global = NULL;
+
+ if (err) {
+ rc = err;
+ goto out;
+ }
+
+ 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, name,
+ value) == NULL)
+ goto out;
+
+ if (show_rc == NULL)
+ cYAML_print_tree(root);
+
+ snprintf(err_str, err_len, "\"success\"");
+
+ rc = LUSTRE_CFG_RC_NO_ERR;
+
+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;
+}
+
+static int ioctl_show_global_values(int ioc, int seq_no, char *name,
+ struct cYAML **show_rc,
+ struct cYAML **err_rc)
+{
+ struct lnet_ioctl_set_value data;
+ int rc;
+ int l_errno = 0;
+ char err_str[LNET_MAX_STR_LEN];
+
+ snprintf(err_str, sizeof(err_str), "\"out of memory\"");
+
+ LIBCFS_IOC_INIT_V2(data, sv_hdr);
+
+ rc = l_ioctl(LNET_DEV_ID, ioc, &data);
+ if (rc != 0) {
+ l_errno = -errno;
+ snprintf(err_str,
+ sizeof(err_str),
+ "\"cannot get %s: %s\"",
+ name, strerror(l_errno));
+ }
+
+ return build_global_yaml_entry(err_str, sizeof(err_str), seq_no, name,
+ data.sv_value, show_rc, err_rc, l_errno);
+}
+
+int lustre_lnet_show_recov_intrv(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];
+ int intrv = -1, l_errno = 0;
+ char err_str[LNET_MAX_STR_LEN];
+
+ snprintf(err_str, sizeof(err_str), "\"out of memory\"");
+
+ rc = read_sysfs_file(modparam_path, "lnet_recovery_interval", val,
+ 1, sizeof(val));
+ if (rc) {
+ l_errno = -errno;
+ snprintf(err_str, sizeof(err_str),
+ "\"cannot get recovery interval: %d\"", rc);
+ } else {
+ intrv = atoi(val);
+ }
+
+ return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
+ "recovery_interval", intrv, show_rc,
+ err_rc, l_errno);
+}
+
+int lustre_lnet_show_hsensitivity(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];
+ int sen = -1, l_errno = 0;
+ char err_str[LNET_MAX_STR_LEN];
+
+ snprintf(err_str, sizeof(err_str), "\"out of memory\"");
+
+ rc = read_sysfs_file(modparam_path, "lnet_health_sensitivity", val,
+ 1, sizeof(val));
+ if (rc) {
+ l_errno = -errno;
+ snprintf(err_str, sizeof(err_str),
+ "\"cannot get health sensitivity: %d\"", rc);
+ } else {
+ sen = atoi(val);
+ }
+
+ return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
+ "health_sensitivity", sen, show_rc,
+ err_rc, l_errno);
+}
+
+int lustre_lnet_show_transaction_to(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];
+ int tto = -1, l_errno = 0;
+ char err_str[LNET_MAX_STR_LEN];
+
+ snprintf(err_str, sizeof(err_str), "\"out of memory\"");
+
+ rc = read_sysfs_file(modparam_path, "lnet_transaction_timeout", val,
+ 1, sizeof(val));
+ if (rc) {
+ l_errno = -errno;
+ snprintf(err_str, sizeof(err_str),
+ "\"cannot get transaction timeout: %d\"", rc);
+ } else {
+ tto = atoi(val);
+ }
+
+ return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
+ "transaction_timeout", tto, show_rc,
+ err_rc, l_errno);
+}
+
+int lustre_lnet_show_retry_count(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];
+ int retry_count = -1, l_errno = 0;
+ char err_str[LNET_MAX_STR_LEN];
+
+ snprintf(err_str, sizeof(err_str), "\"out of memory\"");
+
+ rc = read_sysfs_file(modparam_path, "lnet_retry_count", val,
+ 1, sizeof(val));
+ if (rc) {
+ l_errno = -errno;
+ snprintf(err_str, sizeof(err_str),
+ "\"cannot get retry count: %d\"", rc);
+ } else {
+ retry_count = atoi(val);
+ }
+
+ return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
+ "retry_count", retry_count, show_rc,
+ err_rc, l_errno);
+}
+
+int show_recovery_queue(enum lnet_health_type type, char *name, int seq_no,
+ struct cYAML **show_rc, struct cYAML **err_rc)
+{
+ struct lnet_ioctl_recovery_list nid_list;
+ struct cYAML *root = NULL, *nids = NULL;
+ int rc, i;
+ char err_str[LNET_MAX_STR_LEN];
+
+ snprintf(err_str, sizeof(err_str), "failed to print recovery queue\n");