Skip to content

Commit 60733d8

Browse files
jeff-lien-sndkigaw
authored andcommitted
ocp: Fixes to telemetry-string-log command
Added option to specify output-file Fix telemetry-string-log output file initialization Signed-off-by: jeff-lien-sndk <jeff.lien@sandisk.com> Reviewed-by: brandon-paupore-sndk <brandon.paupore@sandisk.com>
1 parent a5741a3 commit 60733d8

File tree

2 files changed

+29
-16
lines changed

2 files changed

+29
-16
lines changed

plugins/ocp/ocp-nvme.c

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1338,14 +1338,16 @@ static int get_telemetry_log_page_data(struct nvme_dev *dev, int tele_type)
13381338
return err;
13391339
}
13401340

1341-
static int get_c9_log_page_data(struct nvme_dev *dev, int print_data, int save_bin)
1341+
static int get_c9_log_page_data(struct nvme_dev *dev,
1342+
int print_data,
1343+
int save_bin,
1344+
const char *output_file)
13421345
{
13431346
int ret = 0;
13441347
__le64 stat_id_str_table_ofst = 0;
13451348
__le64 event_str_table_ofst = 0;
13461349
__le64 vu_event_str_table_ofst = 0;
13471350
__le64 ascii_table_ofst = 0;
1348-
char file_path[PATH_MAX];
13491351

13501352
_cleanup_fd_ int fd = STDIN_FILENO;
13511353

@@ -1404,10 +1406,9 @@ static int get_c9_log_page_data(struct nvme_dev *dev, int print_data, int save_b
14041406
}
14051407

14061408
if (save_bin) {
1407-
sprintf(file_path, DEFAULT_STRING_BIN);
1408-
fd = open(file_path, O_WRONLY | O_CREAT | O_TRUNC, 0666);
1409+
fd = open(output_file, O_WRONLY | O_CREAT | O_TRUNC, 0666);
14091410
if (fd < 0) {
1410-
fprintf(stderr, "Failed to open output file %s: %s!\n", file_path,
1411+
fprintf(stderr, "Failed to open output file %s: %s!\n", output_file,
14111412
strerror(errno));
14121413
return fd;
14131414
}
@@ -1578,7 +1579,8 @@ static int ocp_telemetry_log(int argc, char **argv, struct command *cmd, struct
15781579

15791580
if (!opt.string_log) {
15801581
nvme_show_result("Missing string-log. Fetching from drive...\n");
1581-
err = get_c9_log_page_data(dev, 0, 1); //Pull String log
1582+
/* Pull String log */
1583+
err = get_c9_log_page_data(dev, 0, 1, (const char *)opt.output_file);
15821584
if (err) {
15831585
nvme_show_error("Failed to fetch string-log from the drive.\n");
15841586
goto out;
@@ -2574,7 +2576,9 @@ static int get_dssd_async_event_config(int argc, char **argv, struct command *cm
25742576
static int ocp_telemetry_str_log_format(int argc, char **argv, struct command *cmd,
25752577
struct plugin *plugin);
25762578

2577-
static int get_c9_log_page(struct nvme_dev *dev, char *format)
2579+
static int get_c9_log_page(struct nvme_dev *dev,
2580+
char *format,
2581+
const char *output_file)
25782582
{
25792583
int ret = 0;
25802584
nvme_print_flags_t fmt;
@@ -2585,16 +2589,12 @@ static int get_c9_log_page(struct nvme_dev *dev, char *format)
25852589
return ret;
25862590
}
25872591

2588-
if (fmt == BINARY)
2589-
ret = get_c9_log_page_data(dev, 0, 1);
2590-
else
2591-
ret = get_c9_log_page_data(dev, 0, 0);
2592+
ret = get_c9_log_page_data(dev, 0, 1, output_file);
25922593

2593-
if (!ret) {
2594+
if ((!ret) && (fmt != BINARY))
25942595
ocp_c9_log(log_data, pC9_string_buffer, total_log_page_sz, fmt);
2595-
} else {
2596+
else if (ret)
25962597
fprintf(stderr, "ERROR : OCP : Unable to read C9 data from buffer\n");
2597-
}
25982598

25992599
free(header_data);
26002600
return ret;
@@ -2605,27 +2605,40 @@ static int ocp_telemetry_str_log_format(int argc, char **argv, struct command *c
26052605
{
26062606
struct nvme_dev *dev;
26072607
int ret = 0;
2608+
char file_path[PATH_MAX];
2609+
const char *string_suffix = ".bin";
26082610
const char *desc = "Retrieve telemetry string log format";
2611+
const char *output_file = "Output file name with path;\n"
2612+
"e.g. '-f ./path/name'\n'-f ./path1/path2/';\n"
2613+
"If requested path does not exist, the directory will be newly created.";
26092614

26102615
struct config {
26112616
char *output_format;
2617+
char *output_file;
26122618
};
26132619

26142620
struct config cfg = {
26152621
.output_format = "normal",
2622+
.output_file = NULL,
26162623
};
26172624

26182625
OPT_ARGS(opts) = {
26192626
OPT_FMT("output-format", 'o', &cfg.output_format,
26202627
"output Format:normal|json|binary"),
2628+
OPT_FILE("output-file", 'f', &cfg.output_file, output_file),
26212629
OPT_END()
26222630
};
26232631

26242632
ret = parse_and_open(&dev, argc, argv, desc, opts);
26252633
if (ret)
26262634
return ret;
26272635

2628-
ret = get_c9_log_page(dev, cfg.output_format);
2636+
if (cfg.output_file != NULL)
2637+
sprintf(file_path, "%s%s", cfg.output_file, string_suffix);
2638+
else
2639+
sprintf(file_path, "%s", DEFAULT_STRING_BIN);
2640+
2641+
ret = get_c9_log_page(dev, cfg.output_format, file_path);
26292642
if (ret)
26302643
fprintf(stderr, "ERROR : OCP : Failure reading the C9 Log Page, ret = %d\n", ret);
26312644

plugins/ocp/ocp-nvme.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#if !defined(OCP_NVME) || defined(CMD_HEADER_MULTI_READ)
1212
#define OCP_NVME
1313

14-
#define OCP_PLUGIN_VERSION "2.12.0"
14+
#define OCP_PLUGIN_VERSION "2.15.1"
1515
#include "cmd.h"
1616

1717
PLUGIN(NAME("ocp", "OCP cloud SSD extensions", OCP_PLUGIN_VERSION),

0 commit comments

Comments
 (0)