Skip to content

Commit 35f293b

Browse files
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 <[email protected]>
1 parent d801e1e commit 35f293b

2 files changed

Lines changed: 22 additions & 5 deletions

File tree

libnvme/src/nvme/util.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,17 @@
4343
#define LINE_MAX 2048
4444
#endif
4545

46+
/* Some error codes aren't defined on all platforms. Use best equivalents. */
47+
#ifndef EREMOTEIO
48+
#define EREMOTEIO ENXIO
49+
#endif
50+
#ifndef EDQUOT
51+
#define EDQUOT ENOSPC
52+
#endif
53+
#ifndef ERESTART
54+
#define ERESTART EAGAIN
55+
#endif
56+
4657
/* Source Code Control System, query version of binary with 'what' */
4758
const char sccsid[] = "@(#)libnvme " GIT_VERSION;
4859

nvme.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7371,6 +7371,12 @@ static void get_pif_sts(struct nvme_id_ns *ns, struct nvme_nvm_id_ns *nvm_ns,
73717371
*pif = (elbaf & NVME_NVM_ELBAF_QPIF_MASK) >> 9;
73727372
}
73737373

7374+
/*
7375+
* Internal return code used to flag that an invalid field error was received
7376+
* and should be ignored by the calling code.
7377+
*/
7378+
#define ERR_IGNORE_INVALID_FIELD 0x2000 /* invalid field error - ignore */
7379+
73747380
static int get_pi_info(struct libnvme_transport_handle *hdl,
73757381
__u32 nsid, __u8 prinfo, __u64 ilbrt, __u64 lbst,
73767382
unsigned int *logical_block_size, __u16 *metadata_size)
@@ -7412,7 +7418,7 @@ static int get_pi_info(struct libnvme_transport_handle *hdl,
74127418
* Keep the I/O commands behavior same as before.
74137419
* Since the error returned by drives unsupported.
74147420
*/
7415-
return -ENAVAIL;
7421+
return ERR_IGNORE_INVALID_FIELD;
74167422

74177423
pi_size = (pif == NVME_NVM_PIF_16B_GUARD) ? 8 : 16;
74187424
if (NVME_FLBAS_META_EXT(ns->flbas)) {
@@ -7467,7 +7473,7 @@ static int init_pi_tags(struct libnvme_transport_handle *hdl,
74677473
* Keep the I/O commands behavior same as before.
74687474
* Since the error returned by drives unsupported.
74697475
*/
7470-
return -ENAVAIL;
7476+
return ERR_IGNORE_INVALID_FIELD;
74717477

74727478
if (invalid_tags(lbst, ilbrt, sts, pif))
74737479
return -EINVAL;
@@ -7583,7 +7589,7 @@ static int write_zeroes(int argc, char **argv,
75837589

75847590
err = init_pi_tags(hdl, &cmd, cfg.nsid, cfg.ilbrt, cfg.lbst, cfg.lbat,
75857591
cfg.lbatm);
7586-
if (err && err != -ENAVAIL)
7592+
if (err && err != ERR_IGNORE_INVALID_FIELD)
75877593
return err;
75887594

75897595
err = libnvme_submit_io_passthru(hdl, &cmd);
@@ -7926,7 +7932,7 @@ static int copy_cmd(int argc, char **argv, struct command *acmd, struct plugin *
79267932
cfg.fua, cfg.lr, 0, cfg.dspec, copy->f0);
79277933
err = init_pi_tags(hdl, &cmd, cfg.nsid, cfg.ilbrt, cfg.lbst, cfg.lbat,
79287934
cfg.lbatm);
7929-
if (err != 0 && err != -ENAVAIL)
7935+
if (err != 0 && err != ERR_IGNORE_INVALID_FIELD)
79307936
return err;
79317937
err = libnvme_submit_io_passthru(hdl, &cmd);
79327938
if (err) {
@@ -8765,7 +8771,7 @@ static int verify_cmd(int argc, char **argv, struct command *acmd, struct plugin
87658771
cfg.block_count, control, 0, NULL, 0, NULL, 0);
87668772
err = init_pi_tags(hdl, &cmd, cfg.nsid, cfg.ilbrt, cfg.lbst,
87678773
cfg.lbat, cfg.lbatm);
8768-
if (err != 0 && err != -ENAVAIL)
8774+
if (err != 0 && err != ERR_IGNORE_INVALID_FIELD)
87698775
return err;
87708776
err = libnvme_submit_io_passthru(hdl, &cmd);
87718777
if (err) {

0 commit comments

Comments
 (0)