From: Paolo Bonzini <pbonzini@redhat.com>
To: Fam Zheng <famz@redhat.com>, qemu-devel@nongnu.org
Cc: Kevin Wolf <kwolf@redhat.com>, Peter Lieven <pl@kamp.de>,
qemu-block@nongnu.org, Ronnie Sahlberg <ronniesahlberg@gmail.com>
Subject: Re: [Qemu-devel] [PATCH v3] iscsi: Translate scsi sense into error code
Date: Thu, 5 Nov 2015 11:30:20 +0100 [thread overview]
Message-ID: <563B2FBC.1050104@redhat.com> (raw)
In-Reply-To: <1446699609-11376-1-git-send-email-famz@redhat.com>
On 05/11/2015 06:00, Fam Zheng wrote:
> Previously we return -EIO blindly when anything goes wrong. Add a helper
> function to parse sense fields and try to make the return code more
> meaningful.
>
> This also fixes the default werror configuration (enospc) when we're
> using qcow2 on an iscsi lun. The old -EIO not being treated as out of
> space error failed to trigger vm stop.
>
> Signed-off-by: Fam Zheng <famz@redhat.com>
>
> ---
> v3: Don't use err_code as return value when it's not set. [Peter]
> v2: Drop the qcow2 patch with ERANGE -> ENOSPC.
> Drop dead break after return.
> Return EIO for NO_SENSE.
> Translate error code for other I/O paths too.
> ---
> block/iscsi.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++------
> 1 file changed, 53 insertions(+), 6 deletions(-)
>
> diff --git a/block/iscsi.c b/block/iscsi.c
> index 9a628b7..26bd452 100644
> --- a/block/iscsi.c
> +++ b/block/iscsi.c
> @@ -84,6 +84,7 @@ typedef struct IscsiTask {
> IscsiLun *iscsilun;
> QEMUTimer retry_timer;
> bool force_next_flush;
> + int err_code;
> } IscsiTask;
>
> typedef struct IscsiAIOCB {
> @@ -182,6 +183,51 @@ static inline unsigned exp_random(double mean)
> #define QEMU_SCSI_STATUS_TIMEOUT SCSI_STATUS_TIMEOUT
> #endif
>
> +static int iscsi_translate_sense(struct scsi_sense *sense)
> +{
> + int ret;
> +
> + switch (sense->key) {
> + case SCSI_SENSE_NOT_READY:
> + return -EBUSY;
> + case SCSI_SENSE_DATA_PROTECTION:
> + return -EACCES;
> + case SCSI_SENSE_COMMAND_ABORTED:
> + return -ECANCELED;
> + case SCSI_SENSE_ILLEGAL_REQUEST:
> + /* Parse ASCQ */
> + break;
> + default:
> + return -EIO;
> + }
> + switch (sense->ascq) {
> + case SCSI_SENSE_ASCQ_PARAMETER_LIST_LENGTH_ERROR:
> + case SCSI_SENSE_ASCQ_INVALID_OPERATION_CODE:
> + case SCSI_SENSE_ASCQ_INVALID_FIELD_IN_CDB:
> + case SCSI_SENSE_ASCQ_INVALID_FIELD_IN_PARAMETER_LIST:
> + ret = -EINVAL;
> + break;
> + case SCSI_SENSE_ASCQ_LBA_OUT_OF_RANGE:
> + ret = -ENOSPC;
> + break;
> + case SCSI_SENSE_ASCQ_LOGICAL_UNIT_NOT_SUPPORTED:
> + ret = -ENOTSUP;
> + break;
> + case SCSI_SENSE_ASCQ_MEDIUM_NOT_PRESENT:
> + case SCSI_SENSE_ASCQ_MEDIUM_NOT_PRESENT_TRAY_CLOSED:
> + case SCSI_SENSE_ASCQ_MEDIUM_NOT_PRESENT_TRAY_OPEN:
> + ret = -ENOMEDIUM;
> + break;
> + case SCSI_SENSE_ASCQ_WRITE_PROTECTED:
> + ret = -EACCES;
> + break;
> + default:
> + ret = -EIO;
> + break;
> + }
> + return ret;
> +}
> +
> static void
> iscsi_co_generic_cb(struct iscsi_context *iscsi, int status,
> void *command_data, void *opaque)
> @@ -226,6 +272,7 @@ iscsi_co_generic_cb(struct iscsi_context *iscsi, int status,
> return;
> }
> }
> + iTask->err_code = iscsi_translate_sense(&task->sense);
> error_report("iSCSI Failure: %s", iscsi_get_error(iscsi));
> } else {
> iTask->iscsilun->force_next_flush |= iTask->force_next_flush;
> @@ -455,7 +502,7 @@ retry:
> }
>
> if (iTask.status != SCSI_STATUS_GOOD) {
> - return -EIO;
> + return iTask.err_code;
> }
>
> iscsi_allocationmap_set(iscsilun, sector_num, nb_sectors);
> @@ -644,7 +691,7 @@ retry:
> }
>
> if (iTask.status != SCSI_STATUS_GOOD) {
> - return -EIO;
> + return iTask.err_code;
> }
>
> return 0;
> @@ -683,7 +730,7 @@ retry:
> }
>
> if (iTask.status != SCSI_STATUS_GOOD) {
> - return -EIO;
> + return iTask.err_code;
> }
>
> return 0;
> @@ -703,7 +750,7 @@ iscsi_aio_ioctl_cb(struct iscsi_context *iscsi, int status,
> if (status < 0) {
> error_report("Failed to ioctl(SG_IO) to iSCSI lun. %s",
> iscsi_get_error(iscsi));
> - acb->status = -EIO;
> + acb->status = iscsi_translate_sense(&acb->task->sense);
> }
>
> acb->ioh->driver_status = 0;
> @@ -905,7 +952,7 @@ retry:
> }
>
> if (iTask.status != SCSI_STATUS_GOOD) {
> - return -EIO;
> + return iTask.err_code;
> }
>
> iscsi_allocationmap_clear(iscsilun, sector_num, nb_sectors);
> @@ -999,7 +1046,7 @@ retry:
> }
>
> if (iTask.status != SCSI_STATUS_GOOD) {
> - return -EIO;
> + return iTask.err_code;
> }
>
> if (flags & BDRV_REQ_MAY_UNMAP) {
>
Replaced, thanks.
Paolo
next prev parent reply other threads:[~2015-11-05 10:32 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-11-05 5:00 [Qemu-devel] [PATCH v3] iscsi: Translate scsi sense into error code Fam Zheng
2015-11-05 10:30 ` Paolo Bonzini [this message]
2015-11-05 22:14 ` Peter Lieven
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=563B2FBC.1050104@redhat.com \
--to=pbonzini@redhat.com \
--cc=famz@redhat.com \
--cc=kwolf@redhat.com \
--cc=pl@kamp.de \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=ronniesahlberg@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).