qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: Peter Lieven <pl@kamp.de>
Subject: [Qemu-devel] [PULL 01/15] block/iscsi: handle BUSY condition
Date: Wed, 18 Jun 2014 18:03:55 +0200	[thread overview]
Message-ID: <1403107449-6186-2-git-send-email-pbonzini@redhat.com> (raw)
In-Reply-To: <1403107449-6186-1-git-send-email-pbonzini@redhat.com>

From: Peter Lieven <pl@kamp.de>

this patch adds handling of BUSY status reponse from an iSCSI target.
Currently, we fail with -EIO in case of SCSI_STATUS_BUSY while the
obvious reaction would be to retry the operation after some time.
The retry time is randomly choosen from a range with exponential
growth increasing with each retry.

This patch includes most of the changes by a an upcoming patch
from Stefan Hajnoczi:

 iscsi: implement .bdrv_detach/attach_aio_context()

because I also need the reference to the aio_context for
the retry timer to work. I included the changes to maintain
better mergeability.

Signed-off-by: Peter Lieven <pl@kamp.de>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 block/iscsi.c | 55 +++++++++++++++++++++++++++++++++++++++++++------------
 1 file changed, 43 insertions(+), 12 deletions(-)

diff --git a/block/iscsi.c b/block/iscsi.c
index 6f87605..e64659f 100644
--- a/block/iscsi.c
+++ b/block/iscsi.c
@@ -26,6 +26,7 @@
 #include "config-host.h"
 
 #include <poll.h>
+#include <math.h>
 #include <arpa/inet.h>
 #include "qemu-common.h"
 #include "qemu/config-file.h"
@@ -75,6 +76,7 @@ typedef struct IscsiTask {
     Coroutine *co;
     QEMUBH *bh;
     IscsiLun *iscsilun;
+    QEMUTimer retry_timer;
 } IscsiTask;
 
 typedef struct IscsiAIOCB {
@@ -86,7 +88,6 @@ typedef struct IscsiAIOCB {
     uint8_t *buf;
     int status;
     int canceled;
-    int retries;
     int64_t sector_num;
     int nb_sectors;
 #ifdef __linux__
@@ -96,7 +97,8 @@ typedef struct IscsiAIOCB {
 
 #define NOP_INTERVAL 5000
 #define MAX_NOP_FAILURES 3
-#define ISCSI_CMD_RETRIES 5
+#define ISCSI_CMD_RETRIES ARRAY_SIZE(iscsi_retry_times)
+static const unsigned iscsi_retry_times[] = {8, 32, 128, 512, 2048};
 
 /* this threshhold is a trade-off knob to choose between
  * the potential additional overhead of an extra GET_LBA_STATUS request
@@ -146,6 +148,19 @@ static void iscsi_co_generic_bh_cb(void *opaque)
     qemu_coroutine_enter(iTask->co, NULL);
 }
 
+static void iscsi_retry_timer_expired(void *opaque)
+{
+    struct IscsiTask *iTask = opaque;
+    if (iTask->co) {
+        qemu_coroutine_enter(iTask->co, NULL);
+    }
+}
+
+static inline unsigned exp_random(double mean)
+{
+    return -mean * log((double)rand() / RAND_MAX);
+}
+
 static void
 iscsi_co_generic_cb(struct iscsi_context *iscsi, int status,
                         void *command_data, void *opaque)
@@ -158,14 +173,30 @@ iscsi_co_generic_cb(struct iscsi_context *iscsi, int status,
     iTask->do_retry = 0;
     iTask->task = task;
 
-    if (iTask->retries-- > 0 && 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_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) {
+                unsigned retry_time =
+                    exp_random(iscsi_retry_times[iTask->retries - 1]);
+                error_report("iSCSI Busy (retry #%u in %u ms): %s",
+                             iTask->retries, retry_time,
+                             iscsi_get_error(iscsi));
+                aio_timer_init(iTask->iscsilun->aio_context,
+                               &iTask->retry_timer, QEMU_CLOCK_REALTIME,
+                               SCALE_MS, iscsi_retry_timer_expired, iTask);
+                timer_mod(&iTask->retry_timer,
+                          qemu_clock_get_ms(QEMU_CLOCK_REALTIME) + retry_time);
+                iTask->do_retry = 1;
+                return;
+            }
+        }
         error_report("iSCSI Failure: %s", iscsi_get_error(iscsi));
     }
 
@@ -180,9 +211,9 @@ out:
 static void iscsi_co_init_iscsitask(IscsiLun *iscsilun, struct IscsiTask *iTask)
 {
     *iTask = (struct IscsiTask) {
-        .co             = qemu_coroutine_self(),
-        .retries        = ISCSI_CMD_RETRIES,
-        .iscsilun       = iscsilun,
+        .co         = qemu_coroutine_self(),
+        .retries    = ISCSI_CMD_RETRIES,
+        .iscsilun   = iscsilun,
     };
 }
 
-- 
1.8.3.1

  reply	other threads:[~2014-06-18 16:04 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-06-18 16:03 [Qemu-devel] [PULL 00/15] SCSI changes for 2014-06-18 Paolo Bonzini
2014-06-18 16:03 ` Paolo Bonzini [this message]
2014-06-30  9:39   ` [Qemu-devel] [PULL 01/15] block/iscsi: handle BUSY condition Alexey Kardashevskiy
2014-06-18 16:03 ` [Qemu-devel] [PULL 02/15] block/iscsi: fix potential segfault on early callback Paolo Bonzini
2014-06-18 16:03 ` [Qemu-devel] [PULL 03/15] block/iscsi: use 16 byte CDBs only when necessary Paolo Bonzini
2014-06-18 16:03 ` [Qemu-devel] [PULL 04/15] scsi-disk.c: Fix compilation with -DDEBUG_SCSI Paolo Bonzini
2014-06-18 16:03 ` [Qemu-devel] [PULL 05/15] scsi-disk: fix bug in scsi_block_new_request() introduced by commit 137745c Paolo Bonzini
2014-06-18 16:04 ` [Qemu-devel] [PULL 06/15] scsi: Print command name in debug Paolo Bonzini
2014-06-18 16:04 ` [Qemu-devel] [PULL 07/15] megasas: use PCI DMA API Paolo Bonzini
2014-06-18 16:04 ` [Qemu-devel] [PULL 08/15] util: add return value to qemu_iovec_concat_iov Paolo Bonzini
2014-06-18 16:04 ` [Qemu-devel] [PULL 09/15] virtio-scsi: start preparing for any_layout Paolo Bonzini
2014-06-18 16:04 ` [Qemu-devel] [PULL 10/15] virtio-scsi: add target swap for VirtIOSCSICtrlTMFReq fields Paolo Bonzini
2014-06-18 16:04 ` [Qemu-devel] [PULL 11/15] virtio-scsi: add extra argument and return type to qemu_sgl_concat Paolo Bonzini
2014-06-18 16:04 ` [Qemu-devel] [PULL 12/15] virtio-scsi: prepare sense data handling for any_layout Paolo Bonzini
2014-06-18 16:04 ` [Qemu-devel] [PULL 13/15] virtio-scsi: introduce virtio_scsi_complete_cmd_req Paolo Bonzini
2014-06-18 16:04 ` [Qemu-devel] [PULL 14/15] virtio-scsi: add support for the any_layout feature Paolo Bonzini
2014-06-18 16:04 ` [Qemu-devel] [PULL 15/15] block/iscsi: bump libiscsi requirement to 1.9.0 Paolo Bonzini
2014-06-19 16:14 ` [Qemu-devel] [PULL 00/15] SCSI changes for 2014-06-18 Peter Maydell

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=1403107449-6186-2-git-send-email-pbonzini@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=pl@kamp.de \
    --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).