Whamcloud - gitweb
LU-10452 lnet: cleanup YAML output 45/30845/6
authorAmir Shehata <amir.shehata@intel.com>
Fri, 12 Jan 2018 03:29:54 +0000 (19:29 -0800)
committerOleg Drokin <oleg.drokin@intel.com>
Tue, 6 Feb 2018 04:28:31 +0000 (04:28 +0000)
The level of verbosity is high when exporting the YAML configuration
for the purposes of storing it to reconfigure a node. This patch
eliminates the unnecessary YAML lines which are not needed when
reconfiguring a node, such as statistics, status, etc.

Test-Parameters: trivial
Signed-off-by: Amir Shehata <amir.shehata@intel.com>
Change-Id: Ie57c761415cfb0ceee8b2dbc0b293e85ae415685
Reviewed-on: https://review.whamcloud.com/30845
Tested-by: Jenkins
Tested-by: Maloo <hpdd-maloo@intel.com>
Reviewed-by: Doug Oucharek <dougso@me.com>
Reviewed-by: Andreas Dilger <andreas.dilger@intel.com>
Reviewed-by: James Simmons <uja.ornl@yahoo.com>
Reviewed-by: Oleg Drokin <oleg.drokin@intel.com>
lnet/utils/lnetconfig/liblnetconfig.c
lnet/utils/lnetconfig/liblnetconfig.h
lnet/utils/lnetconfig/liblnetconfig_lnd.c
lnet/utils/lnetctl.c

index a8b3bc5..dce0795 100644 (file)
@@ -952,7 +952,7 @@ out:
 
 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;
@@ -1072,7 +1072,8 @@ int lustre_lnet_show_route(char *nw, char *gw, int hops, int prio, int detail,
                                                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)
@@ -1858,7 +1859,8 @@ get_counts(struct lnet_ioctl_element_msg_stats *msg_stats, int idx)
 }
 
 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;
@@ -1935,6 +1937,10 @@ int lustre_lnet_show_net(char *nw, int detail, int seq_no,
                    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;
@@ -1968,11 +1974,13 @@ int lustre_lnet_show_net(char *nw, int detail, int seq_no,
                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) ?
@@ -2003,6 +2011,9 @@ int lustre_lnet_show_net(char *nw, int detail, int seq_no,
                        char *limit;
                        int k;
 
+                       if (backup)
+                               goto continue_without_msg_stats;
+
                        statistics = cYAML_create_object(item, "statistics");
                        if (statistics == NULL)
                                goto out;
@@ -2064,24 +2075,30 @@ continue_without_msg_stats:
                        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, "\"[");
@@ -2291,7 +2308,7 @@ out:
 }
 
 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;
@@ -2320,7 +2337,10 @@ int lustre_lnet_show_routing(int seq_no, struct cYAML **show_rc,
        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;
 
@@ -2340,6 +2360,9 @@ int lustre_lnet_show_routing(int seq_no, struct cYAML **show_rc,
 
                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)
@@ -2352,24 +2375,31 @@ int lustre_lnet_show_routing(int seq_no, struct cYAML **show_rc,
                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;
@@ -2380,6 +2410,15 @@ int lustre_lnet_show_routing(int seq_no, struct cYAML **show_rc,
        }
 
        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;
@@ -2389,6 +2428,7 @@ int lustre_lnet_show_routing(int seq_no, struct cYAML **show_rc,
                        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 */
@@ -2444,7 +2484,8 @@ out:
 }
 
 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
@@ -2582,7 +2623,8 @@ int lustre_lnet_show_peer(char *knid, int detail, int seq_no,
                 * 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;
@@ -2609,6 +2651,9 @@ int lustre_lnet_show_peer(char *knid, int detail, int seq_no,
                            == NULL)
                                goto out;
 
+                       if (backup)
+                               continue;
+
                        if (cYAML_create_string(peer_ni, "state",
                                                lpni_cri->cr_aliveness)
                            == NULL)
@@ -3695,8 +3740,7 @@ static int handle_yaml_show_route(struct cYAML *tree, struct cYAML **show_rc,
                                      (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,
@@ -3711,8 +3755,7 @@ 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,
@@ -3723,7 +3766,7 @@ 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,
@@ -3738,7 +3781,7 @@ 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,
index f2a193d..227a66e 100644 (file)
@@ -123,11 +123,13 @@ int lustre_lnet_del_route(char *nw, char *gw, int seq_no,
  *   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
@@ -172,9 +174,12 @@ int lustre_lnet_del_ni(struct lnet_dlc_network_descr *nw,
  *   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
@@ -286,9 +291,11 @@ int lustre_lnet_config_buffers(int tiny, int small, int large,
  *   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
@@ -351,10 +358,13 @@ int lustre_lnet_del_peer_nid(char *pnid, char **nid, int num_nids,
  *     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
index f804531..be820b5 100644 (file)
@@ -111,7 +111,7 @@ lustre_ni_show_tunables(struct cYAML *lnd_tunables,
                        __u32 net_type,
                        struct lnet_lnd_tunables *lnd)
 {
-       int rc = LUSTRE_CFG_RC_NO_ERR;
+       int rc = LUSTRE_CFG_RC_NO_MATCH;
 
        if (net_type == O2IBLND)
                rc = lustre_o2iblnd_show_tun(lnd_tunables,
index a385f40..bce3e90 100644 (file)
@@ -843,7 +843,7 @@ static int jt_show_route(int argc, char **argv)
        }
 
        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);
@@ -893,7 +893,8 @@ static int jt_show_net(int argc, char **argv)
                }
        }
 
-       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);
@@ -915,7 +916,7 @@ static int jt_show_routing(int argc, char **argv)
        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);
@@ -1165,32 +1166,43 @@ static int jt_export(int argc, char **argv)
        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);
@@ -1198,21 +1210,21 @@ static int jt_export(int argc, char **argv)
        }
 
        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);
@@ -1403,7 +1415,8 @@ static int jt_show_peer(int argc, char **argv)
                }
        }
 
-       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);