Skip to contentSkip to conversation

nvmet: ignore EOPNOTSUPP for discard

PATCH New Christoph Hellwig 4 participants 5 messages Mar 12, 2019

Subsystems (2)
lore
Share & tools
lore

Christoph Hellwig

author maintainer
#0 lore raw

PATCH 1/1 nvmet: ignore EOPNOTSUPP for discard

NVMe DSM is a pure hint, so if the underlying device / file system does not support discard-like operations we should not fail the operation but rather return success.

Signed-off-by Christoph Hellwig <hch at lst.de>
---
 drivers/nvme/target/io-cmd-bdev.c | 7 ++++---
 drivers/nvme/target/io-cmd-file.c | 2 +-
 2 files changed, 5 insertions(+), 4 deletions(-)
drivers/nvme/target/io-cmd-bdev.c +4 -3
index 71dfedbadc26..28d742d7bdaf 100644
@@ -194,11 +194,12 @@ static u16 nvmet_bdev_discard_range(struct nvmet_req *req,
 			le64_to_cpu(range->slba) << (ns->blksize_shift - 9),
 			le32_to_cpu(range->nlb) << (ns->blksize_shift - 9),
 			GFP_KERNEL, 0, bio);
-
-	if (ret)
+	if (ret && ret != -EOPNOTSUPP) {
 		req->error_slba = le64_to_cpu(range->slba);
+		return errno_to_nvme_status(req, ret);
+	}
 
-	return blk_to_nvme_status(req, errno_to_blk_status(ret));
+	return 0;
 }
 
 static void nvmet_bdev_execute_discard(struct nvmet_req *req)
drivers/nvme/target/io-cmd-file.c +1 -1
index 517522305e5c..3e43212d3c1c 100644
@@ -297,7 +297,7 @@ static void nvmet_file_execute_discard(struct nvmet_req *req)
 		}
 
 		ret = vfs_fallocate(req->ns->file, mode, offset, len);
-		if (ret) {
+		if (ret && ret != -EOPNOTSUPP) {
 			req->error_slba = le64_to_cpu(range.slba);
 			status = errno_to_nvme_status(req, ret);
 			break;
Signature · 1 line
2.20.1
#1 lore raw

PATCH 1/1 nvmet: ignore EOPNOTSUPP for discard

Looks good.

Reviewed by: Chaitanya Kulkarni <chaitanya.kulkarni at wdc.com>.

Quoted 44 lines · Christoph Hellwig

NVMe DSM is a pure hint, so if the underlying device / file system does not support discard-like operations we should not fail the operation but rather return success.

Signed-off-by Christoph Hellwig <hch at lst.de>
---
  drivers/nvme/target/io-cmd-bdev.c | 7 ++++---
  drivers/nvme/target/io-cmd-file.c | 2 +-
  2 files changed, 5 insertions(+), 4 deletions(-)
drivers/nvme/target/io-cmd-bdev.c +4 -3
index 71dfedbadc26..28d742d7bdaf 100644
@@ -194,11 +194,12 @@ static u16 nvmet_bdev_discard_range(struct nvmet_req *req,
  			le64_to_cpu(range->slba) << (ns->blksize_shift - 9),
  			le32_to_cpu(range->nlb) << (ns->blksize_shift - 9),
  			GFP_KERNEL, 0, bio);
-
-	if (ret)
+	if (ret && ret != -EOPNOTSUPP) {
  		req->error_slba = le64_to_cpu(range->slba);
+		return errno_to_nvme_status(req, ret);
+	}
 
-	return blk_to_nvme_status(req, errno_to_blk_status(ret));
+	return 0;
  }
 
  static void nvmet_bdev_execute_discard(struct nvmet_req *req)
drivers/nvme/target/io-cmd-file.c +1 -1
index 517522305e5c..3e43212d3c1c 100644
@@ -297,7 +297,7 @@ static void nvmet_file_execute_discard(struct nvmet_req *req)
  		}
 
  		ret = vfs_fallocate(req->ns->file, mode, offset, len);
-		if (ret) {
+		if (ret && ret != -EOPNOTSUPP) {
  			req->error_slba = le64_to_cpu(range.slba);
  			status = errno_to_nvme_status(req, ret);
  			break;
author maintainer
#2 lore raw

PATCH 1/1 nvmet: ignore EOPNOTSUPP for discard

Btw, one bit missing in the description is that it also converts directly from the errno to the nvme status code for io-cmd-bdev.c, but I guess that should really be a separate patch. I'll resend it as two patches with the reviewed-by tags added, if any of you wants to revoke their reviews, let me know.

#3 lore raw

PATCH 1/1 nvmet: ignore EOPNOTSUPP for discard

In reply to Christoph Hellwig
Quoted 35 lines · Christoph Hellwig

NVMe DSM is a pure hint, so if the underlying device / file system does not support discard-like operations we should not fail the operation but rather return success.

Signed-off-by Christoph Hellwig <hch at lst.de>
---
 drivers/nvme/target/io-cmd-bdev.c | 7 ++++---
 drivers/nvme/target/io-cmd-file.c | 2 +-
 2 files changed, 5 insertions(+), 4 deletions(-)
drivers/nvme/target/io-cmd-bdev.c +4 -3
index 71dfedbadc26..28d742d7bdaf 100644
@@ -194,11 +194,12 @@ static u16 nvmet_bdev_discard_range(struct nvmet_req *req,
 			le64_to_cpu(range->slba) << (ns->blksize_shift - 9),
 			le32_to_cpu(range->nlb) << (ns->blksize_shift - 9),
 			GFP_KERNEL, 0, bio);
-
-	if (ret)
+	if (ret && ret != -EOPNOTSUPP) {
 		req->error_slba = le64_to_cpu(range->slba);
+		return errno_to_nvme_status(req, ret);
+	}
 
-	return blk_to_nvme_status(req, errno_to_blk_status(ret));
+	return 0;
 }
 
 static void nvmet_bdev_execute_discard(struct nvmet_req *req)
drivers/nvme/target/io-cmd-file.c +0 -0
index 517522305e5c..3e43212d3c1c 100644

drivers/nvme/target/io-cmd-file.c static void nvmet_file_execute_discard(struct nvmet_req *req) · line 303

Quoted 8 lines
drivers/nvme/target/io-cmd-file.c +1 -1
@@ -297,7 +297,7 @@ static void nvmet_file_execute_discard(struct nvmet_req *req)
 		}
 
 		ret = vfs_fallocate(req->ns->file, mode, offset, len);
-		if (ret) {
+		if (ret && ret != -EOPNOTSUPP) {
 			req->error_slba = le64_to_cpu(range.slba);
 			status = errno_to_nvme_status(req, ret);
 			break;

I had one test failure with mkfs.ext4 over multipath to an underlying device that did not support discard, this fixes that problem, thanks!

Tested-by Ewan D. Milne <emilne at redhat.com>