]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
storage: Flush host cache after write
authorMichal Privoznik <mprivozn@redhat.com>
Thu, 18 Aug 2011 12:40:03 +0000 (14:40 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Fri, 19 Aug 2011 09:10:31 +0000 (11:10 +0200)
Although we are flushing cache after some critical writes (e.g.
volume creation), after some others we do not (e.g. volume cloning).
This patch fix this issue. That is for volume cloning, writing
header of logical volume, and storage wipe.

src/storage/storage_backend.c
src/storage/storage_backend_logical.c
src/storage/storage_driver.c

index 6243d1e9b2bc352287279a28d5111e5494dc8f4c..889f5305cc430eee601bc8909226d41c52bbbd7e 100644 (file)
@@ -208,6 +208,14 @@ virStorageBackendCopyToFD(virStorageVolDefPtr vol,
         } while ((amtleft -= interval) > 0);
     }
 
+    if (fdatasync(fd) < 0) {
+        ret = -errno;
+        virReportSystemError(errno, _("cannot sync data to file '%s'"),
+                             vol->target.path);
+        goto cleanup;
+    }
+
+
     if (VIR_CLOSE(inputfd) < 0) {
         ret = -errno;
         virReportSystemError(errno,
index c622d2a3b32123965de049cece9e0b1268f49ba2..ca4166da2b4d162542c1e1e7af63671ee4bf81b4 100644 (file)
@@ -424,6 +424,13 @@ virStorageBackendLogicalBuildPool(virConnectPtr conn ATTRIBUTE_UNUSED,
             VIR_FORCE_CLOSE(fd);
             goto cleanup;
         }
+        if (fsync(fd) < 0) {
+            virReportSystemError(errno,
+                                 _("cannot flush header of device'%s'"),
+                                 pool->def->source.devices[i].path);
+            VIR_FORCE_CLOSE(fd);
+            goto cleanup;
+        }
         if (VIR_CLOSE(fd) < 0) {
             virReportSystemError(errno,
                                  _("cannot close device '%s'"),
index 6715790a6f99dd6ddc43c99e753b41c188f06f48..68cac1fc474b03fcf49ee140be3eab4c4dcdec46 100644 (file)
@@ -1777,6 +1777,14 @@ storageWipeExtent(virStorageVolDefPtr vol,
         remaining -= written;
     }
 
+    if (fdatasync(fd) < 0) {
+        ret = -errno;
+        virReportSystemError(errno,
+                             _("cannot sync data to volume with path '%s'"),
+                             vol->target.path);
+        goto out;
+    }
+
     VIR_DEBUG("Wrote %zu bytes to volume with path '%s'",
               *bytes_wiped, vol->target.path);