]> xenbits.xensource.com Git - libvirt.git/commitdiff
util: introduce virFileDataSync
authorDaniel P. Berrangé <berrange@redhat.com>
Tue, 24 Dec 2019 15:14:13 +0000 (15:14 +0000)
committerDaniel P. Berrangé <berrange@redhat.com>
Fri, 3 Jan 2020 15:42:12 +0000 (15:42 +0000)
A wrapper that calls g_fsync on Win32/macOS and fdatasync
elsewhere. g_fsync is a stronger flush than we need but it
satisfies the caller's requirements & matches the approach
gnulib takes.

Reviewed-by: Fabiano Fidêncio <fidencio@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
src/libvirt_private.syms
src/storage/storage_util.c
src/util/iohelper.c
src/util/virfile.c
src/util/virfile.h

index d3184dbf5c5ecab0485e52f1be34901e51b57ab1..951ba7f0cae3eb17a5661d8b76be785c33748428 100644 (file)
@@ -1976,6 +1976,7 @@ virFileChownFiles;
 virFileClose;
 virFileComparePaths;
 virFileCopyACLs;
+virFileDataSync;
 virFileDeleteTree;
 virFileDirectFdFlag;
 virFileExists;
index c1a6b44f4b52f2a731306ebb3de821ada4ab3dd0..45ffd2206ee52461be6cbf0844fb6cea0833a7d7 100644 (file)
@@ -216,7 +216,7 @@ virStorageBackendCopyToFD(virStorageVolDefPtr vol,
         } while ((amtleft -= interval) > 0);
     }
 
-    if (fdatasync(fd) < 0) {
+    if (virFileDataSync(fd) < 0) {
         ret = -errno;
         virReportSystemError(errno, _("cannot sync data to file '%s'"),
                              vol->target.path);
@@ -2539,7 +2539,7 @@ storageBackendWipeLocal(const char *path,
         remaining -= written;
     }
 
-    if (fdatasync(fd) < 0) {
+    if (virFileDataSync(fd) < 0) {
         virReportSystemError(errno,
                              _("cannot sync data to volume with path '%s'"),
                              path);
index a102a95abb086f0d366fc86767875e4d87176e73..d864bbeaedb533572b1494d7f94d411073c4530e 100644 (file)
@@ -154,7 +154,7 @@ runIO(const char *path, int fd, int oflags)
     }
 
     /* Ensure all data is written */
-    if (fdatasync(fdout) < 0) {
+    if (virFileDataSync(fdout) < 0) {
         if (errno != EINVAL && errno != EROFS) {
             /* fdatasync() may fail on some special FDs, e.g. pipes */
             virReportSystemError(errno, _("unable to fsync %s"), fdoutname);
index 1784895575878952d323fd9f6ab53eca12c29502..c79fe864035a93e99adc976626eab8f80dcfca84 100644 (file)
@@ -4432,3 +4432,14 @@ virFileGetXAttr(const char *path,
 
     return ret;
 }
+
+
+int
+virFileDataSync(int fd)
+{
+#if defined(__APPLE__) || defined(WIN32)
+    return g_fsync(fd);
+#else
+    return fdatasync(fd);
+#endif
+}
index 264b12c03de53b3436c185ce154b86732058c236..c73f5252e4961d09f55cfe71ffcb6a41afcb7e83 100644 (file)
@@ -372,3 +372,5 @@ int virFileSetXAttr(const char *path,
 int virFileRemoveXAttr(const char *path,
                        const char *name)
     G_GNUC_NO_INLINE;
+
+int virFileDataSync(int fd);