Skip to contentSkip to conversation

migration: Modified 'migrate' QAPI command for migration

PATCH Superseded Het Gala 5 participants 24 messages Dec 26, 2022 – Jan 18, 2023

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Het Gala

author
#0 lore raw

cover migration: Modified 'migrate' QAPI command for migration

Current QAPI 'migrate' command design (for initiating a migration stream) contains information regarding different migrate transport mechanism (tcp / unix / exec), dest-host IP address, and binding port number in form of a string. Thus the design does seem to have some design issues. Some of the issues, stated below are:

1. Use of string URIs is a data encoding scheme within a data encoding scheme. QEMU code should directly be able to work with the results from QAPI, without resorting to do a second level of parsing (eg. socket_parse()).
2. For features / parameters related to migration, the migration tunables needs to be defined and updated upfront. For example, 'migrate-set-capability' and 'migrate-set-parameter' is required to enable multifd capability and multifd-number of channels respectively. Instead, 'Multifd-channels' can directly be represented as a single additional parameter to 'migrate' QAPI. 'migrate-set-capability' and 'migrate-set-parameter' commands could be used for runtime tunables that need setting after migration has already started.

The current patchset focuses on solving the first problem of multi-level encoding of URIs. The patch defines 'migrate' command as a QAPI discriminated union for the various transport backends (like socket, exec and rdma), and on basis of transport backends, different migration parameters are defined.

(uri) string --> (channel) Channel-type
Transport-type
Migration parameters based on transport type

-----------------------------------------------------------------------------

Author Het Gala (5):
migration: Updated QAPI format for 'migrate' qemu monitor command
migration: HMP side changes for modified 'migrate' QAPI design
migration: Avoid multiple parsing of uri in migration code flow
migration: Modified 'migrate-incoming' QAPI and HMP side changes on
the destination interface.
migration: Established connection for listener sockets on the dest
interface

 migration/migration.c | 133 +++++++++++++++++++++++++++++----------
 migration/socket.c    |  31 +--------
 migration/socket.h    |   5 +-
 monitor/hmp-cmds.c    | 101 ++++++++++++++++++++++++++++-
 qapi/migration.json   | 143 ++++++++++++++++++++++++++++++++++++++++--
 softmmu/vl.c          |   2 +-
 6 files changed, 344 insertions(+), 71 deletions(-)
Signature · 1 line
2.22.3
author
#1 lore raw

PATCH 1/5 migration: Updated QAPI format for 'migrate' qemu monitor command

From: Author Het Gala <[email protected]>

Existing 'migrate' QAPI design enforces transport mechanism, ip address of destination interface and corresponding port number in the form of a unified string 'uri' parameter. This scheme does seem to have an issue in it, i.e. double-level encoding of URIs.

The current patch maps existing QAPI design into a well-defined data structure - 'MigrateChannel' only from the design perspective. Please note that the existing 'uri' parameter is kept untouched for backward compatibility.

---
 qapi/migration.json | 121 +++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 119 insertions(+), 2 deletions(-)
qapi/migration.json +119 -2
index 88ecf86ac8..753e187ce2 100644
@@ -1449,12 +1449,108 @@
 ##
 { 'command': 'migrate-continue', 'data': {'state': 'MigrationStatus'} }
 
+##
+# @MigrateTransport:
+#
+# The supported communication transport mechanisms for migration
+#
+# @socket: Supported communication type between two devices for migration.
+#          Socket is able to cover all of 'tcp', 'unix', 'vsock' and
+#          'fd' already
+#
+# @exec: Supported communication type to redirect migration stream into file.
+#
+# @rdma: Supported communication type to redirect rdma type migration stream.
+#
+# Since 8.0
+##
+{ 'enum': 'MigrateTransport',
+  'data': ['socket', 'exec', 'rdma'] }
+
+##
+# @MigrateSocketAddr:
+#
+# To support different type of socket.
+#
+# @socket-type: Different type of socket connections.
+#
+# Since 8.0
+##
+{ 'struct': 'MigrateSocketAddr',
+  'data': {'socket-type': 'SocketAddress' } }
+
+##
+# @MigrateExecAddr:
+ #
+ # Since 8.0
+ ##
+{ 'struct': 'MigrateExecAddr',
+   'data' : {'exec-str': 'str' } }
+
+##
+# @MigrateRdmaAddr:
+#
+# Since 8.0
+##
+{ 'struct': 'MigrateRdmaAddr',
+   'data' : {'rdma-str': 'str' } }
+
+##
+# @MigrateAddress:
+#
+# The options available for communication transport mechanisms for migration
+#
+# Since 8.0
+##
+{ 'union' : 'MigrateAddress',
+  'base' : { 'transport' : 'MigrateTransport'},
+  'discriminator' : 'transport',
+  'data' : {
+    'socket' : 'MigrateSocketAddr',
+    'exec' : 'MigrateExecAddr',
+    'rdma': 'MigrateRdmaAddr' } }
+
+##
+# @MigrateChannelType:
+#
+# The supported options for migration channel type requests
+#
+# @main: Support request for main outbound migration control channel
+#
+# Since 8.0
+##
+{ 'enum': 'MigrateChannelType',
+  'data': [ 'main'] }
+
+##
+# @MigrateChannel:
+#
+# Information regarding migration Channel-type for transferring packets,
+# source and corresponding destination interface for socket connection
+# and number of multifd channels over the interface.
+#
+# @channeltype: Name of Channel type for transfering packet information
+#
+# @addr: SocketAddress of destination interface
+#
+# Since 8.0
+##
+{ 'struct': 'MigrateChannel',
+  'data' : {
+	'channeltype' : 'MigrateChannelType',
+	'addr' : 'MigrateAddress' } }
+
 ##
 # @migrate:
 #
 # Migrates the current running guest to another Virtual Machine.
 #
 # @uri: the Uniform Resource Identifier of the destination VM
+#       for migration thread
+#
+# @channel: Struct containing migration channel type, along with all
+#           the details of destination interface required for initiating
+#           a migration stream.
 #
 # @blk: do block migration (full disk copy)
 #
@@ -1479,15 +1575,36 @@
 # 3. The user Monitor's "detach" argument is invalid in QMP and should not
 #    be used
 #
+# 4. The uri argument should have the Uniform Resource Identifier of default
+#    destination VM. This connection will be bound to default network
+#
+# 5. Both 'uri' and 'channel' arguments, are mututally exclusive but, atleast
+#    one of the two arguments should be present.
+#
 # Example:
 #
 # -> { "execute": "migrate", "arguments": { "uri": "tcp:0:4446" } }
 # <- { "return": {} }
 #
+# -> { "execute": "migrate",
+#      "arguments": {
+#          "channel": { "channeltype": "main",
+#                        "addr": { "transport": "socket",
+#                                  "socket-type": { "type': "inet',
+#                                                   "host": "10.12.34.9",
+#                                                   "port": "1050" } } } } }
+# <- { "return": {} }
+#
+# -> { "execute": "migrate",
+#      "arguments": { "channel": { "channeltype": "main",
+#                                  "addr": { "transport": "exec",
+#                                            "exec-str": "/tmp/exec" } } } }
+# <- { "return": {} }
+#
 ##
 { 'command': 'migrate',
-  'data': {'uri': 'str', '*blk': 'bool', '*inc': 'bool',
-           '*detach': 'bool', '*resume': 'bool' } }
+  'data': {'*uri': 'str', '*channel': 'MigrateChannel', '*blk': 'bool',
+           '*inc': 'bool', '*detach': 'bool', '*resume': 'bool' } }
 
 ##
 # @migrate-incoming:
Signature · 1 line
2.22.3
#2 lore raw

Re: [PATCH 1/5] migration: Updated QAPI format for 'migrate' qemu monitor command

Quoted 53 lines · Het Gala

From: Author Het Gala <[email protected]>

Existing 'migrate' QAPI design enforces transport mechanism, ip address of destination interface and corresponding port number in the form of a unified string 'uri' parameter. This scheme does seem to have an issue in it, i.e. double-level encoding of URIs.

The current patch maps existing QAPI design into a well-defined data structure - 'MigrateChannel' only from the design perspective. Please note that the existing 'uri' parameter is kept untouched for backward compatibility.

---
 qapi/migration.json | 121 +++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 119 insertions(+), 2 deletions(-)
qapi/migration.json +27 -0
index 88ecf86ac8..753e187ce2 100644
@@ -1449,12 +1449,108 @@
 ##
 { 'command': 'migrate-continue', 'data': {'state': 'MigrationStatus'} }
 
+##
+# @MigrateTransport:
+#
+# The supported communication transport mechanisms for migration
+#
+# @socket: Supported communication type between two devices for migration.
+#          Socket is able to cover all of 'tcp', 'unix', 'vsock' and
+#          'fd' already
+#
+# @exec: Supported communication type to redirect migration stream into file.
+#
+# @rdma: Supported communication type to redirect rdma type migration stream.
+#
+# Since 8.0
+##
+{ 'enum': 'MigrateTransport',
+  'data': ['socket', 'exec', 'rdma'] }
+
+##
+# @MigrateSocketAddr:
+#
+# To support different type of socket.
+#
+# @socket-type: Different type of socket connections.
+#
+# Since 8.0
+##

qapi/migration.json line 1488

Quoted 10 lines
qapi/migration.json +10 -0
+{ 'struct': 'MigrateSocketAddr',
+  'data': {'socket-type': 'SocketAddress' } }
+
+##
+# @MigrateExecAddr:
+ #
+ # Since 8.0
+ ##
+{ 'struct': 'MigrateExecAddr',
+   'data' : {'exec-str': 'str' } }

Currently for 'exec:cmdstr' the 'cmdstr' part is a shell command that is passed

  const char *argv[] = { "/bin/sh", "-c", command, NULL };

I have a strong preference for making it possible to avoid use of shell when spawning commands, since much of thue time it is not required and has the potential to open up vulnerabilities. It would be nice to be able to just take the full argv directly IOW

{ 'struct': 'MigrateExecAddr',

    'data' : {'argv': ['str'] } }

If the caller wants to keep life safe and simple now they can use
["/bin/nc", "-U", "/some/sock"]

but if they still want to send it via shell, they can also do so

["/bin/sh", "-c", "...arbitrary shell script code...."]

qapi/migration.json line 1496

Quoted 8 lines
qapi/migration.json +8 -0
+
+##
+# @MigrateRdmaAddr:
+#
+# Since 8.0
+##
+{ 'struct': 'MigrateRdmaAddr',
+   'data' : {'rdma-str': 'str' } }

Loooking at the RDMA code it takes the str, and treats it as an IPv4 address:

        addr = g_new(InetSocketAddress, 1);
        if (!inet_parse(addr, host_port, NULL)) {
            rdma->port = atoi(addr->port);
            rdma->host = g_strdup(addr->host);
            rdma->host_port = g_strdup(host_port);
        } 

so we really ought to accept an InetSocketAddress struct directly

{ 'struct': 'MigrateRdmaAddr',

    'data' : {'rdma-str': 'InetSocketAddress' } }
Quoted 61 lines
qapi/migration.json +51 -0
+
+##
+# @MigrateAddress:
+#
+# The options available for communication transport mechanisms for migration
+#
+# Since 8.0
+##
+{ 'union' : 'MigrateAddress',
+  'base' : { 'transport' : 'MigrateTransport'},
+  'discriminator' : 'transport',
+  'data' : {
+    'socket' : 'MigrateSocketAddr',
+    'exec' : 'MigrateExecAddr',
+    'rdma': 'MigrateRdmaAddr' } }
+
+##
+# @MigrateChannelType:
+#
+# The supported options for migration channel type requests
+#
+# @main: Support request for main outbound migration control channel
+#
+# Since 8.0
+##
+{ 'enum': 'MigrateChannelType',
+  'data': [ 'main'] }
+
+##
+# @MigrateChannel:
+#
+# Information regarding migration Channel-type for transferring packets,
+# source and corresponding destination interface for socket connection
+# and number of multifd channels over the interface.
+#
+# @channeltype: Name of Channel type for transfering packet information
+#
+# @addr: SocketAddress of destination interface
+#
+# Since 8.0
+##
+{ 'struct': 'MigrateChannel',
+  'data' : {
+	'channeltype' : 'MigrateChannelType',
+	'addr' : 'MigrateAddress' } }
+
 ##
 # @migrate:
 #
 # Migrates the current running guest to another Virtual Machine.
 #
 # @uri: the Uniform Resource Identifier of the destination VM
+#       for migration thread
+#
+# @channel: Struct containing migration channel type, along with all
+#           the details of destination interface required for initiating
+#           a migration stream.
 #
 # @blk: do block migration (full disk copy)
 #

qapi/migration.json line 1581

Quoted 7 lines
qapi/migration.json +4 -0
@@ -1479,15 +1575,36 @@
 # 3. The user Monitor's "detach" argument is invalid in QMP and should not
 #    be used
 #
+# 4. The uri argument should have the Uniform Resource Identifier of default
+#    destination VM. This connection will be bound to default network
+#
+# 5. Both 'uri' and 'channel' arguments, are mututally exclusive but, atleast

Minor typos "mutually" "at least"

Quoted 10 lines
qapi/migration.json +5 -0
+#    one of the two arguments should be present.
+#
 # Example:
 #
 # -> { "execute": "migrate", "arguments": { "uri": "tcp:0:4446" } }
 # <- { "return": {} }
 #
+# -> { "execute": "migrate",
+#      "arguments": {
+#          "channel": { "channeltype": "main",

qapi/migration.json line 1601

Quoted 10 lines
qapi/migration.json +10 -0
+#                        "addr": { "transport": "socket",
+#                                  "socket-type": { "type': "inet',
+#                                                   "host": "10.12.34.9",
+#                                                   "port": "1050" } } } } }
+# <- { "return": {} }
+#
+# -> { "execute": "migrate",
+#      "arguments": { "channel": { "channeltype": "main",
+#                                  "addr": { "transport": "exec",
+#                                            "exec-str": "/tmp/exec" } } } }

Will need updating given my feedback above

qapi/migration.json line 1607

Quoted 8 lines
qapi/migration.json +4 -2
+# <- { "return": {} }
+#
 ##
 { 'command': 'migrate',
-  'data': {'uri': 'str', '*blk': 'bool', '*inc': 'bool',
-           '*detach': 'bool', '*resume': 'bool' } }
+  'data': {'*uri': 'str', '*channel': 'MigrateChannel', '*blk': 'bool',
+           '*inc': 'bool', '*detach': 'bool', '*resume': 'bool' } }

With regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
author
#3 lore raw

Re: [PATCH 1/5] migration: Updated QAPI format for 'migrate' qemu monitor command

Quoted 33 lines · Daniel P. Berrangé
Quoted 11 lines · Het Gala

From: Author Het Gala <[email protected]>

Existing 'migrate' QAPI design enforces transport mechanism, ip address of destination interface and corresponding port number in the form of a unified string 'uri' parameter. This scheme does seem to have an issue in it, i.e. double-level encoding of URIs.

The current patch maps existing QAPI design into a well-defined data structure - 'MigrateChannel' only from the design perspective. Please note that the existing 'uri' parameter is kept untouched for backward compatibility.

qapi/migration.json line 1488

Quoted 7 lines
qapi/migration.json +7 -0
+##
+# @MigrateExecAddr:
+ #
+ # Since 8.0
+ ##
+{ 'struct': 'MigrateExecAddr',
+   'data' : {'exec-str': 'str' } }

Currently for 'exec:cmdstr' the 'cmdstr' part is a shell command that is passed

   const char *argv[] = { "/bin/sh", "-c", command, NULL };

I have a strong preference for making it possible to avoid use of shell when spawning commands, since much of thue time it is not required and has the potential to open up vulnerabilities. It would be nice to be able to just take the full argv directly IOW

{ 'struct': 'MigrateExecAddr',

     'data' : {'argv': ['str'] } }
Quoted 8 lines

If the caller wants to keep life safe and simple now they can use

    ["/bin/nc", "-U", "/some/sock"]

but if they still want to send it via shell, they can also do so

    ["/bin/sh", "-c", "...arbitrary shell script code...."]

Okay Daniel. I get your point and it makes sense too. This will also have some code changes in exec.c file I assume.

Quoted 19 lines

qapi/migration.json line 1496

Quoted 8 lines
qapi/migration.json +8 -0
+
+##
+# @MigrateRdmaAddr:
+#
+# Since 8.0
+##
+{ 'struct': 'MigrateRdmaAddr',
+   'data' : {'rdma-str': 'str' } }

Loooking at the RDMA code it takes the str, and treats it as an IPv4 address:

         addr = g_new(InetSocketAddress, 1);
         if (!inet_parse(addr, host_port, NULL)) {
             rdma->port = atoi(addr->port);
             rdma->host = g_strdup(addr->host);
             rdma->host_port = g_strdup(host_port);
         }
Quoted 6 lines

so we really ought to accept an InetSocketAddress struct directly

{ 'struct': 'MigrateRdmaAddr',

     'data' : {'rdma-str': 'InetSocketAddress' } }

Yes, It resembles to InetSocketAddress. Will make the relevant changes in rdma.c file.

With this, I had a small question in mind, do qemu need to develop / leverage some functionality to check the correctness for host or port. So that if the user enters an invalid host address, they get an error message to enter correct address, if trying to migrate via qmp command line interface. Please correct me if I am wrong here.

Quoted 15 lines

along with all

qapi/migration.json +6 -0
+#           the details of destination interface required for initiating
+#           a migration stream.
  #
  # @blk: do block migration (full disk copy)
  #
@@ -1479,15 +1575,36 @@
  # 3. The user Monitor's "detach" argument is invalid in QMP and should not
  #    be used
  #
+# 4. The uri argument should have the Uniform Resource Identifier of default
+#    destination VM. This connection will be bound to default network
+#
+# 5. Both 'uri' and 'channel' arguments, are mututally exclusive but, atleast
 
Quoted 1 line

Minor typos "mutually" "at least"

Thanks for pointing that out Daniel. Ack.

Quoted 18 lines

# Example:
#
# -> { "execute": "migrate", "arguments": { "uri": "tcp:0:4446" } } # <- { "return": {} }
#

qapi/migration.json +13 -0
+# -> { "execute": "migrate",
+#      "arguments": {
+#          "channel": { "channeltype": "main",
+#                        "addr": { "transport": "socket",
+#                                  "socket-type": { "type': "inet',
+#                                                   "host": "10.12.34.9",
+#                                                   "port": "1050" } } } } }
+# <- { "return": {} }
+#
+# -> { "execute": "migrate",
+#      "arguments": { "channel": { "channeltype": "main",
+#                                  "addr": { "transport": "exec",
+#                                            "exec-str": "/tmp/exec" } } } }
Quoted 1 line

Will need updating given my feedback above

Yeah sure.Thanks for the feedback above.

Quoted 2 lines

With regards,
Daniel

Regards,
Het Gala

#4 lore raw

Re: [PATCH 1/5] migration: Updated QAPI format for 'migrate' qemu monitor command

Quoted 70 lines · Het Gala
Quoted 33 lines · Daniel P. Berrangé
Quoted 11 lines · Het Gala

From: Author Het Gala <[email protected]>

Existing 'migrate' QAPI design enforces transport mechanism, ip address of destination interface and corresponding port number in the form of a unified string 'uri' parameter. This scheme does seem to have an issue in it, i.e. double-level encoding of URIs.

The current patch maps existing QAPI design into a well-defined data structure - 'MigrateChannel' only from the design perspective. Please note that the existing 'uri' parameter is kept untouched for backward compatibility.

qapi/migration.json line 1488

Quoted 7 lines
qapi/migration.json +7 -0
+##
+# @MigrateExecAddr:
+ #
+ # Since 8.0
+ ##
+{ 'struct': 'MigrateExecAddr',
+   'data' : {'exec-str': 'str' } }

Currently for 'exec:cmdstr' the 'cmdstr' part is a shell command that is passed

   const char *argv[] = { "/bin/sh", "-c", command, NULL };

I have a strong preference for making it possible to avoid use of shell when spawning commands, since much of thue time it is not required and has the potential to open up vulnerabilities. It would be nice to be able to just take the full argv directly IOW

{ 'struct': 'MigrateExecAddr',

     'data' : {'argv': ['str'] } }
Quoted 8 lines

If the caller wants to keep life safe and simple now they can use

    ["/bin/nc", "-U", "/some/sock"]

but if they still want to send it via shell, they can also do so

    ["/bin/sh", "-c", "...arbitrary shell script code...."]

Okay Daniel. I get your point and it makes sense too. This will also have some code changes in exec.c file I assume.

Quoted 19 lines

qapi/migration.json line 1496

Quoted 8 lines
qapi/migration.json +8 -0
+
+##
+# @MigrateRdmaAddr:
+#
+# Since 8.0
+##
+{ 'struct': 'MigrateRdmaAddr',
+   'data' : {'rdma-str': 'str' } }

Loooking at the RDMA code it takes the str, and treats it as an IPv4 address:

         addr = g_new(InetSocketAddress, 1);
         if (!inet_parse(addr, host_port, NULL)) {
             rdma->port = atoi(addr->port);
             rdma->host = g_strdup(addr->host);
             rdma->host_port = g_strdup(host_port);
         }
Quoted 6 lines

so we really ought to accept an InetSocketAddress struct directly

{ 'struct': 'MigrateRdmaAddr',

     'data' : {'rdma-str': 'InetSocketAddress' } }
Quoted 8 lines

Yes, It resembles to InetSocketAddress. Will make the relevant changes in rdma.c file.

With this, I had a small question in mind, do qemu need to develop / leverage some functionality to check the correctness for host or port. So that if the user enters an invalid host address, they get an error message to enter correct address, if trying to migrate via qmp command line interface.

When the RDMA code uses the host address to resolve the RDMA endpoint, it will fail and report an error back.

With regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
author
#5 lore raw

Re: [PATCH 1/5] migration: Updated QAPI format for 'migrate' qemu monitor command

Quoted 28 lines · Daniel P. Berrangé
Quoted 19 lines · Het Gala
Quoted 11 lines · Daniel P. Berrangé

Loooking at the RDMA code it takes the str, and treats it as an IPv4 address:

          addr = g_new(InetSocketAddress, 1);
          if (!inet_parse(addr, host_port, NULL)) {
              rdma->port = atoi(addr->port);
              rdma->host = g_strdup(addr->host);
              rdma->host_port = g_strdup(host_port);
          }
Quoted 6 lines

so we really ought to accept an InetSocketAddress struct directly

{ 'struct': 'MigrateRdmaAddr',

      'data' : {'rdma-str': 'InetSocketAddress' } }
Quoted 8 lines

Yes, It resembles to InetSocketAddress. Will make the relevant changes in rdma.c file.

With this, I had a small question in mind, do qemu need to develop / leverage some functionality to check the correctness for host or port. So that if the user enters an invalid host address, they get an error message to enter correct address, if trying to migrate via qmp command line interface.

Quoted 6 lines

When the RDMA code uses the host address to resolve the RDMA endpoint, it will fail and report an error back.

With regards,
Daniel

Okay, understood. Thanks for the explanation Daniel

Regards,
Het Gala

author
#6 lore raw

Re: [PATCH 1/5] migration: Updated QAPI format for 'migrate' qemu monitor command

In reply to Daniel P. Berrangé
Quoted 30 lines · Daniel P. Berrangé
Quoted 11 lines · Het Gala

From: Author Het Gala <[email protected]>

Existing 'migrate' QAPI design enforces transport mechanism, ip address of destination interface and corresponding port number in the form of a unified string 'uri' parameter. This scheme does seem to have an issue in it, i.e. double-level encoding of URIs.

The current patch maps existing QAPI design into a well-defined data structure - 'MigrateChannel' only from the design perspective. Please note that the existing 'uri' parameter is kept untouched for backward compatibility.

qapi/migration.json line 1496

Quoted 7 lines
qapi/migration.json +7 -0
+##
+# @MigrateRdmaAddr:
+#
+# Since 8.0
+##
+{ 'struct': 'MigrateRdmaAddr',
+   'data' : {'rdma-str': 'str' } }

Loooking at the RDMA code it takes the str, and treats it as an IPv4 address:

         addr = g_new(InetSocketAddress, 1);
         if (!inet_parse(addr, host_port, NULL)) {
             rdma->port = atoi(addr->port);
             rdma->host = g_strdup(addr->host);
             rdma->host_port = g_strdup(host_port);
         }
Quoted 6 lines

so we really ought to accept an InetSocketAddress struct directly

{ 'struct': 'MigrateRdmaAddr',

     'data' : {'rdma-str': 'InetSocketAddress' } }

Hi Daniel. I was going through the rdma code, and I think we also need 'host_port' for rdma_return_path context https://github.com/qemu/qemu/commit/44bcfd45e9806c78d9d526d69b0590227d215a78. I dont have much understanding but If you have any suggestion or a workaround for this, please suggest :)

Quoted 12 lines

qapi/migration.json line 1504

Quoted 10 lines
qapi/migration.json +8 -0
+
+##
+# @MigrateAddress:
+#
+# The options available for communication transport mechanisms for migration
+#
+# Since 8.0
+##

With regards,
Daniel

Regards,
Het Gala

#7 lore raw

Re: [PATCH 1/5] migration: Updated QAPI format for 'migrate' qemu monitor command

Quoted 35 lines · Het Gala
Quoted 33 lines · Daniel P. Berrangé
Quoted 11 lines · Het Gala

From: Author Het Gala <[email protected]>

Existing 'migrate' QAPI design enforces transport mechanism, ip address of destination interface and corresponding port number in the form of a unified string 'uri' parameter. This scheme does seem to have an issue in it, i.e. double-level encoding of URIs.

The current patch maps existing QAPI design into a well-defined data structure - 'MigrateChannel' only from the design perspective. Please note that the existing 'uri' parameter is kept untouched for backward compatibility.

qapi/migration.json line 1496

Quoted 7 lines
qapi/migration.json +7 -0
+##
+# @MigrateRdmaAddr:
+#
+# Since 8.0
+##
+{ 'struct': 'MigrateRdmaAddr',
+   'data' : {'rdma-str': 'str' } }

Loooking at the RDMA code it takes the str, and treats it as an IPv4 address:

         addr = g_new(InetSocketAddress, 1);
         if (!inet_parse(addr, host_port, NULL)) {
             rdma->port = atoi(addr->port);
             rdma->host = g_strdup(addr->host);
             rdma->host_port = g_strdup(host_port);
         }

so we really ought to accept an InetSocketAddress struct directly

Quoted 8 lines
Quoted 3 lines

{ 'struct': 'MigrateRdmaAddr',

     'data' : {'rdma-str': 'InetSocketAddress' } }

Hi Daniel. I was going through the rdma code, and I think we also need 'host_port' for rdma_return_path context
https://github.com/qemu/qemu/commit/44bcfd45e9806c78d9d526d69b0590227d215a78.
I dont have much understanding but If you have any suggestion or a workaround for this, please suggest :)

The return path calls back into qemu_rdma_data_init() which takes host_port, but you'll already be changing that to take InetSocketAddress, so that'll be fine.

With regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#8 lore raw

Re: [PATCH 1/5] migration: Updated QAPI format for 'migrate' qemu monitor command

In reply to Daniel P. Berrangé
Quoted 108 lines · * Daniel P. Berrangé ([email protected]) wrote:
Quoted 53 lines · Het Gala

From: Author Het Gala <[email protected]>

Existing 'migrate' QAPI design enforces transport mechanism, ip address of destination interface and corresponding port number in the form of a unified string 'uri' parameter. This scheme does seem to have an issue in it, i.e. double-level encoding of URIs.

The current patch maps existing QAPI design into a well-defined data structure - 'MigrateChannel' only from the design perspective. Please note that the existing 'uri' parameter is kept untouched for backward compatibility.

---
 qapi/migration.json | 121 +++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 119 insertions(+), 2 deletions(-)
qapi/migration.json +27 -0
index 88ecf86ac8..753e187ce2 100644
@@ -1449,12 +1449,108 @@
 ##
 { 'command': 'migrate-continue', 'data': {'state': 'MigrationStatus'} }
 
+##
+# @MigrateTransport:
+#
+# The supported communication transport mechanisms for migration
+#
+# @socket: Supported communication type between two devices for migration.
+#          Socket is able to cover all of 'tcp', 'unix', 'vsock' and
+#          'fd' already
+#
+# @exec: Supported communication type to redirect migration stream into file.
+#
+# @rdma: Supported communication type to redirect rdma type migration stream.
+#
+# Since 8.0
+##
+{ 'enum': 'MigrateTransport',
+  'data': ['socket', 'exec', 'rdma'] }
+
+##
+# @MigrateSocketAddr:
+#
+# To support different type of socket.
+#
+# @socket-type: Different type of socket connections.
+#
+# Since 8.0
+##

qapi/migration.json line 1488

Quoted 10 lines
qapi/migration.json +10 -0
+{ 'struct': 'MigrateSocketAddr',
+  'data': {'socket-type': 'SocketAddress' } }
+
+##
+# @MigrateExecAddr:
+ #
+ # Since 8.0
+ ##
+{ 'struct': 'MigrateExecAddr',
+   'data' : {'exec-str': 'str' } }

Currently for 'exec:cmdstr' the 'cmdstr' part is a shell command that is passed

  const char *argv[] = { "/bin/sh", "-c", command, NULL };

I have a strong preference for making it possible to avoid use of shell when spawning commands, since much of thue time it is not required and has the potential to open up vulnerabilities. It would be nice to be able to just take the full argv directly IOW

{ 'struct': 'MigrateExecAddr',

    'data' : {'argv': ['str'] } }

If the caller wants to keep life safe and simple now they can use
["/bin/nc", "-U", "/some/sock"]

but if they still want to send it via shell, they can also do so

   ["/bin/sh", "-c", "...arbitrary shell script code...."]

qapi/migration.json line 1496

Quoted 8 lines
qapi/migration.json +8 -0
+
+##
+# @MigrateRdmaAddr:
+#
+# Since 8.0
+##
+{ 'struct': 'MigrateRdmaAddr',
+   'data' : {'rdma-str': 'str' } }

Loooking at the RDMA code it takes the str, and treats it as an IPv4 address:

        addr = g_new(InetSocketAddress, 1);
        if (!inet_parse(addr, host_port, NULL)) {
            rdma->port = atoi(addr->port);
            rdma->host = g_strdup(addr->host);
            rdma->host_port = g_strdup(host_port);
        } 
Quoted 5 lines

so we really ought to accept an InetSocketAddress struct directly

{ 'struct': 'MigrateRdmaAddr',

    'data' : {'rdma-str': 'InetSocketAddress' } }

I think that's probably the right thing to do; there is a native RDMA addressing scheme that people occasionally (once a decade or so) ask about but I don't think we've ever supported it.

Dave

Quoted 113 lines
Quoted 63 lines
qapi/migration.json +51 -0
+
+##
+# @MigrateAddress:
+#
+# The options available for communication transport mechanisms for migration
+#
+# Since 8.0
+##
+{ 'union' : 'MigrateAddress',
+  'base' : { 'transport' : 'MigrateTransport'},
+  'discriminator' : 'transport',
+  'data' : {
+    'socket' : 'MigrateSocketAddr',
+    'exec' : 'MigrateExecAddr',
+    'rdma': 'MigrateRdmaAddr' } }
+
+##
+# @MigrateChannelType:
+#
+# The supported options for migration channel type requests
+#
+# @main: Support request for main outbound migration control channel
+#
+# Since 8.0
+##
+{ 'enum': 'MigrateChannelType',
+  'data': [ 'main'] }
+
+##
+# @MigrateChannel:
+#
+# Information regarding migration Channel-type for transferring packets,
+# source and corresponding destination interface for socket connection
+# and number of multifd channels over the interface.
+#
+# @channeltype: Name of Channel type for transfering packet information
+#
+# @addr: SocketAddress of destination interface
+#
+# Since 8.0
+##
+{ 'struct': 'MigrateChannel',
+  'data' : {
+	'channeltype' : 'MigrateChannelType',
+	'addr' : 'MigrateAddress' } }
+
 ##
 # @migrate:
 #
 # Migrates the current running guest to another Virtual Machine.
 #
 # @uri: the Uniform Resource Identifier of the destination VM
+#       for migration thread
+#
+# @channel: Struct containing migration channel type, along with all
+#           the details of destination interface required for initiating
+#           a migration stream.
 #
 # @blk: do block migration (full disk copy)
 #

qapi/migration.json line 1581

Quoted 7 lines
qapi/migration.json +4 -0
@@ -1479,15 +1575,36 @@
 # 3. The user Monitor's "detach" argument is invalid in QMP and should not
 #    be used
 #
+# 4. The uri argument should have the Uniform Resource Identifier of default
+#    destination VM. This connection will be bound to default network
+#
+# 5. Both 'uri' and 'channel' arguments, are mututally exclusive but, atleast

Minor typos "mutually" "at least"

Quoted 10 lines
qapi/migration.json +5 -0
+#    one of the two arguments should be present.
+#
 # Example:
 #
 # -> { "execute": "migrate", "arguments": { "uri": "tcp:0:4446" } }
 # <- { "return": {} }
 #
+# -> { "execute": "migrate",
+#      "arguments": {
+#          "channel": { "channeltype": "main",

qapi/migration.json line 1601

Quoted 10 lines
qapi/migration.json +10 -0
+#                        "addr": { "transport": "socket",
+#                                  "socket-type": { "type': "inet',
+#                                                   "host": "10.12.34.9",
+#                                                   "port": "1050" } } } } }
+# <- { "return": {} }
+#
+# -> { "execute": "migrate",
+#      "arguments": { "channel": { "channeltype": "main",
+#                                  "addr": { "transport": "exec",
+#                                            "exec-str": "/tmp/exec" } } } }

Will need updating given my feedback above

qapi/migration.json line 1607

Quoted 8 lines
qapi/migration.json +4 -2
+# <- { "return": {} }
+#
 ##
 { 'command': 'migrate',
-  'data': {'uri': 'str', '*blk': 'bool', '*inc': 'bool',
-           '*detach': 'bool', '*resume': 'bool' } }
+  'data': {'*uri': 'str', '*channel': 'MigrateChannel', '*blk': 'bool',
+           '*inc': 'bool', '*detach': 'bool', '*resume': 'bool' } }

With regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
Signature · 1 line
Dr. David Alan Gilbert / [email protected] / Manchester, UK
author
#9 lore raw

Re: [PATCH 1/5] migration: Updated QAPI format for 'migrate' qemu monitor command

Quoted 62 lines · Dr. David Alan Gilbert
Quoted 61 lines · * Daniel P. Berrangé ([email protected]) wrote:
Quoted 7 lines · Het Gala

From: Author Het Gala <[email protected]>

Existing 'migrate' QAPI design enforces transport mechanism, ip address of destination interface and corresponding port number in the form of a unified string 'uri' parameter. This scheme does seem to have an issue in it, i.e. double-level encoding of URIs.

Quoted 8 lines

The current patch maps existing QAPI design into a well-defined data structure - 'MigrateChannel' only from the design perspective. Please note that the existing 'uri' parameter is kept untouched for backward compatibility.

Currently for 'exec:cmdstr' the 'cmdstr' part is a shell command that is passed

   const char *argv[] = { "/bin/sh", "-c", command, NULL };

I have a strong preference for making it possible to avoid use of shell when spawning commands, since much of thue time it is not required and has the potential to open up vulnerabilities. It would be nice to be able to just take the full argv directly IOW

{ 'struct': 'MigrateExecAddr',

     'data' : {'argv': ['str'] } }

If the caller wants to keep life safe and simple now they can use

    ["/bin/nc", "-U", "/some/sock"]

but if they still want to send it via shell, they can also do so

    ["/bin/sh", "-c", "...arbitrary shell script code...."]

qapi/migration.json line 1496

Quoted 8 lines
qapi/migration.json +8 -0
+
+##
+# @MigrateRdmaAddr:
+#
+# Since 8.0
+##
+{ 'struct': 'MigrateRdmaAddr',
+   'data' : {'rdma-str': 'str' } }

Loooking at the RDMA code it takes the str, and treats it as an IPv4 address:

         addr = g_new(InetSocketAddress, 1);
         if (!inet_parse(addr, host_port, NULL)) {
             rdma->port = atoi(addr->port);
             rdma->host = g_strdup(addr->host);
             rdma->host_port = g_strdup(host_port);
         }

so we really ought to accept an InetSocketAddress struct directly

Quoted 7 lines
Quoted 2 lines

{ 'struct': 'MigrateRdmaAddr',

     'data' : {'rdma-str': 'InetSocketAddress' } }

I think that's probably the right thing to do; there is a native RDMA addressing scheme that people occasionally (once a decade or so) ask about but I don't think we've ever supported it.

Dave

Yes Dave. I will be implementing Rdma in form of InetSocketAddress only in the upcoming patch.

Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
qapi/migration.json +13 -0
+
+##
+# @MigrateAddress:
+#
+# The options available for communication transport mechanisms for migration
+#
+# Since 8.0
+##
+{ 'union' : 'MigrateAddress',
+  'base' : { 'transport' : 'MigrateTransport'},
+  'discriminator' : 'transport',
+  'data' : {
+    'socket' : 'MigrateSocketAddr',
Quoted 8 lines
Quoted 8 lines

qapi/migration.json line 1512

Quoted 3 lines
qapi/migration.json +3 -0
+    'exec' : 'MigrateExecAddr',
+    'rdma': 'MigrateRdmaAddr' } }
+

With regards,
Daniel

Signature · 1 line
|: https://urldefense.proofpoint.com/v2/url?u=https-3A__berrange.com&d=DwIDAw&c=s883GpUCOChKOHiocYtGcg&r=-qwZZzrw4EKSsq0BK7MBd3wW1WEpXmJeng3ZUT5uBCg&m=p8peRp4ioaDxoipqUtW15yQdVtCPnDBQv-1wk3r3y41SXWuI5JUUPMATMyMNDI4q&s=hukETUEPKU_01AyhkaMiQFWSRE1kUv84DdpSGvVjr1Q&e=       -o-    https://urldefense.proofpoint.com/v2/url?u=https-3A__www.flickr.com_photos_dberrange&d=DwIDAw&c=s883GpUCOChKOHiocYtGcg&r=-qwZZzrw4EKSsq0BK7MBd3wW1WEpXmJeng3ZUT5uBCg&m=p8peRp4ioaDxoipqUtW15yQdVtCPnDBQv-

Regards,
Het Gala

#10 lore raw

Re: [PATCH 1/5] migration: Updated QAPI format for 'migrate' qemu monitor command

In reply to Het Gala
Quoted 108 lines · * Het Gala ([email protected]) wrote:

From: Author Het Gala <[email protected]>

Existing 'migrate' QAPI design enforces transport mechanism, ip address of destination interface and corresponding port number in the form of a unified string 'uri' parameter. This scheme does seem to have an issue in it, i.e. double-level encoding of URIs.

The current patch maps existing QAPI design into a well-defined data structure - 'MigrateChannel' only from the design perspective. Please note that the existing 'uri' parameter is kept untouched for backward compatibility.

---
 qapi/migration.json | 121 +++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 119 insertions(+), 2 deletions(-)
qapi/migration.json +81 -0
index 88ecf86ac8..753e187ce2 100644
@@ -1449,12 +1449,108 @@
 ##
 { 'command': 'migrate-continue', 'data': {'state': 'MigrationStatus'} }
 
+##
+# @MigrateTransport:
+#
+# The supported communication transport mechanisms for migration
+#
+# @socket: Supported communication type between two devices for migration.
+#          Socket is able to cover all of 'tcp', 'unix', 'vsock' and
+#          'fd' already
+#
+# @exec: Supported communication type to redirect migration stream into file.
+#
+# @rdma: Supported communication type to redirect rdma type migration stream.
+#
+# Since 8.0
+##
+{ 'enum': 'MigrateTransport',
+  'data': ['socket', 'exec', 'rdma'] }
+
+##
+# @MigrateSocketAddr:
+#
+# To support different type of socket.
+#
+# @socket-type: Different type of socket connections.
+#
+# Since 8.0
+##
+{ 'struct': 'MigrateSocketAddr',
+  'data': {'socket-type': 'SocketAddress' } }
+
+##
+# @MigrateExecAddr:
+ #
+ # Since 8.0
+ ##
+{ 'struct': 'MigrateExecAddr',
+   'data' : {'exec-str': 'str' } }
+
+##
+# @MigrateRdmaAddr:
+#
+# Since 8.0
+##
+{ 'struct': 'MigrateRdmaAddr',
+   'data' : {'rdma-str': 'str' } }
+
+##
+# @MigrateAddress:
+#
+# The options available for communication transport mechanisms for migration
+#
+# Since 8.0
+##
+{ 'union' : 'MigrateAddress',
+  'base' : { 'transport' : 'MigrateTransport'},
+  'discriminator' : 'transport',
+  'data' : {
+    'socket' : 'MigrateSocketAddr',
+    'exec' : 'MigrateExecAddr',
+    'rdma': 'MigrateRdmaAddr' } }
+
+##
+# @MigrateChannelType:
+#
+# The supported options for migration channel type requests
+#
+# @main: Support request for main outbound migration control channel
+#
+# Since 8.0
+##
+{ 'enum': 'MigrateChannelType',
+  'data': [ 'main'] }
+
+##
+# @MigrateChannel:
+#
+# Information regarding migration Channel-type for transferring packets,
+# source and corresponding destination interface for socket connection
+# and number of multifd channels over the interface.
+#
+# @channeltype: Name of Channel type for transfering packet information

qapi/migration.json line 1542

Quoted 10 lines
qapi/migration.json +10 -0
+#
+# @addr: SocketAddress of destination interface
+#
+# Since 8.0
+##
+{ 'struct': 'MigrateChannel',
+  'data' : {
+	'channeltype' : 'MigrateChannelType',
+	'addr' : 'MigrateAddress' } }
+

The presence of the channeltype field suggests you're going to try to support multiple addresses; that's OK, but can you show an example of how that might look in the migrate command below?

Dave

Quoted 56 lines
qapi/migration.json +28 -2
 ##
 # @migrate:
 #
 # Migrates the current running guest to another Virtual Machine.
 #
 # @uri: the Uniform Resource Identifier of the destination VM
+#       for migration thread
+#
+# @channel: Struct containing migration channel type, along with all
+#           the details of destination interface required for initiating
+#           a migration stream.
 #
 # @blk: do block migration (full disk copy)
 #
@@ -1479,15 +1575,36 @@
 # 3. The user Monitor's "detach" argument is invalid in QMP and should not
 #    be used
 #
+# 4. The uri argument should have the Uniform Resource Identifier of default
+#    destination VM. This connection will be bound to default network
+#
+# 5. Both 'uri' and 'channel' arguments, are mututally exclusive but, atleast
+#    one of the two arguments should be present.
+#
 # Example:
 #
 # -> { "execute": "migrate", "arguments": { "uri": "tcp:0:4446" } }
 # <- { "return": {} }
 #
+# -> { "execute": "migrate",
+#      "arguments": {
+#          "channel": { "channeltype": "main",
+#                        "addr": { "transport": "socket",
+#                                  "socket-type": { "type': "inet',
+#                                                   "host": "10.12.34.9",
+#                                                   "port": "1050" } } } } }
+# <- { "return": {} }
+#
+# -> { "execute": "migrate",
+#      "arguments": { "channel": { "channeltype": "main",
+#                                  "addr": { "transport": "exec",
+#                                            "exec-str": "/tmp/exec" } } } }
+# <- { "return": {} }
+#
 ##
 { 'command': 'migrate',
-  'data': {'uri': 'str', '*blk': 'bool', '*inc': 'bool',
-           '*detach': 'bool', '*resume': 'bool' } }
+  'data': {'*uri': 'str', '*channel': 'MigrateChannel', '*blk': 'bool',
+           '*inc': 'bool', '*detach': 'bool', '*resume': 'bool' } }
 
 ##
 # @migrate-incoming:
Signature · 1 line
2.22.3
Signature · 1 line
Dr. David Alan Gilbert / [email protected] / Manchester, UK
author
#11 lore raw

Re: [PATCH 1/5] migration: Updated QAPI format for 'migrate' qemu monitor command

Quoted 123 lines · Dr. David Alan Gilbert
Quoted 108 lines · * Het Gala ([email protected]) wrote:

From: Author Het Gala <[email protected]>

Existing 'migrate' QAPI design enforces transport mechanism, ip address of destination interface and corresponding port number in the form of a unified string 'uri' parameter. This scheme does seem to have an issue in it, i.e. double-level encoding of URIs.

The current patch maps existing QAPI design into a well-defined data structure - 'MigrateChannel' only from the design perspective. Please note that the existing 'uri' parameter is kept untouched for backward compatibility.

---
  qapi/migration.json | 121 +++++++++++++++++++++++++++++++++++++++++++-
  1 file changed, 119 insertions(+), 2 deletions(-)
qapi/migration.json +81 -0
index 88ecf86ac8..753e187ce2 100644
@@ -1449,12 +1449,108 @@
  ##
  { 'command': 'migrate-continue', 'data': {'state': 'MigrationStatus'} }
 
+##
+# @MigrateTransport:
+#
+# The supported communication transport mechanisms for migration
+#
+# @socket: Supported communication type between two devices for migration.
+#          Socket is able to cover all of 'tcp', 'unix', 'vsock' and
+#          'fd' already
+#
+# @exec: Supported communication type to redirect migration stream into file.
+#
+# @rdma: Supported communication type to redirect rdma type migration stream.
+#
+# Since 8.0
+##
+{ 'enum': 'MigrateTransport',
+  'data': ['socket', 'exec', 'rdma'] }
+
+##
+# @MigrateSocketAddr:
+#
+# To support different type of socket.
+#
+# @socket-type: Different type of socket connections.
+#
+# Since 8.0
+##
+{ 'struct': 'MigrateSocketAddr',
+  'data': {'socket-type': 'SocketAddress' } }
+
+##
+# @MigrateExecAddr:
+ #
+ # Since 8.0
+ ##
+{ 'struct': 'MigrateExecAddr',
+   'data' : {'exec-str': 'str' } }
+
+##
+# @MigrateRdmaAddr:
+#
+# Since 8.0
+##
+{ 'struct': 'MigrateRdmaAddr',
+   'data' : {'rdma-str': 'str' } }
+
+##
+# @MigrateAddress:
+#
+# The options available for communication transport mechanisms for migration
+#
+# Since 8.0
+##
+{ 'union' : 'MigrateAddress',
+  'base' : { 'transport' : 'MigrateTransport'},
+  'discriminator' : 'transport',
+  'data' : {
+    'socket' : 'MigrateSocketAddr',
+    'exec' : 'MigrateExecAddr',
+    'rdma': 'MigrateRdmaAddr' } }
+
+##
+# @MigrateChannelType:
+#
+# The supported options for migration channel type requests
+#
+# @main: Support request for main outbound migration control channel
+#
+# Since 8.0
+##
+{ 'enum': 'MigrateChannelType',
+  'data': [ 'main'] }
+
+##
+# @MigrateChannel:
+#
+# Information regarding migration Channel-type for transferring packets,
+# source and corresponding destination interface for socket connection
+# and number of multifd channels over the interface.
+#
+# @channeltype: Name of Channel type for transfering packet information

qapi/migration.json line 1542

Quoted 10 lines
qapi/migration.json +10 -0
+#
+# @addr: SocketAddress of destination interface
+#
+# Since 8.0
+##
+{ 'struct': 'MigrateChannel',
+  'data' : {
+	'channeltype' : 'MigrateChannelType',
+	'addr' : 'MigrateAddress' } }
+

The presence of the channeltype field suggests you're going to try to support multiple addresses; that's OK, but can you show an example of how that might look in the migrate command below?

Quoted 1 line

Dave

Yes Dave. Other options will be "data" (for multifd) and "post-copy" (for post-copy migration).

I am not very sure how will we represent "post-copy" part, but I will give you an example of how "main" and "data" Channels will be represented by an example below:

-> { "execute": "migrate",
       "arguments": {
            "channels": [ { 'channeltype': 'main',
                                  'addr': {'transport': 'socket',
                                             'socket-type': { 'type': 'inet',
'host': '10.12.34.9', 'port': '1050'} }
                                { 'channeltype': 'data',
                                  'addr': {'transport': 'socket',
                                             'socket-type': { 'type': 'inet',
'host': '10.12.34.92', 'port': '1234'},
                                  'multifd-count': 5 },
                                { 'channeltype': 'data',
                                  'addr': { 'transport': 'socket',
                                              'socket-type': {'type': 'inet',
'host': '0.0.0.4', 'port': '3000'},
                                  'multifd-count': 3 } ] } }
So, 'data' channels will be used for multi-fd conection while 'main' will be used for just normal migration connection. This 'data' channel option has been planned with a whole different patchset series in future.
Let me know if you have any more doubts regarding this :)

Quoted 26 lines
Quoted 26 lines
qapi/migration.json +17 -2
  #
  # -> { "execute": "migrate", "arguments": { "uri": "tcp:0:4446" } }
  # <- { "return": {} }
  #
+# -> { "execute": "migrate",
+#      "arguments": {
+#          "channel": { "channeltype": "main",
+#                        "addr": { "transport": "socket",
+#                                  "socket-type": { "type': "inet',
+#                                                   "host": "10.12.34.9",
+#                                                   "port": "1050" } } } } }
+# <- { "return": {} }
+#
+# -> { "execute": "migrate",
+#      "arguments": { "channel": { "channeltype": "main",
+#                                  "addr": { "transport": "exec",
+#                                            "exec-str": "/tmp/exec" } } } }
+# <- { "return": {} }
+#
  ##
  { 'command': 'migrate',
-  'data': {'uri': 'str', '*blk': 'bool', '*inc': 'bool',
-           '*detach': 'bool', '*resume': 'bool' } }
+  'data': {'*uri': 'str', '*channel': 'MigrateChannel', '*blk': 'bool',
+           '*inc': 'bool', '*detach': 'bool', '*resume': 'bool' } }
Quoted 2 lines
Quoted 2 lines

##
# @migrate-incoming:

Regards,
Het Gala

author
#12 lore raw

PATCH 2/5 migration: HMP side changes for modified 'migrate' QAPI design

In reply to Het Gala

From: Author Het Gala <[email protected]>

hmp_migrate() accepts uri (backward compatibility) and a well-defined struct for migration parameters, and with help of migrate_channel_from_qdict() maps QDict's 'key':'value' pair required for migration stream into MigrateChannel struct.

---
 migration/migration.c |  6 +--
 monitor/hmp-cmds.c    | 91 ++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 93 insertions(+), 4 deletions(-)
migration/migration.c +3 -3
index 52b5d39244..1b6e62612a 100644
@@ -2391,9 +2391,9 @@ static bool migrate_prepare(MigrationState *s, bool blk, bool blk_inc,
     return true;
 }
 
-void qmp_migrate(const char *uri, bool has_blk, bool blk,
-                 bool has_inc, bool inc, bool has_detach, bool detach,
-                 bool has_resume, bool resume, Error **errp)
+void qmp_migrate(const char *uri, MigrateChannel *channel, bool has_blk,
+                 bool blk, bool has_inc, bool inc, bool has_detach,
+                 bool detach, bool has_resume, bool resume, Error **errp)
 {
     Error *local_err = NULL;
     MigrationState *s = migrate_get_current();
monitor/hmp-cmds.c +90 -1

104 lines not on this page · raw message

Signature · 1 line
2.22.3
author
#13 lore raw

PATCH 3/5 migration: Avoid multiple parsing of uri in migration code flow

In reply to Het Gala

From: Author Het Gala <[email protected]>

Existing uri is encoded at multiple levels to extract the relevant migration information.

The modified QAPI design maps migration parameters into MigrateChannel struct before, thus avoiding double-level uri encoding.

socket_outgoing_migration() has been depricated as It's only purpose was uri parsing.
Renamed socket_outgoing_migration_internal() as socket_outgoing_migration(). qemu_uri_parsing() has been introduced to parse uri string (backward compatibility) and populate the MigrateChannel struct parameters. Note that the function will no longer be needed once the 'uri' parameter is depricated.

---
 migration/migration.c | 78 +++++++++++++++++++++++++++++++++++--------
 migration/socket.c    | 15 +--------
 migration/socket.h    |  3 +-
 3 files changed, 67 insertions(+), 29 deletions(-)
migration/migration.c +64 -14
index 1b6e62612a..36de9f6a6b 100644
@@ -61,6 +61,7 @@
 #include "sysemu/cpus.h"
 #include "yank_functions.h"
 #include "sysemu/qtest.h"
+#include "qemu/sockets.h"
 
 #define MAX_THROTTLE  (128 << 20)      /* Migration transfer speed throttling */
 
@@ -486,6 +487,39 @@ void migrate_add_address(SocketAddress *address)
                       QAPI_CLONE(SocketAddress, address));
 }
 
+static void qemu_uri_parsing(const char *uri,
+                             MigrateChannel **channel,
+                             Error **errp)
+{
+    Error *local_err = NULL;
+    const char *p = NULL;
+    MigrateChannel *val = g_new0(MigrateChannel, 1);
+    MigrateAddress *addrs = g_new0(MigrateAddress, 1);
+    SocketAddress *saddr = g_new0(SocketAddress, 1);
+
+    if (strstart(uri, "exec:", &p)) {
+        addrs->transport = MIGRATE_TRANSPORT_EXEC;
+        addrs->u.exec.exec_str = g_strdup(p + strlen("exec:"));
+    } else if (strstart(uri, "rdma:", NULL)) {
+        addrs->transport = MIGRATE_TRANSPORT_RDMA;
+        addrs->u.rdma.rdma_str = g_strdup(p + strlen("rdma:"));
+    } else if (strstart(uri, "tcp:", NULL) ||
+                strstart(uri, "unix:", NULL) ||
+                strstart(uri, "vsock:", NULL) ||
+                strstart(uri, "fd:", NULL)) {
+        addrs->transport = MIGRATE_TRANSPORT_SOCKET;
+        saddr = socket_parse(uri, &local_err);
+        addrs->u.socket.socket_type = saddr;
+    }
+    val->channeltype = MIGRATE_CHANNEL_TYPE_MAIN;
+    val->addr = addrs;
+    *channel = val;
+
+    if (local_err) {
+        error_propagate(errp, local_err);
+    }
+}
+
 static void qemu_start_incoming_migration(const char *uri, Error **errp)
 {
     const char *p = NULL;
@@ -2397,7 +2431,8 @@ void qmp_migrate(const char *uri, MigrateChannel *channel, bool has_blk,
 {
     Error *local_err = NULL;
     MigrationState *s = migrate_get_current();
-    const char *p = NULL;
+    MigrateAddress *addrs = g_new0(MigrateAddress, 1);
+    SocketAddress *saddr = g_new0(SocketAddress, 1);
 
     if (!migrate_prepare(s, has_blk && blk, has_inc && inc,
                          has_resume && resume, errp)) {
@@ -2411,20 +2446,35 @@ void qmp_migrate(const char *uri, MigrateChannel *channel, bool has_blk,
         }
     }
 
+    /*
+     * motive here is just to have checks and convert uri into
+     * socketaddress struct
+     */
+    if (uri && channel) {
+        error_setg(errp, "uri and channels options should be"
+                          "mutually exclusive");
+    } else if (uri) {
+        qemu_uri_parsing(uri, &channel, &local_err);
+    }
+
     migrate_protocol_allow_multi_channels(false);
-    if (strstart(uri, "tcp:", &p) ||
-        strstart(uri, "unix:", NULL) ||
-        strstart(uri, "vsock:", NULL)) {
-        migrate_protocol_allow_multi_channels(true);
-        socket_start_outgoing_migration(s, p ? p : uri, &local_err);
-#ifdef CONFIG_RDMA
-    } else if (strstart(uri, "rdma:", &p)) {
-        rdma_start_outgoing_migration(s, p, &local_err);
-#endif
-    } else if (strstart(uri, "exec:", &p)) {
-        exec_start_outgoing_migration(s, p, &local_err);
-    } else if (strstart(uri, "fd:", &p)) {
-        fd_start_outgoing_migration(s, p, &local_err);
+    addrs = channel->addr;
+    saddr = channel->addr->u.socket.socket_type;
+    if (addrs->transport == MIGRATE_TRANSPORT_SOCKET) {
+        if (saddr->type == SOCKET_ADDRESS_TYPE_INET ||
+            saddr->type == SOCKET_ADDRESS_TYPE_UNIX ||
+            saddr->type == SOCKET_ADDRESS_TYPE_VSOCK) {
+            migrate_protocol_allow_multi_channels(true);
+            socket_start_outgoing_migration(s, saddr, &local_err);
+        } else if (saddr->type == SOCKET_ADDRESS_TYPE_FD) {
+            fd_start_outgoing_migration(s, saddr->u.fd.str, &local_err);
+        }
+    #ifdef CONFIG_RDMA
+    } else if (addrs->transport == MIGRATE_TRANSPORT_RDMA) {
+        rdma_start_outgoing_migration(s, addrs->u.rdma.rdma_str, &local_err);
+    #endif
+    } else if (addrs->transport == MIGRATE_TRANSPORT_EXEC) {
+        exec_start_outgoing_migration(s, addrs->u.exec.exec_str, &local_err);
     } else {
         if (!(has_resume && resume)) {
             yank_unregister_instance(MIGRATION_YANK_INSTANCE);
migration/socket.c +1 -14
index e6fdf3c5e1..ecf98b7e6b 100644
@@ -107,8 +107,7 @@ out:
     object_unref(OBJECT(sioc));
 }
 
-static void
-socket_start_outgoing_migration_internal(MigrationState *s,
+void socket_start_outgoing_migration(MigrationState *s,
                                          SocketAddress *saddr,
                                          Error **errp)
 {
@@ -134,18 +133,6 @@ socket_start_outgoing_migration_internal(MigrationState *s,
                                      NULL);
 }
 
-void socket_start_outgoing_migration(MigrationState *s,
-                                     const char *str,
-                                     Error **errp)
-{
-    Error *err = NULL;
-    SocketAddress *saddr = socket_parse(str, &err);
-    if (!err) {
-        socket_start_outgoing_migration_internal(s, saddr, &err);
-    }
-    error_propagate(errp, err);
-}
-
 static void socket_accept_incoming_migration(QIONetListener *listener,
                                              QIOChannelSocket *cioc,
                                              gpointer opaque)
migration/socket.h +2 -1
index dc54df4e6c..95c9c166ec 100644
@@ -19,6 +19,7 @@
 
 #include "io/channel.h"
 #include "io/task.h"
+#include "io/channel-socket.h"
 
 void socket_send_channel_create(QIOTaskFunc f, void *data);
 QIOChannel *socket_send_channel_create_sync(Error **errp);
@@ -26,6 +27,6 @@ int socket_send_channel_destroy(QIOChannel *send);
 
 void socket_start_incoming_migration(const char *str, Error **errp);
 
-void socket_start_outgoing_migration(MigrationState *s, const char *str,
+void socket_start_outgoing_migration(MigrationState *s, SocketAddress *saddr,
                                      Error **errp);
 #endif
Signature · 1 line
2.22.3
#14 lore raw

Re: [PATCH 3/5] migration: Avoid multiple parsing of uri in migration code flow

Quoted 38 lines · Het Gala

From: Author Het Gala <[email protected]>

Existing uri is encoded at multiple levels to extract the relevant migration information.

The modified QAPI design maps migration parameters into MigrateChannel struct before, thus avoiding double-level uri encoding.

socket_outgoing_migration() has been depricated as It's only purpose was uri parsing.
Renamed socket_outgoing_migration_internal() as socket_outgoing_migration(). qemu_uri_parsing() has been introduced to parse uri string (backward compatibility) and populate the MigrateChannel struct parameters. Note that the function will no longer be needed once the 'uri' parameter is depricated.

---
 migration/migration.c | 78 +++++++++++++++++++++++++++++++++++--------
 migration/socket.c    | 15 +--------
 migration/socket.h    |  3 +-
 3 files changed, 67 insertions(+), 29 deletions(-)
migration/migration.c +1 -0
index 1b6e62612a..36de9f6a6b 100644
@@ -61,6 +61,7 @@
 #include "sysemu/cpus.h"
 #include "yank_functions.h"
 #include "sysemu/qtest.h"
+#include "qemu/sockets.h"
 
 #define MAX_THROTTLE  (128 << 20)      /* Migration transfer speed throttling */
 

migration/migration.c void migrate_add_address(SocketAddress *address) · line 492

Quoted 6 lines
migration/migration.c +3 -0
@@ -486,6 +487,39 @@ void migrate_add_address(SocketAddress *address)
                       QAPI_CLONE(SocketAddress, address));
 }
 
+static void qemu_uri_parsing(const char *uri,
+                             MigrateChannel **channel,
+                             Error **errp)

Coding style would prefer 'bool' instad of 'void'...

Also lets call this 'migrate_uri_parse'

Quoted 17 lines
migration/migration.c +17 -0
+{
+    Error *local_err = NULL;
+    const char *p = NULL;
+    MigrateChannel *val = g_new0(MigrateChannel, 1);
+    MigrateAddress *addrs = g_new0(MigrateAddress, 1);
+    SocketAddress *saddr = g_new0(SocketAddress, 1);
+
+    if (strstart(uri, "exec:", &p)) {
+        addrs->transport = MIGRATE_TRANSPORT_EXEC;
+        addrs->u.exec.exec_str = g_strdup(p + strlen("exec:"));
+    } else if (strstart(uri, "rdma:", NULL)) {
+        addrs->transport = MIGRATE_TRANSPORT_RDMA;
+        addrs->u.rdma.rdma_str = g_strdup(p + strlen("rdma:"));
+    } else if (strstart(uri, "tcp:", NULL) ||
+                strstart(uri, "unix:", NULL) ||
+                strstart(uri, "vsock:", NULL) ||
+                strstart(uri, "fd:", NULL)) {

migration/migration.c void migrate_add_address(SocketAddress *address) · line 519

Quoted 10 lines
migration/migration.c +10 -0
+        addrs->transport = MIGRATE_TRANSPORT_SOCKET;
+        saddr = socket_parse(uri, &local_err);
+        addrs->u.socket.socket_type = saddr;
+    }
+    val->channeltype = MIGRATE_CHANNEL_TYPE_MAIN;
+    val->addr = addrs;
+    *channel = val;
+
+    if (local_err) {
+        error_propagate(errp, local_err);
     ...   'return false';

migration/migration.c void migrate_add_address(SocketAddress *address) · line 520

Quoted 1 line
migration/migration.c +1 -0
+    }

... 'return true;'

Quoted 16 lines
migration/migration.c +4 -1
+}
+
 static void qemu_start_incoming_migration(const char *uri, Error **errp)
 {
     const char *p = NULL;
@@ -2397,7 +2431,8 @@ void qmp_migrate(const char *uri, MigrateChannel *channel, bool has_blk,
 {
     Error *local_err = NULL;
     MigrationState *s = migrate_get_current();
-    const char *p = NULL;
+    MigrateAddress *addrs = g_new0(MigrateAddress, 1);
+    SocketAddress *saddr = g_new0(SocketAddress, 1);
 
     if (!migrate_prepare(s, has_blk && blk, has_inc && inc,
                          has_resume && resume, errp)) {

migration/migration.c void qmp_migrate(const char *uri, MigrateChannel *channel, bool has_blk, · line 2455

Quoted 10 lines
migration/migration.c +7 -0
@@ -2411,20 +2446,35 @@ void qmp_migrate(const char *uri, MigrateChannel *channel, bool has_blk,
         }
     }
 
+    /*
+     * motive here is just to have checks and convert uri into
+     * socketaddress struct
+     */
+    if (uri && channel) {
+        error_setg(errp, "uri and channels options should be"
+                          "mutually exclusive");

Needs a 'return' statement after reporting the error. ALso, this check should be moved to the earlier patch that introduced the 'channel' field.

migration/migration.c void qmp_migrate(const char *uri, MigrateChannel *channel, bool has_blk, · line 2457

Quoted 2 lines
migration/migration.c +2 -0
+    } else if (uri) {
+        qemu_uri_parsing(uri, &channel, &local_err);

Needs to 'return' on error, eg

  } else if (uri && !qemu_uri_parsing(...))
      return;

migration/migration.c void qmp_migrate(const char *uri, MigrateChannel *channel, bool has_blk, · line 2459

Quoted 2 lines
migration/migration.c +2 -0
+    }
+

With regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
author
#15 lore raw

Re: [PATCH 3/5] migration: Avoid multiple parsing of uri in migration code flow

Quoted 22 lines · Daniel P. Berrangé
Quoted 21 lines · Het Gala

From: Author Het Gala <[email protected]>

Existing uri is encoded at multiple levels to extract the relevant migration information.

The modified QAPI design maps migration parameters into MigrateChannel struct before, thus avoiding double-level uri encoding.

socket_outgoing_migration() has been depricated as It's only purpose was uri parsing.
Renamed socket_outgoing_migration_internal() as socket_outgoing_migration(). qemu_uri_parsing() has been introduced to parse uri string (backward compatibility) and populate the MigrateChannel struct parameters. Note that the function will no longer be needed once the 'uri' parameter is depricated.

migration/migration.c +0 -0
@@ -486,6 +487,39 @@ void migrate_add_address(SocketAddress *address)
                        QAPI_CLONE(SocketAddress, address));
  }
 
Quoted 6 lines

migration/migration.c void migrate_add_address(SocketAddress *address) · line 492

Quoted 3 lines
migration/migration.c +3 -0
+static void qemu_uri_parsing(const char *uri,
+                             MigrateChannel **channel,
+                             Error **errp)

Coding style would prefer 'bool' instad of 'void'...

Also lets call this 'migrate_uri_parse'

Sure, Ack. Will change it in the upcoming patch.

Quoted 20 lines
Quoted 10 lines
migration/migration.c +10 -0
+    if (strstart(uri, "exec:", &p)) {
+        addrs->transport = MIGRATE_TRANSPORT_EXEC;
+        addrs->u.exec.exec_str = g_strdup(p + strlen("exec:"));
+    } else if (strstart(uri, "rdma:", NULL)) {
+        addrs->transport = MIGRATE_TRANSPORT_RDMA;
+        addrs->u.rdma.rdma_str = g_strdup(p + strlen("rdma:"));
+    } else if (strstart(uri, "tcp:", NULL) ||
+                strstart(uri, "unix:", NULL) ||
+                strstart(uri, "vsock:", NULL) ||
+                strstart(uri, "fd:", NULL)) {

migration/migration.c void migrate_add_address(SocketAddress *address) · line 519

Quoted 10 lines
migration/migration.c +10 -0
+        addrs->transport = MIGRATE_TRANSPORT_SOCKET;
+        saddr = socket_parse(uri, &local_err);
+        addrs->u.socket.socket_type = saddr;
+    }
+    val->channeltype = MIGRATE_CHANNEL_TYPE_MAIN;
+    val->addr = addrs;
+    *channel = val;
+
+    if (local_err) {
+        error_propagate(errp, local_err);
Quoted 3 lines
      ...   'return false';

Review void migrate_add_address(SocketAddress *address) · line 513

Quoted 1 line
(quoted diff) +1 -0
+    }

... 'return true;'

Ack.

Quoted 19 lines
Quoted 19 lines
migration/migration.c +4 -1
+}
+
  static void qemu_start_incoming_migration(const char *uri, Error **errp)
  {
      const char *p = NULL;
@@ -2397,7 +2431,8 @@ void qmp_migrate(const char *uri, MigrateChannel *channel, bool has_blk,
  {
      Error *local_err = NULL;
      MigrationState *s = migrate_get_current();
-    const char *p = NULL;
+    MigrateAddress *addrs = g_new0(MigrateAddress, 1);
+    SocketAddress *saddr = g_new0(SocketAddress, 1);
 
      if (!migrate_prepare(s, has_blk && blk, has_inc && inc,
                           has_resume && resume, errp)) {
@@ -2411,20 +2446,35 @@ void qmp_migrate(const char *uri, MigrateChannel *channel, bool has_blk,
          }
      }
 
Quoted 10 lines

migration/migration.c void qmp_migrate(const char *uri, MigrateChannel *channel, bool has_blk, · line 2455

Quoted 7 lines
migration/migration.c +7 -0
+    /*
+     * motive here is just to have checks and convert uri into
+     * socketaddress struct
+     */
+    if (uri && channel) {
+        error_setg(errp, "uri and channels options should be"
+                          "mutually exclusive");

Needs a 'return' statement after reporting the error. ALso, this check should be moved to the earlier patch that introduced the 'channel' field.

Okay sure. Will introduce the check in 2nd patch itself.

Quoted 6 lines

migration/migration.c void qmp_migrate(const char *uri, MigrateChannel *channel, bool has_blk, · line 2457

Quoted 2 lines
migration/migration.c +2 -0
+    } else if (uri) {
+        qemu_uri_parsing(uri, &channel, &local_err);

Needs to 'return' on error, eg

   } else if (uri && !qemu_uri_parsing(...))
       return;

Ack.

Quoted 2 lines

With regards,
Daniel

Regards,
Het Gala

author
#16 lore raw

PATCH 4/5 migration: Modified 'migrate-incoming' QAPI and HMP side changes on the destination interface.

In reply to Het Gala

From: Author Het Gala <[email protected]>

'migrate-incoming' QAPI design have been modified into a well-defined struct 'MigrateChannel'. Similarly like the source side, modified design was introduced on destination side mainly to prevent multiple-level encoding of uri string.

The struct contains various fields for type of migration channel, type of transport backends and various associated migration parameters with each backends.

Please note that the 'uri' parameter is kept for backward compatibility. HMP side changes similar to source interface , on dest interface uses migrate_channel_from_qdict() to redirect migration parameters from QDict into 'MigrateChannel' struct.

---
 migration/migration.c |  3 ++-
 monitor/hmp-cmds.c    | 10 ++++++++--
 qapi/migration.json   | 22 ++++++++++++++++++++--
 softmmu/vl.c          |  2 +-
 4 files changed, 31 insertions(+), 6 deletions(-)
migration/migration.c +2 -1
index 36de9f6a6b..838940fd55 100644
@@ -2237,7 +2237,8 @@ void migrate_del_blocker(Error *reason)
     migration_blockers = g_slist_remove(migration_blockers, reason);
 }
 
-void qmp_migrate_incoming(const char *uri, Error **errp)
+void qmp_migrate_incoming(const char *uri, MigrateChannel *channel,
+                          Error **errp)
 {
     Error *local_err = NULL;
     static bool once = true;
monitor/hmp-cmds.c +8 -2
index e44d96f5dc..7f45624c41 100644
@@ -1106,9 +1106,15 @@ void hmp_migrate_incoming(Monitor *mon, const QDict *qdict)
 {
     Error *err = NULL;
     const char *uri = qdict_get_str(qdict, "uri");
+    MigrateChannel *channel = g_new0(MigrateChannel, 1);
+    migrate_channel_from_qdict(&channel, qdict, &err);
+    if (err) {
+        error_setg(&err, "error in retrieving channel from qdict");
+        return;
+    }
 
-    qmp_migrate_incoming(uri, &err);
-
+    qmp_migrate_incoming(uri, channel, &err);
+    qapi_free_MigrateChannel(channel);
     hmp_handle_error(mon, err);
 }
 
qapi/migration.json +20 -2
index 753e187ce2..201b085715 100644
@@ -1613,7 +1613,11 @@
 # with -incoming defer
 #
 # @uri: The Uniform Resource Identifier identifying the source or
-#       address to listen on
+#       the address to listen on
+#
+# @channel: Struct containing migration channel type, along with
+#           all the details of the destination interface required
+#           for the address to listen on for migration stream.
 #
 # Returns: nothing on success
 #
@@ -1630,14 +1634,28 @@
 #
 # 3. The uri format is the same as for -incoming
 #
+# 4. The 'uri' and 'channel' arguments are mutually exclusive but, atleast
+#    one of the two arguments should be present.
+#
 # Example:
 #
 # -> { "execute": "migrate-incoming",
 #      "arguments": { "uri": "tcp::4446" } }
 # <- { "return": {} }
 #
+# -> { "execute": "migrate",
+#      "arguments": {
+#          "channels": { 'channeltype': 'main',
+#                        'addr': { 'transport': 'socket',
+#                                  'socket-type': {'type': 'inet',
+#                                  'host': '10.12.34.9',
+#                                  'port': '1050' } } } } }
+# <- { "return": {} }
+#
 ##
-{ 'command': 'migrate-incoming', 'data': {'uri': 'str' } }
+{ 'command': 'migrate-incoming',
+             'data': {'*uri': 'str',
+                      '*channel': 'MigrateChannel'} }
 
 ##
 # @xen-save-devices-state:
softmmu/vl.c +1 -1
index 798e1dc933..7005be978a 100644
@@ -2614,7 +2614,7 @@ void qmp_x_exit_preconfig(Error **errp)
     if (incoming) {
         Error *local_err = NULL;
         if (strcmp(incoming, "defer") != 0) {
-            qmp_migrate_incoming(incoming, &local_err);
+            qmp_migrate_incoming(incoming, NULL, &local_err);
             if (local_err) {
                 error_reportf_err(local_err, "-incoming %s: ", incoming);
                 exit(1);
Signature · 1 line
2.22.3
author
#17 lore raw

PATCH 5/5 migration: Established connection for listener sockets on the dest interface

In reply to Het Gala

From: Author Het Gala <[email protected]>

Modified 'migrate-incoming' QAPI supports MigrateChannel parameters to prevent multi-level encodings of uri on the destination side.

socket_start_incoming_migration() has been depricated as it's only purpose was uri parsing.
Renamed socket_outgoing_migration_internal() as socket_start_incoming_migration(). qemu_uri_parsing() is used to populate the new struct from 'uri' string needed for migration connection. The function will no longer be used once the 'uri' parameter is depricated, as the parameters will already be mapped into new struct.

---
 migration/migration.c | 48 ++++++++++++++++++++++++++++---------------
 migration/socket.c    | 16 ++-------------
 migration/socket.h    |  2 +-
 3 files changed, 35 insertions(+), 31 deletions(-)
migration/migration.c +32 -16
index 838940fd55..c70fd0ab4f 100644
@@ -520,27 +520,43 @@ static void qemu_uri_parsing(const char *uri,
     }
 }
 
-static void qemu_start_incoming_migration(const char *uri, Error **errp)
+static void qemu_start_incoming_migration(const char *uri,
+                                          MigrateChannel *channel,
+                                          Error **errp)
 {
-    const char *p = NULL;
+    MigrateAddress *addrs = g_new0(MigrateAddress, 1);
+    SocketAddress *saddr = g_new0(SocketAddress, 1);
+
+    /*
+     * motive here is just to have checks and convert uri into
+     * socketaddress struct
+     */
+    if (uri && channel) {
+        error_setg(errp, "uri and channels options should be used "
+                          "mutually exclusive");
+    } else if (uri) {
+        qemu_uri_parsing(uri, &channel, errp);
+    }
 
     migrate_protocol_allow_multi_channels(false); /* reset it anyway */
     qapi_event_send_migration(MIGRATION_STATUS_SETUP);
-    if (strstart(uri, "tcp:", &p) ||
-        strstart(uri, "unix:", NULL) ||
-        strstart(uri, "vsock:", NULL)) {
-        migrate_protocol_allow_multi_channels(true);
-        socket_start_incoming_migration(p ? p : uri, errp);
+    if (addrs->transport == MIGRATE_TRANSPORT_SOCKET) {
+        if (saddr->type == SOCKET_ADDRESS_TYPE_INET ||
+            saddr->type == SOCKET_ADDRESS_TYPE_UNIX ||
+            saddr->type == SOCKET_ADDRESS_TYPE_VSOCK) {
+            migrate_protocol_allow_multi_channels(true);
+            socket_start_incoming_migration(saddr, errp);
+        } else if (saddr->type == SOCKET_ADDRESS_TYPE_FD) {
+            fd_start_incoming_migration(saddr->u.fd.str, errp);
+        }
 #ifdef CONFIG_RDMA
-    } else if (strstart(uri, "rdma:", &p)) {
-        rdma_start_incoming_migration(p, errp);
+    } else if (addrs->transport == MIGRATE_TRANSPORT_RDMA) {
+        rdma_start_incomng_migration(addrs->u.rdma.rdma_str, errp);
 #endif
-    } else if (strstart(uri, "exec:", &p)) {
-        exec_start_incoming_migration(p, errp);
-    } else if (strstart(uri, "fd:", &p)) {
-        fd_start_incoming_migration(p, errp);
+    } else if (addrs->transport == MIGRATE_TRANSPORT_EXEC) {
+        exec_start_incoming_migration(addrs->u.exec.exec_str, errp);
     } else {
-        error_setg(errp, "unknown migration protocol: %s", uri);
+        error_setg(errp, "unknown migration protocol: %i", addrs->transport);
     }
 }
 
@@ -2256,7 +2272,7 @@ void qmp_migrate_incoming(const char *uri, MigrateChannel *channel,
         return;
     }
 
-    qemu_start_incoming_migration(uri, &local_err);
+    qemu_start_incoming_migration(uri, channel, &local_err);
 
     if (local_err) {
         yank_unregister_instance(MIGRATION_YANK_INSTANCE);
@@ -2292,7 +2308,7 @@ void qmp_migrate_recover(const char *uri, Error **errp)
      * only re-setup the migration stream and poke existing migration
      * to continue using that newly established channel.
      */
-    qemu_start_incoming_migration(uri, errp);
+    qemu_start_incoming_migration(uri, NULL, errp);
 }
 
 void qmp_migrate_pause(Error **errp)
migration/socket.c +2 -14
index ecf98b7e6b..3558821298 100644
@@ -158,9 +158,8 @@ socket_incoming_migration_end(void *opaque)
     object_unref(OBJECT(listener));
 }
 
-static void
-socket_start_incoming_migration_internal(SocketAddress *saddr,
-                                         Error **errp)
+void socket_start_incoming_migration(SocketAddress *saddr,
+                                     Error **errp)
 {
     QIONetListener *listener = qio_net_listener_new();
     MigrationIncomingState *mis = migration_incoming_get_current();
@@ -198,14 +197,3 @@ socket_start_incoming_migration_internal(SocketAddress *saddr,
         qapi_free_SocketAddress(address);
     }
 }
-
-void socket_start_incoming_migration(const char *str, Error **errp)
-{
-    Error *err = NULL;
-    SocketAddress *saddr = socket_parse(str, &err);
-    if (!err) {
-        socket_start_incoming_migration_internal(saddr, &err);
-    }
-    qapi_free_SocketAddress(saddr);
-    error_propagate(errp, err);
-}
migration/socket.h +1 -1
index 95c9c166ec..4769a2bdf9 100644
@@ -25,7 +25,7 @@ void socket_send_channel_create(QIOTaskFunc f, void *data);
 QIOChannel *socket_send_channel_create_sync(Error **errp);
 int socket_send_channel_destroy(QIOChannel *send);
 
-void socket_start_incoming_migration(const char *str, Error **errp);
+void socket_start_incoming_migration(SocketAddress *saddr, Error **errp);
 
 void socket_start_outgoing_migration(MigrationState *s, SocketAddress *saddr,
                                      Error **errp);
Signature · 1 line
2.22.3
#18 lore raw

Re: [PATCH 5/5] migration: Established connection for listener sockets on the dest interface

Quoted 62 lines · Het Gala

From: Author Het Gala <[email protected]>

Modified 'migrate-incoming' QAPI supports MigrateChannel parameters to prevent multi-level encodings of uri on the destination side.

socket_start_incoming_migration() has been depricated as it's only purpose was uri parsing.
Renamed socket_outgoing_migration_internal() as socket_start_incoming_migration(). qemu_uri_parsing() is used to populate the new struct from 'uri' string needed for migration connection. The function will no longer be used once the 'uri' parameter is depricated, as the parameters will already be mapped into new struct.

---
 migration/migration.c | 48 ++++++++++++++++++++++++++++---------------
 migration/socket.c    | 16 ++-------------
 migration/socket.h    |  2 +-
 3 files changed, 35 insertions(+), 31 deletions(-)
migration/migration.c +20 -7
index 838940fd55..c70fd0ab4f 100644
@@ -520,27 +520,43 @@ static void qemu_uri_parsing(const char *uri,
     }
 }
 
-static void qemu_start_incoming_migration(const char *uri, Error **errp)
+static void qemu_start_incoming_migration(const char *uri,
+                                          MigrateChannel *channel,
+                                          Error **errp)
 {
-    const char *p = NULL;
+    MigrateAddress *addrs = g_new0(MigrateAddress, 1);
+    SocketAddress *saddr = g_new0(SocketAddress, 1);
+
+    /*
+     * motive here is just to have checks and convert uri into
+     * socketaddress struct
+     */
+    if (uri && channel) {
+        error_setg(errp, "uri and channels options should be used "
+                          "mutually exclusive");
+    } else if (uri) {
+        qemu_uri_parsing(uri, &channel, errp);
+    }
 
     migrate_protocol_allow_multi_channels(false); /* reset it anyway */
     qapi_event_send_migration(MIGRATION_STATUS_SETUP);
-    if (strstart(uri, "tcp:", &p) ||
-        strstart(uri, "unix:", NULL) ||
-        strstart(uri, "vsock:", NULL)) {
-        migrate_protocol_allow_multi_channels(true);
-        socket_start_incoming_migration(p ? p : uri, errp);
+    if (addrs->transport == MIGRATE_TRANSPORT_SOCKET) {
+        if (saddr->type == SOCKET_ADDRESS_TYPE_INET ||
+            saddr->type == SOCKET_ADDRESS_TYPE_UNIX ||
+            saddr->type == SOCKET_ADDRESS_TYPE_VSOCK) {

migration/migration.c static void qemu_uri_parsing(const char *uri, · line 554

Quoted 10 lines
migration/migration.c +7 -2
+            migrate_protocol_allow_multi_channels(true);
+            socket_start_incoming_migration(saddr, errp);
+        } else if (saddr->type == SOCKET_ADDRESS_TYPE_FD) {
+            fd_start_incoming_migration(saddr->u.fd.str, errp);
+        }
 #ifdef CONFIG_RDMA
-    } else if (strstart(uri, "rdma:", &p)) {
-        rdma_start_incoming_migration(p, errp);
+    } else if (addrs->transport == MIGRATE_TRANSPORT_RDMA) {
+        rdma_start_incomng_migration(addrs->u.rdma.rdma_str, errp);

Fails to compile:

../migration/migration.c: In function ‘qemu_start_incoming_migration’:
../migration/migration.c:554:9: error: implicit declaration of function ‘rdma_start_incomng_migration’; did you mean ‘rdma_start_incoming_migration’? [-Werror=implicit-function-declaration]
554 | rdma_start_incomng_migration(addrs->u.rdma.rdma_str, errp);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
| rdma_start_incoming_migration
../migration/migration.c:554:9: error: nested extern declaration of ‘rdma_start_incomng_migration’ [-Werror=nested-externs]

Please fix that, and also test RDMA.

Quoted 13 lines
migration/migration.c +3 -5
 #endif
-    } else if (strstart(uri, "exec:", &p)) {
-        exec_start_incoming_migration(p, errp);
-    } else if (strstart(uri, "fd:", &p)) {
-        fd_start_incoming_migration(p, errp);
+    } else if (addrs->transport == MIGRATE_TRANSPORT_EXEC) {
+        exec_start_incoming_migration(addrs->u.exec.exec_str, errp);
     } else {
-        error_setg(errp, "unknown migration protocol: %s", uri);
+        error_setg(errp, "unknown migration protocol: %i", addrs->transport);
     }
 }
 

[...]

author
#19 lore raw
In reply to Het Gala
Quoted 18 lines · Het Gala

Current QAPI 'migrate' command design (for initiating a migration stream) contains information regarding different migrate transport mechanism (tcp / unix / exec), dest-host IP address, and binding port number in form of a string. Thus the design does seem to have some design issues. Some of the issues, stated below are:

1. Use of string URIs is a data encoding scheme within a data encoding scheme. QEMU code should directly be able to work with the results from QAPI, without resorting to do a second level of parsing (eg. socket_parse()).
2. For features / parameters related to migration, the migration tunables needs to be defined and updated upfront. For example, 'migrate-set-capability' and 'migrate-set-parameter' is required to enable multifd capability and multifd-number of channels respectively. Instead, 'Multifd-channels' can directly be represented as a single additional parameter to 'migrate' QAPI. 'migrate-set-capability' and 'migrate-set-parameter' commands could be used for runtime tunables that need setting after migration has already started.

Quoted 8 lines

The current patchset focuses on solving the first problem of multi-level encoding of URIs. The patch defines 'migrate' command as a QAPI discriminated union for the various transport backends (like socket, exec and rdma), and on basis of transport backends, different migration parameters are defined.

(uri) string --> (channel) Channel-type
Transport-type
Migration parameters based on transport type

I hope all of you had nice a lovely christmas :) and wish you all a beautiful new year!!

Just a gentle reminder for patch review.
This patchset series focuses on the idea of modifying qemu 'migration' QAPI syntax into a well defined data structure. Hoping for suggestions and active discussions on the patchset series from all the maintainers.

Regards,
Het Gala

author
#20 lore raw
Quoted 29 lines · Het Gala
Quoted 18 lines · Het Gala

Current QAPI 'migrate' command design (for initiating a migration stream) contains information regarding different migrate transport mechanism (tcp / unix / exec), dest-host IP address, and binding port number in form of a string. Thus the design does seem to have some design issues. Some of the issues, stated below are:

1. Use of string URIs is a data encoding scheme within a data encoding scheme. QEMU code should directly be able to work with the results from QAPI, without resorting to do a second level of parsing (eg. socket_parse()).
2. For features / parameters related to migration, the migration tunables needs to be defined and updated upfront. For example, 'migrate-set-capability' and 'migrate-set-parameter' is required to enable multifd capability and multifd-number of channels respectively. Instead, 'Multifd-channels' can directly be represented as a single additional parameter to 'migrate' QAPI. 'migrate-set-capability' and 'migrate-set-parameter' commands could be used for runtime tunables that need setting after migration has already started.

Quoted 8 lines

The current patchset focuses on solving the first problem of multi-level encoding of URIs. The patch defines 'migrate' command as a QAPI discriminated union for the various transport backends (like socket, exec and rdma), and on basis of transport backends, different migration parameters are defined.

(uri) string -->  (channel) Channel-type
                             Transport-type
                             Migration parameters based on transport type

Quoted 5 lines

I hope all of you had nice a lovely christmas :) and wish you all a beautiful new year!!

Just a gentle reminder for patch review.
This patchset series focuses on the idea of modifying qemu 'migration' QAPI syntax into a well defined data structure. Hoping for suggestions and active discussions on the patchset series from all the maintainers.

A gentle reminder once again :)
This patchset could prove to the base of changing wire protocol around migration QAPIs. It could help in taking other decisions regarding restructuring around live migration code base in future. Would be glad to have some feedback on the patches from the maintainers. Waiting for a positive response from the upstream community.

Regards, Het Gala

#21 lore raw
In reply to Het Gala

Hi,

Quoted 6 lines · Het Gala

Current QAPI 'migrate' command design (for initiating a migration stream) contains information regarding different migrate transport mechanism (tcp / unix / exec), dest-host IP address, and binding port number in form of a string. Thus the design does seem to have some design issues. Some of the issues, stated below are:

Quoted 11 lines

1. Use of string URIs is a data encoding scheme within a data encoding scheme. QEMU code should directly be able to work with the results from QAPI, without resorting to do a second level of parsing (eg. socket_parse()).
2. For features / parameters related to migration, the migration tunables needs to be defined and updated upfront. For example, 'migrate-set-capability' and 'migrate-set-parameter' is required to enable multifd capability and multifd-number of channels respectively. Instead, 'Multifd-channels' can directly be represented as a single additional parameter to 'migrate' QAPI. 'migrate-set-capability' and 'migrate-set-parameter' commands could be used for runtime tunables that need setting after migration has already started.

Is efficient and parallel migration to file of large VMs in scope for this design?

Thanks,

Claudio

Quoted 29 lines

The current patchset focuses on solving the first problem of multi-level encoding of URIs. The patch defines 'migrate' command as a QAPI discriminated union for the various transport backends (like socket, exec and rdma), and on basis of transport backends, different migration parameters are defined.

(uri) string --> (channel) Channel-type
Transport-type
Migration parameters based on transport type

-----------------------------------------------------------------------------

Author Het Gala (5):
migration: Updated QAPI format for 'migrate' qemu monitor command
migration: HMP side changes for modified 'migrate' QAPI design
migration: Avoid multiple parsing of uri in migration code flow
migration: Modified 'migrate-incoming' QAPI and HMP side changes on
the destination interface.
migration: Established connection for listener sockets on the dest
interface

 migration/migration.c | 133 +++++++++++++++++++++++++++++----------
 migration/socket.c    |  31 +--------
 migration/socket.h    |   5 +-
 monitor/hmp-cmds.c    | 101 ++++++++++++++++++++++++++++-
 qapi/migration.json   | 143 ++++++++++++++++++++++++++++++++++++++++--
 softmmu/vl.c          |   2 +-
 6 files changed, 344 insertions(+), 71 deletions(-)
author
#22 lore raw
Quoted 20 lines · Claudio Fontana

Hi,

Quoted 6 lines · Het Gala

Current QAPI 'migrate' command design (for initiating a migration stream) contains information regarding different migrate transport mechanism (tcp / unix / exec), dest-host IP address, and binding port number in form of a string. Thus the design does seem to have some design issues. Some of the issues, stated below are:

Quoted 11 lines

1. Use of string URIs is a data encoding scheme within a data encoding scheme. QEMU code should directly be able to work with the results from QAPI, without resorting to do a second level of parsing (eg. socket_parse()).
2. For features / parameters related to migration, the migration tunables needs to be defined and updated upfront. For example, 'migrate-set-capability' and 'migrate-set-parameter' is required to enable multifd capability and multifd-number of channels respectively. Instead, 'Multifd-channels' can directly be represented as a single additional parameter to 'migrate' QAPI. 'migrate-set-capability' and 'migrate-set-parameter' commands could be used for runtime tunables that need setting after migration has already started.

Quoted 5 lines

Is efficient and parallel migration to file of large VMs in scope for this design?

Thanks,

Claudio

This patch's design right now mainly focuses on revamping the design for 'migrate' command.

In the upcomig patchset series in future, it will try to accomodate multifd as a feature in the same QAPI command and try to build multiple interface support on top of multifd feature. Main aim is to increase network bandwidth for migration with help of multiple interface and multifd.

Regards,
Het Gala.

#23 lore raw
Quoted 31 lines · Het Gala
Quoted 20 lines · Claudio Fontana

Hi,

Quoted 6 lines · Het Gala

Current QAPI 'migrate' command design (for initiating a migration stream) contains information regarding different migrate transport mechanism (tcp / unix / exec), dest-host IP address, and binding port number in form of a string. Thus the design does seem to have some design issues. Some of the issues, stated below are:

Quoted 11 lines

1. Use of string URIs is a data encoding scheme within a data encoding scheme. QEMU code should directly be able to work with the results from QAPI, without resorting to do a second level of parsing (eg. socket_parse()).
2. For features / parameters related to migration, the migration tunables needs to be defined and updated upfront. For example, 'migrate-set-capability' and 'migrate-set-parameter' is required to enable multifd capability and multifd-number of channels respectively. Instead, 'Multifd-channels' can directly be represented as a single additional parameter to 'migrate' QAPI. 'migrate-set-capability' and 'migrate-set-parameter' commands could be used for runtime tunables that need setting after migration has already started.

Quoted 5 lines

Is efficient and parallel migration to file of large VMs in scope for this design?

Thanks,

Claudio

This patch's design right now mainly focuses on revamping the design for 'migrate' command.

Quoted 7 lines

In the upcomig patchset series in future, it will try to accomodate multifd as a feature in the same QAPI command and try to build multiple interface support on top of multifd feature. Main aim is to increase network bandwidth for migration with help of multiple interface and multifd.

Regards,
Het Gala.

Understand, hopefully we can make sure that we can have a design that allows also increasing disk bandwidth for direct migration to disk.

Currently upstream migration to fast disks of medium to large size VMs is badly bottlenecked by qemu/libvirt interfaces.

Just FYI for existing work if interested see:

https://www.mail-archive.com/[email protected]/msg230248.html (not upstreamable, but dramatically improves VM save/restore performance)

https://lists.gnu.org/archive/html/qemu-devel/2022-10/msg02870.html (attempt to address the issue in QEMU project itself via migrating to file:///).

Ciao,

C