[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 38/66] failover: split failover_find_primary_device_id()
From: |
Michael S. Tsirkin |
Subject: |
[PULL 38/66] failover: split failover_find_primary_device_id() |
Date: |
Tue, 8 Dec 2020 14:35:48 -0500 |
From: Juan Quintela <quintela@redhat.com>
So we can calculate the device id when we need it.
Signed-off-by: Juan Quintela <quintela@redhat.com>
Message-Id: <20201118083748.1328-24-quintela@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
hw/net/virtio-net.c | 63 +++++++++++++++++++++++++++++++++------------
1 file changed, 47 insertions(+), 16 deletions(-)
diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
index b994796734..2c502c13fd 100644
--- a/hw/net/virtio-net.c
+++ b/hw/net/virtio-net.c
@@ -788,6 +788,49 @@ static inline uint64_t
virtio_net_supported_guest_offloads(VirtIONet *n)
return virtio_net_guest_offloads_by_features(vdev->guest_features);
}
+typedef struct {
+ VirtIONet *n;
+ char *id;
+} FailoverId;
+
+/**
+ * Set the id of the failover primary device
+ *
+ * @opaque: FailoverId to setup
+ * @opts: opts for device we are handling
+ * @errp: returns an error if this function fails
+ */
+static int failover_set_primary(void *opaque, QemuOpts *opts, Error **errp)
+{
+ FailoverId *fid = opaque;
+ const char *standby_id = qemu_opt_get(opts, "failover_pair_id");
+
+ if (g_strcmp0(standby_id, fid->n->netclient_name) == 0) {
+ fid->id = g_strdup(opts->id);
+ return 1;
+ }
+
+ return 0;
+}
+
+/**
+ * Find the primary device id for this failover virtio-net
+ *
+ * @n: VirtIONet device
+ * @errp: returns an error if this function fails
+ */
+static char *failover_find_primary_device_id(VirtIONet *n)
+{
+ Error *err = NULL;
+ FailoverId fid;
+
+ if (!qemu_opts_foreach(qemu_find_opts("device"),
+ failover_set_primary, &fid, &err)) {
+ return NULL;
+ }
+ return fid.id;
+}
+
static void failover_add_primary(VirtIONet *n, Error **errp)
{
Error *err = NULL;
@@ -812,20 +855,6 @@ static void failover_add_primary(VirtIONet *n, Error
**errp)
error_propagate(errp, err);
}
-static int is_my_primary(void *opaque, QemuOpts *opts, Error **errp)
-{
- VirtIONet *n = opaque;
- int ret = 0;
- const char *standby_id = qemu_opt_get(opts, "failover_pair_id");
-
- if (g_strcmp0(standby_id, n->netclient_name) == 0) {
- n->primary_device_id = g_strdup(opts->id);
- ret = 1;
- }
-
- return ret;
-}
-
/**
* Find the primary device for this failover virtio-net
*
@@ -834,11 +863,13 @@ static int is_my_primary(void *opaque, QemuOpts *opts,
Error **errp)
*/
static DeviceState *failover_find_primary_device(VirtIONet *n)
{
- Error *err = NULL;
+ char *id = failover_find_primary_device_id(n);
- if (!qemu_opts_foreach(qemu_find_opts("device"), is_my_primary, n, &err)) {
+ if (!id) {
return NULL;
}
+ n->primary_device_id = g_strdup(id);
+
return qdev_find_recursive(sysbus_get_default(), n->primary_device_id);
}
--
MST
- [PULL 29/66] failover: simplify virtio_net_find_primary(), (continued)
- [PULL 29/66] failover: simplify virtio_net_find_primary(), Michael S. Tsirkin, 2020/12/08
- [PULL 28/66] failover: Remove memory leak, Michael S. Tsirkin, 2020/12/08
- [PULL 30/66] failover: should_be_hidden() should take a bool, Michael S. Tsirkin, 2020/12/08
- [PULL 32/66] failover: virtio_net_connect_failover_devices() does nothing, Michael S. Tsirkin, 2020/12/08
- [PULL 31/66] failover: Rename function to hide_device(), Michael S. Tsirkin, 2020/12/08
- [PULL 33/66] failover: Rename to failover_find_primary_device(), Michael S. Tsirkin, 2020/12/08
- [PULL 34/66] failover: simplify qdev_device_add() failover case, Michael S. Tsirkin, 2020/12/08
- [PULL 37/66] failover: remove failover_find_primary_device() error parameter, Michael S. Tsirkin, 2020/12/08
- [PULL 36/66] failover: make sure that id always exist, Michael S. Tsirkin, 2020/12/08
- [PULL 35/66] failover: simplify qdev_device_add(), Michael S. Tsirkin, 2020/12/08
- [PULL 38/66] failover: split failover_find_primary_device_id(),
Michael S. Tsirkin <=
- [PULL 39/66] failover: We don't need to cache primary_device_id anymore, Michael S. Tsirkin, 2020/12/08
- [PULL 40/66] failover: Caller of this two functions already have primary_dev, Michael S. Tsirkin, 2020/12/08
- [PULL 42/66] failover: Remove primary_dev member, Michael S. Tsirkin, 2020/12/08
- [PULL 43/66] hw: add compat machines for 6.0, Michael S. Tsirkin, 2020/12/08
- [PULL 44/66] libvhost-user: replace qemu/bswap.h with glibc endian.h, Michael S. Tsirkin, 2020/12/08
- [PULL 47/66] libvhost-user: drop qemu/osdep.h dependency, Michael S. Tsirkin, 2020/12/08
- [PULL 45/66] libvhost-user: replace qemu/memfd.h usage, Michael S. Tsirkin, 2020/12/08
- [PULL 46/66] libvhost-user: remove qemu/compiler.h usage, Michael S. Tsirkin, 2020/12/08
- [PULL 48/66] libvhost-user: make it a meson subproject, Michael S. Tsirkin, 2020/12/08
- [PULL 50/66] libvhost-user: add a simple link test without glib, Michael S. Tsirkin, 2020/12/08