From 115c2b5a6806615206dfa5518509911bfc7b1d07 Mon Sep 17 00:00:00 2001 From: MORITA Kazutaka Date: Thu, 3 May 2012 05:26:07 +0900 Subject: sheepdog: switch to writethrough mode if cluster doesn't support flush This is necessary for qemu to work with the older version of Sheepdog which doesn't support SD_OP_FLUSH_VDI. Signed-off-by: MORITA Kazutaka Signed-off-by: Kevin Wolf --- block/sheepdog.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'block') diff --git a/block/sheepdog.c b/block/sheepdog.c index 0ed6b193c9..e01d371680 100644 --- a/block/sheepdog.c +++ b/block/sheepdog.c @@ -1678,6 +1678,14 @@ static int coroutine_fn sd_co_flush_to_disk(BlockDriverState *bs) return ret; } + if (rsp->result == SD_RES_INVALID_PARMS) { + dprintf("disable write cache since the server doesn't support it\n"); + + s->cache_enabled = 0; + closesocket(s->flush_fd); + return 0; + } + if (rsp->result != SD_RES_SUCCESS) { error_report("%s", sd_strerror(rsp->result)); return -EIO; -- cgit v1.2.3 From 54e6814360ab2110ed3ed07b2b9a3f9907e1202a Mon Sep 17 00:00:00 2001 From: Kevin Wolf Date: Thu, 26 Apr 2012 19:41:22 +0200 Subject: qcow2: Limit COW to where it's needed This fixes a regression introduced in commit 250196f1. The bug leads to data corruption, found during an Autotest run with a Fedora 8 guest. Consider a write request whose first part is covered by an already allocated cluster, but additional clusters need to be newly allocated. When counting the number of clusters to allocate, the qcow2 code would decide to do COW for all remaining clusters of the write request, even if some of them are already allocated. If during this COW operation another write request is issued that touches the same cluster, it will still refer to the old cluster. When the COW completes, the first request will update the L2 table and the second write request will be lost. Note that the requests need not overlap, it's enough for them to touch the same cluster. This patch ensures that only clusters that really require COW are considered for allocation. In this case any other request writing to the same cluster will be an allocating write and gets serialised. Reported-by: Marcelo Tosatti Tested-by: Marcelo Tosatti Signed-off-by: Kevin Wolf --- block/qcow2-cluster.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'block') diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c index 353889d41b..10c22fe12b 100644 --- a/block/qcow2-cluster.c +++ b/block/qcow2-cluster.c @@ -883,15 +883,19 @@ again: assert(keep_clusters <= nb_clusters); nb_clusters -= keep_clusters; } else { + keep_clusters = 0; + cluster_offset = 0; + } + + if (nb_clusters > 0) { /* For the moment, overwrite compressed clusters one by one */ - if (cluster_offset & QCOW_OFLAG_COMPRESSED) { + uint64_t entry = be64_to_cpu(l2_table[l2_index + keep_clusters]); + if (entry & QCOW_OFLAG_COMPRESSED) { nb_clusters = 1; } else { - nb_clusters = count_cow_clusters(s, nb_clusters, l2_table, l2_index); + nb_clusters = count_cow_clusters(s, nb_clusters, l2_table, + l2_index + keep_clusters); } - - keep_clusters = 0; - cluster_offset = 0; } cluster_offset &= L2E_OFFSET_MASK; -- cgit v1.2.3 From 15552c4ad38b9ec66792b044cf5ae74538c32717 Mon Sep 17 00:00:00 2001 From: Zhi Yong Wu Date: Mon, 7 May 2012 16:51:03 +0800 Subject: qcow2: lock on prealloc preallocate() will be locked. This is required because qcow2_alloc_cluster_link_l2() assumes that it runs under a lock that it can drop while COW is being performed. Signed-off-by: Zhi Yong Wu Signed-off-by: Kevin Wolf --- block/qcow2.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'block') diff --git a/block/qcow2.c b/block/qcow2.c index 8c60a6f061..ee4678f6ed 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -1192,7 +1192,10 @@ static int qcow2_create2(const char *filename, int64_t total_size, /* And if we're supposed to preallocate metadata, do that now */ if (prealloc) { + BDRVQcowState *s = bs->opaque; + qemu_co_mutex_lock(&s->lock); ret = preallocate(bs); + qemu_co_mutex_unlock(&s->lock); if (ret < 0) { goto out; } -- cgit v1.2.3