diff mbox

[for-2.2,2/3] block/raw-posix: Only sync after successful preallocation

Message ID 1416306186-19053-3-git-send-email-mreitz@redhat.com
State New
Headers show

Commit Message

Max Reitz Nov. 18, 2014, 10:23 a.m. UTC
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 <mreitz@redhat.com>
---
 block/raw-posix.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
diff mbox

Patch

diff --git a/block/raw-posix.c b/block/raw-posix.c
index 4e6552f..f67fb11 100644
--- a/block/raw-posix.c
+++ b/block/raw-posix.c
@@ -1459,7 +1459,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;
     }