[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [RFC V8 20/24] qcow2: Serialize write requests when dedupli
From: |
Benoît Canet |
Subject: |
[Qemu-devel] [RFC V8 20/24] qcow2: Serialize write requests when deduplication is activated. |
Date: |
Thu, 20 Jun 2013 16:26:28 +0200 |
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 | 14 ++++++++++++++
block/qcow2.h | 1 +
2 files changed, 15 insertions(+)
diff --git a/block/qcow2.c b/block/qcow2.c
index 8eb63f1..11c115f 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -534,6 +534,7 @@ static int qcow2_open(BlockDriverState *bs, QDict *options,
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 &&
@@ -841,6 +842,15 @@ static coroutine_fn int qcow2_co_writev(BlockDriverState
*bs,
s->cluster_cache_offset = -1; /* disable compressed cache */
+ if (s->has_dedup) {
+ /* 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);
if (s->has_dedup) {
@@ -1018,6 +1028,10 @@ fail:
l2meta = next;
}
+ if (s->has_dedup) {
+ 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 6f85e03..3c6e685 100644
--- a/block/qcow2.h
+++ b/block/qcow2.h
@@ -364,6 +364,7 @@ typedef struct BDRVQcowState {
Coroutine *load_filter_co; /* used to load incarnations filters */
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 V8 13/24] qcow2: Implement qcow2_compute_cluster_hash., (continued)
- [Qemu-devel] [RFC V8 13/24] qcow2: Implement qcow2_compute_cluster_hash., Benoît Canet, 2013/06/20
- [Qemu-devel] [RFC V8 17/24] qcow2: Drop hash for a given cluster when dedup makes refcount > 2^16/2., Benoît Canet, 2013/06/20
- [Qemu-devel] [RFC V8 15/24] qcow2: Extract qcow2_set_incompat_feature and qcow2_clear_incompat_feature., Benoît Canet, 2013/06/20
- [Qemu-devel] [RFC V8 19/24] qcow2: Integrate deduplication in qcow2_co_writev loop., Benoît Canet, 2013/06/20
- [Qemu-devel] [RFC V8 16/24] block: Add qcow2_dedup format and image creation code., Benoît Canet, 2013/06/20
- [Qemu-devel] [RFC V8 22/24] qcow2: Add qcow2_dedup_init and qcow2_dedup_close., Benoît Canet, 2013/06/20
- [Qemu-devel] [RFC V8 21/24] qcow2: Integrate SKEIN hash algorithm in deduplication., Benoît Canet, 2013/06/20
- [Qemu-devel] [RFC V8 23/24] qcow2: Enable the deduplication feature., Benoît Canet, 2013/06/20
- [Qemu-devel] [RFC V8 24/24] qcow2: Enable deduplication tests, Benoît Canet, 2013/06/20
- [Qemu-devel] [RFC V8 18/24] qcow2: Remove hash when cluster is deleted., Benoît Canet, 2013/06/20
- [Qemu-devel] [RFC V8 20/24] qcow2: Serialize write requests when deduplication is activated.,
Benoît Canet <=