Skip to contentSkip to conversation

nvmet-file: fix nvmet_file_flush() always returning an error

PATCH Superseded Logan Gunthorpe 3 participants 4 messages Jul 12, 2019 – Jul 14, 2019 NVMe target

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 nvmet-file: fix nvmet_file_flush() always returning an error

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")
Cc Chaitanya Kulkarni <[email protected]>
---
 drivers/nvme/target/io-cmd-file.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/nvme/target/io-cmd-file.c +7 -1
index 05453f5d1448..fec17c66b8cd 100644
@@ -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)
Signature · 1 line
2.20.1
#2 lore raw
In reply to Logan Gunthorpe
Quoted 3 lines · Logan Gunthorpe

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.

Might it make more sense to handle 0 in errno_to_nvme_status to avoid future problems like this one as well? That would also match the similar blk_to_nvme_status function better.

#3 lore raw
Quoted 8 lines · Christoph Hellwig
Quoted 3 lines · Logan Gunthorpe

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.

Might it make more sense to handle 0 in errno_to_nvme_status to avoid future problems like this one as well? That would also match the similar blk_to_nvme_status function better.

Sure, I'll send a v2 with that approach next week.

I had assumed that it was done this way for performance reasons so I followed the way it was done in the other call sites.

Logan