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

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