Blame SOURCES/kvm-block-dirty-bitmaps-unify-qmp_locked-and-user_locked.patch

383d26
From dc1a43268c8f0859cce105a0025c3b7affc6d52c Mon Sep 17 00:00:00 2001
383d26
From: John Snow <jsnow@redhat.com>
383d26
Date: Wed, 3 Apr 2019 18:18:45 +0200
383d26
Subject: [PATCH 140/163] block/dirty-bitmaps: unify qmp_locked and user_locked
383d26
 calls
383d26
383d26
RH-Author: John Snow <jsnow@redhat.com>
383d26
Message-id: <20190403181857.9693-10-jsnow@redhat.com>
383d26
Patchwork-id: 85417
383d26
O-Subject: [RHEL-7.7 qemu-kvm-rhev PATCH 09/21] block/dirty-bitmaps: unify qmp_locked and user_locked calls
383d26
Bugzilla: 1677073
383d26
RH-Acked-by: Max Reitz <mreitz@redhat.com>
383d26
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
383d26
RH-Acked-by: Sergio Lopez Pascual <slp@redhat.com>
383d26
383d26
These mean the same thing now. Unify them and rename the merged call
383d26
bdrv_dirty_bitmap_busy to indicate semantically what we are describing,
383d26
as well as help disambiguate from the various _locked and _unlocked
383d26
versions of bitmap helpers that refer to mutex locks.
383d26
383d26
Signed-off-by: John Snow <jsnow@redhat.com>
383d26
Reviewed-by: Eric Blake <eblake@redhat.com>
383d26
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
383d26
Message-id: 20190223000614.13894-8-jsnow@redhat.com
383d26
Signed-off-by: John Snow <jsnow@redhat.com>
383d26
(cherry picked from commit 27a1b301a448a0426a96716484fc034b73c10c51)
383d26
Signed-off-by: John Snow <jsnow@redhat.com>
383d26
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
383d26
---
383d26
 block/dirty-bitmap.c           | 43 +++++++++++++++++++-----------------------
383d26
 blockdev.c                     | 18 +++++++++---------
383d26
 include/block/dirty-bitmap.h   |  5 ++---
383d26
 migration/block-dirty-bitmap.c |  6 +++---
383d26
 nbd/server.c                   |  6 +++---
383d26
 5 files changed, 36 insertions(+), 42 deletions(-)
383d26
383d26
diff --git a/block/dirty-bitmap.c b/block/dirty-bitmap.c
383d26
index a495178..89c9665 100644
383d26
--- a/block/dirty-bitmap.c
383d26
+++ b/block/dirty-bitmap.c
383d26
@@ -48,8 +48,7 @@ struct BdrvDirtyBitmap {
383d26
     QemuMutex *mutex;
383d26
     HBitmap *bitmap;            /* Dirty bitmap implementation */
383d26
     HBitmap *meta;              /* Meta dirty bitmap */
383d26
-    bool qmp_locked;            /* Bitmap is locked, it can't be modified
383d26
-                                   through QMP */
383d26
+    bool busy;                  /* Bitmap is busy, it can't be used via QMP */
383d26
     BdrvDirtyBitmap *successor; /* Anonymous child, if any. */
383d26
     char *name;                 /* Optional non-empty unique ID */
383d26
     int64_t size;               /* Size of the bitmap, in bytes */
383d26
@@ -188,22 +187,18 @@ bool bdrv_dirty_bitmap_has_successor(BdrvDirtyBitmap *bitmap)
383d26
     return bitmap->successor;
383d26
 }
383d26
 
383d26
-bool bdrv_dirty_bitmap_user_locked(BdrvDirtyBitmap *bitmap) {
383d26
-    return bdrv_dirty_bitmap_qmp_locked(bitmap);
383d26
+bool bdrv_dirty_bitmap_busy(BdrvDirtyBitmap *bitmap)
383d26
+{
383d26
+    return bitmap->busy;
383d26
 }
383d26
 
383d26
-void bdrv_dirty_bitmap_set_qmp_locked(BdrvDirtyBitmap *bitmap, bool qmp_locked)
383d26
+void bdrv_dirty_bitmap_set_busy(BdrvDirtyBitmap *bitmap, bool busy)
383d26
 {
383d26
     qemu_mutex_lock(bitmap->mutex);
383d26
-    bitmap->qmp_locked = qmp_locked;
383d26
+    bitmap->busy = busy;
383d26
     qemu_mutex_unlock(bitmap->mutex);
383d26
 }
383d26
 
383d26
-bool bdrv_dirty_bitmap_qmp_locked(BdrvDirtyBitmap *bitmap)
383d26
-{
383d26
-    return bitmap->qmp_locked;
383d26
-}
383d26
-
383d26
 /* Called with BQL taken.  */
383d26
 bool bdrv_dirty_bitmap_enabled(BdrvDirtyBitmap *bitmap)
383d26
 {
383d26
@@ -215,7 +210,7 @@ DirtyBitmapStatus bdrv_dirty_bitmap_status(BdrvDirtyBitmap *bitmap)
383d26
 {
383d26
     if (bdrv_dirty_bitmap_has_successor(bitmap)) {
383d26
         return DIRTY_BITMAP_STATUS_FROZEN;
383d26
-    } else if (bdrv_dirty_bitmap_qmp_locked(bitmap)) {
383d26
+    } else if (bdrv_dirty_bitmap_busy(bitmap)) {
383d26
         return DIRTY_BITMAP_STATUS_LOCKED;
383d26
     } else if (!bdrv_dirty_bitmap_enabled(bitmap)) {
383d26
         return DIRTY_BITMAP_STATUS_DISABLED;
383d26
@@ -233,7 +228,7 @@ static bool bdrv_dirty_bitmap_recording(BdrvDirtyBitmap *bitmap)
383d26
 
383d26
 /**
383d26
  * Create a successor bitmap destined to replace this bitmap after an operation.
383d26
- * Requires that the bitmap is not user_locked and has no successor.
383d26
+ * Requires that the bitmap is not marked busy and has no successor.
383d26
  * The successor will be enabled if the parent bitmap was.
383d26
  * Called with BQL taken.
383d26
  */
383d26
@@ -243,7 +238,7 @@ int bdrv_dirty_bitmap_create_successor(BlockDriverState *bs,
383d26
     uint64_t granularity;
383d26
     BdrvDirtyBitmap *child;
383d26
 
383d26
-    if (bdrv_dirty_bitmap_user_locked(bitmap)) {
383d26
+    if (bdrv_dirty_bitmap_busy(bitmap)) {
383d26
         error_setg(errp, "Cannot create a successor for a bitmap that is "
383d26
                    "in-use by an operation");
383d26
         return -1;
383d26
@@ -265,9 +260,9 @@ int bdrv_dirty_bitmap_create_successor(BlockDriverState *bs,
383d26
     child->disabled = bitmap->disabled;
383d26
     bitmap->disabled = true;
383d26
 
383d26
-    /* Install the successor and lock the parent */
383d26
+    /* Install the successor and mark the parent as busy */
383d26
     bitmap->successor = child;
383d26
-    bitmap->qmp_locked = true;
383d26
+    bitmap->busy = true;
383d26
     return 0;
383d26
 }
383d26
 
383d26
@@ -289,7 +284,7 @@ void bdrv_dirty_bitmap_enable_successor(BdrvDirtyBitmap *bitmap)
383d26
 static void bdrv_release_dirty_bitmap_locked(BdrvDirtyBitmap *bitmap)
383d26
 {
383d26
     assert(!bitmap->active_iterators);
383d26
-    assert(!bdrv_dirty_bitmap_user_locked(bitmap));
383d26
+    assert(!bdrv_dirty_bitmap_busy(bitmap));
383d26
     assert(!bdrv_dirty_bitmap_has_successor(bitmap));
383d26
     assert(!bitmap->meta);
383d26
     QLIST_REMOVE(bitmap, list);
383d26
@@ -322,7 +317,7 @@ BdrvDirtyBitmap *bdrv_dirty_bitmap_abdicate(BlockDriverState *bs,
383d26
     bitmap->successor = NULL;
383d26
     successor->persistent = bitmap->persistent;
383d26
     bitmap->persistent = false;
383d26
-    bitmap->qmp_locked = false;
383d26
+    bitmap->busy = false;
383d26
     bdrv_release_dirty_bitmap(bs, bitmap);
383d26
 
383d26
     return successor;
383d26
@@ -331,7 +326,7 @@ BdrvDirtyBitmap *bdrv_dirty_bitmap_abdicate(BlockDriverState *bs,
383d26
 /**
383d26
  * In cases of failure where we can no longer safely delete the parent,
383d26
  * we may wish to re-join the parent and child/successor.
383d26
- * The merged parent will not be user_locked.
383d26
+ * The merged parent will be marked as not busy.
383d26
  * The marged parent will be enabled if and only if the successor was enabled.
383d26
  * Called within bdrv_dirty_bitmap_lock..unlock and with BQL taken.
383d26
  */
383d26
@@ -352,7 +347,7 @@ BdrvDirtyBitmap *bdrv_reclaim_dirty_bitmap_locked(BlockDriverState *bs,
383d26
     }
383d26
 
383d26
     parent->disabled = successor->disabled;
383d26
-    parent->qmp_locked = false;
383d26
+    parent->busy = false;
383d26
     bdrv_release_dirty_bitmap_locked(successor);
383d26
     parent->successor = NULL;
383d26
 
383d26
@@ -383,7 +378,7 @@ void bdrv_dirty_bitmap_truncate(BlockDriverState *bs, int64_t bytes)
383d26
 
383d26
     bdrv_dirty_bitmaps_lock(bs);
383d26
     QLIST_FOREACH(bitmap, &bs->dirty_bitmaps, list) {
383d26
-        assert(!bdrv_dirty_bitmap_user_locked(bitmap));
383d26
+        assert(!bdrv_dirty_bitmap_busy(bitmap));
383d26
         assert(!bdrv_dirty_bitmap_has_successor(bitmap));
383d26
         assert(!bitmap->active_iterators);
383d26
         hbitmap_truncate(bitmap->bitmap, bytes);
383d26
@@ -402,7 +397,7 @@ void bdrv_release_dirty_bitmap(BlockDriverState *bs, BdrvDirtyBitmap *bitmap)
383d26
 
383d26
 /**
383d26
  * Release all named dirty bitmaps attached to a BDS (for use in bdrv_close()).
383d26
- * There must not be any user_locked bitmaps attached.
383d26
+ * There must not be any busy bitmaps attached.
383d26
  * This function does not remove persistent bitmaps from the storage.
383d26
  * Called with BQL taken.
383d26
  */
383d26
@@ -466,7 +461,7 @@ BlockDirtyInfoList *bdrv_query_dirty_bitmaps(BlockDriverState *bs)
383d26
         info->name = g_strdup(bm->name);
383d26
         info->status = bdrv_dirty_bitmap_status(bm);
383d26
         info->recording = bdrv_dirty_bitmap_recording(bm);
383d26
-        info->busy = bdrv_dirty_bitmap_user_locked(bm);
383d26
+        info->busy = bdrv_dirty_bitmap_busy(bm);
383d26
         info->persistent = bm->persistent;
383d26
         entry->value = info;
383d26
         *plist = entry;
383d26
@@ -774,7 +769,7 @@ void bdrv_merge_dirty_bitmap(BdrvDirtyBitmap *dest, const BdrvDirtyBitmap *src,
383d26
 
383d26
     qemu_mutex_lock(dest->mutex);
383d26
 
383d26
-    if (bdrv_dirty_bitmap_user_locked(dest)) {
383d26
+    if (bdrv_dirty_bitmap_busy(dest)) {
383d26
         error_setg(errp, "Bitmap '%s' is currently in use by another"
383d26
         " operation and cannot be modified", dest->name);
383d26
         goto out;
383d26
diff --git a/blockdev.c b/blockdev.c
383d26
index f437896..c9ade12 100644
383d26
--- a/blockdev.c
383d26
+++ b/blockdev.c
383d26
@@ -2161,7 +2161,7 @@ static void block_dirty_bitmap_clear_prepare(BlkActionState *common,
383d26
         return;
383d26
     }
383d26
 
383d26
-    if (bdrv_dirty_bitmap_user_locked(state->bitmap)) {
383d26
+    if (bdrv_dirty_bitmap_busy(state->bitmap)) {
383d26
         error_setg(errp, "Cannot modify a bitmap in use by another operation");
383d26
         return;
383d26
     } else if (bdrv_dirty_bitmap_readonly(state->bitmap)) {
383d26
@@ -2210,7 +2210,7 @@ static void block_dirty_bitmap_enable_prepare(BlkActionState *common,
383d26
         return;
383d26
     }
383d26
 
383d26
-    if (bdrv_dirty_bitmap_user_locked(state->bitmap)) {
383d26
+    if (bdrv_dirty_bitmap_busy(state->bitmap)) {
383d26
         error_setg(errp,
383d26
                    "Bitmap '%s' is currently in use by another operation"
383d26
                    " and cannot be enabled", action->name);
383d26
@@ -2251,7 +2251,7 @@ static void block_dirty_bitmap_disable_prepare(BlkActionState *common,
383d26
         return;
383d26
     }
383d26
 
383d26
-    if (bdrv_dirty_bitmap_user_locked(state->bitmap)) {
383d26
+    if (bdrv_dirty_bitmap_busy(state->bitmap)) {
383d26
         error_setg(errp,
383d26
                    "Bitmap '%s' is currently in use by another operation"
383d26
                    " and cannot be disabled", action->name);
383d26
@@ -3045,7 +3045,7 @@ void qmp_block_dirty_bitmap_remove(const char *node, const char *name,
383d26
         return;
383d26
     }
383d26
 
383d26
-    if (bdrv_dirty_bitmap_user_locked(bitmap)) {
383d26
+    if (bdrv_dirty_bitmap_busy(bitmap)) {
383d26
         error_setg(errp,
383d26
                    "Bitmap '%s' is currently in use by another operation and"
383d26
                    " cannot be removed", name);
383d26
@@ -3084,7 +3084,7 @@ void qmp_block_dirty_bitmap_clear(const char *node, const char *name,
383d26
         return;
383d26
     }
383d26
 
383d26
-    if (bdrv_dirty_bitmap_user_locked(bitmap)) {
383d26
+    if (bdrv_dirty_bitmap_busy(bitmap)) {
383d26
         error_setg(errp,
383d26
                    "Bitmap '%s' is currently in use by another operation"
383d26
                    " and cannot be cleared", name);
383d26
@@ -3108,7 +3108,7 @@ void qmp_block_dirty_bitmap_enable(const char *node, const char *name,
383d26
         return;
383d26
     }
383d26
 
383d26
-    if (bdrv_dirty_bitmap_user_locked(bitmap)) {
383d26
+    if (bdrv_dirty_bitmap_busy(bitmap)) {
383d26
         error_setg(errp,
383d26
                    "Bitmap '%s' is currently in use by another operation"
383d26
                    " and cannot be enabled", name);
383d26
@@ -3129,7 +3129,7 @@ void qmp_block_dirty_bitmap_disable(const char *node, const char *name,
383d26
         return;
383d26
     }
383d26
 
383d26
-    if (bdrv_dirty_bitmap_user_locked(bitmap)) {
383d26
+    if (bdrv_dirty_bitmap_busy(bitmap)) {
383d26
         error_setg(errp,
383d26
                    "Bitmap '%s' is currently in use by another operation"
383d26
                    " and cannot be disabled", name);
383d26
@@ -3710,7 +3710,7 @@ static BlockJob *do_drive_backup(DriveBackup *backup, JobTxn *txn,
383d26
             bdrv_unref(target_bs);
383d26
             goto out;
383d26
         }
383d26
-        if (bdrv_dirty_bitmap_user_locked(bmap)) {
383d26
+        if (bdrv_dirty_bitmap_busy(bmap)) {
383d26
             error_setg(errp,
383d26
                        "Bitmap '%s' is currently in use by another operation"
383d26
                        " and cannot be used for backup", backup->bitmap);
383d26
@@ -3817,7 +3817,7 @@ BlockJob *do_blockdev_backup(BlockdevBackup *backup, JobTxn *txn,
383d26
             error_setg(errp, "Bitmap '%s' could not be found", backup->bitmap);
383d26
             goto out;
383d26
         }
383d26
-        if (bdrv_dirty_bitmap_user_locked(bmap)) {
383d26
+        if (bdrv_dirty_bitmap_busy(bmap)) {
383d26
             error_setg(errp,
383d26
                        "Bitmap '%s' is currently in use by another operation"
383d26
                        " and cannot be used for backup", backup->bitmap);
383d26
diff --git a/include/block/dirty-bitmap.h b/include/block/dirty-bitmap.h
383d26
index cdbb4df..ba8477b 100644
383d26
--- a/include/block/dirty-bitmap.h
383d26
+++ b/include/block/dirty-bitmap.h
383d26
@@ -68,7 +68,7 @@ void bdrv_dirty_bitmap_deserialize_finish(BdrvDirtyBitmap *bitmap);
383d26
 void bdrv_dirty_bitmap_set_readonly(BdrvDirtyBitmap *bitmap, bool value);
383d26
 void bdrv_dirty_bitmap_set_persistance(BdrvDirtyBitmap *bitmap,
383d26
                                        bool persistent);
383d26
-void bdrv_dirty_bitmap_set_qmp_locked(BdrvDirtyBitmap *bitmap, bool qmp_locked);
383d26
+void bdrv_dirty_bitmap_set_busy(BdrvDirtyBitmap *bitmap, bool busy);
383d26
 void bdrv_merge_dirty_bitmap(BdrvDirtyBitmap *dest, const BdrvDirtyBitmap *src,
383d26
                              HBitmap **backup, Error **errp);
383d26
 void bdrv_dirty_bitmap_set_migration(BdrvDirtyBitmap *bitmap, bool migration);
383d26
@@ -91,8 +91,7 @@ bool bdrv_dirty_bitmap_readonly(const BdrvDirtyBitmap *bitmap);
383d26
 bool bdrv_has_readonly_bitmaps(BlockDriverState *bs);
383d26
 bool bdrv_dirty_bitmap_get_autoload(const BdrvDirtyBitmap *bitmap);
383d26
 bool bdrv_dirty_bitmap_get_persistance(BdrvDirtyBitmap *bitmap);
383d26
-bool bdrv_dirty_bitmap_qmp_locked(BdrvDirtyBitmap *bitmap);
383d26
-bool bdrv_dirty_bitmap_user_locked(BdrvDirtyBitmap *bitmap);
383d26
+bool bdrv_dirty_bitmap_busy(BdrvDirtyBitmap *bitmap);
383d26
 bool bdrv_has_changed_persistent_bitmaps(BlockDriverState *bs);
383d26
 BdrvDirtyBitmap *bdrv_dirty_bitmap_next(BlockDriverState *bs,
383d26
                                         BdrvDirtyBitmap *bitmap);
383d26
diff --git a/migration/block-dirty-bitmap.c b/migration/block-dirty-bitmap.c
383d26
index 89b2a2f..62f2806 100644
383d26
--- a/migration/block-dirty-bitmap.c
383d26
+++ b/migration/block-dirty-bitmap.c
383d26
@@ -261,7 +261,7 @@ static void dirty_bitmap_mig_cleanup(void)
383d26
 
383d26
     while ((dbms = QSIMPLEQ_FIRST(&dirty_bitmap_mig_state.dbms_list)) != NULL) {
383d26
         QSIMPLEQ_REMOVE_HEAD(&dirty_bitmap_mig_state.dbms_list, entry);
383d26
-        bdrv_dirty_bitmap_set_qmp_locked(dbms->bitmap, false);
383d26
+        bdrv_dirty_bitmap_set_busy(dbms->bitmap, false);
383d26
         bdrv_unref(dbms->bs);
383d26
         g_free(dbms);
383d26
     }
383d26
@@ -301,7 +301,7 @@ static int init_dirty_bitmap_migration(void)
383d26
                 goto fail;
383d26
             }
383d26
 
383d26
-            if (bdrv_dirty_bitmap_user_locked(bitmap)) {
383d26
+            if (bdrv_dirty_bitmap_busy(bitmap)) {
383d26
                 error_report("Can't migrate a bitmap that is in use by another operation: '%s'",
383d26
                              bdrv_dirty_bitmap_name(bitmap));
383d26
                 goto fail;
383d26
@@ -314,7 +314,7 @@ static int init_dirty_bitmap_migration(void)
383d26
             }
383d26
 
383d26
             bdrv_ref(bs);
383d26
-            bdrv_dirty_bitmap_set_qmp_locked(bitmap, true);
383d26
+            bdrv_dirty_bitmap_set_busy(bitmap, true);
383d26
 
383d26
             dbms = g_new0(DirtyBitmapMigBitmapState, 1);
383d26
             dbms->bs = bs;
383d26
diff --git a/nbd/server.c b/nbd/server.c
383d26
index de21c64..02773e2 100644
383d26
--- a/nbd/server.c
383d26
+++ b/nbd/server.c
383d26
@@ -1510,7 +1510,7 @@ NBDExport *nbd_export_new(BlockDriverState *bs, uint64_t dev_offset,
383d26
             goto fail;
383d26
         }
383d26
 
383d26
-        if (bdrv_dirty_bitmap_user_locked(bm)) {
383d26
+        if (bdrv_dirty_bitmap_busy(bm)) {
383d26
             error_setg(errp, "Bitmap '%s' is in use", bitmap);
383d26
             goto fail;
383d26
         }
383d26
@@ -1523,7 +1523,7 @@ NBDExport *nbd_export_new(BlockDriverState *bs, uint64_t dev_offset,
383d26
             goto fail;
383d26
         }
383d26
 
383d26
-        bdrv_dirty_bitmap_set_qmp_locked(bm, true);
383d26
+        bdrv_dirty_bitmap_set_busy(bm, true);
383d26
         exp->export_bitmap = bm;
383d26
         exp->export_bitmap_context = g_strdup_printf("qemu:dirty-bitmap:%s",
383d26
                                                      bitmap);
383d26
@@ -1641,7 +1641,7 @@ void nbd_export_put(NBDExport *exp)
383d26
         }
383d26
 
383d26
         if (exp->export_bitmap) {
383d26
-            bdrv_dirty_bitmap_set_qmp_locked(exp->export_bitmap, false);
383d26
+            bdrv_dirty_bitmap_set_busy(exp->export_bitmap, false);
383d26
             g_free(exp->export_bitmap_context);
383d26
         }
383d26
 
383d26
-- 
383d26
1.8.3.1
383d26