Commit 1b72b71f authored by Sagi Grimberg's avatar Sagi Grimberg Committed by Christoph Hellwig

nvmet: fix file discard return status

If nvmet_copy_from_sgl failed, we falsly return successful
completion status.

Fixes: d5eff33e ("nvmet: add simple file backed ns support")
Signed-off-by: default avatarSagi Grimberg <sagi@grimberg.me>
Reviewed-by: default avatarChaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
parent 75862c72
...@@ -227,22 +227,24 @@ static void nvmet_file_execute_discard(struct nvmet_req *req) ...@@ -227,22 +227,24 @@ static void nvmet_file_execute_discard(struct nvmet_req *req)
{ {
int mode = FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE; int mode = FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE;
struct nvme_dsm_range range; struct nvme_dsm_range range;
loff_t offset; loff_t offset, len;
loff_t len; u16 ret;
int i, ret; int i;
for (i = 0; i <= le32_to_cpu(req->cmd->dsm.nr); i++) { for (i = 0; i <= le32_to_cpu(req->cmd->dsm.nr); i++) {
if (nvmet_copy_from_sgl(req, i * sizeof(range), &range, ret = nvmet_copy_from_sgl(req, i * sizeof(range), &range,
sizeof(range))) sizeof(range));
if (ret)
break; break;
offset = le64_to_cpu(range.slba) << req->ns->blksize_shift; offset = le64_to_cpu(range.slba) << req->ns->blksize_shift;
len = le32_to_cpu(range.nlb) << req->ns->blksize_shift; len = le32_to_cpu(range.nlb) << req->ns->blksize_shift;
ret = vfs_fallocate(req->ns->file, mode, offset, len); if (vfs_fallocate(req->ns->file, mode, offset, len)) {
if (ret) ret = NVME_SC_INTERNAL | NVME_SC_DNR;
break; break;
}
} }
nvmet_req_complete(req, ret < 0 ? NVME_SC_INTERNAL | NVME_SC_DNR : 0); nvmet_req_complete(req, ret);
} }
static void nvmet_file_dsm_work(struct work_struct *w) static void nvmet_file_dsm_work(struct work_struct *w)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment