errno_to_nvme_status() doesn't take into account the case
when errno=0, all other use cases only call it if there is actually
an error.

Presently, nvmet_file_flush() always returns a call to
errno_to_nvme_status() so, even if it is successful, it will
return NVME_SC_INTERNAL.

This bug was found while trying to get the existing blktests to pass.

Fixes: c6aa3542e010 ("nvmet: add error log support for file backend")
Signed-off-by: Logan Gunthorpe <log...@deltatee.com>
Cc: Chaitanya Kulkarni <chaitanya.kulka...@wdc.com>
---
 drivers/nvme/target/io-cmd-file.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/drivers/nvme/target/io-cmd-file.c 
b/drivers/nvme/target/io-cmd-file.c
index 05453f5d1448..fec17c66b8cd 100644
--- a/drivers/nvme/target/io-cmd-file.c
+++ b/drivers/nvme/target/io-cmd-file.c
@@ -261,7 +261,13 @@ static void nvmet_file_execute_rw(struct nvmet_req *req)
 
 u16 nvmet_file_flush(struct nvmet_req *req)
 {
-       return errno_to_nvme_status(req, vfs_fsync(req->ns->file, 1));
+       int ret;
+
+       ret = vfs_fsync(req->ns->file, 1);
+       if (ret)
+               return errno_to_nvme_status(req, ret);
+
+       return NVME_SC_SUCCESS;
 }
 
 static void nvmet_file_flush_work(struct work_struct *w)
-- 
2.20.1

Reply via email to