diff mbox

[for-2.2,3/3] block/raw-posix: Catch fsync() errors

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

Commit Message

Max Reitz Nov. 18, 2014, 10:23 a.m. UTC
fsync() may fail, and that case should be handled.

Reported-by: László Érsek <lersek@redhat.com>
Signed-off-by: Max Reitz <mreitz@redhat.com>
---
 block/raw-posix.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
diff mbox

Patch

diff --git a/block/raw-posix.c b/block/raw-posix.c
index f67fb11..666cdec 100644
--- a/block/raw-posix.c
+++ b/block/raw-posix.c
@@ -1460,7 +1460,12 @@  static int raw_create(const char *filename, QemuOpts *opts, Error **errp)
             left -= result;
         }
         if (result >= 0) {
-            fsync(fd);
+            result = fsync(fd);
+            if (result < 0) {
+                result = -errno;
+                error_setg_errno(errp, -result,
+                                 "Could not flush new file to disk");
+            }
         }
         g_free(buf);
         break;