All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH v3 1/1] qemu-img: wait for convert coroutines to complete
@ 2017-04-26  8:33 Anton Nefedov
  2017-04-27 19:09 ` [Qemu-devel] [Qemu-stable] " Peter Lieven
  2017-05-09 15:25 ` [Qemu-devel] " Kevin Wolf
  0 siblings, 2 replies; 3+ messages in thread
From: Anton Nefedov @ 2017-04-26  8:33 UTC (permalink / raw)
  To: qemu-devel; +Cc: den, qemu-block, qemu-stable, kwolf, mreitz, pl, Anton Nefedov

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 | 26 +++++++++++---------------
 1 file changed, 11 insertions(+), 15 deletions(-)

diff --git a/qemu-img.c b/qemu-img.c
index bbe1574..8c50379 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -1761,13 +1761,13 @@ static void coroutine_fn convert_co_do_copy(void *opaque)
         qemu_co_mutex_lock(&s->lock);
         if (s->ret != -EINPROGRESS || s->sector_num >= s->total_sectors) {
             qemu_co_mutex_unlock(&s->lock);
-            goto out;
+            break;
         }
         n = convert_iteration_sectors(s, s->sector_num);
         if (n < 0) {
             qemu_co_mutex_unlock(&s->lock);
             s->ret = n;
-            goto out;
+            break;
         }
         /* save current sector and allocation status to local variables */
         sector_num = s->sector_num;
@@ -1792,7 +1792,6 @@ 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;
-                goto out;
             }
         } else if (!s->min_sparse && status == BLK_ZERO) {
             status = BLK_DATA;
@@ -1801,22 +1800,20 @@ static void coroutine_fn convert_co_do_copy(void *opaque)
 
         if (s->wr_in_order) {
             /* keep writes in order */
-            while (s->wr_offs != sector_num) {
-                if (s->ret != -EINPROGRESS) {
-                    goto out;
-                }
+            while (s->wr_offs != sector_num && s->ret == -EINPROGRESS) {
                 s->wait_sector_num[index] = sector_num;
                 qemu_coroutine_yield();
             }
             s->wait_sector_num[index] = -1;
         }
 
-        ret = convert_co_write(s, sector_num, n, buf, status);
-        if (ret < 0) {
-            error_report("error while writing sector %" PRId64
-                         ": %s", sector_num, strerror(-ret));
-            s->ret = ret;
-            goto out;
+        if (s->ret == -EINPROGRESS) {
+            ret = convert_co_write(s, sector_num, n, buf, status);
+            if (ret < 0) {
+                error_report("error while writing sector %" PRId64
+                             ": %s", sector_num, strerror(-ret));
+                s->ret = ret;
+            }
         }
 
         if (s->wr_in_order) {
@@ -1837,7 +1834,6 @@ static void coroutine_fn convert_co_do_copy(void *opaque)
         }
     }
 
-out:
     qemu_vfree(buf);
     s->co[index] = NULL;
     s->running_coroutines--;
@@ -1899,7 +1895,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

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [Qemu-devel] [Qemu-stable] [PATCH v3 1/1] qemu-img: wait for convert coroutines to complete
  2017-04-26  8:33 [Qemu-devel] [PATCH v3 1/1] qemu-img: wait for convert coroutines to complete Anton Nefedov
@ 2017-04-27 19:09 ` Peter Lieven
  2017-05-09 15:25 ` [Qemu-devel] " Kevin Wolf
  1 sibling, 0 replies; 3+ messages in thread
From: Peter Lieven @ 2017-04-27 19:09 UTC (permalink / raw)
  To: Anton Nefedov
  Cc: qemu-devel, Kevin Wolf, den, qemu-block, qemu-stable, mreitz


> Am 26.04.2017 um 10:33 schrieb Anton Nefedov <anton.nefedov@virtuozzo.com>:
> 
> 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 | 26 +++++++++++---------------
> 1 file changed, 11 insertions(+), 15 deletions(-)
> 
> diff --git a/qemu-img.c b/qemu-img.c
> index bbe1574..8c50379 100644
> --- a/qemu-img.c
> +++ b/qemu-img.c
> @@ -1761,13 +1761,13 @@ static void coroutine_fn convert_co_do_copy(void *opaque)
>         qemu_co_mutex_lock(&s->lock);
>         if (s->ret != -EINPROGRESS || s->sector_num >= s->total_sectors) {
>             qemu_co_mutex_unlock(&s->lock);
> -            goto out;
> +            break;
>         }
>         n = convert_iteration_sectors(s, s->sector_num);
>         if (n < 0) {
>             qemu_co_mutex_unlock(&s->lock);
>             s->ret = n;
> -            goto out;
> +            break;
>         }
>         /* save current sector and allocation status to local variables */
>         sector_num = s->sector_num;
> @@ -1792,7 +1792,6 @@ 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;
> -                goto out;
>             }
>         } else if (!s->min_sparse && status == BLK_ZERO) {
>             status = BLK_DATA;
> @@ -1801,22 +1800,20 @@ static void coroutine_fn convert_co_do_copy(void *opaque)
> 
>         if (s->wr_in_order) {
>             /* keep writes in order */
> -            while (s->wr_offs != sector_num) {
> -                if (s->ret != -EINPROGRESS) {
> -                    goto out;
> -                }
> +            while (s->wr_offs != sector_num && s->ret == -EINPROGRESS) {
>                 s->wait_sector_num[index] = sector_num;
>                 qemu_coroutine_yield();
>             }
>             s->wait_sector_num[index] = -1;
>         }
> 
> -        ret = convert_co_write(s, sector_num, n, buf, status);
> -        if (ret < 0) {
> -            error_report("error while writing sector %" PRId64
> -                         ": %s", sector_num, strerror(-ret));
> -            s->ret = ret;
> -            goto out;
> +        if (s->ret == -EINPROGRESS) {
> +            ret = convert_co_write(s, sector_num, n, buf, status);
> +            if (ret < 0) {
> +                error_report("error while writing sector %" PRId64
> +                             ": %s", sector_num, strerror(-ret));
> +                s->ret = ret;
> +            }
>         }
> 
>         if (s->wr_in_order) {
> @@ -1837,7 +1834,6 @@ static void coroutine_fn convert_co_do_copy(void *opaque)
>         }
>     }
> 
> -out:
>     qemu_vfree(buf);
>     s->co[index] = NULL;
>     s->running_coroutines--;
> @@ -1899,7 +1895,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
> 
> 

Reviewed-by: Peter Lieven <pl@kamp.de <mailto:pl@kamp.de>>

Peter

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Qemu-devel] [PATCH v3 1/1] qemu-img: wait for convert coroutines to complete
  2017-04-26  8:33 [Qemu-devel] [PATCH v3 1/1] qemu-img: wait for convert coroutines to complete Anton Nefedov
  2017-04-27 19:09 ` [Qemu-devel] [Qemu-stable] " Peter Lieven
@ 2017-05-09 15:25 ` Kevin Wolf
  1 sibling, 0 replies; 3+ messages in thread
From: Kevin Wolf @ 2017-05-09 15:25 UTC (permalink / raw)
  To: Anton Nefedov; +Cc: qemu-devel, den, qemu-block, qemu-stable, mreitz, pl

Am 26.04.2017 um 10:33 hat Anton Nefedov geschrieben:
> 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>

Thanks, applied to the block branch.

Kevin

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-05-09 15:25 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-04-26  8:33 [Qemu-devel] [PATCH v3 1/1] qemu-img: wait for convert coroutines to complete Anton Nefedov
2017-04-27 19:09 ` [Qemu-devel] [Qemu-stable] " Peter Lieven
2017-05-09 15:25 ` [Qemu-devel] " Kevin Wolf

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.