Skip to contentSkip to conversation

migration/cpr: Add HMP support for cpr-transfer

PATCH Superseded Dongli Zhang 4 participants 7 messages Jun 21 – Jun 25

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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 argument 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 "unix:/tmp/cpr.sock" is for CPR URI.

(qemu) migrate_set_parameter mode cpr-transfer
(qemu) migrate tcp:0:50002 unix:/tmp/cpr.sock

---
 hmp-commands.hx                | 11 +++++++----
 migration/migration-hmp-cmds.c | 18 ++++++++++++++++++
 2 files changed, 25 insertions(+), 4 deletions(-)
hmp-commands.hx +7 -4
index 7ae2468a3d..021e51b142 100644
@@ -928,16 +928,17 @@ ERST
 
     {
         .name       = "migrate",
-        .args_type  = "detach:-d,resume:-r,uri:s",
-        .params     = "[-d] [-r] uri",
+        .args_type  = "detach:-d,resume:-r,uri:s,uri-cpr:s?",
+        .params     = "[-d] [-r] uri [uri-cpr]",
         .help       = "migrate to URI (using -d to not wait for completion)"
-		      "\n\t\t\t -r to resume a paused postcopy migration",
+		      "\n\t\t\t -r to resume a paused postcopy migration"
+		      "\n\t\t\t uri-cpr specifies CPR URI for cpr-transfer mode",
         .cmd        = hmp_migrate,
     },
 
 
 SRST
-``migrate [-d] [-r]`` *uri*
+``migrate [-d] [-r]`` *uri* [*uri-cpr*]
   Migrate the VM to *uri*.
 
   ``-d``
@@ -945,6 +946,8 @@ SRST
     query an ongoing migration process, use "info migrate".
   ``-r``
     Resume a paused postcopy migration.
+  ``uri-cpr``
+    Specify CPR URI for cpr-transfer mode. It must be a UNIX domain socket.
 ERST
 
     {
migration/migration-hmp-cmds.c +18 -0
index 8b385f560e..42ca652bb3 100644
@@ -836,9 +836,11 @@ void hmp_migrate(Monitor *mon, const QDict *qdict)
     bool detach = qdict_get_try_bool(qdict, "detach", false);
     bool resume = qdict_get_try_bool(qdict, "resume", false);
     const char *uri = qdict_get_str(qdict, "uri");
+    const char *uri_cpr = qdict_get_try_str(qdict, "uri-cpr");
     Error *err = NULL;
     g_autoptr(MigrationChannelList) caps = NULL;
     g_autoptr(MigrationChannel) channel = NULL;
+    g_autoptr(MigrationChannel) channel_cpr = NULL;
 
     if (!migrate_uri_parse(uri, &channel, &err)) {
         hmp_handle_error(mon, err);
@@ -846,6 +848,22 @@ void hmp_migrate(Monitor *mon, const QDict *qdict)
     }
     QAPI_LIST_PREPEND(caps, g_steal_pointer(&channel));
 
+    if (uri_cpr) {
+        if (migrate_mode() != MIG_MODE_CPR_TRANSFER) {
+            error_setg(&err, "uri-cpr requires cpr-transfer mode");
+            hmp_handle_error(mon, err);
+            return;
+        }
+
+        if (!migrate_uri_parse(uri_cpr, &channel_cpr, &err)) {
+            hmp_handle_error(mon, err);
+            return;
+        }
+
+        channel_cpr->channel_type = MIGRATION_CHANNEL_TYPE_CPR;
+        QAPI_LIST_PREPEND(caps, g_steal_pointer(&channel_cpr));
+    }
+
     qmp_migrate(NULL, true, caps, true, resume, &err);
     if (hmp_handle_error(mon, err)) {
         return;
Signature · 1 line
2.43.7
#1 lore raw
Quoted 10 lines · * Dongli Zhang ([email protected]) wrote:

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 argument is rejected unless the migration mode is cpr-transfer, so existing HMP migrate usage is unchanged.

Quoted 7 lines

For example, source QEMU HMP commands can be something like below. The "unix:/tmp/cpr.sock" is for CPR URI.

(qemu) migrate_set_parameter mode cpr-transfer
(qemu) migrate tcp:0:50002 unix:/tmp/cpr.sock

Yeh this looks OK to me; I don't see a check for if you do:
(qemu) migrate_set_parameter mode cpr-transfer (qemu) migrate tcp:0:50002

Does that get caught by the qmp_migrate or should you add a check here?

I do have a slight preference for using flag optional parameters rather than positional, e.g.

migrate -c unix:/tmp/cpr.sock tcp:0:50002

but I wouldn't insist on it.

Dave

Quoted 82 lines
---
 hmp-commands.hx                | 11 +++++++----
 migration/migration-hmp-cmds.c | 18 ++++++++++++++++++
 2 files changed, 25 insertions(+), 4 deletions(-)
hmp-commands.hx +7 -4
index 7ae2468a3d..021e51b142 100644
@@ -928,16 +928,17 @@ ERST
 
     {
         .name       = "migrate",
-        .args_type  = "detach:-d,resume:-r,uri:s",
-        .params     = "[-d] [-r] uri",
+        .args_type  = "detach:-d,resume:-r,uri:s,uri-cpr:s?",
+        .params     = "[-d] [-r] uri [uri-cpr]",
         .help       = "migrate to URI (using -d to not wait for completion)"
-		      "\n\t\t\t -r to resume a paused postcopy migration",
+		      "\n\t\t\t -r to resume a paused postcopy migration"
+		      "\n\t\t\t uri-cpr specifies CPR URI for cpr-transfer mode",
         .cmd        = hmp_migrate,
     },
 
 
 SRST
-``migrate [-d] [-r]`` *uri*
+``migrate [-d] [-r]`` *uri* [*uri-cpr*]
   Migrate the VM to *uri*.
 
   ``-d``
@@ -945,6 +946,8 @@ SRST
     query an ongoing migration process, use "info migrate".
   ``-r``
     Resume a paused postcopy migration.
+  ``uri-cpr``
+    Specify CPR URI for cpr-transfer mode. It must be a UNIX domain socket.
 ERST
 
     {
migration/migration-hmp-cmds.c +18 -0
index 8b385f560e..42ca652bb3 100644
@@ -836,9 +836,11 @@ void hmp_migrate(Monitor *mon, const QDict *qdict)
     bool detach = qdict_get_try_bool(qdict, "detach", false);
     bool resume = qdict_get_try_bool(qdict, "resume", false);
     const char *uri = qdict_get_str(qdict, "uri");
+    const char *uri_cpr = qdict_get_try_str(qdict, "uri-cpr");
     Error *err = NULL;
     g_autoptr(MigrationChannelList) caps = NULL;
     g_autoptr(MigrationChannel) channel = NULL;
+    g_autoptr(MigrationChannel) channel_cpr = NULL;
 
     if (!migrate_uri_parse(uri, &channel, &err)) {
         hmp_handle_error(mon, err);
@@ -846,6 +848,22 @@ void hmp_migrate(Monitor *mon, const QDict *qdict)
     }
     QAPI_LIST_PREPEND(caps, g_steal_pointer(&channel));
 
+    if (uri_cpr) {
+        if (migrate_mode() != MIG_MODE_CPR_TRANSFER) {
+            error_setg(&err, "uri-cpr requires cpr-transfer mode");
+            hmp_handle_error(mon, err);
+            return;
+        }
+
+        if (!migrate_uri_parse(uri_cpr, &channel_cpr, &err)) {
+            hmp_handle_error(mon, err);
+            return;
+        }
+
+        channel_cpr->channel_type = MIGRATION_CHANNEL_TYPE_CPR;
+        QAPI_LIST_PREPEND(caps, g_steal_pointer(&channel_cpr));
+    }
+
     qmp_migrate(NULL, true, caps, true, resume, &err);
     if (hmp_handle_error(mon, err)) {
         return;
Signature · 1 line
2.43.7
Signature · 4 lines
 -----Open up your eyes, open up your mind, open up your code -------   
/ Dr. David Alan Gilbert    |       Running GNU/Linux       | Happy  \ 
\        dave @ treblig.org |                               | In Hex /
 \ _________________________|_____ http://www.treblig.org   |_______/
#2 lore raw
Quoted 23 lines · Dr. David Alan Gilbert
Quoted 10 lines · * Dongli Zhang ([email protected]) wrote:

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 argument is rejected unless the migration mode is cpr-transfer, so existing HMP migrate usage is unchanged.

Quoted 7 lines

For example, source QEMU HMP commands can be something like below. The "unix:/tmp/cpr.sock" is for CPR URI.

(qemu) migrate_set_parameter mode cpr-transfer
(qemu) migrate tcp:0:50002 unix:/tmp/cpr.sock

Yeh this looks OK to me; I don't see a check for if you do:
(qemu) migrate_set_parameter mode cpr-transfer (qemu) migrate tcp:0:50002

Quoted 8 lines

Does that get caught by the qmp_migrate or should you add a check here?

I do have a slight preference for using flag optional parameters rather than positional, e.g.

   migrate -c unix:/tmp/cpr.sock tcp:0:50002

but I wouldn't insist on it.

I'll also vote for that.

Thanks,

Signature · 1 line
Peter Xu
#3 lore raw
In reply to Dr. David Alan Gilbert
Quoted 17 lines · Dr. David Alan Gilbert
Quoted 16 lines · * Dongli Zhang ([email protected]) wrote:

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 argument 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 "unix:/tmp/cpr.sock" is for CPR URI.

(qemu) migrate_set_parameter mode cpr-transfer
(qemu) migrate tcp:0:50002 unix:/tmp/cpr.sock

Quoted 7 lines
Quoted 1 line

Yeh this looks OK to me; I don't see a check for if you do:
(qemu) migrate_set_parameter mode cpr-transfer (qemu) migrate tcp:0:50002

Does that get caught by the qmp_migrate or should you add a check here?

I did test this before sending the patch.

With cpr-transfer mode enabled, missing the CPR channel is caught by migrate_channels_parse().

(qemu) migrate_set_parameter mode cpr-transfer
(qemu) migrate tcp:0:50002
Error: missing 'cpr' migration channel

... including when the second uri is not a UNIX domain socket, reported by cpr_transfer_output().

(qemu) migrate tcp:0:50002 tcp:0:50003
Error: bad cpr channel address; must be unix

Quoted 7 lines

I do have a slight preference for using flag optional parameters rather than positional, e.g.

   migrate -c unix:/tmp/cpr.sock tcp:0:50002

but I wouldn't insist on it.

I will follow this as Peter also voted for it.

Thank you very much!

Dongli Zhang

#4 lore raw
Quoted 37 lines · * Dongli Zhang ([email protected]) wrote:
Quoted 17 lines · Dr. David Alan Gilbert
Quoted 16 lines · * Dongli Zhang ([email protected]) wrote:

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 argument 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 "unix:/tmp/cpr.sock" is for CPR URI.

(qemu) migrate_set_parameter mode cpr-transfer
(qemu) migrate tcp:0:50002 unix:/tmp/cpr.sock

Quoted 7 lines
Quoted 1 line

Yeh this looks OK to me; I don't see a check for if you do:
(qemu) migrate_set_parameter mode cpr-transfer (qemu) migrate tcp:0:50002

Does that get caught by the qmp_migrate or should you add a check here?

I did test this before sending the patch.

With cpr-transfer mode enabled, missing the CPR channel is caught by migrate_channels_parse().

(qemu) migrate_set_parameter mode cpr-transfer
(qemu) migrate tcp:0:50002
Error: missing 'cpr' migration channel

Quoted 5 lines

... including when the second uri is not a UNIX domain socket, reported by cpr_transfer_output().

(qemu) migrate tcp:0:50002 tcp:0:50003
Error: bad cpr channel address; must be unix

OK, great.

Quoted 9 lines
Quoted 7 lines

I do have a slight preference for using flag optional parameters rather than positional, e.g.

   migrate -c unix:/tmp/cpr.sock tcp:0:50002

but I wouldn't insist on it.

I will follow this as Peter also voted for it.

Thanks - using a flag like that is much nicer, because it gets even harder if someone wanted to add a 3rd path on in the future.

Dave

Quoted 6 lines

Thank you very much!

Dongli Zhang

Signature · 4 lines
 -----Open up your eyes, open up your mind, open up your code -------   
/ Dr. David Alan Gilbert    |       Running GNU/Linux       | Happy  \ 
\        dave @ treblig.org |                               | In Hex /
 \ _________________________|_____ http://www.treblig.org   |_______/
#5 lore raw
In reply to Dongli Zhang
Quoted 74 lines · Dongli Zhang

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 argument 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 "unix:/tmp/cpr.sock" is for CPR URI.

(qemu) migrate_set_parameter mode cpr-transfer
(qemu) migrate tcp:0:50002 unix:/tmp/cpr.sock

---
 hmp-commands.hx                | 11 +++++++----
 migration/migration-hmp-cmds.c | 18 ++++++++++++++++++
 2 files changed, 25 insertions(+), 4 deletions(-)
hmp-commands.hx +7 -4
index 7ae2468a3d..021e51b142 100644
@@ -928,16 +928,17 @@ ERST
 
     {
         .name       = "migrate",
-        .args_type  = "detach:-d,resume:-r,uri:s",
-        .params     = "[-d] [-r] uri",
+        .args_type  = "detach:-d,resume:-r,uri:s,uri-cpr:s?",
+        .params     = "[-d] [-r] uri [uri-cpr]",
         .help       = "migrate to URI (using -d to not wait for completion)"
-		      "\n\t\t\t -r to resume a paused postcopy migration",
+		      "\n\t\t\t -r to resume a paused postcopy migration"
+		      "\n\t\t\t uri-cpr specifies CPR URI for cpr-transfer mode",
         .cmd        = hmp_migrate,
     },
 
 
 SRST
-``migrate [-d] [-r]`` *uri*
+``migrate [-d] [-r]`` *uri* [*uri-cpr*]
   Migrate the VM to *uri*.
 
   ``-d``
@@ -945,6 +946,8 @@ SRST
     query an ongoing migration process, use "info migrate".
   ``-r``
     Resume a paused postcopy migration.
+  ``uri-cpr``
+    Specify CPR URI for cpr-transfer mode. It must be a UNIX domain socket.
 ERST
 
     {
migration/migration-hmp-cmds.c +2 -0
index 8b385f560e..42ca652bb3 100644
@@ -836,9 +836,11 @@ void hmp_migrate(Monitor *mon, const QDict *qdict)
     bool detach = qdict_get_try_bool(qdict, "detach", false);
     bool resume = qdict_get_try_bool(qdict, "resume", false);
     const char *uri = qdict_get_str(qdict, "uri");
+    const char *uri_cpr = qdict_get_try_str(qdict, "uri-cpr");
     Error *err = NULL;
     g_autoptr(MigrationChannelList) caps = NULL;
     g_autoptr(MigrationChannel) channel = NULL;
+    g_autoptr(MigrationChannel) channel_cpr = NULL;
 
     if (!migrate_uri_parse(uri, &channel, &err)) {
         hmp_handle_error(mon, err);

migration/migration-hmp-cmds.c void hmp_migrate(Monitor *mon, const QDict *qdict) · line 853

Quoted 6 lines
migration/migration-hmp-cmds.c +3 -0
@@ -846,6 +848,22 @@ void hmp_migrate(Monitor *mon, const QDict *qdict)
     }
     QAPI_LIST_PREPEND(caps, g_steal_pointer(&channel));
 
+    if (uri_cpr) {
+        if (migrate_mode() != MIG_MODE_CPR_TRANSFER) {
+            error_setg(&err, "uri-cpr requires cpr-transfer mode");

Most users probably won't know what an uri-cpr is. Maybe: "a second uri can only be used in cpr-transfer mode".

Quoted 16 lines
migration/migration-hmp-cmds.c +13 -0
+            hmp_handle_error(mon, err);
+            return;
+        }
+
+        if (!migrate_uri_parse(uri_cpr, &channel_cpr, &err)) {
+            hmp_handle_error(mon, err);
+            return;
+        }
+
+        channel_cpr->channel_type = MIGRATION_CHANNEL_TYPE_CPR;
+        QAPI_LIST_PREPEND(caps, g_steal_pointer(&channel_cpr));
+    }
+
     qmp_migrate(NULL, true, caps, true, resume, &err);
     if (hmp_handle_error(mon, err)) {
         return;
#6 lore raw
Quoted 79 lines · Fabiano Rosas
Quoted 77 lines · Dongli Zhang

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 argument 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 "unix:/tmp/cpr.sock" is for CPR URI.

(qemu) migrate_set_parameter mode cpr-transfer
(qemu) migrate tcp:0:50002 unix:/tmp/cpr.sock

---
 hmp-commands.hx                | 11 +++++++----
 migration/migration-hmp-cmds.c | 18 ++++++++++++++++++
 2 files changed, 25 insertions(+), 4 deletions(-)
hmp-commands.hx +7 -4
index 7ae2468a3d..021e51b142 100644
@@ -928,16 +928,17 @@ ERST
 
     {
         .name       = "migrate",
-        .args_type  = "detach:-d,resume:-r,uri:s",
-        .params     = "[-d] [-r] uri",
+        .args_type  = "detach:-d,resume:-r,uri:s,uri-cpr:s?",
+        .params     = "[-d] [-r] uri [uri-cpr]",
         .help       = "migrate to URI (using -d to not wait for completion)"
-		      "\n\t\t\t -r to resume a paused postcopy migration",
+		      "\n\t\t\t -r to resume a paused postcopy migration"
+		      "\n\t\t\t uri-cpr specifies CPR URI for cpr-transfer mode",
         .cmd        = hmp_migrate,
     },
 
 
 SRST
-``migrate [-d] [-r]`` *uri*
+``migrate [-d] [-r]`` *uri* [*uri-cpr*]
   Migrate the VM to *uri*.
 
   ``-d``
@@ -945,6 +946,8 @@ SRST
     query an ongoing migration process, use "info migrate".
   ``-r``
     Resume a paused postcopy migration.
+  ``uri-cpr``
+    Specify CPR URI for cpr-transfer mode. It must be a UNIX domain socket.
 ERST
 
     {
migration/migration-hmp-cmds.c +2 -0
index 8b385f560e..42ca652bb3 100644
@@ -836,9 +836,11 @@ void hmp_migrate(Monitor *mon, const QDict *qdict)
     bool detach = qdict_get_try_bool(qdict, "detach", false);
     bool resume = qdict_get_try_bool(qdict, "resume", false);
     const char *uri = qdict_get_str(qdict, "uri");
+    const char *uri_cpr = qdict_get_try_str(qdict, "uri-cpr");
     Error *err = NULL;
     g_autoptr(MigrationChannelList) caps = NULL;
     g_autoptr(MigrationChannel) channel = NULL;
+    g_autoptr(MigrationChannel) channel_cpr = NULL;
 
     if (!migrate_uri_parse(uri, &channel, &err)) {
         hmp_handle_error(mon, err);
@@ -846,6 +848,22 @@ void hmp_migrate(Monitor *mon, const QDict *qdict)
     }
     QAPI_LIST_PREPEND(caps, g_steal_pointer(&channel));
 
Quoted 7 lines

migration/migration-hmp-cmds.c void hmp_migrate(Monitor *mon, const QDict *qdict) · line 853

Quoted 3 lines
migration/migration-hmp-cmds.c +3 -0
+    if (uri_cpr) {
+        if (migrate_mode() != MIG_MODE_CPR_TRANSFER) {
+            error_setg(&err, "uri-cpr requires cpr-transfer mode");

Most users probably won't know what an uri-cpr is. Maybe: "a second uri can only be used in cpr-transfer mode".

Will do. Thank you very much for suggestion!

Dongli Zhang