Message ID | 1469077560-20620-3-git-send-email-zhang.zhanghailiang@huawei.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
* zhanghailiang (zhang.zhanghailiang@huawei.com) wrote: > Usage: > -incoming file:/path/to/vm_statefile > > Besides, use qemu_strtol() instead of strtol(). > > 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 | 37 +++++++++++++++++++++++++++++++------ > migration/migration.c | 2 ++ > migration/trace-events | 1 + > 4 files changed, 36 insertions(+), 6 deletions(-) > > diff --git a/include/migration/migration.h b/include/migration/migration.h > index cc2e4f6..a7f1051 100644 > --- a/include/migration/migration.h > +++ b/include/migration/migration.h > @@ -223,6 +223,8 @@ void fd_start_outgoing_migration(MigrationState *s, const char *fdname, Error ** > > void file_start_outgoing_migration(MigrationState *s, const char *filename, Error **errp); > > +void file_start_incoming_migration(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 fa5df67..472876c 100644 > --- a/migration/fd.c > +++ b/migration/fd.c > @@ -21,7 +21,7 @@ > #include "monitor/monitor.h" > #include "io/channel-util.h" > #include "trace.h" > - > +#include "qemu/cutils.h" > > static void fd_start_outgoing_migration_core(MigrationState *s, int fd, > Error **errp) > @@ -73,13 +73,9 @@ static gboolean fd_accept_incoming_migration(QIOChannel *ioc, > return FALSE; /* unregister */ > } > > -void fd_start_incoming_migration(const char *infd, Error **errp) > +static void fd_start_incoming_migration_core(int fd, Error **errp) > { > QIOChannel *ioc; > - int fd; > - > - fd = strtol(infd, NULL, 0); > - trace_migration_fd_incoming(fd); > > ioc = qio_channel_new_fd(fd, errp); > if (!ioc) { > @@ -93,3 +89,32 @@ void fd_start_incoming_migration(const char *infd, Error **errp) > NULL, > NULL); > } > + > +void fd_start_incoming_migration(const char *infd, Error **errp) > +{ > + long fd; > + int err; > + > + err = qemu_strtol(infd, NULL, 0, &fd); > + if (err < 0) { > + error_setg_errno(errp, -err, "Failed to convert string '%s'" > + " to number", infd); > + return; > + } > + > + trace_migration_fd_incoming((int)fd); > + fd_start_incoming_migration_core((int)fd, errp); > +} > + > +void file_start_incoming_migration(const char *filename, Error **errp) > +{ > + int fd; > + > + fd = qemu_open(filename, O_RDONLY); > + if (fd < 0) { > + error_setg_errno(errp, errno, "Failed to open file:%s", filename); > + return; > + } > + trace_migration_file_incoming(filename); > + fd_start_incoming_migration_core(fd, errp); > +} > diff --git a/migration/migration.c b/migration/migration.c > index 097adba..5ed3fea 100644 > --- a/migration/migration.c > +++ b/migration/migration.c > @@ -315,6 +315,8 @@ void qemu_start_incoming_migration(const char *uri, Error **errp) > unix_start_incoming_migration(p, errp); > } else if (strstart(uri, "fd:", &p)) { > fd_start_incoming_migration(p, errp); > + } else if (strstart(uri, "file:", &p)) { > + file_start_incoming_migration(p, errp); > } else { > error_setg(errp, "unknown migration protocol: %s", uri); > } > diff --git a/migration/trace-events b/migration/trace-events > index 4fca64c..8a76595 100644 > --- a/migration/trace-events > +++ b/migration/trace-events > @@ -195,6 +195,7 @@ migration_exec_incoming(const char *cmd) "cmd=%s" > migration_fd_outgoing(int fd) "fd=%d" > migration_fd_incoming(int fd) "fd=%d" > migration_file_outgoing(const char *filename) "file=%s" > +migration_file_incoming(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
diff --git a/include/migration/migration.h b/include/migration/migration.h index cc2e4f6..a7f1051 100644 --- a/include/migration/migration.h +++ b/include/migration/migration.h @@ -223,6 +223,8 @@ void fd_start_outgoing_migration(MigrationState *s, const char *fdname, Error ** void file_start_outgoing_migration(MigrationState *s, const char *filename, Error **errp); +void file_start_incoming_migration(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 fa5df67..472876c 100644 --- a/migration/fd.c +++ b/migration/fd.c @@ -21,7 +21,7 @@ #include "monitor/monitor.h" #include "io/channel-util.h" #include "trace.h" - +#include "qemu/cutils.h" static void fd_start_outgoing_migration_core(MigrationState *s, int fd, Error **errp) @@ -73,13 +73,9 @@ static gboolean fd_accept_incoming_migration(QIOChannel *ioc, return FALSE; /* unregister */ } -void fd_start_incoming_migration(const char *infd, Error **errp) +static void fd_start_incoming_migration_core(int fd, Error **errp) { QIOChannel *ioc; - int fd; - - fd = strtol(infd, NULL, 0); - trace_migration_fd_incoming(fd); ioc = qio_channel_new_fd(fd, errp); if (!ioc) { @@ -93,3 +89,32 @@ void fd_start_incoming_migration(const char *infd, Error **errp) NULL, NULL); } + +void fd_start_incoming_migration(const char *infd, Error **errp) +{ + long fd; + int err; + + err = qemu_strtol(infd, NULL, 0, &fd); + if (err < 0) { + error_setg_errno(errp, -err, "Failed to convert string '%s'" + " to number", infd); + return; + } + + trace_migration_fd_incoming((int)fd); + fd_start_incoming_migration_core((int)fd, errp); +} + +void file_start_incoming_migration(const char *filename, Error **errp) +{ + int fd; + + fd = qemu_open(filename, O_RDONLY); + if (fd < 0) { + error_setg_errno(errp, errno, "Failed to open file:%s", filename); + return; + } + trace_migration_file_incoming(filename); + fd_start_incoming_migration_core(fd, errp); +} diff --git a/migration/migration.c b/migration/migration.c index 097adba..5ed3fea 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -315,6 +315,8 @@ void qemu_start_incoming_migration(const char *uri, Error **errp) unix_start_incoming_migration(p, errp); } else if (strstart(uri, "fd:", &p)) { fd_start_incoming_migration(p, errp); + } else if (strstart(uri, "file:", &p)) { + file_start_incoming_migration(p, errp); } else { error_setg(errp, "unknown migration protocol: %s", uri); } diff --git a/migration/trace-events b/migration/trace-events index 4fca64c..8a76595 100644 --- a/migration/trace-events +++ b/migration/trace-events @@ -195,6 +195,7 @@ migration_exec_incoming(const char *cmd) "cmd=%s" migration_fd_outgoing(int fd) "fd=%d" migration_fd_incoming(int fd) "fd=%d" migration_file_outgoing(const char *filename) "file=%s" +migration_file_incoming(const char *filename) "file=%s" # migration/socket.c migration_socket_incoming_accepted(void) ""