From: Steve Sistare <steven.sistare@oracle.com>
To: qemu-devel@nongnu.org
Cc: "Peter Xu" <peterx@redhat.com>,
"Paolo Bonzini" <pbonzini@redhat.com>,
"Thomas Huth" <thuth@redhat.com>,
"Daniel P. Berrangé" <berrange@redhat.com>,
"Fabiano Rosas" <farosas@suse.de>,
"Leonardo Bras" <leobras@redhat.com>,
"Markus Armbruster" <armbru@redhat.com>,
"Anthony PERARD" <anthony.perard@citrix.com>,
"Stefan Berger" <stefanb@linux.vnet.ibm.com>,
"Gerd Hoffmann" <kraxel@redhat.com>,
"Stefano Stabellini" <sstabellini@kernel.org>,
"Paul Durrant" <paul@xen.org>, "Eric Blake" <eblake@redhat.com>,
"Richard Henderson" <richard.henderson@linaro.org>,
"Steve Sistare" <steven.sistare@oracle.com>
Subject: [PATCH V9 05/12] migration: propagate suspended runstate
Date: Wed, 3 Jan 2024 12:05:34 -0800 [thread overview]
Message-ID: <1704312341-66640-6-git-send-email-steven.sistare@oracle.com> (raw)
In-Reply-To: <1704312341-66640-1-git-send-email-steven.sistare@oracle.com>
If the outgoing machine was previously suspended, propagate that to the
incoming side via global_state, so a subsequent vm_start restores the
suspended state. To maintain backward and forward compatibility, reclaim
some space from the runstate member.
Signed-off-by: Steve Sistare <steven.sistare@oracle.com>
Reviewed-by: Peter Xu <peterx@redhat.com>
---
migration/global_state.c | 47 +++++++++++++++++++++++++++--------------------
1 file changed, 27 insertions(+), 20 deletions(-)
diff --git a/migration/global_state.c b/migration/global_state.c
index 4e2a9d8..64a573c 100644
--- a/migration/global_state.c
+++ b/migration/global_state.c
@@ -22,7 +22,16 @@
typedef struct {
uint32_t size;
- uint8_t runstate[100];
+
+ /*
+ * runstate was 100 bytes, zero padded, but we trimmed it to add a
+ * few fields and maintain backwards compatibility.
+ */
+ uint8_t runstate[32];
+ uint8_t has_vm_was_suspended;
+ uint8_t vm_was_suspended;
+ uint8_t unused[66];
+
RunState state;
bool received;
} GlobalState;
@@ -35,6 +44,10 @@ static void global_state_do_store(RunState state)
assert(strlen(state_str) < sizeof(global_state.runstate));
strpadcpy((char *)global_state.runstate, sizeof(global_state.runstate),
state_str, '\0');
+ global_state.has_vm_was_suspended = true;
+ global_state.vm_was_suspended = vm_get_suspended();
+
+ memset(global_state.unused, 0, sizeof(global_state.unused));
}
void global_state_store(void)
@@ -59,24 +72,7 @@ RunState global_state_get_runstate(void)
static bool global_state_needed(void *opaque)
{
- GlobalState *s = opaque;
- char *runstate = (char *)s->runstate;
-
- /* If it is not optional, it is mandatory */
-
- if (migrate_get_current()->store_global_state) {
- return true;
- }
-
- /* If state is running or paused, it is not needed */
-
- if (strcmp(runstate, "running") == 0 ||
- strcmp(runstate, "paused") == 0) {
- return false;
- }
-
- /* for any other state it is needed */
- return true;
+ return migrate_get_current()->store_global_state;
}
static int global_state_post_load(void *opaque, int version_id)
@@ -93,7 +89,7 @@ static int global_state_post_load(void *opaque, int version_id)
sizeof(s->runstate)) == sizeof(s->runstate)) {
/*
* This condition should never happen during migration, because
- * all runstate names are shorter than 100 bytes (the size of
+ * all runstate names are shorter than 32 bytes (the size of
* s->runstate). However, a malicious stream could overflow
* the qapi_enum_parse() call, so we force the last character
* to a NUL byte.
@@ -110,6 +106,14 @@ static int global_state_post_load(void *opaque, int version_id)
}
s->state = r;
+ /*
+ * global_state is saved on the outgoing side before forcing a stopped
+ * state, so it may have saved state=suspended and vm_was_suspended=0.
+ * Now we are in a paused state, and when we later call vm_start, it must
+ * restore the suspended state, so we must set vm_was_suspended=1 here.
+ */
+ vm_set_suspended(s->vm_was_suspended || r == RUN_STATE_SUSPENDED);
+
return 0;
}
@@ -134,6 +138,9 @@ static const VMStateDescription vmstate_globalstate = {
.fields = (VMStateField[]) {
VMSTATE_UINT32(size, GlobalState),
VMSTATE_BUFFER(runstate, GlobalState),
+ VMSTATE_UINT8(has_vm_was_suspended, GlobalState),
+ VMSTATE_UINT8(vm_was_suspended, GlobalState),
+ VMSTATE_BUFFER(unused, GlobalState),
VMSTATE_END_OF_LIST()
},
};
--
1.8.3.1
next prev parent reply other threads:[~2024-01-03 20:07 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-03 20:05 [PATCH V9 00/12] fix migration of suspended runstate Steve Sistare
2024-01-03 20:05 ` [PATCH V9 01/12] cpus: vm_was_suspended Steve Sistare
2024-01-03 20:05 ` [PATCH V9 02/12] cpus: stop vm in suspended runstate Steve Sistare
2024-01-03 20:05 ` [PATCH V9 03/12] cpus: check running not RUN_STATE_RUNNING Steve Sistare
2024-01-03 20:05 ` [PATCH V9 04/12] cpus: vm_resume Steve Sistare
2024-01-03 20:05 ` Steve Sistare [this message]
2024-01-03 20:05 ` [PATCH V9 06/12] migration: preserve suspended runstate Steve Sistare
2024-01-03 20:05 ` [PATCH V9 07/12] migration: preserve suspended for snapshot Steve Sistare
2024-01-03 20:05 ` [PATCH V9 08/12] migration: preserve suspended for bg_migration Steve Sistare
2024-01-03 20:05 ` [PATCH V9 09/12] tests/qtest: migration events Steve Sistare
2024-01-03 20:05 ` [PATCH V9 10/12] tests/qtest: option to suspend during migration Steve Sistare
2024-01-03 20:05 ` [PATCH V9 11/12] tests/qtest: precopy migration with suspend Steve Sistare
2024-01-03 20:05 ` [PATCH V9 12/12] tests/qtest: postcopy " Steve Sistare
2024-01-04 4:37 ` [PATCH V9 00/12] fix migration of suspended runstate Peter Xu
2024-01-08 12:47 ` Markus Armbruster
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=1704312341-66640-6-git-send-email-steven.sistare@oracle.com \
--to=steven.sistare@oracle.com \
--cc=anthony.perard@citrix.com \
--cc=armbru@redhat.com \
--cc=berrange@redhat.com \
--cc=eblake@redhat.com \
--cc=farosas@suse.de \
--cc=kraxel@redhat.com \
--cc=leobras@redhat.com \
--cc=paul@xen.org \
--cc=pbonzini@redhat.com \
--cc=peterx@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=richard.henderson@linaro.org \
--cc=sstabellini@kernel.org \
--cc=stefanb@linux.vnet.ibm.com \
--cc=thuth@redhat.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 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).