From 731de38052b245eab79e417aeac5e1dcebe6437f Mon Sep 17 00:00:00 2001 From: Max Reitz Date: Tue, 18 Nov 2014 11:23:05 +0100 Subject: block/raw-posix: Only sync after successful preallocation The loop which filled the file with zeroes may have been left early due to an error. In that case, the fsync() should be skipped. Signed-off-by: Max Reitz Signed-off-by: Kevin Wolf --- block/raw-posix.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'block') diff --git a/block/raw-posix.c b/block/raw-posix.c index e0e48c5f51..d106fc456b 100644 --- a/block/raw-posix.c +++ b/block/raw-posix.c @@ -1453,7 +1453,9 @@ static int raw_create(const char *filename, QemuOpts *opts, Error **errp) } left -= result; } - fsync(fd); + if (result >= 0) { + fsync(fd); + } g_free(buf); break; } -- cgit v1.2.1