Skip to contentSkip to conversation

nvme: move protection information check into nvme_setup_rw

PATCH New Christoph Hellwig 5 participants 7 messages Jun 12, 2017 – Jun 15, 2017 NVMe

lore
Share & tools
lore

Christoph Hellwig

author maintainer
#0 lore raw

PATCH 1/1 nvme: move protection information check into nvme_setup_rw

It only applies to read/write commands, and this way non-PCIe drivers get the check as well instead of having to duplicate it when adding metadata support.

Signed-off-by Christoph Hellwig <hch at lst.de>
---
 drivers/nvme/host/core.c | 16 +++++++++++++---
 drivers/nvme/host/pci.c  | 13 +------------
 2 files changed, 14 insertions(+), 15 deletions(-)
drivers/nvme/host/core.c +13 -3
index 1a8b0bd77673..c24267a95e66 100644
@@ -347,12 +347,21 @@ static blk_status_t nvme_setup_discard(struct nvme_ns *ns, struct request *req,
 	return BLK_STS_OK;
 }
 
-static inline void nvme_setup_rw(struct nvme_ns *ns, struct request *req,
-		struct nvme_command *cmnd)
+static inline blk_status_t nvme_setup_rw(struct nvme_ns *ns,
+		struct request *req, struct nvme_command *cmnd)
 {
 	u16 control = 0;
 	u32 dsmgmt = 0;
 
+	/*
+	 * If formated with metadata, require the block layer provide a buffer
+	 * unless this namespace is formated such that the metadata can be
+	 * stripped/generated by the controller with PRACT=1.
+	 */
+	if (ns && ns->ms && (!ns->pi_type || ns->ms != 8) &&
+	    !blk_integrity_rq(req) && !blk_rq_is_passthrough(req))
+		return BLK_STS_NOTSUPP;
+
 	if (req->cmd_flags & REQ_FUA)
 		control |= NVME_RW_FUA;
 	if (req->cmd_flags & (REQ_FAILFAST_DEV | REQ_RAHEAD))
@@ -386,6 +395,7 @@ static inline void nvme_setup_rw(struct nvme_ns *ns, struct request *req,
 
 	cmnd->rw.control = cpu_to_le16(control);
 	cmnd->rw.dsmgmt = cpu_to_le32(dsmgmt);
+	return 0;
 }
 
 blk_status_t nvme_setup_cmd(struct nvme_ns *ns, struct request *req,
@@ -414,7 +424,7 @@ blk_status_t nvme_setup_cmd(struct nvme_ns *ns, struct request *req,
 		break;
 	case REQ_OP_READ:
 	case REQ_OP_WRITE:
-		nvme_setup_rw(ns, req, cmd);
+		ret = nvme_setup_rw(ns, req, cmd);
 		break;
 	default:
 		WARN_ON_ONCE(1);
drivers/nvme/host/pci.c +1 -12
index 0a816910cf0e..92c1325251f0 100644
@@ -692,18 +692,7 @@ static blk_status_t nvme_queue_rq(struct blk_mq_hw_ctx *hctx,
 	struct nvme_dev *dev = nvmeq->dev;
 	struct request *req = bd->rq;
 	struct nvme_command cmnd;
-	blk_status_t ret = BLK_STS_OK;
-
-	/*
-	 * If formated with metadata, require the block layer provide a buffer
-	 * unless this namespace is formated such that the metadata can be
-	 * stripped/generated by the controller with PRACT=1.
-	 */
-	if (ns && ns->ms && !blk_integrity_rq(req)) {
-		if (!(ns->pi_type && ns->ms == 8) &&
-		    !blk_rq_is_passthrough(req))
-			return BLK_STS_NOTSUPP;
-	}
+	blk_status_t ret;
 
 	ret = nvme_setup_cmd(ns, req, &cmnd);
 	if (ret)
Signature · 1 line
2.11.0
#1 lore raw

PATCH 1/1 nvme: move protection information check into nvme_setup_rw

drivers/nvme/host/core.c static blk_status_t nvme_setup_discard(struct nvme_ns *ns, struct request *req, · line 352

Quoted 3 lines · Christoph Hellwig
drivers/nvme/host/core.c +2 -0
+static inline blk_status_t nvme_setup_rw(struct nvme_ns *ns,
+		struct request *req, struct nvme_command *cmnd)
 {

Hmm here you're changing nvme_setup_rw to return blk_status_t

[...]

drivers/nvme/host/core.c static inline void nvme_setup_rw(struct nvme_ns *ns, struct request *req, · line 399

Quoted 6 lines
drivers/nvme/host/core.c +1 -0
@@ -386,6 +395,7 @@ static inline void nvme_setup_rw(struct nvme_ns *ns, struct request *req,
 
 	cmnd->rw.control = cpu_to_le16(control);
 	cmnd->rw.dsmgmt = cpu_to_le32(dsmgmt);
+	return 0;
 }

And here you're returning 0 instead of BLK_STATUS_OK.

Intentional?

Signature · 6 lines
Johannes Thumshirn                                          Storage
jthumshirn at suse.de                                +49 911 74053 689
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 N?rnberg
GF: Felix Imend?rffer, Jane Smithard, Graham Norton
HRB 21284 (AG N?rnberg)
Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850
author maintainer
#2 lore raw

PATCH 1/1 nvme: move protection information check into nvme_setup_rw

Quoted 10 lines · Johannes Thumshirn

drivers/nvme/host/core.c static inline void nvme_setup_rw(struct nvme_ns *ns, struct request *req, · line 399

Quoted 6 lines
drivers/nvme/host/core.c +1 -0
@@ -386,6 +395,7 @@ static inline void nvme_setup_rw(struct nvme_ns *ns, struct request *req,
 
 	cmnd->rw.control = cpu_to_le16(control);
 	cmnd->rw.dsmgmt = cpu_to_le32(dsmgmt);
+	return 0;
 }

And here you're returning 0 instead of BLK_STATUS_OK.

Intentional?

Yes, at least sort of. Even for __bitwise types 0 is special, so this is perfectly fine.

#3 lore raw

PATCH 1/1 nvme: move protection information check into nvme_setup_rw

In reply to Christoph Hellwig
Quoted 5 lines · Christoph Hellwig

It only applies to read/write commands, and this way non-PCIe drivers get the check as well instead of having to duplicate it when adding metadata support.

Signed-off-by Christoph Hellwig <hch at lst.de>

Looks good to me.

Reviewed-by Keith Busch <keith.busch at intel.com>
maintainer
#4 lore raw

PATCH 1/1 nvme: move protection information check into nvme_setup_rw

In reply to Christoph Hellwig
Quoted 22 lines · Christoph Hellwig

It only applies to read/write commands, and this way non-PCIe drivers get the check as well instead of having to duplicate it when adding metadata support.

Signed-off-by Christoph Hellwig <hch at lst.de>
---
  drivers/nvme/host/core.c | 16 +++++++++++++---
  drivers/nvme/host/pci.c  | 13 +------------
  2 files changed, 14 insertions(+), 15 deletions(-)
drivers/nvme/host/core.c +2 -2
index 1a8b0bd77673..c24267a95e66 100644
@@ -347,12 +347,21 @@ static blk_status_t nvme_setup_discard(struct nvme_ns *ns, struct request *req,
  	return BLK_STS_OK;
  }
 
-static inline void nvme_setup_rw(struct nvme_ns *ns, struct request *req,
-		struct nvme_command *cmnd)
+static inline blk_status_t nvme_setup_rw(struct nvme_ns *ns,
+		struct request *req, struct nvme_command *cmnd)

drivers/nvme/host/core.c static blk_status_t nvme_setup_discard(struct nvme_ns *ns, struct request *req, · line 361

Quoted 10 lines
drivers/nvme/host/core.c +6 -0
  {
  	u16 control = 0;
  	u32 dsmgmt = 0;
 
+	/*
+	 * If formated with metadata, require the block layer provide a buffer
+	 * unless this namespace is formated such that the metadata can be
+	 * stripped/generated by the controller with PRACT=1.
+	 */
+	if (ns && ns->ms && (!ns->pi_type || ns->ms != 8) &&

Not directly related to this patch, but 8 should be replaced with sizeof(struct t10_pi_tuple).

Otherwise looks good,

Reviewed-by Sagi Grimberg <sagi at grimberg.me>

Should I send out an incremental change?

author maintainer
#5 lore raw

PATCH 1/1 nvme: move protection information check into nvme_setup_rw

Quoted 8 lines · Sagi Grimberg

Not directly related to this patch, but 8 should be replaced with sizeof(struct t10_pi_tuple).

Otherwise looks good,

Reviewed-by Sagi Grimberg <sagi at grimberg.me>

Should I send out an incremental change?

Yes, please do.

#6 lore raw

PATCH 1/1 nvme: move protection information check into nvme_setup_rw

In reply to Sagi Grimberg
Quoted 8 lines · Sagi Grimberg

Not directly related to this patch, but 8 should be replaced with sizeof(struct t10_pi_tuple).

Otherwise looks good,

Reviewed-by Sagi Grimberg <sagi at grimberg.me>

Should I send out an incremental change?

Yes, please do.