Skip to contentSkip to conversation

qcow2: add overlap check for bitmap directory

PATCH Superseded Vladimir Sementsov-Ogievskiy 2 participants 3 messages Jul 5, 2018 Block layer

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 qcow2: add overlap check for bitmap directory

If it appropriate for 3.0, let's push it. If not - then for 3.1 with fixed "since". Should I cc stable?

v3: - update Qcow2OverlapCheckFlags in qapi/block-core.json [Max]

v2: - squash 02 (indentation fix) to 01
- drop comment from qcow2_check_metadata_overlap()
- set @ign to QCOW2_OL_BITMAP_DIRECTORY for in-place case in bitmap_list_store. I don't think non-inplace case should be changed, as it don't touch active bitmap directory.

---
 qapi/block-core.json   | 21 ++++++++++++---------
 block/qcow2.h          | 45 ++++++++++++++++++++++++---------------------
 block/qcow2-bitmap.c   |  7 ++++++-
 block/qcow2-refcount.c | 10 ++++++++++
 block/qcow2.c          | 22 ++++++++++++++--------
 5 files changed, 66 insertions(+), 39 deletions(-)
qapi/block-core.json +12 -9
index 90e554ed0f..e7393e0313 100644
@@ -2695,18 +2695,21 @@
 # @template: Specifies a template mode which can be adjusted using the other
 #            flags, defaults to 'cached'
 #
+# @bitmap-directory: since 3.0
+#
 # Since: 2.9
 ##
 { 'struct': 'Qcow2OverlapCheckFlags',
-  'data': { '*template':       'Qcow2OverlapCheckMode',
-            '*main-header':    'bool',
-            '*active-l1':      'bool',
-            '*active-l2':      'bool',
-            '*refcount-table': 'bool',
-            '*refcount-block': 'bool',
-            '*snapshot-table': 'bool',
-            '*inactive-l1':    'bool',
-            '*inactive-l2':    'bool' } }
+  'data': { '*template':        'Qcow2OverlapCheckMode',
+            '*main-header':     'bool',
+            '*active-l1':       'bool',
+            '*active-l2':       'bool',
+            '*refcount-table':  'bool',
+            '*refcount-block':  'bool',
+            '*snapshot-table':  'bool',
+            '*inactive-l1':     'bool',
+            '*inactive-l2':     'bool',
+            '*bitmap-directory': 'bool' } }
 
 ##
 # @Qcow2OverlapChecks:
block/qcow2.h +24 -21

64 lines not on this page · raw message

block/qcow2-bitmap.c +6 -1
index 69485aa1de..ba978ad2aa 100644
@@ -775,7 +775,12 @@ static int bitmap_list_store(BlockDriverState *bs, Qcow2BitmapList *bm_list,
         }
     }
 
-    ret = qcow2_pre_write_overlap_check(bs, 0, dir_offset, dir_size);
+    /* Actually, even in in-place case ignoring QCOW2_OL_BITMAP_DIRECTORY is not
+     * necessary, because we drop QCOW2_AUTOCLEAR_BITMAPS when updating bitmap
+     * directory in-place (actually, turn-off the extension), which is checked
+     * in qcow2_check_metadata_overlap() */
+    ret = qcow2_pre_write_overlap_check(
+            bs, in_place ? QCOW2_OL_BITMAP_DIRECTORY : 0, dir_offset, dir_size);
     if (ret < 0) {
         goto fail;
     }
block/qcow2-refcount.c +10 -0
index 18c729aa27..1b9ecb1ca0 100644
@@ -2705,6 +2705,16 @@ int qcow2_check_metadata_overlap(BlockDriverState *bs, int ign, int64_t offset,
         }
     }
 
+    if ((chk & QCOW2_OL_BITMAP_DIRECTORY) &&
+        (s->autoclear_features & QCOW2_AUTOCLEAR_BITMAPS))
+    {
+        if (overlaps_with(s->bitmap_directory_offset,
+                          s->bitmap_directory_size))
+        {
+            return QCOW2_OL_BITMAP_DIRECTORY;
+        }
+    }
+
     return 0;
 }
 
block/qcow2.c +14 -8
index 2f9e58e0c4..af51220499 100644
@@ -676,6 +676,11 @@ static QemuOptsList qcow2_runtime_opts = {
             .help = "Check for unintended writes into an inactive L2 table",
         },
         {
+            .name = QCOW2_OPT_OVERLAP_BITMAP_DIRECTORY,
+            .type = QEMU_OPT_BOOL,
+            .help = "Check for unintended writes into the bitmap directory",
+        },
+        {
             .name = QCOW2_OPT_CACHE_SIZE,
             .type = QEMU_OPT_SIZE,
             .help = "Maximum combined metadata (L2 tables and refcount blocks) "
@@ -708,14 +713,15 @@ static QemuOptsList qcow2_runtime_opts = {
 };
 
 static const char *overlap_bool_option_names[QCOW2_OL_MAX_BITNR] = {
-    [QCOW2_OL_MAIN_HEADER_BITNR]    = QCOW2_OPT_OVERLAP_MAIN_HEADER,
-    [QCOW2_OL_ACTIVE_L1_BITNR]      = QCOW2_OPT_OVERLAP_ACTIVE_L1,
-    [QCOW2_OL_ACTIVE_L2_BITNR]      = QCOW2_OPT_OVERLAP_ACTIVE_L2,
-    [QCOW2_OL_REFCOUNT_TABLE_BITNR] = QCOW2_OPT_OVERLAP_REFCOUNT_TABLE,
-    [QCOW2_OL_REFCOUNT_BLOCK_BITNR] = QCOW2_OPT_OVERLAP_REFCOUNT_BLOCK,
-    [QCOW2_OL_SNAPSHOT_TABLE_BITNR] = QCOW2_OPT_OVERLAP_SNAPSHOT_TABLE,
-    [QCOW2_OL_INACTIVE_L1_BITNR]    = QCOW2_OPT_OVERLAP_INACTIVE_L1,
-    [QCOW2_OL_INACTIVE_L2_BITNR]    = QCOW2_OPT_OVERLAP_INACTIVE_L2,
+    [QCOW2_OL_MAIN_HEADER_BITNR]      = QCOW2_OPT_OVERLAP_MAIN_HEADER,
+    [QCOW2_OL_ACTIVE_L1_BITNR]        = QCOW2_OPT_OVERLAP_ACTIVE_L1,
+    [QCOW2_OL_ACTIVE_L2_BITNR]        = QCOW2_OPT_OVERLAP_ACTIVE_L2,
+    [QCOW2_OL_REFCOUNT_TABLE_BITNR]   = QCOW2_OPT_OVERLAP_REFCOUNT_TABLE,
+    [QCOW2_OL_REFCOUNT_BLOCK_BITNR]   = QCOW2_OPT_OVERLAP_REFCOUNT_BLOCK,
+    [QCOW2_OL_SNAPSHOT_TABLE_BITNR]   = QCOW2_OPT_OVERLAP_SNAPSHOT_TABLE,
+    [QCOW2_OL_INACTIVE_L1_BITNR]      = QCOW2_OPT_OVERLAP_INACTIVE_L1,
+    [QCOW2_OL_INACTIVE_L2_BITNR]      = QCOW2_OPT_OVERLAP_INACTIVE_L2,
+    [QCOW2_OL_BITMAP_DIRECTORY_BITNR] = QCOW2_OPT_OVERLAP_BITMAP_DIRECTORY,
 };
 
 static void cache_clean_timer_cb(void *opaque)
Signature · 1 line
2.11.1
#1 lore raw

Am 05.07.2018 um 11:21 hat Vladimir Sementsov-Ogievskiy geschrieben:

Quoted 42 lines

If it appropriate for 3.0, let's push it. If not - then for 3.1 with fixed "since". Should I cc stable?

v3: - update Qcow2OverlapCheckFlags in qapi/block-core.json [Max]

v2: - squash 02 (indentation fix) to 01
- drop comment from qcow2_check_metadata_overlap()
- set @ign to QCOW2_OL_BITMAP_DIRECTORY for in-place case in bitmap_list_store. I don't think non-inplace case should be changed, as it don't touch active bitmap directory.

---
 qapi/block-core.json   | 21 ++++++++++++---------
 block/qcow2.h          | 45 ++++++++++++++++++++++++---------------------
 block/qcow2-bitmap.c   |  7 ++++++-
 block/qcow2-refcount.c | 10 ++++++++++
 block/qcow2.c          | 22 ++++++++++++++--------
 5 files changed, 66 insertions(+), 39 deletions(-)
qapi/block-core.json +2 -9
index 90e554ed0f..e7393e0313 100644
@@ -2695,18 +2695,21 @@
 # @template: Specifies a template mode which can be adjusted using the other
 #            flags, defaults to 'cached'
 #
+# @bitmap-directory: since 3.0
+#
 # Since: 2.9
 ##
 { 'struct': 'Qcow2OverlapCheckFlags',
-  'data': { '*template':       'Qcow2OverlapCheckMode',
-            '*main-header':    'bool',
-            '*active-l1':      'bool',
-            '*active-l2':      'bool',
-            '*refcount-table': 'bool',
-            '*refcount-block': 'bool',
-            '*snapshot-table': 'bool',
-            '*inactive-l1':    'bool',
-            '*inactive-l2':    'bool' } }

qapi/block-core.json line 2712

Quoted 10 lines
qapi/block-core.json +10 -0
+  'data': { '*template':        'Qcow2OverlapCheckMode',
+            '*main-header':     'bool',
+            '*active-l1':       'bool',
+            '*active-l2':       'bool',
+            '*refcount-table':  'bool',
+            '*refcount-block':  'bool',
+            '*snapshot-table':  'bool',
+            '*inactive-l1':     'bool',
+            '*inactive-l2':     'bool',
+            '*bitmap-directory': 'bool' } }

Did you intend to add two spaces to each line? Because this still isn't aligned to the same column.

Kevin

#2 lore raw
Quoted 56 lines · Kevin Wolf

Am 05.07.2018 um 11:21 hat Vladimir Sementsov-Ogievskiy geschrieben:

Quoted 42 lines

If it appropriate for 3.0, let's push it. If not - then for 3.1 with fixed "since". Should I cc stable?

v3: - update Qcow2OverlapCheckFlags in qapi/block-core.json [Max]

v2: - squash 02 (indentation fix) to 01
- drop comment from qcow2_check_metadata_overlap()
- set @ign to QCOW2_OL_BITMAP_DIRECTORY for in-place case in bitmap_list_store. I don't think non-inplace case should be changed, as it don't touch active bitmap directory.

---
  qapi/block-core.json   | 21 ++++++++++++---------
  block/qcow2.h          | 45 ++++++++++++++++++++++++---------------------
  block/qcow2-bitmap.c   |  7 ++++++-
  block/qcow2-refcount.c | 10 ++++++++++
  block/qcow2.c          | 22 ++++++++++++++--------
  5 files changed, 66 insertions(+), 39 deletions(-)
qapi/block-core.json +2 -9
index 90e554ed0f..e7393e0313 100644
@@ -2695,18 +2695,21 @@
  # @template: Specifies a template mode which can be adjusted using the other
  #            flags, defaults to 'cached'
  #
+# @bitmap-directory: since 3.0
+#
  # Since: 2.9
  ##
  { 'struct': 'Qcow2OverlapCheckFlags',
-  'data': { '*template':       'Qcow2OverlapCheckMode',
-            '*main-header':    'bool',
-            '*active-l1':      'bool',
-            '*active-l2':      'bool',
-            '*refcount-table': 'bool',
-            '*refcount-block': 'bool',
-            '*snapshot-table': 'bool',
-            '*inactive-l1':    'bool',
-            '*inactive-l2':    'bool' } }

qapi/block-core.json line 2712

Quoted 10 lines
qapi/block-core.json +10 -0
+  'data': { '*template':        'Qcow2OverlapCheckMode',
+            '*main-header':     'bool',
+            '*active-l1':       'bool',
+            '*active-l2':       'bool',
+            '*refcount-table':  'bool',
+            '*refcount-block':  'bool',
+            '*snapshot-table':  'bool',
+            '*inactive-l1':     'bool',
+            '*inactive-l2':     'bool',
+            '*bitmap-directory': 'bool' } }

Did you intend to add two spaces to each line? Because this still isn't aligned to the same column.

Quoted 1 line

Kevin

Aha, I forget to add '*', and added it late, after indentation.

Signature · 2 lines
Best regards,
Vladimir