From: Hannes Reinecke Date: Thu, 4 Apr 2024 07:07:33 +0000 (+0200) Subject: ioctl: return EPROTO when an NVMe status occurred X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=3089da58d2c35b3b700c1eb88540f96cfe0e87ad;p=users%2Fsagi%2Flibnvme.git ioctl: return EPROTO when an NVMe status occurred The ioctl might return 0, but the NVMe status might indicate an error. In these cases we should return EPROTO to indicate that the command did not succeed. Signed-off-by: Hannes Reinecke --- diff --git a/src/nvme/ioctl.c b/src/nvme/ioctl.c index ce5a911a..fa7d70d8 100644 --- a/src/nvme/ioctl.c +++ b/src/nvme/ioctl.c @@ -85,8 +85,14 @@ int nvme_submit_passthru64(int fd, unsigned long ioctl_cmd, { int err = ioctl(fd, ioctl_cmd, cmd); - if (err >= 0 && result) - *result = cmd->result; + if (err >= 0) { + if (result) + *result = cmd->result; + if (cmd->result) { + errno = EPROTO; + err = -1; + } + } return err; } @@ -96,8 +102,14 @@ int nvme_submit_passthru(int fd, unsigned long ioctl_cmd, { int err = ioctl(fd, ioctl_cmd, cmd); - if (err >= 0 && result) - *result = cmd->result; + if (err >= 0) { + if (result) + *result = cmd->result; + if (cmd->result) { + errno = EPROTO; + err = -1; + } + } return err; } diff --git a/test/ioctl/features.c b/test/ioctl/features.c index 73864979..3c452100 100644 --- a/test/ioctl/features.c +++ b/test/ioctl/features.c @@ -17,7 +17,7 @@ #define TEST_CDW15 0x15151515 #define TEST_UUIDX 0b1001110 #define TEST_FID 0xFE -#define TEST_RESULT 0x12345678 +#define TEST_RESULT 0x0 #define TEST_SEL NVME_GET_FEATURES_SEL_SAVED #define TEST_SC NVME_SC_INVALID_FIELD