Skip to content

Commit ffa58cc

Browse files
Allow specifiying data areas 1-4 when generating telemetry logs
Allow users to specify data areas 1-4 when generating telemetry logs. Previously, the command is rejected if it is not 1 or 2. When users specify data area N, data areas <= N now get parsed into the output. Closes: #2754 Signed-off-by: dsfw-opensource <[email protected]>
1 parent 71fa5d9 commit ffa58cc

2 files changed

Lines changed: 20 additions & 19 deletions

File tree

plugins/ocp/ocp-nvme.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1465,8 +1465,8 @@ static int ocp_telemetry_log(int argc, char **argv, struct command *cmd, struct
14651465
if (!opt.data_area) {
14661466
nvme_show_result("Missing data-area. Using default data area 1.\n");
14671467
opt.data_area = DATA_AREA_1;//Default data area 1
1468-
} else if (opt.data_area != 1 && opt.data_area != 2) {
1469-
nvme_show_result("Invalid data-area specified. Please specify 1 or 2.\n");
1468+
} else if ((opt.data_area < DATA_AREA_1) || (opt.data_area > DATA_AREA_4)) {
1469+
nvme_show_result("Invalid data-area specified. Please specify 1-4.\n");
14701470
goto out;
14711471
}
14721472

plugins/ocp/ocp-telemetry-decode.c

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -980,9 +980,10 @@ int parse_event_fifo(unsigned int fifo_num, unsigned char *pfifo_start,
980980

981981
int status = 0;
982982
unsigned int event_fifo_number = fifo_num + 1;
983-
char *description = (char *)malloc((40 + 1) * sizeof(char));
983+
const size_t desc_size = sizeof(char) * (40 + 1);
984+
char *description = (char *)malloc(desc_size);
984985

985-
memset(description, 0, sizeof(40));
986+
memset(description, 0, desc_size);
986987

987988
status =
988989
parse_ocp_telemetry_string_log(event_fifo_number, 0, 0, EVENT_STRING, description);
@@ -1202,9 +1203,9 @@ int parse_event_fifos(struct json_object *root, struct nvme_ocp_telemetry_offset
12021203
(event_fifo[fifo_no].event_fifo_size * SIZE_OF_DWORD);
12031204
__u8 *pfifo_start = NULL;
12041205

1205-
if (event_fifo[fifo_no].event_fifo_da == 1)
1206+
if (event_fifo[fifo_no].event_fifo_da == DATA_AREA_1)
12061207
pfifo_start = pda1_header_offset + fifo_offset;
1207-
else if (event_fifo[fifo_no].event_fifo_da == 2)
1208+
else if (event_fifo[fifo_no].event_fifo_da == DATA_AREA_2)
12081209
pfifo_start = pda2_offset + fifo_offset;
12091210
else {
12101211
nvme_show_error("Unsupported Data Area:[%d]", poffsets->data_area);
@@ -1222,7 +1223,7 @@ int parse_event_fifos(struct json_object *root, struct nvme_ocp_telemetry_offset
12221223
}
12231224

12241225
if (pevent_fifos_object != NULL && root != NULL) {
1225-
const char *data_area = (poffsets->data_area == 1 ? STR_DA_1_EVENT_FIFO_INFO :
1226+
const char *data_area = (poffsets->data_area == DATA_AREA_1 ? STR_DA_1_EVENT_FIFO_INFO :
12261227
STR_DA_2_EVENT_FIFO_INFO);
12271228

12281229
json_object_add_value_array(root, data_area, pevent_fifos_object);
@@ -1410,7 +1411,7 @@ int parse_statistics(struct json_object *root, struct nvme_ocp_telemetry_offsets
14101411
__u8 *pstats_offset = NULL;
14111412
int parse_rc = 0;
14121413

1413-
if (poffsets->data_area == 1) {
1414+
if (poffsets->data_area == DATA_AREA_1) {
14141415
__u32 stats_da_1_start = *(__u32 *)(pda1_ocp_header_offset +
14151416
offsetof(struct nvme_ocp_header_in_da1, da1_statistic_start));
14161417
__u32 stats_da_1_size = *(__u32 *)(pda1_ocp_header_offset +
@@ -1422,7 +1423,7 @@ int parse_statistics(struct json_object *root, struct nvme_ocp_telemetry_offsets
14221423

14231424
pstats_offset = pda1_ocp_header_offset + stats_da_1_start_dw;
14241425
statistics_size = stats_da_1_size_dw;
1425-
} else if (poffsets->data_area == 2) {
1426+
} else if (poffsets->data_area == DATA_AREA_2) {
14261427
__u32 stats_da_2_start = *(__u32 *)(pda1_ocp_header_offset +
14271428
offsetof(struct nvme_ocp_header_in_da1, da2_statistic_start));
14281429
__u32 stats_da_2_size = *(__u32 *)(pda1_ocp_header_offset +
@@ -1459,7 +1460,7 @@ int parse_statistics(struct json_object *root, struct nvme_ocp_telemetry_offsets
14591460

14601461
if (root != NULL && pstats_array != NULL) {
14611462
const char *pdata_area =
1462-
(poffsets->data_area == 1 ? STR_DA_1_STATS : STR_DA_2_STATS);
1463+
(poffsets->data_area == DATA_AREA_1 ? STR_DA_1_STATS : STR_DA_2_STATS);
14631464

14641465
json_object_add_value_array(root, pdata_area, pstats_array);
14651466
}
@@ -1509,7 +1510,7 @@ int print_ocp_telemetry_normal(struct ocp_telemetry_parse_options *options)
15091510
//Set DA to 1 and get offsets
15101511
struct nvme_ocp_telemetry_offsets offsets = { 0 };
15111512

1512-
offsets.data_area = 1;// Default DA - DA1
1513+
offsets.data_area = DATA_AREA_1;// Default DA - DA1
15131514

15141515
struct nvme_ocp_telemetry_common_header *ptelemetry_common_header =
15151516
(struct nvme_ocp_telemetry_common_header *) ptelemetry_buffer;
@@ -1562,8 +1563,8 @@ int print_ocp_telemetry_normal(struct ocp_telemetry_parse_options *options)
15621563
}
15631564

15641565
//Set the DA to 2
1565-
if (options->data_area == 2) {
1566-
offsets.data_area = 2;
1566+
if (options->data_area >= DATA_AREA_2) {
1567+
offsets.data_area = DATA_AREA_2;
15671568
fprintf(fp, STR_LINE);
15681569
fprintf(fp, "%s\n", STR_DA_2_STATS);
15691570
fprintf(fp, STR_LINE);
@@ -1622,7 +1623,7 @@ int print_ocp_telemetry_normal(struct ocp_telemetry_parse_options *options)
16221623
//Set DA to 1 and get offsets
16231624
struct nvme_ocp_telemetry_offsets offsets = { 0 };
16241625

1625-
offsets.data_area = 1;
1626+
offsets.data_area = DATA_AREA_1;
16261627

16271628
struct nvme_ocp_telemetry_common_header *ptelemetry_common_header =
16281629
(struct nvme_ocp_telemetry_common_header *) ptelemetry_buffer;
@@ -1671,8 +1672,8 @@ int print_ocp_telemetry_normal(struct ocp_telemetry_parse_options *options)
16711672
}
16721673

16731674
//Set the DA to 2
1674-
if (options->data_area == 2) {
1675-
offsets.data_area = 2;
1675+
if (options->data_area >= DATA_AREA_2) {
1676+
offsets.data_area = DATA_AREA_2;
16761677
printf(STR_LINE);
16771678
printf("%s\n", STR_DA_2_STATS);
16781679
printf(STR_LINE);
@@ -1730,7 +1731,7 @@ int print_ocp_telemetry_json(struct ocp_telemetry_parse_options *options)
17301731
struct nvme_ocp_telemetry_offsets offsets = { 0 };
17311732

17321733
//Set DA to 1 and get offsets
1733-
offsets.data_area = 1;
1734+
offsets.data_area = DATA_AREA_1;
17341735
struct nvme_ocp_telemetry_common_header *ptelemetry_common_header =
17351736
(struct nvme_ocp_telemetry_common_header *) ptelemetry_buffer;
17361737

@@ -1776,9 +1777,9 @@ int print_ocp_telemetry_json(struct ocp_telemetry_parse_options *options)
17761777
return -1;
17771778
}
17781779

1779-
if (options->data_area == 2) {
1780+
if (options->data_area >= DATA_AREA_2) {
17801781
//Set the DA to 2
1781-
offsets.data_area = 2;
1782+
offsets.data_area = DATA_AREA_2;
17821783
//Data Area 2 Statistics
17831784
status = parse_statistics(root, &offsets, NULL);
17841785
if (status != 0) {

0 commit comments

Comments
 (0)