[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 5/8] qcow2: Switch L1 table in a single sequence
From: |
Stefan Hajnoczi |
Subject: |
[Qemu-devel] [PULL 5/8] qcow2: Switch L1 table in a single sequence |
Date: |
Mon, 7 Oct 2013 13:28:06 +0200 |
From: Max Reitz <address@hidden>
Switching the L1 table in memory should be an atomic operation, as far
as possible. Calling qcow2_free_clusters on the old L1 table on disk is
not a good idea when the old L1 table is no longer valid and the address
to the new one hasn't yet been written into the corresponding
BDRVQcowState field. To be more specific, this can lead to segfaults due
to qcow2_check_metadata_overlap trying to access the L1 table during the
free operation.
Signed-off-by: Max Reitz <address@hidden>
Reviewed-by: Eric Blake <address@hidden>
Reviewed-by: Kevin Wolf <address@hidden>
Signed-off-by: Stefan Hajnoczi <address@hidden>
---
block/qcow2-cluster.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c
index 39323ac..2ed45f0 100644
--- a/block/qcow2-cluster.c
+++ b/block/qcow2-cluster.c
@@ -35,6 +35,7 @@ int qcow2_grow_l1_table(BlockDriverState *bs, uint64_t
min_size,
BDRVQcowState *s = bs->opaque;
int new_l1_size2, ret, i;
uint64_t *new_l1_table;
+ int64_t old_l1_table_offset, old_l1_size;
int64_t new_l1_table_offset, new_l1_size;
uint8_t data[12];
@@ -106,11 +107,13 @@ int qcow2_grow_l1_table(BlockDriverState *bs, uint64_t
min_size,
goto fail;
}
g_free(s->l1_table);
- qcow2_free_clusters(bs, s->l1_table_offset, s->l1_size * sizeof(uint64_t),
- QCOW2_DISCARD_OTHER);
+ old_l1_table_offset = s->l1_table_offset;
s->l1_table_offset = new_l1_table_offset;
s->l1_table = new_l1_table;
+ old_l1_size = s->l1_size;
s->l1_size = new_l1_size;
+ qcow2_free_clusters(bs, old_l1_table_offset, old_l1_size *
sizeof(uint64_t),
+ QCOW2_DISCARD_OTHER);
return 0;
fail:
g_free(new_l1_table);
--
1.8.3.1
- [Qemu-devel] [PULL 0/8] Block patches, Stefan Hajnoczi, 2013/10/07
- [Qemu-devel] [PULL 1/8] qcow2: Correct endianness in overlap check, Stefan Hajnoczi, 2013/10/07
- [Qemu-devel] [PULL 2/8] qcow2: CHECK_OFLAG_COPIED is obsolete, Stefan Hajnoczi, 2013/10/07
- [Qemu-devel] [PULL 3/8] block: use correct filename for error report, Stefan Hajnoczi, 2013/10/07
- [Qemu-devel] [PULL 4/8] block: vhdx - add migration blocker, Stefan Hajnoczi, 2013/10/07
- [Qemu-devel] [PULL 6/8] qcow2: Free allocated L2 cluster on error, Stefan Hajnoczi, 2013/10/07
- [Qemu-devel] [PULL 5/8] qcow2: Switch L1 table in a single sequence,
Stefan Hajnoczi <=
- [Qemu-devel] [PULL 7/8] qemu-iotests: Correct 026 output, Stefan Hajnoczi, 2013/10/07
- [Qemu-devel] [PULL 8/8] block: use correct filename, Stefan Hajnoczi, 2013/10/07