Re: [PATCH, RFC] virtio_blk: add cache flush command

Christoph Hellwig
2009-05-12T07:24:11Z

On Mon, May 11, 2009 at 12:47:58PM -0500, Anthony Liguori wrote:
> But how do we define the data integrity guarantees to the user of
> cache=writeback+fsync? It seems to require a rather detailed knowledge
> of Linux's use of T_FLUSH operations.

It does work the same as for disks with writeback caches. If a barrier
request completes the filesystem can assume all previous I/O on this
disk has finished before the barrier request, and the barrier request
has finished after these without any later request being finished before
it. If a cache flush is issued the cache as of that point in time is
flushed (used for fsync).

> Right now, it's fairly easy to understand. cache=none and
> cache=writethrough guarantee that all write operations that the guest
> thinks have completed are completed. cache=writeback provides no such
> guarantee.

As said above with barriers it indeed does.

> cache=writeback+fsync would guarantee that only operations that include
> a T_FLUSH are present on disk which currently includes fsyncs but does
> not include O_DIRECT writes. I guess whether O_SYNC does a T_FLUSH also
> has to be determined.

O_SYNC and O_DIRECT do it at least on XFS due to updating metadata after
the write. I can't vouch for implementation details on other
filesystems.