qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 05/14] virtio-net: Implement pci-failover


From: Akihiko Odaki
Subject: [PATCH 05/14] virtio-net: Implement pci-failover
Date: Sat, 02 Dec 2023 17:00:28 +0900

This change removes the parsing of pci-device's failover_pair_id
property from virtio-net, and lets pci-device to report an error if
an unknown ID is specified for the property.

Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com>
---
 include/hw/virtio/virtio-net.h |  3 ++-
 hw/net/virtio-net.c            | 24 ++++--------------------
 hw/virtio/virtio-net-pci.c     | 14 ++++++++++++++
 3 files changed, 20 insertions(+), 21 deletions(-)

diff --git a/include/hw/virtio/virtio-net.h b/include/hw/virtio/virtio-net.h
index 55977f01f0..753cab4b32 100644
--- a/include/hw/virtio/virtio-net.h
+++ b/include/hw/virtio/virtio-net.h
@@ -218,7 +218,6 @@ struct VirtIONet {
     /* primary failover device is hidden*/
     bool failover_primary_hidden;
     bool failover;
-    DeviceListener primary_listener;
     QDict *primary_opts;
     bool primary_opts_from_json;
     Notifier migration_state;
@@ -233,6 +232,8 @@ size_t virtio_net_handle_ctrl_iov(VirtIODevice *vdev,
                                   unsigned out_num);
 void virtio_net_set_netclient_name(VirtIONet *n, const char *name,
                                    const char *type);
+bool virtio_net_set_primary(VirtIONet *n, const QDict *device_opts,
+                            bool from_json, Error **errp);
 uint64_t virtio_net_supported_guest_offloads(const VirtIONet *n);
 
 #endif
diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
index 80c56f0cfc..7def9a1200 100644
--- a/hw/net/virtio-net.c
+++ b/hw/net/virtio-net.c
@@ -3536,19 +3536,11 @@ static void 
virtio_net_migration_state_notifier(Notifier *notifier, void *data)
     virtio_net_handle_migration_primary(n, s);
 }
 
-static bool failover_hide_primary_device(DeviceListener *listener,
-                                         const QDict *device_opts,
-                                         bool from_json,
-                                         Error **errp)
+bool virtio_net_set_primary(VirtIONet *n, const QDict *device_opts,
+                            bool from_json, Error **errp)
 {
-    VirtIONet *n = container_of(listener, VirtIONet, primary_listener);
-    const char *standby_id;
-
-    if (!device_opts) {
-        return false;
-    }
-
-    if (!qdict_haskey(device_opts, "failover_pair_id")) {
+    if (!n->failover) {
+        error_setg(errp, "failover pair does not support failover");
         return false;
     }
 
@@ -3557,11 +3549,6 @@ static bool failover_hide_primary_device(DeviceListener 
*listener,
         return false;
     }
 
-    standby_id = qdict_get_str(device_opts, "failover_pair_id");
-    if (g_strcmp0(standby_id, n->netclient_name) != 0) {
-        return false;
-    }
-
     /*
      * The hide helper can be called several times for a given device.
      * Check there is only one primary for a virtio-net device but
@@ -3621,9 +3608,7 @@ static void virtio_net_device_realize(DeviceState *dev, 
Error **errp)
     }
 
     if (n->failover) {
-        n->primary_listener.hide_device = failover_hide_primary_device;
         qatomic_set(&n->failover_primary_hidden, true);
-        device_listener_register(&n->primary_listener);
         migration_add_notifier(&n->migration_state,
                                virtio_net_migration_state_notifier);
         n->host_features |= (1ULL << VIRTIO_NET_F_STANDBY);
@@ -3789,7 +3774,6 @@ static void virtio_net_device_unrealize(DeviceState *dev)
 
     if (n->failover) {
         qobject_unref(n->primary_opts);
-        device_listener_unregister(&n->primary_listener);
         migration_remove_notifier(&n->migration_state);
     } else {
         assert(n->primary_opts == NULL);
diff --git a/hw/virtio/virtio-net-pci.c b/hw/virtio/virtio-net-pci.c
index e03543a70a..e421cd9cea 100644
--- a/hw/virtio/virtio-net-pci.c
+++ b/hw/virtio/virtio-net-pci.c
@@ -64,10 +64,19 @@ static void virtio_net_pci_realize(VirtIOPCIProxy 
*vpci_dev, Error **errp)
     qdev_realize(vdev, BUS(&vpci_dev->bus), errp);
 }
 
+static bool virtio_net_pci_set_primary(DeviceState *dev,
+                                       const QDict *device_opts,
+                                       bool from_json, Error **errp)
+{
+    return virtio_net_set_primary(&VIRTIO_NET_PCI(dev)->vdev, device_opts,
+                                  from_json, errp);
+}
+
 static void virtio_net_pci_class_init(ObjectClass *klass, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
     PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
+    PCIFailoverClass *pfc = PCI_FAILOVER_CLASS(klass);
     VirtioPCIClass *vpciklass = VIRTIO_PCI_CLASS(klass);
 
     k->romfile = "efi-virtio.rom";
@@ -75,6 +84,7 @@ static void virtio_net_pci_class_init(ObjectClass *klass, 
void *data)
     k->device_id = PCI_DEVICE_ID_VIRTIO_NET;
     k->revision = VIRTIO_PCI_ABI_VERSION;
     k->class_id = PCI_CLASS_NETWORK_ETHERNET;
+    pfc->set_primary = virtio_net_pci_set_primary;
     set_bit(DEVICE_CATEGORY_NETWORK, dc->categories);
     device_class_set_props(dc, virtio_net_properties);
     vpciklass->realize = virtio_net_pci_realize;
@@ -98,6 +108,10 @@ static const VirtioPCIDeviceTypeInfo virtio_net_pci_info = {
     .instance_size = sizeof(VirtIONetPCI),
     .instance_init = virtio_net_pci_instance_init,
     .class_init    = virtio_net_pci_class_init,
+    .interfaces = (InterfaceInfo[]) {
+        { TYPE_PCI_FAILOVER },
+        { }
+    },
 };
 
 static void virtio_net_pci_register(void)

-- 
2.43.0




reply via email to

[Prev in Thread] Current Thread [Next in Thread]