Skip to contentSkip to conversation

vhost: Cancel migration when vhost-user process restarted during migration

PATCH In review fangying 3 participants 6 messages Nov 27, 2017 – Nov 30, 2017

lore
Share & tools
lore

fangying

author
#0 lore raw

PATCH v3 1/1 vhost: Cancel migration when vhost-user process restarted during migration

QEMU will abort when vhost-user process is restarted during migration and vhost_log_global_start/stop is called. The reason is clear that vhost_dev_set_log returns -1 because network connection is temporarily lost. To handle this situation, let's cancel migration here.

---
 hw/virtio/vhost.c     | 15 +++++++++++++--
 migration/migration.c |  2 +-
 migration/migration.h |  2 +-
 3 files changed, 15 insertions(+), 4 deletions(-)
hw/virtio/vhost.c +13 -2
index ddc42f0..e2ade93 100644
@@ -26,6 +26,7 @@
 #include "hw/virtio/virtio-bus.h"
 #include "hw/virtio/virtio-access.h"
 #include "migration/blocker.h"
+#include "migration/migration.h"
 #include "sysemu/dma.h"
 
 /* enabled until disconnected backend stabilizes */
@@ -882,20 +883,30 @@ static int vhost_migration_log(MemoryListener *listener, int enable)
 static void vhost_log_global_start(MemoryListener *listener)
 {
     int r;
+    MigrationState *s = NULL;
 
     r = vhost_migration_log(listener, true);
     if (r < 0) {
-        abort();
+        error_report("Failed to start vhost dirty log");
+        s = migrate_get_current();
+        if (s->migration_thread_running) {
+            migrate_fd_cancel(s);
+        }
     }
 }
 
 static void vhost_log_global_stop(MemoryListener *listener)
 {
     int r;
+    MigrationState *s = NULL;
 
     r = vhost_migration_log(listener, false);
     if (r < 0) {
-        abort();
+        error_report("Failed to stop vhost dirty log");
+        s = migrate_get_current();
+        if (s->migration_thread_running) {
+            migrate_fd_cancel(s);
+        }
     }
 }
 
migration/migration.c +1 -1
index 4de3b55..6d2b7df 100644
@@ -1131,7 +1131,7 @@ void migrate_fd_error(MigrationState *s, const Error *error)
     block_cleanup_parameters(s);
 }
 
-static void migrate_fd_cancel(MigrationState *s)
+void migrate_fd_cancel(MigrationState *s)
 {
     int old_state ;
     QEMUFile *f = migrate_get_current()->to_dst_file;
migration/migration.h +1 -1
index 663415f..f0261e3 100644
@@ -167,7 +167,7 @@ uint64_t migrate_max_downtime(void);
 
 void migrate_set_error(MigrationState *s, const Error *error);
 void migrate_fd_error(MigrationState *s, const Error *error);
-
+void migrate_fd_cancel(MigrationState *s);
 void migrate_fd_connect(MigrationState *s);
 
 MigrationState *migrate_init(void);
Signature · 1 line
1.8.3.1
Reviewed-by on v3 1/1
#1 lore raw

Hi

Quoted 6 lines · fangying

QEMU will abort when vhost-user process is restarted during migration and vhost_log_global_start/stop is called. The reason is clear that vhost_dev_set_log returns -1 because network connection is temporarily lost. To handle this situation, let's cancel migration here.

Quoted 82 lines
---
 hw/virtio/vhost.c     | 15 +++++++++++++--
 migration/migration.c |  2 +-
 migration/migration.h |  2 +-
 3 files changed, 15 insertions(+), 4 deletions(-)
hw/virtio/vhost.c +13 -2
index ddc42f0..e2ade93 100644
@@ -26,6 +26,7 @@
 #include "hw/virtio/virtio-bus.h"
 #include "hw/virtio/virtio-access.h"
 #include "migration/blocker.h"
+#include "migration/migration.h"
 #include "sysemu/dma.h"
 
 /* enabled until disconnected backend stabilizes */
@@ -882,20 +883,30 @@ static int vhost_migration_log(MemoryListener *listener, int enable)
 static void vhost_log_global_start(MemoryListener *listener)
 {
     int r;
+    MigrationState *s = NULL;
 
     r = vhost_migration_log(listener, true);
     if (r < 0) {
-        abort();
+        error_report("Failed to start vhost dirty log");
+        s = migrate_get_current();
+        if (s->migration_thread_running) {
+            migrate_fd_cancel(s);
+        }
     }
 }
 
 static void vhost_log_global_stop(MemoryListener *listener)
 {
     int r;
+    MigrationState *s = NULL;
 
     r = vhost_migration_log(listener, false);
     if (r < 0) {
-        abort();
+        error_report("Failed to stop vhost dirty log");
+        s = migrate_get_current();
+        if (s->migration_thread_running) {
+            migrate_fd_cancel(s);
+        }
     }
 }
 
migration/migration.c +1 -1
index 4de3b55..6d2b7df 100644
@@ -1131,7 +1131,7 @@ void migrate_fd_error(MigrationState *s, const Error *error)
     block_cleanup_parameters(s);
 }
 
-static void migrate_fd_cancel(MigrationState *s)
+void migrate_fd_cancel(MigrationState *s)
 {
     int old_state ;
     QEMUFile *f = migrate_get_current()->to_dst_file;
migration/migration.h +1 -2
index 663415f..f0261e3 100644
@@ -167,7 +167,7 @@ uint64_t migrate_max_downtime(void);
 
 void migrate_set_error(MigrationState *s, const Error *error);
 void migrate_fd_error(MigrationState *s, const Error *error);
-
+void migrate_fd_cancel(MigrationState *s);
 void migrate_fd_connect(MigrationState *s);
 
 MigrationState *migrate_init(void);
--

1.8.3.1

Signature · 1 line
Marc-André Lureau
#2 lore raw
In reply to fangying
Quoted 6 lines · * fangying ([email protected]) wrote:

QEMU will abort when vhost-user process is restarted during migration and vhost_log_global_start/stop is called. The reason is clear that vhost_dev_set_log returns -1 because network connection is temporarily lost. To handle this situation, let's cancel migration here.

I thought we had agreed not to use migrate_fd_cancel here - that's for cancelling not erroring.

Dave

Quoted 82 lines
---
 hw/virtio/vhost.c     | 15 +++++++++++++--
 migration/migration.c |  2 +-
 migration/migration.h |  2 +-
 3 files changed, 15 insertions(+), 4 deletions(-)
hw/virtio/vhost.c +13 -2
index ddc42f0..e2ade93 100644
@@ -26,6 +26,7 @@
 #include "hw/virtio/virtio-bus.h"
 #include "hw/virtio/virtio-access.h"
 #include "migration/blocker.h"
+#include "migration/migration.h"
 #include "sysemu/dma.h"
 
 /* enabled until disconnected backend stabilizes */
@@ -882,20 +883,30 @@ static int vhost_migration_log(MemoryListener *listener, int enable)
 static void vhost_log_global_start(MemoryListener *listener)
 {
     int r;
+    MigrationState *s = NULL;
 
     r = vhost_migration_log(listener, true);
     if (r < 0) {
-        abort();
+        error_report("Failed to start vhost dirty log");
+        s = migrate_get_current();
+        if (s->migration_thread_running) {
+            migrate_fd_cancel(s);
+        }
     }
 }
 
 static void vhost_log_global_stop(MemoryListener *listener)
 {
     int r;
+    MigrationState *s = NULL;
 
     r = vhost_migration_log(listener, false);
     if (r < 0) {
-        abort();
+        error_report("Failed to stop vhost dirty log");
+        s = migrate_get_current();
+        if (s->migration_thread_running) {
+            migrate_fd_cancel(s);
+        }
     }
 }
 
migration/migration.c +1 -1
index 4de3b55..6d2b7df 100644
@@ -1131,7 +1131,7 @@ void migrate_fd_error(MigrationState *s, const Error *error)
     block_cleanup_parameters(s);
 }
 
-static void migrate_fd_cancel(MigrationState *s)
+void migrate_fd_cancel(MigrationState *s)
 {
     int old_state ;
     QEMUFile *f = migrate_get_current()->to_dst_file;
migration/migration.h +1 -1
index 663415f..f0261e3 100644
@@ -167,7 +167,7 @@ uint64_t migrate_max_downtime(void);
 
 void migrate_set_error(MigrationState *s, const Error *error);
 void migrate_fd_error(MigrationState *s, const Error *error);
-
+void migrate_fd_cancel(MigrationState *s);
 void migrate_fd_connect(MigrationState *s);
 
 MigrationState *migrate_init(void);
Signature · 1 line
1.8.3.1

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

author
#3 lore raw
Quoted 6 lines · Dr. David Alan Gilbert
Quoted 5 lines · * fangying ([email protected]) wrote:

QEMU will abort when vhost-user process is restarted during migration and vhost_log_global_start/stop is called. The reason is clear that vhost_dev_set_log returns -1 because network connection is temporarily lost. To handle this situation, let's cancel migration here.

Quoted 6 lines
Quoted 1 line

I thought we had agreed not to use migrate_fd_cancel here - that's for cancelling not erroring.

Dave

We can not use migrate_fd_error(migrate_get_current(),...) here, since it will touch the assertion of "s->to_dst_file", Is there any better solution ? Thanks.

void migrate_fd_error(MigrationState *s, const Error *error)

{
    trace_migrate_fd_error(error_get_pretty(error));
--> assert(s->to_dst_file == NULL);
    migrate_set_state(&s->state, MIGRATION_STATUS_SETUP,
                      MIGRATION_STATUS_FAILED);
    migrate_set_error(s, error);
    notifier_list_notify(&migration_state_notifiers, s);
    block_cleanup_parameters(s);
}
Quoted 88 lines
Quoted 83 lines
---
 hw/virtio/vhost.c     | 15 +++++++++++++--
 migration/migration.c |  2 +-
 migration/migration.h |  2 +-
 3 files changed, 15 insertions(+), 4 deletions(-)
hw/virtio/vhost.c +13 -2
index ddc42f0..e2ade93 100644
@@ -26,6 +26,7 @@
 #include "hw/virtio/virtio-bus.h"
 #include "hw/virtio/virtio-access.h"
 #include "migration/blocker.h"
+#include "migration/migration.h"
 #include "sysemu/dma.h"
 
 /* enabled until disconnected backend stabilizes */
@@ -882,20 +883,30 @@ static int vhost_migration_log(MemoryListener *listener, int enable)
 static void vhost_log_global_start(MemoryListener *listener)
 {
     int r;
+    MigrationState *s = NULL;
 
     r = vhost_migration_log(listener, true);
     if (r < 0) {
-        abort();
+        error_report("Failed to start vhost dirty log");
+        s = migrate_get_current();
+        if (s->migration_thread_running) {
+            migrate_fd_cancel(s);
+        }
     }
 }
 
 static void vhost_log_global_stop(MemoryListener *listener)
 {
     int r;
+    MigrationState *s = NULL;
 
     r = vhost_migration_log(listener, false);
     if (r < 0) {
-        abort();
+        error_report("Failed to stop vhost dirty log");
+        s = migrate_get_current();
+        if (s->migration_thread_running) {
+            migrate_fd_cancel(s);
+        }
     }
 }
 
migration/migration.c +1 -1
index 4de3b55..6d2b7df 100644
@@ -1131,7 +1131,7 @@ void migrate_fd_error(MigrationState *s, const Error *error)
     block_cleanup_parameters(s);
 }
 
-static void migrate_fd_cancel(MigrationState *s)
+void migrate_fd_cancel(MigrationState *s)
 {
     int old_state ;
     QEMUFile *f = migrate_get_current()->to_dst_file;
migration/migration.h +1 -1
index 663415f..f0261e3 100644
@@ -167,7 +167,7 @@ uint64_t migrate_max_downtime(void);
 
 void migrate_set_error(MigrationState *s, const Error *error);
 void migrate_fd_error(MigrationState *s, const Error *error);
-
+void migrate_fd_cancel(MigrationState *s);
 void migrate_fd_connect(MigrationState *s);
 
 MigrationState *migrate_init(void);
Signature · 1 line
1.8.3.1

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

.

#4 lore raw
Quoted 10 lines · * Ying Fang ([email protected]) wrote:
Quoted 8 lines · Dr. David Alan Gilbert
Quoted 6 lines · * fangying ([email protected]) wrote:

QEMU will abort when vhost-user process is restarted during migration and vhost_log_global_start/stop is called. The reason is clear that vhost_dev_set_log returns -1 because network connection is temporarily lost. To handle this situation, let's cancel migration here.

Quoted 7 lines
Quoted 4 lines

I thought we had agreed not to use migrate_fd_cancel here - that's for cancelling not erroring.

Dave

We can not use migrate_fd_error(migrate_get_current(),...) here, since it will touch the assertion of "s->to_dst_file", Is there any better solution ? Thanks.

How about:
error_report(....) qemu_file_set_error(migrate_get_current()->to_dst_file, -ECHILD);

But please, don't use cancel.

Dave

Quoted 100 lines

void migrate_fd_error(MigrationState *s, const Error *error)

{
    trace_migrate_fd_error(error_get_pretty(error));
--> assert(s->to_dst_file == NULL);
    migrate_set_state(&s->state, MIGRATION_STATUS_SETUP,
                      MIGRATION_STATUS_FAILED);
    migrate_set_error(s, error);
    notifier_list_notify(&migration_state_notifiers, s);
    block_cleanup_parameters(s);
}
Quoted 88 lines
Quoted 83 lines
---
 hw/virtio/vhost.c     | 15 +++++++++++++--
 migration/migration.c |  2 +-
 migration/migration.h |  2 +-
 3 files changed, 15 insertions(+), 4 deletions(-)
hw/virtio/vhost.c +13 -2
index ddc42f0..e2ade93 100644
@@ -26,6 +26,7 @@
 #include "hw/virtio/virtio-bus.h"
 #include "hw/virtio/virtio-access.h"
 #include "migration/blocker.h"
+#include "migration/migration.h"
 #include "sysemu/dma.h"
 
 /* enabled until disconnected backend stabilizes */
@@ -882,20 +883,30 @@ static int vhost_migration_log(MemoryListener *listener, int enable)
 static void vhost_log_global_start(MemoryListener *listener)
 {
     int r;
+    MigrationState *s = NULL;
 
     r = vhost_migration_log(listener, true);
     if (r < 0) {
-        abort();
+        error_report("Failed to start vhost dirty log");
+        s = migrate_get_current();
+        if (s->migration_thread_running) {
+            migrate_fd_cancel(s);
+        }
     }
 }
 
 static void vhost_log_global_stop(MemoryListener *listener)
 {
     int r;
+    MigrationState *s = NULL;
 
     r = vhost_migration_log(listener, false);
     if (r < 0) {
-        abort();
+        error_report("Failed to stop vhost dirty log");
+        s = migrate_get_current();
+        if (s->migration_thread_running) {
+            migrate_fd_cancel(s);
+        }
     }
 }
 
migration/migration.c +1 -1
index 4de3b55..6d2b7df 100644
@@ -1131,7 +1131,7 @@ void migrate_fd_error(MigrationState *s, const Error *error)
     block_cleanup_parameters(s);
 }
 
-static void migrate_fd_cancel(MigrationState *s)
+void migrate_fd_cancel(MigrationState *s)
 {
     int old_state ;
     QEMUFile *f = migrate_get_current()->to_dst_file;
migration/migration.h +1 -1
index 663415f..f0261e3 100644
@@ -167,7 +167,7 @@ uint64_t migrate_max_downtime(void);
 
 void migrate_set_error(MigrationState *s, const Error *error);
 void migrate_fd_error(MigrationState *s, const Error *error);
-
+void migrate_fd_cancel(MigrationState *s);
 void migrate_fd_connect(MigrationState *s);
 
 MigrationState *migrate_init(void);
Signature · 1 line
1.8.3.1

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

.

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

author
#5 lore raw
Quoted 19 lines · Dr. David Alan Gilbert
Quoted 10 lines · * Ying Fang ([email protected]) wrote:
Quoted 8 lines · Dr. David Alan Gilbert
Quoted 6 lines · * fangying ([email protected]) wrote:

QEMU will abort when vhost-user process is restarted during migration and vhost_log_global_start/stop is called. The reason is clear that vhost_dev_set_log returns -1 because network connection is temporarily lost. To handle this situation, let's cancel migration here.

Quoted 7 lines
Quoted 4 lines

I thought we had agreed not to use migrate_fd_cancel here - that's for cancelling not erroring.

Dave

We can not use migrate_fd_error(migrate_get_current(),...) here, since it will touch the assertion of "s->to_dst_file", Is there any better solution ? Thanks.

Quoted 7 lines

How about:
error_report(....) qemu_file_set_error(migrate_get_current()->to_dst_file, -ECHILD);

But please, don't use cancel.

Dave

Thanks for your advise, I test this approach and send the V4.

Ying

Quoted 106 lines
Quoted 101 lines

void migrate_fd_error(MigrationState *s, const Error *error)

{
    trace_migrate_fd_error(error_get_pretty(error));
--> assert(s->to_dst_file == NULL);
    migrate_set_state(&s->state, MIGRATION_STATUS_SETUP,
                      MIGRATION_STATUS_FAILED);
    migrate_set_error(s, error);
    notifier_list_notify(&migration_state_notifiers, s);
    block_cleanup_parameters(s);
}
Quoted 88 lines
Quoted 83 lines
---
 hw/virtio/vhost.c     | 15 +++++++++++++--
 migration/migration.c |  2 +-
 migration/migration.h |  2 +-
 3 files changed, 15 insertions(+), 4 deletions(-)
hw/virtio/vhost.c +13 -2
index ddc42f0..e2ade93 100644
@@ -26,6 +26,7 @@
 #include "hw/virtio/virtio-bus.h"
 #include "hw/virtio/virtio-access.h"
 #include "migration/blocker.h"
+#include "migration/migration.h"
 #include "sysemu/dma.h"
 
 /* enabled until disconnected backend stabilizes */
@@ -882,20 +883,30 @@ static int vhost_migration_log(MemoryListener *listener, int enable)
 static void vhost_log_global_start(MemoryListener *listener)
 {
     int r;
+    MigrationState *s = NULL;
 
     r = vhost_migration_log(listener, true);
     if (r < 0) {
-        abort();
+        error_report("Failed to start vhost dirty log");
+        s = migrate_get_current();
+        if (s->migration_thread_running) {
+            migrate_fd_cancel(s);
+        }
     }
 }
 
 static void vhost_log_global_stop(MemoryListener *listener)
 {
     int r;
+    MigrationState *s = NULL;
 
     r = vhost_migration_log(listener, false);
     if (r < 0) {
-        abort();
+        error_report("Failed to stop vhost dirty log");
+        s = migrate_get_current();
+        if (s->migration_thread_running) {
+            migrate_fd_cancel(s);
+        }
     }
 }
 
migration/migration.c +1 -1
index 4de3b55..6d2b7df 100644
@@ -1131,7 +1131,7 @@ void migrate_fd_error(MigrationState *s, const Error *error)
     block_cleanup_parameters(s);
 }
 
-static void migrate_fd_cancel(MigrationState *s)
+void migrate_fd_cancel(MigrationState *s)
 {
     int old_state ;
     QEMUFile *f = migrate_get_current()->to_dst_file;
migration/migration.h +1 -1
index 663415f..f0261e3 100644
@@ -167,7 +167,7 @@ uint64_t migrate_max_downtime(void);
 
 void migrate_set_error(MigrationState *s, const Error *error);
 void migrate_fd_error(MigrationState *s, const Error *error);
-
+void migrate_fd_cancel(MigrationState *s);
 void migrate_fd_connect(MigrationState *s);
 
 MigrationState *migrate_init(void);
Signature · 1 line
1.8.3.1

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

.

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

.