From patchwork Tue Nov 14 10:16:51 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Nefedov X-Patchwork-Id: 10057267 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 36F93601D3 for ; Tue, 14 Nov 2017 10:19:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0A9C92930B for ; Tue, 14 Nov 2017 10:19:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F3410292FF; Tue, 14 Nov 2017 10:19:01 +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 38B62292E5 for ; Tue, 14 Nov 2017 10:19:01 +0000 (UTC) Received: from localhost ([::1]:58629 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eEYJ2-0003Dl-Hr for patchwork-qemu-devel@patchwork.kernel.org; Tue, 14 Nov 2017 05:19:00 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48251) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eEYHT-0003AF-Rk for qemu-devel@nongnu.org; Tue, 14 Nov 2017 05:17:27 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eEYHN-00079q-Sg for qemu-devel@nongnu.org; Tue, 14 Nov 2017 05:17:23 -0500 Received: from mail-db5eur01on0136.outbound.protection.outlook.com ([104.47.2.136]:21775 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 1eEYHN-00078P-H6; Tue, 14 Nov 2017 05:17:17 -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=rh6fahBpaLDgcYGTgG2A/cpfLw0j1jmMvl41r3annOs=; b=EbAWc9au5YA0OON+30VIdQuothvNXQW4dBtxAT/jCAM3k4eF1+5xqiB/f6HatxBBfXSQlBvtV1ribRT9MNdL7Ng5kBbGgu/2lRXTTA4k4dbaw72SPDLiwCJPB8WhPy7EdPdlFZ//KNQa7KLHFDqdguN64pjlbkugcBB5A1tT/CY= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=anton.nefedov@virtuozzo.com; Received: from xantnef-ws.sw.ru (195.214.232.6) by HE1PR0801MB1993.eurprd08.prod.outlook.com (2603:10a6:3:4f::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.218.12; Tue, 14 Nov 2017 10:17:14 +0000 From: Anton Nefedov To: qemu-devel@nongnu.org Date: Tue, 14 Nov 2017 13:16:51 +0300 Message-Id: <1510654613-47868-4-git-send-email-anton.nefedov@virtuozzo.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1510654613-47868-1-git-send-email-anton.nefedov@virtuozzo.com> References: <1510654613-47868-1-git-send-email-anton.nefedov@virtuozzo.com> MIME-Version: 1.0 X-Originating-IP: [195.214.232.6] X-ClientProxiedBy: HE1PR0202CA0012.eurprd02.prod.outlook.com (2603:10a6:3:8c::22) To HE1PR0801MB1993.eurprd08.prod.outlook.com (2603:10a6:3:4f::23) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 3e212435-f908-4d13-4a62-08d52b48e0f7 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(4534020)(4602075)(4627115)(201703031133081)(201702281549075)(2017052603258); SRVR:HE1PR0801MB1993; X-Microsoft-Exchange-Diagnostics: 1; HE1PR0801MB1993; 3:Z8jWPvo/PuVgthl9+TvJw4zxKvMLPXWrn9BrXPUJUpw2dCff1y42vxnynhOSd2BGQ7LMqsMhsmSrlG/S6ZnvJCSXH2+EOE4kIQyq0T0x4gESZEzK54EcZE5WUSvPhZV0fhO6F0vR8jXr2dmjlYrwNky9ec+7pYhu+p0xomN+l5sZZ92pwfg2ppMUXX2OHwtXkOJfh+3ho1XcSi/Bzfhimg7a9avCQTSy+CFwErdAW+6nl4B0HEQLKG1k2C3JxnIP; 25:iB1vZ2yucCfma3KfdKVS+OS8RASUbEgP/Z8fGdVHCVwFXiWo9MHavrxt89dD+6Ro1gDb/hR+QoGyh9NRzIN5T7Rxm6WvC4zuB8KNl0h328aVdrH0FL5/7uTBcXQSBIxoR3x7B+ZZpHwjrrgSf2/J7aykQwYS8QRvwSeKHopq1m9oIydOY0UvYC3KIKacnAJAaPWAboLQIjXTfz1eQq/h+sVQciqYA4Lz+zAa0njFgAHmUg3xoFprFQaRDtO14wVcag4Ct6aWtFYLdbotv4+lOuz6qWWlJqKXT+/fVLcHe/u0gkh5tZYnhwLkt/VkloTBKqXnVN8raVxWgcebN2LodmLHK/ju1/JVyLeT3FJrmfo=; 31:af5/L7rwovicqZtLeErS3EB74JMzSvKKOrdCMsClfnqDUqR2Wmcq7ZKok/s3PsXt0wRxoz+KVRE5bgcXf7SvykryAkU+7KCAunsJgFGFLi3CzgsDF96pbrBTrtZhfoDR3AHRNKbsVsQcLD5CNwdepfu6FgfWnW1K9ZcLIA08LBca3U/8V29FXOUUVTawsDvsEF+iHA55BBCsU3uz06i9arl/4zzDnO5+JCMvQP4AYbE= X-MS-TrafficTypeDiagnostic: HE1PR0801MB1993: X-Microsoft-Exchange-Diagnostics: 1; HE1PR0801MB1993; 20:9VG4O7S3EBxcXy79y+0RlmFy44ynoeeMGlb1rR/5dT4jYR84Cv0pQDPfNlz1QUcaE8EdLtGD6feKu45iQmSqtMtmxGY9lNMKAvTJNr5sCXjYpysKc2wNupabhqqqYISd4UIaMpL/2KfMYg6fZi7paH9muwHtreH/4UISilsaja5FgAbfL8LZFR8rv2HP6ASGxYWwtmScqKuI7HNyiHA+qG+NZ1FEAmqR+qQ5cIoNCnfxYID3PQfzGEEj/BikjKnPeUEO8kppfm3yJZCepIcjSWLckGWDD+R3tCAXs6eMyD9qBGlUaybtEYDaKNd9jJDzzU3ORTVXtzM17KOrVJNlkD883g+d8bEpGTfW6uw+aU1QXysvxwMDYcKsssSS/sd7HG3SahsaLmcetuZjalufSHmXwNBckEHXT1PBg4qIQr0=; 4:545yG7qPqCc4obmfANCZMNQ2wHIsvtsdL1s7UtUtA9mYU4NsCOUzGOz3W9q/LHlTJNKW03lHSjfKFiFcvRajY3G2A+eCbsZbbERQZ0I8Q1PwAsfIc5ySYweEbLZ/4fdUnRonJUVWOV7racCr8yvTJ+qGIgza64/DUES8xeGI5u99y6Zg7OBjblDuS9V0GfaX7cHhkYqlZNTtq3qOc9Cj2QOvde1V4KxsAFdr+bcehDdsiWqRTBQlZ5sM1rIT0u0EZJpMVhR1yDVk80AvDz7mkA== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(6040450)(2401047)(5005006)(8121501046)(3231022)(3002001)(10201501046)(100000703101)(100105400095)(93006095)(93001095)(6041248)(20161123562025)(20161123558100)(20161123564025)(20161123560025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123555025)(6072148)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095); SRVR:HE1PR0801MB1993; BCL:0; PCL:0; RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095); SRVR:HE1PR0801MB1993; X-Forefront-PRVS: 04916EA04C X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(6009001)(376002)(346002)(39830400002)(189002)(199003)(97736004)(5003940100001)(6916009)(3846002)(2361001)(5660300001)(69596002)(6116002)(8936002)(8676002)(81156014)(230783001)(2950100002)(48376002)(33646002)(81166006)(2351001)(25786009)(6666003)(189998001)(50226002)(47776003)(6506006)(16526018)(106356001)(107886003)(105586002)(68736007)(478600001)(305945005)(36756003)(76176999)(50986999)(101416001)(316002)(16586007)(50466002)(4326008)(6512007)(2906002)(6486002)(53416004)(66066001)(53936002)(7736002)(86362001); DIR:OUT; SFP:1102; SCL:1; SRVR:HE1PR0801MB1993; H:xantnef-ws.sw.ru; FPR:; SPF:None; PTR:InfoNoRecords; MX:1; A: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; HE1PR0801MB1993; 23:1si7QgEDGAAr46045RmyDskLfRlQsYSYuEdg6Yp?= =?us-ascii?Q?bE8FGXLSfSkW8iedqTrNWsUi1kppP4GTFMtVJwhlkPrZOuv767iLGRNRgMX9?= =?us-ascii?Q?0lV0KvwuowmQBmraFFfmHELkUkOkR1FKlrYShYx0GnshEIKA8yTOzDzuwyNc?= =?us-ascii?Q?PJ6bZQq5BOIklhA+0TL9RZQPf63UGU2ZK+u0y+ixIpONiAf5CGxlacR42BAH?= =?us-ascii?Q?TFFH+p5TEPOezm3t4RoDbaVB0uQX8JaQJo3wGf+s/0CUb6vSp2xC8D0C3FCD?= =?us-ascii?Q?vulEwjgX8ppFA+FxpFhcejU9h3n7qatuAJ1SHlXw5B3UO1IskiGHqXYIliHh?= =?us-ascii?Q?i43PJd+DDFWADkdmYjoN8nbxhhGpMQ1B+7p0+X6LP06PhfzkthmLDE2gtPDC?= =?us-ascii?Q?3mxK2igrwMRNQzySojBg/pWLBNPPpNwaIbrHbD+eJp8Kt4s3PweQxAQkkeQG?= =?us-ascii?Q?8dA0SdgRHcjJOFMmRUMuQS7GQ9u1CYKV85N8qKJFUNd1L+37FJZKd0YlM+54?= =?us-ascii?Q?MRPK7PYHbYXs8qa7waXgvrPXcFWANY5dGLpqVC4lSIx3f/Rvmlr7nahPbG+o?= =?us-ascii?Q?wQajJ852ypXutbFZXTivD9bPZrwHzcTltLXPvSGR0aToZCq5yYwswYQVbgO2?= =?us-ascii?Q?SRGuL4F42UDB0WujM6T2EFWBZnM+41MoiGAQlenaFT6A8FzjKdz2DZc192tu?= =?us-ascii?Q?j/5QSsfs5dbiAt518Ae/KkxsxxTpea/QR8Dd9pqpTV2c77q2qNAY1DmxFIUm?= =?us-ascii?Q?4oGoM9sQDUl1wkD8r+AXb31jFN4uU1RrgBrwgv+3F5yHrAdsJuQnTFjqYpJz?= =?us-ascii?Q?IcofMetwb+0Tpdh3kp9UnCJFMEbnAV5CxIuGiYKLKxVPyAjXauGoLWUXbeLE?= =?us-ascii?Q?I2W9gslg+Y9y/F0gKpb2PFb5wpHwQEoOkZTJ7xUINpla7XUQECRtViCsWJ4h?= =?us-ascii?Q?RLmCuR/aFJqB++W+4FEAuG8Dq/ivMntjN4tD91DKsP2KH74z97Q9KORhVhPY?= =?us-ascii?Q?oUcFY8X8WEBavffF4d3Z3SuvwAsVZqoKStTyjT/NtPB0sO2uEBg3adRj9cIe?= =?us-ascii?Q?C3XSMhg1pck5e6e6e22qT99HdyW1OV8GsPZ4w3vhZd+1l4uJWfU1KPR9sMyl?= =?us-ascii?Q?7xVEbtp+u8JR0J2RRF9uKOB2qP3L8UTomR4uoeiEibCPWHBCijEZlAteB7sF?= =?us-ascii?Q?hJIt0aKXKjJiwMEiFDH6IvlSOjgaru3hoZDnO?= X-Microsoft-Exchange-Diagnostics: 1; HE1PR0801MB1993; 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MAxnNh8uDmXldh6bVQ4Mpt5G6G+j18SnJiqzpt2MPafX8dSFm3XZp6UWEkj91Lf9SFesAOpMtSoPhnjaxb31V4DNPPoM= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Nov 2017 10:17:14.9266 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 3e212435-f908-4d13-4a62-08d52b48e0f7 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-Transport-CrossTenantHeadersStamped: HE1PR0801MB1993 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 104.47.2.136 Subject: [Qemu-devel] [PATCH 3/5] block: support compressed write for copy-on-read 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, Anton Nefedov , famz@redhat.com, den@virtuozzo.com, qemu-block@nongnu.org, mreitz@redhat.com, stefanha@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: Anton Nefedov Reviewed-by: Max Reitz --- block/io.c | 30 ++++++++++++++++++++++++------ block/trace-events | 2 +- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/block/io.c b/block/io.c index 3d5ef2c..93c6b24 100644 --- a/block/io.c +++ b/block/io.c @@ -953,7 +953,7 @@ bdrv_driver_pwritev_compressed(BlockDriverState *bs, uint64_t offset, } static int coroutine_fn bdrv_co_do_copy_on_readv(BdrvChild *child, - int64_t offset, unsigned int bytes, QEMUIOVector *qiov) + int64_t offset, unsigned int bytes, QEMUIOVector *qiov, int flags) { BlockDriverState *bs = child->bs; @@ -988,12 +988,13 @@ static int coroutine_fn bdrv_co_do_copy_on_readv(BdrvChild *child, * allocating cluster in the image file. Note that this value may exceed * BDRV_REQUEST_MAX_BYTES (even when the original read did not), which * is one reason we loop rather than doing it all at once. + * Also this is crucial for compressed copy-on-read. */ bdrv_round_to_clusters(bs, offset, bytes, &cluster_offset, &cluster_bytes); skip_bytes = offset - cluster_offset; trace_bdrv_co_do_copy_on_readv(bs, offset, bytes, - cluster_offset, cluster_bytes); + cluster_offset, cluster_bytes, flags); bounce_buffer = qemu_try_blockalign(bs, MIN(MIN(max_transfer, cluster_bytes), @@ -1041,8 +1042,13 @@ static int coroutine_fn bdrv_co_do_copy_on_readv(BdrvChild *child, /* This does not change the data on the disk, it is not * necessary to flush even in cache=writethrough mode. */ - ret = bdrv_driver_pwritev(bs, cluster_offset, pnum, - &local_qiov, 0); + if (flags & BDRV_REQ_WRITE_COMPRESSED) { + ret = bdrv_driver_pwritev_compressed(bs, cluster_offset, + pnum, &local_qiov); + } else { + ret = bdrv_driver_pwritev(bs, cluster_offset, pnum, + &local_qiov, 0); + } } if (ret < 0) { @@ -1107,7 +1113,12 @@ static int coroutine_fn bdrv_aligned_preadv(BdrvChild *child, * potential fallback support, if we ever implement any read flags * to pass through to drivers. For now, there aren't any * passthrough flags. */ - assert(!(flags & ~(BDRV_REQ_NO_SERIALISING | BDRV_REQ_COPY_ON_READ))); + assert(!(flags & ~(BDRV_REQ_NO_SERIALISING | BDRV_REQ_COPY_ON_READ | + BDRV_REQ_WRITE_COMPRESSED))); + + /* write compressed only makes sense with copy on read */ + assert(!(flags & BDRV_REQ_WRITE_COMPRESSED) || + (flags & BDRV_REQ_COPY_ON_READ)); /* Handle Copy on Read and associated serialisation */ if (flags & BDRV_REQ_COPY_ON_READ) { @@ -1132,7 +1143,7 @@ static int coroutine_fn bdrv_aligned_preadv(BdrvChild *child, } if (!ret || pnum != bytes) { - ret = bdrv_co_do_copy_on_readv(child, offset, bytes, qiov); + ret = bdrv_co_do_copy_on_readv(child, offset, bytes, qiov, flags); goto out; } } @@ -1209,6 +1220,13 @@ int coroutine_fn bdrv_co_preadv(BdrvChild *child, return ret; } + /* write compressed only makes sense with copy on read */ + if ((flags & BDRV_REQ_WRITE_COMPRESSED) && + !(flags & BDRV_REQ_COPY_ON_READ)) + { + return -EINVAL; + } + bdrv_inc_in_flight(bs); /* Don't do copy-on-read if we read data before write operation */ diff --git a/block/trace-events b/block/trace-events index 11c8d5f..12fe188 100644 --- a/block/trace-events +++ b/block/trace-events @@ -12,7 +12,7 @@ blk_co_pwritev(void *blk, void *bs, int64_t offset, unsigned int bytes, int flag bdrv_co_preadv(void *bs, int64_t offset, int64_t nbytes, unsigned int flags) "bs %p offset %"PRId64" nbytes %"PRId64" flags 0x%x" bdrv_co_pwritev(void *bs, int64_t offset, int64_t nbytes, unsigned int flags) "bs %p offset %"PRId64" nbytes %"PRId64" flags 0x%x" bdrv_co_pwrite_zeroes(void *bs, int64_t offset, int count, int flags) "bs %p offset %"PRId64" count %d flags 0x%x" -bdrv_co_do_copy_on_readv(void *bs, int64_t offset, unsigned int bytes, int64_t cluster_offset, int64_t cluster_bytes) "bs %p offset %"PRId64" bytes %u cluster_offset %"PRId64" cluster_bytes %"PRId64 +bdrv_co_do_copy_on_readv(void *bs, int64_t offset, unsigned int bytes, int64_t cluster_offset, int64_t cluster_bytes, int flags) "bs %p offset %"PRId64" bytes %u cluster_offset %"PRId64" cluster_bytes %"PRId64" flags 0x%x" # block/stream.c stream_one_iteration(void *s, int64_t offset, uint64_t bytes, int is_allocated) "s %p offset %" PRId64 " bytes %" PRIu64 " is_allocated %d"