From: Fam Zheng <famz@redhat.com>
To: qemu-devel@nongnu.org
Cc: Kevin Wolf <kwolf@redhat.com>,
Paolo Bonzini <pbonzini@redhat.com>, Peter Lieven <pl@kamp.de>,
qemu-block@nongnu.org, Ronnie Sahlberg <ronniesahlberg@gmail.com>
Subject: [Qemu-devel] [PATCH 1/2] iscsi: Translate scsi sense into error code
Date: Thu, 22 Oct 2015 16:17:37 +0800 [thread overview]
Message-ID: <1445501858-18790-2-git-send-email-famz@redhat.com> (raw)
In-Reply-To: <1445501858-18790-1-git-send-email-famz@redhat.com>
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.
Signed-off-by: Fam Zheng <famz@redhat.com>
---
block/iscsi.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 55 insertions(+), 1 deletion(-)
diff --git a/block/iscsi.c b/block/iscsi.c
index 93f1ee4..f3e20ae 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,58 @@ 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 = 0;
+
+ switch (sense->key) {
+ case SCSI_SENSE_NO_SENSE:
+ return 0;
+ break;
+ case SCSI_SENSE_NOT_READY:
+ return -EBUSY;
+ break;
+ case SCSI_SENSE_DATA_PROTECTION:
+ return -EACCES;
+ break;
+ case SCSI_SENSE_COMMAND_ABORTED:
+ return -ECANCELED;
+ break;
+ case SCSI_SENSE_ILLEGAL_REQUEST:
+ /* Parse ASCQ */
+ break;
+ default:
+ return -EIO;
+ break;
+ }
+ 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 = -ERANGE;
+ break;
+ case SCSI_SENSE_ASCQ_LOGICAL_UNIT_NOT_SUPPORTED:
+ ret = -ENOTSUP;
+ break;
+ case SCSI_SENSE_ASCQ_WRITE_PROTECTED:
+ ret = -EACCES;
+ 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;
+ 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 +279,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 +509,7 @@ retry:
}
if (iTask.status != SCSI_STATUS_GOOD) {
- return -EIO;
+ return iTask.err_code;
}
iscsi_allocationmap_set(iscsilun, sector_num, nb_sectors);
--
2.4.3
next prev parent reply other threads:[~2015-10-22 8:18 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-10-22 8:17 [Qemu-devel] [PATCH 0/2] Fix werror=enospc for qcow2 on iscsi Fam Zheng
2015-10-22 8:17 ` Fam Zheng [this message]
2015-10-22 8:31 ` [Qemu-devel] [PATCH 1/2] iscsi: Translate scsi sense into error code Peter Lieven
2015-10-22 8:45 ` Paolo Bonzini
2015-10-22 9:11 ` Peter Lieven
2015-10-22 9:51 ` Fam Zheng
2015-10-22 9:56 ` Paolo Bonzini
2015-10-22 9:11 ` Kevin Wolf
2015-10-22 8:17 ` [Qemu-devel] [PATCH 2/2] qcow2: Translate -ERANGE to -ENOSPC Fam Zheng
2015-10-22 8:32 ` [Qemu-devel] [PATCH 0/2] Fix werror=enospc for qcow2 on iscsi Peter Lieven
2015-10-22 10:06 ` Fam Zheng
2015-10-22 8:45 ` Paolo Bonzini
2015-10-22 9:03 ` Kevin Wolf
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=1445501858-18790-2-git-send-email-famz@redhat.com \
--to=famz@redhat.com \
--cc=kwolf@redhat.com \
--cc=pbonzini@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).