qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Juan Quintela <quintela@redhat.com>
To: qemu-devel@nongnu.org
Cc: Paolo Bonzini <pbonzini@redhat.com>,
	Leonardo Bras <leobras@redhat.com>, Peter Xu <peterx@redhat.com>,
	Juan Quintela <quintela@redhat.com>,
	Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
Subject: [PULL 02/21] migration: never fail in global_state_store()
Date: Tue, 30 May 2023 20:25:12 +0200	[thread overview]
Message-ID: <20230530182531.6371-3-quintela@redhat.com> (raw)
In-Reply-To: <20230530182531.6371-1-quintela@redhat.com>

From: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>

Actually global_state_store() can never fail. Let's get rid of extra
error paths.

To make things clear, use new runstate_get() and use same approach for
global_state_store() and global_state_store_running().

Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
Reviewed-by: Juan Quintela <quintela@redhat.com>
Message-Id: <20230517123752.21615-3-vsementsov@yandex-team.ru>
Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 include/migration/global_state.h |  2 +-
 migration/global_state.c         | 29 +++++++++++-----------
 migration/migration.c            | 41 +++++++++++++++-----------------
 migration/savevm.c               |  6 +----
 4 files changed, 35 insertions(+), 43 deletions(-)

diff --git a/include/migration/global_state.h b/include/migration/global_state.h
index 945eb35d5b..d7c2cd3216 100644
--- a/include/migration/global_state.h
+++ b/include/migration/global_state.h
@@ -16,7 +16,7 @@
 #include "qapi/qapi-types-run-state.h"
 
 void register_global_state(void);
-int global_state_store(void);
+void global_state_store(void);
 void global_state_store_running(void);
 bool global_state_received(void);
 RunState global_state_get_runstate(void);
diff --git a/migration/global_state.c b/migration/global_state.c
index a33947ca32..4e2a9d8ec0 100644
--- a/migration/global_state.c
+++ b/migration/global_state.c
@@ -29,23 +29,22 @@ typedef struct {
 
 static GlobalState global_state;
 
-int global_state_store(void)
+static void global_state_do_store(RunState state)
 {
-    if (!runstate_store((char *)global_state.runstate,
-                        sizeof(global_state.runstate))) {
-        error_report("runstate name too big: %s", global_state.runstate);
-        trace_migrate_state_too_big();
-        return -EINVAL;
-    }
-    return 0;
-}
-
-void global_state_store_running(void)
-{
-    const char *state = RunState_str(RUN_STATE_RUNNING);
-    assert(strlen(state) < sizeof(global_state.runstate));
+    const char *state_str = RunState_str(state);
+    assert(strlen(state_str) < sizeof(global_state.runstate));
     strpadcpy((char *)global_state.runstate, sizeof(global_state.runstate),
-              state, '\0');
+              state_str, '\0');
+}
+
+void global_state_store(void)
+{
+    global_state_do_store(runstate_get());
+}
+
+void global_state_store_running(void)
+{
+    global_state_do_store(RUN_STATE_RUNNING);
 }
 
 bool global_state_received(void)
diff --git a/migration/migration.c b/migration/migration.c
index 5de7f734b9..c75d5aa479 100644
--- a/migration/migration.c
+++ b/migration/migration.c
@@ -2288,27 +2288,26 @@ static void migration_completion(MigrationState *s)
         s->downtime_start = qemu_clock_get_ms(QEMU_CLOCK_REALTIME);
         qemu_system_wakeup_request(QEMU_WAKEUP_REASON_OTHER, NULL);
         s->vm_was_running = runstate_is_running();
-        ret = global_state_store();
+        global_state_store();
 
-        if (!ret) {
-            ret = vm_stop_force_state(RUN_STATE_FINISH_MIGRATE);
-            trace_migration_completion_vm_stop(ret);
-            if (ret >= 0) {
-                ret = migration_maybe_pause(s, &current_active_state,
-                                            MIGRATION_STATUS_DEVICE);
-            }
-            if (ret >= 0) {
-                /*
-                 * Inactivate disks except in COLO, and track that we
-                 * have done so in order to remember to reactivate
-                 * them if migration fails or is cancelled.
-                 */
-                s->block_inactive = !migrate_colo();
-                migration_rate_set(RATE_LIMIT_DISABLED);
-                ret = qemu_savevm_state_complete_precopy(s->to_dst_file, false,
-                                                         s->block_inactive);
-            }
+        ret = vm_stop_force_state(RUN_STATE_FINISH_MIGRATE);
+        trace_migration_completion_vm_stop(ret);
+        if (ret >= 0) {
+            ret = migration_maybe_pause(s, &current_active_state,
+                                        MIGRATION_STATUS_DEVICE);
         }
+        if (ret >= 0) {
+            /*
+             * Inactivate disks except in COLO, and track that we
+             * have done so in order to remember to reactivate
+             * them if migration fails or is cancelled.
+             */
+            s->block_inactive = !migrate_colo();
+            migration_rate_set(RATE_LIMIT_DISABLED);
+            ret = qemu_savevm_state_complete_precopy(s->to_dst_file, false,
+                                                     s->block_inactive);
+        }
+
         qemu_mutex_unlock_iothread();
 
         if (ret < 0) {
@@ -3088,9 +3087,7 @@ static void *bg_migration_thread(void *opaque)
     qemu_system_wakeup_request(QEMU_WAKEUP_REASON_OTHER, NULL);
     s->vm_was_running = runstate_is_running();
 
-    if (global_state_store()) {
-        goto fail;
-    }
+    global_state_store();
     /* Forcibly stop VM before saving state of vCPUs and devices */
     if (vm_stop_force_state(RUN_STATE_PAUSED)) {
         goto fail;
diff --git a/migration/savevm.c b/migration/savevm.c
index 03795ce8dc..bc284087f9 100644
--- a/migration/savevm.c
+++ b/migration/savevm.c
@@ -2919,11 +2919,7 @@ bool save_snapshot(const char *name, bool overwrite, const char *vmstate,
 
     saved_vm_running = runstate_is_running();
 
-    ret = global_state_store();
-    if (ret) {
-        error_setg(errp, "Error saving global state");
-        return false;
-    }
+    global_state_store();
     vm_stop(RUN_STATE_SAVE_VM);
 
     bdrv_drain_all_begin();
-- 
2.40.1



  parent reply	other threads:[~2023-05-30 18:28 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-30 18:25 [PULL 00/21] Migration 20230530 patches Juan Quintela
2023-05-30 18:25 ` [PULL 01/21] runstate: add runstate_get() Juan Quintela
2023-05-30 18:25 ` Juan Quintela [this message]
2023-05-30 18:25 ` [PULL 03/21] runstate: drop unused runstate_store() Juan Quintela
2023-05-30 18:25 ` [PULL 04/21] migration: switch from .vm_was_running to .vm_old_state Juan Quintela
2023-05-30 18:25 ` [PULL 05/21] migration: restore vmstate on migration failure Juan Quintela
2023-05-30 18:25 ` [PULL 06/21] migration: Don't abuse qemu_file transferred for RDMA Juan Quintela
2023-05-30 18:25 ` [PULL 07/21] migration/RDMA: It is accounting for zero/normal pages in two places Juan Quintela
2023-05-30 18:25 ` [PULL 08/21] migration/rdma: Remove QEMUFile parameter when not used Juan Quintela
2023-05-30 18:25 ` [PULL 09/21] migration/rdma: Don't use imaginary transfers Juan Quintela
2023-05-30 18:25 ` [PULL 10/21] migration: Remove unused qemu_file_credit_transfer() Juan Quintela
2023-05-30 18:25 ` [PULL 11/21] migration/rdma: Simplify the function that saves a page Juan Quintela
2023-05-30 18:25 ` [PULL 12/21] migration: Create migrate_rdma() Juan Quintela
2023-05-30 18:25 ` [PULL 13/21] migration/rdma: Unfold ram_control_before_iterate() Juan Quintela
2023-06-01  8:57   ` Daniel P. Berrangé
2023-05-30 18:25 ` [PULL 14/21] migration/rdma: Unfold ram_control_after_iterate() Juan Quintela
2023-06-01  8:58   ` Daniel P. Berrangé
2023-05-30 18:25 ` [PULL 15/21] migration/rdma: Remove all uses of RAM_CONTROL_HOOK Juan Quintela
2023-06-01  9:01   ` Daniel P. Berrangé
2023-05-30 18:25 ` [PULL 16/21] migration/rdma: Unfold hook_ram_load() Juan Quintela
2023-06-01  9:02   ` Daniel P. Berrangé
2023-05-30 18:25 ` [PULL 17/21] migration/rdma: Create rdma_control_save_page() Juan Quintela
2023-05-30 18:25 ` [PULL 18/21] qemu-file: Remove QEMUFileHooks Juan Quintela
2023-05-30 18:25 ` [PULL 19/21] migration/rdma: Move rdma constants from qemu-file.h to rdma.h Juan Quintela
2023-05-30 18:25 ` [PULL 20/21] migration/rdma: Remove qemu_ prefix from exported functions Juan Quintela
2023-05-30 18:25 ` [PULL 21/21] migration/rdma: Check sooner if we are in postcopy for save_page() Juan Quintela
2023-05-30 20:23 ` [PULL 00/21] Migration 20230530 patches Richard Henderson
2023-05-31  7:28   ` Juan Quintela
2023-05-31  9:10   ` Juan Quintela
     [not found]   ` <87mt1ktdr8.fsf@secure.mitica>
2023-05-31 21:28     ` Richard Henderson
2023-06-01  6:47       ` Juan Quintela
2023-06-01  8:27     ` Daniel P. Berrangé
2023-06-01  9:05       ` Daniel P. Berrangé
2023-06-01 11:46         ` Juan Quintela
  -- strict thread matches above, loose matches on Subject: below --
2023-05-30 11:54 Juan Quintela
2023-05-30 11:54 ` [PULL 02/21] migration: never fail in global_state_store() Juan Quintela

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=20230530182531.6371-3-quintela@redhat.com \
    --to=quintela@redhat.com \
    --cc=leobras@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=peterx@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=vsementsov@yandex-team.ru \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).