[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-block] [PATCH v2 10/18] block/pcache: cache invalidation on write
From: |
Pavel Butsykin |
Subject: |
[Qemu-block] [PATCH v2 10/18] block/pcache: cache invalidation on write requests |
Date: |
Fri, 30 Dec 2016 17:31:34 +0300 |
In AIO write request completion we just drop all the intersecting nodes in the
cache, it's a simple way to keep the cache up-to-date.
Signed-off-by: Pavel Butsykin <address@hidden>
---
block/pcache.c | 32 +++++++++++++++++++++++++++++++-
1 file changed, 31 insertions(+), 1 deletion(-)
diff --git a/block/pcache.c b/block/pcache.c
index f30e9e7bfe..4007241d37 100644
--- a/block/pcache.c
+++ b/block/pcache.c
@@ -314,11 +314,41 @@ skip_large_request:
return bdrv_co_preadv(bs->file, offset, bytes, qiov, flags);
}
+static void pcache_invalidation(BlockDriverState *bs, uint64_t offset,
+ uint64_t bytes)
+{
+ BDRVPCacheState *s = bs->opaque;
+ uint64_t chunk_offset = offset, chunk_bytes = bytes;
+ uint64_t end_offs = offset + bytes;
+
+ do {
+ PCacheNode *node = rbcache_search(s->cache, chunk_offset, chunk_bytes);
+ if (node == NULL) {
+ break;
+ }
+ assert(node->status == NODE_STATUS_COMPLETED ||
+ node->status == NODE_STATUS_INFLIGHT);
+
+ chunk_offset = node->common.offset + node->common.bytes;
+ chunk_bytes = end_offs - chunk_offset;
+
+ if (node->status & NODE_STATUS_COMPLETED) {
+ rbcache_remove(s->cache, &node->common);
+ }
+ } while (end_offs > chunk_offset);
+}
+
static coroutine_fn int pcache_co_pwritev(BlockDriverState *bs, uint64_t
offset,
uint64_t bytes, QEMUIOVector *qiov,
int flags)
{
- return bdrv_co_pwritev(bs->file, offset, bytes, qiov, flags);
+ int ret = bdrv_co_pwritev(bs->file, offset, bytes, qiov, flags);
+ if (ret < 0) {
+ return ret;
+ }
+ pcache_invalidation(bs, offset, bytes);
+
+ return ret;
}
static void pcache_state_init(QemuOpts *opts, BDRVPCacheState *s)
--
2.11.0
- [Qemu-block] [PATCH v2 12/18] block/pcache: inflight readahead request waiting for read, (continued)
- [Qemu-block] [PATCH v2 12/18] block/pcache: inflight readahead request waiting for read, Pavel Butsykin, 2016/12/30
- [Qemu-block] [PATCH v2 02/18] util/rbtree: add rbtree from linux kernel, Pavel Butsykin, 2016/12/30
- [Qemu-block] [PATCH v2 18/18] block/pcache: add tracepoints, Pavel Butsykin, 2016/12/30
- [Qemu-block] [PATCH v2 15/18] block/pcache: pick up parts of the cache, Pavel Butsykin, 2016/12/30
- [Qemu-block] [PATCH v2 03/18] util/rbcache: range-based cache core, Pavel Butsykin, 2016/12/30
- [Qemu-block] [PATCH v2 08/18] block/pcache: add AIO readahead, Pavel Butsykin, 2016/12/30
- [Qemu-block] [PATCH v2 07/18] block/pcache: updating statistics for overlapping requests, Pavel Butsykin, 2016/12/30
- [Qemu-block] [PATCH v2 14/18] block/pcache: up-to-date cache for removed nodes, Pavel Butsykin, 2016/12/30
- [Qemu-block] [PATCH v2 17/18] qapi: allow blockdev-add for pcache, Pavel Butsykin, 2016/12/30
- [Qemu-block] [PATCH v2 05/18] block/pcache: statistics collection read requests, Pavel Butsykin, 2016/12/30
- [Qemu-block] [PATCH v2 10/18] block/pcache: cache invalidation on write requests,
Pavel Butsykin <=
- [Qemu-block] [PATCH v2 06/18] block/pcache: skip large aio read, Pavel Butsykin, 2016/12/30
- [Qemu-block] [PATCH v2 04/18] tests/test-rbcache: add test cases, Pavel Butsykin, 2016/12/30
- [Qemu-block] [PATCH v2 01/18] block/pcache: empty pcache driver filter, Pavel Butsykin, 2016/12/30
- [Qemu-block] [PATCH v2 09/18] block/pcache: skip readahead for unallocated clusters, Pavel Butsykin, 2016/12/30
- [Qemu-block] [PATCH v2 13/18] block/pcache: write through, Pavel Butsykin, 2016/12/30