From patchwork Fri Dec 30 14:31:39 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Butsykin X-Patchwork-Id: 9492243 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 4613260417 for ; Fri, 30 Dec 2016 15:08:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3776F1FF29 for ; Fri, 30 Dec 2016 15:08:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2C07A223B2; Fri, 30 Dec 2016 15:08:53 +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 3E8BD1FF29 for ; Fri, 30 Dec 2016 15:08:52 +0000 (UTC) Received: from localhost ([::1]:40224 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cMynb-00031F-9v for patchwork-qemu-devel@patchwork.kernel.org; Fri, 30 Dec 2016 10:08:51 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40614) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cMykt-0001A7-86 for qemu-devel@nongnu.org; Fri, 30 Dec 2016 10:06:04 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cMykp-0001l2-0C for qemu-devel@nongnu.org; Fri, 30 Dec 2016 10:06:03 -0500 Received: from mail-db5eur01on0091.outbound.protection.outlook.com ([104.47.2.91]:52399 helo=EUR01-DB5-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cMyko-0001kh-Lj; Fri, 30 Dec 2016 10:05:58 -0500 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=Cvhxx5ak2lrwHPhgocH216Vuahs2+jylLMzDPI48/CQ=; b=Z3HNs0HonNQVmaTCrDmEk1YhzaHIP1bhIdwvw3ra+V+T+qxubn6XGZ1CJjX8ZB7bbPtsRDnraFr7XRW1DQYXczFsXf7OOBVvCcfgSLuDYX5gU46vkoei8c2ugzLFCt6+8V427pcuxbTph+zFNYjusbg48KxunbirDzqvxS2NV28= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=pbutsykin@virtuozzo.com; Received: from pavelb-Z68P-DS3.sw.ru (195.214.232.6) by HE1PR0802MB2555.eurprd08.prod.outlook.com (10.175.35.148) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.803.11; Fri, 30 Dec 2016 14:32:13 +0000 From: Pavel Butsykin To: , Date: Fri, 30 Dec 2016 17:31:39 +0300 Message-ID: <20161230143142.18214-16-pbutsykin@virtuozzo.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20161230143142.18214-1-pbutsykin@virtuozzo.com> References: <20161230143142.18214-1-pbutsykin@virtuozzo.com> MIME-Version: 1.0 X-Originating-IP: [195.214.232.6] X-ClientProxiedBy: HE1PR0802CA0010.eurprd08.prod.outlook.com (10.172.123.148) To HE1PR0802MB2555.eurprd08.prod.outlook.com (10.175.35.148) X-MS-Office365-Filtering-Correlation-Id: 2c80fef3-b68c-4d4e-d3dd-08d430c0a568 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001); SRVR:HE1PR0802MB2555; X-Microsoft-Exchange-Diagnostics: 1; HE1PR0802MB2555; 3:u2x/dn1YZu0oPXJDMSShXaccEtuHmzEJGup9txeXYwV22nwJpZrz/nIvSaDPd7kM669kAlO55zZ4Kq8FN9CmPHBMme9oSKhrQuf2rKT1vC2wCqU0e9oMc4x4VOeGD7Kfh3uy/Rh1rsm4B487UkwJ4qYLGfgNaIZl70PB7kKNEZRlm4mVOSgQWkGJzKmyfJvjZRzNL82P6VQnAoc6DaV1Vunb56eSLDuoVXS02XsyhdKrJAph3DYoe6yh83OZuw0XBP/9e4eC9aovE9A2Grs4gA==; 25:ovSh2VsxGbXvgO1B8D3wQUuJJ+4rg/RntHZSeFpmbdo45n8CqpFeqgnHjrIm840sUDpyTrkvmNbNeV9IzO9pH/8Hr1z0m3hPumNGGQEc4RGjXGW1FwWbhpn2eotYY1CujHv8IOUqy+QnlFbz4V4r0GxVRdZRAUA/WIQkfZZ4ZrysV0t7JZhvYOkvbgdYjCMtTxEd+kdHZwYDiXYa+EMdraZFCLXVl6BzqbSbCZZyraOpQf9kRI6qxIBy8tqoHiegsLEQajTymCREAo6d7RYclcw8H8VANmlfTbgsyNclT0RKCLVa9RK9wbW0wm6n9C9/WA4BfiD0a9ftjpffuPChApJqQU6s8omlkxQULk+IDjrzUDd0EvdLTJDWGsGFg0EM74A6w77y2JaPr51p/6vqhmYYU5jROqfYpLrrugqGfgSTrJR3Qrw61ZfV/PKUGn+BOnnbG1DKxIKE3GZKkVyQhg== X-Microsoft-Exchange-Diagnostics: 1; HE1PR0802MB2555; 31:BZIh/AJVYLRdegaf0lfAdb3JHk6jvSZBN4pEdZIfj9uhjzgsM9XogQIxFx/8eCEq7VRGYBvoxP2ztWA/0GRkNUg+ieEErm4BMKpQfJ3UuTLEMwUkfnpSmwNiejAn/jxcfDrzZ/x1Ru0M/hIinQKd2F38s6meLaCsLLQamCg6n36SMUlpSxBgF/M2U67Tpsk/asA9QG01tsxgi3SdBlpV/4S1Ch9JtC0bgoJ1BRA1uJI+5/cWQtasoeKsYfOVH9+qHRkXQncFY+3MnawTb1SORw==; 20:NpibJByvJJX8gLqBNR0vs2L6cvMywGwfueOjEvZ8+BwaW44xWIPUj5pAu1+zP5A/eG641JMAjc113inOH0oAzq8YYcGrN1xaA2Ya5N77SISTkBlmDnYMuLdx75CQksZsRhaKehnqLx5qZuWNPIOKA8klEst9NQ8elKrBcyBUmw76d00Xm0GSLMGZ4df3xiGF4cfdIo2oOnsyY4dSifetOamHRu3+msdB6ykxUqYNjpNermQc/i7sbM8o3YH3IK0R X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040375)(601004)(2401047)(8121501046)(5005006)(3002001)(10201501046)(6041248)(20161123564025)(20161123562025)(20161123555025)(20161123558021)(20161123560025)(6072148); SRVR:HE1PR0802MB2555; BCL:0; PCL:0; RULEID:; SRVR:HE1PR0802MB2555; X-Microsoft-Exchange-Diagnostics: 1; HE1PR0802MB2555; 4:fp8pWiNs6P7ojY9OMdWKSJFNgl56ODfDvN1UrF2PwWqkXTPDiQEOOnTBw8+AvSsH7l+NL+gr/b8HrBj7PK62dfuSbTQ/FxOc5taICxuV6XBEYdJK3JfOeen1T2QeKHQnNHajR4091xd/CisE/lz3sYkuqirTqZqYJWK7CTeuirPoqneQ8YwwQ4JAeRnCo8GRf2QWDeRUk0E3w+SQDiOIW5nkU7Fr2tGwgMjbJKnEaXq1iWXUsWoBPon/gDEpvKqp4HNQS6QndkNnTzR3EjC9hbUonsa4Yi0tCoTIJThSHdpKhUJ9HAGRiwtExDJg3URzLujdKDS/GMx/IoVPTR5tQo7u9zD6b00Q8Khey4Oy8gc+QZ34Peaa7hs0YFUldZCK0tZxezIaehF0P2TyuLVtCzWFPvmYaLHNOF0DTSy6yX7cmtT8kzeQkcByTBRhQgr/Q/U/5XVbiFc+oJ6Ag7jEkp/5G0/Z1UjfFg6bx33mYhajwYG1FS/2KgrSE+YOeITndk0XE/zwb6LnJwpBswOhOMv74eqO47ZV2/yVsZA9w0wh/aCZNqooiDUBho2Ymry7kz60TwFxeMWRyWLTZiIBHflE7h45BhrxTQPC+Akr8zI= X-Forefront-PRVS: 0172F0EF77 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(4630300001)(6009001)(7916002)(39450400003)(199003)(189002)(6666003)(5660300001)(189998001)(5001770100001)(50226002)(81156014)(81166006)(5003940100001)(8676002)(97736004)(47776003)(66066001)(6486002)(36756003)(6116002)(3846002)(76176999)(105586002)(33646002)(92566002)(305945005)(38730400001)(50466002)(106356001)(50986999)(1076002)(6506006)(6512006)(69596002)(4326007)(2950100002)(25786008)(2906002)(7736002)(68736007)(53416004)(42186005)(48376002)(101416001)(86362001); DIR:OUT; SFP:1102; SCL:1; SRVR:HE1PR0802MB2555; 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; HE1PR0802MB2555; 23:wIfWpf9Gn/zGWyJamsKGOA6MkorWjfTSDik3ftT?= =?us-ascii?Q?DvbnBwS1klO85+2t8AmWAjxcLIs9aEVLVxeMgWEWrkt5BXeyUmlxLl+BzUun?= =?us-ascii?Q?fQIUwZ8hv9J3wFbGmt56MSeHzb3zjETDtvAJhxT0pVq1pxN/KAFwV0x2imM3?= =?us-ascii?Q?U2rbvEhuvKn9lOKK7YwAkcGQh+mVM6s4X1mM0VtTsX19B4FFodCM3GgoQEry?= =?us-ascii?Q?ty1QS0/v6cGEElc4YS/cxgkMXN+203UFLHOpPM8fxM88mcgqc3+aH/8ZVixj?= =?us-ascii?Q?Z79vDXPJHh/l21Jl3en5Nde4UEiVRJiVcczck/wNddmZVIfSpqXTA5Ce4p3Z?= =?us-ascii?Q?c7U7oHh+bkLuDpFF4qjBwayqzkhG8QgCpU19zrm4igszJjoliPzEwvj6xtiA?= =?us-ascii?Q?JjEBx5R9nugUpWpGWFW30qV+9QWXIyqzMKnyGZBsR7E/d3XDlP6akwBOd070?= =?us-ascii?Q?fghG+qnLRxw2PzVn5r9zyfkf3P/p1TlDV5QV2v2LuTOTzgxHH+gEWrSJfVE+?= =?us-ascii?Q?rk26W2qIkIDtztl0v6gzMSrhoXRfp04mRyPvR7w2zUsHR9OHiynrIMrGMwMG?= =?us-ascii?Q?dpOgw9z+nWPDi2Me29WKTDizblSHn+BdbPZKVztajqBFRBX41LUcFppgitCz?= =?us-ascii?Q?Va7YmjweNmqhB4g8rhOiCrC7FABbsG3xQxnw75MmqMes4x9R5wpi0nTtkRMF?= =?us-ascii?Q?wS4ma9l+Hq2bHq+t6GqsZC4U5n0D+X7cA9Bds6AcirG1dfGpqGj7n0IVhwuM?= =?us-ascii?Q?TlGBztCHi7rpZpbFNWxM/gNQxNPUGHovzCxyiOYTR/xl3ck1v4lYMSiMY6aG?= =?us-ascii?Q?HLPBrUz/OMUyPR7XQFjEs415758He6RLDU5fq+KzOZDKTbB/lgkKMHNNhwRN?= =?us-ascii?Q?/VC85fyM9RUDV0rMqoWi3Vr1vHlfA3jclEgcQ+qS90xrdRp0lmxe+460toCv?= =?us-ascii?Q?1x0Yh5aTXu0hJUq8614w+q//CNzr+s48hNOsN4X5/xzGo9AVG7CBsj6eSfoj?= =?us-ascii?Q?kMUgzRGi+pTnSHZwUXIP9CE6UK7Z5vYADYerAilYxXKErnH32MbeHFtDdEck?= =?us-ascii?Q?rmjX3sFE8gIQlJqgr9bj+VOdC9pF/8UIyB33a63p1S237IwHkrn7i7b1sQy1?= =?us-ascii?Q?W5hyI2Hwh4Rs=3D?= X-Microsoft-Exchange-Diagnostics: 1; HE1PR0802MB2555; 6:ISZhtX0TsSww5dzq2N7ghCTOMYlaTk3tyRmBNz1Ui/r6x2r+V+beu4J8wEO4m+eG8+ndeLrRrWhK3tRZAQbIWvuBSF3AvjSAlng/wgK3SySJREgq7fo9HlkZzq5pWGpi+yHqbyGSqp7Eg6ZuY2mE0H7YpqMjwExrVBefJRHuaySgHM/aeEn/2pkJ2iDX7M01J0usZF2GF54Y6pknxZ/PjxPGCmtvl49i7cnRJfEDCGCkj70XBLt/VZyhJMuNuHXVzPLF4Y85CaCudarR4rHkQ3K4HZ6Mnf9hv0or/321qH1AJU6Q700mOKjWHZExNcBkHVk7G15+Mk0I/w/VQyRs/IFX8apQNXiD+ft321eHxt3JrSL3yI6jRejvHPUYWV83VZjAIZcgXqcsUstcTZjk01/NuJ5n1o3hmy6Ugpz/19o=; 5:RSgz7NPy/Sdq+9Xn5SM5SIU6kGPTK9E8/ZyWCcYWkfJyXlIuW2J8lEx6i8gclOJoWXiO+feyHkOfxn7LYTFUp4UQpkqfiqVOgoFz260wEVERCNNrznb8AV1OGIGpwoImk1+GYGBcQ+G8TxTdeLm2MQ==; 24:HbL+5A5DI8mOEzSm/WnJkOhFxkN8BssNSEQEPfMsswgGSmadsUOCrF1jaqhN7EnEh+uKsGIxdlM0TrFFCb7kC6Nw9dtpVYtPv3SAt5UGZ04= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; HE1PR0802MB2555; 7:pSvabrmpA5cMw9t2jIeAOl4eIjTp+GNdmKchOZgHG2a6hjmBMl3QcbUvw140tLeYdnUZOeYXKdmLKc01zSN1YGLtv8mgRVwDG2uCpJhZv9soGQ2OLo9HrdLxcYBZoGnUpkMHXtoKlVsSJnkbiqwq3sFOY18ZHnTH5M1sdx6kezggzjxC+p6PupEpX0ACft5ud23a9Yttr7nT9gd8uBZLM95gtkvpYuBQQy7lfbeRvRXb7ZaF2jFjwnkOuH6zBs2aloeRaxEsZo8Bg0P3iPahmxYtrYWGxtcu6rhI04puUjqSo3PxR3X8yTzyxsSXYqNvdtK1GDhTmDUyxCBV7rPEz0/7Bv6YtAWHzfr3KrNiS9vmCs+eAZ3VQrAWkcZVeGiD4I7ZkqvGDZXbCn1qVgw6lDyO1Cq99GULasTLGFb10tcjVAPJjBRQmVjjx2cF9g5NIrVSavGn+5uMwfs5hxdvjg==; 20:OGS8E0pBQ+xiUgrjV14ajmcKWathPRvkEEhbqYKaRVELAX0iLl4ykqb/w/ET+g1DK+vrcJa7D0DWDL8eRUx0bwPJ+WVIXzLWuUKAJQfodyNckICi4pvrz7KXANqpI1zFQN3Gfu89duIaz3R5b0fySA6V7S33STtqtP1qLjRcmk4= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Dec 2016 14:32:13.0495 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: HE1PR0802MB2555 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 104.47.2.91 Subject: [Qemu-devel] [PATCH v2 15/18] block/pcache: pick up parts of the cache 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, den@openvz.org, armbru@redhat.com, mreitz@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Provided that the request size is less than the readahead size, a partial cache hit can occur in the following three cases: 1. The request covers the bottom part of the node 2. The request covers the upper part of the node 3. The request is between two nodes and partially covers both of them The function pickup_parts_of_cache() covers all three cases and for the uncached part of the request it creates a new request. Signed-off-by: Pavel Butsykin --- block/pcache.c | 174 ++++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 166 insertions(+), 8 deletions(-) diff --git a/block/pcache.c b/block/pcache.c index 86b28de44b..3f89e40b05 100644 --- a/block/pcache.c +++ b/block/pcache.c @@ -10,6 +10,7 @@ */ #include "qemu/osdep.h" +#include "qemu/error-report.h" #include "block/block_int.h" #include "qapi/error.h" #include "qapi/qmp/qstring.h" @@ -355,6 +356,153 @@ static void pcache_readahead_entry(void *opaque) readahead_co->bytes); } +/* + * Provided that the request size is less or equal than the readahead size, + * a partial cache hit can occur in the following three cases: + * 1. The request covers the bottom part of the node. + * 2. The request covers the upper part of the node. + * 3. The request is between two nodes and partially covers both of them. + * + * Therefore, the request can be divided into no more than 3 parts. + */ +#define PCACHE_MAX_FRAGMENT_NUM 3 + +typedef struct PartReqEntry { + ReqLinkEntry rlink; + PCacheNode *node; +} PartReqEntry; + +typedef struct PartReqDesc { + Coroutine *co; + PartReqEntry parts[PCACHE_MAX_FRAGMENT_NUM]; + uint32_t cnt; + uint32_t completed; +} PartReqDesc; + +typedef struct PCachePartReqCo { + BlockDriverState *bs; + uint64_t offset; + uint64_t bytes; + PartReqDesc *desc; +} PCachePartReqCo; + +static void coroutine_fn pcache_co_part_req(BlockDriverState *bs, + uint64_t offset, uint64_t bytes, + PartReqDesc *req) +{ + BDRVPCacheState *s = bs->opaque; + QEMUIOVector qiov; + PartReqEntry *part = &req->parts[req->cnt]; + PCacheNode *node = container_of(rbcache_node_alloc(s->cache, offset, bytes), + PCacheNode, common); + node->status = NODE_STATUS_INFLIGHT; + qemu_iovec_init(&qiov, 1); + qemu_iovec_add(&qiov, node->data, node->common.bytes); + + part->node = node; + assert(++req->cnt <= PCACHE_MAX_FRAGMENT_NUM); + + part->rlink.ret = bdrv_co_preadv(bs->file, offset, bytes, &qiov, 0); + + node->status = NODE_STATUS_COMPLETED | NODE_STATUS_REMOVE; + QLIST_INSERT_HEAD(&s->remove_node_list, node, entry); + + if (!qemu_coroutine_entered(req->co)) { + qemu_coroutine_enter(req->co); + } else { + req->completed++; + } +} + +static void pcache_part_req_entry(void *opaque) +{ + PCachePartReqCo *req_co = opaque; + + pcache_co_part_req(req_co->bs, req_co->offset, req_co->bytes, req_co->desc); +} + +static int pickup_parts_of_cache(BlockDriverState *bs, PCacheNode *node, + uint64_t offset, uint64_t bytes, + QEMUIOVector *qiov) +{ + BDRVPCacheState *s = bs->opaque; + PartReqDesc req = { + .co = qemu_coroutine_self(), + }; + PCachePartReqCo req_co = { + .bs = bs, + .desc = &req + }; + uint64_t chunk_offset = offset, chunk_bytes = bytes; + uint64_t up_size; + int ret = 0; + + do { + pcache_node_ref(node); + + if (chunk_offset < node->common.offset) { + Coroutine *co; + + req_co.offset = chunk_offset; + req_co.bytes = up_size = node->common.offset - chunk_offset; + + co = qemu_coroutine_create(pcache_part_req_entry, &req_co); + qemu_coroutine_enter(co); + + chunk_offset += up_size; + chunk_bytes -= up_size; + } + + req.parts[req.cnt].node = node; + if (node->status & NODE_STATUS_INFLIGHT) { + req.parts[req.cnt].rlink.co = qemu_coroutine_self(); + QTAILQ_INSERT_HEAD(&node->wait_list, + &req.parts[req.cnt].rlink, entry); + } else { + req.completed++; + } + assert(++req.cnt <= PCACHE_MAX_FRAGMENT_NUM); + + up_size = MIN(node->common.offset + node->common.bytes - chunk_offset, + chunk_bytes); + chunk_bytes -= up_size; + chunk_offset += up_size; + + if (chunk_bytes != 0) { + node = rbcache_search(s->cache, chunk_offset, chunk_bytes); + if (node == NULL) { + Coroutine *co; + + req_co.offset = chunk_offset; + req_co.bytes = chunk_bytes; + + co = qemu_coroutine_create(pcache_part_req_entry, &req_co); + qemu_coroutine_enter(co); + chunk_bytes = 0; + } + } + } while (chunk_bytes != 0); + + while (req.completed < req.cnt) { + qemu_coroutine_yield(); + req.completed++; + } + + while (req.cnt--) { + PartReqEntry *part = &req.parts[req.cnt]; + if (ret == 0) { + if (part->rlink.ret == 0) { + read_cache_data_direct(part->node, offset, bytes, qiov); + } else { + ret = part->rlink.ret; + } + } + pcache_node_unref(part->node); + } + + return ret; +} + enum { CACHE_MISS, CACHE_HIT, @@ -364,6 +512,7 @@ static int pcache_lookup_data(BlockDriverState *bs, uint64_t offset, uint64_t bytes, QEMUIOVector *qiov) { BDRVPCacheState *s = bs->opaque; + int ret; PCacheNode *node = rbcache_search(s->cache, offset, bytes); if (node == NULL) { @@ -374,14 +523,16 @@ static int pcache_lookup_data(BlockDriverState *bs, uint64_t offset, if (node->common.offset <= offset && node->common.offset + node->common.bytes >= offset + bytes) { - int ret = read_cache_data(node, offset, bytes, qiov); - if (ret < 0) { - return ret; - } - return CACHE_HIT; + ret = read_cache_data(node, offset, bytes, qiov); + + } else { + ret = pickup_parts_of_cache(bs, node, offset, bytes, qiov); } - return CACHE_MISS; + if (ret < 0) { + return ret; + } + return CACHE_HIT; } static coroutine_fn int pcache_co_preadv(BlockDriverState *bs, uint64_t offset, @@ -484,7 +635,7 @@ static coroutine_fn int pcache_co_pwritev(BlockDriverState *bs, uint64_t offset, return ret; } -static void pcache_state_init(QemuOpts *opts, BDRVPCacheState *s) +static int pcache_state_init(QemuOpts *opts, BDRVPCacheState *s) { uint64_t stats_size = qemu_opt_get_size(opts, PCACHE_OPT_STATS_SIZE, PCACHE_DEFAULT_STATS_SIZE); @@ -499,6 +650,13 @@ static void pcache_state_init(QemuOpts *opts, BDRVPCacheState *s) s->readahead_size = qemu_opt_get_size(opts, PCACHE_OPT_READAHEAD_SIZE, PCACHE_DEFAULT_READAHEAD_SIZE); QLIST_INIT(&s->remove_node_list); + + if (s->readahead_size < s->max_aio_size) { + error_report("Readahead size can't be less than maximum request size" + "that can be handled by pcache"); + return -ENOTSUP; + } + return 0; } static int pcache_file_open(BlockDriverState *bs, QDict *options, int flags, @@ -524,7 +682,7 @@ static int pcache_file_open(BlockDriverState *bs, QDict *options, int flags, error_propagate(errp, local_err); goto fail; } - pcache_state_init(opts, bs->opaque); + ret = pcache_state_init(opts, bs->opaque); fail: qemu_opts_del(opts); return ret;