Whamcloud - gitweb
LU-6099 lnet: correct YAML output 04/13304/2
authorAmir Shehata <amir.shehata@intel.com>
Fri, 9 Jan 2015 00:53:06 +0000 (16:53 -0800)
committerOleg Drokin <oleg.drokin@intel.com>
Mon, 12 Jan 2015 18:46:02 +0000 (18:46 +0000)
Currently when dumping out network configuration the parameter
CPT describes which cpu partitions the network is configured on.
The current output looks like:
CPT = [0,1,...]
however the library used to parse YAML doesn't accept the use of
'[', so now I enclose it in double quotes:
CPT = "[0,1,...]"

Signed-off-by: Amir Shehata <amir.shehata@intel.com>
Change-Id: Ib15b2bc7db9463875ee0414ef614d71a42039fbb
Reviewed-on: http://review.whamcloud.com/13304
Tested-by: Jenkins
Tested-by: Maloo <hpdd-maloo@intel.com>
Reviewed-by: James Simmons <uja.ornl@gmail.com>
Reviewed-by: Andreas Dilger <andreas.dilger@intel.com>
lnet/utils/lnetconfig/liblnetconfig.c

index 82ef583..46c00f0 100644 (file)
@@ -667,6 +667,8 @@ int lustre_lnet_show_net(char *nw, int detail, int seq_no,
                }
 
                if (detail) {
+                       char *limit;
+
                        tunables = cYAML_create_object(item, "tunables");
                        if (tunables == NULL)
                                goto out;
@@ -693,25 +695,17 @@ int lustre_lnet_show_net(char *nw, int detail, int seq_no,
                                goto out;
 
                        /* out put the CPTs in the format: "[x,x,x,...]" */
-                       pos += snprintf(pos, str_buf + str_buf_len - pos, "[");
+                       limit = str_buf + str_buf_len - 3;
+                       pos += snprintf(pos, limit - pos, "\"[");
                        for (j = 0 ; data->cfg_ncpts > 1 &&
-                               j < data->cfg_ncpts; j++) {
-                               pos += snprintf(pos,
-                                               str_buf + str_buf_len - pos,
+                               j < data->cfg_ncpts &&
+                               pos < limit; j++) {
+                               pos += snprintf(pos, limit - pos,
                                                "%d", net_config->ni_cpts[j]);
                                if ((j + 1) < data->cfg_ncpts)
-                                       pos += snprintf(pos,
-                                                       str_buf +
-                                                        str_buf_len - pos,
-                                                       ",");
+                                       pos += snprintf(pos, limit - pos, ",");
                        }
-                       if (str_buf + str_buf_len - pos <= 0)
-                               pos += snprintf(str_buf + str_buf_len - 2,
-                                               2, "]");
-                       else
-                               pos += snprintf(pos,
-                                               str_buf + str_buf_len - pos,
-                                               "]");
+                       pos += snprintf(pos, 3, "]\"");
 
                        if (data->cfg_ncpts > 1 &&
                            cYAML_create_string(tunables, "CPT",