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

Daniel Veillard veillard at redhat.com
Tue Mar 2 16:58:13 UTC 2010


On Tue, Mar 02, 2010 at 04:26:59PM +0100, Jiri Denemark wrote:
> 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 at redhat.com>
> ---
>  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,

  I would tend to prefer this patch on the basis that I would prefer a
smaller change to the code at this point before the release. But the
O_DSYNC was added after finding that cache effects could just break the
qemu startup timeout in the test environment. I'm not 100% sure fsync()
will have the same behaviour overall, it should but theory and practice
may diverge :-)
  So I'm tempted to go with this patch but we should validate it on testing
before the end of the week.

Daniel

-- 
Daniel Veillard      | libxml Gnome XML XSLT toolkit  http://xmlsoft.org/
daniel at veillard.com  | Rpmfind RPM search engine http://rpmfind.net/
http://veillard.com/ | virtualization library  http://libvirt.org/




More information about the libvir-list mailing list