+ cYAML_build_error(rc, seq_no, SHOW_CMD, "net", err_str, err_rc);
+
+ return rc;
+}
+
+int lustre_lnet_enable_routing(int enable, int seq_no, struct cYAML **err_rc)
+{
+ struct lnet_ioctl_config_data data;
+ int rc = LUSTRE_CFG_RC_NO_ERR;
+ char err_str[LNET_MAX_STR_LEN] = "\"success\"";
+
+ LIBCFS_IOC_INIT_V2(data, cfg_hdr);
+ data.cfg_config_u.cfg_buffers.buf_enable = (enable) ? 1 : 0;
+
+ 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));
+ goto out;
+ }
+
+out:
+ cYAML_build_error(rc, seq_no,
+ (enable) ? ADD_CMD : DEL_CMD,
+ "routing", err_str, err_rc);
+
+ return rc;
+}
+
+int ioctl_set_value(__u32 val, int ioc, char *name,
+ int seq_no, struct cYAML **err_rc)
+{
+ struct lnet_ioctl_set_value data;
+ int rc = LUSTRE_CFG_RC_NO_ERR;
+ char err_str[LNET_MAX_STR_LEN] = "\"success\"";
+
+ LIBCFS_IOC_INIT_V2(data, sv_hdr);
+ data.sv_value = val;
+
+ rc = l_ioctl(LNET_DEV_ID, ioc , &data);
+ if (rc != 0) {
+ rc = -errno;
+ snprintf(err_str,
+ sizeof(err_str),
+ "\"cannot configure %s to %d: %s\"", name,
+ val, strerror(errno));
+ }
+
+ cYAML_build_error(rc, seq_no, ADD_CMD, name, err_str, err_rc);
+
+ return rc;
+}
+
+int lustre_lnet_config_recov_intrv(int intrv, int seq_no, struct cYAML **err_rc)
+{
+ int rc = LUSTRE_CFG_RC_NO_ERR;
+ char err_str[LNET_MAX_STR_LEN] = "\"success\"";
+ char val[LNET_MAX_STR_LEN];
+
+ snprintf(val, sizeof(val), "%d", intrv);
+
+ rc = write_sysfs_file(modparam_path, "lnet_recovery_interval", val,
+ 1, strlen(val) + 1);
+ if (rc)
+ snprintf(err_str, sizeof(err_str),
+ "\"cannot configure recovery interval: %s\"",
+ strerror(errno));
+
+ cYAML_build_error(rc, seq_no, ADD_CMD, "recovery_interval", err_str, err_rc);
+
+ return rc;
+}
+
+int lustre_lnet_config_rtr_sensitivity(int sen, int seq_no, struct cYAML **err_rc)
+{
+ int rc = LUSTRE_CFG_RC_NO_ERR;
+ char err_str[LNET_MAX_STR_LEN] = "\"success\"";
+ char val[LNET_MAX_STR_LEN];
+
+ snprintf(val, sizeof(val), "%d", sen);
+
+ rc = write_sysfs_file(modparam_path, "router_sensitivity_percentage", val,
+ 1, strlen(val) + 1);
+ if (rc)
+ snprintf(err_str, sizeof(err_str),
+ "\"cannot configure router health sensitivity: %s\"",
+ strerror(errno));
+
+ cYAML_build_error(rc, seq_no, ADD_CMD, "router_sensitivity", err_str, err_rc);
+
+ return rc;
+}
+
+int lustre_lnet_config_hsensitivity(int sen, int seq_no, struct cYAML **err_rc)
+{
+ int rc = LUSTRE_CFG_RC_NO_ERR;
+ char err_str[LNET_MAX_STR_LEN] = "\"success\"";
+ char val[LNET_MAX_STR_LEN];
+
+ snprintf(val, sizeof(val), "%d", sen);
+
+ rc = write_sysfs_file(modparam_path, "lnet_health_sensitivity", val,
+ 1, strlen(val) + 1);
+ if (rc)
+ snprintf(err_str, sizeof(err_str),
+ "\"cannot configure health sensitivity: %s\"",
+ strerror(errno));
+
+ cYAML_build_error(rc, seq_no, ADD_CMD, "health_sensitivity", err_str, err_rc);
+
+ return rc;
+}
+
+int lustre_lnet_config_transaction_to(int timeout, int seq_no, struct cYAML **err_rc)
+{
+ int rc = LUSTRE_CFG_RC_NO_ERR;
+ char err_str[LNET_MAX_STR_LEN] = "\"success\"";
+ char val[LNET_MAX_STR_LEN];
+
+ snprintf(val, sizeof(val), "%d", timeout);
+
+ rc = write_sysfs_file(modparam_path, "lnet_transaction_timeout", val,
+ 1, strlen(val) + 1);
+ if (rc)
+ snprintf(err_str, sizeof(err_str),
+ "\"cannot configure transaction timeout: %s\"",
+ strerror(errno));
+
+ cYAML_build_error(rc, seq_no, ADD_CMD, "transaction_timeout", err_str, err_rc);
+
+ return rc;
+}
+
+int lustre_lnet_config_retry_count(int count, int seq_no, struct cYAML **err_rc)
+{
+ int rc = LUSTRE_CFG_RC_NO_ERR;
+ char err_str[LNET_MAX_STR_LEN] = "\"success\"";
+ char val[LNET_MAX_STR_LEN];
+
+ snprintf(val, sizeof(val), "%d", count);
+
+ rc = write_sysfs_file(modparam_path, "lnet_retry_count", val,
+ 1, strlen(val) + 1);
+ if (rc)
+ snprintf(err_str, sizeof(err_str),
+ "\"cannot configure retry count: %s\"",
+ strerror(errno));
+
+ cYAML_build_error(rc, seq_no, ADD_CMD, "retry_count", err_str, err_rc);
+
+ return rc;
+}
+
+int lustre_lnet_config_response_tracking(int val, int seq_no,
+ struct cYAML **err_rc)
+{
+ int rc = LUSTRE_CFG_RC_NO_ERR;
+ char err_str[LNET_MAX_STR_LEN];
+ char val_str[LNET_MAX_STR_LEN];
+
+ if (val < 0 || val > 3) {
+ rc = LUSTRE_CFG_RC_BAD_PARAM;
+ snprintf(err_str, sizeof(err_str),
+ "\"Valid values are: 0, 1, 2, or 3\"");
+ } else {
+ snprintf(err_str, sizeof(err_str), "\"success\"");
+
+ snprintf(val_str, sizeof(val_str), "%d", val);
+
+ rc = write_sysfs_file(modparam_path, "lnet_response_tracking",
+ val_str, 1, strlen(val_str) + 1);
+ if (rc)
+ snprintf(err_str, sizeof(err_str),
+ "\"cannot configure response tracking: %s\"",
+ strerror(errno));
+ }
+
+ cYAML_build_error(rc, seq_no, ADD_CMD, "response_tracking", err_str,
+ err_rc);
+
+ return rc;
+}
+
+int lustre_lnet_config_recovery_limit(int val, int seq_no,
+ struct cYAML **err_rc)
+{
+ int rc = LUSTRE_CFG_RC_NO_ERR;
+ char err_str[LNET_MAX_STR_LEN];
+ char val_str[LNET_MAX_STR_LEN];
+
+ if (val < 0) {
+ rc = LUSTRE_CFG_RC_BAD_PARAM;
+ snprintf(err_str, sizeof(err_str),
+ "\"Must be greater than or equal to 0\"");
+ } else {
+ snprintf(err_str, sizeof(err_str), "\"success\"");
+
+ snprintf(val_str, sizeof(val_str), "%d", val);
+
+ rc = write_sysfs_file(modparam_path, "lnet_recovery_limit",
+ val_str, 1, strlen(val_str) + 1);
+ if (rc)
+ snprintf(err_str, sizeof(err_str),
+ "\"cannot configure recovery limit: %s\"",
+ strerror(errno));
+ }
+
+ cYAML_build_error(rc, seq_no, ADD_CMD, "recovery_limit", err_str,
+ err_rc);
+
+ return rc;
+}
+
+int lustre_lnet_config_max_intf(int max, int seq_no, struct cYAML **err_rc)
+{
+ int rc = LUSTRE_CFG_RC_NO_ERR;
+ char err_str[LNET_MAX_STR_LEN] = "\"success\"";
+ char val[LNET_MAX_STR_LEN];
+
+ snprintf(val, sizeof(val), "%d", max);
+
+ rc = write_sysfs_file(modparam_path, "lnet_interfaces_max", val,
+ 1, strlen(val) + 1);
+ if (rc)
+ snprintf(err_str, sizeof(err_str),
+ "\"cannot configure max interfaces: %s\"",
+ strerror(errno));
+
+ cYAML_build_error(rc, seq_no, ADD_CMD, "max_interfaces", err_str, 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] = "\"success\"";
+ char val[LNET_MAX_STR_LEN];
+
+ 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_drop_asym_route(int drop, int seq_no,
+ struct cYAML **err_rc)
+{
+ int rc = LUSTRE_CFG_RC_NO_ERR;
+ char err_str[LNET_MAX_STR_LEN] = "\"success\"";
+ char val[LNET_MAX_STR_LEN];
+
+ snprintf(val, sizeof(val), "%u", (drop) ? 1 : 0);
+
+ rc = write_sysfs_file(modparam_path, "lnet_drop_asym_route", val,
+ 1, strlen(val) + 1);
+ if (rc)
+ snprintf(err_str, sizeof(err_str),
+ "\"cannot configure drop asym route: %s\"",
+ strerror(errno));
+
+ cYAML_build_error(rc, seq_no, ADD_CMD, "drop_asym_route",
+ err_str, err_rc);
+
+ return rc;
+
+}
+
+int lustre_lnet_config_numa_range(int range, int seq_no, struct cYAML **err_rc)
+{
+ return ioctl_set_value(range, IOC_LIBCFS_SET_NUMA_RANGE,
+ "numa_range", seq_no, err_rc);
+}
+
+int lustre_lnet_config_buffers(int tiny, int small, int large, int seq_no,
+ struct cYAML **err_rc)
+{
+ struct lnet_ioctl_config_data data;
+ int rc = LUSTRE_CFG_RC_NO_ERR;
+ char err_str[LNET_MAX_STR_LEN] = "\"success\"";
+
+ /* -1 indicates to ignore changes to this field */
+ if (tiny < -1 || small < -1 || large < -1) {
+ snprintf(err_str,
+ sizeof(err_str),
+ "\"tiny, small and large must be >= 0\"");
+ rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM;
+ goto out;
+ }
+
+ LIBCFS_IOC_INIT_V2(data, cfg_hdr);
+ data.cfg_config_u.cfg_buffers.buf_tiny = tiny;
+ data.cfg_config_u.cfg_buffers.buf_small = small;
+ data.cfg_config_u.cfg_buffers.buf_large = large;
+
+ 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));
+ goto out;
+ }
+
+out:
+ cYAML_build_error(rc, seq_no, ADD_CMD, "buf", err_str, err_rc);
+
+ return rc;
+}
+
+int lustre_lnet_show_routing(int seq_no, struct cYAML **show_rc,
+ struct cYAML **err_rc, bool backup)
+{
+ 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"};
+ int buf_count[LNET_NRBPOOLS] = {0};
+ struct cYAML *root = NULL, *pools_node = NULL,
+ *type_node = NULL, *item = NULL, *cpt = NULL,
+ *first_seq = NULL, *buffers = NULL;
+ int i, j;
+ char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
+ char node_name[LNET_MAX_STR_LEN];
+ bool exist = false;
+
+ buf = calloc(1, sizeof(*data) + sizeof(*pool_cfg));
+ if (buf == NULL)
+ goto out;
+
+ data = (struct lnet_ioctl_config_data *)buf;
+
+ root = cYAML_create_object(NULL, NULL);
+ if (root == NULL)
+ goto out;
+
+ if (backup)
+ pools_node = cYAML_create_object(root, "routing");
+ else
+ pools_node = cYAML_create_seq(root, "routing");
+ if (pools_node == NULL)
+ goto out;
+
+ for (i = 0;; i++) {
+ LIBCFS_IOC_INIT_V2(*data, cfg_hdr);
+ data->cfg_hdr.ioc_len = sizeof(struct lnet_ioctl_config_data) +
+ sizeof(struct lnet_ioctl_pool_cfg);
+ data->cfg_count = i;
+
+ rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_BUF, data);
+ if (rc != 0) {
+ l_errno = errno;
+ break;
+ }
+
+ exist = true;
+
+ pool_cfg = (struct lnet_ioctl_pool_cfg *)data->cfg_bulk;
+
+ if (backup)
+ goto calculate_buffers;
+
+ snprintf(node_name, sizeof(node_name), "cpt[%d]", i);
+ item = cYAML_create_seq_item(pools_node);
+ if (item == NULL)
+ goto out;
+
+ if (first_seq == NULL)
+ first_seq = item;
+
+ cpt = cYAML_create_object(item, node_name);
+ if (cpt == NULL)
+ goto out;
+
+calculate_buffers:
+ /* create the tree and print */
+ for (j = 0; j < LNET_NRBPOOLS; j++) {
+ if (!backup) {
+ type_node = cYAML_create_object(cpt, pools[j]);
+ if (type_node == NULL)
+ goto out;
+ }
+ if (!backup &&
+ cYAML_create_number(type_node, "npages",
+ pool_cfg->pl_pools[j].pl_npages)
+ == NULL)
+ goto out;
+ if (!backup &&
+ cYAML_create_number(type_node, "nbuffers",
+ pool_cfg->pl_pools[j].
+ pl_nbuffers) == NULL)
+ goto out;
+ if (!backup &&
+ cYAML_create_number(type_node, "credits",
+ pool_cfg->pl_pools[j].
+ pl_credits) == NULL)
+ goto out;
+ if (!backup &&
+ cYAML_create_number(type_node, "mincredits",
+ pool_cfg->pl_pools[j].
+ pl_mincredits) == NULL)
+ goto out;
+ /* keep track of the total count for each of the
+ * tiny, small and large buffers */
+ buf_count[j] += pool_cfg->pl_pools[j].pl_nbuffers;
+ }
+ }
+
+ if (pool_cfg != NULL) {
+ if (backup) {
+ if (cYAML_create_number(pools_node, "enable",
+ pool_cfg->pl_routing) ==
+ NULL)
+ goto out;
+
+ goto add_buffer_section;
+ }
+
+ item = cYAML_create_seq_item(pools_node);
+ if (item == NULL)
+ goto out;
+
+ if (cYAML_create_number(item, "enable", pool_cfg->pl_routing) ==
+ NULL)
+ goto out;
+ }
+
+add_buffer_section:
+ /* create a buffers entry in the show. This is necessary so that
+ * if the YAML output is used to configure a node, the buffer
+ * configuration takes hold */
+ buffers = cYAML_create_object(root, "buffers");
+ if (buffers == NULL)
+ goto out;
+
+ for (i = 0; i < LNET_NRBPOOLS; i++) {
+ if (cYAML_create_number(buffers, pools[i], buf_count[i]) == NULL)
+ goto out;
+ }
+
+ if (show_rc == NULL)
+ cYAML_print_tree(root);
+
+ if (l_errno != ENOENT) {
+ snprintf(err_str,
+ sizeof(err_str),
+ "\"cannot get routing information: %s\"",
+ strerror(l_errno));
+ rc = -l_errno;
+ goto out;
+ } else
+ rc = LUSTRE_CFG_RC_NO_ERR;
+
+ snprintf(err_str, sizeof(err_str), "\"success\"");
+ rc = LUSTRE_CFG_RC_NO_ERR;
+
+out:
+ free(buf);
+ 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 *routing_node;
+ /* there should exist only one routing block and one
+ * buffers block. If there already exists a previous one
+ * then don't add another */
+ routing_node = cYAML_get_object_item(*show_rc, "routing");
+ if (routing_node == NULL) {
+ cYAML_insert_sibling((*show_rc)->cy_child,
+ root->cy_child);
+ free(root);
+ } else {
+ cYAML_free_tree(root);
+ }
+ } else {
+ *show_rc = root;
+ }
+
+ cYAML_build_error(rc, seq_no, SHOW_CMD, "routing", err_str, err_rc);
+
+ return rc;
+}
+
+int lustre_lnet_show_peer(char *knid, int detail, int seq_no,
+ struct cYAML **show_rc, struct cYAML **err_rc,
+ bool backup)
+{
+ /*
+ * TODO: This function is changing in a future patch to accommodate
+ * PEER_LIST and proper filtering on any nid of the peer
+ */
+ struct lnet_ioctl_peer_cfg peer_info;
+ struct lnet_peer_ni_credit_info *lpni_cri;
+ struct lnet_ioctl_element_stats *lpni_stats;
+ struct lnet_ioctl_element_msg_stats *msg_stats;
+ struct lnet_ioctl_peer_ni_hstats *hstats;
+ struct lnet_ioctl_construct_udsp_info udsp_info;
+ lnet_nid_t *nidp;
+ int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
+ int i, j, k;
+ 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,
+ *msg_statistics = NULL, *statistics = NULL,
+ *yhstats;
+ char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
+ struct lnet_process_id *list = NULL;
+ void *data = NULL;
+ void *lpni_data;
+ bool exist = false;
+
+ /* create struct cYAML root object */
+ root = cYAML_create_object(NULL, NULL);
+ if (root == NULL)
+ goto out;
+
+ peer_root = cYAML_create_seq(root, "peer");
+ if (peer_root == NULL)
+ goto out;
+
+ count = 1000;
+ size = count * sizeof(struct lnet_process_id);
+ 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_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;
+ }
+ }
+ }
+
+ 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;
+ }
+ }
+ exist = true;
+
+ peer = cYAML_create_seq_item(peer_root);
+ if (peer == NULL)
+ goto out;
+
+ if (first_seq == NULL)
+ first_seq = 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;
+ /*
+ * print out the state of the peer only if details are
+ * requested
+ */
+ if (detail >= 3) {
+ if (!backup &&
+ cYAML_create_number(peer, "peer state",
+ peer_info.prcfg_state)
+ == NULL)
+ goto out;
+ }
+
+ tmp = cYAML_create_seq(peer, "peer ni");
+ if (tmp == NULL)
+ goto out;
+
+ 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);
+ msg_stats = (void *)lpni_stats + sizeof(*lpni_stats);
+ hstats = (void *)msg_stats + sizeof(*msg_stats);
+ lpni_data = (void *)hstats + sizeof(*hstats);
+
+ peer_ni = cYAML_create_seq_item(tmp);
+ if (peer_ni == NULL)
+ goto out;
+
+ if (cYAML_create_string(peer_ni, "nid",
+ libcfs_nid2str(*nidp))
+ == NULL)
+ goto out;
+
+ if (backup)
+ continue;
+
+ if (detail < 4)
+ goto continue_without_udsp_info;
+
+ LIBCFS_IOC_INIT_V2(udsp_info, cud_hdr);
+ udsp_info.cud_nid = *nidp;
+ udsp_info.cud_peer = true;
+ rc = l_ioctl(LNET_DEV_ID,
+ IOC_LIBCFS_GET_CONST_UDSP_INFO,
+ &udsp_info);
+ if (rc != 0) {
+ l_errno = errno;
+ goto continue_without_udsp_info;
+ }
+
+ rc = create_remote_udsp_info(&udsp_info, peer_ni);
+ if (rc) {
+ l_errno = errno;
+ goto out;
+ }
+
+continue_without_udsp_info:
+ if (cYAML_create_string(peer_ni, "state",
+ lpni_cri->cr_aliveness)
+ == NULL)
+ goto out;
+
+ if (!detail)
+ continue;
+
+ if (cYAML_create_number(peer_ni, "max_ni_tx_credits",
+ lpni_cri->cr_ni_peer_tx_credits)
+ == NULL)
+ goto out;
+
+ if (cYAML_create_number(peer_ni, "available_tx_credits",
+ lpni_cri->cr_peer_tx_credits)
+ == NULL)
+ goto out;
+
+ 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;
+ if (cYAML_create_number(yhstats, "ping_count",
+ hstats->hlpni_ping_count)
+ == NULL)
+ goto out;
+
+ if (cYAML_create_number(yhstats, "next_ping",
+ hstats->hlpni_next_ping)
+ == 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] = "\"out of memory\"";
+ struct lnet_process_id *list = NULL;
+
+ 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, __u64 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] = "\"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] = "\"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] = "\"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_rtr_sensitivity(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] = "\"out of memory\"";
+
+ rc = read_sysfs_file(modparam_path, "router_sensitivity_percentage", val,
+ 1, sizeof(val));
+ if (rc) {
+ l_errno = -errno;
+ snprintf(err_str, sizeof(err_str),
+ "\"cannot get router sensitivity percentage: %d\"", rc);
+ } else {
+ sen = atoi(val);
+ }
+
+ return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
+ "router_sensitivity", sen, show_rc,
+ err_rc, l_errno);
+}
+
+int lustre_lnet_show_lnd_timeout(int seq_no, struct cYAML **show_rc,
+ struct cYAML **err_rc)
+{
+ char val[LNET_MAX_STR_LEN];
+ char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
+ int lnd_to = -1;
+ int l_errno = 0;
+ int rc;
+ int fd;
+ glob_t path;
+
+ rc = cfs_get_param_paths(&path, "lnet_lnd_timeout");
+ if (rc < 0) {
+ l_errno = -errno;
+ snprintf(err_str, sizeof(err_str),
+ "\"cannot get LND timeout: %d\"", rc);
+ return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
+ "lnd_timeout", lnd_to, show_rc,
+ err_rc, l_errno);
+ }
+
+ fd = open(path.gl_pathv[0], O_RDONLY);
+ if (fd < 0) {
+ l_errno = -errno;
+ snprintf(err_str, sizeof(err_str),
+ "\"error opening %s\"", path.gl_pathv[0]);
+ goto failed;
+ }
+
+ rc = read(fd, val, sizeof(val));
+ if (rc < 0)
+ l_errno = -errno;
+
+ close(fd);
+
+ if (rc < 0) {
+ snprintf(err_str, sizeof(err_str),
+ "\"error reading %s\"", path.gl_pathv[0]);
+ goto failed;
+ }
+
+ lnd_to = atoi(val);
+
+failed:
+ cfs_free_param_data(&path);
+
+ return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
+ "lnd_timeout", lnd_to, 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] = "\"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] = "\"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 lustre_lnet_calc_service_id(__u64 *service_id)
+{
+ int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
+ char val[LNET_MAX_STR_LEN];
+ int service_port = -1, l_errno = 0;
+
+ rc = read_sysfs_file(o2ib_modparam_path, "service", val,
+ 1, sizeof(val));
+ if (rc) {
+ l_errno = errno;
+ fprintf(stderr, "error:\n msg: \"cannot get service port: %s (%d)\"\n",
+ strerror(l_errno), -l_errno);
+ return rc;
+ } else {
+ service_port = atoi(val);
+ }
+
+ *service_id = htobe64(((__u64)RDMA_PS_TCP << 16) + service_port);
+
+ return LUSTRE_CFG_RC_NO_ERR;
+}
+
+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] = "failed to print recovery queue\n";
+
+ LIBCFS_IOC_INIT_V2(nid_list, rlst_hdr);
+ nid_list.rlst_type = type;
+
+ rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_RECOVERY_QUEUE, &nid_list);
+ if (rc) {
+ rc = errno;
+ goto out;
+ }
+
+ if (nid_list.rlst_num_nids == 0)
+ goto out;
+
+ root = cYAML_create_object(NULL, NULL);
+ if (root == NULL)
+ goto out;
+
+ nids = cYAML_create_object(root, name);
+ if (nids == NULL)
+ goto out;
+
+ rc = -EINVAL;
+
+ for (i = 0; i < nid_list.rlst_num_nids; i++) {
+ char nidenum[LNET_MAX_STR_LEN];
+ snprintf(nidenum, sizeof(nidenum), "nid-%d", i);
+ if (!cYAML_create_string(nids, nidenum,
+ libcfs_nid2str(nid_list.rlst_nid_array[i])))
+ goto out;
+ }
+
+ snprintf(err_str, sizeof(err_str), "success\n");
+
+ rc = 0;
+
+out:
+ 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 net node, if one doesn't exist
+ * then insert one. Otherwise add to the one there
+ */
+ show_node = cYAML_get_object_item(*show_rc, name);
+ if (show_node != NULL && cYAML_is_sequence(show_node)) {
+ cYAML_insert_child(show_node, nids);
+ free(nids);
+ free(root);
+ } else if (show_node == NULL) {
+ cYAML_insert_sibling((*show_rc)->cy_child,
+ nids);
+ free(root);
+ } else {
+ cYAML_free_tree(root);
+ }
+ } else {
+ *show_rc = root;
+ }
+
+ cYAML_build_error(rc, seq_no, SHOW_CMD, name, err_str, err_rc);
+
+ return rc;
+}
+
+int lustre_lnet_show_local_ni_recovq(int seq_no, struct cYAML **show_rc,
+ struct cYAML **err_rc)
+{
+ return show_recovery_queue(LNET_HEALTH_TYPE_LOCAL_NI, "local NI recovery",
+ seq_no, show_rc, err_rc);
+}
+
+int lustre_lnet_show_peer_ni_recovq(int seq_no, struct cYAML **show_rc,
+ struct cYAML **err_rc)
+{
+ return show_recovery_queue(LNET_HEALTH_TYPE_PEER_NI, "peer NI recovery",
+ seq_no, show_rc, err_rc);
+}
+
+int lustre_lnet_show_response_tracking(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 rsp_tracking = -1, l_errno = 0;
+ char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
+
+ rc = read_sysfs_file(modparam_path, "lnet_response_tracking", val,
+ 1, sizeof(val));
+ if (rc) {
+ l_errno = -errno;
+ snprintf(err_str, sizeof(err_str),
+ "\"cannot get lnet_response_tracking value: %d\"", rc);
+ } else {
+ rsp_tracking = atoi(val);
+ }
+
+ return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
+ "response_tracking", rsp_tracking,
+ show_rc, err_rc, l_errno);
+}
+
+int lustre_lnet_show_recovery_limit(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 recov_limit = -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_limit", val,
+ 1, sizeof(val));
+ if (rc) {
+ l_errno = -errno;
+ snprintf(err_str, sizeof(err_str),
+ "\"cannot get lnet_recovery_limit value: %d\"", rc);
+ } else {
+ recov_limit = atoi(val);
+ }
+
+ return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
+ "recovery_limit", recov_limit,
+ show_rc, err_rc, l_errno);
+}
+
+int lustre_lnet_show_max_intf(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 max_intf = -1, l_errno = 0;
+ char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
+
+ rc = read_sysfs_file(modparam_path, "lnet_interfaces_max", val,
+ 1, sizeof(val));
+ if (rc) {
+ l_errno = -errno;
+ snprintf(err_str, sizeof(err_str),
+ "\"cannot get max interfaces: %d\"", rc);
+ } else {
+ max_intf = atoi(val);
+ }
+
+ return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
+ "max_interfaces", max_intf, show_rc,
+ err_rc, l_errno);
+}
+
+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];
+ int discovery = -1, l_errno = 0;
+ char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
+
+ rc = read_sysfs_file(modparam_path, "lnet_peer_discovery_disabled", val,
+ 1, sizeof(val));
+ if (rc) {
+ l_errno = -errno;
+ snprintf(err_str, sizeof(err_str),
+ "\"cannot get discovery setting: %d\"", rc);
+ } else {
+ /*
+ * The kernel stores a discovery disabled value. User space
+ * shows whether discovery is enabled. So the value must be
+ * inverted.
+ */
+ discovery = !atoi(val);
+ }
+
+ return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
+ "discovery", discovery, show_rc,
+ err_rc, l_errno);
+}
+
+int lustre_lnet_show_drop_asym_route(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 drop_asym_route = -1, l_errno = 0;
+ char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
+
+ rc = read_sysfs_file(modparam_path, "lnet_drop_asym_route", val,
+ 1, sizeof(val));
+ if (rc) {
+ l_errno = -errno;
+ snprintf(err_str, sizeof(err_str),
+ "\"cannot get drop asym route setting: %d\"", rc);
+ } else {
+ drop_asym_route = atoi(val);
+ }
+
+ return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
+ "drop_asym_route", drop_asym_route,
+ show_rc, err_rc, l_errno);
+}
+
+int lustre_lnet_show_numa_range(int seq_no, struct cYAML **show_rc,
+ struct cYAML **err_rc)
+{
+ return ioctl_show_global_values(IOC_LIBCFS_GET_NUMA_RANGE, seq_no,
+ "numa_range", show_rc, err_rc);
+}
+
+int lustre_lnet_show_stats(int seq_no, struct cYAML **show_rc,
+ struct cYAML **err_rc)
+{
+ struct lnet_ioctl_lnet_stats data;
+ struct lnet_counters *cntrs;
+ int rc;
+ int l_errno;
+ char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
+ struct cYAML *root = NULL, *stats = NULL;
+
+ LIBCFS_IOC_INIT_V2(data, st_hdr);
+
+ rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_LNET_STATS, &data);
+ if (rc) {
+ l_errno = errno;
+ snprintf(err_str,
+ sizeof(err_str),
+ "\"cannot get lnet statistics: %s\"",
+ strerror(l_errno));
+ rc = -l_errno;
+ goto out;
+ }
+
+ rc = LUSTRE_CFG_RC_OUT_OF_MEM;
+
+ cntrs = &data.st_cntrs;
+
+ root = cYAML_create_object(NULL, NULL);
+ if (!root)
+ goto out;
+
+ stats = cYAML_create_object(root, "statistics");
+ if (!stats)
+ goto out;
+
+ if (!cYAML_create_number(stats, "msgs_alloc",
+ cntrs->lct_common.lcc_msgs_alloc))
+ goto out;
+
+ if (!cYAML_create_number(stats, "msgs_max",
+ cntrs->lct_common.lcc_msgs_max))
+ goto out;
+
+ if (!cYAML_create_number(stats, "rst_alloc",
+ cntrs->lct_health.lch_rst_alloc))
+ goto out;
+
+ if (!cYAML_create_number(stats, "errors",
+ cntrs->lct_common.lcc_errors))
+ goto out;
+
+ if (!cYAML_create_number(stats, "send_count",
+ cntrs->lct_common.lcc_send_count))
+ goto out;
+
+ if (!cYAML_create_number(stats, "resend_count",
+ cntrs->lct_health.lch_resend_count))
+ goto out;
+
+ if (!cYAML_create_number(stats, "response_timeout_count",
+ cntrs->lct_health.lch_response_timeout_count))
+ goto out;
+
+ if (!cYAML_create_number(stats, "local_interrupt_count",
+ cntrs->lct_health.lch_local_interrupt_count))
+ goto out;
+
+ if (!cYAML_create_number(stats, "local_dropped_count",
+ cntrs->lct_health.lch_local_dropped_count))
+ goto out;
+
+ if (!cYAML_create_number(stats, "local_aborted_count",
+ cntrs->lct_health.lch_local_aborted_count))
+ goto out;
+
+ if (!cYAML_create_number(stats, "local_no_route_count",
+ cntrs->lct_health.lch_local_no_route_count))
+ goto out;
+
+ if (!cYAML_create_number(stats, "local_timeout_count",
+ cntrs->lct_health.lch_local_timeout_count))
+ goto out;
+
+ if (!cYAML_create_number(stats, "local_error_count",
+ cntrs->lct_health.lch_local_error_count))
+ goto out;
+
+ if (!cYAML_create_number(stats, "remote_dropped_count",
+ cntrs->lct_health.lch_remote_dropped_count))
+ goto out;
+
+ if (!cYAML_create_number(stats, "remote_error_count",
+ cntrs->lct_health.lch_remote_error_count))
+ goto out;
+
+ if (!cYAML_create_number(stats, "remote_timeout_count",
+ cntrs->lct_health.lch_remote_timeout_count))
+ goto out;
+
+ if (!cYAML_create_number(stats, "network_timeout_count",
+ cntrs->lct_health.lch_network_timeout_count))
+ goto out;
+
+ if (!cYAML_create_number(stats, "recv_count",
+ cntrs->lct_common.lcc_recv_count))
+ goto out;
+
+ if (!cYAML_create_number(stats, "route_count",
+ cntrs->lct_common.lcc_route_count))
+ goto out;
+
+ if (!cYAML_create_number(stats, "drop_count",
+ cntrs->lct_common.lcc_drop_count))
+ goto out;
+
+ if (!cYAML_create_number(stats, "send_length",
+ cntrs->lct_common.lcc_send_length))
+ goto out;
+
+ if (!cYAML_create_number(stats, "recv_length",
+ cntrs->lct_common.lcc_recv_length))
+ goto out;
+
+ if (!cYAML_create_number(stats, "route_length",
+ cntrs->lct_common.lcc_route_length))
+ goto out;
+
+ if (!cYAML_create_number(stats, "drop_length",
+ cntrs->lct_common.lcc_drop_length))
+ goto out;
+
+ if (!show_rc)
+ cYAML_print_tree(root);
+
+ snprintf(err_str, sizeof(err_str), "\"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) {
+ cYAML_insert_sibling((*show_rc)->cy_child,
+ root->cy_child);
+ free(root);
+ } else {
+ *show_rc = root;
+ }
+
+ cYAML_build_error(rc, seq_no, SHOW_CMD, "statistics", err_str, err_rc);
+
+ return rc;
+}
+
+typedef int (*cmd_handler_t)(struct cYAML *tree,
+ struct cYAML **show_rc,
+ struct cYAML **err_rc);
+
+static int handle_yaml_config_route(struct cYAML *tree, struct cYAML **show_rc,
+ struct cYAML **err_rc)
+{
+ struct cYAML *net, *gw, *hop, *prio, *sen, *seq_no;
+
+ net = cYAML_get_object_item(tree, "net");
+ gw = cYAML_get_object_item(tree, "gateway");
+ hop = cYAML_get_object_item(tree, "hop");
+ prio = cYAML_get_object_item(tree, "priority");
+ sen = cYAML_get_object_item(tree, "health_sensitivity");
+ seq_no = cYAML_get_object_item(tree, "seq_no");
+
+ return lustre_lnet_config_route((net) ? net->cy_valuestring : NULL,
+ (gw) ? gw->cy_valuestring : NULL,
+ (hop) ? hop->cy_valueint : -1,
+ (prio) ? prio->cy_valueint : -1,
+ (sen) ? sen->cy_valueint : -1,
+ (seq_no) ? seq_no->cy_valueint : -1,
+ err_rc);
+}
+
+/*
+ * interfaces:
+ * 0: <intf_name>['['<expr>']']
+ * 1: <intf_name>['['<expr>']']
+ */
+static int yaml_copy_intf_info(struct cYAML *intf_tree,
+ struct lnet_dlc_network_descr *nw_descr)
+{
+ struct cYAML *child = NULL;
+ int intf_num = 0, rc = LUSTRE_CFG_RC_NO_ERR;
+ struct lnet_dlc_intf_descr *intf_descr, *tmp;
+
+ if (intf_tree == NULL || nw_descr == NULL)
+ return LUSTRE_CFG_RC_BAD_PARAM;
+
+ /* now grab all the interfaces and their cpts */
+ child = intf_tree->cy_child;
+ while (child != NULL) {
+ if (child->cy_valuestring == NULL) {
+ child = child->cy_next;
+ continue;
+ }
+
+ if (strlen(child->cy_valuestring) >= LNET_MAX_STR_LEN)
+ goto failed;
+
+ rc = lustre_lnet_add_intf_descr(&nw_descr->nw_intflist,
+ child->cy_valuestring,
+ strlen(child->cy_valuestring));
+ if (rc != LUSTRE_CFG_RC_NO_ERR)
+ goto failed;
+
+ intf_num++;
+ child = child->cy_next;
+ }
+
+ if (intf_num == 0)
+ return LUSTRE_CFG_RC_MISSING_PARAM;
+
+ return intf_num;
+
+failed:
+ list_for_each_entry_safe(intf_descr, tmp, &nw_descr->nw_intflist,
+ intf_on_network) {
+ list_del(&intf_descr->intf_on_network);
+ free_intf_descr(intf_descr);
+ }
+
+ return rc;
+}
+
+static bool
+yaml_extract_cmn_tunables(struct cYAML *tree,
+ struct lnet_ioctl_config_lnd_cmn_tunables *tunables,
+ struct cfs_expr_list **global_cpts)
+{
+ struct cYAML *tun, *item, *smp;
+ int rc;
+
+ tun = cYAML_get_object_item(tree, "tunables");
+ if (tun != NULL) {
+ item = cYAML_get_object_item(tun, "peer_timeout");
+ if (item != NULL)
+ tunables->lct_peer_timeout = item->cy_valueint;
+ item = cYAML_get_object_item(tun, "peer_credits");
+ if (item != NULL)
+ tunables->lct_peer_tx_credits = item->cy_valueint;
+ item = cYAML_get_object_item(tun, "peer_buffer_credits");
+ if (item != NULL)
+ tunables->lct_peer_rtr_credits = item->cy_valueint;
+ item = cYAML_get_object_item(tun, "credits");
+ if (item != NULL)
+ tunables->lct_max_tx_credits = item->cy_valueint;
+ smp = cYAML_get_object_item(tun, "CPT");
+ if (smp != NULL) {
+ rc = cfs_expr_list_parse(smp->cy_valuestring,
+ strlen(smp->cy_valuestring),
+ 0, UINT_MAX, global_cpts);
+ if (rc != 0)
+ *global_cpts = NULL;
+ }
+
+ return true;
+ }
+
+ return false;
+}
+
+static bool
+yaml_extract_tunables(struct cYAML *tree,
+ struct lnet_ioctl_config_lnd_tunables *tunables,
+ struct cfs_expr_list **global_cpts,
+ __u32 net_type)
+{
+ bool rc;
+
+ rc = yaml_extract_cmn_tunables(tree, &tunables->lt_cmn,
+ global_cpts);
+
+ if (!rc)
+ return rc;
+
+ lustre_yaml_extract_lnd_tunables(tree, net_type,
+ &tunables->lt_tun);
+
+ return rc;
+}
+
+/*
+ * net:
+ * - net type: <net>[<NUM>]
+ * local NI(s):
+ * - nid: <ip>@<net>[<NUM>]
+ * status: up
+ * interfaces:
+ * 0: <intf_name>['['<expr>']']
+ * 1: <intf_name>['['<expr>']']
+ * tunables:
+ * peer_timeout: <NUM>
+ * peer_credits: <NUM>
+ * peer_buffer_credits: <NUM>
+ * credits: <NUM>
+* lnd tunables:
+ * peercredits_hiw: <NUM>
+ * map_on_demand: <NUM>
+ * concurrent_sends: <NUM>
+ * fmr_pool_size: <NUM>
+ * fmr_flush_trigger: <NUM>
+ * fmr_cache: <NUM>
+ *
+ * At least one interface is required. If no interfaces are provided the
+ * network interface can not be configured.
+ */
+static int handle_yaml_config_ni(struct cYAML *tree, struct cYAML **show_rc,
+ struct cYAML **err_rc)
+{
+ struct cYAML *net, *intf, *seq_no, *ip2net = NULL, *local_nis = NULL,
+ *item = NULL;
+ int num_entries = 0, rc;
+ struct lnet_dlc_network_descr nw_descr;
+ struct cfs_expr_list *global_cpts = NULL;
+ struct lnet_ioctl_config_lnd_tunables tunables;
+ bool found = false;
+
+ memset(&tunables, 0, sizeof(tunables));
+
+ INIT_LIST_HEAD(&nw_descr.network_on_rule);
+ INIT_LIST_HEAD(&nw_descr.nw_intflist);
+
+ ip2net = cYAML_get_object_item(tree, "ip2net");
+ net = cYAML_get_object_item(tree, "net type");
+ if (net)
+ nw_descr.nw_id = libcfs_str2net(net->cy_valuestring);
+ else
+ nw_descr.nw_id = LOLND;
+
+ /*
+ * if neither net nor ip2nets are present, then we can not
+ * configure the network.
+ */
+ if (!net && !ip2net)
+ return LUSTRE_CFG_RC_MISSING_PARAM;
+
+ local_nis = cYAML_get_object_item(tree, "local NI(s)");
+ if (local_nis == NULL)
+ return LUSTRE_CFG_RC_MISSING_PARAM;
+
+ if (!cYAML_is_sequence(local_nis))
+ return LUSTRE_CFG_RC_BAD_PARAM;
+
+ while (cYAML_get_next_seq_item(local_nis, &item) != NULL) {
+ intf = cYAML_get_object_item(item, "interfaces");
+ if (intf == NULL)
+ continue;
+ num_entries = yaml_copy_intf_info(intf, &nw_descr);
+ if (num_entries <= 0) {
+ cYAML_build_error(num_entries, -1, "ni", "add",
+ "bad interface list",
+ err_rc);
+ return LUSTRE_CFG_RC_BAD_PARAM;
+ }
+ }
+
+ found = yaml_extract_tunables(tree, &tunables, &global_cpts,
+ LNET_NETTYP(nw_descr.nw_id));
+ seq_no = cYAML_get_object_item(tree, "seq_no");
+
+ rc = lustre_lnet_config_ni(&nw_descr,
+ global_cpts,
+ (ip2net) ? ip2net->cy_valuestring : NULL,
+ (found) ? &tunables: NULL,
+ (seq_no) ? seq_no->cy_valueint : -1,
+ err_rc);
+
+ if (global_cpts != NULL)
+ cfs_expr_list_free(global_cpts);
+
+ return rc;
+}
+
+/*
+ * ip2nets:
+ * - net-spec: <tcp|o2ib|gni>[NUM]
+ * interfaces:
+ * 0: <intf name>['['<expr>']']
+ * 1: <intf name>['['<expr>']']
+ * ip-range:
+ * 0: <expr.expr.expr.expr>
+ * 1: <expr.expr.expr.expr>
+ */
+static int handle_yaml_config_ip2nets(struct cYAML *tree,
+ struct cYAML **show_rc,
+ struct cYAML **err_rc)
+{
+ struct cYAML *net, *ip_range, *item = NULL, *intf = NULL,
+ *seq_no = NULL;
+ struct lustre_lnet_ip2nets ip2nets;
+ struct lustre_lnet_ip_range_descr *ip_range_descr = NULL,
+ *tmp = NULL;
+ int rc = LUSTRE_CFG_RC_NO_ERR;
+ struct cfs_expr_list *global_cpts = NULL;
+ struct cfs_expr_list *el, *el_tmp;
+ struct lnet_ioctl_config_lnd_tunables tunables;
+ struct lnet_dlc_intf_descr *intf_descr, *intf_tmp;
+ bool found = false;
+
+ memset(&tunables, 0, sizeof(tunables));
+
+ /* initialize all lists */
+ INIT_LIST_HEAD(&ip2nets.ip2nets_ip_ranges);
+ INIT_LIST_HEAD(&ip2nets.ip2nets_net.network_on_rule);
+ INIT_LIST_HEAD(&ip2nets.ip2nets_net.nw_intflist);