aboutsummaryrefslogtreecommitdiff
path: root/block.c
diff options
context:
space:
mode:
authorLiran Schour <lirans@il.ibm.com>2010-01-26 10:31:48 +0200
committerAnthony Liguori <aliguori@us.ibm.com>2010-02-09 16:56:14 -0600
commitaaa0eb75e2e56d483c89731a447c999985713b43 (patch)
tree1d026f3e2867cabc2e896b82aede646297aee8a6 /block.c
parentd76cac7dfbff76acb8eac2de849d148b0ff8cbbb (diff)
Count dirty blocks and expose an API to get dirty count
This will manage dirty counter for each device and will allow to get the dirty counter from above. Signed-off-by: Liran Schour <lirans@il.ibm.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Diffstat (limited to 'block.c')
-rw-r--r--block.c16
1 files changed, 14 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;
+}