26ba25
From 0729a3f3d2313e3429c27004ba91bce8644e4765 Mon Sep 17 00:00:00 2001
26ba25
From: Fam Zheng <famz@redhat.com>
26ba25
Date: Fri, 29 Jun 2018 06:11:47 +0200
26ba25
Subject: [PATCH 173/268] iscsi: Create and use iscsi_co_wait_for_task
26ba25
26ba25
RH-Author: Fam Zheng <famz@redhat.com>
26ba25
Message-id: <20180629061153.12687-8-famz@redhat.com>
26ba25
Patchwork-id: 81160
26ba25
O-Subject: [RHEL-7.6 qemu-kvm-rhev PATCH v2 07/13] iscsi: Create and use iscsi_co_wait_for_task
26ba25
Bugzilla: 1482537
26ba25
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
26ba25
RH-Acked-by: Max Reitz <mreitz@redhat.com>
26ba25
RH-Acked-by: Kevin Wolf <kwolf@redhat.com>
26ba25
26ba25
This loop is repeated a growing number times. Make a helper.
26ba25
26ba25
Signed-off-by: Fam Zheng <famz@redhat.com>
26ba25
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
26ba25
Reviewed-by: Eric Blake <eblake@redhat.com>
26ba25
Message-id: 20180601092648.24614-8-famz@redhat.com
26ba25
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
26ba25
(cherry picked from commit 66e75c03b2247bda6dcaa883b700291bc0f7f0ef)
26ba25
Signed-off-by: Fam Zheng <famz@redhat.com>
26ba25
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
26ba25
---
26ba25
 block/iscsi.c | 54 +++++++++++++++++-------------------------------------
26ba25
 1 file changed, 17 insertions(+), 37 deletions(-)
26ba25
26ba25
diff --git a/block/iscsi.c b/block/iscsi.c
26ba25
index a1a0044..338f3dd 100644
26ba25
--- a/block/iscsi.c
26ba25
+++ b/block/iscsi.c
26ba25
@@ -557,6 +557,17 @@ static inline bool iscsi_allocmap_is_valid(IscsiLun *iscsilun,
26ba25
                                offset / iscsilun->cluster_size) == size);
26ba25
 }
26ba25
 
26ba25
+static void coroutine_fn iscsi_co_wait_for_task(IscsiTask *iTask,
26ba25
+                                                IscsiLun *iscsilun)
26ba25
+{
26ba25
+    while (!iTask->complete) {
26ba25
+        iscsi_set_events(iscsilun);
26ba25
+        qemu_mutex_unlock(&iscsilun->mutex);
26ba25
+        qemu_coroutine_yield();
26ba25
+        qemu_mutex_lock(&iscsilun->mutex);
26ba25
+    }
26ba25
+}
26ba25
+
26ba25
 static int coroutine_fn
26ba25
 iscsi_co_writev_flags(BlockDriverState *bs, int64_t sector_num, int nb_sectors,
26ba25
                       QEMUIOVector *iov, int flags)
26ba25
@@ -618,12 +629,7 @@ retry:
26ba25
     scsi_task_set_iov_out(iTask.task, (struct scsi_iovec *) iov->iov,
26ba25
                           iov->niov);
26ba25
 #endif
26ba25
-    while (!iTask.complete) {
26ba25
-        iscsi_set_events(iscsilun);
26ba25
-        qemu_mutex_unlock(&iscsilun->mutex);
26ba25
-        qemu_coroutine_yield();
26ba25
-        qemu_mutex_lock(&iscsilun->mutex);
26ba25
-    }
26ba25
+    iscsi_co_wait_for_task(&iTask, iscsilun);
26ba25
 
26ba25
     if (iTask.task != NULL) {
26ba25
         scsi_free_scsi_task(iTask.task);
26ba25
@@ -694,13 +700,7 @@ retry:
26ba25
         ret = -ENOMEM;
26ba25
         goto out_unlock;
26ba25
     }
26ba25
-
26ba25
-    while (!iTask.complete) {
26ba25
-        iscsi_set_events(iscsilun);
26ba25
-        qemu_mutex_unlock(&iscsilun->mutex);
26ba25
-        qemu_coroutine_yield();
26ba25
-        qemu_mutex_lock(&iscsilun->mutex);
26ba25
-    }
26ba25
+    iscsi_co_wait_for_task(&iTask, iscsilun);
26ba25
 
26ba25
     if (iTask.do_retry) {
26ba25
         if (iTask.task != NULL) {
26ba25
@@ -864,13 +864,8 @@ retry:
26ba25
 #if LIBISCSI_API_VERSION < (20160603)
26ba25
     scsi_task_set_iov_in(iTask.task, (struct scsi_iovec *) iov->iov, iov->niov);
26ba25
 #endif
26ba25
-    while (!iTask.complete) {
26ba25
-        iscsi_set_events(iscsilun);
26ba25
-        qemu_mutex_unlock(&iscsilun->mutex);
26ba25
-        qemu_coroutine_yield();
26ba25
-        qemu_mutex_lock(&iscsilun->mutex);
26ba25
-    }
26ba25
 
26ba25
+    iscsi_co_wait_for_task(&iTask, iscsilun);
26ba25
     if (iTask.task != NULL) {
26ba25
         scsi_free_scsi_task(iTask.task);
26ba25
         iTask.task = NULL;
26ba25
@@ -907,12 +902,7 @@ retry:
26ba25
         return -ENOMEM;
26ba25
     }
26ba25
 
26ba25
-    while (!iTask.complete) {
26ba25
-        iscsi_set_events(iscsilun);
26ba25
-        qemu_mutex_unlock(&iscsilun->mutex);
26ba25
-        qemu_coroutine_yield();
26ba25
-        qemu_mutex_lock(&iscsilun->mutex);
26ba25
-    }
26ba25
+    iscsi_co_wait_for_task(&iTask, iscsilun);
26ba25
 
26ba25
     if (iTask.task != NULL) {
26ba25
         scsi_free_scsi_task(iTask.task);
26ba25
@@ -1144,12 +1134,7 @@ retry:
26ba25
         goto out_unlock;
26ba25
     }
26ba25
 
26ba25
-    while (!iTask.complete) {
26ba25
-        iscsi_set_events(iscsilun);
26ba25
-        qemu_mutex_unlock(&iscsilun->mutex);
26ba25
-        qemu_coroutine_yield();
26ba25
-        qemu_mutex_lock(&iscsilun->mutex);
26ba25
-    }
26ba25
+    iscsi_co_wait_for_task(&iTask, iscsilun);
26ba25
 
26ba25
     if (iTask.task != NULL) {
26ba25
         scsi_free_scsi_task(iTask.task);
26ba25
@@ -1245,12 +1230,7 @@ retry:
26ba25
         return -ENOMEM;
26ba25
     }
26ba25
 
26ba25
-    while (!iTask.complete) {
26ba25
-        iscsi_set_events(iscsilun);
26ba25
-        qemu_mutex_unlock(&iscsilun->mutex);
26ba25
-        qemu_coroutine_yield();
26ba25
-        qemu_mutex_lock(&iscsilun->mutex);
26ba25
-    }
26ba25
+    iscsi_co_wait_for_task(&iTask, iscsilun);
26ba25
 
26ba25
     if (iTask.status == SCSI_STATUS_CHECK_CONDITION &&
26ba25
         iTask.task->sense.key == SCSI_SENSE_ILLEGAL_REQUEST &&
26ba25
-- 
26ba25
1.8.3.1
26ba25