From b32f8b19894c2a05e5955056caa45cb4cb0babeb Mon Sep 17 00:00:00 2001 From: Michal Privoznik Date: Thu, 18 Aug 2011 14:40:03 +0200 Subject: [PATCH] storage: Flush host cache after write 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 | 8 ++++++++ src/storage/storage_backend_logical.c | 7 +++++++ src/storage/storage_driver.c | 8 ++++++++ 3 files changed, 23 insertions(+) diff --git a/src/storage/storage_backend.c b/src/storage/storage_backend.c index 6243d1e9b2..889f5305cc 100644 --- a/src/storage/storage_backend.c +++ b/src/storage/storage_backend.c @@ -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, diff --git a/src/storage/storage_backend_logical.c b/src/storage/storage_backend_logical.c index c622d2a3b3..ca4166da2b 100644 --- a/src/storage/storage_backend_logical.c +++ b/src/storage/storage_backend_logical.c @@ -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'"), diff --git a/src/storage/storage_driver.c b/src/storage/storage_driver.c index 6715790a6f..68cac1fc47 100644 --- a/src/storage/storage_driver.c +++ b/src/storage/storage_driver.c @@ -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); -- GitLab