failover: simplify failover_unplug_primary
We can calculate device just once. Signed-off-by: Juan Quintela <quintela@redhat.com> Message-Id: <20201118083748.1328-27-quintela@redhat.com> Reviewed-by: Michael S. Tsirkin <mst@redhat.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
This commit is contained in:
parent
0e9a65c5b1
commit
07a5d816d5
@ -3146,34 +3146,29 @@ out:
|
|||||||
return !err;
|
return !err;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void virtio_net_handle_migration_primary(VirtIONet *n,
|
static void virtio_net_handle_migration_primary(VirtIONet *n, MigrationState *s)
|
||||||
MigrationState *s)
|
|
||||||
{
|
{
|
||||||
bool should_be_hidden;
|
bool should_be_hidden;
|
||||||
Error *err = NULL;
|
Error *err = NULL;
|
||||||
|
DeviceState *dev = failover_find_primary_device(n);
|
||||||
|
|
||||||
|
if (!dev) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
should_be_hidden = qatomic_read(&n->failover_primary_hidden);
|
should_be_hidden = qatomic_read(&n->failover_primary_hidden);
|
||||||
|
|
||||||
if (!n->primary_dev) {
|
|
||||||
n->primary_dev = failover_find_primary_device(n);
|
|
||||||
if (!n->primary_dev) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (migration_in_setup(s) && !should_be_hidden) {
|
if (migration_in_setup(s) && !should_be_hidden) {
|
||||||
if (failover_unplug_primary(n, n->primary_dev)) {
|
if (failover_unplug_primary(n, dev)) {
|
||||||
vmstate_unregister(VMSTATE_IF(n->primary_dev),
|
vmstate_unregister(VMSTATE_IF(dev), qdev_get_vmsd(dev), dev);
|
||||||
qdev_get_vmsd(n->primary_dev),
|
qapi_event_send_unplug_primary(dev->id);
|
||||||
n->primary_dev);
|
|
||||||
qapi_event_send_unplug_primary(n->primary_dev->id);
|
|
||||||
qatomic_set(&n->failover_primary_hidden, true);
|
qatomic_set(&n->failover_primary_hidden, true);
|
||||||
} else {
|
} else {
|
||||||
warn_report("couldn't unplug primary device");
|
warn_report("couldn't unplug primary device");
|
||||||
}
|
}
|
||||||
} else if (migration_has_failed(s)) {
|
} else if (migration_has_failed(s)) {
|
||||||
/* We already unplugged the device let's plug it back */
|
/* We already unplugged the device let's plug it back */
|
||||||
if (!failover_replug_primary(n, n->primary_dev, &err)) {
|
if (!failover_replug_primary(n, dev, &err)) {
|
||||||
if (err) {
|
if (err) {
|
||||||
error_report_err(err);
|
error_report_err(err);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user