+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);
+}
+
+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;
+ 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_interfaces_max", val,
+ 1, LNET_MAX_STR_LEN);
+ if (rc) {
+ snprintf(err_str, sizeof(err_str),
+ "\"cannot get max interfaces: %d\"", rc);
+ goto out;
+ }
+
+ max_intf = 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, "max_intf",
+ max_intf) == 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_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;
+}
+