nvme-cli: Introduce nvme-status mapping with errno
v7 cover nvme-cli: Introduce nvme-status mapping with errno
Hi Keith,
Now it's v7 patchset for the nvme-status mapping with errno. Chaitanya has reviewed for the first five patches, and Sagi has suggested to return an error for a case that numrec is different. The 6th and 7th patch will make what Sagi's said.
This patchset introduces nvme-status module to manage mapping relationships between nvme error status and errno. It cannot be directly mapped in 1:1, but we can figure out what kind of errors happended by the return value of nvme-cli.
NVMe status fields are 16bits to indicate, but UNIX return value from main() will be parsed in 8bits so that we need to do something about return value to indicate nvme error status.
This patch series has been tested with:
- nvme pcie device controller/namespaces
- nvme loop target with nvme-fabrics
The branch on github can be found at:
https://github.com/minwooim/nvme-cli.git for-1.9/return-negative-errno-v7
Please pick this series.
Thanks,
Changes to previous V6:
- Added Reviewed-by: tags of Chaitanya for the first and second commmits.
- Added a new command(6th) which makes it return an error when the fabrics discovery retry(10 times) exhausted.
- Sagi has suggested that when numrec is different from the expected value, then it should return an error. The 7th patch will do it.
Changes to previous V5:
- The first patch has been updated being without an whitespace in front of new label("ret") in a function. The other lables added followed the existing style in where it belongs to.
The default style would be great to follow the kernel style which is non-space label, as suggested by Chaitanya.
- The second patch has been updated to have "out" named label just like the others in that file(fabrics).
- No functional changed in this version 6. Only style change has been applied.
Changes to previous V4:
- Add the first three patches before introducing errno mapping module.
Changes to previous V3:
- Fix to return 0 when given error is 0 which means success. (Chaitanya)
Changes to previous V2:
- do not overwrite the err local variable, instead returning the converted errno mapped directly.
- return ECOMM in case of linux internal err which indicates the negative values from in the middle of the subcommand.
Changes to previous V1:
- make switch-case inline in nvme-status (Chaitanya)
Minwoo Im (7):
nvme: Do not return in the middle of the subcommand
fabrics: Do not return in the middle of the subcommand
nvme: Return negative error value for internal errors
nvme-status: Introduce nvme status module to map errno
nvme: Return errno mapped for nvme error status
fabrics: return error when discovery retry exhausted
fabrics: Return errno mapped for fabrics error status
Makefile | 3 +- fabrics.c | 67 +++-- linux/nvme.h | 6 + nvme-status.c | 155 +++++++++++ nvme-status.h | 14 + nvme.c | 701 ++++++++++++++++++++++++++++++-------------------- 6 files changed, 641 insertions(+), 305 deletions(-) create mode 100644 nvme-status.c create mode 100644 nvme-status.h
Signature · 1 line
2.21.0
PATCH v7 1/7 nvme: Do not return in the middle of the subcommand
To make nvme-cli subcommand return a mapped errno value to main(), it should return the error status in a single place because it would be great if the return statements and free operations are in an one shot place.
This patch makes all the subcommands in nvme module return the error which means internal error which should be in negative and nvme error status which is in positive at the end of the subcommand.
Most of the changed parts are file descriptors which is returned from parse_and_open() function. The "fd" could be in a negative value so that it needs to be mapped to a uniformed errno value which will be applied by the next patches.
--- nvme.c | 427 +++++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 278 insertions(+), 149 deletions(-)
nvme.c +278 -149
@@ -193,8 +193,10 @@ static int get_smart_log(int argc, char **argv, struct command *cmd, struct plug }; fd =parse_and_open (argc, argv, desc, command_line_options, &cfg,sizeof (cfg)); -if (fd <0 ) -return fd; +if (fd <0 ) { + err = fd; + goto ret; + } fmt =validate_output_format (cfg.output_format);if (fmt <0 ) {
@@ -220,6 +222,7 @@ static int get_smart_log(int argc, char **argv, struct command *cmd, struct plug close_fd:close (fd); + ret:return err; }
@@ -249,8 +252,10 @@ static int get_ana_log(int argc, char **argv, struct command *cmd, }; fd =parse_and_open (argc, argv, desc, command_line_options,NULL ,0 ); -if (fd <0 ) -return fd; +if (fd <0 ) { + err = fd; + goto ret; + } fmt =validate_output_format (cfg.output_format);if (fmt <0 ) {
@@ -292,6 +297,7 @@ static int get_ana_log(int argc, char **argv, struct command *cmd,free (ana_log); close_fd:close (fd); +ret:return err; }
@@ -330,8 +336,10 @@ static int get_telemetry_log(int argc, char **argv, struct command *cmd, struct }; fd =parse_and_open (argc, argv, desc, command_line_options, &cfg,sizeof (cfg)); -if (fd <0 ) -return fd; +if (fd <0 ) { + err = fd; + goto ret; + }if (!cfg.file_name) {fprintf (stderr,"Please provide an output file!\n" );
@@ -419,6 +427,7 @@ static int get_telemetry_log(int argc, char **argv, struct command *cmd, structfree (page_log); close_fd:close (fd); + ret:return err; }
@@ -449,8 +458,10 @@ static int get_endurance_log(int argc, char **argv, struct command *cmd, struct }; fd =parse_and_open (argc, argv, desc, command_line_options, &cfg,sizeof (cfg)); -if (fd <0 ) -return fd; +if (fd <0 ) { + err = fd; + goto ret; + } fmt =validate_output_format (cfg.output_format);if (fmt <0 ) {
@@ -473,6 +484,7 @@ static int get_endurance_log(int argc, char **argv, struct command *cmd, struct close_fd:close (fd); + ret:return err; }
@@ -505,8 +517,10 @@ static int get_effects_log(int argc, char **argv, struct command *cmd, struct pl }; fd =parse_and_open (argc, argv, desc, command_line_options, &cfg,sizeof (cfg)); -if (fd <0 ) -return fd; +if (fd <0 ) { + err = fd; + goto ret; + } fmt =validate_output_format (cfg.output_format);if (fmt <0 ) {
@@ -535,6 +549,7 @@ static int get_effects_log(int argc, char **argv, struct command *cmd, struct pl close_fd:close (fd); + ret:return err; }
@@ -567,8 +582,10 @@ static int get_error_log(int argc, char **argv, struct command *cmd, struct plug }; fd =parse_and_open (argc, argv, desc, command_line_options, &cfg,sizeof (cfg)); -if (fd <0 ) -return fd; +if (fd <0 ) { + err = fd; + goto ret; + } fmt =validate_output_format (cfg.output_format);if (fmt <0 ) {
@@ -619,6 +636,7 @@ static int get_error_log(int argc, char **argv, struct command *cmd, struct plug close_fd:close (fd); + ret:return err; }
@@ -646,8 +664,10 @@ static int get_fw_log(int argc, char **argv, struct command *cmd, struct plugin }; fd =parse_and_open (argc, argv, desc, command_line_options, &cfg,sizeof (cfg)); -if (fd <0 ) -return fd; +if (fd <0 ) { + err = fd; + goto ret; + } fmt =validate_output_format (cfg.output_format);if (fmt <0 ) {
@@ -673,6 +693,7 @@ static int get_fw_log(int argc, char **argv, struct command *cmd, struct plugin close_fd:close (fd); + ret:return err; }
@@ -701,8 +722,10 @@ static int get_changed_ns_list_log(int argc, char **argv, struct command *cmd, s }; fd =parse_and_open (argc, argv, desc, command_line_options, &cfg,sizeof (cfg)); -if (fd <0 ) -return fd; +if (fd <0 ) { + err = fd; + goto ret; + } fmt =validate_output_format (cfg.output_format);if (fmt <0 ) {
@@ -728,7 +751,7 @@ static int get_changed_ns_list_log(int argc, char **argv, struct command *cmd, s close_fd:close (fd); - + ret:return err; }
@@ -780,8 +803,10 @@ static int get_log(int argc, char **argv, struct command *cmd, struct plugin *pl }; fd =parse_and_open (argc, argv, desc, command_line_options, &cfg,sizeof (cfg)); -if (fd <0 ) -return fd; +if (fd <0 ) { + err = fd; + goto ret; + }if (cfg.aen) { cfg.log_len =4096 ;
@@ -828,6 +853,7 @@ static int get_log(int argc, char **argv, struct command *cmd, struct plugin *pl close_fd:close (fd); + ret:return err; }
@@ -860,8 +886,10 @@ static int sanitize_log(int argc, char **argv, struct command *command, struct p }; fd =parse_and_open (argc, argv, desc, command_line_options, &cfg,sizeof (cfg)); -if (fd <0 ) -return fd; +if (fd <0 ) { + ret = fd; + goto ret; + } fmt =validate_output_format (cfg.output_format);if (fmt <0 ) {
@@ -890,7 +918,7 @@ static int sanitize_log(int argc, char **argv, struct command *command, struct p close_fd:close (fd); - + ret:return ret; }
@@ -919,8 +947,10 @@ static int list_ctrl(int argc, char **argv, struct command *cmd, struct plugin * }; fd =parse_and_open (argc, argv, desc, command_line_options, &cfg,sizeof (cfg)); -if (fd <0 ) -return fd; +if (fd <0 ) { + err = fd; + goto ret; + }if (posix_memalign ((void *)&cntlist,getpagesize (),0x1000 )) {fprintf (stderr,"can not allocate controller list payload\n" );
@@ -944,7 +974,7 @@ static int list_ctrl(int argc, char **argv, struct command *cmd, struct plugin * close_fd:close (fd); - +ret:return err; }
@@ -973,8 +1003,10 @@ static int list_ns(int argc, char **argv, struct command *cmd, struct plugin *pl }; fd =parse_and_open (argc, argv, desc, command_line_options, &cfg,sizeof (cfg)); -if (fd <0 ) -return fd; +if (fd <0 ) { + err = fd; + goto ret; + }if (!cfg.namespace_id) { err = -EINVAL ;
@@ -996,7 +1028,7 @@ static int list_ns(int argc, char **argv, struct command *cmd, struct plugin *pl close_fd:close (fd); - +ret:return err; }
@@ -1041,8 +1073,10 @@ static int delete_ns(int argc, char **argv, struct command *cmd, struct plugin * }; fd =parse_and_open (argc, argv, desc, command_line_options, &cfg,sizeof (cfg)); -if (fd <0 ) -return fd; +if (fd <0 ) { + err = fd; + goto ret; + }if (S_ISBLK (nvme_stat.st_mode)) { cfg.namespace_id =get_nsid (fd);
@@ -1068,7 +1102,7 @@ static int delete_ns(int argc, char **argv, struct command *cmd, struct plugin * close_fd:close (fd); - + ret:return err; }
@@ -1096,8 +1130,10 @@ static int nvme_attach_ns(int argc, char **argv, int attach, const char *desc, s }; fd =parse_and_open (argc, argv, desc, command_line_options, &cfg,sizeof (cfg)); -if (fd <0 ) -return fd; +if (fd <0 ) { + err = fd; + goto ret; + }if (!cfg.namespace_id) { fprintf(stderr, "%s: namespace-id parameter required\n",
@@ -1133,7 +1169,7 @@ static int nvme_attach_ns(int argc, char **argv, int attach, const char *desc, s close_fd:close (fd); - + ret:return err; }
@@ -1203,8 +1239,10 @@ static int create_ns(int argc, char **argv, struct command *cmd, struct plugin * }; fd =parse_and_open (argc, argv, desc, command_line_options, &cfg,sizeof (cfg)); -if (fd <0 ) -return fd; +if (fd <0 ) { + err = fd; + goto ret; + }if (cfg.flbas !=0xff && cfg.bs !=0x00 ) { fprintf(stderr,
@@ -1261,7 +1299,7 @@ static int create_ns(int argc, char **argv, struct command *cmd, struct plugin * close_fd:close (fd); - +ret:return err; }
@@ -1699,7 +1737,7 @@ static int list_subsys(int argc, char **argv, struct command *cmd, ret =argconfig_parse (argc, argv, desc, opts, &cfg,sizeof (cfg));if (ret <0 ) -return ret; + goto ret; devicename =NULL ;if (optind < argc) {
@@ -1711,29 +1749,30 @@ static int list_subsys(int argc, char **argv, struct command *cmd, &cfg.namespace_id) != 2) {fprintf (stderr,"%s is not a NVMe namespace device\n" , argv[optind]); -return -EINVAL ; + ret = -EINVAL ; + goto ret; }sprintf (path,"/sys/block/%s/device" , devicename); subsysnqn =get_nvme_subsnqn (path);if (!subsysnqn) {fprintf (stderr,"Cannot read subsys NQN from %s\n" , devicename); -return -EINVAL ; + ret = -EINVAL ; + goto ret; } optind++; }if (ret <0 ) {argconfig_print_help (desc, opts); -if (subsysnqn) -free (subsysnqn); -return ret; + goto free; } fmt =validate_output_format (cfg.output_format);if (fmt !=JSON && fmt !=NORMAL ) {if (subsysnqn)free (subsysnqn); -return -EINVAL ; + ret = -EINVAL ; + goto free; } slist =get_subsys_list (&subcnt, subsysnqn, cfg.namespace_id);
@@ -1744,8 +1783,11 @@ static int list_subsys(int argc, char **argv, struct command *cmd,show_nvme_subsystem_list (slist, subcnt);free_subsys_list (slist, subcnt); +free:if (subsysnqn)free (subsysnqn); + +ret:return ret; }
@@ -1817,17 +1859,20 @@ static int list(int argc, char **argv, struct command *cmd, struct plugin *plugi ret =argconfig_parse (argc, argv, desc, opts, &cfg,sizeof (cfg));if (ret <0 ) -return ret; + goto ret; fmt =validate_output_format (cfg.output_format); -if (fmt !=JSON && fmt !=NORMAL ) -return -EINVAL ; +if (fmt !=JSON && fmt !=NORMAL ) { + ret = -EINVAL ; + goto ret; + } n =scandir (dev, &devices, scan_dev_filter, alphasort);if (n <0 ) {fprintf (stderr,"no NVMe device(s) detected.\n" ); -return n; + ret = n; + goto ret; } list_items =calloc (n,sizeof (*list_items));
@@ -1875,7 +1920,7 @@ static int list(int argc, char **argv, struct command *cmd, struct plugin *plugifor (i =0 ; i < n; i++)free (devices[i]);free (devices); - + ret:return ret; }
@@ -1913,8 +1958,10 @@ int __id_ctrl(int argc, char **argv, struct command *cmd, struct plugin *plugin, }; fd =parse_and_open (argc, argv, desc, command_line_options, &cfg,sizeof (cfg)); -if (fd <0 ) -return fd; +if (fd <0 ) { + err = fd; + goto ret; + } fmt =validate_output_format (cfg.output_format);if (fmt <0 ) {
@@ -1949,7 +1996,7 @@ int __id_ctrl(int argc, char **argv, struct command *cmd, struct plugin *plugin, close_fd:close (fd); - + ret:return err; }
@@ -1986,8 +2033,10 @@ static int ns_descs(int argc, char **argv, struct command *cmd, struct plugin *p }; fd =parse_and_open (argc, argv, desc, command_line_options, &cfg,sizeof (cfg)); -if (fd <0 ) -return fd; +if (fd <0 ) { + err = fd; + goto ret; + } fmt =validate_output_format (cfg.output_format);if (fmt <0 ) {
@@ -2030,7 +2079,7 @@ static int ns_descs(int argc, char **argv, struct command *cmd, struct plugin *p close_fd:close (fd); - + ret:return err; }
@@ -2074,8 +2123,10 @@ static int id_ns(int argc, char **argv, struct command *cmd, struct plugin *plug }; fd =parse_and_open (argc, argv, desc, command_line_options, &cfg,sizeof (cfg)); -if (fd <0 ) -return fd; +if (fd <0 ) { + err = fd; + goto ret; + } fmt =validate_output_format (cfg.output_format);if (fmt <0 ) {
@@ -2117,7 +2168,7 @@ static int id_ns(int argc, char **argv, struct command *cmd, struct plugin *plug close_fd:close (fd); - + ret:return err; }
@@ -2148,8 +2199,10 @@ static int id_nvmset(int argc, char **argv, struct command *cmd, struct plugin * }; fd =parse_and_open (argc, argv, desc, command_line_options, &cfg,sizeof (cfg)); -if (fd <0 ) -return fd; +if (fd <0 ) { + err = fd; + goto ret; + } fmt =validate_output_format (cfg.output_format);if (fmt <0 ) {
@@ -2173,15 +2226,15 @@ static int id_nvmset(int argc, char **argv, struct command *cmd, struct plugin *else perror ("identify nvm set list" ); - close_fd: +close_fd:close (fd); - +ret:return err; }static int get_ns_id (int argc,char **argv,struct command *cmd,struct plugin *plugin) { -int nsid, fd; +int err =0 , nsid, fd;const char *desc ="Get namespce ID of a the block device." ; const struct argconfig_commandline_options command_line_options[] = {
@@ -2189,18 +2242,23 @@ static int get_ns_id(int argc, char **argv, struct command *cmd, struct plugin * }; fd =parse_and_open (argc, argv, desc, command_line_options,NULL ,0 ); -if (fd <0 ) -return fd; +if (fd <0 ) { + err = fd; + goto ret; + } + nsid =nvme_get_nsid (fd);if (nsid <=0 ) {perror (devicename); -close (fd); -return errno; + err = errno; + goto close_fd; }printf ("%s: namespace-id:%d\n" , devicename, nsid); + close_fd:close (fd); -return 0 ; + ret: +return err; }static int virtual_mgmt (int argc,char **argv,struct command *cmd,struct plugin *plugin)
@@ -2248,8 +2306,10 @@ static int virtual_mgmt(int argc, char **argv, struct command *cmd, struct plugi }; fd =parse_and_open (argc, argv, desc, command_line_options, &cfg,sizeof (cfg)); -if (fd <0 ) -return fd; +if (fd <0 ) { + err = fd; + goto ret; + } cfg.cdw10 = cfg.cntlid <<16 ; cfg.cdw10 = cfg.cdw10 | (cfg.rt <<8 );
@@ -2264,6 +2324,7 @@ static int virtual_mgmt(int argc, char **argv, struct command *cmd, struct plugiperror ("virt-mgmt" );close (fd); +ret:return err; }
@@ -2301,8 +2362,10 @@ static int list_secondary_ctrl(int argc, char **argv, struct command *cmd, struc }; fd =parse_and_open (argc, argv, desc, command_line_options, &cfg,sizeof (cfg)); -if (fd <0 ) -return fd; +if (fd <0 ) { + err = fd; + goto ret; + } fmt =validate_output_format (cfg.output_format);if (fmt <0 ) {
@@ -2340,7 +2403,7 @@ static int list_secondary_ctrl(int argc, char **argv, struct command *cmd, struc close_fd:close (fd); - +ret:return err; }
@@ -2374,8 +2437,10 @@ static int device_self_test(int argc, char **argv, struct command *cmd, struct p }; fd =parse_and_open (argc, argv, desc, command_line_options, &cfg,sizeof (cfg)); -if (fd <0 ) -return fd; +if (fd <0 ) { + err = fd; + goto ret; + } err =nvme_self_test_start (fd, cfg.namespace_id, cfg.cdw10);if (!err) {
@@ -2389,6 +2454,7 @@ static int device_self_test(int argc, char **argv, struct command *cmd, struct pperror ("Device self-test" );close (fd); + ret:return err; }
@@ -2414,8 +2480,10 @@ static int self_test_log(int argc, char **argv, struct command *cmd, struct plug }; fd =parse_and_open (argc, argv, desc, command_line_options, &cfg,sizeof (cfg)); -if (fd <0 ) -return fd; +if (fd <0 ) { + err = fd; + goto ret; + } fmt =validate_output_format (cfg.output_format);if (fmt <0 ) {
@@ -2444,7 +2512,7 @@ static int self_test_log(int argc, char **argv, struct command *cmd, struct plug close_fd:close (fd); - + ret:return err; }
@@ -2500,8 +2568,10 @@ static int get_feature(int argc, char **argv, struct command *cmd, struct plugin }; fd =parse_and_open (argc, argv, desc, command_line_options, &cfg,sizeof (cfg)); -if (fd <0 ) -return fd; +if (fd <0 ) { + err = fd; + goto ret; + }if (cfg.sel >7 ) {fprintf (stderr,"invalid 'select' param:%d\n" , cfg.sel);
@@ -2575,7 +2645,7 @@ static int get_feature(int argc, char **argv, struct command *cmd, struct plugin close_fd:close (fd); - + ret:return err; }
@@ -2617,8 +2687,10 @@ static int fw_download(int argc, char **argv, struct command *cmd, struct plugin }; fd =parse_and_open (argc, argv, desc, command_line_options, &cfg,sizeof (cfg)); -if (fd <0 ) -return fd; +if (fd <0 ) { + err = fd; + goto ret; + } fw_fd =open (cfg.fw,O_RDONLY ); cfg.offset <<=2 ;
@@ -2680,7 +2752,7 @@ static int fw_download(int argc, char **argv, struct command *cmd, struct pluginclose (fw_fd); close_fd:close (fd); - + ret:return err; }
@@ -2726,8 +2798,10 @@ static int fw_commit(int argc, char **argv, struct command *cmd, struct plugin * }; fd =parse_and_open (argc, argv, desc, command_line_options, &cfg,sizeof (cfg)); -if (fd <0 ) -return fd; +if (fd <0 ) { + err = fd; + goto ret; + }if (cfg.slot >7 ) {fprintf (stderr,"invalid slot:%d\n" , cfg.slot);
@@ -2773,7 +2847,7 @@ static int fw_commit(int argc, char **argv, struct command *cmd, struct plugin * close_fd:close (fd); - + ret:return err; }
@@ -2787,21 +2861,22 @@ static int subsystem_reset(int argc, char **argv, struct command *cmd, struct pl }; fd =parse_and_open (argc, argv, desc, command_line_options,NULL ,0 ); -if (fd <0 ) -return fd; +if (fd <0 ) { + err = fd; + goto ret; + } err =nvme_subsystem_reset (fd);if (err <0 ) { -close (fd);if (errno ==ENOTTY )fprintf (stderr,"Subsystem-reset: NVM Subsystem Reset not supported.\n" );else perror ("Subsystem-reset" ); -return errno; }close (fd); +ret:return err; }
@@ -2815,17 +2890,17 @@ static int reset(int argc, char **argv, struct command *cmd, struct plugin *plug }; fd =parse_and_open (argc, argv, desc, command_line_options,NULL ,0 ); -if (fd <0 ) -return fd; +if (fd <0 ) { + err = fd; + goto ret; + } err =nvme_reset_controller (fd); -if (err <0 ) { -close (fd); +if (err <0 )perror ("Reset" ); -return errno; - }close (fd); +ret:return err; }
@@ -2839,17 +2914,17 @@ static int ns_rescan(int argc, char **argv, struct command *cmd, struct plugin * }; fd =parse_and_open (argc, argv, desc, command_line_options,NULL ,0 ); -if (fd <0 ) -return fd; +if (fd <0 ) { + err = fd; + goto ret; + } err =nvme_ns_rescan (fd); -if (err <0 ) { -close (fd); +if (err <0 )perror ("Namespace Rescan" ); -return errno; - }close (fd); +ret:return err; }
@@ -2895,8 +2970,10 @@ static int sanitize(int argc, char **argv, struct command *cmd, struct plugin *p }; fd =parse_and_open (argc, argv, desc, command_line_options,NULL ,0 ); -if (fd <0 ) -return fd; +if (fd <0 ) { + ret = fd; + goto ret; + }switch (cfg.sanact) {case NVME_SANITIZE_ACT_CRYPTO_ERASE :
@@ -2941,7 +3018,7 @@ static int sanitize(int argc, char **argv, struct command *cmd, struct plugin *p close_fd:close (fd); - + ret:return ret; }
@@ -2973,8 +3050,10 @@ static int show_registers(int argc, char **argv, struct command *cmd, struct plu }; fd =parse_and_open (argc, argv, desc, command_line_options, &cfg,sizeof (cfg)); -if (fd <0 ) -return fd; +if (fd <0 ) { + err = fd; + goto ret; + } fmt =validate_output_format (cfg.output_format);if (fmt <0 ) {
@@ -3014,7 +3093,7 @@ static int show_registers(int argc, char **argv, struct command *cmd, struct plu close_fd:close (fd); - + ret:return err; }
@@ -3046,8 +3125,10 @@ static int get_property(int argc, char **argv, struct command *cmd, struct plugi }; fd =parse_and_open (argc, argv, desc, command_line_options, &cfg,sizeof (cfg)); -if (fd <0 ) -return fd; +if (fd <0 ) { + err = fd; + goto ret; + }if (cfg.offset ==-1 ) {fprintf (stderr,"offset required param" );
@@ -3066,7 +3147,7 @@ static int get_property(int argc, char **argv, struct command *cmd, struct plugi close_fd:close (fd); - + ret:return err; }
@@ -3095,8 +3176,10 @@ static int set_property(int argc, char **argv, struct command *cmd, struct plugi }; fd =parse_and_open (argc, argv, desc, command_line_options, &cfg,sizeof (cfg)); -if (fd <0 ) -return fd; +if (fd <0 ) { + err = fd; + goto ret; + }if (cfg.offset ==-1 ) {fprintf (stderr,"offset required param" );
@@ -3121,7 +3204,7 @@ static int set_property(int argc, char **argv, struct command *cmd, struct plugi close_fd:close (fd); - + ret:return err; }
@@ -3181,8 +3264,10 @@ static int format(int argc, char **argv, struct command *cmd, struct plugin *plu }; fd =parse_and_open (argc, argv, desc, command_line_options, &cfg,sizeof (cfg)); -if (fd <0 ) -return fd; +if (fd <0 ) { + err = fd; + goto ret; + }if (cfg.lbaf !=0xff && cfg.bs !=0 ) { fprintf(stderr,
@@ -3282,7 +3367,7 @@ static int format(int argc, char **argv, struct command *cmd, struct plugin *plu close_fd:close (fd); - + ret:return err; }
@@ -3340,8 +3425,10 @@ static int set_feature(int argc, char **argv, struct command *cmd, struct plugin }; fd =parse_and_open (argc, argv, desc, command_line_options, &cfg,sizeof (cfg)); -if (fd <0 ) -return fd; +if (fd <0 ) { + err = fd; + goto ret; + }if (!cfg.feature_id) {fprintf (stderr,"feature-id required param\n" );
@@ -3402,6 +3489,7 @@ static int set_feature(int argc, char **argv, struct command *cmd, struct pluginfree (buf); close_fd:close (fd); + ret:return err; }
@@ -3451,8 +3539,10 @@ static int sec_send(int argc, char **argv, struct command *cmd, struct plugin *p }; fd =parse_and_open (argc, argv, desc, command_line_options, &cfg,sizeof (cfg)); -if (fd <0 ) -return fd; +if (fd <0 ) { + err = fd; + goto ret; + } sec_fd =open (cfg.file,O_RDONLY );if (sec_fd <0 ) {
@@ -3498,6 +3588,7 @@ static int sec_send(int argc, char **argv, struct command *cmd, struct plugin *pclose (sec_fd); close_fd:close (fd); + ret:return err; }
@@ -3558,8 +3649,10 @@ static int dir_send(int argc, char **argv, struct command *cmd, struct plugin *p }; fd =parse_and_open (argc, argv, desc, command_line_options, &cfg,sizeof (cfg)); -if (fd <0 ) -return fd; +if (fd <0 ) { + err = fd; + goto ret; + }switch (cfg.dtype) {case NVME_DIR_IDENTIFY :
@@ -3649,6 +3742,7 @@ free:free (buf); close_fd:close (fd); +ret:return err; }
@@ -3681,8 +3775,10 @@ static int write_uncor(int argc, char **argv, struct command *cmd, struct plugin }; fd =parse_and_open (argc, argv, desc, command_line_options, &cfg,sizeof (cfg)); -if (fd <0 ) -return fd; +if (fd <0 ) { + err = fd; + goto ret; + }if (!cfg.namespace_id) { cfg.namespace_id =get_nsid (fd);
@@ -3703,7 +3799,7 @@ static int write_uncor(int argc, char **argv, struct command *cmd, struct plugin close_fd:close (fd); - +ret:return err; }
@@ -3761,8 +3857,10 @@ static int write_zeroes(int argc, char **argv, struct command *cmd, struct plugi }; fd =parse_and_open (argc, argv, desc, command_line_options, &cfg,sizeof (cfg)); -if (fd <0 ) -return fd; +if (fd <0 ) { + err = fd; + goto ret; + }if (cfg.prinfo >0xf ) { err =EINVAL ;
@@ -3795,6 +3893,7 @@ static int write_zeroes(int argc, char **argv, struct command *cmd, struct plugi close_fd:close (fd); + ret:return err; }
@@ -3855,8 +3954,10 @@ static int dsm(int argc, char **argv, struct command *cmd, struct plugin *plugin }; fd =parse_and_open (argc, argv, desc, command_line_options, &cfg,sizeof (cfg)); -if (fd <0 ) -return fd; +if (fd <0 ) { + err = fd; + goto ret; + } nc =argconfig_parse_comma_sep_array (cfg.ctx_attrs, ctx_attrs,ARRAY_SIZE (ctx_attrs)); nb =argconfig_parse_comma_sep_array (cfg.blocks, nlbs,ARRAY_SIZE (nlbs));
@@ -3895,6 +3996,7 @@ static int dsm(int argc, char **argv, struct command *cmd, struct plugin *plugin close_fd:close (fd); + ret:return err; }
@@ -3922,8 +4024,10 @@ static int flush(int argc, char **argv, struct command *cmd, struct plugin *plug }; fd =parse_and_open (argc, argv, desc, command_line_options, &cfg,sizeof (cfg)); -if (fd <0 ) -return fd; +if (fd <0 ) { + err = fd; + goto ret; + }if (S_ISBLK (nvme_stat.st_mode)) { cfg.namespace_id =get_nsid (fd);
@@ -3942,6 +4046,7 @@ static int flush(int argc, char **argv, struct command *cmd, struct plugin *plugprintf ("NVMe Flush: success\n" ); close_fd:close (fd); +ret:return err; }
@@ -3989,8 +4094,10 @@ static int resv_acquire(int argc, char **argv, struct command *cmd, struct plugi }; fd =parse_and_open (argc, argv, desc, command_line_options, &cfg,sizeof (cfg)); -if (fd <0 ) -return fd; +if (fd <0 ) { + err = fd; + goto ret; + }if (!cfg.namespace_id) { cfg.namespace_id =get_nsid (fd);
@@ -4016,6 +4123,7 @@ static int resv_acquire(int argc, char **argv, struct command *cmd, struct plugi close_fd:close (fd); + ret:return err; }
@@ -4060,8 +4168,10 @@ static int resv_register(int argc, char **argv, struct command *cmd, struct plug }; fd =parse_and_open (argc, argv, desc, command_line_options, &cfg,sizeof (cfg)); -if (fd <0 ) -return fd; +if (fd <0 ) { + err = fd; + goto ret; + }if (!cfg.namespace_id) { cfg.namespace_id =get_nsid (fd);
@@ -4093,6 +4203,7 @@ static int resv_register(int argc, char **argv, struct command *cmd, struct plug close_fd:close (fd); + ret:return err; }
@@ -4139,8 +4250,10 @@ static int resv_release(int argc, char **argv, struct command *cmd, struct plugi }; fd =parse_and_open (argc, argv, desc, command_line_options, &cfg,sizeof (cfg)); -if (fd <0 ) -return fd; +if (fd <0 ) { + err = fd; + goto ret; + }if (!cfg.namespace_id) { cfg.namespace_id =get_nsid (fd);
@@ -4166,6 +4279,7 @@ static int resv_release(int argc, char **argv, struct command *cmd, struct plugi close_fd:close (fd); + ret:return err; }
@@ -4209,8 +4323,10 @@ static int resv_report(int argc, char **argv, struct command *cmd, struct plugin }; fd =parse_and_open (argc, argv, desc, command_line_options, &cfg,sizeof (cfg)); -if (fd <0 ) -return fd; +if (fd <0 ) { + err = fd; + goto ret; + } fmt =validate_output_format (cfg.output_format);if (fmt <0 ) {
@@ -4260,6 +4376,7 @@ static int resv_report(int argc, char **argv, struct command *cmd, struct plugin close_fd:close (fd); + ret:return err; }
@@ -4353,8 +4470,10 @@ static int submit_io(int opcode, char *command, const char *desc, }; fd =parse_and_open (argc, argv, desc, command_line_options, &cfg,sizeof (cfg)); -if (fd <0 ) -return fd; +if (fd <0 ) { + err = fd; + goto ret; + } dfd = mfd = opcode &1 ?STDIN_FILENO :STDOUT_FILENO ;if (cfg.prinfo >0xf ) {
@@ -4505,6 +4624,7 @@ static int submit_io(int opcode, char *command, const char *desc,close (dfd); close_fd:close (fd); + ret:return err; }
@@ -4579,8 +4699,10 @@ static int sec_recv(int argc, char **argv, struct command *cmd, struct plugin *p }; fd =parse_and_open (argc, argv, desc, command_line_options, &cfg,sizeof (cfg)); -if (fd <0 ) -return fd; +if (fd <0 ) { + err = fd; + goto ret; + }if (cfg.size) {if (posix_memalign (&sec_buf,getpagesize (), cfg.size)) {
@@ -4611,6 +4733,7 @@ static int sec_recv(int argc, char **argv, struct command *cmd, struct plugin *p close_fd:close (fd); + ret:return err; }
@@ -4664,8 +4787,10 @@ static int dir_receive(int argc, char **argv, struct command *cmd, struct plugin }; fd =parse_and_open (argc, argv, desc, command_line_options, &cfg,sizeof (cfg)); -if (fd <0 ) -return fd; +if (fd <0 ) { + err = fd; + goto ret; + }switch (cfg.dtype) {case NVME_DIR_IDENTIFY :
@@ -4741,6 +4866,7 @@ free:free (buf); close_fd:close (fd); +ret:return err; }
@@ -4845,8 +4971,10 @@ static int passthru(int argc, char **argv, int ioctl_cmd, const char *desc, stru }; fd =parse_and_open (argc, argv, desc, command_line_options, &cfg,sizeof (cfg)); -if (fd <0 ) -return fd; +if (fd <0 ) { + err = fd; + goto ret; + }if (strlen (cfg.input_file)){ wfd = open(cfg.input_file, O_RDONLY,
@@ -4941,6 +5069,7 @@ static int passthru(int argc, char **argv, int ioctl_cmd, const char *desc, struclose (wfd); close_fd:close (fd); + ret:return err; }
Signature · 1 line
2.21.0
PATCH v7 2/7 fabrics: Do not return in the middle of the subcommand
In reply to Minwoo ImThis patch also makes fabrics module to not return the internal error status in the middle of the subcommands to support uniformed mapped error value which will be introduced in the next patches.
--- fabrics.c | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-)
fabrics.c +19 -12
@@ -984,20 +984,23 @@ int discover(const char *desc, int argc, char **argv, bool connect) ret =argconfig_parse (argc, argv, desc, command_line_options, &cfg,sizeof (cfg));if (ret) -return ret; + goto out; cfg.nqn =NVME_DISC_SUBSYS_NAME ;if (!cfg.transport && !cfg.traddr) { -return discover_from_conf_file (desc, argstr, + ret =discover_from_conf_file (desc, argstr, command_line_options, connect); }else { ret =build_options (argstr,BUF_SIZE );if (ret) -return ret; + goto out; -return do_discover (argstr, connect); + ret =do_discover (argstr, connect); } + +out: +return ret; }int connect (const char *desc,int argc,char **argv)
@@ -1029,21 +1032,23 @@ int connect(const char *desc, int argc, char **argv) ret =argconfig_parse (argc, argv, desc, command_line_options, &cfg,sizeof (cfg));if (ret) -return ret; + goto out; ret =build_options (argstr,BUF_SIZE );if (ret) -return ret; + goto out;if (!cfg.nqn) {fprintf (stderr,"need a -n argument\n" ); -return -EINVAL ; + ret = -EINVAL ; + goto out; } instance =add_ctrl (argstr);if (instance <0 ) -return instance; -return 0 ; + ret = instance; +out: +return ret; }static int scan_sys_nvme_filter (const struct dirent *d)
@@ -1148,11 +1153,12 @@ int disconnect(const char *desc, int argc, char **argv) ret =argconfig_parse (argc, argv, desc, command_line_options, &cfg,sizeof (cfg));if (ret) -return ret; + goto out;if (!cfg.nqn && !cfg.device) {fprintf (stderr,"need a -n or -d argument\n" ); -return -EINVAL ; + ret = -EINVAL ; + goto out; }if (cfg.nqn) {
@@ -1174,6 +1180,7 @@ int disconnect(const char *desc, int argc, char **argv) cfg.device); } +out:return ret; }
@@ -1188,7 +1195,7 @@ int disconnect_all(const char *desc, int argc, char **argv) ret =argconfig_parse (argc, argv, desc, command_line_options, &cfg,sizeof (cfg));if (ret) -return ret; + goto out; slist =get_subsys_list (&subcnt,NULL ,NVME_NSID_ALL );for (i =0 ; i < subcnt; i++) {
Signature · 1 line
2.21.0
PATCH v7 3/7 nvme: Return negative error value for internal errors
In reply to Minwoo ImTo support the mapping of error values which will be introduced in the next patches, All the internal errors caused in the middle of the subcommands preparation or teardown should be returned as a negative value to make it distinguished from nvme error status which is positive.
This patch makes all the internal error values which used to be returned as a positive value to be returned as a negative value.
--- nvme.c | 170 ++++++++++++++++++++++++++++----------------------------- 1 file changed, 85 insertions(+), 85 deletions(-)
nvme.c +85 -85
@@ -343,7 +343,7 @@ static int get_telemetry_log(int argc, char **argv, struct command *cmd, structif (!cfg.file_name) {fprintf (stderr,"Please provide an output file!\n" ); - err =EINVAL ; + err = -EINVAL ; goto close_fd; }
@@ -353,7 +353,7 @@ static int get_telemetry_log(int argc, char **argv, struct command *cmd, structif (!hdr || !page_log) {fprintf (stderr,"Failed to allocate %zu bytes for log: %s\n" , bs,strerror (errno)); - err =ENOMEM ; + err = -ENOMEM ; goto free_mem; }memset (hdr,0 , bs);
@@ -393,7 +393,7 @@ static int get_telemetry_log(int argc, char **argv, struct command *cmd, structbreak ;default :fprintf (stderr,"Invalid data area requested" ); - err =EINVAL ; + err = -EINVAL ; goto close_output; }
@@ -597,7 +597,7 @@ static int get_error_log(int argc, char **argv, struct command *cmd, struct plugif (!cfg.log_entries) {fprintf (stderr,"non-zero log-entries is required param\n" ); - err =EINVAL ; + err = -EINVAL ; goto close_fd; }
@@ -606,7 +606,7 @@ static int get_error_log(int argc, char **argv, struct command *cmd, struct plugperror ("identify controller" ); else if (err) {fprintf (stderr,"could not identify controller\n" ); - err =ENODEV ; + err = -ENODEV ; } else {struct nvme_error_log_page *err_log;
@@ -614,7 +614,7 @@ static int get_error_log(int argc, char **argv, struct command *cmd, struct plug err_log =calloc (cfg.log_entries,sizeof (struct nvme_error_log_page ));if (!err_log) {fprintf (stderr,"could not alloc buffer for error log\n" ); - err =ENOMEM ; + err = -ENOMEM ; goto close_fd; }
@@ -815,13 +815,13 @@ static int get_log(int argc, char **argv, struct command *cmd, struct plugin *plif (cfg.log_id >0xff ) {fprintf (stderr,"Invalid log identifier: %d. Valid range: 0-255\n" , cfg.log_id); - err =EINVAL ; + err = -EINVAL ; goto close_fd; }if (!cfg.log_len) {fprintf (stderr,"non-zero log-len is required param\n" ); - err =EINVAL ; + err = -EINVAL ; }else {unsigned char *log;
@@ -829,7 +829,7 @@ static int get_log(int argc, char **argv, struct command *cmd, struct plugin *plif (!log) {fprintf (stderr,"could not alloc buffer for log: %s\n" ,strerror (errno)); - err =EINVAL ; + err = -EINVAL ; goto close_fd; }
@@ -1081,13 +1081,13 @@ static int delete_ns(int argc, char **argv, struct command *cmd, struct plugin *if (S_ISBLK (nvme_stat.st_mode)) { cfg.namespace_id =get_nsid (fd);if (cfg.namespace_id ==0 ) { - err =EINVAL ; + err = -EINVAL ; goto close_fd; } }else if (!cfg.namespace_id) {fprintf (stderr,"%s: namespace-id parameter required\n" , cmd->name); - err =EINVAL ; + err = -EINVAL ; goto close_fd; }
@@ -1138,7 +1138,7 @@ static int nvme_attach_ns(int argc, char **argv, int attach, const char *desc, sif (!cfg.namespace_id) {fprintf (stderr,"%s: namespace-id parameter required\n" , cmd->name); - err =EINVAL ; + err = -EINVAL ; goto close_fd; }
@@ -1148,7 +1148,7 @@ static int nvme_attach_ns(int argc, char **argv, int attach, const char *desc, sif (num ==-1 ) {fprintf (stderr,"%s: controller id list is required\n" , cmd->name); - err =EINVAL ; + err = -EINVAL ; goto close_fd; }
@@ -2048,14 +2048,14 @@ static int ns_descs(int argc, char **argv, struct command *cmd, struct plugin *pif (!cfg.namespace_id) { cfg.namespace_id =get_nsid (fd);if (cfg.namespace_id ==0 ) { - err =EINVAL ; + err = -EINVAL ; goto close_fd; } }if (posix_memalign (&nsdescs,getpagesize (),0x1000 )) {fprintf (stderr,"can not allocate controller list payload\n" ); - err =ENOMEM ; + err = -ENOMEM ; goto close_fd; }
@@ -2142,7 +2142,7 @@ static int id_ns(int argc, char **argv, struct command *cmd, struct plugin *plugif (!cfg.namespace_id &&S_ISBLK (nvme_stat.st_mode)) { cfg.namespace_id =get_nsid (fd);if (cfg.namespace_id ==0 ) { - err =EINVAL ; + err = -EINVAL ; goto close_fd; } }
@@ -2575,12 +2575,12 @@ static int get_feature(int argc, char **argv, struct command *cmd, struct pluginif (cfg.sel >7 ) {fprintf (stderr,"invalid 'select' param:%d\n" , cfg.sel); - err =EINVAL ; + err = -EINVAL ; goto close_fd; }if (!cfg.feature_id) {fprintf (stderr,"feature-id required param\n" ); - err =EINVAL ; + err = -EINVAL ; goto close_fd; }
@@ -2614,7 +2614,7 @@ static int get_feature(int argc, char **argv, struct command *cmd, struct pluginif (cfg.data_len) {if (posix_memalign (&buf,getpagesize (), cfg.data_len)) {fprintf (stderr,"can not allocate feature payload\n" ); - err =ENOMEM ; + err = -ENOMEM ; goto close_fd; }memset (buf,0 , cfg.data_len);
@@ -2697,7 +2697,7 @@ static int fw_download(int argc, char **argv, struct command *cmd, struct pluginif (fw_fd <0 ) {fprintf (stderr,"Failed to open firmware file %s: %s\n" , cfg.fw,strerror (errno)); - err =EINVAL ; + err = -EINVAL ; goto close_fd; }
@@ -2710,12 +2710,12 @@ static int fw_download(int argc, char **argv, struct command *cmd, struct plugin fw_size = sb.st_size;if (fw_size &0x3 ) {fprintf (stderr,"Invalid size:%d for f/w image\n" , fw_size); - err =EINVAL ; + err = -EINVAL ; goto close_fw_fd; }if (posix_memalign (&fw_buf,getpagesize (), fw_size)) {fprintf (stderr,"No memory for f/w size:%d\n" , fw_size); - err =ENOMEM ; + err = -ENOMEM ; goto close_fw_fd; }
@@ -2805,17 +2805,17 @@ static int fw_commit(int argc, char **argv, struct command *cmd, struct plugin *if (cfg.slot >7 ) {fprintf (stderr,"invalid slot:%d\n" , cfg.slot); - err =EINVAL ; + err = -EINVAL ; goto close_fd; }if (cfg.action >7 || cfg.action ==4 || cfg.action ==5 ) {fprintf (stderr,"invalid action:%d\n" , cfg.action); - err =EINVAL ; + err = -EINVAL ; goto close_fd; }if (cfg.bpid >1 ) {fprintf (stderr,"invalid boot partition id:%d\n" , cfg.bpid); - err =EINVAL ; + err = -EINVAL ; goto close_fd; }
@@ -2983,14 +2983,14 @@ static int sanitize(int argc, char **argv, struct command *cmd, struct plugin *pbreak ;default :fprintf (stderr,"Invalid Sanitize Action\n" ); - ret =EINVAL ; + ret = -EINVAL ; goto close_fd; }if (cfg.sanact ==NVME_SANITIZE_ACT_EXIT ) {if (cfg.ause || cfg.no_dealloc) {fprintf (stderr,"SANACT is Exit Failure Mode\n" ); - ret =EINVAL ; + ret = -EINVAL ; goto close_fd; } }
@@ -2998,13 +2998,13 @@ static int sanitize(int argc, char **argv, struct command *cmd, struct plugin *pif (cfg.sanact ==NVME_SANITIZE_ACT_OVERWRITE ) {if (cfg.owpass >16 ) {fprintf (stderr,"OWPASS out of range [0-16]\n" ); - ret =EINVAL ; + ret = -EINVAL ; goto close_fd; } }else {if (cfg.owpass || cfg.oipbp || cfg.ovrpat) {fprintf (stderr,"SANACT is not Overwrite\n" ); - ret =EINVAL ; + ret = -EINVAL ; goto close_fd; } }
@@ -3065,7 +3065,7 @@ static int show_registers(int argc, char **argv, struct command *cmd, struct pluif (cfg.human_readable && fmt !=NORMAL ) {fprintf (stderr,"Only --output-format=normal supports -H\n" ); - err =EINVAL ; + err = -EINVAL ; goto close_fd; }
@@ -3077,7 +3077,7 @@ static int show_registers(int argc, char **argv, struct command *cmd, struct plu err =0 ; }if (!bar) { - err =ENODEV ; + err = -ENODEV ; goto close_fd; }
@@ -3132,7 +3132,7 @@ static int get_property(int argc, char **argv, struct command *cmd, struct plugiif (cfg.offset ==-1 ) {fprintf (stderr,"offset required param" ); - err =EINVAL ; + err = -EINVAL ; goto close_fd; }
@@ -3183,12 +3183,12 @@ static int set_property(int argc, char **argv, struct command *cmd, struct plugiif (cfg.offset ==-1 ) {fprintf (stderr,"offset required param" ); - err =EINVAL ; + err = -EINVAL ; goto close_fd; }if (cfg.value ==-1 ) {fprintf (stderr,"value required param" ); - err =EINVAL ; + err = -EINVAL ; goto close_fd; }
@@ -3287,7 +3287,7 @@ static int format(int argc, char **argv, struct command *cmd, struct plugin *pluif (S_ISBLK (nvme_stat.st_mode)) { cfg.namespace_id =get_nsid (fd);if (cfg.namespace_id ==0 ) { - err =EINVAL ; + err = -EINVAL ; goto close_fd; } }
@@ -3328,27 +3328,27 @@ static int format(int argc, char **argv, struct command *cmd, struct plugin *plu/* ses & pi checks set to 7 for forward-compatibility */ if (cfg.ses >7 ) {fprintf (stderr,"invalid secure erase settings:%d\n" , cfg.ses); - err =EINVAL ; + err = -EINVAL ; goto close_fd; }if (cfg.lbaf >15 ) {fprintf (stderr,"invalid lbaf:%d\n" , cfg.lbaf); - err =EINVAL ; + err = -EINVAL ; goto close_fd; }if (cfg.pi >7 ) {fprintf (stderr,"invalid pi:%d\n" , cfg.pi); - err =EINVAL ; + err = -EINVAL ; goto close_fd; }if (cfg.pil >1 ) {fprintf (stderr,"invalid pil:%d\n" , cfg.pil); - err =EINVAL ; + err = -EINVAL ; goto close_fd; }if (cfg.ms >1 ) {fprintf (stderr,"invalid ms:%d\n" , cfg.ms); - err =EINVAL ; + err = -EINVAL ; goto close_fd; }
@@ -3432,7 +3432,7 @@ static int set_feature(int argc, char **argv, struct command *cmd, struct pluginif (!cfg.feature_id) {fprintf (stderr,"feature-id required param\n" ); - err =EINVAL ; + err = -EINVAL ; goto close_fd; }if (cfg.feature_id ==NVME_FEAT_LBA_RANGE )
@@ -3440,7 +3440,7 @@ static int set_feature(int argc, char **argv, struct command *cmd, struct pluginif (cfg.data_len) {if (posix_memalign (&buf,getpagesize (), cfg.data_len)) {fprintf (stderr,"can not allocate feature payload\n" ); - err =ENOMEM ; + err = -ENOMEM ; goto close_fd; }memset (buf,0 , cfg.data_len);
@@ -3452,7 +3452,7 @@ static int set_feature(int argc, char **argv, struct command *cmd, struct pluginif (ffd <=0 ) {fprintf (stderr,"Failed to open file %s: %s\n" , cfg.file,strerror (errno)); - err =EINVAL ; + err = -EINVAL ; goto free; } }
@@ -3548,7 +3548,7 @@ static int sec_send(int argc, char **argv, struct command *cmd, struct plugin *pif (sec_fd <0 ) {fprintf (stderr,"Failed to open %s: %s\n" , cfg.file,strerror (errno)); - err =EINVAL ; + err = -EINVAL ; goto close_fd; }
@@ -3561,7 +3561,7 @@ static int sec_send(int argc, char **argv, struct command *cmd, struct plugin *p sec_size = sb.st_size;if (posix_memalign (&sec_buf,getpagesize (), sec_size)) {fprintf (stderr,"No memory for security size:%d\n" , sec_size); - err =ENOMEM ; + err = -ENOMEM ; goto close_sec_fd; }
@@ -3660,14 +3660,14 @@ static int dir_send(int argc, char **argv, struct command *cmd, struct plugin *pcase NVME_DIR_SND_ID_OP_ENABLE :if (!cfg.ttype) {fprintf (stderr,"target-dir required param\n" ); - err =EINVAL ; + err = -EINVAL ; goto close_fd; } dw12 = cfg.ttype <<8 | cfg.endir;break ;default :fprintf (stderr,"invalid directive operations for Identify Directives\n" ); - err =EINVAL ; + err = -EINVAL ; goto close_fd; }break ;
@@ -3678,20 +3678,20 @@ static int dir_send(int argc, char **argv, struct command *cmd, struct plugin *pbreak ;default :fprintf (stderr,"invalid directive operations for Streams Directives\n" ); - err =EINVAL ; + err = -EINVAL ; goto close_fd; }break ;default :fprintf (stderr,"invalid directive type\n" ); - err =EINVAL ; + err = -EINVAL ; goto close_fd; }if (cfg.data_len) {if (posix_memalign (&buf,getpagesize (), cfg.data_len)) { - err =ENOMEM ; + err = -ENOMEM ; goto close_fd; }memset (buf,0 , cfg.data_len);
@@ -3703,7 +3703,7 @@ static int dir_send(int argc, char **argv, struct command *cmd, struct plugin *pif (ffd <=0 ) {fprintf (stderr,"Failed to open file %s: %s\n" , cfg.file,strerror (errno)); - err =EINVAL ; + err = -EINVAL ; goto free; } }
@@ -3783,7 +3783,7 @@ static int write_uncor(int argc, char **argv, struct command *cmd, struct pluginif (!cfg.namespace_id) { cfg.namespace_id =get_nsid (fd);if (cfg.namespace_id ==0 ) { - err =EINVAL ; + err = -EINVAL ; goto close_fd; } }
@@ -3863,7 +3863,7 @@ static int write_zeroes(int argc, char **argv, struct command *cmd, struct plugi }if (cfg.prinfo >0xf ) { - err =EINVAL ; + err = -EINVAL ; goto close_fd; }
@@ -3877,7 +3877,7 @@ static int write_zeroes(int argc, char **argv, struct command *cmd, struct plugiif (!cfg.namespace_id) { cfg.namespace_id =get_nsid (fd);if (cfg.namespace_id ==0 ) { - err =EINVAL ; + err = -EINVAL ; goto close_fd; } }
@@ -3965,14 +3965,14 @@ static int dsm(int argc, char **argv, struct command *cmd, struct plugin *plugin nr =max (nc,max (nb, ns));if (!nr || nr >256 ) {fprintf (stderr,"No range definition provided\n" ); - err =EINVAL ; + err = -EINVAL ; goto close_fd; }if (!cfg.namespace_id) { cfg.namespace_id =get_nsid (fd);if (cfg.namespace_id ==0 ) { - err =EINVAL ; + err = -EINVAL ; goto close_fd; } }
@@ -3982,7 +3982,7 @@ static int dsm(int argc, char **argv, struct command *cmd, struct plugin *plugin dsm =nvme_setup_dsm_range ((__u32 *)ctx_attrs, (__u32 *)nlbs, (__u64 *)slbas, nr);if (!dsm) {fprintf (stderr,"failed to allocate data set payload\n" ); - err =ENOMEM ; + err = -ENOMEM ; goto close_fd; }
@@ -4032,7 +4032,7 @@ static int flush(int argc, char **argv, struct command *cmd, struct plugin *plugif (S_ISBLK (nvme_stat.st_mode)) { cfg.namespace_id =get_nsid (fd);if (cfg.namespace_id ==0 ) { - err =EINVAL ; + err = -EINVAL ; goto close_fd; } }
@@ -4102,13 +4102,13 @@ static int resv_acquire(int argc, char **argv, struct command *cmd, struct plugiif (!cfg.namespace_id) { cfg.namespace_id =get_nsid (fd);if (cfg.namespace_id ==0 ) { - err =EINVAL ; + err = -EINVAL ; goto close_fd; } }if (cfg.racqa >7 ) {fprintf (stderr,"invalid racqa:%d\n" , cfg.racqa); - err =EINVAL ; + err = -EINVAL ; goto close_fd; }
@@ -4176,19 +4176,19 @@ static int resv_register(int argc, char **argv, struct command *cmd, struct plugif (!cfg.namespace_id) { cfg.namespace_id =get_nsid (fd);if (cfg.namespace_id ==0 ) { - err =EINVAL ; + err = -EINVAL ; goto close_fd; } }if (cfg.cptpl >3 ) {fprintf (stderr,"invalid cptpl:%d\n" , cfg.cptpl); - err =EINVAL ; + err = -EINVAL ; goto close_fd; }if (cfg.rrega >7 ) {fprintf (stderr,"invalid rrega:%d\n" , cfg.rrega); - err =EINVAL ; + err = -EINVAL ; goto close_fd; }
@@ -4258,13 +4258,13 @@ static int resv_release(int argc, char **argv, struct command *cmd, struct plugiif (!cfg.namespace_id) { cfg.namespace_id =get_nsid (fd);if (cfg.namespace_id ==0 ) { - err =EINVAL ; + err = -EINVAL ; goto close_fd; } }if (cfg.rrela >7 ) {fprintf (stderr,"invalid rrela:%d\n" , cfg.rrela); - err =EINVAL ; + err = -EINVAL ; goto close_fd; }
@@ -4339,7 +4339,7 @@ static int resv_report(int argc, char **argv, struct command *cmd, struct pluginif (!cfg.namespace_id) { cfg.namespace_id =get_nsid (fd);if (cfg.namespace_id ==0 ) { - err =EINVAL ; + err = -EINVAL ; goto close_fd; } }
@@ -4352,7 +4352,7 @@ static int resv_report(int argc, char **argv, struct command *cmd, struct pluginif (posix_memalign ((void **)&status,getpagesize (), size)) {fprintf (stderr,"No memory for resv report:%d\n" , size); - err =ENOMEM ; + err = -ENOMEM ; goto close_fd; }memset (status,0 , size);
@@ -4477,7 +4477,7 @@ static int submit_io(int opcode, char *command, const char *desc, dfd = mfd = opcode &1 ?STDIN_FILENO :STDOUT_FILENO ;if (cfg.prinfo >0xf ) { - err =EINVAL ; + err = -EINVAL ; goto close_fd; }
@@ -4491,7 +4491,7 @@ static int submit_io(int opcode, char *command, const char *desc,if (cfg.dtype >0xf ) {fprintf (stderr,"Invalid directive type, %x\n" , cfg.dtype); - err =EINVAL ; + err = -EINVAL ; goto close_fd; } control |= cfg.dtype <<4 ;
@@ -4502,7 +4502,7 @@ static int submit_io(int opcode, char *command, const char *desc, dfd =open (cfg.data, flags, mode);if (dfd <0 ) {perror (cfg.data); - err =EINVAL ; + err = -EINVAL ; goto close_fd; } mfd = dfd;
@@ -4511,14 +4511,14 @@ static int submit_io(int opcode, char *command, const char *desc, mfd =open (cfg.metadata, flags, mode);if (mfd <0 ) {perror (cfg.metadata); - err =EINVAL ; + err = -EINVAL ; goto close_dfd; } }if (!cfg.data_size) {fprintf (stderr,"data size not provided\n" ); - err =EINVAL ; + err = -EINVAL ; goto close_mfd; }
@@ -4535,7 +4535,7 @@ static int submit_io(int opcode, char *command, const char *desc,if (posix_memalign (&buffer,getpagesize (), buffer_size)) {fprintf (stderr,"can not allocate io payload\n" ); - err =ENOMEM ; + err = -ENOMEM ; goto close_mfd; }memset (buffer,0 , buffer_size);
@@ -4545,7 +4545,7 @@ static int submit_io(int opcode, char *command, const char *desc,if (!mbuffer) {fprintf (stderr,"can not allocate io metadata " "payload: %s\n" ,strerror (errno)); - err =ENOMEM ; + err = -ENOMEM ; goto free_buffer; } }
@@ -4602,12 +4602,12 @@ static int submit_io(int opcode, char *command, const char *desc,if (!(opcode &1 ) &&write (dfd, (void *)buffer, cfg.data_size) <0 ) {fprintf (stderr,"write: %s: failed to write buffer to output file\n" ,strerror (errno)); - err =EINVAL ; + err = -EINVAL ; }else if (!(opcode &1 ) && cfg.metadata_size &&write (mfd, (void *)mbuffer, cfg.metadata_size) <0 ) {fprintf (stderr,"write: %s: failed to write meta-data buffer to output file\n" ,strerror (errno)); - err =EINVAL ; + err = -EINVAL ; }else fprintf (stderr,"%s: Success\n" , command); }
@@ -4708,7 +4708,7 @@ static int sec_recv(int argc, char **argv, struct command *cmd, struct plugin *pif (posix_memalign (&sec_buf,getpagesize (), cfg.size)) {fprintf (stderr,"No memory for security size:%d\n" , cfg.size); - err =ENOMEM ; + err = -ENOMEM ; goto close_fd; } }
@@ -4801,7 +4801,7 @@ static int dir_receive(int argc, char **argv, struct command *cmd, struct pluginbreak ;default :fprintf (stderr,"invalid directive operations for Identify Directives\n" ); - err =EINVAL ; + err = -EINVAL ; goto close_fd; }break ;
@@ -4820,19 +4820,19 @@ static int dir_receive(int argc, char **argv, struct command *cmd, struct pluginbreak ;default :fprintf (stderr,"invalid directive operations for Streams Directives\n" ); - err =EINVAL ; + err = -EINVAL ; goto close_fd; }break ;default :fprintf (stderr,"invalid directive type\n" ); - err =EINVAL ; + err = -EINVAL ; goto close_fd; }if (cfg.data_len) {if (posix_memalign (&buf,getpagesize (), cfg.data_len)) { - err =ENOMEM ; + err = -ENOMEM ; goto close_fd; }memset (buf,0 , cfg.data_len);
@@ -4981,7 +4981,7 @@ static int passthru(int argc, char **argv, int ioctl_cmd, const char *desc, stru S_IRUSR | S_IRGRP | S_IROTH);if (wfd <0 ) {perror (cfg.input_file); - err =EINVAL ; + err = -EINVAL ; goto close_fd; } }
@@ -4991,21 +4991,21 @@ static int passthru(int argc, char **argv, int ioctl_cmd, const char *desc, struif (!metadata) {fprintf (stderr,"can not allocate metadata " "payload: %s\n" ,strerror (errno)); - err =ENOMEM ; + err = -ENOMEM ; goto close_wfd; } }if (cfg.data_len) {if (posix_memalign (&data,getpagesize (), cfg.data_len)) {fprintf (stderr,"can not allocate data payload\n" ); - err =ENOMEM ; + err = -ENOMEM ; goto free_metadata; }memset (data, cfg.prefill, cfg.data_len);if (!cfg.read && !cfg.write) {fprintf (stderr,"data direction not given\n" ); - err =EINVAL ; + err = -EINVAL ; goto free_data; }else if (cfg.write) {if (read (wfd, data, cfg.data_len) <0 ) {
Signature · 1 line
2.21.0
PATCH v7 4/7 nvme-status: Introduce nvme status module to map errno
In reply to Minwoo ImBackground:
It's not enough to return the nvme status value in main() because it's
allowed to be in 8bits, but nvme status is indicated in 16bits. So we has not been able to figure out what kind of nvme status has been returned by return value.
This patch introduces nvme-status module that manages mapping between
nvme status and errno. It's not possible to make 1:1 mapping relations, but we can map it as a groups.
All the internal errors which has been returned in a negative value will be returned with ECOMM that indicates communication errors. In this case, we can see what happened via stderr.
--- Makefile | 3 +- linux/nvme.h | 6 ++ nvme-status.c | 155 ++++++++++++++++++++++++++++++++++++++++++++++++++ nvme-status.h | 14 +++++ 4 files changed, 177 insertions(+), 1 deletion(-) create mode 100644 nvme-status.c create mode 100644 nvme-status.h
Makefile +2 -1
@@ -32,7 +32,8 @@ override CFLAGS += -DNVME_VERSION='"$(NVME_VERSION)"' NVME_DPKG_VERSION=1~`lsb_release -sc` OBJS := argconfig.o suffix.o parser.o nvme-print.o nvme-ioctl.o \ - nvme-lightnvm.o fabrics.o json.o nvme-models.o plugin.o + nvme-lightnvm.o fabrics.o json.o nvme-models.o plugin.o \ + nvme-status.o PLUGIN_OBJS := \ plugins/intel/intel-nvme.o \
linux/nvme.h +6 -0
@@ -1319,6 +1319,12 @@ static inline bool nvme_is_write(struct nvme_command *cmd)return cmd->common.opcode &1 ; } +enum { +NVME_SCT_GENERIC =0x0 , +NVME_SCT_CMD_SPECIFIC =0x1 , +NVME_SCT_MEDIA =0x2 , +}; +enum {/* * Generic Command Status:
nvme-status.c new file +155 -0
155 lines not on this page · raw message
nvme-status.h new file +14 -0
@@ -0,0 +1,14 @@ +#include <linux/types.h> +#include <stdbool.h> + +/* +* nvme_status_type - It gives SCT(Status Code Type) in status field in +* completion queue entry. +* @status: status field located at DW3 in completion queue entry +*/ +static inline __u8 nvme_status_type (__u16 status) +{ +return (status &0x700 ) >>8 ; +} + +__u8 nvme_status_to_errno (int status,bool fabrics);
Signature · 1 line
2.21.0
PATCH v7 5/7 nvme: Return errno mapped for nvme error status
In reply to Minwoo ImIf ioctl module has returned a nvme error status, it will be returned by being converted to a mapped errno value which has been provided by previous commits.
--- nvme.c | 106 ++++++++++++++++++++++++++++----------------------------- 1 file changed, 53 insertions(+), 53 deletions(-)
nvme.c +53 -53
@@ -48,6 +48,7 @@#include "common.h" #include "nvme-print.h" #include "nvme-ioctl.h" +#include "nvme-status.h" #include "nvme-lightnvm.h" #include "plugin.h"
@@ -223,7 +224,7 @@ static int get_smart_log(int argc, char **argv, struct command *cmd, struct plugclose (fd); ret: -return err; +return nvme_status_to_errno (err, false); } static int get_ana_log(int argc, char **argv, struct command *cmd,
@@ -298,7 +299,7 @@ static int get_ana_log(int argc, char **argv, struct command *cmd, close_fd:close (fd); ret: -return err; +return nvme_status_to_errno (err, false); }static int get_telemetry_log (int argc,char **argv,struct command *cmd,struct plugin *plugin)
@@ -428,7 +429,7 @@ static int get_telemetry_log(int argc, char **argv, struct command *cmd, struct close_fd:close (fd); ret: -return err; +return nvme_status_to_errno (err, false); }static int get_endurance_log (int argc,char **argv,struct command *cmd,struct plugin *plugin)
@@ -485,7 +486,7 @@ static int get_endurance_log(int argc, char **argv, struct command *cmd, struct close_fd:close (fd); ret: -return err; +return nvme_status_to_errno (err, false); }static int get_effects_log (int argc,char **argv,struct command *cmd,struct plugin *plugin)
@@ -550,7 +551,7 @@ static int get_effects_log(int argc, char **argv, struct command *cmd, struct pl close_fd:close (fd); ret: -return err; +return nvme_status_to_errno (err, false); }static int get_error_log (int argc,char **argv,struct command *cmd,struct plugin *plugin)
@@ -637,7 +638,7 @@ static int get_error_log(int argc, char **argv, struct command *cmd, struct plug close_fd:close (fd); ret: -return err; +return nvme_status_to_errno (err, false); }static int get_fw_log (int argc,char **argv,struct command *cmd,struct plugin *plugin)
@@ -694,7 +695,7 @@ static int get_fw_log(int argc, char **argv, struct command *cmd, struct plugin close_fd:close (fd); ret: -return err; +return nvme_status_to_errno (err, false); }static int get_changed_ns_list_log (int argc,char **argv,struct command *cmd,struct plugin *plugin)
@@ -752,7 +753,7 @@ static int get_changed_ns_list_log(int argc, char **argv, struct command *cmd, s close_fd:close (fd); ret: -return err; +return nvme_status_to_errno (err, false); }static int get_log (int argc,char **argv,struct command *cmd,struct plugin *plugin)
@@ -854,7 +855,7 @@ static int get_log(int argc, char **argv, struct command *cmd, struct plugin *pl close_fd:close (fd); ret: -return err; +return nvme_status_to_errno (err, false); }static int sanitize_log (int argc,char **argv,struct command *command,struct plugin *plugin)
@@ -919,7 +920,7 @@ static int sanitize_log(int argc, char **argv, struct command *command, struct p close_fd:close (fd); ret: -return ret; +return nvme_status_to_errno (ret, false); }static int list_ctrl (int argc,char **argv,struct command *cmd,struct plugin *plugin)
@@ -975,7 +976,7 @@ static int list_ctrl(int argc, char **argv, struct command *cmd, struct plugin * close_fd:close (fd); ret: -return err; +return nvme_status_to_errno (err, false); }static int list_ns (int argc,char **argv,struct command *cmd,struct plugin *plugin)
@@ -1029,7 +1030,7 @@ static int list_ns(int argc, char **argv, struct command *cmd, struct plugin *pl close_fd:close (fd); ret: -return err; +return nvme_status_to_errno (err, false); }static int get_nsid (int fd)
@@ -1103,7 +1104,7 @@ static int delete_ns(int argc, char **argv, struct command *cmd, struct plugin * close_fd:close (fd); ret: -return err; +return nvme_status_to_errno (err, false); }static int nvme_attach_ns (int argc,char **argv,int attach,const char *desc,struct command *cmd)
@@ -1170,7 +1171,7 @@ static int nvme_attach_ns(int argc, char **argv, int attach, const char *desc, s close_fd:close (fd); ret: -return err; +return nvme_status_to_errno (err, false); }static int attach_ns (int argc,char **argv,struct command *cmd,struct plugin *plugin)
@@ -1300,7 +1301,7 @@ static int create_ns(int argc, char **argv, struct command *cmd, struct plugin * close_fd:close (fd); ret: -return err; +return nvme_status_to_errno (err, false); }char *nvme_char_from_block (char *block)
@@ -1788,7 +1789,7 @@ free:free (subsysnqn); ret: -return ret; +return nvme_status_to_errno (ret, false); }static int get_nvme_info (int fd,struct list_item *item,const char *node)
@@ -1921,7 +1922,7 @@ static int list(int argc, char **argv, struct command *cmd, struct plugin *plugifree (devices[i]);free (devices); ret: -return ret; +return nvme_status_to_errno (ret, false); }int __id_ctrl (int argc,char **argv,struct command *cmd,struct plugin *plugin,void (*vs)(__u8 *vs,struct json_object *root))
@@ -1997,7 +1998,7 @@ int __id_ctrl(int argc, char **argv, struct command *cmd, struct plugin *plugin, close_fd:close (fd); ret: -return err; +return nvme_status_to_errno (err, false); }static int id_ctrl (int argc,char **argv,struct command *cmd,struct plugin *plugin)
@@ -2080,7 +2081,7 @@ static int ns_descs(int argc, char **argv, struct command *cmd, struct plugin *p close_fd:close (fd); ret: -return err; +return nvme_status_to_errno (err, false); }static int id_ns (int argc,char **argv,struct command *cmd,struct plugin *plugin)
@@ -2169,7 +2170,7 @@ static int id_ns(int argc, char **argv, struct command *cmd, struct plugin *plug close_fd:close (fd); ret: -return err; +return nvme_status_to_errno (err, false); }static int id_nvmset (int argc,char **argv,struct command *cmd,struct plugin *plugin)
@@ -2229,7 +2230,7 @@ static int id_nvmset(int argc, char **argv, struct command *cmd, struct plugin * close_fd:close (fd); ret: -return err; +return nvme_status_to_errno (err, false); }static int get_ns_id (int argc,char **argv,struct command *cmd,struct plugin *plugin)
@@ -2258,7 +2259,7 @@ static int get_ns_id(int argc, char **argv, struct command *cmd, struct plugin * close_fd:close (fd); ret: -return err; +return nvme_status_to_errno (err, false); }static int virtual_mgmt (int argc,char **argv,struct command *cmd,struct plugin *plugin)
@@ -2325,8 +2326,7 @@ static int virtual_mgmt(int argc, char **argv, struct command *cmd, struct plugiclose (fd); ret: -return err; - +return nvme_status_to_errno (err, false); }static int list_secondary_ctrl (int argc,char **argv,struct command *cmd,struct plugin *plugin)
@@ -2404,7 +2404,7 @@ static int list_secondary_ctrl(int argc, char **argv, struct command *cmd, struc close_fd:close (fd); ret: -return err; +return nvme_status_to_errno (err, false); }static int device_self_test (int argc,char **argv,struct command *cmd,struct plugin *plugin)
@@ -2455,7 +2455,7 @@ static int device_self_test(int argc, char **argv, struct command *cmd, struct pclose (fd); ret: -return err; +return nvme_status_to_errno (err, false); }static int self_test_log (int argc,char **argv,struct command *cmd,struct plugin *plugin)
@@ -2513,7 +2513,7 @@ static int self_test_log(int argc, char **argv, struct command *cmd, struct plug close_fd:close (fd); ret: -return err; +return nvme_status_to_errno (err, false); }static int get_feature (int argc,char **argv,struct command *cmd,struct plugin *plugin)
@@ -2646,7 +2646,7 @@ static int get_feature(int argc, char **argv, struct command *cmd, struct plugin close_fd:close (fd); ret: -return err; +return nvme_status_to_errno (err, false); }static int fw_download (int argc,char **argv,struct command *cmd,struct plugin *plugin)
@@ -2753,7 +2753,7 @@ static int fw_download(int argc, char **argv, struct command *cmd, struct plugin close_fd:close (fd); ret: -return err; +return nvme_status_to_errno (err, false); }static char *nvme_fw_status_reset_type (__u32 status)
@@ -2848,7 +2848,7 @@ static int fw_commit(int argc, char **argv, struct command *cmd, struct plugin * close_fd:close (fd); ret: -return err; +return nvme_status_to_errno (err, false); }static int subsystem_reset (int argc,char **argv,struct command *cmd,struct plugin *plugin)
@@ -2877,7 +2877,7 @@ static int subsystem_reset(int argc, char **argv, struct command *cmd, struct plclose (fd); ret: -return err; +return nvme_status_to_errno (err, false); }static int reset (int argc,char **argv,struct command *cmd,struct plugin *plugin)
@@ -2901,7 +2901,7 @@ static int reset(int argc, char **argv, struct command *cmd, struct plugin *plugclose (fd); ret: -return err; +return nvme_status_to_errno (err, false); }static int ns_rescan (int argc,char **argv,struct command *cmd,struct plugin *plugin)
@@ -2925,7 +2925,7 @@ static int ns_rescan(int argc, char **argv, struct command *cmd, struct plugin *close (fd); ret: -return err; +return nvme_status_to_errno (err, false); }static int sanitize (int argc,char **argv,struct command *cmd,struct plugin *plugin)
@@ -3019,7 +3019,7 @@ static int sanitize(int argc, char **argv, struct command *cmd, struct plugin *p close_fd:close (fd); ret: -return ret; +return nvme_status_to_errno (ret, false); }static int show_registers (int argc,char **argv,struct command *cmd,struct plugin *plugin)
@@ -3094,7 +3094,7 @@ static int show_registers(int argc, char **argv, struct command *cmd, struct plu close_fd:close (fd); ret: -return err; +return nvme_status_to_errno (err, false); }static int get_property (int argc,char **argv,struct command *cmd,struct plugin *plugin)
@@ -3148,7 +3148,7 @@ static int get_property(int argc, char **argv, struct command *cmd, struct plugi close_fd:close (fd); ret: -return err; +return nvme_status_to_errno (err, false); }static int set_property (int argc,char **argv,struct command *cmd,struct plugin *plugin)
@@ -3205,7 +3205,7 @@ static int set_property(int argc, char **argv, struct command *cmd, struct plugi close_fd:close (fd); ret: -return err; +return nvme_status_to_errno (err, false); }static int format (int argc,char **argv,struct command *cmd,struct plugin *plugin)
@@ -3368,7 +3368,7 @@ static int format(int argc, char **argv, struct command *cmd, struct plugin *plu close_fd:close (fd); ret: -return err; +return nvme_status_to_errno (err, false); }static int set_feature (int argc,char **argv,struct command *cmd,struct plugin *plugin)
@@ -3490,7 +3490,7 @@ static int set_feature(int argc, char **argv, struct command *cmd, struct plugin close_fd:close (fd); ret: -return err; +return nvme_status_to_errno (err, false); }static int sec_send (int argc,char **argv,struct command *cmd,struct plugin *plugin)
@@ -3589,7 +3589,7 @@ static int sec_send(int argc, char **argv, struct command *cmd, struct plugin *p close_fd:close (fd); ret: -return err; +return nvme_status_to_errno (err, false); }static int dir_send (int argc,char **argv,struct command *cmd,struct plugin *plugin)
@@ -3743,7 +3743,7 @@ free: close_fd:close (fd); ret: -return err; +return nvme_status_to_errno (err, false); }static int write_uncor (int argc,char **argv,struct command *cmd,struct plugin *plugin)
@@ -3800,7 +3800,7 @@ static int write_uncor(int argc, char **argv, struct command *cmd, struct plugin close_fd:close (fd); ret: -return err; +return nvme_status_to_errno (err, false); }static int write_zeroes (int argc,char **argv,struct command *cmd,struct plugin *plugin)
@@ -3894,7 +3894,7 @@ static int write_zeroes(int argc, char **argv, struct command *cmd, struct plugi close_fd:close (fd); ret: -return err; +return nvme_status_to_errno (err, false); }static int dsm (int argc,char **argv,struct command *cmd,struct plugin *plugin)
@@ -3997,7 +3997,7 @@ static int dsm(int argc, char **argv, struct command *cmd, struct plugin *plugin close_fd:close (fd); ret: -return err; +return nvme_status_to_errno (err, false); }static int flush (int argc,char **argv,struct command *cmd,struct plugin *plugin)
@@ -4047,7 +4047,7 @@ static int flush(int argc, char **argv, struct command *cmd, struct plugin *plug close_fd:close (fd); ret: -return err; +return nvme_status_to_errno (err, false); }static int resv_acquire (int argc,char **argv,struct command *cmd,struct plugin *plugin)
@@ -4124,7 +4124,7 @@ static int resv_acquire(int argc, char **argv, struct command *cmd, struct plugi close_fd:close (fd); ret: -return err; +return nvme_status_to_errno (err, false); }static int resv_register (int argc,char **argv,struct command *cmd,struct plugin *plugin)
@@ -4204,7 +4204,7 @@ static int resv_register(int argc, char **argv, struct command *cmd, struct plug close_fd:close (fd); ret: -return err; +return nvme_status_to_errno (err, false); }static int resv_release (int argc,char **argv,struct command *cmd,struct plugin *plugin)
@@ -4280,7 +4280,7 @@ static int resv_release(int argc, char **argv, struct command *cmd, struct plugi close_fd:close (fd); ret: -return err; +return nvme_status_to_errno (err, false); }static int resv_report (int argc,char **argv,struct command *cmd,struct plugin *plugin)
@@ -4377,7 +4377,7 @@ static int resv_report(int argc, char **argv, struct command *cmd, struct plugin close_fd:close (fd); ret: -return err; +return nvme_status_to_errno (err, false); } static int submit_io(int opcode, char *command, const char *desc,
@@ -4625,7 +4625,7 @@ static int submit_io(int opcode, char *command, const char *desc, close_fd:close (fd); ret: -return err; +return nvme_status_to_errno (err, false); }static int compare (int argc,char **argv,struct command *cmd,struct plugin *plugin)
@@ -4734,7 +4734,7 @@ static int sec_recv(int argc, char **argv, struct command *cmd, struct plugin *p close_fd:close (fd); ret: -return err; +return nvme_status_to_errno (err, false); }static int dir_receive (int argc,char **argv,struct command *cmd,struct plugin *plugin)
@@ -4867,7 +4867,7 @@ free: close_fd:close (fd); ret: -return err; +return nvme_status_to_errno (err, false); }static int passthru (int argc,char **argv,int ioctl_cmd,const char *desc,struct command *cmd)
@@ -5070,7 +5070,7 @@ static int passthru(int argc, char **argv, int ioctl_cmd, const char *desc, stru close_fd:close (fd); ret: -return err; +return nvme_status_to_errno (err, false); }static int io_passthru (int argc,char **argv,struct command *cmd,struct plugin *plugin)
Signature · 1 line
2.21.0
PATCH v7 6/7 fabrics: return error when discovery retry exhausted
In reply to Minwoo ImIf the discovery page is not updated to the latest one over the 10 times, it's currently returning DISC_OK if the numrec has no problem. If so, the caller might think that the discovery has been successfully done without any errors even there is.
This patch makes it return an error -EAGAIN if retry(10 times) has been exhausted.
--- fabrics.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
fabrics.c +15 -0
@@ -291,6 +291,7 @@ enum {DISC_NO_LOG ,DISC_GET_NUMRECS ,DISC_GET_LOG , +DISC_RETRY_EXHAUSTED , DISC_NOT_EQUAL, };
@@ -385,6 +386,16 @@ static int nvmf_get_log_page_discovery(const char *dev_path, }while (genctr !=le64_to_cpu (log->genctr) && ++retries < max_retries); +/* +* If genctr is still different with the one in the log entry, it +* means the retires have been exhausted to max_retries. Then it +* should be retried by the caller or the user. +*/ +if (genctr !=le64_to_cpu (log->genctr)) { + error =DISC_RETRY_EXHAUSTED ; + goto out_free_log; + } +if (*numrec !=le32_to_cpu (log->numrec)) { error =DISC_NOT_EQUAL ; goto out_free_log;
@@ -882,6 +893,10 @@ static int do_discover(char *argstr, bool connect)fprintf (stdout,"No discovery log entries to fetch.\n" ); ret =DISC_OK ;break ; +case DISC_RETRY_EXHAUSTED : +fprintf (stdout,"Discovery retries exhausted.\n" ); + ret = -EAGAIN ; +break ;case DISC_NOT_EQUAL :fprintf (stderr,"Numrec values of last two get discovery log page not equal\n" );
Signature · 1 line
2.21.0
PATCH v7 7/7 fabrics: Return errno mapped for fabrics error status
In reply to Minwoo ImIf discover has been failed due to a nvme status, it will be returned to main() with mapped value for fabrics get log page command.
Now connect command related status cannot be added in this patch because kernel is not currently returning the nvme status, it's instead returning -EIO if fails. errno for connect command can be added once kernel is ready to return the proper value for nvme status.
--- fabrics.c | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-)
fabrics.c +17 -8
@@ -35,6 +35,7 @@#include "parser.h" #include "nvme-ioctl.h" +#include "nvme-status.h" #include "fabrics.h" #include "nvme.h"
@@ -296,7 +297,7 @@ enum { };static int nvmf_get_log_page_discovery (const char *dev_path, -struct nvmf_disc_rsp_page_hdr **logp,int *numrec) +struct nvmf_disc_rsp_page_hdr **logp,int *numrec,int *status) {struct nvmf_disc_rsp_page_hdr *log;unsigned int hdr_size;
@@ -411,6 +412,7 @@ out_free_log: out_close:close (fd); out: + *status =nvme_status_to_errno (error, true);return error; }
@@ -860,6 +862,7 @@ static int do_discover(char *argstr, bool connect)struct nvmf_disc_rsp_page_hdr *log =NULL ;char *dev_name;int instance, numrec =0 , ret, err; +int status =0 ; instance =add_ctrl (argstr);if (instance <0 )
@@ -867,7 +870,7 @@ static int do_discover(char *argstr, bool connect)if (asprintf (&dev_name,"/dev/nvme%d" , instance) <0 )return -errno; - ret =nvmf_get_log_page_discovery (dev_name, &log, &numrec); + ret =nvmf_get_log_page_discovery (dev_name, &log, &numrec, &status);free (dev_name); err =remove_ctrl (instance);if (err)
@@ -885,9 +888,11 @@ static int do_discover(char *argstr, bool connect)case DISC_GET_NUMRECS :fprintf (stderr,"Get number of discovery log entries failed.\n" ); + ret = status;break ;case DISC_GET_LOG :fprintf (stderr,"Get discovery log entries failed.\n" ); + ret = status;break ;case DISC_NO_LOG :fprintf (stdout,"No discovery log entries to fetch.\n" );
@@ -900,6 +905,7 @@ static int do_discover(char *argstr, bool connect)case DISC_NOT_EQUAL :fprintf (stderr,"Numrec values of last two get discovery log page not equal\n" ); + ret = -EBADSLT ;break ;default :fprintf (stderr,"Get discovery log page failed: %d\n" , ret);
@@ -1015,7 +1021,7 @@ int discover(const char *desc, int argc, char **argv, bool connect) } out: -return ret; +return nvme_status_to_errno (ret, true); }int connect (const char *desc,int argc,char **argv)
@@ -1062,8 +1068,9 @@ int connect(const char *desc, int argc, char **argv) instance =add_ctrl (argstr);if (instance <0 ) ret = instance; + out: -return ret; +return nvme_status_to_errno (ret, true); }static int scan_sys_nvme_filter (const struct dirent *d)
@@ -1196,7 +1203,7 @@ int disconnect(const char *desc, int argc, char **argv) } out: -return ret; +return nvme_status_to_errno (ret, true); }int disconnect_all (const char *desc,int argc,char **argv)
@@ -1223,10 +1230,12 @@ int disconnect_all(const char *desc, int argc, char **argv) ret =disconnect_by_device (ctrl->name);if (ret) - goto out; + goto free; } } -out: + +free:free_subsys_list (slist, subcnt); -return ret; +out: +return nvme_status_to_errno (ret, true); }
Signature · 1 line
2.21.0
Sagi Grimberg
maintainerv7 cover nvme-cli: Introduce nvme-status mapping with errno
In reply to Minwoo ImFor the series:
v7 cover nvme-cli: Introduce nvme-status mapping with errno
In reply to Minwoo ImIn case if missing any of my reviews, this is for the series.
Quoted 80 lines · Minwoo Im
Hi Keith,
Now it's v7 patchset for the nvme-status mapping with errno. Chaitanya has reviewed for the first five patches, and Sagi has suggested to return an error for a case that numrec is different. The 6th and 7th patch will make what Sagi's said.
This patchset introduces nvme-status module to manage mapping relationships between nvme error status and errno. It cannot be directly mapped in 1:1, but we can figure out what kind of errors happended by the return value of nvme-cli.
NVMe status fields are 16bits to indicate, but UNIX return value from
main()will be parsed in 8bits so that we need to do something about return value to indicate nvme error status.This patch series has been tested with:
- nvme pcie device controller/namespaces
- nvme loop target with nvme-fabricsThe branch on github can be found at:
https://github.com/minwooim/nvme-cli.git for-1.9/return-negative-errno-v7Please pick this series.
Thanks,Changes to previous V6:
- Added Reviewed-by: tags of Chaitanya for the first and second commmits.
- Added a new command(6th) which makes it return an error when the fabrics discovery retry(10 times) exhausted.
- Sagi has suggested that when numrec is different from the expected value, then it should return an error. The 7th patch will do it.Changes to previous V5:
- The first patch has been updated being without an whitespace in front of newlabel("ret")in a function. The other lables added followed the existing style in where it belongs to.
The default style would be great to follow the kernel style which is non-space label, as suggested by Chaitanya.
- The second patch has been updated to have "out" named label just like the others in that file(fabrics).
- No functional changed in this version 6. Only style change has been applied.Changes to previous V4:
- Add the first three patches before introducing errno mapping module.Changes to previous V3:
- Fix to return 0 when given error is 0 which means success. (Chaitanya)Changes to previous V2:
- do not overwrite the err local variable, instead returning the converted errno mapped directly.
- return ECOMM in case of linux internal err which indicates the negative values from in the middle of the subcommand.Changes to previous V1:
- make switch-case inline in nvme-status (Chaitanya)Minwoo Im (7):
nvme: Do not return in the middle of the subcommand
fabrics: Do not return in the middle of the subcommand
nvme: Return negative error value for internal errors
nvme-status: Introduce nvme status module to map errno
nvme: Return errno mapped for nvme error status
fabrics: return error when discovery retry exhausted
fabrics: Return errno mapped for fabrics error statusMakefile | 3 +- fabrics.c | 67 +++-- linux/nvme.h | 6 + nvme-status.c | 155 +++++++++++ nvme-status.h | 14 + nvme.c | 701 ++++++++++++++++++++++++++++++-------------------- 6 files changed, 641 insertions(+), 305 deletions(-)create mode 100644
nvme-status.c
create mode 100644nvme-status.h
v7 cover nvme-cli: Introduce nvme-status mapping with errno
In reply to Minwoo ImQuoted 6 lines · Minwoo Im
Hi Keith,
Now it's v7 patchset for the nvme-status mapping with errno. Chaitanya has reviewed for the first five patches, and Sagi has suggested to return an error for a case that numrec is different. The 6th and 7th patch will make what Sagi's said.
Hi Keith,
I will put this series to the Github PR for your convenience.
Thanks in advance,
(Also thanks to Sagi and Chaitanya for the reviews :))