From patchwork Mon Aug 29 17:10:11 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Butsykin X-Patchwork-Id: 9304563 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 6F57F6086B for ; Mon, 29 Aug 2016 21:53:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5EA6A28673 for ; Mon, 29 Aug 2016 21:53:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 534302867C; Mon, 29 Aug 2016 21:53:00 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAD_ENC_HEADER,BAYES_00, DKIM_SIGNED, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 88A2028673 for ; Mon, 29 Aug 2016 21:52:59 +0000 (UTC) Received: from localhost ([::1]:45931 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1beUUD-0003m3-TC for patchwork-qemu-devel@patchwork.kernel.org; Mon, 29 Aug 2016 17:52:57 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46652) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1beUPo-0000aE-8m for qemu-devel@nongnu.org; Mon, 29 Aug 2016 17:48:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1beUPl-0003Al-Nu for qemu-devel@nongnu.org; Mon, 29 Aug 2016 17:48:23 -0400 Received: from mail-db5eur01on0114.outbound.protection.outlook.com ([104.47.2.114]:60483 helo=EUR01-DB5-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1beUPg-00037x-F1; Mon, 29 Aug 2016 17:48:16 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=virtuozzo.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=VAHwZwCDS11sGd7cUOkn8GEfayKDYgvZohgkwBUNFMs=; b=FMluHMkUfZvuSB0ekCohCdmKrS+EC/5BLBXtDtlt/+k2u4J5cwpZuaApySQr+ECM8tc7+GsQOUn1BJVFXAdBIdlf9AzKwD35PRo5RAByEvvC6NnUsRAJGfTYxCaFpG3TTwWu4EdYTgINXtGPgjnFReGpuJJfWNrnOlcdsH400Gw= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=pbutsykin@virtuozzo.com; Received: from pavelb-Z68P-DS3.sw.ru (195.214.232.10) by AM5PR0802MB2547.eurprd08.prod.outlook.com (10.175.45.23) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA_P384) id 15.1.587.13; Mon, 29 Aug 2016 17:11:24 +0000 From: Pavel Butsykin To: , Date: Mon, 29 Aug 2016 20:10:11 +0300 Message-ID: <20160829171021.4902-13-pbutsykin@virtuozzo.com> X-Mailer: git-send-email 2.8.3 In-Reply-To: <20160829171021.4902-1-pbutsykin@virtuozzo.com> References: <20160829171021.4902-1-pbutsykin@virtuozzo.com> MIME-Version: 1.0 X-Originating-IP: [195.214.232.10] X-ClientProxiedBy: AM5PR0901CA0011.eurprd09.prod.outlook.com (10.164.186.149) To AM5PR0802MB2547.eurprd08.prod.outlook.com (10.175.45.23) X-MS-Office365-Filtering-Correlation-Id: aeaa3616-4b00-4293-6506-08d3d02f81fb X-Microsoft-Exchange-Diagnostics: 1; AM5PR0802MB2547; 2:M7Z1vQZVEOxuorbbkfOjncBuhoSwjYClqTvjJuOiNYPc6dCne3foMRFpjS1bOLQcK0DUUWX9icVamOpRGF4jHkWlTq4sGrvQtwB8HUJrJJXU3OYogop0Ieq0uHGxASeGnD9FZiD0Tv7P2nlLyTstUuZPAX3Y+d+jaq7PrADWVZeOwclgNSSFfDoSvzY7IWIR; 3:oVJbNOz30VFhNuubo58NXJo3Gv7/GkvUY1Teu92j790EpxErw9uBGq5i/WTSFfjgbi66wOroRywjrwH0S00S2fiL79D9Q+kB5oCJPxvEUSc0tYd7gpeGu7/PXbe2LAsG X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:AM5PR0802MB2547; X-Microsoft-Exchange-Diagnostics: 1; AM5PR0802MB2547; 25:W23yQgVecYXUBKKzOzj3olEOBSaUJfyrWvYrYLTyBpJKvHcBOBV0oFdrOZR7nREzjkAxBmgJ58RVPcucUftJdLiko8PqCkgmxMtg67N0uV6zUa5UNmtwpxch1TOxG6E8EBFAeVm/KrP2seVNj+ljP69rMRnvTcv0JeKaI6tKgrb1bpTgPI69lJ4eLLdQZscUy+suYhOp6RYSgyKkVYWMT7sXp3TiYc6iX94QY9uInA3w8rtwe0NJBXZZTzpRy+NOTXKik5eBER+YksOznyEXQFfrDsJ5oSoMOFk06bJzYTe5nBEG12YrDgMdGO15Y/ikudZjZXIW3b0mko6qKRaQao+WRgX7fsv/0l8tFVtHW5M4sD1fBPwI+FBbhgqc3JxyHpsBCRAmNuSBNDgbebGk4A4efmPfceL69eJEqzLXN7o+3rMMBGr9bx/1+4nStrFWzHF4wfFH+VkvLzXpP0lHcVRZ77eU0y+/efsfKjPggtlpXIaTgYi+mBfMm//LQenVBTeUyJb+J+gk9B905Cz9nLKceSQOPo20IaIT4fFpxQJqc4uzbYRTsvU6Nkk1/E7/SL4fvjbMCDo1SmRHHJPnVm53ZA5hlG+pU/DWCeVdaAu+k6ZrCyRPQ4Wx9leMRLPxyb4oV85zKVD/aE82cCW5wtE6h+cFLcenO7wlm4FCyda7xcYNNtC7rVnCqRzwVXWzNx6C/03lPAVcgYuTH9+A1A==; 31:cDgF/m23J8YFAOrlZ+rPbqDOn1FJc4aIYElFxHTph8ZgjsOemqSDwHf9uMuUcXuPIf0R/pas5YSchdXx8F4GtEJrb96Uh7tfnYTdcsFsl0iTH8XcRGH8GU1cvjYCZ3JkvvUo3jMKuoa5E7HJPecIG67mLkuVC4CmRHCj5tVd8t+zjFEaTwc+PgTOSTFS/ShUEN1djrzZKXIO1q218TDvYXxINDuAGJHeazIfOoxwPEA= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040176)(601004)(2401047)(8121501046)(5005006)(10201501046)(3002001)(6042046)(6043046); SRVR:AM5PR0802MB2547; BCL:0; PCL:0; RULEID:; SRVR:AM5PR0802MB2547; X-Microsoft-Exchange-Diagnostics: 1; AM5PR0802MB2547; 4:aWRRYOyqhh1RCJ54noZC2JFh9qPHqyG3jg06OeOHOLqtC6BHVrFLkyXnMGT9n5PitvMyDJ4T43WjxvS2zZPfwE3ZeNGgeTaLZvVQhrxxA+l6iZL9YLohJK7SqKC543XRkWtdq01mly7eMq3V2Uv7D7Jn7vMq5PZn13wa7KesfOi56nw+bqV4uovpJ3XVjgkg7aEQqE8fCI7sAJrxD5hLg1mXAPXZlw43wwJHRdEThty2Ewrd3AhTNwdX3eDAtA1x4oGFW165AuawO+Q4RW2lMqDbYGmmJDhhnhi3ahHGDSb4Eo1iT1P9k02mrCHoS/IRLOV19OxN4UZruNWuEdceUApYWvzpu1HLBuJ02sxUm0SJ5k222mx8e0JJ1FL9+WpgL+AAl5Ws7acOYRLExh1H19Conq2RXy+FEhSi1po1GPw= X-Forefront-PRVS: 0049B3F387 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(4630300001)(6009001)(7916002)(199003)(189002)(3846002)(305945005)(77096005)(86362001)(1076002)(53416004)(92566002)(68736007)(42186005)(97736004)(5001770100001)(47776003)(105586002)(2906002)(6116002)(189998001)(50986999)(4326007)(48376002)(586003)(2950100001)(5003940100001)(50466002)(66066001)(19580405001)(19580395003)(76176999)(69596002)(5660300001)(229853001)(101416001)(36756003)(7736002)(8676002)(106356001)(50226002)(7846002)(81156014)(33646002)(81166006)(21314002)(217873001); DIR:OUT; SFP:1102; SCL:1; SRVR:AM5PR0802MB2547; H:pavelb-Z68P-DS3.sw.ru; FPR:; SPF:None; PTR:InfoNoRecords; A:1; MX:1; LANG:en; Received-SPF: None (protection.outlook.com: virtuozzo.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; AM5PR0802MB2547; 23:rP2EHRsssd8ZurLpyameGXBeZFoBiBBPhsFKwiU?= =?us-ascii?Q?hGbkag/6jfMi9j63ansks04uxzjzBcwfDq5pAD1+aFMr0uMqhhFanK/WldDS?= =?us-ascii?Q?XmraoJQikiZ5q9cGSL7OzCB+rge3zfoRm7IJL+56/wJwntNE1XN0OpSj4v9m?= =?us-ascii?Q?t9yB805GfC8CLnYXWYZMZoJ6jNpuoJsNxFvA3mhbq7hARNrI3N5C5w2xZt8C?= =?us-ascii?Q?I6Tvn3hSNNgdPU2u24RL1d+9Ahue9ZcO0DMV2eVF4ajokqDQX0B8eOexPOk0?= =?us-ascii?Q?YG3y1Ty1eyAMwMJ3DsiDoySXDFczry+WmB++c/qajfQE3kRetyaNW3Ty9JCc?= =?us-ascii?Q?OKMt7EVY4pf1z/M1S4crXvQPzMQgz6qf6ieCfAhW4dg8/dcGTvu7UpvXnbUn?= =?us-ascii?Q?tGaNZfyOeAS51DoHegIb6XXoRuKgXUSJ4ctuDctUKkwaFD/XM6sWIXpHFELU?= =?us-ascii?Q?aw+sNnq7xfjs6XiMV/83eKQ6fpFcvA6QWz15TPi+LOyT7darxuyYnaIxgppe?= =?us-ascii?Q?9Ty4gd3m07HM03n6oSowOZurIWTilGjuBUznkph2Ysza0lBsUsDcSKpCVX5I?= =?us-ascii?Q?pcaWy+r3vf/GNsTyeq5WWvSXykNT86FmkycE4zrnasvwM7dXYIxmX+LMlgSH?= =?us-ascii?Q?agMxoxDyfF0/9t0p5+pygkDB8rEoqwpq7CCtXghKJ+iXYqwSqcchK1nYH/J8?= =?us-ascii?Q?VtAC1JkRBWn9m9yOqj0kgS9Tf1xFkugNZ9O65pOJknRmurEZCGTivu73on6e?= =?us-ascii?Q?7coJGsStCSPLhPZWeyYtLz4RckylizYkTiVMqAKwDTgn5wd5h0M4prRDFKLa?= =?us-ascii?Q?PV0xpAhybhFa0SNX+w/0l1Fhf36XBy267f7tLKe+etge6Flbebre3cUwfIyn?= =?us-ascii?Q?hrBtLt2sbm6gXlywjMCQ7S6thga01ZRyGFlQ0UCnsjPq8qvZFP0txYka/waQ?= =?us-ascii?Q?8KSLwKE/yBITHzf4OHRyRPO2JlNq2tRQsS3w955tX6tRbnfdwtAthcdTM2ba?= =?us-ascii?Q?i+eYFNwN21CM4ESo2/X55JqtzX8WyKi5GmLuzilkx6bIO+OuPigCUa46ETJq?= =?us-ascii?Q?bpQHenM1xJ4+MxI1/wTxD7iUjaauerNjO4BTv9Lna3DmJVMrAKSx3oqRSNyy?= =?us-ascii?Q?wqGNubuGAazr6zZfnd/qTgbY15dXFFXVn5EEwoVtZ/RHFcTXvcn7yFixq1WR?= =?us-ascii?Q?Y8FrWWhL5UGc1MrU=3D?= X-Microsoft-Exchange-Diagnostics: 1; AM5PR0802MB2547; 6:3UVkVhwbGvmLqYj1HheNEimS4iSIvDE/PgCUqnPfLKs8zJLX6G44x/qmWp4+ttHRWmRuI8zLWjbUoh3TcTvII72DkYn+GcFVfVFt5dkr7VJNiGXefAB02OjSvbpPJ3O+SUYp0A3vp4GOuzY+tVXGxgxJR2oMZxGgpGPywyTcyWuqLxY84FclhsskwdmpULJJil1cUWmaYVHaWHzKKHv/BcuPgItVjNTvvH7uImqMucykcKXdRnzC19n/cgnflXM4OTjTU5xS76QR5S8HeC4YdWw+diEo9KT6LqRWlesCCRYa1eNTxR2CHRpVu1/Pdtrj; 5:QBQNnPBwS8ZwBL0LSnEIvbQtzzHLD1oCecnH6z32ghMnsno/V2tWg7hN5gv7qDGD304BwI6ZKFpch/tO1206M5VtQilDQzOFiG7X92SBsxr1SenOlnyEkkEu/DN9vPhy8qxuq/URlo1+m6y/+KBPnA==; 24:525RW9uFoNYt32rvL4v75n8pbe0rqZCtDkz1tMu+nTYJEC5LGGVD43PlkDuUe8fpq1mmzhv4rv+EFuZ/NZnNyV/pOUpveft++5dFU2iQjmk=; 7:xkgNsPhh7jJdzWCjg2V1hiZmnUAMBQU6gZB+wR+tM/vVbr4p38d2PFTbAdSgAmd0o3Zl+9u8W+bqn6JWsT2929u//5mNxRNR6JoXda3uliSw4/QlyZ1fanLdUdMJBXwE9xlGlUYU0WmP4JVRnOEZQNC5t5s/t3DKIK/HNoCIe0WI31VnrqgroK/KKSYyY0+bPAF/gWHIc+CrKVCCS5oOfSJvjPbWez+s6I9lE+rZuptAsCTMB4Xof65px9f86XtY SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; AM5PR0802MB2547; 20:Hz1GEGgCHEi4Lrzu5LFlnBnjT/Usw4YnC8/GCrWKabMRHbVKWfF/6Z/4sH3LfCjrqofFDqt2fZC8wgSHD7lmvqNRjWxVbwKUkEId397d5vr+o/biW5ZfEFaDIpn5sQSoulB/68T90haWK2rKQfvqnPhHhx5IpPmqBfh0aihCAz0= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Aug 2016 17:11:24.6733 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM5PR0802MB2547 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 104.47.2.114 Subject: [Qemu-devel] [PATCH RFC v2 12/22] block/pcache: implement read cache to qiov and drop node during aio write X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, famz@redhat.com, mreitz@redhat.com, stefanha@redhat.com, den@openvz.org, jsnow@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP After applying this patch aio read can pick up data from the pcache. for correct driver work added 3 things: 1. Filling the qiov out of the cache. 2. Request completes. This is necessary to inform the upper level, that the data for the request has already been obtained. 3. Cache Invalidation in the aio write requests. This is a simple way to keep the cache up-to-date. Signed-off-by: Pavel Butsykin --- block/pcache.c | 126 +++++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 118 insertions(+), 8 deletions(-) diff --git a/block/pcache.c b/block/pcache.c index a8a57e3..435f2b4 100644 --- a/block/pcache.c +++ b/block/pcache.c @@ -103,7 +103,9 @@ typedef struct PrefCacheAIOCB { struct { QTAILQ_HEAD(req_head, PrefCachePartReq) list; CoMutex lock; + uint32_t cnt; } requests; + QEMUBH *bh; int ret; } PrefCacheAIOCB; @@ -217,6 +219,27 @@ static BlockNode *pcache_node_prev(BlockNode* node, RbNodeKey *key) return node; } +static void *node_search(struct RbRoot *root, RbNodeKey *key) +{ + struct RbNode *rb_node = root->rb_node; + + while (rb_node) { + BlockNode *node = container_of(rb_node, BlockNode, rb_node); + int32_t result = pcache_key_cmp(key, &node->key); + if (result == 0) { + return pcache_node_prev(node, key); + } + rb_node = result < 0 ? rb_node->rb_left : rb_node->rb_right; + } + return NULL; +} + +static PCNode *pcache_node_search(struct RbRoot *root, RbNodeKey *key) +{ + PCNode *node = node_search(root, key); + return node == NULL ? NULL : pcache_node_ref(node); +} + static void *node_insert(struct RbRoot *root, BlockNode *node) { struct RbNode **new = &(root->rb_node), *parent = NULL; @@ -320,6 +343,8 @@ static inline void push_node_request(PrefCacheAIOCB *acb, PCNode *node) { PrefCachePartReq *req = pcache_req_get(acb, node); + acb->requests.cnt++; + QTAILQ_INSERT_HEAD(&acb->requests.list, req, entry); } @@ -360,6 +385,38 @@ static bool pcache_node_find_and_create(PrefCacheAIOCB *acb, RbNodeKey *key, return true; } +static uint64_t ranges_overlap_size(uint64_t node1, uint32_t size1, + uint64_t node2, uint32_t size2) +{ + return MIN(node1 + size1, node2 + size2) - MAX(node1, node2); +} + +static void pcache_node_read(PrefCacheAIOCB *acb, PCNode* node) +{ + uint64_t qiov_offs = 0, node_offs = 0; + uint32_t size; + uint32_t copy; + + if (acb->sector_num < node->cm.sector_num) { + qiov_offs = (node->cm.sector_num - acb->sector_num) << BDRV_SECTOR_BITS; + } else { + node_offs = (acb->sector_num - node->cm.sector_num) << BDRV_SECTOR_BITS; + } + size = ranges_overlap_size(acb->sector_num, acb->nb_sectors, + node->cm.sector_num, node->cm.nb_sectors) + << BDRV_SECTOR_BITS; + + assert(node->status == NODE_SUCCESS_STATUS || + node->status == NODE_REMOVE_STATUS); + assert(node->data != NULL); + + qemu_co_mutex_lock(&node->lock); + copy = \ + qemu_iovec_from_buf(acb->qiov, qiov_offs, node->data + node_offs, size); + assert(copy == size); + qemu_co_mutex_unlock(&node->lock); +} + static inline void prefetch_init_key(PrefCacheAIOCB *acb, RbNodeKey* key) { key->num = acb->sector_num; @@ -388,7 +445,7 @@ static void pcache_pickup_parts_of_cache(PrefCacheAIOCB *acb, PCNode *node, size -= up_size; num += up_size; } - /* XXX: node read */ + pcache_node_read(acb, node); up_size = MIN(node->cm.sector_num + node->cm.nb_sectors - num, size); pcache_node_unref(acb->s, node); @@ -429,13 +486,28 @@ static int32_t pcache_prefetch(PrefCacheAIOCB *acb) node->cm.sector_num + node->cm.nb_sectors >= acb->sector_num + acb->nb_sectors) { - /* XXX: node read */ + pcache_node_read(acb, node); pcache_node_unref(acb->s, node); return PREFETCH_FULL_UP; } pcache_pickup_parts_of_cache(acb, node, key.num, key.size); - return PREFETCH_PART_UP; + return acb->requests.cnt == 0 ? PREFETCH_FULL_UP : PREFETCH_PART_UP; +} + +static void pcache_aio_bh(void *opaque) +{ + PrefCacheAIOCB *acb = opaque; + qemu_bh_delete(acb->bh); + acb->common.cb(acb->common.opaque, 0); + qemu_aio_unref(acb); +} + +static void complete_aio_request(PrefCacheAIOCB *acb) +{ + acb->bh = aio_bh_new(bdrv_get_aio_context(acb->common.bs), + pcache_aio_bh, acb); + qemu_bh_schedule(acb->bh); } static void pcache_node_submit(PrefCachePartReq *req) @@ -471,7 +543,7 @@ static void pcache_merge_requests(PrefCacheAIOCB *acb) pcache_node_submit(req); - /* XXX: pcache read */ + pcache_node_read(acb, req->node); pcache_node_unref(acb->s, req->node); @@ -480,11 +552,36 @@ static void pcache_merge_requests(PrefCacheAIOCB *acb) qemu_co_mutex_unlock(&acb->requests.lock); } +static void pcache_try_node_drop(PrefCacheAIOCB *acb) +{ + BDRVPCacheState *s = acb->s; + RbNodeKey key; + + prefetch_init_key(acb, &key); + + do { + PCNode *node; + qemu_co_mutex_lock(&s->pcache.tree.lock); + node = pcache_node_search(&s->pcache.tree.root, &key); + qemu_co_mutex_unlock(&s->pcache.tree.lock); + if (node == NULL) { + break; + } + + pcache_node_drop(s, node); + + pcache_node_unref(s, node); + } while (true); +} + static void pcache_aio_cb(void *opaque, int ret) { PrefCacheAIOCB *acb = opaque; if (acb->aio_type & QEMU_AIO_READ) { + if (atomic_dec_fetch(&acb->requests.cnt) > 0) { + return; + } pcache_merge_requests(acb); } @@ -503,6 +600,7 @@ static PrefCacheAIOCB *pcache_aio_get(BlockDriverState *bs, int64_t sector_num, acb->s = bs->opaque; acb->sector_num = sector_num; acb->nb_sectors = nb_sectors; + acb->requests.cnt = 0; acb->qiov = qiov; acb->aio_type = type; acb->ret = 0; @@ -522,10 +620,21 @@ static BlockAIOCB *pcache_aio_readv(BlockDriverState *bs, { PrefCacheAIOCB *acb = pcache_aio_get(bs, sector_num, qiov, nb_sectors, cb, opaque, QEMU_AIO_READ); - pcache_prefetch(acb); - - bdrv_aio_readv(bs->file, sector_num, qiov, nb_sectors, - pcache_aio_cb, acb); + int32_t status = pcache_prefetch(acb); + if (status == PREFETCH_FULL_UP) { + assert(acb->requests.cnt == 0); + complete_aio_request(acb); + } else { + PrefCachePartReq *req; + assert(acb->requests.cnt != 0); + + qemu_co_mutex_lock(&acb->requests.lock); + QTAILQ_FOREACH(req, &acb->requests.list, entry) { + bdrv_aio_readv(bs->file, req->sector_num, &req->qiov, + req->nb_sectors, pcache_aio_cb, acb); + } + qemu_co_mutex_unlock(&acb->requests.lock); + } return &acb->common; } @@ -538,6 +647,7 @@ static BlockAIOCB *pcache_aio_writev(BlockDriverState *bs, { PrefCacheAIOCB *acb = pcache_aio_get(bs, sector_num, qiov, nb_sectors, cb, opaque, QEMU_AIO_WRITE); + pcache_try_node_drop(acb); /* XXX: use write through */ bdrv_aio_writev(bs->file, sector_num, qiov, nb_sectors, pcache_aio_cb, acb);