From patchwork Tue Nov 14 10:16:50 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Nefedov X-Patchwork-Id: 10057271 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 70693601D3 for ; Tue, 14 Nov 2017 10:21:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 43945292D9 for ; Tue, 14 Nov 2017 10:21:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 36937292F7; Tue, 14 Nov 2017 10:21:11 +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 87FF3292D9 for ; Tue, 14 Nov 2017 10:21:09 +0000 (UTC) Received: from localhost ([::1]:58643 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eEYL6-0005As-NC for patchwork-qemu-devel@patchwork.kernel.org; Tue, 14 Nov 2017 05:21:08 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48267) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eEYHV-0003BM-S9 for qemu-devel@nongnu.org; Tue, 14 Nov 2017 05:17:29 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eEYHL-000789-W8 for qemu-devel@nongnu.org; Tue, 14 Nov 2017 05:17:25 -0500 Received: from mail-db5eur01on0129.outbound.protection.outlook.com ([104.47.2.129]:55200 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 1eEYHL-000770-L9; Tue, 14 Nov 2017 05:17:15 -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=aRJWzfFwxQgGpmtCUv/7OB5Ez1wvB8AqrIUttg/9x6I=; b=VX7e2tOWhBGZC4VxFSiqGJZq9hN4p7jmnXjK5y0cBxRlCFAYxp/ciYKUlNWceTfVV85zuDmHQbhqY21XIGMGd63S+mM4LE3CXodkQ6U8YHu7JwbQopuGWwf7ugferVMcwOSOvkbnVkzkrObZADG+FODazIHQid/9dZLQkMD4Xu0= 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:13 +0000 From: Anton Nefedov To: qemu-devel@nongnu.org Date: Tue, 14 Nov 2017 13:16:50 +0300 Message-Id: <1510654613-47868-3-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: 6fe0e5b6-3f5f-4dfa-f4ca-08d52b48dfdd 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:O6/eFdu6P/vV6ZzTAC0J0LrA2/EFgO8mp5yOEyUJAUWt6FG4j4U6NCo0R5XXT7FBW5BqcaZ5+nIKUWrQf9Gt0SIXwfXj0LOtFPoTb0YZiAYF3rpGWzCLUCF+oa9jSTx1gxfYx51nUbhYotGIto45+MHG1KCZLgohG1ukK8IhjKEnxThjJQ7CZ0Zdui/ijUZFuqRwJpD68cLEZcbfzC3pv657KfA1HBYADHbjZx12ns5urEFmbNC1C9oeDL+PZlU3; 25:+I0Xl/Fq6Lu1QRtuk07UKCwE/rRLhvGZTdUUDjE/fSHMrgBs5gxbUZiXsVrmOnsFZg/WCXaTCBMBw0B7tS7b3e3dr8dm10HOzTbQ/RwQb3mQe44L5Fe5jYv4BdeZuSI54ee/3af1Yf8d5L6AAFhVxZRriLEDgCMomoc1l9bv/ltXWfw4zzhzjziPxq6zfjZ9VbQpGiPwpTTbBDvGaJ+1FZPJrEyxYlzXIJiGPmuuayMLCvZA5ORR9pFpjKbAyZsAT6/5lLSZdX38ceL5NDtyUTJ1mkP3nKOS+2S5ZiDEwGqVDCi9/5ZCSVQ3rqFLzcRzy4CN1BM9oRRefD7SjWjIH2kmbCVgQnAw7G3fIr3T/mI=; 31:qHdkkph0hzNw7ni5MzOD5ON4uUDroHJnj90ftlYpUw8Ymjvdq4cDapegUnAm5PHy2E+hA3mfTLjGYt0WdLaC2gbDFhOc7aZ2MtdCfHnF5PLordueLt52aJPrRzTgJJUaW1o2ncah7a4EN9QZ0J0QCyKGegWxFYTScGHzRSKwKvGGMa/T2F2Hho8R/2GgQ2/cTcGw7rAMiLHz8NzVVmvV/xRm1H1Ty+mZ71lskWAPlJ8= X-MS-TrafficTypeDiagnostic: HE1PR0801MB1993: X-Microsoft-Exchange-Diagnostics: 1; HE1PR0801MB1993; 20:2Y21pvR4E0P5H85ds3HZs1xWLoEI1IoPeHYgjHMmZgg5R+rUWm/z0zxqmpQ81f/ws42E8UgJeD6sznlH6bkkpu13Hp/fDQWKu8t9X9O3fTnSwpu9wXhWYgugAIILvQTGYLm9PeG7h5jAwLCI5QAKbbhGpA06AYkeOYL+XanLW7gVLxPWbRuBqVC1hoNpgxExvVLKu50Ti+NAEh8funpLW4aYzxPF0NLtx4MT+Ce3lyz4Pb+dI7ENPWEBxvMbYaHpL9pMZBe7GQk/RpdOQHe3HuCqBlvnIbhUWe/IB4Gd58ymRZ+Xm7Ata1/7STrS/h0OIqs1tTqrNzXKAd2e181fOMBtS8/3U6Sa1cbDfL9Ix5eSiFhVjPWTwWroY0bNs9CDb6QNaF1Kp/rScCQ381qZ/79TLETa4YGZhMQi59UiQbU=; 4:emF3XCXAetf/4+oHT2AzAdeQbsmpm3hdMwXj8kTB5ovAe3XO2F1QpKXQxMI0oVysCsScWKRKR2aQR+fLQNp5yAuCAsAUi2dqLfI+JpIym9khsjQlyBH79EA1zSxkKrX8z3qx0p6gZZROvEBz4zpQhXOm4OZ/0TEWthpaEJDk3YgJYL+ENHVIwgm2zn32OC9Q1WQEziGo/uzcoowAP52W2KX4NhxfqSwrcpP/wKEhcF5bVxqO0bNzbZSbs5QaE7agfPNXX632lxk0zJuZopPPnw== 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)(2950100002)(48376002)(33646002)(81166006)(2351001)(25786009)(6666003)(189998001)(50226002)(47776003)(6506006)(16526018)(106356001)(107886003)(105586002)(68736007)(478600001)(305945005)(36756003)(76176999)(50986999)(54906003)(101416001)(316002)(16586007)(50466002)(4326008)(6512007)(2906002)(6486002)(53416004)(66066001)(53936002)(7736002)(86362001)(21314002); 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:VbDl9SIqdC3e4AtpoRHV3dy3ULYjOFN0vc7tv+C?= =?us-ascii?Q?rIwf67QSRLWFlwi8ccFl9GNJ9NXI4ZRL/xHNlsU8zOgcoJz/2+DPcUM8Y+fX?= =?us-ascii?Q?W1ctFFvqfbQNsDLPPNsNNGnCjBQA/06wVRoeVujHzmgRUKgzYc5jOJj1lbBJ?= =?us-ascii?Q?UuOdX18zYzuPI3jEgniI3Lv2BD9GAikcC1coF9NxpO0hEIfFJ0pz7YQsjGz0?= =?us-ascii?Q?qFNPROHllngtaHF1/bZ5gELUCXKyt3HckRc3t+hrlyHzZhwguVxzu+21ZnPd?= =?us-ascii?Q?lF8XA3xsisOxlcl9yY8BW4Y3HoJepUBvpR+dtnY/X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adata: NSPM X-Microsoft-Exchange-Diagnostics: 1; HE1PR0801MB1993; 20:Za93DzHDBjdiFVMnHwuyeWRhajeYg5y9goUAkMzLVvr64HsIzHHAJBfTvHYbvF+ObNqt8qa7UgE0YAMK1+y9hIR929eKVHE5tGGWOtgDJP03lgWHgyQUKnuqMyBadQ25rzQuBEEAMpFWAJhym3i8zAQUM2J1+QRwH8V84HWXDx4= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Nov 2017 10:17:13.0204 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 6fe0e5b6-3f5f-4dfa-f4ca-08d52b48dfdd 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.129 Subject: [Qemu-devel] [PATCH 2/5] qcow2: multiple clusters write compressed 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, Pavel Butsykin , 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 From: Pavel Butsykin At the moment, qcow2_co_pwritev_compressed can process the requests size less than or equal to one cluster. This patch added possibility to write compressed data in the QCOW2 more than one cluster. The implementation is simple, we just split large requests into separate clusters and write using existing functionality. For unaligned requests we use a workaround and do write data without compression. Signed-off-by: Anton Nefedov --- block/qcow2.c | 77 +++++++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 56 insertions(+), 21 deletions(-) diff --git a/block/qcow2.c b/block/qcow2.c index 45c5651..3d5f17d 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -3325,11 +3325,9 @@ static int qcow2_truncate(BlockDriverState *bs, int64_t offset, return 0; } -/* XXX: put compressed sectors first, then all the cluster aligned - tables to avoid losing bytes in alignment */ static coroutine_fn int -qcow2_co_pwritev_compressed(BlockDriverState *bs, uint64_t offset, - uint64_t bytes, QEMUIOVector *qiov) +qcow2_co_pwritev_cluster_compressed(BlockDriverState *bs, uint64_t offset, + uint64_t bytes, QEMUIOVector *qiov) { BDRVQcow2State *s = bs->opaque; QEMUIOVector hd_qiov; @@ -3339,25 +3337,12 @@ qcow2_co_pwritev_compressed(BlockDriverState *bs, uint64_t offset, uint8_t *buf, *out_buf; int64_t cluster_offset; - if (bytes == 0) { - /* align end of file to a sector boundary to ease reading with - sector based I/Os */ - cluster_offset = bdrv_getlength(bs->file->bs); - if (cluster_offset < 0) { - return cluster_offset; - } - return bdrv_truncate(bs->file, cluster_offset, PREALLOC_MODE_OFF, NULL); - } - - if (offset_into_cluster(s, offset)) { - return -EINVAL; - } + assert(bytes <= s->cluster_size); + assert(!offset_into_cluster(s, offset)); buf = qemu_blockalign(bs, s->cluster_size); - if (bytes != s->cluster_size) { - if (bytes > s->cluster_size || - offset + bytes != bs->total_sectors << BDRV_SECTOR_BITS) - { + if (bytes < s->cluster_size) { + if (offset + bytes != bs->total_sectors << BDRV_SECTOR_BITS) { qemu_vfree(buf); return -EINVAL; } @@ -3437,6 +3422,56 @@ fail: return ret; } +/* XXX: put compressed sectors first, then all the cluster aligned + tables to avoid losing bytes in alignment */ +static coroutine_fn int +qcow2_co_pwritev_compressed(BlockDriverState *bs, uint64_t offset, + uint64_t bytes, QEMUIOVector *qiov) +{ + BDRVQcow2State *s = bs->opaque; + QEMUIOVector hd_qiov; + uint64_t curr_off = 0; + int ret; + + if (bytes == 0) { + /* align end of file to a sector boundary to ease reading with + sector based I/Os */ + int64_t cluster_offset = bdrv_getlength(bs->file->bs); + if (cluster_offset < 0) { + return cluster_offset; + } + return bdrv_truncate(bs->file, cluster_offset, PREALLOC_MODE_OFF, NULL); + } + + if (offset_into_cluster(s, offset)) { + return -EINVAL; + } + + qemu_iovec_init(&hd_qiov, qiov->niov); + do { + uint32_t chunk_size; + + qemu_iovec_reset(&hd_qiov); + chunk_size = MIN(bytes, s->cluster_size); + qemu_iovec_concat(&hd_qiov, qiov, curr_off, chunk_size); + + ret = qcow2_co_pwritev_cluster_compressed(bs, offset + curr_off, + chunk_size, &hd_qiov); + if (ret == -ENOTSUP) { + ret = qcow2_co_pwritev(bs, offset + curr_off, chunk_size, + &hd_qiov, 0); + } + if (ret < 0) { + break; + } + curr_off += chunk_size; + bytes -= chunk_size; + } while (bytes); + qemu_iovec_destroy(&hd_qiov); + + return ret; +} + static int make_completely_empty(BlockDriverState *bs) { BDRVQcow2State *s = bs->opaque;