Skip to content

Commit 7fb4278

Browse files
mikechristiemartinkpetersen
authored andcommitted
nvme: Convert NVMe errors to PR errors
This converts the NVMe errors we commonly see during PR handling to PR_STS errors or -Exyz errors. pr_ops callers can then handle SCSI and NVMe errors without knowing the device types. Signed-off-by: Mike Christie <[email protected]> Link: https://lore.kernel.org/r/[email protected] Reviewed-by: Chaitanya Kulkarni <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]> Signed-off-by: Martin K. Petersen <[email protected]>
1 parent 04b3c8c commit 7fb4278

File tree

1 file changed

+31
-2
lines changed

1 file changed

+31
-2
lines changed

drivers/nvme/host/core.c

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2104,11 +2104,34 @@ static int nvme_send_ns_pr_command(struct nvme_ns *ns, struct nvme_command *c,
21042104
return nvme_submit_sync_cmd(ns->queue, c, data, 16);
21052105
}
21062106

2107+
static int nvme_sc_to_pr_err(int nvme_sc)
2108+
{
2109+
if (nvme_is_path_error(nvme_sc))
2110+
return PR_STS_PATH_FAILED;
2111+
2112+
switch (nvme_sc) {
2113+
case NVME_SC_SUCCESS:
2114+
return PR_STS_SUCCESS;
2115+
case NVME_SC_RESERVATION_CONFLICT:
2116+
return PR_STS_RESERVATION_CONFLICT;
2117+
case NVME_SC_ONCS_NOT_SUPPORTED:
2118+
return -EOPNOTSUPP;
2119+
case NVME_SC_BAD_ATTRIBUTES:
2120+
case NVME_SC_INVALID_OPCODE:
2121+
case NVME_SC_INVALID_FIELD:
2122+
case NVME_SC_INVALID_NS:
2123+
return -EINVAL;
2124+
default:
2125+
return PR_STS_IOERR;
2126+
}
2127+
}
2128+
21072129
static int nvme_pr_command(struct block_device *bdev, u32 cdw10,
21082130
u64 key, u64 sa_key, u8 op)
21092131
{
21102132
struct nvme_command c = { };
21112133
u8 data[16] = { 0, };
2134+
int ret;
21122135

21132136
put_unaligned_le64(key, &data[0]);
21142137
put_unaligned_le64(sa_key, &data[8]);
@@ -2118,8 +2141,14 @@ static int nvme_pr_command(struct block_device *bdev, u32 cdw10,
21182141

21192142
if (IS_ENABLED(CONFIG_NVME_MULTIPATH) &&
21202143
bdev->bd_disk->fops == &nvme_ns_head_ops)
2121-
return nvme_send_ns_head_pr_command(bdev, &c, data);
2122-
return nvme_send_ns_pr_command(bdev->bd_disk->private_data, &c, data);
2144+
ret = nvme_send_ns_head_pr_command(bdev, &c, data);
2145+
else
2146+
ret = nvme_send_ns_pr_command(bdev->bd_disk->private_data, &c,
2147+
data);
2148+
if (ret < 0)
2149+
return ret;
2150+
2151+
return nvme_sc_to_pr_err(ret);
21232152
}
21242153

21252154
static int nvme_pr_register(struct block_device *bdev, u64 old,

0 commit comments

Comments
 (0)