Skip to content

Commit ceaa310

Browse files
lgdacunhigaw
authored andcommitted
plugins/solidigm: parse telemetry error message improvements.
Improved parameter checking. Improved error message and return codes. Better JSON parser error message Signed-off-by: Leonardo da Cunha <[email protected]>
1 parent 7567f01 commit ceaa310

1 file changed

Lines changed: 37 additions & 38 deletions

File tree

plugins/solidigm/solidigm-telemetry.c

Lines changed: 37 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ static int read_file2buffer(char *file_name, char **buffer, size_t *length)
4949
struct config {
5050
__u32 host_gen;
5151
bool ctrl_init;
52-
int data_area;
52+
__u8 data_area;
5353
char *cfg_file;
5454
char *binary_file;
5555
char *jq_filter;
@@ -92,7 +92,7 @@ int solidigm_get_telemetry_log(int argc, char **argv, struct command *acmd, stru
9292
OPT_ARGS(opts) = {
9393
OPT_UINT("host-generate", 'g', &cfg.host_gen, hgen),
9494
OPT_FLAG("controller-init", 'c', &cfg.ctrl_init, cgen),
95-
OPT_UINT("data-area", 'd', &cfg.data_area, dgen),
95+
OPT_BYTE("data-area", 'd', &cfg.data_area, dgen),
9696
OPT_FILE("config-file", 'j', &cfg.cfg_file, cfile),
9797
OPT_FILE("source-file", 's', &cfg.binary_file, sfile),
9898
OPT_STR("jq-filter", 'q', &cfg.jq_filter, jqfilt),
@@ -103,57 +103,63 @@ int solidigm_get_telemetry_log(int argc, char **argv, struct command *acmd, stru
103103
int err = argconfig_parse(argc, argv, desc, opts);
104104

105105
if (err) {
106-
nvme_show_status(err);
107106
return err;
108107
}
109-
110108
/* When not selected on the command line, get minimum data area required */
111109
if (!argconfig_parse_seen(opts, "data-area"))
112110
cfg.data_area = argconfig_parse_seen(opts, "config-file") ? 3 : 1;
113111

112+
if (cfg.data_area < 1 || cfg.data_area > 4) {
113+
errno = EINVAL;
114+
nvme_show_perror("data-area = '%d'", cfg.data_area);
115+
return -errno;
116+
}
117+
114118
has_binary_file = argconfig_parse_seen(opts, "source-file");
115119
if (has_binary_file) {
116120
// If a binary file is provided, we don't want to open a device.
117121
// GNU getopt() permutes the contents of argv as it scans,
118122
// so that eventually all the nonoptions are at the end.
119123
if (argc > optind) {
120124
errno = EINVAL;
121-
err = -errno;
122-
nvme_show_status(err);
123-
return err;
125+
nvme_show_perror(
126+
"Device path not allowed when using --source-file");
127+
return -errno;
124128
}
125129
err = read_file2buffer(cfg.binary_file, (char **)&tlog, &tl.log_size);
126130
} else {
127131
err = parse_and_open(&ctx, &hdl, argc, argv, desc, opts);
128132
}
129-
if (err) {
130-
nvme_show_status(err);
131-
return err;
133+
if (err < 0) {
134+
errno = -err;
135+
nvme_show_perror("Error");
132136
}
137+
if (err)
138+
return err;
133139

134140
if (cfg.host_gen > 1) {
135-
SOLIDIGM_LOG_WARNING("Invalid host-generate value '%d'", cfg.host_gen);
136-
err = -EINVAL;
137-
nvme_show_status(err);
138-
return err;
141+
errno = EINVAL;
142+
nvme_show_perror("host-generate = '%d'", cfg.host_gen);
143+
return -errno;
139144
}
140145

141146
if (argconfig_parse_seen(opts, "config-file")) {
142147
_cleanup_free_ char *conf_str = NULL;
143148
size_t length = 0;
149+
enum json_tokener_error jerr;
144150

145151
err = read_file2buffer(cfg.cfg_file, &conf_str, &length);
146152
if (err) {
147-
nvme_show_status(err);
153+
nvme_show_perror("config-file %s", cfg.cfg_file);
148154
return err;
149155
}
150-
configuration = json_tokener_parse(conf_str);
156+
configuration = json_tokener_parse_verbose(conf_str, &jerr);
151157
if (!configuration) {
152-
SOLIDIGM_LOG_WARNING(
153-
"Failed to parse JSON configuration file %s",
154-
cfg.cfg_file);
155-
err = EINVAL;
156-
return err;
158+
nvme_show_error(
159+
"Failed to parse JSON file %s: %s",
160+
cfg.cfg_file,
161+
json_tokener_error_desc(jerr));
162+
return -EINVAL;
157163
}
158164
tl.configuration = configuration;
159165
}
@@ -164,13 +170,8 @@ int solidigm_get_telemetry_log(int argc, char **argv, struct command *acmd, stru
164170
__u8 mdts = 0;
165171

166172
err = nvme_get_telemetry_max(hdl, NULL, &max_data_tx);
167-
if (err < 0) {
168-
SOLIDIGM_LOG_WARNING("identify_ctrl: %s",
169-
nvme_strerror(errno));
170-
return err;
171-
} else if (err > 0) {
172-
nvme_show_status(err);
173-
SOLIDIGM_LOG_WARNING("Failed to acquire identify ctrl %d!", err);
173+
if (err) {
174+
nvme_show_err("identify_ctrl", err);
174175
return err;
175176
}
176177
power2 = max_data_tx / NVME_LOG_PAGE_PDU_SIZE;
@@ -181,13 +182,8 @@ int solidigm_get_telemetry_log(int argc, char **argv, struct command *acmd, stru
181182

182183
err = sldgm_dynamic_telemetry(hdl, cfg.host_gen, cfg.ctrl_init, true,
183184
mdts, cfg.data_area, &tlog, &tl.log_size);
184-
if (err < 0) {
185-
SOLIDIGM_LOG_WARNING("get-telemetry-log: %s",
186-
nvme_strerror(errno));
187-
return err;
188-
} else if (err > 0) {
189-
nvme_show_status(err);
190-
SOLIDIGM_LOG_WARNING("Failed to acquire telemetry log %d!", err);
185+
if (err) {
186+
nvme_show_err("get-telemetry-log", err);
191187
return err;
192188
}
193189
}
@@ -221,18 +217,21 @@ int solidigm_get_telemetry_log(int argc, char **argv, struct command *acmd, stru
221217
if (err != 0)
222218
err = -EINVAL;
223219
} else {
224-
SOLIDIGM_LOG_WARNING(
220+
errno = ENOENT;
221+
nvme_show_perror(
225222
"Failed to execute jq command");
226223
err = -ENOENT;
227224
}
228225
} else {
229-
SOLIDIGM_LOG_WARNING(
226+
errno = EINVAL;
227+
nvme_show_perror(
230228
"jq filter entry '%s' is not a valid string",
231229
cfg.jq_filter);
232230
err = -EINVAL;
233231
}
234232
} else {
235-
SOLIDIGM_LOG_WARNING(
233+
errno = ENOENT;
234+
nvme_show_perror(
236235
"jq filter entry '%s' not found in configuration file",
237236
cfg.jq_filter);
238237
err = -ENOENT;

0 commit comments

Comments
 (0)