|
|
1bdc94 |
From 1b36ea8bc4840907b78867ae040231fe91f12851 Mon Sep 17 00:00:00 2001
|
|
|
1bdc94 |
From: John Snow <jsnow@redhat.com>
|
|
|
1bdc94 |
Date: Wed, 18 Jul 2018 22:54:45 +0200
|
|
|
1bdc94 |
Subject: [PATCH 60/89] qcow2: add overlap check for bitmap directory
|
|
|
1bdc94 |
|
|
|
1bdc94 |
RH-Author: John Snow <jsnow@redhat.com>
|
|
|
1bdc94 |
Message-id: <20180718225511.14878-10-jsnow@redhat.com>
|
|
|
1bdc94 |
Patchwork-id: 81394
|
|
|
1bdc94 |
O-Subject: [RHEL-7.6 qemu-kvm-rhev PATCH 09/35] qcow2: add overlap check for bitmap directory
|
|
|
1bdc94 |
Bugzilla: 1207657
|
|
|
1bdc94 |
RH-Acked-by: Eric Blake <eblake@redhat.com>
|
|
|
1bdc94 |
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
|
|
|
1bdc94 |
RH-Acked-by: Fam Zheng <famz@redhat.com>
|
|
|
1bdc94 |
|
|
|
1bdc94 |
From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
|
|
|
1bdc94 |
|
|
|
1bdc94 |
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
|
|
|
1bdc94 |
Message-id: 20180705151515.779173-1-vsementsov@virtuozzo.com
|
|
|
1bdc94 |
Signed-off-by: Max Reitz <mreitz@redhat.com>
|
|
|
1bdc94 |
(cherry picked from commit 0e4e4318eaa56c831001bdf617094807ec6d451c)
|
|
|
1bdc94 |
Signed-off-by: John Snow <jsnow@redhat.com>
|
|
|
1bdc94 |
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
|
|
|
1bdc94 |
---
|
|
|
1bdc94 |
block/qcow2-bitmap.c | 7 ++++++-
|
|
|
1bdc94 |
block/qcow2-refcount.c | 10 ++++++++++
|
|
|
1bdc94 |
block/qcow2.c | 22 ++++++++++++++--------
|
|
|
1bdc94 |
block/qcow2.h | 45 ++++++++++++++++++++++++---------------------
|
|
|
1bdc94 |
qapi/block-core.json | 21 ++++++++++++---------
|
|
|
1bdc94 |
5 files changed, 66 insertions(+), 39 deletions(-)
|
|
|
1bdc94 |
|
|
|
1bdc94 |
diff --git a/block/qcow2-bitmap.c b/block/qcow2-bitmap.c
|
|
|
1bdc94 |
index 3e4e4e4..14050eb 100644
|
|
|
1bdc94 |
--- a/block/qcow2-bitmap.c
|
|
|
1bdc94 |
+++ b/block/qcow2-bitmap.c
|
|
|
1bdc94 |
@@ -775,7 +775,12 @@ static int bitmap_list_store(BlockDriverState *bs, Qcow2BitmapList *bm_list,
|
|
|
1bdc94 |
}
|
|
|
1bdc94 |
}
|
|
|
1bdc94 |
|
|
|
1bdc94 |
- ret = qcow2_pre_write_overlap_check(bs, 0, dir_offset, dir_size);
|
|
|
1bdc94 |
+ /* Actually, even in in-place case ignoring QCOW2_OL_BITMAP_DIRECTORY is not
|
|
|
1bdc94 |
+ * necessary, because we drop QCOW2_AUTOCLEAR_BITMAPS when updating bitmap
|
|
|
1bdc94 |
+ * directory in-place (actually, turn-off the extension), which is checked
|
|
|
1bdc94 |
+ * in qcow2_check_metadata_overlap() */
|
|
|
1bdc94 |
+ ret = qcow2_pre_write_overlap_check(
|
|
|
1bdc94 |
+ bs, in_place ? QCOW2_OL_BITMAP_DIRECTORY : 0, dir_offset, dir_size);
|
|
|
1bdc94 |
if (ret < 0) {
|
|
|
1bdc94 |
goto fail;
|
|
|
1bdc94 |
}
|
|
|
1bdc94 |
diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c
|
|
|
1bdc94 |
index 4e14c0a..1307069 100644
|
|
|
1bdc94 |
--- a/block/qcow2-refcount.c
|
|
|
1bdc94 |
+++ b/block/qcow2-refcount.c
|
|
|
1bdc94 |
@@ -2705,6 +2705,16 @@ int qcow2_check_metadata_overlap(BlockDriverState *bs, int ign, int64_t offset,
|
|
|
1bdc94 |
}
|
|
|
1bdc94 |
}
|
|
|
1bdc94 |
|
|
|
1bdc94 |
+ if ((chk & QCOW2_OL_BITMAP_DIRECTORY) &&
|
|
|
1bdc94 |
+ (s->autoclear_features & QCOW2_AUTOCLEAR_BITMAPS))
|
|
|
1bdc94 |
+ {
|
|
|
1bdc94 |
+ if (overlaps_with(s->bitmap_directory_offset,
|
|
|
1bdc94 |
+ s->bitmap_directory_size))
|
|
|
1bdc94 |
+ {
|
|
|
1bdc94 |
+ return QCOW2_OL_BITMAP_DIRECTORY;
|
|
|
1bdc94 |
+ }
|
|
|
1bdc94 |
+ }
|
|
|
1bdc94 |
+
|
|
|
1bdc94 |
return 0;
|
|
|
1bdc94 |
}
|
|
|
1bdc94 |
|
|
|
1bdc94 |
diff --git a/block/qcow2.c b/block/qcow2.c
|
|
|
1bdc94 |
index 71fbfcd..c5341a4 100644
|
|
|
1bdc94 |
--- a/block/qcow2.c
|
|
|
1bdc94 |
+++ b/block/qcow2.c
|
|
|
1bdc94 |
@@ -676,6 +676,11 @@ static QemuOptsList qcow2_runtime_opts = {
|
|
|
1bdc94 |
.help = "Check for unintended writes into an inactive L2 table",
|
|
|
1bdc94 |
},
|
|
|
1bdc94 |
{
|
|
|
1bdc94 |
+ .name = QCOW2_OPT_OVERLAP_BITMAP_DIRECTORY,
|
|
|
1bdc94 |
+ .type = QEMU_OPT_BOOL,
|
|
|
1bdc94 |
+ .help = "Check for unintended writes into the bitmap directory",
|
|
|
1bdc94 |
+ },
|
|
|
1bdc94 |
+ {
|
|
|
1bdc94 |
.name = QCOW2_OPT_CACHE_SIZE,
|
|
|
1bdc94 |
.type = QEMU_OPT_SIZE,
|
|
|
1bdc94 |
.help = "Maximum combined metadata (L2 tables and refcount blocks) "
|
|
|
1bdc94 |
@@ -708,14 +713,15 @@ static QemuOptsList qcow2_runtime_opts = {
|
|
|
1bdc94 |
};
|
|
|
1bdc94 |
|
|
|
1bdc94 |
static const char *overlap_bool_option_names[QCOW2_OL_MAX_BITNR] = {
|
|
|
1bdc94 |
- [QCOW2_OL_MAIN_HEADER_BITNR] = QCOW2_OPT_OVERLAP_MAIN_HEADER,
|
|
|
1bdc94 |
- [QCOW2_OL_ACTIVE_L1_BITNR] = QCOW2_OPT_OVERLAP_ACTIVE_L1,
|
|
|
1bdc94 |
- [QCOW2_OL_ACTIVE_L2_BITNR] = QCOW2_OPT_OVERLAP_ACTIVE_L2,
|
|
|
1bdc94 |
- [QCOW2_OL_REFCOUNT_TABLE_BITNR] = QCOW2_OPT_OVERLAP_REFCOUNT_TABLE,
|
|
|
1bdc94 |
- [QCOW2_OL_REFCOUNT_BLOCK_BITNR] = QCOW2_OPT_OVERLAP_REFCOUNT_BLOCK,
|
|
|
1bdc94 |
- [QCOW2_OL_SNAPSHOT_TABLE_BITNR] = QCOW2_OPT_OVERLAP_SNAPSHOT_TABLE,
|
|
|
1bdc94 |
- [QCOW2_OL_INACTIVE_L1_BITNR] = QCOW2_OPT_OVERLAP_INACTIVE_L1,
|
|
|
1bdc94 |
- [QCOW2_OL_INACTIVE_L2_BITNR] = QCOW2_OPT_OVERLAP_INACTIVE_L2,
|
|
|
1bdc94 |
+ [QCOW2_OL_MAIN_HEADER_BITNR] = QCOW2_OPT_OVERLAP_MAIN_HEADER,
|
|
|
1bdc94 |
+ [QCOW2_OL_ACTIVE_L1_BITNR] = QCOW2_OPT_OVERLAP_ACTIVE_L1,
|
|
|
1bdc94 |
+ [QCOW2_OL_ACTIVE_L2_BITNR] = QCOW2_OPT_OVERLAP_ACTIVE_L2,
|
|
|
1bdc94 |
+ [QCOW2_OL_REFCOUNT_TABLE_BITNR] = QCOW2_OPT_OVERLAP_REFCOUNT_TABLE,
|
|
|
1bdc94 |
+ [QCOW2_OL_REFCOUNT_BLOCK_BITNR] = QCOW2_OPT_OVERLAP_REFCOUNT_BLOCK,
|
|
|
1bdc94 |
+ [QCOW2_OL_SNAPSHOT_TABLE_BITNR] = QCOW2_OPT_OVERLAP_SNAPSHOT_TABLE,
|
|
|
1bdc94 |
+ [QCOW2_OL_INACTIVE_L1_BITNR] = QCOW2_OPT_OVERLAP_INACTIVE_L1,
|
|
|
1bdc94 |
+ [QCOW2_OL_INACTIVE_L2_BITNR] = QCOW2_OPT_OVERLAP_INACTIVE_L2,
|
|
|
1bdc94 |
+ [QCOW2_OL_BITMAP_DIRECTORY_BITNR] = QCOW2_OPT_OVERLAP_BITMAP_DIRECTORY,
|
|
|
1bdc94 |
};
|
|
|
1bdc94 |
|
|
|
1bdc94 |
static void cache_clean_timer_cb(void *opaque)
|
|
|
1bdc94 |
diff --git a/block/qcow2.h b/block/qcow2.h
|
|
|
1bdc94 |
index b5e2aa3..d2c63e4 100644
|
|
|
1bdc94 |
--- a/block/qcow2.h
|
|
|
1bdc94 |
+++ b/block/qcow2.h
|
|
|
1bdc94 |
@@ -98,6 +98,7 @@
|
|
|
1bdc94 |
#define QCOW2_OPT_OVERLAP_SNAPSHOT_TABLE "overlap-check.snapshot-table"
|
|
|
1bdc94 |
#define QCOW2_OPT_OVERLAP_INACTIVE_L1 "overlap-check.inactive-l1"
|
|
|
1bdc94 |
#define QCOW2_OPT_OVERLAP_INACTIVE_L2 "overlap-check.inactive-l2"
|
|
|
1bdc94 |
+#define QCOW2_OPT_OVERLAP_BITMAP_DIRECTORY "overlap-check.bitmap-directory"
|
|
|
1bdc94 |
#define QCOW2_OPT_CACHE_SIZE "cache-size"
|
|
|
1bdc94 |
#define QCOW2_OPT_L2_CACHE_SIZE "l2-cache-size"
|
|
|
1bdc94 |
#define QCOW2_OPT_L2_CACHE_ENTRY_SIZE "l2-cache-entry-size"
|
|
|
1bdc94 |
@@ -401,34 +402,36 @@ typedef enum QCow2ClusterType {
|
|
|
1bdc94 |
} QCow2ClusterType;
|
|
|
1bdc94 |
|
|
|
1bdc94 |
typedef enum QCow2MetadataOverlap {
|
|
|
1bdc94 |
- QCOW2_OL_MAIN_HEADER_BITNR = 0,
|
|
|
1bdc94 |
- QCOW2_OL_ACTIVE_L1_BITNR = 1,
|
|
|
1bdc94 |
- QCOW2_OL_ACTIVE_L2_BITNR = 2,
|
|
|
1bdc94 |
- QCOW2_OL_REFCOUNT_TABLE_BITNR = 3,
|
|
|
1bdc94 |
- QCOW2_OL_REFCOUNT_BLOCK_BITNR = 4,
|
|
|
1bdc94 |
- QCOW2_OL_SNAPSHOT_TABLE_BITNR = 5,
|
|
|
1bdc94 |
- QCOW2_OL_INACTIVE_L1_BITNR = 6,
|
|
|
1bdc94 |
- QCOW2_OL_INACTIVE_L2_BITNR = 7,
|
|
|
1bdc94 |
-
|
|
|
1bdc94 |
- QCOW2_OL_MAX_BITNR = 8,
|
|
|
1bdc94 |
-
|
|
|
1bdc94 |
- QCOW2_OL_NONE = 0,
|
|
|
1bdc94 |
- QCOW2_OL_MAIN_HEADER = (1 << QCOW2_OL_MAIN_HEADER_BITNR),
|
|
|
1bdc94 |
- QCOW2_OL_ACTIVE_L1 = (1 << QCOW2_OL_ACTIVE_L1_BITNR),
|
|
|
1bdc94 |
- QCOW2_OL_ACTIVE_L2 = (1 << QCOW2_OL_ACTIVE_L2_BITNR),
|
|
|
1bdc94 |
- QCOW2_OL_REFCOUNT_TABLE = (1 << QCOW2_OL_REFCOUNT_TABLE_BITNR),
|
|
|
1bdc94 |
- QCOW2_OL_REFCOUNT_BLOCK = (1 << QCOW2_OL_REFCOUNT_BLOCK_BITNR),
|
|
|
1bdc94 |
- QCOW2_OL_SNAPSHOT_TABLE = (1 << QCOW2_OL_SNAPSHOT_TABLE_BITNR),
|
|
|
1bdc94 |
- QCOW2_OL_INACTIVE_L1 = (1 << QCOW2_OL_INACTIVE_L1_BITNR),
|
|
|
1bdc94 |
+ QCOW2_OL_MAIN_HEADER_BITNR = 0,
|
|
|
1bdc94 |
+ QCOW2_OL_ACTIVE_L1_BITNR = 1,
|
|
|
1bdc94 |
+ QCOW2_OL_ACTIVE_L2_BITNR = 2,
|
|
|
1bdc94 |
+ QCOW2_OL_REFCOUNT_TABLE_BITNR = 3,
|
|
|
1bdc94 |
+ QCOW2_OL_REFCOUNT_BLOCK_BITNR = 4,
|
|
|
1bdc94 |
+ QCOW2_OL_SNAPSHOT_TABLE_BITNR = 5,
|
|
|
1bdc94 |
+ QCOW2_OL_INACTIVE_L1_BITNR = 6,
|
|
|
1bdc94 |
+ QCOW2_OL_INACTIVE_L2_BITNR = 7,
|
|
|
1bdc94 |
+ QCOW2_OL_BITMAP_DIRECTORY_BITNR = 8,
|
|
|
1bdc94 |
+
|
|
|
1bdc94 |
+ QCOW2_OL_MAX_BITNR = 9,
|
|
|
1bdc94 |
+
|
|
|
1bdc94 |
+ QCOW2_OL_NONE = 0,
|
|
|
1bdc94 |
+ QCOW2_OL_MAIN_HEADER = (1 << QCOW2_OL_MAIN_HEADER_BITNR),
|
|
|
1bdc94 |
+ QCOW2_OL_ACTIVE_L1 = (1 << QCOW2_OL_ACTIVE_L1_BITNR),
|
|
|
1bdc94 |
+ QCOW2_OL_ACTIVE_L2 = (1 << QCOW2_OL_ACTIVE_L2_BITNR),
|
|
|
1bdc94 |
+ QCOW2_OL_REFCOUNT_TABLE = (1 << QCOW2_OL_REFCOUNT_TABLE_BITNR),
|
|
|
1bdc94 |
+ QCOW2_OL_REFCOUNT_BLOCK = (1 << QCOW2_OL_REFCOUNT_BLOCK_BITNR),
|
|
|
1bdc94 |
+ QCOW2_OL_SNAPSHOT_TABLE = (1 << QCOW2_OL_SNAPSHOT_TABLE_BITNR),
|
|
|
1bdc94 |
+ QCOW2_OL_INACTIVE_L1 = (1 << QCOW2_OL_INACTIVE_L1_BITNR),
|
|
|
1bdc94 |
/* NOTE: Checking overlaps with inactive L2 tables will result in bdrv
|
|
|
1bdc94 |
* reads. */
|
|
|
1bdc94 |
- QCOW2_OL_INACTIVE_L2 = (1 << QCOW2_OL_INACTIVE_L2_BITNR),
|
|
|
1bdc94 |
+ QCOW2_OL_INACTIVE_L2 = (1 << QCOW2_OL_INACTIVE_L2_BITNR),
|
|
|
1bdc94 |
+ QCOW2_OL_BITMAP_DIRECTORY = (1 << QCOW2_OL_BITMAP_DIRECTORY_BITNR),
|
|
|
1bdc94 |
} QCow2MetadataOverlap;
|
|
|
1bdc94 |
|
|
|
1bdc94 |
/* Perform all overlap checks which can be done in constant time */
|
|
|
1bdc94 |
#define QCOW2_OL_CONSTANT \
|
|
|
1bdc94 |
(QCOW2_OL_MAIN_HEADER | QCOW2_OL_ACTIVE_L1 | QCOW2_OL_REFCOUNT_TABLE | \
|
|
|
1bdc94 |
- QCOW2_OL_SNAPSHOT_TABLE)
|
|
|
1bdc94 |
+ QCOW2_OL_SNAPSHOT_TABLE | QCOW2_OL_BITMAP_DIRECTORY)
|
|
|
1bdc94 |
|
|
|
1bdc94 |
/* Perform all overlap checks which don't require disk access */
|
|
|
1bdc94 |
#define QCOW2_OL_CACHED \
|
|
|
1bdc94 |
diff --git a/qapi/block-core.json b/qapi/block-core.json
|
|
|
1bdc94 |
index 27ed91b..69e0cf8 100644
|
|
|
1bdc94 |
--- a/qapi/block-core.json
|
|
|
1bdc94 |
+++ b/qapi/block-core.json
|
|
|
1bdc94 |
@@ -2666,18 +2666,21 @@
|
|
|
1bdc94 |
# @template: Specifies a template mode which can be adjusted using the other
|
|
|
1bdc94 |
# flags, defaults to 'cached'
|
|
|
1bdc94 |
#
|
|
|
1bdc94 |
+# @bitmap-directory: since 3.0
|
|
|
1bdc94 |
+#
|
|
|
1bdc94 |
# Since: 2.9
|
|
|
1bdc94 |
##
|
|
|
1bdc94 |
{ 'struct': 'Qcow2OverlapCheckFlags',
|
|
|
1bdc94 |
- 'data': { '*template': 'Qcow2OverlapCheckMode',
|
|
|
1bdc94 |
- '*main-header': 'bool',
|
|
|
1bdc94 |
- '*active-l1': 'bool',
|
|
|
1bdc94 |
- '*active-l2': 'bool',
|
|
|
1bdc94 |
- '*refcount-table': 'bool',
|
|
|
1bdc94 |
- '*refcount-block': 'bool',
|
|
|
1bdc94 |
- '*snapshot-table': 'bool',
|
|
|
1bdc94 |
- '*inactive-l1': 'bool',
|
|
|
1bdc94 |
- '*inactive-l2': 'bool' } }
|
|
|
1bdc94 |
+ 'data': { '*template': 'Qcow2OverlapCheckMode',
|
|
|
1bdc94 |
+ '*main-header': 'bool',
|
|
|
1bdc94 |
+ '*active-l1': 'bool',
|
|
|
1bdc94 |
+ '*active-l2': 'bool',
|
|
|
1bdc94 |
+ '*refcount-table': 'bool',
|
|
|
1bdc94 |
+ '*refcount-block': 'bool',
|
|
|
1bdc94 |
+ '*snapshot-table': 'bool',
|
|
|
1bdc94 |
+ '*inactive-l1': 'bool',
|
|
|
1bdc94 |
+ '*inactive-l2': 'bool',
|
|
|
1bdc94 |
+ '*bitmap-directory': 'bool' } }
|
|
|
1bdc94 |
|
|
|
1bdc94 |
##
|
|
|
1bdc94 |
# @Qcow2OverlapChecks:
|
|
|
1bdc94 |
--
|
|
|
1bdc94 |
1.8.3.1
|
|
|
1bdc94 |
|