Blame SOURCES/kvm-qcow2-Remove-coroutine-trampoline-for-preallocate_co.patch

1bdc94
From 17d9cdafd0e6859af0b44b26870f8d61bc6f7c2d Mon Sep 17 00:00:00 2001
1bdc94
From: Kevin Wolf <kwolf@redhat.com>
1bdc94
Date: Thu, 12 Jul 2018 14:42:55 +0200
1bdc94
Subject: [PATCH 36/89] qcow2: Remove coroutine trampoline for preallocate_co()
1bdc94
1bdc94
RH-Author: Kevin Wolf <kwolf@redhat.com>
1bdc94
Message-id: <20180712144258.17303-4-kwolf@redhat.com>
1bdc94
Patchwork-id: 81329
1bdc94
O-Subject: [RHV-7.6 qemu-kvm-rhev PATCH 3/6] qcow2: Remove coroutine trampoline for preallocate_co()
1bdc94
Bugzilla: 1595173
1bdc94
RH-Acked-by: Max Reitz <mreitz@redhat.com>
1bdc94
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
1bdc94
RH-Acked-by: John Snow <jsnow@redhat.com>
1bdc94
1bdc94
All callers are coroutine_fns now, so we can just directly call
1bdc94
preallocate_co().
1bdc94
1bdc94
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
1bdc94
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
1bdc94
(cherry picked from commit 47e86b868d57ffe13162ca44e5f6a51c15c4a769)
1bdc94
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
1bdc94
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
1bdc94
---
1bdc94
 block/qcow2.c | 51 ++++++++-------------------------------------------
1bdc94
 1 file changed, 8 insertions(+), 43 deletions(-)
1bdc94
1bdc94
diff --git a/block/qcow2.c b/block/qcow2.c
1bdc94
index c5c6ae9..71fbfcd 100644
1bdc94
--- a/block/qcow2.c
1bdc94
+++ b/block/qcow2.c
1bdc94
@@ -2517,15 +2517,6 @@ static int qcow2_set_up_encryption(BlockDriverState *bs,
1bdc94
     return ret;
1bdc94
 }
1bdc94
 
1bdc94
-
1bdc94
-typedef struct PreallocCo {
1bdc94
-    BlockDriverState *bs;
1bdc94
-    uint64_t offset;
1bdc94
-    uint64_t new_length;
1bdc94
-
1bdc94
-    int ret;
1bdc94
-} PreallocCo;
1bdc94
-
1bdc94
 /**
1bdc94
  * Preallocates metadata structures for data clusters between @offset (in the
1bdc94
  * guest disk) and @new_length (which is thus generally the new guest disk
1bdc94
@@ -2533,12 +2524,9 @@ typedef struct PreallocCo {
1bdc94
  *
1bdc94
  * Returns: 0 on success, -errno on failure.
1bdc94
  */
1bdc94
-static void coroutine_fn preallocate_co(void *opaque)
1bdc94
+static int coroutine_fn preallocate_co(BlockDriverState *bs, uint64_t offset,
1bdc94
+                                       uint64_t new_length)
1bdc94
 {
1bdc94
-    PreallocCo *params = opaque;
1bdc94
-    BlockDriverState *bs = params->bs;
1bdc94
-    uint64_t offset = params->offset;
1bdc94
-    uint64_t new_length = params->new_length;
1bdc94
     uint64_t bytes;
1bdc94
     uint64_t host_offset = 0;
1bdc94
     unsigned int cur_bytes;
1bdc94
@@ -2553,7 +2541,7 @@ static void coroutine_fn preallocate_co(void *opaque)
1bdc94
         ret = qcow2_alloc_cluster_offset(bs, offset, &cur_bytes,
1bdc94
                                          &host_offset, &meta);
1bdc94
         if (ret < 0) {
1bdc94
-            goto done;
1bdc94
+            return ret;
1bdc94
         }
1bdc94
 
1bdc94
         while (meta) {
1bdc94
@@ -2563,7 +2551,7 @@ static void coroutine_fn preallocate_co(void *opaque)
1bdc94
             if (ret < 0) {
1bdc94
                 qcow2_free_any_clusters(bs, meta->alloc_offset,
1bdc94
                                         meta->nb_clusters, QCOW2_DISCARD_NEVER);
1bdc94
-                goto done;
1bdc94
+                return ret;
1bdc94
             }
1bdc94
 
1bdc94
             /* There are no dependent requests, but we need to remove our
1bdc94
@@ -2590,34 +2578,11 @@ static void coroutine_fn preallocate_co(void *opaque)
1bdc94
         ret = bdrv_pwrite(bs->file, (host_offset + cur_bytes) - 1,
1bdc94
                           &data, 1);
1bdc94
         if (ret < 0) {
1bdc94
-            goto done;
1bdc94
+            return ret;
1bdc94
         }
1bdc94
     }
1bdc94
 
1bdc94
-    ret = 0;
1bdc94
-
1bdc94
-done:
1bdc94
-    params->ret = ret;
1bdc94
-}
1bdc94
-
1bdc94
-static int preallocate(BlockDriverState *bs,
1bdc94
-                       uint64_t offset, uint64_t new_length)
1bdc94
-{
1bdc94
-    PreallocCo params = {
1bdc94
-        .bs         = bs,
1bdc94
-        .offset     = offset,
1bdc94
-        .new_length = new_length,
1bdc94
-        .ret        = -EINPROGRESS,
1bdc94
-    };
1bdc94
-
1bdc94
-    if (qemu_in_coroutine()) {
1bdc94
-        preallocate_co(&params);
1bdc94
-    } else {
1bdc94
-        Coroutine *co = qemu_coroutine_create(preallocate_co, &params);
1bdc94
-        bdrv_coroutine_enter(bs, co);
1bdc94
-        BDRV_POLL_WHILE(bs, params.ret == -EINPROGRESS);
1bdc94
-    }
1bdc94
-    return params.ret;
1bdc94
+    return 0;
1bdc94
 }
1bdc94
 
1bdc94
 /* qcow2_refcount_metadata_size:
1bdc94
@@ -3035,7 +3000,7 @@ qcow2_co_create(BlockdevCreateOptions *create_options, Error **errp)
1bdc94
     if (qcow2_opts->preallocation != PREALLOC_MODE_OFF) {
1bdc94
         BDRVQcow2State *s = blk_bs(blk)->opaque;
1bdc94
         qemu_co_mutex_lock(&s->lock);
1bdc94
-        ret = preallocate(blk_bs(blk), 0, qcow2_opts->size);
1bdc94
+        ret = preallocate_co(blk_bs(blk), 0, qcow2_opts->size);
1bdc94
         qemu_co_mutex_unlock(&s->lock);
1bdc94
 
1bdc94
         if (ret < 0) {
1bdc94
@@ -3544,7 +3509,7 @@ static int coroutine_fn qcow2_co_truncate(BlockDriverState *bs, int64_t offset,
1bdc94
         break;
1bdc94
 
1bdc94
     case PREALLOC_MODE_METADATA:
1bdc94
-        ret = preallocate(bs, old_length, offset);
1bdc94
+        ret = preallocate_co(bs, old_length, offset);
1bdc94
         if (ret < 0) {
1bdc94
             error_setg_errno(errp, -ret, "Preallocation failed");
1bdc94
             goto fail;
1bdc94
-- 
1bdc94
1.8.3.1
1bdc94