diff options
Diffstat (limited to 'cli/src/cli-xml-output.c')
| -rw-r--r-- | cli/src/cli-xml-output.c | 133 |
1 files changed, 85 insertions, 48 deletions
diff --git a/cli/src/cli-xml-output.c b/cli/src/cli-xml-output.c index 3accd9ce4bf..069de75801c 100644 --- a/cli/src/cli-xml-output.c +++ b/cli/src/cli-xml-output.c @@ -1661,15 +1661,15 @@ cli_xml_output_vol_top_rw_perf(xmlTextWriterPtr writer, dict_t *dict, int ret = -1; char *filename = NULL; uint64_t throughput = 0; - long int time_sec = 0; - long int time_usec = 0; - char timestr[256] = { + struct timeval tv = { + 0, + }; + char timestr[GF_TIMESTR_SIZE] = { 0, }; char key[1024] = { 0, }; - int len; /* <file> */ ret = xmlTextWriterStartElement(writer, (xmlChar *)"file"); @@ -1692,19 +1692,16 @@ cli_xml_output_vol_top_rw_perf(xmlTextWriterPtr writer, dict_t *dict, XML_RET_CHECK_AND_GOTO(ret, out); snprintf(key, sizeof(key), "%d-time-sec-%d", brick_index, member_index); - ret = dict_get_int32(dict, key, (int32_t *)&time_sec); + ret = dict_get_int32(dict, key, (int32_t *)&tv.tv_sec); if (ret) goto out; snprintf(key, sizeof(key), "%d-time-usec-%d", brick_index, member_index); - ret = dict_get_int32(dict, key, (int32_t *)&time_usec); + ret = dict_get_int32(dict, key, (int32_t *)&tv.tv_usec); if (ret) goto out; - gf_time_fmt(timestr, sizeof timestr, time_sec, gf_timefmt_FT); - len = strlen(timestr); - snprintf(timestr + len, sizeof(timestr) - len, ".%" GF_PRI_SUSECONDS, - time_usec); + gf_time_fmt_tv(timestr, sizeof timestr, &tv, gf_timefmt_FT); ret = xmlTextWriterWriteFormatElement(writer, (xmlChar *)"time", "%s", timestr); XML_RET_CHECK_AND_GOTO(ret, out); @@ -1953,11 +1950,11 @@ cli_xml_output_vol_profile_stats(xmlTextWriterPtr writer, dict_t *dict, XML_RET_CHECK_AND_GOTO(ret, out); ret = xmlTextWriterWriteFormatElement(writer, (xmlChar *)"size", - "%" PRIu32, (1 << i)); + "%" PRIu32, (1U << i)); XML_RET_CHECK_AND_GOTO(ret, out); - snprintf(key, sizeof(key), "%d-%d-read-%d", brick_index, interval, - (1 << i)); + snprintf(key, sizeof(key), "%d-%d-read-%" PRIu32, brick_index, interval, + (1U << i)); ret = dict_get_uint64(dict, key, &read_count); if (ret) read_count = 0; @@ -1965,8 +1962,8 @@ cli_xml_output_vol_profile_stats(xmlTextWriterPtr writer, dict_t *dict, "%" PRIu64, read_count); XML_RET_CHECK_AND_GOTO(ret, out); - snprintf(key, sizeof(key), "%d-%d-write-%d", brick_index, interval, - (1 << i)); + snprintf(key, sizeof(key), "%d-%d-write-%" PRIu32, brick_index, + interval, (1U << i)); ret = dict_get_uint64(dict, key, &write_count); if (ret) write_count = 0; @@ -2507,8 +2504,9 @@ cli_xml_output_vol_info(cli_local_t *local, dict_t *dict) ret = dict_get_int32(dict, key, &dist_count); if (ret) goto out; - ret = xmlTextWriterWriteFormatElement( - local->writer, (xmlChar *)"distCount", "%d", dist_count); + ret = xmlTextWriterWriteFormatElement(local->writer, + (xmlChar *)"distCount", "%d", + (brick_count / dist_count)); XML_RET_CHECK_AND_GOTO(ret, out); snprintf(key, sizeof(key), "volume%d.stripe_count", i); @@ -2779,7 +2777,9 @@ cli_xml_output_peer_hostnames(xmlTextWriterPtr writer, dict_t *dict, XML_RET_CHECK_AND_GOTO(ret, out); for (i = 0; i < count; i++) { - snprintf(key, sizeof(key), "%s.hostname%d", prefix, i); + ret = snprintf(key, sizeof(key), "%s.hostname%d", prefix, i); + if (ret < 0) + goto out; ret = dict_get_str(dict, key, &hostname); if (ret) goto out; @@ -3577,20 +3577,21 @@ cli_xml_output_vol_gsync_status(dict_t *dict, xmlTextWriterPtr writer) char *volume_next = NULL; char *slave = NULL; char *slave_next = NULL; - char *title_values[] = {"master_node", "", "master_brick", "slave_user", - "slave", "slave_node", "status", "crawl_status", - /* last_synced */ - "", "entry", "data", "meta", "failures", - /* checkpoint_time */ - "", "checkpoint_completed", - /* checkpoint_completion_time */ - "", "master_node_uuid", - /* last_synced_utc */ - "last_synced", - /* checkpoint_time_utc */ - "checkpoint_time", - /* checkpoint_completion_time_utc */ - "checkpoint_completion_time"}; + static const char *title_values[] = { + "master_node", "", "master_brick", "slave_user", "slave", "slave_node", + "status", "crawl_status", + /* last_synced */ + "", "entry", "data", "meta", "failures", + /* checkpoint_time */ + "", "checkpoint_completed", + /* checkpoint_completion_time */ + "", "master_node_uuid", + /* last_synced_utc */ + "last_synced", + /* checkpoint_time_utc */ + "checkpoint_time", + /* checkpoint_completion_time_utc */ + "checkpoint_completion_time"}; GF_ASSERT(dict); @@ -4201,7 +4202,9 @@ cli_xml_snapshot_info_snap_vol(xmlTextWriterPtr writer, xmlDocPtr doc, ret = xmlTextWriterStartElement(writer, (xmlChar *)"snapVolume"); XML_RET_CHECK_AND_GOTO(ret, out); - snprintf(key, sizeof(key), "%s.volname", keyprefix); + ret = snprintf(key, sizeof(key), "%s.volname", keyprefix); + if (ret < 0) + goto out; ret = dict_get_str(dict, key, &buffer); if (ret) { @@ -4213,7 +4216,9 @@ cli_xml_snapshot_info_snap_vol(xmlTextWriterPtr writer, xmlDocPtr doc, buffer); XML_RET_CHECK_AND_GOTO(ret, out); - snprintf(key, sizeof(key), "%s.vol-status", keyprefix); + ret = snprintf(key, sizeof(key), "%s.vol-status", keyprefix); + if (ret < 0) + goto out; ret = dict_get_str(dict, key, &buffer); if (ret) { @@ -4228,7 +4233,10 @@ cli_xml_snapshot_info_snap_vol(xmlTextWriterPtr writer, xmlDocPtr doc, /* If the command is snap_driven then we need to show origin volume * info. Else this is shown in the start of info display.*/ if (snap_driven) { - snprintf(key, sizeof(key), "%s.", keyprefix); + ret = snprintf(key, sizeof(key), "%s.", keyprefix); + if (ret < 0) + goto out; + ret = cli_xml_snapshot_info_orig_vol(writer, doc, dict, key); if (ret) { gf_log("cli", GF_LOG_ERROR, @@ -4279,7 +4287,9 @@ cli_xml_snapshot_info_per_snap(xmlTextWriterPtr writer, xmlDocPtr doc, ret = xmlTextWriterStartElement(writer, (xmlChar *)"snapshot"); XML_RET_CHECK_AND_GOTO(ret, out); - snprintf(key_buffer, sizeof(key_buffer), "%s.snapname", keyprefix); + ret = snprintf(key_buffer, sizeof(key_buffer), "%s.snapname", keyprefix); + if (ret < 0) + goto out; ret = dict_get_str(dict, key_buffer, &buffer); if (ret) { @@ -4291,7 +4301,9 @@ cli_xml_snapshot_info_per_snap(xmlTextWriterPtr writer, xmlDocPtr doc, buffer); XML_RET_CHECK_AND_GOTO(ret, out); - snprintf(key_buffer, sizeof(key_buffer), "%s.snap-id", keyprefix); + ret = snprintf(key_buffer, sizeof(key_buffer), "%s.snap-id", keyprefix); + if (ret < 0) + goto out; ret = dict_get_str(dict, key_buffer, &buffer); if (ret) { @@ -4303,7 +4315,9 @@ cli_xml_snapshot_info_per_snap(xmlTextWriterPtr writer, xmlDocPtr doc, buffer); XML_RET_CHECK_AND_GOTO(ret, out); - snprintf(key_buffer, sizeof(key_buffer), "%s.snap-desc", keyprefix); + ret = snprintf(key_buffer, sizeof(key_buffer), "%s.snap-desc", keyprefix); + if (ret < 0) + goto out; ret = dict_get_str(dict, key_buffer, &buffer); if (!ret) { @@ -4315,7 +4329,9 @@ cli_xml_snapshot_info_per_snap(xmlTextWriterPtr writer, xmlDocPtr doc, } XML_RET_CHECK_AND_GOTO(ret, out); - snprintf(key_buffer, sizeof(key_buffer), "%s.snap-time", keyprefix); + ret = snprintf(key_buffer, sizeof(key_buffer), "%s.snap-time", keyprefix); + if (ret < 0) + goto out; ret = dict_get_str(dict, key_buffer, &buffer); if (ret) { @@ -4327,7 +4343,10 @@ cli_xml_snapshot_info_per_snap(xmlTextWriterPtr writer, xmlDocPtr doc, buffer); XML_RET_CHECK_AND_GOTO(ret, out); - snprintf(key_buffer, sizeof(key_buffer), "%s.vol-count", keyprefix); + ret = snprintf(key_buffer, sizeof(key_buffer), "%s.vol-count", keyprefix); + if (ret < 0) + goto out; + ret = dict_get_int32(dict, key_buffer, &volcount); if (ret) { gf_log("cli", GF_LOG_ERROR, "Fail to get snap vol count"); @@ -4341,7 +4360,10 @@ cli_xml_snapshot_info_per_snap(xmlTextWriterPtr writer, xmlDocPtr doc, ret = dict_get_int32(dict, key_buffer, &volcount); /* Display info of each snapshot volume */ for (i = 1; i <= volcount; i++) { - snprintf(key_buffer, sizeof(key_buffer), "%s.vol%d", keyprefix, i); + ret = snprintf(key_buffer, sizeof(key_buffer), "%s.vol%d", keyprefix, + i); + if (ret < 0) + goto out; ret = cli_xml_snapshot_info_snap_vol(writer, doc, dict, key_buffer, snap_driven); @@ -4465,7 +4487,9 @@ cli_xml_snapshot_volume_status(xmlTextWriterPtr writer, xmlDocPtr doc, GF_ASSERT(dict); GF_ASSERT(keyprefix); - snprintf(key, sizeof(key), "%s.brickcount", keyprefix); + ret = snprintf(key, sizeof(key), "%s.brickcount", keyprefix); + if (ret < 0) + goto out; ret = dict_get_int32(dict, key, &brickcount); if (ret) { @@ -4483,7 +4507,9 @@ cli_xml_snapshot_volume_status(xmlTextWriterPtr writer, xmlDocPtr doc, ret = xmlTextWriterStartElement(writer, (xmlChar *)"brick"); XML_RET_CHECK_AND_GOTO(ret, out); - snprintf(key, sizeof(key), "%s.brick%d.path", keyprefix, i); + ret = snprintf(key, sizeof(key), "%s.brick%d.path", keyprefix, i); + if (ret < 0) + goto out; ret = dict_get_str(dict, key, &buffer); if (ret) { @@ -4502,7 +4528,9 @@ cli_xml_snapshot_volume_status(xmlTextWriterPtr writer, xmlDocPtr doc, buffer); XML_RET_CHECK_AND_GOTO(ret, out); - snprintf(key, sizeof(key), "%s.brick%d.vgname", keyprefix, i); + ret = snprintf(key, sizeof(key), "%s.brick%d.vgname", keyprefix, i); + if (ret < 0) + goto out; ret = dict_get_str(dict, key, &buffer); if (ret) { @@ -4515,7 +4543,9 @@ cli_xml_snapshot_volume_status(xmlTextWriterPtr writer, xmlDocPtr doc, XML_RET_CHECK_AND_GOTO(ret, out); - snprintf(key, sizeof(key), "%s.brick%d.status", keyprefix, i); + ret = snprintf(key, sizeof(key), "%s.brick%d.status", keyprefix, i); + if (ret < 0) + goto out; ret = dict_get_str(dict, key, &buffer); if (ret) { @@ -4528,7 +4558,9 @@ cli_xml_snapshot_volume_status(xmlTextWriterPtr writer, xmlDocPtr doc, XML_RET_CHECK_AND_GOTO(ret, out); - snprintf(key, sizeof(key), "%s.brick%d.pid", keyprefix, i); + ret = snprintf(key, sizeof(key), "%s.brick%d.pid", keyprefix, i); + if (ret < 0) + goto out; ret = dict_get_int32(dict, key, &pid); if (ret) { @@ -4541,7 +4573,9 @@ cli_xml_snapshot_volume_status(xmlTextWriterPtr writer, xmlDocPtr doc, XML_RET_CHECK_AND_GOTO(ret, out); - snprintf(key, sizeof(key), "%s.brick%d.data", keyprefix, i); + ret = snprintf(key, sizeof(key), "%s.brick%d.data", keyprefix, i); + if (ret < 0) + goto out; ret = dict_get_str(dict, key, &buffer); if (ret) { @@ -4554,7 +4588,10 @@ cli_xml_snapshot_volume_status(xmlTextWriterPtr writer, xmlDocPtr doc, XML_RET_CHECK_AND_GOTO(ret, out); - snprintf(key, sizeof(key), "%s.brick%d.lvsize", keyprefix, i); + ret = snprintf(key, sizeof(key), "%s.brick%d.lvsize", keyprefix, i); + if (ret < 0) + goto out; + ret = dict_get_str(dict, key, &buffer); if (ret) { gf_log("cli", GF_LOG_ERROR, "Unable to get LV Size"); |
