libcfs_nid2str(ping.ping_id.nid)) == NULL)
goto out;
- if (cYAML_create_string(item, "Multi-Rail", ping.mr_info ? "True" :
- "False") == NULL)
+ if (cYAML_create_string(item, "Multi-Rail", ping.mr_info ?
+ "True" : "False") == NULL)
goto out;
tmp = cYAML_create_seq(item, "peer ni");
return rc;
}
+int lustre_lnet_discover_nid(char *ping_nids, int force, int seq_no,
+ struct cYAML **show_rc, struct cYAML **err_rc)
+{
+ int rc;
+
+ rc = infra_ping_nid(ping_nids, "discover", force, IOC_LIBCFS_DISCOVER,
+ seq_no, show_rc, err_rc);
+ return rc;
+}
+
int lustre_lnet_config_peer_nid(char *pnid, char **nid, int num_nids,
bool mr, int seq_no, struct cYAML **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];
+
+ snprintf(err_str, sizeof(err_str), "\"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_max_intf(int max, int seq_no, struct cYAML **err_rc)
{
int rc = LUSTRE_CFG_RC_NO_ERR;
int lustre_lnet_config_numa_range(int range, 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];
-
- snprintf(err_str, sizeof(err_str), "\"success\"");
-
- if (range < 0) {
- snprintf(err_str,
- sizeof(err_str),
- "\"range must be >= 0\"");
- rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM;
- goto out;
- }
-
- LIBCFS_IOC_INIT_V2(data, sv_hdr);
- data.sv_value = range;
-
- rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_SET_NUMA_RANGE, &data);
- if (rc != 0) {
- rc = -errno;
- snprintf(err_str,
- sizeof(err_str),
- "\"cannot configure numa_range: %s\"", strerror(errno));
- goto out;
- }
-
-out:
- cYAML_build_error(rc, seq_no, ADD_CMD, "numa_range", err_str, err_rc);
-
- return 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,
free(root);
}
-int lustre_lnet_show_max_intf(int seq_no, struct cYAML **show_rc,
- struct cYAML **err_rc)
+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;
- 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);
+ if (err) {
+ rc = err;
goto out;
}
- max_intf = atoi(val);
-
root = cYAML_create_object(NULL, NULL);
if (root == NULL)
goto out;
if (global == NULL)
goto out;
- if (cYAML_create_number(global, "max_intf",
- max_intf) == NULL)
+ if (cYAML_create_number(global, name,
+ value) == NULL)
goto out;
if (show_rc == NULL)
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)
- 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\"");
+ snprintf(err_str, err_len, "\"success\"");
rc = LUSTRE_CFG_RC_NO_ERR;
return rc;
}
-int lustre_lnet_show_numa_range(int seq_no, struct cYAML **show_rc,
- struct cYAML **err_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;
+ int l_errno = 0;
char err_str[LNET_MAX_STR_LEN];
- struct cYAML *root = NULL, *global = NULL;
snprintf(err_str, sizeof(err_str), "\"out of memory\"");
LIBCFS_IOC_INIT_V2(data, sv_hdr);
- rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_NUMA_RANGE, &data);
+ rc = l_ioctl(LNET_DEV_ID, ioc, &data);
if (rc != 0) {
- l_errno = errno;
+ l_errno = -errno;
snprintf(err_str,
sizeof(err_str),
- "\"cannot get numa range: %s\"",
- strerror(l_errno));
- rc = -l_errno;
- goto out;
+ "\"cannot get %s: %s\"",
+ name, strerror(l_errno));
}
- rc = LUSTRE_CFG_RC_OUT_OF_MEM;
+ return build_global_yaml_entry(err_str, sizeof(err_str), seq_no, name,
+ data.sv_value, show_rc, err_rc, l_errno);
+}
- root = cYAML_create_object(NULL, NULL);
- if (root == NULL)
- goto out;
+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];
- global = cYAML_create_object(root, "global");
- if (global == NULL)
- goto out;
+ snprintf(err_str, sizeof(err_str), "\"out of memory\"");
- if (cYAML_create_number(global, "numa_range",
- data.sv_value) == NULL)
- goto out;
+ 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);
+ }
- if (show_rc == NULL)
- cYAML_print_tree(root);
+ return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
+ "max_intf", max_intf, show_rc,
+ err_rc, l_errno);
+}
- 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) {
- add_to_global(*show_rc, global, root);
+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];
+
+ 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) {
+ l_errno = -errno;
+ snprintf(err_str, sizeof(err_str),
+ "\"cannot get discovery setting: %d\"", rc);
} else {
- *show_rc = root;
+ /*
+ * The kernel stores a discovery disabled value. User space
+ * shows whether discovery is enabled. So the value must be
+ * inverted.
+ */
+ discovery = !atoi(val);
}
- cYAML_build_error(rc, seq_no, SHOW_CMD, "global", err_str, err_rc);
+ return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
+ "discovery", discovery, show_rc,
+ err_rc, l_errno);
+}
- return rc;
+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,
show_rc, err_rc);
}
+static int handle_yaml_discover(struct cYAML *tree, struct cYAML **show_rc,
+ struct cYAML **err_rc)
+{
+ struct cYAML *seq_no, *nid, *force;
+
+ seq_no = cYAML_get_object_item(tree, "seq_no");
+ nid = cYAML_get_object_item(tree, "primary nid");
+ force = cYAML_get_object_item(tree, "force");
+
+ return lustre_lnet_discover_nid((nid) ? nid->cy_valuestring : NULL,
+ (force) ? force->cy_valueint : 0,
+ (seq_no) ? seq_no->cy_valueint : -1,
+ show_rc, err_rc);
+}
+
static int handle_yaml_no_op()
{
return LUSTRE_CFG_RC_NO_ERR;
{ .name = "statistics", .cb = handle_yaml_no_op },
{ .name = "global", .cb = handle_yaml_config_global_settings},
{ .name = "ping", .cb = handle_yaml_no_op },
+ { .name = "discover", .cb = handle_yaml_no_op },
{ .name = NULL } };
static struct lookup_cmd_hdlr_tbl lookup_del_tbl[] = {
{ .name = "statistics", .cb = handle_yaml_no_op },
{ .name = "global", .cb = handle_yaml_del_global_settings},
{ .name = "ping", .cb = handle_yaml_no_op },
+ { .name = "discover", .cb = handle_yaml_no_op },
{ .name = NULL } };
static struct lookup_cmd_hdlr_tbl lookup_show_tbl[] = {
{ .name = "statistics", .cb = handle_yaml_show_stats },
{ .name = "global", .cb = handle_yaml_show_global_settings},
{ .name = "ping", .cb = handle_yaml_no_op },
+ { .name = "discover", .cb = handle_yaml_no_op },
{ .name = NULL } };
static struct lookup_cmd_hdlr_tbl lookup_exec_tbl[] = {
{ .name = "statistics", .cb = handle_yaml_no_op },
{ .name = "global", .cb = handle_yaml_no_op },
{ .name = "ping", .cb = handle_yaml_ping },
+ { .name = "discover", .cb = handle_yaml_discover },
{ .name = NULL } };
static cmd_handler_t lookup_fn(char *key,
if (rc != LUSTRE_CFG_RC_NO_ERR) {
cYAML_print_tree2file(stderr, err_rc);
cYAML_free_tree(err_rc);
+ err_rc = NULL;
}
rc = lustre_lnet_show_route(NULL, NULL, -1, -1, 1, -1, &show_rc,
if (rc != LUSTRE_CFG_RC_NO_ERR) {
cYAML_print_tree2file(stderr, err_rc);
cYAML_free_tree(err_rc);
+ err_rc = NULL;
}
rc = lustre_lnet_show_routing(-1, &show_rc, &err_rc);
if (rc != LUSTRE_CFG_RC_NO_ERR) {
cYAML_print_tree2file(stderr, err_rc);
cYAML_free_tree(err_rc);
+ err_rc = NULL;
}
rc = lustre_lnet_show_peer(NULL, 1, -1, &show_rc, &err_rc);
if (rc != LUSTRE_CFG_RC_NO_ERR) {
cYAML_print_tree2file(stderr, err_rc);
cYAML_free_tree(err_rc);
+ err_rc = NULL;
}
rc = lustre_lnet_show_numa_range(-1, &show_rc, &err_rc);
if (rc != LUSTRE_CFG_RC_NO_ERR) {
cYAML_print_tree2file(stderr, err_rc);
cYAML_free_tree(err_rc);
+ err_rc = NULL;
}
rc = lustre_lnet_show_max_intf(-1, &show_rc, &err_rc);
if (rc != LUSTRE_CFG_RC_NO_ERR) {
cYAML_print_tree2file(stderr, err_rc);
cYAML_free_tree(err_rc);
+ err_rc = NULL;
+ }
+
+ rc = lustre_lnet_show_discovery(-1, &show_rc, &err_rc);
+ if (rc != LUSTRE_CFG_RC_NO_ERR) {
+ cYAML_print_tree2file(stderr, err_rc);
+ cYAML_free_tree(err_rc);
+ err_rc = NULL;
}
if (show_rc != NULL) {
return rc;
}
+static int jt_discover(int argc, char **argv)
+{
+ struct cYAML *err_rc = NULL;
+ struct cYAML *show_rc = NULL;
+ int force = 0;
+ int rc = 0, opt;
+
+ const char *const short_options = "fh";
+ const struct option long_options[] = {
+ { "force", 0, NULL, 'f' },
+ { "help", 0, NULL, 'h' },
+ { NULL, 0, NULL, 0 },
+ };
+
+ while ((opt = getopt_long(argc, argv, short_options,
+ long_options, NULL)) != -1) {
+ switch (opt) {
+ case 'f':
+ force = 1;
+ break;
+ case 'h':
+ printf("discover: nid1 nid2 .. nidN (e.g. 10.2.2.2@tcp)\n"
+ "\t--force\n"
+ "\t--help: display this help\n");
+ return 0;
+ default:
+ return 0;
+ }
+ }
+
+ if (argc < 2)
+ return CMD_HELP;
+
+ for (; optind < argc; optind++)
+ rc = lustre_lnet_discover_nid(argv[optind], force, -1, &show_rc,
+ &err_rc);
+
+ if (show_rc)
+ cYAML_print_tree(show_rc);
+
+ if (err_rc)
+ cYAML_print_tree2file(stderr, err_rc);
+
+ cYAML_free_tree(err_rc);
+ cYAML_free_tree(show_rc);
+
+ return rc;
+}
+
command_t list[] = {
{"lnet", jt_lnet, 0, "lnet {configure | unconfigure} [--all]"},
{"route", jt_route, 0, "route {add | del | show | help}"},
{"global", jt_global, 0, "global {show | help}"},
{"peer", jt_peers, 0, "peer {add | del | show | help}"},
{"ping", jt_ping, 0, "ping {--help}"},
+ {"discover", jt_discover, 0, "discover {--help}"},
{"help", Parser_help, 0, "help"},
{"exit", Parser_quit, 0, "quit"},
{"quit", Parser_quit, 0, "quit"},