Message ID | 1452169208-840-3-git-send-email-zhang.zhanghailiang@huawei.com |
---|---|
State | New |
Headers | show |
* 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> > --- > - With this patch, we can easily test memory snapshot > - Rebase on qemu 2.5 > --- > include/migration/migration.h | 6 +++++- > migration/fd.c | 19 +++++++++++++++++-- > migration/migration.c | 4 +++- > 3 files changed, 25 insertions(+), 4 deletions(-) Even if the rest of this series takes some time to finish; it might be best to post this patch separately - it just a nice bit of simplification. Of course now you have to rewrite using qio_channel_file_new_path but I guess it's simple. (I've tended to use migrate "exec:cat > file" but a file: would be nice) Dave > diff --git a/include/migration/migration.h b/include/migration/migration.h > index 4c80939..bf4f8e9 100644 > --- a/include/migration/migration.h > +++ b/include/migration/migration.h > @@ -193,7 +193,11 @@ void unix_start_outgoing_migration(MigrationState *s, const char *path, Error ** > > void fd_start_incoming_migration(const char *path, Error **errp); > > -void fd_start_outgoing_migration(MigrationState *s, const char *fdname, Error **errp); > +void fd_start_outgoing_migration(MigrationState *s, const char *fdname, > + int outfd, 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); > > diff --git a/migration/fd.c b/migration/fd.c > index 3e4bed0..b62161f 100644 > --- a/migration/fd.c > +++ b/migration/fd.c > @@ -42,9 +42,10 @@ static bool fd_is_socket(int fd) > return S_ISSOCK(stat.st_mode); > } > > -void fd_start_outgoing_migration(MigrationState *s, const char *fdname, Error **errp) > +void fd_start_outgoing_migration(MigrationState *s, const char *fdname, > + int outfd, Error **errp) > { > - int fd = monitor_get_fd(cur_mon, fdname, errp); > + int fd = fdname ? monitor_get_fd(cur_mon, fdname, errp) : outfd; > if (fd == -1) { > return; > } > @@ -58,6 +59,20 @@ void fd_start_outgoing_migration(MigrationState *s, const char *fdname, Error ** > migrate_fd_connect(s); > } > > +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; > + } > + fd_start_outgoing_migration(s, NULL, fd, errp); > +} > + > + > static void fd_accept_incoming_migration(void *opaque) > { > QEMUFile *f = opaque; > diff --git a/migration/migration.c b/migration/migration.c > index c842499..3ec3b85 100644 > --- a/migration/migration.c > +++ b/migration/migration.c > @@ -1021,7 +1021,9 @@ void qmp_migrate(const char *uri, bool has_blk, bool blk, > } else if (strstart(uri, "unix:", &p)) { > unix_start_outgoing_migration(s, p, &local_err); > } else if (strstart(uri, "fd:", &p)) { > - fd_start_outgoing_migration(s, p, &local_err); > + fd_start_outgoing_migration(s, p, -1, &local_err); > + } else if (strstart(uri, "file:", &p)) { > + file_start_outgoing_migration(s, p, &local_err); > #endif > } else { > error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "uri", > -- > 1.8.3.1 > > -- Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK
On 2016/7/14 0:12, Dr. David Alan Gilbert wrote: > * 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> >> --- >> - With this patch, we can easily test memory snapshot >> - Rebase on qemu 2.5 >> --- >> include/migration/migration.h | 6 +++++- >> migration/fd.c | 19 +++++++++++++++++-- >> migration/migration.c | 4 +++- >> 3 files changed, 25 insertions(+), 4 deletions(-) > > Even if the rest of this series takes some time to finish; it might be > best to post this patch separately - it just a nice bit of simplification. > Of course now you have to rewrite using qio_channel_file_new_path > but I guess it's simple. > > (I've tended to use migrate "exec:cat > file" but a file: would be nice) > OK, if you need this, i will send it as a single patch. Thanks. > Dave > >> diff --git a/include/migration/migration.h b/include/migration/migration.h >> index 4c80939..bf4f8e9 100644 >> --- a/include/migration/migration.h >> +++ b/include/migration/migration.h >> @@ -193,7 +193,11 @@ void unix_start_outgoing_migration(MigrationState *s, const char *path, Error ** >> >> void fd_start_incoming_migration(const char *path, Error **errp); >> >> -void fd_start_outgoing_migration(MigrationState *s, const char *fdname, Error **errp); >> +void fd_start_outgoing_migration(MigrationState *s, const char *fdname, >> + int outfd, 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); >> >> diff --git a/migration/fd.c b/migration/fd.c >> index 3e4bed0..b62161f 100644 >> --- a/migration/fd.c >> +++ b/migration/fd.c >> @@ -42,9 +42,10 @@ static bool fd_is_socket(int fd) >> return S_ISSOCK(stat.st_mode); >> } >> >> -void fd_start_outgoing_migration(MigrationState *s, const char *fdname, Error **errp) >> +void fd_start_outgoing_migration(MigrationState *s, const char *fdname, >> + int outfd, Error **errp) >> { >> - int fd = monitor_get_fd(cur_mon, fdname, errp); >> + int fd = fdname ? monitor_get_fd(cur_mon, fdname, errp) : outfd; >> if (fd == -1) { >> return; >> } >> @@ -58,6 +59,20 @@ void fd_start_outgoing_migration(MigrationState *s, const char *fdname, Error ** >> migrate_fd_connect(s); >> } >> >> +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; >> + } >> + fd_start_outgoing_migration(s, NULL, fd, errp); >> +} >> + >> + >> static void fd_accept_incoming_migration(void *opaque) >> { >> QEMUFile *f = opaque; >> diff --git a/migration/migration.c b/migration/migration.c >> index c842499..3ec3b85 100644 >> --- a/migration/migration.c >> +++ b/migration/migration.c >> @@ -1021,7 +1021,9 @@ void qmp_migrate(const char *uri, bool has_blk, bool blk, >> } else if (strstart(uri, "unix:", &p)) { >> unix_start_outgoing_migration(s, p, &local_err); >> } else if (strstart(uri, "fd:", &p)) { >> - fd_start_outgoing_migration(s, p, &local_err); >> + fd_start_outgoing_migration(s, p, -1, &local_err); >> + } else if (strstart(uri, "file:", &p)) { >> + file_start_outgoing_migration(s, p, &local_err); >> #endif >> } else { >> error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "uri", >> -- >> 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 4c80939..bf4f8e9 100644 --- a/include/migration/migration.h +++ b/include/migration/migration.h @@ -193,7 +193,11 @@ void unix_start_outgoing_migration(MigrationState *s, const char *path, Error ** void fd_start_incoming_migration(const char *path, Error **errp); -void fd_start_outgoing_migration(MigrationState *s, const char *fdname, Error **errp); +void fd_start_outgoing_migration(MigrationState *s, const char *fdname, + int outfd, 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); diff --git a/migration/fd.c b/migration/fd.c index 3e4bed0..b62161f 100644 --- a/migration/fd.c +++ b/migration/fd.c @@ -42,9 +42,10 @@ static bool fd_is_socket(int fd) return S_ISSOCK(stat.st_mode); } -void fd_start_outgoing_migration(MigrationState *s, const char *fdname, Error **errp) +void fd_start_outgoing_migration(MigrationState *s, const char *fdname, + int outfd, Error **errp) { - int fd = monitor_get_fd(cur_mon, fdname, errp); + int fd = fdname ? monitor_get_fd(cur_mon, fdname, errp) : outfd; if (fd == -1) { return; } @@ -58,6 +59,20 @@ void fd_start_outgoing_migration(MigrationState *s, const char *fdname, Error ** migrate_fd_connect(s); } +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; + } + fd_start_outgoing_migration(s, NULL, fd, errp); +} + + static void fd_accept_incoming_migration(void *opaque) { QEMUFile *f = opaque; diff --git a/migration/migration.c b/migration/migration.c index c842499..3ec3b85 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -1021,7 +1021,9 @@ void qmp_migrate(const char *uri, bool has_blk, bool blk, } else if (strstart(uri, "unix:", &p)) { unix_start_outgoing_migration(s, p, &local_err); } else if (strstart(uri, "fd:", &p)) { - fd_start_outgoing_migration(s, p, &local_err); + fd_start_outgoing_migration(s, p, -1, &local_err); + } else if (strstart(uri, "file:", &p)) { + file_start_outgoing_migration(s, p, &local_err); #endif } else { error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "uri",