From patchwork Thu Nov 16 16:54:55 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Nefedov X-Patchwork-Id: 10061517 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 2F86060230 for ; Thu, 16 Nov 2017 16:56:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1FCDD2A5BE for ; Thu, 16 Nov 2017 16:56:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 147DD2AB55; Thu, 16 Nov 2017 16:56:40 +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 8EB9F2A5BE for ; Thu, 16 Nov 2017 16:56:39 +0000 (UTC) Received: from localhost ([::1]:41813 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eFNSw-0001SF-R9 for patchwork-qemu-devel@patchwork.kernel.org; Thu, 16 Nov 2017 11:56:38 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40183) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eFNRm-0001R6-4z for qemu-devel@nongnu.org; Thu, 16 Nov 2017 11:55:27 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eFNRi-0007Ob-KE for qemu-devel@nongnu.org; Thu, 16 Nov 2017 11:55:25 -0500 Received: from mail-he1eur01on0120.outbound.protection.outlook.com ([104.47.0.120]:43088 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 1eFNRi-0007Fo-1z; Thu, 16 Nov 2017 11:55:22 -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=RPxr/th3PVLkqye9KPeFeSApsdSLDDHupBr0cyEDcDY=; b=Upt6/jhUaDr7hn/JkX/zeqQwf1nSIPb7kz0MFz+VCxDfdvFqrTRBL2PO3RZXshCyqOTc3/HfpAojkcI0dRxaHr8MuaI+fhSC8aDluyPSjRLDWxE0y5nhB60GOJalEJ64Io01H1LugjM8JIn29i/UaQyhD7jOAWZvuwz+6sGPLrs= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=anton.nefedov@virtuozzo.com; Received: from xantnef-ws.sw.ru (195.214.232.6) by DB6PR0801MB1992.eurprd08.prod.outlook.com (2603:10a6:4:76::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.239.5; Thu, 16 Nov 2017 16:55:16 +0000 From: Anton Nefedov To: qemu-devel@nongnu.org Date: Thu, 16 Nov 2017 19:54:55 +0300 Message-Id: <1510851298-59922-2-git-send-email-anton.nefedov@virtuozzo.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1510851298-59922-1-git-send-email-anton.nefedov@virtuozzo.com> References: <1510851298-59922-1-git-send-email-anton.nefedov@virtuozzo.com> MIME-Version: 1.0 X-Originating-IP: [195.214.232.6] X-ClientProxiedBy: DB3PR0202CA0008.eurprd02.prod.outlook.com (2603:10a6:8:1::21) To DB6PR0801MB1992.eurprd08.prod.outlook.com (2603:10a6:4:76::9) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: e71ce6ed-d01e-454b-6b4a-08d52d12d091 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(4534020)(4602075)(7168017)(4627115)(201703031133081)(201702281549075)(2017052603258); SRVR:DB6PR0801MB1992; X-Microsoft-Exchange-Diagnostics: 1; DB6PR0801MB1992; 3:JQZwHWh+8b3Y2iTdRIHqHGVwG5YsSFTrawQ9bWeWrinQrBWnIbRwES9DsuzI2oDH1ZLzARWV0uS6qV87hYld6MSSiQkPpZX8jjP4k+SUoNnjvoTGKYLxNLUgCCC6n/IKx1rOoQeAz+itBXh5Gr97yiJ1SBZOYhgNWV7mJcHD2MtUApc2odK68kBvq1kNLFFxT1T2DLdXTmxH8Emg+GKa2v4WQIUXw+dQjca64PRxl1jbLd2STU+oXsE3dw+Gf3vI; 25:0ZCvmezSraYMrSCbC0WwUlz2komn+ULE9iefu/Haz8q3lgRdQLPKKNktLHWe4G51oHL/3q1waMexeUH5WhmCUsw+7StPc5xKWxrKaymNRq8q9SH1SZM9v6LrCRp9BzBLKjWlN792To5o1J39MVBsXyPgsY9Y4moDiZORFUfKZitBsXooDZmdYpCvRQkL2mwPLP2LVMP2tR53iyxUWq26LfqJpoBpgxOgvcamEd4IRX+NnCxI2Wd3QNUdPcSKBBpAWzzekv0YETkSnMCYFWhCrMKEBNbNWSHdTc92slpw2eNkq2uMjCATEcJvfB8YZxKKuoccd+uJM+84WfIWdWE4FA==; 31:9nN8yt1PuhCTmW2PsRuNdV3nqd8p4UV+8gYzyhOgywzgRTLkkXY/pfKeRJ5MmzzJTkem/OGkggb+TOpQLyoB6keS0gdR6Ki8aafYH0mhPQAyNTygExAIbI2xFjBThGwkx/FhXN89cegKpKUN8blldYL2NF79rP88eMpZ5HSWN7coxLg7fn+Lfx6Wk7j8kqSDSScmGZfcEkUYqXYsKQxWUvA1fdp8AWYe9nbVufnvBR4= X-MS-TrafficTypeDiagnostic: DB6PR0801MB1992: X-Microsoft-Exchange-Diagnostics: 1; DB6PR0801MB1992; 20:MXnE0WboXVjQJwzhs9wO/AvhQikHUC6i6Cmd9S45jIH5mwJ+Un2/X0Dag7/MfPtZaztNbFK46UO1nCwylsloCm3osI3f/8Q1GFqzhLjSqdAR0ozrOXMJbrnqdZQQbpCgR39wcIg0mGGeJ86ScRs4rW4eQxynFczAc3Ji/2A0br62uS2vciVlF2sDILn+qyh244Fd7lRvG248uGQ1JkRJcX0D+eskybgNXE9yI/Qu+R9bGOudhvMVPpv6c62MxUstPYEb9TtqmP4eq3bmsbxj+31hHWeB7G03ZIcZvQ2IPd+f++GgSqkePsh4U6OGoI0jHVYFslvpmIzzyxn03K+u8iXGtZr6S8rBuKZj4nst64lJaYhkHMFkg2SzJXgQ+jTtU+WzZTvPIrs/lWTeSzHuH1NAayzqBBa17J4dDS0cwu0=; 4:YS2mL1XzHx8opZ9XDnKTQUEm8/lTqDWSZxhfE9NKXgRYEn4wvg8zBRq9RTlsLnV2QNK7McYolVnJ/s+3BG0UCuSkPeUsiNkdO+/ffdEA8hhvuGhD2h4tksX1QaUsZjjIIl3rueVf0mltRkzYH6GxPt9ymLgfk7dyvUYjCPEcBZIot4Ol2HqKlYnwwrP0/gIEI4eVFN+AYI05lGKagdM7NwMZ3L5zg0qPtx6tQ8/QYYN4KtkCtL/OMTOf/BOELKcogst2F5syDQXE1BM7/cQrkw== 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)(8121501046)(5005006)(3002001)(10201501046)(3231022)(100000703101)(100105400095)(93006095)(93001095)(6041248)(20161123562025)(20161123560025)(20161123564025)(20161123555025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123558100)(6072148)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095); SRVR:DB6PR0801MB1992; BCL:0; PCL:0; RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095); SRVR:DB6PR0801MB1992; X-Forefront-PRVS: 0493852DA9 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(6009001)(376002)(346002)(189002)(199003)(189998001)(69596002)(54906003)(97736004)(2950100002)(6916009)(6666003)(47776003)(50466002)(66066001)(3846002)(48376002)(5660300001)(316002)(6116002)(16586007)(86362001)(5003940100001)(16526018)(33646002)(6512007)(478600001)(2361001)(106356001)(53936002)(105586002)(2351001)(36756003)(7736002)(76176999)(50986999)(107886003)(305945005)(50226002)(68736007)(53416004)(8676002)(81156014)(81166006)(25786009)(4326008)(8936002)(6506006)(101416001)(6486002)(2906002)(21314002); DIR:OUT; SFP:1102; SCL:1; SRVR:DB6PR0801MB1992; 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; DB6PR0801MB1992; 23:X5F3PYeLy4MOd2V/HQyTFxf3eY3dmMJ9Ud3P0cr?= =?us-ascii?Q?Q3qFDQ1UH9/RFj/zROEXkxKkuSnaGeC7Xu9Ix6DIkugPqTqnmUWe6kyvQtDr?= =?us-ascii?Q?Ve8BMnjH9N6ms160PW3qmO02OvT9nl8w3OTTwzPbYQ7znhaulCAlPLwp66cN?= =?us-ascii?Q?27OI+1+GriqdfpuEStGxFqWhCT19J4otk5cuA1f1RZ5vgFk//8KCWgqZKTv3?= =?us-ascii?Q?Va6KB6F11JJ/16T8oeQuX3abYDHR9YOqv07j4bPVSiCtpHlnur+vUvLxVwGa?= =?us-ascii?Q?qtc+CIJpyOYerVOr+gmLMTQTP2Z1D7hzDb0AguPFpb/Zr1qpED/VHXbpMDj0?= =?us-ascii?Q?l5mOj4SrpM6W1nVanPqRRAOSKB3Y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4EO8nzouVAvVNaP3A/OOISxmRiqHIZPZXf9zTN0NiQLwOt2yAwfsbJ5jHtar/TL4xKUuQvsVXuq7SFNVScEXU6vOvv05hLPcjxg4zlr8nac= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Nov 2017 16:55:16.6364 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: e71ce6ed-d01e-454b-6b4a-08d52d12d091 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB6PR0801MB1992 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 104.47.0.120 Subject: [Qemu-devel] [PATCH v2 1/4] 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. Signed-off-by: Anton Nefedov --- block/qcow2.c | 73 ++++++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 52 insertions(+), 21 deletions(-) diff --git a/block/qcow2.c b/block/qcow2.c index c276b24..f1e2759 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -3332,11 +3332,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; @@ -3346,25 +3344,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; } @@ -3444,6 +3429,52 @@ 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 < 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;