[libvirt] [PATCH option 2] Use fsync() at the end of file allocation instead of O_DSYNC

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Instead of opening storage file with O_DSYNC, make sure data are written
to a disk only before we claim allocation has finished.

Signed-off-by: Jiri Denemark <jdenemar@xxxxxxxxxx>
---
 src/storage/storage_backend.c |    9 ++++++++-
 1 files changed, 8 insertions(+), 1 deletions(-)

diff --git a/src/storage/storage_backend.c b/src/storage/storage_backend.c
index 849f01b..4cc2f93 100644
--- a/src/storage/storage_backend.c
+++ b/src/storage/storage_backend.c
@@ -332,6 +332,13 @@ static int createRawFileOpHook(int fd, void *data) {
                 goto cleanup;
             }
         }
+
+        if (fsync(fd) < 0) {
+            ret = errno;
+            virReportSystemError(errno, _("cannot sync data to file '%s'"),
+                                 hdata->vol->target.path);
+            goto cleanup;
+        }
     }
 
 cleanup:
@@ -357,7 +364,7 @@ virStorageBackendCreateRaw(virConnectPtr conn ATTRIBUTE_UNUSED,
     }
 
     if ((createstat = virFileOperation(vol->target.path,
-                                       O_RDWR | O_CREAT | O_EXCL | O_DSYNC,
+                                       O_RDWR | O_CREAT | O_EXCL,
                                        vol->target.perms.mode,
                                        vol->target.perms.uid, vol->target.perms.gid,
                                        createRawFileOpHook, &hdata,
-- 
1.7.0

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]