migration: re-use migrate_incoming for postcopy recovery
cover migration: re-use migrate_incoming for postcopy recovery
This series is based on the postcopy failure recovery series. It sololy tries to provide a new way to allow the destination to have a new incoming channel.
One use case is when we are doing postcopy migration using a fd on destination side. When network failure is detected, destination QEMU will switch to postcopy-pause state for a recovery. However since the old fd is disconnected and not valid any more, there is no way to do a reconnection without a new reconfiguration.
With this series, we can specify the new listening channel by using "migrate_incoming xxx:xxx" command. It was used only for "-incoming defer" to defer an incoming migration. This series extended its usage for paused postcopy as well.
Please review, thanks.
Peter Xu (6):
migration: free SocketAddress where allocated
migration: return incoming task tag for sockets
migration: return incoming task tag for exec
migration: return incoming task tag for fd
migration: store listen task tag
migration: allow migrate_incoming for paused VM
migration/exec.c | 18 ++++++++++------- migration/exec.h | 2 +- migration/fd.c | 18 ++++++++++------- migration/fd.h | 2 +- migration/migration.c | 56 +++++++++++++++++++++++++++++++++++++++++---------- migration/migration.h | 2 ++ migration/socket.c | 40 +++++++++++++++++++++++------------- migration/socket.h | 4 ++-- 8 files changed, 99 insertions(+), 43 deletions(-)
Signature · 1 line
2.7.4
RFC 1/6 migration: free SocketAddress where allocated
Freeing the SocketAddress struct in socket_start_incoming_migration is slightly confusing. Let's free the address in the same context where we allocated it.
--- migration/socket.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
migration/socket.c +2 -2
@@ -168,7 +168,6 @@ static void socket_start_incoming_migration(SocketAddress *saddr,if (qio_channel_socket_listen_sync (listen_ioc, saddr, errp) <0 ) {object_unref (OBJECT (listen_ioc)); -qapi_free_SocketAddress (saddr);return ; }
@@ -177,7 +176,6 @@ static void socket_start_incoming_migration(SocketAddress *saddr, socket_accept_incoming_migration, listen_ioc, (GDestroyNotify)object_unref); -qapi_free_SocketAddress (saddr); }void tcp_start_incoming_migration (const char *host_port,Error **errp)
@@ -188,10 +186,12 @@ void tcp_start_incoming_migration(const char *host_port, Error **errp)socket_start_incoming_migration (saddr, &err); }error_propagate (errp, err); +qapi_free_SocketAddress (saddr); }void unix_start_incoming_migration (const char *path,Error **errp) {SocketAddress *saddr =unix_build_address (path);socket_start_incoming_migration (saddr, errp); +qapi_free_SocketAddress (saddr); }
Signature · 1 line
2.7.4
RFC 2/6 migration: return incoming task tag for sockets
In reply to Peter XuFor socket based incoming migration, we attached a background task onto main loop to handle the acception of connections. We never had a way to destroy it before, only if we finished the migration.
Let's allow socket_start_incoming_migration() to return the source tag of the listening async work, so that we may be able to clean it up in the future.
--- migration/socket.c | 36 ++++++++++++++++++++++++------------ migration/socket.h | 4 ++-- 2 files changed, 26 insertions(+), 14 deletions(-)
migration/socket.c +24 -12
@@ -158,8 +158,12 @@ out: } -static void socket_start_incoming_migration (SocketAddress *saddr, -Error **errp) +/* +* Returns the tag ID of the watch that is attached to global main +* loop (>0), or zero if failure detected. +*/ +static guint socket_start_incoming_migration (SocketAddress *saddr, +Error **errp) {QIOChannelSocket *listen_ioc =qio_channel_socket_new ();
@@ -168,30 +172,38 @@ static void socket_start_incoming_migration(SocketAddress *saddr,if (qio_channel_socket_listen_sync (listen_ioc, saddr, errp) <0 ) {object_unref (OBJECT (listen_ioc)); -return ; +return 0 ; } -qio_channel_add_watch (QIO_CHANNEL (listen_ioc), -G_IO_IN , - socket_accept_incoming_migration, - listen_ioc, - (GDestroyNotify )object_unref); +return qio_channel_add_watch (QIO_CHANNEL (listen_ioc), +G_IO_IN , + socket_accept_incoming_migration, + listen_ioc, + (GDestroyNotify )object_unref); } -void tcp_start_incoming_migration (const char *host_port,Error **errp) +guint tcp_start_incoming_migration (const char *host_port,Error **errp) {Error *err =NULL ;SocketAddress *saddr =tcp_build_address (host_port, &err); +guint tag; +if (!err) { -socket_start_incoming_migration (saddr, &err); + tag =socket_start_incoming_migration (saddr, &err); }error_propagate (errp, err);qapi_free_SocketAddress (saddr); + +return tag; } -void unix_start_incoming_migration (const char *path,Error **errp) +guint unix_start_incoming_migration (const char *path,Error **errp) {SocketAddress *saddr =unix_build_address (path); -socket_start_incoming_migration (saddr, errp); +guint tag; + + tag =socket_start_incoming_migration (saddr, errp);qapi_free_SocketAddress (saddr); + +return tag; }
migration/socket.h +2 -2
@@ -16,12 +16,12 @@#ifndef QEMU_MIGRATION_SOCKET_H #define QEMU_MIGRATION_SOCKET_H -void tcp_start_incoming_migration (const char *host_port,Error **errp); +guint tcp_start_incoming_migration (const char *host_port,Error **errp);void tcp_start_outgoing_migration (MigrationState *s,const char *host_port,Error **errp); -void unix_start_incoming_migration (const char *path,Error **errp); +guint unix_start_incoming_migration (const char *path,Error **errp);void unix_start_outgoing_migration (MigrationState *s,const char *path,Error **errp);
Signature · 1 line
2.7.4
RFC 3/6 migration: return incoming task tag for exec
In reply to Peter XuReturn the async task tag for exec typed incoming migration in exec_start_incoming_migration().
--- migration/exec.c | 18 +++++++++++------- migration/exec.h | 2 +- 2 files changed, 12 insertions(+), 8 deletions(-)
migration/exec.c +11 -7
@@ -52,7 +52,11 @@ static gboolean exec_accept_incoming_migration(QIOChannel *ioc,return FALSE;/* unregister */ } -void exec_start_incoming_migration (const char *command,Error **errp) +/* +* Returns the tag ID of the watch that is attached to global main +* loop (>0), or zero if failure detected. +*/ +guint exec_start_incoming_migration (const char *command,Error **errp) {QIOChannel *ioc;const char *argv[] = {"/bin/sh" ,"-c" , command,NULL };
@@ -62,13 +66,13 @@ void exec_start_incoming_migration(const char *command, Error **errp)O_RDWR , errp));if (!ioc) { -return ; +return 0 ; }qio_channel_set_name (ioc,"migration-exec-incoming" ); -qio_channel_add_watch (ioc, -G_IO_IN , - exec_accept_incoming_migration, -NULL , -NULL ); +return qio_channel_add_watch (ioc, +G_IO_IN , + exec_accept_incoming_migration, +NULL , +NULL ); }
migration/exec.h +1 -1
@@ -19,7 +19,7 @@#ifndef QEMU_MIGRATION_EXEC_H #define QEMU_MIGRATION_EXEC_H -void exec_start_incoming_migration (const char *host_port,Error **errp); +guint exec_start_incoming_migration (const char *host_port,Error **errp);void exec_start_outgoing_migration (MigrationState *s,const char *host_port,Error **errp);
Signature · 1 line
2.7.4
RFC 4/6 migration: return incoming task tag for fd
In reply to Peter XuAllow to return the task tag in fd_start_incoming_migration().
--- migration/fd.c | 18 +++++++++++------- migration/fd.h | 2 +- 2 files changed, 12 insertions(+), 8 deletions(-)
migration/fd.c +11 -7
@@ -52,7 +52,11 @@ static gboolean fd_accept_incoming_migration(QIOChannel *ioc,return FALSE;/* unregister */ } -void fd_start_incoming_migration (const char *infd,Error **errp) +/* +* Returns the tag ID of the watch that is attached to global main +* loop (>0), or zero if failure detected. +*/ +guint fd_start_incoming_migration (const char *infd,Error **errp) {QIOChannel *ioc;int fd;
@@ -63,13 +67,13 @@ void fd_start_incoming_migration(const char *infd, Error **errp) ioc =qio_channel_new_fd (fd, errp);if (!ioc) {close (fd); -return ; +return 0 ; }qio_channel_set_name (QIO_CHANNEL (ioc),"migration-fd-incoming" ); -qio_channel_add_watch (ioc, -G_IO_IN , - fd_accept_incoming_migration, -NULL , -NULL ); +return qio_channel_add_watch (ioc, +G_IO_IN , + fd_accept_incoming_migration, +NULL , +NULL ); }
migration/fd.h +1 -1
@@ -16,7 +16,7 @@#ifndef QEMU_MIGRATION_FD_H #define QEMU_MIGRATION_FD_H -void fd_start_incoming_migration (const char *path,Error **errp); +guint fd_start_incoming_migration (const char *path,Error **errp);void fd_start_outgoing_migration (MigrationState *s,const char *fdname,Error **errp);
Signature · 1 line
2.7.4
RFC 5/6 migration: store listen task tag
In reply to Peter XuStore the task tag for migration types: tcp/unix/fd/exec in current MigrationIncomingState struct.
For defered migration, no need to store task tag since there is no task running in the main loop at all. For RDMA, let's mark it as todo.
--- migration/migration.c | 22 ++++++++++++++++++---- migration/migration.h | 2 ++ 2 files changed, 20 insertions(+), 4 deletions(-)
migration/migration.c +18 -4
@@ -171,6 +171,7 @@ void migration_incoming_state_destroy(void) mis->from_src_file =NULL ; } + mis->listen_task_tag =0 ;qemu_event_destroy (&mis->main_thread_load_event); }
@@ -265,25 +266,31 @@ int migrate_send_rp_req_pages(MigrationIncomingState *mis, const char *rbname,void qemu_start_incoming_migration (const char *uri,Error **errp) {const char *p; +guint task_tag =0 ; +MigrationIncomingState *mis =migration_incoming_get_current ();qapi_event_send_migration (MIGRATION_STATUS_SETUP , &error_abort);if (!strcmp (uri,"defer" )) {deferred_incoming_migration (errp); }else if (strstart (uri,"tcp:" , &p)) { -tcp_start_incoming_migration (p, errp); + task_tag =tcp_start_incoming_migration (p, errp); #ifdef CONFIG_RDMA }else if (strstart (uri,"rdma:" , &p)) { +/* TODO: store task tag for RDMA migrations */ rdma_start_incoming_migration (p, errp);#endif }else if (strstart (uri,"exec:" , &p)) { -exec_start_incoming_migration (p, errp); + task_tag =exec_start_incoming_migration (p, errp); }else if (strstart (uri,"unix:" , &p)) { -unix_start_incoming_migration (p, errp); + task_tag =unix_start_incoming_migration (p, errp); }else if (strstart (uri,"fd:" , &p)) { -fd_start_incoming_migration (p, errp); + task_tag =fd_start_incoming_migration (p, errp); }else {error_setg (errp,"unknown migration protocol: %s" , uri); +return ; } + + mis->listen_task_tag = task_tag; }static void process_incoming_migration_bh (void *opaque)
@@ -422,6 +429,13 @@ void migration_fd_process_incoming(QEMUFile *f) co =qemu_coroutine_create (process_incoming_migration_co, f);qemu_coroutine_enter (co); } + +/* +* When reach here, we should not need the listening port any +* more. We'll detach the listening task soon, let's reset the +* listen task tag. +*/ + mis->listen_task_tag =0 ; }/*
migration/migration.h +2 -0
@@ -26,6 +26,8 @@/* State for the incoming migration */ struct MigrationIncomingState {QEMUFile *from_src_file; +/* Task tag for incoming listen port. Valid when >0. */ +guint listen_task_tag;/* * Free at the start of the main state load, set as the main thread finishes
Signature · 1 line
2.7.4
Re: [Qemu-devel] [RFC 5/6] migration: store listen task tag
Quoted 47 lines · Peter Xu
Store the task tag for migration types: tcp/unix/fd/exec in current MigrationIncomingState struct.
For defered migration, no need to store task tag since there is no task running in the main loop at all. For RDMA, let's mark it as todo.
Signed-off-by Peter Xu <[email protected]>--- migration/migration.c | 22 ++++++++++++++++++---- migration/migration.h | 2 ++ 2 files changed, 20 insertions(+), 4 deletions(-)migration/migration.c +6
-3@@ -171,6 +171,7 @@ void migration_incoming_state_destroy(void) mis->from_src_file =NULL ; } + mis->listen_task_tag =0 ;qemu_event_destroy (&mis->main_thread_load_event); }@@ -265,25 +266,31 @@ int migrate_send_rp_req_pages(MigrationIncomingState *mis, const char *rbname,void qemu_start_incoming_migration (const char *uri,Error **errp) {const char *p; +guint task_tag =0 ; +MigrationIncomingState *mis =migration_incoming_get_current ();qapi_event_send_migration (MIGRATION_STATUS_SETUP , &error_abort);if (!strcmp (uri,"defer" )) {deferred_incoming_migration (errp); }else if (strstart (uri,"tcp:" , &p)) { -tcp_start_incoming_migration (p, errp); + task_tag =tcp_start_incoming_migration (p, errp); #ifdef CONFIG_RDMA }else if (strstart (uri,"rdma:" , &p)) { +/* TODO: store task tag for RDMA migrations */ rdma_start_incoming_migration (p, errp);#endif }else if (strstart (uri,"exec:" , &p)) { -exec_start_incoming_migration (p, errp); + task_tag =exec_start_incoming_migration (p, errp); }else if (strstart (uri,"unix:" , &p)) { -unix_start_incoming_migration (p, errp);
migration/migration.c int migrate_send_rp_req_pages(MigrationIncomingState *mis, const char *rbname, · line 293
Quoted 10 lines
migration/migration.c +5
-1+ task_tag =unix_start_incoming_migration (p, errp); }else if (strstart (uri,"fd:" , &p)) { -fd_start_incoming_migration (p, errp); + task_tag =fd_start_incoming_migration (p, errp); }else {error_setg (errp,"unknown migration protocol: %s" , uri); +return ; } + + mis->listen_task_tag = task_tag;
This is unsafe as currently written. The main loop watches that are associated with these tags are all unregistered when incoming migration starts. So if you save them, and then unregister later when postcopy is "stuck", then you're likely unregistering a tag associated with some other random part of QEMU, because the saved value is no longer valid.
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 :|
Re: [Qemu-devel] [RFC 5/6] migration: store listen task tag
Quoted 57 lines · Daniel P. Berrange
Quoted 56 lines · Peter Xu
Store the task tag for migration types: tcp/unix/fd/exec in current MigrationIncomingState struct.
For defered migration, no need to store task tag since there is no task running in the main loop at all. For RDMA, let's mark it as todo.
Signed-off-by Peter Xu <[email protected]>--- migration/migration.c | 22 ++++++++++++++++++---- migration/migration.h | 2 ++ 2 files changed, 20 insertions(+), 4 deletions(-)migration/migration.c +10
-4@@ -171,6 +171,7 @@ void migration_incoming_state_destroy(void) mis->from_src_file =NULL ; } + mis->listen_task_tag =0 ;qemu_event_destroy (&mis->main_thread_load_event); }@@ -265,25 +266,31 @@ int migrate_send_rp_req_pages(MigrationIncomingState *mis, const char *rbname,void qemu_start_incoming_migration (const char *uri,Error **errp) {const char *p; +guint task_tag =0 ; +MigrationIncomingState *mis =migration_incoming_get_current ();qapi_event_send_migration (MIGRATION_STATUS_SETUP , &error_abort);if (!strcmp (uri,"defer" )) {deferred_incoming_migration (errp); }else if (strstart (uri,"tcp:" , &p)) { -tcp_start_incoming_migration (p, errp); + task_tag =tcp_start_incoming_migration (p, errp); #ifdef CONFIG_RDMA }else if (strstart (uri,"rdma:" , &p)) { +/* TODO: store task tag for RDMA migrations */ rdma_start_incoming_migration (p, errp);#endif }else if (strstart (uri,"exec:" , &p)) { -exec_start_incoming_migration (p, errp); + task_tag =exec_start_incoming_migration (p, errp); }else if (strstart (uri,"unix:" , &p)) { -unix_start_incoming_migration (p, errp); + task_tag =unix_start_incoming_migration (p, errp); }else if (strstart (uri,"fd:" , &p)) { -fd_start_incoming_migration (p, errp); + task_tag =fd_start_incoming_migration (p, errp); }else {error_setg (errp,"unknown migration protocol: %s" , uri); +return ; } +
Quoted 8 lines
migration/migration.c int migrate_send_rp_req_pages(MigrationIncomingState *mis, const char *rbname, · line 293
Quoted 1 line
migration/migration.c +1
-0+ mis->listen_task_tag = task_tag;This is unsafe as currently written. The main loop watches that are associated with these tags are all unregistered when incoming migration starts. So if you save them, and then unregister later when postcopy is "stuck", then you're likely unregistering a tag associated with some other random part of QEMU, because the saved value is no longer valid.
IIUC for incoming migration, the watch is not detached until migration_fd_process_incoming() completes. So:
- for precopy, the watch should be detached when migration completes
- for postcopy, the watch should be detached when postcopy starts, then main loop thread returns, while the ram_load_thread starts to continue the migration.
So basically the watch is detaching itself after migration_fd_process_incoming() completes. To handle that, this patch has this change:
@@ -422,6 +429,13 @@ void migration_fd_process_incoming(QEMUFile *f)
co = qemu_coroutine_create(process_incoming_migration_co, f);
qemu_coroutine_enter(co);
}
+
+ /*
+ * When reach here, we should not need the listening port any
+ * more. We'll detach the listening task soon, let's reset the
+ * listen task tag.
+ */+ mis->listen_task_tag = 0;
Would this make sure the listen_task_tag is always valid if nonzero?
Thanks,
Signature · 1 line
Peter Xu
Re: [Qemu-devel] [RFC 5/6] migration: store listen task tag
Quoted 92 lines · Peter Xu
Quoted 57 lines · Daniel P. Berrange
Quoted 56 lines · Peter Xu
Store the task tag for migration types: tcp/unix/fd/exec in current MigrationIncomingState struct.
For defered migration, no need to store task tag since there is no task running in the main loop at all. For RDMA, let's mark it as todo.
Signed-off-by Peter Xu <[email protected]>--- migration/migration.c | 22 ++++++++++++++++++---- migration/migration.h | 2 ++ 2 files changed, 20 insertions(+), 4 deletions(-)migration/migration.c +10
-4@@ -171,6 +171,7 @@ void migration_incoming_state_destroy(void) mis->from_src_file =NULL ; } + mis->listen_task_tag =0 ;qemu_event_destroy (&mis->main_thread_load_event); }@@ -265,25 +266,31 @@ int migrate_send_rp_req_pages(MigrationIncomingState *mis, const char *rbname,void qemu_start_incoming_migration (const char *uri,Error **errp) {const char *p; +guint task_tag =0 ; +MigrationIncomingState *mis =migration_incoming_get_current ();qapi_event_send_migration (MIGRATION_STATUS_SETUP , &error_abort);if (!strcmp (uri,"defer" )) {deferred_incoming_migration (errp); }else if (strstart (uri,"tcp:" , &p)) { -tcp_start_incoming_migration (p, errp); + task_tag =tcp_start_incoming_migration (p, errp); #ifdef CONFIG_RDMA }else if (strstart (uri,"rdma:" , &p)) { +/* TODO: store task tag for RDMA migrations */ rdma_start_incoming_migration (p, errp);#endif }else if (strstart (uri,"exec:" , &p)) { -exec_start_incoming_migration (p, errp); + task_tag =exec_start_incoming_migration (p, errp); }else if (strstart (uri,"unix:" , &p)) { -unix_start_incoming_migration (p, errp); + task_tag =unix_start_incoming_migration (p, errp); }else if (strstart (uri,"fd:" , &p)) { -fd_start_incoming_migration (p, errp); + task_tag =fd_start_incoming_migration (p, errp); }else {error_setg (errp,"unknown migration protocol: %s" , uri); +return ; } +Quoted 8 lines
migration/migration.c int migrate_send_rp_req_pages(MigrationIncomingState *mis, const char *rbname, · line 293
Quoted 1 line
migration/migration.c +1
-0+ mis->listen_task_tag = task_tag;This is unsafe as currently written. The main loop watches that are associated with these tags are all unregistered when incoming migration starts. So if you save them, and then unregister later when postcopy is "stuck", then you're likely unregistering a tag associated with some other random part of QEMU, because the saved value is no longer valid.
IIUC for incoming migration, the watch is not detached until
migration_fd_process_incoming()completes. So:- for precopy, the watch should be detached when migration completes
- for postcopy, the watch should be detached when postcopy starts, then main loop thread returns, while the
ram_load_threadstarts to continue the migration.So basically the watch is detaching itself after
migration_fd_process_incoming()completes. To handle that, this patch has this change:migration/migration.c +7
-0@@ -422,6 +429,13 @@ void migration_fd_process_incoming(QEMUFile *f) co =qemu_coroutine_create (process_incoming_migration_co, f);qemu_coroutine_enter (co); } + +/* +* When reach here, we should not need the listening port any +* more. We'll detach the listening task soon, let's reset the +* listen task tag. +*/ + mis->listen_task_tag =0 ;
Quoted 1 line
Would this make sure the
listen_task_tagis always valid if nonzero?
Mixing 'return FALSE' from callbacks, with g_source_remove is a recipe for hard to diagnose bugs, so should be avoided in general.
So, IMHO, you should change all the callbacks to 'return TRUE' so that they keep the watch registered, and then explicitly call g_source_remove() passing the listen tag, when incoming migration starts.
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 :|
Re: [Qemu-devel] [RFC 5/6] migration: store listen task tag
Quoted 93 lines · Daniel P. Berrange
Quoted 92 lines · Peter Xu
Quoted 57 lines · Daniel P. Berrange
Quoted 56 lines · Peter Xu
Store the task tag for migration types: tcp/unix/fd/exec in current MigrationIncomingState struct.
For defered migration, no need to store task tag since there is no task running in the main loop at all. For RDMA, let's mark it as todo.
Signed-off-by Peter Xu <[email protected]>--- migration/migration.c | 22 ++++++++++++++++++---- migration/migration.h | 2 ++ 2 files changed, 20 insertions(+), 4 deletions(-)migration/migration.c +10
-4@@ -171,6 +171,7 @@ void migration_incoming_state_destroy(void) mis->from_src_file =NULL ; } + mis->listen_task_tag =0 ;qemu_event_destroy (&mis->main_thread_load_event); }@@ -265,25 +266,31 @@ int migrate_send_rp_req_pages(MigrationIncomingState *mis, const char *rbname,void qemu_start_incoming_migration (const char *uri,Error **errp) {const char *p; +guint task_tag =0 ; +MigrationIncomingState *mis =migration_incoming_get_current ();qapi_event_send_migration (MIGRATION_STATUS_SETUP , &error_abort);if (!strcmp (uri,"defer" )) {deferred_incoming_migration (errp); }else if (strstart (uri,"tcp:" , &p)) { -tcp_start_incoming_migration (p, errp); + task_tag =tcp_start_incoming_migration (p, errp); #ifdef CONFIG_RDMA }else if (strstart (uri,"rdma:" , &p)) { +/* TODO: store task tag for RDMA migrations */ rdma_start_incoming_migration (p, errp);#endif }else if (strstart (uri,"exec:" , &p)) { -exec_start_incoming_migration (p, errp); + task_tag =exec_start_incoming_migration (p, errp); }else if (strstart (uri,"unix:" , &p)) { -unix_start_incoming_migration (p, errp); + task_tag =unix_start_incoming_migration (p, errp); }else if (strstart (uri,"fd:" , &p)) { -fd_start_incoming_migration (p, errp); + task_tag =fd_start_incoming_migration (p, errp); }else {error_setg (errp,"unknown migration protocol: %s" , uri); +return ; } +Quoted 8 lines
migration/migration.c int migrate_send_rp_req_pages(MigrationIncomingState *mis, const char *rbname, · line 293
Quoted 1 line
migration/migration.c +1
-0+ mis->listen_task_tag = task_tag;This is unsafe as currently written. The main loop watches that are associated with these tags are all unregistered when incoming migration starts. So if you save them, and then unregister later when postcopy is "stuck", then you're likely unregistering a tag associated with some other random part of QEMU, because the saved value is no longer valid.
IIUC for incoming migration, the watch is not detached until
migration_fd_process_incoming()completes. So:- for precopy, the watch should be detached when migration completes
- for postcopy, the watch should be detached when postcopy starts, then main loop thread returns, while the
ram_load_threadstarts to continue the migration.So basically the watch is detaching itself after
migration_fd_process_incoming()completes. To handle that, this patch has this change:migration/migration.c +7
-0@@ -422,6 +429,13 @@ void migration_fd_process_incoming(QEMUFile *f) co =qemu_coroutine_create (process_incoming_migration_co, f);qemu_coroutine_enter (co); } + +/* +* When reach here, we should not need the listening port any +* more. We'll detach the listening task soon, let's reset the +* listen task tag. +*/ + mis->listen_task_tag =0 ;
Quoted 4 lines
Quoted 1 line
Would this make sure the
listen_task_tagis always valid if nonzero?Mixing 'return FALSE' from callbacks, with
g_source_removeis a recipe for hard to diagnose bugs, so should be avoided in general.
Makes sense.
Quoted 4 lines
So, IMHO, you should change all the callbacks to 'return TRUE' so that they keep the watch registered, and then explicitly call
g_source_remove()passing the listen tag, when incoming migration starts.
Yes this sounds better. Thanks!
Signature · 1 line
Peter Xu
Re: [Qemu-devel] [RFC 5/6] migration: store listen task tag
Quoted 99 lines · Peter Xu
Quoted 93 lines · Daniel P. Berrange
Quoted 92 lines · Peter Xu
Quoted 57 lines · Daniel P. Berrange
Quoted 56 lines · Peter Xu
Store the task tag for migration types: tcp/unix/fd/exec in current MigrationIncomingState struct.
For defered migration, no need to store task tag since there is no task running in the main loop at all. For RDMA, let's mark it as todo.
Signed-off-by Peter Xu <[email protected]>--- migration/migration.c | 22 ++++++++++++++++++---- migration/migration.h | 2 ++ 2 files changed, 20 insertions(+), 4 deletions(-)migration/migration.c +10
-4@@ -171,6 +171,7 @@ void migration_incoming_state_destroy(void) mis->from_src_file =NULL ; } + mis->listen_task_tag =0 ;qemu_event_destroy (&mis->main_thread_load_event); }@@ -265,25 +266,31 @@ int migrate_send_rp_req_pages(MigrationIncomingState *mis, const char *rbname,void qemu_start_incoming_migration (const char *uri,Error **errp) {const char *p; +guint task_tag =0 ; +MigrationIncomingState *mis =migration_incoming_get_current ();qapi_event_send_migration (MIGRATION_STATUS_SETUP , &error_abort);if (!strcmp (uri,"defer" )) {deferred_incoming_migration (errp); }else if (strstart (uri,"tcp:" , &p)) { -tcp_start_incoming_migration (p, errp); + task_tag =tcp_start_incoming_migration (p, errp); #ifdef CONFIG_RDMA }else if (strstart (uri,"rdma:" , &p)) { +/* TODO: store task tag for RDMA migrations */ rdma_start_incoming_migration (p, errp);#endif }else if (strstart (uri,"exec:" , &p)) { -exec_start_incoming_migration (p, errp); + task_tag =exec_start_incoming_migration (p, errp); }else if (strstart (uri,"unix:" , &p)) { -unix_start_incoming_migration (p, errp); + task_tag =unix_start_incoming_migration (p, errp); }else if (strstart (uri,"fd:" , &p)) { -fd_start_incoming_migration (p, errp); + task_tag =fd_start_incoming_migration (p, errp); }else {error_setg (errp,"unknown migration protocol: %s" , uri); +return ; } +Quoted 8 lines
migration/migration.c int migrate_send_rp_req_pages(MigrationIncomingState *mis, const char *rbname, · line 293
Quoted 1 line
migration/migration.c +1
-0+ mis->listen_task_tag = task_tag;This is unsafe as currently written. The main loop watches that are associated with these tags are all unregistered when incoming migration starts. So if you save them, and then unregister later when postcopy is "stuck", then you're likely unregistering a tag associated with some other random part of QEMU, because the saved value is no longer valid.
IIUC for incoming migration, the watch is not detached until
migration_fd_process_incoming()completes. So:- for precopy, the watch should be detached when migration completes
- for postcopy, the watch should be detached when postcopy starts, then main loop thread returns, while the
ram_load_threadstarts to continue the migration.So basically the watch is detaching itself after
migration_fd_process_incoming()completes. To handle that, this patch has this change:migration/migration.c +7
-0@@ -422,6 +429,13 @@ void migration_fd_process_incoming(QEMUFile *f) co =qemu_coroutine_create (process_incoming_migration_co, f);qemu_coroutine_enter (co); } + +/* +* When reach here, we should not need the listening port any +* more. We'll detach the listening task soon, let's reset the +* listen task tag. +*/ + mis->listen_task_tag =0 ;Quoted 4 lines
Quoted 1 line
Would this make sure the
listen_task_tagis always valid if nonzero?Mixing 'return FALSE' from callbacks, with
g_source_removeis a recipe for hard to diagnose bugs, so should be avoided in general.
Quoted 8 lines
Makes sense.
Quoted 4 lines
So, IMHO, you should change all the callbacks to 'return TRUE' so that they keep the watch registered, and then explicitly call
g_source_remove()passing the listen tag, when incoming migration starts.Yes this sounds better. Thanks!
Hmm... when incoming migration starts, we are still in the handler of the listening gsource. I am not sure whether it's safe to remove the gsource in its own handlers.
Would this mean I should still keep current way to do it? After all although we may have two places to detach the gsource (either return FALSE in its handler, or we call g_source_detach), we are safe since both of them are in main loop context.
Thanks,
Signature · 1 line
Peter Xu
Re: [Qemu-devel] [RFC 5/6] migration: store listen task tag
Quoted 107 lines · Peter Xu
Quoted 106 lines · Peter Xu
Quoted 93 lines · Daniel P. Berrange
Quoted 92 lines · Peter Xu
Quoted 57 lines · Daniel P. Berrange
Quoted 56 lines · Peter Xu
Store the task tag for migration types: tcp/unix/fd/exec in current MigrationIncomingState struct.
For defered migration, no need to store task tag since there is no task running in the main loop at all. For RDMA, let's mark it as todo.
Signed-off-by Peter Xu <[email protected]>--- migration/migration.c | 22 ++++++++++++++++++---- migration/migration.h | 2 ++ 2 files changed, 20 insertions(+), 4 deletions(-)migration/migration.c +10
-4@@ -171,6 +171,7 @@ void migration_incoming_state_destroy(void) mis->from_src_file =NULL ; } + mis->listen_task_tag =0 ;qemu_event_destroy (&mis->main_thread_load_event); }@@ -265,25 +266,31 @@ int migrate_send_rp_req_pages(MigrationIncomingState *mis, const char *rbname,void qemu_start_incoming_migration (const char *uri,Error **errp) {const char *p; +guint task_tag =0 ; +MigrationIncomingState *mis =migration_incoming_get_current ();qapi_event_send_migration (MIGRATION_STATUS_SETUP , &error_abort);if (!strcmp (uri,"defer" )) {deferred_incoming_migration (errp); }else if (strstart (uri,"tcp:" , &p)) { -tcp_start_incoming_migration (p, errp); + task_tag =tcp_start_incoming_migration (p, errp); #ifdef CONFIG_RDMA }else if (strstart (uri,"rdma:" , &p)) { +/* TODO: store task tag for RDMA migrations */ rdma_start_incoming_migration (p, errp);#endif }else if (strstart (uri,"exec:" , &p)) { -exec_start_incoming_migration (p, errp); + task_tag =exec_start_incoming_migration (p, errp); }else if (strstart (uri,"unix:" , &p)) { -unix_start_incoming_migration (p, errp); + task_tag =unix_start_incoming_migration (p, errp); }else if (strstart (uri,"fd:" , &p)) { -fd_start_incoming_migration (p, errp); + task_tag =fd_start_incoming_migration (p, errp); }else {error_setg (errp,"unknown migration protocol: %s" , uri); +return ; } +Quoted 8 lines
migration/migration.c int migrate_send_rp_req_pages(MigrationIncomingState *mis, const char *rbname, · line 293
Quoted 1 line
migration/migration.c +1
-0+ mis->listen_task_tag = task_tag;This is unsafe as currently written. The main loop watches that are associated with these tags are all unregistered when incoming migration starts. So if you save them, and then unregister later when postcopy is "stuck", then you're likely unregistering a tag associated with some other random part of QEMU, because the saved value is no longer valid.
IIUC for incoming migration, the watch is not detached until
migration_fd_process_incoming()completes. So:- for precopy, the watch should be detached when migration completes
- for postcopy, the watch should be detached when postcopy starts, then main loop thread returns, while the
ram_load_threadstarts to continue the migration.So basically the watch is detaching itself after
migration_fd_process_incoming()completes. To handle that, this patch has this change:migration/migration.c +7
-0@@ -422,6 +429,13 @@ void migration_fd_process_incoming(QEMUFile *f) co =qemu_coroutine_create (process_incoming_migration_co, f);qemu_coroutine_enter (co); } + +/* +* When reach here, we should not need the listening port any +* more. We'll detach the listening task soon, let's reset the +* listen task tag. +*/ + mis->listen_task_tag =0 ;Quoted 4 lines
Quoted 1 line
Would this make sure the
listen_task_tagis always valid if nonzero?Mixing 'return FALSE' from callbacks, with
g_source_removeis a recipe for hard to diagnose bugs, so should be avoided in general.Makes sense.
Quoted 4 lines
So, IMHO, you should change all the callbacks to 'return TRUE' so that they keep the watch registered, and then explicitly call
g_source_remove()passing the listen tag, when incoming migration starts.
Quoted 5 lines
Quoted 1 line
Yes this sounds better. Thanks!
Hmm... when incoming migration starts, we are still in the handler of the listening gsource. I am not sure whether it's safe to remove the gsource in its own handlers.
Yes, it should be safe to call g_source_remove from within the handler itself.
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 :|
Re: [Qemu-devel] [RFC 5/6] migration: store listen task tag
Quoted 4 lines · Daniel P. Berrange
Quoted 4 lines
Quoted 4 lines
Quoted 3 lines
So, IMHO, you should change all the callbacks to 'return TRUE' so that they keep the watch registered, and then explicitly call
g_source_remove()passing the listen tag, when incoming migration starts.
Quoted 8 lines
Quoted 5 lines
Quoted 1 line
Yes this sounds better. Thanks!
Hmm... when incoming migration starts, we are still in the handler of the listening gsource. I am not sure whether it's safe to remove the gsource in its own handlers.
Yes, it should be safe to call
g_source_removefrom within the handler itself.
Thanks for confirmation. Will post a new version soon.
Signature · 1 line
Peter Xu
RFC 6/6 migration: allow migrate_incoming for paused VM
In reply to Peter Xumigrate_incoming command is previously only used when we were providing "-incoming defer" in the command line, to defer the incoming migration channel creation.
However there is similar requirement when we are paused during postcopy migration. The old incoming channel might have been destroyed already. We may need another new channel for the recovery to happen.
This patch leveraged the same interface, but allows the user to specify incoming migration channel even for paused postcopy.
--- migration/migration.c | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-)
migration/migration.c +27 -7
@@ -1288,17 +1288,39 @@ void migrate_del_blocker(Error *reason) migration_blockers =g_slist_remove (migration_blockers, reason); } +static bool migrate_incoming_detach_listen (MigrationIncomingState *mis) +{ +if (mis->listen_task_tag) { +/* Never fail */ +g_source_remove (mis->listen_task_tag); + mis->listen_task_tag =0 ; +return true; + } +return false; +} +void qmp_migrate_incoming (const char *uri,Error **errp) {Error *local_err =NULL ; -static bool once = true; +MigrationIncomingState *mis =migration_incoming_get_current (); -if (!deferred_incoming) { -error_setg (errp,"For use with '-incoming defer'" ); +if (!deferred_incoming && + mis->state !=MIGRATION_STATUS_POSTCOPY_PAUSED ) { +error_setg (errp,"For use with '-incoming defer'" +" or PAUSED postcopy migration only." );return ; } -if (!once) { -error_setg (errp,"The incoming migration has already been started" ); + +/* +* Destroy existing listening task if exist. Logically this should +* not really happen at all (for either deferred migration or +* postcopy migration, we should both detached the listening +* task). So raise an error but still we safely detach it. +*/ +if (migrate_incoming_detach_listen (mis)) { +error_report ("%s: detected existing listen channel, " +"while it should not exist" , __func__); +/* Continue */ }qemu_start_incoming_migration (uri, &local_err);
@@ -1307,8 +1329,6 @@ void qmp_migrate_incoming(const char *uri, Error **errp)error_propagate (errp, local_err);return ; } - - once = false; }bool migration_is_blocked (Error **errp)
Signature · 1 line
2.7.4