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>
This commit is contained in:
parent
d76cac7dfb
commit
aaa0eb75e2
16
block.c
16
block.c
@ -686,9 +686,15 @@ static void set_dirty_bitmap(BlockDriverState *bs, int64_t sector_num,
|
|||||||
bit = start % (sizeof(unsigned long) * 8);
|
bit = start % (sizeof(unsigned long) * 8);
|
||||||
val = bs->dirty_bitmap[idx];
|
val = bs->dirty_bitmap[idx];
|
||||||
if (dirty) {
|
if (dirty) {
|
||||||
val |= 1 << bit;
|
if (!(val & (1 << bit))) {
|
||||||
|
bs->dirty_count++;
|
||||||
|
val |= 1 << bit;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
val &= ~(1 << bit);
|
if (val & (1 << bit)) {
|
||||||
|
bs->dirty_count--;
|
||||||
|
val &= ~(1 << bit);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
bs->dirty_bitmap[idx] = val;
|
bs->dirty_bitmap[idx] = val;
|
||||||
}
|
}
|
||||||
@ -2139,6 +2145,7 @@ void bdrv_set_dirty_tracking(BlockDriverState *bs, int enable)
|
|||||||
{
|
{
|
||||||
int64_t bitmap_size;
|
int64_t bitmap_size;
|
||||||
|
|
||||||
|
bs->dirty_count = 0;
|
||||||
if (enable) {
|
if (enable) {
|
||||||
if (!bs->dirty_bitmap) {
|
if (!bs->dirty_bitmap) {
|
||||||
bitmap_size = (bdrv_getlength(bs) >> BDRV_SECTOR_BITS) +
|
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);
|
set_dirty_bitmap(bs, cur_sector, nr_sectors, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int64_t bdrv_get_dirty_count(BlockDriverState *bs)
|
||||||
|
{
|
||||||
|
return bs->dirty_count;
|
||||||
|
}
|
||||||
|
1
block.h
1
block.h
@ -200,4 +200,5 @@ void bdrv_set_dirty_tracking(BlockDriverState *bs, int enable);
|
|||||||
int bdrv_get_dirty(BlockDriverState *bs, int64_t sector);
|
int bdrv_get_dirty(BlockDriverState *bs, int64_t sector);
|
||||||
void bdrv_reset_dirty(BlockDriverState *bs, int64_t cur_sector,
|
void bdrv_reset_dirty(BlockDriverState *bs, int64_t cur_sector,
|
||||||
int nr_sectors);
|
int nr_sectors);
|
||||||
|
int64_t bdrv_get_dirty_count(BlockDriverState *bs);
|
||||||
#endif
|
#endif
|
||||||
|
@ -175,6 +175,7 @@ struct BlockDriverState {
|
|||||||
int type;
|
int type;
|
||||||
char device_name[32];
|
char device_name[32];
|
||||||
unsigned long *dirty_bitmap;
|
unsigned long *dirty_bitmap;
|
||||||
|
int64_t dirty_count;
|
||||||
BlockDriverState *next;
|
BlockDriverState *next;
|
||||||
void *private;
|
void *private;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user