Skip to contentSkip to conversation

virtio-net: live-TAP local migration

RFC Superseded Vladimir Sementsov-Ogievskiy 1 participant 9 messages Aug 23, 2025 – Aug 25, 2025 Networking

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

cover virtio-net: live-TAP local migration

Hi all!

That's a kind of alternative to
[RFC V2 0/8] Live update: tap and vhost
https://patchew.org/QEMU/[email protected]/

Instead of using CPR with additional stage and channel to pass FDs, we just pass everything we need (including FDs) through main migration channel (of-course, it should be unix socket). So, it's similar to live-backend vhost-user-blk migration which I propose in [PATCH 00/33] vhost-user-blk: live-backend local migration
https://patchew.org/QEMU/[email protected]/

The series is based on
[PATCH 00/33] vhost-user-blk: live-backend local migration and
[PATCH v2 00/20] TAP initialization refactoring

The series is also pushed to tag up-tap-fd-migration-v1 here:
https://gitlab.com/vsementsov/qemu/-/tree/up-tap-fd-migration-v1?ref_type=tags

The series is working draft, so marked as RFC. Next steps would be implementing a test, and smarter migration of vhostnet (without reinitialization of vhost).

The last patch provides a kind of stand to test these series, and it also can help with testing "[RFC V2 0/8] Live update: tap and vhost"

Based-on: <[email protected]>
Based-on: <[email protected]>

Vladimir Sementsov-Ogievskiy (7):
net/tap: add some trace points
net/tap: keep exit notifier only when downscript set
qapi: add interface for local TAP migration
net/tap: implement interfaces for local migration
virtio-net: support local tap migration
net/tap: experimental support for vhost in local tap migration
RFC: add python/tap-migration-stand.py

 hw/net/virtio-net.c            | 100 +++++++++-
 include/hw/virtio/virtio-net.h |   2 +
 include/net/tap.h              |   4 +
 migration/options.c            |   7 +
 migration/options.h            |   1 +
 net/tap.c                      | 226 ++++++++++++++++-----
 net/trace-events               |   7 +
 python/qemu/machine/machine.py |  37 ++--
 python/tap-migration-stand.py  | 348 +++++++++++++++++++++++++++++++++
 qapi/migration.json            |   9 +-
 qapi/net.json                  |  12 +-
 11 files changed, 681 insertions(+), 72 deletions(-)
 create mode 100755 python/tap-migration-stand.py
Signature · 1 line
2.48.1
#1 lore raw

RFC 1/7 net/tap: add some trace points

Add trace points to simplify debugging migration.

---
 net/tap.c        | 58 ++++++++++++++++++++++++++++++++++++++++++++++++
 net/trace-events |  7 ++++++
 2 files changed, 65 insertions(+)
net/tap.c +58 -0
index 45d1bcd326..44bd6eefd8 100644
@@ -43,6 +43,7 @@
 #include "qemu/main-loop.h"
 #include "qemu/sockets.h"
 #include "hw/virtio/vhost.h"
+#include "trace.h"
 
 #include "net/tap.h"
 
@@ -148,6 +149,9 @@ static ssize_t tap_receive_iov(NetClientState *nc, const struct iovec *iov,
     g_autofree struct iovec *iov_copy = NULL;
     struct virtio_net_hdr hdr = { };
 
+    trace_tap_receive_iov(s->using_vnet_hdr, s->host_vnet_hdr_len, iovcnt,
+                          iov->iov_len);
+
     if (s->host_vnet_hdr_len && !s->using_vnet_hdr) {
         iov_copy = g_new(struct iovec, iovcnt + 1);
         iov_copy[0].iov_base = &hdr;
@@ -183,6 +187,49 @@ static void tap_send_completed(NetClientState *nc, ssize_t len)
     tap_read_poll(s, true);
 }
 
+static char *tap_dump_packet(const uint8_t *buf, int size)
+{
+    int i, j;
+    char hex_line[80];  /* Enough space for hex pairs + spaces */
+    char ascii_line[17]; /* 16 + 1 for null terminator */
+    GString *dump_str = g_string_new(NULL);
+
+    g_string_append_printf(dump_str, "Packet dump (%d bytes):\n", size);
+
+    for (i = 0; i < size; i += 16) {
+        memset(hex_line, 0, sizeof(hex_line));
+        memset(ascii_line, 0, sizeof(ascii_line));
+
+        /* Build hex line in groups of 2 bytes (4 hex chars) */
+        int hex_pos = 0;
+        for (j = 0; j < 16 && (i + j) < size; j += 2) {
+            if (i + j + 1 < size) {
+                /* Two bytes available */
+                hex_pos += snprintf(hex_line + hex_pos,
+                                    sizeof(hex_line) - hex_pos,
+                                    "%02x%02x ", buf[i + j], buf[i + j + 1]);
+            } else {
+                /* Only one byte left */
+                hex_pos += snprintf(hex_line + hex_pos,
+                                    sizeof(hex_line) - hex_pos,
+                                    "%02x   ", buf[i + j]);
+            }
+        }
+
+        /* Build ASCII line */
+        for (j = 0; j < 16 && (i + j) < size; j++) {
+            uint8_t byte = buf[i + j];
+            ascii_line[j] = (byte >= 32 && byte <= 126) ? byte : '.';
+        }
+
+        /* Add the line in tcpdump-like format */
+        g_string_append_printf(dump_str, "\t0x%04x:  %-40s %s\n",
+                               i, hex_line, ascii_line);
+    }
+
+    return g_string_free(dump_str, false);
+}
+
 static void tap_send(void *opaque)
 {
     TAPState *s = opaque;
@@ -199,6 +246,13 @@ static void tap_send(void *opaque)
             break;
         }
 
+        if (trace_event_get_state_backends(TRACE_TAP_PACKET_DUMP)) {
+            g_autofree char *dump = tap_dump_packet(s->buf, size);
+            trace_tap_packet_dump(dump);
+        }
+
+        trace_tap_send_packet(s->using_vnet_hdr, s->host_vnet_hdr_len, size);
+
         if (s->host_vnet_hdr_len && size <= s->host_vnet_hdr_len) {
             /* Invalid packet */
             break;
@@ -992,6 +1046,8 @@ int tap_enable(NetClientState *nc)
     TAPState *s = DO_UPCAST(TAPState, nc, nc);
     int ret;
 
+    trace_tap_enable();
+
     if (s->enabled) {
         return 0;
     } else {
@@ -1009,6 +1065,8 @@ int tap_disable(NetClientState *nc)
     TAPState *s = DO_UPCAST(TAPState, nc, nc);
     int ret;
 
+    trace_tap_disable();
+
     if (s->enabled == 0) {
         return 0;
     } else {
net/trace-events +7 -0
index cda960f42b..b51427f539 100644
@@ -29,3 +29,10 @@ vhost_vdpa_set_address_space_id(void *v, unsigned vq_group, unsigned asid_num) "
 vhost_vdpa_net_load_cmd(void *s, uint8_t class, uint8_t cmd, int data_num, int data_size) "vdpa state: %p class: %u cmd: %u sg_num: %d size: %d"
 vhost_vdpa_net_load_cmd_retval(void *s, uint8_t class, uint8_t cmd, int r) "vdpa state: %p class: %u cmd: %u retval: %d"
 vhost_vdpa_net_load_mq(void *s, int ncurqps) "vdpa state: %p current_qpairs: %d"
+
+# tap.c
+tap_receive_iov(bool using_vnet_hdr, uint32_t host_vnet_hdr_len, int iovcnt, size_t iov_len) "using_vnet_hdr:%d host_vnet_hdr_len:%u iovcnt:%d iov_len:%zu"
+tap_send_packet(bool using_vnet_hdr, uint32_t host_vnet_hdr_len, int size) "using_vnet_hdr:%d host_vnet_hdr_len:%u size:%d"
+tap_enable(void) "tap enabled"
+tap_disable(void) "tap disabled"
+tap_packet_dump(const char *dump_str) "%s"
Signature · 1 line
2.48.1
#2 lore raw

RFC 2/7 net/tap: keep exit notifier only when downscript set

In reply to Vladimir Sementsov-Ogievskiy

The notifier is used only to call the downscript. Avoid extra notifier for other cases.

---
 net/tap.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)
net/tap.c +7 -5
index 44bd6eefd8..c07af762b0 100644
@@ -384,8 +384,10 @@ static void tap_cleanup(NetClientState *nc)
 
     qemu_purge_queued_packets(nc);
 
-    tap_exit_notify(&s->exit, NULL);
-    qemu_remove_exit_notifier(&s->exit);
+    if (s->exit.notify) {
+        tap_exit_notify(&s->exit, NULL);
+        qemu_remove_exit_notifier(&s->exit);
+    }
 
     tap_read_poll(s, false);
     tap_write_poll(s, false);
@@ -787,9 +789,7 @@ static int net_tap_fd_init_common(const Netdev *netdev, NetClientState *peer,
     }
     tap_read_poll(s, true);
     s->vhost_net = NULL;
-
-    s->exit.notify = tap_exit_notify;
-    qemu_add_exit_notifier(&s->exit);
+    s->exit.notify = NULL;
 
     if (netdev->type == NET_CLIENT_DRIVER_BRIDGE) {
         const NetdevBridgeOptions *bridge = &netdev->u.bridge;
@@ -817,6 +817,8 @@ static int net_tap_fd_init_common(const Netdev *netdev, NetClientState *peer,
             snprintf(s->down_script, sizeof(s->down_script), "%s", downscript);
             snprintf(s->down_script_arg, sizeof(s->down_script_arg),
                      "%s", ifname);
+            s->exit.notify = tap_exit_notify;
+            qemu_add_exit_notifier(&s->exit);
         }
     }
 
Signature · 1 line
2.48.1
#3 lore raw

RFC 3/7 qapi: add interface for local TAP migration

In reply to Vladimir Sementsov-Ogievskiy

To migrate TAP device (including open fds) locally, user should:

1. enable local-tap migration capability both on source and target
2. use additional local-incoming=true option for tap on target

Why capability is not enough? We need an option to modify early initialization of TAP, to avoid opening new fds. The capability may not be set at the moment of netdev initialization.

---
 migration/options.c |  7 +++++++
 migration/options.h |  1 +
 qapi/migration.json |  9 ++++++++-
 qapi/net.json       | 12 +++++++++++-
 4 files changed, 27 insertions(+), 2 deletions(-)
migration/options.c +7 -0
index 11b719c81b..fd0cca97b3 100644
@@ -276,6 +276,13 @@ bool migrate_local_vhost_user_blk(void)
     return s->capabilities[MIGRATION_CAPABILITY_LOCAL_VHOST_USER_BLK];
 }
 
+bool migrate_local_tap(void)
+{
+    MigrationState *s = migrate_get_current();
+
+    return s->capabilities[MIGRATION_CAPABILITY_LOCAL_TAP];
+}
+
 bool migrate_ignore_shared(void)
 {
     MigrationState *s = migrate_get_current();
migration/options.h +1 -0
index 5a40ac073d..aa0ab6a61f 100644
@@ -32,6 +32,7 @@ bool migrate_events(void);
 bool migrate_mapped_ram(void);
 bool migrate_local_char_socket(void);
 bool migrate_local_vhost_user_blk(void);
+bool migrate_local_tap(void);
 bool migrate_ignore_shared(void);
 bool migrate_late_block_activate(void);
 bool migrate_multifd(void);
qapi/migration.json +8 -1
index ead7f4d17c..bf554684f4 100644
@@ -529,6 +529,12 @@
 #     For target device also @local-incoming option must be specified
 #     (since 10.2)
 #
+# @local-tap: Migrate TAPs locally, keeping backend alive. Open file
+#     descriptors and TAP-related state are migrated. Only may be
+#     used when migration channel is unix socket. For target device
+#     also @local-incoming option must be specified (since 10.2)
+#     (since 10.2)
+#
 # Features:
 #
 # @unstable: Members @x-colo, @x-ignore-shared, @local-char-socket,
@@ -551,7 +557,8 @@
            'zero-copy-send', 'postcopy-preempt', 'switchover-ack',
            'dirty-limit', 'mapped-ram',
            { 'name': 'local-char-socket', 'features': [ 'unstable' ] },
-           { 'name': 'local-vhost-user-blk', 'features': [ 'unstable' ] } ] }
+           { 'name': 'local-vhost-user-blk', 'features': [ 'unstable' ] },
+           { 'name': 'local-tap', 'features': [ 'unstable' ] } ] }
 
 ##
 # @MigrationCapabilityStatus:
qapi/net.json +11 -1
index 78bcc9871e..8f53549d58 100644
@@ -353,6 +353,15 @@
 # @poll-us: maximum number of microseconds that could be spent on busy
 #     polling for tap (since 2.7)
 #
+# @local-incoming: Do load open file descriptor for that TAP
+#     on incoming migration. May be used only if QEMU is started
+#     for incoming migration. Will work only together with local-tap
+#     migration capability enabled (default: false) (Since: 10.2)
+#
+# Features:
+#
+# @unstable: Member @local-incoming is experimental
+#
 # Since: 1.2
 ##
 { 'struct': 'NetdevTapOptions',
@@ -371,7 +380,8 @@
     '*vhostfds':   'str',
     '*vhostforce': 'bool',
     '*queues':     'uint32',
-    '*poll-us':    'uint32'} }
+    '*poll-us':    'uint32',
+    '*local-incoming': { 'type': 'bool', 'features': [ 'unstable' ] } } }
 
 ##
 # @NetdevSocketOptions:
Signature · 1 line
2.48.1
#4 lore raw

RFC 4/7 net/tap: implement interfaces for local migration

In reply to Vladimir Sementsov-Ogievskiy

Handle local-incoming option:

---
 include/net/tap.h |   4 ++
 net/tap.c         | 129 ++++++++++++++++++++++++++++++++++------------
 2 files changed, 99 insertions(+), 34 deletions(-)
include/net/tap.h +4 -0
index 6f34f13eae..3ef2e2dbae 100644
@@ -30,7 +30,11 @@
 
 int tap_enable(NetClientState *nc);
 int tap_disable(NetClientState *nc);
+bool tap_local_incoming(NetClientState *nc);
 
 int tap_get_fd(NetClientState *nc);
 
+int tap_load(NetClientState *nc, QEMUFile *f);
+int tap_save(NetClientState *nc, QEMUFile *f);
+
 #endif /* QEMU_NET_TAP_H */
net/tap.c +95 -34

185 lines not on this page · raw message

Signature · 1 line
2.48.1
#5 lore raw

RFC 5/7 virtio-net: support local tap migration

In reply to Vladimir Sementsov-Ogievskiy
---
 hw/net/virtio-net.c            | 100 ++++++++++++++++++++++++++++++++-
 include/hw/virtio/virtio-net.h |   2 +
 2 files changed, 101 insertions(+), 1 deletion(-)
hw/net/virtio-net.c +99 -1
index 6b5b5dace3..874e349fee 100644
@@ -38,6 +38,8 @@
 #include "qapi/qapi-events-migration.h"
 #include "hw/virtio/virtio-access.h"
 #include "migration/misc.h"
+#include "migration/migration.h"
+#include "migration/options.h"
 #include "standard-headers/linux/ethtool.h"
 #include "system/system.h"
 #include "system/replay.h"
@@ -2999,7 +3001,13 @@ 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);
+    /*
+     * Called from set_features(0) on reset, when on target we
+     * doesn't have fds yet
+     */
+    if (!n->tap_wait_incoming) {
+        virtio_net_set_queue_pairs(n);
+    }
 }
 
 static int virtio_net_pre_load_queues(VirtIODevice *vdev, uint32_t n)
@@ -3009,6 +3017,19 @@ static int virtio_net_pre_load_queues(VirtIODevice *vdev, uint32_t n)
     return 0;
 }
 
+static int virtio_net_pre_save_device(void *opaque)
+{
+    VirtIONet *n = opaque;
+    int i, r;
+
+    for (i = 0; i < n->curr_queue_pairs; i++) {
+        r = peer_detach(n, i);
+        assert(!r);
+    }
+
+    return 0;
+}
+
 static uint64_t virtio_net_get_features(VirtIODevice *vdev, uint64_t features,
                                         Error **errp)
 {
@@ -3028,6 +3049,11 @@ static uint64_t virtio_net_get_features(VirtIODevice *vdev, uint64_t features,
 
     virtio_add_feature(&features, VIRTIO_NET_F_MAC);
 
+    if (n->tap_wait_incoming) {
+        /* Excessive feature set is OK for early initialization */
+        return features;
+    }
+
     if (!peer_has_vnet_hdr(n)) {
         virtio_clear_feature(&features, VIRTIO_NET_F_CSUM);
         virtio_clear_feature(&features, VIRTIO_NET_F_HOST_TSO4);
@@ -3494,11 +3520,69 @@ static const VMStateDescription vhost_user_net_backend_state = {
     }
 };
 
+static int virtio_net_tap_save(QEMUFile *f, void *pv, size_t size,
+                                     const VMStateField *field,
+                                     JSONWriter *vmdesc)
+{
+    VirtIONet *n = pv;
+    int i;
+
+    for (i = 0; i < n->max_queue_pairs; i++) {
+        NetClientState *nc = qemu_get_subqueue(n->nic, i);
+        assert(nc->peer->info->type == NET_CLIENT_DRIVER_TAP);
+
+        tap_save(nc->peer, f);
+    }
+
+    return 0;
+}
+
+static int virtio_net_tap_load(QEMUFile *f, void *pv, size_t size,
+                                     const VMStateField *field)
+{
+    VirtIONet *n = pv;
+    VirtIODevice *vdev = VIRTIO_DEVICE(n);
+    VirtioDeviceClass *vdc = VIRTIO_DEVICE_GET_CLASS(vdev);
+    Error *local_err = NULL;
+    int i;
+
+    for (i = 0; i < n->max_queue_pairs; i++) {
+        NetClientState *nc = qemu_get_subqueue(n->nic, i);
+        assert(nc->peer->info->type == NET_CLIENT_DRIVER_TAP);
+
+        tap_load(nc->peer, f);
+    }
+
+    peer_test_vnet_hdr(n);
+    n->tap_wait_incoming = false;
+
+    vdev->host_features = vdc->get_features(vdev, vdev->host_features,
+                                            &local_err);
+    if (local_err) {
+        error_report_err(local_err);
+        return -EINVAL;
+    }
+
+    return 0;
+}
+
+static bool virtio_net_is_tap_local(void *opaque, int version_id)
+{
+    VirtIONet *n = opaque;
+    NetClientState *nc;
+
+    nc = qemu_get_queue(n->nic);
+
+    return migrate_local_tap() && nc->peer &&
+        nc->peer->info->type == NET_CLIENT_DRIVER_TAP;
+}
+
 static const VMStateDescription vmstate_virtio_net_device = {
     .name = "virtio-net-device",
     .version_id = VIRTIO_NET_VM_VERSION,
     .minimum_version_id = VIRTIO_NET_VM_VERSION,
     .post_load = virtio_net_post_load_device,
+    .pre_save = virtio_net_pre_save_device,
     .fields = (const VMStateField[]) {
         VMSTATE_UINT8_ARRAY(mac, VirtIONet, ETH_ALEN),
         VMSTATE_STRUCT_POINTER(vqs, VirtIONet,
@@ -3525,6 +3609,15 @@ static const VMStateDescription vmstate_virtio_net_device = {
          * but based on the uint.
          */
         VMSTATE_BUFFER_POINTER_UNSAFE(vlans, VirtIONet, 0, MAX_VLAN >> 3),
+        {
+            .name = "tap",
+            .info = &(const VMStateInfo) {
+                .name = "virtio-net vhost-user backend state",
+                .get = virtio_net_tap_load,
+                .put = virtio_net_tap_save,
+            },
+            .field_exists = virtio_net_is_tap_local,
+        },
         VMSTATE_WITH_TMP(VirtIONet, struct VirtIONetMigTmp,
                          vmstate_virtio_net_has_vnet),
         VMSTATE_UINT8(mac_table.multi_overflow, VirtIONet),
@@ -3954,6 +4047,11 @@ static void virtio_net_device_realize(DeviceState *dev, Error **errp)
         vhost_net_set_config(get_vhost_net(nc->peer),
             (uint8_t *)&netcfg, 0, ETH_ALEN, VHOST_SET_CONFIG_TYPE_FRONTEND);
     }
+
+    if (nc->peer && nc->peer->info->type == NET_CLIENT_DRIVER_TAP) {
+        n->tap_wait_incoming = tap_local_incoming(nc->peer);
+    }
+
     QTAILQ_INIT(&n->rsc_chains);
     n->qdev = dev;
 
include/hw/virtio/virtio-net.h +2 -0
index 73fdefc0dc..04ae0e4c06 100644
@@ -231,6 +231,8 @@ struct VirtIONet {
     struct EBPFRSSContext ebpf_rss;
     uint32_t nr_ebpf_rss_fds;
     char **ebpf_rss_fds;
+
+    bool tap_wait_incoming;
 };
 
 size_t virtio_net_handle_ctrl_iov(VirtIODevice *vdev,
Signature · 1 line
2.48.1
#6 lore raw

RFC 6/7 net/tap: experimental support for vhost in local tap migration

In reply to Vladimir Sementsov-Ogievskiy

Just reinitialize vhost after getting the fd on target. This significantly increase downtime (0.03s -> 0.06s in my simple testing). So next step is to rework it, completely migrating the vhost state to the new qemu without reinitialization.

---
 net/tap.c | 35 +++++++++++++++++------------------
 1 file changed, 17 insertions(+), 18 deletions(-)
net/tap.c +17 -18
index 4d3cdc0662..7a4de07025 100644
@@ -84,6 +84,9 @@ typedef struct TAPState {
     unsigned host_vnet_hdr_len;
     Notifier exit;
     bool local_incoming;
+    bool need_vhost;
+    char *vhost_fdname;
+    uint32_t vhost_busyloop_timeout;
 } TAPState;
 
 static void launch_script(const char *setup_script, const char *ifname,
@@ -98,8 +101,7 @@ static int net_tap_fd_init_common(const Netdev *netdev, NetClientState *peer,
                                   const char *downscript,
                                   const char *vhostfdname,
                                   int vnet_hdr, int fd, Error **errp);
-static int net_tap_setup_vhost(TAPState *s, const NetdevTapOptions *tap,
-                               const char *vhostfdname, Error **errp);
+static int net_tap_setup_vhost(TAPState *s, Error **errp);
 
 static void tap_update_fd_handler(TAPState *s)
 {
@@ -384,6 +386,7 @@ static void tap_cleanup(NetClientState *nc)
         g_free(s->vhost_net);
         s->vhost_net = NULL;
     }
+    g_free(s->vhost_fdname);
 
     qemu_purge_queued_packets(nc);
 
@@ -794,10 +797,8 @@ int tap_load(NetClientState *nc, QEMUFile *f)
     qemu_get_be32s(f, &s->host_vnet_hdr_len);
 
     tap_read_poll(s, true);
-    s->exit.notify = tap_exit_notify;
-    qemu_add_exit_notifier(&s->exit);
 
-    return 0;
+    return net_tap_setup_vhost(s, NULL);
 }
 
 static int net_tap_fd_init_common(const Netdev *netdev, NetClientState *peer,
@@ -874,8 +875,12 @@ static int net_tap_fd_init_common(const Netdev *netdev, NetClientState *peer,
         }
     }
 
+    s->need_vhost = tap->has_vhost ? tap->vhost :
+        vhostfdname || (tap->has_vhostforce && tap->vhostforce);
+    s->vhost_fdname = g_strdup(vhostfdname);
+    s->vhost_busyloop_timeout = tap->has_poll_us ? tap->poll_us : 0;
     if (!local_incoming) {
-        ret = net_tap_setup_vhost(s, tap, vhostfdname, errp);
+        ret = net_tap_setup_vhost(s, errp);
         if (ret < 0) {
             goto failed;
         }
@@ -888,28 +893,22 @@ failed:
     return -1;
 }
 
-static int net_tap_setup_vhost(TAPState *s, const NetdevTapOptions *tap,
-                               const char *vhostfdname, Error **errp)
+static int net_tap_setup_vhost(TAPState *s, Error **errp)
 {
-    if (tap->has_vhost ? tap->vhost :
-        vhostfdname || (tap->has_vhostforce && tap->vhostforce)) {
+    if (s->need_vhost) {
         VhostNetOptions options;
         int vhostfd;
 
         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.busyloop_timeout = s->vhost_busyloop_timeout;
 
-        if (vhostfdname) {
-            vhostfd = monitor_fd_param(monitor_cur(), vhostfdname, errp);
+        if (s->vhost_fdname) {
+            vhostfd = monitor_fd_param(monitor_cur(), s->vhost_fdname, errp);
             if (vhostfd == -1) {
                 return -1;
             }
-            if (!set_fd_nonblocking(vhostfd, vhostfdname, errp)) {
+            if (!set_fd_nonblocking(vhostfd, s->vhost_fdname, errp)) {
                 return -1;
             }
         } else {
Signature · 1 line
2.48.1
#7 lore raw

RFC 7/7 RFC: add python/tap-migration-stand.py

In reply to Vladimir Sementsov-Ogievskiy

How to use:

1. prepare test image (any distribution with working network), and modify IMAGE variable in script

You'll need to setup static ip in the image, for example in Ubuntu:

cat /etc/netplan/01-netcfg.yaml
network:
version: 2
renderer: networkd
ethernets:

    ens1:
      dhcp4: no
      addresses: [10.0.1.2/24]
      gateway4: 10.0.1.1
      nameservers:
	addresses: [8.8.8.8, 8.8.4.4]

2. run script with sudo (to manipulate with TAPs)

cd python
sudo ./tap-migration-stand.py --qemu-binary path/to/qemu-system-x86_64 \
--mode (new | cpr)

mode=new means current series, mode=cpr means
"[RFC V2 0/8] Live update: tap and vhost"

3. run in separate terminal something like

while true; do gvncviewer :0; gvncviewer :1; sleep 0.5; done

to monitor our vms (on live update, vnc port will change every time)

4. run ping processes, for example

in host: ping -f 10.0.1.2 -i 0.002
in vm: ping -f 10.0.1.1 -i 0

5. in running script, run command "u" (without quotes), which means live-update.

6. you may also pass a counter, like "u 1000", to update 1000 times, which helps to catch racy bugs.

---
 python/qemu/machine/machine.py |  37 ++--
 python/tap-migration-stand.py  | 348 +++++++++++++++++++++++++++++++++
 2 files changed, 369 insertions(+), 16 deletions(-)
 create mode 100755 python/tap-migration-stand.py
python/qemu/machine/machine.py +21 -16
index ebb58d5b68..fed54f768d 100644
@@ -360,6 +360,7 @@ def _pre_launch(self) -> None:
         # _post_shutdown()!
         # pylint: disable=consider-using-with
         self._qemu_log_path = os.path.join(self.log_dir, self._name + ".log")
+        print(f"Open log file: {self._qemu_log_path}")
         self._qemu_log_file = open(self._qemu_log_path, 'wb')
 
         self._iolog = None
@@ -435,17 +436,17 @@ def _post_shutdown(self) -> None:
         self._user_killed = False
         self._launched = False
 
-    def launch(self) -> None:
+    def launch(self, do_launch=True, do_post_launch=True) -> None:
         """
         Launch the VM and make sure we cleanup and expose the
         command line/output in case of exception
         """
 
-        if self._launched:
+        if self._launched and do_launch:
             raise QEMUMachineError('VM already launched')
 
         try:
-            self._launch()
+            self._launch(do_launch, do_post_launch)
         except BaseException as exc:
             # We may have launched the process but it may
             # have exited before we could connect via QMP.
@@ -468,23 +469,26 @@ def launch(self) -> None:
             # that exception. However, we still want to clean up.
             raise
 
-    def _launch(self) -> None:
+    def _launch(self, do_launch=True, do_post_launch=True) -> None:
         """
         Launch the VM and establish a QMP connection
         """
-        self._pre_launch()
-        LOG.debug('VM launch command: %r', ' '.join(self._qemu_full_args))
+        if do_launch:
+            self._pre_launch()
+            print('VM launch command: %r', ' '.join(self._qemu_full_args))
 
-        # Cleaning up of this subprocess is guaranteed by _do_shutdown.
-        # pylint: disable=consider-using-with
-        self._popen = subprocess.Popen(self._qemu_full_args,
-                                       stdin=subprocess.DEVNULL,
-                                       stdout=self._qemu_log_file,
-                                       stderr=subprocess.STDOUT,
-                                       shell=False,
-                                       close_fds=False)
-        self._launched = True
-        self._post_launch()
+            # Cleaning up of this subprocess is guaranteed by _do_shutdown.
+            # pylint: disable=consider-using-with
+            self._popen = subprocess.Popen(self._qemu_full_args,
+                                           stdin=subprocess.DEVNULL,
+                                           stdout=self._qemu_log_file,
+                                           stderr=subprocess.STDOUT,
+                                           shell=False,
+                                           close_fds=False)
+            self._launched = True
+
+        if do_post_launch:
+            self._post_launch()
 
     def _close_qmp_connection(self) -> None:
         """
@@ -732,6 +736,7 @@ def cmd(self, cmd: str,
             conv_keys = True
 
         qmp_args = self._qmp_args(conv_keys, args)
+        print(cmd, qmp_args)
         ret = self._qmp.cmd(cmd, **qmp_args)
         if cmd == 'quit':
             self._quit_issued = True
python/tap-migration-stand.py new file +348 -0

348 lines not on this page · raw message

Signature · 1 line
2.48.1
#8 lore raw

Re: [RFC 7/7] RFC: add python/tap-migration-stand.py

Quoted 1 line · Vladimir Sementsov-Ogievskiy

How to use:

(this patch 7/7 is not for commit)

Signature · 2 lines
Best regards,
Vladimir