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.
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsement...@yandex-team.ru> --- net/tap.c | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/net/tap.c b/net/tap.c index 4d3cdc0662..7a4de07025 100644 --- a/net/tap.c +++ b/net/tap.c @@ -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 { -- 2.48.1