[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [RFC V7 24/32] qcow2: Serialize write requests when dedupli
From: |
Benoît Canet |
Subject: |
[Qemu-devel] [RFC V7 24/32] qcow2: Serialize write requests when deduplication is activated. |
Date: |
Fri, 15 Mar 2013 15:49:38 +0100 |
This fixes the sub cluster sized writes race conditions while waiting
for a faster solution.
Signed-off-by: Benoit Canet <address@hidden>
---
block/qcow2.c | 17 ++++++++++++++++-
block/qcow2.h | 1 +
2 files changed, 17 insertions(+), 1 deletion(-)
diff --git a/block/qcow2.c b/block/qcow2.c
index 838241c..9c613e5 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -515,6 +515,7 @@ static int qcow2_open(BlockDriverState *bs, int flags)
/* Initialise locks */
qemu_co_mutex_init(&s->lock);
+ qemu_co_mutex_init(&s->dedup_lock);
/* Repair image if dirty */
if (!(flags & BDRV_O_CHECK) && !bs->read_only &&
@@ -805,9 +806,19 @@ static coroutine_fn int qcow2_co_writev(BlockDriverState
*bs,
s->cluster_cache_offset = -1; /* disable compressed cache */
+ atomic_dedup_is_running = qcow2_dedup_is_running(bs);
+
+ if (atomic_dedup_is_running) {
+ /* This mutex is used to serialize the write requests in the dedup
case.
+ * The goal is to avoid that the dedup process concurrents requests to
+ * the same clusters and corrupt data.
+ * With qcow2_dedup_read_missing_and_concatenate that would not work.
+ */
+ qemu_co_mutex_lock(&s->dedup_lock);
+ }
+
qemu_co_mutex_lock(&s->lock);
- atomic_dedup_is_running = qcow2_dedup_is_running(bs);
if (atomic_dedup_is_running) {
QTAILQ_INIT(&ds.undedupables);
ds.phash.reuse = false;
@@ -977,6 +988,10 @@ fail:
g_free(l2meta);
}
+ if (atomic_dedup_is_running) {
+ qemu_co_mutex_unlock(&s->dedup_lock);
+ }
+
qemu_iovec_destroy(&hd_qiov);
qemu_vfree(cluster_data);
qemu_vfree(dedup_cluster_data);
diff --git a/block/qcow2.h b/block/qcow2.h
index b858db9..a430fe1 100644
--- a/block/qcow2.h
+++ b/block/qcow2.h
@@ -236,6 +236,7 @@ typedef struct BDRVQcowState {
GTree *dedup_tree_by_hash;
CoMutex lock;
+ CoMutex dedup_lock;
uint32_t crypt_method; /* current crypt method, 0 if no key yet */
uint32_t crypt_method_header;
--
1.7.10.4
- [Qemu-devel] [RFC V7 12/32] qcow2: Makes qcow2_alloc_cluster_link_l2 mark to deduplicate clusters., (continued)
- [Qemu-devel] [RFC V7 12/32] qcow2: Makes qcow2_alloc_cluster_link_l2 mark to deduplicate clusters., Benoît Canet, 2013/03/15
- [Qemu-devel] [RFC V7 11/32] qcow2: Add qcow2_dedup_grow_table and use it., Benoît Canet, 2013/03/15
- [Qemu-devel] [RFC V7 13/32] qcow2: make the deduplication forget a cluster hash when a cluster is to dedupe, Benoît Canet, 2013/03/15
- [Qemu-devel] [RFC V7 14/32] qcow2: Create qcow2_is_cluster_to_dedup., Benoît Canet, 2013/03/15
- [Qemu-devel] [RFC V7 16/32] qcow2: Extract qcow2_do_table_init., Benoît Canet, 2013/03/15
- [Qemu-devel] [RFC V7 15/32] qcow2: Load and save deduplication table header extension., Benoît Canet, 2013/03/15
- [Qemu-devel] [RFC V7 17/32] qcow2-cache: Allow to choose table size at creation., Benoît Canet, 2013/03/15
- [Qemu-devel] [RFC V7 21/32] qcow2: Remove hash when cluster is deleted., Benoît Canet, 2013/03/15
- [Qemu-devel] [RFC V7 22/32] qcow2: Add qcow2_dedup_is_running to probe if dedup is running., Benoît Canet, 2013/03/15
- [Qemu-devel] [RFC V7 20/32] qcow2: Drop hash for a given cluster when dedup makes refcount > 2^16/2., Benoît Canet, 2013/03/15
- [Qemu-devel] [RFC V7 24/32] qcow2: Serialize write requests when deduplication is activated.,
Benoît Canet <=
- [Qemu-devel] [RFC V7 23/32] qcow2: Integrate deduplication in qcow2_co_writev loop., Benoît Canet, 2013/03/15
- [Qemu-devel] [RFC V7 19/32] block: Add qcow2_dedup format and image creation code., Benoît Canet, 2013/03/15
- [Qemu-devel] [RFC V7 25/32] qcow2: Adapt checking of QCOW_OFLAG_COPIED for dedup., Benoît Canet, 2013/03/15
- [Qemu-devel] [RFC V7 26/32] qcow2: Add check_dedup_l2 in order to check l2 of dedup table., Benoît Canet, 2013/03/15
- [Qemu-devel] [RFC V7 27/32] qcow2: Add verification of dedup table., Benoît Canet, 2013/03/15
- [Qemu-devel] [RFC V7 30/32] qcow2: Add qcow2_dedup_init and qcow2_dedup_close., Benoît Canet, 2013/03/15
- [Qemu-devel] [RFC V7 28/32] qcow2: Integrate SKEIN hash algorithm in deduplication., Benoît Canet, 2013/03/15
- [Qemu-devel] [RFC V7 29/32] qcow: Set large dedup hash block size., Benoît Canet, 2013/03/15
- [Qemu-devel] [RFC V7 32/32] qcow2: Enable the deduplication feature., Benoît Canet, 2013/03/15
- [Qemu-devel] [RFC V7 31/32] qcow2: Add qcow2_co_dedup_resume to restart deduplication., Benoît Canet, 2013/03/15