All of lore.kernel.org
 help / color / mirror / Atom feed
From: luzhipeng <luzhipeng@cestc.cn>
To: qemu-devel@nongnu.org
Cc: Peter Xu <peterx@redhat.com>, Fabiano Rosas <farosas@suse.de>,
	Eric Blake <eblake@redhat.com>,
	Markus Armbruster <armbru@redhat.com>,
	luzhipeng <luzhipeng@cestc.cn>
Subject: [PATCH] qmp: Add ram-block-set/get-migratable commands
Date: Wed, 11 Mar 2026 18:01:16 +0800	[thread overview]
Message-ID: <20260311100116.984-1-luzhipeng@cestc.cn> (raw)

Introduce two new QMP commands to manage RAMBlock migratable state:
1. ram-block-set-migratable: Dynamically set a RAMBlock's migratable state
2. ram-block-get-migratable: Query a RAMBlock's migratable state

Signed-off-by: luzhipeng <luzhipeng@cestc.cn>
---
 migration/ram.c     | 48 +++++++++++++++++++++++++++++++++++++++++++++
 qapi/migration.json | 39 ++++++++++++++++++++++++++++++++++++
 2 files changed, 87 insertions(+)

diff --git a/migration/ram.c b/migration/ram.c
index 979751f61b..8b4fd8226d 100644
--- a/migration/ram.c
+++ b/migration/ram.c
@@ -234,6 +234,54 @@ bool migrate_ram_is_ignored(RAMBlock *block)
                                     && qemu_ram_is_named_file(block));
 }
 
+void qmp_ram_block_set_migratable(const char *name,
+                                  bool migratable, Error **errp)
+{
+    RAMBlock *rb = qemu_ram_block_by_name(name);
+    if (!rb) {
+        error_setg(errp, "RAMBlock '%s' not found", name);
+        return;
+    }
+
+    if (migration_is_running()) {
+        error_setg(errp, "Cannot modify RAMBlock migratable state
+                   during migration");
+        return;
+    }
+
+    if (migratable) {
+        qemu_ram_set_migratable(rb);
+        info_report("RAMBlock '%s' marked as migratable", name);
+    } else {
+        qemu_ram_unset_migratable(rb);
+        info_report("RAMBlock '%s' marked as non-migratable", name);
+    }
+}
+
+/**
+ * qmp_ram_block_get_migratable:
+ * @name: Name of RAMBlock to query
+ * @errp: Error object
+ *
+ * Return: RamBlockMigratableInfo
+ */
+RamBlockMigratableInfo *qmp_ram_block_get_migratable(const char *name,
+                                                     Error **errp)
+{
+    RAMBlock *rb;
+    RamBlockMigratableInfo *info = g_new0(RamBlockMigratableInfo, 1);
+    rb = qemu_ram_block_by_name(name);
+    if (!rb) {
+        g_free(info);
+        error_setg(errp, "RAMBlock '%s' not found", name);
+        return NULL;
+    }
+    info->migratable = qemu_ram_is_migratable(rb);
+    info_report("RAMBlock '%s' migratable state: %s", name,
+                 info->migratable ? "true" : "false");
+    return info;
+}
+
 #undef RAMBLOCK_FOREACH
 
 int foreach_not_ignored_block(RAMBlockIterFunc func, void *opaque)
diff --git a/qapi/migration.json b/qapi/migration.json
index 7134d4ce47..483116db49 100644
--- a/qapi/migration.json
+++ b/qapi/migration.json
@@ -2233,3 +2233,42 @@
   'data': { 'job-id': 'str',
             'tag': 'str',
             'devices': ['str'] } }
+
+##
+# @ram-block-set-migratable:
+#
+# Set the migratable state of a specific RAMBlock.
+#
+# @name: Name of the RAMBlock to modify
+# @migratable: true to enable migration for the RAMBlock,
+# false to disable
+#
+# Since: 11.1
+##
+{ 'command': 'ram-block-set-migratable',
+  'data': { 'name': 'str', 'migratable': 'bool' } }
+
+##
+# @RamBlockMigratableInfo:
+#
+# Information about a RAMBlock's migratable state
+#
+# @migratable: true if the RAMBlock is migratable, false otherwise
+#
+# Since: 11.1
+##
+{ 'struct': 'RamBlockMigratableInfo', 'data': { 'migratable': 'bool' } }
+
+##
+# @ram-block-get-migratable:
+#
+# Get the migratable state of a specific RAMBlock.
+#
+# @name: Name of the RAMBlock to query
+#
+# Returns: RamBlockMigratableInfo containing the migratable state
+#
+# Since: 11.1
+##
+{ 'command': 'ram-block-get-migratable', 'data': { 'name': 'str' },
+                                         'returns': 'RamBlockMigratableInfo' }
-- 
2.31.1





             reply	other threads:[~2026-03-11 10:02 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-11 10:01 luzhipeng [this message]
2026-03-11 12:47 ` [PATCH] qmp: Add ram-block-set/get-migratable commands Fabiano Rosas
2026-03-11 17:42   ` 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=20260311100116.984-1-luzhipeng@cestc.cn \
    --to=luzhipeng@cestc.cn \
    --cc=armbru@redhat.com \
    --cc=eblake@redhat.com \
    --cc=farosas@suse.de \
    --cc=peterx@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 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.