Skip to content

Commit 12b2fad

Browse files
committed
virtio-net: Avoid QemuOpts in failover_find_primary_device()
Don't go through the global QemuOptsList, it is state of the legacy command line parser and we will create devices that are not contained in it. It is also just the command line configuration and not necessarily the current runtime state. Instead, look at the qdev device tree which has the current state of all existing devices. Signed-off-by: Kevin Wolf <[email protected]> Message-Id: <[email protected]> Reviewed-by: Michael S. Tsirkin <[email protected]> Tested-by: Peter Krempa <[email protected]> Signed-off-by: Kevin Wolf <[email protected]>
1 parent 259a10d commit 12b2fad

File tree

1 file changed

+19
-33
lines changed

1 file changed

+19
-33
lines changed

hw/net/virtio-net.c

Lines changed: 19 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -796,48 +796,34 @@ static inline uint64_t virtio_net_supported_guest_offloads(VirtIONet *n)
796796

797797
typedef struct {
798798
VirtIONet *n;
799-
char *id;
800-
} FailoverId;
799+
DeviceState *dev;
800+
} FailoverDevice;
801801

802802
/**
803-
* Set the id of the failover primary device
803+
* Set the failover primary device
804804
*
805805
* @opaque: FailoverId to setup
806806
* @opts: opts for device we are handling
807807
* @errp: returns an error if this function fails
808808
*/
809-
static int failover_set_primary(void *opaque, QemuOpts *opts, Error **errp)
809+
static int failover_set_primary(DeviceState *dev, void *opaque)
810810
{
811-
FailoverId *fid = opaque;
812-
const char *standby_id = qemu_opt_get(opts, "failover_pair_id");
811+
FailoverDevice *fdev = opaque;
812+
PCIDevice *pci_dev = (PCIDevice *)
813+
object_dynamic_cast(OBJECT(dev), TYPE_PCI_DEVICE);
813814

814-
if (g_strcmp0(standby_id, fid->n->netclient_name) == 0) {
815-
fid->id = g_strdup(opts->id);
815+
if (!pci_dev) {
816+
return 0;
817+
}
818+
819+
if (!g_strcmp0(pci_dev->failover_pair_id, fdev->n->netclient_name)) {
820+
fdev->dev = dev;
816821
return 1;
817822
}
818823

819824
return 0;
820825
}
821826

822-
/**
823-
* Find the primary device id for this failover virtio-net
824-
*
825-
* @n: VirtIONet device
826-
* @errp: returns an error if this function fails
827-
*/
828-
static char *failover_find_primary_device_id(VirtIONet *n)
829-
{
830-
Error *err = NULL;
831-
FailoverId fid;
832-
833-
fid.n = n;
834-
if (!qemu_opts_foreach(qemu_find_opts("device"),
835-
failover_set_primary, &fid, &err)) {
836-
return NULL;
837-
}
838-
return fid.id;
839-
}
840-
841827
/**
842828
* Find the primary device for this failover virtio-net
843829
*
@@ -846,13 +832,13 @@ static char *failover_find_primary_device_id(VirtIONet *n)
846832
*/
847833
static DeviceState *failover_find_primary_device(VirtIONet *n)
848834
{
849-
char *id = failover_find_primary_device_id(n);
850-
851-
if (!id) {
852-
return NULL;
853-
}
835+
FailoverDevice fdev = {
836+
.n = n,
837+
};
854838

855-
return qdev_find_recursive(sysbus_get_default(), id);
839+
qbus_walk_children(sysbus_get_default(), failover_set_primary, NULL,
840+
NULL, NULL, &fdev);
841+
return fdev.dev;
856842
}
857843

858844
static void failover_add_primary(VirtIONet *n, Error **errp)

0 commit comments

Comments
 (0)