]> Git Repo - qemu.git/commitdiff
qcow2: store bitmaps on reopening image as read-only
authorVladimir Sementsov-Ogievskiy <[email protected]>
Wed, 28 Jun 2017 12:05:20 +0000 (15:05 +0300)
committerMax Reitz <[email protected]>
Tue, 11 Jul 2017 15:44:58 +0000 (17:44 +0200)
Store bitmaps and mark them read-only on reopening image as read-only.

Signed-off-by: Vladimir Sementsov-Ogievskiy <[email protected]>
Reviewed-by: Max Reitz <[email protected]>
Message-id: 20170628120530[email protected]
Signed-off-by: Max Reitz <[email protected]>
block/qcow2-bitmap.c
block/qcow2.c
block/qcow2.h

index 81c49aecdb91c18e493908c003d4ef237459d48b..f82478c02af994be519a1d8e39b74c94adec4571 100644 (file)
@@ -1366,3 +1366,25 @@ fail:
 
     bitmap_list_free(bm_list);
 }
+
+int qcow2_reopen_bitmaps_ro(BlockDriverState *bs, Error **errp)
+{
+    BdrvDirtyBitmap *bitmap;
+    Error *local_err = NULL;
+
+    qcow2_store_persistent_dirty_bitmaps(bs, &local_err);
+    if (local_err != NULL) {
+        error_propagate(errp, local_err);
+        return -EINVAL;
+    }
+
+    for (bitmap = bdrv_dirty_bitmap_next(bs, NULL); bitmap != NULL;
+         bitmap = bdrv_dirty_bitmap_next(bs, bitmap))
+    {
+        if (bdrv_dirty_bitmap_get_persistance(bitmap)) {
+            bdrv_dirty_bitmap_set_readonly(bitmap, true);
+        }
+    }
+
+    return 0;
+}
index 790b5b188f10a9d90df9c1c25d612d9586177f48..1a31f1d360b81d271be0273d4492df088c1559b9 100644 (file)
@@ -1555,6 +1555,11 @@ static int qcow2_reopen_prepare(BDRVReopenState *state,
 
     /* We need to write out any unwritten data if we reopen read-only. */
     if ((state->flags & BDRV_O_RDWR) == 0) {
+        ret = qcow2_reopen_bitmaps_ro(state->bs, errp);
+        if (ret < 0) {
+            goto fail;
+        }
+
         ret = bdrv_flush(state->bs);
         if (ret < 0) {
             goto fail;
index 308cefd0a60f87f154efe03e36fcc39621d4371f..1f80b5d8d44ea1fdfbfd3e53608b75c7d4794f28 100644 (file)
@@ -648,5 +648,6 @@ int qcow2_check_bitmaps_refcounts(BlockDriverState *bs, BdrvCheckResult *res,
 bool qcow2_load_autoloading_dirty_bitmaps(BlockDriverState *bs, Error **errp);
 int qcow2_reopen_bitmaps_rw(BlockDriverState *bs, Error **errp);
 void qcow2_store_persistent_dirty_bitmaps(BlockDriverState *bs, Error **errp);
+int qcow2_reopen_bitmaps_ro(BlockDriverState *bs, Error **errp);
 
 #endif
This page took 0.035671 seconds and 4 git commands to generate.