[Qemu-devel] [RFC v2 28/33] migration: return incoming task tag for sockets

Peter Xu posted 33 patches 8 years, 5 months ago
There is a newer version of this series
[Qemu-devel] [RFC v2 28/33] migration: return incoming task tag for sockets
Posted by Peter Xu 8 years, 5 months ago
For socket based incoming migration, we attached a background task onto
main loop to handle the acception of connections. We never had a way to
destroy it before, only if we finished the migration.

Let's allow socket_start_incoming_migration() to return the source tag
of the listening async work, so that we may be able to clean it up in
the future.

Signed-off-by: Peter Xu <peterx@redhat.com>
---
 migration/socket.c | 36 ++++++++++++++++++++++++------------
 migration/socket.h |  4 ++--
 2 files changed, 26 insertions(+), 14 deletions(-)

diff --git a/migration/socket.c b/migration/socket.c
index 9fc6cb3..6ee51ef 100644
--- a/migration/socket.c
+++ b/migration/socket.c
@@ -158,8 +158,12 @@ out:
 }
 
 
-static void socket_start_incoming_migration(SocketAddress *saddr,
-                                            Error **errp)
+/*
+ * Returns the tag ID of the watch that is attached to global main
+ * loop (>0), or zero if failure detected.
+ */
+static guint socket_start_incoming_migration(SocketAddress *saddr,
+                                             Error **errp)
 {
     QIOChannelSocket *listen_ioc = qio_channel_socket_new();
 
@@ -168,30 +172,38 @@ static void socket_start_incoming_migration(SocketAddress *saddr,
 
     if (qio_channel_socket_listen_sync(listen_ioc, saddr, errp) < 0) {
         object_unref(OBJECT(listen_ioc));
-        return;
+        return 0;
     }
 
-    qio_channel_add_watch(QIO_CHANNEL(listen_ioc),
-                          G_IO_IN,
-                          socket_accept_incoming_migration,
-                          listen_ioc,
-                          (GDestroyNotify)object_unref);
+    return qio_channel_add_watch(QIO_CHANNEL(listen_ioc),
+                                 G_IO_IN,
+                                 socket_accept_incoming_migration,
+                                 listen_ioc,
+                                 (GDestroyNotify)object_unref);
 }
 
-void tcp_start_incoming_migration(const char *host_port, Error **errp)
+guint tcp_start_incoming_migration(const char *host_port, Error **errp)
 {
     Error *err = NULL;
     SocketAddress *saddr = tcp_build_address(host_port, &err);
+    guint tag;
+
     if (!err) {
-        socket_start_incoming_migration(saddr, &err);
+        tag = socket_start_incoming_migration(saddr, &err);
     }
     error_propagate(errp, err);
     qapi_free_SocketAddress(saddr);
+
+    return tag;
 }
 
-void unix_start_incoming_migration(const char *path, Error **errp)
+guint unix_start_incoming_migration(const char *path, Error **errp)
 {
     SocketAddress *saddr = unix_build_address(path);
-    socket_start_incoming_migration(saddr, errp);
+    guint tag;
+
+    tag = socket_start_incoming_migration(saddr, errp);
     qapi_free_SocketAddress(saddr);
+
+    return tag;
 }
diff --git a/migration/socket.h b/migration/socket.h
index 6b91e9d..bc8a59a 100644
--- a/migration/socket.h
+++ b/migration/socket.h
@@ -16,12 +16,12 @@
 
 #ifndef QEMU_MIGRATION_SOCKET_H
 #define QEMU_MIGRATION_SOCKET_H
-void tcp_start_incoming_migration(const char *host_port, Error **errp);
+guint tcp_start_incoming_migration(const char *host_port, Error **errp);
 
 void tcp_start_outgoing_migration(MigrationState *s, const char *host_port,
                                   Error **errp);
 
-void unix_start_incoming_migration(const char *path, Error **errp);
+guint unix_start_incoming_migration(const char *path, Error **errp);
 
 void unix_start_outgoing_migration(MigrationState *s, const char *path,
                                    Error **errp);
-- 
2.7.4


Re: [Qemu-devel] [RFC v2 28/33] migration: return incoming task tag for sockets
Posted by Dr. David Alan Gilbert 8 years, 4 months ago
* Peter Xu (peterx@redhat.com) wrote:
> For socket based incoming migration, we attached a background task onto
> main loop to handle the acception of connections. We never had a way to
> destroy it before, only if we finished the migration.
> 
> Let's allow socket_start_incoming_migration() to return the source tag
> of the listening async work, so that we may be able to clean it up in
> the future.
> 
> Signed-off-by: Peter Xu <peterx@redhat.com>
> ---
>  migration/socket.c | 36 ++++++++++++++++++++++++------------
>  migration/socket.h |  4 ++--
>  2 files changed, 26 insertions(+), 14 deletions(-)
> 
> diff --git a/migration/socket.c b/migration/socket.c
> index 9fc6cb3..6ee51ef 100644
> --- a/migration/socket.c
> +++ b/migration/socket.c
> @@ -158,8 +158,12 @@ out:
>  }
>  
>  
> -static void socket_start_incoming_migration(SocketAddress *saddr,
> -                                            Error **errp)
> +/*
> + * Returns the tag ID of the watch that is attached to global main
> + * loop (>0), or zero if failure detected.
> + */
> +static guint socket_start_incoming_migration(SocketAddress *saddr,
> +                                             Error **errp)
>  {
>      QIOChannelSocket *listen_ioc = qio_channel_socket_new();
>  
> @@ -168,30 +172,38 @@ static void socket_start_incoming_migration(SocketAddress *saddr,
>  
>      if (qio_channel_socket_listen_sync(listen_ioc, saddr, errp) < 0) {
>          object_unref(OBJECT(listen_ioc));
> -        return;
> +        return 0;
>      }
>  
> -    qio_channel_add_watch(QIO_CHANNEL(listen_ioc),
> -                          G_IO_IN,
> -                          socket_accept_incoming_migration,
> -                          listen_ioc,
> -                          (GDestroyNotify)object_unref);
> +    return qio_channel_add_watch(QIO_CHANNEL(listen_ioc),
> +                                 G_IO_IN,
> +                                 socket_accept_incoming_migration,
> +                                 listen_ioc,
> +                                 (GDestroyNotify)object_unref);
>  }
>  
> -void tcp_start_incoming_migration(const char *host_port, Error **errp)
> +guint tcp_start_incoming_migration(const char *host_port, Error **errp)
>  {
>      Error *err = NULL;
>      SocketAddress *saddr = tcp_build_address(host_port, &err);
> +    guint tag;
> +
>      if (!err) {
> -        socket_start_incoming_migration(saddr, &err);
> +        tag = socket_start_incoming_migration(saddr, &err);
>      }

I'd be tempted to initialise that tag = 0   for the case where
there's an error; but OK.

Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com>

>      error_propagate(errp, err);
>      qapi_free_SocketAddress(saddr);
> +
> +    return tag;
>  }
>  
> -void unix_start_incoming_migration(const char *path, Error **errp)
> +guint unix_start_incoming_migration(const char *path, Error **errp)
>  {
>      SocketAddress *saddr = unix_build_address(path);
> -    socket_start_incoming_migration(saddr, errp);
> +    guint tag;
> +
> +    tag = socket_start_incoming_migration(saddr, errp);
>      qapi_free_SocketAddress(saddr);
> +
> +    return tag;
>  }
> diff --git a/migration/socket.h b/migration/socket.h
> index 6b91e9d..bc8a59a 100644
> --- a/migration/socket.h
> +++ b/migration/socket.h
> @@ -16,12 +16,12 @@
>  
>  #ifndef QEMU_MIGRATION_SOCKET_H
>  #define QEMU_MIGRATION_SOCKET_H
> -void tcp_start_incoming_migration(const char *host_port, Error **errp);
> +guint tcp_start_incoming_migration(const char *host_port, Error **errp);
>  
>  void tcp_start_outgoing_migration(MigrationState *s, const char *host_port,
>                                    Error **errp);
>  
> -void unix_start_incoming_migration(const char *path, Error **errp);
> +guint unix_start_incoming_migration(const char *path, Error **errp);
>  
>  void unix_start_outgoing_migration(MigrationState *s, const char *path,
>                                     Error **errp);
> -- 
> 2.7.4
> 
> 
--
Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK

Re: [Qemu-devel] [RFC v2 28/33] migration: return incoming task tag for sockets
Posted by Peter Xu 8 years, 4 months ago
On Fri, Sep 22, 2017 at 09:11:50PM +0100, Dr. David Alan Gilbert wrote:

[...]

> > -void tcp_start_incoming_migration(const char *host_port, Error **errp)
> > +guint tcp_start_incoming_migration(const char *host_port, Error **errp)
> >  {
> >      Error *err = NULL;
> >      SocketAddress *saddr = tcp_build_address(host_port, &err);
> > +    guint tag;
> > +
> >      if (!err) {
> > -        socket_start_incoming_migration(saddr, &err);
> > +        tag = socket_start_incoming_migration(saddr, &err);
> >      }
> 
> I'd be tempted to initialise that tag = 0   for the case where
> there's an error; but OK.

Yeh, I think it worths a touch-up.

> 
> Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com>

Will take the r-b after fixing above.  Thanks!

-- 
Peter Xu