Keep track of the active L1 table in the metadata list to protect it against accidental modifications.
Signed-off-by: Max Reitz <mre...@redhat.com> --- block/qcow2-cluster.c | 11 +++++++++++ block/qcow2-snapshot.c | 10 ++++++++++ block/qcow2.c | 4 ++++ 3 files changed, 25 insertions(+) diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c index df0b2c9..131e5b2 100644 --- a/block/qcow2-cluster.c +++ b/block/qcow2-cluster.c @@ -125,6 +125,17 @@ int qcow2_grow_l1_table(BlockDriverState *bs, uint64_t min_size, s->l1_table = new_l1_table; old_l1_size = s->l1_size; s->l1_size = new_l1_size; + + qcow2_metadata_list_remove(bs, old_l1_table_offset, + size_to_clusters(s, old_l1_size * + sizeof(uint64_t)), + QCOW2_OL_ACTIVE_L1); + + qcow2_metadata_list_enter(bs, s->l1_table_offset, + size_to_clusters(s, s->l1_size * + sizeof(uint64_t)), + QCOW2_OL_ACTIVE_L1); + qcow2_free_clusters(bs, old_l1_table_offset, old_l1_size * sizeof(uint64_t), QCOW2_DISCARD_OTHER); return 0; diff --git a/block/qcow2-snapshot.c b/block/qcow2-snapshot.c index 5b3903c..41ea053 100644 --- a/block/qcow2-snapshot.c +++ b/block/qcow2-snapshot.c @@ -720,6 +720,11 @@ int qcow2_snapshot_load_tmp(BlockDriverState *bs, return ret; } + qcow2_metadata_list_remove(bs, s->l1_table_offset, + size_to_clusters(s, s->l1_size * + sizeof(uint64_t)), + QCOW2_OL_ACTIVE_L1); + /* Switch the L1 table */ qemu_vfree(s->l1_table); @@ -731,5 +736,10 @@ int qcow2_snapshot_load_tmp(BlockDriverState *bs, be64_to_cpus(&s->l1_table[i]); } + qcow2_metadata_list_enter(bs, s->l1_table_offset, + size_to_clusters(s, s->l1_size * + sizeof(uint64_t)), + QCOW2_OL_ACTIVE_L1); + return 0; } diff --git a/block/qcow2.c b/block/qcow2.c index 1644421..775cb39 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -831,6 +831,10 @@ static int qcow2_open(BlockDriverState *bs, QDict *options, int flags, } s->l1_table_offset = header.l1_table_offset; + qcow2_metadata_list_enter(bs, s->l1_table_offset, + size_to_clusters(s, s->l1_size * + sizeof(uint64_t)), + QCOW2_OL_ACTIVE_L1); if (s->l1_size > 0) { s->l1_table = qemu_try_blockalign(bs->file, -- 1.9.3