Skip to contentSkip to conversation

Virtio net failover fixes

PATCH In review Juan Quintela 4 participants 58 messages Nov 18, 2020 – Dec 8, 2020

lore
Share & tools
lore
#0 lore raw

v2 cover Virtio net failover fixes

Hi

This is a big rework of the network failover setup. General idea is:
* We don't cache the name of the primary/standby devices
We have several problems there with stale pointers
* After this:
- We can always remove either the primary/standby devices without trouble
- Pluggin/unplugging works
- We go to device opts to see what the failover device are. Notice that we are plugging/unplugging the device, so it is not critical.
- Once there, I "fixed" managedsave for libvirt (now gives an error instead o= f just hanging)
* Fields not cached anymore:
- primary_device_dict
- primary_device_opts
- standby_id
- primary_device_id
- primary_dev
* I renamed the should_be_hidden() callback to hide device, but if people preffer the old name I can leave it.
* Add (some) doc to some functions
* Remove almost 100 lines of code while fixing things.

Please review.

Later, Juan.

Juan Quintela (27):
migration: Network Failover can't work with a paused guest
failover: fix indentantion
failover: Use always atomics for primary_should_be_hidden
failover: primary bus is only used once, and where it is set
failover: Remove unused parameter
failover: Remove external partially_hotplugged property
failover: qdev_device_add() returns err or dev set
failover: Rename bool to failover_primary_hidden
failover: g_strcmp0() knows how to handle NULL
failover: Remove primary_device_opts
failover: remove standby_id variable
failover: Remove primary_device_dict
failover: Remove memory leak
failover: simplify virtio_net_find_primary()
failover: should_be_hidden() should take a bool
failover: Rename function to hide_device()
failover: virtio_net_connect_failover_devices() does nothing
failover: Rename to failover_find_primary_device()
failover: simplify qdev_device_add() failover case
failover: simplify qdev_device_add()
failover: make sure that id always exist
failover: remove failover_find_primary_device() error parameter
failover: split failover_find_primary_device_id()
failover: We don't need to cache primary_device_id anymore
failover: Caller of this two functions already have primary_dev
failover: simplify failover_unplug_primary
failover: Remove primary_dev member

 include/hw/qdev-core.h         |  28 ++--
 include/hw/virtio/virtio-net.h |   9 +-
 hw/core/qdev.c                 |  19 +--
 hw/net/virtio-net.c            | 298 +++++++++++++--------------------
 migration/migration.c          |  13 ++
 softmmu/qdev-monitor.c         |  43 ++---
 6 files changed, 167 insertions(+), 243 deletions(-)

--=20
2.26.2

#1 lore raw

PATCH v2 1/27 migration: Network Failover can't work with a paused guest

If we have a paused guest, it can't unplug the network VF device, so we wait there forever. Just change the code to give one error on that case.

---
 migration/migration.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)
migration/migration.c +13 -0
index 87a9b59f83..d44fc880f9 100644
@@ -3548,6 +3548,18 @@ static void *migration_thread(void *opaque)
     qemu_savevm_state_setup(s->to_dst_file);
 
     if (qemu_savevm_state_guest_unplug_pending()) {
+        /* if guest is paused, it can send back the wait event */
+        if (!runstate_is_running()) {
+            Error *local_err = NULL;
+
+            error_setg(&local_err, "migration: network failover and "
+                       "guest is paused'");
+            migrate_set_error(s, local_err);
+            error_free(local_err);
+            migrate_set_state(&s->state, MIGRATION_STATUS_SETUP,
+                              MIGRATION_STATUS_FAILED);
+            goto end;
+        }
         migrate_set_state(&s->state, MIGRATION_STATUS_SETUP,
                           MIGRATION_STATUS_WAIT_UNPLUG);
 
@@ -3597,6 +3609,7 @@ static void *migration_thread(void *opaque)
     }
 
     trace_migration_thread_after_loop();
+end:
     migration_iteration_finish(s);
     object_unref(OBJECT(s));
     rcu_unregister_thread();
Signature · 1 line
2.26.2
Reviewed-by on v2 1/27
#2 lore raw

Re: [PATCH v2 01/27] migration: Network Failover can't work with a paused guest

Quoted 5 lines · * Juan Quintela ([email protected]) wrote:

If we have a paused guest, it can't unplug the network VF device, so we wait there forever. Just change the code to give one error on that case.

Quoted 38 lines
---
 migration/migration.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)
migration/migration.c +13 -0
index 87a9b59f83..d44fc880f9 100644
@@ -3548,6 +3548,18 @@ static void *migration_thread(void *opaque)
     qemu_savevm_state_setup(s->to_dst_file);
 
     if (qemu_savevm_state_guest_unplug_pending()) {
+        /* if guest is paused, it can send back the wait event */
+        if (!runstate_is_running()) {
+            Error *local_err = NULL;
+
+            error_setg(&local_err, "migration: network failover and "
+                       "guest is paused'");
+            migrate_set_error(s, local_err);
+            error_free(local_err);
+            migrate_set_state(&s->state, MIGRATION_STATUS_SETUP,
+                              MIGRATION_STATUS_FAILED);
+            goto end;
+        }
         migrate_set_state(&s->state, MIGRATION_STATUS_SETUP,
                           MIGRATION_STATUS_WAIT_UNPLUG);
 
@@ -3597,6 +3609,7 @@ static void *migration_thread(void *opaque)
     }
 
     trace_migration_thread_after_loop();
+end:
     migration_iteration_finish(s);
     object_unref(OBJECT(s));
     rcu_unregister_thread();
Signature · 1 line
2.26.2
Signature · 1 line
Dr. David Alan Gilbert / [email protected] / Manchester, UK
#3 lore raw

Re: [PATCH v2 01/27] migration: Network Failover can't work with a paused guest

In reply to Juan Quintela
Quoted 5 lines · Juan Quintela

If we have a paused guest, it can't unplug the network VF device, so we wait there forever. Just change the code to give one error on that case.

It's certainly possible but it's management that created this situation after all - why do we bother to enforce a policy? It is possible that management will unpause immediately afterwards and everything will proceed smoothly.

Yes migration will not happen until guest is unpaused but the same it true of e.g. a guest that is stuck because of a bug.

Quoted 37 lines
---
 migration/migration.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)
migration/migration.c +13 -0
index 87a9b59f83..d44fc880f9 100644
@@ -3548,6 +3548,18 @@ static void *migration_thread(void *opaque)
     qemu_savevm_state_setup(s->to_dst_file);
 
     if (qemu_savevm_state_guest_unplug_pending()) {
+        /* if guest is paused, it can send back the wait event */
+        if (!runstate_is_running()) {
+            Error *local_err = NULL;
+
+            error_setg(&local_err, "migration: network failover and "
+                       "guest is paused'");
+            migrate_set_error(s, local_err);
+            error_free(local_err);
+            migrate_set_state(&s->state, MIGRATION_STATUS_SETUP,
+                              MIGRATION_STATUS_FAILED);
+            goto end;
+        }
         migrate_set_state(&s->state, MIGRATION_STATUS_SETUP,
                           MIGRATION_STATUS_WAIT_UNPLUG);
 
@@ -3597,6 +3609,7 @@ static void *migration_thread(void *opaque)
     }
 
     trace_migration_thread_after_loop();
+end:
     migration_iteration_finish(s);
     object_unref(OBJECT(s));
     rcu_unregister_thread();
Signature · 1 line
2.26.2
#4 lore raw

Re: [PATCH v2 01/27] migration: Network Failover can't work with a paused guest

Quoted 7 lines · Michael S. Tsirkin
Quoted 5 lines · Juan Quintela

If we have a paused guest, it can't unplug the network VF device, so we wait there forever. Just change the code to give one error on that case.

Quoted 8 lines

It's certainly possible but it's management that created this situation after all - why do we bother to enforce a policy? It is possible that management will unpause immediately afterwards and everything will proceed smoothly.

Yes migration will not happen until guest is unpaused but the same it true of e.g. a guest that is stuck because of a bug.

That's pretty different behaviour from how migration normally handles a paused guest, which is that it is guaranteed to complete the migration in as short a time as network bandwidth allows.

Just ignoring the situation I think will lead to surprise apps / admins, because the person/entity invoking the migration is not likely to have checked wether this particular guest uses net failover or not before invoking - they'll just be expecting a paused migration to run fast and be guaranteed to complete.

Regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#5 lore raw

Re: [PATCH v2 01/27] migration: Network Failover can't work with a paused guest

Quoted 21 lines · Daniel P. Berrangé
Quoted 7 lines · Michael S. Tsirkin
Quoted 5 lines · Juan Quintela

If we have a paused guest, it can't unplug the network VF device, so we wait there forever. Just change the code to give one error on that case.

Quoted 8 lines

It's certainly possible but it's management that created this situation after all - why do we bother to enforce a policy? It is possible that management will unpause immediately afterwards and everything will proceed smoothly.

Yes migration will not happen until guest is unpaused but the same it true of e.g. a guest that is stuck because of a bug.

That's pretty different behaviour from how migration normally handles a paused guest, which is that it is guaranteed to complete the migration in as short a time as network bandwidth allows.

Quoted 8 lines

Just ignoring the situation I think will lead to surprise apps / admins, because the person/entity invoking the migration is not likely to have checked wether this particular guest uses net failover or not before invoking - they'll just be expecting a paused migration to run fast and be guaranteed to complete.

Regards,
Daniel

Okay I guess. But then shouldn't we handle the reverse situation too:
pausing guest after migration started but before device was unplugged?

Quoted 4 lines
Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#6 lore raw

Re: [PATCH v2 01/27] migration: Network Failover can't work with a paused guest

Quoted 28 lines · Michael S. Tsirkin
Quoted 27 lines · Daniel P. Berrangé
Quoted 7 lines · Michael S. Tsirkin
Quoted 5 lines · Juan Quintela

If we have a paused guest, it can't unplug the network VF device, so we wait there forever. Just change the code to give one error on that case.

Quoted 8 lines

It's certainly possible but it's management that created this situation after all - why do we bother to enforce a policy? It is possible that management will unpause immediately afterwards and everything will proceed smoothly.

Yes migration will not happen until guest is unpaused but the same it true of e.g. a guest that is stuck because of a bug.

That's pretty different behaviour from how migration normally handles a paused guest, which is that it is guaranteed to complete the migration in as short a time as network bandwidth allows.

Just ignoring the situation I think will lead to surprise apps / admins, because the person/entity invoking the migration is not likely to have checked wether this particular guest uses net failover or not before invoking - they'll just be expecting a paused migration to run fast and be guaranteed to complete.

Quoted 7 lines
Quoted 2 lines

Regards,
Daniel

Okay I guess. But then shouldn't we handle the reverse situation too:
pausing guest after migration started but before device was unplugged?

Thinking of which, I have no idea how we'd handle it - fail pausing guest until migration is cancelled?

All this seems heavy handed to me ...

Quoted 4 lines
Quoted 4 lines
Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#7 lore raw

Re: [PATCH v2 01/27] migration: Network Failover can't work with a paused guest

Quoted 37 lines · Michael S. Tsirkin
Quoted 28 lines · Michael S. Tsirkin
Quoted 27 lines · Daniel P. Berrangé
Quoted 7 lines · Michael S. Tsirkin
Quoted 5 lines · Juan Quintela

If we have a paused guest, it can't unplug the network VF device, so we wait there forever. Just change the code to give one error on that case.

Quoted 8 lines

It's certainly possible but it's management that created this situation after all - why do we bother to enforce a policy? It is possible that management will unpause immediately afterwards and everything will proceed smoothly.

Yes migration will not happen until guest is unpaused but the same it true of e.g. a guest that is stuck because of a bug.

That's pretty different behaviour from how migration normally handles a paused guest, which is that it is guaranteed to complete the migration in as short a time as network bandwidth allows.

Just ignoring the situation I think will lead to surprise apps / admins, because the person/entity invoking the migration is not likely to have checked wether this particular guest uses net failover or not before invoking - they'll just be expecting a paused migration to run fast and be guaranteed to complete.

Quoted 7 lines
Quoted 2 lines

Regards,
Daniel

Okay I guess. But then shouldn't we handle the reverse situation too:
pausing guest after migration started but before device was unplugged?

Quoted 4 lines

Thinking of which, I have no idea how we'd handle it - fail pausing guest until migration is cancelled?

All this seems heavy handed to me ...

This is the minimal fix that I can think of.

Further solution would be:
- Add a new migration parameter: migrate-paused
- change libvirt to use the new parameter if it exist
- in qemu, when we do start migration (but after we wait for the unplug device) paused the guest before starting migration and resume it after migration finish.

My understanding talking with Laine is that they use this functionality by default for migration, saving, etc, i.e. it is not an isolated case.

Later, Juan.

#8 lore raw

Re: [PATCH v2 01/27] migration: Network Failover can't work with a paused guest

Quoted 43 lines · Juan Quintela
Quoted 37 lines · Michael S. Tsirkin
Quoted 28 lines · Michael S. Tsirkin
Quoted 27 lines · Daniel P. Berrangé
Quoted 7 lines · Michael S. Tsirkin
Quoted 5 lines · Juan Quintela

If we have a paused guest, it can't unplug the network VF device, so we wait there forever. Just change the code to give one error on that case.

Quoted 8 lines

It's certainly possible but it's management that created this situation after all - why do we bother to enforce a policy? It is possible that management will unpause immediately afterwards and everything will proceed smoothly.

Yes migration will not happen until guest is unpaused but the same it true of e.g. a guest that is stuck because of a bug.

That's pretty different behaviour from how migration normally handles a paused guest, which is that it is guaranteed to complete the migration in as short a time as network bandwidth allows.

Just ignoring the situation I think will lead to surprise apps / admins, because the person/entity invoking the migration is not likely to have checked wether this particular guest uses net failover or not before invoking - they'll just be expecting a paused migration to run fast and be guaranteed to complete.

Quoted 7 lines
Quoted 2 lines

Regards,
Daniel

Okay I guess. But then shouldn't we handle the reverse situation too:
pausing guest after migration started but before device was unplugged?

Quoted 4 lines

Thinking of which, I have no idea how we'd handle it - fail pausing guest until migration is cancelled?

All this seems heavy handed to me ...

Quoted 8 lines

This is the minimal fix that I can think of.

Further solution would be:
- Add a new migration parameter: migrate-paused
- change libvirt to use the new parameter if it exist
- in qemu, when we do start migration (but after we wait for the unplug device) paused the guest before starting migration and resume it after migration finish.

It would also have to handle issuing of paused after migration has been started - delay the pause request until the nuplug is complete is one answer.

Quoted 2 lines

My understanding talking with Laine is that they use this functionality by default for migration, saving, etc, i.e. it is not an isolated case.

Yep, save-to-disk always runs in the paused state, and migration is also paused by default unless the mgmt app explicitl asks for live migration.

Regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#9 lore raw

Re: [PATCH v2 01/27] migration: Network Failover can't work with a paused guest

Quoted 53 lines · Daniel P. Berrangé
Quoted 43 lines · Juan Quintela
Quoted 37 lines · Michael S. Tsirkin
Quoted 28 lines · Michael S. Tsirkin
Quoted 27 lines · Daniel P. Berrangé
Quoted 7 lines · Michael S. Tsirkin
Quoted 5 lines · Juan Quintela

If we have a paused guest, it can't unplug the network VF device, so we wait there forever. Just change the code to give one error on that case.

Quoted 8 lines

It's certainly possible but it's management that created this situation after all - why do we bother to enforce a policy? It is possible that management will unpause immediately afterwards and everything will proceed smoothly.

Yes migration will not happen until guest is unpaused but the same it true of e.g. a guest that is stuck because of a bug.

That's pretty different behaviour from how migration normally handles a paused guest, which is that it is guaranteed to complete the migration in as short a time as network bandwidth allows.

Just ignoring the situation I think will lead to surprise apps / admins, because the person/entity invoking the migration is not likely to have checked wether this particular guest uses net failover or not before invoking - they'll just be expecting a paused migration to run fast and be guaranteed to complete.

Quoted 7 lines
Quoted 2 lines

Regards,
Daniel

Okay I guess. But then shouldn't we handle the reverse situation too:
pausing guest after migration started but before device was unplugged?

Quoted 4 lines

Thinking of which, I have no idea how we'd handle it - fail pausing guest until migration is cancelled?

All this seems heavy handed to me ...

Quoted 8 lines

This is the minimal fix that I can think of.

Further solution would be:
- Add a new migration parameter: migrate-paused
- change libvirt to use the new parameter if it exist
- in qemu, when we do start migration (but after we wait for the unplug device) paused the guest before starting migration and resume it after migration finish.

Quoted 3 lines

It would also have to handle issuing of paused after migration has been started - delay the pause request until the nuplug is complete is one answer.

Hmm my worry would be that pausing is one way to give cpu resources back to host. It's problematic if guest can delay that indefinitely.

Quoted 13 lines
Quoted 2 lines

My understanding talking with Laine is that they use this functionality by default for migration, saving, etc, i.e. it is not an isolated case.

Yep, save-to-disk always runs in the paused state, and migration is also paused by default unless the mgmt app explicitl asks for live migration.

Regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#10 lore raw

Re: [PATCH v2 01/27] migration: Network Failover can't work with a paused guest

Quoted 54 lines · Michael S. Tsirkin
Quoted 53 lines · Daniel P. Berrangé
Quoted 51 lines · Juan Quintela
Quoted 37 lines · Michael S. Tsirkin
Quoted 28 lines · Michael S. Tsirkin
Quoted 27 lines · Daniel P. Berrangé
Quoted 7 lines · Michael S. Tsirkin
Quoted 5 lines · Juan Quintela

If we have a paused guest, it can't unplug the network VF device, so we wait there forever. Just change the code to give one error on that case.

Quoted 8 lines

It's certainly possible but it's management that created this situation after all - why do we bother to enforce a policy? It is possible that management will unpause immediately afterwards and everything will proceed smoothly.

Yes migration will not happen until guest is unpaused but the same it true of e.g. a guest that is stuck because of a bug.

That's pretty different behaviour from how migration normally handles a paused guest, which is that it is guaranteed to complete the migration in as short a time as network bandwidth allows.

Just ignoring the situation I think will lead to surprise apps / admins, because the person/entity invoking the migration is not likely to have checked wether this particular guest uses net failover or not before invoking - they'll just be expecting a paused migration to run fast and be guaranteed to complete.

Quoted 7 lines
Quoted 2 lines

Regards,
Daniel

Okay I guess. But then shouldn't we handle the reverse situation too:
pausing guest after migration started but before device was unplugged?

Quoted 4 lines

Thinking of which, I have no idea how we'd handle it - fail pausing guest until migration is cancelled?

All this seems heavy handed to me ...

This is the minimal fix that I can think of.

Further solution would be:
- Add a new migration parameter: migrate-paused
- change libvirt to use the new parameter if it exist
- in qemu, when we do start migration (but after we wait for the unplug device) paused the guest before starting migration and resume it after migration finish.

Quoted 7 lines
Quoted 3 lines

It would also have to handle issuing of paused after migration has been started - delay the pause request until the nuplug is complete is one answer.

Hmm my worry would be that pausing is one way to give cpu resources back to host. It's problematic if guest can delay that indefinitely.

hmm, yes, that is awkward. Perhaps we should just report an explicit error then. In normal cases this won't happen, as unplug will have easily completed before the mgmt app pauses the running migration. In broken/malicious guest cases, this at least ives mgmt a heads up that something is wrong and they might then decide to cancel the migration.

Regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#11 lore raw

Re: [PATCH v2 01/27] migration: Network Failover can't work with a paused guest

Quoted 59 lines · Daniel P. Berrangé
Quoted 58 lines · Michael S. Tsirkin
Quoted 56 lines · Daniel P. Berrangé
Quoted 43 lines · Juan Quintela
Quoted 37 lines · Michael S. Tsirkin
Quoted 28 lines · Michael S. Tsirkin
Quoted 27 lines · Daniel P. Berrangé
Quoted 7 lines · Michael S. Tsirkin
Quoted 5 lines · Juan Quintela

If we have a paused guest, it can't unplug the network VF device, so we wait there forever. Just change the code to give one error on that case.

Quoted 8 lines

It's certainly possible but it's management that created this situation after all - why do we bother to enforce a policy? It is possible that management will unpause immediately afterwards and everything will proceed smoothly.

Yes migration will not happen until guest is unpaused but the same it true of e.g. a guest that is stuck because of a bug.

That's pretty different behaviour from how migration normally handles a paused guest, which is that it is guaranteed to complete the migration in as short a time as network bandwidth allows.

Just ignoring the situation I think will lead to surprise apps / admins, because the person/entity invoking the migration is not likely to have checked wether this particular guest uses net failover or not before invoking - they'll just be expecting a paused migration to run fast and be guaranteed to complete.

Quoted 7 lines
Quoted 2 lines

Regards,
Daniel

Okay I guess. But then shouldn't we handle the reverse situation too:
pausing guest after migration started but before device was unplugged?

Quoted 4 lines

Thinking of which, I have no idea how we'd handle it - fail pausing guest until migration is cancelled?

All this seems heavy handed to me ...

Quoted 8 lines

This is the minimal fix that I can think of.

Further solution would be:
- Add a new migration parameter: migrate-paused
- change libvirt to use the new parameter if it exist
- in qemu, when we do start migration (but after we wait for the unplug device) paused the guest before starting migration and resume it after migration finish.

It would also have to handle issuing of paused after migration has been started - delay the pause request until the nuplug is complete is one answer.

Quoted 6 lines
Quoted 3 lines

Hmm my worry would be that pausing is one way to give cpu resources back to host. It's problematic if guest can delay that indefinitely.

hmm, yes, that is awkward. Perhaps we should just report an explicit error then.

Report an error in response to which command? Do you mean fail migration?

Quoted 13 lines

In normal cases this won't happen, as unplug will have easily completed before the mgmt app pauses the running migration. In broken/malicious guest cases, this at least ives mgmt a heads up that something is wrong and they might then decide to cancel the migration.

Regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#12 lore raw

Re: [PATCH v2 01/27] migration: Network Failover can't work with a paused guest

Quoted 64 lines · Michael S. Tsirkin
Quoted 63 lines · Daniel P. Berrangé
Quoted 61 lines · Michael S. Tsirkin
Quoted 53 lines · Daniel P. Berrangé
Quoted 43 lines · Juan Quintela
Quoted 37 lines · Michael S. Tsirkin
Quoted 28 lines · Michael S. Tsirkin
Quoted 27 lines · Daniel P. Berrangé
Quoted 7 lines · Michael S. Tsirkin
Quoted 5 lines · Juan Quintela

If we have a paused guest, it can't unplug the network VF device, so we wait there forever. Just change the code to give one error on that case.

Quoted 8 lines

It's certainly possible but it's management that created this situation after all - why do we bother to enforce a policy? It is possible that management will unpause immediately afterwards and everything will proceed smoothly.

Yes migration will not happen until guest is unpaused but the same it true of e.g. a guest that is stuck because of a bug.

That's pretty different behaviour from how migration normally handles a paused guest, which is that it is guaranteed to complete the migration in as short a time as network bandwidth allows.

Just ignoring the situation I think will lead to surprise apps / admins, because the person/entity invoking the migration is not likely to have checked wether this particular guest uses net failover or not before invoking - they'll just be expecting a paused migration to run fast and be guaranteed to complete.

Quoted 7 lines
Quoted 2 lines

Regards,
Daniel

Okay I guess. But then shouldn't we handle the reverse situation too:
pausing guest after migration started but before device was unplugged?

Quoted 4 lines

Thinking of which, I have no idea how we'd handle it - fail pausing guest until migration is cancelled?

All this seems heavy handed to me ...

Quoted 8 lines

This is the minimal fix that I can think of.

Further solution would be:
- Add a new migration parameter: migrate-paused
- change libvirt to use the new parameter if it exist
- in qemu, when we do start migration (but after we wait for the unplug device) paused the guest before starting migration and resume it after migration finish.

Quoted 3 lines

It would also have to handle issuing of paused after migration has been started - delay the pause request until the nuplug is complete is one answer.

Hmm my worry would be that pausing is one way to give cpu resources back to host. It's problematic if guest can delay that indefinitely.

Quoted 5 lines
Quoted 2 lines

hmm, yes, that is awkward. Perhaps we should just report an explicit error then.

Report an error in response to which command? Do you mean fail migration?

If mgt attempt to pause an existing migration that hasn't finished the PCI unplug stage, then fail the pause request.

Quoted 6 lines
Quoted 6 lines

In normal cases this won't happen, as unplug will have easily completed before the mgmt app pauses the running migration. In broken/malicious guest cases, this at least ives mgmt a heads up that something is wrong and they might then decide to cancel the migration.

Regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#13 lore raw

Re: [PATCH v2 01/27] migration: Network Failover can't work with a paused guest

Quoted 65 lines · Daniel P. Berrangé
Quoted 64 lines · Michael S. Tsirkin
Quoted 63 lines · Daniel P. Berrangé
Quoted 61 lines · Michael S. Tsirkin
Quoted 53 lines · Daniel P. Berrangé
Quoted 43 lines · Juan Quintela
Quoted 37 lines · Michael S. Tsirkin
Quoted 28 lines · Michael S. Tsirkin
Quoted 27 lines · Daniel P. Berrangé
Quoted 7 lines · Michael S. Tsirkin
Quoted 5 lines · Juan Quintela

If we have a paused guest, it can't unplug the network VF device, so we wait there forever. Just change the code to give one error on that case.

Quoted 8 lines

It's certainly possible but it's management that created this situation after all - why do we bother to enforce a policy? It is possible that management will unpause immediately afterwards and everything will proceed smoothly.

Yes migration will not happen until guest is unpaused but the same it true of e.g. a guest that is stuck because of a bug.

That's pretty different behaviour from how migration normally handles a paused guest, which is that it is guaranteed to complete the migration in as short a time as network bandwidth allows.

Just ignoring the situation I think will lead to surprise apps / admins, because the person/entity invoking the migration is not likely to have checked wether this particular guest uses net failover or not before invoking - they'll just be expecting a paused migration to run fast and be guaranteed to complete.

Quoted 7 lines
Quoted 2 lines

Regards,
Daniel

Okay I guess. But then shouldn't we handle the reverse situation too:
pausing guest after migration started but before device was unplugged?

Quoted 4 lines

Thinking of which, I have no idea how we'd handle it - fail pausing guest until migration is cancelled?

All this seems heavy handed to me ...

Quoted 8 lines

This is the minimal fix that I can think of.

Further solution would be:
- Add a new migration parameter: migrate-paused
- change libvirt to use the new parameter if it exist
- in qemu, when we do start migration (but after we wait for the unplug device) paused the guest before starting migration and resume it after migration finish.

Quoted 3 lines

It would also have to handle issuing of paused after migration has been started - delay the pause request until the nuplug is complete is one answer.

Hmm my worry would be that pausing is one way to give cpu resources back to host. It's problematic if guest can delay that indefinitely.

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

hmm, yes, that is awkward. Perhaps we should just report an explicit error then.

Report an error in response to which command? Do you mean fail migration?

If mgt attempt to pause an existing migration that hasn't finished the PCI unplug stage, then fail the pause request.

Pause guest not migration ...
Might be tricky ...

Let me ask this, why not just produce a warning that migration wan't finish until guest actually runs? User will then know and unpause the guest when he wants migration to succeed ...

For example, user can restrict the amount of cpu using cgroups to a level where almost no progress is made. QEMU can't detect this ....

Quoted 13 lines
Quoted 6 lines
Quoted 6 lines

In normal cases this won't happen, as unplug will have easily completed before the mgmt app pauses the running migration. In broken/malicious guest cases, this at least ives mgmt a heads up that something is wrong and they might then decide to cancel the migration.

Regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#14 lore raw

Re: [PATCH v2 01/27] migration: Network Failover can't work with a paused guest

Quoted 75 lines · Michael S. Tsirkin
Quoted 65 lines · Daniel P. Berrangé
Quoted 64 lines · Michael S. Tsirkin
Quoted 63 lines · Daniel P. Berrangé
Quoted 61 lines · Michael S. Tsirkin
Quoted 53 lines · Daniel P. Berrangé
Quoted 43 lines · Juan Quintela
Quoted 37 lines · Michael S. Tsirkin
Quoted 28 lines · Michael S. Tsirkin
Quoted 27 lines · Daniel P. Berrangé
Quoted 7 lines · Michael S. Tsirkin
Quoted 5 lines · Juan Quintela

If we have a paused guest, it can't unplug the network VF device, so we wait there forever. Just change the code to give one error on that case.

Quoted 8 lines

It's certainly possible but it's management that created this situation after all - why do we bother to enforce a policy? It is possible that management will unpause immediately afterwards and everything will proceed smoothly.

Yes migration will not happen until guest is unpaused but the same it true of e.g. a guest that is stuck because of a bug.

That's pretty different behaviour from how migration normally handles a paused guest, which is that it is guaranteed to complete the migration in as short a time as network bandwidth allows.

Just ignoring the situation I think will lead to surprise apps / admins, because the person/entity invoking the migration is not likely to have checked wether this particular guest uses net failover or not before invoking - they'll just be expecting a paused migration to run fast and be guaranteed to complete.

Quoted 7 lines
Quoted 2 lines

Regards,
Daniel

Okay I guess. But then shouldn't we handle the reverse situation too:
pausing guest after migration started but before device was unplugged?

Quoted 4 lines

Thinking of which, I have no idea how we'd handle it - fail pausing guest until migration is cancelled?

All this seems heavy handed to me ...

Quoted 8 lines

This is the minimal fix that I can think of.

Further solution would be:
- Add a new migration parameter: migrate-paused
- change libvirt to use the new parameter if it exist
- in qemu, when we do start migration (but after we wait for the unplug device) paused the guest before starting migration and resume it after migration finish.

Quoted 3 lines

It would also have to handle issuing of paused after migration has been started - delay the pause request until the nuplug is complete is one answer.

Hmm my worry would be that pausing is one way to give cpu resources back to host. It's problematic if guest can delay that indefinitely.

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

hmm, yes, that is awkward. Perhaps we should just report an explicit error then.

Report an error in response to which command? Do you mean fail migration?

If mgt attempt to pause an existing migration that hasn't finished the PCI unplug stage, then fail the pause request.

Quoted 7 lines

Pause guest not migration ...
Might be tricky ...

Let me ask this, why not just produce a warning that migration wan't finish until guest actually runs? User will then know and unpause the guest when he wants migration to succeed ...

A warning is going to be essentally invisible if the pause command succeeeds.

Regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#15 lore raw

Re: [PATCH v2 01/27] migration: Network Failover can't work with a paused guest

Quoted 84 lines · Daniel P. Berrangé
Quoted 75 lines · Michael S. Tsirkin
Quoted 65 lines · Daniel P. Berrangé
Quoted 64 lines · Michael S. Tsirkin
Quoted 63 lines · Daniel P. Berrangé
Quoted 61 lines · Michael S. Tsirkin
Quoted 53 lines · Daniel P. Berrangé
Quoted 43 lines · Juan Quintela
Quoted 37 lines · Michael S. Tsirkin
Quoted 28 lines · Michael S. Tsirkin
Quoted 27 lines · Daniel P. Berrangé
Quoted 7 lines · Michael S. Tsirkin
Quoted 5 lines · Juan Quintela

If we have a paused guest, it can't unplug the network VF device, so
we wait there forever. Just change the code to give one error on that
case.

Signed-off-by: Juan Quintela <[email protected]>

Quoted 8 lines

It's certainly possible but it's management that created this situation after all - why do we bother to enforce a policy? It is possible that management will unpause immediately afterwards and everything will proceed smoothly.

Yes migration will not happen until guest is unpaused but the same it true of e.g. a guest that is stuck because of a bug.

That's pretty different behaviour from how migration normally handles a paused guest, which is that it is guaranteed to complete the migration in as short a time as network bandwidth allows.

Just ignoring the situation I think will lead to surprise apps / admins, because the person/entity invoking the migration is not likely to have checked wether this particular guest uses net failover or not before invoking - they'll just be expecting a paused migration to run fast and be guaranteed to complete.

Quoted 7 lines
Quoted 2 lines

Regards,
Daniel

Okay I guess. But then shouldn't we handle the reverse situation too:
pausing guest after migration started but before device was unplugged?

Quoted 4 lines

Thinking of which, I have no idea how we'd handle it - fail pausing guest until migration is cancelled?

All this seems heavy handed to me ...

Quoted 8 lines

This is the minimal fix that I can think of.

Further solution would be:
- Add a new migration parameter: migrate-paused
- change libvirt to use the new parameter if it exist
- in qemu, when we do start migration (but after we wait for the unplug device) paused the guest before starting migration and resume it after migration finish.

Quoted 3 lines

It would also have to handle issuing of paused after migration has been started - delay the pause request until the nuplug is complete is one answer.

Hmm my worry would be that pausing is one way to give cpu resources back to host. It's problematic if guest can delay that indefinitely.

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

hmm, yes, that is awkward. Perhaps we should just report an explicit error then.

Report an error in response to which command? Do you mean fail migration?

If mgt attempt to pause an existing migration that hasn't finished the PCI unplug stage, then fail the pause request.

Quoted 7 lines

Pause guest not migration ...
Might be tricky ...

Let me ask this, why not just produce a warning that migration wan't finish until guest actually runs? User will then know and unpause the guest when he wants migration to succeed ...

Quoted 5 lines

A warning is going to be essentally invisible if the pause command succeeeds.

Regards,
Daniel

I mean the situation here isn't earth shattering, an admin created it. Maybe he will unpause shortly
and all will be well ...

How about we make it possible for admin to detect that the reason for migration not making progress is that it is waiting for unplug? And maybe that guest is paused too?

I just don't see how we can detect all cases and I am not sure it is worth it to try and detect only some of them, making users think they can rely on command failure to detect them.

Quoted 4 lines
Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#16 lore raw

Re: [PATCH v2 01/27] migration: Network Failover can't work with a paused guest

Quoted 91 lines · * Michael S. Tsirkin ([email protected]) wrote:
Quoted 84 lines · Daniel P. Berrangé
Quoted 75 lines · Michael S. Tsirkin
Quoted 65 lines · Daniel P. Berrangé
Quoted 64 lines · Michael S. Tsirkin
Quoted 63 lines · Daniel P. Berrangé
Quoted 61 lines · Michael S. Tsirkin
Quoted 53 lines · Daniel P. Berrangé
Quoted 43 lines · Juan Quintela
Quoted 37 lines · Michael S. Tsirkin
Quoted 28 lines · Michael S. Tsirkin
Quoted 27 lines · Daniel P. Berrangé
Quoted 15 lines · Michael S. Tsirkin

On Wed, Nov 18, 2020 at 09:37:22AM +0100, Juan Quintela wrote:
If we have a paused guest, it can't unplug the network VF device, so
we wait there forever. Just change the code to give one error on that
case.

Signed-off-by: Juan Quintela <[email protected]>

It's certainly possible but it's management that created
this situation after all - why do we bother to enforce
a policy? It is possible that management will unpause immediately
afterwards and everything will proceed smoothly.

Yes migration will not happen until guest is
unpaused but the same it true of e.g. a guest that is stuck
because of a bug.

That's pretty different behaviour from how migration normally handles a paused guest, which is that it is guaranteed to complete the migration in as short a time as network bandwidth allows.

Just ignoring the situation I think will lead to surprise apps / admins, because the person/entity invoking the migration is not likely to have checked wether this particular guest uses net failover or not before invoking - they'll just be expecting a paused migration to run fast and be guaranteed to complete.

Quoted 7 lines
Quoted 2 lines

Regards,
Daniel

Okay I guess. But then shouldn't we handle the reverse situation too:
pausing guest after migration started but before device was unplugged?

Quoted 4 lines

Thinking of which, I have no idea how we'd handle it - fail pausing guest until migration is cancelled?

All this seems heavy handed to me ...

Quoted 8 lines

This is the minimal fix that I can think of.

Further solution would be:
- Add a new migration parameter: migrate-paused
- change libvirt to use the new parameter if it exist
- in qemu, when we do start migration (but after we wait for the unplug device) paused the guest before starting migration and resume it after migration finish.

Quoted 3 lines

It would also have to handle issuing of paused after migration has been started - delay the pause request until the nuplug is complete is one answer.

Hmm my worry would be that pausing is one way to give cpu resources back to host. It's problematic if guest can delay that indefinitely.

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

hmm, yes, that is awkward. Perhaps we should just report an explicit error then.

Report an error in response to which command? Do you mean fail migration?

If mgt attempt to pause an existing migration that hasn't finished the PCI unplug stage, then fail the pause request.

Quoted 7 lines

Pause guest not migration ...
Might be tricky ...

Let me ask this, why not just produce a warning that migration wan't finish until guest actually runs? User will then know and unpause the guest when he wants migration to succeed ...

Quoted 5 lines

A warning is going to be essentally invisible if the pause command succeeeds.

Regards,
Daniel

Quoted 7 lines

I mean the situation here isn't earth shattering, an admin created it. Maybe he will unpause shortly
and all will be well ...

How about we make it possible for admin to detect that the reason for migration not making progress is that it is waiting for unplug? And maybe that guest is paused too?

We already know that from the state of the VM.

Quoted 4 lines

I just don't see how we can detect all cases and I am not sure it is worth it to try and detect only some of them, making users think they can rely on command failure to detect them.

Another way to solve this would be to remove the unplugging from the migration layer and leave it as a problem for the management layer to do the unplug.

Dave

Quoted 6 lines
Quoted 5 lines
Signature · 4 lines
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
Signature · 1 line
Dr. David Alan Gilbert / [email protected] / Manchester, UK
#17 lore raw

Re: [PATCH v2 01/27] migration: Network Failover can't work with a paused guest

Quoted 96 lines · Dr. David Alan Gilbert
Quoted 95 lines · * Michael S. Tsirkin ([email protected]) wrote:
Quoted 84 lines · Daniel P. Berrangé
Quoted 75 lines · Michael S. Tsirkin
Quoted 65 lines · Daniel P. Berrangé
Quoted 64 lines · Michael S. Tsirkin
Quoted 63 lines · Daniel P. Berrangé
Quoted 61 lines · Michael S. Tsirkin
Quoted 53 lines · Daniel P. Berrangé
Quoted 43 lines · Juan Quintela
Quoted 37 lines · Michael S. Tsirkin
Quoted 28 lines · Michael S. Tsirkin
Quoted 27 lines · Daniel P. Berrangé

On Wed, Dec 02, 2020 at 05:13:18AM -0500, Michael S. Tsirkin wrote:
On Wed, Nov 18, 2020 at 09:37:22AM +0100, Juan Quintela wrote:
If we have a paused guest, it can't unplug the network VF device, so
we wait there forever. Just change the code to give one error on that
case.

Signed-off-by: Juan Quintela <[email protected]>

It's certainly possible but it's management that created
this situation after all - why do we bother to enforce
a policy? It is possible that management will unpause immediately
afterwards and everything will proceed smoothly.

Yes migration will not happen until guest is
unpaused but the same it true of e.g. a guest that is stuck
because of a bug.

That's pretty different behaviour from how migration normally handles
a paused guest, which is that it is guaranteed to complete the migration
in as short a time as network bandwidth allows.

Just ignoring the situation I think will lead to surprise apps / admins,
because the person/entity invoking the migration is not likely to have
checked wether this particular guest uses net failover or not before
invoking - they'll just be expecting a paused migration to run fast and
be guaranteed to complete.

Quoted 7 lines
Quoted 2 lines

Regards,
Daniel

Okay I guess. But then shouldn't we handle the reverse situation too:
pausing guest after migration started but before device was unplugged?

Quoted 4 lines

Thinking of which, I have no idea how we'd handle it - fail pausing guest until migration is cancelled?

All this seems heavy handed to me ...

Quoted 8 lines

This is the minimal fix that I can think of.

Further solution would be:
- Add a new migration parameter: migrate-paused
- change libvirt to use the new parameter if it exist
- in qemu, when we do start migration (but after we wait for the unplug device) paused the guest before starting migration and resume it after migration finish.

Quoted 3 lines

It would also have to handle issuing of paused after migration has been started - delay the pause request until the nuplug is complete is one answer.

Hmm my worry would be that pausing is one way to give cpu resources back to host. It's problematic if guest can delay that indefinitely.

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

hmm, yes, that is awkward. Perhaps we should just report an explicit error then.

Report an error in response to which command? Do you mean fail migration?

If mgt attempt to pause an existing migration that hasn't finished the PCI unplug stage, then fail the pause request.

Quoted 7 lines

Pause guest not migration ...
Might be tricky ...

Let me ask this, why not just produce a warning that migration wan't finish until guest actually runs? User will then know and unpause the guest when he wants migration to succeed ...

Quoted 5 lines

A warning is going to be essentally invisible if the pause command succeeeds.

Regards,
Daniel

I mean the situation here isn't earth shattering, an admin created it. Maybe he will unpause shortly
and all will be well ...

Quoted 5 lines
Quoted 3 lines

How about we make it possible for admin to detect that the reason for migration not making progress is that it is waiting for unplug? And maybe that guest is paused too?

We already know that from the state of the VM.

You don't know that migration is waiting for the guest action, no.

This is what we care about here right?

Quoted 19 lines
Quoted 4 lines

I just don't see how we can detect all cases and I am not sure it is worth it to try and detect only some of them, making users think they can rely on command failure to detect them.

Another way to solve this would be to remove the unplugging from the migration layer and leave it as a problem for the management layer to do the unplug.

Dave

Quoted 6 lines
Quoted 5 lines
Signature · 4 lines
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
Signature · 1 line
Dr. David Alan Gilbert / [email protected] / Manchester, UK
#18 lore raw

Re: [PATCH v2 01/27] migration: Network Failover can't work with a paused guest

Quoted 101 lines · * Michael S. Tsirkin ([email protected]) wrote:
Quoted 100 lines · Dr. David Alan Gilbert
Quoted 98 lines · * Michael S. Tsirkin ([email protected]) wrote:
Quoted 84 lines · Daniel P. Berrangé
Quoted 75 lines · Michael S. Tsirkin
Quoted 65 lines · Daniel P. Berrangé
Quoted 64 lines · Michael S. Tsirkin
Quoted 63 lines · Daniel P. Berrangé
Quoted 61 lines · Michael S. Tsirkin
Quoted 53 lines · Daniel P. Berrangé
Quoted 43 lines · Juan Quintela
Quoted 37 lines · Michael S. Tsirkin
Quoted 35 lines · Michael S. Tsirkin

On Wed, Dec 02, 2020 at 10:27:18AM +0000, Daniel P. Berrangé wrote:
On Wed, Dec 02, 2020 at 05:13:18AM -0500, Michael S. Tsirkin wrote:
On Wed, Nov 18, 2020 at 09:37:22AM +0100, Juan Quintela wrote:
If we have a paused guest, it can't unplug the network VF device, so
we wait there forever. Just change the code to give one error on that
case.

Signed-off-by: Juan Quintela <[email protected]>

It's certainly possible but it's management that created
this situation after all - why do we bother to enforce
a policy? It is possible that management will unpause immediately
afterwards and everything will proceed smoothly.

Yes migration will not happen until guest is
unpaused but the same it true of e.g. a guest that is stuck
because of a bug.

That's pretty different behaviour from how migration normally handles
a paused guest, which is that it is guaranteed to complete the migration
in as short a time as network bandwidth allows.

Just ignoring the situation I think will lead to surprise apps / admins,
because the person/entity invoking the migration is not likely to have
checked wether this particular guest uses net failover or not before
invoking - they'll just be expecting a paused migration to run fast and
be guaranteed to complete.

Regards,
Daniel

Okay I guess. But then shouldn't we handle the reverse situation too:
pausing guest after migration started but before device was
unplugged?

Quoted 4 lines

Thinking of which, I have no idea how we'd handle it - fail pausing guest until migration is cancelled?

All this seems heavy handed to me ...

Quoted 8 lines

This is the minimal fix that I can think of.

Further solution would be:
- Add a new migration parameter: migrate-paused
- change libvirt to use the new parameter if it exist
- in qemu, when we do start migration (but after we wait for the unplug device) paused the guest before starting migration and resume it after migration finish.

Quoted 3 lines

It would also have to handle issuing of paused after migration has been started - delay the pause request until the nuplug is complete is one answer.

Hmm my worry would be that pausing is one way to give cpu resources back to host. It's problematic if guest can delay that indefinitely.

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

hmm, yes, that is awkward. Perhaps we should just report an explicit error then.

Report an error in response to which command? Do you mean fail migration?

If mgt attempt to pause an existing migration that hasn't finished the PCI unplug stage, then fail the pause request.

Quoted 7 lines

Pause guest not migration ...
Might be tricky ...

Let me ask this, why not just produce a warning that migration wan't finish until guest actually runs? User will then know and unpause the guest when he wants migration to succeed ...

Quoted 5 lines

A warning is going to be essentally invisible if the pause command succeeeds.

Regards,
Daniel

I mean the situation here isn't earth shattering, an admin created it. Maybe he will unpause shortly
and all will be well ...

How about we make it possible for admin to detect that the reason for migration not making progress is that it is waiting for unplug? And maybe that guest is paused too?

Quoted 6 lines
Quoted 1 line

We already know that from the state of the VM.

You don't know that migration is waiting for the guest action, no.

This is what we care about here right?

Yes we do, the migration status should be in 'MIGRATION_STATUS_WAIT_UNPLUG' (and that should have been notified as an event).

Dave

Quoted 21 lines
Quoted 20 lines
Quoted 5 lines

I just don't see how we can detect all cases and I am not sure it is worth it to try and detect only some of them, making users think they can rely on command failure to detect them.

Another way to solve this would be to remove the unplugging from the migration layer and leave it as a problem for the management layer to do the unplug.

Dave

Quoted 6 lines
Quoted 5 lines
Signature · 4 lines
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
Signature · 1 line
Dr. David Alan Gilbert / [email protected] / Manchester, UK
Signature · 1 line
Dr. David Alan Gilbert / [email protected] / Manchester, UK
#19 lore raw

Re: [PATCH v2 01/27] migration: Network Failover can't work with a paused guest

In reply to Dr. David Alan Gilbert
Quoted 3 lines · Dr. David Alan Gilbert

Another way to solve this would be to remove the unplugging from the migration layer and leave it as a problem for the management layer to do the unplug.

Daniel described the problem with modular management tools which expect pausing or slowing down guest to cause migration to converge.

Point is, it actually *will* make it converge but only if you pause it after unplug.

As it is, these tools fundamentally can not handle failover requiring guest cooperation. Moving code between layers won't help. Introducing failure modes as this patch does won't help either especially since Daniel wrote there are countless tools like this. We just break them all but have no resources to fix them, this does not help at all.

We can just leave the situation as is.

Or if we do want to be nice to these tools, how about we unpause the guest until unplug, then pause it again? This actually addresses the problem instead of shifting the blame, does it not?

Signature · 1 line
MST
#20 lore raw

Re: [PATCH v2 01/27] migration: Network Failover can't work with a paused guest

Quoted 18 lines · Michael S. Tsirkin
Quoted 3 lines · Dr. David Alan Gilbert

Another way to solve this would be to remove the unplugging from the migration layer and leave it as a problem for the management layer to do the unplug.

Daniel described the problem with modular management tools which expect pausing or slowing down guest to cause migration to converge.

Point is, it actually *will* make it converge but only if you pause it after unplug.

As it is, these tools fundamentally can not handle failover requiring guest cooperation. Moving code between layers won't help. Introducing failure modes as this patch does won't help either especially since Daniel wrote there are countless tools like this. We just break them all but have no resources to fix them, this does not help at all.

Quoted 6 lines

We can just leave the situation as is.

Or if we do want to be nice to these tools, how about we unpause the guest until unplug, then pause it again? This actually addresses the problem instead of shifting the blame, does it not?

This is a very bad idea because it changes the execution status of the guest behind the apps/admins back, and that cannot be assumed to be a safe thing todo.

Regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#21 lore raw

Re: [PATCH v2 01/27] migration: Network Failover can't work with a paused guest

Quoted 26 lines · Daniel P. Berrangé
Quoted 18 lines · Michael S. Tsirkin
Quoted 3 lines · Dr. David Alan Gilbert

Another way to solve this would be to remove the unplugging from the migration layer and leave it as a problem for the management layer to do the unplug.

Daniel described the problem with modular management tools which expect pausing or slowing down guest to cause migration to converge.

Point is, it actually *will* make it converge but only if you pause it after unplug.

As it is, these tools fundamentally can not handle failover requiring guest cooperation. Moving code between layers won't help. Introducing failure modes as this patch does won't help either especially since Daniel wrote there are countless tools like this. We just break them all but have no resources to fix them, this does not help at all.

Quoted 6 lines

We can just leave the situation as is.

Or if we do want to be nice to these tools, how about we unpause the guest until unplug, then pause it again? This actually addresses the problem instead of shifting the blame, does it not?

Quoted 6 lines

This is a very bad idea because it changes the execution status of the guest behind the apps/admins back, and that cannot be assumed to be a safe thing todo.

Regards,
Daniel

My question is this: management gets an error since guest was paused presumably by someone (admin?) outside its control.
How does it know when it is unpaused?

Quoted 4 lines
Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#22 lore raw

Re: [PATCH v2 01/27] migration: Network Failover can't work with a paused guest

In reply to Michael S. Tsirkin
Quoted 85 lines · Michael S. Tsirkin
Quoted 84 lines · Daniel P. Berrangé
Quoted 82 lines · Michael S. Tsirkin
Quoted 65 lines · Daniel P. Berrangé
Quoted 64 lines · Michael S. Tsirkin
Quoted 63 lines · Daniel P. Berrangé
Quoted 61 lines · Michael S. Tsirkin
Quoted 53 lines · Daniel P. Berrangé
Quoted 43 lines · Juan Quintela
Quoted 37 lines · Michael S. Tsirkin
Quoted 28 lines · Michael S. Tsirkin
Quoted 27 lines · Daniel P. Berrangé
Quoted 15 lines · Michael S. Tsirkin

On Wed, Nov 18, 2020 at 09:37:22AM +0100, Juan Quintela wrote:
If we have a paused guest, it can't unplug the network VF device, so
we wait there forever. Just change the code to give one error on that
case.

Signed-off-by: Juan Quintela <[email protected]>

It's certainly possible but it's management that created
this situation after all - why do we bother to enforce
a policy? It is possible that management will unpause immediately
afterwards and everything will proceed smoothly.

Yes migration will not happen until guest is
unpaused but the same it true of e.g. a guest that is stuck
because of a bug.

That's pretty different behaviour from how migration normally handles a paused guest, which is that it is guaranteed to complete the migration in as short a time as network bandwidth allows.

Just ignoring the situation I think will lead to surprise apps / admins, because the person/entity invoking the migration is not likely to have checked wether this particular guest uses net failover or not before invoking - they'll just be expecting a paused migration to run fast and be guaranteed to complete.

Quoted 7 lines
Quoted 2 lines

Regards,
Daniel

Okay I guess. But then shouldn't we handle the reverse situation too:
pausing guest after migration started but before device was unplugged?

Quoted 4 lines

Thinking of which, I have no idea how we'd handle it - fail pausing guest until migration is cancelled?

All this seems heavy handed to me ...

Quoted 8 lines

This is the minimal fix that I can think of.

Further solution would be:
- Add a new migration parameter: migrate-paused
- change libvirt to use the new parameter if it exist
- in qemu, when we do start migration (but after we wait for the unplug device) paused the guest before starting migration and resume it after migration finish.

Quoted 3 lines

It would also have to handle issuing of paused after migration has been started - delay the pause request until the nuplug is complete is one answer.

Hmm my worry would be that pausing is one way to give cpu resources back to host. It's problematic if guest can delay that indefinitely.

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

hmm, yes, that is awkward. Perhaps we should just report an explicit error then.

Report an error in response to which command? Do you mean fail migration?

If mgt attempt to pause an existing migration that hasn't finished the PCI unplug stage, then fail the pause request.

Pause guest not migration ...
Might be tricky ...

Let me ask this, why not just produce a warning that migration wan't finish until guest actually runs? User will then know and unpause the guest when he wants migration to succeed ...

Quoted 6 lines
Quoted 2 lines

A warning is going to be essentally invisible if the pause command succeeeds.

I mean the situation here isn't earth shattering, an admin created it. Maybe he will unpause shortly
and all will be well ...

It isn't really about the admin. It is about countless existing mgmt apps that expect migration will always succeed if the VM is paused. The mgmt apps triggering the migraiton is not neccessarily the same as the app which introduced the use of NIC failover in the config.

eg in OpenStack Nova provides the VM config, but there are completely separate apps that are built todo automation on top of Nova which this is liable to break. There's no human admin there to diagnose this and re-try with unpause, as all the logic is in the apps.

Regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#23 lore raw

Re: [PATCH v2 01/27] migration: Network Failover can't work with a paused guest

Quoted 98 lines · Daniel P. Berrangé
Quoted 85 lines · Michael S. Tsirkin
Quoted 84 lines · Daniel P. Berrangé
Quoted 82 lines · Michael S. Tsirkin
Quoted 65 lines · Daniel P. Berrangé
Quoted 64 lines · Michael S. Tsirkin
Quoted 63 lines · Daniel P. Berrangé
Quoted 61 lines · Michael S. Tsirkin
Quoted 53 lines · Daniel P. Berrangé
Quoted 43 lines · Juan Quintela
Quoted 37 lines · Michael S. Tsirkin
Quoted 28 lines · Michael S. Tsirkin
Quoted 27 lines · Daniel P. Berrangé

On Wed, Dec 02, 2020 at 05:13:18AM -0500, Michael S. Tsirkin wrote:
On Wed, Nov 18, 2020 at 09:37:22AM +0100, Juan Quintela wrote:
If we have a paused guest, it can't unplug the network VF device, so
we wait there forever. Just change the code to give one error on that
case.

Signed-off-by: Juan Quintela <[email protected]>

It's certainly possible but it's management that created
this situation after all - why do we bother to enforce
a policy? It is possible that management will unpause immediately
afterwards and everything will proceed smoothly.

Yes migration will not happen until guest is
unpaused but the same it true of e.g. a guest that is stuck
because of a bug.

That's pretty different behaviour from how migration normally handles
a paused guest, which is that it is guaranteed to complete the migration
in as short a time as network bandwidth allows.

Just ignoring the situation I think will lead to surprise apps / admins,
because the person/entity invoking the migration is not likely to have
checked wether this particular guest uses net failover or not before
invoking - they'll just be expecting a paused migration to run fast and
be guaranteed to complete.

Quoted 7 lines
Quoted 2 lines

Regards,
Daniel

Okay I guess. But then shouldn't we handle the reverse situation too:
pausing guest after migration started but before device was unplugged?

Quoted 4 lines

Thinking of which, I have no idea how we'd handle it - fail pausing guest until migration is cancelled?

All this seems heavy handed to me ...

Quoted 8 lines

This is the minimal fix that I can think of.

Further solution would be:
- Add a new migration parameter: migrate-paused
- change libvirt to use the new parameter if it exist
- in qemu, when we do start migration (but after we wait for the unplug device) paused the guest before starting migration and resume it after migration finish.

Quoted 3 lines

It would also have to handle issuing of paused after migration has been started - delay the pause request until the nuplug is complete is one answer.

Hmm my worry would be that pausing is one way to give cpu resources back to host. It's problematic if guest can delay that indefinitely.

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

hmm, yes, that is awkward. Perhaps we should just report an explicit error then.

Report an error in response to which command? Do you mean fail migration?

If mgt attempt to pause an existing migration that hasn't finished the PCI unplug stage, then fail the pause request.

Pause guest not migration ...
Might be tricky ...

Let me ask this, why not just produce a warning that migration wan't finish until guest actually runs? User will then know and unpause the guest when he wants migration to succeed ...

Quoted 6 lines
Quoted 2 lines

A warning is going to be essentally invisible if the pause command succeeeds.

I mean the situation here isn't earth shattering, an admin created it. Maybe he will unpause shortly
and all will be well ...

It isn't really about the admin. It is about countless existing mgmt apps that expect migration will always succeed if the VM is paused. The mgmt apps triggering the migraiton is not neccessarily the same as the app which introduced the use of NIC failover in the config.

Quoted 8 lines

eg in OpenStack Nova provides the VM config, but there are completely separate apps that are built todo automation on top of Nova which this is liable to break. There's no human admin there to diagnose this and re-try with unpause, as all the logic is in the apps.

Regards,
Daniel

So let's say pause fails. Won't this break these theoretical apps?

Quoted 4 lines
Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#24 lore raw

Re: [PATCH v2 01/27] migration: Network Failover can't work with a paused guest

Quoted 105 lines · Michael S. Tsirkin
Quoted 104 lines · Daniel P. Berrangé
Quoted 85 lines · Michael S. Tsirkin
Quoted 84 lines · Daniel P. Berrangé
Quoted 82 lines · Michael S. Tsirkin
Quoted 65 lines · Daniel P. Berrangé
Quoted 64 lines · Michael S. Tsirkin
Quoted 63 lines · Daniel P. Berrangé
Quoted 61 lines · Michael S. Tsirkin
Quoted 53 lines · Daniel P. Berrangé
Quoted 43 lines · Juan Quintela
Quoted 37 lines · Michael S. Tsirkin
Quoted 35 lines · Michael S. Tsirkin

On Wed, Dec 02, 2020 at 10:27:18AM +0000, Daniel P. Berrangé wrote:
On Wed, Dec 02, 2020 at 05:13:18AM -0500, Michael S. Tsirkin wrote:
On Wed, Nov 18, 2020 at 09:37:22AM +0100, Juan Quintela wrote:
If we have a paused guest, it can't unplug the network VF device, so
we wait there forever. Just change the code to give one error on that
case.

Signed-off-by: Juan Quintela <[email protected]>

It's certainly possible but it's management that created
this situation after all - why do we bother to enforce
a policy? It is possible that management will unpause immediately
afterwards and everything will proceed smoothly.

Yes migration will not happen until guest is
unpaused but the same it true of e.g. a guest that is stuck
because of a bug.

That's pretty different behaviour from how migration normally handles
a paused guest, which is that it is guaranteed to complete the migration
in as short a time as network bandwidth allows.

Just ignoring the situation I think will lead to surprise apps / admins,
because the person/entity invoking the migration is not likely to have
checked wether this particular guest uses net failover or not before
invoking - they'll just be expecting a paused migration to run fast and
be guaranteed to complete.

Regards,
Daniel

Okay I guess. But then shouldn't we handle the reverse situation too:
pausing guest after migration started but before device was
unplugged?

Quoted 4 lines

Thinking of which, I have no idea how we'd handle it - fail pausing guest until migration is cancelled?

All this seems heavy handed to me ...

Quoted 8 lines

This is the minimal fix that I can think of.

Further solution would be:
- Add a new migration parameter: migrate-paused
- change libvirt to use the new parameter if it exist
- in qemu, when we do start migration (but after we wait for the unplug device) paused the guest before starting migration and resume it after migration finish.

Quoted 3 lines

It would also have to handle issuing of paused after migration has been started - delay the pause request until the nuplug is complete is one answer.

Hmm my worry would be that pausing is one way to give cpu resources back to host. It's problematic if guest can delay that indefinitely.

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

hmm, yes, that is awkward. Perhaps we should just report an explicit error then.

Report an error in response to which command? Do you mean fail migration?

If mgt attempt to pause an existing migration that hasn't finished the PCI unplug stage, then fail the pause request.

Pause guest not migration ...
Might be tricky ...

Let me ask this, why not just produce a warning that migration wan't finish until guest actually runs? User will then know and unpause the guest when he wants migration to succeed ...

Quoted 6 lines
Quoted 2 lines

A warning is going to be essentally invisible if the pause command succeeeds.

I mean the situation here isn't earth shattering, an admin created it. Maybe he will unpause shortly
and all will be well ...

It isn't really about the admin. It is about countless existing mgmt apps that expect migration will always succeed if the VM is paused. The mgmt apps triggering the migraiton is not neccessarily the same as the app which introduced the use of NIC failover in the config.

eg in OpenStack Nova provides the VM config, but there are completely separate apps that are built todo automation on top of Nova which this is liable to break. There's no human admin there to diagnose this and re-try with unpause, as all the logic is in the apps.

Quoted 4 lines
Quoted 2 lines

Regards,
Daniel

So let's say pause fails. Won't this break these theoretical apps?

Yes, they are broken in a way that can now actually be seen, as opposed to just hanging forever in migration.

Regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#25 lore raw

Re: [PATCH v2 01/27] migration: Network Failover can't work with a paused guest

Quoted 11 lines · Daniel P. Berrangé
Quoted 11 lines
Quoted 11 lines

It isn't really about the admin. It is about countless existing mgmt apps that expect migration will always succeed if the VM is paused. The mgmt apps triggering the migraiton is not neccessarily the same as the app which introduced the use of NIC failover in the config.

eg in OpenStack Nova provides the VM config, but there are completely separate apps that are built todo automation on top of Nova which this is liable to break. There's no human admin there to diagnose this and re-try with unpause, as all the logic is in the apps.

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

Regards,
Daniel

So let's say pause fails. Won't this break these theoretical apps?

Yes, they are broken in a way that can now actually be seen, as opposed to just hanging forever in migration.

Right but there are countless apps out there, and they are all broken, maybe not too hard to debug if one knows where to look, but still ...

And again only true for pause then migrate, migrate then pause is still broken, and if we fix it by failing pause then no one knows whether apps are prepared to handle a failure in the pause command, previously if used correctly it would never fail I think ...

Signature · 1 line
MST
#26 lore raw

Re: [PATCH v2 01/27] migration: Network Failover can't work with a paused guest

In reply to Daniel P. Berrangé
Quoted 65 lines · Daniel P. Berrangé
Quoted 64 lines · Michael S. Tsirkin
Quoted 63 lines · Daniel P. Berrangé
Quoted 61 lines · Michael S. Tsirkin
Quoted 53 lines · Daniel P. Berrangé
Quoted 43 lines · Juan Quintela
Quoted 37 lines · Michael S. Tsirkin
Quoted 28 lines · Michael S. Tsirkin
Quoted 27 lines · Daniel P. Berrangé
Quoted 7 lines · Michael S. Tsirkin
Quoted 5 lines · Juan Quintela

If we have a paused guest, it can't unplug the network VF device, so we wait there forever. Just change the code to give one error on that case.

Quoted 8 lines

It's certainly possible but it's management that created this situation after all - why do we bother to enforce a policy? It is possible that management will unpause immediately afterwards and everything will proceed smoothly.

Yes migration will not happen until guest is unpaused but the same it true of e.g. a guest that is stuck because of a bug.

That's pretty different behaviour from how migration normally handles a paused guest, which is that it is guaranteed to complete the migration in as short a time as network bandwidth allows.

Just ignoring the situation I think will lead to surprise apps / admins, because the person/entity invoking the migration is not likely to have checked wether this particular guest uses net failover or not before invoking - they'll just be expecting a paused migration to run fast and be guaranteed to complete.

Quoted 7 lines
Quoted 2 lines

Regards,
Daniel

Okay I guess. But then shouldn't we handle the reverse situation too:
pausing guest after migration started but before device was unplugged?

Quoted 4 lines

Thinking of which, I have no idea how we'd handle it - fail pausing guest until migration is cancelled?

All this seems heavy handed to me ...

Quoted 8 lines

This is the minimal fix that I can think of.

Further solution would be:
- Add a new migration parameter: migrate-paused
- change libvirt to use the new parameter if it exist
- in qemu, when we do start migration (but after we wait for the unplug device) paused the guest before starting migration and resume it after migration finish.

Quoted 3 lines

It would also have to handle issuing of paused after migration has been started - delay the pause request until the nuplug is complete is one answer.

Hmm my worry would be that pausing is one way to give cpu resources back to host. It's problematic if guest can delay that indefinitely.

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

hmm, yes, that is awkward. Perhaps we should just report an explicit error then.

Report an error in response to which command? Do you mean fail migration?

If mgt attempt to pause an existing migration that hasn't finished the PCI unplug stage, then fail the pause request.

OK so I guess I'll apply the rest of the patchset, and let's see a complete patch that makes pause and migrate mutually exclusive?

Quoted 13 lines
Quoted 6 lines
Quoted 6 lines

In normal cases this won't happen, as unplug will have easily completed before the mgmt app pauses the running migration. In broken/malicious guest cases, this at least ives mgmt a heads up that something is wrong and they might then decide to cancel the migration.

Regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#27 lore raw

Re: [PATCH v2 01/27] migration: Network Failover can't work with a paused guest

In reply to Michael S. Tsirkin
Quoted 28 lines · Michael S. Tsirkin
Quoted 21 lines · Daniel P. Berrangé
Quoted 7 lines · Michael S. Tsirkin
Quoted 5 lines · Juan Quintela

If we have a paused guest, it can't unplug the network VF device, so we wait there forever. Just change the code to give one error on that case.

Quoted 8 lines

It's certainly possible but it's management that created this situation after all - why do we bother to enforce a policy? It is possible that management will unpause immediately afterwards and everything will proceed smoothly.

Yes migration will not happen until guest is unpaused but the same it true of e.g. a guest that is stuck because of a bug.

That's pretty different behaviour from how migration normally handles a paused guest, which is that it is guaranteed to complete the migration in as short a time as network bandwidth allows.

Quoted 5 lines

Just ignoring the situation I think will lead to surprise apps / admins, because the person/entity invoking the migration is not likely to have checked wether this particular guest uses net failover or not before invoking - they'll just be expecting a paused migration to run fast and be guaranteed to complete.

Quoted 3 lines

Okay I guess. But then shouldn't we handle the reverse situation too:
pausing guest after migration started but before device was unplugged?

Yeah we likely want todo something there.

Regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#28 lore raw

PATCH v2 2/27 failover: fix indentantion

In reply to Juan Quintela

Once there, remove not needed cast.

---
 hw/net/virtio-net.c    | 33 +++++++++++++++------------------
 softmmu/qdev-monitor.c |  4 ++--
 2 files changed, 17 insertions(+), 20 deletions(-)
hw/net/virtio-net.c +15 -18
index 9179013ac4..1011a524bf 100644
@@ -797,7 +797,7 @@ static void failover_add_primary(VirtIONet *n, Error **errp)
     }
 
     n->primary_device_opts = qemu_opts_find(qemu_find_opts("device"),
-            n->primary_device_id);
+                                            n->primary_device_id);
     if (n->primary_device_opts) {
         n->primary_dev = qdev_device_add(n->primary_device_opts, &err);
         if (err) {
@@ -814,9 +814,9 @@ static void failover_add_primary(VirtIONet *n, Error **errp)
     } 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");
-}
+                          "sure primary device has parameter"
+                          " failover_pair_id=<virtio-net-id>\n");
+    }
     error_propagate(errp, err);
 }
 
@@ -824,7 +824,6 @@ static int is_my_primary(void *opaque, QemuOpts *opts, Error **errp)
 {
     VirtIONet *n = opaque;
     int ret = 0;
-
     const char *standby_id = qemu_opt_get(opts, "failover_pair_id");
 
     if (standby_id != NULL && (g_strcmp0(standby_id, n->netclient_name) == 0)) {
@@ -841,14 +840,14 @@ static DeviceState *virtio_net_find_primary(VirtIONet *n, Error **errp)
     Error *err = NULL;
 
     if (qemu_opts_foreach(qemu_find_opts("device"),
-                         is_my_primary, n, &err)) {
+                          is_my_primary, n, &err)) {
         if (err) {
             error_propagate(errp, err);
             return NULL;
         }
         if (n->primary_device_id) {
             dev = qdev_find_recursive(sysbus_get_default(),
-                    n->primary_device_id);
+                                      n->primary_device_id);
         } else {
             error_setg(errp, "Primary device id not found");
             return NULL;
@@ -857,8 +856,6 @@ static DeviceState *virtio_net_find_primary(VirtIONet *n, Error **errp)
     return dev;
 }
 
-
-
 static DeviceState *virtio_connect_failover_devices(VirtIONet *n,
                                                     DeviceState *dev,
                                                     Error **errp)
@@ -3126,9 +3123,9 @@ static bool failover_replug_primary(VirtIONet *n, Error **errp)
         return true;
     }
     if (!n->primary_device_opts) {
-        n->primary_device_opts = qemu_opts_from_qdict(
-                qemu_find_opts("device"),
-                n->primary_device_dict, errp);
+        n->primary_device_opts = qemu_opts_from_qdict(qemu_find_opts("device"),
+                                                      n->primary_device_dict,
+                                                      errp);
         if (!n->primary_device_opts) {
             return false;
         }
@@ -3176,8 +3173,8 @@ static void virtio_net_handle_migration_primary(VirtIONet *n,
     if (migration_in_setup(s) && !should_be_hidden) {
         if (failover_unplug_primary(n)) {
             vmstate_unregister(VMSTATE_IF(n->primary_dev),
-                    qdev_get_vmsd(n->primary_dev),
-                    n->primary_dev);
+                               qdev_get_vmsd(n->primary_dev),
+                               n->primary_dev);
             qapi_event_send_unplug_primary(n->primary_device_id);
             qatomic_set(&n->primary_should_be_hidden, true);
         } else {
@@ -3201,7 +3198,7 @@ static void virtio_net_migration_state_notifier(Notifier *notifier, void *data)
 }
 
 static int virtio_net_primary_should_be_hidden(DeviceListener *listener,
-            QemuOpts *device_opts)
+                                               QemuOpts *device_opts)
 {
     VirtIONet *n = container_of(listener, VirtIONet, primary_listener);
     bool match_found = false;
@@ -3211,11 +3208,11 @@ static int virtio_net_primary_should_be_hidden(DeviceListener *listener,
         return -1;
     }
     n->primary_device_dict = qemu_opts_to_qdict(device_opts,
-            n->primary_device_dict);
+                                                n->primary_device_dict);
     if (n->primary_device_dict) {
         g_free(n->standby_id);
         n->standby_id = g_strdup(qdict_get_try_str(n->primary_device_dict,
-                    "failover_pair_id"));
+                                                   "failover_pair_id"));
     }
     if (g_strcmp0(n->standby_id, n->netclient_name) == 0) {
         match_found = true;
@@ -3235,7 +3232,7 @@ static int virtio_net_primary_should_be_hidden(DeviceListener *listener,
     if (n->primary_device_dict) {
         g_free(n->primary_device_id);
         n->primary_device_id = g_strdup(qdict_get_try_str(
-                    n->primary_device_dict, "id"));
+                                            n->primary_device_dict, "id"));
         if (!n->primary_device_id) {
             warn_report("primary_device_id not set");
         }
softmmu/qdev-monitor.c +2 -2
index bf79d0bbcd..a25f5d612c 100644
@@ -573,10 +573,10 @@ void qdev_set_id(DeviceState *dev, const char *id)
 }
 
 static int is_failover_device(void *opaque, const char *name, const char *value,
-                        Error **errp)
+                              Error **errp)
 {
     if (strcmp(name, "failover_pair_id") == 0) {
-        QemuOpts *opts = (QemuOpts *)opaque;
+        QemuOpts *opts = opaque;
 
         if (qdev_should_hide_device(opts)) {
             return 1;
Signature · 1 line
2.26.2
#29 lore raw

PATCH v2 3/27 failover: Use always atomics for primary_should_be_hidden

In reply to Juan Quintela
---
 hw/net/virtio-net.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/net/virtio-net.c +1 -1
index 1011a524bf..a0fa63e7cb 100644
@@ -3136,7 +3136,7 @@ static bool failover_replug_primary(VirtIONet *n, Error **errp)
         return false;
     }
     qdev_set_parent_bus(n->primary_dev, n->primary_bus, &error_abort);
-    n->primary_should_be_hidden = false;
+    qatomic_set(&n->primary_should_be_hidden, false);
     if (!qemu_opt_set_bool(n->primary_device_opts,
                            "partially_hotplugged", true, errp)) {
         return false;
Signature · 1 line
2.26.2
#30 lore raw

PATCH v2 4/27 failover: primary bus is only used once, and where it is set

In reply to Juan Quintela

Just remove the struct member.

---
 include/hw/virtio/virtio-net.h | 1 -
 hw/net/virtio-net.c            | 8 ++++----
 2 files changed, 4 insertions(+), 5 deletions(-)
include/hw/virtio/virtio-net.h +0 -1
index f4852ac27b..c8da637d40 100644
@@ -205,7 +205,6 @@ struct VirtIONet {
     QemuOpts *primary_device_opts;
     QDict *primary_device_dict;
     DeviceState *primary_dev;
-    BusState *primary_bus;
     char *primary_device_id;
     char *standby_id;
     bool primary_should_be_hidden;
hw/net/virtio-net.c +4 -4
index a0fa63e7cb..786d313330 100644
@@ -804,7 +804,6 @@ static void failover_add_primary(VirtIONet *n, Error **errp)
             qemu_opts_del(n->primary_device_opts);
         }
         if (n->primary_dev) {
-            n->primary_bus = n->primary_dev->parent_bus;
             if (err) {
                 qdev_unplug(n->primary_dev, &err);
                 qdev_set_id(n->primary_dev, "");
@@ -3118,6 +3117,7 @@ static bool failover_replug_primary(VirtIONet *n, Error **errp)
     Error *err = NULL;
     HotplugHandler *hotplug_ctrl;
     PCIDevice *pdev = PCI_DEVICE(n->primary_dev);
+    BusState *primary_bus;
 
     if (!pdev->partially_hotplugged) {
         return true;
@@ -3130,12 +3130,12 @@ static bool failover_replug_primary(VirtIONet *n, Error **errp)
             return false;
         }
     }
-    n->primary_bus = n->primary_dev->parent_bus;
-    if (!n->primary_bus) {
+    primary_bus = n->primary_dev->parent_bus;
+    if (!primary_bus) {
         error_setg(errp, "virtio_net: couldn't find primary bus");
         return false;
     }
-    qdev_set_parent_bus(n->primary_dev, n->primary_bus, &error_abort);
+    qdev_set_parent_bus(n->primary_dev, primary_bus, &error_abort);
     qatomic_set(&n->primary_should_be_hidden, false);
     if (!qemu_opt_set_bool(n->primary_device_opts,
                            "partially_hotplugged", true, errp)) {
Signature · 1 line
2.26.2
#31 lore raw

PATCH v2 5/27 failover: Remove unused parameter

In reply to Juan Quintela
---
 hw/net/virtio-net.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
hw/net/virtio-net.c +3 -5
index 786d313330..3f658d6246 100644
@@ -855,9 +855,7 @@ static DeviceState *virtio_net_find_primary(VirtIONet *n, Error **errp)
     return dev;
 }
 
-static DeviceState *virtio_connect_failover_devices(VirtIONet *n,
-                                                    DeviceState *dev,
-                                                    Error **errp)
+static DeviceState *virtio_connect_failover_devices(VirtIONet *n, Error **errp)
 {
     DeviceState *prim_dev = NULL;
     Error *err = NULL;
@@ -928,7 +926,7 @@ static void virtio_net_set_features(VirtIODevice *vdev, uint64_t features)
         qatomic_set(&n->primary_should_be_hidden, false);
         failover_add_primary(n, &err);
         if (err) {
-            n->primary_dev = virtio_connect_failover_devices(n, n->qdev, &err);
+            n->primary_dev = virtio_connect_failover_devices(n, &err);
             if (err) {
                 goto out_err;
             }
@@ -3164,7 +3162,7 @@ static void virtio_net_handle_migration_primary(VirtIONet *n,
     should_be_hidden = qatomic_read(&n->primary_should_be_hidden);
 
     if (!n->primary_dev) {
-        n->primary_dev = virtio_connect_failover_devices(n, n->qdev, &err);
+        n->primary_dev = virtio_connect_failover_devices(n, &err);
         if (!n->primary_dev) {
             return;
         }
Signature · 1 line
2.26.2
#32 lore raw

PATCH v2 6/27 failover: Remove external partially_hotplugged property

In reply to Juan Quintela

It was only set "once", and with the wrong value. As far as I can see, libvirt still don't use it.

---
 hw/net/virtio-net.c | 4 ----
 1 file changed, 4 deletions(-)
hw/net/virtio-net.c +0 -4
index 3f658d6246..6ca85627d8 100644
@@ -3135,10 +3135,6 @@ static bool failover_replug_primary(VirtIONet *n, Error **errp)
     }
     qdev_set_parent_bus(n->primary_dev, primary_bus, &error_abort);
     qatomic_set(&n->primary_should_be_hidden, false);
-    if (!qemu_opt_set_bool(n->primary_device_opts,
-                           "partially_hotplugged", true, errp)) {
-        return false;
-    }
     hotplug_ctrl = qdev_get_hotplug_handler(n->primary_dev);
     if (hotplug_ctrl) {
         hotplug_handler_pre_plug(hotplug_ctrl, n->primary_dev, &err);
Signature · 1 line
2.26.2
#33 lore raw

PATCH v2 7/27 failover: qdev_device_add() returns err or dev set

In reply to Juan Quintela

Never both.

---
 hw/net/virtio-net.c | 7 -------
 1 file changed, 7 deletions(-)
hw/net/virtio-net.c +0 -7
index 6ca85627d8..3e82108d42 100644
@@ -803,13 +803,6 @@ static void failover_add_primary(VirtIONet *n, Error **errp)
         if (err) {
             qemu_opts_del(n->primary_device_opts);
         }
-        if (n->primary_dev) {
-            if (err) {
-                qdev_unplug(n->primary_dev, &err);
-                qdev_set_id(n->primary_dev, "");
-
-            }
-        }
     } else {
         error_setg(errp, "Primary device not found");
         error_append_hint(errp, "Virtio-net failover will not work. Make "
Signature · 1 line
2.26.2
#34 lore raw

PATCH v2 8/27 failover: Rename bool to failover_primary_hidden

In reply to Juan Quintela

You should not use passive naming variables.
And once there, be able to search for them.

---
 include/hw/virtio/virtio-net.h |  3 ++-
 hw/net/virtio-net.c            | 14 +++++++-------
 2 files changed, 9 insertions(+), 8 deletions(-)
include/hw/virtio/virtio-net.h +2 -1
index c8da637d40..ca68be759f 100644
@@ -207,7 +207,8 @@ struct VirtIONet {
     DeviceState *primary_dev;
     char *primary_device_id;
     char *standby_id;
-    bool primary_should_be_hidden;
+    /* primary failover device is hidden*/
+    bool failover_primary_hidden;
     bool failover;
     DeviceListener primary_listener;
     Notifier migration_state;
hw/net/virtio-net.c +7 -7
index 3e82108d42..c221671852 100644
@@ -916,7 +916,7 @@ static void virtio_net_set_features(VirtIODevice *vdev, uint64_t features)
 
     if (virtio_has_feature(features, VIRTIO_NET_F_STANDBY)) {
         qapi_event_send_failover_negotiated(n->netclient_name);
-        qatomic_set(&n->primary_should_be_hidden, false);
+        qatomic_set(&n->failover_primary_hidden, false);
         failover_add_primary(n, &err);
         if (err) {
             n->primary_dev = virtio_connect_failover_devices(n, &err);
@@ -3127,7 +3127,7 @@ static bool failover_replug_primary(VirtIONet *n, Error **errp)
         return false;
     }
     qdev_set_parent_bus(n->primary_dev, primary_bus, &error_abort);
-    qatomic_set(&n->primary_should_be_hidden, false);
+    qatomic_set(&n->failover_primary_hidden, false);
     hotplug_ctrl = qdev_get_hotplug_handler(n->primary_dev);
     if (hotplug_ctrl) {
         hotplug_handler_pre_plug(hotplug_ctrl, n->primary_dev, &err);
@@ -3148,7 +3148,7 @@ static void virtio_net_handle_migration_primary(VirtIONet *n,
     bool should_be_hidden;
     Error *err = NULL;
 
-    should_be_hidden = qatomic_read(&n->primary_should_be_hidden);
+    should_be_hidden = qatomic_read(&n->failover_primary_hidden);
 
     if (!n->primary_dev) {
         n->primary_dev = virtio_connect_failover_devices(n, &err);
@@ -3163,7 +3163,7 @@ static void virtio_net_handle_migration_primary(VirtIONet *n,
                                qdev_get_vmsd(n->primary_dev),
                                n->primary_dev);
             qapi_event_send_unplug_primary(n->primary_device_id);
-            qatomic_set(&n->primary_should_be_hidden, true);
+            qatomic_set(&n->failover_primary_hidden, true);
         } else {
             warn_report("couldn't unplug primary device");
         }
@@ -3213,8 +3213,8 @@ static int virtio_net_primary_should_be_hidden(DeviceListener *listener,
 
     n->primary_device_opts = device_opts;
 
-    /* primary_should_be_hidden is set during feature negotiation */
-    hide = qatomic_read(&n->primary_should_be_hidden);
+    /* failover_primary_hidden is set during feature negotiation */
+    hide = qatomic_read(&n->failover_primary_hidden);
 
     if (n->primary_device_dict) {
         g_free(n->primary_device_id);
@@ -3271,7 +3271,7 @@ static void virtio_net_device_realize(DeviceState *dev, Error **errp)
     if (n->failover) {
         n->primary_listener.should_be_hidden =
             virtio_net_primary_should_be_hidden;
-        qatomic_set(&n->primary_should_be_hidden, true);
+        qatomic_set(&n->failover_primary_hidden, true);
         device_listener_register(&n->primary_listener);
         n->migration_state.notify = virtio_net_migration_state_notifier;
         add_migration_state_change_notifier(&n->migration_state);
Signature · 1 line
2.26.2
#35 lore raw

PATCH v2 9/27 failover: g_strcmp0() knows how to handle NULL

In reply to Juan Quintela
---
 hw/net/virtio-net.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/net/virtio-net.c +1 -1
index c221671852..e334f05352 100644
@@ -818,7 +818,7 @@ static int is_my_primary(void *opaque, QemuOpts *opts, Error **errp)
     int ret = 0;
     const char *standby_id = qemu_opt_get(opts, "failover_pair_id");
 
-    if (standby_id != NULL && (g_strcmp0(standby_id, n->netclient_name) == 0)) {
+    if (g_strcmp0(standby_id, n->netclient_name) == 0) {
         n->primary_device_id = g_strdup(opts->id);
         ret = 1;
     }
Signature · 1 line
2.26.2
#36 lore raw

PATCH v2 10/27 failover: Remove primary_device_opts

In reply to Juan Quintela

It was really only used once, in failover_add_primary(). Just search for it on global opts when it is needed.

---
 include/hw/virtio/virtio-net.h |  1 -
 hw/net/virtio-net.c            | 21 +++++----------------
 2 files changed, 5 insertions(+), 17 deletions(-)
include/hw/virtio/virtio-net.h +0 -1
index ca68be759f..7159e6c0a0 100644
@@ -202,7 +202,6 @@ struct VirtIONet {
     AnnounceTimer announce_timer;
     bool needs_vnet_hdr_swap;
     bool mtu_bypass_backend;
-    QemuOpts *primary_device_opts;
     QDict *primary_device_dict;
     DeviceState *primary_dev;
     char *primary_device_id;
hw/net/virtio-net.c +5 -16
index e334f05352..2a99b0e0f6 100644
@@ -791,17 +791,17 @@ static inline uint64_t virtio_net_supported_guest_offloads(VirtIONet *n)
 static void failover_add_primary(VirtIONet *n, Error **errp)
 {
     Error *err = NULL;
+    QemuOpts *opts;
 
     if (n->primary_dev) {
         return;
     }
 
-    n->primary_device_opts = qemu_opts_find(qemu_find_opts("device"),
-                                            n->primary_device_id);
-    if (n->primary_device_opts) {
-        n->primary_dev = qdev_device_add(n->primary_device_opts, &err);
+    opts = qemu_opts_find(qemu_find_opts("device"), n->primary_device_id);
+    if (opts) {
+        n->primary_dev = qdev_device_add(opts, &err);
         if (err) {
-            qemu_opts_del(n->primary_device_opts);
+            qemu_opts_del(opts);
         }
     } else {
         error_setg(errp, "Primary device not found");
@@ -856,7 +856,6 @@ static DeviceState *virtio_connect_failover_devices(VirtIONet *n, Error **errp)
     prim_dev = virtio_net_find_primary(n, &err);
     if (prim_dev) {
         n->primary_device_id = g_strdup(prim_dev->id);
-        n->primary_device_opts = prim_dev->opts;
     } else {
         error_propagate(errp, err);
     }
@@ -3113,14 +3112,6 @@ static bool failover_replug_primary(VirtIONet *n, Error **errp)
     if (!pdev->partially_hotplugged) {
         return true;
     }
-    if (!n->primary_device_opts) {
-        n->primary_device_opts = qemu_opts_from_qdict(qemu_find_opts("device"),
-                                                      n->primary_device_dict,
-                                                      errp);
-        if (!n->primary_device_opts) {
-            return false;
-        }
-    }
     primary_bus = n->primary_dev->parent_bus;
     if (!primary_bus) {
         error_setg(errp, "virtio_net: couldn't find primary bus");
@@ -3211,8 +3202,6 @@ static int virtio_net_primary_should_be_hidden(DeviceListener *listener,
         goto out;
     }
 
-    n->primary_device_opts = device_opts;
-
     /* failover_primary_hidden is set during feature negotiation */
     hide = qatomic_read(&n->failover_primary_hidden);
 
Signature · 1 line
2.26.2
#37 lore raw

PATCH v2 11/27 failover: remove standby_id variable

In reply to Juan Quintela

We can calculate it, and we only use it once anyways.

---
 include/hw/virtio/virtio-net.h |  1 -
 hw/net/virtio-net.c            | 11 +++--------
 2 files changed, 3 insertions(+), 9 deletions(-)
include/hw/virtio/virtio-net.h +0 -1
index 7159e6c0a0..a055f39dd6 100644
@@ -205,7 +205,6 @@ struct VirtIONet {
     QDict *primary_device_dict;
     DeviceState *primary_dev;
     char *primary_device_id;
-    char *standby_id;
     /* primary failover device is hidden*/
     bool failover_primary_hidden;
     bool failover;
hw/net/virtio-net.c +3 -8
index 2a99b0e0f6..953d5c2bc8 100644
@@ -3181,23 +3181,19 @@ static int virtio_net_primary_should_be_hidden(DeviceListener *listener,
     VirtIONet *n = container_of(listener, VirtIONet, primary_listener);
     bool match_found = false;
     bool hide = false;
+    const char *standby_id;
 
     if (!device_opts) {
         return -1;
     }
     n->primary_device_dict = qemu_opts_to_qdict(device_opts,
                                                 n->primary_device_dict);
-    if (n->primary_device_dict) {
-        g_free(n->standby_id);
-        n->standby_id = g_strdup(qdict_get_try_str(n->primary_device_dict,
-                                                   "failover_pair_id"));
-    }
-    if (g_strcmp0(n->standby_id, n->netclient_name) == 0) {
+    standby_id = qemu_opt_get(device_opts, "failover_pair_id");
+    if (g_strcmp0(standby_id, n->netclient_name) == 0) {
         match_found = true;
     } else {
         match_found = false;
         hide = false;
-        g_free(n->standby_id);
         n->primary_device_dict = NULL;
         goto out;
     }
@@ -3400,7 +3396,6 @@ static void virtio_net_device_unrealize(DeviceState *dev)
     if (n->failover) {
         device_listener_unregister(&n->primary_listener);
         g_free(n->primary_device_id);
-        g_free(n->standby_id);
         qobject_unref(n->primary_device_dict);
         n->primary_device_dict = NULL;
     }
Signature · 1 line
2.26.2
#38 lore raw

PATCH v2 12/27 failover: Remove primary_device_dict

In reply to Juan Quintela

It was only used once. And we have there opts->id, so no need for it.

---
 include/hw/virtio/virtio-net.h |  1 -
 hw/net/virtio-net.c            | 17 ++++-------------
 2 files changed, 4 insertions(+), 14 deletions(-)
include/hw/virtio/virtio-net.h +0 -1
index a055f39dd6..fe353d8299 100644
@@ -202,7 +202,6 @@ struct VirtIONet {
     AnnounceTimer announce_timer;
     bool needs_vnet_hdr_swap;
     bool mtu_bypass_backend;
-    QDict *primary_device_dict;
     DeviceState *primary_dev;
     char *primary_device_id;
     /* primary failover device is hidden*/
hw/net/virtio-net.c +4 -13
index 953d5c2bc8..6e5a56a230 100644
@@ -3186,28 +3186,21 @@ static int virtio_net_primary_should_be_hidden(DeviceListener *listener,
     if (!device_opts) {
         return -1;
     }
-    n->primary_device_dict = qemu_opts_to_qdict(device_opts,
-                                                n->primary_device_dict);
     standby_id = qemu_opt_get(device_opts, "failover_pair_id");
     if (g_strcmp0(standby_id, n->netclient_name) == 0) {
         match_found = true;
     } else {
         match_found = false;
         hide = false;
-        n->primary_device_dict = NULL;
         goto out;
     }
 
     /* failover_primary_hidden is set during feature negotiation */
     hide = qatomic_read(&n->failover_primary_hidden);
-
-    if (n->primary_device_dict) {
-        g_free(n->primary_device_id);
-        n->primary_device_id = g_strdup(qdict_get_try_str(
-                                            n->primary_device_dict, "id"));
-        if (!n->primary_device_id) {
-            warn_report("primary_device_id not set");
-        }
+    g_free(n->primary_device_id);
+    n->primary_device_id = g_strdup(device_opts->id);
+    if (!n->primary_device_id) {
+        warn_report("primary_device_id not set");
     }
 
 out:
@@ -3396,8 +3389,6 @@ static void virtio_net_device_unrealize(DeviceState *dev)
     if (n->failover) {
         device_listener_unregister(&n->primary_listener);
         g_free(n->primary_device_id);
-        qobject_unref(n->primary_device_dict);
-        n->primary_device_dict = NULL;
     }
 
     max_queues = n->multiqueue ? n->max_queues : 1;
Signature · 1 line
2.26.2
#39 lore raw

PATCH v2 13/27 failover: Remove memory leak

In reply to Juan Quintela

Two things, at this point:

* n->primary_device_id has to be set, otherwise virtio_net_find_primary don't work. So we have a leak here.

* it has to be exactly the same that prim_dev->id because what qdev_find_recursive() does is just compare this two values.

So remove the unneeded assignment and leaky bits.

---
 hw/net/virtio-net.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
hw/net/virtio-net.c +1 -3
index 6e5a56a230..70fa372c08 100644
@@ -854,9 +854,7 @@ static DeviceState *virtio_connect_failover_devices(VirtIONet *n, Error **errp)
     Error *err = NULL;
 
     prim_dev = virtio_net_find_primary(n, &err);
-    if (prim_dev) {
-        n->primary_device_id = g_strdup(prim_dev->id);
-    } else {
+    if (!prim_dev) {
         error_propagate(errp, err);
     }
 
Signature · 1 line
2.26.2
#40 lore raw

PATCH v2 14/27 failover: simplify virtio_net_find_primary()

In reply to Juan Quintela

a - is_my_primary() never sets one error
b - If we return 1, primary_device_id is always set

---
 hw/net/virtio-net.c | 18 +++---------------
 1 file changed, 3 insertions(+), 15 deletions(-)
hw/net/virtio-net.c +3 -15
index 70fa372c08..881907d1bd 100644
@@ -828,24 +828,12 @@ static int is_my_primary(void *opaque, QemuOpts *opts, Error **errp)
 
 static DeviceState *virtio_net_find_primary(VirtIONet *n, Error **errp)
 {
-    DeviceState *dev = NULL;
     Error *err = NULL;
 
-    if (qemu_opts_foreach(qemu_find_opts("device"),
-                          is_my_primary, n, &err)) {
-        if (err) {
-            error_propagate(errp, err);
-            return NULL;
-        }
-        if (n->primary_device_id) {
-            dev = qdev_find_recursive(sysbus_get_default(),
-                                      n->primary_device_id);
-        } else {
-            error_setg(errp, "Primary device id not found");
-            return NULL;
-        }
+    if (!qemu_opts_foreach(qemu_find_opts("device"), is_my_primary, n, &err)) {
+        return NULL;
     }
-    return dev;
+    return qdev_find_recursive(sysbus_get_default(), n->primary_device_id);
 }
 
 static DeviceState *virtio_connect_failover_devices(VirtIONet *n, Error **errp)
Signature · 1 line
2.26.2
#41 lore raw

PATCH v2 15/27 failover: should_be_hidden() should take a bool

In reply to Juan Quintela

We didn't use at all the -1 value, and we don't really care. It was only used for the cases when this is not the device that we are searching for. And in that case we should not hide the device.

Once there, simplify virtio-Snet_primary_should_be_hidden.

---
 include/hw/qdev-core.h |  2 +-
 hw/core/qdev.c         | 19 +++++--------------
 hw/net/virtio-net.c    | 27 +++++++--------------------
 3 files changed, 13 insertions(+), 35 deletions(-)
include/hw/qdev-core.h +1 -1
index 5e737195b5..250f4edef6 100644
@@ -200,7 +200,7 @@ struct DeviceListener {
      * inform qdev that a device should be hidden, depending on the device
      * opts, for example, to hide a standby device.
      */
-    int (*should_be_hidden)(DeviceListener *listener, QemuOpts *device_opts);
+    bool (*should_be_hidden)(DeviceListener *listener, QemuOpts *device_opts);
     QTAILQ_ENTRY(DeviceListener) link;
 };
 
hw/core/qdev.c +5 -14
index 262bca716f..8f4b8f3cc1 100644
@@ -214,26 +214,17 @@ void device_listener_unregister(DeviceListener *listener)
 
 bool qdev_should_hide_device(QemuOpts *opts)
 {
-    int rc = -1;
     DeviceListener *listener;
 
     QTAILQ_FOREACH(listener, &device_listeners, link) {
-       if (listener->should_be_hidden) {
-            /*
-             * should_be_hidden_will return
-             *  1 if device matches opts and it should be hidden
-             *  0 if device matches opts and should not be hidden
-             *  -1 if device doesn't match ops
-             */
-            rc = listener->should_be_hidden(listener, opts);
-        }
-
-        if (rc > 0) {
-            break;
+        if (listener->should_be_hidden) {
+            if (listener->should_be_hidden(listener, opts)) {
+                return true;
+            }
         }
     }
 
-    return rc > 0;
+    return false;
 }
 
 void qdev_set_legacy_instance_id(DeviceState *dev, int alias_id,
hw/net/virtio-net.c +7 -20
index 881907d1bd..9f12d33da0 100644
@@ -3161,24 +3161,19 @@ static void virtio_net_migration_state_notifier(Notifier *notifier, void *data)
     virtio_net_handle_migration_primary(n, s);
 }
 
-static int virtio_net_primary_should_be_hidden(DeviceListener *listener,
-                                               QemuOpts *device_opts)
+static bool virtio_net_primary_should_be_hidden(DeviceListener *listener,
+                                                QemuOpts *device_opts)
 {
     VirtIONet *n = container_of(listener, VirtIONet, primary_listener);
-    bool match_found = false;
-    bool hide = false;
+    bool hide;
     const char *standby_id;
 
     if (!device_opts) {
-        return -1;
+        return false;
     }
     standby_id = qemu_opt_get(device_opts, "failover_pair_id");
-    if (g_strcmp0(standby_id, n->netclient_name) == 0) {
-        match_found = true;
-    } else {
-        match_found = false;
-        hide = false;
-        goto out;
+    if (g_strcmp0(standby_id, n->netclient_name) != 0) {
+        return false;
     }
 
     /* failover_primary_hidden is set during feature negotiation */
@@ -3188,15 +3183,7 @@ static int virtio_net_primary_should_be_hidden(DeviceListener *listener,
     if (!n->primary_device_id) {
         warn_report("primary_device_id not set");
     }
-
-out:
-    if (match_found && hide) {
-        return 1;
-    } else if (match_found && !hide) {
-        return 0;
-    } else {
-        return -1;
-    }
+    return hide;
 }
 
 static void virtio_net_device_realize(DeviceState *dev, Error **errp)
Signature · 1 line
2.26.2
#42 lore raw

PATCH v2 16/27 failover: Rename function to hide_device()

In reply to Juan Quintela

You should not use pasive.

---
 include/hw/qdev-core.h | 28 +++++++++++++++-------------
 hw/core/qdev.c         |  4 ++--
 hw/net/virtio-net.c    |  7 +++----
 3 files changed, 20 insertions(+), 19 deletions(-)
include/hw/qdev-core.h +15 -13
index 250f4edef6..6ac86db44e 100644
@@ -81,16 +81,17 @@ typedef void (*BusUnrealize)(BusState *bus);
  * </note>
  *
  * # Hiding a device #
- * To hide a device, a DeviceListener function should_be_hidden() needs to
+ * To hide a device, a DeviceListener function hide_device() needs to
  * be registered.
- * It can be used to defer adding a device and therefore hide it from the
- * guest. The handler registering to this DeviceListener can save the QOpts
- * passed to it for re-using it later and must return that it wants the device
- * to be/remain hidden or not. When the handler function decides the device
- * shall not be hidden it will be added in qdev_device_add() and
- * realized as any other device. Otherwise qdev_device_add() will return early
- * without adding the device. The guest will not see a "hidden" device
- * until it was marked don't hide and qdev_device_add called again.
+ * It can be used to defer adding a device and therefore hide it from
+ * the guest. The handler registering to this DeviceListener can save
+ * the QOpts passed to it for re-using it later. It must return if it
+ * wants the device to be hidden or visible. When the handler function
+ * decides the device shall be visible it will be added with
+ * qdev_device_add() and realized as any other device. Otherwise
+ * qdev_device_add() will return early without adding the device. The
+ * guest will not see a "hidden" device until it was marked visible
+ * and qdev_device_add called again.
  *
  */
 struct DeviceClass {
@@ -196,11 +197,12 @@ struct DeviceListener {
     void (*realize)(DeviceListener *listener, DeviceState *dev);
     void (*unrealize)(DeviceListener *listener, DeviceState *dev);
     /*
-     * This callback is called upon init of the DeviceState and allows to
-     * inform qdev that a device should be hidden, depending on the device
-     * opts, for example, to hide a standby device.
+     * This callback is called upon init of the DeviceState and
+     * informs qdev if a device should be visible or hidden.  We can
+     * hide a failover device depending for example on the device
+     * opts.
      */
-    bool (*should_be_hidden)(DeviceListener *listener, QemuOpts *device_opts);
+    bool (*hide_device)(DeviceListener *listener, QemuOpts *device_opts);
     QTAILQ_ENTRY(DeviceListener) link;
 };
 
hw/core/qdev.c +2 -2
index 8f4b8f3cc1..cbdff0b6c6 100644
@@ -217,8 +217,8 @@ bool qdev_should_hide_device(QemuOpts *opts)
     DeviceListener *listener;
 
     QTAILQ_FOREACH(listener, &device_listeners, link) {
-        if (listener->should_be_hidden) {
-            if (listener->should_be_hidden(listener, opts)) {
+        if (listener->hide_device) {
+            if (listener->hide_device(listener, opts)) {
                 return true;
             }
         }
hw/net/virtio-net.c +3 -4
index 9f12d33da0..747614ff2a 100644
@@ -3161,8 +3161,8 @@ static void virtio_net_migration_state_notifier(Notifier *notifier, void *data)
     virtio_net_handle_migration_primary(n, s);
 }
 
-static bool virtio_net_primary_should_be_hidden(DeviceListener *listener,
-                                                QemuOpts *device_opts)
+static bool failover_hide_primary_device(DeviceListener *listener,
+                                         QemuOpts *device_opts)
 {
     VirtIONet *n = container_of(listener, VirtIONet, primary_listener);
     bool hide;
@@ -3220,8 +3220,7 @@ static void virtio_net_device_realize(DeviceState *dev, Error **errp)
     }
 
     if (n->failover) {
-        n->primary_listener.should_be_hidden =
-            virtio_net_primary_should_be_hidden;
+        n->primary_listener.hide_device = failover_hide_primary_device;
         qatomic_set(&n->failover_primary_hidden, true);
         device_listener_register(&n->primary_listener);
         n->migration_state.notify = virtio_net_migration_state_notifier;
Signature · 1 line
2.26.2
#43 lore raw

PATCH v2 17/27 failover: virtio_net_connect_failover_devices() does nothing

In reply to Juan Quintela

It just calls virtio_net_find_primary(), so just update the callers.

---
 hw/net/virtio-net.c | 17 ++---------------
 1 file changed, 2 insertions(+), 15 deletions(-)
hw/net/virtio-net.c +2 -15
index 747614ff2a..c6200b924e 100644
@@ -836,19 +836,6 @@ static DeviceState *virtio_net_find_primary(VirtIONet *n, Error **errp)
     return qdev_find_recursive(sysbus_get_default(), n->primary_device_id);
 }
 
-static DeviceState *virtio_connect_failover_devices(VirtIONet *n, Error **errp)
-{
-    DeviceState *prim_dev = NULL;
-    Error *err = NULL;
-
-    prim_dev = virtio_net_find_primary(n, &err);
-    if (!prim_dev) {
-        error_propagate(errp, err);
-    }
-
-    return prim_dev;
-}
-
 static void virtio_net_set_features(VirtIODevice *vdev, uint64_t features)
 {
     VirtIONet *n = VIRTIO_NET(vdev);
@@ -904,7 +891,7 @@ 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 = virtio_connect_failover_devices(n, &err);
+            n->primary_dev = virtio_net_find_primary(n, &err);
             if (err) {
                 goto out_err;
             }
@@ -3128,7 +3115,7 @@ static void virtio_net_handle_migration_primary(VirtIONet *n,
     should_be_hidden = qatomic_read(&n->failover_primary_hidden);
 
     if (!n->primary_dev) {
-        n->primary_dev = virtio_connect_failover_devices(n, &err);
+        n->primary_dev = virtio_net_find_primary(n, &err);
         if (!n->primary_dev) {
             return;
         }
Signature · 1 line
2.26.2
#44 lore raw

PATCH v2 18/27 failover: Rename to failover_find_primary_device()

In reply to Juan Quintela

This commit:
* Rename them to failover_find_primary_devices() so
- it starts with failover_
- it don't connect anything, just find the primary device
* Create documentation for the function

---
 hw/net/virtio-net.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
hw/net/virtio-net.c +9 -3
index c6200b924e..ff82f1017d 100644
@@ -826,7 +826,13 @@ static int is_my_primary(void *opaque, QemuOpts *opts, Error **errp)
     return ret;
 }
 
-static DeviceState *virtio_net_find_primary(VirtIONet *n, Error **errp)
+/**
+ * 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, Error **errp)
 {
     Error *err = NULL;
 
@@ -891,7 +897,7 @@ 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 = virtio_net_find_primary(n, &err);
+            n->primary_dev = failover_find_primary_device(n, &err);
             if (err) {
                 goto out_err;
             }
@@ -3115,7 +3121,7 @@ static void virtio_net_handle_migration_primary(VirtIONet *n,
     should_be_hidden = qatomic_read(&n->failover_primary_hidden);
 
     if (!n->primary_dev) {
-        n->primary_dev = virtio_net_find_primary(n, &err);
+        n->primary_dev = failover_find_primary_device(n, &err);
         if (!n->primary_dev) {
             return;
         }
Signature · 1 line
2.26.2
#45 lore raw

PATCH v2 19/27 failover: simplify qdev_device_add() failover case

In reply to Juan Quintela

Just put allthe logic inside the same if.

---
 softmmu/qdev-monitor.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)
softmmu/qdev-monitor.c +8 -7
index a25f5d612c..12b7540f17 100644
@@ -600,7 +600,6 @@ DeviceState *qdev_device_add(QemuOpts *opts, Error **errp)
     const char *driver, *path;
     DeviceState *dev = NULL;
     BusState *bus = NULL;
-    bool hide;
 
     driver = qemu_opt_get(opts, "driver");
     if (!driver) {
@@ -634,17 +633,19 @@ DeviceState *qdev_device_add(QemuOpts *opts, Error **errp)
             return NULL;
         }
     }
-    hide = should_hide_device(opts);
 
-    if ((hide || qdev_hotplug) && bus && !qbus_is_hotpluggable(bus)) {
+    if (should_hide_device(opts)) {
+        if (bus && !qbus_is_hotpluggable(bus)) {
+            error_setg(errp, QERR_BUS_NO_HOTPLUG, bus->name);
+        }
+        return NULL;
+    }
+
+    if (qdev_hotplug && bus && !qbus_is_hotpluggable(bus)) {
         error_setg(errp, QERR_BUS_NO_HOTPLUG, bus->name);
         return NULL;
     }
 
-    if (hide) {
-        return NULL;
-    }
-
     if (!migration_is_idle()) {
         error_setg(errp, "device_add not allowed while migrating");
         return NULL;
Signature · 1 line
2.26.2
#46 lore raw

PATCH v2 20/27 failover: simplify qdev_device_add()

In reply to Juan Quintela

We don't need to walk the opts by hand. qmp_opt_get() already does that. And then we can remove the functions that did that walk.

---
 softmmu/qdev-monitor.c | 32 ++++++--------------------------
 1 file changed, 6 insertions(+), 26 deletions(-)
softmmu/qdev-monitor.c +6 -26
index 12b7540f17..0e10f0466f 100644
@@ -572,28 +572,6 @@ void qdev_set_id(DeviceState *dev, const char *id)
     }
 }
 
-static int is_failover_device(void *opaque, const char *name, const char *value,
-                              Error **errp)
-{
-    if (strcmp(name, "failover_pair_id") == 0) {
-        QemuOpts *opts = opaque;
-
-        if (qdev_should_hide_device(opts)) {
-            return 1;
-        }
-    }
-
-    return 0;
-}
-
-static bool should_hide_device(QemuOpts *opts)
-{
-    if (qemu_opt_foreach(opts, is_failover_device, opts, NULL) == 0) {
-        return false;
-    }
-    return true;
-}
-
 DeviceState *qdev_device_add(QemuOpts *opts, Error **errp)
 {
     DeviceClass *dc;
@@ -634,11 +612,13 @@ DeviceState *qdev_device_add(QemuOpts *opts, Error **errp)
         }
     }
 
-    if (should_hide_device(opts)) {
-        if (bus && !qbus_is_hotpluggable(bus)) {
-            error_setg(errp, QERR_BUS_NO_HOTPLUG, bus->name);
+    if (qemu_opt_get(opts, "failover_pair_id")) {
+        if (qdev_should_hide_device(opts)) {
+            if (bus && !qbus_is_hotpluggable(bus)) {
+                error_setg(errp, QERR_BUS_NO_HOTPLUG, bus->name);
+            }
+            return NULL;
         }
-        return NULL;
     }
 
     if (qdev_hotplug && bus && !qbus_is_hotpluggable(bus)) {
Signature · 1 line
2.26.2
#47 lore raw

PATCH v2 21/27 failover: make sure that id always exist

In reply to Juan Quintela

We check that it exist at device creation time, so we don't have to check anywhere else.

---
 hw/net/virtio-net.c    | 3 ---
 softmmu/qdev-monitor.c | 4 ++++
 2 files changed, 4 insertions(+), 3 deletions(-)
hw/net/virtio-net.c +0 -3
index ff82f1017d..c708c03cf6 100644
@@ -3173,9 +3173,6 @@ static bool failover_hide_primary_device(DeviceListener *listener,
     hide = qatomic_read(&n->failover_primary_hidden);
     g_free(n->primary_device_id);
     n->primary_device_id = g_strdup(device_opts->id);
-    if (!n->primary_device_id) {
-        warn_report("primary_device_id not set");
-    }
     return hide;
 }
 
softmmu/qdev-monitor.c +4 -0
index 0e10f0466f..301089eaea 100644
@@ -613,6 +613,10 @@ DeviceState *qdev_device_add(QemuOpts *opts, Error **errp)
     }
 
     if (qemu_opt_get(opts, "failover_pair_id")) {
+        if (!opts->id) {
+            error_setg(errp, "Device with failover_pair_id don't have id");
+            return NULL;
+        }
         if (qdev_should_hide_device(opts)) {
             if (bus && !qbus_is_hotpluggable(bus)) {
                 error_setg(errp, QERR_BUS_NO_HOTPLUG, bus->name);
Signature · 1 line
2.26.2
#48 lore raw

PATCH v2 22/27 failover: remove failover_find_primary_device() error parameter

In reply to Juan Quintela

It can never give one error.

---
 hw/net/virtio-net.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)
hw/net/virtio-net.c +3 -6
index c708c03cf6..b994796734 100644
@@ -832,7 +832,7 @@ static int is_my_primary(void *opaque, QemuOpts *opts, Error **errp)
  * @n: VirtIONet device
  * @errp: returns an error if this function fails
  */
-static DeviceState *failover_find_primary_device(VirtIONet *n, Error **errp)
+static DeviceState *failover_find_primary_device(VirtIONet *n)
 {
     Error *err = NULL;
 
@@ -897,10 +897,7 @@ 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, &err);
-            if (err) {
-                goto out_err;
-            }
+            n->primary_dev = failover_find_primary_device(n);
             failover_add_primary(n, &err);
             if (err) {
                 goto out_err;
@@ -3121,7 +3118,7 @@ static void virtio_net_handle_migration_primary(VirtIONet *n,
     should_be_hidden = qatomic_read(&n->failover_primary_hidden);
 
     if (!n->primary_dev) {
-        n->primary_dev = failover_find_primary_device(n, &err);
+        n->primary_dev = failover_find_primary_device(n);
         if (!n->primary_dev) {
             return;
         }
Signature · 1 line
2.26.2
#49 lore raw

PATCH v2 23/27 failover: split failover_find_primary_device_id()

In reply to Juan Quintela

So we can calculate the device id when we need it.

---
 hw/net/virtio-net.c | 63 +++++++++++++++++++++++++++++++++------------
 1 file changed, 47 insertions(+), 16 deletions(-)
hw/net/virtio-net.c +47 -16
index b994796734..2c502c13fd 100644
@@ -788,6 +788,49 @@ static inline uint64_t virtio_net_supported_guest_offloads(VirtIONet *n)
     return virtio_net_guest_offloads_by_features(vdev->guest_features);
 }
 
+typedef struct {
+    VirtIONet *n;
+    char *id;
+} FailoverId;
+
+/**
+ * Set the id of the failover primary device
+ *
+ * @opaque: FailoverId to setup
+ * @opts: opts for device we are handling
+ * @errp: returns an error if this function fails
+ */
+static int failover_set_primary(void *opaque, QemuOpts *opts, Error **errp)
+{
+    FailoverId *fid = opaque;
+    const char *standby_id = qemu_opt_get(opts, "failover_pair_id");
+
+    if (g_strcmp0(standby_id, fid->n->netclient_name) == 0) {
+        fid->id = g_strdup(opts->id);
+        return 1;
+    }
+
+    return 0;
+}
+
+/**
+ * Find the primary device id for this failover virtio-net
+ *
+ * @n: VirtIONet device
+ * @errp: returns an error if this function fails
+ */
+static char *failover_find_primary_device_id(VirtIONet *n)
+{
+    Error *err = NULL;
+    FailoverId fid;
+
+    if (!qemu_opts_foreach(qemu_find_opts("device"),
+                           failover_set_primary, &fid, &err)) {
+        return NULL;
+    }
+    return fid.id;
+}
+
 static void failover_add_primary(VirtIONet *n, Error **errp)
 {
     Error *err = NULL;
@@ -812,20 +855,6 @@ static void failover_add_primary(VirtIONet *n, Error **errp)
     error_propagate(errp, err);
 }
 
-static int is_my_primary(void *opaque, QemuOpts *opts, Error **errp)
-{
-    VirtIONet *n = opaque;
-    int ret = 0;
-    const char *standby_id = qemu_opt_get(opts, "failover_pair_id");
-
-    if (g_strcmp0(standby_id, n->netclient_name) == 0) {
-        n->primary_device_id = g_strdup(opts->id);
-        ret = 1;
-    }
-
-    return ret;
-}
-
 /**
  * Find the primary device for this failover virtio-net
  *
@@ -834,11 +863,13 @@ static int is_my_primary(void *opaque, QemuOpts *opts, Error **errp)
  */
 static DeviceState *failover_find_primary_device(VirtIONet *n)
 {
-    Error *err = NULL;
+    char *id = failover_find_primary_device_id(n);
 
-    if (!qemu_opts_foreach(qemu_find_opts("device"), is_my_primary, n, &err)) {
+    if (!id) {
         return NULL;
     }
+    n->primary_device_id = g_strdup(id);
+
     return qdev_find_recursive(sysbus_get_default(), n->primary_device_id);
 }
 
Signature · 1 line
2.26.2
#50 lore raw

PATCH v2 24/27 failover: We don't need to cache primary_device_id anymore

In reply to Juan Quintela
---
 include/hw/virtio/virtio-net.h |  1 -
 hw/net/virtio-net.c            | 20 ++++++++++----------
 2 files changed, 10 insertions(+), 11 deletions(-)
include/hw/virtio/virtio-net.h +0 -1
index fe353d8299..efef64e02f 100644
@@ -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;
hw/net/virtio-net.c +10 -10
index 2c502c13fd..746ed3fb71 100644
@@ -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;
Signature · 1 line
2.26.2
#51 lore raw

PATCH v2 25/27 failover: Caller of this two functions already have primary_dev

In reply to Juan Quintela

Pass it as an argument.

---
 hw/net/virtio-net.c | 27 ++++++++++++++-------------
 1 file changed, 14 insertions(+), 13 deletions(-)
hw/net/virtio-net.c +14 -13
index 746ed3fb71..b37e9cd1d9 100644
@@ -3093,17 +3093,17 @@ void virtio_net_set_netclient_name(VirtIONet *n, const char *name,
     n->netclient_type = g_strdup(type);
 }
 
-static bool failover_unplug_primary(VirtIONet *n)
+static bool failover_unplug_primary(VirtIONet *n, DeviceState *dev)
 {
     HotplugHandler *hotplug_ctrl;
     PCIDevice *pci_dev;
     Error *err = NULL;
 
-    hotplug_ctrl = qdev_get_hotplug_handler(n->primary_dev);
+    hotplug_ctrl = qdev_get_hotplug_handler(dev);
     if (hotplug_ctrl) {
-        pci_dev = PCI_DEVICE(n->primary_dev);
+        pci_dev = PCI_DEVICE(dev);
         pci_dev->partially_hotplugged = true;
-        hotplug_handler_unplug_request(hotplug_ctrl, n->primary_dev, &err);
+        hotplug_handler_unplug_request(hotplug_ctrl, dev, &err);
         if (err) {
             error_report_err(err);
             return false;
@@ -3114,30 +3114,31 @@ static bool failover_unplug_primary(VirtIONet *n)
     return true;
 }
 
-static bool failover_replug_primary(VirtIONet *n, Error **errp)
+static bool failover_replug_primary(VirtIONet *n, DeviceState *dev,
+                                    Error **errp)
 {
     Error *err = NULL;
     HotplugHandler *hotplug_ctrl;
-    PCIDevice *pdev = PCI_DEVICE(n->primary_dev);
+    PCIDevice *pdev = PCI_DEVICE(dev);
     BusState *primary_bus;
 
     if (!pdev->partially_hotplugged) {
         return true;
     }
-    primary_bus = n->primary_dev->parent_bus;
+    primary_bus = dev->parent_bus;
     if (!primary_bus) {
         error_setg(errp, "virtio_net: couldn't find primary bus");
         return false;
     }
-    qdev_set_parent_bus(n->primary_dev, primary_bus, &error_abort);
+    qdev_set_parent_bus(dev, primary_bus, &error_abort);
     qatomic_set(&n->failover_primary_hidden, false);
-    hotplug_ctrl = qdev_get_hotplug_handler(n->primary_dev);
+    hotplug_ctrl = qdev_get_hotplug_handler(dev);
     if (hotplug_ctrl) {
-        hotplug_handler_pre_plug(hotplug_ctrl, n->primary_dev, &err);
+        hotplug_handler_pre_plug(hotplug_ctrl, dev, &err);
         if (err) {
             goto out;
         }
-        hotplug_handler_plug(hotplug_ctrl, n->primary_dev, &err);
+        hotplug_handler_plug(hotplug_ctrl, dev, &err);
     }
 
 out:
@@ -3161,7 +3162,7 @@ static void virtio_net_handle_migration_primary(VirtIONet *n,
     }
 
     if (migration_in_setup(s) && !should_be_hidden) {
-        if (failover_unplug_primary(n)) {
+        if (failover_unplug_primary(n, n->primary_dev)) {
             vmstate_unregister(VMSTATE_IF(n->primary_dev),
                                qdev_get_vmsd(n->primary_dev),
                                n->primary_dev);
@@ -3172,7 +3173,7 @@ static void virtio_net_handle_migration_primary(VirtIONet *n,
         }
     } else if (migration_has_failed(s)) {
         /* We already unplugged the device let's plug it back */
-        if (!failover_replug_primary(n, &err)) {
+        if (!failover_replug_primary(n, n->primary_dev, &err)) {
             if (err) {
                 error_report_err(err);
             }
Signature · 1 line
2.26.2
#52 lore raw
In reply to Juan Quintela
Quoted 23 lines · Juan Quintela

Hi

This is a big rework of the network failover setup. General idea is:
* We don't cache the name of the primary/standby devices
We have several problems there with stale pointers
* After this:
- We can always remove either the primary/standby devices without trouble
- Pluggin/unplugging works
- We go to device opts to see what the failover device are. Notice that we are plugging/unplugging the device, so it is not critical.
- Once there, I "fixed" managedsave for libvirt (now gives an error instead o= f just hanging)
* Fields not cached anymore:
- primary_device_dict
- primary_device_opts
- standby_id
- primary_device_id
- primary_dev
* I renamed the should_be_hidden() callback to hide device, but if people preffer the old name I can leave it.
* Add (some) doc to some functions
* Remove almost 100 lines of code while fixing things.

Quoted 1 line

Please review.

OK that's great, any of this appropriate for 5.2?
The memory leak fix maybe?

Quoted 42 lines

Later, Juan.

Juan Quintela (27):
migration: Network Failover can't work with a paused guest
failover: fix indentantion
failover: Use always atomics for primary_should_be_hidden
failover: primary bus is only used once, and where it is set
failover: Remove unused parameter
failover: Remove external partially_hotplugged property
failover: qdev_device_add() returns err or dev set
failover: Rename bool to failover_primary_hidden
failover: g_strcmp0() knows how to handle NULL
failover: Remove primary_device_opts
failover: remove standby_id variable
failover: Remove primary_device_dict
failover: Remove memory leak
failover: simplify virtio_net_find_primary()
failover: should_be_hidden() should take a bool
failover: Rename function to hide_device()
failover: virtio_net_connect_failover_devices() does nothing
failover: Rename to failover_find_primary_device()
failover: simplify qdev_device_add() failover case
failover: simplify qdev_device_add()
failover: make sure that id always exist
failover: remove failover_find_primary_device() error parameter
failover: split failover_find_primary_device_id()
failover: We don't need to cache primary_device_id anymore
failover: Caller of this two functions already have primary_dev
failover: simplify failover_unplug_primary
failover: Remove primary_dev member

 include/hw/qdev-core.h         |  28 ++--
 include/hw/virtio/virtio-net.h |   9 +-
 hw/core/qdev.c                 |  19 +--
 hw/net/virtio-net.c            | 298 +++++++++++++--------------------
 migration/migration.c          |  13 ++
 softmmu/qdev-monitor.c         |  43 ++---
 6 files changed, 167 insertions(+), 243 deletions(-)

--=20
2.26.2

#53 lore raw
Quoted 24 lines · Michael S. Tsirkin
Quoted 23 lines · Juan Quintela

Hi

This is a big rework of the network failover setup. General idea is:
* We don't cache the name of the primary/standby devices
We have several problems there with stale pointers
* After this:
- We can always remove either the primary/standby devices without trouble
- Pluggin/unplugging works
- We go to device opts to see what the failover device are. Notice that we are plugging/unplugging the device, so it is not critical.
- Once there, I "fixed" managedsave for libvirt (now gives an error instead o= f just hanging)
* Fields not cached anymore:
- primary_device_dict
- primary_device_opts
- standby_id
- primary_device_id
- primary_dev
* I renamed the should_be_hidden() callback to hide device, but if people preffer the old name I can leave it.
* Add (some) doc to some functions
* Remove almost 100 lines of code while fixing things.

Quoted 4 lines
Quoted 1 line

Please review.

OK that's great, any of this appropriate for 5.2?
The memory leak fix maybe?

1st one is also a fix, current code just hangs the guest. Rest of things .... current code fails a lot, but we are too late on the cycle.

Later, Juan.

Quoted 42 lines
Quoted 42 lines

Later, Juan.

Juan Quintela (27):
migration: Network Failover can't work with a paused guest
failover: fix indentantion
failover: Use always atomics for primary_should_be_hidden
failover: primary bus is only used once, and where it is set
failover: Remove unused parameter
failover: Remove external partially_hotplugged property
failover: qdev_device_add() returns err or dev set
failover: Rename bool to failover_primary_hidden
failover: g_strcmp0() knows how to handle NULL
failover: Remove primary_device_opts
failover: remove standby_id variable
failover: Remove primary_device_dict
failover: Remove memory leak
failover: simplify virtio_net_find_primary()
failover: should_be_hidden() should take a bool
failover: Rename function to hide_device()
failover: virtio_net_connect_failover_devices() does nothing
failover: Rename to failover_find_primary_device()
failover: simplify qdev_device_add() failover case
failover: simplify qdev_device_add()
failover: make sure that id always exist
failover: remove failover_find_primary_device() error parameter
failover: split failover_find_primary_device_id()
failover: We don't need to cache primary_device_id anymore
failover: Caller of this two functions already have primary_dev
failover: simplify failover_unplug_primary
failover: Remove primary_dev member

 include/hw/qdev-core.h         |  28 ++--
 include/hw/virtio/virtio-net.h |   9 +-
 hw/core/qdev.c                 |  19 +--
 hw/net/virtio-net.c            | 298 +++++++++++++--------------------
 migration/migration.c          |  13 ++
 softmmu/qdev-monitor.c         |  43 ++---
 6 files changed, 167 insertions(+), 243 deletions(-)

--=20
2.26.2

#54 lore raw
Quoted 25 lines · Juan Quintela
Quoted 24 lines · Michael S. Tsirkin
Quoted 23 lines · Juan Quintela

Hi

This is a big rework of the network failover setup. General idea is:
* We don't cache the name of the primary/standby devices
We have several problems there with stale pointers
* After this:
- We can always remove either the primary/standby devices without trouble
- Pluggin/unplugging works
- We go to device opts to see what the failover device are. Notice that we are plugging/unplugging the device, so it is not critical.
- Once there, I "fixed" managedsave for libvirt (now gives an error instead o= f just hanging)
* Fields not cached anymore:
- primary_device_dict
- primary_device_opts
- standby_id
- primary_device_id
- primary_dev
* I renamed the should_be_hidden() callback to hide device, but if people preffer the old name I can leave it.
* Add (some) doc to some functions
* Remove almost 100 lines of code while fixing things.

Quoted 6 lines
Quoted 4 lines
Quoted 1 line

Please review.

OK that's great, any of this appropriate for 5.2?
The memory leak fix maybe?

1st one is also a fix, current code just hangs the guest.

Hmm it does but then proceeds when you unpause so I'm not sure it's a good idea for 5.2. It's late in the cycle to try to handle management bugs ...

Quoted 48 lines

Rest of things .... current code fails a lot, but we are too late on the cycle.

Later, Juan.

Quoted 42 lines
Quoted 42 lines

Later, Juan.

Juan Quintela (27):
migration: Network Failover can't work with a paused guest
failover: fix indentantion
failover: Use always atomics for primary_should_be_hidden
failover: primary bus is only used once, and where it is set
failover: Remove unused parameter
failover: Remove external partially_hotplugged property
failover: qdev_device_add() returns err or dev set
failover: Rename bool to failover_primary_hidden
failover: g_strcmp0() knows how to handle NULL
failover: Remove primary_device_opts
failover: remove standby_id variable
failover: Remove primary_device_dict
failover: Remove memory leak
failover: simplify virtio_net_find_primary()
failover: should_be_hidden() should take a bool
failover: Rename function to hide_device()
failover: virtio_net_connect_failover_devices() does nothing
failover: Rename to failover_find_primary_device()
failover: simplify qdev_device_add() failover case
failover: simplify qdev_device_add()
failover: make sure that id always exist
failover: remove failover_find_primary_device() error parameter
failover: split failover_find_primary_device_id()
failover: We don't need to cache primary_device_id anymore
failover: Caller of this two functions already have primary_dev
failover: simplify failover_unplug_primary
failover: Remove primary_dev member

 include/hw/qdev-core.h         |  28 ++--
 include/hw/virtio/virtio-net.h |   9 +-
 hw/core/qdev.c                 |  19 +--
 hw/net/virtio-net.c            | 298 +++++++++++++--------------------
 migration/migration.c          |  13 ++
 softmmu/qdev-monitor.c         |  43 ++---
 6 files changed, 167 insertions(+), 243 deletions(-)

--=20
2.26.2

#55 lore raw

PATCH v2 26/27 failover: simplify failover_unplug_primary

In reply to Juan Quintela

We can calculate device just once.

---
 hw/net/virtio-net.c | 25 ++++++++++---------------
 1 file changed, 10 insertions(+), 15 deletions(-)
hw/net/virtio-net.c +10 -15
index b37e9cd1d9..9203d81780 100644
@@ -3146,34 +3146,29 @@ out:
     return !err;
 }
 
-static void virtio_net_handle_migration_primary(VirtIONet *n,
-                                                MigrationState *s)
+static void virtio_net_handle_migration_primary(VirtIONet *n, MigrationState *s)
 {
     bool should_be_hidden;
     Error *err = NULL;
+    DeviceState *dev = failover_find_primary_device(n);
+
+    if (!dev) {
+        return;
+    }
 
     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 (failover_unplug_primary(n, n->primary_dev)) {
-            vmstate_unregister(VMSTATE_IF(n->primary_dev),
-                               qdev_get_vmsd(n->primary_dev),
-                               n->primary_dev);
-            qapi_event_send_unplug_primary(n->primary_dev->id);
+        if (failover_unplug_primary(n, dev)) {
+            vmstate_unregister(VMSTATE_IF(dev), qdev_get_vmsd(dev), dev);
+            qapi_event_send_unplug_primary(dev->id);
             qatomic_set(&n->failover_primary_hidden, true);
         } else {
             warn_report("couldn't unplug primary device");
         }
     } else if (migration_has_failed(s)) {
         /* 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) {
                 error_report_err(err);
             }
Signature · 1 line
2.26.2
#56 lore raw

PATCH v2 27/27 failover: Remove primary_dev member

In reply to Juan Quintela

Only three uses remained, and we can remove them on that case.

---
 include/hw/virtio/virtio-net.h |  1 -
 hw/net/virtio-net.c            | 55 +++++++++++++++-------------------
 2 files changed, 24 insertions(+), 32 deletions(-)
include/hw/virtio/virtio-net.h +0 -1
index efef64e02f..7e96d193aa 100644
@@ -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;
hw/net/virtio-net.c +24 -31

99 lines not on this page · raw message

Signature · 1 line
2.26.2
#57 lore raw
In reply to Juan Quintela
Quoted 1 line · Juan Quintela

Hi

I tagged this for after the release. To help make sure this is not lost pls ping me after the release. Thanks!

Quoted 65 lines

This is a big rework of the network failover setup. General idea is:
* We don't cache the name of the primary/standby devices
We have several problems there with stale pointers
* After this:
- We can always remove either the primary/standby devices without trouble
- Pluggin/unplugging works
- We go to device opts to see what the failover device are. Notice that we are plugging/unplugging the device, so it is not critical.
- Once there, I "fixed" managedsave for libvirt (now gives an error instead o= f just hanging)
* Fields not cached anymore:
- primary_device_dict
- primary_device_opts
- standby_id
- primary_device_id
- primary_dev
* I renamed the should_be_hidden() callback to hide device, but if people preffer the old name I can leave it.
* Add (some) doc to some functions
* Remove almost 100 lines of code while fixing things.

Please review.

Later, Juan.

Juan Quintela (27):
migration: Network Failover can't work with a paused guest
failover: fix indentantion
failover: Use always atomics for primary_should_be_hidden
failover: primary bus is only used once, and where it is set
failover: Remove unused parameter
failover: Remove external partially_hotplugged property
failover: qdev_device_add() returns err or dev set
failover: Rename bool to failover_primary_hidden
failover: g_strcmp0() knows how to handle NULL
failover: Remove primary_device_opts
failover: remove standby_id variable
failover: Remove primary_device_dict
failover: Remove memory leak
failover: simplify virtio_net_find_primary()
failover: should_be_hidden() should take a bool
failover: Rename function to hide_device()
failover: virtio_net_connect_failover_devices() does nothing
failover: Rename to failover_find_primary_device()
failover: simplify qdev_device_add() failover case
failover: simplify qdev_device_add()
failover: make sure that id always exist
failover: remove failover_find_primary_device() error parameter
failover: split failover_find_primary_device_id()
failover: We don't need to cache primary_device_id anymore
failover: Caller of this two functions already have primary_dev
failover: simplify failover_unplug_primary
failover: Remove primary_dev member

 include/hw/qdev-core.h         |  28 ++--
 include/hw/virtio/virtio-net.h |   9 +-
 hw/core/qdev.c                 |  19 +--
 hw/net/virtio-net.c            | 298 +++++++++++++--------------------
 migration/migration.c          |  13 ++
 softmmu/qdev-monitor.c         |  43 ++---
 6 files changed, 167 insertions(+), 243 deletions(-)

--=20
2.26.2