nvme: Remove duplicated variables#3080
Conversation
already defined as static const char variable Signed-off-by: Steven Seungcheol Lee <sc108.lee@samsung.com>
|
Hmm, it is a bit odd that we have some of the variables as globals and some not. Can't we come up with something more sane in the long run. Any ideas? |
|
I agree. To avoid confilct, do we need manage all argments set in global? rough idea use |
|
The commands in While I like to reduce duplication, I think here it would be contra productive as it introduces even more abstractions from what is happening. E.g. the struct config {
char *file_name;
__u32 host_gen;
bool ctrl_init;
int data_area;
bool rae;
__u8 mcda;
};
struct config cfg = {
.file_name = NULL,
.host_gen = 1,
.ctrl_init = false,
.data_area = 3,
.rae = false,
.mcda = 0xff,
};
NVME_ARGS(opts,
OPT_FILE("output-file", 'O', &cfg.file_name, fname),
OPT_UINT("host-generate", 'g', &cfg.host_gen, hgen),
OPT_FLAG("controller-init", 'c', &cfg.ctrl_init, cgen),
OPT_UINT("data-area", 'd', &cfg.data_area, dgen),
OPT_FLAG("rae", 'r', &cfg.rae, rae),
OPT_BYTE("mcda", 'm', &cfg.mcda, mcda));
err = parse_and_open(&ctx, &hdl, argc, argv, desc, opts);
if (err)
return err;
err = validate_output_format(nvme_cfg.output_format, &flags);
if (err < 0) {
nvme_show_error("Invalid output format");
return err;
}I think for any casual reader, it's pretty clear what's happening and it's easy to extend. Having more abstraction is making this more difficult. The main objective is always making the code maintainable in the log run. Anyway, the only thing which is annoying is the help string. So a bunch of function use the global defined strings and some have local defined strings. Maybe we should just move all those strings to the global section? If we do this, then I would suggest to introduce a common prefix for these variables, so it's also clear what they are. |
|
I've done some cleanups in the command parser area. It should be a bit more consistent. So I think it's time to look at the help text strings. So the command itself use e.g. these here would be prefixed with const char *fname = "File name to save raw binary, includes header";
const char *hgen = "Have the host tell the controller to generate the report";
const char *cgen = "Gather report generated by the controller.";
const char *dgen = "Pick which telemetry data area to report. Default is 3 to fetch areas 1-3. Valid options are 1, 2, 3, 4.";
const char *mcda = "Host-init Maximum Created Data Area. Valid options are 0 ~ 4 "
"If given, This option will override dgen. 0 : controller determines data area";WDYT? |
already defined as static const char variable