thebeanogamer / rpms / qemu-kvm

Forked from rpms/qemu-kvm 5 months ago
Clone
9ae3a8
From 2f66e62873ef54bd27ec6e063c8b4f3f11e2413d Mon Sep 17 00:00:00 2001
9ae3a8
From: Dr. David Alan Gilbert (git) <dgilbert@redhat.com>
9ae3a8
Date: Mon, 10 Mar 2014 17:41:43 +0100
9ae3a8
Subject: [PATCH 15/16] qemu_file: use fwrite() correctly
9ae3a8
9ae3a8
RH-Author: Dr. David Alan Gilbert (git) <dgilbert@redhat.com>
9ae3a8
Message-id: <1394473304-7190-2-git-send-email-dgilbert@redhat.com>
9ae3a8
Patchwork-id: 58073
9ae3a8
O-Subject: [RHEL-7.0 qemu-kvm PATCH v2 1/2] qemu_file: use fwrite() correctly
9ae3a8
Bugzilla: 1005103
9ae3a8
RH-Acked-by: Juan Quintela <quintela@redhat.com>
9ae3a8
RH-Acked-by: Eric Blake <eblake@redhat.com>
9ae3a8
RH-Acked-by: Amit Shah <amit.shah@redhat.com>
9ae3a8
9ae3a8
From: Juan Quintela <quintela@redhat.com>
9ae3a8
9ae3a8
fwrite() returns the number of items written.  But when there is one
9ae3a8
error, it can return a short write.
9ae3a8
9ae3a8
In the particular bug that I was tracking, I did a migration to a
9ae3a8
read-only filesystem.  And it was able to finish the migration
9ae3a8
correctly.  fwrite() never returned a negative error code, nor zero,
9ae3a8
always 4096. (migration writes chunks of about 14000 bytes).  And it
9ae3a8
was able to "complete" the migration with success (yes, reading the
9ae3a8
file was a bit more difficult).
9ae3a8
9ae3a8
To add insult to injury, if your amount of memory was big enough (12GB
9ae3a8
on my case), it overwrote some important structure, and from them,
9ae3a8
malloc failed.  This check makes the problem go away.
9ae3a8
9ae3a8
Signed-off-by: Juan Quintela <quintela@redhat.com>
9ae3a8
Reviewed-by: Eric Blake <eblake@redhat.com>
9ae3a8
Reviewed-by: Markus Armbruster <armbru@redhat.com>
9ae3a8
Signed-off-by: Juan Quintela <quintela@redhat.com>
9ae3a8
(cherry picked from commit aded6539d983280212e08d09f14157b1cb4d58cc)
9ae3a8
9ae3a8
Conflicts:
9ae3a8
	qemu-file.c
9ae3a8
9ae3a8
Code still in savevm.c
9ae3a8
---
9ae3a8
 savevm.c | 9 ++++++++-
9ae3a8
 1 file changed, 8 insertions(+), 1 deletion(-)
9ae3a8
9ae3a8
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
9ae3a8
---
9ae3a8
 savevm.c |    9 ++++++++-
9ae3a8
 1 files changed, 8 insertions(+), 1 deletions(-)
9ae3a8
9ae3a8
diff --git a/savevm.c b/savevm.c
9ae3a8
index bd37959..94121a2 100644
9ae3a8
--- a/savevm.c
9ae3a8
+++ b/savevm.c
9ae3a8
@@ -211,7 +211,14 @@ static int stdio_get_fd(void *opaque)
9ae3a8
 static int stdio_put_buffer(void *opaque, const uint8_t *buf, int64_t pos, int size)
9ae3a8
 {
9ae3a8
     QEMUFileStdio *s = opaque;
9ae3a8
-    return fwrite(buf, 1, size, s->stdio_file);
9ae3a8
+    int res;
9ae3a8
+
9ae3a8
+    res = fwrite(buf, 1, size, s->stdio_file);
9ae3a8
+
9ae3a8
+    if (res != size) {
9ae3a8
+        return -EIO;	/* fake errno value */
9ae3a8
+    }
9ae3a8
+    return res;
9ae3a8
 }
9ae3a8
 
9ae3a8
 static int stdio_get_buffer(void *opaque, uint8_t *buf, int64_t pos, int size)
9ae3a8
-- 
9ae3a8
1.7.1
9ae3a8