On 11/15/22 13:28, Mike Christie wrote: > 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 <michael.christie@xxxxxxxxxx> > --- > drivers/nvme/host/core.c | 42 ++++++++++++++++++++++++++++++++++++++-- > 1 file changed, 40 insertions(+), 2 deletions(-) > > diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c > index dc4220600585..811de141a7ee 100644 > --- a/drivers/nvme/host/core.c > +++ b/drivers/nvme/host/core.c > @@ -2104,11 +2104,43 @@ static int nvme_send_ns_pr_command(struct nvme_ns *ns, struct nvme_command *c, > return nvme_submit_sync_cmd(ns->queue, c, data, 16); > } > > +static int nvme_sc_to_pr_err(int nvme_sc) > +{ > + int err; > + > + if (nvme_is_path_error(nvme_sc)) > + return PR_STS_PATH_FAILED; > + > + switch (nvme_sc) { > + case NVME_SC_SUCCESS: > + err = PR_STS_SUCCESS; > + break; > + case NVME_SC_RESERVATION_CONFLICT: > + err = PR_STS_RESERVATION_CONFLICT; > + break; > + case NVME_SC_ONCS_NOT_SUPPORTED: > + err = -EOPNOTSUPP; > + break; > + case NVME_SC_BAD_ATTRIBUTES: > + case NVME_SC_INVALID_OPCODE: > + case NVME_SC_INVALID_FIELD: > + case NVME_SC_INVALID_NS: > + err = -EINVAL; > + break; > + default: > + err = PR_STS_IOERR; > + break; > + } > + > + return err; > +} > + > Like nvmet_bdev_parse_io_cmd() if we return directly we can remove the local variable and break for each case [1], no big deal feel free to ignore this comment. Looks good. Reviewed-by: Chaitanya Kulkarni <kch@xxxxxxxxxx> -ck [1] static int nvme_sc_to_pr_err(int nvme_sc) { if (nvme_is_path_error(nvme_sc)) return PR_STS_PATH_FAILED; switch (nvme_sc) { case NVME_SC_SUCCESS: return PR_STS_SUCCESS; case NVME_SC_RESERVATION_CONFLICT: return PR_STS_RESERVATION_CONFLICT; case NVME_SC_ONCS_NOT_SUPPORTED: return -EOPNOTSUPP; case NVME_SC_BAD_ATTRIBUTES: case NVME_SC_INVALID_OPCODE: case NVME_SC_INVALID_FIELD: case NVME_SC_INVALID_NS: return -EINVAL; default: return PR_STS_IOERR; } }