Skip to contentSkip to conversation

migration mapped-ram fixes

PATCH In review Fabiano Rosas 3 participants 16 messages Mar 15, 2024 – Mar 19, 2024

lore
Share & tools
lore
#0 lore raw

v3 cover migration mapped-ram fixes

Hi,

In this v3:

patch 1 - The fd_is_socket() verification and an update to the comment

          in the code;

patch 2 - The fix for the fd-reuse bug in outgoing_args;

patch 3 - A proposal on how to fix the fd-socket vs. fd-file
issue. I'm basically moving the fd_is_socket() call earlier to be able to do the checks properly.

based-on: https://gitlab.com/peterx/qemu/-/commits/migration-stable

CI run: https://gitlab.com/farosas/qemu/-/pipelines/1214405210

Fabiano Rosas (3):
migration/multifd: Ensure we're not given a socket for file migration migration/multifd: Duplicate the fd for the outgoing_args
migration: Add fd to FileMigrationArgs

 migration/fd.c        |  20 ++++++---
 migration/file.c      |   9 ++++
 migration/migration.c | 100 ++++++++++++++++++++++++++++++++++++------
 migration/migration.h |   1 +
 qapi/migration.json   |  11 ++++-
 5 files changed, 119 insertions(+), 22 deletions(-)
Signature · 1 line
2.35.3
#1 lore raw

PATCH v3 1/3 migration/multifd: Ensure we're not given a socket for file migration

When doing migration using the fd: URI, QEMU will fetch the file descriptor passed in via the monitor at fd_start_outgoing|incoming_migration(), which means the checks at migration_channels_and_transport_compatible() happen too soon and we don't know at that point whether the FD refers to a plain file or a socket.

For this reason, we've been allowing a migration channel of type SOCKET_ADDRESS_TYPE_FD to pass the initial verifications in scenarios where the socket migration is not supported, such as with fd + multifd.

The commit decdc76772 ("migration/multifd: Add mapped-ram support to
fd: URI") was supposed to add a second check prior to starting migration to make sure a socket fd is not passed instead of a file fd, but failed to do so.

Add the missing verification and update the comment explaining this situation which is currently incorrect.

Fixes decdc76772 ("migration/multifd: Add mapped-ram support to fd: URI")
---
 migration/fd.c        | 8 ++++++++
 migration/file.c      | 7 +++++++
 migration/migration.c | 6 +++---
 3 files changed, 18 insertions(+), 3 deletions(-)
migration/fd.c +8 -0
index 39a52e5c90..c07030f715 100644
@@ -22,6 +22,7 @@
 #include "migration.h"
 #include "monitor/monitor.h"
 #include "io/channel-file.h"
+#include "io/channel-socket.h"
 #include "io/channel-util.h"
 #include "options.h"
 #include "trace.h"
@@ -95,6 +96,13 @@ void fd_start_incoming_migration(const char *fdname, Error **errp)
     }
 
     if (migrate_multifd()) {
+        if (fd_is_socket(fd)) {
+            error_setg(errp,
+                       "Multifd migration to a socket FD is not supported");
+            object_unref(ioc);
+            return;
+        }
+
         file_create_incoming_channels(ioc, errp);
     } else {
         qio_channel_set_name(ioc, "migration-fd-incoming");
migration/file.c +7 -0
index ddde0ca818..b6e8ba13f2 100644
@@ -15,6 +15,7 @@
 #include "file.h"
 #include "migration.h"
 #include "io/channel-file.h"
+#include "io/channel-socket.h"
 #include "io/channel-util.h"
 #include "options.h"
 #include "trace.h"
@@ -58,6 +59,12 @@ bool file_send_channel_create(gpointer opaque, Error **errp)
     int fd = fd_args_get_fd();
 
     if (fd && fd != -1) {
+        if (fd_is_socket(fd)) {
+            error_setg(errp,
+                       "Multifd migration to a socket FD is not supported");
+            goto out;
+        }
+
         ioc = qio_channel_file_new_dupfd(fd, errp);
     } else {
         ioc = qio_channel_file_new_path(outgoing_args.fname, flags, 0, errp);
migration/migration.c +3 -3
index 644e073b7d..f60bd371e3 100644
@@ -166,9 +166,9 @@ static bool transport_supports_seeking(MigrationAddress *addr)
     }
 
     /*
-     * At this point, the user might not yet have passed the file
-     * descriptor to QEMU, so we cannot know for sure whether it
-     * refers to a plain file or a socket. Let it through anyway.
+     * At this point QEMU has not yet fetched the fd passed in by the
+     * user, so we cannot know for sure whether it refers to a plain
+     * file or a socket. Let it through anyway and check at fd.c.
      */
     if (addr->transport == MIGRATION_ADDRESS_TYPE_SOCKET) {
         return addr->u.socket.type == SOCKET_ADDRESS_TYPE_FD;
Signature · 1 line
2.35.3
Reviewed-by on v3 1/3
#2 lore raw

Re: [PATCH v3 1/3] migration/multifd: Ensure we're not given a socket for file migration

Quoted 16 lines · Fabiano Rosas

When doing migration using the fd: URI, QEMU will fetch the file descriptor passed in via the monitor at fd_start_outgoing|incoming_migration(), which means the checks at migration_channels_and_transport_compatible() happen too soon and we don't know at that point whether the FD refers to a plain file or a socket.

For this reason, we've been allowing a migration channel of type SOCKET_ADDRESS_TYPE_FD to pass the initial verifications in scenarios where the socket migration is not supported, such as with fd + multifd.

The commit decdc76772 ("migration/multifd: Add mapped-ram support to
fd: URI") was supposed to add a second check prior to starting migration to make sure a socket fd is not passed instead of a file fd, but failed to do so.

Quoted 5 lines

Add the missing verification and update the comment explaining this situation which is currently incorrect.

Fixes decdc76772 ("migration/multifd: Add mapped-ram support to fd: URI")
Signature · 1 line
Peter Xu
#3 lore raw

PATCH v3 2/3 migration/multifd: Duplicate the fd for the outgoing_args

In reply to Fabiano Rosas

We currently store the file descriptor used during the main outgoing channel creation to use it again when creating the multifd channels.

Since this fd is used for the first iochannel, there's risk that the QIOChannel gets freed and the fd closed while outgoing_args.fd still has it available. This could lead to an fd-reuse bug.

Duplicate the outgoing_args fd to avoid this issue.

---
 migration/fd.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)
migration/fd.c +12 -3
index c07030f715..fe0d096abd 100644
@@ -49,8 +49,7 @@ void fd_start_outgoing_migration(MigrationState *s, const char *fdname, Error **
 {
     QIOChannel *ioc;
     int fd = monitor_get_fd(monitor_cur(), fdname, errp);
-
-    outgoing_args.fd = -1;
+    int newfd;
 
     if (fd == -1) {
         return;
@@ -63,7 +62,17 @@ void fd_start_outgoing_migration(MigrationState *s, const char *fdname, Error **
         return;
     }
 
-    outgoing_args.fd = fd;
+    /*
+     * This is dup()ed just to avoid referencing an fd that might
+     * be already closed by the iochannel.
+     */
+    newfd = dup(fd);
+    if (newfd == -1) {
+        error_setg_errno(errp, errno, "Could not dup FD %d", fd);
+        object_unref(ioc);
+        return;
+    }
+    outgoing_args.fd = newfd;
 
     qio_channel_set_name(ioc, "migration-fd-outgoing");
     migration_channel_connect(s, ioc, NULL, NULL);
Signature · 1 line
2.35.3
Reviewed-by on v3 2/3
#4 lore raw

Re: [PATCH v3 2/3] migration/multifd: Duplicate the fd for the outgoing_args

Quoted 4 lines · Fabiano Rosas

We currently store the file descriptor used during the main outgoing channel creation to use it again when creating the multifd channels.

Quoted 8 lines

Since this fd is used for the first iochannel, there's risk that the QIOChannel gets freed and the fd closed while outgoing_args.fd still has it available. This could lead to an fd-reuse bug.

Duplicate the outgoing_args fd to avoid this issue.

Signature · 1 line
Peter Xu
#5 lore raw

RFC PATCH v3 3/3 migration: Add fd to FileMigrationArgs

In reply to Fabiano Rosas

The fd: URI has supported migration to a file or socket since before QEMU 8.2. In 8.2 we added the file: URI that supported migration to a file. So now we have two ways (three if you count exec:>cat) to migrate to a file. Fine.

However,

In 8.2 we also added the new qmp_migrate API that uses a JSON channel list instead of the URI. It added two migration transports SOCKET and FILE. It was decided that the new API would classify the fd migration as a type of socket migration, neglecting the fact that the fd.c code also supported file migrations.

In 9.0 we're adding support for fd + multifd + mapped-ram, which is tied to the file migration. This was implemented in fd.c, which is only reachable when the SOCKET address type is used.

The result of this is that we're asking users of the new API to create (1)
something called a "socket" to perform migration to a plain file. And creating something called a "file" provides no way of passing in a file descriptor. This is confusing.

The new API also parses the old-style URI into the new-style data structures, so the old and correct fd:<filefd> now also considers fd:
to be socket-related only.

Unlike the other migration addresses, the fd comes already setup from the user, it's not just a string that QEMU will use to start a connection. We need to actually fetch the fd from the monitor before even being able to poke at it to know if it is a socket.

Aside from the issue (1) above, the current approach of parsing the fd into a SOCKET and only later deciding if it is file-backed doesn't work well now that we're adding multifd support for fd: and file:
migration via the mapped-ram feature. With a larger number of combinations, we need to be able to know upfront when an fd is backed by a plain file vs. a socket.

We're currently using a trick of allowing socket channels to pass some (2)
validation that they shouldn't, to only later verify if the fd was indeed a socket.

To clean this up I'm proposing we start requiring users of the new API to use the "file" structure when the migration stream will end up in a file and use the "socket" structure when the fd points to an actual socket. This improves (1).

To keep backward compatibility, I'm still accepting everything that was accepted before and only changing the structures internally to allow the rest of the code to rely on the MIGRATION_ADDRESS_TYPE. This addresses (2).

We can then slowly deprecate the wrong way, i.e. using type socket for fd + file migration.

In this patch you'll find:

- a new function migrate_resolve_fd() that fetches the fd from the monitor and converts the MigrationAddress into the correct type;

- the removal of the hacks for (2);

- a helper function to convert the resolved fd that's represented as a string for storage in the MigrationAddress back into an integer for consumption.

---
 migration/fd.c        |  15 +------
 migration/file.c      |  14 +++---
 migration/migration.c | 100 ++++++++++++++++++++++++++++++++++++------
 migration/migration.h |   1 +
 qapi/migration.json   |  11 ++++-
 5 files changed, 107 insertions(+), 34 deletions(-)
migration/fd.c +2 -13
index fe0d096abd..2d4414c7ea 100644
@@ -20,9 +20,6 @@
 #include "fd.h"
 #include "file.h"
 #include "migration.h"
-#include "monitor/monitor.h"
-#include "io/channel-file.h"
-#include "io/channel-socket.h"
 #include "io/channel-util.h"
 #include "options.h"
 #include "trace.h"
@@ -48,8 +45,7 @@ void fd_cleanup_outgoing_migration(void)
 void fd_start_outgoing_migration(MigrationState *s, const char *fdname, Error **errp)
 {
     QIOChannel *ioc;
-    int fd = monitor_get_fd(monitor_cur(), fdname, errp);
-    int newfd;
+    int newfd, fd = migrate_fd_str_to_int(fdname, errp);
 
     if (fd == -1) {
         return;
@@ -91,7 +87,7 @@ static gboolean fd_accept_incoming_migration(QIOChannel *ioc,
 void fd_start_incoming_migration(const char *fdname, Error **errp)
 {
     QIOChannel *ioc;
-    int fd = monitor_fd_param(monitor_cur(), fdname, errp);
+    int fd = migrate_fd_str_to_int(fdname, errp);
     if (fd == -1) {
         return;
     }
@@ -105,13 +101,6 @@ void fd_start_incoming_migration(const char *fdname, Error **errp)
     }
 
     if (migrate_multifd()) {
-        if (fd_is_socket(fd)) {
-            error_setg(errp,
-                       "Multifd migration to a socket FD is not supported");
-            object_unref(ioc);
-            return;
-        }
-
         file_create_incoming_channels(ioc, errp);
     } else {
         qio_channel_set_name(ioc, "migration-fd-incoming");
migration/file.c +8 -6
index b6e8ba13f2..b29521ffa7 100644
@@ -59,12 +59,6 @@ bool file_send_channel_create(gpointer opaque, Error **errp)
     int fd = fd_args_get_fd();
 
     if (fd && fd != -1) {
-        if (fd_is_socket(fd)) {
-            error_setg(errp,
-                       "Multifd migration to a socket FD is not supported");
-            goto out;
-        }
-
         ioc = qio_channel_file_new_dupfd(fd, errp);
     } else {
         ioc = qio_channel_file_new_path(outgoing_args.fname, flags, 0, errp);
@@ -95,6 +89,10 @@ void file_start_outgoing_migration(MigrationState *s,
     uint64_t offset = file_args->offset;
     QIOChannel *ioc;
 
+    if (file_args->fd) {
+        return fd_start_outgoing_migration(s, file_args->fd, errp);
+    }
+
     trace_migration_file_outgoing(filename);
 
     fioc = qio_channel_file_new_path(filename, O_CREAT | O_WRONLY | O_TRUNC,
@@ -163,6 +161,10 @@ void file_start_incoming_migration(FileMigrationArgs *file_args, Error **errp)
     QIOChannelFile *fioc = NULL;
     uint64_t offset = file_args->offset;
 
+    if (file_args->fd) {
+        return fd_start_incoming_migration(file_args->fd, errp);
+    }
+
     trace_migration_file_incoming(filename);
 
     fioc = qio_channel_file_new_path(filename, O_RDONLY, 0, errp);
migration/migration.c +87 -13

130 lines not on this page · raw message

migration/migration.h +1 -0
index 8045e39c26..e265d1732c 100644
@@ -543,5 +543,6 @@ int migration_rp_wait(MigrationState *s);
  * to remember the target is always the migration thread.
  */
 void migration_rp_kick(MigrationState *s);
+int migrate_fd_str_to_int(const char *fdname, Error **errp);
 
 #endif
qapi/migration.json +9 -2
index aa1b39bce1..37f4b9c6fb 100644
@@ -1656,13 +1656,20 @@
 #
 # @filename: The file to receive the migration stream
 #
+# @fd: A file descriptor name or number.  File descriptors must be
+#     first added with the 'getfd' command. (since 9.0).
+#
 # @offset: The file offset where the migration stream will start
 #
+# Since 9.0, all members are optional, but at least one of @filename
+# or @fd are required.
+#
 # Since: 8.2
 ##
 { 'struct': 'FileMigrationArgs',
-  'data': { 'filename': 'str',
-            'offset': 'uint64' } }
+  'data': { '*filename': 'str',
+            '*fd': 'str',
+            '*offset': 'uint64' } }
 
 ##
 # @MigrationExecCommand:
Signature · 1 line
2.35.3
#6 lore raw

Re: [RFC PATCH v3 3/3] migration: Add fd to FileMigrationArgs

Quoted 13 lines · Fabiano Rosas

The fd: URI has supported migration to a file or socket since before QEMU 8.2. In 8.2 we added the file: URI that supported migration to a file. So now we have two ways (three if you count exec:>cat) to migrate to a file. Fine.

However,

In 8.2 we also added the new qmp_migrate API that uses a JSON channel list instead of the URI. It added two migration transports SOCKET and FILE. It was decided that the new API would classify the fd migration as a type of socket migration, neglecting the fact that the fd.c code also supported file migrations.

Quoted 8 lines

In 9.0 we're adding support for fd + multifd + mapped-ram, which is tied to the file migration. This was implemented in fd.c, which is only reachable when the SOCKET address type is used.

The result of this is that we're asking users of the new API to create (1)
something called a "socket" to perform migration to a plain file. And creating something called a "file" provides no way of passing in a file descriptor. This is confusing.

The 'file:' protocol eventually calls into qemu_open, and this transparently allows for FD passing using /dev/fdset/NNN syntax to pass in FDs.

Quoted 14 lines
qapi/migration.json +4 -0
index aa1b39bce1..37f4b9c6fb 100644
@@ -1656,13 +1656,20 @@
 #
 # @filename: The file to receive the migration stream
 #
+# @fd: A file descriptor name or number.  File descriptors must be
+#     first added with the 'getfd' command. (since 9.0).
+#
 # @offset: The file offset where the migration stream will start
 #
+# Since 9.0, all members are optional, but at least one of @filename

qapi/migration.json line 1672

Quoted 10 lines
qapi/migration.json +5 -2
+# or @fd are required.
+#
 # Since: 8.2
 ##
 { 'struct': 'FileMigrationArgs',
-  'data': { 'filename': 'str',
-            'offset': 'uint64' } }
+  'data': { '*filename': 'str',
+            '*fd': 'str',
+            '*offset': 'uint64' } }

Adding 'fd' here is not desirable, because 'filename' is resolved via qemu_open which allows for FD passing without introducing any new syntax in interfaces which take filenames.

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 :|
#7 lore raw

Re: [RFC PATCH v3 3/3] migration: Add fd to FileMigrationArgs

Quoted 18 lines · Daniel P. Berrangé
Quoted 17 lines · Fabiano Rosas

The fd: URI has supported migration to a file or socket since before QEMU 8.2. In 8.2 we added the file: URI that supported migration to a file. So now we have two ways (three if you count exec:>cat) to migrate to a file. Fine.

However,

In 8.2 we also added the new qmp_migrate API that uses a JSON channel list instead of the URI. It added two migration transports SOCKET and FILE. It was decided that the new API would classify the fd migration as a type of socket migration, neglecting the fact that the fd.c code also supported file migrations.

In 9.0 we're adding support for fd + multifd + mapped-ram, which is tied to the file migration. This was implemented in fd.c, which is only reachable when the SOCKET address type is used.

Quoted 9 lines
Quoted 4 lines

The result of this is that we're asking users of the new API to create (1)
something called a "socket" to perform migration to a plain file. And creating something called a "file" provides no way of passing in a file descriptor. This is confusing.

The 'file:' protocol eventually calls into qemu_open, and this transparently allows for FD passing using /dev/fdset/NNN syntax to pass in FDs.

Ok, that's technically correct. But it works differently from fd:fdname.

/dev/fdset requires the user to switch from getfd to add-fd and it requires QEMU and libvirt/user to synchronize on the open() flags being used. QEMU cannot just receive any fd, it must be an fd that matches the flags QEMU passed into qio_channel_file_new_path().

Users will have to adapt to the new API anyway, so it might be ok to require these changes around it as well.

To keep compatibility, we'd continue to accept the fd that comes from "fd:" or SOCKET_ADDRESS_TYPE_FD. But we'd be making it harder for users of the fd: syntax to move to the new API.

I also don't know how we would deal with fdset when (if) we add support for passing in more channels in the new API. It supports multiple fds, but how do we deal with something like:

"[ { 'channel-type': 'main',"
" 'addr': { 'transport': 'file',"
" 'filename': '/dev/fdset/1' } },
" { 'channel-type': 'second',"
" 'addr': { 'transport': 'file',"
" 'filename': '/dev/fdset/2' } } ]",

Maybe that's too far ahead for this discussion.

Quoted 31 lines
Quoted 14 lines
qapi/migration.json +4 -0
index aa1b39bce1..37f4b9c6fb 100644
@@ -1656,13 +1656,20 @@
 #
 # @filename: The file to receive the migration stream
 #
+# @fd: A file descriptor name or number.  File descriptors must be
+#     first added with the 'getfd' command. (since 9.0).
+#
 # @offset: The file offset where the migration stream will start
 #
+# Since 9.0, all members are optional, but at least one of @filename

qapi/migration.json line 1672

Quoted 10 lines
qapi/migration.json +5 -2
+# or @fd are required.
+#
 # Since: 8.2
 ##
 { 'struct': 'FileMigrationArgs',
-  'data': { 'filename': 'str',
-            'offset': 'uint64' } }
+  'data': { '*filename': 'str',
+            '*fd': 'str',
+            '*offset': 'uint64' } }

Adding 'fd' here is not desirable, because 'filename' is resolved via qemu_open which allows for FD passing without introducing any new syntax in interfaces which take filenames.

With regards,
Daniel

#8 lore raw

Re: [RFC PATCH v3 3/3] migration: Add fd to FileMigrationArgs

Quoted 33 lines · Fabiano Rosas
Quoted 18 lines · Daniel P. Berrangé
Quoted 17 lines · Fabiano Rosas

The fd: URI has supported migration to a file or socket since before QEMU 8.2. In 8.2 we added the file: URI that supported migration to a file. So now we have two ways (three if you count exec:>cat) to migrate to a file. Fine.

However,

In 8.2 we also added the new qmp_migrate API that uses a JSON channel list instead of the URI. It added two migration transports SOCKET and FILE. It was decided that the new API would classify the fd migration as a type of socket migration, neglecting the fact that the fd.c code also supported file migrations.

In 9.0 we're adding support for fd + multifd + mapped-ram, which is tied to the file migration. This was implemented in fd.c, which is only reachable when the SOCKET address type is used.

Quoted 9 lines
Quoted 4 lines

The result of this is that we're asking users of the new API to create (1)
something called a "socket" to perform migration to a plain file. And creating something called a "file" provides no way of passing in a file descriptor. This is confusing.

The 'file:' protocol eventually calls into qemu_open, and this transparently allows for FD passing using /dev/fdset/NNN syntax to pass in FDs.

Ok, that's technically correct. But it works differently from fd:fdname.

Quoted 7 lines

/dev/fdset requires the user to switch from getfd to add-fd and it requires QEMU and libvirt/user to synchronize on the open() flags being used. QEMU cannot just receive any fd, it must be an fd that matches the flags QEMU passed into qio_channel_file_new_path().

Users will have to adapt to the new API anyway, so it might be ok to require these changes around it as well.

Passing plain files to QEMU is a new feature, so apps have to adapt their code already. The expectations around flags are not especially hard - RDONLY|WRONLY|RDWR, optionally with O_DIRECT depending on what migrate feature is enabled.

Quoted 8 lines

To keep compatibility, we'd continue to accept the fd that comes from "fd:" or SOCKET_ADDRESS_TYPE_FD. But we'd be making it harder for users of the fd: syntax to move to the new API.

I also don't know how we would deal with fdset when (if) we add support for passing in more channels in the new API. It supports multiple fds, but how do we deal with something like:

Quoted 6 lines

"[ { 'channel-type': 'main',"
" 'addr': { 'transport': 'file',"
" 'filename': '/dev/fdset/1' } },
" { 'channel-type': 'second',"
" 'addr': { 'transport': 'file',"
" 'filename': '/dev/fdset/2' } } ]",

Having multiple fdsets should "just work" - qemu_open() handles everything behind the scenes, so the rest of QEMU shouldn't need to know anything about FD passing of plain files.

Similarly for socket FD passing, if the QEMU code works with a SocketAddress struct in its public API, FD passing of of sockets should again "just work" without any special logic.

The only reason why 'migrate' has this "fd:name" protocol, is because this pre-dates the introduction of "SocketAddress" in QAPI.

With the switch to "MigrateAddress" exposing "SocketAddress" directly, 'migrate' has normalized itself with best practice.

Quoted 35 lines

Maybe that's too far ahead for this discussion.

Quoted 31 lines
Quoted 14 lines
qapi/migration.json +4 -0
index aa1b39bce1..37f4b9c6fb 100644
@@ -1656,13 +1656,20 @@
 #
 # @filename: The file to receive the migration stream
 #
+# @fd: A file descriptor name or number.  File descriptors must be
+#     first added with the 'getfd' command. (since 9.0).
+#
 # @offset: The file offset where the migration stream will start
 #
+# Since 9.0, all members are optional, but at least one of @filename

qapi/migration.json line 1672

Quoted 10 lines
qapi/migration.json +5 -2
+# or @fd are required.
+#
 # Since: 8.2
 ##
 { 'struct': 'FileMigrationArgs',
-  'data': { 'filename': 'str',
-            'offset': 'uint64' } }
+  'data': { '*filename': 'str',
+            '*fd': 'str',
+            '*offset': 'uint64' } }

Adding 'fd' here is not desirable, because 'filename' is resolved via qemu_open which allows for FD passing without introducing any new syntax in interfaces which take filenames.

With regards,
Daniel

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 :|
#9 lore raw

Re: [RFC PATCH v3 3/3] migration: Add fd to FileMigrationArgs

In reply to Daniel P. Berrangé

[I queued patch 1-2 into -stable, leaving this patch for further
discussions]

Quoted 3 lines · Daniel P. Berrangé

The 'file:' protocol eventually calls into qemu_open, and this transparently allows for FD passing using /dev/fdset/NNN syntax to pass in FDs.

If it always use /dev/fdsets for files, does it mean that the newly added SOCKET_ADDRESS_TYPE_FD support on mapped-ram will never be used (so we can drop them)?

What about the old getfd? Is it obsolete because it relies on monitor object? Or maybe it's still in use?

It would be greatly helpful if there can be a summary of how libvirt uses fd for migration purpose.

Thanks,

Signature · 1 line
Peter Xu
#10 lore raw

Re: [RFC PATCH v3 3/3] migration: Add fd to FileMigrationArgs

Quoted 11 lines · Peter Xu

[I queued patch 1-2 into -stable, leaving this patch for further
discussions]

Quoted 3 lines · Daniel P. Berrangé

The 'file:' protocol eventually calls into qemu_open, and this transparently allows for FD passing using /dev/fdset/NNN syntax to pass in FDs.

If it always use /dev/fdsets for files, does it mean that the newly added SOCKET_ADDRESS_TYPE_FD support on mapped-ram will never be used (so we can drop them)?

We already have SOCKET_ADDRESS_TYPE_FD + file since 8.2 when the MigrationAddress was added. So this:

'channels': [ { 'channel-type': 'main',

                'addr': { 'transport': 'socket',
                'type': 'fd',
                'str': 'fdname' } } ]

works without multifd and without mapped-ram if the fd is a file or socket.

So yes, you're correct, but given we already have this^ it would be perhaps more confusing for users to allow it, but not allow the very same JSON when multifd=true, mapped-ram=true.

That's the only reason I didn't propose reverting commit decdc76772 ("migration/multifd: Add mapped-ram support to fd: URI").

For mapped-ram in libvirt, we'll definitely not use SOCKET_ADDRESS_TYPE_FD (as in the JSON), because I don't think libvirt supports the new API.

As for SOCKET_ADDRESS_TYPE_FD as in "fd:", we could use it when direct-io is disabled. With direct-io, the fdset will be required.

Quoted 8 lines

What about the old getfd? Is it obsolete because it relies on monitor object? Or maybe it's still in use?

It would be greatly helpful if there can be a summary of how libvirt uses fd for migration purpose.

Thanks,

#11 lore raw

Re: [RFC PATCH v3 3/3] migration: Add fd to FileMigrationArgs

Quoted 22 lines · Fabiano Rosas
Quoted 11 lines · Peter Xu

[I queued patch 1-2 into -stable, leaving this patch for further
discussions]

Quoted 3 lines · Daniel P. Berrangé

The 'file:' protocol eventually calls into qemu_open, and this transparently allows for FD passing using /dev/fdset/NNN syntax to pass in FDs.

If it always use /dev/fdsets for files, does it mean that the newly added SOCKET_ADDRESS_TYPE_FD support on mapped-ram will never be used (so we can drop them)?

We already have SOCKET_ADDRESS_TYPE_FD + file since 8.2 when the MigrationAddress was added. So this:

'channels': [ { 'channel-type': 'main',

                'addr': { 'transport': 'socket',
                'type': 'fd',
                'str': 'fdname' } } ]
Quoted 6 lines

works without multifd and without mapped-ram if the fd is a file or socket.

So yes, you're correct, but given we already have this^ it would be perhaps more confusing for users to allow it, but not allow the very same JSON when multifd=true, mapped-ram=true.

I don't think the fd: protocol (no matter the old "fd:", or the new JSON format) is trivial to use. If libvirt didn't use it I won't be surprised to see nobody using it. I want us to avoid working on things that nobody is using, or has a better replacement.

So even if Libvirt supports both, I'm wondering whether /dev/fdset/ works for all the cases that libvirt needs. I am aware that the old getfd has the monitor limitation so that if the QMP disconnected and reconnect, the fd can be gone. However I'm not sure whether that's the only reason to have add-fd, and also not sure whether it means add-fd is always preferred, so that maybe we can consider obsolete getfd?

Quoted 20 lines

That's the only reason I didn't propose reverting commit decdc76772 ("migration/multifd: Add mapped-ram support to fd: URI").

For mapped-ram in libvirt, we'll definitely not use SOCKET_ADDRESS_TYPE_FD (as in the JSON), because I don't think libvirt supports the new API.

As for SOCKET_ADDRESS_TYPE_FD as in "fd:", we could use it when direct-io is disabled. With direct-io, the fdset will be required.

Quoted 8 lines

What about the old getfd? Is it obsolete because it relies on monitor object? Or maybe it's still in use?

It would be greatly helpful if there can be a summary of how libvirt uses fd for migration purpose.

Thanks,

Signature · 1 line
Peter Xu
#12 lore raw

Re: [RFC PATCH v3 3/3] migration: Add fd to FileMigrationArgs

Quoted 35 lines · Peter Xu
Quoted 22 lines · Fabiano Rosas
Quoted 11 lines · Peter Xu

[I queued patch 1-2 into -stable, leaving this patch for further
discussions]

Quoted 3 lines · Daniel P. Berrangé

The 'file:' protocol eventually calls into qemu_open, and this transparently allows for FD passing using /dev/fdset/NNN syntax to pass in FDs.

If it always use /dev/fdsets for files, does it mean that the newly added SOCKET_ADDRESS_TYPE_FD support on mapped-ram will never be used (so we can drop them)?

We already have SOCKET_ADDRESS_TYPE_FD + file since 8.2 when the MigrationAddress was added. So this:

'channels': [ { 'channel-type': 'main',

                'addr': { 'transport': 'socket',
                'type': 'fd',
                'str': 'fdname' } } ]
Quoted 6 lines

works without multifd and without mapped-ram if the fd is a file or socket.

So yes, you're correct, but given we already have this^ it would be perhaps more confusing for users to allow it, but not allow the very same JSON when multifd=true, mapped-ram=true.

I don't think the fd: protocol (no matter the old "fd:", or the new JSON format) is trivial to use. If libvirt didn't use it I won't be surprised to see nobody using it. I want us to avoid working on things that nobody is using, or has a better replacement.

Quoted 6 lines

So even if Libvirt supports both, I'm wondering whether /dev/fdset/ works for all the cases that libvirt needs. I am aware that the old getfd has the monitor limitation so that if the QMP disconnected and reconnect, the fd can be gone. However I'm not sure whether that's the only reason to have add-fd, and also not sure whether it means add-fd is always preferred, so that maybe we can consider obsolete getfd?

Historically libvirt primariily uses the 'fd:' protocol, with a socket FD. It never gives QEMU a plain file FD, since it has always added its "iohelper" as a MITM, in order to add O_DIRECT on top.

The 'getfd' command is something that is needed when talking to QEMU for any API that involves a "SocketAddress" QAPI type, which is applicable for migration.

With the introduction of 'MigrationAddress', the 'socket' protocol is backed by 'SocketAddress' and thus supports FD passing for sockets (or potentally pipes too), in combination with 'getfd'.

With the 'file' protocol in 'MigrationAddress', since it gets backed by qemu_open(), then /dev/fdset/NN and 'add-fd' provide passing for plain files.

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 :|
#13 lore raw

Re: [RFC PATCH v3 3/3] migration: Add fd to FileMigrationArgs

Quoted 52 lines · Daniel P. Berrangé
Quoted 35 lines · Peter Xu
Quoted 22 lines · Fabiano Rosas
Quoted 11 lines · Peter Xu

[I queued patch 1-2 into -stable, leaving this patch for further
discussions]

Quoted 3 lines · Daniel P. Berrangé

The 'file:' protocol eventually calls into qemu_open, and this transparently allows for FD passing using /dev/fdset/NNN syntax to pass in FDs.

If it always use /dev/fdsets for files, does it mean that the newly added SOCKET_ADDRESS_TYPE_FD support on mapped-ram will never be used (so we can drop them)?

We already have SOCKET_ADDRESS_TYPE_FD + file since 8.2 when the MigrationAddress was added. So this:

'channels': [ { 'channel-type': 'main',

                'addr': { 'transport': 'socket',
                'type': 'fd',
                'str': 'fdname' } } ]
Quoted 6 lines

works without multifd and without mapped-ram if the fd is a file or socket.

So yes, you're correct, but given we already have this^ it would be perhaps more confusing for users to allow it, but not allow the very same JSON when multifd=true, mapped-ram=true.

I don't think the fd: protocol (no matter the old "fd:", or the new JSON format) is trivial to use. If libvirt didn't use it I won't be surprised to see nobody using it. I want us to avoid working on things that nobody is using, or has a better replacement.

Quoted 6 lines

So even if Libvirt supports both, I'm wondering whether /dev/fdset/ works for all the cases that libvirt needs. I am aware that the old getfd has the monitor limitation so that if the QMP disconnected and reconnect, the fd can be gone. However I'm not sure whether that's the only reason to have add-fd, and also not sure whether it means add-fd is always preferred, so that maybe we can consider obsolete getfd?

Historically libvirt primariily uses the 'fd:' protocol, with a socket FD. It never gives QEMU a plain file FD, since it has always added its "iohelper" as a MITM, in order to add O_DIRECT on top.

The 'getfd' command is something that is needed when talking to QEMU for any API that involves a "SocketAddress" QAPI type, which is applicable for migration.

Quoted 7 lines

With the introduction of 'MigrationAddress', the 'socket' protocol is backed by 'SocketAddress' and thus supports FD passing for sockets (or potentally pipes too), in combination with 'getfd'.

With the 'file' protocol in 'MigrationAddress', since it gets backed by qemu_open(), then /dev/fdset/NN and 'add-fd' provide passing for plain files.

I see. I assume it means we still have multiple users of getfd so it's still in use where add-fd is not yet avaiable.

But then, SOCKET_ADDRESS_TYPE_FD is then not used for libvirt in the whole mapped-ram effort, neither do we need any support on file migrations over "fd", e.g. fd_start_incoming_migration() for files. So we can drop these parts, am I right?

Thanks,

Signature · 1 line
Peter Xu
#14 lore raw

Re: [RFC PATCH v3 3/3] migration: Add fd to FileMigrationArgs

Quoted 61 lines · Peter Xu
Quoted 52 lines · Daniel P. Berrangé
Quoted 35 lines · Peter Xu
Quoted 22 lines · Fabiano Rosas
Quoted 11 lines · Peter Xu

[I queued patch 1-2 into -stable, leaving this patch for further
discussions]

Quoted 3 lines · Daniel P. Berrangé

The 'file:' protocol eventually calls into qemu_open, and this transparently allows for FD passing using /dev/fdset/NNN syntax to pass in FDs.

If it always use /dev/fdsets for files, does it mean that the newly added SOCKET_ADDRESS_TYPE_FD support on mapped-ram will never be used (so we can drop them)?

We already have SOCKET_ADDRESS_TYPE_FD + file since 8.2 when the MigrationAddress was added. So this:

'channels': [ { 'channel-type': 'main',

                'addr': { 'transport': 'socket',
                'type': 'fd',
                'str': 'fdname' } } ]
Quoted 6 lines

works without multifd and without mapped-ram if the fd is a file or socket.

So yes, you're correct, but given we already have this^ it would be perhaps more confusing for users to allow it, but not allow the very same JSON when multifd=true, mapped-ram=true.

I don't think the fd: protocol (no matter the old "fd:", or the new JSON format) is trivial to use. If libvirt didn't use it I won't be surprised to see nobody using it. I want us to avoid working on things that nobody is using, or has a better replacement.

Quoted 6 lines

So even if Libvirt supports both, I'm wondering whether /dev/fdset/ works for all the cases that libvirt needs. I am aware that the old getfd has the monitor limitation so that if the QMP disconnected and reconnect, the fd can be gone. However I'm not sure whether that's the only reason to have add-fd, and also not sure whether it means add-fd is always preferred, so that maybe we can consider obsolete getfd?

Historically libvirt primariily uses the 'fd:' protocol, with a socket FD. It never gives QEMU a plain file FD, since it has always added its "iohelper" as a MITM, in order to add O_DIRECT on top.

The 'getfd' command is something that is needed when talking to QEMU for any API that involves a "SocketAddress" QAPI type, which is applicable for migration.

Quoted 7 lines

With the introduction of 'MigrationAddress', the 'socket' protocol is backed by 'SocketAddress' and thus supports FD passing for sockets (or potentally pipes too), in combination with 'getfd'.

With the 'file' protocol in 'MigrationAddress', since it gets backed by qemu_open(), then /dev/fdset/NN and 'add-fd' provide passing for plain files.

Quoted 7 lines

I see. I assume it means we still have multiple users of getfd so it's still in use where add-fd is not yet avaiable.

But then, SOCKET_ADDRESS_TYPE_FD is then not used for libvirt in the whole mapped-ram effort, neither do we need any support on file migrations over "fd", e.g. fd_start_incoming_migration() for files. So we can drop these parts, am I right?

Correct, libvirt hasn't got any impl for 'mapped-ram' yet, at least not something merged.

Since this is new functionality, libvirt could go straight for the 'file' protocol / address type.

At some point I think we can stop using 'fd' for traditional migration too and pass the socket address to QEMU and let QEMU open the socket.

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 :|
#15 lore raw

Re: [RFC PATCH v3 3/3] migration: Add fd to FileMigrationArgs

Quoted 70 lines · Daniel P. Berrangé
Quoted 61 lines · Peter Xu
Quoted 52 lines · Daniel P. Berrangé
Quoted 35 lines · Peter Xu
Quoted 22 lines · Fabiano Rosas
Quoted 11 lines · Peter Xu

[I queued patch 1-2 into -stable, leaving this patch for further
discussions]

Quoted 3 lines · Daniel P. Berrangé

The 'file:' protocol eventually calls into qemu_open, and this transparently allows for FD passing using /dev/fdset/NNN syntax to pass in FDs.

If it always use /dev/fdsets for files, does it mean that the newly added SOCKET_ADDRESS_TYPE_FD support on mapped-ram will never be used (so we can drop them)?

We already have SOCKET_ADDRESS_TYPE_FD + file since 8.2 when the MigrationAddress was added. So this:

'channels': [ { 'channel-type': 'main',

                'addr': { 'transport': 'socket',
                'type': 'fd',
                'str': 'fdname' } } ]
Quoted 6 lines

works without multifd and without mapped-ram if the fd is a file or socket.

So yes, you're correct, but given we already have this^ it would be perhaps more confusing for users to allow it, but not allow the very same JSON when multifd=true, mapped-ram=true.

I don't think the fd: protocol (no matter the old "fd:", or the new JSON format) is trivial to use. If libvirt didn't use it I won't be surprised to see nobody using it. I want us to avoid working on things that nobody is using, or has a better replacement.

Quoted 6 lines

So even if Libvirt supports both, I'm wondering whether /dev/fdset/ works for all the cases that libvirt needs. I am aware that the old getfd has the monitor limitation so that if the QMP disconnected and reconnect, the fd can be gone. However I'm not sure whether that's the only reason to have add-fd, and also not sure whether it means add-fd is always preferred, so that maybe we can consider obsolete getfd?

Historically libvirt primariily uses the 'fd:' protocol, with a socket FD. It never gives QEMU a plain file FD, since it has always added its "iohelper" as a MITM, in order to add O_DIRECT on top.

The 'getfd' command is something that is needed when talking to QEMU for any API that involves a "SocketAddress" QAPI type, which is applicable for migration.

Quoted 7 lines

With the introduction of 'MigrationAddress', the 'socket' protocol is backed by 'SocketAddress' and thus supports FD passing for sockets (or potentally pipes too), in combination with 'getfd'.

With the 'file' protocol in 'MigrationAddress', since it gets backed by qemu_open(), then /dev/fdset/NN and 'add-fd' provide passing for plain files.

Quoted 7 lines

I see. I assume it means we still have multiple users of getfd so it's still in use where add-fd is not yet avaiable.

But then, SOCKET_ADDRESS_TYPE_FD is then not used for libvirt in the whole mapped-ram effort, neither do we need any support on file migrations over "fd", e.g. fd_start_incoming_migration() for files. So we can drop these parts, am I right?

Quoted 8 lines

Correct, libvirt hasn't got any impl for 'mapped-ram' yet, at least not something merged.

Since this is new functionality, libvirt could go straight for the 'file' protocol / address type.

At some point I think we can stop using 'fd' for traditional migration too and pass the socket address to QEMU and let QEMU open the socket.

Thanks for confirming this, that sounds good. I quickly discussed this with Fabiano just now, I think there's a plan we start to mark fd migration deprecated for the next release (9.1), then there is a chance we drop it in migration for 9.3. That'll copy libvirt list so we can re-check there.

Fabiano will then prepare patches to remove the "fd:" support on file migrations; that will be for 9.0.

Thanks,

Signature · 1 line
Peter Xu