Received: from eggs.gnu.org ([208.118.235.92]:39993) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SCsMy-0005Pc-N2 for qemu-devel@nongnu.org; Wed, 28 Mar 2012 08:53:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SCsMq-0007pF-Du for qemu-devel@nongnu.org; Wed, 28 Mar 2012 08:52:56 -0400 From: =?UTF-8?q?Andreas=20F=C3=A4rber?= Date: Wed, 28 Mar 2012 14:52:15 +0200 Message-Id: <1332939159-16434-13-git-send-email-afaerber@suse.de> In-Reply-To: <1332939159-16434-1-git-send-email-afaerber@suse.de> References: <1332939159-16434-1-git-send-email-afaerber@suse.de> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PATCH stable-0.15 12/36] migration: flush migration data to disk. List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Anthony Liguori , Juan Quintela , kvm@suse.de, qemu-stable@nongnu.org, Bruce Rogers , Gerd Hoffmann , Jiri Denemark , =?UTF-8?q?Andreas=20F=C3=A4rber?= From: Gerd Hoffmann This patch increases robustness when migrating to a file with two little changes: (1) Before closing the migration file handle checks if it happens to be a regular file and if so it issues a fsync. This way the data is flushed to disk before qemu sends the migration completed event. (2) It adds error checking. In case either fsync or close syscall fails pass up the error (and fail migration). [ v2: return -errno instead of -1 ] Cc: Juan Quintela Cc: Jiri Denemark Signed-off-by: Gerd Hoffmann Signed-off-by: Anthony Liguori (cherry picked from commit aab2293687ee54a409f3fb53a1ab3595b595e0fb) Signed-off-by: Bruce Rogers Signed-off-by: Andreas F=C3=A4rber --- migration-fd.c | 23 ++++++++++++++++++++++- 1 files changed, 22 insertions(+), 1 deletions(-) diff --git a/migration-fd.c b/migration-fd.c index 66d51c1..f986bdf 100644 --- a/migration-fd.c +++ b/migration-fd.c @@ -42,10 +42,31 @@ static int fd_write(FdMigrationState *s, const void *= buf, size_t size) =20 static int fd_close(FdMigrationState *s) { + struct stat st; + int ret; + DPRINTF("fd_close\n"); if (s->fd !=3D -1) { - close(s->fd); + ret =3D fstat(s->fd, &st); + if (ret =3D=3D 0 && S_ISREG(st.st_mode)) { + /* + * If the file handle is a regular file make sure the + * data is flushed to disk before signaling success. + */ + ret =3D fsync(s->fd); + if (ret !=3D 0) { + ret =3D -errno; + perror("migration-fd: fsync"); + return ret; + } + } + ret =3D close(s->fd); s->fd =3D -1; + if (ret !=3D 0) { + ret =3D -errno; + perror("migration-fd: close"); + return ret; + } } return 0; } --=20 1.7.7