[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 14/17] block: protect against "torn reads" for guest
From: |
Paolo Bonzini |
Subject: |
[Qemu-devel] [PATCH 14/17] block: protect against "torn reads" for guest_block_size > host_block_size |
Date: |
Tue, 13 Dec 2011 13:37:17 +0100 |
When the guest sees a higher alignment than the host, writes may be
done in multiple steps. So, reads have to be serialized against
overlapping writes, so that the writes look atomic to the guest.
This is true even when O_DIRECT is not in use.
Signed-off-by: Paolo Bonzini <address@hidden>
---
block.c | 22 ++++++++++++++++++++++
1 files changed, 22 insertions(+), 0 deletions(-)
diff --git a/block.c b/block.c
index 07b9cf4..9e35c85 100644
--- a/block.c
+++ b/block.c
@@ -1598,6 +1598,16 @@ static int coroutine_fn
bdrv_co_do_readv(BlockDriverState *bs,
get_cluster_size(bs), false);
}
+ /* When the guest sees a higher alignment than the host, writes may be
+ * done in multiple steps. So, reads have to be serialized against
+ * overlapping writes, so that the writes look atomic to the guest,
+ * even when O_DIRECT is not in use.
+ */
+ if (bs->guest_block_size > bs->host_block_size) {
+ wait_for_overlapping_requests(bs, sector_num, nb_sectors,
+ bs->guest_block_size, true);
+ }
+
tracked_request_begin(&req, bs, sector_num, nb_sectors, false);
if (bs->copy_on_read) {
@@ -3582,6 +3592,18 @@ BlockDriverAIOCB *bdrv_aio_ioctl(BlockDriverState *bs,
void bdrv_set_guest_block_size(BlockDriverState *bs, int align)
{
bs->guest_block_size = align;
+ if ((bs->open_flags & BDRV_O_RDWR) &&
+ bs->host_block_size < bs->guest_block_size) {
+ error_report("Host block size is %d, guest block size is %d. Due to
partially\n"
+ "written sectors, power failures may cause data
corruption.%s",
+ bs->host_block_size, bs->guest_block_size,
+
+ /* The host block size might not be detected correctly if
+ * the guest is not using O_DIRECT. */
+ (bs->open_flags & BDRV_O_NOCACHE) ? "" :
+ "\nIf you think this message is wrong, start the guest
with cache=none"
+ "\nand see if it disappears.");
+ }
}
void *qemu_blockalign(BlockDriverState *bs, size_t size)
--
1.7.7.1
- Re: [Qemu-devel] [PATCH 03/17] block: pass protocol flags up to the format, (continued)
- [Qemu-devel] [PATCH 04/17] block: non-raw protocols never cache, Paolo Bonzini, 2011/12/13
- [Qemu-devel] [PATCH 06/17] block: move flag bits together, Paolo Bonzini, 2011/12/13
- [Qemu-devel] [PATCH 07/17] raw: remove the aligned_buf, Paolo Bonzini, 2011/12/13
- [Qemu-devel] [PATCH 08/17] block: rename buffer_alignment to guest_block_size, Paolo Bonzini, 2011/12/13
- [Qemu-devel] [PATCH 09/17] block: add host_block_size, Paolo Bonzini, 2011/12/13
- [Qemu-devel] [PATCH 11/17] iscsi: save host block size, Paolo Bonzini, 2011/12/13
- [Qemu-devel] [PATCH 12/17] block: allow waiting only for overlapping writes, Paolo Bonzini, 2011/12/13
- [Qemu-devel] [PATCH 10/17] raw: probe host_block_size, Paolo Bonzini, 2011/12/13
- [Qemu-devel] [PATCH 16/17] block: default physical block size to host block size, Paolo Bonzini, 2011/12/13
- [Qemu-devel] [PATCH 14/17] block: protect against "torn reads" for guest_block_size > host_block_size,
Paolo Bonzini <=
- [Qemu-devel] [PATCH 15/17] block: align and serialize I/O when guest_block_size < host_block_size, Paolo Bonzini, 2011/12/13
- [Qemu-devel] [PATCH 13/17] block: allow waiting at arbitrary granularity, Paolo Bonzini, 2011/12/13
- [Qemu-devel] [PATCH 17/17] qemu-io: add blocksize argument to open, Paolo Bonzini, 2011/12/13
- Re: [Qemu-devel] [PATCH 00/17] Support mismatched host and guest logical block sizes, Kevin Wolf, 2011/12/14