From: Liu Yuan <tailai...@taobao.com> The 'qemu-img convert -h' advertise that the default cache mode is 'writeback', while in fact it is 'unsafe'.
This patch 1) changes the cache mode as 'writeback' and 2) explicitly calls bdrv_flush() to flush the dirty bits. 2) is needed because some backend storage doesn't have a self-flush mechanism(for e.g., sheepdog), so we need to call bdrv_flush() to make sure the image is really writen to the storage instead of hanging around writeback cache forever. Signed-off-by: Liu Yuan <tailai...@taobao.com> --- qemu-img.c | 5 ++++- 1 files changed, 4 insertions(+), 1 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index 6a61ca8..f96230b 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -644,7 +644,7 @@ static int img_convert(int argc, char **argv) fmt = NULL; out_fmt = "raw"; - cache = "unsafe"; + cache = "writeback"; out_baseimg = NULL; compress = 0; for(;;) { @@ -1036,6 +1036,9 @@ out: free_option_parameters(param); qemu_vfree(buf); if (out_bs) { + if (ret == 0) { + bdrv_flush(out_bs); + } bdrv_delete(out_bs); } if (bs) { -- 1.7.8.2