]> www.infradead.org Git - users/sagi/libnvme.git/commitdiff
ioctl: return EPROTO when an NVMe status occurred
authorHannes Reinecke <hare@suse.de>
Thu, 4 Apr 2024 07:07:33 +0000 (09:07 +0200)
committerDaniel Wagner <wagi@monom.org>
Tue, 9 Apr 2024 12:47:59 +0000 (14:47 +0200)
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 <hare@suse.de>
src/nvme/ioctl.c
test/ioctl/features.c

index ce5a911a2ae3d3bc022466d7de7b236fb95e94aa..fa7d70d844bf04e0cc255dd9b3b2c2f8ab208b31 100644 (file)
@@ -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;
 }
 
index 738649799e11cca6fd7db41580050a1031b2a1a4..3c452100720e688b9a6ab8315b9de004e6b7071d 100644 (file)
@@ -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