nvmet-file: fix nvmet_file_flush() always returning an error
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.
--- drivers/nvme/target/io-cmd-file.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/nvme/target/io-cmd-file.c +7 -1
@@ -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
Looks good,
Christoph Hellwig
maintainerQuoted 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.
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_statusto avoid future problems like this one as well? That would also match the similarblk_to_nvme_statusfunction 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