File Allow-bdrv_get_allocated_file_size-to-ru.patch of Package qemu.30222

From: Dario Faggioli <dfaggioli@suse.com>
Date: Thu, 1 Jun 2023 16:31:16 +0200
Subject: Allow bdrv_get_allocated_file_size to run in bdrv context

Git-commit: Not yet
References: bsc#1211000

Signed-off-by: Joao Silva <joao.silva@suse.com>
Signed-off-by: Dario Faggioli <dfaggioli@suse.com>
---
 block/qapi.c | 22 +++++++++++++++++++++-
 1 file changed, 21 insertions(+), 1 deletion(-)

diff --git a/block/qapi.c b/block/qapi.c
index 7a3140ec1e5c30991a519f14db3e..12c86ad73921c39e74b272a11f97 100644
--- a/block/qapi.c
+++ b/block/qapi.c
@@ -251,6 +251,26 @@ int bdrv_query_snapshot_info_list(BlockDriverState *bs,
     return 0;
 }
 
+static int64_t bdrv_get_actual_size(BlockDriverState *bs)
+{
+    int64_t size;
+    AioContext *old_ctx = NULL;
+
+    if (qemu_in_coroutine()) {
+        aio_context_release(bdrv_get_aio_context(bs));
+        old_ctx = bdrv_co_enter(bs);
+    }
+
+    size = bdrv_get_allocated_file_size(bs);
+
+    if (qemu_in_coroutine() && old_ctx) {
+        bdrv_co_leave(bs, old_ctx);
+        aio_context_acquire(bdrv_get_aio_context(bs));
+    }
+
+    return size;
+}
+
 /**
  * bdrv_query_image_info:
  * @bs: block device to examine
@@ -292,7 +312,7 @@ void bdrv_query_image_info(BlockDriverState *bs,
     info->filename        = g_strdup(bs->filename);
     info->format          = g_strdup(bdrv_get_format_name(bs));
     info->virtual_size    = size;
-    info->actual_size     = bdrv_get_allocated_file_size(bs);
+    info->actual_size     = bdrv_get_actual_size(bs);
     info->has_actual_size = info->actual_size >= 0;
     if (bs->encrypted) {
         info->encrypted = true;
openSUSE Build Service is sponsored by