From 35f293b29d4c34bba6d082e0f53f61c9dd3a4bb7 Mon Sep 17 00:00:00 2001 From: Broc Going Date: Thu, 23 Apr 2026 11:01:25 -0700 Subject: [PATCH] compat (errno): Adds cross-platform compatibility for errno values. Some errno values used in the code are only available on Linux. Adds compatible handling of errno values not available on all platforms. - Substitutes good equivalent errno value for unsupported values used by nvme/util.c when converting status to errno. - Replaces ENAVAIL usage in nvme.c with a local error code. It is only used internally within nvme.c to signal that an "invalid field" error was returned and should be ignored. Signed-off-by: Broc Going --- libnvme/src/nvme/util.c | 11 +++++++++++ nvme.c | 16 +++++++++++----- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/libnvme/src/nvme/util.c b/libnvme/src/nvme/util.c index da4449ceb4..e2f0273d84 100644 --- a/libnvme/src/nvme/util.c +++ b/libnvme/src/nvme/util.c @@ -43,6 +43,17 @@ #define LINE_MAX 2048 #endif +/* Some error codes aren't defined on all platforms. Use best equivalents. */ +#ifndef EREMOTEIO +#define EREMOTEIO ENXIO +#endif +#ifndef EDQUOT +#define EDQUOT ENOSPC +#endif +#ifndef ERESTART +#define ERESTART EAGAIN +#endif + /* Source Code Control System, query version of binary with 'what' */ const char sccsid[] = "@(#)libnvme " GIT_VERSION; diff --git a/nvme.c b/nvme.c index c074b4f962..fb60a035a3 100644 --- a/nvme.c +++ b/nvme.c @@ -7371,6 +7371,12 @@ static void get_pif_sts(struct nvme_id_ns *ns, struct nvme_nvm_id_ns *nvm_ns, *pif = (elbaf & NVME_NVM_ELBAF_QPIF_MASK) >> 9; } +/* + * Internal return code used to flag that an invalid field error was received + * and should be ignored by the calling code. + */ +#define ERR_IGNORE_INVALID_FIELD 0x2000 /* invalid field error - ignore */ + static int get_pi_info(struct libnvme_transport_handle *hdl, __u32 nsid, __u8 prinfo, __u64 ilbrt, __u64 lbst, unsigned int *logical_block_size, __u16 *metadata_size) @@ -7412,7 +7418,7 @@ static int get_pi_info(struct libnvme_transport_handle *hdl, * Keep the I/O commands behavior same as before. * Since the error returned by drives unsupported. */ - return -ENAVAIL; + return ERR_IGNORE_INVALID_FIELD; pi_size = (pif == NVME_NVM_PIF_16B_GUARD) ? 8 : 16; if (NVME_FLBAS_META_EXT(ns->flbas)) { @@ -7467,7 +7473,7 @@ static int init_pi_tags(struct libnvme_transport_handle *hdl, * Keep the I/O commands behavior same as before. * Since the error returned by drives unsupported. */ - return -ENAVAIL; + return ERR_IGNORE_INVALID_FIELD; if (invalid_tags(lbst, ilbrt, sts, pif)) return -EINVAL; @@ -7583,7 +7589,7 @@ static int write_zeroes(int argc, char **argv, err = init_pi_tags(hdl, &cmd, cfg.nsid, cfg.ilbrt, cfg.lbst, cfg.lbat, cfg.lbatm); - if (err && err != -ENAVAIL) + if (err && err != ERR_IGNORE_INVALID_FIELD) return err; err = libnvme_submit_io_passthru(hdl, &cmd); @@ -7926,7 +7932,7 @@ static int copy_cmd(int argc, char **argv, struct command *acmd, struct plugin * cfg.fua, cfg.lr, 0, cfg.dspec, copy->f0); err = init_pi_tags(hdl, &cmd, cfg.nsid, cfg.ilbrt, cfg.lbst, cfg.lbat, cfg.lbatm); - if (err != 0 && err != -ENAVAIL) + if (err != 0 && err != ERR_IGNORE_INVALID_FIELD) return err; err = libnvme_submit_io_passthru(hdl, &cmd); if (err) { @@ -8765,7 +8771,7 @@ static int verify_cmd(int argc, char **argv, struct command *acmd, struct plugin cfg.block_count, control, 0, NULL, 0, NULL, 0); err = init_pi_tags(hdl, &cmd, cfg.nsid, cfg.ilbrt, cfg.lbst, cfg.lbat, cfg.lbatm); - if (err != 0 && err != -ENAVAIL) + if (err != 0 && err != ERR_IGNORE_INVALID_FIELD) return err; err = libnvme_submit_io_passthru(hdl, &cmd); if (err) {