From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:49165) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RLIgC-0000wj-I4 for qemu-devel@nongnu.org; Tue, 01 Nov 2011 14:03:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RLIgB-00025a-F2 for qemu-devel@nongnu.org; Tue, 01 Nov 2011 14:03:20 -0400 Received: from mail-qy0-f180.google.com ([209.85.216.180]:52855) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RLIgB-00025Q-5j for qemu-devel@nongnu.org; Tue, 01 Nov 2011 14:03:19 -0400 Received: by qyl38 with SMTP id 38so1027217qyl.4 for ; Tue, 01 Nov 2011 11:03:18 -0700 (PDT) Message-ID: <4EB03462.6040502@codemonkey.ws> Date: Tue, 01 Nov 2011 13:03:14 -0500 From: Anthony Liguori MIME-Version: 1.0 References: <1319699524-32758-1-git-send-email-kraxel@redhat.com> In-Reply-To: <1319699524-32758-1-git-send-email-kraxel@redhat.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH v2] migration: flush migration data to disk. List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Gerd Hoffmann Cc: Jiri Denemark , qemu-devel@nongnu.org, Juan Quintela On 10/27/2011 02:12 AM, Gerd Hoffmann wrote: > 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 Applied. Thanks. Regards, Anthony Liguori > --- > migration-fd.c | 23 ++++++++++++++++++++++- > 1 files changed, 22 insertions(+), 1 deletions(-) > > diff --git a/migration-fd.c b/migration-fd.c > index d0aec89..6211124 100644 > --- a/migration-fd.c > +++ b/migration-fd.c > @@ -42,10 +42,31 @@ static int fd_write(MigrationState *s, const void * buf, size_t size) > > static int fd_close(MigrationState *s) > { > + struct stat st; > + int ret; > + > DPRINTF("fd_close\n"); > if (s->fd != -1) { > - close(s->fd); > + ret = fstat(s->fd,&st); > + if (ret == 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 = fsync(s->fd); > + if (ret != 0) { > + ret = -errno; > + perror("migration-fd: fsync"); > + return ret; > + } > + } > + ret = close(s->fd); > s->fd = -1; > + if (ret != 0) { > + ret = -errno; > + perror("migration-fd: close"); > + return ret; > + } > } > return 0; > }