Skip to content
Commit 7d94a719 authored by Pekka Enberg's avatar Pekka Enberg Committed by Will Deacon
Browse files

kvm tools, qcow: Use fdatasync() instead of sync_file_range()



As explained by Christoph Hellwig, sync_file_range() is not sufficient to
guarantee that Qcow image metadata is never corrupted:

  On Thu, Jun 16, 2011 at 12:34:04PM +0300, Pekka Enberg wrote:
  > Hi Christoph,
  >
  > On Thu, Jun 16, 2011 at 09:21:03AM +0300, Pekka Enberg wrote:
  > >> And btw, we use sync_file_range()
  >
  > On Thu, Jun 16, 2011 at 12:24 PM, Christoph Hellwig <hch@infradead.org> wrote:
  > > Which doesn't help you at all. ?sync_file_range is just a hint for VM
  > > writeback, but never commits filesystem metadata nor the physical
  > > disk's write cache. ?In short it's a completely dangerous interface, and
  > > that is pretty well documented in the man page.
  >
  > Doh - I didn't read it carefully enough and got hung up with:
  >
  >     Therefore, unless the application is strictly performing overwrites of
  >     already-instantiated disk blocks, there are no guarantees that the data will
  >     be available after a crash.
  >
  > without noticing that it obviously doesn't work with filesystems like
  > btrfs that do copy-on-write.

  You also missed:

  " This system call does not flush disk write caches and thus does not
    provide any data integrity on systems with volatile disk write
    caches."

  so it's not safe if you either have a cache, or are using btrfs, or
  are using a sparse image, or are using an image preallocated using
  fallocate/posix_fallocate.

  > What's the right thing to do here? Is fdatasync() sufficient?

  Yes.

Cc: Ingo Molnar <mingo@elte.hu>
Cc: Prasad Joshi <prasadjoshi124@gmail.com>
Cc: Christoph Hellwig <hch@infradead.org>
Signed-off-by: default avatarPekka Enberg <penberg@kernel.org>
parent c7828731
Loading
Loading
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment