int lustre_lnet_show_route(char *nw, char *gw, int hops, int prio, int detail,
int seq_no, struct cYAML **show_rc,
- struct cYAML **err_rc)
+ struct cYAML **err_rc, bool backup)
{
struct lnet_ioctl_config_data data;
lnet_nid_t gateway_nid;
cfg_route.rtr_priority) == NULL)
goto out;
- if (cYAML_create_string(item, "state",
+ if (!backup &&
+ cYAML_create_string(item, "state",
data.cfg_config_u.cfg_route.
rtr_flags ?
"up" : "down") == NULL)
}
int lustre_lnet_show_net(char *nw, int detail, int seq_no,
- struct cYAML **show_rc, struct cYAML **err_rc)
+ struct cYAML **show_rc, struct cYAML **err_rc,
+ bool backup)
{
char *buf;
struct lnet_ioctl_config_ni *ni_data;
net != rc_net)
continue;
+ /* if we're backing up don't store lo */
+ if (backup && LNET_NETTYP(rc_net) == LOLND)
+ continue;
+
/* default rc to -1 in case we hit the goto */
rc = -1;
exist = true;
if (first_seq == NULL)
first_seq = item;
- if (cYAML_create_string(item, "nid",
+ if (!backup &&
+ cYAML_create_string(item, "nid",
libcfs_nid2str(ni_data->lic_nid)) == NULL)
goto out;
- if (cYAML_create_string(item,
+ if (!backup &&
+ cYAML_create_string(item,
"status",
(ni_data->lic_status ==
LNET_NI_STATUS_UP) ?
char *limit;
int k;
+ if (backup)
+ goto continue_without_msg_stats;
+
statistics = cYAML_create_object(item, "statistics");
if (statistics == NULL)
goto out;
if (rc != LUSTRE_CFG_RC_NO_ERR)
goto out;
- tunables = cYAML_create_object(item, "lnd tunables");
- if (tunables == NULL)
- goto out;
-
rc = lustre_ni_show_tunables(tunables, LNET_NETTYP(rc_net),
&lnd->lt_tun);
- if (rc != LUSTRE_CFG_RC_NO_ERR)
+ if (rc != LUSTRE_CFG_RC_NO_ERR &&
+ rc != LUSTRE_CFG_RC_NO_MATCH)
goto out;
- if (cYAML_create_number(item, "tcp bonding",
- ni_data->lic_tcp_bonding)
- == NULL)
- goto out;
+ if (rc != LUSTRE_CFG_RC_NO_MATCH) {
+ tunables = cYAML_create_object(item,
+ "lnd tunables");
+ if (tunables == NULL)
+ goto out;
+ }
- if (cYAML_create_number(item, "dev cpt",
+ if (!backup &&
+ cYAML_create_number(item, "dev cpt",
ni_data->lic_dev_cpt) == NULL)
goto out;
+ if (!backup &&
+ cYAML_create_number(item, "tcp bonding",
+ ni_data->lic_tcp_bonding)
+ == NULL)
+ goto out;
+
/* out put the CPTs in the format: "[x,x,x,...]" */
limit = str_buf + str_buf_len - 3;
pos += snprintf(pos, limit - pos, "\"[");
}
int lustre_lnet_show_routing(int seq_no, struct cYAML **show_rc,
- struct cYAML **err_rc)
+ struct cYAML **err_rc, bool backup)
{
struct lnet_ioctl_config_data *data;
struct lnet_ioctl_pool_cfg *pool_cfg = NULL;
if (root == NULL)
goto out;
- pools_node = cYAML_create_seq(root, "routing");
+ if (backup)
+ pools_node = cYAML_create_object(root, "routing");
+ else
+ pools_node = cYAML_create_seq(root, "routing");
if (pools_node == NULL)
goto out;
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)
if (cpt == NULL)
goto out;
+calculate_buffers:
/* create the tree and print */
for (j = 0; j < LNET_NRBPOOLS; j++) {
- type_node = cYAML_create_object(cpt, pools[j]);
- if (type_node == NULL)
- goto out;
- if (cYAML_create_number(type_node, "npages",
+ 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 (cYAML_create_number(type_node, "nbuffers",
+ if (!backup &&
+ cYAML_create_number(type_node, "nbuffers",
pool_cfg->pl_pools[j].
pl_nbuffers) == NULL)
goto out;
- if (cYAML_create_number(type_node, "credits",
+ if (!backup &&
+ cYAML_create_number(type_node, "credits",
pool_cfg->pl_pools[j].
pl_credits) == NULL)
goto out;
- if (cYAML_create_number(type_node, "mincredits",
+ if (!backup &&
+ cYAML_create_number(type_node, "mincredits",
pool_cfg->pl_pools[j].
pl_mincredits) == NULL)
goto out;
}
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;
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 */
}
int lustre_lnet_show_peer(char *knid, int detail, int seq_no,
- struct cYAML **show_rc, struct cYAML **err_rc)
+ struct cYAML **show_rc, struct cYAML **err_rc,
+ bool backup)
{
/*
* TODO: This function is changing in a future patch to accommodate
* requested
*/
if (detail >= 3) {
- if (cYAML_create_number(peer, "peer state",
+ if (!backup &&
+ cYAML_create_number(peer, "peer state",
peer_info.prcfg_state)
== NULL)
goto out;
== NULL)
goto out;
+ if (backup)
+ continue;
+
if (cYAML_create_string(peer_ni, "state",
lpni_cri->cr_aliveness)
== NULL)
(prio) ? prio->cy_valueint : -1,
(detail) ? detail->cy_valueint : 0,
(seq_no) ? seq_no->cy_valueint : -1,
- show_rc,
- err_rc);
+ show_rc, err_rc, false);
}
static int handle_yaml_show_net(struct cYAML *tree, struct cYAML **show_rc,
return lustre_lnet_show_net((net) ? net->cy_valuestring : NULL,
(detail) ? detail->cy_valueint : 0,
(seq_no) ? seq_no->cy_valueint : -1,
- show_rc,
- err_rc);
+ show_rc, err_rc, false);
}
static int handle_yaml_show_routing(struct cYAML *tree, struct cYAML **show_rc,
seq_no = cYAML_get_object_item(tree, "seq_no");
return lustre_lnet_show_routing((seq_no) ? seq_no->cy_valueint : -1,
- show_rc, err_rc);
+ show_rc, err_rc, false);
}
static int handle_yaml_show_peers(struct cYAML *tree, struct cYAML **show_rc,
return lustre_lnet_show_peer((nid) ? nid->cy_valuestring : NULL,
(detail) ? detail->cy_valueint : 0,
(seq_no) ? seq_no->cy_valueint : -1,
- show_rc, err_rc);
+ show_rc, err_rc, false);
}
static int handle_yaml_show_stats(struct cYAML *tree, struct cYAML **show_rc,
* seq_no - sequence number of the request
* show_rc - [OUT] The show output in YAML. Must be freed by caller.
* err_rc - [OUT] struct cYAML tree describing the error. Freed by caller
+ * backup - true to output only what's necessary for reconfiguring
+ * a node.
*/
int lustre_lnet_show_route(char *nw, char *gw,
int hops, int prio, int detail,
int seq_no, struct cYAML **show_rc,
- struct cYAML **err_rc);
+ struct cYAML **err_rc, bool backup);
/*
* lustre_lnet_config_ni
* seq_no - sequence number of the request
* show_rc - [OUT] The show output in YAML. Must be freed by caller.
* err_rc - [OUT] struct cYAML tree describing the error. Freed by caller
+ * backup - true to output only what's necessary for reconfiguring
+ * a node.
*/
int lustre_lnet_show_net(char *nw, int detail, int seq_no,
- struct cYAML **show_rc, struct cYAML **err_rc);
+ struct cYAML **show_rc, struct cYAML **err_rc,
+ bool backup);
/*
* lustre_lnet_enable_routing
* seq_no - sequence number of the request
* show_rc - [OUT] The show output in YAML. Must be freed by caller.
* err_rc - [OUT] struct cYAML tree describing the error. Freed by caller
+ * backup - true to output only what's necessary for reconfiguring
+ * a node.
*/
int lustre_lnet_show_routing(int seq_no, struct cYAML **show_rc,
- struct cYAML **err_rc);
+ struct cYAML **err_rc, bool backup);
/*
* lustre_lnet_show_stats
* seq_no - sequence number of the command
* show_rc - YAML structure of the resultant show
* err_rc - YAML strucutre of the resultant return code.
+ * backup - true to output only what's necessary for reconfiguring
+ * a node.
*
*/
int lustre_lnet_show_peer(char *knid, int detail, int seq_no,
- struct cYAML **show_rc, struct cYAML **err_rc);
+ struct cYAML **show_rc, struct cYAML **err_rc,
+ bool backup);
/*
* lustre_lnet_list_peer
}
rc = lustre_lnet_show_route(network, gateway, hop, prio, detail, -1,
- &show_rc, &err_rc);
+ &show_rc, &err_rc, false);
if (rc != LUSTRE_CFG_RC_NO_ERR)
cYAML_print_tree2file(stderr, err_rc);
}
}
- rc = lustre_lnet_show_net(network, (int) detail, -1, &show_rc, &err_rc);
+ rc = lustre_lnet_show_net(network, (int) detail, -1, &show_rc, &err_rc,
+ false);
if (rc != LUSTRE_CFG_RC_NO_ERR)
cYAML_print_tree2file(stderr, err_rc);
if (rc)
return rc;
- rc = lustre_lnet_show_routing(-1, &show_rc, &err_rc);
+ rc = lustre_lnet_show_routing(-1, &show_rc, &err_rc, false);
if (rc != LUSTRE_CFG_RC_NO_ERR)
cYAML_print_tree2file(stderr, err_rc);
int rc;
FILE *f = NULL;
int opt;
+ bool backup = false;
+ char *file = NULL;
- const char *const short_options = "h";
+ const char *const short_options = "bh";
static const struct option long_options[] = {
+ { .name = "backup", .has_arg = no_argument, .val = 'b' },
{ .name = "help", .has_arg = no_argument, .val = 'h' },
{ .name = NULL } };
while ((opt = getopt_long(argc, argv, short_options,
long_options, NULL)) != -1) {
switch (opt) {
+ case 'b':
+ backup = true;
+ break;
case 'h':
+ default:
printf("export > FILE.yaml : export configuration\n"
"\t--help: display this help\n");
return 0;
- default:
- return 0;
}
}
- if (argc >= 2) {
- f = fopen(argv[1], "w");
+ if (backup && argc >= 3)
+ file = argv[2];
+ else if (!backup && argc >= 2)
+ file = argv[1];
+ else
+ f = stdout;
+
+ if (file) {
+ f = fopen(file, "w");
if (f == NULL)
return -1;
- } else
- f = stdout;
+ }
- rc = lustre_lnet_show_net(NULL, 2, -1, &show_rc, &err_rc);
+ rc = lustre_lnet_show_net(NULL, 2, -1, &show_rc, &err_rc, backup);
if (rc != LUSTRE_CFG_RC_NO_ERR) {
cYAML_print_tree2file(stderr, err_rc);
cYAML_free_tree(err_rc);
}
rc = lustre_lnet_show_route(NULL, NULL, -1, -1, 1, -1, &show_rc,
- &err_rc);
+ &err_rc, backup);
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);
+ rc = lustre_lnet_show_routing(-1, &show_rc, &err_rc, backup);
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, 2, -1, &show_rc, &err_rc);
+ rc = lustre_lnet_show_peer(NULL, 2, -1, &show_rc, &err_rc, backup);
if (rc != LUSTRE_CFG_RC_NO_ERR) {
cYAML_print_tree2file(stderr, err_rc);
cYAML_free_tree(err_rc);
}
}
- rc = lustre_lnet_show_peer(nid, (int) detail, -1, &show_rc, &err_rc);
+ rc = lustre_lnet_show_peer(nid, (int) detail, -1, &show_rc, &err_rc,
+ false);
if (rc != LUSTRE_CFG_RC_NO_ERR)
cYAML_print_tree2file(stderr, err_rc);