@samitouri / QOSamiQemu / commits / 403ccbc55d

migration/cpr: Add HMP support for cpr-transfer

Currently the cpr-transfer source QEMU instance cannot be driven entirely via HMP. The source must use QMP in order to specify both the main migration channel and the CPR channel. Extend the HMP migrate command with an optional CPR channel URI. When the migration mode is cpr-transfer, HMP uses this URI to build a CPR MigrationChannel in addition to the main migration channel. The new option is rejected unless the migration mode is cpr-transfer, so existing HMP migrate usage is unchanged. For example, source QEMU HMP commands can be something like below. The "-c unix:/tmp/cpr.sock" is for CPR URI. (qemu) migrate_set_parameter mode cpr-transfer (qemu) migrate -c unix:/tmp/cpr.sock tcp:0:50002 Signed-off-by: Dongli Zhang <dongli.zhang@oracle.com> Reviewed-by: Dr. David Alan Gilbert <dave@treblig.org> Acked-by: Maciej S. Szmigiero <maciej.szmigiero@oracle.com> Link: https://lore.kernel.org/r/20260728085903.173265-1-dongli.zhang@oracle.com Signed-off-by: Peter Xu <peterx@redhat.com>

Dongli Zhang committed Jul 28, 2026 at 01:59 UTC 403ccbc55d7bfdef41998fbe26967b017663c3eb
2 files changed +26 -4
hmp-commands.hx
+8 -4
@@ -928,16 +928,17 @@ ERST
928
929 {
930 .name = "migrate",
931 - .args_type = "detach:-d,resume:-r,uri:s",
932 - .params = "[-d] [-r] uri",
931 + .args_type = "detach:-d,resume:-r,uri-cpr:-cs,uri:s",
932 + .params = "[-d] [-r] [-c uri-cpr] uri",
933 .help = "migrate to URI (using -d to not wait for completion)"
934 - "\n\t\t\t -r to resume a paused postcopy migration",
934 + "\n\t\t\t -r to resume a paused postcopy migration"
935 + "\n\t\t\t -c to specify a CPR URI for cpr-transfer mode",
936 .cmd = hmp_migrate,
937 },
938
939
940 SRST
940 -``migrate [-d] [-r]`` *uri*
941 +``migrate [-d] [-r] [-c uri-cpr]`` *uri*
942 Migrate the VM to *uri*.
943
944 ``-d``
@@ -945,6 +946,9 @@ SRST
946 query an ongoing migration process, use "info migrate".
947 ``-r``
948 Resume a paused postcopy migration.
949 + ``-c`` *uri-cpr*
950 + Specify the CPR URI for cpr-transfer mode. It must be a UNIX domain
951 + socket.
952 ERST
953
954 {
migration/migration-hmp-cmds.c
+18
@@ -837,9 +837,11 @@ void hmp_migrate(Monitor *mon, const QDict *qdict)
837 bool detach = qdict_get_try_bool(qdict, "detach", false);
838 bool resume = qdict_get_try_bool(qdict, "resume", false);
839 const char *uri = qdict_get_str(qdict, "uri");
840 + const char *uri_cpr = qdict_get_try_str(qdict, "uri-cpr");
841 Error *err = NULL;
842 g_autoptr(MigrationChannelList) caps = NULL;
843 g_autoptr(MigrationChannel) channel = NULL;
844 + g_autoptr(MigrationChannel) channel_cpr = NULL;
845
846 if (!migrate_uri_parse(uri, &channel, &err)) {
847 hmp_handle_error(mon, err);
@@ -847,6 +849,22 @@ void hmp_migrate(Monitor *mon, const QDict *qdict)
849 }
850 QAPI_LIST_PREPEND(caps, g_steal_pointer(&channel));
851
852 + if (uri_cpr) {
853 + if (migrate_mode() != MIG_MODE_CPR_TRANSFER) {
854 + error_setg(&err, "-c can only be used in cpr-transfer mode");
855 + hmp_handle_error(mon, err);
856 + return;
857 + }
858 +
859 + if (!migrate_uri_parse(uri_cpr, &channel_cpr, &err)) {
860 + hmp_handle_error(mon, err);
861 + return;
862 + }
863 +
864 + channel_cpr->channel_type = MIGRATION_CHANNEL_TYPE_CPR;
865 + QAPI_LIST_PREPEND(caps, g_steal_pointer(&channel_cpr));
866 + }
867 +
868 qmp_migrate(NULL, true, caps, true, resume, &err);
869 if (hmp_handle_error(mon, err)) {
870 return;