From: Peter Xu <peterx@redhat.com>
To: qemu-devel@nongnu.org
Cc: Fabiano Rosas <farosas@suse.de>,
peterx@redhat.com, Juraj Marcin <jmarcin@redhat.com>
Subject: [PULL 7/9] tests/migration-test: Merge shmem_opts into memory_backend
Date: Fri, 21 Nov 2025 19:26:53 -0500 [thread overview]
Message-ID: <20251122002656.687350-8-peterx@redhat.com> (raw)
In-Reply-To: <20251122002656.687350-1-peterx@redhat.com>
The two parameters are more or less duplicated in migrate_args(). They all
describe the memory type. When one is used, the other is not.
mem_type currently uses numa parameter to specify the memory backend, while
memory_backend (the two users of such uses "-machine memory-backend=ID").
This patch merges the use of the two variables so that we always generate a
memory object string and put it into "memory_backend" variable. Now we can
drop shmem_opts parameter in the function.
Meanwhile we always use a memory-backend-* no matter which mem type is
used. This brings mem_type to be aligned with memory_backend usage, then
we stick with this as this is flexible enough.
This paves way that we merge mem_type and memory_backend in MigrateStart.
Reviewed-by: Juraj Marcin <jmarcin@redhat.com>
Reviewed-by: Fabiano Rosas <farosas@suse.de>
Link: https://lore.kernel.org/r/20251117223908.415965-3-peterx@redhat.com
[peterx: move MEM_TYPE_ANON case upper, per juraj]
Signed-off-by: Peter Xu <peterx@redhat.com>
---
tests/qtest/migration/framework.c | 41 ++++++++++++++++++++-----------
1 file changed, 26 insertions(+), 15 deletions(-)
diff --git a/tests/qtest/migration/framework.c b/tests/qtest/migration/framework.c
index 8fa39999a1..7f325e4753 100644
--- a/tests/qtest/migration/framework.c
+++ b/tests/qtest/migration/framework.c
@@ -260,23 +260,36 @@ static char *test_shmem_path(void)
return g_strdup_printf("/dev/shm/qemu-%d", getpid());
}
+#define MIG_MEM_ID "mig.mem"
+
/* NOTE: caller is responsbile to free the string if returned */
static char *migrate_mem_type_get_opts(MemType type, const char *memory_size)
{
g_autofree char *shmem_path = NULL;
- char *backend = NULL;
+ g_autofree char *backend = NULL;
+ bool share = true;
+ char *opts;
switch (type) {
+ case MEM_TYPE_ANON:
+ backend = g_strdup("-object memory-backend-ram");
+ share = false;
+ break;
case MEM_TYPE_SHMEM:
shmem_path = test_shmem_path();
- backend = g_strdup_printf(
- "-object memory-backend-file,id=mem0,size=%s"
- ",mem-path=%s,share=on -numa node,memdev=mem0",
- memory_size, shmem_path);
- return backend;
+ backend = g_strdup_printf("-object memory-backend-file,mem-path=%s",
+ shmem_path);
+ break;
default:
- return NULL;
+ g_assert_not_reached();
+ break;
}
+
+ opts = g_strdup_printf("%s,id=%s,size=%s,share=%s",
+ backend, MIG_MEM_ID, memory_size,
+ share ? "on" : "off");
+
+ return opts;
}
int migrate_args(char **from, char **to, const char *uri, MigrateStart *args)
@@ -286,7 +299,7 @@ int migrate_args(char **from, char **to, const char *uri, MigrateStart *args)
gchar *cmd_source = NULL;
gchar *cmd_target = NULL;
const gchar *ignore_stderr;
- g_autofree char *shmem_opts = NULL;
+ g_autofree char *mem_object = NULL;
const char *kvm_opts = NULL;
const char *arch = qtest_get_arch();
const char *memory_size;
@@ -350,12 +363,12 @@ int migrate_args(char **from, char **to, const char *uri, MigrateStart *args)
ignore_stderr = "";
}
- shmem_opts = migrate_mem_type_get_opts(args->mem_type, memory_size);
-
if (args->memory_backend) {
memory_backend = g_strdup_printf(args->memory_backend, memory_size);
} else {
- memory_backend = g_strdup_printf("-m %s ", memory_size);
+ mem_object = migrate_mem_type_get_opts(args->mem_type, memory_size);
+ memory_backend = g_strdup_printf("-machine memory-backend=%s %s",
+ MIG_MEM_ID, mem_object);
}
if (args->use_dirty_ring) {
@@ -378,12 +391,11 @@ int migrate_args(char **from, char **to, const char *uri, MigrateStart *args)
"-name source,debug-threads=on "
"%s "
"-serial file:%s/src_serial "
- "%s %s %s %s",
+ "%s %s %s",
kvm_opts ? kvm_opts : "",
machine, machine_opts,
memory_backend, tmpfs,
arch_opts ? arch_opts : "",
- shmem_opts ? shmem_opts : "",
args->opts_source ? args->opts_source : "",
ignore_stderr);
@@ -400,13 +412,12 @@ int migrate_args(char **from, char **to, const char *uri, MigrateStart *args)
"%s "
"-serial file:%s/dest_serial "
"-incoming %s "
- "%s %s %s %s %s",
+ "%s %s %s %s",
kvm_opts ? kvm_opts : "",
machine, machine_opts,
memory_backend, tmpfs, uri,
events,
arch_opts ? arch_opts : "",
- shmem_opts ? shmem_opts : "",
args->opts_target ? args->opts_target : "",
ignore_stderr);
--
2.50.1
next prev parent reply other threads:[~2025-11-22 1:52 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-22 0:26 [PULL 0/9] Staging patches Peter Xu
2025-11-22 0:26 ` [PULL 1/9] migration: Fix transition to COLO state from precopy Peter Xu
2025-11-22 0:26 ` [PULL 2/9] migration: set correct list pointer when removing notifier Peter Xu
2025-11-22 0:26 ` [PULL 3/9] migration: Plug memory leaks after migrate_set_error() Peter Xu
2025-11-22 0:26 ` [PULL 4/9] migration: Use warn_reportf_err() where appropriate Peter Xu
2025-11-22 0:26 ` [PULL 5/9] migration/postcopy-ram: Improve error reporting after loadvm failure Peter Xu
2025-11-22 0:26 ` [PULL 6/9] tests/migration-test: Introduce MemType Peter Xu
2025-11-22 0:26 ` Peter Xu [this message]
2025-11-22 0:26 ` [PULL 8/9] tests/migration-test: Add MEM_TYPE_SHMEM Peter Xu
2025-11-22 0:26 ` [PULL 9/9] tests/migration-test: Use MEM_TYPE_MEMFD for memory_backend Peter Xu
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=20251122002656.687350-8-peterx@redhat.com \
--to=peterx@redhat.com \
--cc=farosas@suse.de \
--cc=jmarcin@redhat.com \
--cc=qemu-devel@nongnu.org \
/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).