diff mbox

[RFC,1/2] migration: Allow the migrate command to work on file:urls

Message ID 1469077560-20620-2-git-send-email-zhang.zhanghailiang@huawei.com (mailing list archive)
State New, archived
Headers show

Commit Message

Zhanghailiang July 21, 2016, 5:05 a.m. UTC
Usage:
(qemu) migrate file:/path/to/vm_statefile

Signed-off-by: zhanghailiang <zhang.zhanghailiang@huawei.com>
Signed-off-by: Benoit Canet <benoit.canet@gmail.com>
---
 include/migration/migration.h |  2 ++
 migration/fd.c                | 34 ++++++++++++++++++++++++++++------
 migration/migration.c         |  2 ++
 migration/trace-events        |  1 +
 4 files changed, 33 insertions(+), 6 deletions(-)

Comments

Dr. David Alan Gilbert July 21, 2016, 12:05 p.m. UTC | #1
* zhanghailiang (zhang.zhanghailiang@huawei.com) wrote:
> Usage:
> (qemu) migrate file:/path/to/vm_statefile
> 
> Signed-off-by: zhanghailiang <zhang.zhanghailiang@huawei.com>
> Signed-off-by: Benoit Canet <benoit.canet@gmail.com>

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

> ---
>  include/migration/migration.h |  2 ++
>  migration/fd.c                | 34 ++++++++++++++++++++++++++++------
>  migration/migration.c         |  2 ++
>  migration/trace-events        |  1 +
>  4 files changed, 33 insertions(+), 6 deletions(-)
> 
> diff --git a/include/migration/migration.h b/include/migration/migration.h
> index 3c96623..cc2e4f6 100644
> --- a/include/migration/migration.h
> +++ b/include/migration/migration.h
> @@ -221,6 +221,8 @@ void fd_start_incoming_migration(const char *path, Error **errp);
>  
>  void fd_start_outgoing_migration(MigrationState *s, const char *fdname, Error **errp);
>  
> +void file_start_outgoing_migration(MigrationState *s, const char *filename, Error **errp);
> +
>  void rdma_start_outgoing_migration(void *opaque, const char *host_port, Error **errp);
>  
>  void rdma_start_incoming_migration(const char *host_port, Error **errp);
> diff --git a/migration/fd.c b/migration/fd.c
> index 84a10fd..fa5df67 100644
> --- a/migration/fd.c
> +++ b/migration/fd.c
> @@ -23,15 +23,11 @@
>  #include "trace.h"
>  
>  
> -void fd_start_outgoing_migration(MigrationState *s, const char *fdname, Error **errp)
> +static void fd_start_outgoing_migration_core(MigrationState *s, int fd,
> +                                             Error **errp)
>  {
>      QIOChannel *ioc;
> -    int fd = monitor_get_fd(cur_mon, fdname, errp);
> -    if (fd == -1) {
> -        return;
> -    }
>  
> -    trace_migration_fd_outgoing(fd);
>      ioc = qio_channel_new_fd(fd, errp);
>      if (!ioc) {
>          close(fd);
> @@ -42,6 +38,32 @@ void fd_start_outgoing_migration(MigrationState *s, const char *fdname, Error **
>      object_unref(OBJECT(ioc));
>  }
>  
> +void fd_start_outgoing_migration(MigrationState *s, const char *fdname, Error **errp)
> +{
> +    int fd = monitor_get_fd(cur_mon, fdname, errp);
> +    if (fd == -1) {
> +        return;
> +    }
> +
> +    trace_migration_fd_outgoing(fd);
> +    fd_start_outgoing_migration_core(s, fd, errp);
> +}
> +
> +void file_start_outgoing_migration(MigrationState *s, const char *filename,
> +                                   Error **errp)
> +{
> +    int fd;
> +
> +    fd = qemu_open(filename, O_CREAT | O_TRUNC | O_WRONLY, S_IRUSR | S_IWUSR);
> +    if (fd < 0) {
> +        error_setg_errno(errp, errno, "Failed to open file: %s", filename);
> +        return;
> +    }
> +    
> +    trace_migration_file_outgoing(filename);
> +    fd_start_outgoing_migration_core(s, fd, errp);
> +}
> +
>  static gboolean fd_accept_incoming_migration(QIOChannel *ioc,
>                                               GIOCondition condition,
>                                               gpointer opaque)
> diff --git a/migration/migration.c b/migration/migration.c
> index c4e0193..097adba 100644
> --- a/migration/migration.c
> +++ b/migration/migration.c
> @@ -1109,6 +1109,8 @@ void qmp_migrate(const char *uri, bool has_blk, bool blk,
>          unix_start_outgoing_migration(s, p, &local_err);
>      } else if (strstart(uri, "fd:", &p)) {
>          fd_start_outgoing_migration(s, p, &local_err);
> +    } else if (strstart(uri, "file:", &p)) {
> +        file_start_outgoing_migration(s, p, &local_err);
>      } else {
>          error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "uri",
>                     "a valid migration protocol");
> diff --git a/migration/trace-events b/migration/trace-events
> index 8568dab..4fca64c 100644
> --- a/migration/trace-events
> +++ b/migration/trace-events
> @@ -194,6 +194,7 @@ migration_exec_incoming(const char *cmd) "cmd=%s"
>  # migration/fd.c
>  migration_fd_outgoing(int fd) "fd=%d"
>  migration_fd_incoming(int fd) "fd=%d"
> +migration_file_outgoing(const char *filename) "file=%s"
>  
>  # migration/socket.c
>  migration_socket_incoming_accepted(void) ""
> -- 
> 1.8.3.1
> 
> 
--
Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK
Daniel P. Berrangé July 21, 2016, 12:13 p.m. UTC | #2
On Thu, Jul 21, 2016 at 01:05:59PM +0800, zhanghailiang wrote:
> Usage:
> (qemu) migrate file:/path/to/vm_statefile
> 
> Signed-off-by: zhanghailiang <zhang.zhanghailiang@huawei.com>
> Signed-off-by: Benoit Canet <benoit.canet@gmail.com>
> ---
>  include/migration/migration.h |  2 ++
>  migration/fd.c                | 34 ++++++++++++++++++++++++++++------
>  migration/migration.c         |  2 ++
>  migration/trace-events        |  1 +
>  4 files changed, 33 insertions(+), 6 deletions(-)
> 
> diff --git a/include/migration/migration.h b/include/migration/migration.h
> index 3c96623..cc2e4f6 100644
> --- a/include/migration/migration.h
> +++ b/include/migration/migration.h
> @@ -221,6 +221,8 @@ void fd_start_incoming_migration(const char *path, Error **errp);
>  
>  void fd_start_outgoing_migration(MigrationState *s, const char *fdname, Error **errp);
>  
> +void file_start_outgoing_migration(MigrationState *s, const char *filename, Error **errp);
> +
>  void rdma_start_outgoing_migration(void *opaque, const char *host_port, Error **errp);
>  
>  void rdma_start_incoming_migration(const char *host_port, Error **errp);
> diff --git a/migration/fd.c b/migration/fd.c
> index 84a10fd..fa5df67 100644
> --- a/migration/fd.c
> +++ b/migration/fd.c
> @@ -23,15 +23,11 @@
>  #include "trace.h"
>  
>  
> -void fd_start_outgoing_migration(MigrationState *s, const char *fdname, Error **errp)
> +static void fd_start_outgoing_migration_core(MigrationState *s, int fd,
> +                                             Error **errp)
>  {
>      QIOChannel *ioc;
> -    int fd = monitor_get_fd(cur_mon, fdname, errp);
> -    if (fd == -1) {
> -        return;
> -    }
>  
> -    trace_migration_fd_outgoing(fd);
>      ioc = qio_channel_new_fd(fd, errp);
>      if (!ioc) {
>          close(fd);
> @@ -42,6 +38,32 @@ void fd_start_outgoing_migration(MigrationState *s, const char *fdname, Error **
>      object_unref(OBJECT(ioc));
>  }
>  
> +void fd_start_outgoing_migration(MigrationState *s, const char *fdname, Error **errp)
> +{
> +    int fd = monitor_get_fd(cur_mon, fdname, errp);
> +    if (fd == -1) {
> +        return;
> +    }
> +
> +    trace_migration_fd_outgoing(fd);
> +    fd_start_outgoing_migration_core(s, fd, errp);
> +}
> +
> +void file_start_outgoing_migration(MigrationState *s, const char *filename,
> +                                   Error **errp)
> +{
> +    int fd;
> +
> +    fd = qemu_open(filename, O_CREAT | O_TRUNC | O_WRONLY, S_IRUSR | S_IWUSR);
> +    if (fd < 0) {
> +        error_setg_errno(errp, errno, "Failed to open file: %s", filename);
> +        return;
> +    }
> +    
> +    trace_migration_file_outgoing(filename);
> +    fd_start_outgoing_migration_core(s, fd, errp);
> +}

This isn't going to fly.

Annoyingly with plain files on POSIX platforms you can't get non-blocking
I/O, so even though we'll be setting the O_NONBLOCK on fd shortly, I/O is
still going to block the entire thread.  The same applies for file reads
wrt to your next patch supporting incoming mode.

Regards,
Daniel
diff mbox

Patch

diff --git a/include/migration/migration.h b/include/migration/migration.h
index 3c96623..cc2e4f6 100644
--- a/include/migration/migration.h
+++ b/include/migration/migration.h
@@ -221,6 +221,8 @@  void fd_start_incoming_migration(const char *path, Error **errp);
 
 void fd_start_outgoing_migration(MigrationState *s, const char *fdname, Error **errp);
 
+void file_start_outgoing_migration(MigrationState *s, const char *filename, Error **errp);
+
 void rdma_start_outgoing_migration(void *opaque, const char *host_port, Error **errp);
 
 void rdma_start_incoming_migration(const char *host_port, Error **errp);
diff --git a/migration/fd.c b/migration/fd.c
index 84a10fd..fa5df67 100644
--- a/migration/fd.c
+++ b/migration/fd.c
@@ -23,15 +23,11 @@ 
 #include "trace.h"
 
 
-void fd_start_outgoing_migration(MigrationState *s, const char *fdname, Error **errp)
+static void fd_start_outgoing_migration_core(MigrationState *s, int fd,
+                                             Error **errp)
 {
     QIOChannel *ioc;
-    int fd = monitor_get_fd(cur_mon, fdname, errp);
-    if (fd == -1) {
-        return;
-    }
 
-    trace_migration_fd_outgoing(fd);
     ioc = qio_channel_new_fd(fd, errp);
     if (!ioc) {
         close(fd);
@@ -42,6 +38,32 @@  void fd_start_outgoing_migration(MigrationState *s, const char *fdname, Error **
     object_unref(OBJECT(ioc));
 }
 
+void fd_start_outgoing_migration(MigrationState *s, const char *fdname, Error **errp)
+{
+    int fd = monitor_get_fd(cur_mon, fdname, errp);
+    if (fd == -1) {
+        return;
+    }
+
+    trace_migration_fd_outgoing(fd);
+    fd_start_outgoing_migration_core(s, fd, errp);
+}
+
+void file_start_outgoing_migration(MigrationState *s, const char *filename,
+                                   Error **errp)
+{
+    int fd;
+
+    fd = qemu_open(filename, O_CREAT | O_TRUNC | O_WRONLY, S_IRUSR | S_IWUSR);
+    if (fd < 0) {
+        error_setg_errno(errp, errno, "Failed to open file: %s", filename);
+        return;
+    }
+    
+    trace_migration_file_outgoing(filename);
+    fd_start_outgoing_migration_core(s, fd, errp);
+}
+
 static gboolean fd_accept_incoming_migration(QIOChannel *ioc,
                                              GIOCondition condition,
                                              gpointer opaque)
diff --git a/migration/migration.c b/migration/migration.c
index c4e0193..097adba 100644
--- a/migration/migration.c
+++ b/migration/migration.c
@@ -1109,6 +1109,8 @@  void qmp_migrate(const char *uri, bool has_blk, bool blk,
         unix_start_outgoing_migration(s, p, &local_err);
     } else if (strstart(uri, "fd:", &p)) {
         fd_start_outgoing_migration(s, p, &local_err);
+    } else if (strstart(uri, "file:", &p)) {
+        file_start_outgoing_migration(s, p, &local_err);
     } else {
         error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "uri",
                    "a valid migration protocol");
diff --git a/migration/trace-events b/migration/trace-events
index 8568dab..4fca64c 100644
--- a/migration/trace-events
+++ b/migration/trace-events
@@ -194,6 +194,7 @@  migration_exec_incoming(const char *cmd) "cmd=%s"
 # migration/fd.c
 migration_fd_outgoing(int fd) "fd=%d"
 migration_fd_incoming(int fd) "fd=%d"
+migration_file_outgoing(const char *filename) "file=%s"
 
 # migration/socket.c
 migration_socket_incoming_accepted(void) ""