[2/4] block/dirty-bitmap: add bs link
diff mbox series

Message ID 20190916141911.5255-3-vsementsov@virtuozzo.com
State New
Headers show
Series
  • bitmaps: some refactoring
Related show

Commit Message

Vladimir Sementsov-Ogievskiy Sept. 16, 2019, 2:19 p.m. UTC
Add bs field to BdrvDirtyBitmap structure. Drop BlockDriverState
parameter from bitmap APIs where possible.

Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
---
 include/block/dirty-bitmap.h   | 14 +++++---------
 block/backup.c                 | 14 ++++++--------
 block/dirty-bitmap.c           | 24 ++++++++++++------------
 block/mirror.c                 |  4 ++--
 block/qcow2-bitmap.c           |  6 +++---
 blockdev.c                     |  6 +++---
 migration/block-dirty-bitmap.c |  7 +++----
 migration/block.c              |  4 ++--
 8 files changed, 36 insertions(+), 43 deletions(-)

Comments

John Snow Sept. 18, 2019, 11:04 p.m. UTC | #1
On 9/16/19 10:19 AM, Vladimir Sementsov-Ogievskiy wrote:
> Add bs field to BdrvDirtyBitmap structure. Drop BlockDriverState
> parameter from bitmap APIs where possible.
> 
> Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>

I've thought about doing this before, but couldn't figure out if it was
worth it.

So, let's do it.

makes any functions that take (bs, bitmap) pairs less error-prone.

Reviewed-by: John Snow <jsnow@redhat.com>

> ---
>  include/block/dirty-bitmap.h   | 14 +++++---------
>  block/backup.c                 | 14 ++++++--------
>  block/dirty-bitmap.c           | 24 ++++++++++++------------
>  block/mirror.c                 |  4 ++--
>  block/qcow2-bitmap.c           |  6 +++---
>  blockdev.c                     |  6 +++---
>  migration/block-dirty-bitmap.c |  7 +++----
>  migration/block.c              |  4 ++--
>  8 files changed, 36 insertions(+), 43 deletions(-)
> 
> diff --git a/include/block/dirty-bitmap.h b/include/block/dirty-bitmap.h
> index 848dfc6590..4c58d922e4 100644
> --- a/include/block/dirty-bitmap.h
> +++ b/include/block/dirty-bitmap.h
> @@ -18,21 +18,18 @@ BdrvDirtyBitmap *bdrv_create_dirty_bitmap(BlockDriverState *bs,
>                                            uint32_t granularity,
>                                            const char *name,
>                                            Error **errp);
> -int bdrv_dirty_bitmap_create_successor(BlockDriverState *bs,
> -                                       BdrvDirtyBitmap *bitmap,
> +int bdrv_dirty_bitmap_create_successor(BdrvDirtyBitmap *bitmap,
>                                         Error **errp);
> -BdrvDirtyBitmap *bdrv_dirty_bitmap_abdicate(BlockDriverState *bs,
> -                                            BdrvDirtyBitmap *bitmap,
> +BdrvDirtyBitmap *bdrv_dirty_bitmap_abdicate(BdrvDirtyBitmap *bitmap,
>                                              Error **errp);
> -BdrvDirtyBitmap *bdrv_reclaim_dirty_bitmap(BlockDriverState *bs,
> -                                           BdrvDirtyBitmap *bitmap,
> +BdrvDirtyBitmap *bdrv_reclaim_dirty_bitmap(BdrvDirtyBitmap *bitmap,
>                                             Error **errp);
>  void bdrv_dirty_bitmap_enable_successor(BdrvDirtyBitmap *bitmap);
>  BdrvDirtyBitmap *bdrv_find_dirty_bitmap(BlockDriverState *bs,
>                                          const char *name);
>  int bdrv_dirty_bitmap_check(const BdrvDirtyBitmap *bitmap, uint32_t flags,
>                              Error **errp);
> -void bdrv_release_dirty_bitmap(BlockDriverState *bs, BdrvDirtyBitmap *bitmap);
> +void bdrv_release_dirty_bitmap(BdrvDirtyBitmap *bitmap);
>  void bdrv_release_named_dirty_bitmaps(BlockDriverState *bs);
>  void bdrv_remove_persistent_dirty_bitmap(BlockDriverState *bs,
>                                           const char *name,
> @@ -107,8 +104,7 @@ int64_t bdrv_dirty_bitmap_next_zero(BdrvDirtyBitmap *bitmap, uint64_t offset,
>                                      uint64_t bytes);
>  bool bdrv_dirty_bitmap_next_dirty_area(BdrvDirtyBitmap *bitmap,
>                                         uint64_t *offset, uint64_t *bytes);
> -BdrvDirtyBitmap *bdrv_reclaim_dirty_bitmap_locked(BlockDriverState *bs,
> -                                                  BdrvDirtyBitmap *bitmap,
> +BdrvDirtyBitmap *bdrv_reclaim_dirty_bitmap_locked(BdrvDirtyBitmap *bitmap,
>                                                    Error **errp);
>  
>  #endif
> diff --git a/block/backup.c b/block/backup.c
> index 763f0d7ff6..acb67da3a7 100644
> --- a/block/backup.c
> +++ b/block/backup.c
> @@ -352,7 +352,6 @@ static int coroutine_fn backup_before_write_notify(
>  static void backup_cleanup_sync_bitmap(BackupBlockJob *job, int ret)
>  {
>      BdrvDirtyBitmap *bm;
> -    BlockDriverState *bs = blk_bs(job->common.blk);
>      bool sync = (((ret == 0) || (job->bitmap_mode == BITMAP_SYNC_MODE_ALWAYS)) \
>                   && (job->bitmap_mode != BITMAP_SYNC_MODE_NEVER));
>  
> @@ -361,13 +360,13 @@ static void backup_cleanup_sync_bitmap(BackupBlockJob *job, int ret)
>           * We succeeded, or we always intended to sync the bitmap.
>           * Delete this bitmap and install the child.
>           */
> -        bm = bdrv_dirty_bitmap_abdicate(bs, job->sync_bitmap, NULL);
> +        bm = bdrv_dirty_bitmap_abdicate(job->sync_bitmap, NULL);
>      } else {
>          /*
>           * We failed, or we never intended to sync the bitmap anyway.
>           * Merge the successor back into the parent, keeping all data.
>           */
> -        bm = bdrv_reclaim_dirty_bitmap(bs, job->sync_bitmap, NULL);
> +        bm = bdrv_reclaim_dirty_bitmap(job->sync_bitmap, NULL);
>      }
>  
>      assert(bm);
> @@ -398,10 +397,9 @@ static void backup_abort(Job *job)
>  static void backup_clean(Job *job)
>  {
>      BackupBlockJob *s = container_of(job, BackupBlockJob, common.job);
> -    BlockDriverState *bs = blk_bs(s->common.blk);
>  
>      if (s->copy_bitmap) {
> -        bdrv_release_dirty_bitmap(bs, s->copy_bitmap);
> +        bdrv_release_dirty_bitmap(s->copy_bitmap);
>          s->copy_bitmap = NULL;
>      }
>  
> @@ -679,7 +677,7 @@ BlockJob *backup_job_create(const char *job_id, BlockDriverState *bs,
>          }
>  
>          /* Create a new bitmap, and freeze/disable this one. */
> -        if (bdrv_dirty_bitmap_create_successor(bs, sync_bitmap, errp) < 0) {
> +        if (bdrv_dirty_bitmap_create_successor(sync_bitmap, errp) < 0) {
>              return NULL;
>          }
>      }
> @@ -758,10 +756,10 @@ BlockJob *backup_job_create(const char *job_id, BlockDriverState *bs,
>   error:
>      if (copy_bitmap) {
>          assert(!job || !job->copy_bitmap);
> -        bdrv_release_dirty_bitmap(bs, copy_bitmap);
> +        bdrv_release_dirty_bitmap(copy_bitmap);
>      }
>      if (sync_bitmap) {
> -        bdrv_reclaim_dirty_bitmap(bs, sync_bitmap, NULL);
> +        bdrv_reclaim_dirty_bitmap(sync_bitmap, NULL);
>      }
>      if (job) {
>          backup_clean(&job->common.job);
> diff --git a/block/dirty-bitmap.c b/block/dirty-bitmap.c
> index acfc3077f1..f3dc7b3ca5 100644
> --- a/block/dirty-bitmap.c
> +++ b/block/dirty-bitmap.c
> @@ -29,6 +29,7 @@
>  
>  struct BdrvDirtyBitmap {
>      QemuMutex *mutex;
> +    BlockDriverState *bs;
>      HBitmap *bitmap;            /* Dirty bitmap implementation */
>      bool busy;                  /* Bitmap is busy, it can't be used via QMP */
>      BdrvDirtyBitmap *successor; /* Anonymous child, if any. */
> @@ -114,6 +115,7 @@ BdrvDirtyBitmap *bdrv_create_dirty_bitmap(BlockDriverState *bs,
>          return NULL;
>      }
>      bitmap = g_new0(BdrvDirtyBitmap, 1);
> +    bitmap->bs = bs;
>      bitmap->mutex = &bs->dirty_bitmap_mutex;
>      bitmap->bitmap = hbitmap_alloc(bitmap_size, ctz32(granularity));
>      bitmap->size = bitmap_size;
> @@ -236,8 +238,7 @@ int bdrv_dirty_bitmap_check(const BdrvDirtyBitmap *bitmap, uint32_t flags,
>   * The successor will be enabled if the parent bitmap was.
>   * Called with BQL taken.
>   */
> -int bdrv_dirty_bitmap_create_successor(BlockDriverState *bs,
> -                                       BdrvDirtyBitmap *bitmap, Error **errp)
> +int bdrv_dirty_bitmap_create_successor(BdrvDirtyBitmap *bitmap, Error **errp)
>  {
>      uint64_t granularity;
>      BdrvDirtyBitmap *child;
> @@ -253,7 +254,7 @@ int bdrv_dirty_bitmap_create_successor(BlockDriverState *bs,
>  
>      /* Create an anonymous successor */
>      granularity = bdrv_dirty_bitmap_granularity(bitmap);
> -    child = bdrv_create_dirty_bitmap(bs, granularity, NULL, errp);
> +    child = bdrv_create_dirty_bitmap(bitmap->bs, granularity, NULL, errp);
>      if (!child) {
>          return -1;
>      }
> @@ -299,8 +300,7 @@ static void bdrv_release_dirty_bitmap_locked(BdrvDirtyBitmap *bitmap)
>   * delete the old bitmap, and return a handle to the new bitmap.
>   * Called with BQL taken.
>   */
> -BdrvDirtyBitmap *bdrv_dirty_bitmap_abdicate(BlockDriverState *bs,
> -                                            BdrvDirtyBitmap *bitmap,
> +BdrvDirtyBitmap *bdrv_dirty_bitmap_abdicate(BdrvDirtyBitmap *bitmap,
>                                              Error **errp)
>  {
>      char *name;
> @@ -319,7 +319,7 @@ BdrvDirtyBitmap *bdrv_dirty_bitmap_abdicate(BlockDriverState *bs,
>      successor->persistent = bitmap->persistent;
>      bitmap->persistent = false;
>      bitmap->busy = false;
> -    bdrv_release_dirty_bitmap(bs, bitmap);
> +    bdrv_release_dirty_bitmap(bitmap);
>  
>      return successor;
>  }
> @@ -331,8 +331,7 @@ BdrvDirtyBitmap *bdrv_dirty_bitmap_abdicate(BlockDriverState *bs,
>   * The marged parent will be enabled if and only if the successor was enabled.
>   * Called within bdrv_dirty_bitmap_lock..unlock and with BQL taken.
>   */
> -BdrvDirtyBitmap *bdrv_reclaim_dirty_bitmap_locked(BlockDriverState *bs,
> -                                                  BdrvDirtyBitmap *parent,
> +BdrvDirtyBitmap *bdrv_reclaim_dirty_bitmap_locked(BdrvDirtyBitmap *parent,
>                                                    Error **errp)
>  {
>      BdrvDirtyBitmap *successor = parent->successor;
> @@ -356,14 +355,13 @@ BdrvDirtyBitmap *bdrv_reclaim_dirty_bitmap_locked(BlockDriverState *bs,
>  }
>  
>  /* Called with BQL taken. */
> -BdrvDirtyBitmap *bdrv_reclaim_dirty_bitmap(BlockDriverState *bs,
> -                                           BdrvDirtyBitmap *parent,
> +BdrvDirtyBitmap *bdrv_reclaim_dirty_bitmap(BdrvDirtyBitmap *parent,
>                                             Error **errp)
>  {
>      BdrvDirtyBitmap *ret;
>  
>      qemu_mutex_lock(parent->mutex);
> -    ret = bdrv_reclaim_dirty_bitmap_locked(bs, parent, errp);
> +    ret = bdrv_reclaim_dirty_bitmap_locked(parent, errp);
>      qemu_mutex_unlock(parent->mutex);
>  
>      return ret;
> @@ -389,8 +387,10 @@ void bdrv_dirty_bitmap_truncate(BlockDriverState *bs, int64_t bytes)
>  }
>  
>  /* Called with BQL taken.  */
> -void bdrv_release_dirty_bitmap(BlockDriverState *bs, BdrvDirtyBitmap *bitmap)
> +void bdrv_release_dirty_bitmap(BdrvDirtyBitmap *bitmap)
>  {
> +    BlockDriverState *bs = bitmap->bs;
> +
>      bdrv_dirty_bitmaps_lock(bs);
>      bdrv_release_dirty_bitmap_locked(bitmap);
>      bdrv_dirty_bitmaps_unlock(bs);
> diff --git a/block/mirror.c b/block/mirror.c
> index fe984efb90..a6c50caea4 100644
> --- a/block/mirror.c
> +++ b/block/mirror.c
> @@ -638,7 +638,7 @@ static int mirror_exit_common(Job *job)
>          bdrv_unfreeze_backing_chain(mirror_top_bs, target_bs);
>      }
>  
> -    bdrv_release_dirty_bitmap(src, s->dirty_bitmap);
> +    bdrv_release_dirty_bitmap(s->dirty_bitmap);
>  
>      /* Make sure that the source BDS doesn't go away during bdrv_replace_node,
>       * before we can call bdrv_drained_end */
> @@ -1709,7 +1709,7 @@ fail:
>          blk_unref(s->target);
>          bs_opaque->job = NULL;
>          if (s->dirty_bitmap) {
> -            bdrv_release_dirty_bitmap(bs, s->dirty_bitmap);
> +            bdrv_release_dirty_bitmap(s->dirty_bitmap);
>          }
>          job_early_fail(&s->common.job);
>      }
> diff --git a/block/qcow2-bitmap.c b/block/qcow2-bitmap.c
> index b2487101ed..6d795a2255 100644
> --- a/block/qcow2-bitmap.c
> +++ b/block/qcow2-bitmap.c
> @@ -374,7 +374,7 @@ static BdrvDirtyBitmap *load_bitmap(BlockDriverState *bs,
>  fail:
>      g_free(bitmap_table);
>      if (bitmap != NULL) {
> -        bdrv_release_dirty_bitmap(bs, bitmap);
> +        bdrv_release_dirty_bitmap(bitmap);
>      }
>  
>      return NULL;
> @@ -941,7 +941,7 @@ fail:
>  static void release_dirty_bitmap_helper(gpointer bitmap,
>                                          gpointer bs)
>  {
> -    bdrv_release_dirty_bitmap(bs, bitmap);
> +    bdrv_release_dirty_bitmap(bitmap);
>  }
>  
>  /* for g_slist_foreach for GSList of BdrvDirtyBitmap* elements */
> @@ -1569,7 +1569,7 @@ void qcow2_store_persistent_dirty_bitmaps(BlockDriverState *bs, Error **errp)
>              continue;
>          }
>  
> -        bdrv_release_dirty_bitmap(bs, bm->dirty_bitmap);
> +        bdrv_release_dirty_bitmap(bm->dirty_bitmap);
>      }
>  
>      bitmap_list_free(bm_list);
> diff --git a/blockdev.c b/blockdev.c
> index fbef6845c8..a8593fa0c1 100644
> --- a/blockdev.c
> +++ b/blockdev.c
> @@ -2178,7 +2178,7 @@ static void block_dirty_bitmap_remove_commit(BlkActionState *common)
>                                               common, common);
>  
>      bdrv_dirty_bitmap_set_busy(state->bitmap, false);
> -    bdrv_release_dirty_bitmap(state->bs, state->bitmap);
> +    bdrv_release_dirty_bitmap(state->bitmap);
>  }
>  
>  static void abort_prepare(BlkActionState *common, Error **errp)
> @@ -2954,7 +2954,7 @@ static BdrvDirtyBitmap *do_block_dirty_bitmap_remove(
>      }
>  
>      if (release) {
> -        bdrv_release_dirty_bitmap(bs, bitmap);
> +        bdrv_release_dirty_bitmap(bitmap);
>      }
>  
>      if (bitmap_bs) {
> @@ -3086,7 +3086,7 @@ static BdrvDirtyBitmap *do_block_dirty_bitmap_merge(
>      bdrv_merge_dirty_bitmap(dst, anon, backup, errp);
>  
>   out:
> -    bdrv_release_dirty_bitmap(bs, anon);
> +    bdrv_release_dirty_bitmap(anon);
>      return dst;
>  }
>  
> diff --git a/migration/block-dirty-bitmap.c b/migration/block-dirty-bitmap.c
> index 5121f86d73..793f249aa5 100644
> --- a/migration/block-dirty-bitmap.c
> +++ b/migration/block-dirty-bitmap.c
> @@ -474,7 +474,7 @@ static int dirty_bitmap_load_start(QEMUFile *f, DirtyBitmapLoadState *s)
>      if (flags & DIRTY_BITMAP_MIG_START_FLAG_ENABLED) {
>          DirtyBitmapLoadBitmapState *b;
>  
> -        bdrv_dirty_bitmap_create_successor(s->bs, s->bitmap, &local_err);
> +        bdrv_dirty_bitmap_create_successor(s->bitmap, &local_err);
>          if (local_err) {
>              error_report_err(local_err);
>              return -EINVAL;
> @@ -535,13 +535,12 @@ static void dirty_bitmap_load_complete(QEMUFile *f, DirtyBitmapLoadState *s)
>          bdrv_dirty_bitmap_lock(s->bitmap);
>          if (enabled_bitmaps == NULL) {
>              /* in postcopy */
> -            bdrv_reclaim_dirty_bitmap_locked(s->bs, s->bitmap, &error_abort);
> +            bdrv_reclaim_dirty_bitmap_locked(s->bitmap, &error_abort);
>              bdrv_enable_dirty_bitmap_locked(s->bitmap);
>          } else {
>              /* target not started, successor must be empty */
>              int64_t count = bdrv_get_dirty_count(s->bitmap);
> -            BdrvDirtyBitmap *ret = bdrv_reclaim_dirty_bitmap_locked(s->bs,
> -                                                                    s->bitmap,
> +            BdrvDirtyBitmap *ret = bdrv_reclaim_dirty_bitmap_locked(s->bitmap,
>                                                                      NULL);
>              /* bdrv_reclaim_dirty_bitmap can fail only on no successor (it
>               * must be) or on merge fail, but merge can't fail when second
> diff --git a/migration/block.c b/migration/block.c
> index 0de9d84198..0496b9b66e 100644
> --- a/migration/block.c
> +++ b/migration/block.c
> @@ -361,7 +361,7 @@ static int set_dirty_tracking(void)
>  fail:
>      QSIMPLEQ_FOREACH(bmds, &block_mig_state.bmds_list, entry) {
>          if (bmds->dirty_bitmap) {
> -            bdrv_release_dirty_bitmap(blk_bs(bmds->blk), bmds->dirty_bitmap);
> +            bdrv_release_dirty_bitmap(bmds->dirty_bitmap);
>          }
>      }
>      return ret;
> @@ -374,7 +374,7 @@ static void unset_dirty_tracking(void)
>      BlkMigDevState *bmds;
>  
>      QSIMPLEQ_FOREACH(bmds, &block_mig_state.bmds_list, entry) {
> -        bdrv_release_dirty_bitmap(blk_bs(bmds->blk), bmds->dirty_bitmap);
> +        bdrv_release_dirty_bitmap(bmds->dirty_bitmap);
>      }
>  }
>  
>

Patch
diff mbox series

diff --git a/include/block/dirty-bitmap.h b/include/block/dirty-bitmap.h
index 848dfc6590..4c58d922e4 100644
--- a/include/block/dirty-bitmap.h
+++ b/include/block/dirty-bitmap.h
@@ -18,21 +18,18 @@  BdrvDirtyBitmap *bdrv_create_dirty_bitmap(BlockDriverState *bs,
                                           uint32_t granularity,
                                           const char *name,
                                           Error **errp);
-int bdrv_dirty_bitmap_create_successor(BlockDriverState *bs,
-                                       BdrvDirtyBitmap *bitmap,
+int bdrv_dirty_bitmap_create_successor(BdrvDirtyBitmap *bitmap,
                                        Error **errp);
-BdrvDirtyBitmap *bdrv_dirty_bitmap_abdicate(BlockDriverState *bs,
-                                            BdrvDirtyBitmap *bitmap,
+BdrvDirtyBitmap *bdrv_dirty_bitmap_abdicate(BdrvDirtyBitmap *bitmap,
                                             Error **errp);
-BdrvDirtyBitmap *bdrv_reclaim_dirty_bitmap(BlockDriverState *bs,
-                                           BdrvDirtyBitmap *bitmap,
+BdrvDirtyBitmap *bdrv_reclaim_dirty_bitmap(BdrvDirtyBitmap *bitmap,
                                            Error **errp);
 void bdrv_dirty_bitmap_enable_successor(BdrvDirtyBitmap *bitmap);
 BdrvDirtyBitmap *bdrv_find_dirty_bitmap(BlockDriverState *bs,
                                         const char *name);
 int bdrv_dirty_bitmap_check(const BdrvDirtyBitmap *bitmap, uint32_t flags,
                             Error **errp);
-void bdrv_release_dirty_bitmap(BlockDriverState *bs, BdrvDirtyBitmap *bitmap);
+void bdrv_release_dirty_bitmap(BdrvDirtyBitmap *bitmap);
 void bdrv_release_named_dirty_bitmaps(BlockDriverState *bs);
 void bdrv_remove_persistent_dirty_bitmap(BlockDriverState *bs,
                                          const char *name,
@@ -107,8 +104,7 @@  int64_t bdrv_dirty_bitmap_next_zero(BdrvDirtyBitmap *bitmap, uint64_t offset,
                                     uint64_t bytes);
 bool bdrv_dirty_bitmap_next_dirty_area(BdrvDirtyBitmap *bitmap,
                                        uint64_t *offset, uint64_t *bytes);
-BdrvDirtyBitmap *bdrv_reclaim_dirty_bitmap_locked(BlockDriverState *bs,
-                                                  BdrvDirtyBitmap *bitmap,
+BdrvDirtyBitmap *bdrv_reclaim_dirty_bitmap_locked(BdrvDirtyBitmap *bitmap,
                                                   Error **errp);
 
 #endif
diff --git a/block/backup.c b/block/backup.c
index 763f0d7ff6..acb67da3a7 100644
--- a/block/backup.c
+++ b/block/backup.c
@@ -352,7 +352,6 @@  static int coroutine_fn backup_before_write_notify(
 static void backup_cleanup_sync_bitmap(BackupBlockJob *job, int ret)
 {
     BdrvDirtyBitmap *bm;
-    BlockDriverState *bs = blk_bs(job->common.blk);
     bool sync = (((ret == 0) || (job->bitmap_mode == BITMAP_SYNC_MODE_ALWAYS)) \
                  && (job->bitmap_mode != BITMAP_SYNC_MODE_NEVER));
 
@@ -361,13 +360,13 @@  static void backup_cleanup_sync_bitmap(BackupBlockJob *job, int ret)
          * We succeeded, or we always intended to sync the bitmap.
          * Delete this bitmap and install the child.
          */
-        bm = bdrv_dirty_bitmap_abdicate(bs, job->sync_bitmap, NULL);
+        bm = bdrv_dirty_bitmap_abdicate(job->sync_bitmap, NULL);
     } else {
         /*
          * We failed, or we never intended to sync the bitmap anyway.
          * Merge the successor back into the parent, keeping all data.
          */
-        bm = bdrv_reclaim_dirty_bitmap(bs, job->sync_bitmap, NULL);
+        bm = bdrv_reclaim_dirty_bitmap(job->sync_bitmap, NULL);
     }
 
     assert(bm);
@@ -398,10 +397,9 @@  static void backup_abort(Job *job)
 static void backup_clean(Job *job)
 {
     BackupBlockJob *s = container_of(job, BackupBlockJob, common.job);
-    BlockDriverState *bs = blk_bs(s->common.blk);
 
     if (s->copy_bitmap) {
-        bdrv_release_dirty_bitmap(bs, s->copy_bitmap);
+        bdrv_release_dirty_bitmap(s->copy_bitmap);
         s->copy_bitmap = NULL;
     }
 
@@ -679,7 +677,7 @@  BlockJob *backup_job_create(const char *job_id, BlockDriverState *bs,
         }
 
         /* Create a new bitmap, and freeze/disable this one. */
-        if (bdrv_dirty_bitmap_create_successor(bs, sync_bitmap, errp) < 0) {
+        if (bdrv_dirty_bitmap_create_successor(sync_bitmap, errp) < 0) {
             return NULL;
         }
     }
@@ -758,10 +756,10 @@  BlockJob *backup_job_create(const char *job_id, BlockDriverState *bs,
  error:
     if (copy_bitmap) {
         assert(!job || !job->copy_bitmap);
-        bdrv_release_dirty_bitmap(bs, copy_bitmap);
+        bdrv_release_dirty_bitmap(copy_bitmap);
     }
     if (sync_bitmap) {
-        bdrv_reclaim_dirty_bitmap(bs, sync_bitmap, NULL);
+        bdrv_reclaim_dirty_bitmap(sync_bitmap, NULL);
     }
     if (job) {
         backup_clean(&job->common.job);
diff --git a/block/dirty-bitmap.c b/block/dirty-bitmap.c
index acfc3077f1..f3dc7b3ca5 100644
--- a/block/dirty-bitmap.c
+++ b/block/dirty-bitmap.c
@@ -29,6 +29,7 @@ 
 
 struct BdrvDirtyBitmap {
     QemuMutex *mutex;
+    BlockDriverState *bs;
     HBitmap *bitmap;            /* Dirty bitmap implementation */
     bool busy;                  /* Bitmap is busy, it can't be used via QMP */
     BdrvDirtyBitmap *successor; /* Anonymous child, if any. */
@@ -114,6 +115,7 @@  BdrvDirtyBitmap *bdrv_create_dirty_bitmap(BlockDriverState *bs,
         return NULL;
     }
     bitmap = g_new0(BdrvDirtyBitmap, 1);
+    bitmap->bs = bs;
     bitmap->mutex = &bs->dirty_bitmap_mutex;
     bitmap->bitmap = hbitmap_alloc(bitmap_size, ctz32(granularity));
     bitmap->size = bitmap_size;
@@ -236,8 +238,7 @@  int bdrv_dirty_bitmap_check(const BdrvDirtyBitmap *bitmap, uint32_t flags,
  * The successor will be enabled if the parent bitmap was.
  * Called with BQL taken.
  */
-int bdrv_dirty_bitmap_create_successor(BlockDriverState *bs,
-                                       BdrvDirtyBitmap *bitmap, Error **errp)
+int bdrv_dirty_bitmap_create_successor(BdrvDirtyBitmap *bitmap, Error **errp)
 {
     uint64_t granularity;
     BdrvDirtyBitmap *child;
@@ -253,7 +254,7 @@  int bdrv_dirty_bitmap_create_successor(BlockDriverState *bs,
 
     /* Create an anonymous successor */
     granularity = bdrv_dirty_bitmap_granularity(bitmap);
-    child = bdrv_create_dirty_bitmap(bs, granularity, NULL, errp);
+    child = bdrv_create_dirty_bitmap(bitmap->bs, granularity, NULL, errp);
     if (!child) {
         return -1;
     }
@@ -299,8 +300,7 @@  static void bdrv_release_dirty_bitmap_locked(BdrvDirtyBitmap *bitmap)
  * delete the old bitmap, and return a handle to the new bitmap.
  * Called with BQL taken.
  */
-BdrvDirtyBitmap *bdrv_dirty_bitmap_abdicate(BlockDriverState *bs,
-                                            BdrvDirtyBitmap *bitmap,
+BdrvDirtyBitmap *bdrv_dirty_bitmap_abdicate(BdrvDirtyBitmap *bitmap,
                                             Error **errp)
 {
     char *name;
@@ -319,7 +319,7 @@  BdrvDirtyBitmap *bdrv_dirty_bitmap_abdicate(BlockDriverState *bs,
     successor->persistent = bitmap->persistent;
     bitmap->persistent = false;
     bitmap->busy = false;
-    bdrv_release_dirty_bitmap(bs, bitmap);
+    bdrv_release_dirty_bitmap(bitmap);
 
     return successor;
 }
@@ -331,8 +331,7 @@  BdrvDirtyBitmap *bdrv_dirty_bitmap_abdicate(BlockDriverState *bs,
  * The marged parent will be enabled if and only if the successor was enabled.
  * Called within bdrv_dirty_bitmap_lock..unlock and with BQL taken.
  */
-BdrvDirtyBitmap *bdrv_reclaim_dirty_bitmap_locked(BlockDriverState *bs,
-                                                  BdrvDirtyBitmap *parent,
+BdrvDirtyBitmap *bdrv_reclaim_dirty_bitmap_locked(BdrvDirtyBitmap *parent,
                                                   Error **errp)
 {
     BdrvDirtyBitmap *successor = parent->successor;
@@ -356,14 +355,13 @@  BdrvDirtyBitmap *bdrv_reclaim_dirty_bitmap_locked(BlockDriverState *bs,
 }
 
 /* Called with BQL taken. */
-BdrvDirtyBitmap *bdrv_reclaim_dirty_bitmap(BlockDriverState *bs,
-                                           BdrvDirtyBitmap *parent,
+BdrvDirtyBitmap *bdrv_reclaim_dirty_bitmap(BdrvDirtyBitmap *parent,
                                            Error **errp)
 {
     BdrvDirtyBitmap *ret;
 
     qemu_mutex_lock(parent->mutex);
-    ret = bdrv_reclaim_dirty_bitmap_locked(bs, parent, errp);
+    ret = bdrv_reclaim_dirty_bitmap_locked(parent, errp);
     qemu_mutex_unlock(parent->mutex);
 
     return ret;
@@ -389,8 +387,10 @@  void bdrv_dirty_bitmap_truncate(BlockDriverState *bs, int64_t bytes)
 }
 
 /* Called with BQL taken.  */
-void bdrv_release_dirty_bitmap(BlockDriverState *bs, BdrvDirtyBitmap *bitmap)
+void bdrv_release_dirty_bitmap(BdrvDirtyBitmap *bitmap)
 {
+    BlockDriverState *bs = bitmap->bs;
+
     bdrv_dirty_bitmaps_lock(bs);
     bdrv_release_dirty_bitmap_locked(bitmap);
     bdrv_dirty_bitmaps_unlock(bs);
diff --git a/block/mirror.c b/block/mirror.c
index fe984efb90..a6c50caea4 100644
--- a/block/mirror.c
+++ b/block/mirror.c
@@ -638,7 +638,7 @@  static int mirror_exit_common(Job *job)
         bdrv_unfreeze_backing_chain(mirror_top_bs, target_bs);
     }
 
-    bdrv_release_dirty_bitmap(src, s->dirty_bitmap);
+    bdrv_release_dirty_bitmap(s->dirty_bitmap);
 
     /* Make sure that the source BDS doesn't go away during bdrv_replace_node,
      * before we can call bdrv_drained_end */
@@ -1709,7 +1709,7 @@  fail:
         blk_unref(s->target);
         bs_opaque->job = NULL;
         if (s->dirty_bitmap) {
-            bdrv_release_dirty_bitmap(bs, s->dirty_bitmap);
+            bdrv_release_dirty_bitmap(s->dirty_bitmap);
         }
         job_early_fail(&s->common.job);
     }
diff --git a/block/qcow2-bitmap.c b/block/qcow2-bitmap.c
index b2487101ed..6d795a2255 100644
--- a/block/qcow2-bitmap.c
+++ b/block/qcow2-bitmap.c
@@ -374,7 +374,7 @@  static BdrvDirtyBitmap *load_bitmap(BlockDriverState *bs,
 fail:
     g_free(bitmap_table);
     if (bitmap != NULL) {
-        bdrv_release_dirty_bitmap(bs, bitmap);
+        bdrv_release_dirty_bitmap(bitmap);
     }
 
     return NULL;
@@ -941,7 +941,7 @@  fail:
 static void release_dirty_bitmap_helper(gpointer bitmap,
                                         gpointer bs)
 {
-    bdrv_release_dirty_bitmap(bs, bitmap);
+    bdrv_release_dirty_bitmap(bitmap);
 }
 
 /* for g_slist_foreach for GSList of BdrvDirtyBitmap* elements */
@@ -1569,7 +1569,7 @@  void qcow2_store_persistent_dirty_bitmaps(BlockDriverState *bs, Error **errp)
             continue;
         }
 
-        bdrv_release_dirty_bitmap(bs, bm->dirty_bitmap);
+        bdrv_release_dirty_bitmap(bm->dirty_bitmap);
     }
 
     bitmap_list_free(bm_list);
diff --git a/blockdev.c b/blockdev.c
index fbef6845c8..a8593fa0c1 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -2178,7 +2178,7 @@  static void block_dirty_bitmap_remove_commit(BlkActionState *common)
                                              common, common);
 
     bdrv_dirty_bitmap_set_busy(state->bitmap, false);
-    bdrv_release_dirty_bitmap(state->bs, state->bitmap);
+    bdrv_release_dirty_bitmap(state->bitmap);
 }
 
 static void abort_prepare(BlkActionState *common, Error **errp)
@@ -2954,7 +2954,7 @@  static BdrvDirtyBitmap *do_block_dirty_bitmap_remove(
     }
 
     if (release) {
-        bdrv_release_dirty_bitmap(bs, bitmap);
+        bdrv_release_dirty_bitmap(bitmap);
     }
 
     if (bitmap_bs) {
@@ -3086,7 +3086,7 @@  static BdrvDirtyBitmap *do_block_dirty_bitmap_merge(
     bdrv_merge_dirty_bitmap(dst, anon, backup, errp);
 
  out:
-    bdrv_release_dirty_bitmap(bs, anon);
+    bdrv_release_dirty_bitmap(anon);
     return dst;
 }
 
diff --git a/migration/block-dirty-bitmap.c b/migration/block-dirty-bitmap.c
index 5121f86d73..793f249aa5 100644
--- a/migration/block-dirty-bitmap.c
+++ b/migration/block-dirty-bitmap.c
@@ -474,7 +474,7 @@  static int dirty_bitmap_load_start(QEMUFile *f, DirtyBitmapLoadState *s)
     if (flags & DIRTY_BITMAP_MIG_START_FLAG_ENABLED) {
         DirtyBitmapLoadBitmapState *b;
 
-        bdrv_dirty_bitmap_create_successor(s->bs, s->bitmap, &local_err);
+        bdrv_dirty_bitmap_create_successor(s->bitmap, &local_err);
         if (local_err) {
             error_report_err(local_err);
             return -EINVAL;
@@ -535,13 +535,12 @@  static void dirty_bitmap_load_complete(QEMUFile *f, DirtyBitmapLoadState *s)
         bdrv_dirty_bitmap_lock(s->bitmap);
         if (enabled_bitmaps == NULL) {
             /* in postcopy */
-            bdrv_reclaim_dirty_bitmap_locked(s->bs, s->bitmap, &error_abort);
+            bdrv_reclaim_dirty_bitmap_locked(s->bitmap, &error_abort);
             bdrv_enable_dirty_bitmap_locked(s->bitmap);
         } else {
             /* target not started, successor must be empty */
             int64_t count = bdrv_get_dirty_count(s->bitmap);
-            BdrvDirtyBitmap *ret = bdrv_reclaim_dirty_bitmap_locked(s->bs,
-                                                                    s->bitmap,
+            BdrvDirtyBitmap *ret = bdrv_reclaim_dirty_bitmap_locked(s->bitmap,
                                                                     NULL);
             /* bdrv_reclaim_dirty_bitmap can fail only on no successor (it
              * must be) or on merge fail, but merge can't fail when second
diff --git a/migration/block.c b/migration/block.c
index 0de9d84198..0496b9b66e 100644
--- a/migration/block.c
+++ b/migration/block.c
@@ -361,7 +361,7 @@  static int set_dirty_tracking(void)
 fail:
     QSIMPLEQ_FOREACH(bmds, &block_mig_state.bmds_list, entry) {
         if (bmds->dirty_bitmap) {
-            bdrv_release_dirty_bitmap(blk_bs(bmds->blk), bmds->dirty_bitmap);
+            bdrv_release_dirty_bitmap(bmds->dirty_bitmap);
         }
     }
     return ret;
@@ -374,7 +374,7 @@  static void unset_dirty_tracking(void)
     BlkMigDevState *bmds;
 
     QSIMPLEQ_FOREACH(bmds, &block_mig_state.bmds_list, entry) {
-        bdrv_release_dirty_bitmap(blk_bs(bmds->blk), bmds->dirty_bitmap);
+        bdrv_release_dirty_bitmap(bmds->dirty_bitmap);
     }
 }