Whamcloud - gitweb
LU-6043 lnet: Fix YAML FSM and other cleanup 15/13115/2
authorAmir Shehata <amir.shehata@intel.com>
Thu, 18 Dec 2014 02:34:00 +0000 (18:34 -0800)
committerOleg Drokin <oleg.drokin@intel.com>
Sun, 4 Jan 2015 18:07:04 +0000 (18:07 +0000)
1. Fixed the FSM to be able to parse lnetctl YAML output properly
2. Don't print out elements which are not configured
3. Minor static analysis cleanup (LU-6021)

Signed-off-by: Amir Shehata <amir.shehata@intel.com>
Change-Id: I0e7812775a3c718882f0845c71ac7fb2fa46d1b0
Reviewed-on: http://review.whamcloud.com/13115
Tested-by: Jenkins
Reviewed-by: James Simmons <uja.ornl@gmail.com>
Tested-by: Maloo <hpdd-maloo@intel.com>
Reviewed-by: John L. Hammond <john.hammond@intel.com>
Reviewed-by: Oleg Drokin <oleg.drokin@intel.com>
lnet/utils/cyaml/cyaml.c
lnet/utils/lnetconfig/liblnetconfig.c

index 503c895..cb2bf83 100644 (file)
@@ -448,7 +448,8 @@ static enum cYAML_handler_error yaml_stream_start(yaml_token_t *token,
 static enum cYAML_handler_error yaml_stream_end(yaml_token_t *token,
                                                struct cYAML_tree_node *tree)
 {
-       if (tree->state != TREE_STATE_TREE_STARTED)
+       if (tree->state != TREE_STATE_TREE_STARTED &&
+           tree->state != TREE_STATE_COMPLETE)
                return CYAML_ERROR_UNEXPECTED_STATE;
 
        tree->state = TREE_STATE_INITED;
@@ -885,6 +886,9 @@ static void print_value(FILE *f, struct list_head *stack)
        struct cYAML_print_info *cpi = NULL;
        struct cYAML *node = cYAML_ll_pop(stack, &cpi);
 
+       if (node == NULL)
+               return;
+
        switch (node->cy_type) {
        case CYAML_TYPE_FALSE:
        case CYAML_TYPE_TRUE:
index 0579a2b..bd57092 100644 (file)
@@ -264,6 +264,7 @@ int lustre_lnet_show_route(char *nw, char *gw, int hops, int prio, int detail,
        struct cYAML *root = NULL, *route = NULL, *item = NULL;
        struct cYAML *first_seq = NULL;
        char err_str[LNET_MAX_STR_LEN];
+       bool exist = false;
 
        snprintf(err_str, sizeof(err_str),
                 "\"out of memory\"");
@@ -352,6 +353,7 @@ int lustre_lnet_show_route(char *nw, char *gw, int hops, int prio, int detail,
 
                /* default rc to -1 incase we hit the goto */
                rc = -1;
+               exist = true;
 
                item = cYAML_create_seq_item(route);
                if (item == NULL)
@@ -404,7 +406,7 @@ int lustre_lnet_show_route(char *nw, char *gw, int hops, int prio, int detail,
 
        snprintf(err_str, sizeof(err_str), "\"success\"");
 out:
-       if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR) {
+       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;
@@ -560,6 +562,7 @@ int lustre_lnet_show_net(char *nw, int detail, int seq_no,
        char str_buf[str_buf_len];
        char *pos;
        char err_str[LNET_MAX_STR_LEN];
+       bool exist = false;
 
        snprintf(err_str, sizeof(err_str), "\"out of memory\"");
 
@@ -613,6 +616,7 @@ int lustre_lnet_show_net(char *nw, int detail, int seq_no,
 
                /* default rc to -1 in case we hit the goto */
                rc = -1;
+               exist = true;
 
                net_config = (struct lnet_ioctl_net_config *)data->cfg_bulk;
 
@@ -732,7 +736,7 @@ int lustre_lnet_show_net(char *nw, int detail, int seq_no,
 
        snprintf(err_str, sizeof(err_str), "\"success\"");
 out:
-       if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR) {
+       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;
@@ -841,6 +845,7 @@ int lustre_lnet_show_routing(int seq_no, struct cYAML **show_rc,
        int i, j;
        char err_str[LNET_MAX_STR_LEN];
        char node_name[LNET_MAX_STR_LEN];
+       bool exist = false;
 
        snprintf(err_str, sizeof(err_str), "\"out of memory\"");
 
@@ -868,6 +873,8 @@ int lustre_lnet_show_routing(int seq_no, struct cYAML **show_rc,
                if (rc != 0)
                        break;
 
+               exist = true;
+
                pool_cfg = (struct lnet_ioctl_pool_cfg *)data->cfg_bulk;
 
                snprintf(node_name, sizeof(node_name), "cpt[%d]", i);
@@ -934,7 +941,7 @@ int lustre_lnet_show_routing(int seq_no, struct cYAML **show_rc,
 
 out:
        free(buf);
-       if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR) {
+       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;
@@ -1517,32 +1524,13 @@ static int lustre_yaml_cb_helper(char *f, struct lookup_cmd_hdlr_tbl *table,
                        while ((head = cYAML_get_next_seq_item(child, &item))
                               != NULL) {
                                rc = cb(head, show_rc, err_rc);
-                               /* if processing fails or no cb is found
-                                * then fail */
-                               if (rc != LUSTRE_CFG_RC_NO_ERR) {
-                                       snprintf(err_str, sizeof(err_str),
-                                               "\"Failed to process request:  "
-                                               "'%s' [%d, %p]\"",
-                                               head->cy_string, rc, cb);
-                                       cYAML_build_error(
-                                               LUSTRE_CFG_RC_BAD_PARAM, -1,
-                                               "yaml", "helper", err_str,
-                                               err_rc);
+                               if (rc != LUSTRE_CFG_RC_NO_ERR)
                                        return_rc = rc;
-                               }
                        }
                } else {
                        rc = cb(child, show_rc, err_rc);
-                       /* if processing fails or no cb is found then fail */
-                       if (rc != LUSTRE_CFG_RC_NO_ERR) {
-                               snprintf(err_str, sizeof(err_str),
-                                       "\"Failed to process request: '%s'"
-                                       " [%d, %p]\"",
-                                       child->cy_string, rc, cb);
-                               cYAML_build_error(LUSTRE_CFG_RC_BAD_PARAM, -1,
-                                       "yaml", "helper", err_str, err_rc);
+                       if (rc != LUSTRE_CFG_RC_NO_ERR)
                                return_rc = rc;
-                       }
                }
                item = NULL;
                child = child->cy_next;