[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 11/23] qcow2: Batch flushes for COW
From: |
Kevin Wolf |
Subject: |
[Qemu-devel] [PATCH 11/23] qcow2: Batch flushes for COW |
Date: |
Mon, 24 Jan 2011 22:10:40 +0100 |
qcow2 calls bdrv_flush() after performing COW in order to ensure that the
L2 table change is never written before the copy is safe on disk. Now that the
L2 table is cached, we can wait with flushing until we write out the next L2
table.
Signed-off-by: Kevin Wolf <address@hidden>
---
block/qcow2-cache.c | 20 +++++++++++++++++---
block/qcow2-cluster.c | 2 +-
block/qcow2.h | 1 +
3 files changed, 19 insertions(+), 4 deletions(-)
diff --git a/block/qcow2-cache.c b/block/qcow2-cache.c
index 5f1740b..8f2955b 100644
--- a/block/qcow2-cache.c
+++ b/block/qcow2-cache.c
@@ -38,6 +38,7 @@ struct Qcow2Cache {
int size;
Qcow2CachedTable* entries;
struct Qcow2Cache* depends;
+ bool depends_on_flush;
bool writethrough;
};
@@ -85,13 +86,15 @@ static int qcow2_cache_flush_dependency(BlockDriverState
*bs, Qcow2Cache *c)
}
c->depends = NULL;
+ c->depends_on_flush = false;
+
return 0;
}
static int qcow2_cache_entry_flush(BlockDriverState *bs, Qcow2Cache *c, int i)
{
BDRVQcowState *s = bs->opaque;
- int ret;
+ int ret = 0;
if (!c->entries[i].dirty || !c->entries[i].offset) {
return 0;
@@ -99,11 +102,17 @@ static int qcow2_cache_entry_flush(BlockDriverState *bs,
Qcow2Cache *c, int i)
if (c->depends) {
ret = qcow2_cache_flush_dependency(bs, c);
- if (ret < 0) {
- return ret;
+ } else if (c->depends_on_flush) {
+ ret = bdrv_flush(bs->file);
+ if (ret >= 0) {
+ c->depends_on_flush = false;
}
}
+ if (ret < 0) {
+ return ret;
+ }
+
if (c == s->refcount_block_cache) {
BLKDBG_EVENT(bs->file, BLKDBG_REFBLOCK_UPDATE_PART);
} else if (c == s->l2_table_cache) {
@@ -167,6 +176,11 @@ int qcow2_cache_set_dependency(BlockDriverState *bs,
Qcow2Cache *c,
return 0;
}
+void qcow2_cache_depends_on_flush(Qcow2Cache *c)
+{
+ c->depends_on_flush = true;
+}
+
static int qcow2_cache_find_entry_to_replace(Qcow2Cache *c)
{
int i;
diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c
index 76e7e07..1c2003a 100644
--- a/block/qcow2-cluster.c
+++ b/block/qcow2-cluster.c
@@ -637,7 +637,7 @@ int qcow2_alloc_cluster_link_l2(BlockDriverState *bs,
QCowL2Meta *m)
* handled.
*/
if (cow) {
- bdrv_flush(bs->file);
+ qcow2_cache_depends_on_flush(s->l2_table_cache);
}
qcow2_cache_set_dependency(bs, s->l2_table_cache, s->refcount_block_cache);
diff --git a/block/qcow2.h b/block/qcow2.h
index 11cbce3..6d80120 100644
--- a/block/qcow2.h
+++ b/block/qcow2.h
@@ -229,6 +229,7 @@ void qcow2_cache_entry_mark_dirty(Qcow2Cache *c, void
*table);
int qcow2_cache_flush(BlockDriverState *bs, Qcow2Cache *c);
int qcow2_cache_set_dependency(BlockDriverState *bs, Qcow2Cache *c,
Qcow2Cache *dependency);
+void qcow2_cache_depends_on_flush(Qcow2Cache *c);
int qcow2_cache_get(BlockDriverState *bs, Qcow2Cache *c, uint64_t offset,
void **table);
--
1.7.2.3
- [Qemu-devel] [PULL 00/23] Block patches, Kevin Wolf, 2011/01/24
- [Qemu-devel] [PATCH 01/23] qcow2: fix unaligned access, Kevin Wolf, 2011/01/24
- [Qemu-devel] [PATCH 02/23] qemu-img snapshot: Use writeback caching, Kevin Wolf, 2011/01/24
- [Qemu-devel] [PATCH 03/23] do_snapshot_blkdev() error on missing snapshot_file argument, Kevin Wolf, 2011/01/24
- [Qemu-devel] [PATCH 04/23] Make strtosz() return int64_t instead of ssize_t, Kevin Wolf, 2011/01/24
- [Qemu-devel] [PATCH 05/23] Avoid divide by zero when there is no block device to migrate, Kevin Wolf, 2011/01/24
- [Qemu-devel] [PATCH 06/23] ide: factor dma handling helpers, Kevin Wolf, 2011/01/24
- [Qemu-devel] [PATCH 07/23] ide: also reset io_buffer_index for writes, Kevin Wolf, 2011/01/24
- [Qemu-devel] [PATCH 08/23] ide: kill ide_dma_submit_check, Kevin Wolf, 2011/01/24
- [Qemu-devel] [PATCH 09/23] qcow2: Add QcowCache, Kevin Wolf, 2011/01/24
- [Qemu-devel] [PATCH 11/23] qcow2: Batch flushes for COW,
Kevin Wolf <=
- [Qemu-devel] [PATCH 10/23] qcow2: Use QcowCache, Kevin Wolf, 2011/01/24
- [Qemu-devel] [PATCH 12/23] ide: Remove unneeded null pointer check, Kevin Wolf, 2011/01/24
- [Qemu-devel] [PATCH 13/23] Documentation: Add qemu-img check/rebase, Kevin Wolf, 2011/01/24
- [Qemu-devel] [PATCH 14/23] qed: Refuse to create images on block devices, Kevin Wolf, 2011/01/24
- [Qemu-devel] [PATCH 15/23] Fix block migration when the device size is not a multiple of 1 MB, Kevin Wolf, 2011/01/24
- [Qemu-devel] [PATCH 16/23] blockdev: Fix error message for invalid -drive CHS, Kevin Wolf, 2011/01/24
- [Qemu-devel] [PATCH 17/23] blockdev: Make drive_init() use error_report(), Kevin Wolf, 2011/01/24
- [Qemu-devel] [PATCH 18/23] blockdev: Fix drive_del not to crash when drive is not in use, Kevin Wolf, 2011/01/24
- [Qemu-devel] [PATCH 19/23] block: Use backing format driver during image creation, Kevin Wolf, 2011/01/24
- [Qemu-devel] [PATCH 22/23] usb-msd: Propagate removable bit to SCSI device, Kevin Wolf, 2011/01/24