From patchwork Tue Nov 15 06:37:13 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Butsykin X-Patchwork-Id: 9430175 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 9E24C6047D for ; Tue, 15 Nov 2016 16:13:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8D2D027F93 for ; Tue, 15 Nov 2016 16:13:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8212828383; Tue, 15 Nov 2016 16:13:38 +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 BCB5328338 for ; Tue, 15 Nov 2016 16:13:37 +0000 (UTC) Received: from localhost ([::1]:47343 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c6gMb-0007Sn-07 for patchwork-qemu-devel@patchwork.kernel.org; Tue, 15 Nov 2016 11:13:37 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57064) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c6gHp-0004Uv-2h for qemu-devel@nongnu.org; Tue, 15 Nov 2016 11:08:42 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1c6gHk-0001IW-CV for qemu-devel@nongnu.org; Tue, 15 Nov 2016 11:08:41 -0500 Received: from mail-he1eur01on0126.outbound.protection.outlook.com ([104.47.0.126]:45289 helo=EUR01-HE1-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 1c6gHj-0001Gj-QV; Tue, 15 Nov 2016 11:08:36 -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=vCewhZqmo0xEmdpizUyLrF29GvHZbI0072WW1bEygrs=; b=PwWIg4N10nG7vjjzwejKu2pJXMig+5A8JpFG7FhSZhruKXxaU4uDNKVePZUisblQiEpJQRSoQl6szd5krXT4BsQPvXQWWCz+uaYHiNiHNSDIj80tURTdtQGl2Ng8zH23DtpsoTPqFxXIQDtE6bI9hVglMHY7LUv2D3Nk8FdIeA8= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=pbutsykin@virtuozzo.com; Received: from pavelb-Z68P-DS3.sw.ru (195.214.232.10) by VI1PR0802MB2558.eurprd08.prod.outlook.com (10.172.255.136) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.721.10; Tue, 15 Nov 2016 06:38:31 +0000 From: Pavel Butsykin To: , Date: Tue, 15 Nov 2016 09:37:13 +0300 Message-ID: <20161115063715.12561-17-pbutsykin@virtuozzo.com> X-Mailer: git-send-email 2.10.1 In-Reply-To: <20161115063715.12561-1-pbutsykin@virtuozzo.com> References: <20161115063715.12561-1-pbutsykin@virtuozzo.com> MIME-Version: 1.0 X-Originating-IP: [195.214.232.10] X-ClientProxiedBy: AM5PR0101CA0010.eurprd01.prod.exchangelabs.com (10.169.240.20) To VI1PR0802MB2558.eurprd08.prod.outlook.com (10.172.255.136) X-Microsoft-Exchange-Diagnostics: 1; VI1PR0802MB2558; 2:Dewr0FHUGVVR8h3U3V2ge6JsfW5CjKsoiCgie1qQ5N62VYtkqpi5sCx4FPNNMYP3XISps7qW3pDlFcDszW6g6Psm1fgHSt26lxUl00rn5v/iWEhiXbC9fDxmOJ6sS3TdYwSwt7OW42IPMAxD0QQeMYPFGaZp298IklAZ2kjYJNI=; 3:/YDH9MBMYiPLW/FAtoz6p11IehHd7+utdbiGL9hIcqk5mW8j1TMIYwNZKyzCZ/kvH0H92TBCUujb5JxgPXz21Dfklfyrt57yqjzXQtFOvkBvbhAAi6aMUslWXiaw/wWWx+65s+TRkdIimXIy6niKf/U1HZi9sgYWLopS+V2asvE= X-MS-Office365-Filtering-Correlation-Id: 4a925ecf-6ca8-4a74-cfbb-08d40d22048a X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001); SRVR:VI1PR0802MB2558; X-Microsoft-Exchange-Diagnostics: 1; VI1PR0802MB2558; 25:SdqY5eEZfGiYe6D3VTvIG93ltIMrwYY6Wkx0uuYjPuBssvxnVsWdYJFzyWjVIpdMJGb3JWU+016i6/rr91Dc5skpWy/0cy2suJDLvwE22TqvxRPHi91EGe2aAUsxwwRyE5+73vPkW76FRzGjOIP/DAplgA08PPp1Hjnm5YruTDqK2tqFsfv+7GrQIeKkLuRotUMddHrR+raPTY+ltlakVCdbaDKybN7Pe7l3ry2X004uvfHUAgwwvZI2dFr3ZXkIQAl84sMZxOmYIK4WoHDvCHQie2AvymiMtAnHt2nae2g2WrLzr2aVVbka0+jZy0aGDLjpZQL36NS7lik7VCqdN6Hi1sZJ1v4Zy3NGxJtg0KbjE5g2rOxu5xOWdjNSRlLm/pfdDaGv+AJ3QP2zCxkSKrHkIw0Q3OdTnUnZ22/auz1cNlHiDvinyPVF7OL/7lgE+HD37H6IeJaO22/oNt94u1Qi+1E0RtqT7dXtsWv5wcruckzVXpM3Q/F+57UkeobAM8yPu4AG9k+T+fgtScf++4JjqmoPry9KIUsQpfBckNlycgch6x8zUiG+IHNZzOgcA8dXLKF112foikgsIHTu1pm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Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6060326)(601004)(2401047)(8121501046)(5005006)(10201501046)(3002001)(6061324)(6043046); SRVR:VI1PR0802MB2558; BCL:0; PCL:0; RULEID:; SRVR:VI1PR0802MB2558; X-Forefront-PRVS: 012792EC17 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(4630300001)(6009001)(7916002)(199003)(189002)(47776003)(105586002)(101416001)(1076002)(68736007)(106356001)(6666003)(76176999)(305945005)(4326007)(97736004)(66066001)(53416004)(189998001)(42186005)(69596002)(2906002)(7736002)(5001770100001)(7846002)(86362001)(48376002)(50226002)(2950100002)(50466002)(50986999)(5003940100001)(33646002)(77096005)(81156014)(8676002)(92566002)(81166006)(3846002)(36756003)(6116002)(5660300001); DIR:OUT; SFP:1102; SCL:1; SRVR:VI1PR0802MB2558; 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; VI1PR0802MB2558; 23:weaFzyMPKTWdetp2IJ8ZYBGk9ywy2KNkLAvaYyu?= =?us-ascii?Q?EFnEoq91LB74/XNtA2L2jt2FGFFv3EYXWb2OIk5mUYB+cSrCwAtrdYI8e7fa?= =?us-ascii?Q?ElBmTkxFP+Xgf4uRXpKmbi2sCcFm3S5n4AA/mnuo+BRWU1dKrbcEjGHQpJtX?= =?us-ascii?Q?MT9uUZAaH6A2W+XSiLf5dn8dw3MXNnTW2URBvWKfZpmmFprKtWxLr7sh9rUN?= =?us-ascii?Q?cix0o77ELnG1u14gZfQk2rEMI4dhP8NVO3OcJfHaDbPZZVBl2jF9VezC03NT?= =?us-ascii?Q?vSLm3cJcG4O50qKlmzfc1xK/7YkKJGqp51axnVKf59roJl5tS9IUphLEyr1E?= =?us-ascii?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MIVIaPGMsdWxgXT4Ohn8VRGLSljb/ZTAEjivxa2KDqJNUihADkc5D1H6i240jh8iqo5OXQsTbeOPSkV4J0rONxTO2ifMWyGk= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Nov 2016 06:38:31.5522 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0802MB2558 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 104.47.0.126 Subject: [Qemu-devel] [PATCH v1 16/18] block/pcache: write through 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 Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Write-through is another way to keep the cache up-to-date. Even if this case will be rare, write to the cache is more optimal than drop-cache. Signed-off-by: Pavel Butsykin --- block/pcache.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/block/pcache.c b/block/pcache.c index df4834a..a592ea0 100644 --- a/block/pcache.c +++ b/block/pcache.c @@ -92,6 +92,7 @@ typedef struct PCacheAIOCBWrite { Coroutine *co; uint64_t offset; uint64_t bytes; + QEMUIOVector *qiov; int ret; } PCacheAIOCBWrite; @@ -553,6 +554,24 @@ out: return acb.ret; } +static void write_cache_data(QEMUIOVector *qiov, PCacheNode *node, + uint64_t offset, uint64_t bytes) +{ + uint64_t qiov_offs = 0, node_offs = 0; + uint64_t size; + uint64_t copy; + + if (offset < node->common.offset) { + qiov_offs = node->common.offset - offset; + } else { + node_offs = offset - node->common.offset; + } + size = ranges_overlap_size(offset, bytes, node->common.offset, + node->common.bytes); + copy = qemu_iovec_to_buf(qiov, qiov_offs, node->data + node_offs, size); + assert(copy == size); +} + static void pcache_aio_write_cb(void *opaque, int ret) { PCacheAIOCBWrite *acb = opaque; @@ -578,7 +597,7 @@ static void pcache_aio_write_cb(void *opaque, int ret) bytes = end_offs - offset; if (node->status == NODE_STATUS_COMPLETED) { - rbcache_remove(s->cache, &node->common); + write_cache_data(acb->qiov, node, acb->offset, acb->bytes); } } while (end_offs > offset); @@ -596,6 +615,7 @@ static coroutine_fn int pcache_co_pwritev(BlockDriverState *bs, uint64_t offset, .bs = bs, .offset = offset, .bytes = bytes, + .qiov = qiov, }; bdrv_aio_pwritev(bs->file, offset, qiov, bytes, pcache_aio_write_cb, &acb);