diff options
author | Kevin Wolf <kwolf@redhat.com> | 2011-11-10 18:13:59 +0100 |
---|---|---|
committer | Kevin Wolf <kwolf@redhat.com> | 2011-11-11 14:02:59 +0100 |
commit | ca716364f045da710ddef7fc6420bd6760e45b56 (patch) | |
tree | e29039d09181ff4a234373d2f65342c32b5f5e12 | |
parent | eb489bb1eceea0d710cd5f5122d37213300ceef6 (diff) | |
download | qemu-ca716364f045da710ddef7fc6420bd6760e45b56.zip qemu-ca716364f045da710ddef7fc6420bd6760e45b56.tar.gz qemu-ca716364f045da710ddef7fc6420bd6760e45b56.tar.bz2 |
block: Make cache=unsafe flush to the OS
cache=unsafe completely ignored bdrv_flush, because flushing the host disk
costs a lot of performance. However, this means that qcow2 images (and
potentially any other format) can lose data even after the guest has issued a
flush if the qemu process crashes/is killed. In case of a host crash, data loss
is certainly expected with cache=unsafe, but if just the qemu process dies this
is a bit too unsafe.
Now that we have two separate flush functions, we can choose to flush
everythign to the OS, but don't enforce that it's physically written to the
disk.
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
-rw-r--r-- | block.c | 10 |
1 files changed, 7 insertions, 3 deletions
@@ -2791,12 +2791,11 @@ int coroutine_fn bdrv_co_flush(BlockDriverState *bs) { int ret; - if (bs->open_flags & BDRV_O_NO_FLUSH) { - return 0; - } else if (!bs->drv) { + if (!bs->drv) { return 0; } + /* Write back cached data to the OS even with cache=unsafe */ if (bs->drv->bdrv_co_flush_to_os) { ret = bs->drv->bdrv_co_flush_to_os(bs); if (ret < 0) { @@ -2804,6 +2803,11 @@ int coroutine_fn bdrv_co_flush(BlockDriverState *bs) } } + /* But don't actually force it to the disk with cache=unsafe */ + if (bs->open_flags & BDRV_O_NO_FLUSH) { + return 0; + } + if (bs->drv->bdrv_co_flush_to_disk) { return bs->drv->bdrv_co_flush_to_disk(bs); } else if (bs->drv->bdrv_aio_flush) { |