[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [RFC PATCH 21/36] block: introduce new dirty bitmap functio
From: |
Paolo Bonzini |
Subject: |
[Qemu-devel] [RFC PATCH 21/36] block: introduce new dirty bitmap functionality |
Date: |
Fri, 15 Jun 2012 17:05:44 +0200 |
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>
---
block.c | 51 +++++++++++++++++++++++++++++++++++++++++++++------
block.h | 5 +++--
2 files changed, 48 insertions(+), 8 deletions(-)
diff --git a/block.c b/block.c
index f1afdd6..dbb9041 100644
--- a/block.c
+++ b/block.c
@@ -2021,7 +2021,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) {
@@ -2838,9 +2838,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);
}
@@ -4069,13 +4067,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 1e13469..c13d779 100644
--- a/block.h
+++ b/block.h
@@ -356,8 +356,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.10.2
- [Qemu-devel] [RFC PATCH 07/36] qemu-iotests: add test for pausing a streaming operation, (continued)
- [Qemu-devel] [RFC PATCH 07/36] qemu-iotests: add test for pausing a streaming operation, Paolo Bonzini, 2012/06/15
- [Qemu-devel] [RFC PATCH 10/36] block: move BlockdevOnError declaration to QAPI, Paolo Bonzini, 2012/06/15
- [Qemu-devel] [RFC PATCH 09/36] block: rename BlockErrorAction, BlockQMPEventAction, Paolo Bonzini, 2012/06/15
- [Qemu-devel] [RFC PATCH 12/36] block: sort BlockDeviceIoStatus errors by severity, Paolo Bonzini, 2012/06/15
- [Qemu-devel] [RFC PATCH 11/36] block: reorganize io error code, Paolo Bonzini, 2012/06/15
- [Qemu-devel] [RFC PATCH 15/36] qemu-iotests: add tests for streaming error handling, Paolo Bonzini, 2012/06/15
- [Qemu-devel] [RFC PATCH 13/36] block: introduce block job error, Paolo Bonzini, 2012/06/15
- [Qemu-devel] [RFC PATCH 20/36] block: forward bdrv_iostatus_reset to block job, Paolo Bonzini, 2012/06/15
- [Qemu-devel] [RFC PATCH 21/36] block: introduce new dirty bitmap functionality,
Paolo Bonzini <=
- [Qemu-devel] [RFC PATCH 22/36] block: add mirror job, Paolo Bonzini, 2012/06/15
- [Qemu-devel] [RFC PATCH 19/36] block: add target info to QMP query-blockjobs command, Paolo Bonzini, 2012/06/15
- [Qemu-devel] [RFC PATCH 25/36] mirror: add support for on_source_error/on_target_error, Paolo Bonzini, 2012/06/15
- [Qemu-devel] [RFC PATCH 24/36] mirror: support querying target file, Paolo Bonzini, 2012/06/15
- [Qemu-devel] [RFC PATCH 29/36] mirror: implement completion, Paolo Bonzini, 2012/06/15
- [Qemu-devel] [RFC PATCH 34/36] block: return count of dirty sectors, not chunks, Paolo Bonzini, 2012/06/15
- [Qemu-devel] [RFC PATCH 33/36] mirror: perform COW if the cluster size is bigger than the granularity, Paolo Bonzini, 2012/06/15
- [Qemu-devel] [RFC PATCH 26/36] block: live snapshot documentation tweaks, Paolo Bonzini, 2012/06/15