nvme-cli: Introduce nvme-status mapping with errno
v4 cover nvme-cli: Introduce nvme-status mapping with errno
Hi,
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.
Please review.
Thanks,
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 (3):
nvme-status: Introduce nvme status module to map errno
nvme: Return errno mapped for nvme error status
fabrics: Return errno mapped for fabrics error status
Makefile | 3 +- fabrics.c | 18 ++++-- linux/nvme.h | 6 ++ nvme-status.c | 155 ++++++++++++++++++++++++++++++++++++++++++++++++++ nvme-status.h | 14 +++++ nvme.c | 108 ++++++++++++++--------------------- 6 files changed, 233 insertions(+), 71 deletions(-) create mode 100644 nvme-status.c create mode 100644 nvme-status.h
Signature · 1 line
2.21.0
PATCH v4 1/3 nvme-status: Introduce nvme status module to map errno
Background:
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 v4 2/3 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 | 108 +++++++++++++++++++++++---------------------------------- 1 file changed, 43 insertions(+), 65 deletions(-)
nvme.c +43 -65
@@ -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"
@@ -220,7 +221,7 @@ static int get_smart_log(int argc, char **argv, struct command *cmd, struct plug close_fd:close (fd); -return err; +return nvme_status_to_errno (err, false); } static int get_ana_log(int argc, char **argv, struct command *cmd,
@@ -292,7 +293,7 @@ static int get_ana_log(int argc, char **argv, struct command *cmd,free (ana_log); close_fd:close (fd); -return err; +return nvme_status_to_errno (err, false); }static int get_telemetry_log (int argc,char **argv,struct command *cmd,struct plugin *plugin)
@@ -419,7 +420,7 @@ static int get_telemetry_log(int argc, char **argv, struct command *cmd, structfree (page_log); close_fd:close (fd); -return err; +return nvme_status_to_errno (err, false); }static int get_endurance_log (int argc,char **argv,struct command *cmd,struct plugin *plugin)
@@ -473,7 +474,7 @@ static int get_endurance_log(int argc, char **argv, struct command *cmd, struct close_fd:close (fd); -return err; +return nvme_status_to_errno (err, false); }static int get_effects_log (int argc,char **argv,struct command *cmd,struct plugin *plugin)
@@ -535,7 +536,7 @@ static int get_effects_log(int argc, char **argv, struct command *cmd, struct pl close_fd:close (fd); -return err; +return nvme_status_to_errno (err, false); }static int get_error_log (int argc,char **argv,struct command *cmd,struct plugin *plugin)
@@ -619,7 +620,7 @@ static int get_error_log(int argc, char **argv, struct command *cmd, struct plug close_fd:close (fd); -return err; +return nvme_status_to_errno (err, false); }static int get_fw_log (int argc,char **argv,struct command *cmd,struct plugin *plugin)
@@ -673,7 +674,7 @@ static int get_fw_log(int argc, char **argv, struct command *cmd, struct plugin close_fd:close (fd); -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)
@@ -728,8 +729,7 @@ static int get_changed_ns_list_log(int argc, char **argv, struct command *cmd, s close_fd:close (fd); - -return err; +return nvme_status_to_errno (err, false); }static int get_log (int argc,char **argv,struct command *cmd,struct plugin *plugin)
@@ -828,7 +828,7 @@ static int get_log(int argc, char **argv, struct command *cmd, struct plugin *pl close_fd:close (fd); -return err; +return nvme_status_to_errno (err, false); }static int sanitize_log (int argc,char **argv,struct command *command,struct plugin *plugin)
@@ -890,8 +890,7 @@ static int sanitize_log(int argc, char **argv, struct command *command, struct p close_fd:close (fd); - -return ret; +return nvme_status_to_errno (ret, false); }static int list_ctrl (int argc,char **argv,struct command *cmd,struct plugin *plugin)
@@ -941,11 +940,9 @@ static int list_ctrl(int argc, char **argv, struct command *cmd, struct plugin *perror ("id controller list" );free (cntlist); - close_fd:close (fd); - -return err; +return nvme_status_to_errno (err, false); }static int list_ns (int argc,char **argv,struct command *cmd,struct plugin *plugin)
@@ -988,8 +985,7 @@ static int list_ns(int argc, char **argv, struct command *cmd, struct plugin *plperror ("id namespace list" );close (fd); - -return err; +return nvme_status_to_errno (err, false); }static int get_nsid (int fd)
@@ -1060,8 +1056,7 @@ static int delete_ns(int argc, char **argv, struct command *cmd, struct plugin * close_fd:close (fd); - -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)
@@ -1125,8 +1120,7 @@ static int nvme_attach_ns(int argc, char **argv, int attach, const char *desc, s close_fd:close (fd); - -return err; +return nvme_status_to_errno (err, false); }static int attach_ns (int argc,char **argv,struct command *cmd,struct plugin *plugin)
@@ -1253,8 +1247,7 @@ static int create_ns(int argc, char **argv, struct command *cmd, struct plugin * close_fd:close (fd); - -return err; +return nvme_status_to_errno (err, false); }char *nvme_char_from_block (char *block)
@@ -1867,8 +1860,7 @@ static int list(int argc, char **argv, struct command *cmd, struct plugin *plugifor (i =0 ; i < n; i++)free (devices[i]);free (devices); - -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))
@@ -1941,8 +1933,7 @@ int __id_ctrl(int argc, char **argv, struct command *cmd, struct plugin *plugin, close_fd:close (fd); - -return err; +return nvme_status_to_errno (err, false); }static int id_ctrl (int argc,char **argv,struct command *cmd,struct plugin *plugin)
@@ -2022,8 +2013,7 @@ static int ns_descs(int argc, char **argv, struct command *cmd, struct plugin *p close_fd:close (fd); - -return err; +return nvme_status_to_errno (err, false); }static int id_ns (int argc,char **argv,struct command *cmd,struct plugin *plugin)
@@ -2109,8 +2099,7 @@ static int id_ns(int argc, char **argv, struct command *cmd, struct plugin *plug close_fd:close (fd); - -return err; +return nvme_status_to_errno (err, false); }static int id_nvmset (int argc,char **argv,struct command *cmd,struct plugin *plugin)
@@ -2167,8 +2156,7 @@ static int id_nvmset(int argc, char **argv, struct command *cmd, struct plugin * close_fd:close (fd); - -return err; +return nvme_status_to_errno (err, false); }static int get_ns_id (int argc,char **argv,struct command *cmd,struct plugin *plugin)
@@ -2256,8 +2244,7 @@ static int virtual_mgmt(int argc, char **argv, struct command *cmd, struct plugiperror ("virt-mgmt" );close (fd); -return err; - +return nvme_status_to_errno (err, false); }static int list_secondary_ctrl (int argc,char **argv,struct command *cmd,struct plugin *plugin)
@@ -2381,7 +2368,7 @@ static int device_self_test(int argc, char **argv, struct command *cmd, struct pperror ("Device self-test" );close (fd); -return err; +return nvme_status_to_errno (err, false); }static int self_test_log (int argc,char **argv,struct command *cmd,struct plugin *plugin)
@@ -2436,8 +2423,7 @@ static int self_test_log(int argc, char **argv, struct command *cmd, struct plug close_fd:close (fd); - -return err; +return nvme_status_to_errno (err, false); }static int get_feature (int argc,char **argv,struct command *cmd,struct plugin *plugin)
@@ -2567,8 +2553,7 @@ static int get_feature(int argc, char **argv, struct command *cmd, struct plugin close_fd:close (fd); - -return err; +return nvme_status_to_errno (err, false); }static int fw_download (int argc,char **argv,struct command *cmd,struct plugin *plugin)
@@ -2672,8 +2657,7 @@ static int fw_download(int argc, char **argv, struct command *cmd, struct pluginclose (fw_fd); close_fd:close (fd); - -return err; +return nvme_status_to_errno (err, false); }static char *nvme_fw_status_reset_type (__u32 status)
@@ -2765,8 +2749,7 @@ static int fw_commit(int argc, char **argv, struct command *cmd, struct plugin * close_fd:close (fd); - -return err; +return nvme_status_to_errno (err, false); }static int subsystem_reset (int argc,char **argv,struct command *cmd,struct plugin *plugin)
@@ -2933,8 +2916,7 @@ static int sanitize(int argc, char **argv, struct command *cmd, struct plugin *p close_fd:close (fd); - -return ret; +return nvme_status_to_errno (ret, false); }static int show_registers (int argc,char **argv,struct command *cmd,struct plugin *plugin)
@@ -3058,8 +3040,7 @@ static int get_property(int argc, char **argv, struct command *cmd, struct plugi close_fd:close (fd); - -return err; +return nvme_status_to_errno (err, false); }static int set_property (int argc,char **argv,struct command *cmd,struct plugin *plugin)
@@ -3113,8 +3094,7 @@ static int set_property(int argc, char **argv, struct command *cmd, struct plugi close_fd:close (fd); - -return err; +return nvme_status_to_errno (err, false); }static int format (int argc,char **argv,struct command *cmd,struct plugin *plugin)
@@ -3274,8 +3254,7 @@ static int format(int argc, char **argv, struct command *cmd, struct plugin *plu close_fd:close (fd); - -return err; +return nvme_status_to_errno (err, false); }static int set_feature (int argc,char **argv,struct command *cmd,struct plugin *plugin)
@@ -3394,7 +3373,7 @@ static int set_feature(int argc, char **argv, struct command *cmd, struct pluginfree (buf); close_fd:close (fd); -return err; +return nvme_status_to_errno (err, false); }static int sec_send (int argc,char **argv,struct command *cmd,struct plugin *plugin)
@@ -3641,7 +3620,7 @@ free:free (buf); close_fd:close (fd); -return err; +return nvme_status_to_errno (err, false); }static int write_uncor (int argc,char **argv,struct command *cmd,struct plugin *plugin)
@@ -3695,8 +3674,7 @@ static int write_uncor(int argc, char **argv, struct command *cmd, struct plugin close_fd:close (fd); - -return err; +return nvme_status_to_errno (err, false); }static int write_zeroes (int argc,char **argv,struct command *cmd,struct plugin *plugin)
@@ -3787,7 +3765,7 @@ static int write_zeroes(int argc, char **argv, struct command *cmd, struct plugi close_fd:close (fd); -return err; +return nvme_status_to_errno (err, false); }static int dsm (int argc,char **argv,struct command *cmd,struct plugin *plugin)
@@ -3887,7 +3865,7 @@ static int dsm(int argc, char **argv, struct command *cmd, struct plugin *plugin close_fd:close (fd); -return err; +return nvme_status_to_errno (err, false); }static int flush (int argc,char **argv,struct command *cmd,struct plugin *plugin)
@@ -3934,7 +3912,7 @@ static int flush(int argc, char **argv, struct command *cmd, struct plugin *plugprintf ("NVMe Flush: success\n" ); close_fd:close (fd); -return err; +return nvme_status_to_errno (err, false); }static int resv_acquire (int argc,char **argv,struct command *cmd,struct plugin *plugin)
@@ -4008,7 +3986,7 @@ static int resv_acquire(int argc, char **argv, struct command *cmd, struct plugi close_fd:close (fd); -return err; +return nvme_status_to_errno (err, false); }static int resv_register (int argc,char **argv,struct command *cmd,struct plugin *plugin)
@@ -4085,7 +4063,7 @@ static int resv_register(int argc, char **argv, struct command *cmd, struct plug close_fd:close (fd); -return err; +return nvme_status_to_errno (err, false); }static int resv_release (int argc,char **argv,struct command *cmd,struct plugin *plugin)
@@ -4158,7 +4136,7 @@ static int resv_release(int argc, char **argv, struct command *cmd, struct plugi close_fd:close (fd); -return err; +return nvme_status_to_errno (err, false); }static int resv_report (int argc,char **argv,struct command *cmd,struct plugin *plugin)
@@ -4497,7 +4475,7 @@ static int submit_io(int opcode, char *command, const char *desc,close (dfd); close_fd:close (fd); -return err; +return nvme_status_to_errno (err, false); }static int compare (int argc,char **argv,struct command *cmd,struct plugin *plugin)
@@ -4733,7 +4711,7 @@ free:free (buf); close_fd:close (fd); -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)
@@ -4933,7 +4911,7 @@ static int passthru(int argc, char **argv, int ioctl_cmd, const char *desc, struclose (wfd); close_fd:close (fd); -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 v4 3/3 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 | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-)
fabrics.c +13 -5
@@ -35,6 +35,7 @@#include "parser.h" #include "nvme-ioctl.h" +#include "nvme-status.h" #include "fabrics.h" #include "nvme.h"
@@ -295,7 +296,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;
@@ -400,6 +401,7 @@ out_free_log: out_close:close (fd); out: + *status =nvme_status_to_errno (error, true);return error; }
@@ -849,6 +851,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 )
@@ -856,7 +859,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)
@@ -874,9 +877,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" );
@@ -885,6 +890,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 =DISC_OK ;break ;default :fprintf (stderr,"Get discovery log page failed: %d\n" , ret);
@@ -989,15 +995,17 @@ int discover(const char *desc, int argc, char **argv, bool connect) 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; +return nvme_status_to_errno (ret, true); -return do_discover (argstr, connect); + ret =do_discover (argstr, connect); } + +return nvme_status_to_errno (ret, true); }int connect (const char *desc,int argc,char **argv)
Signature · 1 line
2.21.0
v4 cover nvme-cli: Introduce nvme-status mapping with errno
In reply to Minwoo ImPlease do not review on this series yet. I seems like to fix multi-return in the subcommands also.
Will post V5 soon.