All of lore.kernel.org
 help / color / mirror / Atom feed
From: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
To: qemu-devel@nongnu.org
Cc: lukasstraub2@web.de, quintela@redhat.com, chen.zhang@intel.com,
	vsementsov@yandex-team.ru,
	Hailiang Zhang <zhanghailiang@xfusion.com>,
	Peter Xu <peterx@redhat.com>, Leonardo Bras <leobras@redhat.com>,
	Paolo Bonzini <pbonzini@redhat.com>
Subject: [PATCH v4 08/10] migration: process_incoming_migration_co(): move colo part to colo
Date: Fri, 28 Apr 2023 22:49:26 +0300	[thread overview]
Message-ID: <20230428194928.1426370-9-vsementsov@yandex-team.ru> (raw)
In-Reply-To: <20230428194928.1426370-1-vsementsov@yandex-team.ru>

Let's make better public interface for COLO: instead of
colo_process_incoming_thread and not trivial logic around creating the
thread let's make simple colo_incoming_co(), hiding implementation from
generic code.

Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
---
 include/migration/colo.h |  9 ++++++++-
 migration/colo.c         | 39 ++++++++++++++++++++++++++++++++++++++-
 migration/migration.c    | 28 ++--------------------------
 stubs/colo.c             |  6 ++----
 4 files changed, 50 insertions(+), 32 deletions(-)

diff --git a/include/migration/colo.h b/include/migration/colo.h
index 7ef315473e..eaac07f26d 100644
--- a/include/migration/colo.h
+++ b/include/migration/colo.h
@@ -28,7 +28,6 @@ bool migration_in_colo_state(void);
 int migration_incoming_enable_colo(void);
 void migration_incoming_disable_colo(void);
 bool migration_incoming_colo_enabled(void);
-void *colo_process_incoming_thread(void *opaque);
 bool migration_incoming_in_colo_state(void);
 
 COLOMode get_colo_mode(void);
@@ -44,5 +43,13 @@ void colo_do_failover(void);
  */
 void colo_checkpoint_delay_set(void);
 
+/*
+ * Starts COLO incoming process. Called from process_incoming_migration_co()
+ * after loading the state.
+ *
+ * Called with BQL locked, may temporary release BQL.
+ */
+int coroutine_fn colo_incoming_co(void);
+
 void colo_shutdown(void);
 #endif
diff --git a/migration/colo.c b/migration/colo.c
index a688ac553a..d775b442d8 100644
--- a/migration/colo.c
+++ b/migration/colo.c
@@ -817,7 +817,7 @@ void colo_shutdown(void)
     }
 }
 
-void *colo_process_incoming_thread(void *opaque)
+static void *colo_process_incoming_thread(void *opaque)
 {
     MigrationIncomingState *mis = opaque;
     QEMUFile *fb = NULL;
@@ -918,3 +918,40 @@ out:
     rcu_unregister_thread();
     return NULL;
 }
+
+int coroutine_fn colo_incoming_co(void)
+{
+    MigrationIncomingState *mis = migration_incoming_get_current();
+    Error *local_err = NULL;
+    QemuThread th;
+
+    assert(!qemu_mutex_iothread_locked());
+
+    if (!migration_incoming_colo_enabled()) {
+        return 0;
+    }
+
+    /* Make sure all file formats throw away their mutable metadata */
+    bdrv_activate_all(&local_err);
+    if (local_err) {
+        error_report_err(local_err);
+        return -EINVAL;
+    }
+
+    qemu_thread_create(&th, "COLO incoming", colo_process_incoming_thread,
+                       mis, QEMU_THREAD_JOINABLE);
+
+    mis->colo_incoming_co = qemu_coroutine_self();
+    qemu_coroutine_yield();
+    mis->colo_incoming_co = NULL;
+
+    qemu_mutex_unlock_iothread();
+    /* Wait checkpoint incoming thread exit before free resource */
+    qemu_thread_join(&th);
+    qemu_mutex_lock_iothread();
+
+    /* We hold the global iothread lock, so it is safe here */
+    colo_release_ram_cache();
+
+    return 0;
+}
diff --git a/migration/migration.c b/migration/migration.c
index 23b2d187de..0d912ee0d7 100644
--- a/migration/migration.c
+++ b/migration/migration.c
@@ -502,7 +502,6 @@ process_incoming_migration_co(void *opaque)
     MigrationIncomingState *mis = migration_incoming_get_current();
     PostcopyState ps;
     int ret;
-    Error *local_err = NULL;
 
     assert(mis->from_src_file);
     mis->largest_page_size = qemu_ram_pagesize_largest();
@@ -540,37 +539,14 @@ process_incoming_migration_co(void *opaque)
         goto fail;
     }
 
-    /* we get COLO info, and know if we are in COLO mode */
-    if (migration_incoming_colo_enabled()) {
-        QemuThread colo_incoming_thread;
-
-        /* Make sure all file formats throw away their mutable metadata */
-        bdrv_activate_all(&local_err);
-        if (local_err) {
-            error_report_err(local_err);
-            goto fail;
-        }
-
-        qemu_thread_create(&colo_incoming_thread, "COLO incoming",
-             colo_process_incoming_thread, mis, QEMU_THREAD_JOINABLE);
-
-        mis->colo_incoming_co = qemu_coroutine_self();
-        qemu_coroutine_yield();
-        mis->colo_incoming_co = NULL;
-
-        qemu_mutex_unlock_iothread();
-        /* Wait checkpoint incoming thread exit before free resource */
-        qemu_thread_join(&colo_incoming_thread);
-        qemu_mutex_lock_iothread();
-        /* We hold the global iothread lock, so it is safe here */
-        colo_release_ram_cache();
+    if (colo_incoming_co() < 0) {
+        goto fail;
     }
 
     mis->bh = qemu_bh_new(process_incoming_migration_bh, mis);
     qemu_bh_schedule(mis->bh);
     return;
 fail:
-    local_err = NULL;
     migrate_set_state(&mis->state, MIGRATION_STATUS_ACTIVE,
                       MIGRATION_STATUS_FAILED);
     qemu_fclose(mis->from_src_file);
diff --git a/stubs/colo.c b/stubs/colo.c
index cf9816d368..f33379d0fd 100644
--- a/stubs/colo.c
+++ b/stubs/colo.c
@@ -10,11 +10,9 @@ void colo_shutdown(void)
 {
 }
 
-void *colo_process_incoming_thread(void *opaque)
+int coroutine_fn colo_incoming_co(void)
 {
-    error_report("Impossible happend: trying to start COLO thread when COLO "
-                 "module is not built in");
-    abort();
+    return 0;
 }
 
 void colo_checkpoint_delay_set(void)
-- 
2.34.1



  parent reply	other threads:[~2023-04-28 19:51 UTC|newest]

Thread overview: 50+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-28 19:49 [PATCH v4 00/10] COLO: improve build options Vladimir Sementsov-Ogievskiy
2023-04-28 19:49 ` [PATCH v4 01/10] block/meson.build: prefer positive condition for replication Vladimir Sementsov-Ogievskiy
2023-05-04  7:31   ` Zhang, Chen
2023-04-28 19:49 ` [PATCH v4 02/10] colo: make colo_checkpoint_notify static and provide simpler API Vladimir Sementsov-Ogievskiy
2023-05-02 18:24   ` Juan Quintela
2023-05-02 20:58   ` Peter Xu
2023-05-04  7:35   ` Zhang, Chen
2023-04-28 19:49 ` [PATCH v4 03/10] build: move COLO under CONFIG_REPLICATION Vladimir Sementsov-Ogievskiy
2023-05-02 16:41   ` Peter Xu
2023-05-03 22:43     ` Vladimir Sementsov-Ogievskiy
2023-05-09 18:17   ` Juan Quintela
2023-04-28 19:49 ` [PATCH v4 04/10] configure: add --disable-colo-proxy option Vladimir Sementsov-Ogievskiy
2023-05-04  7:45   ` Zhang, Chen
2023-05-09 18:42     ` Juan Quintela
2023-05-10 11:36       ` Vladimir Sementsov-Ogievskiy
2023-05-10 12:18         ` Juan Quintela
2023-05-10 12:48           ` Vladimir Sementsov-Ogievskiy
2023-05-10 13:48             ` Juan Quintela
2023-04-28 19:49 ` [PATCH v4 05/10] migration: drop colo_incoming_thread from MigrationIncomingState Vladimir Sementsov-Ogievskiy
2023-05-02 16:43   ` Peter Xu
2023-05-02 18:19   ` Juan Quintela
2023-05-04  7:46   ` Zhang, Chen
2023-04-28 19:49 ` [PATCH v4 06/10] migration: process_incoming_migration_co: simplify code flow around ret Vladimir Sementsov-Ogievskiy
2023-05-02 16:52   ` Peter Xu
2023-05-02 18:20   ` Juan Quintela
2023-05-04  7:48   ` Zhang, Chen
2023-04-28 19:49 ` [PATCH v4 07/10] migration: split migration_incoming_co Vladimir Sementsov-Ogievskiy
2023-05-02 20:48   ` Peter Xu
2023-05-03 22:51     ` Vladimir Sementsov-Ogievskiy
2023-05-04  7:51       ` Zhang, Chen
2023-04-28 19:49 ` Vladimir Sementsov-Ogievskiy [this message]
2023-05-02 20:54   ` [PATCH v4 08/10] migration: process_incoming_migration_co(): move colo part to colo Peter Xu
2023-05-03  9:15     ` Vladimir Sementsov-Ogievskiy
2023-04-28 19:49 ` [PATCH v4 09/10] migration: disallow change capabilities in COLO state Vladimir Sementsov-Ogievskiy
2023-05-02 20:57   ` Peter Xu
2023-05-04  8:09   ` Zhang, Chen
2023-05-04  8:23     ` Vladimir Sementsov-Ogievskiy
2023-05-04  9:03       ` Zhang, Chen
2023-05-09 18:22         ` Juan Quintela
2023-05-09 18:46   ` Juan Quintela
2023-04-28 19:49 ` [PATCH v4 10/10] migration: block incoming colo when capability is disabled Vladimir Sementsov-Ogievskiy
2023-05-02 20:57   ` Peter Xu
2023-05-04  9:25   ` Zhang, Chen
2023-05-04 22:10   ` Lukas Straub
2023-05-04 22:30     ` Vladimir Sementsov-Ogievskiy
2023-05-04 22:46       ` Lukas Straub
2023-05-05  7:51         ` Zhang, Chen
2023-05-09 18:23   ` Juan Quintela
2023-05-05  7:56 ` [PATCH v4 00/10] COLO: improve build options Zhang, Chen
2023-05-05  8:21   ` Vladimir Sementsov-Ogievskiy

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230428194928.1426370-9-vsementsov@yandex-team.ru \
    --to=vsementsov@yandex-team.ru \
    --cc=chen.zhang@intel.com \
    --cc=leobras@redhat.com \
    --cc=lukasstraub2@web.de \
    --cc=pbonzini@redhat.com \
    --cc=peterx@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=quintela@redhat.com \
    --cc=zhanghailiang@xfusion.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.