|
|
cd9d16 |
From 06400ebc136bf44f1fa423159fae9cc9a4f6839d Mon Sep 17 00:00:00 2001
|
|
|
cd9d16 |
From: Gerd Hoffmann <kraxel@redhat.com>
|
|
|
cd9d16 |
Date: Thu, 27 Oct 2011 09:12:04 +0200
|
|
|
cd9d16 |
Subject: [PATCH] migration: flush migration data to disk.
|
|
|
cd9d16 |
MIME-Version: 1.0
|
|
|
cd9d16 |
Content-Type: text/plain; charset=UTF-8
|
|
|
cd9d16 |
Content-Transfer-Encoding: 8bit
|
|
|
cd9d16 |
|
|
|
cd9d16 |
This patch increases robustness when migrating to a file with
|
|
|
cd9d16 |
two little changes:
|
|
|
cd9d16 |
|
|
|
cd9d16 |
(1) Before closing the migration file handle checks if it happens to be
|
|
|
cd9d16 |
a regular file and if so it issues a fsync. This way the data is
|
|
|
cd9d16 |
flushed to disk before qemu sends the migration completed event.
|
|
|
cd9d16 |
(2) It adds error checking. In case either fsync or close syscall
|
|
|
cd9d16 |
fails pass up the error (and fail migration).
|
|
|
cd9d16 |
|
|
|
cd9d16 |
[ v2: return -errno instead of -1 ]
|
|
|
cd9d16 |
|
|
|
cd9d16 |
Cc: Juan Quintela <quintela@redhat.com>
|
|
|
cd9d16 |
Cc: Jiri Denemark <jdenemar@redhat.com>
|
|
|
cd9d16 |
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
|
|
|
cd9d16 |
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
|
|
|
cd9d16 |
(cherry picked from commit aab2293687ee54a409f3fb53a1ab3595b595e0fb)
|
|
|
cd9d16 |
|
|
|
cd9d16 |
Signed-off-by: Bruce Rogers <brogers@suse.com>
|
|
|
cd9d16 |
Signed-off-by: Andreas Färber <afaerber@suse.de>
|
|
|
cd9d16 |
---
|
|
|
cd9d16 |
migration-fd.c | 23 ++++++++++++++++++++++-
|
|
|
cd9d16 |
1 file changed, 22 insertions(+), 1 deletion(-)
|
|
|
cd9d16 |
|
|
|
cd9d16 |
diff --git a/migration-fd.c b/migration-fd.c
|
|
|
cd9d16 |
index 66d51c1..f986bdf 100644
|
|
|
cd9d16 |
--- a/migration-fd.c
|
|
|
cd9d16 |
+++ b/migration-fd.c
|
|
|
cd9d16 |
@@ -42,10 +42,31 @@ static int fd_write(FdMigrationState *s, const void * buf, size_t size)
|
|
|
cd9d16 |
|
|
|
cd9d16 |
static int fd_close(FdMigrationState *s)
|
|
|
cd9d16 |
{
|
|
|
cd9d16 |
+ struct stat st;
|
|
|
cd9d16 |
+ int ret;
|
|
|
cd9d16 |
+
|
|
|
cd9d16 |
DPRINTF("fd_close\n");
|
|
|
cd9d16 |
if (s->fd != -1) {
|
|
|
cd9d16 |
- close(s->fd);
|
|
|
cd9d16 |
+ ret = fstat(s->fd, &st);
|
|
|
cd9d16 |
+ if (ret == 0 && S_ISREG(st.st_mode)) {
|
|
|
cd9d16 |
+ /*
|
|
|
cd9d16 |
+ * If the file handle is a regular file make sure the
|
|
|
cd9d16 |
+ * data is flushed to disk before signaling success.
|
|
|
cd9d16 |
+ */
|
|
|
cd9d16 |
+ ret = fsync(s->fd);
|
|
|
cd9d16 |
+ if (ret != 0) {
|
|
|
cd9d16 |
+ ret = -errno;
|
|
|
cd9d16 |
+ perror("migration-fd: fsync");
|
|
|
cd9d16 |
+ return ret;
|
|
|
cd9d16 |
+ }
|
|
|
cd9d16 |
+ }
|
|
|
cd9d16 |
+ ret = close(s->fd);
|
|
|
cd9d16 |
s->fd = -1;
|
|
|
cd9d16 |
+ if (ret != 0) {
|
|
|
cd9d16 |
+ ret = -errno;
|
|
|
cd9d16 |
+ perror("migration-fd: close");
|
|
|
cd9d16 |
+ return ret;
|
|
|
cd9d16 |
+ }
|
|
|
cd9d16 |
}
|
|
|
cd9d16 |
return 0;
|
|
|
cd9d16 |
}
|
|
|
cd9d16 |
--
|
|
|
cd9d16 |
1.7.11.2
|
|
|
cd9d16 |
|