131 lines
4.1 KiB
Diff
131 lines
4.1 KiB
Diff
|
|
From 12cf5e9ece9cb0825f14ca80f6b1c5d1eb95c3e5 Mon Sep 17 00:00:00 2001
|
||
|
|
From: Jinhua Cao <caojinhua1@huawei.com>
|
||
|
|
Date: Fri, 11 Feb 2022 18:59:34 +0800
|
||
|
|
Subject: [PATCH] vhost-user: add vhost_set_mem_table when vm load_setup at
|
||
|
|
destination
|
||
|
|
|
||
|
|
When migrate huge vm, packages lost are 90+.
|
||
|
|
|
||
|
|
During the load_setup of the destination vm, pass the
|
||
|
|
vm mem structure to ovs, the netcard could be enabled
|
||
|
|
when the migration finish state shifting.
|
||
|
|
|
||
|
|
Signed-off-by: Jinhua Cao <caojinhua1@huawei.com>
|
||
|
|
---
|
||
|
|
hw/virtio/vhost-user.c | 24 ++++++++++++++++++++++++
|
||
|
|
tests/qtest/vhost-user-test.c | 35 ++++++++++++++++++-----------------
|
||
|
|
2 files changed, 42 insertions(+), 17 deletions(-)
|
||
|
|
|
||
|
|
diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c
|
||
|
|
index f214df804b..6739dfc98e 100644
|
||
|
|
--- a/hw/virtio/vhost-user.c
|
||
|
|
+++ b/hw/virtio/vhost-user.c
|
||
|
|
@@ -28,6 +28,7 @@
|
||
|
|
#include "sysemu/cryptodev.h"
|
||
|
|
#include "migration/migration.h"
|
||
|
|
#include "migration/postcopy-ram.h"
|
||
|
|
+#include "migration/register.h"
|
||
|
|
#include "trace.h"
|
||
|
|
#include "exec/ramblock.h"
|
||
|
|
|
||
|
|
@@ -2119,6 +2120,28 @@ static int vhost_user_postcopy_notifier(NotifierWithReturn *notifier,
|
||
|
|
return 0;
|
||
|
|
}
|
||
|
|
|
||
|
|
+static int vhost_user_load_setup(QEMUFile *f, void *opaque)
|
||
|
|
+{
|
||
|
|
+ struct vhost_dev *hdev = opaque;
|
||
|
|
+ int r;
|
||
|
|
+
|
||
|
|
+ if (hdev->vhost_ops && hdev->vhost_ops->vhost_set_mem_table) {
|
||
|
|
+ r = hdev->vhost_ops->vhost_set_mem_table(hdev, hdev->mem);
|
||
|
|
+ if (r < 0) {
|
||
|
|
+ qemu_log("error: vhost_set_mem_table failed: %s(%d)\n",
|
||
|
|
+ strerror(errno), errno);
|
||
|
|
+ return r;
|
||
|
|
+ } else {
|
||
|
|
+ qemu_log("info: vhost_set_mem_table OK\n");
|
||
|
|
+ }
|
||
|
|
+ }
|
||
|
|
+ return 0;
|
||
|
|
+}
|
||
|
|
+
|
||
|
|
+SaveVMHandlers savevm_vhost_user_handlers = {
|
||
|
|
+ .load_setup = vhost_user_load_setup,
|
||
|
|
+};
|
||
|
|
+
|
||
|
|
static int vhost_user_backend_init(struct vhost_dev *dev, void *opaque,
|
||
|
|
Error **errp)
|
||
|
|
{
|
||
|
|
@@ -2255,6 +2278,7 @@ static int vhost_user_backend_init(struct vhost_dev *dev, void *opaque,
|
||
|
|
|
||
|
|
u->postcopy_notifier.notify = vhost_user_postcopy_notifier;
|
||
|
|
postcopy_add_notifier(&u->postcopy_notifier);
|
||
|
|
+ register_savevm_live("vhost-user", -1, 1, &savevm_vhost_user_handlers, dev);
|
||
|
|
|
||
|
|
return 0;
|
||
|
|
}
|
||
|
|
diff --git a/tests/qtest/vhost-user-test.c b/tests/qtest/vhost-user-test.c
|
||
|
|
index d4e437265f..fadf3f0f2e 100644
|
||
|
|
--- a/tests/qtest/vhost-user-test.c
|
||
|
|
+++ b/tests/qtest/vhost-user-test.c
|
||
|
|
@@ -799,6 +799,23 @@ static void test_read_guest_mem(void *obj, void *arg, QGuestAllocator *alloc)
|
||
|
|
read_guest_mem_server(global_qtest, server);
|
||
|
|
}
|
||
|
|
|
||
|
|
+static void wait_for_rings_started(TestServer *s, size_t count)
|
||
|
|
+{
|
||
|
|
+ gint64 end_time;
|
||
|
|
+
|
||
|
|
+ g_mutex_lock(&s->data_mutex);
|
||
|
|
+ end_time = g_get_monotonic_time() + 5 * G_TIME_SPAN_SECOND;
|
||
|
|
+ while (ctpop64(s->rings) != count) {
|
||
|
|
+ if (!g_cond_wait_until(&s->data_cond, &s->data_mutex, end_time)) {
|
||
|
|
+ /* timeout has passed */
|
||
|
|
+ g_assert_cmpint(ctpop64(s->rings), ==, count);
|
||
|
|
+ break;
|
||
|
|
+ }
|
||
|
|
+ }
|
||
|
|
+
|
||
|
|
+ g_mutex_unlock(&s->data_mutex);
|
||
|
|
+}
|
||
|
|
+
|
||
|
|
static void test_migrate(void *obj, void *arg, QGuestAllocator *alloc)
|
||
|
|
{
|
||
|
|
TestServer *s = arg;
|
||
|
|
@@ -869,6 +886,7 @@ static void test_migrate(void *obj, void *arg, QGuestAllocator *alloc)
|
||
|
|
qtest_qmp_eventwait(to, "RESUME");
|
||
|
|
|
||
|
|
g_assert(wait_for_fds(dest));
|
||
|
|
+ wait_for_rings_started(dest, 2);
|
||
|
|
read_guest_mem_server(to, dest);
|
||
|
|
|
||
|
|
g_source_destroy(source);
|
||
|
|
@@ -880,23 +898,6 @@ static void test_migrate(void *obj, void *arg, QGuestAllocator *alloc)
|
||
|
|
g_string_free(dest_cmdline, true);
|
||
|
|
}
|
||
|
|
|
||
|
|
-static void wait_for_rings_started(TestServer *s, size_t count)
|
||
|
|
-{
|
||
|
|
- gint64 end_time;
|
||
|
|
-
|
||
|
|
- g_mutex_lock(&s->data_mutex);
|
||
|
|
- end_time = g_get_monotonic_time() + 5 * G_TIME_SPAN_SECOND;
|
||
|
|
- while (ctpop64(s->rings) != count) {
|
||
|
|
- if (!g_cond_wait_until(&s->data_cond, &s->data_mutex, end_time)) {
|
||
|
|
- /* timeout has passed */
|
||
|
|
- g_assert_cmpint(ctpop64(s->rings), ==, count);
|
||
|
|
- break;
|
||
|
|
- }
|
||
|
|
- }
|
||
|
|
-
|
||
|
|
- g_mutex_unlock(&s->data_mutex);
|
||
|
|
-}
|
||
|
|
-
|
||
|
|
static inline void test_server_connect(TestServer *server)
|
||
|
|
{
|
||
|
|
test_server_create_chr(server, ",reconnect=1");
|
||
|
|
--
|
||
|
|
2.27.0
|
||
|
|
|