summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--block.c16
-rw-r--r--block.h1
-rw-r--r--block_int.h1
3 files changed, 16 insertions, 2 deletions
diff --git a/block.c b/block.c
index 1919d19732..e9fd8808bb 100644
--- a/block.c
+++ b/block.c
@@ -686,9 +686,15 @@ static void set_dirty_bitmap(BlockDriverState *bs, int64_t sector_num,
bit = start % (sizeof(unsigned long) * 8);
val = bs->dirty_bitmap[idx];
if (dirty) {
- val |= 1 << bit;
+ if (!(val & (1 << bit))) {
+ bs->dirty_count++;
+ val |= 1 << bit;
+ }
} else {
- val &= ~(1 << bit);
+ if (val & (1 << bit)) {
+ bs->dirty_count--;
+ val &= ~(1 << bit);
+ }
}
bs->dirty_bitmap[idx] = val;
}
@@ -2139,6 +2145,7 @@ void bdrv_set_dirty_tracking(BlockDriverState *bs, int enable)
{
int64_t bitmap_size;
+ bs->dirty_count = 0;
if (enable) {
if (!bs->dirty_bitmap) {
bitmap_size = (bdrv_getlength(bs) >> BDRV_SECTOR_BITS) +
@@ -2173,3 +2180,8 @@ void bdrv_reset_dirty(BlockDriverState *bs, int64_t cur_sector,
{
set_dirty_bitmap(bs, cur_sector, nr_sectors, 0);
}
+
+int64_t bdrv_get_dirty_count(BlockDriverState *bs)
+{
+ return bs->dirty_count;
+}
diff --git a/block.h b/block.h
index ecf66c52ab..536265e86c 100644
--- a/block.h
+++ b/block.h
@@ -200,4 +200,5 @@ 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);
+int64_t bdrv_get_dirty_count(BlockDriverState *bs);
#endif
diff --git a/block_int.h b/block_int.h
index a0ebd90a0b..223a437b6a 100644
--- a/block_int.h
+++ b/block_int.h
@@ -175,6 +175,7 @@ struct BlockDriverState {
int type;
char device_name[32];
unsigned long *dirty_bitmap;
+ int64_t dirty_count;
BlockDriverState *next;
void *private;
};