qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Anton Nefedov <anton.nefedov@virtuozzo.com>
To: qemu-devel@nongnu.org
Cc: den@virtuozzo.com, qemu-block@nongnu.org, qemu-stable@nongnu.org,
	kwolf@redhat.com, mreitz@redhat.com, pl@kamp.de,
	Anton Nefedov <anton.nefedov@virtuozzo.com>
Subject: [Qemu-devel] [PATCH v2 1/1] qemu-img: wait for convert coroutines to complete
Date: Fri, 21 Apr 2017 13:04:36 +0300	[thread overview]
Message-ID: <1492769076-64466-1-git-send-email-anton.nefedov@virtuozzo.com> (raw)

On error path (like i/o error in one of the coroutines), it's required to
  - wait for coroutines completion before cleaning the common structures
  - reenter dependent coroutines so they ever finish

Introduced in 2d9187bc65.

Signed-off-by: Anton Nefedov <anton.nefedov@virtuozzo.com>
---
 qemu-img.c | 44 +++++++++++++++++++++++++++-----------------
 1 file changed, 27 insertions(+), 17 deletions(-)

diff --git a/qemu-img.c b/qemu-img.c
index b220cf7..24950c1 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -1735,6 +1735,27 @@ static int coroutine_fn convert_co_write(ImgConvertState *s, int64_t sector_num,
     return 0;
 }
 
+static void coroutine_fn convert_reenter_waiting(ImgConvertState *s,
+                                                 uint64_t wr_offs)
+{
+    int i;
+    if (s->wr_in_order) {
+        /* reenter the coroutine that might have waited
+         * for the write to complete */
+        for (i = 0; i < s->num_coroutines; i++) {
+            if (s->co[i] && s->wait_sector_num[i] == wr_offs) {
+                /*
+                 * A -> B -> A cannot occur because A has
+                 * s->wait_sector_num[i] == -1 during A -> B.  Therefore
+                 * B will never enter A during this time window.
+                 */
+                qemu_coroutine_enter(s->co[i]);
+                break;
+            }
+        }
+    }
+}
+
 static void coroutine_fn convert_co_do_copy(void *opaque)
 {
     ImgConvertState *s = opaque;
@@ -1792,6 +1813,7 @@ static void coroutine_fn convert_co_do_copy(void *opaque)
                 error_report("error while reading sector %" PRId64
                              ": %s", sector_num, strerror(-ret));
                 s->ret = ret;
+                convert_reenter_waiting(s, sector_num + n);
                 goto out;
             }
         } else if (!s->min_sparse && status == BLK_ZERO) {
@@ -1803,6 +1825,7 @@ static void coroutine_fn convert_co_do_copy(void *opaque)
             /* keep writes in order */
             while (s->wr_offs != sector_num) {
                 if (s->ret != -EINPROGRESS) {
+                    convert_reenter_waiting(s, sector_num + n);
                     goto out;
                 }
                 s->wait_sector_num[index] = sector_num;
@@ -1816,25 +1839,12 @@ static void coroutine_fn convert_co_do_copy(void *opaque)
             error_report("error while writing sector %" PRId64
                          ": %s", sector_num, strerror(-ret));
             s->ret = ret;
+            convert_reenter_waiting(s, sector_num + n);
             goto out;
         }
 
-        if (s->wr_in_order) {
-            /* reenter the coroutine that might have waited
-             * for this write to complete */
-            s->wr_offs = sector_num + n;
-            for (i = 0; i < s->num_coroutines; i++) {
-                if (s->co[i] && s->wait_sector_num[i] == s->wr_offs) {
-                    /*
-                     * A -> B -> A cannot occur because A has
-                     * s->wait_sector_num[i] == -1 during A -> B.  Therefore
-                     * B will never enter A during this time window.
-                     */
-                    qemu_coroutine_enter(s->co[i]);
-                    break;
-                }
-            }
-        }
+        s->wr_offs = sector_num + n;
+        convert_reenter_waiting(s, s->wr_offs);
     }
 
 out:
@@ -1899,7 +1909,7 @@ static int convert_do_copy(ImgConvertState *s)
         qemu_coroutine_enter(s->co[i]);
     }
 
-    while (s->ret == -EINPROGRESS) {
+    while (s->running_coroutines) {
         main_loop_wait(false);
     }
 
-- 
2.7.4

             reply	other threads:[~2017-04-21 17:38 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-21 10:04 Anton Nefedov [this message]
2017-04-21 10:44 ` [Qemu-devel] [PATCH v2 1/1] qemu-img: wait for convert coroutines to complete Peter Lieven
2017-04-21 12:19   ` Anton Nefedov
2017-04-21 12:37     ` Peter Lieven
2017-04-24 16:27       ` Anton Nefedov
2017-04-24 18:16         ` [Qemu-devel] [Qemu-stable] " Peter Lieven
2017-04-24 20:13           ` Anton Nefedov
2017-04-25  9:55             ` Peter Lieven
2017-04-25 13:27               ` Anton Nefedov
2017-04-25 13:39               ` Peter Lieven

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=1492769076-64466-1-git-send-email-anton.nefedov@virtuozzo.com \
    --to=anton.nefedov@virtuozzo.com \
    --cc=den@virtuozzo.com \
    --cc=kwolf@redhat.com \
    --cc=mreitz@redhat.com \
    --cc=pl@kamp.de \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-stable@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).