[RFC v2 3/3] nvme: ignore starting sector while error logging for passthrough requests

Alan Adamson
2023-03-23T23:04:18Z

Error log will print a garbage value as the starting LBA for passthrough
requests and requests with uninitialized starting sector that return an
error.

Signed-off-by: Pankaj Raghav <p.raghav@samsung.com>
Signed-off-by: Alan Adamson <alan.adamson@oracle.com>
---
drivers/nvme/host/core.c | 29 ++++++++++++++++++++++++++++-
1 file changed, 28 insertions(+), 1 deletion(-)

diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index 48e9abacd80b..82afe72b7cbd 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -306,6 +306,33 @@ static void nvme_retry_req(struct request *req)
blk_mq_delay_kick_requeue_list(req->q, delay);
}

+static inline u64 nvme_log_error_rq_lba(struct nvme_ns *ns, struct request *rq)
+{
+ struct nvme_request *nr = nvme_req(rq);
+
+ if (blk_rq_is_passthrough(rq)) {
+ switch (nr->cmd->common.opcode) {
+ u64 cdw11;
+
+ case nvme_cmd_flush:
+ case nvme_cmd_write:
+ case nvme_cmd_read:
+ case nvme_cmd_write_uncor:
+ case nvme_cmd_compare:
+ case nvme_cmd_write_zeroes:
+ case nvme_cmd_verify:
+ cdw11 = nr->cmd->common.cdw11;
+
+ return nr->cmd->common.cdw10 | (cdw11 << 32);
+ default:
+ return 0;
+ }
+ }
+ if (blk_rq_pos(rq) == (sector_t)-1)
+ return 0;
+ return nvme_sect_to_lba(ns, blk_rq_pos(rq));
+}
+
static void nvme_log_error(struct request *req)
{
struct nvme_ns *ns = req->q->queuedata;
@@ -316,7 +343,7 @@ static void nvme_log_error(struct request *req)
ns->disk ? ns->disk->disk_name : "?",
nvme_get_opcode_str(nr->cmd->common.opcode),
nr->cmd->common.opcode,
- (unsigned long long)nvme_sect_to_lba(ns, blk_rq_pos(req)),
+ (unsigned long long)nvme_log_error_rq_lba(ns, req),
(unsigned long long)blk_rq_bytes(req) >> ns->lba_shift,
nvme_get_error_status_str(nr->status),
nr->status >> 8 & 7, /* Status Code Type */
--
2.31.1