After cpr of a multi-queue NIC, if any queues are unused, then the
corresponding tap is marked enabled in userland, but it is disabled in the
kernel for the fd that was preserved. One cannot call tap_disable() during
postload, because that eventually calls IFF_DETACH_QUEUE, which fails
because the queue is already detached. Define tap_disable_postload to
avoid IFF_DETACH_QUEUE.
Signed-off-by: Steve Sistare <steven.sistare@oracle.com>
---
include/net/tap.h | 1 +
hw/net/virtio-net.c | 20 ++++++++++++++++++++
net/tap-win32.c | 5 +++++
net/tap.c | 17 +++++++++++++++++
4 files changed, 43 insertions(+)
diff --git a/include/net/tap.h b/include/net/tap.h
index 5d58551..9456abe 100644
--- a/include/net/tap.h
+++ b/include/net/tap.h
@@ -30,6 +30,7 @@
int tap_enable(NetClientState *nc);
int tap_disable(NetClientState *nc);
+void tap_disable_postload(NetClientState *nc);
int tap_get_fd(NetClientState *nc);
diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
index eb93607..b45128e 100644
--- a/hw/net/virtio-net.c
+++ b/hw/net/virtio-net.c
@@ -730,6 +730,25 @@ static int peer_detach(VirtIONet *n, int index)
return tap_disable(nc->peer);
}
+/*
+ * Set the disabled flag on unused queue pairs after vmstate load, without
+ * calling IFF_DETACH_QUEUE, which fails because the queue is already detached.
+ */
+static void virtio_net_postload_queue_pairs(VirtIONet *n)
+{
+ int i;
+ MigMode mode = migrate_mode();
+
+ if (mode == MIG_MODE_CPR_TRANSFER) {
+ for (i = n->curr_queue_pairs; i < n->max_queue_pairs; i++) {
+ NetClientState *nc = qemu_get_subqueue(n->nic, i);
+ if (nc->peer && nc->peer->info->type == NET_CLIENT_DRIVER_TAP) {
+ tap_disable_postload(nc->peer);
+ }
+ }
+ }
+}
+
static void virtio_net_set_queue_pairs(VirtIONet *n)
{
int i;
@@ -3106,6 +3125,7 @@ static int virtio_net_post_load_device(void *opaque, int version_id)
*/
n->saved_guest_offloads = n->curr_guest_offloads;
+ virtio_net_postload_queue_pairs(n);
virtio_net_set_queue_pairs(n);
/* Find the first multicast entry in the saved MAC filter */
diff --git a/net/tap-win32.c b/net/tap-win32.c
index 671dee9..66be7c9 100644
--- a/net/tap-win32.c
+++ b/net/tap-win32.c
@@ -771,3 +771,8 @@ int tap_disable(NetClientState *nc)
{
abort();
}
+
+void tap_disable_postload(NetClientState *nc)
+{
+ abort();
+}
diff --git a/net/tap.c b/net/tap.c
index 6a12751..c7f9023 100644
--- a/net/tap.c
+++ b/net/tap.c
@@ -1079,3 +1079,20 @@ int tap_disable(NetClientState *nc)
return ret;
}
}
+
+/*
+ * On cpr restart, the tap is marked enabled in userland, but it might be
+ * disabled in the kernel, and IFF_DETACH_QUEUE will fail because it is
+ * already detached. This function disables without calling IFF_DETACH_QUEUE.
+ */
+void tap_disable_postload(NetClientState *nc)
+{
+ TAPState *s = DO_UPCAST(TAPState, nc, nc);
+
+ if (!s->cpr || s->enabled == 0) {
+ return;
+ } else {
+ s->enabled = false;
+ tap_update_fd_handler(s);
+ }
+}
--
1.8.3.1