[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 42/66] failover: Remove primary_dev member
From: |
Michael S. Tsirkin |
Subject: |
[PULL 42/66] failover: Remove primary_dev member |
Date: |
Tue, 8 Dec 2020 14:36:04 -0500 |
From: Juan Quintela <quintela@redhat.com>
Only three uses remained, and we can remove them on that case.
Signed-off-by: Juan Quintela <quintela@redhat.com>
Message-Id: <20201118083748.1328-28-quintela@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
include/hw/virtio/virtio-net.h | 1 -
hw/net/virtio-net.c | 75 +++++++++++++++-------------------
2 files changed, 34 insertions(+), 42 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,35 +832,6 @@ static char *failover_find_primary_device_id(VirtIONet *n)
return fid.id;
}
-static void failover_add_primary(VirtIONet *n, Error **errp)
-{
- Error *err = NULL;
- QemuOpts *opts;
- char *id;
-
- if (n->primary_dev) {
- return;
- }
-
- id = failover_find_primary_device_id(n);
- if (!id) {
- return;
- }
- opts = qemu_opts_find(qemu_find_opts("device"), id);
- if (opts) {
- n->primary_dev = qdev_device_add(opts, &err);
- if (err) {
- qemu_opts_del(opts);
- }
- } else {
- error_setg(errp, "Primary device not found");
- error_append_hint(errp, "Virtio-net failover will not work. Make "
- "sure primary device has parameter"
- " failover_pair_id=<virtio-net-id>\n");
- }
- error_propagate(errp, err);
-}
-
/**
* Find the primary device for this failover virtio-net
*
@@ -878,6 +849,36 @@ static DeviceState *failover_find_primary_device(VirtIONet
*n)
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 (dev) {
+ return;
+ }
+
+ id = failover_find_primary_device_id(n);
+ if (!id) {
+ return;
+ }
+ opts = qemu_opts_find(qemu_find_opts("device"), id);
+ if (opts) {
+ dev = qdev_device_add(opts, &err);
+ if (err) {
+ qemu_opts_del(opts);
+ }
+ } else {
+ error_setg(errp, "Primary device not found");
+ error_append_hint(errp, "Virtio-net failover will not work. Make "
+ "sure primary device has parameter"
+ " failover_pair_id=<virtio-net-id>\n");
+ }
+ error_propagate(errp, err);
+}
+
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)
--
MST
- [PULL 32/66] failover: virtio_net_connect_failover_devices() does nothing, (continued)
- [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, 2020/12/08
- [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 <=
- [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
- [PULL 51/66] .gitlab-ci: add build-libvhost-user, Michael S. Tsirkin, 2020/12/08
- [PULL 52/66] contrib/vhost-user-blk: avoid g_return_val_if() input validation, Michael S. Tsirkin, 2020/12/08
- [PULL 49/66] libvhost-user: check memfd API, Michael S. Tsirkin, 2020/12/08