Blame SOURCES/kvm-iscsi-Create-and-use-iscsi_co_wait_for_task.patch

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