Liran Schour wrote:
> This will manage dirty counter for each device and will allow to get the
> dirty counter from above.
> 
> Signed-off-by: Liran Schour <lir...@il.ibm.com>
> ---
>  block.c     |   20 ++++++++++++++++----
>  block.h     |    1 +
>  block_int.h |    1 +
>  3 files changed, 18 insertions(+), 4 deletions(-)
> 
> diff --git a/block.c b/block.c
> index 853f025..ecfcba4 100644
> --- a/block.c
> +++ b/block.c
> @@ -652,9 +652,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;
>      }
> @@ -1972,14 +1978,15 @@ void *qemu_blockalign(BlockDriverState *bs, size_t 
> size)
>  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) +
>                      BDRV_SECTORS_PER_DIRTY_CHUNK * 8 - 1;
>              bitmap_size /= BDRV_SECTORS_PER_DIRTY_CHUNK * 8;
>  
> -            bs->dirty_bitmap = qemu_mallocz(bitmap_size);
> +            bs->dirty_bitmap = qemu_mallocz(bitmap_size);  
>          }
>      } else {
>          if (bs->dirty_bitmap) {
> @@ -2007,3 +2014,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 4a8b628..bf489d0 100644
> --- a/block.h
> +++ b/block.h
> @@ -198,4 +198,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 9a3b2e0..8d5d9bc 100644
> --- a/block_int.h
> +++ b/block_int.h
> @@ -172,6 +172,7 @@ struct BlockDriverState {
>      int type;
>      char device_name[32];
>      unsigned long *dirty_bitmap;
> +    int64_t dirty_count;
>      BlockDriverState *next;
>      void *private;
>  };

Looks good (except for the whitespace issues).

Jan

-- 
Siemens AG, Corporate Technology, CT T DE IT 1
Corporate Competence Center Embedded Linux


Reply via email to