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

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