From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <s.reiter@proxmox.com>
Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68])
 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
 key-exchange X25519 server-signature RSA-PSS (2048 bits))
 (No client certificate requested)
 by lists.proxmox.com (Postfix) with ESMTPS id CEB4663FBA
 for <pve-devel@lists.proxmox.com>; Thu, 29 Oct 2020 14:11:31 +0100 (CET)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
 by firstgate.proxmox.com (Proxmox) with ESMTP id 9314B958D
 for <pve-devel@lists.proxmox.com>; Thu, 29 Oct 2020 14:11:01 +0100 (CET)
Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com
 [212.186.127.180])
 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
 key-exchange X25519 server-signature RSA-PSS (2048 bits))
 (No client certificate requested)
 by firstgate.proxmox.com (Proxmox) with ESMTPS id 623A29556
 for <pve-devel@lists.proxmox.com>; Thu, 29 Oct 2020 14:10:44 +0100 (CET)
Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1])
 by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 2B21645F93
 for <pve-devel@lists.proxmox.com>; Thu, 29 Oct 2020 14:10:44 +0100 (CET)
From: Stefan Reiter <s.reiter@proxmox.com>
To: pve-devel@lists.proxmox.com
Date: Thu, 29 Oct 2020 14:10:32 +0100
Message-Id: <20201029131036.11786-3-s.reiter@proxmox.com>
X-Mailer: git-send-email 2.20.1
In-Reply-To: <20201029131036.11786-1-s.reiter@proxmox.com>
References: <20201029131036.11786-1-s.reiter@proxmox.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-SPAM-LEVEL: Spam detection results:  0
 AWL -0.038 Adjusted score from AWL reputation of From: address
 KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment
 RCVD_IN_DNSWL_MED        -2.3 Sender listed at https://www.dnswl.org/,
 medium trust
 SPF_HELO_NONE           0.001 SPF: HELO does not publish an SPF Record
 SPF_PASS               -0.001 SPF: sender matches SPF record
Subject: [pve-devel] [PATCH v2 qemu 2/6] PVE: Introduce generic CoCtxData
 struct
X-BeenThere: pve-devel@lists.proxmox.com
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Proxmox VE development discussion <pve-devel.lists.proxmox.com>
List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pve-devel>, 
 <mailto:pve-devel-request@lists.proxmox.com?subject=unsubscribe>
List-Archive: <http://lists.proxmox.com/pipermail/pve-devel/>
List-Post: <mailto:pve-devel@lists.proxmox.com>
List-Help: <mailto:pve-devel-request@lists.proxmox.com?subject=help>
List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel>, 
 <mailto:pve-devel-request@lists.proxmox.com?subject=subscribe>
X-List-Received-Date: Thu, 29 Oct 2020 13:11:31 -0000

Adapted from ProxmoxBackupWaker for more general use cases as well.

Signed-off-by: Stefan Reiter <s.reiter@proxmox.com>
---

v2: new, makes patch 4 and 5 cleaner

 proxmox-backup-client.c | 20 +++++++-------------
 proxmox-backup-client.h |  6 ++++++
 2 files changed, 13 insertions(+), 13 deletions(-)

diff --git a/proxmox-backup-client.c b/proxmox-backup-client.c
index 0e9c584701..4ce7bc0b5e 100644
--- a/proxmox-backup-client.c
+++ b/proxmox-backup-client.c
@@ -12,12 +12,6 @@ typedef struct BlockOnCoroutineWrapper {
     bool finished;
 } BlockOnCoroutineWrapper;
 
-// Waker implementaion to syncronice with proxmox backup rust code
-typedef struct ProxmoxBackupWaker {
-    Coroutine *co;
-    AioContext *ctx;
-} ProxmoxBackupWaker;
-
 static void coroutine_fn block_on_coroutine_wrapper(void *opaque)
 {
     BlockOnCoroutineWrapper *wrapper = opaque;
@@ -44,7 +38,7 @@ void block_on_coroutine_fn(CoroutineEntry *entry, void *entry_arg)
 
 // This is called from another thread, so we use aio_co_schedule()
 static void proxmox_backup_schedule_wake(void *data) {
-    ProxmoxBackupWaker *waker = (ProxmoxBackupWaker *)data;
+    CoCtxData *waker = (CoCtxData *)data;
     aio_co_schedule(waker->ctx, waker->co);
 }
 
@@ -53,7 +47,7 @@ proxmox_backup_co_connect(ProxmoxBackupHandle *pbs, Error **errp)
 {
     Coroutine *co = qemu_coroutine_self();
     AioContext *ctx = qemu_get_current_aio_context();
-    ProxmoxBackupWaker waker = { .co = co, .ctx = ctx };
+    CoCtxData waker = { .co = co, .ctx = ctx };
     char *pbs_err = NULL;
     int pbs_res = -1;
 
@@ -76,7 +70,7 @@ proxmox_backup_co_add_config(
 {
     Coroutine *co = qemu_coroutine_self();
     AioContext *ctx = qemu_get_current_aio_context();
-    ProxmoxBackupWaker waker = { .co = co, .ctx = ctx };
+    CoCtxData waker = { .co = co, .ctx = ctx };
     char *pbs_err = NULL;
     int pbs_res = -1;
 
@@ -100,7 +94,7 @@ proxmox_backup_co_register_image(
 {
     Coroutine *co = qemu_coroutine_self();
     AioContext *ctx = qemu_get_current_aio_context();
-    ProxmoxBackupWaker waker = { .co = co, .ctx = ctx };
+    CoCtxData waker = { .co = co, .ctx = ctx };
     char *pbs_err = NULL;
     int pbs_res = -1;
 
@@ -121,7 +115,7 @@ proxmox_backup_co_finish(
 {
     Coroutine *co = qemu_coroutine_self();
     AioContext *ctx = qemu_get_current_aio_context();
-    ProxmoxBackupWaker waker = { .co = co, .ctx = ctx };
+    CoCtxData waker = { .co = co, .ctx = ctx };
     char *pbs_err = NULL;
     int pbs_res = -1;
 
@@ -143,7 +137,7 @@ proxmox_backup_co_close_image(
 {
     Coroutine *co = qemu_coroutine_self();
     AioContext *ctx = qemu_get_current_aio_context();
-    ProxmoxBackupWaker waker = { .co = co, .ctx = ctx };
+    CoCtxData waker = { .co = co, .ctx = ctx };
     char *pbs_err = NULL;
     int pbs_res = -1;
 
@@ -168,7 +162,7 @@ proxmox_backup_co_write_data(
 {
     Coroutine *co = qemu_coroutine_self();
     AioContext *ctx = qemu_get_current_aio_context();
-    ProxmoxBackupWaker waker = { .co = co, .ctx = ctx };
+    CoCtxData waker = { .co = co, .ctx = ctx };
     char *pbs_err = NULL;
     int pbs_res = -1;
 
diff --git a/proxmox-backup-client.h b/proxmox-backup-client.h
index a4781c5851..8cbf645b2c 100644
--- a/proxmox-backup-client.h
+++ b/proxmox-backup-client.h
@@ -5,6 +5,12 @@
 #include "qemu/coroutine.h"
 #include "proxmox-backup-qemu.h"
 
+typedef struct CoCtxData {
+    Coroutine *co;
+    AioContext *ctx;
+    void *data;
+} CoCtxData;
+
 // FIXME: Remove once coroutines are supported for QMP
 void block_on_coroutine_fn(CoroutineEntry *entry, void *entry_arg);
 
-- 
2.20.1