[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL v2 39/65] failover: We don't need to cache primary_device_id anymo
From: |
Michael S. Tsirkin |
Subject: |
[PULL v2 39/65] failover: We don't need to cache primary_device_id anymore |
Date: |
Wed, 9 Dec 2020 13:09:35 -0500 |
From: Juan Quintela <quintela@redhat.com>
Signed-off-by: Juan Quintela <quintela@redhat.com>
Message-Id: <20201118083748.1328-25-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 | 20 ++++++++++----------
2 files changed, 10 insertions(+), 11 deletions(-)
diff --git a/include/hw/virtio/virtio-net.h b/include/hw/virtio/virtio-net.h
index fe353d8299..efef64e02f 100644
--- a/include/hw/virtio/virtio-net.h
+++ b/include/hw/virtio/virtio-net.h
@@ -203,7 +203,6 @@ struct VirtIONet {
bool needs_vnet_hdr_swap;
bool mtu_bypass_backend;
DeviceState *primary_dev;
- char *primary_device_id;
/* 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 2c502c13fd..746ed3fb71 100644
--- a/hw/net/virtio-net.c
+++ b/hw/net/virtio-net.c
@@ -824,6 +824,7 @@ static char *failover_find_primary_device_id(VirtIONet *n)
Error *err = NULL;
FailoverId fid;
+ fid.n = n;
if (!qemu_opts_foreach(qemu_find_opts("device"),
failover_set_primary, &fid, &err)) {
return NULL;
@@ -835,12 +836,17 @@ static void failover_add_primary(VirtIONet *n, Error
**errp)
{
Error *err = NULL;
QemuOpts *opts;
+ char *id;
if (n->primary_dev) {
return;
}
- opts = qemu_opts_find(qemu_find_opts("device"), n->primary_device_id);
+ 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) {
@@ -868,9 +874,8 @@ static DeviceState *failover_find_primary_device(VirtIONet
*n)
if (!id) {
return NULL;
}
- n->primary_device_id = g_strdup(id);
- return qdev_find_recursive(sysbus_get_default(), n->primary_device_id);
+ return qdev_find_recursive(sysbus_get_default(), id);
}
static void virtio_net_set_features(VirtIODevice *vdev, uint64_t features)
@@ -3160,7 +3165,7 @@ static void virtio_net_handle_migration_primary(VirtIONet
*n,
vmstate_unregister(VMSTATE_IF(n->primary_dev),
qdev_get_vmsd(n->primary_dev),
n->primary_dev);
- qapi_event_send_unplug_primary(n->primary_device_id);
+ qapi_event_send_unplug_primary(n->primary_dev->id);
qatomic_set(&n->failover_primary_hidden, true);
} else {
warn_report("couldn't unplug primary device");
@@ -3186,7 +3191,6 @@ static bool failover_hide_primary_device(DeviceListener
*listener,
QemuOpts *device_opts)
{
VirtIONet *n = container_of(listener, VirtIONet, primary_listener);
- bool hide;
const char *standby_id;
if (!device_opts) {
@@ -3198,10 +3202,7 @@ static bool failover_hide_primary_device(DeviceListener
*listener,
}
/* failover_primary_hidden is set during feature negotiation */
- hide = qatomic_read(&n->failover_primary_hidden);
- g_free(n->primary_device_id);
- n->primary_device_id = g_strdup(device_opts->id);
- return hide;
+ return qatomic_read(&n->failover_primary_hidden);
}
static void virtio_net_device_realize(DeviceState *dev, Error **errp)
@@ -3378,7 +3379,6 @@ static void virtio_net_device_unrealize(DeviceState *dev)
if (n->failover) {
device_listener_unregister(&n->primary_listener);
- g_free(n->primary_device_id);
}
max_queues = n->multiqueue ? n->max_queues : 1;
--
MST
- [PULL v2 28/65] failover: Remove memory leak, (continued)
- [PULL v2 28/65] failover: Remove memory leak, Michael S. Tsirkin, 2020/12/09
- [PULL v2 29/65] failover: simplify virtio_net_find_primary(), Michael S. Tsirkin, 2020/12/09
- [PULL v2 30/65] failover: should_be_hidden() should take a bool, Michael S. Tsirkin, 2020/12/09
- [PULL v2 31/65] failover: Rename function to hide_device(), Michael S. Tsirkin, 2020/12/09
- [PULL v2 32/65] failover: virtio_net_connect_failover_devices() does nothing, Michael S. Tsirkin, 2020/12/09
- [PULL v2 33/65] failover: Rename to failover_find_primary_device(), Michael S. Tsirkin, 2020/12/09
- [PULL v2 34/65] failover: simplify qdev_device_add() failover case, Michael S. Tsirkin, 2020/12/09
- [PULL v2 35/65] failover: simplify qdev_device_add(), Michael S. Tsirkin, 2020/12/09
- [PULL v2 36/65] failover: make sure that id always exist, Michael S. Tsirkin, 2020/12/09
- [PULL v2 38/65] failover: split failover_find_primary_device_id(), Michael S. Tsirkin, 2020/12/09
- [PULL v2 39/65] failover: We don't need to cache primary_device_id anymore,
Michael S. Tsirkin <=
- [PULL v2 40/65] failover: Caller of this two functions already have primary_dev, Michael S. Tsirkin, 2020/12/09
- [PULL v2 42/65] failover: Remove primary_dev member, Michael S. Tsirkin, 2020/12/09
- [PULL v2 41/65] failover: simplify failover_unplug_primary, Michael S. Tsirkin, 2020/12/09
- [PULL v2 43/65] hw: add compat machines for 6.0, Michael S. Tsirkin, 2020/12/09
- [PULL v2 44/65] libvhost-user: replace qemu/bswap.h with glibc endian.h, Michael S. Tsirkin, 2020/12/09
- [PULL v2 45/65] libvhost-user: replace qemu/memfd.h usage, Michael S. Tsirkin, 2020/12/09
- [PULL v2 46/65] libvhost-user: remove qemu/compiler.h usage, Michael S. Tsirkin, 2020/12/09
- [PULL v2 47/65] libvhost-user: drop qemu/osdep.h dependency, Michael S. Tsirkin, 2020/12/09
- [PULL v2 48/65] libvhost-user: make it a meson subproject, Michael S. Tsirkin, 2020/12/09