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