[libvirt] [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(+), 0 deletions(-) diff --git a/src/storage/storage_backend.c b/src/storage/storage_backend.c index 6243d1e..889f530 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 c622d2a..ca4166d 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 6715790..68cac1f 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); -- 1.7.3.4

On 08/18/2011 07:44 AM, Michal Privoznik wrote:
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(+), 0 deletions(-)
diff --git a/src/storage/storage_backend.c b/src/storage/storage_backend.c index 6243d1e..889f530 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) {
Why fdatasync here,
+++ 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) {
but only fsync here? -- Eric Blake eblake@redhat.com +1-801-349-2682 Libvirt virtualization library http://libvirt.org

On 18.08.2011 15:55, Eric Blake wrote:
On 08/18/2011 07:44 AM, Michal Privoznik wrote:
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(+), 0 deletions(-)
diff --git a/src/storage/storage_backend.c b/src/storage/storage_backend.c index 6243d1e..889f530 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) {
Why fdatasync here, Here we need to flush data but not metadata.
+++ 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) {
but only fsync here?
Here we are accessing logical volume where we want to make sure anybody (including LVM) will read data & metadata.

On Thu, Aug 18, 2011 at 04:25:55PM +0200, Michal Privoznik wrote:
On 18.08.2011 15:55, Eric Blake wrote:
On 08/18/2011 07:44 AM, Michal Privoznik wrote:
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(+), 0 deletions(-)
diff --git a/src/storage/storage_backend.c b/src/storage/storage_backend.c index 6243d1e..889f530 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) {
Why fdatasync here, Here we need to flush data but not metadata.
+++ 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) {
but only fsync here?
Here we are accessing logical volume where we want to make sure anybody (including LVM) will read data & metadata.
thanks for the explanation, ACK then ! Daniel -- Daniel Veillard | libxml Gnome XML XSLT toolkit http://xmlsoft.org/ daniel@veillard.com | Rpmfind RPM search engine http://rpmfind.net/ http://veillard.com/ | virtualization library http://libvirt.org/

On 19.08.2011 11:04, Daniel Veillard wrote:
On Thu, Aug 18, 2011 at 04:25:55PM +0200, Michal Privoznik wrote:
On 18.08.2011 15:55, Eric Blake wrote:
On 08/18/2011 07:44 AM, Michal Privoznik wrote:
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(+), 0 deletions(-)
diff --git a/src/storage/storage_backend.c b/src/storage/storage_backend.c index 6243d1e..889f530 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) {
Why fdatasync here, Here we need to flush data but not metadata.
+++ 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) {
but only fsync here?
Here we are accessing logical volume where we want to make sure anybody (including LVM) will read data & metadata.
thanks for the explanation, ACK then !
Daniel
Thanks, applied. Michal
participants (3)
-
Daniel Veillard
-
Eric Blake
-
Michal Privoznik