[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 19/32] block: introduce new dirty bitmap functionali
From: |
Kevin Wolf |
Subject: |
[Qemu-devel] [PATCH 19/32] block: introduce new dirty bitmap functionality |
Date: |
Wed, 24 Oct 2012 11:50:43 +0200 |
From: Paolo Bonzini <address@hidden>
Assert that write_compressed is never used with the dirty bitmap.
Setting the bits early is wrong, because a coroutine might concurrently
examine them and copy incomplete data from the source.
Signed-off-by: Paolo Bonzini <address@hidden>
Signed-off-by: Kevin Wolf <address@hidden>
---
block.c | 51 +++++++++++++++++++++++++++++++++++++++++++++------
block.h | 5 +++--
2 files changed, 48 insertions(+), 8 deletions(-)
diff --git a/block.c b/block.c
index e06d78f..2c3d3da 100644
--- a/block.c
+++ b/block.c
@@ -2391,7 +2391,7 @@ static int coroutine_fn
bdrv_co_do_writev(BlockDriverState *bs,
}
if (bs->dirty_bitmap) {
- set_dirty_bitmap(bs, sector_num, nb_sectors, 1);
+ bdrv_set_dirty(bs, sector_num, nb_sectors);
}
if (bs->wr_highest_sector < sector_num + nb_sectors - 1) {
@@ -2960,9 +2960,7 @@ int bdrv_write_compressed(BlockDriverState *bs, int64_t
sector_num,
if (bdrv_check_request(bs, sector_num, nb_sectors))
return -EIO;
- if (bs->dirty_bitmap) {
- set_dirty_bitmap(bs, sector_num, nb_sectors, 1);
- }
+ assert(!bs->dirty_bitmap);
return drv->bdrv_write_compressed(bs, sector_num, buf, nb_sectors);
}
@@ -4269,13 +4267,54 @@ int bdrv_get_dirty(BlockDriverState *bs, int64_t sector)
if (bs->dirty_bitmap &&
(sector << BDRV_SECTOR_BITS) < bdrv_getlength(bs)) {
- return !!(bs->dirty_bitmap[chunk / (sizeof(unsigned long) * 8)] &
- (1UL << (chunk % (sizeof(unsigned long) * 8))));
+ return !!(bs->dirty_bitmap[chunk / BITS_PER_LONG] &
+ (1UL << (chunk % BITS_PER_LONG)));
} else {
return 0;
}
}
+int64_t bdrv_get_next_dirty(BlockDriverState *bs, int64_t sector)
+{
+ int64_t chunk;
+ int bit, elem;
+
+ /* Avoid an infinite loop. */
+ assert(bs->dirty_count > 0);
+
+ sector = (sector | (BDRV_SECTORS_PER_DIRTY_CHUNK - 1)) + 1;
+ chunk = sector / (int64_t)BDRV_SECTORS_PER_DIRTY_CHUNK;
+
+ QEMU_BUILD_BUG_ON(sizeof(bs->dirty_bitmap[0]) * 8 != BITS_PER_LONG);
+ elem = chunk / BITS_PER_LONG;
+ bit = chunk % BITS_PER_LONG;
+ for (;;) {
+ if (sector >= bs->total_sectors) {
+ sector = 0;
+ bit = elem = 0;
+ }
+ if (bit == 0 && bs->dirty_bitmap[elem] == 0) {
+ sector += BDRV_SECTORS_PER_DIRTY_CHUNK * BITS_PER_LONG;
+ elem++;
+ } else {
+ if (bs->dirty_bitmap[elem] & (1UL << bit)) {
+ return sector;
+ }
+ sector += BDRV_SECTORS_PER_DIRTY_CHUNK;
+ if (++bit == BITS_PER_LONG) {
+ bit = 0;
+ elem++;
+ }
+ }
+ }
+}
+
+void bdrv_set_dirty(BlockDriverState *bs, int64_t cur_sector,
+ int nr_sectors)
+{
+ set_dirty_bitmap(bs, cur_sector, nr_sectors, 1);
+}
+
void bdrv_reset_dirty(BlockDriverState *bs, int64_t cur_sector,
int nr_sectors)
{
diff --git a/block.h b/block.h
index 096fa09..27b8f80 100644
--- a/block.h
+++ b/block.h
@@ -353,8 +353,9 @@ void *qemu_blockalign(BlockDriverState *bs, size_t size);
void bdrv_set_dirty_tracking(BlockDriverState *bs, int enable);
int bdrv_get_dirty(BlockDriverState *bs, int64_t sector);
-void bdrv_reset_dirty(BlockDriverState *bs, int64_t cur_sector,
- int nr_sectors);
+void bdrv_set_dirty(BlockDriverState *bs, int64_t cur_sector, int nr_sectors);
+void bdrv_reset_dirty(BlockDriverState *bs, int64_t cur_sector, int
nr_sectors);
+int64_t bdrv_get_next_dirty(BlockDriverState *bs, int64_t sector);
int64_t bdrv_get_dirty_count(BlockDriverState *bs);
void bdrv_enable_copy_on_read(BlockDriverState *bs);
--
1.7.6.5
- [Qemu-devel] [PATCH 04/32] qemu-img rebase: use empty string to rebase without backing file, (continued)
- [Qemu-devel] [PATCH 04/32] qemu-img rebase: use empty string to rebase without backing file, Kevin Wolf, 2012/10/24
- [Qemu-devel] [PATCH 08/32] qemu-img: Add --backing-chain option to info command, Kevin Wolf, 2012/10/24
- [Qemu-devel] [PATCH 06/32] block: in commit, determine base image from the top image, Kevin Wolf, 2012/10/24
- [Qemu-devel] [PATCH 12/32] monitor: Allow add-fd to any specified fd set, Kevin Wolf, 2012/10/24
- [Qemu-devel] [PATCH 10/32] qemu-img: document 'info --backing-chain', Kevin Wolf, 2012/10/24
- [Qemu-devel] [PATCH 11/32] block: bdrv_create(): don't leak cco.filename on error, Kevin Wolf, 2012/10/24
- [Qemu-devel] [PATCH 14/32] monitor: Prevent removing fd from set during init, Kevin Wolf, 2012/10/24
- [Qemu-devel] [PATCH 09/32] qemu-iotests: Add 043 backing file chain infinite loop test, Kevin Wolf, 2012/10/24
- [Qemu-devel] [PATCH 17/32] block: add bdrv_query_stats, Kevin Wolf, 2012/10/24
- [Qemu-devel] [PATCH 15/32] qemu-config: Add new -add-fd command line option, Kevin Wolf, 2012/10/24
- [Qemu-devel] [PATCH 19/32] block: introduce new dirty bitmap functionality,
Kevin Wolf <=
- [Qemu-devel] [PATCH 21/32] block: rename block_job_complete to block_job_completed, Kevin Wolf, 2012/10/24
- [Qemu-devel] [PATCH 13/32] monitor: Enable adding an inherited fd to an fd set, Kevin Wolf, 2012/10/24
- [Qemu-devel] [PATCH 22/32] block: add block-job-complete, Kevin Wolf, 2012/10/24
- [Qemu-devel] [PATCH 16/32] block: add bdrv_query_info, Kevin Wolf, 2012/10/24
- [Qemu-devel] [PATCH 18/32] block: add bdrv_open_backing_file, Kevin Wolf, 2012/10/24
- [Qemu-devel] [PATCH 20/32] block: export dirty bitmap information in query-block, Kevin Wolf, 2012/10/24
- [Qemu-devel] [PATCH 25/32] qmp: add drive-mirror command, Kevin Wolf, 2012/10/24
- [Qemu-devel] [PATCH 24/32] mirror: introduce mirror job, Kevin Wolf, 2012/10/24
- [Qemu-devel] [PATCH 23/32] block: introduce BLOCK_JOB_READY event, Kevin Wolf, 2012/10/24
- [Qemu-devel] [PATCH 31/32] qemu-iotests: add testcases for mirroring on-source-error/on-target-error, Kevin Wolf, 2012/10/24