[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v2 27/27] failover: Remove primary_dev member
|
From: |
Juan Quintela |
|
Subject: |
[PATCH v2 27/27] failover: Remove primary_dev member |
|
Date: |
Wed, 18 Nov 2020 09:37:48 +0100 |
Only three uses remained, and we can remove them on that case.
Signed-off-by: Juan Quintela <quintela@redhat.com>
---
include/hw/virtio/virtio-net.h | 1 -
hw/net/virtio-net.c | 55 +++++++++++++++-------------------
2 files changed, 24 insertions(+), 32 deletions(-)
diff --git a/include/hw/virtio/virtio-net.h b/include/hw/virtio/virtio-net.h
index efef64e02f..7e96d193aa 100644
--- a/include/hw/virtio/virtio-net.h
+++ b/include/hw/virtio/virtio-net.h
@@ -202,7 +202,6 @@ struct VirtIONet {
AnnounceTimer announce_timer;
bool needs_vnet_hdr_swap;
bool mtu_bypass_backend;
- DeviceState *primary_dev;
/* primary failover device is hidden*/
bool failover_primary_hidden;
bool failover;
diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
index 9203d81780..044ac95f6f 100644
--- a/hw/net/virtio-net.c
+++ b/hw/net/virtio-net.c
@@ -832,13 +832,31 @@ static char *failover_find_primary_device_id(VirtIONet *n)
return fid.id;
}
+/**
+ * Find the primary device for this failover virtio-net
+ *
+ * @n: VirtIONet device
+ * @errp: returns an error if this function fails
+ */
+static DeviceState *failover_find_primary_device(VirtIONet *n)
+{
+ char *id = failover_find_primary_device_id(n);
+
+ if (!id) {
+ return NULL;
+ }
+
+ return qdev_find_recursive(sysbus_get_default(), id);
+}
+
static void failover_add_primary(VirtIONet *n, Error **errp)
{
Error *err = NULL;
QemuOpts *opts;
char *id;
+ DeviceState *dev = failover_find_primary_device(n);
- if (n->primary_dev) {
+ if (dev) {
return;
}
@@ -848,7 +866,7 @@ static void failover_add_primary(VirtIONet *n, Error **errp)
}
opts = qemu_opts_find(qemu_find_opts("device"), id);
if (opts) {
- n->primary_dev = qdev_device_add(opts, &err);
+ dev = qdev_device_add(opts, &err);
if (err) {
qemu_opts_del(opts);
}
@@ -861,23 +879,6 @@ static void failover_add_primary(VirtIONet *n, Error
**errp)
error_propagate(errp, err);
}
-/**
- * Find the primary device for this failover virtio-net
- *
- * @n: VirtIONet device
- * @errp: returns an error if this function fails
- */
-static DeviceState *failover_find_primary_device(VirtIONet *n)
-{
- char *id = failover_find_primary_device_id(n);
-
- if (!id) {
- return NULL;
- }
-
- return qdev_find_recursive(sysbus_get_default(), id);
-}
-
static void virtio_net_set_features(VirtIODevice *vdev, uint64_t features)
{
VirtIONet *n = VIRTIO_NET(vdev);
@@ -933,19 +934,9 @@ static void virtio_net_set_features(VirtIODevice *vdev,
uint64_t features)
qatomic_set(&n->failover_primary_hidden, false);
failover_add_primary(n, &err);
if (err) {
- n->primary_dev = failover_find_primary_device(n);
- failover_add_primary(n, &err);
- if (err) {
- goto out_err;
- }
+ warn_report_err(err);
}
}
- return;
-
-out_err:
- if (err) {
- warn_report_err(err);
- }
}
static int virtio_net_handle_rx_mode(VirtIONet *n, uint8_t cmd,
@@ -3420,13 +3411,15 @@ static int virtio_net_pre_save(void *opaque)
static bool primary_unplug_pending(void *opaque)
{
DeviceState *dev = opaque;
+ DeviceState *primary;
VirtIODevice *vdev = VIRTIO_DEVICE(dev);
VirtIONet *n = VIRTIO_NET(vdev);
if (!virtio_vdev_has_feature(vdev, VIRTIO_NET_F_STANDBY)) {
return false;
}
- return n->primary_dev ? n->primary_dev->pending_deleted_event : false;
+ primary = failover_find_primary_device(n);
+ return primary ? primary->pending_deleted_event : false;
}
static bool dev_unplug_pending(void *opaque)
--
2.26.2
- [PATCH v2 16/27] failover: Rename function to hide_device(), (continued)
- [PATCH v2 16/27] failover: Rename function to hide_device(), Juan Quintela, 2020/11/18
- [PATCH v2 17/27] failover: virtio_net_connect_failover_devices() does nothing, Juan Quintela, 2020/11/18
- [PATCH v2 18/27] failover: Rename to failover_find_primary_device(), Juan Quintela, 2020/11/18
- [PATCH v2 19/27] failover: simplify qdev_device_add() failover case, Juan Quintela, 2020/11/18
- [PATCH v2 20/27] failover: simplify qdev_device_add(), Juan Quintela, 2020/11/18
- [PATCH v2 21/27] failover: make sure that id always exist, Juan Quintela, 2020/11/18
- [PATCH v2 22/27] failover: remove failover_find_primary_device() error parameter, Juan Quintela, 2020/11/18
- [PATCH v2 23/27] failover: split failover_find_primary_device_id(), Juan Quintela, 2020/11/18
- [PATCH v2 24/27] failover: We don't need to cache primary_device_id anymore, Juan Quintela, 2020/11/18
- [PATCH v2 25/27] failover: Caller of this two functions already have primary_dev, Juan Quintela, 2020/11/18
- [PATCH v2 27/27] failover: Remove primary_dev member,
Juan Quintela <=
- [PATCH v2 26/27] failover: simplify failover_unplug_primary, Juan Quintela, 2020/11/18
- Re: [PATCH v2 00/27] Virtio net failover fixes, Michael S. Tsirkin, 2020/11/18