diff mbox series

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

Message ID 20181123165511.416480-6-vsementsov@virtuozzo.com (mailing list archive)
State New, archived
Headers show
Series qcow2: encryption threads | expand

Commit Message

Vladimir Sementsov-Ogievskiy Nov. 23, 2018, 4:55 p.m. UTC
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 <vsementsov@virtuozzo.com>
---
 block/qcow2-threads.c | 41 ++++++++++++++++++++++++++++-------------
 1 file changed, 28 insertions(+), 13 deletions(-)
diff mbox series

Patch

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;
 }