Patchwork [16/20] block: split bdrv_enable_dirty_tracking and bdrv_disable_dirty_tracking

login
register
mail settings
Submitter Paolo Bonzini
Date Dec. 12, 2012, 1:46 p.m.
Message ID <1355319999-30627-17-git-send-email-pbonzini@redhat.com>
Download mbox | patch
Permalink /patch/205520/
State New
Headers show

Comments

Paolo Bonzini - Dec. 12, 2012, 1:46 p.m.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 block-migration.c | 17 +++--------------
 block.c           | 22 +++++++++++-----------
 block.h           |  3 ++-
 block/mirror.c    |  4 ++--
 4 files changed, 18 insertions(+), 28 deletions(-)
Eric Blake - Dec. 20, 2012, 6:26 p.m.
On 12/12/2012 06:46 AM, Paolo Bonzini wrote:
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
>  block-migration.c | 17 +++--------------
>  block.c           | 22 +++++++++++-----------
>  block.h           |  3 ++-
>  block/mirror.c    |  4 ++--
>  4 files changed, 18 insertions(+), 28 deletions(-)

Reviewed-by: Eric Blake <eblake@redhat.com>

Patch

diff --git a/block-migration.c b/block-migration.c
index 1e1d25e..bf995f5 100644
--- a/block-migration.c
+++ b/block-migration.c
@@ -260,15 +260,6 @@  static int mig_save_device_bulk(QEMUFile *f, BlkMigDevState *bmds)
     return (bmds->cur_sector >= total_sectors);
 }
 
-static void set_dirty_tracking(int enable)
-{
-    BlkMigDevState *bmds;
-
-    QSIMPLEQ_FOREACH(bmds, &block_mig_state.bmds_list, entry) {
-        bdrv_set_dirty_tracking(bmds->bs, enable ? BLOCK_SIZE : 0);
-    }
-}
-
 static void init_blk_migration_it(void *opaque, BlockDriverState *bs)
 {
     BlkMigDevState *bmds;
@@ -289,6 +280,7 @@  static void init_blk_migration_it(void *opaque, BlockDriverState *bs)
         alloc_aio_bitmap(bmds);
         drive_get_ref(drive_get_by_blockdev(bs));
         bdrv_set_in_use(bs, 1);
+        bdrv_enable_dirty_tracking(bs, BLOCK_SIZE);
 
         block_mig_state.total_sector_sum += sectors;
 
@@ -527,10 +519,9 @@  static void blk_mig_cleanup(void)
 
     bdrv_drain_all();
 
-    set_dirty_tracking(0);
-
     while ((bmds = QSIMPLEQ_FIRST(&block_mig_state.bmds_list)) != NULL) {
         QSIMPLEQ_REMOVE_HEAD(&block_mig_state.bmds_list, entry);
+        bdrv_disable_dirty_tracking(bmds->bs);
         bdrv_set_in_use(bmds->bs, 0);
         drive_put_ref(drive_get_by_blockdev(bmds->bs));
         g_free(bmds->aio_bitmap);
@@ -556,10 +547,8 @@  static int block_save_setup(QEMUFile *f, void *opaque)
     DPRINTF("Enter save live setup submitted %d transferred %d\n",
             block_mig_state.submitted, block_mig_state.transferred);
 
-    init_blk_migration(f);
-
     /* start track dirty blocks */
-    set_dirty_tracking(1);
+    init_blk_migration(f);
 
     ret = flush_blks(f);
     if (ret) {
diff --git a/block.c b/block.c
index 09f9ca9..66e30aa 100644
--- a/block.c
+++ b/block.c
@@ -4220,22 +4220,22 @@  void *qemu_blockalign(BlockDriverState *bs, size_t size)
     return qemu_memalign((bs && bs->buffer_alignment) ? bs->buffer_alignment : 512, size);
 }
 
-void bdrv_set_dirty_tracking(BlockDriverState *bs, int granularity)
+void bdrv_enable_dirty_tracking(BlockDriverState *bs, int granularity)
 {
     int64_t bitmap_size;
 
     assert((granularity & (granularity - 1)) == 0);
+    granularity >>= BDRV_SECTOR_BITS;
+    assert(!bs->dirty_bitmap);
+    bitmap_size = (bdrv_getlength(bs) >> BDRV_SECTOR_BITS);
+    bs->dirty_bitmap = hbitmap_alloc(bitmap_size, ffs(granularity) - 1);
+}
 
-    if (granularity) {
-        granularity >>= BDRV_SECTOR_BITS;
-        assert(!bs->dirty_bitmap);
-        bitmap_size = (bdrv_getlength(bs) >> BDRV_SECTOR_BITS);
-        bs->dirty_bitmap = hbitmap_alloc(bitmap_size, ffs(granularity) - 1);
-    } else {
-        if (bs->dirty_bitmap) {
-            hbitmap_free(bs->dirty_bitmap);
-            bs->dirty_bitmap = NULL;
-        }
+void bdrv_disable_dirty_tracking(BlockDriverState *bs)
+{
+    if (bs->dirty_bitmap) {
+        hbitmap_free(bs->dirty_bitmap);
+        bs->dirty_bitmap = NULL;
     }
 }
 
diff --git a/block.h b/block.h
index b57896a..78a39fb 100644
--- a/block.h
+++ b/block.h
@@ -355,7 +355,8 @@  void bdrv_set_buffer_alignment(BlockDriverState *bs, int align);
 void *qemu_blockalign(BlockDriverState *bs, size_t size);
 
 struct HBitmapIter;
-void bdrv_set_dirty_tracking(BlockDriverState *bs, int granularity);
+void bdrv_enable_dirty_tracking(BlockDriverState *bs, int granularity);
+void bdrv_disable_dirty_tracking(BlockDriverState *bs);
 int bdrv_get_dirty(BlockDriverState *bs, int64_t sector);
 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);
diff --git a/block/mirror.c b/block/mirror.c
index 23f87d2..99c5bd1 100644
--- a/block/mirror.c
+++ b/block/mirror.c
@@ -467,7 +467,7 @@  immediate_exit:
     g_free(s->buf);
     g_free(s->cow_bitmap);
     g_free(s->in_flight_bitmap);
-    bdrv_set_dirty_tracking(bs, 0);
+    bdrv_disable_dirty_tracking(bs);
     bdrv_iostatus_disable(s->target);
     if (s->should_complete && ret == 0) {
         if (bdrv_get_flags(s->target) != bdrv_get_flags(s->common.bs)) {
@@ -570,7 +570,7 @@  void mirror_start(BlockDriverState *bs, BlockDriverState *target,
     s->granularity = granularity;
     s->buf_size = MAX(buf_size, granularity);
 
-    bdrv_set_dirty_tracking(bs, granularity);
+    bdrv_enable_dirty_tracking(bs, granularity);
     bdrv_set_enable_write_cache(s->target, true);
     bdrv_set_on_error(s->target, on_target_error, on_target_error);
     bdrv_iostatus_enable(s->target);