virtio-net: live-TAP local migration
Subsystems (2)
v10 cover virtio-net: live-TAP local migration
Hi all!
Here is a new migration parameter backend-transfer, which allows to enable local migration of TAP virtio-net backend (and maybe other devices and backends in future), including its properties and open fds.
With this new option, management software doesn't need to initialize new TAP and do a switch to it. Nothing should be done around virtio-net in local migration: it just migrates and continues to use same TAP device. So we avoid extra logic in management software, extra allocations in kernel (for new TAP), and corresponding extra delay in migration downtime.
v10:
reworked interface:
1. backend-transfer migration parameter - simple boolean
2. backend-transfer option for virtio-net device - in combination with
[1] it enables the feature for concrete virtio-net device
3. incoming-fds option for TAP - to skip any open() calls and setting up the fd, and instead wait for incoming FD.
Why we need [1]? To be able to simply choose between local and remote migration, not touching device options.
Why we need [2]? Because otherwise we have to significantly complicate migration paremeter (to be a list of QOM paths of devices to enable backend-transfer for), which doesn't look good architectural design (we don't want to end with migration parameters like
feature1 = [list of QOM paths],
feature2 = [list of QOM paths]k,
...
Why we need [3]? To avoid complicated logic of postponing the whole initialization of TAP up to pre-incoming point (see
"[PATCH v9 0/9] net/tap: postpone connect"), and to make the whole feature more reliable: with such a parameter user is sure, that backend code will not do any open()/connect(), etc, which may influence running source vm. Automatic logic of 3 stage postponing in v9 (first, we postpone initialization up to attaching to frontend, then, if it's a virtio-net, it take ownership and postpone initializing of backend up to pre-incoming point (where we know migration parameters), and finally if it's a backend-transfer, postpone it up to post-load) can't be so reliable. Misconfiguration on target may lead to breaking source vm. And with separate parameter, everything becomes a lot simpler and reliable.
The series is based on
"[PATCH v2 00/12] net: refactoring and fixes"
Based-on: <[email protected]>
Vladimir Sementsov-Ogievskiy (8):
net/tap: move vhost-net open() calls to tap_parse_vhost_fds() net/tap: move vhost initialization to tap_setup_vhost()
qapi: add backend-transfer migration parameter
net: introduce vmstate_net_peer_backend
virtio-net: support backend-transfer migration net/tap: support backend-transfer migration tests/functional: add skipWithoutSudo() decorator tests/functional: add test_tap_migration
hw/core/machine.c | 4 +- hw/net/virtio-net.c | 137 +++++- include/hw/virtio/virtio-net.h | 2 + include/migration/misc.h | 2 + include/net/net.h | 6 + migration/options.c | 18 +- net/net.c | 47 ++ net/tap.c | 185 ++++++-- qapi/migration.json | 13 +- qapi/net.json | 6 +- tests/functional/qemu_test/decorators.py | 16 + tests/functional/x86_64/meson.build | 1 + tests/functional/x86_64/test_tap_migration.py | 401 ++++++++++++++++++ 13 files changed, 792 insertions(+), 46 deletions(-) create mode 100644 tests/functional/x86_64/test_tap_migration.py
Signature · 1 line
2.52.0
PATCH v10 1/8 net/tap: move vhost-net open() calls to tap_parse_vhost_fds()
1. Simplify code path: get vhostfds for all cases in one function.
2. Prepare for further tap-fd-migraton feature, when we'll need to postpone vhost initialization up to post-load stage.
--- net/tap.c | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-)
net/tap.c +21 -16
@@ -738,8 +738,7 @@ static bool net_init_tap_one(const NetdevTapOptions *tap, NetClientState *peer, } } -if (tap->has_vhost ? tap->vhost : - (vhostfd !=-1 ) || (tap->has_vhostforce && tap->vhostforce)) { +if (vhostfd !=-1 ) {VhostNetOptions options; options.backend_type =VHOST_BACKEND_TYPE_KERNEL ;
@@ -749,17 +748,6 @@ static bool net_init_tap_one(const NetdevTapOptions *tap, NetClientState *peer, }else { options.busyloop_timeout =0 ; } - -if (vhostfd ==-1 ) { - vhostfd =open ("/dev/vhost-net" ,O_RDWR ); -if (vhostfd <0 ) { -error_setg_file_open (errp, errno,"/dev/vhost-net" ); - goto failed; - } -if (!qemu_set_blocking (vhostfd, false, errp)) { - goto failed; - } - } options.opaque = (void *)(uintptr_t )vhostfd; options.nvqs =2 ; options.feature_bits = kernel_feature_bits;
@@ -841,13 +829,30 @@ static int tap_parse_fds_and_queues(const NetdevTapOptions *tap, int **fds,static bool tap_parse_vhost_fds (const NetdevTapOptions *tap,int **vhost_fds,unsigned queues,Error **errp) { -if (!(tap->vhostfd || tap->vhostfds)) { +bool need_vhost = tap->has_vhost ? tap->vhost : + ((tap->vhostfd || tap->vhostfds) || + (tap->has_vhostforce && tap->vhostforce)); + +if (!need_vhost) { *vhost_fds =NULL ;return true; } -if (net_parse_fds (tap->fd ?: tap->fds, vhost_fds, queues, errp) <0 ) { -return false; +if (tap->vhostfd || tap->vhostfds) { +if (net_parse_fds (tap->fd ?: tap->fds, vhost_fds, queues, errp) <0 ) { +return false; + } + }else if (!(tap->vhostfd || tap->vhostfds)) { + *vhost_fds =g_new (int, queues); +for (int i =0 ; i < queues; i++) { +int vhostfd =open ("/dev/vhost-net" ,O_RDWR ); +if (vhostfd <0 ) { +error_setg_file_open (errp, errno,"/dev/vhost-net" ); +net_free_fds (*vhost_fds, i); +return false; + } + (*vhost_fds)[i] = vhostfd; + } }if (!unblock_fds (*vhost_fds, queues, errp)) {
Signature · 1 line
2.52.0
PATCH v10 2/8 net/tap: move vhost initialization to tap_setup_vhost()
In reply to Vladimir Sementsov-OgievskiyMake a new helper function in a way it can be reused later for TAP fd-migration feature: we'll need to initialize vhost in a later point when we doesn't have access to QAPI parameters.
--- net/tap.c | 62 ++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 38 insertions(+), 24 deletions(-)
net/tap.c +38 -24
@@ -71,6 +71,8 @@ static const int kernel_feature_bits[] = { typedef struct TAPState { NetClientState nc; int fd; + int vhostfd; + uint32_t vhost_busyloop_timeout; char down_script[1024]; char down_script_arg[128]; uint8_t buf[NET_BUFSIZE];
@@ -704,6 +706,38 @@ static int net_tap_init(const NetdevTapOptions *tap, int *vnet_hdr,#define MAX_TAP_QUEUES 1024 +static bool tap_setup_vhost (TAPState *s,Error **errp) +{ +VhostNetOptions options; + +if (s->vhostfd ==-1 ) { +return true; + } + + options.backend_type =VHOST_BACKEND_TYPE_KERNEL ; + options.net_backend = &s->nc; + options.busyloop_timeout = s->vhost_busyloop_timeout; + options.opaque = (void *)(uintptr_t )s->vhostfd; + options.nvqs =2 ; + options.feature_bits = kernel_feature_bits; + options.get_acked_features =NULL ; + options.save_acked_features =NULL ; + options.max_tx_queue_size =0 ; + options.is_vhost_user = false; + + s->vhost_net =vhost_net_init (&options); +if (!s->vhost_net) { +error_setg (errp, +"vhost-net requested but could not be initialized" ); +return false; + } + +/* vhostfd ownership is passed to s->vhost_net */ + s->vhostfd =-1 ; + +return true; +} + static bool net_init_tap_one(const NetdevTapOptions *tap, NetClientState *peer, const char *name, const char *ifname, const char *script,
@@ -738,30 +772,10 @@ static bool net_init_tap_one(const NetdevTapOptions *tap, NetClientState *peer, } } -if (vhostfd !=-1 ) { -VhostNetOptions options; - - options.backend_type =VHOST_BACKEND_TYPE_KERNEL ; - options.net_backend = &s->nc; -if (tap->has_poll_us) { - options.busyloop_timeout = tap->poll_us; - }else { - options.busyloop_timeout =0 ; - } - options.opaque = (void *)(uintptr_t )vhostfd; - options.nvqs =2 ; - options.feature_bits = kernel_feature_bits; - options.get_acked_features =NULL ; - options.save_acked_features =NULL ; - options.max_tx_queue_size =0 ; - options.is_vhost_user = false; - - s->vhost_net =vhost_net_init (&options); -if (!s->vhost_net) { -error_setg (errp, -"vhost-net requested but could not be initialized" ); - goto failed; - } + s->vhostfd = vhostfd; + s->vhost_busyloop_timeout = tap->has_poll_us ? tap->poll_us :0 ; +if (!tap_setup_vhost (s, errp)) { +return false; }return true;
Signature · 1 line
2.52.0
PATCH v10 3/8 qapi: add backend-transfer migration parameter
In reply to Vladimir Sementsov-OgievskiyWe 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 enables the feature, for supporting devices (no one at the moment).
--- include/migration/misc.h | 2 ++ migration/options.c | 18 +++++++++++++++++- qapi/migration.json | 13 +++++++++++-- 3 files changed, 30 insertions(+), 3 deletions(-)
include/migration/misc.h +2 -0
@@ -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 ); +bool migrate_backend_transfer (void ); +#endif
migration/options.c +17 -1
@@ -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"
@@ -336,6 +338,12 @@ bool migrate_mapped_ram(void)return s->capabilities[MIGRATION_CAPABILITY_MAPPED_RAM ]; } +bool migrate_backend_transfer (void ) +{ +MigrationState *s =migrate_get_current (); +return s->parameters.backend_transfer; +} +bool migrate_ignore_shared (void ) {MigrationState *s =migrate_get_current ();
@@ -1047,7 +1055,7 @@ static void migrate_mark_all_params_present(MigrationParameters *p) &p->has_announce_step, &p->has_block_bitmap_mapping, &p->has_x_vcpu_dirty_limit_period, &p->has_vcpu_dirty_limit, &p->has_mode, &p->has_zero_page_detection, &p->has_direct_io, - &p->has_cpr_exec_command, + &p->has_cpr_exec_command, &p->has_backend_transfer, }; len =ARRAY_SIZE (has_fields);
@@ -1386,6 +1394,10 @@ static void migrate_params_test_apply(MigrationParameters *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 (MigrationParameters *params)
@@ -1514,6 +1526,10 @@ static void migrate_params_apply(MigrationParameters *params) s->parameters.cpr_exec_command =QAPI_CLONE (strList, params->cpr_exec_command); } + +if (params->has_backend_transfer) { + s->parameters.backend_transfer = params->backend_transfer; + } }void qmp_migrate_set_parameters (MigrationParameters *params,Error **errp)
qapi/migration.json +11 -2
@@ -828,7 +828,8 @@ 'mode', 'zero-page-detection', 'direct-io', - 'cpr-exec-command'] } + 'cpr-exec-command', + 'backend-transfer'] } ## # @migrate-set-parameters:
@@ -1004,6 +1005,13 @@ # is @cpr-exec. The first list element is the program's filename, # the remainder its arguments. (Since 10.2) # +# @backend-transfer: Enable backend-transfer feature for devices that +# supports it. In general that means that backend state and its +# file descriptors are passed to the destination in the migraton +# channel (which must be a UNIX socket). Individual devices +# declare the support for backend-transfer by per-device +# backend-transfer option. (Since 11.0) +# # Features: # # @unstable: Members @x-checkpoint-delay and
@@ -1043,7 +1051,8 @@ '*mode': 'MigMode', '*zero-page-detection': 'ZeroPageDetection', '*direct-io': 'bool', - '*cpr-exec-command': [ 'str' ]} } + '*cpr-exec-command': [ 'str' ], + '*backend-transfer': 'bool' } } ## # @query-migrate-parameters:
Signature · 1 line
2.52.0
Re: [PATCH v10 3/8] qapi: add backend-transfer migration parameter
Quoted 10 lines · Vladimir Sementsov-Ogievskiy
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 enables the feature, for supporting devices (no one at the moment).
Signed-off-by Vladimir Sementsov-Ogievskiy <[email protected]>
[...]
Quoted 16 lines
void
qmp_migrate_set_parameters(MigrationParameters *params, Error **errp)qapi/migration.json +2
-1@@ -828,7 +828,8 @@ 'mode', 'zero-page-detection', 'direct-io', - 'cpr-exec-command'] } + 'cpr-exec-command', + 'backend-transfer'] } ## # @migrate-set-parameters:
qapi/migration.json line 1009
Quoted 5 lines
qapi/migration.json +2
-0@@ -1004,6 +1005,13 @@ # is @cpr-exec. The first list element is the program's filename, # the remainder its arguments. (Since 10.2) # +# @backend-transfer: Enable backend-transfer feature for devices that +# supports it. In general that means that backend state and its
support
Quoted 9 lines
qapi/migration.json +5
-0+# file descriptors are passed to the destination in the migraton +# channel (which must be a UNIX socket). Individual devices +# declare the support for backend-transfer by per-device +# backend-transfer option. (Since 11.0) +# # Features: # # @unstable: Members @x-checkpoint-delay and
qapi/migration.json line 1058
Quoted 9 lines
qapi/migration.json +2
-1@@ -1043,7 +1051,8 @@ '*mode': 'MigMode', '*zero-page-detection': 'ZeroPageDetection', '*direct-io': 'bool', - '*cpr-exec-command': [ 'str' ]} } + '*cpr-exec-command': [ 'str' ], + '*backend-transfer': 'bool' } } ## # @query-migrate-parameters:
With the grammar fix, QAPI schema
Re: [PATCH v10 3/8] qapi: add backend-transfer migration parameter
In reply to Vladimir Sementsov-Ogievskiyqapi/migration.json line 1013
Quoted 11 lines · Vladimir Sementsov-Ogievskiy
# @migrate-set-parameters:
qapi/migration.json +6
-0@@ -1004,6 +1005,13 @@ # is @cpr-exec. The first list element is the program's filename, # the remainder its arguments. (Since 10.2) # +# @backend-transfer: Enable backend-transfer feature for devices that +# supports it. In general that means that backend state and its +# file descriptors are passed to the destination in the migraton +# channel (which must be a UNIX socket). Individual devices +# declare the support for backend-transfer by per-device +# backend-transfer option. (Since 11.0)
I still think it'll be nice to either have "local" in the name of parameter or at least document it with crystal clear terms.
I used to suggest fd-passing, but maybe you wanted to emphasize there's more than fds to be migrated at least for tap? Then it can still be "local-backend-transfer", because nobody stops a device to transfer backend states in a remote migration either.. so "backend-transfer" seems to also work for remote migrations, but it is not.
Or at least mentioned explicitly in the comment, saying this is a local migration / upgrade.
If you could at least update the doc on the locality attribute for the migration (one way or another..), feel free to take:
If you decide to rename, that's even better.
Thanks,
Signature · 1 line
Peter Xu
Re: [PATCH v10 3/8] qapi: add backend-transfer migration parameter
Quoted 16 lines · Peter Xu
qapi/migration.json line 1013
Quoted 11 lines · Vladimir Sementsov-Ogievskiy
# @migrate-set-parameters:
qapi/migration.json +6
-0@@ -1004,6 +1005,13 @@ # is @cpr-exec. The first list element is the program's filename, # the remainder its arguments. (Since 10.2) # +# @backend-transfer: Enable backend-transfer feature for devices that +# supports it. In general that means that backend state and its +# file descriptors are passed to the destination in the migraton +# channel (which must be a UNIX socket). Individual devices +# declare the support for backend-transfer by per-device +# backend-transfer option. (Since 11.0)I still think it'll be nice to either have "local" in the name of parameter or at least document it with crystal clear terms.
Quoted 8 lines
I used to suggest fd-passing, but maybe you wanted to emphasize there's more than fds to be migrated at least for tap? Then it can still be "local-backend-transfer", because nobody stops a device to transfer backend states in a remote migration either.. so "backend-transfer" seems to also work for remote migrations, but it is not.
Or at least mentioned explicitly in the comment, saying this is a local migration / upgrade.
Documenting the restriction is a must regardless of naming. The proposed text does document it, but only indirectly: "(which must be a UNIX socket)". Could be improved, I guess.
Capturing the restriction in the name might help. But it also makes the name longer. Feels like a matter of taste to me. You guys decide :)
Quoted 8 lines
If you could at least update the doc on the locality attribute for the migration (one way or another..), feel free to take:
Acked-by Peter Xu <[email protected]>If you decide to rename, that's even better.
Thanks,
Re: [PATCH v10 3/8] qapi: add backend-transfer migration parameter
Quoted 18 lines · Markus Armbruster
Quoted 16 lines · Peter Xu
qapi/migration.json line 1013
Quoted 11 lines · Vladimir Sementsov-Ogievskiy
# @migrate-set-parameters:
qapi/migration.json +6
-0@@ -1004,6 +1005,13 @@ # is @cpr-exec. The first list element is the program's filename, # the remainder its arguments. (Since 10.2) # +# @backend-transfer: Enable backend-transfer feature for devices that +# supports it. In general that means that backend state and its +# file descriptors are passed to the destination in the migraton +# channel (which must be a UNIX socket). Individual devices +# declare the support for backend-transfer by per-device +# backend-transfer option. (Since 11.0)I still think it'll be nice to either have "local" in the name of parameter or at least document it with crystal clear terms.
Quoted 2 lines
Quoted 2 lines
I used to suggest fd-passing, but maybe you wanted to emphasize there's more than fds to be migrated at least for tap?
For vhost-user-blk it's the same: not only FDs.
Quoted 4 lines
Quoted 4 lines
Then it can still be
"local-backend-transfer", because nobody stops a device to transfer backend states in a remote migration either.. so "backend-transfer" seems to also work for remote migrations, but it is not.
Hmm. I imagine a mechanism, where OS supports passing FDs to another host. This needs support for actually migrating the corresponding kernel object by OS automatically. But theoretically I think it can be done transparently for userspace QEMU process, which will simply pass FDs to the some special socket, similar to UNIX domain socket.
So, the key aspect is that we should be able to pass FDs to the migration channel, which currently meant that it must be UNIX domain socket, and it must be local migration. But in future it may change.
And yes, "backend-transfer" work for remote migration of backend. If we ever implement remote backend migration, why not to reuse "backend-transfer" for it? Even if there will not be transparent support from OS, and we'll implement another mechanics, we may add new parameter
backend-transfer-mechanism = "scm-rights" | "something-other"
(or we can put this into "backend-transfer", supporting passing string to it and deprecating boolean)
More over, this future "remote-backend-transfer" could be used for local migration, so again, it should be called simply "backend-transfer"..
Quoted 4 lines
Quoted 3 lines
Or at least mentioned explicitly in the comment, saying this is a local migration / upgrade.
Quoted 16 lines
Documenting the restriction is a must regardless of naming. The proposed text does document it, but only indirectly: "(which must be a UNIX socket)". Could be improved, I guess.
Capturing the restriction in the name might help. But it also makes the name longer. Feels like a matter of taste to me. You guys decide :)
Quoted 8 lines
If you could at least update the doc on the locality attribute for the migration (one way or another..), feel free to take:
Acked-by Peter Xu <[email protected]>If you decide to rename, that's even better.
Thanks,
I'm OK with any name, but if you agree with my arguments above, I'd keep "backend-transfer" name, and update the spec:
@backend-transfer: Enable backend-transfer feature for devices that
support it. In general that means that backend state and its file descriptors are passed to the destination in the migraton channel. Individual devices declare the support for backend-transfer by per-device backend-transfer option. SCM_RIGHT mechanism used to pass FDs, so backend-transfer requires migration to be local and the channel to be UNIX domain socket. (Since 11.0)
Signature · 2 lines
Best regards, Vladimir
Re: [PATCH v10 3/8] qapi: add backend-transfer migration parameter
Quoted 35 lines · Vladimir Sementsov-Ogievskiy
Quoted 18 lines · Markus Armbruster
Quoted 16 lines · Peter Xu
qapi/migration.json line 1013
Quoted 11 lines · Vladimir Sementsov-Ogievskiy
# @migrate-set-parameters:
qapi/migration.json +6
-0@@ -1004,6 +1005,13 @@ # is @cpr-exec. The first list element is the program's filename, # the remainder its arguments. (Since 10.2) # +# @backend-transfer: Enable backend-transfer feature for devices that +# supports it. In general that means that backend state and its +# file descriptors are passed to the destination in the migraton +# channel (which must be a UNIX socket). Individual devices +# declare the support for backend-transfer by per-device +# backend-transfer option. (Since 11.0)I still think it'll be nice to either have "local" in the name of parameter or at least document it with crystal clear terms.
Quoted 2 lines
Quoted 2 lines
I used to suggest fd-passing, but maybe you wanted to emphasize there's more than fds to be migrated at least for tap?
For vhost-user-blk it's the same: not only FDs.
Quoted 4 lines
Quoted 4 lines
Then it can still be
"local-backend-transfer", because nobody stops a device to transfer backend states in a remote migration either.. so "backend-transfer" seems to also work for remote migrations, but it is not.Hmm. I imagine a mechanism, where OS supports passing FDs to another host. This needs support for actually migrating the corresponding kernel object by OS automatically. But theoretically I think it can be done transparently for userspace QEMU process, which will simply pass FDs to the some special socket, similar to UNIX domain socket.
Quoted 3 lines
So, the key aspect is that we should be able to pass FDs to the migration channel, which currently meant that it must be UNIX domain socket, and it must be local migration. But in future it may change.
That's a nice vision, but IMHO we shouldn't take it into account when defining any QEMU interface, when it's only about pure imaginations.. unless there is solid work in progress, or ideas proposed / known feasible at least.
Quoted 9 lines
And yes, "backend-transfer" work for remote migration of backend. If we ever implement remote backend migration, why not to reuse "backend-transfer" for it? Even if there will not be transparent support from OS, and we'll implement another mechanics, we may add new parameter
backend-transfer-mechanism = "scm-rights" | "something-other"
Yes, this will look much better. We likely shouldn't make it "scm-rights", it should be generic terms that applies to all platforms like "local", even if the implication / implementation might be different on various platforms.
That's also the major confusion I got when I was reading the other vhost-user-blk series, thought it was a local migration but not.
I feel like the interface is simply wrong to make it one covering both, or at least it shouldn't be a boolean as you said because it represents more than one use case.
If it's a boolean, it also shouldn't rely on UNIX sockets if it was trying to describe a remote migration, right? The vhost-usr-blk way of backend-migration doesn't require UNIX socket, or does it?
Especially, if we still want to have your new proposal try to work for CPR too or even replace it some day (or a continuous set of proposals in the future, from different developers based on this feature), we need to have a solid and clear way represents what CPR does, which is to do local fd sharing. "backend-transfer: local" or something similar can be that.
Quoted 3 lines
(or we can put this into "backend-transfer", supporting passing string to it and deprecating boolean)
It can be a enum, something like NONE, LOCAL, REMOTE. But before that..
Quoted 3 lines
More over, this future "remote-backend-transfer" could be used for local migration, so again, it should be called simply "backend-transfer"..
Yes, REMOTE might be slightly misleading. And considering you seem to want to allow any of below to work:
(1) enable fd migrations only,
(2) enable remote migrations on backends only,
(3) enable both of (1)+(2)
Maybe we should have two different feature bits? The per-device one can be kept as backend-transfer, however we need to change the global migration knob to something describing a local migration.
In summary, still 1 new parameter for migration, 1 new parameter for device, but adjust to:
- Migration parameter: "local", boolean, when set, the migration must be a local migration within host (which requires UNIX sockets on Linux)
- Per-device parameter "backend-transfer", boolean, when set, device will migrate backends when migration happens. Otherwise, backends are not migrated; dest QEMU needs to re-initialize it. The backends may or may not contain FDs.
When the backend device states contain FDs and FD migrations are required, it requires "local" set first above, or it should fail the migration when user requested backend-transfer=on.
When it doesn't contain FD at all (or FD migration is not a must?), it should either migrate the backend or not depending on the user's selection.
For tap (your series here), you need to set both ON and required.
For vhost-usr-blk, that only needs to set per-device knob to ON, the other one shouldn't matter.
Then when we want to replace cpr, we request people switch (cpr-transfer only, keeping cpr-exec / cpr-reboot aside for now) from setting mode=cpr-transfer to local=on, which hopefully will start work as before. The per-device parameter doesn't matter in this case.
Would this be more reasonable?
Thanks,
Signature · 1 line
Peter Xu
Re: [PATCH v10 3/8] qapi: add backend-transfer migration parameter
Quoted 63 lines · Peter Xu
Quoted 35 lines · Vladimir Sementsov-Ogievskiy
Quoted 18 lines · Markus Armbruster
Quoted 16 lines · Peter Xu
qapi/migration.json line 1013
Quoted 11 lines · Vladimir Sementsov-Ogievskiy
# @migrate-set-parameters:
qapi/migration.json +6
-0@@ -1004,6 +1005,13 @@ # is @cpr-exec. The first list element is the program's filename, # the remainder its arguments. (Since 10.2) # +# @backend-transfer: Enable backend-transfer feature for devices that +# supports it. In general that means that backend state and its +# file descriptors are passed to the destination in the migraton +# channel (which must be a UNIX socket). Individual devices +# declare the support for backend-transfer by per-device +# backend-transfer option. (Since 11.0)I still think it'll be nice to either have "local" in the name of parameter or at least document it with crystal clear terms.
Quoted 2 lines
Quoted 2 lines
I used to suggest fd-passing, but maybe you wanted to emphasize there's more than fds to be migrated at least for tap?
For vhost-user-blk it's the same: not only FDs.
Quoted 4 lines
Quoted 4 lines
Then it can still be
"local-backend-transfer", because nobody stops a device to transfer backend states in a remote migration either.. so "backend-transfer" seems to also work for remote migrations, but it is not.Hmm. I imagine a mechanism, where OS supports passing FDs to another host. This needs support for actually migrating the corresponding kernel object by OS automatically. But theoretically I think it can be done transparently for userspace QEMU process, which will simply pass FDs to the some special socket, similar to UNIX domain socket.
Quoted 3 lines
So, the key aspect is that we should be able to pass FDs to the migration channel, which currently meant that it must be UNIX domain socket, and it must be local migration. But in future it may change.
That's a nice vision, but IMHO we shouldn't take it into account when defining any QEMU interface, when it's only about pure imaginations.. unless there is solid work in progress, or ideas proposed / known feasible at least.
Quoted 9 lines
And yes, "backend-transfer" work for remote migration of backend. If we ever implement remote backend migration, why not to reuse "backend-transfer" for it? Even if there will not be transparent support from OS, and we'll implement another mechanics, we may add new parameter
backend-transfer-mechanism = "scm-rights" | "something-other"
Yes, this will look much better. We likely shouldn't make it "scm-rights", it should be generic terms that applies to all platforms like "local", even if the implication / implementation might be different on various platforms.
That's also the major confusion I got when I was reading the other vhost-user-blk series, thought it was a local migration but not.
Quoted 7 lines
I feel like the interface is simply wrong to make it one covering both, or at least it shouldn't be a boolean as you said because it represents more than one use case.
If it's a boolean, it also shouldn't rely on UNIX sockets if it was trying to describe a remote migration, right? The vhost-usr-blk way of backend-migration doesn't require UNIX socket, or does it?
It does require UNIX socket too.
Quoted 52 lines
Especially, if we still want to have your new proposal try to work for CPR too or even replace it some day (or a continuous set of proposals in the future, from different developers based on this feature), we need to have a solid and clear way represents what CPR does, which is to do local fd sharing. "backend-transfer: local" or something similar can be that.
Quoted 3 lines
(or we can put this into "backend-transfer", supporting passing string to it and deprecating boolean)
It can be a enum, something like NONE, LOCAL, REMOTE. But before that..
Quoted 3 lines
More over, this future "remote-backend-transfer" could be used for local migration, so again, it should be called simply "backend-transfer"..
Yes, REMOTE might be slightly misleading. And considering you seem to want to allow any of below to work:
(1) enable fd migrations only,
(2) enable remote migrations on backends only,
(3) enable both of (1)+(2)Maybe we should have two different feature bits? The per-device one can be kept as backend-transfer, however we need to change the global migration knob to something describing a local migration.
In summary, still 1 new parameter for migration, 1 new parameter for device, but adjust to:
- Migration parameter: "local", boolean, when set, the migration must be a local migration within host (which requires UNIX sockets on Linux)
- Per-device parameter "backend-transfer", boolean, when set, device will migrate backends when migration happens. Otherwise, backends are not migrated; dest QEMU needs to re-initialize it. The backends may or may not contain FDs.
When the backend device states contain FDs and FD migrations are required, it requires "local" set first above, or it should fail the migration when user requested backend-transfer=on.
When it doesn't contain FD at all (or FD migration is not a must?), it should either migrate the backend or not depending on the user's selection.
For tap (your series here), you need to set both ON and required.
For vhost-usr-blk, that only needs to set per-device knob to ON, the other one shouldn't matter.
Quoted 7 lines
Then when we want to replace cpr, we request people switch (cpr-transfer only, keeping cpr-exec / cpr-reboot aside for now) from setting mode=cpr-transfer to local=on, which hopefully will start work as before. The per-device parameter doesn't matter in this case.
Would this be more reasonable?
Hmm. So, with backend-transfer=on on device and local mig parameter set to false, it fails?
But this way we'll have to set backend-transfer to on/off before any migration (local or remote) on all devices with help of set-qom. That's not comfortable.
The original idea was that backend-transfer is done for the device when both migration parameter and device option are set to true. This way before the migration (local or remote) we only have to set appropriate migration parameters. And backend-transfer per-device options can be setup once (and the same way) when starting the QEMU, or they may be inherited from Machine Type. And with such logic, it's good to have similar names for migration parameter and device option.
Considering all this, could we keep the logic as is (in this patch), but rename backend-transfer parameter to local-backend-transfer, as you proposed before? Or turn it into "backend-transfer" = "local" | "off" (but IMHO it's too optimistic:
who knows, will we really add something into this enum in the future? I don't have such plans)
Signature · 2 lines
Best regards, Vladimir
Re: [PATCH v10 3/8] qapi: add backend-transfer migration parameter
Quoted 68 lines · Vladimir Sementsov-Ogievskiy
Quoted 67 lines · Peter Xu
Quoted 35 lines · Vladimir Sementsov-Ogievskiy
Quoted 18 lines · Markus Armbruster
Quoted 16 lines · Peter Xu
qapi/migration.json line 1013
Quoted 11 lines · Vladimir Sementsov-Ogievskiy
# @migrate-set-parameters:
qapi/migration.json +6
-0@@ -1004,6 +1005,13 @@ # is @cpr-exec. The first list element is the program's filename, # the remainder its arguments. (Since 10.2) # +# @backend-transfer: Enable backend-transfer feature for devices that +# supports it. In general that means that backend state and its +# file descriptors are passed to the destination in the migraton +# channel (which must be a UNIX socket). Individual devices +# declare the support for backend-transfer by per-device +# backend-transfer option. (Since 11.0)I still think it'll be nice to either have "local" in the name of parameter or at least document it with crystal clear terms.
Quoted 2 lines
Quoted 2 lines
I used to suggest fd-passing, but maybe you wanted to emphasize there's more than fds to be migrated at least for tap?
For vhost-user-blk it's the same: not only FDs.
Quoted 4 lines
Quoted 4 lines
Then it can still be
"local-backend-transfer", because nobody stops a device to transfer backend states in a remote migration either.. so "backend-transfer" seems to also work for remote migrations, but it is not.Hmm. I imagine a mechanism, where OS supports passing FDs to another host. This needs support for actually migrating the corresponding kernel object by OS automatically. But theoretically I think it can be done transparently for userspace QEMU process, which will simply pass FDs to the some special socket, similar to UNIX domain socket.
Quoted 3 lines
So, the key aspect is that we should be able to pass FDs to the migration channel, which currently meant that it must be UNIX domain socket, and it must be local migration. But in future it may change.
That's a nice vision, but IMHO we shouldn't take it into account when defining any QEMU interface, when it's only about pure imaginations.. unless there is solid work in progress, or ideas proposed / known feasible at least.
Quoted 9 lines
And yes, "backend-transfer" work for remote migration of backend. If we ever implement remote backend migration, why not to reuse "backend-transfer" for it? Even if there will not be transparent support from OS, and we'll implement another mechanics, we may add new parameter
backend-transfer-mechanism = "scm-rights" | "something-other"
Yes, this will look much better. We likely shouldn't make it "scm-rights", it should be generic terms that applies to all platforms like "local", even if the implication / implementation might be different on various platforms.
That's also the major confusion I got when I was reading the other vhost-user-blk series, thought it was a local migration but not.
I feel like the interface is simply wrong to make it one covering both, or at least it shouldn't be a boolean as you said because it represents more than one use case.
Quoted 5 lines
Quoted 3 lines
If it's a boolean, it also shouldn't rely on UNIX sockets if it was trying to describe a remote migration, right? The vhost-usr-blk way of backend-migration doesn't require UNIX socket, or does it?
It does require UNIX socket too.
I'm lost once more.. :( Could you share what requires the UNIX socket for the other work here?
https://lore.kernel.org/all/[email protected]/#r
There's indeed the inflight->fd, but it's not migrated but allocated before taking the inflight buffer. I don't see how it requires UNIX socket.
Quoted 58 lines
Quoted 58 lines
Especially, if we still want to have your new proposal try to work for CPR too or even replace it some day (or a continuous set of proposals in the future, from different developers based on this feature), we need to have a solid and clear way represents what CPR does, which is to do local fd sharing. "backend-transfer: local" or something similar can be that.
Quoted 3 lines
(or we can put this into "backend-transfer", supporting passing string to it and deprecating boolean)
It can be a enum, something like NONE, LOCAL, REMOTE. But before that..
Quoted 3 lines
More over, this future "remote-backend-transfer" could be used for local migration, so again, it should be called simply "backend-transfer"..
Yes, REMOTE might be slightly misleading. And considering you seem to want to allow any of below to work:
(1) enable fd migrations only,
(2) enable remote migrations on backends only,
(3) enable both of (1)+(2)Maybe we should have two different feature bits? The per-device one can be kept as backend-transfer, however we need to change the global migration knob to something describing a local migration.
In summary, still 1 new parameter for migration, 1 new parameter for device, but adjust to:
- Migration parameter: "local", boolean, when set, the migration must be a local migration within host (which requires UNIX sockets on Linux)
- Per-device parameter "backend-transfer", boolean, when set, device will migrate backends when migration happens. Otherwise, backends are not migrated; dest QEMU needs to re-initialize it. The backends may or may not contain FDs.
When the backend device states contain FDs and FD migrations are required, it requires "local" set first above, or it should fail the migration when user requested backend-transfer=on.
When it doesn't contain FD at all (or FD migration is not a must?), it should either migrate the backend or not depending on the user's selection.
For tap (your series here), you need to set both ON and required.
For vhost-usr-blk, that only needs to set per-device knob to ON, the other one shouldn't matter.
Then when we want to replace cpr, we request people switch (cpr-transfer only, keeping cpr-exec / cpr-reboot aside for now) from setting mode=cpr-transfer to local=on, which hopefully will start work as before. The per-device parameter doesn't matter in this case.
Quoted 7 lines
Quoted 2 lines
Would this be more reasonable?
Hmm. So, with backend-transfer=on on device and local mig parameter set to false, it fails?
But this way we'll have to set backend-transfer to on/off before any migration (local or remote) on all devices with help of set-qom. That's not comfortable.
Personally as long as we can separate the two use cases with the two knobs properly, then it will look good to me. It doesn't need to be strictly a failure on such conflictions indeed.
E.g. we can also define this case (local=off, backend-transfer=on) the other way round if failing is not wanted; that is, allow migration to happen but skip the part of backend transfer that requires the locality.
Fundamentally, we should accept two kinds of backend-transfer impl:
- When it is supported regardless of local=on/off. I believe that's vhost-usr-blk's case (but I'll now need to double check with you again above on UNIX dependency). Then this only relies on the per-dev knob.
- When it is supported only if local=on (this series). This part is where we can define the behavior of whether we fail the migration on local=off, or we skip the feature instead.
So I think we can choose to skip it for the latter. It should almost be the same logic as what you have done in this patchset, afaict, besides the rename and re-definition of the migration knob.
Quoted 7 lines
The original idea was that backend-transfer is done for the device when both migration parameter and device option are set to true. This way before the migration (local or remote) we only have to set appropriate migration parameters. And backend-transfer per-device options can be setup once (and the same way) when starting the QEMU, or they may be inherited from Machine Type. And with such logic, it's good to have similar names for migration parameter and device option.
I hope above will solve this problem. IIUC what you described should work if we tweat the new proposal on the local=off & backend-transfer=on case.
Quoted 6 lines
Considering all this, could we keep the logic as is (in this patch), but rename backend-transfer parameter to local-backend-transfer, as you proposed before? Or turn it into "backend-transfer" = "local" | "off" (but IMHO it's too optimistic:
who knows, will we really add something into this enum in the future? I don't have such plans)
IMHO "local" would be nicer because it's very simple, generic and clear on is own. It almost says "requires UNIX sockets" on Linux and it also opens the door for this parameter to be reused when without a backend: for example, when some frontend or any-not-trivially-a-backend also want to migrate an FD in the future. I'm not surprised to see it coming.
But let's finish above disucssion and see if we can reach the same page.
Thanks,
Signature · 1 line
Peter Xu
Re: [PATCH v10 3/8] qapi: add backend-transfer migration parameter
Quoted 73 lines · Peter Xu
Quoted 72 lines · Vladimir Sementsov-Ogievskiy
Quoted 70 lines · Peter Xu
Quoted 35 lines · Vladimir Sementsov-Ogievskiy
Quoted 18 lines · Markus Armbruster
Quoted 16 lines · Peter Xu
Review line 1013
Quoted 11 lines · Vladimir Sementsov-Ogievskiy
# @migrate-set-parameters:
(quoted diff) +6
-0@@ -1004,6 +1005,13 @@ # is @cpr-exec. The first list element is the program's filename, # the remainder its arguments. (Since 10.2) # +# @backend-transfer: Enable backend-transfer feature for devices that +# supports it. In general that means that backend state and its +# file descriptors are passed to the destination in the migraton +# channel (which must be a UNIX socket). Individual devices +# declare the support for backend-transfer by per-device +# backend-transfer option. (Since 11.0)I still think it'll be nice to either have "local" in the name of parameter or at least document it with crystal clear terms.
Quoted 2 lines
Quoted 2 lines
I used to suggest fd-passing, but maybe you wanted to emphasize there's more than fds to be migrated at least for tap?
For vhost-user-blk it's the same: not only FDs.
Quoted 4 lines
Quoted 4 lines
Then it can still be
"local-backend-transfer", because nobody stops a device to transfer backend states in a remote migration either.. so "backend-transfer" seems to also work for remote migrations, but it is not.Hmm. I imagine a mechanism, where OS supports passing FDs to another host. This needs support for actually migrating the corresponding kernel object by OS automatically. But theoretically I think it can be done transparently for userspace QEMU process, which will simply pass FDs to the some special socket, similar to UNIX domain socket.
Quoted 3 lines
So, the key aspect is that we should be able to pass FDs to the migration channel, which currently meant that it must be UNIX domain socket, and it must be local migration. But in future it may change.
That's a nice vision, but IMHO we shouldn't take it into account when defining any QEMU interface, when it's only about pure imaginations.. unless there is solid work in progress, or ideas proposed / known feasible at least.
Quoted 9 lines
And yes, "backend-transfer" work for remote migration of backend. If we ever implement remote backend migration, why not to reuse "backend-transfer" for it? Even if there will not be transparent support from OS, and we'll implement another mechanics, we may add new parameter
backend-transfer-mechanism = "scm-rights" | "something-other"
Yes, this will look much better. We likely shouldn't make it "scm-rights", it should be generic terms that applies to all platforms like "local", even if the implication / implementation might be different on various platforms.
That's also the major confusion I got when I was reading the other vhost-user-blk series, thought it was a local migration but not.
I feel like the interface is simply wrong to make it one covering both, or at least it shouldn't be a boolean as you said because it represents more than one use case.
If it's a boolean, it also shouldn't rely on UNIX sockets if it was trying to describe a remote migration, right? The vhost-usr-blk way of backend-migration doesn't require UNIX socket, or does it?
Quoted 6 lines
Quoted 1 line
It does require UNIX socket too.
I'm lost once more.. :( Could you share what requires the UNIX socket for the other work here?
Ah sorry, I thought we are talking about my series "[PATCH v2 00/25] vhost-user-blk: live-backend local migration"
Of course, Alexander's series doesn't need UNIX socket.
Quoted 3 lines
There's indeed the
inflight->fd, but it's not migrated but allocated before taking the inflight buffer. I don't see how it requires UNIX socket.
It doesn't. But it doesn't transfer "the whole backend", only the inflight region.
Quoted 107 lines
Quoted 59 lines
Quoted 59 lines
Especially, if we still want to have your new proposal try to work for CPR too or even replace it some day (or a continuous set of proposals in the future, from different developers based on this feature), we need to have a solid and clear way represents what CPR does, which is to do local fd sharing. "backend-transfer: local" or something similar can be that.
Quoted 3 lines
(or we can put this into "backend-transfer", supporting passing string to it and deprecating boolean)
It can be a enum, something like NONE, LOCAL, REMOTE. But before that..
Quoted 3 lines
More over, this future "remote-backend-transfer" could be used for local migration, so again, it should be called simply "backend-transfer"..
Yes, REMOTE might be slightly misleading. And considering you seem to want to allow any of below to work:
(1) enable fd migrations only,
(2) enable remote migrations on backends only,
(3) enable both of (1)+(2)Maybe we should have two different feature bits? The per-device one can be kept as backend-transfer, however we need to change the global migration knob to something describing a local migration.
In summary, still 1 new parameter for migration, 1 new parameter for device, but adjust to:
- Migration parameter: "local", boolean, when set, the migration must be a local migration within host (which requires UNIX sockets on Linux)
- Per-device parameter "backend-transfer", boolean, when set, device will migrate backends when migration happens. Otherwise, backends are not migrated; dest QEMU needs to re-initialize it. The backends may or may not contain FDs.
When the backend device states contain FDs and FD migrations are required, it requires "local" set first above, or it should fail the migration when user requested backend-transfer=on.
When it doesn't contain FD at all (or FD migration is not a must?), it should either migrate the backend or not depending on the user's selection.
For tap (your series here), you need to set both ON and required.
For vhost-usr-blk, that only needs to set per-device knob to ON, the other one shouldn't matter.
Then when we want to replace cpr, we request people switch (cpr-transfer only, keeping cpr-exec / cpr-reboot aside for now) from setting mode=cpr-transfer to local=on, which hopefully will start work as before. The per-device parameter doesn't matter in this case.
Quoted 7 lines
Quoted 2 lines
Would this be more reasonable?
Hmm. So, with backend-transfer=on on device and local mig parameter set to false, it fails?
But this way we'll have to set backend-transfer to on/off before any migration (local or remote) on all devices with help of set-qom. That's not comfortable.
Personally as long as we can separate the two use cases with the two knobs properly, then it will look good to me. It doesn't need to be strictly a failure on such conflictions indeed.
E.g. we can also define this case (local=off, backend-transfer=on) the other way round if failing is not wanted; that is, allow migration to happen but skip the part of backend transfer that requires the locality.
Fundamentally, we should accept two kinds of backend-transfer impl:
- When it is supported regardless of local=on/off. I believe that's vhost-usr-blk's case (but I'll now need to double check with you again above on UNIX dependency). Then this only relies on the per-dev knob.
- When it is supported only if local=on (this series). This part is where we can define the behavior of whether we fail the migration on local=off, or we skip the feature instead.
So I think we can choose to skip it for the latter. It should almost be the same logic as what you have done in this patchset, afaict, besides the rename and re-definition of the migration knob.
Quoted 7 lines
The original idea was that backend-transfer is done for the device when both migration parameter and device option are set to true. This way before the migration (local or remote) we only have to set appropriate migration parameters. And backend-transfer per-device options can be setup once (and the same way) when starting the QEMU, or they may be inherited from Machine Type. And with such logic, it's good to have similar names for migration parameter and device option.
I hope above will solve this problem. IIUC what you described should work if we tweat the new proposal on the local=off & backend-transfer=on case.
Quoted 6 lines
Considering all this, could we keep the logic as is (in this patch), but rename backend-transfer parameter to local-backend-transfer, as you proposed before? Or turn it into "backend-transfer" = "local" | "off" (but IMHO it's too optimistic:
who knows, will we really add something into this enum in the future? I don't have such plans)
Quoted 8 lines
IMHO "local" would be nicer because it's very simple, generic and clear on is own. It almost says "requires UNIX sockets" on Linux and it also opens the door for this parameter to be reused when without a backend: for example, when some frontend or any-not-trivially-a-backend also want to migrate an FD in the future. I'm not surprised to see it coming.
But let's finish above disucssion and see if we can reach the same page.
So finally, rename to "local", and keep the logic as is, right? OK for me, will do.
Signature · 2 lines
Best regards, Vladimir
PATCH v10 4/8 net: introduce vmstate_net_peer_backend
In reply to Vladimir Sementsov-OgievskiyTo implement backend-transfer migration in virtio-net in the next commit, we need a generic API to migrate net backend. Here is it.
--- include/net/net.h | 4 ++++ net/net.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+)
include/net/net.h +4 -0
@@ -5,6 +5,7 @@#include "qapi/qapi-types-net.h" #include "net/queue.h" #include "hw/core/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], \
@@ -110,6 +111,7 @@ typedef struct NetClientInfo {SetSteeringEBPF *set_steering_ebpf;NetCheckPeerType *check_peer_type;GetVHostNet *get_vhost_net; +const VMStateDescription *backend_vmsd; } NetClientInfo;struct NetClientState {
@@ -354,4 +356,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
net/net.c +47 -0
56 lines not on this page · raw message
Signature · 1 line
2.52.0
PATCH v10 5/8 virtio-net: support backend-transfer migration
In reply to Vladimir Sementsov-OgievskiyAdd virtio-net option backend-transfer, which is true by default, but false for older machine types, which doesn't support the feature.
For backend-transfer migration, both global migration parameter backend-transfer and virtio-net backend-transfer option should be set to true.
With the parameters enabled (both on source and target, of-course), and with unix-socket used as migration-channel, we do "migrate" the virtio-net backend - TAP device, with all its fds.
This way management tool should not care about creating new TAP, and should not handle switching to it. Migration downtime become shorter.
Support for TAP will come in the next commit.
--- hw/core/machine.c | 4 +- hw/net/virtio-net.c | 137 ++++++++++++++++++++++++++++++++- include/hw/virtio/virtio-net.h | 2 + include/net/net.h | 2 + 4 files changed, 143 insertions(+), 2 deletions(-)
hw/core/machine.c +3 -1
@@ -38,7 +38,9 @@#include "hw/acpi/generic_event_device.h" #include "qemu/audio.h" -GlobalProperty hw_compat_10_2[] = {}; +GlobalProperty hw_compat_10_2[] = { + {TYPE_VIRTIO_NET ,"backend-transfer" ,"false" }, +};const size_t hw_compat_10_2_len =G_N_ELEMENTS (hw_compat_10_2);GlobalProperty hw_compat_10_1[] = {
hw/net/virtio-net.c +136 -1
199 lines not on this page · raw message
include/hw/virtio/virtio-net.h +2 -0
@@ -231,6 +231,8 @@ struct VirtIONet {struct EBPFRSSContext ebpf_rss;uint32_t nr_ebpf_rss_fds;char **ebpf_rss_fds; +bool peers_wait_incoming; +bool backend_transfer; }; size_t virtio_net_handle_ctrl_iov(VirtIODevice *vdev,
include/net/net.h +2 -0
@@ -82,6 +82,7 @@ typedef void (SocketReadStateFinalize)(SocketReadState *rs);typedef void (NetAnnounce )(NetClientState *);typedef bool (SetSteeringEBPF )(NetClientState *,int );typedef bool (NetCheckPeerType )(NetClientState *,ObjectClass *,Error **); +typedef bool (IsWaitIncoming )(NetClientState *);typedef struct vhost_net *(GetVHostNet )(NetClientState *nc); typedef struct NetClientInfo {
@@ -110,6 +111,7 @@ typedef struct NetClientInfo {NetAnnounce *announce;SetSteeringEBPF *set_steering_ebpf;NetCheckPeerType *check_peer_type; +IsWaitIncoming *is_wait_incoming;GetVHostNet *get_vhost_net;const VMStateDescription *backend_vmsd; } NetClientInfo;
Signature · 1 line
2.52.0
PATCH v10 6/8 net/tap: support backend-transfer migration
In reply to Vladimir Sementsov-OgievskiySupport transferring of TAP state (including open fd) through migration stream.
Add new option, incoming-fds, which should be set to true to trigger new logic.
--- net/tap.c | 88 ++++++++++++++++++++++++++++++++++++++++++++++++++- qapi/net.json | 6 +++- 2 files changed, 92 insertions(+), 2 deletions(-)
net/tap.c +87 -1
@@ -393,6 +393,65 @@ static VHostNetState *tap_get_vhost_net(NetClientState *nc)return s->vhost_net; } +static bool tap_is_wait_incoming (NetClientState *nc) +{ +TAPState *s =DO_UPCAST (TAPState, nc, nc); +assert (nc->info->type ==NET_CLIENT_DRIVER_TAP ); +return s->fd ==-1 ; +} + +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 bool tap_setup_vhost (TAPState *s,Error **errp); + +static int tap_post_load (void *opaque,int version_id) +{ +TAPState *s = opaque; +Error *local_err =NULL ; + +tap_read_poll (s, true); + +if (s->fd <0 ) { +return -1 ; + } + +if (!tap_setup_vhost (s, &local_err)) { +error_prepend (&local_err, +"Failed to setup vhost during TAP post-load: " ); +error_report_err (local_err); +return -1 ; + } + +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 = {
@@ -412,7 +471,9 @@ static NetClientInfo net_tap_info = { .set_vnet_le = tap_set_vnet_le, .set_vnet_be = tap_set_vnet_be, .set_steering_ebpf = tap_set_steering_ebpf, + .is_wait_incoming = tap_is_wait_incoming, .get_vhost_net = tap_get_vhost_net, + .backend_vmsd = &vmstate_tap, }; static TAPState *net_tap_fd_init(NetClientState *peer,
@@ -907,6 +968,14 @@ int net_init_tap(const Netdev *netdev, const char *name,return -1 ; } +if (tap->incoming_fds && + (tap->fd || tap->fds || tap->helper || tap->script || + tap->downscript)) { +error_setg (errp,"incoming-fds is incompatible with " +"fd=, fds=, helper=, script=, downscript=" ); +return -1 ; + } + queues =tap_parse_fds_and_queues (tap, &fds, errp);if (queues <0 ) {return -1 ;
@@ -925,7 +994,24 @@ int net_init_tap(const Netdev *netdev, const char *name, goto fail; } -if (fds) { +if (tap->incoming_fds) { +for (i =0 ; i < queues; i++) { +NetClientState *nc; +TAPState *s; + + nc =qemu_new_net_client (&net_tap_info, peer,"tap" , name); +qemu_set_info_str (nc,"incoming" ); + + s =DO_UPCAST (TAPState, nc, nc); + s->fd =-1 ; +if (vhost_fds) { + s->vhostfd = vhost_fds[i]; + s->vhost_busyloop_timeout = tap->has_poll_us ? tap->poll_us :0 ; + }else { + s->vhostfd =-1 ; + } + } + }else if (fds) {for (i =0 ; i < queues; i++) {if (i ==0 ) { vnet_hdr =tap_probe_vnet_hdr (fds[i], errp);
qapi/net.json +5 -1
@@ -355,6 +355,9 @@ # @poll-us: maximum number of microseconds that could be spent on busy # polling for tap (since 2.7) # +# @incoming-fds: do not open/connnect any resources, instead wait for +# TAP state from incoming migration stream. (Since 11.0) +# # Since: 1.2 ## { 'struct': 'NetdevTapOptions',
@@ -373,7 +376,8 @@ '*vhostfds': 'str', '*vhostforce': 'bool', '*queues': 'uint32', - '*poll-us': 'uint32'} } + '*poll-us': 'uint32', + '*incoming-fds': 'bool' } } ## # @NetdevSocketOptions:
Signature · 1 line
2.52.0
Re: [PATCH v10 6/8] net/tap: support backend-transfer migration
Quoted 7 lines · On 2/1/26, 11:21 AM, "Vladimir Sementsov-Ogievskiy"…
+ if (
tap->incoming_fds&&
+ (tap->fd||tap->fds||tap->helper||tap->script||
+tap->downscript)) {
+ error_setg(errp, "incoming-fds is incompatible with "
+ "fd=, fds=, helper=, script=, downscript=");
+ return -1;
+ }
Is it possible to relax this constraint at all? If so, I would prefer to allow script= and downscript= parameters to remain in place.
Thanks,
Ben
Re: [PATCH v10 6/8] net/tap: support backend-transfer migration
Quoted 11 lines · Ben
Quoted 7 lines · On 2/1/26, 11:21 AM, "Vladimir Sementsov-Ogievskiy"…
+ if (
tap->incoming_fds&&
+ (tap->fd||tap->fds||tap->helper||tap->script||
+tap->downscript)) {
+ error_setg(errp, "incoming-fds is incompatible with "
+ "fd=, fds=, helper=, script=, downscript=");
+ return -1;
+ }
Quoted 4 lines
Is it possible to relax this constraint at all? If so, I would prefer to allow script= and downscript= parameters to remain in place.
That possible, but this requires some additional logic I think.
What if migration fails? Who should call downscript? Migration may be successful on source, and fail on target.. In this case, management tool usually resume stopped source. And in this case source should get again a responsibility to call downscript.
So, I think it should be additional patch on top, which introduce support for script/downscript together with backend-transfer.
Signature · 2 lines
Best regards, Vladimir
Re: [PATCH v10 6/8] net/tap: support backend-transfer migration
On 2/5/26, 3:12 AM, "Vladimir Sementsov-Ogievskiy" <[email protected] <mailto:[email protected]>> wrote:
Quoted 7 lines · Ben
Is it possible to relax this constraint at all? If so, I would prefer to allow script= and downscript= parameters to remain in place.
Quoted 7 lines
That possible, but this requires some additional logic I think.
What if migration fails? Who should call downscript? Migration may be successful on source, and fail on target.. In this case, management tool usually resume stopped source. And in this case source should get again a responsibility to call downscript.
Hmm... If script and downscript are not set, they default to /etc/qemu-ifup and /etc/qemu-ifdown. To disable them altogether you must pass script=no,downscript=no, which is not currently possible with this patch.
Quoted 2 lines
So, I think it should be additional patch on top, which introduce support for script/downscript together with backend-transfer.
Would it be possible to at least support script=no,downscript=no as part of this patch? We may want to require it because it sounds like we don't have the logic to call qemu-ifup and qemu-ifdown correctly in the event of a failure.
Thanks,
Ben
Re: [PATCH v10 6/8] net/tap: support backend-transfer migration
Quoted 19 lines · Ben
On 2/5/26, 3:12 AM, "Vladimir Sementsov-Ogievskiy" <[email protected] <mailto:[email protected]>> wrote:
Quoted 7 lines · Ben
Is it possible to relax this constraint at all? If so, I would prefer to allow script= and downscript= parameters to remain in place.
Quoted 7 lines
That possible, but this requires some additional logic I think.
What if migration fails? Who should call downscript? Migration may be successful on source, and fail on target.. In this case, management tool usually resume stopped source. And in this case source should get again a responsibility to call downscript.
Quoted 4 lines
Hmm... If script and downscript are not set, they default to
/etc/qemu-ifupand/etc/qemu-ifdown. To disable them altogether you must pass script=no,downscript=no, which is not currently possible with this patch.
Yes, but when new option is set, we don't use any scripts. Like for other options which doesn't allow use of script/downscript (fd=, fds=, helper=).
But I see now, it was wrong decision.
Quoted 9 lines
Quoted 3 lines
So, I think it should be additional patch on top, which introduce support for script/downscript together with backend-transfer.
Would it be possible to at least support script=no,downscript=no as part of this patch? We may want to require it because it sounds like we don't have the logic to call qemu-ifup and qemu-ifdown correctly in the event of a failure.
Agree, that's correct. So, for this patch I should require script and downscript to be present and set to "no", to be able make a full support for them later.
Signature · 2 lines
Best regards, Vladimir
PATCH v10 7/8 tests/functional: add skipWithoutSudo() decorator
In reply to Vladimir Sementsov-OgievskiyTo be used in the next commit: that would be a test for TAP networking, and it will need to setup TAP device.
--- tests/functional/qemu_test/decorators.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
tests/functional/qemu_test/decorators.py +16 -0
@@ -6,6 +6,7 @@ import os import platform import resource +import subprocess from unittest import skipIf, skipUnless from .cmd import which
@@ -177,3 +178,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}')
Signature · 1 line
2.52.0
PATCH v10 8/8 tests/functional: add test_tap_migration
In reply to Vladimir Sementsov-OgievskiyAdd test for a new backend-transfer migration of virtio-net/tap, with fd passing through unix socket.
--- tests/functional/x86_64/meson.build | 1 + tests/functional/x86_64/test_tap_migration.py | 401 ++++++++++++++++++ 2 files changed, 402 insertions(+) create mode 100644 tests/functional/x86_64/test_tap_migration.py
tests/functional/x86_64/meson.build +1 -0
@@ -36,4 +36,5 @@ tests_x86_64_system_thorough = [ 'vfio_user_client', 'virtio_balloon', 'virtio_gpu', + 'tap_migration', ]
tests/functional/x86_64/test_tap_migration.py new file +401 -0
401 lines not on this page · raw message
Signature · 1 line
2.52.0