[PATCHv3 4/4] nvme: use return value from blk_execute_rq()

Christoph Hellwig hch at lst.de
Mon May 24 01:04:28 PDT 2021


> +/*
> + * Return values:
> + * 0:  success
> + * >0: nvme controller's cqe status response
> + * <0: kernel error in lieu of controller response
> + */

For better reading flow I'd reformat this as:

/*
 * Return value:
 *   0:	success
 * > 0:	nvme controller's cqe status response
 * < 0: kernel error in lieu of controller response
 */

> +static int nvme_passthrough_status(struct request *rq, blk_status_t status)
> +{
> +	if (nvme_req(rq)->flags & NVME_REQ_CANCELLED)
> +		return -EINTR;
> +	else if (nvme_req(rq)->status)
> +		return nvme_req(rq)->status;
> +	return blk_status_to_errno(status);
> +}

I find this a little odd disconnected from the actual execure call.
What about a helper like this instead:

static int nvme_execute_rq(struct gendisk *disk, struct request *rq,
		bool at_head)
{
	blk_status_t status;

	status = blk_execute_rq(disk, req, at_head);
	if (nvme_req(rq)->flags & NVME_REQ_CANCELLED)
		return -EINTR;
	if (nvme_req(rq)->status)
		return nvme_req(rq)->status;
	return blk_status_to_errno(status);
}

> -	nvme_execute_passthru_rq(rq);
> +	status = nvme_execute_passthru_rq(rq);
>  
> -	status = nvme_req(rq)->status;
>  	if (status == NVME_SC_SUCCESS &&
>  	    req->cmd->common.opcode == nvme_admin_identify) {
>  		switch (req->cmd->identify.cns) {
> @@ -168,7 +167,8 @@ static void nvmet_passthru_execute_cmd_work(struct work_struct *w)
>  			nvmet_passthru_override_id_ns(req);
>  			break;
>  		}
> -	}
> +	} else if (status < 0)
> +		status = NVME_SC_INTERNAL;

Don't we need a better translation here?



More information about the Linux-nvme mailing list