qemu-block
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-block] [PATCH 05/11] qcow2-threads: split out generic path


From: Vladimir Sementsov-Ogievskiy
Subject: [Qemu-block] [PATCH 05/11] qcow2-threads: split out generic path
Date: Fri, 23 Nov 2018 19:55:05 +0300

Move generic part out of qcow2_co_do_compress, to reuse it for
encryption and rename things that would be shared with encryption path.

Signed-off-by: Vladimir Sementsov-Ogievskiy <address@hidden>
---
 block/qcow2-threads.c | 41 ++++++++++++++++++++++++++++-------------
 1 file changed, 28 insertions(+), 13 deletions(-)

diff --git a/block/qcow2-threads.c b/block/qcow2-threads.c
index 028cf3175e..a09f07e2f9 100644
--- a/block/qcow2-threads.c
+++ b/block/qcow2-threads.c
@@ -31,7 +31,33 @@
 #include "qcow2.h"
 #include "block/thread-pool.h"
 
-#define MAX_COMPRESS_THREADS 4
+#define QCOW2_MAX_THREADS 4
+
+static int coroutine_fn
+qcow2_co_process(BlockDriverState *bs, ThreadPoolFunc *func, void *arg)
+{
+    int ret;
+    BDRVQcow2State *s = bs->opaque;
+    Qcow2ThreadsState *thr = &s->threads;
+    ThreadPool *pool = aio_get_thread_pool(bdrv_get_aio_context(bs));
+
+    while (thr->count >= QCOW2_MAX_THREADS) {
+        qemu_co_queue_wait(&thr->task_queue, NULL);
+    }
+
+    thr->count++;
+    ret = thread_pool_submit_co(pool, func, arg);
+    thr->count--;
+
+    qemu_co_queue_next(&thr->task_queue);
+
+    return ret;
+}
+
+
+/*
+ * Compression
+ */
 
 typedef ssize_t (*Qcow2CompressFunc)(void *dest, size_t dest_size,
                                      const void *src, size_t src_size);
@@ -144,9 +170,6 @@ static ssize_t coroutine_fn
 qcow2_co_do_compress(BlockDriverState *bs, void *dest, size_t dest_size,
                      const void *src, size_t src_size, Qcow2CompressFunc func)
 {
-    BDRVQcow2State *s = bs->opaque;
-    Qcow2ThreadsState *thr = &s->threads;
-    ThreadPool *pool = aio_get_thread_pool(bdrv_get_aio_context(bs));
     Qcow2CompressData arg = {
         .dest = dest,
         .dest_size = dest_size,
@@ -155,15 +178,7 @@ qcow2_co_do_compress(BlockDriverState *bs, void *dest, 
size_t dest_size,
         .func = func,
     };
 
-    while (thr->count >= MAX_COMPRESS_THREADS) {
-        qemu_co_queue_wait(&thr->task_queue, NULL);
-    }
-
-    thr->count++;
-    thread_pool_submit_co(pool, qcow2_compress_pool_func, &arg);
-    thr->count--;
-
-    qemu_co_queue_next(&thr->task_queue);
+    qcow2_co_process(bs, qcow2_compress_pool_func, &arg);
 
     return arg.ret;
 }
-- 
2.18.0




reply via email to

[Prev in Thread] Current Thread [Next in Thread]