qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [PULL 05/19] iscsi: base all handling of check condition on scsi_sense_to_errno
Date: Tue, 16 Jul 2019 10:11:03 +0200	[thread overview]
Message-ID: <1563264677-39718-6-git-send-email-pbonzini@redhat.com> (raw)
In-Reply-To: <1563264677-39718-1-git-send-email-pbonzini@redhat.com>

Now that scsi-disk is not using scsi_sense_to_errno to separate guest-recoverable
sense codes, we can modify it to simplify iscsi's own sense handling.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 block/iscsi.c | 29 ++++++++++++++---------------
 scsi/utils.c  |  5 ++---
 2 files changed, 16 insertions(+), 18 deletions(-)

diff --git a/block/iscsi.c b/block/iscsi.c
index 6e238bf..506bf5f 100644
--- a/block/iscsi.c
+++ b/block/iscsi.c
@@ -225,9 +225,9 @@ static inline unsigned exp_random(double mean)
 
 static int iscsi_translate_sense(struct scsi_sense *sense)
 {
-    return - scsi_sense_to_errno(sense->key,
-                                 (sense->ascq & 0xFF00) >> 8,
-                                 sense->ascq & 0xFF);
+    return scsi_sense_to_errno(sense->key,
+                               (sense->ascq & 0xFF00) >> 8,
+                               sense->ascq & 0xFF);
 }
 
 /* Called (via iscsi_service) with QemuMutex held.  */
@@ -244,13 +244,6 @@ iscsi_co_generic_cb(struct iscsi_context *iscsi, int status,
 
     if (status != SCSI_STATUS_GOOD) {
         if (iTask->retries++ < ISCSI_CMD_RETRIES) {
-            if (status == SCSI_STATUS_CHECK_CONDITION
-                && task->sense.key == SCSI_SENSE_UNIT_ATTENTION) {
-                error_report("iSCSI CheckCondition: %s",
-                             iscsi_get_error(iscsi));
-                iTask->do_retry = 1;
-                goto out;
-            }
             if (status == SCSI_STATUS_BUSY ||
                 status == SCSI_STATUS_TIMEOUT ||
                 status == SCSI_STATUS_TASK_SET_FULL) {
@@ -272,14 +265,20 @@ iscsi_co_generic_cb(struct iscsi_context *iscsi, int status,
                 timer_mod(&iTask->retry_timer,
                           qemu_clock_get_ms(QEMU_CLOCK_REALTIME) + retry_time);
                 iTask->do_retry = 1;
-                goto out;
+            }
+        } else if (status == SCSI_STATUS_CHECK_CONDITION) {
+            int error = iscsi_translate_sense(&task->sense);
+            if (error == EAGAIN) {
+                error_report("iSCSI CheckCondition: %s",
+                             iscsi_get_error(iscsi));
+                iTask->do_retry = 1;
+            } else {
+                iTask->err_code = -error;
+                iTask->err_str = g_strdup(iscsi_get_error(iscsi));
             }
         }
-        iTask->err_code = iscsi_translate_sense(&task->sense);
-        iTask->err_str = g_strdup(iscsi_get_error(iscsi));
     }
 
-out:
     if (iTask->co) {
         aio_bh_schedule_oneshot(iTask->iscsilun->aio_context,
                                  iscsi_co_generic_bh_cb, iTask);
@@ -974,7 +973,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 = iscsi_translate_sense(&acb->task->sense);
+        acb->status = -iscsi_translate_sense(&acb->task->sense);
     }
 
     acb->ioh->driver_status = 0;
diff --git a/scsi/utils.c b/scsi/utils.c
index 873d49c..c50e81f 100644
--- a/scsi/utils.c
+++ b/scsi/utils.c
@@ -379,8 +379,7 @@ int scsi_sense_to_errno(int key, int asc, int ascq)
     case NO_SENSE:
     case RECOVERED_ERROR:
     case UNIT_ATTENTION:
-        /* These sense keys are not errors */
-        return 0;
+        return EAGAIN;
     case ABORTED_COMMAND: /* COMMAND ABORTED */
         return ECANCELED;
     case NOT_READY:
@@ -409,7 +408,7 @@ int scsi_sense_to_errno(int key, int asc, int ascq)
     case 0x2700: /* WRITE PROTECTED */
         return EACCES;
     case 0x0401: /* NOT READY, IN PROGRESS OF BECOMING READY */
-        return EAGAIN;
+        return EINPROGRESS;
     case 0x0402: /* NOT READY, INITIALIZING COMMAND REQUIRED */
         return ENOTCONN;
     default:
-- 
1.8.3.1




  parent reply	other threads:[~2019-07-16  8:12 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-16  8:10 [Qemu-devel] [PULL 00/19] Bugfix/cleanup patches for 2019-07-16 Paolo Bonzini
2019-07-16  8:10 ` [Qemu-devel] [PULL 01/19] scsi-disk: pass sense correctly for guest-recoverable errors Paolo Bonzini
2019-07-16  8:11 ` [Qemu-devel] [PULL 02/19] scsi: explicitly list guest-recoverable sense codes Paolo Bonzini
2019-07-16  8:11 ` [Qemu-devel] [PULL 03/19] scsi: add guest-recoverable ZBC errors Paolo Bonzini
2019-07-16  8:11 ` [Qemu-devel] [PULL 04/19] iscsi: fix busy/timeout/task set full Paolo Bonzini
2019-07-16  8:11 ` Paolo Bonzini [this message]
2019-07-16  8:11 ` [Qemu-devel] [PULL 06/19] build-sys: remove slirp cflags from main-loop.o Paolo Bonzini
2019-07-16  8:11 ` [Qemu-devel] [PULL 07/19] rdmacm-mux: fix strcpy string warning Paolo Bonzini
2019-07-16  8:11 ` [Qemu-devel] [PULL 08/19] hw/i386: turn off vmport if CONFIG_VMPORT is disabled Paolo Bonzini
2019-07-16 18:55   ` Philippe Mathieu-Daudé
2019-07-16 19:13     ` Paolo Bonzini
2019-07-16  8:11 ` [Qemu-devel] [PULL 09/19] memory: unref the memory region in simplify flatview Paolo Bonzini
2019-07-16  8:11 ` [Qemu-devel] [PULL 10/19] Fix broken build with WHPX enabled Paolo Bonzini
2019-07-16  8:11 ` [Qemu-devel] [PULL 11/19] util: merge main-loop.c and iohandler.c Paolo Bonzini
2019-07-16  8:11 ` [Qemu-devel] [PULL 12/19] hw/lm32/Kconfig: Milkymist One provides a USB 1.1 Controller Paolo Bonzini
2019-07-16  8:11 ` [Qemu-devel] [PULL 13/19] checkpatch: detect doubly-encoded UTF-8 Paolo Bonzini
2019-07-16  8:11 ` [Qemu-devel] [PULL 14/19] target/i386: sev: Do not unpin ram device memory region Paolo Bonzini
2019-07-16  8:11 ` [Qemu-devel] [PULL 15/19] hw/usb/Kconfig: Add CONFIG_USB_EHCI_PCI Paolo Bonzini
2019-07-16  8:11 ` [Qemu-devel] [PULL 16/19] hw/usb/Kconfig: USB_XHCI_NEC requires USB_XHCI Paolo Bonzini
2019-07-16  8:11 ` [Qemu-devel] [PULL 17/19] Makefile: do not repeat $(CONFIG_SOFTMMU) in hw/Makefile.objs Paolo Bonzini
2019-07-16  8:11 ` [Qemu-devel] [PULL 18/19] create_config: remove $(CONFIG_SOFTMMU) hack Paolo Bonzini
2019-07-16  8:11 ` [Qemu-devel] [PULL 19/19] vl: make sure char-pty message displayed by moving setbuf to the beginning Paolo Bonzini
2019-07-16  8:18 ` [Qemu-devel] [PULL 00/19] Bugfix/cleanup patches for 2019-07-16 no-reply
2019-07-16 15:05 ` Peter Maydell
2019-07-19 16:15 ` Peter Maydell
2019-07-19 17:00   ` Paolo Bonzini

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=1563264677-39718-6-git-send-email-pbonzini@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /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).