diff mbox series

[RFC,02/27] vhost: Add device callback in vhost_migration_log

Message ID 20201120185105.279030-3-eperezma@redhat.com (mailing list archive)
State New, archived
Headers show
Series vDPA software assisted live migration | expand

Commit Message

Eugenio Perez Martin Nov. 20, 2020, 6:50 p.m. UTC
This allows code to reuse the logic to not to re-enable or re-disable
migration mechanisms. Code works the same way as before.

Signed-off-by: Eugenio Pérez <eperezma@redhat.com>
---
 hw/virtio/vhost.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

Comments

Stefan Hajnoczi Dec. 7, 2020, 4:19 p.m. UTC | #1
On Fri, Nov 20, 2020 at 07:50:40PM +0100, Eugenio Pérez wrote:
> This allows code to reuse the logic to not to re-enable or re-disable
> migration mechanisms. Code works the same way as before.
> 
> Signed-off-by: Eugenio Pérez <eperezma@redhat.com>
> ---
>  hw/virtio/vhost.c | 12 +++++++-----
>  1 file changed, 7 insertions(+), 5 deletions(-)
> 
> diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c
> index 2bd8cdf893..2adb2718c1 100644
> --- a/hw/virtio/vhost.c
> +++ b/hw/virtio/vhost.c
> @@ -862,7 +862,9 @@ err_features:
>      return r;
>  }
>  
> -static int vhost_migration_log(MemoryListener *listener, bool enable)
> +static int vhost_migration_log(MemoryListener *listener,
> +                               bool enable,
> +                               int (*device_cb)(struct vhost_dev *, bool))

Please document the argument. What is the callback function supposed to
do ("device_cb" is not descriptive so I'm not sure)?
Eugenio Perez Martin Dec. 9, 2020, 12:20 p.m. UTC | #2
On Mon, Dec 7, 2020 at 5:19 PM Stefan Hajnoczi <stefanha@gmail.com> wrote:
>
> On Fri, Nov 20, 2020 at 07:50:40PM +0100, Eugenio Pérez wrote:
> > This allows code to reuse the logic to not to re-enable or re-disable
> > migration mechanisms. Code works the same way as before.
> >
> > Signed-off-by: Eugenio Pérez <eperezma@redhat.com>
> > ---
> >  hw/virtio/vhost.c | 12 +++++++-----
> >  1 file changed, 7 insertions(+), 5 deletions(-)
> >
> > diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c
> > index 2bd8cdf893..2adb2718c1 100644
> > --- a/hw/virtio/vhost.c
> > +++ b/hw/virtio/vhost.c
> > @@ -862,7 +862,9 @@ err_features:
> >      return r;
> >  }
> >
> > -static int vhost_migration_log(MemoryListener *listener, bool enable)
> > +static int vhost_migration_log(MemoryListener *listener,
> > +                               bool enable,
> > +                               int (*device_cb)(struct vhost_dev *, bool))
>
> Please document the argument. What is the callback function supposed to
> do ("device_cb" is not descriptive so I'm not sure)?

Sure, I will expand documentation if we stick with this approach to
enable/disable the shadow virtqueue (I hope we agree on a better one
anyway).

Just for completion, it was meant for vhost_dev_set_log, so vhost_dev*
is the device to enable/disable migration, and the second bool is for
enable/disable it.

Thanks!
diff mbox series

Patch

diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c
index 2bd8cdf893..2adb2718c1 100644
--- a/hw/virtio/vhost.c
+++ b/hw/virtio/vhost.c
@@ -862,7 +862,9 @@  err_features:
     return r;
 }
 
-static int vhost_migration_log(MemoryListener *listener, bool enable)
+static int vhost_migration_log(MemoryListener *listener,
+                               bool enable,
+                               int (*device_cb)(struct vhost_dev *, bool))
 {
     struct vhost_dev *dev = container_of(listener, struct vhost_dev,
                                          memory_listener);
@@ -877,14 +879,14 @@  static int vhost_migration_log(MemoryListener *listener, bool enable)
 
     r = 0;
     if (!enable) {
-        r = vhost_dev_set_log(dev, false);
+        r = device_cb(dev, false);
         if (r < 0) {
             goto check_dev_state;
         }
         vhost_log_put(dev, false);
     } else {
         vhost_dev_log_resize(dev, vhost_get_log_size(dev));
-        r = vhost_dev_set_log(dev, true);
+        r = device_cb(dev, true);
         if (r < 0) {
             goto check_dev_state;
         }
@@ -916,7 +918,7 @@  static void vhost_log_global_start(MemoryListener *listener)
 {
     int r;
 
-    r = vhost_migration_log(listener, true);
+    r = vhost_migration_log(listener, true, vhost_dev_set_log);
     if (r < 0) {
         abort();
     }
@@ -926,7 +928,7 @@  static void vhost_log_global_stop(MemoryListener *listener)
 {
     int r;
 
-    r = vhost_migration_log(listener, false);
+    r = vhost_migration_log(listener, false, vhost_dev_set_log);
     if (r < 0) {
         abort();
     }