diff options
author | Gleb Natapov <gleb@redhat.com> | 2009-05-07 11:31:44 +0300 |
---|---|---|
committer | Anthony Liguori <aliguori@us.ibm.com> | 2009-05-08 15:54:06 -0500 |
commit | 8bc2ad6a6aec73844fb0091f9daf73dc8ee4d61c (patch) | |
tree | 0d8d7a46576b3823ca0646c4d4df1e3fa1394289 /block-qcow2.c | |
parent | f24f1e2a857db4b5bccced87a1e29f11d478b862 (diff) |
Fix cluster freeing in qcow2
Need to drop QCOW_OFLAG_COPIED from a cluster pointer before freeing it.
Add an explanation how thing meant to work.
Signed-off-by: Gleb Natapov <gleb@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Diffstat (limited to 'block-qcow2.c')
-rw-r--r-- | block-qcow2.c | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/block-qcow2.c b/block-qcow2.c index 74a0dfa156..a984611a9a 100644 --- a/block-qcow2.c +++ b/block-qcow2.c @@ -903,6 +903,12 @@ static int alloc_cluster_link_l2(BlockDriverState *bs, uint64_t cluster_offset, goto err; for (i = 0; i < m->nb_clusters; i++) { + /* if two concurrent writes happen to the same unallocated cluster + * each write allocates separate cluster and writes data concurrently. + * The first one to complete updates l2 table with pointer to its + * cluster the second one has to do RMW (which is done above by + * copy_sectors()), update l2 table with its cluster pointer and free + * old cluster. This is what this loop does */ if(l2_table[l2_index + i] != 0) old_cluster[j++] = l2_table[l2_index + i]; @@ -916,7 +922,8 @@ static int alloc_cluster_link_l2(BlockDriverState *bs, uint64_t cluster_offset, goto err; for (i = 0; i < j; i++) - free_any_clusters(bs, be64_to_cpu(old_cluster[i]), 1); + free_any_clusters(bs, be64_to_cpu(old_cluster[i]) & ~QCOW_OFLAG_COPIED, + 1); ret = 0; err: |