From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:56173) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T4Wc4-0005xK-Ct for qemu-devel@nongnu.org; Thu, 23 Aug 2012 08:34:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1T4Wby-0000fc-2l for qemu-devel@nongnu.org; Thu, 23 Aug 2012 08:34:16 -0400 Received: from mx1.redhat.com ([209.132.183.28]:15698) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T4Wbx-0000fY-Qx for qemu-devel@nongnu.org; Thu, 23 Aug 2012 08:34:10 -0400 Date: Thu, 23 Aug 2012 13:34:01 +0100 From: "Daniel P. Berrange" Message-ID: <20120823123401.GD10833@redhat.com> References: <1345724888-30204-1-git-send-email-benoit@irqsave.net> <1345724888-30204-2-git-send-email-benoit@irqsave.net> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <1345724888-30204-2-git-send-email-benoit@irqsave.net> Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH 1/2] migration: Allow the migrate command to work on file: urls Reply-To: "Daniel P. Berrange" List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: =?utf-8?Q?Beno=C3=AEt?= Canet Cc: aliguori@us.ibm.com, qemu-devel@nongnu.org, =?utf-8?Q?Beno=C3=AEt?= Canet On Thu, Aug 23, 2012 at 02:28:07PM +0200, Beno=C3=AEt Canet wrote: > Usage: > (qemu) migrate file:/path/to/vm_statefile >=20 > Signed-off-by: Benoit Canet > --- > migration-fd.c | 4 ++-- > migration.c | 20 +++++++++++++++++++- > migration.h | 2 +- > 3 files changed, 22 insertions(+), 4 deletions(-) >=20 > diff --git a/migration-fd.c b/migration-fd.c > index 50138ed..d39e44a 100644 > --- a/migration-fd.c > +++ b/migration-fd.c > @@ -73,9 +73,9 @@ static int fd_close(MigrationState *s) > return 0; > } > =20 > -int fd_start_outgoing_migration(MigrationState *s, const char *fdname) > +int fd_start_outgoing_migration(MigrationState *s, const char *fdname,= int fd) > { > - s->fd =3D monitor_get_fd(cur_mon, fdname); > + s->fd =3D fd ? fd : monitor_get_fd(cur_mon, fdname); > if (s->fd =3D=3D -1) { > DPRINTF("fd_migration: invalid file descriptor identifier\n"); > goto err_after_get_fd; > diff --git a/migration.c b/migration.c > index 1edeec5..679847d 100644 > --- a/migration.c > +++ b/migration.c > @@ -239,9 +239,14 @@ void qmp_migrate_set_capabilities(MigrationCapabil= ityStatusList *params, > static int migrate_fd_cleanup(MigrationState *s) > { > int ret =3D 0; > + struct stat st; > =20 > qemu_set_fd_handler2(s->fd, NULL, NULL, NULL, NULL); > =20 > + if (!fstat(s->fd, &st) && S_ISREG(st.st_mode)) { > + fsync(s->fd); > + } > + > if (s->file) { > DPRINTF("closing file\n"); > ret =3D qemu_fclose(s->file); > @@ -475,6 +480,17 @@ void migrate_del_blocker(Error *reason) > migration_blockers =3D g_slist_remove(migration_blockers, reason); > } > =20 > +static int file_start_outgoing_migration(MigrationState *s, > + const char *filename) > +{ > + int fd; > + fd =3D open(filename, O_CREAT|O_TRUNC|O_WRONLY, S_IRUSR|S_IWUSR); > + if (fd < 0) { > + return -errno; > + } > + return fd_start_outgoing_migration(s, NULL, fd); 'fd_start_outgoing_migration' requires that the FD you give it supports non-blocking I/O. File descriptors opened from plain files or block devices do not honour that requirement. So this proposed code will cause the entire QEMU process to block while migration is taking place. This is why no on has ever implemented the 'file:' protocol in QEMU before. To deal with this issue you'd either have to use the POSIX async I/O APIs (or QEMU's internal equivalent), or spawn a separate 'dd' helper process and give QEMU a pipe FD instead. The latter is what libvirt does to implement migrate to file. Daniel --=20 |: http://berrange.com -o- http://www.flickr.com/photos/dberrange= / :| |: http://libvirt.org -o- http://virt-manager.or= g :| |: http://autobuild.org -o- http://search.cpan.org/~danberr= / :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vn= c :|