* [PATCH v9 1/8] migration: introduce .pre_incoming() vmsd handler
2025-10-30 20:31 [PATCH v9 0/8] virtio-net: live-TAP local migration Vladimir Sementsov-Ogievskiy
@ 2025-10-30 20:31 ` Vladimir Sementsov-Ogievskiy
2025-10-30 20:31 ` [PATCH v9 2/8] qapi: introduce query-backend-transfer-support Vladimir Sementsov-Ogievskiy
` (6 subsequent siblings)
7 siblings, 0 replies; 14+ messages in thread
From: Vladimir Sementsov-Ogievskiy @ 2025-10-30 20:31 UTC (permalink / raw)
To: mst, jasowang
Cc: pbonzini, berrange, eduardo, peterx, farosas, eblake, armbru,
thuth, philmd, zhao1.liu, qemu-devel, leiyang, davydov-max,
yc-core, vsementsov, raphael.s.norwitz
Add possibility for devices to hook into top of migrate-incoming QMP
command. It's a place, where migration capabilities and parameters
are already set, but migration downtime is not yet started (source
is still running). So here devices may do some remaining initializations
dependent on migration capabilities. This will be used in further commit
to support backend-transfer migration feature for vhost-user-blk.
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
Acked-by: Peter Xu <peterx@redhat.com>
---
include/migration/vmstate.h | 1 +
migration/migration.c | 4 ++++
migration/savevm.c | 15 +++++++++++++++
migration/savevm.h | 1 +
4 files changed, 21 insertions(+)
diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h
index 09f1eefcfb..6ea5b212f2 100644
--- a/include/migration/vmstate.h
+++ b/include/migration/vmstate.h
@@ -217,6 +217,7 @@ struct VMStateDescription {
int version_id;
int minimum_version_id;
MigrationPriority priority;
+ bool (*pre_incoming)(void *opaque, Error **errp);
int (*pre_load)(void *opaque);
int (*pre_load_errp)(void *opaque, Error **errp);
int (*post_load)(void *opaque, int version_id);
diff --git a/migration/migration.c b/migration/migration.c
index a63b46bbef..6ed6a10f57 100644
--- a/migration/migration.c
+++ b/migration/migration.c
@@ -1983,6 +1983,10 @@ void qmp_migrate_incoming(const char *uri, bool has_channels,
return;
}
+ if (!qemu_pre_incoming(errp)) {
+ return;
+ }
+
if (!yank_register_instance(MIGRATION_YANK_INSTANCE, errp)) {
return;
}
diff --git a/migration/savevm.c b/migration/savevm.c
index 7b35ec4dd0..6e240ea100 100644
--- a/migration/savevm.c
+++ b/migration/savevm.c
@@ -1268,6 +1268,21 @@ bool qemu_savevm_state_blocked(Error **errp)
return false;
}
+bool qemu_pre_incoming(Error **errp)
+{
+ SaveStateEntry *se;
+
+ QTAILQ_FOREACH(se, &savevm_state.handlers, entry) {
+ if (se->vmsd && se->vmsd->pre_incoming) {
+ if (!se->vmsd->pre_incoming(se->opaque, errp)) {
+ return false;
+ }
+ }
+ }
+
+ return true;
+}
+
void qemu_savevm_non_migratable_list(strList **reasons)
{
SaveStateEntry *se;
diff --git a/migration/savevm.h b/migration/savevm.h
index c337e3e3d1..4ad8997f94 100644
--- a/migration/savevm.h
+++ b/migration/savevm.h
@@ -29,6 +29,7 @@
#define QEMU_VM_COMMAND 0x08
#define QEMU_VM_SECTION_FOOTER 0x7e
+bool qemu_pre_incoming(Error **errp);
bool qemu_savevm_state_blocked(Error **errp);
void qemu_savevm_non_migratable_list(strList **reasons);
int qemu_savevm_state_prepare(Error **errp);
--
2.48.1
^ permalink raw reply related [flat|nested] 14+ messages in thread* [PATCH v9 2/8] qapi: introduce query-backend-transfer-support
2025-10-30 20:31 [PATCH v9 0/8] virtio-net: live-TAP local migration Vladimir Sementsov-Ogievskiy
2025-10-30 20:31 ` [PATCH v9 1/8] migration: introduce .pre_incoming() vmsd handler Vladimir Sementsov-Ogievskiy
@ 2025-10-30 20:31 ` Vladimir Sementsov-Ogievskiy
2025-11-06 15:30 ` Markus Armbruster
2025-10-30 20:31 ` [PATCH v9 3/8] qapi: add backend-transfer migration parameter Vladimir Sementsov-Ogievskiy
` (5 subsequent siblings)
7 siblings, 1 reply; 14+ messages in thread
From: Vladimir Sementsov-Ogievskiy @ 2025-10-30 20:31 UTC (permalink / raw)
To: mst, jasowang
Cc: pbonzini, berrange, eduardo, peterx, farosas, eblake, armbru,
thuth, philmd, zhao1.liu, qemu-devel, leiyang, davydov-max,
yc-core, vsementsov, raphael.s.norwitz
We are going to implement backend-transfer feature: some devices
will be able to transfer their backend through migration stream
for local migration through UNIX domain socket. For example,
virtio-net will migrate its attached TAP netdev, with all its
connected file descriptors.
Let's add a command to list supporting devices (no one for now),
together with necessary infrastructure in qdev code.
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
---
include/hw/qdev-core.h | 7 +++++++
qapi/qdev.json | 26 +++++++++++++++++++++++++
system/qdev-monitor.c | 43 ++++++++++++++++++++++++++++++++++++++++++
3 files changed, 76 insertions(+)
diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h
index 2caa0cbd26..0551fbaa6c 100644
--- a/include/hw/qdev-core.h
+++ b/include/hw/qdev-core.h
@@ -96,6 +96,7 @@ typedef void (*DeviceReset)(DeviceState *dev);
typedef void (*BusRealize)(BusState *bus, Error **errp);
typedef void (*BusUnrealize)(BusState *bus);
typedef int (*DeviceSyncConfig)(DeviceState *dev, Error **errp);
+typedef bool (*DeviceSupportBackendTransfer)(DeviceState *dev, Error **errp);
/**
* struct DeviceClass - The base class for all devices.
@@ -174,6 +175,12 @@ struct DeviceClass {
DeviceUnrealize unrealize;
DeviceSyncConfig sync_config;
+ /**
+ * @backend_transfer_support: reports support for backend-transfer
+ * migration of the device.
+ */
+ DeviceSupportBackendTransfer backend_transfer_support;
+
/**
* @vmsd: device state serialisation description for
* migration/save/restore
diff --git a/qapi/qdev.json b/qapi/qdev.json
index e14a0c9259..d7e878d58d 100644
--- a/qapi/qdev.json
+++ b/qapi/qdev.json
@@ -188,3 +188,29 @@
{ 'command': 'device-sync-config',
'features': [ 'unstable' ],
'data': {'id': 'str'} }
+
+##
+# @DevPath:
+#
+# @path: the device's QOM path
+#
+# Since: 10.2
+##
+{ 'struct': 'DevPath',
+ 'data': { 'path': 'str' } }
+
+##
+# @query-backend-transfer-support:
+#
+# Returns list of devices, supporting backend-transfer
+# migration.
+#
+# Features:
+#
+# @unstable: The command is experimental.
+#
+# Since: 10.2
+##
+{ 'command': 'query-backend-transfer-support',
+ 'features': [ 'unstable' ],
+ 'returns': [ 'DevPath' ] }
diff --git a/system/qdev-monitor.c b/system/qdev-monitor.c
index ec4a2394ce..9d3d961c15 100644
--- a/system/qdev-monitor.c
+++ b/system/qdev-monitor.c
@@ -939,6 +939,49 @@ void qmp_device_del(const char *id, Error **errp)
}
}
+static bool qdev_backend_transfer_support(DeviceState *dev, Error **errp)
+{
+ DeviceClass *dc = DEVICE_GET_CLASS(dev);
+
+ if (!dc->backend_transfer_support) {
+ error_setg(errp, "backend-transfer is not supported for '%s'",
+ object_get_typename(OBJECT(dev)));
+ return false;
+ }
+
+ return dc->backend_transfer_support(dev, errp);
+}
+
+static int qdev_add_if_backend_transfer_supported(Object *obj, void *opaque)
+{
+ DevPathList **list = opaque;
+ DeviceState *dev = (DeviceState *)object_dynamic_cast(obj, TYPE_DEVICE);
+
+ if (dev != NULL && qdev_backend_transfer_support(dev, NULL)) {
+ DevPath *el = g_new(DevPath, 1);
+ *el = (DevPath) {
+ .path = g_strdup(dev->canonical_path),
+ };
+ QAPI_LIST_PREPEND(*list, el);
+ }
+
+ /* Recursively check all children */
+ object_child_foreach(obj, qdev_add_if_backend_transfer_supported, opaque);
+
+ return 0;
+}
+
+DevPathList *qmp_query_backend_transfer_support(Error **errp)
+{
+ DevPathList *result = NULL;
+ Object *peripheral = machine_get_container("peripheral");
+
+ object_child_foreach(peripheral, qdev_add_if_backend_transfer_supported,
+ &result);
+
+ return result;
+}
+
int qdev_sync_config(DeviceState *dev, Error **errp)
{
DeviceClass *dc = DEVICE_GET_CLASS(dev);
--
2.48.1
^ permalink raw reply related [flat|nested] 14+ messages in thread* Re: [PATCH v9 2/8] qapi: introduce query-backend-transfer-support
2025-10-30 20:31 ` [PATCH v9 2/8] qapi: introduce query-backend-transfer-support Vladimir Sementsov-Ogievskiy
@ 2025-11-06 15:30 ` Markus Armbruster
2025-11-06 19:27 ` Vladimir Sementsov-Ogievskiy
0 siblings, 1 reply; 14+ messages in thread
From: Markus Armbruster @ 2025-11-06 15:30 UTC (permalink / raw)
To: Vladimir Sementsov-Ogievskiy
Cc: mst, jasowang, pbonzini, berrange, eduardo, peterx, farosas,
eblake, thuth, philmd, zhao1.liu, qemu-devel, leiyang,
davydov-max, yc-core, raphael.s.norwitz
Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru> writes:
> We are going to implement backend-transfer feature: some devices
> will be able to transfer their backend through migration stream
> for local migration through UNIX domain socket. For example,
> virtio-net will migrate its attached TAP netdev, with all its
> connected file descriptors.
>
> Let's add a command to list supporting devices (no one for now),
> together with necessary infrastructure in qdev code.
Use case?
> Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
> ---
> include/hw/qdev-core.h | 7 +++++++
> qapi/qdev.json | 26 +++++++++++++++++++++++++
> system/qdev-monitor.c | 43 ++++++++++++++++++++++++++++++++++++++++++
> 3 files changed, 76 insertions(+)
>
> diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h
> index 2caa0cbd26..0551fbaa6c 100644
> --- a/include/hw/qdev-core.h
> +++ b/include/hw/qdev-core.h
> @@ -96,6 +96,7 @@ typedef void (*DeviceReset)(DeviceState *dev);
> typedef void (*BusRealize)(BusState *bus, Error **errp);
> typedef void (*BusUnrealize)(BusState *bus);
> typedef int (*DeviceSyncConfig)(DeviceState *dev, Error **errp);
> +typedef bool (*DeviceSupportBackendTransfer)(DeviceState *dev, Error **errp);
>
> /**
> * struct DeviceClass - The base class for all devices.
> @@ -174,6 +175,12 @@ struct DeviceClass {
> DeviceUnrealize unrealize;
> DeviceSyncConfig sync_config;
>
> + /**
> + * @backend_transfer_support: reports support for backend-transfer
> + * migration of the device.
> + */
> + DeviceSupportBackendTransfer backend_transfer_support;
> +
> /**
> * @vmsd: device state serialisation description for
> * migration/save/restore
> diff --git a/qapi/qdev.json b/qapi/qdev.json
> index e14a0c9259..d7e878d58d 100644
> --- a/qapi/qdev.json
> +++ b/qapi/qdev.json
> @@ -188,3 +188,29 @@
> { 'command': 'device-sync-config',
> 'features': [ 'unstable' ],
> 'data': {'id': 'str'} }
> +
> +##
> +# @DevPath:
> +#
> +# @path: the device's QOM path
> +#
> +# Since: 10.2
> +##
> +{ 'struct': 'DevPath',
> + 'data': { 'path': 'str' } }
> +
> +##
> +# @query-backend-transfer-support:
> +#
> +# Returns list of devices, supporting backend-transfer
> +# migration.
Suggest
# Return the devices that support backend-transfer migration.
> +#
> +# Features:
> +#
> +# @unstable: The command is experimental.
The conventional text ist "This command is experimental."
> +#
> +# Since: 10.2
> +##
> +{ 'command': 'query-backend-transfer-support',
> + 'features': [ 'unstable' ],
> + 'returns': [ 'DevPath' ] }
> diff --git a/system/qdev-monitor.c b/system/qdev-monitor.c
> index ec4a2394ce..9d3d961c15 100644
> --- a/system/qdev-monitor.c
> +++ b/system/qdev-monitor.c
> @@ -939,6 +939,49 @@ void qmp_device_del(const char *id, Error **errp)
> }
> }
>
> +static bool qdev_backend_transfer_support(DeviceState *dev, Error **errp)
> +{
> + DeviceClass *dc = DEVICE_GET_CLASS(dev);
> +
> + if (!dc->backend_transfer_support) {
> + error_setg(errp, "backend-transfer is not supported for '%s'",
> + object_get_typename(OBJECT(dev)));
> + return false;
> + }
> +
> + return dc->backend_transfer_support(dev, errp);
> +}
@errp is useless in this patch: the only caller passes NULL. Took me a
minute to check it doesn't remain useless. The next patch puts it to
use.
> +
> +static int qdev_add_if_backend_transfer_supported(Object *obj, void *opaque)
> +{
> + DevPathList **list = opaque;
> + DeviceState *dev = (DeviceState *)object_dynamic_cast(obj, TYPE_DEVICE);
> +
> + if (dev != NULL && qdev_backend_transfer_support(dev, NULL)) {
> + DevPath *el = g_new(DevPath, 1);
> + *el = (DevPath) {
> + .path = g_strdup(dev->canonical_path),
> + };
> + QAPI_LIST_PREPEND(*list, el);
> + }
> +
> + /* Recursively check all children */
> + object_child_foreach(obj, qdev_add_if_backend_transfer_supported, opaque);
> +
> + return 0;
> +}
> +
> +DevPathList *qmp_query_backend_transfer_support(Error **errp)
> +{
> + DevPathList *result = NULL;
> + Object *peripheral = machine_get_container("peripheral");
> +
> + object_child_foreach(peripheral, qdev_add_if_backend_transfer_supported,
> + &result);
> +
> + return result;
> +}
> +
> int qdev_sync_config(DeviceState *dev, Error **errp)
> {
> DeviceClass *dc = DEVICE_GET_CLASS(dev);
^ permalink raw reply [flat|nested] 14+ messages in thread* Re: [PATCH v9 2/8] qapi: introduce query-backend-transfer-support
2025-11-06 15:30 ` Markus Armbruster
@ 2025-11-06 19:27 ` Vladimir Sementsov-Ogievskiy
2025-11-07 5:28 ` Markus Armbruster
0 siblings, 1 reply; 14+ messages in thread
From: Vladimir Sementsov-Ogievskiy @ 2025-11-06 19:27 UTC (permalink / raw)
To: Markus Armbruster
Cc: mst, jasowang, pbonzini, berrange, eduardo, peterx, farosas,
eblake, thuth, philmd, zhao1.liu, qemu-devel, leiyang,
davydov-max, yc-core, raphael.s.norwitz
On 06.11.25 18:30, Markus Armbruster wrote:
> Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru> writes:
>
>> We are going to implement backend-transfer feature: some devices
>> will be able to transfer their backend through migration stream
>> for local migration through UNIX domain socket. For example,
>> virtio-net will migrate its attached TAP netdev, with all its
>> connected file descriptors.
>>
>> Let's add a command to list supporting devices (no one for now),
>> together with necessary infrastructure in qdev code.
>
> Use case?
Will add:
With this command management tool can query such lists on source and
target, and get intersection of them, to now the set of devices, for
which we can enable backend-transfer for given source and target QEMUs.
>
>> Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
>> ---
>> include/hw/qdev-core.h | 7 +++++++
>> qapi/qdev.json | 26 +++++++++++++++++++++++++
>> system/qdev-monitor.c | 43 ++++++++++++++++++++++++++++++++++++++++++
>> 3 files changed, 76 insertions(+)
>>
>> diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h
>> index 2caa0cbd26..0551fbaa6c 100644
--
Best regards,
Vladimir
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH v9 2/8] qapi: introduce query-backend-transfer-support
2025-11-06 19:27 ` Vladimir Sementsov-Ogievskiy
@ 2025-11-07 5:28 ` Markus Armbruster
2025-11-07 6:09 ` Vladimir Sementsov-Ogievskiy
0 siblings, 1 reply; 14+ messages in thread
From: Markus Armbruster @ 2025-11-07 5:28 UTC (permalink / raw)
To: Vladimir Sementsov-Ogievskiy
Cc: mst, jasowang, pbonzini, berrange, eduardo, peterx, farosas,
eblake, thuth, philmd, zhao1.liu, qemu-devel, leiyang,
davydov-max, yc-core, raphael.s.norwitz
Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru> writes:
> On 06.11.25 18:30, Markus Armbruster wrote:
>> Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru> writes:
>>
>>> We are going to implement backend-transfer feature: some devices
>>> will be able to transfer their backend through migration stream
>>> for local migration through UNIX domain socket. For example,
>>> virtio-net will migrate its attached TAP netdev, with all its
>>> connected file descriptors.
>>>
>>> Let's add a command to list supporting devices (no one for now),
>>> together with necessary infrastructure in qdev code.
>>
>> Use case?
>
> Will add:
>
> With this command management tool can query such lists on source and
> target, and get intersection of them, to now the set of devices, for
> which we can enable backend-transfer for given source and target QEMUs.
I like it. Would it make sense to add something similar to QAPI schema
doc comments?
[...]
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH v9 2/8] qapi: introduce query-backend-transfer-support
2025-11-07 5:28 ` Markus Armbruster
@ 2025-11-07 6:09 ` Vladimir Sementsov-Ogievskiy
0 siblings, 0 replies; 14+ messages in thread
From: Vladimir Sementsov-Ogievskiy @ 2025-11-07 6:09 UTC (permalink / raw)
To: Markus Armbruster
Cc: mst, jasowang, pbonzini, berrange, eduardo, peterx, farosas,
eblake, thuth, philmd, zhao1.liu, qemu-devel, leiyang,
davydov-max, yc-core, raphael.s.norwitz
On 07.11.25 08:28, Markus Armbruster wrote:
> Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru> writes:
>
>> On 06.11.25 18:30, Markus Armbruster wrote:
>>> Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru> writes:
>>>
>>>> We are going to implement backend-transfer feature: some devices
>>>> will be able to transfer their backend through migration stream
>>>> for local migration through UNIX domain socket. For example,
>>>> virtio-net will migrate its attached TAP netdev, with all its
>>>> connected file descriptors.
>>>>
>>>> Let's add a command to list supporting devices (no one for now),
>>>> together with necessary infrastructure in qdev code.
>>>
>>> Use case?
>>
>> Will add:
>>
>> With this command management tool can query such lists on source and
>> target, and get intersection of them, to now the set of devices, for
>> which we can enable backend-transfer for given source and target QEMUs.
>
> I like it. Would it make sense to add something similar to QAPI schema
> doc comments?
>
Agree, will do.
--
Best regards,
Vladimir
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH v9 3/8] qapi: add backend-transfer migration parameter
2025-10-30 20:31 [PATCH v9 0/8] virtio-net: live-TAP local migration Vladimir Sementsov-Ogievskiy
2025-10-30 20:31 ` [PATCH v9 1/8] migration: introduce .pre_incoming() vmsd handler Vladimir Sementsov-Ogievskiy
2025-10-30 20:31 ` [PATCH v9 2/8] qapi: introduce query-backend-transfer-support Vladimir Sementsov-Ogievskiy
@ 2025-10-30 20:31 ` Vladimir Sementsov-Ogievskiy
2025-11-06 15:44 ` Markus Armbruster
2025-10-30 20:31 ` [PATCH v9 4/8] net: introduce vmstate_net_peer_backend Vladimir Sementsov-Ogievskiy
` (4 subsequent siblings)
7 siblings, 1 reply; 14+ messages in thread
From: Vladimir Sementsov-Ogievskiy @ 2025-10-30 20:31 UTC (permalink / raw)
To: mst, jasowang
Cc: pbonzini, berrange, eduardo, peterx, farosas, eblake, armbru,
thuth, philmd, zhao1.liu, qemu-devel, leiyang, davydov-max,
yc-core, vsementsov, raphael.s.norwitz
We are going to implement backend-transfer feature: some devices
will be able to transfer their backend through migration stream
for local migration through UNIX domain socket. For example,
virtio-net will migrate its attached TAP netdev, with all its
connected file descriptors.
In this commit we introduce a migration parameter, which pick
devices for backend-transfer migration in context of next
outgoing or incoming migration. Of course, user is responsible
to pick same set of devices on source and target.
QMP command query-backend-transfer-support command may help
to prepare such set as intersection of
query-backend-transfer-support results on source and target.
With this commit, no device yet support backend-transfer,
so passing something other then empty list to backend-transfer
migration parameter will fail.
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
---
include/hw/qdev-core.h | 3 +++
include/migration/misc.h | 2 ++
migration/options.c | 31 +++++++++++++++++++++++++++++++
qapi/migration.json | 35 +++++++++++++++++++++++++++++------
system/qdev-monitor.c | 31 +++++++++++++++++++++++++++++++
5 files changed, 96 insertions(+), 6 deletions(-)
diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h
index 0551fbaa6c..9ed0b3f04d 100644
--- a/include/hw/qdev-core.h
+++ b/include/hw/qdev-core.h
@@ -1168,4 +1168,7 @@ typedef enum MachineInitPhase {
bool phase_check(MachineInitPhase phase);
void phase_advance(MachineInitPhase phase);
+bool migrate_backend_transfer(DeviceState *dev);
+bool migrate_backend_transfer_check_list(const strList *list, Error **errp);
+
#endif
diff --git a/include/migration/misc.h b/include/migration/misc.h
index 592b93021e..7f931bed17 100644
--- a/include/migration/misc.h
+++ b/include/migration/misc.h
@@ -152,4 +152,6 @@ bool multifd_device_state_save_thread_should_exit(void);
void multifd_abort_device_state_save_threads(void);
bool multifd_join_device_state_save_threads(void);
+const strList *migrate_backend_transfer_list(void);
+
#endif
diff --git a/migration/options.c b/migration/options.c
index 5183112775..1644728ed7 100644
--- a/migration/options.c
+++ b/migration/options.c
@@ -13,6 +13,7 @@
#include "qemu/osdep.h"
#include "qemu/error-report.h"
+#include "qapi/util.h"
#include "exec/target_page.h"
#include "qapi/clone-visitor.h"
#include "qapi/error.h"
@@ -24,6 +25,7 @@
#include "migration/colo.h"
#include "migration/cpr.h"
#include "migration/misc.h"
+#include "migration/options.h"
#include "migration.h"
#include "migration-stats.h"
#include "qemu-file.h"
@@ -262,6 +264,12 @@ bool migrate_mapped_ram(void)
return s->capabilities[MIGRATION_CAPABILITY_MAPPED_RAM];
}
+const strList *migrate_backend_transfer_list(void)
+{
+ MigrationState *s = migrate_get_current();
+ return s->parameters.backend_transfer;
+}
+
bool migrate_ignore_shared(void)
{
MigrationState *s = migrate_get_current();
@@ -963,6 +971,12 @@ MigrationParameters *qmp_query_migrate_parameters(Error **errp)
params->cpr_exec_command = QAPI_CLONE(strList,
s->parameters.cpr_exec_command);
+ if (s->parameters.backend_transfer) {
+ params->has_backend_transfer = true;
+ params->backend_transfer = QAPI_CLONE(strList,
+ s->parameters.backend_transfer);
+ }
+
return params;
}
@@ -997,6 +1011,7 @@ void migrate_params_init(MigrationParameters *params)
params->has_zero_page_detection = true;
params->has_direct_io = true;
params->has_cpr_exec_command = true;
+ params->has_backend_transfer = true;
}
/*
@@ -1183,6 +1198,11 @@ bool migrate_params_check(MigrationParameters *params, Error **errp)
return false;
}
+ if (params->has_backend_transfer &&
+ !migrate_backend_transfer_check_list(params->backend_transfer, errp)) {
+ return false;
+ }
+
return true;
}
@@ -1305,6 +1325,10 @@ static void migrate_params_test_apply(MigrateSetParameters *params,
if (params->has_cpr_exec_command) {
dest->cpr_exec_command = params->cpr_exec_command;
}
+
+ if (params->has_backend_transfer) {
+ dest->backend_transfer = params->backend_transfer;
+ }
}
static void migrate_params_apply(MigrateSetParameters *params, Error **errp)
@@ -1443,6 +1467,13 @@ static void migrate_params_apply(MigrateSetParameters *params, Error **errp)
s->parameters.cpr_exec_command =
QAPI_CLONE(strList, params->cpr_exec_command);
}
+
+ if (params->has_backend_transfer) {
+ qapi_free_strList(s->parameters.backend_transfer);
+
+ s->parameters.backend_transfer = QAPI_CLONE(strList,
+ params->backend_transfer);
+ }
}
void qmp_migrate_set_parameters(MigrateSetParameters *params, Error **errp)
diff --git a/qapi/migration.json b/qapi/migration.json
index be0f3fcc12..9478c4ddab 100644
--- a/qapi/migration.json
+++ b/qapi/migration.json
@@ -951,9 +951,15 @@
# is @cpr-exec. The first list element is the program's filename,
# the remainder its arguments. (Since 10.2)
#
+# @backend-transfer: List of devices (IDs or QOM paths) for
+# backend-transfer migration. When enabled, device backends
+# including opened fds will be passed to the destination in the
+# migration channel (which must be a UNIX domain socket). Default
+# is no backend-transfer migration. (Since 10.2)
+#
# Features:
#
-# @unstable: Members @x-checkpoint-delay and
+# @unstable: Members @backend-transfer, @x-checkpoint-delay and
# @x-vcpu-dirty-limit-period are experimental.
#
# Since: 2.4
@@ -978,7 +984,8 @@
'mode',
'zero-page-detection',
'direct-io',
- 'cpr-exec-command'] }
+ 'cpr-exec-command',
+ { 'name': 'backend-transfer', 'features': ['unstable'] } ] }
##
# @MigrateSetParameters:
@@ -1137,9 +1144,15 @@
# is @cpr-exec. The first list element is the program's filename,
# the remainder its arguments. (Since 10.2)
#
+# @backend-transfer: List of devices (IDs or QOM paths) for
+# backend-transfer migration. When enabled, device backends
+# including opened fds will be passed to the destination in the
+# migration channel (which must be a UNIX domain socket). Default
+# is no backend-transfer migration. (Since 10.2)
+#
# Features:
#
-# @unstable: Members @x-checkpoint-delay and
+# @unstable: Members @backend-transfer, @x-checkpoint-delay and
# @x-vcpu-dirty-limit-period are experimental.
#
# TODO: either fuse back into `MigrationParameters`, or make
@@ -1179,7 +1192,9 @@
'*mode': 'MigMode',
'*zero-page-detection': 'ZeroPageDetection',
'*direct-io': 'bool',
- '*cpr-exec-command': [ 'str' ]} }
+ '*cpr-exec-command': [ 'str' ],
+ '*backend-transfer': { 'type': [ 'str' ],
+ 'features': [ 'unstable' ] } } }
##
# @migrate-set-parameters:
@@ -1352,9 +1367,15 @@
# is @cpr-exec. The first list element is the program's filename,
# the remainder its arguments. (Since 10.2)
#
+# @backend-transfer: List of devices (IDs or QOM paths) for
+# backend-transfer migration. When enabled, device backends
+# including opened fds will be passed to the destination in the
+# migration channel (which must be a UNIX domain socket). Default
+# is no backend-transfer migration. (Since 10.2)
+#
# Features:
#
-# @unstable: Members @x-checkpoint-delay and
+# @unstable: Members @backend-transfer, @x-checkpoint-delay and
# @x-vcpu-dirty-limit-period are experimental.
#
# Since: 2.4
@@ -1391,7 +1412,9 @@
'*mode': 'MigMode',
'*zero-page-detection': 'ZeroPageDetection',
'*direct-io': 'bool',
- '*cpr-exec-command': [ 'str' ]} }
+ '*cpr-exec-command': [ 'str' ],
+ '*backend-transfer': { 'type': [ 'str' ],
+ 'features': [ 'unstable' ] } } }
##
# @query-migrate-parameters:
diff --git a/system/qdev-monitor.c b/system/qdev-monitor.c
index 9d3d961c15..549c77b2f0 100644
--- a/system/qdev-monitor.c
+++ b/system/qdev-monitor.c
@@ -939,6 +939,19 @@ void qmp_device_del(const char *id, Error **errp)
}
}
+bool migrate_backend_transfer(DeviceState *dev)
+{
+ const strList *el = migrate_backend_transfer_list();
+
+ for ( ; el; el = el->next) {
+ if (find_device_state(el->value, false, NULL) == dev) {
+ return true;
+ }
+ }
+
+ return false;
+}
+
static bool qdev_backend_transfer_support(DeviceState *dev, Error **errp)
{
DeviceClass *dc = DEVICE_GET_CLASS(dev);
@@ -952,6 +965,24 @@ static bool qdev_backend_transfer_support(DeviceState *dev, Error **errp)
return dc->backend_transfer_support(dev, errp);
}
+bool migrate_backend_transfer_check_list(const strList *list, Error **errp)
+{
+ const strList *el = list;
+
+ for ( ; el; el = el->next) {
+ DeviceState *dev = find_device_state(el->value, true, errp);
+ if (!dev) {
+ return false;
+ }
+
+ if (!qdev_backend_transfer_support(dev, errp)) {
+ return false;
+ }
+ }
+
+ return true;
+}
+
static int qdev_add_if_backend_transfer_supported(Object *obj, void *opaque)
{
DevPathList **list = opaque;
--
2.48.1
^ permalink raw reply related [flat|nested] 14+ messages in thread* Re: [PATCH v9 3/8] qapi: add backend-transfer migration parameter
2025-10-30 20:31 ` [PATCH v9 3/8] qapi: add backend-transfer migration parameter Vladimir Sementsov-Ogievskiy
@ 2025-11-06 15:44 ` Markus Armbruster
0 siblings, 0 replies; 14+ messages in thread
From: Markus Armbruster @ 2025-11-06 15:44 UTC (permalink / raw)
To: Vladimir Sementsov-Ogievskiy
Cc: mst, jasowang, pbonzini, berrange, eduardo, peterx, farosas,
eblake, thuth, philmd, zhao1.liu, qemu-devel, leiyang,
davydov-max, yc-core, raphael.s.norwitz
Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru> writes:
> We are going to implement backend-transfer feature: some devices
> will be able to transfer their backend through migration stream
> for local migration through UNIX domain socket. For example,
> virtio-net will migrate its attached TAP netdev, with all its
> connected file descriptors.
>
> In this commit we introduce a migration parameter, which pick
> devices for backend-transfer migration in context of next
> outgoing or incoming migration. Of course, user is responsible
> to pick same set of devices on source and target.
>
> QMP command query-backend-transfer-support command may help
> to prepare such set as intersection of
> query-backend-transfer-support results on source and target.
>
> With this commit, no device yet support backend-transfer,
> so passing something other then empty list to backend-transfer
> migration parameter will fail.
>
> Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
[...]
> void qmp_migrate_set_parameters(MigrateSetParameters *params, Error **errp)
> diff --git a/qapi/migration.json b/qapi/migration.json
> index be0f3fcc12..9478c4ddab 100644
> --- a/qapi/migration.json
> +++ b/qapi/migration.json
> @@ -951,9 +951,15 @@
> # is @cpr-exec. The first list element is the program's filename,
> # the remainder its arguments. (Since 10.2)
> #
> +# @backend-transfer: List of devices (IDs or QOM paths) for
> +# backend-transfer migration. When enabled, device backends
> +# including opened fds will be passed to the destination in the
> +# migration channel (which must be a UNIX domain socket). Default
> +# is no backend-transfer migration. (Since 10.2)
Two spaces after '.', please.
> +#
> # Features:
> #
> -# @unstable: Members @x-checkpoint-delay and
> +# @unstable: Members @backend-transfer, @x-checkpoint-delay and
> # @x-vcpu-dirty-limit-period are experimental.
> #
> # Since: 2.4
> @@ -978,7 +984,8 @@
> 'mode',
> 'zero-page-detection',
> 'direct-io',
> - 'cpr-exec-command'] }
> + 'cpr-exec-command',
> + { 'name': 'backend-transfer', 'features': ['unstable'] } ] }
>
> ##
> # @MigrateSetParameters:
> @@ -1137,9 +1144,15 @@
> # is @cpr-exec. The first list element is the program's filename,
> # the remainder its arguments. (Since 10.2)
> #
> +# @backend-transfer: List of devices (IDs or QOM paths) for
> +# backend-transfer migration. When enabled, device backends
> +# including opened fds will be passed to the destination in the
> +# migration channel (which must be a UNIX domain socket). Default
> +# is no backend-transfer migration. (Since 10.2)
Likewise.
> +#
> # Features:
> #
> -# @unstable: Members @x-checkpoint-delay and
> +# @unstable: Members @backend-transfer, @x-checkpoint-delay and
> # @x-vcpu-dirty-limit-period are experimental.
> #
> # TODO: either fuse back into `MigrationParameters`, or make
> @@ -1179,7 +1192,9 @@
> '*mode': 'MigMode',
> '*zero-page-detection': 'ZeroPageDetection',
> '*direct-io': 'bool',
> - '*cpr-exec-command': [ 'str' ]} }
> + '*cpr-exec-command': [ 'str' ],
> + '*backend-transfer': { 'type': [ 'str' ],
> + 'features': [ 'unstable' ] } } }
>
> ##
> # @migrate-set-parameters:
> @@ -1352,9 +1367,15 @@
> # is @cpr-exec. The first list element is the program's filename,
> # the remainder its arguments. (Since 10.2)
> #
> +# @backend-transfer: List of devices (IDs or QOM paths) for
> +# backend-transfer migration. When enabled, device backends
> +# including opened fds will be passed to the destination in the
> +# migration channel (which must be a UNIX domain socket). Default
> +# is no backend-transfer migration. (Since 10.2)
Two spaces after '.', please.
> +#
> # Features:
> #
> -# @unstable: Members @x-checkpoint-delay and
> +# @unstable: Members @backend-transfer, @x-checkpoint-delay and
> # @x-vcpu-dirty-limit-period are experimental.
> #
> # Since: 2.4
> @@ -1391,7 +1412,9 @@
> '*mode': 'MigMode',
> '*zero-page-detection': 'ZeroPageDetection',
> '*direct-io': 'bool',
> - '*cpr-exec-command': [ 'str' ]} }
> + '*cpr-exec-command': [ 'str' ],
> + '*backend-transfer': { 'type': [ 'str' ],
> + 'features': [ 'unstable' ] } } }
>
> ##
> # @query-migrate-parameters:
> diff --git a/system/qdev-monitor.c b/system/qdev-monitor.c
> index 9d3d961c15..549c77b2f0 100644
> --- a/system/qdev-monitor.c
> +++ b/system/qdev-monitor.c
> @@ -939,6 +939,19 @@ void qmp_device_del(const char *id, Error **errp)
> }
> }
>
> +bool migrate_backend_transfer(DeviceState *dev)
> +{
> + const strList *el = migrate_backend_transfer_list();
> +
> + for ( ; el; el = el->next) {
Please use
const strList *el;
for (el = migrate_backend_transfer_list(); el; el = el->next) {
> + if (find_device_state(el->value, false, NULL) == dev) {
> + return true;
> + }
> + }
> +
> + return false;
> +}
> +
> static bool qdev_backend_transfer_support(DeviceState *dev, Error **errp)
> {
> DeviceClass *dc = DEVICE_GET_CLASS(dev);
> @@ -952,6 +965,24 @@ static bool qdev_backend_transfer_support(DeviceState *dev, Error **errp)
> return dc->backend_transfer_support(dev, errp);
> }
>
> +bool migrate_backend_transfer_check_list(const strList *list, Error **errp)
> +{
> + const strList *el = list;
> +
> + for ( ; el; el = el->next) {
Likewise.
> + DeviceState *dev = find_device_state(el->value, true, errp);
> + if (!dev) {
> + return false;
> + }
> +
> + if (!qdev_backend_transfer_support(dev, errp)) {
> + return false;
> + }
> + }
> +
> + return true;
> +}
> +
> static int qdev_add_if_backend_transfer_supported(Object *obj, void *opaque)
> {
> DevPathList **list = opaque;
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH v9 4/8] net: introduce vmstate_net_peer_backend
2025-10-30 20:31 [PATCH v9 0/8] virtio-net: live-TAP local migration Vladimir Sementsov-Ogievskiy
` (2 preceding siblings ...)
2025-10-30 20:31 ` [PATCH v9 3/8] qapi: add backend-transfer migration parameter Vladimir Sementsov-Ogievskiy
@ 2025-10-30 20:31 ` Vladimir Sementsov-Ogievskiy
2025-10-30 20:31 ` [PATCH v9 5/8] virtio-net: support backend-transfer migration Vladimir Sementsov-Ogievskiy
` (3 subsequent siblings)
7 siblings, 0 replies; 14+ messages in thread
From: Vladimir Sementsov-Ogievskiy @ 2025-10-30 20:31 UTC (permalink / raw)
To: mst, jasowang
Cc: pbonzini, berrange, eduardo, peterx, farosas, eblake, armbru,
thuth, philmd, zhao1.liu, qemu-devel, leiyang, davydov-max,
yc-core, vsementsov, raphael.s.norwitz
To implement backend-transfer migration in virtio-net in the next
commit, we need a generic API to migrate net backend. Here is it.
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
---
include/net/net.h | 4 ++++
net/net.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 51 insertions(+)
diff --git a/include/net/net.h b/include/net/net.h
index 3aa67db57c..8375ca89a7 100644
--- a/include/net/net.h
+++ b/include/net/net.h
@@ -5,6 +5,7 @@
#include "qapi/qapi-types-net.h"
#include "net/queue.h"
#include "hw/qdev-properties-system.h"
+#include "migration/vmstate.h"
#define MAC_FMT "%02X:%02X:%02X:%02X:%02X:%02X"
#define MAC_ARG(x) ((uint8_t *)(x))[0], ((uint8_t *)(x))[1], \
@@ -115,6 +116,7 @@ typedef struct NetClientInfo {
NetCheckPeerType *check_peer_type;
GetVHostNet *get_vhost_net;
NetBackendConnect *backend_connect;
+ const VMStateDescription *backend_vmsd;
} NetClientInfo;
struct NetClientState {
@@ -360,4 +362,6 @@ static inline bool net_peer_needs_padding(NetClientState *nc)
return nc->peer && !nc->peer->do_not_pad;
}
+extern const VMStateInfo vmstate_net_peer_backend;
+
#endif
diff --git a/net/net.c b/net/net.c
index 4fc6b1d0a6..cca4fa0a6b 100644
--- a/net/net.c
+++ b/net/net.c
@@ -57,6 +57,7 @@
#include "qapi/string-output-visitor.h"
#include "qapi/qobject-input-visitor.h"
#include "standard-headers/linux/virtio_net.h"
+#include "migration/vmstate.h"
/* Net bridge is currently not supported for W32. */
#if !defined(_WIN32)
@@ -2177,3 +2178,49 @@ bool net_backend_connect(NetClientState *nc, Error **errp)
return nc->info->backend_connect(nc, errp);
}
+
+static int get_peer_backend(QEMUFile *f, void *pv, size_t size,
+ const VMStateField *field)
+{
+ NetClientState *nc = pv;
+ Error *local_err = NULL;
+ int ret;
+
+ if (!nc->peer) {
+ return -EINVAL;
+ }
+ nc = nc->peer;
+
+ ret = vmstate_load_state(f, nc->info->backend_vmsd, nc, 0, &local_err);
+ if (ret < 0) {
+ error_report_err(local_err);
+ }
+
+ return ret;
+}
+
+static int put_peer_backend(QEMUFile *f, void *pv, size_t size,
+ const VMStateField *field, JSONWriter *vmdesc)
+{
+ NetClientState *nc = pv;
+ Error *local_err = NULL;
+ int ret;
+
+ if (!nc->peer) {
+ return -EINVAL;
+ }
+ nc = nc->peer;
+
+ ret = vmstate_save_state(f, nc->info->backend_vmsd, nc, 0, &local_err);
+ if (ret < 0) {
+ error_report_err(local_err);
+ }
+
+ return ret;
+}
+
+const VMStateInfo vmstate_net_peer_backend = {
+ .name = "virtio-net-nic-nc-backend",
+ .get = get_peer_backend,
+ .put = put_peer_backend,
+};
--
2.48.1
^ permalink raw reply related [flat|nested] 14+ messages in thread* [PATCH v9 5/8] virtio-net: support backend-transfer migration
2025-10-30 20:31 [PATCH v9 0/8] virtio-net: live-TAP local migration Vladimir Sementsov-Ogievskiy
` (3 preceding siblings ...)
2025-10-30 20:31 ` [PATCH v9 4/8] net: introduce vmstate_net_peer_backend Vladimir Sementsov-Ogievskiy
@ 2025-10-30 20:31 ` Vladimir Sementsov-Ogievskiy
2025-10-30 20:31 ` [PATCH v9 6/8] net/tap: " Vladimir Sementsov-Ogievskiy
` (2 subsequent siblings)
7 siblings, 0 replies; 14+ messages in thread
From: Vladimir Sementsov-Ogievskiy @ 2025-10-30 20:31 UTC (permalink / raw)
To: mst, jasowang
Cc: pbonzini, berrange, eduardo, peterx, farosas, eblake, armbru,
thuth, philmd, zhao1.liu, qemu-devel, leiyang, davydov-max,
yc-core, vsementsov, raphael.s.norwitz
Implement backend-transfer support for virtio-net device.
How it works:
1. Use DEFINE_NIC_PROPERTIES_NO_CONNECT(), so that backend
not being connected during netdev property setting.
2. If we are not in incoming migration, just call
net_backend_connect() in _realize()
3. If we are in incoming migration, postpone backend connect up
to pre-incoming. At this point we check migration parameters,
and if backend-transfer is NOT enabled for this virtio-net
device, do net_backend_connect(). Otherwise - do noting,
live backend will come in migration stream.
4. During virtio-load, we get backend state as part of virtio-net
state
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
---
hw/net/virtio-net.c | 157 ++++++++++++++++++++++++++++++++-
include/hw/virtio/virtio-net.h | 1 +
2 files changed, 156 insertions(+), 2 deletions(-)
diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
index 17ed0ef919..94e41c225a 100644
--- a/hw/net/virtio-net.c
+++ b/hw/net/virtio-net.c
@@ -38,8 +38,10 @@
#include "qapi/qapi-events-migration.h"
#include "hw/virtio/virtio-access.h"
#include "migration/misc.h"
+#include "migration/options.h"
#include "standard-headers/linux/ethtool.h"
#include "system/system.h"
+#include "system/runstate.h"
#include "system/replay.h"
#include "trace.h"
#include "monitor/qdev.h"
@@ -3060,7 +3062,17 @@ static void virtio_net_set_multiqueue(VirtIONet *n, int multiqueue)
n->multiqueue = multiqueue;
virtio_net_change_num_queues(n, max * 2 + 1);
- virtio_net_set_queue_pairs(n);
+ /*
+ * virtio_net_set_multiqueue() called from set_features(0) on early
+ * reset, when peer may wait for incoming (and is not initialized
+ * yet).
+ * Don't worry about it: virtio_net_set_queue_pairs() will be called
+ * later form virtio_net_post_load_device(), and anyway will be
+ * noop for local incoming migration with live backend passing.
+ */
+ if (!n->peers_wait_incoming) {
+ virtio_net_set_queue_pairs(n);
+ }
}
static int virtio_net_pre_load_queues(VirtIODevice *vdev, uint32_t n)
@@ -3089,6 +3101,17 @@ static void virtio_net_get_features(VirtIODevice *vdev, uint64_t *features,
virtio_add_feature_ex(features, VIRTIO_NET_F_MAC);
+ if (n->peers_wait_incoming) {
+ /*
+ * Excessive feature set is OK for early initialization when
+ * we wait for local incoming migration: actual guest-negotiated
+ * features will come with migration stream anyway. And we are sure
+ * that we support same host-features as source, because the backend
+ * is the same (the same TAP device, for example).
+ */
+ return;
+ }
+
if (!peer_has_vnet_hdr(n)) {
virtio_clear_feature_ex(features, VIRTIO_NET_F_CSUM);
virtio_clear_feature_ex(features, VIRTIO_NET_F_HOST_TSO4);
@@ -3180,6 +3203,18 @@ static void virtio_net_get_features(VirtIODevice *vdev, uint64_t *features,
}
}
+static bool virtio_net_update_host_features(VirtIONet *n, Error **errp)
+{
+ ERRP_GUARD();
+ VirtIODevice *vdev = VIRTIO_DEVICE(n);
+
+ peer_test_vnet_hdr(n);
+
+ virtio_net_get_features(vdev, &vdev->host_features, errp);
+
+ return !*errp;
+}
+
static int virtio_net_post_load_device(void *opaque, int version_id)
{
VirtIONet *n = opaque;
@@ -3301,6 +3336,9 @@ struct VirtIONetMigTmp {
uint16_t curr_queue_pairs_1;
uint8_t has_ufo;
uint32_t has_vnet_hdr;
+
+ NetClientState *ncs;
+ uint32_t max_queue_pairs;
};
/* The 2nd and subsequent tx_waiting flags are loaded later than
@@ -3570,6 +3608,57 @@ static const VMStateDescription vhost_user_net_backend_state = {
}
};
+static bool virtio_net_is_backend_transfer(void *opaque, int version_id)
+{
+ VirtIONet *n = opaque;
+
+ return migrate_backend_transfer(DEVICE(n));
+}
+
+static int virtio_net_nic_pre_save(void *opaque)
+{
+ struct VirtIONetMigTmp *tmp = opaque;
+
+ tmp->ncs = tmp->parent->nic->ncs;
+ tmp->max_queue_pairs = tmp->parent->max_queue_pairs;
+
+ return 0;
+}
+
+static int virtio_net_nic_pre_load(void *opaque)
+{
+ /* Reuse the pointer setup from save */
+ virtio_net_nic_pre_save(opaque);
+
+ return 0;
+}
+
+static int virtio_net_nic_post_load(void *opaque, int version_id)
+{
+ struct VirtIONetMigTmp *tmp = opaque;
+ Error *local_err = NULL;
+
+ if (!virtio_net_update_host_features(tmp->parent, &local_err)) {
+ error_report_err(local_err);
+ return -EINVAL;
+ }
+
+ return 0;
+}
+
+static const VMStateDescription vmstate_virtio_net_nic = {
+ .name = "virtio-net-nic",
+ .pre_load = virtio_net_nic_pre_load,
+ .pre_save = virtio_net_nic_pre_save,
+ .post_load = virtio_net_nic_post_load,
+ .fields = (const VMStateField[]) {
+ VMSTATE_VARRAY_UINT32(ncs, struct VirtIONetMigTmp,
+ max_queue_pairs, 0, vmstate_net_peer_backend,
+ NetClientState),
+ VMSTATE_END_OF_LIST()
+ },
+};
+
static const VMStateDescription vmstate_virtio_net_device = {
.name = "virtio-net-device",
.version_id = VIRTIO_NET_VM_VERSION,
@@ -3602,6 +3691,9 @@ static const VMStateDescription vmstate_virtio_net_device = {
*/
VMSTATE_BUFFER_UNSAFE(vlans, VirtIONet, 0,
sizeof(typeof_field(VirtIONet, vlans))),
+ VMSTATE_WITH_TMP_TEST(VirtIONet, virtio_net_is_backend_transfer,
+ struct VirtIONetMigTmp,
+ vmstate_virtio_net_nic),
VMSTATE_WITH_TMP(VirtIONet, struct VirtIONetMigTmp,
vmstate_virtio_net_has_vnet),
VMSTATE_UINT8(mac_table.multi_overflow, VirtIONet),
@@ -4003,6 +4095,20 @@ static void virtio_net_device_realize(DeviceState *dev, Error **errp)
n->nic->ncs[i].do_not_pad = true;
}
+ if (runstate_check(RUN_STATE_INMIGRATE)) {
+ n->peers_wait_incoming = true;
+ } else {
+ for (i = 0; i < n->max_queue_pairs; i++) {
+ nc = qemu_get_subqueue(n->nic, i);
+ if (!nc->peer) {
+ continue;
+ }
+ if (!net_backend_connect(nc->peer, errp)) {
+ return;
+ }
+ }
+ }
+
peer_test_vnet_hdr(n);
if (peer_has_vnet_hdr(n)) {
n->host_hdr_len = sizeof(struct virtio_net_hdr);
@@ -4176,6 +4282,30 @@ static bool dev_unplug_pending(void *opaque)
return vdc->primary_unplug_pending(dev);
}
+static bool vhost_user_blk_pre_incoming(void *opaque, Error **errp)
+{
+ VirtIONet *n = opaque;
+ int i;
+
+ if (!virtio_net_is_backend_transfer(opaque, 0) && n->peers_wait_incoming) {
+ for (i = 0; i < n->max_queue_pairs; i++) {
+ NetClientState *nc = qemu_get_subqueue(n->nic, i);
+ if (!nc->peer) {
+ continue;
+ }
+ if (!net_backend_connect(nc->peer, errp)) {
+ return false;
+ }
+ }
+
+ n->peers_wait_incoming = false;
+
+ return virtio_net_update_host_features(n, errp);
+ }
+
+ return true;
+}
+
static const VMStateDescription vmstate_virtio_net = {
.name = "virtio-net",
.minimum_version_id = VIRTIO_NET_VM_VERSION,
@@ -4184,6 +4314,7 @@ static const VMStateDescription vmstate_virtio_net = {
VMSTATE_VIRTIO_DEVICE,
VMSTATE_END_OF_LIST()
},
+ .pre_incoming = vhost_user_blk_pre_incoming,
.pre_save = virtio_net_pre_save,
.dev_unplug_pending = dev_unplug_pending,
};
@@ -4239,7 +4370,7 @@ static const Property virtio_net_properties[] = {
VIRTIO_NET_F_RSC_EXT, false),
DEFINE_PROP_UINT32("rsc_interval", VirtIONet, rsc_timeout,
VIRTIO_NET_RSC_DEFAULT_INTERVAL),
- DEFINE_NIC_PROPERTIES(VirtIONet, nic_conf),
+ DEFINE_NIC_PROPERTIES_NO_CONNECT(VirtIONet, nic_conf),
DEFINE_PROP_UINT32("x-txtimer", VirtIONet, net_conf.txtimer,
TX_TIMER_INTERVAL),
DEFINE_PROP_INT32("x-txburst", VirtIONet, net_conf.txburst, TX_BURST),
@@ -4314,6 +4445,27 @@ static const Property virtio_net_properties[] = {
false),
};
+static bool virtio_net_backend_transfer_support(DeviceState *dev, Error **errp)
+{
+ VirtIONet *n = VIRTIO_NET(dev);
+ NetClientState *nc = qemu_get_queue(n->nic);
+
+ if (!nc->peer) {
+ error_setg(errp, "Device %s has no attached backend",
+ qdev_get_dev_path(dev));
+ return false;
+ }
+
+ if (!nc->peer->info->backend_vmsd) {
+ error_setg(errp, "Device %s backend is %s, does not support backend"
+ " transfer", qdev_get_dev_path(dev),
+ NetClientDriver_str(nc->peer->info->type));
+ return false;
+ }
+
+ return true;
+}
+
static void virtio_net_class_init(ObjectClass *klass, const void *data)
{
DeviceClass *dc = DEVICE_CLASS(klass);
@@ -4321,6 +4473,7 @@ static void virtio_net_class_init(ObjectClass *klass, const void *data)
device_class_set_props(dc, virtio_net_properties);
dc->vmsd = &vmstate_virtio_net;
+ dc->backend_transfer_support = virtio_net_backend_transfer_support;
set_bit(DEVICE_CATEGORY_NETWORK, dc->categories);
vdc->realize = virtio_net_device_realize;
vdc->unrealize = virtio_net_device_unrealize;
diff --git a/include/hw/virtio/virtio-net.h b/include/hw/virtio/virtio-net.h
index f708355306..7e0e156908 100644
--- a/include/hw/virtio/virtio-net.h
+++ b/include/hw/virtio/virtio-net.h
@@ -231,6 +231,7 @@ struct VirtIONet {
struct EBPFRSSContext ebpf_rss;
uint32_t nr_ebpf_rss_fds;
char **ebpf_rss_fds;
+ bool peers_wait_incoming;
};
size_t virtio_net_handle_ctrl_iov(VirtIODevice *vdev,
--
2.48.1
^ permalink raw reply related [flat|nested] 14+ messages in thread* [PATCH v9 6/8] net/tap: support backend-transfer migration
2025-10-30 20:31 [PATCH v9 0/8] virtio-net: live-TAP local migration Vladimir Sementsov-Ogievskiy
` (4 preceding siblings ...)
2025-10-30 20:31 ` [PATCH v9 5/8] virtio-net: support backend-transfer migration Vladimir Sementsov-Ogievskiy
@ 2025-10-30 20:31 ` Vladimir Sementsov-Ogievskiy
2025-10-30 20:31 ` [PATCH v9 7/8] tests/functional: add skipWithoutSudo() decorator Vladimir Sementsov-Ogievskiy
2025-10-30 20:31 ` [PATCH v9 8/8] tests/functional: add test_tap_migration Vladimir Sementsov-Ogievskiy
7 siblings, 0 replies; 14+ messages in thread
From: Vladimir Sementsov-Ogievskiy @ 2025-10-30 20:31 UTC (permalink / raw)
To: mst, jasowang
Cc: pbonzini, berrange, eduardo, peterx, farosas, eblake, armbru,
thuth, philmd, zhao1.liu, qemu-devel, leiyang, davydov-max,
yc-core, vsementsov, raphael.s.norwitz
Support transferring of TAP state (including open fd) through
migration stream.
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
---
net/tap.c | 46 +++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 45 insertions(+), 1 deletion(-)
diff --git a/net/tap.c b/net/tap.c
index ad1d458521..4a752006de 100644
--- a/net/tap.c
+++ b/net/tap.c
@@ -413,6 +413,49 @@ static VHostNetState *tap_get_vhost_net(NetClientState *nc)
return s->vhost_net;
}
+static int tap_pre_load(void *opaque)
+{
+ TAPState *s = opaque;
+
+ if (s->fd != -1) {
+ error_report(
+ "TAP is already initialized and cannot receive incoming fd");
+ return -EINVAL;
+ }
+
+ return 0;
+}
+
+static int tap_post_load(void *opaque, int version_id)
+{
+ TAPState *s = opaque;
+ Error *local_err = NULL;
+
+ if (!net_tap_setup(s, -1, -1, &local_err)) {
+ error_report_err(local_err);
+ qemu_del_net_client(&s->nc);
+ return -EINVAL;
+ }
+
+ return 0;
+}
+
+static const VMStateDescription vmstate_tap = {
+ .name = "net-tap",
+ .pre_load = tap_pre_load,
+ .post_load = tap_post_load,
+ .fields = (const VMStateField[]) {
+ VMSTATE_FD(fd, TAPState),
+ VMSTATE_BOOL(using_vnet_hdr, TAPState),
+ VMSTATE_BOOL(has_ufo, TAPState),
+ VMSTATE_BOOL(has_uso, TAPState),
+ VMSTATE_BOOL(has_tunnel, TAPState),
+ VMSTATE_BOOL(enabled, TAPState),
+ VMSTATE_UINT32(host_vnet_hdr_len, TAPState),
+ VMSTATE_END_OF_LIST()
+ }
+};
+
/* fd support */
static NetClientInfo net_tap_info = {
@@ -434,6 +477,7 @@ static NetClientInfo net_tap_info = {
.set_steering_ebpf = tap_set_steering_ebpf,
.get_vhost_net = tap_get_vhost_net,
.backend_connect = tap_backend_connect,
+ .backend_vmsd = &vmstate_tap,
};
static TAPState *net_tap_new(NetClientState *peer, const char *model,
@@ -800,7 +844,7 @@ static void net_init_tap_one(const NetdevTapOptions *tap, NetClientState *peer,
static bool net_tap_setup(TAPState *s, int fd, int vnet_hdr, Error **errp)
{
- if (!net_tap_set_fd(s, fd, vnet_hdr, errp)) {
+ if (fd != -1 && !net_tap_set_fd(s, fd, vnet_hdr, errp)) {
return false;
}
--
2.48.1
^ permalink raw reply related [flat|nested] 14+ messages in thread* [PATCH v9 7/8] tests/functional: add skipWithoutSudo() decorator
2025-10-30 20:31 [PATCH v9 0/8] virtio-net: live-TAP local migration Vladimir Sementsov-Ogievskiy
` (5 preceding siblings ...)
2025-10-30 20:31 ` [PATCH v9 6/8] net/tap: " Vladimir Sementsov-Ogievskiy
@ 2025-10-30 20:31 ` Vladimir Sementsov-Ogievskiy
2025-10-30 20:31 ` [PATCH v9 8/8] tests/functional: add test_tap_migration Vladimir Sementsov-Ogievskiy
7 siblings, 0 replies; 14+ messages in thread
From: Vladimir Sementsov-Ogievskiy @ 2025-10-30 20:31 UTC (permalink / raw)
To: mst, jasowang
Cc: pbonzini, berrange, eduardo, peterx, farosas, eblake, armbru,
thuth, philmd, zhao1.liu, qemu-devel, leiyang, davydov-max,
yc-core, vsementsov, raphael.s.norwitz
To be used in the next commit: that would be a test for TAP
networking, and it will need to setup TAP device.
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Reviewed-by: Thomas Huth <thuth@redhat.com>
Tested-by: Lei Yang <leiyang@redhat.com>
Reviewed-by: Maksim Davydov <davydov-max@yandex-team.ru>
---
tests/functional/qemu_test/decorators.py | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/tests/functional/qemu_test/decorators.py b/tests/functional/qemu_test/decorators.py
index b239295804..125d31dda6 100644
--- a/tests/functional/qemu_test/decorators.py
+++ b/tests/functional/qemu_test/decorators.py
@@ -6,6 +6,7 @@
import os
import platform
import resource
+import subprocess
from unittest import skipIf, skipUnless
from .cmd import which
@@ -167,3 +168,18 @@ def skipLockedMemoryTest(locked_memory):
ulimit_memory == resource.RLIM_INFINITY or ulimit_memory >= locked_memory * 1024,
f'Test required {locked_memory} kB of available locked memory',
)
+
+'''
+Decorator to skip execution of a test if passwordless
+sudo command is not available.
+'''
+def skipWithoutSudo():
+ proc = subprocess.run(["sudo", "-n", "/bin/true"],
+ stdin=subprocess.PIPE,
+ stdout=subprocess.PIPE,
+ stderr=subprocess.STDOUT,
+ universal_newlines=True,
+ check=False)
+
+ return skipUnless(proc.returncode == 0,
+ f'requires password-less sudo access: {proc.stdout}')
--
2.48.1
^ permalink raw reply related [flat|nested] 14+ messages in thread* [PATCH v9 8/8] tests/functional: add test_tap_migration
2025-10-30 20:31 [PATCH v9 0/8] virtio-net: live-TAP local migration Vladimir Sementsov-Ogievskiy
` (6 preceding siblings ...)
2025-10-30 20:31 ` [PATCH v9 7/8] tests/functional: add skipWithoutSudo() decorator Vladimir Sementsov-Ogievskiy
@ 2025-10-30 20:31 ` Vladimir Sementsov-Ogievskiy
7 siblings, 0 replies; 14+ messages in thread
From: Vladimir Sementsov-Ogievskiy @ 2025-10-30 20:31 UTC (permalink / raw)
To: mst, jasowang
Cc: pbonzini, berrange, eduardo, peterx, farosas, eblake, armbru,
thuth, philmd, zhao1.liu, qemu-devel, leiyang, davydov-max,
yc-core, vsementsov, raphael.s.norwitz
Add test for a new backend-transfer migration of virtio-net/tap, with fd
passing through unix socket.
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
---
tests/functional/x86_64/meson.build | 1 +
tests/functional/x86_64/test_tap_migration.py | 398 ++++++++++++++++++
2 files changed, 399 insertions(+)
create mode 100644 tests/functional/x86_64/test_tap_migration.py
diff --git a/tests/functional/x86_64/meson.build b/tests/functional/x86_64/meson.build
index f78eec5e6c..d23b0cc727 100644
--- a/tests/functional/x86_64/meson.build
+++ b/tests/functional/x86_64/meson.build
@@ -36,4 +36,5 @@ tests_x86_64_system_thorough = [
'vfio_user_client',
'virtio_balloon',
'virtio_gpu',
+ 'tap_migration',
]
diff --git a/tests/functional/x86_64/test_tap_migration.py b/tests/functional/x86_64/test_tap_migration.py
new file mode 100644
index 0000000000..fd9f706fc3
--- /dev/null
+++ b/tests/functional/x86_64/test_tap_migration.py
@@ -0,0 +1,398 @@
+#!/usr/bin/env python3
+#
+# Functional test that tests TAP local migration
+# with fd passing
+#
+# Copyright (c) Yandex Technologies LLC, 2025
+#
+# SPDX-License-Identifier: GPL-2.0-or-later
+
+import os
+import time
+import subprocess
+from subprocess import run
+import signal
+from typing import Tuple
+
+from qemu_test import (
+ LinuxKernelTest,
+ Asset,
+ exec_command_and_wait_for_pattern,
+)
+from qemu_test.decorators import skipWithoutSudo
+
+GUEST_IP = "10.0.1.2"
+GUEST_IP_MASK = f"{GUEST_IP}/24"
+GUEST_MAC = "d6:0d:75:f8:0f:b7"
+HOST_IP = "10.0.1.1"
+HOST_IP_MASK = f"{HOST_IP}/24"
+TAP_ID = "tap0"
+TAP_ID2 = "tap1"
+TAP_MAC = "e6:1d:44:b5:03:5d"
+
+
+def ip(args, check=True) -> None:
+ """Run ip command with sudo"""
+ run(["sudo", "ip"] + args, check=check)
+
+
+def del_tap(tap_name: str = TAP_ID) -> None:
+ ip(["tuntap", "del", tap_name, "mode", "tap", "multi_queue"], check=False)
+
+
+def init_tap(tap_name: str = TAP_ID, with_ip: bool = True) -> None:
+ ip(["tuntap", "add", "dev", tap_name, "mode", "tap", "multi_queue"])
+ if with_ip:
+ ip(["link", "set", "dev", tap_name, "address", TAP_MAC])
+ ip(["addr", "add", HOST_IP_MASK, "dev", tap_name])
+ ip(["link", "set", tap_name, "up"])
+
+
+def switch_network_to_tap2() -> None:
+ ip(["link", "set", TAP_ID2, "down"])
+ ip(["link", "set", TAP_ID, "down"])
+ ip(["addr", "delete", HOST_IP_MASK, "dev", TAP_ID])
+ ip(["link", "set", "dev", TAP_ID2, "address", TAP_MAC])
+ ip(["addr", "add", HOST_IP_MASK, "dev", TAP_ID2])
+ ip(["link", "set", TAP_ID2, "up"])
+
+
+def parse_ping_line(line: str) -> float:
+ # suspect lines like
+ # [1748524876.590509] 64 bytes from 94.245.155.3 \
+ # (94.245.155.3): icmp_seq=1 ttl=250 time=101 ms
+ spl = line.split()
+ return float(spl[0][1:-1])
+
+
+def parse_ping_output(out) -> Tuple[bool, float, float]:
+ lines = [x for x in out.split("\n") if x.startswith("[")]
+
+ try:
+ first_no_ans = next(
+ (ind for ind in range(len(lines)) if lines[ind][20:26] == "no ans")
+ )
+ except StopIteration:
+ return False, parse_ping_line(lines[0]), parse_ping_line(lines[-1])
+
+ last_no_ans = next(
+ ind
+ for ind in range(len(lines) - 1, -1, -1)
+ if lines[ind][20:26] == "no ans"
+ )
+
+ return (
+ True,
+ parse_ping_line(lines[first_no_ans]),
+ parse_ping_line(lines[last_no_ans]),
+ )
+
+
+def wait_migration_finish(source_vm, target_vm):
+ migr_events = (
+ ("MIGRATION", {"data": {"status": "completed"}}),
+ ("MIGRATION", {"data": {"status": "failed"}}),
+ )
+
+ source_e = source_vm.events_wait(migr_events)["data"]
+ target_e = target_vm.events_wait(migr_events)["data"]
+
+ source_s = source_vm.cmd("query-status")["status"]
+ target_s = target_vm.cmd("query-status")["status"]
+
+ assert (
+ source_e["status"] == "completed"
+ and target_e["status"] == "completed"
+ and source_s == "postmigrate"
+ and target_s == "paused"
+ ), f"""Migration failed:
+ SRC status: {source_s}
+ SRC event: {source_e}
+ TGT status: {target_s}
+ TGT event:{target_e}"""
+
+
+@skipWithoutSudo()
+class VhostUserBlkFdMigration(LinuxKernelTest):
+
+ ASSET_KERNEL = Asset(
+ (
+ "https://archives.fedoraproject.org/pub/archive/fedora/linux/releases"
+ "/31/Server/x86_64/os/images/pxeboot/vmlinuz"
+ ),
+ "d4738d03dbbe083ca610d0821d0a8f1488bebbdccef54ce33e3adb35fda00129",
+ )
+
+ ASSET_INITRD = Asset(
+ (
+ "https://archives.fedoraproject.org/pub/archive/fedora/linux/releases"
+ "/31/Server/x86_64/os/images/pxeboot/initrd.img"
+ ),
+ "277cd6c7adf77c7e63d73bbb2cded8ef9e2d3a2f100000e92ff1f8396513cd8b",
+ )
+
+ ASSET_ALPINE_ISO = Asset(
+ (
+ "https://dl-cdn.alpinelinux.org/"
+ "alpine/v3.22/releases/x86_64/alpine-standard-3.22.1-x86_64.iso"
+ ),
+ "96d1b44ea1b8a5a884f193526d92edb4676054e9fa903ad2f016441a0fe13089",
+ )
+
+ def setUp(self):
+ super().setUp()
+
+ init_tap()
+
+ self.outer_ping_proc = None
+ self.shm_path = None
+
+ def tearDown(self):
+ try:
+ del_tap(TAP_ID)
+ del_tap(TAP_ID2)
+
+ if self.outer_ping_proc:
+ self.stop_outer_ping()
+
+ if self.shm_path:
+ os.unlink(self.shm_path)
+ finally:
+ super().tearDown()
+
+ def start_outer_ping(self) -> None:
+ assert self.outer_ping_proc is None
+ self.outer_ping_log = self.scratch_file("ping.log")
+ with open(self.outer_ping_log, "w") as f:
+ self.outer_ping_proc = subprocess.Popen(
+ ["ping", "-i", "0", "-O", "-D", GUEST_IP],
+ text=True,
+ stdout=f,
+ )
+
+ def stop_outer_ping(self) -> str:
+ assert self.outer_ping_proc
+ self.outer_ping_proc.send_signal(signal.SIGINT)
+
+ self.outer_ping_proc.communicate(timeout=5)
+ self.outer_ping_proc = None
+
+ with open(self.outer_ping_log) as f:
+ return f.read()
+
+ def stop_ping_and_check(self, stop_time, resume_time):
+ ping_res = self.stop_outer_ping()
+
+ discon, a, b = parse_ping_output(ping_res)
+
+ if not discon:
+ text = (
+ f"STOP: {stop_time}, RESUME: {resume_time}," f"PING: {a} - {b}"
+ )
+ if a > stop_time or b < resume_time:
+ self.fail(f"PING failed: {text}")
+ self.log.info(f"PING: no packets lost: {text}")
+ return
+
+ text = (
+ f"STOP: {stop_time}, RESUME: {resume_time},"
+ f"PING: disconnect: {a} - {b}"
+ )
+ self.log.info(text)
+ eps = 0.01
+ if a < stop_time - eps or b > resume_time + eps:
+ self.fail(text)
+
+ def one_ping_from_guest(self, vm) -> None:
+ exec_command_and_wait_for_pattern(
+ self,
+ f"ping -c 1 -W 1 {HOST_IP}",
+ "1 packets transmitted, 1 packets received",
+ "1 packets transmitted, 0 packets received",
+ vm=vm,
+ )
+ self.wait_for_console_pattern("# ", vm=vm)
+
+ def one_ping_from_host(self) -> None:
+ run(["ping", "-c", "1", "-W", "1", GUEST_IP])
+
+ def setup_shared_memory(self):
+ self.shm_path = f"/dev/shm/qemu_test_{os.getpid()}"
+
+ try:
+ with open(self.shm_path, "wb") as f:
+ f.write(b"\0" * (1024 * 1024 * 1024)) # 1GB
+ except Exception as e:
+ self.fail(f"Failed to create shared memory file: {e}")
+
+ def prepare_and_launch_vm(
+ self, shm_path, vhost, incoming=False, vm=None, backend_transfer=True
+ ):
+ if not vm:
+ vm = self.vm
+
+ vm.set_console()
+ vm.add_args("-accel", "kvm")
+ vm.add_args("-device", "pcie-pci-bridge,id=pci.1,bus=pcie.0")
+ vm.add_args("-m", "1G")
+
+ vm.add_args(
+ "-object",
+ f"memory-backend-file,id=ram0,size=1G,mem-path={shm_path},share=on",
+ )
+ vm.add_args("-machine", "memory-backend=ram0")
+
+ vm.add_args(
+ "-drive",
+ f"file={self.ASSET_ALPINE_ISO.fetch()},media=cdrom,format=raw",
+ )
+
+ vm.add_args("-S")
+
+ if incoming:
+ vm.add_args("-incoming", "defer")
+
+ vm_s = "target" if incoming else "source"
+ self.log.info(f"Launching {vm_s} VM")
+ vm.launch()
+
+ if not backend_transfer:
+ tap_name = TAP_ID2 if incoming else TAP_ID
+ else:
+ tap_name = TAP_ID
+
+ self.add_virtio_net(vm, vhost, tap_name)
+
+ self.set_migration_capabilities(vm, backend_transfer)
+
+ def add_virtio_net(self, vm, vhost: bool, tap_name: str = "tap0"):
+ netdev_params = {
+ "id": "netdev.1",
+ "vhost": vhost,
+ "type": "tap",
+ "ifname": tap_name,
+ "script": "no",
+ "downscript": "no",
+ "queues": 4,
+ "vnet_hdr": True,
+ }
+
+ vm.cmd("netdev_add", netdev_params)
+
+ vm.cmd(
+ "device_add",
+ driver="virtio-net-pci",
+ romfile="",
+ id="vnet.1",
+ netdev="netdev.1",
+ mq=True,
+ vectors=18,
+ bus="pci.1",
+ mac=GUEST_MAC,
+ disable_legacy="off",
+ )
+
+ def set_migration_capabilities(self, vm, backend_transfer=True):
+ capabilities = [
+ {"capability": "events", "state": True},
+ {"capability": "x-ignore-shared", "state": True},
+ ]
+ vm.cmd("migrate-set-capabilities", {"capabilities": capabilities})
+ if backend_transfer:
+ res = vm.cmd("query-backend-transfer-support")
+ path = "/machine/peripheral/vnet.1/virtio-backend"
+ self.assertEqual(res, [{"path": path}])
+ vm.cmd("migrate-set-parameters", {"backend-transfer": [path]})
+
+ def setup_guest_network(self) -> None:
+ exec_command_and_wait_for_pattern(self, "ip addr", "# ")
+ exec_command_and_wait_for_pattern(
+ self,
+ f"ip addr add {GUEST_IP_MASK} dev eth0 && "
+ "ip link set eth0 up && echo OK",
+ "OK",
+ )
+ self.wait_for_console_pattern("# ")
+
+ def do_test_tap_fd_migration(self, vhost, backend_transfer=True):
+ self.require_accelerator("kvm")
+ self.set_machine("q35")
+
+ socket_dir = self.socket_dir()
+ migration_socket = os.path.join(socket_dir.name, "migration.sock")
+
+ self.setup_shared_memory()
+
+ # Setup second TAP if needed
+ if not backend_transfer:
+ del_tap(TAP_ID2)
+ init_tap(TAP_ID2, with_ip=False)
+
+ self.prepare_and_launch_vm(
+ self.shm_path, vhost, backend_transfer=backend_transfer
+ )
+ self.vm.cmd("cont")
+ self.wait_for_console_pattern("login:")
+ exec_command_and_wait_for_pattern(self, "root", "# ")
+
+ self.setup_guest_network()
+
+ self.one_ping_from_guest(self.vm)
+ self.one_ping_from_host()
+ self.start_outer_ping()
+
+ # Get some successful pings before migration
+ time.sleep(0.5)
+
+ target_vm = self.get_vm(name="target")
+ self.prepare_and_launch_vm(
+ self.shm_path,
+ vhost,
+ incoming=True,
+ vm=target_vm,
+ backend_transfer=backend_transfer,
+ )
+
+ target_vm.cmd("migrate-incoming", {"uri": f"unix:{migration_socket}"})
+
+ self.log.info("Starting migration")
+ freeze_start = time.time()
+ self.vm.cmd("migrate", {"uri": f"unix:{migration_socket}"})
+
+ self.log.info("Waiting for migration completion")
+ wait_migration_finish(self.vm, target_vm)
+
+ # Switch network to tap1 if not using backend transfer
+ if not backend_transfer:
+ switch_network_to_tap2()
+
+ target_vm.cmd("cont")
+ freeze_end = time.time()
+
+ self.vm.shutdown()
+
+ self.log.info("Verifying PING on target VM after migration")
+ self.one_ping_from_guest(target_vm)
+ self.one_ping_from_host()
+
+ # And a bit more pings after source shutdown
+ time.sleep(0.3)
+ self.stop_ping_and_check(freeze_start, freeze_end)
+
+ target_vm.shutdown()
+
+ def test_tap_fd_migration(self):
+ self.do_test_tap_fd_migration(False)
+
+ def test_tap_fd_migration_vhost(self):
+ self.do_test_tap_fd_migration(True)
+
+ def test_tap_new_tap_migration(self):
+ self.do_test_tap_fd_migration(False, backend_transfer=False)
+
+ def test_tap_new_tap_migration_vhost(self):
+ self.do_test_tap_fd_migration(True, backend_transfer=False)
+
+
+if __name__ == "__main__":
+ LinuxKernelTest.main()
--
2.48.1
^ permalink raw reply related [flat|nested] 14+ messages in thread