From nobody Tue May 7 09:01:17 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1584469714; cv=none; d=zohomail.com; s=zohoarc; b=EGaiLqPbt6y6BVJDej/Sr0aty/MpmYV6K9p5lkdWqzcy6iu+gFRfZt4Ec9Ks+97KubV99R1qDkKk4OqK9XLzsxCsImAnV5TxrHI6rv2vtTOcuHBh+xqyN2iN6BMtTRaktSFxfwKkMKk9ksAtu9tDgcBrSHFqguhArtRSwMV+i/Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1584469714; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Ou/0KyEh6obVUgTdbcmiNLde5sugFWKqcZlnZMotoF0=; b=Lc87bugCBYCj2BwjVG13lVA5V7B4Eo9QARNHjnRSh0YyImNHFpc/61xokg6x5QqNABVQJmbBYUflbA2TIqIh7DdNO5Mrd+ZxvU6A9cUX6wE4/e3xBDm4NU90UygGvaNTmxfYJB8kvaQGYh7Z9/ECP4tJ6Z4uilQJojlHSl7drIg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1584469714818375.81117056645894; Tue, 17 Mar 2020 11:28:34 -0700 (PDT) Received: from localhost ([::1]:39206 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEGx7-0002uh-Md for importer@patchew.org; Tue, 17 Mar 2020 14:28:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48946) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEGn0-0003aK-4E for qemu-devel@nongnu.org; Tue, 17 Mar 2020 14:18:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jEGmv-00009X-7o for qemu-devel@nongnu.org; Tue, 17 Mar 2020 14:18:05 -0400 Received: from fanzine.igalia.com ([178.60.130.6]:58019) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jEGmu-0005yQ-4J; Tue, 17 Mar 2020 14:18:01 -0400 Received: from [81.0.35.138] (helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1jEGmD-00015b-4T; Tue, 17 Mar 2020 19:17:17 +0100 Received: from berto by perseus.local with local (Exim 4.92) (envelope-from ) id 1jEGlw-0006O5-3A; Tue, 17 Mar 2020 19:17:00 +0100 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=Ou/0KyEh6obVUgTdbcmiNLde5sugFWKqcZlnZMotoF0=; b=j5zQvi7Gb8PnZMSYwAUhLo+nLO3gnL6WJmxEeLKaIEXiXoxVxge5oH0WISwICgt3UbrdNd+gSJgx7dd4gyrB4Gzu8ZDGVpt7CfjKCy8l2limx+A/phuknE20b+Yf1Y6qi22mwnArzqD0QhrXZMGRZV0QGSyctPBgvkLqb494O8DjTS8bD6BdOUqhALCzmSiaI3T2OkpVM4kAu+bAHymUOdiZG8RA93c05U5u8TcaIvmBdX5LSp6uv/31j0JqPt9xr1SqI4fjgaz+r11RP8RktLt24MSLo9VEbI0iNzRs8Pgj0yVPkpIrx2d2vFVYJGV9CJgBgGwfz9ahs36z/pMxhA==; From: Alberto Garcia To: qemu-devel@nongnu.org Subject: [PATCH v4 01/30] qcow2: Make Qcow2AioTask store the full host offset Date: Tue, 17 Mar 2020 19:15:58 +0100 Message-Id: X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy] X-Received-From: 178.60.130.6 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Anton Nefedov , Alberto Garcia , qemu-block@nongnu.org, Max Reitz , Vladimir Sementsov-Ogievskiy , "Denis V . Lunev" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" The file_cluster_offset field of Qcow2AioTask stores a cluster-aligned host offset. In practice this is not very useful because all users(*) of this structure need the final host offset into the cluster, which they calculate using host_offset =3D file_cluster_offset + offset_into_cluster(s, offset) There is no reason why Qcow2AioTask cannot store host_offset directly and that is what this patch does. (*) compressed clusters are the exception: in this case what file_cluster_offset was storing was the full compressed cluster descriptor (offset + size). This does not change with this patch but it is documented now. Signed-off-by: Alberto Garcia Reviewed-by: Eric Blake Reviewed-by: Max Reitz Reviewed-by: Vladimir Sementsov-Ogievskiy --- block/qcow2.c | 68 +++++++++++++++++++++++++-------------------------- 1 file changed, 33 insertions(+), 35 deletions(-) diff --git a/block/qcow2.c b/block/qcow2.c index d44b45633d..a00b0c8e45 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -74,7 +74,7 @@ typedef struct { =20 static int coroutine_fn qcow2_co_preadv_compressed(BlockDriverState *bs, - uint64_t file_cluster_offset, + uint64_t cluster_descriptor, uint64_t offset, uint64_t bytes, QEMUIOVector *qiov, @@ -2041,7 +2041,7 @@ out: =20 static coroutine_fn int qcow2_co_preadv_encrypted(BlockDriverState *bs, - uint64_t file_cluster_offset, + uint64_t host_offset, uint64_t offset, uint64_t bytes, QEMUIOVector *qiov, @@ -2068,16 +2068,12 @@ qcow2_co_preadv_encrypted(BlockDriverState *bs, } =20 BLKDBG_EVENT(bs->file, BLKDBG_READ_AIO); - ret =3D bdrv_co_pread(s->data_file, - file_cluster_offset + offset_into_cluster(s, offse= t), - bytes, buf, 0); + ret =3D bdrv_co_pread(s->data_file, host_offset, bytes, buf, 0); if (ret < 0) { goto fail; } =20 - if (qcow2_co_decrypt(bs, - file_cluster_offset + offset_into_cluster(s, offs= et), - offset, buf, bytes) < 0) + if (qcow2_co_decrypt(bs, host_offset, offset, buf, bytes) < 0) { ret =3D -EIO; goto fail; @@ -2095,7 +2091,7 @@ typedef struct Qcow2AioTask { =20 BlockDriverState *bs; QCow2ClusterType cluster_type; /* only for read */ - uint64_t file_cluster_offset; + uint64_t host_offset; /* or full descriptor in compressed clusters */ uint64_t offset; uint64_t bytes; QEMUIOVector *qiov; @@ -2108,7 +2104,7 @@ static coroutine_fn int qcow2_add_task(BlockDriverSta= te *bs, AioTaskPool *pool, AioTaskFunc func, QCow2ClusterType cluster_type, - uint64_t file_cluster_offset, + uint64_t host_offset, uint64_t offset, uint64_t bytes, QEMUIOVector *qiov, @@ -2123,7 +2119,7 @@ static coroutine_fn int qcow2_add_task(BlockDriverSta= te *bs, .bs =3D bs, .cluster_type =3D cluster_type, .qiov =3D qiov, - .file_cluster_offset =3D file_cluster_offset, + .host_offset =3D host_offset, .offset =3D offset, .bytes =3D bytes, .qiov_offset =3D qiov_offset, @@ -2132,7 +2128,7 @@ static coroutine_fn int qcow2_add_task(BlockDriverSta= te *bs, =20 trace_qcow2_add_task(qemu_coroutine_self(), bs, pool, func =3D=3D qcow2_co_preadv_task_entry ? "read" := "write", - cluster_type, file_cluster_offset, offset, bytes, + cluster_type, host_offset, offset, bytes, qiov, qiov_offset); =20 if (!pool) { @@ -2146,13 +2142,12 @@ static coroutine_fn int qcow2_add_task(BlockDriverS= tate *bs, =20 static coroutine_fn int qcow2_co_preadv_task(BlockDriverState *bs, QCow2ClusterType cluster_type, - uint64_t file_cluster_offset, + uint64_t host_offset, uint64_t offset, uint64_t byt= es, QEMUIOVector *qiov, size_t qiov_offset) { BDRVQcow2State *s =3D bs->opaque; - int offset_in_cluster =3D offset_into_cluster(s, offset); =20 switch (cluster_type) { case QCOW2_CLUSTER_ZERO_PLAIN: @@ -2168,19 +2163,17 @@ static coroutine_fn int qcow2_co_preadv_task(BlockD= riverState *bs, qiov, qiov_offset, 0); =20 case QCOW2_CLUSTER_COMPRESSED: - return qcow2_co_preadv_compressed(bs, file_cluster_offset, + return qcow2_co_preadv_compressed(bs, host_offset, offset, bytes, qiov, qiov_offset= ); =20 case QCOW2_CLUSTER_NORMAL: - assert(offset_into_cluster(s, file_cluster_offset) =3D=3D 0); if (bs->encrypted) { - return qcow2_co_preadv_encrypted(bs, file_cluster_offset, + return qcow2_co_preadv_encrypted(bs, host_offset, offset, bytes, qiov, qiov_off= set); } =20 BLKDBG_EVENT(bs->file, BLKDBG_READ_AIO); - return bdrv_co_preadv_part(s->data_file, - file_cluster_offset + offset_in_cluster, + return bdrv_co_preadv_part(s->data_file, host_offset, bytes, qiov, qiov_offset, 0); =20 default: @@ -2196,7 +2189,7 @@ static coroutine_fn int qcow2_co_preadv_task_entry(Ai= oTask *task) =20 assert(!t->l2meta); =20 - return qcow2_co_preadv_task(t->bs, t->cluster_type, t->file_cluster_of= fset, + return qcow2_co_preadv_task(t->bs, t->cluster_type, t->host_offset, t->offset, t->bytes, t->qiov, t->qiov_offs= et); } =20 @@ -2232,11 +2225,20 @@ static coroutine_fn int qcow2_co_preadv_part(BlockD= riverState *bs, { qemu_iovec_memset(qiov, qiov_offset, 0, cur_bytes); } else { + /* + * For compressed clusters the variable cluster_offset + * does not actually store the offset but the full + * descriptor. We need to leave it unchanged because + * that's what qcow2_co_preadv_compressed() expects. + */ + uint64_t host_offset =3D (ret =3D=3D QCOW2_CLUSTER_COMPRESSED)= ? + cluster_offset : + cluster_offset + offset_into_cluster(s, offset); if (!aio && cur_bytes !=3D bytes) { aio =3D aio_task_pool_new(QCOW2_MAX_WORKERS); } ret =3D qcow2_add_task(bs, aio, qcow2_co_preadv_task_entry, re= t, - cluster_offset, offset, cur_bytes, + host_offset, offset, cur_bytes, qiov, qiov_offset, NULL); if (ret < 0) { goto out; @@ -2387,7 +2389,7 @@ static int handle_alloc_space(BlockDriverState *bs, Q= CowL2Meta *l2meta) * not use it somehow after qcow2_co_pwritev_task() call */ static coroutine_fn int qcow2_co_pwritev_task(BlockDriverState *bs, - uint64_t file_cluster_offset, + uint64_t host_offset, uint64_t offset, uint64_t by= tes, QEMUIOVector *qiov, uint64_t qiov_offset, @@ -2396,7 +2398,6 @@ static coroutine_fn int qcow2_co_pwritev_task(BlockDr= iverState *bs, int ret; BDRVQcow2State *s =3D bs->opaque; void *crypt_buf =3D NULL; - int offset_in_cluster =3D offset_into_cluster(s, offset); QEMUIOVector encrypted_qiov; =20 if (bs->encrypted) { @@ -2409,8 +2410,7 @@ static coroutine_fn int qcow2_co_pwritev_task(BlockDr= iverState *bs, } qemu_iovec_to_buf(qiov, qiov_offset, crypt_buf, bytes); =20 - if (qcow2_co_encrypt(bs, file_cluster_offset + offset_in_cluster, - offset, crypt_buf, bytes) < 0) + if (qcow2_co_encrypt(bs, host_offset, offset, crypt_buf, bytes) < = 0) { ret =3D -EIO; goto out_unlocked; @@ -2435,10 +2435,8 @@ static coroutine_fn int qcow2_co_pwritev_task(BlockD= riverState *bs, */ if (!merge_cow(offset, bytes, qiov, qiov_offset, l2meta)) { BLKDBG_EVENT(bs->file, BLKDBG_WRITE_AIO); - trace_qcow2_writev_data(qemu_coroutine_self(), - file_cluster_offset + offset_in_cluster); - ret =3D bdrv_co_pwritev_part(s->data_file, - file_cluster_offset + offset_in_cluster, + trace_qcow2_writev_data(qemu_coroutine_self(), host_offset); + ret =3D bdrv_co_pwritev_part(s->data_file, host_offset, bytes, qiov, qiov_offset, 0); if (ret < 0) { goto out_unlocked; @@ -2468,7 +2466,7 @@ static coroutine_fn int qcow2_co_pwritev_task_entry(A= ioTask *task) =20 assert(!t->cluster_type); =20 - return qcow2_co_pwritev_task(t->bs, t->file_cluster_offset, + return qcow2_co_pwritev_task(t->bs, t->host_offset, t->offset, t->bytes, t->qiov, t->qiov_off= set, t->l2meta); } @@ -2523,8 +2521,8 @@ static coroutine_fn int qcow2_co_pwritev_part( aio =3D aio_task_pool_new(QCOW2_MAX_WORKERS); } ret =3D qcow2_add_task(bs, aio, qcow2_co_pwritev_task_entry, 0, - cluster_offset, offset, cur_bytes, - qiov, qiov_offset, l2meta); + cluster_offset + offset_in_cluster, offset, + cur_bytes, qiov, qiov_offset, l2meta); l2meta =3D NULL; /* l2meta is consumed by qcow2_co_pwritev_task() = */ if (ret < 0) { goto fail_nometa; @@ -4358,7 +4356,7 @@ qcow2_co_pwritev_compressed_part(BlockDriverState *bs, =20 static int coroutine_fn qcow2_co_preadv_compressed(BlockDriverState *bs, - uint64_t file_cluster_offset, + uint64_t cluster_descriptor, uint64_t offset, uint64_t bytes, QEMUIOVector *qiov, @@ -4370,8 +4368,8 @@ qcow2_co_preadv_compressed(BlockDriverState *bs, uint8_t *buf, *out_buf; int offset_in_cluster =3D offset_into_cluster(s, offset); =20 - coffset =3D file_cluster_offset & s->cluster_offset_mask; - nb_csectors =3D ((file_cluster_offset >> s->csize_shift) & s->csize_ma= sk) + 1; + coffset =3D cluster_descriptor & s->cluster_offset_mask; + nb_csectors =3D ((cluster_descriptor >> s->csize_shift) & s->csize_mas= k) + 1; csize =3D nb_csectors * QCOW2_COMPRESSED_SECTOR_SIZE - (coffset & ~QCOW2_COMPRESSED_SECTOR_MASK); =20 --=20 2.20.1 From nobody Tue May 7 09:01:17 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1584469172; cv=none; d=zohomail.com; s=zohoarc; b=F6fzndY8BDKMkIkIeGKWFNHFD8OZPAfMJWx9IQ0KeCc79gEuxlqq4y6rZSxqypZHlfu1BCTbPfOYGMIlHrSyHCbPgP2uMtblG5vjGnwA1Yik8SK5l6d9MyoVmb0f94XNyaeGq1l7nTPwArPlN8H24mPPh7UUjdboyoWCAovvLRY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1584469172; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=WLtKXfd2LOoul3dgnoi9cY4JxZC/k5JqOQ2OW7I73Go=; b=cBCMzeUmQV2kBo10b6qo6ExU/9BVOfUx6kMD2EhH6km8VWlJbvQpa0r59GVKa/BZu5s6FzKeODHfvvNn+RuAcErO7JWgQGp3r6OKuVnvTVIVlWOs0xmbC/eauFbLq5wePlRo2g4ZHILuOGCLdV7A0jQi/4F5JQlBD9WUC9Ubdog= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1584469172732643.7870907209455; Tue, 17 Mar 2020 11:19:32 -0700 (PDT) Received: from localhost ([::1]:38942 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEGoN-0004tN-IK for importer@patchew.org; Tue, 17 Mar 2020 14:19:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48332) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEGmb-0002oj-EJ for qemu-devel@nongnu.org; Tue, 17 Mar 2020 14:17:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jEGmZ-0007VA-1C for qemu-devel@nongnu.org; Tue, 17 Mar 2020 14:17:41 -0400 Received: from fanzine.igalia.com ([178.60.130.6]:57729) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jEGmX-0005Uy-AE; Tue, 17 Mar 2020 14:17:38 -0400 Received: from [81.0.35.138] (helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1jEGmC-00015Z-Vb; Tue, 17 Mar 2020 19:17:17 +0100 Received: from berto by perseus.local with local (Exim 4.92) (envelope-from ) id 1jEGlw-0006O7-42; Tue, 17 Mar 2020 19:17:00 +0100 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=WLtKXfd2LOoul3dgnoi9cY4JxZC/k5JqOQ2OW7I73Go=; b=Q+yZ8Ru3Y7qnLZ5stN6SGF6mIvMqrqkKuwr3XJJ4SK6JbowcXZSYOsr7SUz1CuD8CnPqhJ9Q8/nGPtKZL5f7+nXjXGpzGvN9obJfv/cwhimX9dr3Ihz6aK+EdNZJB+eJmYZhbysjkyYSzFD/QblU/5AT9tDGhyXztj7qdHnRqjW3BKuzxCU2Ei0VeT8zR2jnaj204EuzDLoTQQqkMTkLhsHFBc3l2xItRYZKk298/4BfCHorUh/jebbUtGN0pgol2ZhjtTpPMeSiQgKP0sL33nLkJaiwJYjG0nBY/+ztCuWBA5QRdK2Y/qlP1pI4+bIv6xQg9fB9xVZqnPPcZU7l7A==; From: Alberto Garcia To: qemu-devel@nongnu.org Subject: [PATCH v4 02/30] qcow2: Convert qcow2_get_cluster_offset() into qcow2_get_host_offset() Date: Tue, 17 Mar 2020 19:15:59 +0100 Message-Id: <65243debd4a41e1ebd13877c2e6c665759c37b38.1584468723.git.berto@igalia.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy] X-Received-From: 178.60.130.6 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Anton Nefedov , Alberto Garcia , qemu-block@nongnu.org, Max Reitz , Vladimir Sementsov-Ogievskiy , "Denis V . Lunev" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" qcow2_get_cluster_offset() takes an (unaligned) guest offset and returns the (aligned) offset of the corresponding cluster in the qcow2 image. In practice none of the callers need to know where the cluster starts so this patch makes the function calculate and return the final host offset directly. The function is also renamed accordingly. There is a pre-existing exception with compressed clusters: in this case the function returns the complete cluster descriptor (containing the offset and size of the compressed data). This does not change with this patch but it is now documented. Signed-off-by: Alberto Garcia Reviewed-by: Eric Blake Reviewed-by: Vladimir Sementsov-Ogievskiy --- block/qcow2.h | 4 ++-- block/qcow2-cluster.c | 38 ++++++++++++++++++++++---------------- block/qcow2.c | 24 +++++++----------------- 3 files changed, 31 insertions(+), 35 deletions(-) diff --git a/block/qcow2.h b/block/qcow2.h index 0942126232..f47ef6ca4e 100644 --- a/block/qcow2.h +++ b/block/qcow2.h @@ -679,8 +679,8 @@ int qcow2_write_l1_entry(BlockDriverState *bs, int l1_i= ndex); int qcow2_encrypt_sectors(BDRVQcow2State *s, int64_t sector_num, uint8_t *buf, int nb_sectors, bool enc, Error **= errp); =20 -int qcow2_get_cluster_offset(BlockDriverState *bs, uint64_t offset, - unsigned int *bytes, uint64_t *cluster_offset= ); +int qcow2_get_host_offset(BlockDriverState *bs, uint64_t offset, + unsigned int *bytes, uint64_t *host_offset); int qcow2_alloc_cluster_offset(BlockDriverState *bs, uint64_t offset, unsigned int *bytes, uint64_t *host_offset, QCowL2Meta **m); diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c index 17f1363279..95f04d12cc 100644 --- a/block/qcow2-cluster.c +++ b/block/qcow2-cluster.c @@ -496,10 +496,15 @@ static int coroutine_fn do_perform_cow_write(BlockDri= verState *bs, =20 =20 /* - * get_cluster_offset + * get_host_offset * - * For a given offset of the virtual disk, find the cluster type and offse= t in - * the qcow2 file. The offset is stored in *cluster_offset. + * For a given offset of the virtual disk find the equivalent host + * offset in the qcow2 file and store it in *host_offset. Neither + * offset needs to be aligned to a cluster boundary. + * + * If the cluster is unallocated then *host_offset will be 0. + * If the cluster is compressed then *host_offset will contain the + * complete compressed cluster descriptor. * * On entry, *bytes is the maximum number of contiguous bytes starting at * offset that we are interested in. @@ -511,12 +516,12 @@ static int coroutine_fn do_perform_cow_write(BlockDri= verState *bs, * Returns the cluster type (QCOW2_CLUSTER_*) on success, -errno in error * cases. */ -int qcow2_get_cluster_offset(BlockDriverState *bs, uint64_t offset, - unsigned int *bytes, uint64_t *cluster_offset) +int qcow2_get_host_offset(BlockDriverState *bs, uint64_t offset, + unsigned int *bytes, uint64_t *host_offset) { BDRVQcow2State *s =3D bs->opaque; unsigned int l2_index; - uint64_t l1_index, l2_offset, *l2_slice; + uint64_t l1_index, l2_offset, *l2_slice, l2_entry; int c; unsigned int offset_in_cluster; uint64_t bytes_available, bytes_needed, nb_clusters; @@ -537,7 +542,7 @@ int qcow2_get_cluster_offset(BlockDriverState *bs, uint= 64_t offset, bytes_needed =3D bytes_available; } =20 - *cluster_offset =3D 0; + *host_offset =3D 0; =20 /* seek to the l2 offset in the l1 table */ =20 @@ -570,7 +575,7 @@ int qcow2_get_cluster_offset(BlockDriverState *bs, uint= 64_t offset, /* find the cluster offset for the given disk offset */ =20 l2_index =3D offset_to_l2_slice_index(s, offset); - *cluster_offset =3D be64_to_cpu(l2_slice[l2_index]); + l2_entry =3D be64_to_cpu(l2_slice[l2_index]); =20 nb_clusters =3D size_to_clusters(s, bytes_needed); /* bytes_needed <=3D *bytes + offset_in_cluster, both of which are uns= igned @@ -578,7 +583,7 @@ int qcow2_get_cluster_offset(BlockDriverState *bs, uint= 64_t offset, * true */ assert(nb_clusters <=3D INT_MAX); =20 - type =3D qcow2_get_cluster_type(bs, *cluster_offset); + type =3D qcow2_get_cluster_type(bs, l2_entry); if (s->qcow_version < 3 && (type =3D=3D QCOW2_CLUSTER_ZERO_PLAIN || type =3D=3D QCOW2_CLUSTER_ZERO_ALLOC)) { qcow2_signal_corruption(bs, true, -1, -1, "Zero cluster entry foun= d" @@ -599,41 +604,42 @@ int qcow2_get_cluster_offset(BlockDriverState *bs, ui= nt64_t offset, } /* Compressed clusters can only be processed one by one */ c =3D 1; - *cluster_offset &=3D L2E_COMPRESSED_OFFSET_SIZE_MASK; + *host_offset =3D l2_entry & L2E_COMPRESSED_OFFSET_SIZE_MASK; break; case QCOW2_CLUSTER_ZERO_PLAIN: case QCOW2_CLUSTER_UNALLOCATED: /* how many empty clusters ? */ c =3D count_contiguous_clusters_unallocated(bs, nb_clusters, &l2_slice[l2_index], typ= e); - *cluster_offset =3D 0; + *host_offset =3D 0; break; case QCOW2_CLUSTER_ZERO_ALLOC: case QCOW2_CLUSTER_NORMAL: /* how many allocated clusters ? */ c =3D count_contiguous_clusters(bs, nb_clusters, s->cluster_size, &l2_slice[l2_index], QCOW_OFLAG_ZERO= ); - *cluster_offset &=3D L2E_OFFSET_MASK; - if (offset_into_cluster(s, *cluster_offset)) { + *host_offset =3D l2_entry & L2E_OFFSET_MASK; + if (offset_into_cluster(s, *host_offset)) { qcow2_signal_corruption(bs, true, -1, -1, "Cluster allocation offset %#" PRIx64 " unaligned (L2 offset: %#" PRI= x64 - ", L2 index: %#x)", *cluster_offset, + ", L2 index: %#x)", *host_offset, l2_offset, l2_index); ret =3D -EIO; goto fail; } - if (has_data_file(bs) && *cluster_offset !=3D offset - offset_in_c= luster) + if (has_data_file(bs) && *host_offset !=3D offset - offset_in_clus= ter) { qcow2_signal_corruption(bs, true, -1, -1, "External data file host cluster offse= t %#" PRIx64 " does not match guest cluster " "offset: %#" PRIx64 - ", L2 index: %#x)", *cluster_offset, + ", L2 index: %#x)", *host_offset, offset - offset_in_cluster, l2_index); ret =3D -EIO; goto fail; } + *host_offset +=3D offset_in_cluster; break; default: abort(); diff --git a/block/qcow2.c b/block/qcow2.c index a00b0c8e45..5b6ceaa2fa 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -1964,7 +1964,7 @@ static int coroutine_fn qcow2_co_block_status(BlockDr= iverState *bs, BlockDriverState **file) { BDRVQcow2State *s =3D bs->opaque; - uint64_t cluster_offset; + uint64_t host_offset; unsigned int bytes; int ret, status =3D 0; =20 @@ -1977,7 +1977,7 @@ static int coroutine_fn qcow2_co_block_status(BlockDr= iverState *bs, } =20 bytes =3D MIN(INT_MAX, count); - ret =3D qcow2_get_cluster_offset(bs, offset, &bytes, &cluster_offset); + ret =3D qcow2_get_host_offset(bs, offset, &bytes, &host_offset); qemu_co_mutex_unlock(&s->lock); if (ret < 0) { return ret; @@ -1987,7 +1987,7 @@ static int coroutine_fn qcow2_co_block_status(BlockDr= iverState *bs, =20 if ((ret =3D=3D QCOW2_CLUSTER_NORMAL || ret =3D=3D QCOW2_CLUSTER_ZERO_= ALLOC) && !s->crypto) { - *map =3D cluster_offset | offset_into_cluster(s, offset); + *map =3D host_offset; *file =3D s->data_file->bs; status |=3D BDRV_BLOCK_OFFSET_VALID; } @@ -2201,7 +2201,7 @@ static coroutine_fn int qcow2_co_preadv_part(BlockDri= verState *bs, BDRVQcow2State *s =3D bs->opaque; int ret =3D 0; unsigned int cur_bytes; /* number of bytes in current iteration */ - uint64_t cluster_offset =3D 0; + uint64_t host_offset =3D 0; AioTaskPool *aio =3D NULL; =20 while (bytes !=3D 0 && aio_task_pool_status(aio) =3D=3D 0) { @@ -2213,7 +2213,7 @@ static coroutine_fn int qcow2_co_preadv_part(BlockDri= verState *bs, } =20 qemu_co_mutex_lock(&s->lock); - ret =3D qcow2_get_cluster_offset(bs, offset, &cur_bytes, &cluster_= offset); + ret =3D qcow2_get_host_offset(bs, offset, &cur_bytes, &host_offset= ); qemu_co_mutex_unlock(&s->lock); if (ret < 0) { goto out; @@ -2225,15 +2225,6 @@ static coroutine_fn int qcow2_co_preadv_part(BlockDr= iverState *bs, { qemu_iovec_memset(qiov, qiov_offset, 0, cur_bytes); } else { - /* - * For compressed clusters the variable cluster_offset - * does not actually store the offset but the full - * descriptor. We need to leave it unchanged because - * that's what qcow2_co_preadv_compressed() expects. - */ - uint64_t host_offset =3D (ret =3D=3D QCOW2_CLUSTER_COMPRESSED)= ? - cluster_offset : - cluster_offset + offset_into_cluster(s, offset); if (!aio && cur_bytes !=3D bytes) { aio =3D aio_task_pool_new(QCOW2_MAX_WORKERS); } @@ -3735,7 +3726,7 @@ static coroutine_fn int qcow2_co_pwrite_zeroes(BlockD= riverState *bs, offset =3D QEMU_ALIGN_DOWN(offset, s->cluster_size); bytes =3D s->cluster_size; nr =3D s->cluster_size; - ret =3D qcow2_get_cluster_offset(bs, offset, &nr, &off); + ret =3D qcow2_get_host_offset(bs, offset, &nr, &off); if (ret !=3D QCOW2_CLUSTER_UNALLOCATED && ret !=3D QCOW2_CLUSTER_ZERO_PLAIN && ret !=3D QCOW2_CLUSTER_ZERO_ALLOC) { @@ -3800,7 +3791,7 @@ qcow2_co_copy_range_from(BlockDriverState *bs, cur_bytes =3D MIN(bytes, INT_MAX); cur_write_flags =3D write_flags; =20 - ret =3D qcow2_get_cluster_offset(bs, src_offset, &cur_bytes, ©= _offset); + ret =3D qcow2_get_host_offset(bs, src_offset, &cur_bytes, ©_of= fset); if (ret < 0) { goto out; } @@ -3832,7 +3823,6 @@ qcow2_co_copy_range_from(BlockDriverState *bs, =20 case QCOW2_CLUSTER_NORMAL: child =3D s->data_file; - copy_offset +=3D offset_into_cluster(s, src_offset); break; =20 default: --=20 2.20.1 From nobody Tue May 7 09:01:17 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1584470319; cv=none; d=zohomail.com; s=zohoarc; b=hOvgcox+CASeurSHyBWNh6hrV9cRPTG0xxwf5P4NRr2masVJlOc6TC3wTUx8rlT+Igd7awk4kF+QnziLZJH2pG4Y3kaug1I13ju+45ARd0Sy9Zv8aC+fPnSmyYVGnNseq1VqsJPa3s/ryUZgxIO6tj9hB7MCqyeM5Y0gJx1bLcY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1584470319; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Ev4vMMJ8JchBFJZHoG5+13wlem2tt2RTlRWp331R1Vw=; b=iDGomllnhuQmyNgXnSsfiKhjKHVMqySGY85A38tAz7VHJAAgoOfrX+rU6DkKMOswOlqJ+s3H+j0cizCXo0VS/7JN34BG+ZTzqXntx+/cExvFMZLb/8vFjM29iYYK2qXHyKrgsUtmBApMxN4km2NHrCTgYUf+/c0v5VpOuiEAZqU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1584470319181478.5695335649376; Tue, 17 Mar 2020 11:38:39 -0700 (PDT) Received: from localhost ([::1]:39520 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEH6s-0000X5-05 for importer@patchew.org; Tue, 17 Mar 2020 14:38:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48883) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEGmy-0003Wo-Mc for qemu-devel@nongnu.org; Tue, 17 Mar 2020 14:18:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jEGmv-00009O-7l for qemu-devel@nongnu.org; Tue, 17 Mar 2020 14:18:04 -0400 Received: from fanzine.igalia.com ([178.60.130.6]:57919) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jEGmu-0005wN-40; Tue, 17 Mar 2020 14:18:01 -0400 Received: from [81.0.35.138] (helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1jEGmD-00014v-38; Tue, 17 Mar 2020 19:17:17 +0100 Received: from berto by perseus.local with local (Exim 4.92) (envelope-from ) id 1jEGlw-0006O9-55; Tue, 17 Mar 2020 19:17:00 +0100 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=Ev4vMMJ8JchBFJZHoG5+13wlem2tt2RTlRWp331R1Vw=; b=AE4kfZ1jz3a6S3q1mWlBE97RpRg/sbchMh9RX8VUSReJb9cM73a9+aqa1lBwnVPNEUsS83T4rlPpihxAHZKiaBjEPjc0VtQNlh9r6hvOdwl0GfH2U1UvaafpJCka5bwxfSvQe74r364iJMTr+6/2h5Nj4WY47u7NxXWet3avjudDVdEBoH9r3K6BI3HBJueRMK0QxqnMDAFPRGMwI+ADNFCAahO5VTL3Ne95RSbxYKQGRhS2wrv2HTQ4ylJU1UI9FAsDGaJdM8m6kflNvMGd3916tqXFf3aRicQOh/SXFOWwPTKFcZp8cYAClP3GjO5Jm+hQtHt8AJ9TemzyiCkpqw==; From: Alberto Garcia To: qemu-devel@nongnu.org Subject: [PATCH v4 03/30] qcow2: Add calculate_l2_meta() Date: Tue, 17 Mar 2020 19:16:00 +0100 Message-Id: <627da7ad090c0b166f3d0294312d956fcddc5a2a.1584468723.git.berto@igalia.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy] X-Received-From: 178.60.130.6 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Anton Nefedov , Alberto Garcia , qemu-block@nongnu.org, Max Reitz , Vladimir Sementsov-Ogievskiy , "Denis V . Lunev" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" handle_alloc() creates a QCowL2Meta structure in order to update the image metadata and perform the necessary copy-on-write operations. This patch moves that code to a separate function so it can be used from other places. Signed-off-by: Alberto Garcia Reviewed-by: Max Reitz --- block/qcow2-cluster.c | 77 +++++++++++++++++++++++++++++-------------- 1 file changed, 53 insertions(+), 24 deletions(-) diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c index 95f04d12cc..802fc599a5 100644 --- a/block/qcow2-cluster.c +++ b/block/qcow2-cluster.c @@ -1039,6 +1039,56 @@ void qcow2_alloc_cluster_abort(BlockDriverState *bs,= QCowL2Meta *m) } } =20 +/* + * For a given write request, create a new QCowL2Meta structure, add + * it to @m and the BDRVQcow2State.cluster_allocs list. + * + * @host_cluster_offset points to the beginning of the first cluster. + * + * @guest_offset and @bytes indicate the offset and length of the + * request. + * + * If @keep_old is true it means that the clusters were already + * allocated and will be overwritten. If false then the clusters are + * new and we have to decrease the reference count of the old ones. + */ +static void calculate_l2_meta(BlockDriverState *bs, + uint64_t host_cluster_offset, + uint64_t guest_offset, unsigned bytes, + QCowL2Meta **m, bool keep_old) +{ + BDRVQcow2State *s =3D bs->opaque; + unsigned cow_start_from =3D 0; + unsigned cow_start_to =3D offset_into_cluster(s, guest_offset); + unsigned cow_end_from =3D cow_start_to + bytes; + unsigned cow_end_to =3D ROUND_UP(cow_end_from, s->cluster_size); + unsigned nb_clusters =3D size_to_clusters(s, cow_end_from); + QCowL2Meta *old_m =3D *m; + + *m =3D g_malloc0(sizeof(**m)); + **m =3D (QCowL2Meta) { + .next =3D old_m, + + .alloc_offset =3D host_cluster_offset, + .offset =3D start_of_cluster(s, guest_offset), + .nb_clusters =3D nb_clusters, + + .keep_old_clusters =3D keep_old, + + .cow_start =3D { + .offset =3D cow_start_from, + .nb_bytes =3D cow_start_to - cow_start_from, + }, + .cow_end =3D { + .offset =3D cow_end_from, + .nb_bytes =3D cow_end_to - cow_end_from, + }, + }; + + qemu_co_queue_init(&(*m)->dependent_requests); + QLIST_INSERT_HEAD(&s->cluster_allocs, *m, next_in_flight); +} + /* * Returns the number of contiguous clusters that can be used for an alloc= ating * write, but require COW to be performed (this includes yet unallocated s= pace, @@ -1437,35 +1487,14 @@ static int handle_alloc(BlockDriverState *bs, uint6= 4_t guest_offset, uint64_t requested_bytes =3D *bytes + offset_into_cluster(s, guest_off= set); int avail_bytes =3D nb_clusters << s->cluster_bits; int nb_bytes =3D MIN(requested_bytes, avail_bytes); - QCowL2Meta *old_m =3D *m; - - *m =3D g_malloc0(sizeof(**m)); - - **m =3D (QCowL2Meta) { - .next =3D old_m, - - .alloc_offset =3D alloc_cluster_offset, - .offset =3D start_of_cluster(s, guest_offset), - .nb_clusters =3D nb_clusters, - - .keep_old_clusters =3D keep_old_clusters, - - .cow_start =3D { - .offset =3D 0, - .nb_bytes =3D offset_into_cluster(s, guest_offset), - }, - .cow_end =3D { - .offset =3D nb_bytes, - .nb_bytes =3D avail_bytes - nb_bytes, - }, - }; - qemu_co_queue_init(&(*m)->dependent_requests); - QLIST_INSERT_HEAD(&s->cluster_allocs, *m, next_in_flight); =20 *host_offset =3D alloc_cluster_offset + offset_into_cluster(s, guest_o= ffset); *bytes =3D MIN(*bytes, nb_bytes - offset_into_cluster(s, guest_offset)= ); assert(*bytes !=3D 0); =20 + calculate_l2_meta(bs, alloc_cluster_offset, guest_offset, *bytes, + m, keep_old_clusters); + return 1; =20 fail: --=20 2.20.1 From nobody Tue May 7 09:01:18 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1584469710; cv=none; d=zohomail.com; s=zohoarc; b=Vmmo8I6MT8YciKwF+tM+4NgwtB2MgwwOi3sTHG+KgwJQVnNcVK5zV1IbMTSFFwyMO9rsZaild9oT69c7jvjYQSge7/5sSf2BqQIMo7KTAj85KfIPFpZiUAW7iX9ykoOV+mWA8KrlILhMC7LlaVdwmrspaLYURnHhzr0+/8xvByM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1584469710; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=cPIn3TYC26Psl9t5UvZ+RwiEOaELs2oRUoYn1DabNkw=; b=b8nJ5loMgNOpPZBoHGg0WNcqdF/UEwO8ZJkrKCa8xgnfEzW4Zbqb4uEhenoc5/6e0SNvW0VwDC2XDU+DEUIjR7TEfyPBNSS5nX1ReSEGAHZzAdP+XJZ+8fMTQpqYVoYwP/rT0e8A8C9OWKzD0HBVxe8v64ywwDydldHygdmHex8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1584469710914939.3615293610857; Tue, 17 Mar 2020 11:28:30 -0700 (PDT) Received: from localhost ([::1]:39198 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEGx3-0002mh-Rq for importer@patchew.org; Tue, 17 Mar 2020 14:28:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48689) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEGmt-0003Lg-ML for qemu-devel@nongnu.org; Tue, 17 Mar 2020 14:18:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jEGms-0008UB-Fn for qemu-devel@nongnu.org; Tue, 17 Mar 2020 14:17:59 -0400 Received: from fanzine.igalia.com ([178.60.130.6]:57718) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jEGms-0005V2-5F; Tue, 17 Mar 2020 14:17:58 -0400 Received: from [81.0.35.138] (helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1jEGmC-000158-W3; Tue, 17 Mar 2020 19:17:17 +0100 Received: from berto by perseus.local with local (Exim 4.92) (envelope-from ) id 1jEGlw-0006OB-5z; Tue, 17 Mar 2020 19:17:00 +0100 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=cPIn3TYC26Psl9t5UvZ+RwiEOaELs2oRUoYn1DabNkw=; b=Ez+5DhNwn1hJYjIm792Ny22hwI3W/inTMoayauyYVI5Ju4Of+1mGmUKjlSvhFwUq9ao4/4izcrAX+nULQ1peZohbq8mZF5BiciWVAsF3faR89ZkyIJGiSz6WspwLX2GkDiYvBCXtdiAmq2vjHlX8S+t0qtEdKSJYrO+kHbKGk1GvBGWrjeY8m37/Nwk/ov0KxTDVmd4Y1ab9kU9WS3PBMbH2Mj+UOMZ6mbFsfV5y4ioVY1SQShqDvtLZ3k2PfY+ovgfwYQApFRmiEXjL2k7oZCBBOANAhs+y56LDslpyeuH0494tPg48VLPodkzXTW1U3dnStxytdqbr1Wcp5mnAnA==; From: Alberto Garcia To: qemu-devel@nongnu.org Subject: [PATCH v4 04/30] qcow2: Split cluster_needs_cow() out of count_cow_clusters() Date: Tue, 17 Mar 2020 19:16:01 +0100 Message-Id: X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy] X-Received-From: 178.60.130.6 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Anton Nefedov , Alberto Garcia , qemu-block@nongnu.org, Max Reitz , Vladimir Sementsov-Ogievskiy , "Denis V . Lunev" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" We are going to need it in other places. Signed-off-by: Alberto Garcia Reviewed-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Max Reitz --- block/qcow2-cluster.c | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c index 802fc599a5..e251d00890 100644 --- a/block/qcow2-cluster.c +++ b/block/qcow2-cluster.c @@ -1089,6 +1089,24 @@ static void calculate_l2_meta(BlockDriverState *bs, QLIST_INSERT_HEAD(&s->cluster_allocs, *m, next_in_flight); } =20 +/* Returns true if writing to a cluster requires COW */ +static bool cluster_needs_cow(BlockDriverState *bs, uint64_t l2_entry) +{ + switch (qcow2_get_cluster_type(bs, l2_entry)) { + case QCOW2_CLUSTER_NORMAL: + if (l2_entry & QCOW_OFLAG_COPIED) { + return false; + } + case QCOW2_CLUSTER_UNALLOCATED: + case QCOW2_CLUSTER_COMPRESSED: + case QCOW2_CLUSTER_ZERO_PLAIN: + case QCOW2_CLUSTER_ZERO_ALLOC: + return true; + default: + abort(); + } +} + /* * Returns the number of contiguous clusters that can be used for an alloc= ating * write, but require COW to be performed (this includes yet unallocated s= pace, @@ -1101,25 +1119,11 @@ static int count_cow_clusters(BlockDriverState *bs,= int nb_clusters, =20 for (i =3D 0; i < nb_clusters; i++) { uint64_t l2_entry =3D be64_to_cpu(l2_slice[l2_index + i]); - QCow2ClusterType cluster_type =3D qcow2_get_cluster_type(bs, l2_en= try); - - switch(cluster_type) { - case QCOW2_CLUSTER_NORMAL: - if (l2_entry & QCOW_OFLAG_COPIED) { - goto out; - } + if (!cluster_needs_cow(bs, l2_entry)) { break; - case QCOW2_CLUSTER_UNALLOCATED: - case QCOW2_CLUSTER_COMPRESSED: - case QCOW2_CLUSTER_ZERO_PLAIN: - case QCOW2_CLUSTER_ZERO_ALLOC: - break; - default: - abort(); } } =20 -out: assert(i <=3D nb_clusters); return i; } --=20 2.20.1 From nobody Tue May 7 09:01:18 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1584469300; cv=none; d=zohomail.com; s=zohoarc; b=VtEvlzsZTGD7szR+nEgvQcZrXEkdd0dIuiZxJbbbVyDUuGklLknlnyJK8XazC6kC3eRD5qM8puVMU1G8oDgvDn6Np62NwGFdhRKMdqLvyFKl+XKOqIJWNh2Lsf5xxivT76j8pJKgm+53QzwyH+NHyEFcpC3AZcIhm+Uw5RcrvUQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1584469300; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=AfddvAbDogN4T3Rx/qKiWP9Ls1fyI2MCKXItGa2SYxQ=; b=e6LizGpe2yDWityvKrzK20nfbRvMPe7Yo/Sr9AXpJ9j2dIFS1lOYJZrHmSzcOpwisS0oIBzIziwnKG4MwP7xWZ0PFgnoDEo0AN3OXX812rEXL29aTXX/B/iiqiI5exPI588TCCegUnqYCt5DLP3BGXmlGKJETG8q6L/9ySbrwz4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 158446930053989.03852372193876; Tue, 17 Mar 2020 11:21:40 -0700 (PDT) Received: from localhost ([::1]:38996 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEGqR-000054-D1 for importer@patchew.org; Tue, 17 Mar 2020 14:21:39 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48372) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEGmc-0002pA-LV for qemu-devel@nongnu.org; Tue, 17 Mar 2020 14:17:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jEGmZ-0007Uo-0I for qemu-devel@nongnu.org; Tue, 17 Mar 2020 14:17:42 -0400 Received: from fanzine.igalia.com ([178.60.130.6]:57709) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jEGmX-0005Uu-Qu; Tue, 17 Mar 2020 14:17:38 -0400 Received: from [81.0.35.138] (helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1jEGmB-00014p-PT; Tue, 17 Mar 2020 19:17:15 +0100 Received: from berto by perseus.local with local (Exim 4.92) (envelope-from ) id 1jEGlw-0006OD-6z; Tue, 17 Mar 2020 19:17:00 +0100 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=AfddvAbDogN4T3Rx/qKiWP9Ls1fyI2MCKXItGa2SYxQ=; b=kzSXmu/TOvGqaM7F2Z/x9Ud5r3YIVM961vqnG3OIYNXYE0ptiRYvmej+ubeiUWXN6D4sADLi051TA28AA3tSFvcco3cy9IE+/dn33r0DKl/bjh6vuwozMj21IBntoeNYR9W8kOT55ZdYn+3qoDKvyfL6Rewh1OosAh+UVBCeJuD1pTHr2jzqIZAq7RxXU/tLo88yFVYvxxtAwPfuYwFI390jKEd5mL61WG0Sc2Evdp2wZXyQc2ZIhJeqCtrMLegNSWSaVpdcE/qvRcVO9xuU/+YcpFibSg6cEUIqQeSrx3R8ertOok290Pt4mA99j8mC9rp9Ll3LtYm3MZyOoTg4FA==; From: Alberto Garcia To: qemu-devel@nongnu.org Subject: [PATCH v4 05/30] qcow2: Process QCOW2_CLUSTER_ZERO_ALLOC clusters in handle_copied() Date: Tue, 17 Mar 2020 19:16:02 +0100 Message-Id: <42c52037c0c975e2d1cd23b470e7b61cbd0b3fa3.1584468723.git.berto@igalia.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy] X-Received-From: 178.60.130.6 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Anton Nefedov , Alberto Garcia , qemu-block@nongnu.org, Max Reitz , Vladimir Sementsov-Ogievskiy , "Denis V . Lunev" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" When writing to a qcow2 file there are two functions that take a virtual offset and return a host offset, possibly allocating new clusters if necessary: - handle_copied() looks for normal data clusters that are already allocated and have a reference count of 1. In those clusters we can simply write the data and there is no need to perform any copy-on-write. - handle_alloc() looks for clusters that do need copy-on-write, either because they haven't been allocated yet, because their reference count is !=3D 1 or because they are ZERO_ALLOC clusters. The ZERO_ALLOC case is a bit special because those are clusters that are already allocated and they could perfectly be dealt with in handle_copied() (as long as copy-on-write is performed when required). In fact, there is extra code specifically for them in handle_alloc() that tries to reuse the existing allocation if possible and frees them otherwise. This patch changes the handling of ZERO_ALLOC clusters so the semantics of these two functions are now like this: - handle_copied() looks for clusters that are already allocated and which we can overwrite (NORMAL and ZERO_ALLOC clusters with a reference count of 1). - handle_alloc() looks for clusters for which we need a new allocation (all other cases). One important difference after this change is that clusters found in handle_copied() may now require copy-on-write, but this will be necessary anyway once we add support for subclusters. Signed-off-by: Alberto Garcia Reviewed-by: Eric Blake Reviewed-by: Max Reitz --- block/qcow2-cluster.c | 230 ++++++++++++++++++++++++------------------ 1 file changed, 130 insertions(+), 100 deletions(-) diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c index e251d00890..5c81046c34 100644 --- a/block/qcow2-cluster.c +++ b/block/qcow2-cluster.c @@ -1041,13 +1041,18 @@ void qcow2_alloc_cluster_abort(BlockDriverState *bs= , QCowL2Meta *m) =20 /* * For a given write request, create a new QCowL2Meta structure, add - * it to @m and the BDRVQcow2State.cluster_allocs list. + * it to @m and the BDRVQcow2State.cluster_allocs list. If the write + * request does not need copy-on-write or changes to the L2 metadata + * then this function does nothing. * * @host_cluster_offset points to the beginning of the first cluster. * * @guest_offset and @bytes indicate the offset and length of the * request. * + * @l2_slice contains the L2 entries of all clusters involved in this + * write request. + * * If @keep_old is true it means that the clusters were already * allocated and will be overwritten. If false then the clusters are * new and we have to decrease the reference count of the old ones. @@ -1055,15 +1060,53 @@ void qcow2_alloc_cluster_abort(BlockDriverState *bs= , QCowL2Meta *m) static void calculate_l2_meta(BlockDriverState *bs, uint64_t host_cluster_offset, uint64_t guest_offset, unsigned bytes, - QCowL2Meta **m, bool keep_old) + uint64_t *l2_slice, QCowL2Meta **m, bool kee= p_old) { BDRVQcow2State *s =3D bs->opaque; - unsigned cow_start_from =3D 0; + int l2_index =3D offset_to_l2_slice_index(s, guest_offset); + uint64_t l2_entry; + unsigned cow_start_from, cow_end_to; unsigned cow_start_to =3D offset_into_cluster(s, guest_offset); unsigned cow_end_from =3D cow_start_to + bytes; - unsigned cow_end_to =3D ROUND_UP(cow_end_from, s->cluster_size); unsigned nb_clusters =3D size_to_clusters(s, cow_end_from); QCowL2Meta *old_m =3D *m; + QCow2ClusterType type; + + assert(nb_clusters <=3D s->l2_slice_size - l2_index); + + /* Return if there's no COW (all clusters are normal and we keep them)= */ + if (keep_old) { + int i; + for (i =3D 0; i < nb_clusters; i++) { + l2_entry =3D be64_to_cpu(l2_slice[l2_index + i]); + if (qcow2_get_cluster_type(bs, l2_entry) !=3D QCOW2_CLUSTER_NO= RMAL) { + break; + } + } + if (i =3D=3D nb_clusters) { + return; + } + } + + /* Get the L2 entry of the first cluster */ + l2_entry =3D be64_to_cpu(l2_slice[l2_index]); + type =3D qcow2_get_cluster_type(bs, l2_entry); + + if (type =3D=3D QCOW2_CLUSTER_NORMAL && keep_old) { + cow_start_from =3D cow_start_to; + } else { + cow_start_from =3D 0; + } + + /* Get the L2 entry of the last cluster */ + l2_entry =3D be64_to_cpu(l2_slice[l2_index + nb_clusters - 1]); + type =3D qcow2_get_cluster_type(bs, l2_entry); + + if (type =3D=3D QCOW2_CLUSTER_NORMAL && keep_old) { + cow_end_to =3D cow_end_from; + } else { + cow_end_to =3D ROUND_UP(cow_end_from, s->cluster_size); + } =20 *m =3D g_malloc0(sizeof(**m)); **m =3D (QCowL2Meta) { @@ -1089,18 +1132,22 @@ static void calculate_l2_meta(BlockDriverState *bs, QLIST_INSERT_HEAD(&s->cluster_allocs, *m, next_in_flight); } =20 -/* Returns true if writing to a cluster requires COW */ -static bool cluster_needs_cow(BlockDriverState *bs, uint64_t l2_entry) +/* + * Returns true if writing to the cluster pointed to by @l2_entry + * requires a new allocation (that is, if the cluster is unallocated + * or has refcount > 1 and therefore cannot be written in-place). + */ +static bool cluster_needs_new_alloc(BlockDriverState *bs, uint64_t l2_entr= y) { switch (qcow2_get_cluster_type(bs, l2_entry)) { case QCOW2_CLUSTER_NORMAL: + case QCOW2_CLUSTER_ZERO_ALLOC: if (l2_entry & QCOW_OFLAG_COPIED) { return false; } case QCOW2_CLUSTER_UNALLOCATED: case QCOW2_CLUSTER_COMPRESSED: case QCOW2_CLUSTER_ZERO_PLAIN: - case QCOW2_CLUSTER_ZERO_ALLOC: return true; default: abort(); @@ -1108,20 +1155,38 @@ static bool cluster_needs_cow(BlockDriverState *bs,= uint64_t l2_entry) } =20 /* - * Returns the number of contiguous clusters that can be used for an alloc= ating - * write, but require COW to be performed (this includes yet unallocated s= pace, - * which must copy from the backing file) + * Returns the number of contiguous clusters that can be written to + * using one single write request, starting from @l2_index. + * At most @nb_clusters are checked. + * + * If @new_alloc is true this counts clusters that are either + * unallocated, or allocated but with refcount > 1 (so they need to be + * newly allocated and COWed). + * + * If @new_alloc is false this counts clusters that are already + * allocated and can be overwritten in-place (this includes clusters + * of type QCOW2_CLUSTER_ZERO_ALLOC). */ -static int count_cow_clusters(BlockDriverState *bs, int nb_clusters, - uint64_t *l2_slice, int l2_index) +static int count_single_write_clusters(BlockDriverState *bs, int nb_cluste= rs, + uint64_t *l2_slice, int l2_index, + bool new_alloc) { + BDRVQcow2State *s =3D bs->opaque; + uint64_t l2_entry =3D be64_to_cpu(l2_slice[l2_index]); + uint64_t expected_offset =3D l2_entry & L2E_OFFSET_MASK; int i; =20 for (i =3D 0; i < nb_clusters; i++) { - uint64_t l2_entry =3D be64_to_cpu(l2_slice[l2_index + i]); - if (!cluster_needs_cow(bs, l2_entry)) { + l2_entry =3D be64_to_cpu(l2_slice[l2_index + i]); + if (cluster_needs_new_alloc(bs, l2_entry) !=3D new_alloc) { break; } + if (!new_alloc) { + if (expected_offset !=3D (l2_entry & L2E_OFFSET_MASK)) { + break; + } + expected_offset +=3D s->cluster_size; + } } =20 assert(i <=3D nb_clusters); @@ -1192,10 +1257,10 @@ static int handle_dependencies(BlockDriverState *bs= , uint64_t guest_offset, } =20 /* - * Checks how many already allocated clusters that don't require a copy on - * write there are at the given guest_offset (up to *bytes). If *host_offs= et is - * not INV_OFFSET, only physically contiguous clusters beginning at this h= ost - * offset are counted. + * Checks how many already allocated clusters that don't require a new + * allocation there are at the given guest_offset (up to *bytes). + * If *host_offset is not INV_OFFSET, only physically contiguous clusters + * beginning at this host offset are counted. * * Note that guest_offset may not be cluster aligned. In this case, the * returned *host_offset points to exact byte referenced by guest_offset a= nd @@ -1204,12 +1269,12 @@ static int handle_dependencies(BlockDriverState *bs= , uint64_t guest_offset, * Returns: * 0: if no allocated clusters are available at the given offset. * *bytes is normally unchanged. It is set to 0 if the cluster - * is allocated and doesn't need COW, but doesn't have the right - * physical offset. + * is allocated and can be overwritten in-place but doesn't have + * the right physical offset. * - * 1: if allocated clusters that don't require a COW are available at - * the requested offset. *bytes may have decreased and describes - * the length of the area that can be written to. + * 1: if allocated clusters that can be overwritten in place are + * available at the requested offset. *bytes may have decreased + * and describes the length of the area that can be written to. * * -errno: in error cases */ @@ -1239,7 +1304,8 @@ static int handle_copied(BlockDriverState *bs, uint64= _t guest_offset, =20 l2_index =3D offset_to_l2_slice_index(s, guest_offset); nb_clusters =3D MIN(nb_clusters, s->l2_slice_size - l2_index); - assert(nb_clusters <=3D INT_MAX); + /* Limit total byte count to BDRV_REQUEST_MAX_BYTES */ + nb_clusters =3D MIN(nb_clusters, BDRV_REQUEST_MAX_BYTES >> s->cluster_= bits); =20 /* Find L2 entry for the first involved cluster */ ret =3D get_cluster_table(bs, guest_offset, &l2_slice, &l2_index); @@ -1249,18 +1315,17 @@ static int handle_copied(BlockDriverState *bs, uint= 64_t guest_offset, =20 cluster_offset =3D be64_to_cpu(l2_slice[l2_index]); =20 - /* Check how many clusters are already allocated and don't need COW */ - if (qcow2_get_cluster_type(bs, cluster_offset) =3D=3D QCOW2_CLUSTER_NO= RMAL - && (cluster_offset & QCOW_OFLAG_COPIED)) - { + if (!cluster_needs_new_alloc(bs, cluster_offset)) { /* If a specific host_offset is required, check it */ bool offset_matches =3D (cluster_offset & L2E_OFFSET_MASK) =3D=3D *host_offset; =20 if (offset_into_cluster(s, cluster_offset & L2E_OFFSET_MASK)) { - qcow2_signal_corruption(bs, true, -1, -1, "Data cluster offset= " + qcow2_signal_corruption(bs, true, -1, -1, "%s cluster offset " "%#llx unaligned (guest offset: %#" PR= Ix64 - ")", cluster_offset & L2E_OFFSET_MASK, + ")", cluster_offset & QCOW_OFLAG_ZERO ? + "Preallocated zero" : "Data", + cluster_offset & L2E_OFFSET_MASK, guest_offset); ret =3D -EIO; goto out; @@ -1273,15 +1338,17 @@ static int handle_copied(BlockDriverState *bs, uint= 64_t guest_offset, } =20 /* We keep all QCOW_OFLAG_COPIED clusters */ - keep_clusters =3D - count_contiguous_clusters(bs, nb_clusters, s->cluster_size, - &l2_slice[l2_index], - QCOW_OFLAG_COPIED | QCOW_OFLAG_ZERO); + keep_clusters =3D count_single_write_clusters(bs, nb_clusters, l2_= slice, + l2_index, false); assert(keep_clusters <=3D nb_clusters); =20 *bytes =3D MIN(*bytes, keep_clusters * s->cluster_size - offset_into_cluster(s, guest_offset)); + assert(*bytes !=3D 0); + + calculate_l2_meta(bs, cluster_offset & L2E_OFFSET_MASK, guest_offs= et, + *bytes, l2_slice, m, true); =20 ret =3D 1; } else { @@ -1357,9 +1424,10 @@ static int do_alloc_cluster_offset(BlockDriverState = *bs, uint64_t guest_offset, } =20 /* - * Allocates new clusters for an area that either is yet unallocated or ne= eds a - * copy on write. If *host_offset is not INV_OFFSET, clusters are only - * allocated if the new allocation can match the specified host offset. + * Allocates new clusters for an area that is either still unallocated or + * cannot be overwritten in-place. If *host_offset is not INV_OFFSET, + * clusters are only allocated if the new allocation can match the specifi= ed + * host offset. * * Note that guest_offset may not be cluster aligned. In this case, the * returned *host_offset points to exact byte referenced by guest_offset a= nd @@ -1382,12 +1450,10 @@ static int handle_alloc(BlockDriverState *bs, uint6= 4_t guest_offset, BDRVQcow2State *s =3D bs->opaque; int l2_index; uint64_t *l2_slice; - uint64_t entry; uint64_t nb_clusters; int ret; - bool keep_old_clusters =3D false; =20 - uint64_t alloc_cluster_offset =3D INV_OFFSET; + uint64_t alloc_cluster_offset; =20 trace_qcow2_handle_alloc(qemu_coroutine_self(), guest_offset, *host_of= fset, *bytes); @@ -1402,10 +1468,8 @@ static int handle_alloc(BlockDriverState *bs, uint64= _t guest_offset, =20 l2_index =3D offset_to_l2_slice_index(s, guest_offset); nb_clusters =3D MIN(nb_clusters, s->l2_slice_size - l2_index); - assert(nb_clusters <=3D INT_MAX); - - /* Limit total allocation byte count to INT_MAX */ - nb_clusters =3D MIN(nb_clusters, INT_MAX >> s->cluster_bits); + /* Limit total allocation byte count to BDRV_REQUEST_MAX_BYTES */ + nb_clusters =3D MIN(nb_clusters, BDRV_REQUEST_MAX_BYTES >> s->cluster_= bits); =20 /* Find L2 entry for the first involved cluster */ ret =3D get_cluster_table(bs, guest_offset, &l2_slice, &l2_index); @@ -1413,67 +1477,32 @@ static int handle_alloc(BlockDriverState *bs, uint6= 4_t guest_offset, return ret; } =20 - entry =3D be64_to_cpu(l2_slice[l2_index]); - nb_clusters =3D count_cow_clusters(bs, nb_clusters, l2_slice, l2_index= ); + nb_clusters =3D count_single_write_clusters(bs, nb_clusters, + l2_slice, l2_index, true); =20 /* This function is only called when there were no non-COW clusters, s= o if * we can't find any unallocated or COW clusters either, something is * wrong with our code. */ assert(nb_clusters > 0); =20 - if (qcow2_get_cluster_type(bs, entry) =3D=3D QCOW2_CLUSTER_ZERO_ALLOC = && - (entry & QCOW_OFLAG_COPIED) && - (*host_offset =3D=3D INV_OFFSET || - start_of_cluster(s, *host_offset) =3D=3D (entry & L2E_OFFSET_MASK= ))) - { - int preallocated_nb_clusters; - - if (offset_into_cluster(s, entry & L2E_OFFSET_MASK)) { - qcow2_signal_corruption(bs, true, -1, -1, "Preallocated zero " - "cluster offset %#llx unaligned (guest= " - "offset: %#" PRIx64 ")", - entry & L2E_OFFSET_MASK, guest_offset); - ret =3D -EIO; - goto fail; - } - - /* Try to reuse preallocated zero clusters; contiguous normal clus= ters - * would be fine, too, but count_cow_clusters() above has limited - * nb_clusters already to a range of COW clusters */ - preallocated_nb_clusters =3D - count_contiguous_clusters(bs, nb_clusters, s->cluster_size, - &l2_slice[l2_index], QCOW_OFLAG_COPI= ED); - assert(preallocated_nb_clusters > 0); - - nb_clusters =3D preallocated_nb_clusters; - alloc_cluster_offset =3D entry & L2E_OFFSET_MASK; - - /* We want to reuse these clusters, so qcow2_alloc_cluster_link_l2= () - * should not free them. */ - keep_old_clusters =3D true; + /* Allocate at a given offset in the image file */ + alloc_cluster_offset =3D *host_offset =3D=3D INV_OFFSET ? INV_OFFSET : + start_of_cluster(s, *host_offset); + ret =3D do_alloc_cluster_offset(bs, guest_offset, &alloc_cluster_offse= t, + &nb_clusters); + if (ret < 0) { + goto out; } =20 - qcow2_cache_put(s->l2_table_cache, (void **) &l2_slice); - - if (alloc_cluster_offset =3D=3D INV_OFFSET) { - /* Allocate, if necessary at a given offset in the image file */ - alloc_cluster_offset =3D *host_offset =3D=3D INV_OFFSET ? INV_OFFS= ET : - start_of_cluster(s, *host_offset); - ret =3D do_alloc_cluster_offset(bs, guest_offset, &alloc_cluster_o= ffset, - &nb_clusters); - if (ret < 0) { - goto fail; - } - - /* Can't extend contiguous allocation */ - if (nb_clusters =3D=3D 0) { - *bytes =3D 0; - return 0; - } - - assert(alloc_cluster_offset !=3D INV_OFFSET); + /* Can't extend contiguous allocation */ + if (nb_clusters =3D=3D 0) { + *bytes =3D 0; + ret =3D 0; + goto out; } =20 + assert(alloc_cluster_offset !=3D INV_OFFSET); + /* * Save info needed for meta data update. * @@ -1496,13 +1525,14 @@ static int handle_alloc(BlockDriverState *bs, uint6= 4_t guest_offset, *bytes =3D MIN(*bytes, nb_bytes - offset_into_cluster(s, guest_offset)= ); assert(*bytes !=3D 0); =20 - calculate_l2_meta(bs, alloc_cluster_offset, guest_offset, *bytes, - m, keep_old_clusters); + calculate_l2_meta(bs, alloc_cluster_offset, guest_offset, *bytes, l2_s= lice, + m, false); =20 - return 1; + ret =3D 1; =20 -fail: - if (*m && (*m)->nb_clusters > 0) { +out: + qcow2_cache_put(s->l2_table_cache, (void **) &l2_slice); + if (ret < 0 && *m && (*m)->nb_clusters > 0) { QLIST_REMOVE(*m, next_in_flight); } return ret; --=20 2.20.1 From nobody Tue May 7 09:01:18 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1584469668; cv=none; d=zohomail.com; s=zohoarc; b=KMbr/j96uePKTHlbhiiEuHVrD+/wU2DrjTwur0NwCQs4FIVKtQelYnv8nUM4cfW/evJANt6cxlH5NMWk2ny2SWpFnoMRyajbfZUb+619wRyJBa9rc397zLQbfEZywWHFL83jpbjxc4BzbVKzvguEcLjd+Tjyg6ND+mQ6c/2sYO4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1584469668; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=DJzqjcVKxNmjEGn0/Fro88mKEALPyKfXPzU/B5HHeZA=; b=fvoSVicRUkCCfWLWpHuA4J+QVAG2p6ONqwg84qw42df8J9mglipyyOrT4RtI6Wz3vVHLPn9eUzX5nG6SwHnk/YHhUcgrqNymB2Lk61UuuCm9EUclmI7hIxQz78eykVKbJ3MpbSAG60kabQu3CnKy5MjiDjkK2CR4nKq7R9CCZDI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1584469668528644.5193299055368; Tue, 17 Mar 2020 11:27:48 -0700 (PDT) Received: from localhost ([::1]:39182 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEGwN-0001Ww-Bm for importer@patchew.org; Tue, 17 Mar 2020 14:27:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48356) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEGmc-0002ox-5L for qemu-devel@nongnu.org; Tue, 17 Mar 2020 14:17:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jEGmZ-0007V0-2A for qemu-devel@nongnu.org; Tue, 17 Mar 2020 14:17:41 -0400 Received: from fanzine.igalia.com ([178.60.130.6]:57719) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jEGmX-0005V1-Qz; Tue, 17 Mar 2020 14:17:38 -0400 Received: from [81.0.35.138] (helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1jEGmD-00015V-0y; Tue, 17 Mar 2020 19:17:17 +0100 Received: from berto by perseus.local with local (Exim 4.92) (envelope-from ) id 1jEGlw-0006OF-7v; Tue, 17 Mar 2020 19:17:00 +0100 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=DJzqjcVKxNmjEGn0/Fro88mKEALPyKfXPzU/B5HHeZA=; b=OUKIUZjz+Vpdr7y7nhFhJigaVnVHcNaLzrJ7teyPpfrHZDR1lLWyR+ZKoYEJa7NLvXoRCQEZxHIEshDaqlOAr4nuyciHLQ3Wqs1s+1mgtrVRa8Y4YIGlPWta3YEwLgkUKdJGr8kCNaQ3Anug44edqOABuv+kSuRQcU55uih8aj5HJ+WHP/5hYECVFGonNETEmb5VjC0Psla9Moe7wls1+iZLPM+/HtNRlvg+1MVG/0BlqiN+IJ/PXnegtYnLu7SBlMfy2r1vL7F1H33zsHISfrcJnp16f7o1rVEqdzDbltuCT6luN1zFGqcgNtl+WTjCHRIAz2R0sSbWqJTMRgNUyw==; From: Alberto Garcia To: qemu-devel@nongnu.org Subject: [PATCH v4 06/30] qcow2: Add get_l2_entry() and set_l2_entry() Date: Tue, 17 Mar 2020 19:16:03 +0100 Message-Id: X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy] X-Received-From: 178.60.130.6 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Anton Nefedov , Alberto Garcia , qemu-block@nongnu.org, Max Reitz , Vladimir Sementsov-Ogievskiy , "Denis V . Lunev" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" The size of an L2 entry is 64 bits, but if we want to have subclusters we need extended L2 entries. This means that we have to access L2 tables and slices differently depending on whether an image has extended L2 entries or not. This patch replaces all l2_slice[] accesses with calls to get_l2_entry() and set_l2_entry(). Signed-off-by: Alberto Garcia Reviewed-by: Eric Blake Reviewed-by: Max Reitz Reviewed-by: Vladimir Sementsov-Ogievskiy --- block/qcow2.h | 12 ++++++++ block/qcow2-cluster.c | 63 ++++++++++++++++++++++-------------------- block/qcow2-refcount.c | 17 ++++++------ 3 files changed, 54 insertions(+), 38 deletions(-) diff --git a/block/qcow2.h b/block/qcow2.h index f47ef6ca4e..7754d9bd02 100644 --- a/block/qcow2.h +++ b/block/qcow2.h @@ -495,6 +495,18 @@ typedef enum QCow2MetadataOverlap { =20 #define INV_OFFSET (-1ULL) =20 +static inline uint64_t get_l2_entry(BDRVQcow2State *s, uint64_t *l2_slice, + int idx) +{ + return be64_to_cpu(l2_slice[idx]); +} + +static inline void set_l2_entry(BDRVQcow2State *s, uint64_t *l2_slice, + int idx, uint64_t entry) +{ + l2_slice[idx] =3D cpu_to_be64(entry); +} + static inline bool has_data_file(BlockDriverState *bs) { BDRVQcow2State *s =3D bs->opaque; diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c index 5c81046c34..cd48ab0223 100644 --- a/block/qcow2-cluster.c +++ b/block/qcow2-cluster.c @@ -383,12 +383,13 @@ fail: * cluster which may require a different handling) */ static int count_contiguous_clusters(BlockDriverState *bs, int nb_clusters, - int cluster_size, uint64_t *l2_slice, uint64_t stop_flags) + int cluster_size, uint64_t *l2_slice, int l2_index, uint64_t stop_= flags) { + BDRVQcow2State *s =3D bs->opaque; int i; QCow2ClusterType first_cluster_type; uint64_t mask =3D stop_flags | L2E_OFFSET_MASK | QCOW_OFLAG_COMPRESSED; - uint64_t first_entry =3D be64_to_cpu(l2_slice[0]); + uint64_t first_entry =3D get_l2_entry(s, l2_slice, l2_index); uint64_t offset =3D first_entry & mask; =20 first_cluster_type =3D qcow2_get_cluster_type(bs, first_entry); @@ -401,7 +402,7 @@ static int count_contiguous_clusters(BlockDriverState *= bs, int nb_clusters, first_cluster_type =3D=3D QCOW2_CLUSTER_ZERO_ALLOC); =20 for (i =3D 0; i < nb_clusters; i++) { - uint64_t l2_entry =3D be64_to_cpu(l2_slice[i]) & mask; + uint64_t l2_entry =3D get_l2_entry(s, l2_slice, l2_index + i) & ma= sk; if (offset + (uint64_t) i * cluster_size !=3D l2_entry) { break; } @@ -417,14 +418,16 @@ static int count_contiguous_clusters(BlockDriverState= *bs, int nb_clusters, static int count_contiguous_clusters_unallocated(BlockDriverState *bs, int nb_clusters, uint64_t *l2_slice, + int l2_index, QCow2ClusterType wanted_t= ype) { + BDRVQcow2State *s =3D bs->opaque; int i; =20 assert(wanted_type =3D=3D QCOW2_CLUSTER_ZERO_PLAIN || wanted_type =3D=3D QCOW2_CLUSTER_UNALLOCATED); for (i =3D 0; i < nb_clusters; i++) { - uint64_t entry =3D be64_to_cpu(l2_slice[i]); + uint64_t entry =3D get_l2_entry(s, l2_slice, l2_index + i); QCow2ClusterType type =3D qcow2_get_cluster_type(bs, entry); =20 if (type !=3D wanted_type) { @@ -575,7 +578,7 @@ int qcow2_get_host_offset(BlockDriverState *bs, uint64_= t offset, /* find the cluster offset for the given disk offset */ =20 l2_index =3D offset_to_l2_slice_index(s, offset); - l2_entry =3D be64_to_cpu(l2_slice[l2_index]); + l2_entry =3D get_l2_entry(s, l2_slice, l2_index); =20 nb_clusters =3D size_to_clusters(s, bytes_needed); /* bytes_needed <=3D *bytes + offset_in_cluster, both of which are uns= igned @@ -610,14 +613,14 @@ int qcow2_get_host_offset(BlockDriverState *bs, uint6= 4_t offset, case QCOW2_CLUSTER_UNALLOCATED: /* how many empty clusters ? */ c =3D count_contiguous_clusters_unallocated(bs, nb_clusters, - &l2_slice[l2_index], typ= e); + l2_slice, l2_index, type= ); *host_offset =3D 0; break; case QCOW2_CLUSTER_ZERO_ALLOC: case QCOW2_CLUSTER_NORMAL: /* how many allocated clusters ? */ c =3D count_contiguous_clusters(bs, nb_clusters, s->cluster_size, - &l2_slice[l2_index], QCOW_OFLAG_ZERO= ); + l2_slice, l2_index, QCOW_OFLAG_ZERO); *host_offset =3D l2_entry & L2E_OFFSET_MASK; if (offset_into_cluster(s, *host_offset)) { qcow2_signal_corruption(bs, true, -1, -1, @@ -771,7 +774,7 @@ int qcow2_alloc_compressed_cluster_offset(BlockDriverSt= ate *bs, =20 /* Compression can't overwrite anything. Fail if the cluster was alrea= dy * allocated. */ - cluster_offset =3D be64_to_cpu(l2_slice[l2_index]); + cluster_offset =3D get_l2_entry(s, l2_slice, l2_index); if (cluster_offset & L2E_OFFSET_MASK) { qcow2_cache_put(s->l2_table_cache, (void **) &l2_slice); return -EIO; @@ -800,7 +803,7 @@ int qcow2_alloc_compressed_cluster_offset(BlockDriverSt= ate *bs, =20 BLKDBG_EVENT(bs->file, BLKDBG_L2_UPDATE_COMPRESSED); qcow2_cache_entry_mark_dirty(s->l2_table_cache, l2_slice); - l2_slice[l2_index] =3D cpu_to_be64(cluster_offset); + set_l2_entry(s, l2_slice, l2_index, cluster_offset); qcow2_cache_put(s->l2_table_cache, (void **) &l2_slice); =20 *host_offset =3D cluster_offset & s->cluster_offset_mask; @@ -993,14 +996,14 @@ int qcow2_alloc_cluster_link_l2(BlockDriverState *bs,= QCowL2Meta *m) * cluster the second one has to do RMW (which is done above by * perform_cow()), update l2 table with its cluster pointer and fr= ee * old cluster. This is what this loop does */ - if (l2_slice[l2_index + i] !=3D 0) { - old_cluster[j++] =3D l2_slice[l2_index + i]; + if (get_l2_entry(s, l2_slice, l2_index + i) !=3D 0) { + old_cluster[j++] =3D get_l2_entry(s, l2_slice, l2_index + i); } =20 /* The offset must fit in the offset field of the L2 table entry */ assert((offset & L2E_OFFSET_MASK) =3D=3D offset); =20 - l2_slice[l2_index + i] =3D cpu_to_be64(offset | QCOW_OFLAG_COPIED); + set_l2_entry(s, l2_slice, l2_index + i, offset | QCOW_OFLAG_COPIED= ); } =20 =20 @@ -1014,8 +1017,7 @@ int qcow2_alloc_cluster_link_l2(BlockDriverState *bs,= QCowL2Meta *m) */ if (!m->keep_old_clusters && j !=3D 0) { for (i =3D 0; i < j; i++) { - qcow2_free_any_clusters(bs, be64_to_cpu(old_cluster[i]), 1, - QCOW2_DISCARD_NEVER); + qcow2_free_any_clusters(bs, old_cluster[i], 1, QCOW2_DISCARD_N= EVER); } } =20 @@ -1078,7 +1080,7 @@ static void calculate_l2_meta(BlockDriverState *bs, if (keep_old) { int i; for (i =3D 0; i < nb_clusters; i++) { - l2_entry =3D be64_to_cpu(l2_slice[l2_index + i]); + l2_entry =3D get_l2_entry(s, l2_slice, l2_index + i); if (qcow2_get_cluster_type(bs, l2_entry) !=3D QCOW2_CLUSTER_NO= RMAL) { break; } @@ -1089,7 +1091,7 @@ static void calculate_l2_meta(BlockDriverState *bs, } =20 /* Get the L2 entry of the first cluster */ - l2_entry =3D be64_to_cpu(l2_slice[l2_index]); + l2_entry =3D get_l2_entry(s, l2_slice, l2_index); type =3D qcow2_get_cluster_type(bs, l2_entry); =20 if (type =3D=3D QCOW2_CLUSTER_NORMAL && keep_old) { @@ -1099,7 +1101,7 @@ static void calculate_l2_meta(BlockDriverState *bs, } =20 /* Get the L2 entry of the last cluster */ - l2_entry =3D be64_to_cpu(l2_slice[l2_index + nb_clusters - 1]); + l2_entry =3D get_l2_entry(s, l2_slice, l2_index + nb_clusters - 1); type =3D qcow2_get_cluster_type(bs, l2_entry); =20 if (type =3D=3D QCOW2_CLUSTER_NORMAL && keep_old) { @@ -1172,12 +1174,12 @@ static int count_single_write_clusters(BlockDriverS= tate *bs, int nb_clusters, bool new_alloc) { BDRVQcow2State *s =3D bs->opaque; - uint64_t l2_entry =3D be64_to_cpu(l2_slice[l2_index]); + uint64_t l2_entry =3D get_l2_entry(s, l2_slice, l2_index); uint64_t expected_offset =3D l2_entry & L2E_OFFSET_MASK; int i; =20 for (i =3D 0; i < nb_clusters; i++) { - l2_entry =3D be64_to_cpu(l2_slice[l2_index + i]); + l2_entry =3D get_l2_entry(s, l2_slice, l2_index + i); if (cluster_needs_new_alloc(bs, l2_entry) !=3D new_alloc) { break; } @@ -1313,7 +1315,7 @@ static int handle_copied(BlockDriverState *bs, uint64= _t guest_offset, return ret; } =20 - cluster_offset =3D be64_to_cpu(l2_slice[l2_index]); + cluster_offset =3D get_l2_entry(s, l2_slice, l2_index); =20 if (!cluster_needs_new_alloc(bs, cluster_offset)) { /* If a specific host_offset is required, check it */ @@ -1694,7 +1696,7 @@ static int discard_in_l2_slice(BlockDriverState *bs, = uint64_t offset, for (i =3D 0; i < nb_clusters; i++) { uint64_t old_l2_entry; =20 - old_l2_entry =3D be64_to_cpu(l2_slice[l2_index + i]); + old_l2_entry =3D get_l2_entry(s, l2_slice, l2_index + i); =20 /* * If full_discard is false, make sure that a discarded area reads= back @@ -1734,9 +1736,9 @@ static int discard_in_l2_slice(BlockDriverState *bs, = uint64_t offset, /* First remove L2 entries */ qcow2_cache_entry_mark_dirty(s->l2_table_cache, l2_slice); if (!full_discard && s->qcow_version >=3D 3) { - l2_slice[l2_index + i] =3D cpu_to_be64(QCOW_OFLAG_ZERO); + set_l2_entry(s, l2_slice, l2_index + i, QCOW_OFLAG_ZERO); } else { - l2_slice[l2_index + i] =3D cpu_to_be64(0); + set_l2_entry(s, l2_slice, l2_index + i, 0); } =20 /* Then decrease the refcount */ @@ -1816,7 +1818,7 @@ static int zero_in_l2_slice(BlockDriverState *bs, uin= t64_t offset, uint64_t old_offset; QCow2ClusterType cluster_type; =20 - old_offset =3D be64_to_cpu(l2_slice[l2_index + i]); + old_offset =3D get_l2_entry(s, l2_slice, l2_index + i); =20 /* * Minimize L2 changes if the cluster already reads back as @@ -1830,10 +1832,11 @@ static int zero_in_l2_slice(BlockDriverState *bs, u= int64_t offset, =20 qcow2_cache_entry_mark_dirty(s->l2_table_cache, l2_slice); if (cluster_type =3D=3D QCOW2_CLUSTER_COMPRESSED || unmap) { - l2_slice[l2_index + i] =3D cpu_to_be64(QCOW_OFLAG_ZERO); + set_l2_entry(s, l2_slice, l2_index + i, QCOW_OFLAG_ZERO); qcow2_free_any_clusters(bs, old_offset, 1, QCOW2_DISCARD_REQUE= ST); } else { - l2_slice[l2_index + i] |=3D cpu_to_be64(QCOW_OFLAG_ZERO); + uint64_t entry =3D get_l2_entry(s, l2_slice, l2_index + i); + set_l2_entry(s, l2_slice, l2_index + i, entry | QCOW_OFLAG_ZER= O); } } =20 @@ -1971,7 +1974,7 @@ static int expand_zero_clusters_in_l1(BlockDriverStat= e *bs, uint64_t *l1_table, } =20 for (j =3D 0; j < s->l2_slice_size; j++) { - uint64_t l2_entry =3D be64_to_cpu(l2_slice[j]); + uint64_t l2_entry =3D get_l2_entry(s, l2_slice, j); int64_t offset =3D l2_entry & L2E_OFFSET_MASK; QCow2ClusterType cluster_type =3D qcow2_get_cluster_type(bs, l2_entry); @@ -1985,7 +1988,7 @@ static int expand_zero_clusters_in_l1(BlockDriverStat= e *bs, uint64_t *l1_table, if (!bs->backing) { /* not backed; therefore we can simply deallocate = the * cluster */ - l2_slice[j] =3D 0; + set_l2_entry(s, l2_slice, j, 0); l2_dirty =3D true; continue; } @@ -2051,9 +2054,9 @@ static int expand_zero_clusters_in_l1(BlockDriverStat= e *bs, uint64_t *l1_table, } =20 if (l2_refcount =3D=3D 1) { - l2_slice[j] =3D cpu_to_be64(offset | QCOW_OFLAG_COPIED= ); + set_l2_entry(s, l2_slice, j, offset | QCOW_OFLAG_COPIE= D); } else { - l2_slice[j] =3D cpu_to_be64(offset); + set_l2_entry(s, l2_slice, j, offset); } l2_dirty =3D true; } diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c index 7ef1c0e42a..141e4fdcb1 100644 --- a/block/qcow2-refcount.c +++ b/block/qcow2-refcount.c @@ -1310,7 +1310,7 @@ int qcow2_update_snapshot_refcount(BlockDriverState *= bs, uint64_t cluster_index; uint64_t offset; =20 - entry =3D be64_to_cpu(l2_slice[j]); + entry =3D get_l2_entry(s, l2_slice, j); old_entry =3D entry; entry &=3D ~QCOW_OFLAG_COPIED; offset =3D entry & L2E_OFFSET_MASK; @@ -1384,7 +1384,7 @@ int qcow2_update_snapshot_refcount(BlockDriverState *= bs, qcow2_cache_set_dependency(bs, s->l2_table_cac= he, s->refcount_block_c= ache); } - l2_slice[j] =3D cpu_to_be64(entry); + set_l2_entry(s, l2_slice, j, entry); qcow2_cache_entry_mark_dirty(s->l2_table_cache, l2_slice); } @@ -1617,7 +1617,7 @@ static int check_refcounts_l2(BlockDriverState *bs, B= drvCheckResult *res, =20 /* Do the actual checks */ for(i =3D 0; i < s->l2_size; i++) { - l2_entry =3D be64_to_cpu(l2_table[i]); + l2_entry =3D get_l2_entry(s, l2_table, i); =20 switch (qcow2_get_cluster_type(bs, l2_entry)) { case QCOW2_CLUSTER_COMPRESSED: @@ -1686,7 +1686,7 @@ static int check_refcounts_l2(BlockDriverState *bs, B= drvCheckResult *res, QCOW2_OL_INACTIVE_L2; =20 l2_entry =3D QCOW_OFLAG_ZERO; - l2_table[i] =3D cpu_to_be64(l2_entry); + set_l2_entry(s, l2_table, i, l2_entry); ret =3D qcow2_pre_write_overlap_check(bs, ign, l2e_offset, sizeof(uint64_t), false); if (ret < 0) { @@ -1914,7 +1914,7 @@ static int check_oflag_copied(BlockDriverState *bs, B= drvCheckResult *res, } =20 for (j =3D 0; j < s->l2_size; j++) { - uint64_t l2_entry =3D be64_to_cpu(l2_table[j]); + uint64_t l2_entry =3D get_l2_entry(s, l2_table, j); uint64_t data_offset =3D l2_entry & L2E_OFFSET_MASK; QCow2ClusterType cluster_type =3D qcow2_get_cluster_type(bs, l= 2_entry); =20 @@ -1937,9 +1937,10 @@ static int check_oflag_copied(BlockDriverState *bs, = BdrvCheckResult *res, "l2_entry=3D%" PRIx64 " refcount=3D%" PRIu64 "= \n", repair ? "Repairing" : "ERROR", l2_entry, refc= ount); if (repair) { - l2_table[j] =3D cpu_to_be64(refcount =3D=3D 1 - ? l2_entry | QCOW_OFLAG_COPIED - : l2_entry & ~QCOW_OFLAG_COPIED); + set_l2_entry(s, l2_table, j, + refcount =3D=3D 1 ? + l2_entry | QCOW_OFLAG_COPIED : + l2_entry & ~QCOW_OFLAG_COPIED); l2_dirty++; } } --=20 2.20.1 From nobody Tue May 7 09:01:18 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1584469591; cv=none; d=zohomail.com; s=zohoarc; b=NnNtFtuj/t0G0dgXR0ExwcMqsnzLFOabJL+s16kpQHqxSCxixPio/+EsWfc0cZ96IHWh4x3mGcfhrv8nBfyaA56Q272T9tiUJBQm1tDXz9GhVmQyHWgUck3DkouOEZBNrA7Id8CiQyizor9roL/kXHUGPqnGNRR9OiMawlx/JUg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1584469591; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=TKff4cYs4DZY3KrO7NuCZI8bc9isDfcNxdbF0M4xumo=; b=WroA2qLOEw9maGraO4XHxWFxREAObyRI16hO50gaeGvvx8xxQmnAhVY/A5DMfwwjFAcabW/QyUgT5kaUk/WVtVPcRHXFNQpEZNp8a5qDgaUlMtXZ12ZettXvehID5lvg1h2Whu7Wd3YtD6Xw84TR4iuBVvxAmvZ77AZZ8LpKEwY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1584469591743161.02347052169546; Tue, 17 Mar 2020 11:26:31 -0700 (PDT) Received: from localhost ([::1]:39140 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEGv8-0007kI-Kx for importer@patchew.org; Tue, 17 Mar 2020 14:26:30 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48933) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEGmz-0003ZQ-Oz for qemu-devel@nongnu.org; Tue, 17 Mar 2020 14:18:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jEGmv-00009k-AN for qemu-devel@nongnu.org; Tue, 17 Mar 2020 14:18:05 -0400 Received: from fanzine.igalia.com ([178.60.130.6]:57998) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jEGmu-0005xu-6X; Tue, 17 Mar 2020 14:18:01 -0400 Received: from [81.0.35.138] (helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1jEGmD-00014w-3c; Tue, 17 Mar 2020 19:17:17 +0100 Received: from berto by perseus.local with local (Exim 4.92) (envelope-from ) id 1jEGlw-0006OH-96; Tue, 17 Mar 2020 19:17:00 +0100 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=TKff4cYs4DZY3KrO7NuCZI8bc9isDfcNxdbF0M4xumo=; b=hFxQxeE7crizD8RQ5ShSeWdI2ZP9q5Qck2ULbDgDhHtwr65Zs4YnlCXK4UDgWq/m8ZbQvt6Kg784/jYd7bZ96qDoDVIhXA7SF4BbdappVulRCwdaks1I17rpVZsKIIUEcwVOGa27rWWf+sz1N0LmoY7ivb279SlEDuLexyukLMZ5HXYCQCKexQ5p1vyxXB/l3iesuN4HGbiwobjcGrVNC9+Gz0/gCix9111Lguy8w5cG4GbUgt233DAKyXhxt8b7cMD13F1FXk1MOM3kw8ipegx4EvPhYt/E+XPQIfacju94uwHUx4mUGbCKxSC0Ufyn3VVQZiuHWJmZ7OSZBXRYiw==; From: Alberto Garcia To: qemu-devel@nongnu.org Subject: [PATCH v4 07/30] qcow2: Document the Extended L2 Entries feature Date: Tue, 17 Mar 2020 19:16:04 +0100 Message-Id: X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy] X-Received-From: 178.60.130.6 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Anton Nefedov , Alberto Garcia , qemu-block@nongnu.org, Max Reitz , Vladimir Sementsov-Ogievskiy , "Denis V . Lunev" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Subcluster allocation in qcow2 is implemented by extending the existing L2 table entries and adding additional information to indicate the allocation status of each subcluster. This patch documents the changes to the qcow2 format and how they affect the calculation of the L2 cache size. Signed-off-by: Alberto Garcia Reviewed-by: Max Reitz --- docs/interop/qcow2.txt | 68 ++++++++++++++++++++++++++++++++++++++++-- docs/qcow2-cache.txt | 19 +++++++++++- 2 files changed, 83 insertions(+), 4 deletions(-) diff --git a/docs/interop/qcow2.txt b/docs/interop/qcow2.txt index 5597e24474..2e8cad38c4 100644 --- a/docs/interop/qcow2.txt +++ b/docs/interop/qcow2.txt @@ -39,6 +39,9 @@ The first cluster of a qcow2 image contains the file head= er: as the maximum cluster size and won't be able to open = images with larger cluster sizes. =20 + Note: if the image has Extended L2 Entries then cluste= r_bits + must be at least 14 (i.e. 16384 byte clusters). + 24 - 31: size Virtual disk size in bytes. =20 @@ -114,7 +117,12 @@ the next fields through header_length. clusters. The compression_type field must = be present and not zero. =20 - Bits 4-63: Reserved (set to 0) + Bit 4: Extended L2 Entries. If this bit is set t= hen + L2 table entries use an extended format th= at + allows subcluster-based allocation. See the + Extended L2 Entries section for more detai= ls. + + Bits 5-63: Reserved (set to 0) =20 80 - 87: compatible_features Bitmask of compatible features. An implementation can @@ -493,7 +501,7 @@ cannot be relaxed without an incompatible layout change= ). Given an offset into the virtual disk, the offset into the image file can = be obtained as follows: =20 - l2_entries =3D (cluster_size / sizeof(uint64_t)) + l2_entries =3D (cluster_size / sizeof(uint64_t)) [*] =20 l2_index =3D (offset / cluster_size) % l2_entries l1_index =3D (offset / cluster_size) / l2_entries @@ -503,6 +511,8 @@ obtained as follows: =20 return cluster_offset + (offset % cluster_size) =20 + [*] this changes if Extended L2 Entries are enabled, see next section + L1 table entry: =20 Bit 0 - 8: Reserved (set to 0) @@ -543,7 +553,8 @@ Standard Cluster Descriptor: nor is data read from the backing file if the cluster = is unallocated. =20 - With version 2, this is always 0. + With version 2 or with extended L2 entries (see the ne= xt + section), this is always 0. =20 1 - 8: Reserved (set to 0) =20 @@ -580,6 +591,57 @@ file (except if bit 0 in the Standard Cluster Descript= or is set). If there is no backing file or the backing file is smaller than the image, they shall = read zeros for all parts that are not covered by the backing file. =20 +=3D=3D Extended L2 Entries =3D=3D + +An image uses Extended L2 Entries if bit 4 is set on the incompatible_feat= ures +field of the header. + +In these images standard data clusters are divided into 32 subclusters of = the +same size. They are contiguous and start from the beginning of the cluster. +Subclusters can be allocated independently and the L2 entry contains infor= mation +indicating the status of each one of them. Compressed data clusters don't = have +subclusters so they are treated the same as in images without this feature. + +The size of an extended L2 entry is 128 bits so the number of entries per = table +is calculated using this formula: + + l2_entries =3D (cluster_size / (2 * sizeof(uint64_t))) + +The first 64 bits have the same format as the standard L2 table entry desc= ribed +in the previous section, with the exception of bit 0 of the standard clust= er +descriptor. + +The last 64 bits contain a subcluster allocation bitmap with this format: + +Subcluster Allocation Bitmap (for standard clusters): + + Bit 0 - 31: Allocation status (one bit per subcluster) + + 1: the subcluster is allocated. In this case the + host cluster offset field must contain a valid + offset. + 0: the subcluster is not allocated. In this case + read requests shall go to the backing file or + return zeros if there is no backing file data. + + Bits are assigned starting from the least significant + one (i.e. bit x is used for subcluster x). + + 32 - 63 Subcluster reads as zeros (one bit per subcluster) + + 1: the subcluster reads as zeros. In this case the + allocation status bit must be unset. The host + cluster offset field may or may not be set. + 0: no effect. + + Bits are assigned starting from the least significant + one (i.e. bit x is used for subcluster x - 32). + +Subcluster Allocation Bitmap (for compressed clusters): + + Bit 0 - 63: Reserved (set to 0) + Compressed clusters don't have subclusters, + so this field is not used. =20 =3D=3D Snapshots =3D=3D =20 diff --git a/docs/qcow2-cache.txt b/docs/qcow2-cache.txt index d57f409861..5f763aa6bb 100644 --- a/docs/qcow2-cache.txt +++ b/docs/qcow2-cache.txt @@ -1,6 +1,6 @@ qcow2 L2/refcount cache configuration =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D -Copyright (C) 2015, 2018 Igalia, S.L. +Copyright (C) 2015, 2018-2020 Igalia, S.L. Author: Alberto Garcia =20 This work is licensed under the terms of the GNU GPL, version 2 or @@ -222,3 +222,20 @@ support this functionality, and is 0 (disabled) on oth= er platforms. This functionality currently relies on the MADV_DONTNEED argument for madvise() to actually free the memory. This is a Linux-specific feature, so cache-clean-interval is not supported on other systems. + + +Extended L2 Entries +------------------- +All numbers shown in this document are valid for qcow2 images with normal +64-bit L2 entries. + +Images with extended L2 entries need twice as much L2 metadata, so the L2 +cache size must be twice as large for the same disk space. + + disk_size =3D l2_cache_size * cluster_size / 16 + +i.e. + + l2_cache_size =3D disk_size * 16 / cluster_size + +Refcount blocks are not affected by this. --=20 2.20.1 From nobody Tue May 7 09:01:18 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1584469431; cv=none; d=zohomail.com; s=zohoarc; b=kbMYT7e19U2KtG5Zr59hJ4vQYKvn/Fj0hIzduzwjsX28wT2kQX9zeWeH6vJ0zIInqt91fkYklhZ99FV07sdvfSmkDylVWcD61g3ZPgT+4TH8RgMU2Lt+dBAWRaJddJQ2negR0si/t+lR5bLmYZd7l+ZSU3eUPYvU/dmcI51kqiw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1584469431; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=WWiO0wG6yJvhykhaYHX4vvs8tz93hvSckABso3lwaFM=; b=eXMnKKQwGIHtrXyKfzdoNSxVXzTiha7rPPeUgvdLfDdiT40UN0n2JvtMX+PMjDnJK/1AMr31hil466fubIkQkKxevlMFNhrzJ8sEBwRaOUbLZkUG+fLBfZ3gD9QlmOHaOczASU0dApMw4HlVu3FSEwvnSS/8Sgi5W+Iod9fnXTI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1584469431353647.8695913268424; Tue, 17 Mar 2020 11:23:51 -0700 (PDT) Received: from localhost ([::1]:39064 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEGsY-000407-6R for importer@patchew.org; Tue, 17 Mar 2020 14:23:50 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48819) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEGmw-0003Sn-UC for qemu-devel@nongnu.org; Tue, 17 Mar 2020 14:18:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jEGmu-00007i-R2 for qemu-devel@nongnu.org; Tue, 17 Mar 2020 14:18:02 -0400 Received: from fanzine.igalia.com ([178.60.130.6]:58008) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jEGmu-0005xv-6Z; Tue, 17 Mar 2020 14:18:00 -0400 Received: from [81.0.35.138] (helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1jEGmD-000152-4Z; Tue, 17 Mar 2020 19:17:17 +0100 Received: from berto by perseus.local with local (Exim 4.92) (envelope-from ) id 1jEGlw-0006OJ-A3; Tue, 17 Mar 2020 19:17:00 +0100 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=WWiO0wG6yJvhykhaYHX4vvs8tz93hvSckABso3lwaFM=; b=fJkjztVdyOZbcU47cTfqcr0tlhYB3MURjj1IUQF7ydof+WPFr+aRDOY13Y+SPzTCmyfEpN00XtYchGDkBnvyoEYfYMP8TCd966s+REmnmhQkyFkpYYnRjHw8WkNT576IZF+2z4aAxCN4/7t0JtnpWrHGLtHv61zQcLVL+cr1UCBVMikzPOOHlfZOM94fCfTHqvKJZ02xvXbw2xQSnCWTb+npEUCi1VKmFGuUp8hdiK9RotF6Smn6Qmy2GNASWgBh0UTG67dvlfviszEP5e0azf4XvBm3p2xQWr39rO8EOIk2+MRYn2EkUBPsEc9GQNx7O4CHdx1qdF2f1TnFDEckLA==; From: Alberto Garcia To: qemu-devel@nongnu.org Subject: [PATCH v4 08/30] qcow2: Add dummy has_subclusters() function Date: Tue, 17 Mar 2020 19:16:05 +0100 Message-Id: <0e88d0a02693bc48e1cf5a411ae32af973a6c3c2.1584468723.git.berto@igalia.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy] X-Received-From: 178.60.130.6 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Anton Nefedov , Alberto Garcia , qemu-block@nongnu.org, Max Reitz , Vladimir Sementsov-Ogievskiy , "Denis V . Lunev" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" This function will be used by the qcow2 code to check if an image has subclusters or not. At the moment this simply returns false. Once all patches needed for subcluster support are ready then QEMU will be able to create and read images with subclusters and this function will return the actual value. Signed-off-by: Alberto Garcia Reviewed-by: Eric Blake Reviewed-by: Max Reitz Reviewed-by: Vladimir Sementsov-Ogievskiy --- block/qcow2.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/block/qcow2.h b/block/qcow2.h index 7754d9bd02..55298750bd 100644 --- a/block/qcow2.h +++ b/block/qcow2.h @@ -495,6 +495,12 @@ typedef enum QCow2MetadataOverlap { =20 #define INV_OFFSET (-1ULL) =20 +static inline bool has_subclusters(BDRVQcow2State *s) +{ + /* FIXME: Return false until this feature is complete */ + return false; +} + static inline uint64_t get_l2_entry(BDRVQcow2State *s, uint64_t *l2_slice, int idx) { --=20 2.20.1 From nobody Tue May 7 09:01:18 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1584470000; cv=none; d=zohomail.com; s=zohoarc; b=JPBkT0i65U4JCD6UI7bk6vu+XybPcW6SE9TlYgBkZoelwjfPAKTxT9GbhtpPnMj8PIw3RCVnz0+dtKqyTpUll1JDBh7vCS22CgYQnp0g3yF0SzI6ILOfXN8uWbvVZ3E+27ug/QgcTJJ7nQgthvLT4QIr8tuM9kwrSOnh3I5166M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1584470000; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=kGMBm7CPcoxosu3rPPvnqWJexaU+hdFjFWtE5hsu+VA=; b=aLzqNfY914gdWZJm9pDM0zZdsj3Kb1qf2d3meE1HeGaVv8udg7nI0RylIuoSQiJ+9rzkFua8N/+Wz5E/v/Je3GOa9XIy0Xz17JVELw9V0dofpldfmDN+MZT5d0bNONJNhaUyWO3cDsB809iXOS83PGXHCeWR7Rb9HHQQiyCElsY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1584470000745391.77280268528307; Tue, 17 Mar 2020 11:33:20 -0700 (PDT) Received: from localhost ([::1]:39356 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEH1j-0000Cg-DX for importer@patchew.org; Tue, 17 Mar 2020 14:33:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48838) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEGmx-0003Tt-GC for qemu-devel@nongnu.org; Tue, 17 Mar 2020 14:18:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jEGmu-00007x-Rx for qemu-devel@nongnu.org; Tue, 17 Mar 2020 14:18:03 -0400 Received: from fanzine.igalia.com ([178.60.130.6]:58003) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jEGmu-0005xs-6U; Tue, 17 Mar 2020 14:18:00 -0400 Received: from [81.0.35.138] (helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1jEGmD-000155-4O; Tue, 17 Mar 2020 19:17:17 +0100 Received: from berto by perseus.local with local (Exim 4.92) (envelope-from ) id 1jEGlw-0006OL-B9; Tue, 17 Mar 2020 19:17:00 +0100 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=kGMBm7CPcoxosu3rPPvnqWJexaU+hdFjFWtE5hsu+VA=; b=ZiVVTZ3DpJTazl2RKHVl/Hx6Hgc0WX62GOaTJW9YPhU/U7N+PB5KObPNMTweEzagb83eGm4cqhH8/M6ju3vjEBLnwSZ7JYuAhAaeiN8vPAnTSg34ukKeV+tYLoAmZcp3eOWYPc4ux3q4Z1SAqQtpY6O09ks2dOgFIuMJ+TEsZCOlZ3oktsd4QiqXGtsUWjulMBbTEVFZo3UoePNpJRQoCybeSopyOnchPAMv5KSJmok+H1kiFe0AhmYn1GJpB/abb1HNEyvYJ8Q2nEl8zvspIG0djiN7K1iJhKlbHd25IXa50G3zwYQ81CCduMo3e1iJMJO9AeAE4id+lqx4VetfRQ==; From: Alberto Garcia To: qemu-devel@nongnu.org Subject: [PATCH v4 09/30] qcow2: Add subcluster-related fields to BDRVQcow2State Date: Tue, 17 Mar 2020 19:16:06 +0100 Message-Id: X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy] X-Received-From: 178.60.130.6 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Anton Nefedov , Alberto Garcia , qemu-block@nongnu.org, Max Reitz , Vladimir Sementsov-Ogievskiy , "Denis V . Lunev" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" This patch adds the following new fields to BDRVQcow2State: - subclusters_per_cluster: Number of subclusters in a cluster - subcluster_size: The size of each subcluster, in bytes - subcluster_bits: No. of bits so 1 << subcluster_bits =3D subcluster_size Images without subclusters are treated as if they had exactly one, with subcluster_size =3D cluster_size. Signed-off-by: Alberto Garcia Reviewed-by: Max Reitz Reviewed-by: Vladimir Sementsov-Ogievskiy --- block/qcow2.h | 5 +++++ block/qcow2.c | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/block/qcow2.h b/block/qcow2.h index 55298750bd..3052b14dc0 100644 --- a/block/qcow2.h +++ b/block/qcow2.h @@ -78,6 +78,8 @@ /* The cluster reads as all zeros */ #define QCOW_OFLAG_ZERO (1ULL << 0) =20 +#define QCOW_EXTL2_SUBCLUSTERS_PER_CLUSTER 32 + #define MIN_CLUSTER_BITS 9 #define MAX_CLUSTER_BITS 21 =20 @@ -284,6 +286,9 @@ typedef struct BDRVQcow2State { int cluster_bits; int cluster_size; int l2_slice_size; + int subcluster_bits; + int subcluster_size; + int subclusters_per_cluster; int l2_bits; int l2_size; int l1_size; diff --git a/block/qcow2.c b/block/qcow2.c index 5b6ceaa2fa..239e0ad3d9 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -1380,6 +1380,11 @@ static int coroutine_fn qcow2_do_open(BlockDriverSta= te *bs, QDict *options, } } =20 + s->subclusters_per_cluster =3D + has_subclusters(s) ? QCOW_EXTL2_SUBCLUSTERS_PER_CLUSTER : 1; + s->subcluster_size =3D s->cluster_size / s->subclusters_per_cluster; + s->subcluster_bits =3D ctz32(s->subcluster_size); + /* Check support for various header values */ if (header.refcount_order > 6) { error_setg(errp, "Reference count entry width too large; may not " --=20 2.20.1 From nobody Tue May 7 09:01:18 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1584469172; cv=none; d=zohomail.com; s=zohoarc; b=WQrW0AMMtqkn0pOu5tTJx8pi1zL3YYL6xrKL1J9Eyc173Ss86WQZnmK1cfnaLnCSw9NOkYoSiyFcEwfukF+q36TesfTfO2eHqz4Aq72KUc+3dFdtTewXuGHmi/cIsv8edpk6Ugfbaf/7i1fuUhhc0EQq5PL2f0hTH1qifEbjSBU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1584469172; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=zla0Gbao2cB2emUOI/Sszge/VnY7U5+RKi4/QZftaFk=; b=XBqjq25qhmLHtZi98NkVaX9nlat3+yvNsWdD9wDv5AlQ731+pdrV5hwYr0b8ug0Fc/PODgAV5Jzz6P+ncH+hxZCL35sCgkeUe5pSiHM1KCyE9IK1X095Pokclr0lBxSFw7ftYeTO3a44SuLyERaxRzdjR1Z02Xa3t7WOND8RL38= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1584469170976679.5348695169779; Tue, 17 Mar 2020 11:19:30 -0700 (PDT) Received: from localhost ([::1]:38934 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEGoL-0004ny-NC for importer@patchew.org; Tue, 17 Mar 2020 14:19:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48312) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEGmb-0002oH-0b for qemu-devel@nongnu.org; Tue, 17 Mar 2020 14:17:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jEGmZ-0007Uz-43 for qemu-devel@nongnu.org; Tue, 17 Mar 2020 14:17:40 -0400 Received: from fanzine.igalia.com ([178.60.130.6]:57717) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jEGmX-0005Uw-Ak; Tue, 17 Mar 2020 14:17:38 -0400 Received: from [81.0.35.138] (helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1jEGmC-00015W-QR; Tue, 17 Mar 2020 19:17:16 +0100 Received: from berto by perseus.local with local (Exim 4.92) (envelope-from ) id 1jEGlw-0006ON-CG; Tue, 17 Mar 2020 19:17:00 +0100 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=zla0Gbao2cB2emUOI/Sszge/VnY7U5+RKi4/QZftaFk=; b=QaumKjhqjuPTZ949r3CPye3ac7psL8MeHJQEwTbb1In6TWywk/l8tE6J/KVUo+lvPzHm3AQhckSNIKigLMc2SW8i8kohSBRE6KjV6Z5xdVAuyeDrsFQ7WmJhP7QBKL4xbtXlbRriwhZpoF+IK7fVIlhH0jfCFIHs6dFSxQdS4zmXuUmxOhjysh74zmDQxtdHMhfkNbaX99Wr1BxY/SRhOS3Z27L7UE7eW8xS5TcVEJ64pIDHFVLOdjmVIU3ds+MJb8k4gwDEcVJzt2xm3GJmCrHPO85sUeulF5t7DMwIzQfqTeuOlaYyo2vk9G7enLmRxmaFW8s45ghNt4hsT5eOTA==; From: Alberto Garcia To: qemu-devel@nongnu.org Subject: [PATCH v4 10/30] qcow2: Add offset_to_sc_index() Date: Tue, 17 Mar 2020 19:16:07 +0100 Message-Id: X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy] X-Received-From: 178.60.130.6 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Anton Nefedov , Alberto Garcia , qemu-block@nongnu.org, Max Reitz , Vladimir Sementsov-Ogievskiy , "Denis V . Lunev" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" For a given offset, return the subcluster number within its cluster (i.e. with 32 subclusters per cluster it returns a number between 0 and 31). Signed-off-by: Alberto Garcia Reviewed-by: Max Reitz Reviewed-by: Vladimir Sementsov-Ogievskiy --- block/qcow2.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/block/qcow2.h b/block/qcow2.h index 3052b14dc0..06929072d2 100644 --- a/block/qcow2.h +++ b/block/qcow2.h @@ -566,6 +566,11 @@ static inline int offset_to_l2_slice_index(BDRVQcow2St= ate *s, int64_t offset) return (offset >> s->cluster_bits) & (s->l2_slice_size - 1); } =20 +static inline int offset_to_sc_index(BDRVQcow2State *s, int64_t offset) +{ + return (offset >> s->subcluster_bits) & (s->subclusters_per_cluster - = 1); +} + static inline int64_t qcow2_vm_state_offset(BDRVQcow2State *s) { return (int64_t)s->l1_vm_state_index << (s->cluster_bits + s->l2_bits); --=20 2.20.1 From nobody Tue May 7 09:01:18 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1584469565; cv=none; d=zohomail.com; s=zohoarc; b=m7isnntd1QUHKcgCVGygNB88cODluf+Cld/uKpV58CyOvp/pdRq4qjSTZB8TsQNxEDNdX6EF0vsF10xAyNw4e6OLrYBT9SRYfi8WUz4o+M0O4gctxhExeSpZp0pt4fHSjQstVXGZGkMvIJv4KyhqZmJl2gHzaNxCHS2ysAvEzUo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1584469565; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=2/fHBs05oNAu/0EPAuhlH3K3uwbVq0B0b7Vdy8GVdcg=; b=EpW5N0iwCafKvETUlpqJf5MR5Ct6z09U4EWSgKd0BNnVl0RGQCi0TMZozwoC4YdyRLkm7DMhbqzzH5t7FX5SjQmR/QFZ1ZYaK9BXrek0cZRMQNENsF5IA/n+5qqcH/6Cf0JKTjraCceB9r9XaumF2DsedV6joMg+b5lK3SbpdV0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1584469565191654.2992431643838; Tue, 17 Mar 2020 11:26:05 -0700 (PDT) Received: from localhost ([::1]:39124 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEGuh-00072z-Ur for importer@patchew.org; Tue, 17 Mar 2020 14:26:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48319) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEGmb-0002oP-0q for qemu-devel@nongnu.org; Tue, 17 Mar 2020 14:17:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jEGmZ-0007V8-2x for qemu-devel@nongnu.org; Tue, 17 Mar 2020 14:17:40 -0400 Received: from fanzine.igalia.com ([178.60.130.6]:57773) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jEGmX-0005Yw-AL; Tue, 17 Mar 2020 14:17:38 -0400 Received: from [81.0.35.138] (helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1jEGmD-00015P-0t; Tue, 17 Mar 2020 19:17:17 +0100 Received: from berto by perseus.local with local (Exim 4.92) (envelope-from ) id 1jEGlw-0006OP-DX; Tue, 17 Mar 2020 19:17:00 +0100 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=2/fHBs05oNAu/0EPAuhlH3K3uwbVq0B0b7Vdy8GVdcg=; b=RA+ilQK/ZQiIIgZJe2YHEE49MVH27Aq4azrKyG3E9QPUl/H6DEeurSvMxbegEGC46X4gs12mBWe41DmVz2Py4eJWgZ0BTd4ZL+KNfPHb27j9pDiax1EqMlzCd4nhgCVSRfyK94l6t1PcM/pOIjb2DxImPDkX6BXqL32f/Jnyb5ilxbqY+qMkTbge9lmd4dUPbfRRbKW7+h41f2917D4UOJN/QhTYL4HSSnWMfBiZR/pBY6uNLasJa3FBFreSDMErc6BnWC88WC5lEr1NZaJBwXwOLXIfu83OO4i3xTPUvt+b37AnficyY9BBk6IEhxF54pju81hpU1sp5f2aJu1OIA==; From: Alberto Garcia To: qemu-devel@nongnu.org Subject: [PATCH v4 11/30] qcow2: Add l2_entry_size() Date: Tue, 17 Mar 2020 19:16:08 +0100 Message-Id: X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy] X-Received-From: 178.60.130.6 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Anton Nefedov , Alberto Garcia , qemu-block@nongnu.org, Max Reitz , Vladimir Sementsov-Ogievskiy , "Denis V . Lunev" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" qcow2 images with subclusters have 128-bit L2 entries. The first 64 bits contain the same information as traditional images and the last 64 bits form a bitmap with the status of each individual subcluster. Because of that we cannot assume that L2 entries are sizeof(uint64_t) anymore. This function returns the proper value for the image. Signed-off-by: Alberto Garcia Reviewed-by: Max Reitz --- block/qcow2.h | 9 +++++++++ block/qcow2-cluster.c | 12 ++++++------ block/qcow2-refcount.c | 14 ++++++++------ block/qcow2.c | 8 ++++---- 4 files changed, 27 insertions(+), 16 deletions(-) diff --git a/block/qcow2.h b/block/qcow2.h index 06929072d2..1eb4b46807 100644 --- a/block/qcow2.h +++ b/block/qcow2.h @@ -80,6 +80,10 @@ =20 #define QCOW_EXTL2_SUBCLUSTERS_PER_CLUSTER 32 =20 +/* Size of normal and extended L2 entries */ +#define L2E_SIZE_NORMAL (sizeof(uint64_t)) +#define L2E_SIZE_EXTENDED (sizeof(uint64_t) * 2) + #define MIN_CLUSTER_BITS 9 #define MAX_CLUSTER_BITS 21 =20 @@ -506,6 +510,11 @@ static inline bool has_subclusters(BDRVQcow2State *s) return false; } =20 +static inline size_t l2_entry_size(BDRVQcow2State *s) +{ + return has_subclusters(s) ? L2E_SIZE_EXTENDED : L2E_SIZE_NORMAL; +} + static inline uint64_t get_l2_entry(BDRVQcow2State *s, uint64_t *l2_slice, int idx) { diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c index cd48ab0223..41a23c5305 100644 --- a/block/qcow2-cluster.c +++ b/block/qcow2-cluster.c @@ -208,7 +208,7 @@ static int l2_load(BlockDriverState *bs, uint64_t offse= t, uint64_t l2_offset, uint64_t **l2_slice) { BDRVQcow2State *s =3D bs->opaque; - int start_of_slice =3D sizeof(uint64_t) * + int start_of_slice =3D l2_entry_size(s) * (offset_to_l2_index(s, offset) - offset_to_l2_slice_index(s, offse= t)); =20 return qcow2_cache_get(bs, s->l2_table_cache, l2_offset + start_of_sli= ce, @@ -281,7 +281,7 @@ static int l2_allocate(BlockDriverState *bs, int l1_ind= ex) =20 /* allocate a new l2 entry */ =20 - l2_offset =3D qcow2_alloc_clusters(bs, s->l2_size * sizeof(uint64_t)); + l2_offset =3D qcow2_alloc_clusters(bs, s->l2_size * l2_entry_size(s)); if (l2_offset < 0) { ret =3D l2_offset; goto fail; @@ -305,7 +305,7 @@ static int l2_allocate(BlockDriverState *bs, int l1_ind= ex) =20 /* allocate a new entry in the l2 cache */ =20 - slice_size2 =3D s->l2_slice_size * sizeof(uint64_t); + slice_size2 =3D s->l2_slice_size * l2_entry_size(s); n_slices =3D s->cluster_size / slice_size2; =20 trace_qcow2_l2_allocate_get_empty(bs, l1_index); @@ -369,7 +369,7 @@ fail: } s->l1_table[l1_index] =3D old_l2_offset; if (l2_offset > 0) { - qcow2_free_clusters(bs, l2_offset, s->l2_size * sizeof(uint64_t), + qcow2_free_clusters(bs, l2_offset, s->l2_size * l2_entry_size(s), QCOW2_DISCARD_ALWAYS); } return ret; @@ -718,7 +718,7 @@ static int get_cluster_table(BlockDriverState *bs, uint= 64_t offset, =20 /* Then decrease the refcount of the old table */ if (l2_offset) { - qcow2_free_clusters(bs, l2_offset, s->l2_size * sizeof(uint64_= t), + qcow2_free_clusters(bs, l2_offset, s->l2_size * l2_entry_size(= s), QCOW2_DISCARD_OTHER); } =20 @@ -1919,7 +1919,7 @@ static int expand_zero_clusters_in_l1(BlockDriverStat= e *bs, uint64_t *l1_table, int ret; int i, j; =20 - slice_size2 =3D s->l2_slice_size * sizeof(uint64_t); + slice_size2 =3D s->l2_slice_size * l2_entry_size(s); n_slices =3D s->cluster_size / slice_size2; =20 if (!is_active_l1) { diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c index 141e4fdcb1..3b89a97fd0 100644 --- a/block/qcow2-refcount.c +++ b/block/qcow2-refcount.c @@ -1254,7 +1254,7 @@ int qcow2_update_snapshot_refcount(BlockDriverState *= bs, l2_slice =3D NULL; l1_table =3D NULL; l1_size2 =3D l1_size * sizeof(uint64_t); - slice_size2 =3D s->l2_slice_size * sizeof(uint64_t); + slice_size2 =3D s->l2_slice_size * l2_entry_size(s); n_slices =3D s->cluster_size / slice_size2; =20 s->cache_discards =3D true; @@ -1605,7 +1605,7 @@ static int check_refcounts_l2(BlockDriverState *bs, B= drvCheckResult *res, int i, l2_size, nb_csectors, ret; =20 /* Read L2 table from disk */ - l2_size =3D s->l2_size * sizeof(uint64_t); + l2_size =3D s->l2_size * l2_entry_size(s); l2_table =3D g_malloc(l2_size); =20 ret =3D bdrv_pread(bs->file, l2_offset, l2_table, l2_size); @@ -1680,15 +1680,16 @@ static int check_refcounts_l2(BlockDriverState *bs,= BdrvCheckResult *res, fix & BDRV_FIX_ERRORS ? "Repairing" : "ERROR", offset); if (fix & BDRV_FIX_ERRORS) { + int idx =3D i * (l2_entry_size(s) / sizeof(uint64_= t)); uint64_t l2e_offset =3D - l2_offset + (uint64_t)i * sizeof(uint64_t); + l2_offset + (uint64_t)i * l2_entry_size(s); int ign =3D active ? QCOW2_OL_ACTIVE_L2 : QCOW2_OL_INACTIVE_L2; =20 l2_entry =3D QCOW_OFLAG_ZERO; set_l2_entry(s, l2_table, i, l2_entry); ret =3D qcow2_pre_write_overlap_check(bs, ign, - l2e_offset, sizeof(uint64_t), false); + l2e_offset, l2_entry_size(s), false); if (ret < 0) { fprintf(stderr, "ERROR: Overlap check failed\n= "); res->check_errors++; @@ -1698,7 +1699,8 @@ static int check_refcounts_l2(BlockDriverState *bs, B= drvCheckResult *res, } =20 ret =3D bdrv_pwrite_sync(bs->file, l2e_offset, - &l2_table[i], sizeof(uint64= _t)); + &l2_table[idx], + l2_entry_size(s)); if (ret < 0) { fprintf(stderr, "ERROR: Failed to overwrite L2= " "table entry: %s\n", strerror(-ret)); @@ -1905,7 +1907,7 @@ static int check_oflag_copied(BlockDriverState *bs, B= drvCheckResult *res, } =20 ret =3D bdrv_pread(bs->file, l2_offset, l2_table, - s->l2_size * sizeof(uint64_t)); + s->l2_size * l2_entry_size(s)); if (ret < 0) { fprintf(stderr, "ERROR: Could not read L2 table: %s\n", strerror(-ret)); diff --git a/block/qcow2.c b/block/qcow2.c index 239e0ad3d9..d3b8581aed 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -870,7 +870,7 @@ static void read_cache_sizes(BlockDriverState *bs, Qemu= Opts *opts, uint64_t max_l2_entries =3D DIV_ROUND_UP(virtual_disk_size, s->cluster= _size); /* An L2 table is always one cluster in size so the max cache size * should be a multiple of the cluster size. */ - uint64_t max_l2_cache =3D ROUND_UP(max_l2_entries * sizeof(uint64_t), + uint64_t max_l2_cache =3D ROUND_UP(max_l2_entries * l2_entry_size(s), s->cluster_size); =20 combined_cache_size_set =3D qemu_opt_get(opts, QCOW2_OPT_CACHE_SIZE); @@ -1031,7 +1031,7 @@ static int qcow2_update_options_prepare(BlockDriverSt= ate *bs, } } =20 - r->l2_slice_size =3D l2_cache_entry_size / sizeof(uint64_t); + r->l2_slice_size =3D l2_cache_entry_size / l2_entry_size(s); r->l2_table_cache =3D qcow2_cache_create(bs, l2_cache_size, l2_cache_entry_size); r->refcount_block_cache =3D qcow2_cache_create(bs, refcount_cache_size, @@ -1425,7 +1425,7 @@ static int coroutine_fn qcow2_do_open(BlockDriverStat= e *bs, QDict *options, bs->encrypted =3D true; } =20 - s->l2_bits =3D s->cluster_bits - 3; /* L2 is always one cluster */ + s->l2_bits =3D s->cluster_bits - ctz32(l2_entry_size(s)); s->l2_size =3D 1 << s->l2_bits; /* 2^(s->refcount_order - 3) is the refcount width in bytes */ s->refcount_block_bits =3D s->cluster_bits - (s->refcount_order - 3); @@ -4104,7 +4104,7 @@ static int coroutine_fn qcow2_co_truncate(BlockDriver= State *bs, int64_t offset, * preallocation. All that matters is that we will not have to al= locate * new refcount structures for them.) */ nb_new_l2_tables =3D DIV_ROUND_UP(nb_new_data_clusters, - s->cluster_size / sizeof(uint64_t)= ); + s->cluster_size / l2_entry_size(s)= ); /* The cluster range may not be aligned to L2 boundaries, so add o= ne L2 * table for a potential head/tail */ nb_new_l2_tables++; --=20 2.20.1 From nobody Tue May 7 09:01:18 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1584469399; cv=none; d=zohomail.com; s=zohoarc; b=bj0NYNwFQYCb5PBLtob7sWupRDd/yHyNmrD5Uebo+rrA1D64ESf7ldEhSZH0fiR2+yL50OmSTTxqfk5Akuhr3kDREWsG2eYZEhNG2rux5LVaR0jjoHckayi5XnNyvgEP35tPCGsS+fyZ/YTVzDNgx8DYkJO/05g9L+utfvKw48A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1584469399; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=7sHbHchVW1ZG6KSFzVDN96AUHkkExtfWiKVvhF1b2ew=; b=Q1HpbMELs2aWjaNINiYi6fGD9Ok36xlRX9fyTM2cIgAw4qWoFUemIhikZUP7lr2KxFFar7nS3igk5iJGpyQV9n8/etWl5Y0skS3L33xDxlu00XBEUF1GBsyYH/IRZLBslRDLAc0ronsUz9C4t15E983YQPRKzAein1lRCfApN1o= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1584469399337818.2147805288199; Tue, 17 Mar 2020 11:23:19 -0700 (PDT) Received: from localhost ([::1]:39038 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEGs2-0002ma-AC for importer@patchew.org; Tue, 17 Mar 2020 14:23:18 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48310) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEGma-0002oE-W4 for qemu-devel@nongnu.org; Tue, 17 Mar 2020 14:17:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jEGmZ-0007Ul-1R for qemu-devel@nongnu.org; Tue, 17 Mar 2020 14:17:40 -0400 Received: from fanzine.igalia.com ([178.60.130.6]:57716) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jEGmX-0005Ux-An; Tue, 17 Mar 2020 14:17:38 -0400 Received: from [81.0.35.138] (helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1jEGmD-00015X-0N; Tue, 17 Mar 2020 19:17:17 +0100 Received: from berto by perseus.local with local (Exim 4.92) (envelope-from ) id 1jEGlw-0006OR-Ed; Tue, 17 Mar 2020 19:17:00 +0100 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=7sHbHchVW1ZG6KSFzVDN96AUHkkExtfWiKVvhF1b2ew=; b=DlsQQ9RNg/Btd8ks46DNOKBlT7EGXo14flT8mmprdlBH7nnEO+iAZtR51Z2JrO9ugiR2A7q+5/5BRlocyDeWgPSO2eWkxUwItpCy8UB2MV7/ILv4a+RgWxGAhkW3yj9u0kHngLIuwsROVw/MAuZyCcfIWIcDOefhMnKArVu3QuR01b6XOlMZB0HW+ip7paDuO89Jzr7qiYaoW+d0QxeS+KfGJUKd+gZ8VSiS7xediJIDj17jPgmbgDXd9JHRt07WUGI2NXh0M7GOosmNo44MCXGc/V8hlE2vVqY6v7jiFe8CMWLq3+zQZih8QS7y0E/N+jaqO82Bsr1WfD3gQk0DPg==; From: Alberto Garcia To: qemu-devel@nongnu.org Subject: [PATCH v4 12/30] qcow2: Update get/set_l2_entry() and add get/set_l2_bitmap() Date: Tue, 17 Mar 2020 19:16:09 +0100 Message-Id: X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy] X-Received-From: 178.60.130.6 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Anton Nefedov , Alberto Garcia , qemu-block@nongnu.org, Max Reitz , Vladimir Sementsov-Ogievskiy , "Denis V . Lunev" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Extended L2 entries are 128-bit wide: 64 bits for the entry itself and 64 bits for the subcluster allocation bitmap. In order to support them correctly get/set_l2_entry() need to be updated so they take the entry width into account in order to calculate the correct offset. This patch also adds the get/set_l2_bitmap() functions that are used to access the bitmaps. For convenience we allow calling get_l2_bitmap() on images without subclusters, although the caller does not need and should ignore the returned value. Signed-off-by: Alberto Garcia Reviewed-by: Max Reitz Reviewed-by: Vladimir Sementsov-Ogievskiy --- block/qcow2.h | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/block/qcow2.h b/block/qcow2.h index 1eb4b46807..9611efbc52 100644 --- a/block/qcow2.h +++ b/block/qcow2.h @@ -518,15 +518,37 @@ static inline size_t l2_entry_size(BDRVQcow2State *s) static inline uint64_t get_l2_entry(BDRVQcow2State *s, uint64_t *l2_slice, int idx) { + idx *=3D l2_entry_size(s) / sizeof(uint64_t); return be64_to_cpu(l2_slice[idx]); } =20 +static inline uint64_t get_l2_bitmap(BDRVQcow2State *s, uint64_t *l2_slice, + int idx) +{ + if (has_subclusters(s)) { + idx *=3D l2_entry_size(s) / sizeof(uint64_t); + return be64_to_cpu(l2_slice[idx + 1]); + } else { + /* For convenience only; the caller should ignore this value. */ + return 0; + } +} + static inline void set_l2_entry(BDRVQcow2State *s, uint64_t *l2_slice, int idx, uint64_t entry) { + idx *=3D l2_entry_size(s) / sizeof(uint64_t); l2_slice[idx] =3D cpu_to_be64(entry); } =20 +static inline void set_l2_bitmap(BDRVQcow2State *s, uint64_t *l2_slice, + int idx, uint64_t bitmap) +{ + assert(has_subclusters(s)); + idx *=3D l2_entry_size(s) / sizeof(uint64_t); + l2_slice[idx + 1] =3D cpu_to_be64(bitmap); +} + static inline bool has_data_file(BlockDriverState *bs) { BDRVQcow2State *s =3D bs->opaque; --=20 2.20.1 From nobody Tue May 7 09:01:18 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1584469773; cv=none; d=zohomail.com; s=zohoarc; b=eel3LNwkTUl9ZK9zmCBb5cYm1nFBS0i7yKdp6E4EqJCDTSEyP1wTUitDGewG9CbiKo3Ix85Gk776aFZEE2O6dDwfgvifhjQhMnlPx/SJIg1tdsYw3Icls7+zIYX3Eqn3fM7NKxRSKhu8MfAeF5aKbe9DtGxY6yXafrmfy+ISrAI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1584469773; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=4BBw2Ityi0ohM0ZImSiQSBFtH8AuASPs6yiG1atimPU=; b=RBTsoXm2DGvqgapQErzd1Iv51Uq+oGBzmWWOylKmb20xdjcKsJxanWsLnCLpf8/xXQ3Fn/TwbF0ftnTVHnf8yedkm9UMRVNcNtNmonw0Di1GCTM2eFaijdvX/dsGEbvVznbpNi3o5C0yC8DLSuV5nGQSkBVc9YsrvDBeUriINvM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 158446977329418.080499650948354; Tue, 17 Mar 2020 11:29:33 -0700 (PDT) Received: from localhost ([::1]:39260 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEGy4-0004Zs-8O for importer@patchew.org; Tue, 17 Mar 2020 14:29:32 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48910) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEGmz-0003YQ-CU for qemu-devel@nongnu.org; Tue, 17 Mar 2020 14:18:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jEGmv-00009f-9u for qemu-devel@nongnu.org; Tue, 17 Mar 2020 14:18:05 -0400 Received: from fanzine.igalia.com ([178.60.130.6]:58004) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jEGmu-0005xq-6B; Tue, 17 Mar 2020 14:18:01 -0400 Received: from [81.0.35.138] (helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1jEGmD-00015S-4Q; Tue, 17 Mar 2020 19:17:17 +0100 Received: from berto by perseus.local with local (Exim 4.92) (envelope-from ) id 1jEGlw-0006OT-G1; Tue, 17 Mar 2020 19:17:00 +0100 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=4BBw2Ityi0ohM0ZImSiQSBFtH8AuASPs6yiG1atimPU=; b=D5AzoltHnCOw6U2FSc5xCIu4EfvY3gG/REPK3s1YVYpGBva9of7lncg9f/V6eqgV247Qii3U/845v+2AstQozS8UIT17rH2Ni7DCxLolCmcrXuNrPcy12zewFHtLpll+FO7LHOEizmIaOjPnwsxchKQ1JGZ3KZUBra+TJblEaymzcGUE80i8NDn6nHodBMt7DWI3SGme6r+3S2rFH15nO5U6yt5N5czb/DP50bBP9Y1y0G8Xeh4lFpITOedxWzm4q6P7lepK5KA7kmXsJpsN0UMbgqHjYYRgbpTfKPrWtQjBCcGzxgfIyxqe+kGoDA+cH5G8V/4QQK4oXnLuRBxMRg==; From: Alberto Garcia To: qemu-devel@nongnu.org Subject: [PATCH v4 13/30] qcow2: Add QCow2SubclusterType and qcow2_get_subcluster_type() Date: Tue, 17 Mar 2020 19:16:10 +0100 Message-Id: X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy] X-Received-From: 178.60.130.6 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Anton Nefedov , Alberto Garcia , qemu-block@nongnu.org, Max Reitz , Vladimir Sementsov-Ogievskiy , "Denis V . Lunev" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" This patch adds QCow2SubclusterType, which is the subcluster-level version of QCow2ClusterType. All QCOW2_SUBCLUSTER_* values have the the same meaning as their QCOW2_CLUSTER_* equivalents (when they exist). See below for details and caveats. In images without extended L2 entries clusters are treated as having exactly one subcluster so it is possible to replace one data type with the other while keeping the exact same semantics. With extended L2 entries there are new possible values, and every subcluster in the same cluster can obviously have a different QCow2SubclusterType so functions need to be adapted to work on the subcluster level. There are several things that have to be taken into account: a) QCOW2_SUBCLUSTER_COMPRESSED means that the whole cluster is compressed. We do not support compression at the subcluster level. b) There are two different values for unallocated subclusters: QCOW2_SUBCLUSTER_UNALLOCATED_PLAIN which means that the whole cluster is unallocated, and QCOW2_SUBCLUSTER_UNALLOCATED_ALLOC which means that the cluster is allocated but the subcluster is not. The latter can only happen in images with extended L2 entries. c) QCOW2_SUBCLUSTER_INVALID is used to detect the cases where an L2 entry has a value that violates the specification. The caller is responsible for handling these situations. To prevent compatibility problems with images that have invalid values but are currently being read by QEMU without causing side effects, QCOW2_SUBCLUSTER_INVALID is only returned for images with extended L2 entries. qcow2_cluster_to_subcluster_type() is added as a separate function from qcow2_get_subcluster_type(), but this is only temporary and both will be merged in a subsequent patch. Signed-off-by: Alberto Garcia Reviewed-by: Max Reitz Reviewed-by: Vladimir Sementsov-Ogievskiy --- block/qcow2.h | 120 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 120 insertions(+) diff --git a/block/qcow2.h b/block/qcow2.h index 9611efbc52..52865787ee 100644 --- a/block/qcow2.h +++ b/block/qcow2.h @@ -80,6 +80,15 @@ =20 #define QCOW_EXTL2_SUBCLUSTERS_PER_CLUSTER 32 =20 +/* The subcluster X [0..31] reads as zeroes */ +#define QCOW_OFLAG_SUB_ZERO(X) ((1ULL << 32) << (X)) +/* The subcluster X [0..31] is allocated */ +#define QCOW_OFLAG_SUB_ALLOC(X) (1ULL << (X)) +/* L2 entry bitmap with all "read as zeroes" bits set */ +#define QCOW_L2_BITMAP_ALL_ZEROES 0xFFFFFFFF00000000ULL +/* L2 entry bitmap with all allocation bits set */ +#define QCOW_L2_BITMAP_ALL_ALLOC 0x00000000FFFFFFFFULL + /* Size of normal and extended L2 entries */ #define L2E_SIZE_NORMAL (sizeof(uint64_t)) #define L2E_SIZE_EXTENDED (sizeof(uint64_t) * 2) @@ -447,6 +456,33 @@ typedef struct QCowL2Meta QLIST_ENTRY(QCowL2Meta) next_in_flight; } QCowL2Meta; =20 +/* + * In images with standard L2 entries all clusters are treated as if + * they had one subcluster so QCow2ClusterType and QCow2SubclusterType + * can be mapped to each other and have the exact same meaning + * (QCOW2_SUBCLUSTER_UNALLOCATED_ALLOC cannot happen in these images). + * + * In images with extended L2 entries QCow2ClusterType refers to the + * complete cluster and QCow2SubclusterType to each of the individual + * subclusters, so there are several possible combinations: + * + * |--------------+---------------------------| + * | Cluster type | Possible subcluster types | + * |--------------+---------------------------| + * | UNALLOCATED | UNALLOCATED_PLAIN | + * | | ZERO_PLAIN | + * |--------------+---------------------------| + * | NORMAL | UNALLOCATED_ALLOC | + * | | ZERO_ALLOC | + * | | NORMAL | + * |--------------+---------------------------| + * | COMPRESSED | COMPRESSED | + * |--------------+---------------------------| + * + * QCOW2_SUBCLUSTER_INVALID means that the L2 entry is incorrect and + * the image should be marked corrupt. + */ + typedef enum QCow2ClusterType { QCOW2_CLUSTER_UNALLOCATED, QCOW2_CLUSTER_ZERO_PLAIN, @@ -455,6 +491,16 @@ typedef enum QCow2ClusterType { QCOW2_CLUSTER_COMPRESSED, } QCow2ClusterType; =20 +typedef enum QCow2SubclusterType { + QCOW2_SUBCLUSTER_UNALLOCATED_PLAIN, + QCOW2_SUBCLUSTER_UNALLOCATED_ALLOC, + QCOW2_SUBCLUSTER_ZERO_PLAIN, + QCOW2_SUBCLUSTER_ZERO_ALLOC, + QCOW2_SUBCLUSTER_NORMAL, + QCOW2_SUBCLUSTER_COMPRESSED, + QCOW2_SUBCLUSTER_INVALID, +} QCow2SubclusterType; + typedef enum QCow2MetadataOverlap { QCOW2_OL_MAIN_HEADER_BITNR =3D 0, QCOW2_OL_ACTIVE_L1_BITNR =3D 1, @@ -632,6 +678,80 @@ static inline QCow2ClusterType qcow2_get_cluster_type(= BlockDriverState *bs, } } =20 +/* + * For an image without extended L2 entries, return the + * QCow2SubclusterType equivalent of a given QCow2ClusterType. + */ +static inline +QCow2SubclusterType qcow2_cluster_to_subcluster_type(QCow2ClusterType type) +{ + switch (type) { + case QCOW2_CLUSTER_COMPRESSED: + return QCOW2_SUBCLUSTER_COMPRESSED; + case QCOW2_CLUSTER_ZERO_PLAIN: + return QCOW2_SUBCLUSTER_ZERO_PLAIN; + case QCOW2_CLUSTER_ZERO_ALLOC: + return QCOW2_SUBCLUSTER_ZERO_ALLOC; + case QCOW2_CLUSTER_NORMAL: + return QCOW2_SUBCLUSTER_NORMAL; + case QCOW2_CLUSTER_UNALLOCATED: + return QCOW2_SUBCLUSTER_UNALLOCATED_PLAIN; + default: + g_assert_not_reached(); + } +} + +/* + * In an image without subsclusters @l2_bitmap is ignored and + * @sc_index must be 0. + */ +static inline +QCow2SubclusterType qcow2_get_subcluster_type(BlockDriverState *bs, + uint64_t l2_entry, + uint64_t l2_bitmap, + unsigned sc_index) +{ + BDRVQcow2State *s =3D bs->opaque; + QCow2ClusterType type =3D qcow2_get_cluster_type(bs, l2_entry); + assert(sc_index < s->subclusters_per_cluster); + + if (has_subclusters(s)) { + bool sc_zero =3D l2_bitmap & QCOW_OFLAG_SUB_ZERO(sc_index); + bool sc_alloc =3D l2_bitmap & QCOW_OFLAG_SUB_ALLOC(sc_index); + switch (type) { + case QCOW2_CLUSTER_COMPRESSED: + return QCOW2_SUBCLUSTER_COMPRESSED; + case QCOW2_CLUSTER_ZERO_PLAIN: + case QCOW2_CLUSTER_ZERO_ALLOC: + return QCOW2_SUBCLUSTER_INVALID; + case QCOW2_CLUSTER_NORMAL: + if (!sc_zero && !sc_alloc) { + return QCOW2_SUBCLUSTER_UNALLOCATED_ALLOC; + } else if (!sc_zero && sc_alloc) { + return QCOW2_SUBCLUSTER_NORMAL; + } else if (sc_zero && !sc_alloc) { + return QCOW2_SUBCLUSTER_ZERO_ALLOC; + } else { /* sc_zero && sc_alloc */ + return QCOW2_SUBCLUSTER_INVALID; + } + case QCOW2_CLUSTER_UNALLOCATED: + if (!sc_zero && !sc_alloc) { + return QCOW2_SUBCLUSTER_UNALLOCATED_PLAIN; + } else if (!sc_zero && sc_alloc) { + return QCOW2_SUBCLUSTER_INVALID; + } else if (sc_zero && !sc_alloc) { + return QCOW2_SUBCLUSTER_ZERO_PLAIN; + } else { /* sc_zero && sc_alloc */ + return QCOW2_SUBCLUSTER_INVALID; + } + default: + g_assert_not_reached(); + } + } else { + return qcow2_cluster_to_subcluster_type(type); + } +} + /* Check whether refcounts are eager or lazy */ static inline bool qcow2_need_accurate_refcounts(BDRVQcow2State *s) { --=20 2.20.1 From nobody Tue May 7 09:01:18 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1584470106; cv=none; d=zohomail.com; s=zohoarc; b=WAsuK7mAcmX2d0ae+3U4v2FEQtS0APHeOkfBBvY0hJpDvmmK20+ZgWwQ516TgUCunDfwThsQdFSYiE5AoT/2WExpe900sW4DlmJcHFNYJC/3mvji7gOHQZi1Csc+qQMIAlQZ/+yV/awh4VS1qfSis1avdm5dHmYipTMTOvFTXkQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1584470106; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=woi6foyn/GnsQXxokCfj/612eLxPV2bZbIy780eGch4=; b=IYEtHEItoo+DrdK2NUy7ZJGzIJ53MHddYFhOau13WiEaG202+h+e84ictAInJ+q+oTGOJvfWLk7ScCJcaVzcizG3kEVTyHxAjJ14fBXQ+s5DIqRxbEDrZFrlB+CNfDpl3ZcEEqW/C4P/iEAsCvNLeh3mZLnuJ3nqiN/T2WGyJ6Y= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1584470106296925.1566402023527; Tue, 17 Mar 2020 11:35:06 -0700 (PDT) Received: from localhost ([::1]:39432 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEH3R-0003fV-37 for importer@patchew.org; Tue, 17 Mar 2020 14:35:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48705) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEGmu-0003Mn-57 for qemu-devel@nongnu.org; Tue, 17 Mar 2020 14:18:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jEGms-0008UH-GF for qemu-devel@nongnu.org; Tue, 17 Mar 2020 14:18:00 -0400 Received: from fanzine.igalia.com ([178.60.130.6]:57771) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jEGms-0005Ys-5E; Tue, 17 Mar 2020 14:17:58 -0400 Received: from [81.0.35.138] (helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1jEGmD-00015Q-0o; Tue, 17 Mar 2020 19:17:17 +0100 Received: from berto by perseus.local with local (Exim 4.92) (envelope-from ) id 1jEGlw-0006OV-H0; Tue, 17 Mar 2020 19:17:00 +0100 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=woi6foyn/GnsQXxokCfj/612eLxPV2bZbIy780eGch4=; b=OOndXjn7oDji51bTAsQqtUeSdocQYLxrCgRLxHXRY7rd0r6xQ5e50lIG6RHnHgsgyW1pmkSbjqzgkbaJrsQp9kWTD+67kVTdU24Z6tCL1OoJxeOfb1rfGwVVB6Wne8hqqry0mNc+ZE6mjrLYLMHOPOTsb2LvBtbm1Dx/YCHlrhzoywalGTVauet9cBU9DMCScqc+niaQFrRwz31Cd63to6+c1TdLU5B6pj33JrsRjWpCIWhPJgHIfy57UqphjXahd/PVUtisPpdX6Lm+Lxr7vaLL2ERk+8sTGwkxhPQ27wyi/vYYDxa6vkUYB9OC0tFc8/5ruQwkIW5UoLKffpwaxw==; From: Alberto Garcia To: qemu-devel@nongnu.org Subject: [PATCH v4 14/30] qcow2: Add cluster type parameter to qcow2_get_host_offset() Date: Tue, 17 Mar 2020 19:16:11 +0100 Message-Id: <348c0b057802b5b35eefe3dc7cc8ef2964024ed5.1584468723.git.berto@igalia.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy] X-Received-From: 178.60.130.6 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Anton Nefedov , Alberto Garcia , qemu-block@nongnu.org, Max Reitz , Vladimir Sementsov-Ogievskiy , "Denis V . Lunev" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" This function returns an integer that can be either an error code or a cluster type (a value from the QCow2ClusterType enum). We are going to start using subcluster types instead of cluster types in some functions so it's better to use the exact data types instead of integers for clarity and in order to detect errors more easily. This patch makes qcow2_get_host_offset() return 0 on success and puts the returned cluster type in a separate parameter. There are no semantic changes. Signed-off-by: Alberto Garcia Reviewed-by: Max Reitz Reviewed-by: Vladimir Sementsov-Ogievskiy --- block/qcow2.h | 3 ++- block/qcow2-cluster.c | 11 +++++++---- block/qcow2.c | 37 ++++++++++++++++++++++--------------- 3 files changed, 31 insertions(+), 20 deletions(-) diff --git a/block/qcow2.h b/block/qcow2.h index 52865787ee..6b7b286b91 100644 --- a/block/qcow2.h +++ b/block/qcow2.h @@ -859,7 +859,8 @@ int qcow2_encrypt_sectors(BDRVQcow2State *s, int64_t se= ctor_num, uint8_t *buf, int nb_sectors, bool enc, Error **= errp); =20 int qcow2_get_host_offset(BlockDriverState *bs, uint64_t offset, - unsigned int *bytes, uint64_t *host_offset); + unsigned int *bytes, uint64_t *host_offset, + QCow2ClusterType *cluster_type); int qcow2_alloc_cluster_offset(BlockDriverState *bs, uint64_t offset, unsigned int *bytes, uint64_t *host_offset, QCowL2Meta **m); diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c index 41a23c5305..acfcf8ea4c 100644 --- a/block/qcow2-cluster.c +++ b/block/qcow2-cluster.c @@ -514,13 +514,14 @@ static int coroutine_fn do_perform_cow_write(BlockDri= verState *bs, * * On exit, *bytes is the number of bytes starting at offset that have the= same * cluster type and (if applicable) are stored contiguously in the image f= ile. + * The cluster type is stored in *cluster_type. * Compressed clusters are always returned one by one. * - * Returns the cluster type (QCOW2_CLUSTER_*) on success, -errno in error - * cases. + * Returns 0 on success, -errno in error cases. */ int qcow2_get_host_offset(BlockDriverState *bs, uint64_t offset, - unsigned int *bytes, uint64_t *host_offset) + unsigned int *bytes, uint64_t *host_offset, + QCow2ClusterType *cluster_type) { BDRVQcow2State *s =3D bs->opaque; unsigned int l2_index; @@ -663,7 +664,9 @@ out: assert(bytes_available - offset_in_cluster <=3D UINT_MAX); *bytes =3D bytes_available - offset_in_cluster; =20 - return type; + *cluster_type =3D type; + + return 0; =20 fail: qcow2_cache_put(s->l2_table_cache, (void **)&l2_slice); diff --git a/block/qcow2.c b/block/qcow2.c index d3b8581aed..48e188152c 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -1971,6 +1971,7 @@ static int coroutine_fn qcow2_co_block_status(BlockDr= iverState *bs, BDRVQcow2State *s =3D bs->opaque; uint64_t host_offset; unsigned int bytes; + QCow2ClusterType type; int ret, status =3D 0; =20 qemu_co_mutex_lock(&s->lock); @@ -1982,7 +1983,7 @@ static int coroutine_fn qcow2_co_block_status(BlockDr= iverState *bs, } =20 bytes =3D MIN(INT_MAX, count); - ret =3D qcow2_get_host_offset(bs, offset, &bytes, &host_offset); + ret =3D qcow2_get_host_offset(bs, offset, &bytes, &host_offset, &type); qemu_co_mutex_unlock(&s->lock); if (ret < 0) { return ret; @@ -1990,15 +1991,15 @@ static int coroutine_fn qcow2_co_block_status(Block= DriverState *bs, =20 *pnum =3D bytes; =20 - if ((ret =3D=3D QCOW2_CLUSTER_NORMAL || ret =3D=3D QCOW2_CLUSTER_ZERO_= ALLOC) && + if ((type =3D=3D QCOW2_CLUSTER_NORMAL || type =3D=3D QCOW2_CLUSTER_ZER= O_ALLOC) && !s->crypto) { *map =3D host_offset; *file =3D s->data_file->bs; status |=3D BDRV_BLOCK_OFFSET_VALID; } - if (ret =3D=3D QCOW2_CLUSTER_ZERO_PLAIN || ret =3D=3D QCOW2_CLUSTER_ZE= RO_ALLOC) { + if (type =3D=3D QCOW2_CLUSTER_ZERO_PLAIN || type =3D=3D QCOW2_CLUSTER_= ZERO_ALLOC) { status |=3D BDRV_BLOCK_ZERO; - } else if (ret !=3D QCOW2_CLUSTER_UNALLOCATED) { + } else if (type !=3D QCOW2_CLUSTER_UNALLOCATED) { status |=3D BDRV_BLOCK_DATA; } if (s->metadata_preallocation && (status & BDRV_BLOCK_DATA) && @@ -2207,6 +2208,7 @@ static coroutine_fn int qcow2_co_preadv_part(BlockDri= verState *bs, int ret =3D 0; unsigned int cur_bytes; /* number of bytes in current iteration */ uint64_t host_offset =3D 0; + QCow2ClusterType type; AioTaskPool *aio =3D NULL; =20 while (bytes !=3D 0 && aio_task_pool_status(aio) =3D=3D 0) { @@ -2218,22 +2220,23 @@ static coroutine_fn int qcow2_co_preadv_part(BlockD= riverState *bs, } =20 qemu_co_mutex_lock(&s->lock); - ret =3D qcow2_get_host_offset(bs, offset, &cur_bytes, &host_offset= ); + ret =3D qcow2_get_host_offset(bs, offset, &cur_bytes, + &host_offset, &type); qemu_co_mutex_unlock(&s->lock); if (ret < 0) { goto out; } =20 - if (ret =3D=3D QCOW2_CLUSTER_ZERO_PLAIN || - ret =3D=3D QCOW2_CLUSTER_ZERO_ALLOC || - (ret =3D=3D QCOW2_CLUSTER_UNALLOCATED && !bs->backing)) + if (type =3D=3D QCOW2_CLUSTER_ZERO_PLAIN || + type =3D=3D QCOW2_CLUSTER_ZERO_ALLOC || + (type =3D=3D QCOW2_CLUSTER_UNALLOCATED && !bs->backing)) { qemu_iovec_memset(qiov, qiov_offset, 0, cur_bytes); } else { if (!aio && cur_bytes !=3D bytes) { aio =3D aio_task_pool_new(QCOW2_MAX_WORKERS); } - ret =3D qcow2_add_task(bs, aio, qcow2_co_preadv_task_entry, re= t, + ret =3D qcow2_add_task(bs, aio, qcow2_co_preadv_task_entry, ty= pe, host_offset, offset, cur_bytes, qiov, qiov_offset, NULL); if (ret < 0) { @@ -3716,6 +3719,7 @@ static coroutine_fn int qcow2_co_pwrite_zeroes(BlockD= riverState *bs, if (head || tail) { uint64_t off; unsigned int nr; + QCow2ClusterType type; =20 assert(head + bytes <=3D s->cluster_size); =20 @@ -3731,10 +3735,11 @@ static coroutine_fn int qcow2_co_pwrite_zeroes(Bloc= kDriverState *bs, offset =3D QEMU_ALIGN_DOWN(offset, s->cluster_size); bytes =3D s->cluster_size; nr =3D s->cluster_size; - ret =3D qcow2_get_host_offset(bs, offset, &nr, &off); - if (ret !=3D QCOW2_CLUSTER_UNALLOCATED && - ret !=3D QCOW2_CLUSTER_ZERO_PLAIN && - ret !=3D QCOW2_CLUSTER_ZERO_ALLOC) { + ret =3D qcow2_get_host_offset(bs, offset, &nr, &off, &type); + if (ret < 0 || + (type !=3D QCOW2_CLUSTER_UNALLOCATED && + type !=3D QCOW2_CLUSTER_ZERO_PLAIN && + type !=3D QCOW2_CLUSTER_ZERO_ALLOC)) { qemu_co_mutex_unlock(&s->lock); return -ENOTSUP; } @@ -3792,16 +3797,18 @@ qcow2_co_copy_range_from(BlockDriverState *bs, =20 while (bytes !=3D 0) { uint64_t copy_offset =3D 0; + QCow2ClusterType type; /* prepare next request */ cur_bytes =3D MIN(bytes, INT_MAX); cur_write_flags =3D write_flags; =20 - ret =3D qcow2_get_host_offset(bs, src_offset, &cur_bytes, ©_of= fset); + ret =3D qcow2_get_host_offset(bs, src_offset, &cur_bytes, + ©_offset, &type); if (ret < 0) { goto out; } =20 - switch (ret) { + switch (type) { case QCOW2_CLUSTER_UNALLOCATED: if (bs->backing && bs->backing->bs) { int64_t backing_length =3D bdrv_getlength(bs->backing->bs); --=20 2.20.1 From nobody Tue May 7 09:01:18 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1584469297; cv=none; d=zohomail.com; s=zohoarc; b=g9TiO2zyOPNrSi/D9pGWv6CVvOwm+hq8oYPPe1Tc01ntW6VeSp0uPT0pTg7xFhxKPncDQ1mszF+5/e6RrkHm4hz9m8Vy3sHM9R188G8NlVf7tdzqYAzwUFZU+x43aTDOcRzl5bnL37bLO3RCemTSwLG8jbmrruaO3pcHSpD/9iE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1584469297; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=wvlhvR/WHqHAGsuHWv9RBqJIQK3AknXCaH3EJegJnr8=; b=CIzXvYUwSF9sk0YdGq2ZxJ586OJSnC6jZt+U9/SRm/K6CQqzk8D1ifs4+b7L3JxcoC6fxATzJlPk4W8Ap+Y0QGzeLGFxHtpz/K9BlRWMY1wZr7yUgslsUTc//yD3jX8DMytthQliAAq/h7JWU1348OGwa4e4GUK7uQpFs2jDWFI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1584469297634594.3593799480911; Tue, 17 Mar 2020 11:21:37 -0700 (PDT) Received: from localhost ([::1]:38990 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEGqO-0008QV-Aw for importer@patchew.org; Tue, 17 Mar 2020 14:21:36 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48373) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEGmc-0002pC-MI for qemu-devel@nongnu.org; Tue, 17 Mar 2020 14:17:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jEGmZ-0007VX-28 for qemu-devel@nongnu.org; Tue, 17 Mar 2020 14:17:42 -0400 Received: from fanzine.igalia.com ([178.60.130.6]:57707) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jEGmX-0005Ur-Ab; Tue, 17 Mar 2020 14:17:38 -0400 Received: from [81.0.35.138] (helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1jEGmD-00015N-0i; Tue, 17 Mar 2020 19:17:17 +0100 Received: from berto by perseus.local with local (Exim 4.92) (envelope-from ) id 1jEGlw-0006OX-I0; Tue, 17 Mar 2020 19:17:00 +0100 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=wvlhvR/WHqHAGsuHWv9RBqJIQK3AknXCaH3EJegJnr8=; b=kkV/vc3XO3Vz4h9SYEE1YCWl9IWPB80pl6Pe8ZGqaQu/YL+MNyG3ATedOSkbQ8MvWCPsrkVD+fRi3m+EiNAKbbrofMMnvx0nIsBxmGd0L3ErlNSb6rHCatqh3L1gHhhtvF+qNcJJ3AIpBE6rwqqcpUGLlasLWB9+DVJj84p+1TOdwmpcEpFmoejbtiDczymtkd7KXy6CBSokHZGi7xdIKDu5aVatmcFm6LD5AskN9wpXg/TyONzbvUcedvE1yeg1nJp+u1ncl58Tn0fJ1DNVyGfjVJbuzMNNHsBTqopBdxrcMCgvaopqdeFKyituQXfHjj426HbgOUhdgsP9SeB6cQ==; From: Alberto Garcia To: qemu-devel@nongnu.org Subject: [PATCH v4 15/30] qcow2: Replace QCOW2_CLUSTER_* with QCOW2_SUBCLUSTER_* Date: Tue, 17 Mar 2020 19:16:12 +0100 Message-Id: <8e28c82079d24482fce8e9422dc45503a0401b9b.1584468723.git.berto@igalia.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy] X-Received-From: 178.60.130.6 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Anton Nefedov , Alberto Garcia , qemu-block@nongnu.org, Max Reitz , Vladimir Sementsov-Ogievskiy , "Denis V . Lunev" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" In order to support extended L2 entries some functions of the qcow2 driver need to start dealing with subclusters instead of clusters. qcow2_get_host_offset() is modified to return the subcluster type instead of the cluster type, and all callers are updated to replace all values of QCow2ClusterType with their QCow2SubclusterType equivalents. This patch only changes the data types, there are no semantic changes. Signed-off-by: Alberto Garcia Reviewed-by: Max Reitz Reviewed-by: Vladimir Sementsov-Ogievskiy --- block/qcow2.h | 2 +- block/qcow2-cluster.c | 10 +++---- block/qcow2.c | 70 ++++++++++++++++++++++--------------------- 3 files changed, 42 insertions(+), 40 deletions(-) diff --git a/block/qcow2.h b/block/qcow2.h index 6b7b286b91..e6fbb7d987 100644 --- a/block/qcow2.h +++ b/block/qcow2.h @@ -860,7 +860,7 @@ int qcow2_encrypt_sectors(BDRVQcow2State *s, int64_t se= ctor_num, =20 int qcow2_get_host_offset(BlockDriverState *bs, uint64_t offset, unsigned int *bytes, uint64_t *host_offset, - QCow2ClusterType *cluster_type); + QCow2SubclusterType *subcluster_type); int qcow2_alloc_cluster_offset(BlockDriverState *bs, uint64_t offset, unsigned int *bytes, uint64_t *host_offset, QCowL2Meta **m); diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c index acfcf8ea4c..8cdf8a23b6 100644 --- a/block/qcow2-cluster.c +++ b/block/qcow2-cluster.c @@ -513,15 +513,15 @@ static int coroutine_fn do_perform_cow_write(BlockDri= verState *bs, * offset that we are interested in. * * On exit, *bytes is the number of bytes starting at offset that have the= same - * cluster type and (if applicable) are stored contiguously in the image f= ile. - * The cluster type is stored in *cluster_type. - * Compressed clusters are always returned one by one. + * subcluster type and (if applicable) are stored contiguously in the image + * file. The subcluster type is stored in *subcluster_type. + * Compressed clusters are always processed one by one. * * Returns 0 on success, -errno in error cases. */ int qcow2_get_host_offset(BlockDriverState *bs, uint64_t offset, unsigned int *bytes, uint64_t *host_offset, - QCow2ClusterType *cluster_type) + QCow2SubclusterType *subcluster_type) { BDRVQcow2State *s =3D bs->opaque; unsigned int l2_index; @@ -664,7 +664,7 @@ out: assert(bytes_available - offset_in_cluster <=3D UINT_MAX); *bytes =3D bytes_available - offset_in_cluster; =20 - *cluster_type =3D type; + *subcluster_type =3D qcow2_cluster_to_subcluster_type(type); =20 return 0; =20 diff --git a/block/qcow2.c b/block/qcow2.c index 48e188152c..f8788d6305 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -1971,7 +1971,7 @@ static int coroutine_fn qcow2_co_block_status(BlockDr= iverState *bs, BDRVQcow2State *s =3D bs->opaque; uint64_t host_offset; unsigned int bytes; - QCow2ClusterType type; + QCow2SubclusterType type; int ret, status =3D 0; =20 qemu_co_mutex_lock(&s->lock); @@ -1991,15 +1991,16 @@ static int coroutine_fn qcow2_co_block_status(Block= DriverState *bs, =20 *pnum =3D bytes; =20 - if ((type =3D=3D QCOW2_CLUSTER_NORMAL || type =3D=3D QCOW2_CLUSTER_ZER= O_ALLOC) && - !s->crypto) { + if ((type =3D=3D QCOW2_SUBCLUSTER_NORMAL || + type =3D=3D QCOW2_SUBCLUSTER_ZERO_ALLOC) && !s->crypto) { *map =3D host_offset; *file =3D s->data_file->bs; status |=3D BDRV_BLOCK_OFFSET_VALID; } - if (type =3D=3D QCOW2_CLUSTER_ZERO_PLAIN || type =3D=3D QCOW2_CLUSTER_= ZERO_ALLOC) { + if (type =3D=3D QCOW2_SUBCLUSTER_ZERO_PLAIN || + type =3D=3D QCOW2_SUBCLUSTER_ZERO_ALLOC) { status |=3D BDRV_BLOCK_ZERO; - } else if (type !=3D QCOW2_CLUSTER_UNALLOCATED) { + } else if (type !=3D QCOW2_SUBCLUSTER_UNALLOCATED_PLAIN) { status |=3D BDRV_BLOCK_DATA; } if (s->metadata_preallocation && (status & BDRV_BLOCK_DATA) && @@ -2096,7 +2097,7 @@ typedef struct Qcow2AioTask { AioTask task; =20 BlockDriverState *bs; - QCow2ClusterType cluster_type; /* only for read */ + QCow2SubclusterType subcluster_type; /* only for read */ uint64_t host_offset; /* or full descriptor in compressed clusters */ uint64_t offset; uint64_t bytes; @@ -2109,7 +2110,7 @@ static coroutine_fn int qcow2_co_preadv_task_entry(Ai= oTask *task); static coroutine_fn int qcow2_add_task(BlockDriverState *bs, AioTaskPool *pool, AioTaskFunc func, - QCow2ClusterType cluster_type, + QCow2SubclusterType subcluster_type, uint64_t host_offset, uint64_t offset, uint64_t bytes, @@ -2123,7 +2124,7 @@ static coroutine_fn int qcow2_add_task(BlockDriverSta= te *bs, *task =3D (Qcow2AioTask) { .task.func =3D func, .bs =3D bs, - .cluster_type =3D cluster_type, + .subcluster_type =3D subcluster_type, .qiov =3D qiov, .host_offset =3D host_offset, .offset =3D offset, @@ -2134,7 +2135,7 @@ static coroutine_fn int qcow2_add_task(BlockDriverSta= te *bs, =20 trace_qcow2_add_task(qemu_coroutine_self(), bs, pool, func =3D=3D qcow2_co_preadv_task_entry ? "read" := "write", - cluster_type, host_offset, offset, bytes, + subcluster_type, host_offset, offset, bytes, qiov, qiov_offset); =20 if (!pool) { @@ -2147,7 +2148,7 @@ static coroutine_fn int qcow2_add_task(BlockDriverSta= te *bs, } =20 static coroutine_fn int qcow2_co_preadv_task(BlockDriverState *bs, - QCow2ClusterType cluster_type, + QCow2SubclusterType subc_type, uint64_t host_offset, uint64_t offset, uint64_t byt= es, QEMUIOVector *qiov, @@ -2155,24 +2156,24 @@ static coroutine_fn int qcow2_co_preadv_task(BlockD= riverState *bs, { BDRVQcow2State *s =3D bs->opaque; =20 - switch (cluster_type) { - case QCOW2_CLUSTER_ZERO_PLAIN: - case QCOW2_CLUSTER_ZERO_ALLOC: + switch (subc_type) { + case QCOW2_SUBCLUSTER_ZERO_PLAIN: + case QCOW2_SUBCLUSTER_ZERO_ALLOC: /* Both zero types are handled in qcow2_co_preadv_part */ g_assert_not_reached(); =20 - case QCOW2_CLUSTER_UNALLOCATED: + case QCOW2_SUBCLUSTER_UNALLOCATED_PLAIN: assert(bs->backing); /* otherwise handled in qcow2_co_preadv_part = */ =20 BLKDBG_EVENT(bs->file, BLKDBG_READ_BACKING_AIO); return bdrv_co_preadv_part(bs->backing, offset, bytes, qiov, qiov_offset, 0); =20 - case QCOW2_CLUSTER_COMPRESSED: + case QCOW2_SUBCLUSTER_COMPRESSED: return qcow2_co_preadv_compressed(bs, host_offset, offset, bytes, qiov, qiov_offset= ); =20 - case QCOW2_CLUSTER_NORMAL: + case QCOW2_SUBCLUSTER_NORMAL: if (bs->encrypted) { return qcow2_co_preadv_encrypted(bs, host_offset, offset, bytes, qiov, qiov_off= set); @@ -2195,8 +2196,9 @@ static coroutine_fn int qcow2_co_preadv_task_entry(Ai= oTask *task) =20 assert(!t->l2meta); =20 - return qcow2_co_preadv_task(t->bs, t->cluster_type, t->host_offset, - t->offset, t->bytes, t->qiov, t->qiov_offs= et); + return qcow2_co_preadv_task(t->bs, t->subcluster_type, + t->host_offset, t->offset, t->bytes, + t->qiov, t->qiov_offset); } =20 static coroutine_fn int qcow2_co_preadv_part(BlockDriverState *bs, @@ -2208,7 +2210,7 @@ static coroutine_fn int qcow2_co_preadv_part(BlockDri= verState *bs, int ret =3D 0; unsigned int cur_bytes; /* number of bytes in current iteration */ uint64_t host_offset =3D 0; - QCow2ClusterType type; + QCow2SubclusterType type; AioTaskPool *aio =3D NULL; =20 while (bytes !=3D 0 && aio_task_pool_status(aio) =3D=3D 0) { @@ -2227,9 +2229,9 @@ static coroutine_fn int qcow2_co_preadv_part(BlockDri= verState *bs, goto out; } =20 - if (type =3D=3D QCOW2_CLUSTER_ZERO_PLAIN || - type =3D=3D QCOW2_CLUSTER_ZERO_ALLOC || - (type =3D=3D QCOW2_CLUSTER_UNALLOCATED && !bs->backing)) + if (type =3D=3D QCOW2_SUBCLUSTER_ZERO_PLAIN || + type =3D=3D QCOW2_SUBCLUSTER_ZERO_ALLOC || + (type =3D=3D QCOW2_SUBCLUSTER_UNALLOCATED_PLAIN && !bs->backin= g)) { qemu_iovec_memset(qiov, qiov_offset, 0, cur_bytes); } else { @@ -2463,7 +2465,7 @@ static coroutine_fn int qcow2_co_pwritev_task_entry(A= ioTask *task) { Qcow2AioTask *t =3D container_of(task, Qcow2AioTask, task); =20 - assert(!t->cluster_type); + assert(!t->subcluster_type); =20 return qcow2_co_pwritev_task(t->bs, t->host_offset, t->offset, t->bytes, t->qiov, t->qiov_off= set, @@ -3719,7 +3721,7 @@ static coroutine_fn int qcow2_co_pwrite_zeroes(BlockD= riverState *bs, if (head || tail) { uint64_t off; unsigned int nr; - QCow2ClusterType type; + QCow2SubclusterType type; =20 assert(head + bytes <=3D s->cluster_size); =20 @@ -3737,9 +3739,9 @@ static coroutine_fn int qcow2_co_pwrite_zeroes(BlockD= riverState *bs, nr =3D s->cluster_size; ret =3D qcow2_get_host_offset(bs, offset, &nr, &off, &type); if (ret < 0 || - (type !=3D QCOW2_CLUSTER_UNALLOCATED && - type !=3D QCOW2_CLUSTER_ZERO_PLAIN && - type !=3D QCOW2_CLUSTER_ZERO_ALLOC)) { + (type !=3D QCOW2_SUBCLUSTER_UNALLOCATED_PLAIN && + type !=3D QCOW2_SUBCLUSTER_ZERO_PLAIN && + type !=3D QCOW2_SUBCLUSTER_ZERO_ALLOC)) { qemu_co_mutex_unlock(&s->lock); return -ENOTSUP; } @@ -3797,7 +3799,7 @@ qcow2_co_copy_range_from(BlockDriverState *bs, =20 while (bytes !=3D 0) { uint64_t copy_offset =3D 0; - QCow2ClusterType type; + QCow2SubclusterType type; /* prepare next request */ cur_bytes =3D MIN(bytes, INT_MAX); cur_write_flags =3D write_flags; @@ -3809,7 +3811,7 @@ qcow2_co_copy_range_from(BlockDriverState *bs, } =20 switch (type) { - case QCOW2_CLUSTER_UNALLOCATED: + case QCOW2_SUBCLUSTER_UNALLOCATED_PLAIN: if (bs->backing && bs->backing->bs) { int64_t backing_length =3D bdrv_getlength(bs->backing->bs); if (src_offset >=3D backing_length) { @@ -3824,16 +3826,16 @@ qcow2_co_copy_range_from(BlockDriverState *bs, } break; =20 - case QCOW2_CLUSTER_ZERO_PLAIN: - case QCOW2_CLUSTER_ZERO_ALLOC: + case QCOW2_SUBCLUSTER_ZERO_PLAIN: + case QCOW2_SUBCLUSTER_ZERO_ALLOC: cur_write_flags |=3D BDRV_REQ_ZERO_WRITE; break; =20 - case QCOW2_CLUSTER_COMPRESSED: + case QCOW2_SUBCLUSTER_COMPRESSED: ret =3D -ENOTSUP; goto out; =20 - case QCOW2_CLUSTER_NORMAL: + case QCOW2_SUBCLUSTER_NORMAL: child =3D s->data_file; break; =20 @@ -4289,7 +4291,7 @@ static coroutine_fn int qcow2_co_pwritev_compressed_t= ask_entry(AioTask *task) { Qcow2AioTask *t =3D container_of(task, Qcow2AioTask, task); =20 - assert(!t->cluster_type && !t->l2meta); + assert(!t->subcluster_type && !t->l2meta); =20 return qcow2_co_pwritev_compressed_task(t->bs, t->offset, t->bytes, t-= >qiov, t->qiov_offset); --=20 2.20.1 From nobody Tue May 7 09:01:18 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1584469297; cv=none; d=zohomail.com; s=zohoarc; b=XnuP6HqjJtT0qGg47PTwioPunrntIRBJTeo3wRFbHUvp9+lE50407/KLf/BjUlt/z56DtCkW0yA80hy93J4Gem1PCmmyWnzGWXEjtdYUB/I73I0is60hi7aosXZFJTvXnVZHhknSyiSkV10aX68RABTugG+ela16JPy3glgqt5Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1584469297; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=jOIbxftiwi29Ma/CLOJsLFbSYwwFwEOm5EzACtLvpZQ=; b=Ah/hPUh2ezM4/Vv1t5y+g21odSS5rpoInr9J5uvf7YU+IWyHoajVRWaZm5RWZXR287OC1NFTIjBR3ICCtISkSSmZ/t+E1JaNbSZORZzmxr4ty9Rxte1BBk998WqsIk8CL5lYcRYcXe1lFVrLKfEBTGpVwk7Iv2e9O8++2qYO7dE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1584469297599250.8110585920498; Tue, 17 Mar 2020 11:21:37 -0700 (PDT) Received: from localhost ([::1]:38988 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEGqO-0008QL-Gd for importer@patchew.org; Tue, 17 Mar 2020 14:21:36 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48311) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEGma-0002oF-W7 for qemu-devel@nongnu.org; Tue, 17 Mar 2020 14:17:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jEGmZ-0007VK-1O for qemu-devel@nongnu.org; Tue, 17 Mar 2020 14:17:40 -0400 Received: from fanzine.igalia.com ([178.60.130.6]:57767) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jEGmX-0005Yd-Ap; Tue, 17 Mar 2020 14:17:38 -0400 Received: from [81.0.35.138] (helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1jEGmD-00014q-33; Tue, 17 Mar 2020 19:17:17 +0100 Received: from berto by perseus.local with local (Exim 4.92) (envelope-from ) id 1jEGlw-0006OZ-J9; Tue, 17 Mar 2020 19:17:00 +0100 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=jOIbxftiwi29Ma/CLOJsLFbSYwwFwEOm5EzACtLvpZQ=; b=dKHnLWYDw6smhGytUfXVQJ/TSGK4ZxJiv2MmDAhdVC6KeZeVlzEjhgyke0H1goeP9hNYk4Eyu3zddLjQ4m/VzwVSE9xGxuIjsqhxmfeYKhXDCi+Cn2e2AJVHVFbxMsfsPY4neQ9Wq6mtdRDLwx+3FV3BhfSRnN/6v6GJYzNhI+lcOUdnni3mSTKc5e8t2IxHB3jAHjea8Qf9LxyV/4XQyVXL6esPSsRKmi+cnulJL3sNGOPiZBibpe7t3uzU5zlw0Pf6guRd+XaZ7e9beK5Hmr4W+9AThUt7wTgR2Sm6tez2v/BlXLuAOzDI9g5hAUpHYbg7mMnRmkcErGAc5Vc8lQ==; From: Alberto Garcia To: qemu-devel@nongnu.org Subject: [PATCH v4 16/30] qcow2: Handle QCOW2_SUBCLUSTER_UNALLOCATED_ALLOC Date: Tue, 17 Mar 2020 19:16:13 +0100 Message-Id: <8d7d7287935141177c6a6f92196acc638ea5225b.1584468723.git.berto@igalia.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy] X-Received-From: 178.60.130.6 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Anton Nefedov , Alberto Garcia , qemu-block@nongnu.org, Max Reitz , Vladimir Sementsov-Ogievskiy , "Denis V . Lunev" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" When dealing with subcluster types there is a new value called QCOW2_SUBCLUSTER_UNALLOCATED_ALLOC that has no equivalent in QCow2ClusterType. This patch handles that value in all places where subcluster types are processed. Signed-off-by: Alberto Garcia Reviewed-by: Max Reitz Reviewed-by: Vladimir Sementsov-Ogievskiy --- block/qcow2.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/block/qcow2.c b/block/qcow2.c index f8788d6305..88daaf11a0 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -1992,7 +1992,8 @@ static int coroutine_fn qcow2_co_block_status(BlockDr= iverState *bs, *pnum =3D bytes; =20 if ((type =3D=3D QCOW2_SUBCLUSTER_NORMAL || - type =3D=3D QCOW2_SUBCLUSTER_ZERO_ALLOC) && !s->crypto) { + type =3D=3D QCOW2_SUBCLUSTER_ZERO_ALLOC || + type =3D=3D QCOW2_SUBCLUSTER_UNALLOCATED_ALLOC) && !s->crypto) { *map =3D host_offset; *file =3D s->data_file->bs; status |=3D BDRV_BLOCK_OFFSET_VALID; @@ -2000,7 +2001,8 @@ static int coroutine_fn qcow2_co_block_status(BlockDr= iverState *bs, if (type =3D=3D QCOW2_SUBCLUSTER_ZERO_PLAIN || type =3D=3D QCOW2_SUBCLUSTER_ZERO_ALLOC) { status |=3D BDRV_BLOCK_ZERO; - } else if (type !=3D QCOW2_SUBCLUSTER_UNALLOCATED_PLAIN) { + } else if (type !=3D QCOW2_SUBCLUSTER_UNALLOCATED_PLAIN && + type !=3D QCOW2_SUBCLUSTER_UNALLOCATED_ALLOC) { status |=3D BDRV_BLOCK_DATA; } if (s->metadata_preallocation && (status & BDRV_BLOCK_DATA) && @@ -2163,6 +2165,7 @@ static coroutine_fn int qcow2_co_preadv_task(BlockDri= verState *bs, g_assert_not_reached(); =20 case QCOW2_SUBCLUSTER_UNALLOCATED_PLAIN: + case QCOW2_SUBCLUSTER_UNALLOCATED_ALLOC: assert(bs->backing); /* otherwise handled in qcow2_co_preadv_part = */ =20 BLKDBG_EVENT(bs->file, BLKDBG_READ_BACKING_AIO); @@ -2231,7 +2234,8 @@ static coroutine_fn int qcow2_co_preadv_part(BlockDri= verState *bs, =20 if (type =3D=3D QCOW2_SUBCLUSTER_ZERO_PLAIN || type =3D=3D QCOW2_SUBCLUSTER_ZERO_ALLOC || - (type =3D=3D QCOW2_SUBCLUSTER_UNALLOCATED_PLAIN && !bs->backin= g)) + (type =3D=3D QCOW2_SUBCLUSTER_UNALLOCATED_PLAIN && !bs->backin= g) || + (type =3D=3D QCOW2_SUBCLUSTER_UNALLOCATED_ALLOC && !bs->backin= g)) { qemu_iovec_memset(qiov, qiov_offset, 0, cur_bytes); } else { @@ -3740,6 +3744,7 @@ static coroutine_fn int qcow2_co_pwrite_zeroes(BlockD= riverState *bs, ret =3D qcow2_get_host_offset(bs, offset, &nr, &off, &type); if (ret < 0 || (type !=3D QCOW2_SUBCLUSTER_UNALLOCATED_PLAIN && + type !=3D QCOW2_SUBCLUSTER_UNALLOCATED_ALLOC && type !=3D QCOW2_SUBCLUSTER_ZERO_PLAIN && type !=3D QCOW2_SUBCLUSTER_ZERO_ALLOC)) { qemu_co_mutex_unlock(&s->lock); @@ -3812,6 +3817,7 @@ qcow2_co_copy_range_from(BlockDriverState *bs, =20 switch (type) { case QCOW2_SUBCLUSTER_UNALLOCATED_PLAIN: + case QCOW2_SUBCLUSTER_UNALLOCATED_ALLOC: if (bs->backing && bs->backing->bs) { int64_t backing_length =3D bdrv_getlength(bs->backing->bs); if (src_offset >=3D backing_length) { --=20 2.20.1 From nobody Tue May 7 09:01:18 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1584470440; cv=none; d=zohomail.com; s=zohoarc; b=OU0tAexHytiG+DtGkGxNicvbMC1YpDrFvPdS2+su/fA+l2OLGvNAxvhsQIuduK3NSGZXh+Vg4uOdCTBm5kn0My00JKj2UoG3x6pYGDqBlII+vlZ6J7axlZ8GMEg249QaF4Z3EuRCkKNhPSB/xYllStF8FTrL4d6Y7SjxMnMOccU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1584470440; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=snU5YlWGDhrk8dD7MLwe4YRhknZ6d9pa8+zu7OhWw2g=; b=ciDTUkqHMMcX6ft9WT6XG/H0iRXeo/lE9YMIP8YOznW7M9M4qg4Dppczq4fk5yU2fBOKPPdLWDIcuLQykpX78WtKhFyLQskkXQaRq0K4sf7UXpuvb2R9o4SuKJKCQai6aexSNCAnjo/uosTQbwq9/PiVjl6ow9Zo0sb0v6QrU1k= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1584470440232491.7889420980091; Tue, 17 Mar 2020 11:40:40 -0700 (PDT) Received: from localhost ([::1]:39600 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEH8p-0003jA-13 for importer@patchew.org; Tue, 17 Mar 2020 14:40:39 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48957) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEGn0-0003at-BD for qemu-devel@nongnu.org; Tue, 17 Mar 2020 14:18:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jEGmv-00009D-7B for qemu-devel@nongnu.org; Tue, 17 Mar 2020 14:18:06 -0400 Received: from fanzine.igalia.com ([178.60.130.6]:58055) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jEGmu-000650-9O; Tue, 17 Mar 2020 14:18:01 -0400 Received: from [81.0.35.138] (helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1jEGmD-000153-30; Tue, 17 Mar 2020 19:17:17 +0100 Received: from berto by perseus.local with local (Exim 4.92) (envelope-from ) id 1jEGlw-0006Ob-KF; Tue, 17 Mar 2020 19:17:00 +0100 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=snU5YlWGDhrk8dD7MLwe4YRhknZ6d9pa8+zu7OhWw2g=; b=FZcmKTHssrqx+j+Urw0N1CIWV32YMVWaik4Y5G8mueB6LST4mZq/BvfIOCnBYxi25KvEObsGrIzMvDc6X6ikj5SxS174+sNV0BMPmfBwfblxerhBZSvCzbrXiKz/ph+TsEAkePLkP5dLxMT5KOVFg5vqRXj2vOIE1qqtMZLPf+fJu3Eue+/pyWWQAZtf3RhDZrWoIpZnCxNCfV2+AG9Jfu2/SFUzl7a4Uubr8ZH6iXS4AU8d4p4r8/7tsX1yPxIg9oco6LUoO5gnvPTRPlZ89CaYeWYBS1bru3AVle+bkgE+so8UaO6xmQHjRnC3YV/Bb8R4iU+SwG24fOns9nSsqA==; From: Alberto Garcia To: qemu-devel@nongnu.org Subject: [PATCH v4 17/30] qcow2: Add subcluster support to calculate_l2_meta() Date: Tue, 17 Mar 2020 19:16:14 +0100 Message-Id: <6f179204ed9ab6274a9d30b6aa9a63865a16035a.1584468723.git.berto@igalia.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy] X-Received-From: 178.60.130.6 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Anton Nefedov , Alberto Garcia , qemu-block@nongnu.org, Max Reitz , Vladimir Sementsov-Ogievskiy , "Denis V . Lunev" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" If an image has subclusters then there are more copy-on-write scenarios that we need to consider. Let's say we have a write request from the middle of subcluster #3 until the end of the cluster: - If the cluster is new, then subclusters #0 to #3 from the old cluster must be copied into the new one. - If the cluster is new but the old cluster was unallocated, then only subcluster #3 needs copy-on-write. #0 to #2 are marked as unallocated in the bitmap of the new L2 entry. - If we are overwriting an old cluster and subcluster #3 is unallocated or has the all-zeroes bit set then we need copy-on-write on subcluster #3. - If we are overwriting an old cluster and subcluster #3 was allocated then there is no need to copy-on-write. Signed-off-by: Alberto Garcia Reviewed-by: Max Reitz Reviewed-by: Vladimir Sementsov-Ogievskiy --- block/qcow2-cluster.c | 140 +++++++++++++++++++++++++++++++++--------- 1 file changed, 110 insertions(+), 30 deletions(-) diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c index 8cdf8a23b6..c6f3cc9237 100644 --- a/block/qcow2-cluster.c +++ b/block/qcow2-cluster.c @@ -1061,56 +1061,128 @@ void qcow2_alloc_cluster_abort(BlockDriverState *b= s, QCowL2Meta *m) * If @keep_old is true it means that the clusters were already * allocated and will be overwritten. If false then the clusters are * new and we have to decrease the reference count of the old ones. + * + * Returns 1 on success, -errno on failure (in order to match the + * return value of handle_copied() and handle_alloc()). */ -static void calculate_l2_meta(BlockDriverState *bs, - uint64_t host_cluster_offset, - uint64_t guest_offset, unsigned bytes, - uint64_t *l2_slice, QCowL2Meta **m, bool kee= p_old) +static int calculate_l2_meta(BlockDriverState *bs, uint64_t host_cluster_o= ffset, + uint64_t guest_offset, unsigned bytes, + uint64_t *l2_slice, QCowL2Meta **m, bool keep= _old) { BDRVQcow2State *s =3D bs->opaque; - int l2_index =3D offset_to_l2_slice_index(s, guest_offset); - uint64_t l2_entry; + int sc_index, l2_index =3D offset_to_l2_slice_index(s, guest_offset); + uint64_t l2_entry, l2_bitmap; unsigned cow_start_from, cow_end_to; unsigned cow_start_to =3D offset_into_cluster(s, guest_offset); unsigned cow_end_from =3D cow_start_to + bytes; unsigned nb_clusters =3D size_to_clusters(s, cow_end_from); QCowL2Meta *old_m =3D *m; - QCow2ClusterType type; + QCow2SubclusterType type; =20 assert(nb_clusters <=3D s->l2_slice_size - l2_index); =20 - /* Return if there's no COW (all clusters are normal and we keep them)= */ + /* Return if there's no COW (all subclusters are normal and we are + * keeping the clusters) */ if (keep_old) { + unsigned first_sc =3D cow_start_to / s->subcluster_size; + unsigned last_sc =3D (cow_end_from - 1) / s->subcluster_size; int i; - for (i =3D 0; i < nb_clusters; i++) { - l2_entry =3D get_l2_entry(s, l2_slice, l2_index + i); - if (qcow2_get_cluster_type(bs, l2_entry) !=3D QCOW2_CLUSTER_NO= RMAL) { + for (i =3D first_sc; i <=3D last_sc; i++) { + unsigned c =3D i / s->subclusters_per_cluster; + unsigned sc =3D i % s->subclusters_per_cluster; + l2_entry =3D get_l2_entry(s, l2_slice, l2_index + c); + l2_bitmap =3D get_l2_bitmap(s, l2_slice, l2_index + c); + type =3D qcow2_get_subcluster_type(bs, l2_entry, l2_bitmap, sc= ); + if (type =3D=3D QCOW2_SUBCLUSTER_INVALID) { + l2_index +=3D c; /* Point to the invalid entry */ + goto fail; + } + if (type !=3D QCOW2_SUBCLUSTER_NORMAL) { break; } } - if (i =3D=3D nb_clusters) { - return; + if (i =3D=3D last_sc + 1) { + return 1; } } =20 /* Get the L2 entry of the first cluster */ l2_entry =3D get_l2_entry(s, l2_slice, l2_index); - type =3D qcow2_get_cluster_type(bs, l2_entry); + l2_bitmap =3D get_l2_bitmap(s, l2_slice, l2_index); + sc_index =3D offset_to_sc_index(s, guest_offset); + type =3D qcow2_get_subcluster_type(bs, l2_entry, l2_bitmap, sc_index); =20 - if (type =3D=3D QCOW2_CLUSTER_NORMAL && keep_old) { - cow_start_from =3D cow_start_to; + if (type =3D=3D QCOW2_SUBCLUSTER_INVALID) { + goto fail; + } + + if (!keep_old) { + switch (type) { + case QCOW2_SUBCLUSTER_NORMAL: + case QCOW2_SUBCLUSTER_COMPRESSED: + case QCOW2_SUBCLUSTER_ZERO_ALLOC: + case QCOW2_SUBCLUSTER_UNALLOCATED_ALLOC: + cow_start_from =3D 0; + break; + case QCOW2_SUBCLUSTER_ZERO_PLAIN: + case QCOW2_SUBCLUSTER_UNALLOCATED_PLAIN: + cow_start_from =3D sc_index << s->subcluster_bits; + break; + default: + g_assert_not_reached(); + } } else { - cow_start_from =3D 0; + switch (type) { + case QCOW2_SUBCLUSTER_NORMAL: + cow_start_from =3D cow_start_to; + break; + case QCOW2_SUBCLUSTER_ZERO_ALLOC: + case QCOW2_SUBCLUSTER_UNALLOCATED_ALLOC: + cow_start_from =3D sc_index << s->subcluster_bits; + break; + default: + g_assert_not_reached(); + } } =20 /* Get the L2 entry of the last cluster */ - l2_entry =3D get_l2_entry(s, l2_slice, l2_index + nb_clusters - 1); - type =3D qcow2_get_cluster_type(bs, l2_entry); + l2_index +=3D nb_clusters - 1; + l2_entry =3D get_l2_entry(s, l2_slice, l2_index); + l2_bitmap =3D get_l2_bitmap(s, l2_slice, l2_index); + sc_index =3D offset_to_sc_index(s, guest_offset + bytes - 1); + type =3D qcow2_get_subcluster_type(bs, l2_entry, l2_bitmap, sc_index); =20 - if (type =3D=3D QCOW2_CLUSTER_NORMAL && keep_old) { - cow_end_to =3D cow_end_from; + if (type =3D=3D QCOW2_SUBCLUSTER_INVALID) { + goto fail; + } + + if (!keep_old) { + switch (type) { + case QCOW2_SUBCLUSTER_NORMAL: + case QCOW2_SUBCLUSTER_COMPRESSED: + case QCOW2_SUBCLUSTER_ZERO_ALLOC: + case QCOW2_SUBCLUSTER_UNALLOCATED_ALLOC: + cow_end_to =3D ROUND_UP(cow_end_from, s->cluster_size); + break; + case QCOW2_SUBCLUSTER_ZERO_PLAIN: + case QCOW2_SUBCLUSTER_UNALLOCATED_PLAIN: + cow_end_to =3D ROUND_UP(cow_end_from, s->subcluster_size); + break; + default: + g_assert_not_reached(); + } } else { - cow_end_to =3D ROUND_UP(cow_end_from, s->cluster_size); + switch (type) { + case QCOW2_SUBCLUSTER_NORMAL: + cow_end_to =3D cow_end_from; + break; + case QCOW2_SUBCLUSTER_ZERO_ALLOC: + case QCOW2_SUBCLUSTER_UNALLOCATED_ALLOC: + cow_end_to =3D ROUND_UP(cow_end_from, s->subcluster_size); + break; + default: + g_assert_not_reached(); + } } =20 *m =3D g_malloc0(sizeof(**m)); @@ -1135,6 +1207,18 @@ static void calculate_l2_meta(BlockDriverState *bs, =20 qemu_co_queue_init(&(*m)->dependent_requests); QLIST_INSERT_HEAD(&s->cluster_allocs, *m, next_in_flight); + +fail: + if (type =3D=3D QCOW2_SUBCLUSTER_INVALID) { + uint64_t l1_index =3D offset_to_l1_index(s, guest_offset); + uint64_t l2_offset =3D s->l1_table[l1_index] & L1E_OFFSET_MASK; + qcow2_signal_corruption(bs, true, -1, -1, "Invalid cluster entry f= ound " + " (L2 offset: %#" PRIx64 ", L2 index: %#x)= ", + l2_offset, l2_index); + return -EIO; + } + + return 1; } =20 /* @@ -1352,10 +1436,8 @@ static int handle_copied(BlockDriverState *bs, uint6= 4_t guest_offset, - offset_into_cluster(s, guest_offset)); assert(*bytes !=3D 0); =20 - calculate_l2_meta(bs, cluster_offset & L2E_OFFSET_MASK, guest_offs= et, - *bytes, l2_slice, m, true); - - ret =3D 1; + ret =3D calculate_l2_meta(bs, cluster_offset & L2E_OFFSET_MASK, + guest_offset, *bytes, l2_slice, m, true); } else { ret =3D 0; } @@ -1530,10 +1612,8 @@ static int handle_alloc(BlockDriverState *bs, uint64= _t guest_offset, *bytes =3D MIN(*bytes, nb_bytes - offset_into_cluster(s, guest_offset)= ); assert(*bytes !=3D 0); =20 - calculate_l2_meta(bs, alloc_cluster_offset, guest_offset, *bytes, l2_s= lice, - m, false); - - ret =3D 1; + ret =3D calculate_l2_meta(bs, alloc_cluster_offset, guest_offset, *byt= es, + l2_slice, m, false); =20 out: qcow2_cache_put(s->l2_table_cache, (void **) &l2_slice); --=20 2.20.1 From nobody Tue May 7 09:01:18 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1584469522; cv=none; d=zohomail.com; s=zohoarc; b=NXH6OXtywyCD+4U108xvs7+sPMEZh7yuvama166SlA4SfXREXoDcj9jSQPOChK69sVzdI8Reku2IfTBusx5oS+c16LsTR+rCpxt80OM6osLq0WIqisI35LpzSHKgOVgiaGFK41UY18zoqj6zKht7IrutrGkRNQgANzvsWnaVx5I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1584469522; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=umhirJuT5PwV/Lq2W7F/heDuTqufp2+31C4C+IUp9C4=; b=QXhi+DxH4epH+6yfhFIYXAnwIDooUPZjpT90qssyMOw3UdtQHMFlsNNG2q0uL7ChkwKgbQRfK0u/sTJEmhLg+GK1YjB2F1lotgp/n7tX09qb3/1LiHkGraS6td6kDtvdp6y4CATWBVnYJhgur3BF/GQRqdNBV88A1gS9nIlIEAE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1584469522519186.85513968489795; Tue, 17 Mar 2020 11:25:22 -0700 (PDT) Received: from localhost ([::1]:39104 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEGu1-0006Hv-85 for importer@patchew.org; Tue, 17 Mar 2020 14:25:21 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48359) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEGmc-0002p0-5c for qemu-devel@nongnu.org; Tue, 17 Mar 2020 14:17:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jEGmZ-0007Vm-2K for qemu-devel@nongnu.org; Tue, 17 Mar 2020 14:17:41 -0400 Received: from fanzine.igalia.com ([178.60.130.6]:57766) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jEGmX-0005Yg-Ae; Tue, 17 Mar 2020 14:17:38 -0400 Received: from [81.0.35.138] (helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1jEGmD-000157-2p; Tue, 17 Mar 2020 19:17:17 +0100 Received: from berto by perseus.local with local (Exim 4.92) (envelope-from ) id 1jEGlw-0006Od-L9; Tue, 17 Mar 2020 19:17:00 +0100 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=umhirJuT5PwV/Lq2W7F/heDuTqufp2+31C4C+IUp9C4=; b=SZjeyx4WBg0y34HGYWDxkQAZZLTljb5m3y8KBj1mMJwlONeRAxvd9+67vW6lcqXERl6c98URJpDNZS9tAnJ1b6BEBoQUy/280UiqVF+kW3PdB9EspJ67fHNgzl9+om8Dh7pSyKFOtUrGLs7qKDQGg/UnnzpT0iYNEv0KiELxv5TtF/J2Sulo1Ygm2O4I3OAE4q8s195AerFfUbo3gS3GBt6kDhqXmwmc2vh78wkWjfzXeqn8bgihLXCdpHEbGUcOX6b4I7BYv+JfAwlLEhlOjAVrNB9oM8eejsfcHGsEo5mZG21A6ilTHulDFhctjk4A3smpTwfg58olijX/ClaSpw==; From: Alberto Garcia To: qemu-devel@nongnu.org Subject: [PATCH v4 18/30] qcow2: Add subcluster support to qcow2_get_host_offset() Date: Tue, 17 Mar 2020 19:16:15 +0100 Message-Id: <1cc780f735044ac9138808234589d2c278c9cfbf.1584468723.git.berto@igalia.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy] X-Received-From: 178.60.130.6 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Anton Nefedov , Alberto Garcia , qemu-block@nongnu.org, Max Reitz , Vladimir Sementsov-Ogievskiy , "Denis V . Lunev" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" The logic of this function remains pretty much the same, except that it uses count_contiguous_subclusters(), which combines the logic of count_contiguous_clusters() / count_contiguous_clusters_unallocated() and checks individual subclusters. Signed-off-by: Alberto Garcia Reviewed-by: Max Reitz Reviewed-by: Vladimir Sementsov-Ogievskiy --- block/qcow2.h | 38 +++++------ block/qcow2-cluster.c | 143 +++++++++++++++++++++--------------------- 2 files changed, 85 insertions(+), 96 deletions(-) diff --git a/block/qcow2.h b/block/qcow2.h index e6fbb7d987..031ce823b3 100644 --- a/block/qcow2.h +++ b/block/qcow2.h @@ -678,29 +678,6 @@ static inline QCow2ClusterType qcow2_get_cluster_type(= BlockDriverState *bs, } } =20 -/* - * For an image without extended L2 entries, return the - * QCow2SubclusterType equivalent of a given QCow2ClusterType. - */ -static inline -QCow2SubclusterType qcow2_cluster_to_subcluster_type(QCow2ClusterType type) -{ - switch (type) { - case QCOW2_CLUSTER_COMPRESSED: - return QCOW2_SUBCLUSTER_COMPRESSED; - case QCOW2_CLUSTER_ZERO_PLAIN: - return QCOW2_SUBCLUSTER_ZERO_PLAIN; - case QCOW2_CLUSTER_ZERO_ALLOC: - return QCOW2_SUBCLUSTER_ZERO_ALLOC; - case QCOW2_CLUSTER_NORMAL: - return QCOW2_SUBCLUSTER_NORMAL; - case QCOW2_CLUSTER_UNALLOCATED: - return QCOW2_SUBCLUSTER_UNALLOCATED_PLAIN; - default: - g_assert_not_reached(); - } -} - /* * In an image without subsclusters @l2_bitmap is ignored and * @sc_index must be 0. @@ -748,7 +725,20 @@ QCow2SubclusterType qcow2_get_subcluster_type(BlockDri= verState *bs, g_assert_not_reached(); } } else { - return qcow2_cluster_to_subcluster_type(type); + switch (type) { + case QCOW2_CLUSTER_COMPRESSED: + return QCOW2_SUBCLUSTER_COMPRESSED; + case QCOW2_CLUSTER_ZERO_PLAIN: + return QCOW2_SUBCLUSTER_ZERO_PLAIN; + case QCOW2_CLUSTER_ZERO_ALLOC: + return QCOW2_SUBCLUSTER_ZERO_ALLOC; + case QCOW2_CLUSTER_NORMAL: + return QCOW2_SUBCLUSTER_NORMAL; + case QCOW2_CLUSTER_UNALLOCATED: + return QCOW2_SUBCLUSTER_UNALLOCATED_PLAIN; + default: + g_assert_not_reached(); + } } } =20 diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c index c6f3cc9237..6f2643ba53 100644 --- a/block/qcow2-cluster.c +++ b/block/qcow2-cluster.c @@ -376,66 +376,58 @@ fail: } =20 /* - * Checks how many clusters in a given L2 slice are contiguous in the image - * file. As soon as one of the flags in the bitmask stop_flags changes com= pared - * to the first cluster, the search is stopped and the cluster is not coun= ted - * as contiguous. (This allows it, for example, to stop at the first compr= essed - * cluster which may require a different handling) + * Return the number of contiguous subclusters of the exact same type + * in a given L2 slice, starting from cluster @l2_index, subcluster + * @sc_index. Allocated subclusters are required to be contiguous in + * the image file. + * At most @nb_clusters are checked (note that this means clusters, + * not subclusters). + * Compressed clusters are always processed one by one but for the + * purpose of this count they are treated as if they were divided into + * subclusters of size s->subcluster_size. */ -static int count_contiguous_clusters(BlockDriverState *bs, int nb_clusters, - int cluster_size, uint64_t *l2_slice, int l2_index, uint64_t stop_= flags) +static int count_contiguous_subclusters(BlockDriverState *bs, int nb_clust= ers, + unsigned sc_index, uint64_t *l2_sl= ice, + int l2_index) { BDRVQcow2State *s =3D bs->opaque; - int i; - QCow2ClusterType first_cluster_type; - uint64_t mask =3D stop_flags | L2E_OFFSET_MASK | QCOW_OFLAG_COMPRESSED; - uint64_t first_entry =3D get_l2_entry(s, l2_slice, l2_index); - uint64_t offset =3D first_entry & mask; - - first_cluster_type =3D qcow2_get_cluster_type(bs, first_entry); - if (first_cluster_type =3D=3D QCOW2_CLUSTER_UNALLOCATED) { - return 0; + int i, j, count =3D 0; + uint64_t l2_entry =3D get_l2_entry(s, l2_slice, l2_index); + uint64_t l2_bitmap =3D get_l2_bitmap(s, l2_slice, l2_index); + uint64_t expected_offset =3D l2_entry & L2E_OFFSET_MASK; + bool check_offset =3D true; + QCow2SubclusterType type =3D + qcow2_get_subcluster_type(bs, l2_entry, l2_bitmap, sc_index); + + assert(type !=3D QCOW2_SUBCLUSTER_INVALID); /* The caller should check= this */ + + if (type =3D=3D QCOW2_SUBCLUSTER_COMPRESSED) { + /* Compressed clusters are always processed one by one */ + return s->subclusters_per_cluster - sc_index; } =20 - /* must be allocated */ - assert(first_cluster_type =3D=3D QCOW2_CLUSTER_NORMAL || - first_cluster_type =3D=3D QCOW2_CLUSTER_ZERO_ALLOC); - - for (i =3D 0; i < nb_clusters; i++) { - uint64_t l2_entry =3D get_l2_entry(s, l2_slice, l2_index + i) & ma= sk; - if (offset + (uint64_t) i * cluster_size !=3D l2_entry) { - break; - } + if (type =3D=3D QCOW2_SUBCLUSTER_UNALLOCATED_PLAIN || + type =3D=3D QCOW2_SUBCLUSTER_ZERO_PLAIN) { + check_offset =3D false; } =20 - return i; -} - -/* - * Checks how many consecutive unallocated clusters in a given L2 - * slice have the same cluster type. - */ -static int count_contiguous_clusters_unallocated(BlockDriverState *bs, - int nb_clusters, - uint64_t *l2_slice, - int l2_index, - QCow2ClusterType wanted_t= ype) -{ - BDRVQcow2State *s =3D bs->opaque; - int i; - - assert(wanted_type =3D=3D QCOW2_CLUSTER_ZERO_PLAIN || - wanted_type =3D=3D QCOW2_CLUSTER_UNALLOCATED); for (i =3D 0; i < nb_clusters; i++) { - uint64_t entry =3D get_l2_entry(s, l2_slice, l2_index + i); - QCow2ClusterType type =3D qcow2_get_cluster_type(bs, entry); - - if (type !=3D wanted_type) { - break; + l2_entry =3D get_l2_entry(s, l2_slice, l2_index + i); + l2_bitmap =3D get_l2_bitmap(s, l2_slice, l2_index + i); + if (check_offset && expected_offset !=3D (l2_entry & L2E_OFFSET_MA= SK)) { + goto out; + } + for (j =3D (i =3D=3D 0) ? sc_index : 0; j < s->subclusters_per_clu= ster; j++) { + if (qcow2_get_subcluster_type(bs, l2_entry, l2_bitmap, j) !=3D= type) { + goto out; + } + count++; } + expected_offset +=3D s->cluster_size; } =20 - return i; +out: + return count; } =20 static int coroutine_fn do_perform_cow_read(BlockDriverState *bs, @@ -524,12 +516,12 @@ int qcow2_get_host_offset(BlockDriverState *bs, uint6= 4_t offset, QCow2SubclusterType *subcluster_type) { BDRVQcow2State *s =3D bs->opaque; - unsigned int l2_index; - uint64_t l1_index, l2_offset, *l2_slice, l2_entry; - int c; + unsigned int l2_index, sc_index; + uint64_t l1_index, l2_offset, *l2_slice, l2_entry, l2_bitmap; + int sc; unsigned int offset_in_cluster; uint64_t bytes_available, bytes_needed, nb_clusters; - QCow2ClusterType type; + QCow2SubclusterType type; int ret; =20 offset_in_cluster =3D offset_into_cluster(s, offset); @@ -552,13 +544,13 @@ int qcow2_get_host_offset(BlockDriverState *bs, uint6= 4_t offset, =20 l1_index =3D offset_to_l1_index(s, offset); if (l1_index >=3D s->l1_size) { - type =3D QCOW2_CLUSTER_UNALLOCATED; + type =3D QCOW2_SUBCLUSTER_UNALLOCATED_PLAIN; goto out; } =20 l2_offset =3D s->l1_table[l1_index] & L1E_OFFSET_MASK; if (!l2_offset) { - type =3D QCOW2_CLUSTER_UNALLOCATED; + type =3D QCOW2_SUBCLUSTER_UNALLOCATED_PLAIN; goto out; } =20 @@ -579,7 +571,9 @@ int qcow2_get_host_offset(BlockDriverState *bs, uint64_= t offset, /* find the cluster offset for the given disk offset */ =20 l2_index =3D offset_to_l2_slice_index(s, offset); + sc_index =3D offset_to_sc_index(s, offset); l2_entry =3D get_l2_entry(s, l2_slice, l2_index); + l2_bitmap =3D get_l2_bitmap(s, l2_slice, l2_index); =20 nb_clusters =3D size_to_clusters(s, bytes_needed); /* bytes_needed <=3D *bytes + offset_in_cluster, both of which are uns= igned @@ -587,9 +581,9 @@ int qcow2_get_host_offset(BlockDriverState *bs, uint64_= t offset, * true */ assert(nb_clusters <=3D INT_MAX); =20 - type =3D qcow2_get_cluster_type(bs, l2_entry); - if (s->qcow_version < 3 && (type =3D=3D QCOW2_CLUSTER_ZERO_PLAIN || - type =3D=3D QCOW2_CLUSTER_ZERO_ALLOC)) { + type =3D qcow2_get_subcluster_type(bs, l2_entry, l2_bitmap, sc_index); + if (s->qcow_version < 3 && (type =3D=3D QCOW2_SUBCLUSTER_ZERO_PLAIN || + type =3D=3D QCOW2_SUBCLUSTER_ZERO_ALLOC)) { qcow2_signal_corruption(bs, true, -1, -1, "Zero cluster entry foun= d" " in pre-v3 image (L2 offset: %#" PRIx64 ", L2 index: %#x)", l2_offset, l2_index); @@ -597,7 +591,13 @@ int qcow2_get_host_offset(BlockDriverState *bs, uint64= _t offset, goto fail; } switch (type) { - case QCOW2_CLUSTER_COMPRESSED: + case QCOW2_SUBCLUSTER_INVALID: + qcow2_signal_corruption(bs, true, -1, -1, "Invalid cluster entry f= ound " + " (L2 offset: %#" PRIx64 ", L2 index: %#x)= ", + l2_offset, l2_index); + ret =3D -EIO; + goto fail; + case QCOW2_SUBCLUSTER_COMPRESSED: if (has_data_file(bs)) { qcow2_signal_corruption(bs, true, -1, -1, "Compressed cluster " "entry found in image with external da= ta " @@ -607,21 +607,20 @@ int qcow2_get_host_offset(BlockDriverState *bs, uint6= 4_t offset, goto fail; } /* Compressed clusters can only be processed one by one */ - c =3D 1; + sc =3D s->subclusters_per_cluster - sc_index; *host_offset =3D l2_entry & L2E_COMPRESSED_OFFSET_SIZE_MASK; break; - case QCOW2_CLUSTER_ZERO_PLAIN: - case QCOW2_CLUSTER_UNALLOCATED: - /* how many empty clusters ? */ - c =3D count_contiguous_clusters_unallocated(bs, nb_clusters, - l2_slice, l2_index, type= ); + case QCOW2_SUBCLUSTER_ZERO_PLAIN: + case QCOW2_SUBCLUSTER_UNALLOCATED_PLAIN: + sc =3D count_contiguous_subclusters(bs, nb_clusters, sc_index, + l2_slice, l2_index); *host_offset =3D 0; break; - case QCOW2_CLUSTER_ZERO_ALLOC: - case QCOW2_CLUSTER_NORMAL: - /* how many allocated clusters ? */ - c =3D count_contiguous_clusters(bs, nb_clusters, s->cluster_size, - l2_slice, l2_index, QCOW_OFLAG_ZERO); + case QCOW2_SUBCLUSTER_ZERO_ALLOC: + case QCOW2_SUBCLUSTER_NORMAL: + case QCOW2_SUBCLUSTER_UNALLOCATED_ALLOC: + sc =3D count_contiguous_subclusters(bs, nb_clusters, sc_index, + l2_slice, l2_index); *host_offset =3D l2_entry & L2E_OFFSET_MASK; if (offset_into_cluster(s, *host_offset)) { qcow2_signal_corruption(bs, true, -1, -1, @@ -651,7 +650,7 @@ int qcow2_get_host_offset(BlockDriverState *bs, uint64_= t offset, =20 qcow2_cache_put(s->l2_table_cache, (void **) &l2_slice); =20 - bytes_available =3D (int64_t)c * s->cluster_size; + bytes_available =3D ((int64_t)sc + sc_index) << s->subcluster_bits; =20 out: if (bytes_available > bytes_needed) { @@ -664,7 +663,7 @@ out: assert(bytes_available - offset_in_cluster <=3D UINT_MAX); *bytes =3D bytes_available - offset_in_cluster; =20 - *subcluster_type =3D qcow2_cluster_to_subcluster_type(type); + *subcluster_type =3D type; =20 return 0; =20 --=20 2.20.1 From nobody Tue May 7 09:01:18 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1584470103; cv=none; d=zohomail.com; s=zohoarc; b=bSlP0KJCty4ozJFG0EfCadKOXqbFD1EdM9V/2YcdH3lgrrwNpXIqsEGb/dSGTTbPNH/Jr0/FDstOJRze/v5arMhwAN1SHPRovDTL8JnlesyuVgwI9lRyMby7AJxKNZgT2XRBVqX+4Adx/nakwm1BIo5ARADosgydn/5ydfAzg38= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1584470103; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=/N5tR/EenqLcII0SrkA0hO9WogY+jGlaf4KeRI4XFi4=; b=JShgTjW5l8RAz2QxGJKIq3L3GckLSzqfXDQUOdgK1iSmb2fm379HUzrsSpn0Y0aUD+Y36pFon3GXVPxSPeWUrl3biiirXzr6FWGRaG0azI9RgL74REA9YH4F0WEXx9Kq5MZouA6iFOT5k/DYcBMR067FjaZVX+SHrZUIN44HYPI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1584470103482324.71384094173095; Tue, 17 Mar 2020 11:35:03 -0700 (PDT) Received: from localhost ([::1]:39428 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEH3O-0003XS-CA for importer@patchew.org; Tue, 17 Mar 2020 14:35:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48843) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEGmx-0003U7-IJ for qemu-devel@nongnu.org; Tue, 17 Mar 2020 14:18:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jEGmv-00008k-1x for qemu-devel@nongnu.org; Tue, 17 Mar 2020 14:18:03 -0400 Received: from fanzine.igalia.com ([178.60.130.6]:58012) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jEGmu-0005yA-4H; Tue, 17 Mar 2020 14:18:00 -0400 Received: from [81.0.35.138] (helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1jEGmD-000151-2y; Tue, 17 Mar 2020 19:17:17 +0100 Received: from berto by perseus.local with local (Exim 4.92) (envelope-from ) id 1jEGlw-0006Of-M8; Tue, 17 Mar 2020 19:17:00 +0100 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=/N5tR/EenqLcII0SrkA0hO9WogY+jGlaf4KeRI4XFi4=; b=TBul/DslfCmx4VQNouxwZxLTeT8ahqYMUSOZlDG+HF5UuwWX4OvIOT/azJ9SKn9E2/2S4gc3I8LK0hWFiox4Cg9KdE95Yx0ldV3SJITpEaCpYqbP8L/poxJ278uIkqCWA0jSYMBbRSNJK3xN5LLadbwtFqcdTfHgMni5Sbjwas2U7JiZ82/rPT6QEJo1Gn9Vptu0yagUvYQuGWzx0KGxaU8v98qE8yaazdmrUQdIUi/UJH+odNMG1+vJQEJte1m4cM/otZcdYoISZGQprRwfiyMNyqUhuwWh94LjDPVBMcxVkYklvHuN530iF7m1DTnCwHaB7YFu+ZspPzIJ8G/spw==; From: Alberto Garcia To: qemu-devel@nongnu.org Subject: [PATCH v4 19/30] qcow2: Add subcluster support to zero_in_l2_slice() Date: Tue, 17 Mar 2020 19:16:16 +0100 Message-Id: X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy] X-Received-From: 178.60.130.6 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Anton Nefedov , Alberto Garcia , qemu-block@nongnu.org, Max Reitz , Vladimir Sementsov-Ogievskiy , "Denis V . Lunev" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Setting the QCOW_OFLAG_ZERO bit of the L2 entry is forbidden if an image has subclusters. Instead, the individual 'all zeroes' bits must be used. Signed-off-by: Alberto Garcia Reviewed-by: Max Reitz Reviewed-by: Vladimir Sementsov-Ogievskiy --- block/qcow2-cluster.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c index 6f2643ba53..746006a117 100644 --- a/block/qcow2-cluster.c +++ b/block/qcow2-cluster.c @@ -1897,7 +1897,7 @@ static int zero_in_l2_slice(BlockDriverState *bs, uin= t64_t offset, assert(nb_clusters <=3D INT_MAX); =20 for (i =3D 0; i < nb_clusters; i++) { - uint64_t old_offset; + uint64_t old_offset, l2_entry =3D 0; QCow2ClusterType cluster_type; =20 old_offset =3D get_l2_entry(s, l2_slice, l2_index + i); @@ -1914,12 +1914,18 @@ static int zero_in_l2_slice(BlockDriverState *bs, u= int64_t offset, =20 qcow2_cache_entry_mark_dirty(s->l2_table_cache, l2_slice); if (cluster_type =3D=3D QCOW2_CLUSTER_COMPRESSED || unmap) { - set_l2_entry(s, l2_slice, l2_index + i, QCOW_OFLAG_ZERO); qcow2_free_any_clusters(bs, old_offset, 1, QCOW2_DISCARD_REQUE= ST); } else { - uint64_t entry =3D get_l2_entry(s, l2_slice, l2_index + i); - set_l2_entry(s, l2_slice, l2_index + i, entry | QCOW_OFLAG_ZER= O); + l2_entry =3D get_l2_entry(s, l2_slice, l2_index + i); } + + if (has_subclusters(s)) { + set_l2_bitmap(s, l2_slice, l2_index + i, QCOW_L2_BITMAP_ALL_ZE= ROES); + } else { + l2_entry |=3D QCOW_OFLAG_ZERO; + } + + set_l2_entry(s, l2_slice, l2_index + i, l2_entry); } =20 qcow2_cache_put(s->l2_table_cache, (void **) &l2_slice); --=20 2.20.1 From nobody Tue May 7 09:01:18 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1584469486; cv=none; d=zohomail.com; s=zohoarc; b=i2ixJ8stJ7crFxUFMHBuUC61gLKxv3xXp0pk+ZKwuCwij6uAT5JsRQ444zLUsfewRFiTBD0YTgmHDpsyKQ5YtK3WklVIOXgaiu/NDcOibP9H//lxnvOcHl696dPTnaWywuVrIhCVmYiNtXf9t9+e266754AbqDg7I7j9SAwXgSk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1584469486; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=h/8dxf0/wFbCMRFGzRbk9d/sTeWsYzZatnL8082IbGI=; b=Cn2tVP9ZWrEfN3u5N5qihtO5a1+OZ5B2xNncA9S7oWFY+e3Aliw8dU393BFzobG7VgXAqyAGbWuoJqVZdPwQyARvRaGi4CS6/qyQEocs+aoMjvgq4G/iiHeFrDvMdSw/rPlDkygi1BDLq2Sg2fG+CJJDtm2XmI+wqyl9Ihj/iSg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1584469486783750.5759753365347; Tue, 17 Mar 2020 11:24:46 -0700 (PDT) Received: from localhost ([::1]:39088 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEGtQ-0005XR-9a for importer@patchew.org; Tue, 17 Mar 2020 14:24:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48803) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEGmw-0003Ry-Jv for qemu-devel@nongnu.org; Tue, 17 Mar 2020 14:18:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jEGmu-00007Y-Ml for qemu-devel@nongnu.org; Tue, 17 Mar 2020 14:18:02 -0400 Received: from fanzine.igalia.com ([178.60.130.6]:57914) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jEGmu-0005wQ-4V; Tue, 17 Mar 2020 14:18:00 -0400 Received: from [81.0.35.138] (helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1jEGmC-00015O-W5; Tue, 17 Mar 2020 19:17:17 +0100 Received: from berto by perseus.local with local (Exim 4.92) (envelope-from ) id 1jEGlw-0006Oh-NA; Tue, 17 Mar 2020 19:17:00 +0100 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=h/8dxf0/wFbCMRFGzRbk9d/sTeWsYzZatnL8082IbGI=; b=X6ZB2zogZAWbgFITulhlxt1UEUD6NSYdgUeyIPyZahU1zm+22Qvzx9+ECWa8RJUcsBPISl2vvuhd9HsbzLLVZZ+ZuiwoFBHRrLYrUxlqh2N9i5fekcrTsn8oY6heszG/6cUr7O+W5VhE3D0qCjBgJp5XlevaogEnGayoThsWanJWkfhxQiEUDx7jGqcVQ1vgnRHI61iistBQcZi5WfWfRfcOGOQX7hBMHCB9LVse+cXxJNKynE7FBugA2PS/1JRnVrKORdbHixg1tFd4NIvKDDKFh5WxvDuKP1clpOt7uM87HUgkm+duGFb6W7iyV/D9vEGAf02WZaDHdc03DiFm0A==; From: Alberto Garcia To: qemu-devel@nongnu.org Subject: [PATCH v4 20/30] qcow2: Add subcluster support to discard_in_l2_slice() Date: Tue, 17 Mar 2020 19:16:17 +0100 Message-Id: <99b45e3beb4a38b17eb50fcde1e09cdefdb99724.1584468723.git.berto@igalia.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy] X-Received-From: 178.60.130.6 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Anton Nefedov , Alberto Garcia , qemu-block@nongnu.org, Max Reitz , Vladimir Sementsov-Ogievskiy , "Denis V . Lunev" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Two changes are needed in this function: 1) A full discard deallocates a cluster so we can skip the operation if it is already unallocated. With extended L2 entries however if any of the subclusters has the 'all zeroes' bit set then we have to clear it. 2) Setting the QCOW_OFLAG_ZERO bit of the L2 entry is forbidden if an image has extended L2 entries. Instead, the individual 'all zeroes' bits must be used. Signed-off-by: Alberto Garcia Reviewed-by: Max Reitz --- block/qcow2-cluster.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c index 746006a117..824c710760 100644 --- a/block/qcow2-cluster.c +++ b/block/qcow2-cluster.c @@ -1790,12 +1790,20 @@ static int discard_in_l2_slice(BlockDriverState *bs= , uint64_t offset, * TODO We might want to use bdrv_block_status(bs) here, but we're * holding s->lock, so that doesn't work today. * - * If full_discard is true, the sector should not read back as zer= oes, + * If full_discard is true, the cluster should not read back as ze= roes, * but rather fall through to the backing file. */ switch (qcow2_get_cluster_type(bs, old_l2_entry)) { case QCOW2_CLUSTER_UNALLOCATED: - if (full_discard || !bs->backing) { + if (full_discard) { + /* If the image has extended L2 entries we can only + * skip this operation if the L2 bitmap is zero. */ + uint64_t bitmap =3D has_subclusters(s) ? + get_l2_bitmap(s, l2_slice, l2_index + i) : 0; + if (bitmap =3D=3D 0) { + continue; + } + } else if (!bs->backing) { continue; } break; @@ -1817,7 +1825,11 @@ static int discard_in_l2_slice(BlockDriverState *bs,= uint64_t offset, =20 /* First remove L2 entries */ qcow2_cache_entry_mark_dirty(s->l2_table_cache, l2_slice); - if (!full_discard && s->qcow_version >=3D 3) { + if (has_subclusters(s)) { + set_l2_entry(s, l2_slice, l2_index + i, 0); + set_l2_bitmap(s, l2_slice, l2_index + i, + full_discard ? 0 : QCOW_L2_BITMAP_ALL_ZEROES); + } else if (!full_discard && s->qcow_version >=3D 3) { set_l2_entry(s, l2_slice, l2_index + i, QCOW_OFLAG_ZERO); } else { set_l2_entry(s, l2_slice, l2_index + i, 0); --=20 2.20.1 From nobody Tue May 7 09:01:18 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1584469858; cv=none; d=zohomail.com; s=zohoarc; b=G2X5uJESy0HWswGiY80tnlDGQ5PgBNI+3m9HGEzfjuNQ6naXnaHGAgEb9heKn7at9KgucIa9fPEW+td+/u/lvHFynl6rGH6/BvsOTs+3nDSxvQvuVv/6AAdXCFAo6rKDnwhiZK9ejLX8SGwuoYONdsycLdTIRZ+jEx0TPnPDcx4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1584469858; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=oWauXz47PpW+xVTM/4Ib2FZL1+ZMSwNIBOfuc4avzAI=; b=c6c0Ps92EjArnMFI8nytMUEK0slLHIxNJor7RB55mZH+im8snKQaO0NPXgc2/qNQh9QeM5Rx7XDyzdo0cccCwHeu5X9yzc0+9vm7S4FqlO5BjkZZVhQ5NnQenNNSSXpJjcJgp5BNyQ703rDEwU3as8wqA+AAFMC04bv2VtnAeeM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1584469858996367.36392299015574; Tue, 17 Mar 2020 11:30:58 -0700 (PDT) Received: from localhost ([::1]:39302 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEGzR-00063P-Op for importer@patchew.org; Tue, 17 Mar 2020 14:30:57 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48682) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEGmt-0003LK-GX for qemu-devel@nongnu.org; Tue, 17 Mar 2020 14:18:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jEGms-0008U4-En for qemu-devel@nongnu.org; Tue, 17 Mar 2020 14:17:59 -0400 Received: from fanzine.igalia.com ([178.60.130.6]:57705) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jEGms-0005Ut-5D; Tue, 17 Mar 2020 14:17:58 -0400 Received: from [81.0.35.138] (helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1jEGmD-00015c-0i; Tue, 17 Mar 2020 19:17:17 +0100 Received: from berto by perseus.local with local (Exim 4.92) (envelope-from ) id 1jEGlw-0006Oj-OL; Tue, 17 Mar 2020 19:17:00 +0100 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=oWauXz47PpW+xVTM/4Ib2FZL1+ZMSwNIBOfuc4avzAI=; b=WYjpzvM73Lgs5SQe1qRRYChrWddCJt7O19zP1KdeOkjdxCo2Za00xelT0D3jJPyEG+c8rULlL/Cmbk11q5nwkbKaYY/nH9uNrHH5XWgo3B23FQrGCfJ5jV9ZdFZzbUxi7AKmhKSY2b2lSJzdBHwLOUUXbf1GBkLHbZHrROSqoQr1QDGprXdzAVOohkHEVPpCGSFFafRbzpwDWv53pQRGkg5LS1zyXmzbPF3N/y7cM/sjGHcL2Dt5Q5EoOySWNBg8dL5vWoDj4nAcTHpBdrdnqd+IW4Z4iBipAt9p5M79J6wPSKxLymu9+/8tZzw27KkHoF0W3XIp4LsRABKA6LdV8w==; From: Alberto Garcia To: qemu-devel@nongnu.org Subject: [PATCH v4 21/30] qcow2: Add subcluster support to check_refcounts_l2() Date: Tue, 17 Mar 2020 19:16:18 +0100 Message-Id: X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy] X-Received-From: 178.60.130.6 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Anton Nefedov , Alberto Garcia , qemu-block@nongnu.org, Max Reitz , Vladimir Sementsov-Ogievskiy , "Denis V . Lunev" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Setting the QCOW_OFLAG_ZERO bit of the L2 entry is forbidden if an image has subclusters. Instead, the individual 'all zeroes' bits must be used. Signed-off-by: Alberto Garcia Reviewed-by: Max Reitz Reviewed-by: Vladimir Sementsov-Ogievskiy --- block/qcow2-refcount.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c index 3b89a97fd0..9337496c84 100644 --- a/block/qcow2-refcount.c +++ b/block/qcow2-refcount.c @@ -1686,8 +1686,13 @@ static int check_refcounts_l2(BlockDriverState *bs, = BdrvCheckResult *res, int ign =3D active ? QCOW2_OL_ACTIVE_L2 : QCOW2_OL_INACTIVE_L2; =20 - l2_entry =3D QCOW_OFLAG_ZERO; - set_l2_entry(s, l2_table, i, l2_entry); + if (has_subclusters(s)) { + set_l2_entry(s, l2_table, i, 0); + set_l2_bitmap(s, l2_table, i, + QCOW_L2_BITMAP_ALL_ZEROES); + } else { + set_l2_entry(s, l2_table, i, QCOW_OFLAG_ZERO); + } ret =3D qcow2_pre_write_overlap_check(bs, ign, l2e_offset, l2_entry_size(s), false); if (ret < 0) { --=20 2.20.1 From nobody Tue May 7 09:01:18 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1584469420; cv=none; d=zohomail.com; s=zohoarc; b=VjcgU6qwn3aH58oHmGvYLiT8L9MUqsycGxEUkjQySLOhAQfE7o/ebCszJrgPB14362gtD3K+mkiZm0v50YPuCRhToLUxHQPijNpHKFR9+1YTQEeTQE/FMPMqFU+03oT+5GeF9LtHTtRWVL3KkR1X1ola8q/HmlZX5l17Vt+oZfI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1584469420; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=2dD5+fpTCs+s9KvpJKL8lqwrOb+2rBZz05GePv9EoMw=; b=S/zScSCy98Xr/gltDlUdEQGkEewCk8FuLp0jcpala/gOnxj/szj9nD5qQ/52izYz4CTwc4PRywrNMDloOkCEh6GfugyrKG4xs5LV6tzUtFLkXchMtII0lgDli/8xaTlxQD99ShMMY4+O48IqsT3iRgeqWbW+3UdqModM5wIETaQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1584469420141124.53089130505123; Tue, 17 Mar 2020 11:23:40 -0700 (PDT) Received: from localhost ([::1]:39052 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEGsN-0003a2-1A for importer@patchew.org; Tue, 17 Mar 2020 14:23:39 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48313) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEGmb-0002oI-14 for qemu-devel@nongnu.org; Tue, 17 Mar 2020 14:17:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jEGmZ-0007VS-2N for qemu-devel@nongnu.org; Tue, 17 Mar 2020 14:17:40 -0400 Received: from fanzine.igalia.com ([178.60.130.6]:57721) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jEGmX-0005V8-AI; Tue, 17 Mar 2020 14:17:38 -0400 Received: from [81.0.35.138] (helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1jEGmC-00015U-Sz; Tue, 17 Mar 2020 19:17:16 +0100 Received: from berto by perseus.local with local (Exim 4.92) (envelope-from ) id 1jEGlw-0006Ol-PT; Tue, 17 Mar 2020 19:17:00 +0100 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=2dD5+fpTCs+s9KvpJKL8lqwrOb+2rBZz05GePv9EoMw=; b=TEZBYmI0Tv5TNCV7Jr+W9K9pKfNbWmuMcr/i5fNIhaTPrF+dJx6dhDE9LRHwdxHdURqsAPHksfLaLQXbA7vtYQTPnL0a7r8QKYCXAUUJobxfwMvTlMS1Tabr9DrgPBsSOFZZEEdeF59Qa/hkrN2fQMv5qQf3ymUc7Ve1htasFrNaDwd3bPwEwIBc4NHs8m575NuuDQXsmsUEO7utIl5+II/FbBqq5Ol1ldiGEOGM1ZnTE5JutlZqxi6zKp62ub8jhaXzzXrkaquFVu7CO441xf0kWd1O9CjTFpgGnMiwOl6+TeC9YmWObLjDc5TqSWUlhOUhZVO3sfeagyr5VBAJow==; From: Alberto Garcia To: qemu-devel@nongnu.org Subject: [PATCH v4 22/30] qcow2: Fix offset calculation in handle_dependencies() Date: Tue, 17 Mar 2020 19:16:19 +0100 Message-Id: <46d9ec6dca0b054a529ee776d1c04b002098c127.1584468723.git.berto@igalia.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy] X-Received-From: 178.60.130.6 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Anton Nefedov , Alberto Garcia , qemu-block@nongnu.org, Max Reitz , Vladimir Sementsov-Ogievskiy , "Denis V . Lunev" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" l2meta_cow_start() and l2meta_cow_end() are not necessarily cluster-aligned if the image has subclusters, so update the calculation of old_start and old_end to guarantee that no two requests try to write on the same cluster. Signed-off-by: Alberto Garcia Reviewed-by: Max Reitz --- block/qcow2-cluster.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c index 824c710760..ceacd91ea3 100644 --- a/block/qcow2-cluster.c +++ b/block/qcow2-cluster.c @@ -1306,8 +1306,8 @@ static int handle_dependencies(BlockDriverState *bs, = uint64_t guest_offset, =20 uint64_t start =3D guest_offset; uint64_t end =3D start + bytes; - uint64_t old_start =3D l2meta_cow_start(old_alloc); - uint64_t old_end =3D l2meta_cow_end(old_alloc); + uint64_t old_start =3D start_of_cluster(s, l2meta_cow_start(old_al= loc)); + uint64_t old_end =3D ROUND_UP(l2meta_cow_end(old_alloc), s->cluste= r_size); =20 if (end <=3D old_start || start >=3D old_end) { /* No intersection */ --=20 2.20.1 From nobody Tue May 7 09:01:18 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1584469855; cv=none; d=zohomail.com; s=zohoarc; b=UgEHvZMX6EjPZ4GkLOO1UeyJJXt0foDbj2I5erRwTqPXcKCnweEumErNeMrzuiOB4K5oUg2oOHC0Y58w0tBHbjTeiV+GkcwdCXTs96vm+sRZkKFd8hgnrqSC0WAGD5B9R2gViWmXDTS23aOjSfQ2yb0uttZ8iljLJ6b2z3wudq8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1584469855; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=yU0+mCKAyZ6lIvQHsAFwvNxk4bue3OrHxBOx+RuSq50=; b=UlF0f29J8z5GkGrMg00RPZXzvMMJOcl4/iIJgiDpv/kIsKG/urpxdvKwNpVq6w7g6GxmhYgR/W/jqabQUOEfriDsBMpTsvB9mCJ1LHdf5EMlk5t2UV9f5JWbNLhGzTDdF9CdXLN0eBlXmePMiAkGTEAq2ODRvioQvMYCOKqIQ18= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1584469855373566.554789991253; Tue, 17 Mar 2020 11:30:55 -0700 (PDT) Received: from localhost ([::1]:39298 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEGzO-00062l-4c for importer@patchew.org; Tue, 17 Mar 2020 14:30:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48775) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEGmv-0003Ql-T6 for qemu-devel@nongnu.org; Tue, 17 Mar 2020 14:18:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jEGmu-00006h-DY for qemu-devel@nongnu.org; Tue, 17 Mar 2020 14:18:01 -0400 Received: from fanzine.igalia.com ([178.60.130.6]:57918) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jEGmu-0005wH-41; Tue, 17 Mar 2020 14:18:00 -0400 Received: from [81.0.35.138] (helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1jEGmD-00015a-0D; Tue, 17 Mar 2020 19:17:17 +0100 Received: from berto by perseus.local with local (Exim 4.92) (envelope-from ) id 1jEGlw-0006On-Qy; Tue, 17 Mar 2020 19:17:00 +0100 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=yU0+mCKAyZ6lIvQHsAFwvNxk4bue3OrHxBOx+RuSq50=; b=mxTOrUQFR19UbGg5mLcYZS30OI23nwzBqTrJpTD9Hdv9Qx8icZquwrTWPQDRF73Fxs6f+/wEHEsb/Vv22xk4NJ7M0wygw5TdX1edHqfkKu7jOKiawyMjLMmbtwd1xnxZSGitNE4rL8vymPen6q4t91YNABETOEucak1/KS3ObGpO/jZe65xLecPep6GDfVQsw0HUeN0TN0g7i77fu+kNqy1mVmeJ0dnT6fKUdQQl6mHb4DrZpQSdf71Une/grUEmDsoEYATBfKIjpGJpUjpl1G0xeMZv632Qy0tTD8Wn3AE0NiSvCwaN+8/NFZ9tII3kZnIAQ8f+mY23wo1y04ytiQ==; From: Alberto Garcia To: qemu-devel@nongnu.org Subject: [PATCH v4 23/30] qcow2: Update L2 bitmap in qcow2_alloc_cluster_link_l2() Date: Tue, 17 Mar 2020 19:16:20 +0100 Message-Id: <6ffd3ee7ca1e53272705ad34d2ea7ac10b50ade0.1584468723.git.berto@igalia.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy] X-Received-From: 178.60.130.6 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Anton Nefedov , Alberto Garcia , qemu-block@nongnu.org, Max Reitz , Vladimir Sementsov-Ogievskiy , "Denis V . Lunev" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" The L2 bitmap needs to be updated after each write to indicate what new subclusters are now allocated. This needs to happen even if the cluster was already allocated and the L2 entry was otherwise valid. Signed-off-by: Alberto Garcia Reviewed-by: Max Reitz --- block/qcow2-cluster.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c index ceacd91ea3..dfd8b66958 100644 --- a/block/qcow2-cluster.c +++ b/block/qcow2-cluster.c @@ -1006,6 +1006,23 @@ int qcow2_alloc_cluster_link_l2(BlockDriverState *bs= , QCowL2Meta *m) assert((offset & L2E_OFFSET_MASK) =3D=3D offset); =20 set_l2_entry(s, l2_slice, l2_index + i, offset | QCOW_OFLAG_COPIED= ); + + /* Update bitmap with the subclusters that were just written */ + if (has_subclusters(s)) { + unsigned written_from =3D m->cow_start.offset; + unsigned written_to =3D m->cow_end.offset + m->cow_end.nb_byte= s ?: + m->nb_clusters << s->cluster_bits; + uint64_t l2_bitmap =3D get_l2_bitmap(s, l2_slice, l2_index + i= ); + int sc; + for (sc =3D 0; sc < s->subclusters_per_cluster; sc++) { + int sc_off =3D i * s->cluster_size + sc * s->subcluster_si= ze; + if (sc_off >=3D written_from && sc_off < written_to) { + l2_bitmap |=3D QCOW_OFLAG_SUB_ALLOC(sc); + l2_bitmap &=3D ~QCOW_OFLAG_SUB_ZERO(sc); + } + } + set_l2_bitmap(s, l2_slice, l2_index + i, l2_bitmap); + } } =20 =20 --=20 2.20.1 From nobody Tue May 7 09:01:18 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1584470228; cv=none; d=zohomail.com; s=zohoarc; b=G9F3f+2ZZi9JCoQwxCb2GoFqI+8X/QbX1wj0Pr6rfIwNFx4REO1rMtDCti9BZtZiLEB+PPB2yVptP77Gvm0wxPwi6l4xJQBhY3GazEi5Su4myC/psG5p4Kh8LIKGUl1YNdwi9e8bIrrT2DOmmADK9X1RPR7PREeYQLKyK0wGIkw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1584470228; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=s7dRHxBO3oqeFHBCKa67pRvg2ir7e1CHI3jX0YPDL6A=; b=gOuSF/eFg1rqK4HcgpWbli5RNQytrnoY/XjVm0oB1EbqpaUcW8gBkJOTbFk0jVT6Q/fHnry6eIRqzKgfYeePfHRNl1HKYr0NzC8GiM2+Sbzb0aqwJegENO9+ID1IqvfwZQ5jrZdKDSPYt0TTJCPzNzMQMzd5El+AJ501/M3y1y0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1584470228329668.4713272695321; Tue, 17 Mar 2020 11:37:08 -0700 (PDT) Received: from localhost ([::1]:39486 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEH5P-0006Oh-9S for importer@patchew.org; Tue, 17 Mar 2020 14:37:07 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48824) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEGmx-0003Sx-08 for qemu-devel@nongnu.org; Tue, 17 Mar 2020 14:18:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jEGmu-000086-Tu for qemu-devel@nongnu.org; Tue, 17 Mar 2020 14:18:02 -0400 Received: from fanzine.igalia.com ([178.60.130.6]:57999) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jEGmu-0005xk-6Z; Tue, 17 Mar 2020 14:18:00 -0400 Received: from [81.0.35.138] (helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1jEGmD-000156-4G; Tue, 17 Mar 2020 19:17:17 +0100 Received: from berto by perseus.local with local (Exim 4.92) (envelope-from ) id 1jEGlw-0006Op-Ry; Tue, 17 Mar 2020 19:17:00 +0100 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=s7dRHxBO3oqeFHBCKa67pRvg2ir7e1CHI3jX0YPDL6A=; b=hQTVEwlum3Sq6l/FFvFiETJzZQn+C2MQJUCN2MvxqTL0XagiRwaDizgDLYDBpEu3H3pg78M3z5Q/iTLvc8z2NkNtcvhkOvBObRrkn1vVudBepgu6l7teK/H+sZVy8+QT7rHGEJvU8YQ8GYVWVvDsqVhCRhc9vXRH5TjugzvbDu6Egyw6pPNU0GGO6I3QV+ANUa2szvK6ZsCIkvLTi1+In2tNlPqy/8+yngy6GuA+0edKa4Lgew5b49XSPSiIuMHcXQkilrS5QDKp8TTPHc5DV9i7T4bzQt2HACnldrM2gIjvEmb3vLgU5fMjgF7VHSqSaNOo9g/JDXCbuZkcgASIdg==; From: Alberto Garcia To: qemu-devel@nongnu.org Subject: [PATCH v4 24/30] qcow2: Clear the L2 bitmap when allocating a compressed cluster Date: Tue, 17 Mar 2020 19:16:21 +0100 Message-Id: <6d596d82ed62615a8565b661691a06bfaf32237e.1584468723.git.berto@igalia.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy] X-Received-From: 178.60.130.6 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Anton Nefedov , Alberto Garcia , qemu-block@nongnu.org, Max Reitz , Vladimir Sementsov-Ogievskiy , "Denis V . Lunev" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Compressed clusters always have the bitmap part of the extended L2 entry set to 0. Signed-off-by: Alberto Garcia Reviewed-by: Max Reitz --- block/qcow2-cluster.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c index dfd8b66958..1f471db98c 100644 --- a/block/qcow2-cluster.c +++ b/block/qcow2-cluster.c @@ -806,6 +806,9 @@ int qcow2_alloc_compressed_cluster_offset(BlockDriverSt= ate *bs, BLKDBG_EVENT(bs->file, BLKDBG_L2_UPDATE_COMPRESSED); qcow2_cache_entry_mark_dirty(s->l2_table_cache, l2_slice); set_l2_entry(s, l2_slice, l2_index, cluster_offset); + if (has_subclusters(s)) { + set_l2_bitmap(s, l2_slice, l2_index, 0); + } qcow2_cache_put(s->l2_table_cache, (void **) &l2_slice); =20 *host_offset =3D cluster_offset & s->cluster_offset_mask; --=20 2.20.1 From nobody Tue May 7 09:01:18 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1584470003; cv=none; d=zohomail.com; s=zohoarc; b=Mg1O25BLJ1Zr3trVhCxLLwCOPw1CXwAnA/IIjHGyPOhvSJNOW544sv6SbAM+KbAm3ORAvkyITTivyF0baW/wa8fgIKXT0Z0Ig3yprP/QW5b7wJ4+yZ2B1OhXOcTAwC8r0ifuHh/K+K21EpuM13ejNN/XlJDvkGgGJcn0tAVHL2k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1584470003; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=jqTKqtd2jDDQ2OjEdrmXgcDY2lStZiVJr05vUx6LPMs=; b=aIidH7tT5Ic8QSzTs3FC0C90JYwBab/+7puUXSlsS4pafK0h5QJPpH0NoDJueeZu4WixblmvJov7C7goH9rz5CBHfK9tmjqe1XBApdpIGhF/Do0VQezsZLAjy4NucnjA2y1XeQIKUSFs7VsJBJXRRMnKjo8s040qosWYKT4P71Q= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1584470003577841.9802805622958; Tue, 17 Mar 2020 11:33:23 -0700 (PDT) Received: from localhost ([::1]:39368 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEH1m-0000HC-EX for importer@patchew.org; Tue, 17 Mar 2020 14:33:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48688) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEGmt-0003Lc-KX for qemu-devel@nongnu.org; Tue, 17 Mar 2020 14:18:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jEGms-0008UM-Gj for qemu-devel@nongnu.org; Tue, 17 Mar 2020 14:17:59 -0400 Received: from fanzine.igalia.com ([178.60.130.6]:57720) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jEGms-0005V7-78; Tue, 17 Mar 2020 14:17:58 -0400 Received: from [81.0.35.138] (helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1jEGmD-00014r-39; Tue, 17 Mar 2020 19:17:17 +0100 Received: from berto by perseus.local with local (Exim 4.92) (envelope-from ) id 1jEGlw-0006Or-T2; Tue, 17 Mar 2020 19:17:00 +0100 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=jqTKqtd2jDDQ2OjEdrmXgcDY2lStZiVJr05vUx6LPMs=; b=pyTxDLfavOBARhoSz75na+X1vWd6wRqF+akZVYJHPMU8XVSGbMe3Ut/BHbvg3g2GlXVTBS3rx6p7V2XYGPELHern1ndZ2C68t4hChoqveS4VJeJpku7vNl4pldy3m6hpQjpNClAzuYFVE+S9UQNi5ngbSfCgreZZuTlwoXWYMe+dM6nby3GnEVTJhOsJmzlA2H6Y1mUQhEQuhgibhVpQhLClJZL02Lsx/jRhVHg83aqD4pGghJ0+Xu3jlBWDxnYVuwazmzBmEwrDMdw9lRCE+mhZ4fy9tBYfYZsAqsrcf8DaTd10ewhABrQEuEQjIh/NDi0lbc+3cUoeS0TIFrzMyA==; From: Alberto Garcia To: qemu-devel@nongnu.org Subject: [PATCH v4 25/30] qcow2: Add subcluster support to handle_alloc_space() Date: Tue, 17 Mar 2020 19:16:22 +0100 Message-Id: <7346b6242cb3589cf946314db445edc9250bd3e7.1584468723.git.berto@igalia.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy] X-Received-From: 178.60.130.6 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Anton Nefedov , Alberto Garcia , qemu-block@nongnu.org, Max Reitz , Vladimir Sementsov-Ogievskiy , "Denis V . Lunev" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" The bdrv_co_pwrite_zeroes() call here fills complete clusters with zeroes, but it can happen that some subclusters are not part of the write request or the copy-on-write. This patch makes sure that only the affected subclusters are overwritten. A potential improvement would be to also fill with zeroes the other subclusters if we can guarantee that we are not overwriting existing data. However this would waste more disk space, so we should first evaluate if it's really worth doing. Signed-off-by: Alberto Garcia Reviewed-by: Max Reitz Reviewed-by: Vladimir Sementsov-Ogievskiy --- block/qcow2.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/block/qcow2.c b/block/qcow2.c index 88daaf11a0..ad230ed1b1 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -2349,6 +2349,9 @@ static int handle_alloc_space(BlockDriverState *bs, Q= CowL2Meta *l2meta) =20 for (m =3D l2meta; m !=3D NULL; m =3D m->next) { int ret; + uint64_t start_offset =3D m->alloc_offset + m->cow_start.offset; + unsigned nb_bytes =3D m->cow_end.offset + m->cow_end.nb_bytes - + m->cow_start.offset; =20 if (!m->cow_start.nb_bytes && !m->cow_end.nb_bytes) { continue; @@ -2363,16 +2366,14 @@ static int handle_alloc_space(BlockDriverState *bs,= QCowL2Meta *l2meta) * efficiently zero out the whole clusters */ =20 - ret =3D qcow2_pre_write_overlap_check(bs, 0, m->alloc_offset, - m->nb_clusters * s->cluster_si= ze, + ret =3D qcow2_pre_write_overlap_check(bs, 0, start_offset, nb_byte= s, true); if (ret < 0) { return ret; } =20 BLKDBG_EVENT(bs->file, BLKDBG_CLUSTER_ALLOC_SPACE); - ret =3D bdrv_co_pwrite_zeroes(s->data_file, m->alloc_offset, - m->nb_clusters * s->cluster_size, + ret =3D bdrv_co_pwrite_zeroes(s->data_file, start_offset, nb_bytes, BDRV_REQ_NO_FALLBACK); if (ret < 0) { if (ret !=3D -ENOTSUP && ret !=3D -EAGAIN) { --=20 2.20.1 From nobody Tue May 7 09:01:18 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1584469641; cv=none; d=zohomail.com; s=zohoarc; b=OBxEZCMeVN7mqR1veNA33vT6rB4XN3liliYMR+8PQms9Yu91ZvGnxJYlchPBd6+JyDl+LgzF6aDGRABVPhX6b0WOcK1rpFEg1ssKbwWMeGwF6ykGZxV84glyC4EfyulKbEdi7LZtS457/m5uLqrplQVI1Vs9ccq4Niv1SQIoPKY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1584469641; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=hxp55E9JUt56NLfwt7oK+Qjm0FNoUMZxhVIeDlCQuSw=; b=cBnFyLlPdbpaHP8XqjAvIJBB1GqZJqs8Ysa7iQ207qXOL68iBdD5TLGuLmKzJCY64GmSKmMVTMZG6WxbSka72KhuTd+Qah3okojby09SOGGUxi7OdYHQ0hh9H7qX4LQQdRFsgVsaa0ulopXiSePEqsYNi8t20yDyJLn8R92m8vs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1584469641908566.3329903113522; Tue, 17 Mar 2020 11:27:21 -0700 (PDT) Received: from localhost ([::1]:39156 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEGvw-0000TQ-RN for importer@patchew.org; Tue, 17 Mar 2020 14:27:20 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48832) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEGmx-0003TS-AQ for qemu-devel@nongnu.org; Tue, 17 Mar 2020 14:18:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jEGmv-000097-5T for qemu-devel@nongnu.org; Tue, 17 Mar 2020 14:18:03 -0400 Received: from fanzine.igalia.com ([178.60.130.6]:58015) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jEGmu-0005yG-4U; Tue, 17 Mar 2020 14:18:00 -0400 Received: from [81.0.35.138] (helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1jEGmD-00015Y-48; Tue, 17 Mar 2020 19:17:17 +0100 Received: from berto by perseus.local with local (Exim 4.92) (envelope-from ) id 1jEGlw-0006Ot-U4; Tue, 17 Mar 2020 19:17:00 +0100 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=hxp55E9JUt56NLfwt7oK+Qjm0FNoUMZxhVIeDlCQuSw=; b=ZxQ1KWUydvc5RQVXn4Iqu7OnVYcvAuhOC90senR0rMEDbNCs2d7iZJdYAr7TPXyC1nSDBgvkgVdkerh6/rodF/cRcmPACOySSroLqyHaK3PBE1QlDMSu7DZGj64h3XKFuo7k790SAEY9PzBB4KaVq5EX/Wbtnv7zOTgZqb6/Ma+ILnR3wttFX9S0ioObK1v2CPTAO/TSHk8KeOgMO6HN5x52B0G3lKdHFW7A9IK0xLvmoUeUUIN5HBT7bG6yyjn7IsnjxHd8fh8yG6Q2Qs0KcTzHJ21VFaSiY0UdLgrHaYYC1M/NTb+6LV68sgNfbIp1j2PKVBAmJwdvbXTP0PgNmA==; From: Alberto Garcia To: qemu-devel@nongnu.org Subject: [PATCH v4 26/30] qcow2: Restrict qcow2_co_pwrite_zeroes() to full clusters only Date: Tue, 17 Mar 2020 19:16:23 +0100 Message-Id: <1415552fc60acc658e3f80751d9ecd63da2b863d.1584468723.git.berto@igalia.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy] X-Received-From: 178.60.130.6 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Anton Nefedov , Alberto Garcia , qemu-block@nongnu.org, Max Reitz , Vladimir Sementsov-Ogievskiy , "Denis V . Lunev" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Ideally it should be possible to zero individual subclusters using this function, but this is currently not implemented. Signed-off-by: Alberto Garcia Reviewed-by: Max Reitz Reviewed-by: Vladimir Sementsov-Ogievskiy --- block/qcow2.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/block/qcow2.c b/block/qcow2.c index ad230ed1b1..d406ef355b 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -3743,7 +3743,9 @@ static coroutine_fn int qcow2_co_pwrite_zeroes(BlockD= riverState *bs, bytes =3D s->cluster_size; nr =3D s->cluster_size; ret =3D qcow2_get_host_offset(bs, offset, &nr, &off, &type); - if (ret < 0 || + /* TODO: allow zeroing separate subclusters, we only allow + * zeroing full clusters at the moment. */ + if (ret < 0 || nr !=3D bytes || (type !=3D QCOW2_SUBCLUSTER_UNALLOCATED_PLAIN && type !=3D QCOW2_SUBCLUSTER_UNALLOCATED_ALLOC && type !=3D QCOW2_SUBCLUSTER_ZERO_PLAIN && --=20 2.20.1 From nobody Tue May 7 09:01:18 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1584470226; cv=none; d=zohomail.com; s=zohoarc; b=NC1B4E33/P2qtB0nPAlNgEr8zevv5BQPcftXMdiniruVoGgouv1lrcCT8MEDL9eXkhUNx4Z0PeZDL8ofYVss9x4PLAG8iPWv9d49I4SlH3bzrF01JBHIJ1vhnpaKMTSuEODdjxegU1s37Wf8P66CgpMQwz11UvULERnB78gBKaA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1584470226; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=C0eALyg6t8kHhqoCkYLe5gXMSMiybsgvLwFsI8EfjjI=; b=FzjpS/ZiwwMQ33m2YMizjE8yaANC5su0KrLNf3l1zfRgabIh5PbAY9AujJV8IYQXARNHL9xlfTHsvUincsxkr7jSegJXQhbF5EPMkIXETioqWmaeOmcTPONeCc6Sz6jehY28BUR3VVKirQXpHbSblspKQAHrDP+0fkHR+tDd+2Y= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1584470226134511.5770223879191; Tue, 17 Mar 2020 11:37:06 -0700 (PDT) Received: from localhost ([::1]:39482 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEH5M-0006KE-VB for importer@patchew.org; Tue, 17 Mar 2020 14:37:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48870) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEGmy-0003W8-Bi for qemu-devel@nongnu.org; Tue, 17 Mar 2020 14:18:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jEGmv-00009s-A2 for qemu-devel@nongnu.org; Tue, 17 Mar 2020 14:18:04 -0400 Received: from fanzine.igalia.com ([178.60.130.6]:58013) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jEGmu-0005yB-43; Tue, 17 Mar 2020 14:18:01 -0400 Received: from [81.0.35.138] (helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1jEGmD-00015A-4V; Tue, 17 Mar 2020 19:17:17 +0100 Received: from berto by perseus.local with local (Exim 4.92) (envelope-from ) id 1jEGlw-0006Ov-Uz; Tue, 17 Mar 2020 19:17:00 +0100 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=C0eALyg6t8kHhqoCkYLe5gXMSMiybsgvLwFsI8EfjjI=; b=Us9bL0NBDkov6frBccZz/YTvQdgQ+ViKkF6Xc4JKeHbpjnsUxnJWm5X4pVzvCE6pq49NR1OoCq4WrITqGV4Y0p+emAT7jdH3U52XtKiS8XSLkk1Q4ViXC3z4py1NrM6RqG3W3qdeAZNFXgToE+nFZDbeqtGkFKgLt2JzZykB5gSrGzW71LSbzrZ7CYvK/VMoevRYoDlNqTwlPPqafjeXgowx4ApIZX/B0lBL2PICn3PSPZbwJfDmXW9upDEj7p3498Yu9XkaJR6fYXbY7ACQzaHFiSw9v5wu32HerYE9ELSCU2HkrVjH63fY5j7+A3YrT4L1V2aleiqKzOalq1zKoQ==; From: Alberto Garcia To: qemu-devel@nongnu.org Subject: [PATCH v4 27/30] qcow2: Assert that expand_zero_clusters_in_l1() does not support subclusters Date: Tue, 17 Mar 2020 19:16:24 +0100 Message-Id: <5cc70489bfeb7d2f8f6c8a113dc530cab504db9e.1584468723.git.berto@igalia.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy] X-Received-From: 178.60.130.6 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Anton Nefedov , Alberto Garcia , qemu-block@nongnu.org, Max Reitz , Vladimir Sementsov-Ogievskiy , "Denis V . Lunev" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" This function is only used by qcow2_expand_zero_clusters() to downgrade a qcow2 image to a previous version. It is however not possible to downgrade an image with extended L2 entries because older versions of qcow2 do not have this feature. Signed-off-by: Alberto Garcia --- block/qcow2-cluster.c | 8 +++++++- tests/qemu-iotests/061 | 6 ++++++ tests/qemu-iotests/061.out | 5 +++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c index 1f471db98c..125d2852f6 100644 --- a/block/qcow2-cluster.c +++ b/block/qcow2-cluster.c @@ -2039,6 +2039,9 @@ static int expand_zero_clusters_in_l1(BlockDriverStat= e *bs, uint64_t *l1_table, int ret; int i, j; =20 + /* qcow2_downgrade() is not allowed in images with subclusters */ + assert(!has_subclusters(s)); + slice_size2 =3D s->l2_slice_size * l2_entry_size(s); n_slices =3D s->cluster_size / slice_size2; =20 @@ -2107,7 +2110,8 @@ static int expand_zero_clusters_in_l1(BlockDriverStat= e *bs, uint64_t *l1_table, if (cluster_type =3D=3D QCOW2_CLUSTER_ZERO_PLAIN) { if (!bs->backing) { /* not backed; therefore we can simply deallocate = the - * cluster */ + * cluster. No need to call set_l2_bitmap(), this + * function doesn't support images with subcluster= s. */ set_l2_entry(s, l2_slice, j, 0); l2_dirty =3D true; continue; @@ -2178,6 +2182,8 @@ static int expand_zero_clusters_in_l1(BlockDriverStat= e *bs, uint64_t *l1_table, } else { set_l2_entry(s, l2_slice, j, offset); } + /* No need to call set_l2_bitmap() after set_l2_entry() be= cause + * this function doesn't support images with subclusters. = */ l2_dirty =3D true; } =20 diff --git a/tests/qemu-iotests/061 b/tests/qemu-iotests/061 index 36b040491f..66bfd23179 100755 --- a/tests/qemu-iotests/061 +++ b/tests/qemu-iotests/061 @@ -266,6 +266,12 @@ $QEMU_IMG amend -o "compat=3D0.10" "$TEST_IMG" _img_info --format-specific _check_test_img =20 +echo +echo "=3D=3D=3D Testing version downgrade with extended L2 entries =3D=3D= =3D" +echo +_make_test_img -o "compat=3D1.1,extended_l2=3Don" 64M +$QEMU_IMG amend -o "compat=3D0.10" "$TEST_IMG" + echo echo "=3D=3D=3D Try changing the external data file =3D=3D=3D" echo diff --git a/tests/qemu-iotests/061.out b/tests/qemu-iotests/061.out index 8b3091a412..5d009867a2 100644 --- a/tests/qemu-iotests/061.out +++ b/tests/qemu-iotests/061.out @@ -498,6 +498,11 @@ Format specific information: corrupt: false No errors were found on the image. =20 +=3D=3D=3D Testing version downgrade with extended L2 entries =3D=3D=3D + +Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D67108864 +qemu-img: Cannot downgrade an image with incompatible features 0x10 set + =3D=3D=3D Try changing the external data file =3D=3D=3D =20 Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D67108864 --=20 2.20.1 From nobody Tue May 7 09:01:18 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1584470022; cv=none; d=zohomail.com; s=zohoarc; b=CDxQ2ymG5Sy1ofpboX1Zr+rcLEoM0gnxYVihw7Fiq2/EKIZ+eUlZQJAzoFfjSi91R9FYM1fzkOGoOJ8NlXvyZSZPL5nNhW9e30vZrc7HWYJSrQ0yhYaYUTZUiEHplxlgkMzLC78q+2YOfvDc2EmUhCecx+iZiKwj/aopF3ys4WQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1584470022; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=TAAbjr0iG92RAxAMVe6pdMpvy2C4Bt3jRPGa1Ug2hm0=; b=mVKlXP+DtMCVN+CIXff7YLLkjzzQt7YT2HrBXHiGAMtI9O5TGDjC5BD0reSAOd2cTRoa+nqGTiQ1le3J/vv2UNX04OFKHVL9ASX+lWY16J9Un5HmSxFzmf7hzzfO0V7d1TLJVC96pzrqOCggBGNsq89TWCcaemGHQydmTx9a/Sg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1584470022554193.22097235410695; Tue, 17 Mar 2020 11:33:42 -0700 (PDT) Received: from localhost ([::1]:39386 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEH25-0000su-4a for importer@patchew.org; Tue, 17 Mar 2020 14:33:41 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49152) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEGn6-0003nR-5d for qemu-devel@nongnu.org; Tue, 17 Mar 2020 14:18:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jEGmv-0000AS-E7 for qemu-devel@nongnu.org; Tue, 17 Mar 2020 14:18:12 -0400 Received: from fanzine.igalia.com ([178.60.130.6]:58014) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jEGmu-0005y9-4T; Tue, 17 Mar 2020 14:18:01 -0400 Received: from [81.0.35.138] (helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1jEGmD-000154-0q; Tue, 17 Mar 2020 19:17:17 +0100 Received: from berto by perseus.local with local (Exim 4.92) (envelope-from ) id 1jEGlw-0006Ox-WB; Tue, 17 Mar 2020 19:17:01 +0100 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=TAAbjr0iG92RAxAMVe6pdMpvy2C4Bt3jRPGa1Ug2hm0=; b=MK+VqoWeYi+YJRpWVHmgPnNjKFqW76mh6T4O4QOo6zx9+JcMkveFfvvoiInkUnnP2zDzXXhLkRby4PQf4pqcUwYR3yynp9qDL5ZmXbc8+/oxrh+N6nlaw0zxb0HlLdqJq/lzmJfS2BH5D05CWTFwWfGwiR8qQhEwiyv5kjYcxCk/NxyV6ZnpfjW+4ZpaEWU3118zFrnIVLXf1ZPb8ZDFBBknw+kkhjVtkKj3hyqyCN+e5/lhKSU9kgTUyh77YvQwxXjYrMhsvcr6sbeF/diSG70sgsA0sksxRaPpqaLXS+LacPcjF5fOmkK4Xkco3tv3p07qbfrnu9KL+FpIZ3AJVg==; From: Alberto Garcia To: qemu-devel@nongnu.org Subject: [PATCH v4 28/30] qcow2: Add the 'extended_l2' option and the QCOW2_INCOMPAT_EXTL2 bit Date: Tue, 17 Mar 2020 19:16:25 +0100 Message-Id: <3de25a8fec2085e835c0f167ad91f05bd9002fa4.1584468724.git.berto@igalia.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy] X-Received-From: 178.60.130.6 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Anton Nefedov , Alberto Garcia , qemu-block@nongnu.org, Max Reitz , Vladimir Sementsov-Ogievskiy , "Denis V . Lunev" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Now that the implementation of subclusters is complete we can finally add the necessary options to create and read images with this feature, which we call "extended L2 entries". Signed-off-by: Alberto Garcia Reviewed-by: Max Reitz --- qapi/block-core.json | 7 +++ block/qcow2.h | 8 ++- include/block/block_int.h | 1 + block/qcow2.c | 65 ++++++++++++++++++-- tests/qemu-iotests/031.out | 8 +-- tests/qemu-iotests/036.out | 4 +- tests/qemu-iotests/049.out | 102 +++++++++++++++---------------- tests/qemu-iotests/060.out | 1 + tests/qemu-iotests/061.out | 20 +++--- tests/qemu-iotests/065 | 18 ++++-- tests/qemu-iotests/082.out | 48 ++++++++++++--- tests/qemu-iotests/085.out | 38 ++++++------ tests/qemu-iotests/144.out | 4 +- tests/qemu-iotests/182.out | 2 +- tests/qemu-iotests/185.out | 8 +-- tests/qemu-iotests/198.out | 2 + tests/qemu-iotests/206.out | 4 ++ tests/qemu-iotests/242.out | 5 ++ tests/qemu-iotests/255.out | 8 +-- tests/qemu-iotests/280.out | 2 +- tests/qemu-iotests/common.filter | 1 + 21 files changed, 240 insertions(+), 116 deletions(-) diff --git a/qapi/block-core.json b/qapi/block-core.json index 91586fb1fb..6161d6c03a 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -66,6 +66,9 @@ # standalone (read-only) raw image without looking at qcow2 # metadata (since: 4.0) # +# @extended-l2: true if the image has extended L2 entries; only valid for +# compat >=3D 1.1 (since 5.0) +# # @lazy-refcounts: on or off; only valid for compat >=3D 1.1 # # @corrupt: true if the image has been marked corrupt; only valid for @@ -85,6 +88,7 @@ 'compat': 'str', '*data-file': 'str', '*data-file-raw': 'bool', + '*extended-l2': 'bool', '*lazy-refcounts': 'bool', '*corrupt': 'bool', 'refcount-bits': 'int', @@ -4270,6 +4274,8 @@ # @data-file-raw: True if the external data file must stay valid as a # standalone (read-only) raw image without looking at qcow2 # metadata (default: false; since: 4.0) +# @extended-l2 True to make the image have extended L2 entries +# (default: false; since 5.0) # @size: Size of the virtual disk in bytes # @version: Compatibility level (default: v3) # @backing-file: File name of the backing file if a backing file @@ -4288,6 +4294,7 @@ 'data': { 'file': 'BlockdevRef', '*data-file': 'BlockdevRef', '*data-file-raw': 'bool', + '*extended-l2': 'bool', 'size': 'size', '*version': 'BlockdevQcow2Version', '*backing-file': 'str', diff --git a/block/qcow2.h b/block/qcow2.h index 031ce823b3..a5506d66d0 100644 --- a/block/qcow2.h +++ b/block/qcow2.h @@ -231,13 +231,16 @@ enum { QCOW2_INCOMPAT_DIRTY_BITNR =3D 0, QCOW2_INCOMPAT_CORRUPT_BITNR =3D 1, QCOW2_INCOMPAT_DATA_FILE_BITNR =3D 2, + QCOW2_INCOMPAT_EXTL2_BITNR =3D 4, QCOW2_INCOMPAT_DIRTY =3D 1 << QCOW2_INCOMPAT_DIRTY_BITNR, QCOW2_INCOMPAT_CORRUPT =3D 1 << QCOW2_INCOMPAT_CORRUPT_BITNR, QCOW2_INCOMPAT_DATA_FILE =3D 1 << QCOW2_INCOMPAT_DATA_FILE_BITN= R, + QCOW2_INCOMPAT_EXTL2 =3D 1 << QCOW2_INCOMPAT_EXTL2_BITNR, =20 QCOW2_INCOMPAT_MASK =3D QCOW2_INCOMPAT_DIRTY | QCOW2_INCOMPAT_CORRUPT - | QCOW2_INCOMPAT_DATA_FILE, + | QCOW2_INCOMPAT_DATA_FILE + | QCOW2_INCOMPAT_EXTL2, }; =20 /* Compatible feature bits */ @@ -552,8 +555,7 @@ typedef enum QCow2MetadataOverlap { =20 static inline bool has_subclusters(BDRVQcow2State *s) { - /* FIXME: Return false until this feature is complete */ - return false; + return s->incompatible_features & QCOW2_INCOMPAT_EXTL2; } =20 static inline size_t l2_entry_size(BDRVQcow2State *s) diff --git a/include/block/block_int.h b/include/block/block_int.h index ae9c4da4d0..5c2d02de22 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -57,6 +57,7 @@ #define BLOCK_OPT_REFCOUNT_BITS "refcount_bits" #define BLOCK_OPT_DATA_FILE "data_file" #define BLOCK_OPT_DATA_FILE_RAW "data_file_raw" +#define BLOCK_OPT_EXTL2 "extended_l2" =20 #define BLOCK_PROBE_BUF_SIZE 512 =20 diff --git a/block/qcow2.c b/block/qcow2.c index d406ef355b..77b2713533 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -1385,6 +1385,12 @@ static int coroutine_fn qcow2_do_open(BlockDriverSta= te *bs, QDict *options, s->subcluster_size =3D s->cluster_size / s->subclusters_per_cluster; s->subcluster_bits =3D ctz32(s->subcluster_size); =20 + if (s->subcluster_size < (1 << MIN_CLUSTER_BITS)) { + error_setg(errp, "Unsupported subcluster size: %d", s->subcluster_= size); + ret =3D -EINVAL; + goto fail; + } + /* Check support for various header values */ if (header.refcount_order > 6) { error_setg(errp, "Reference count entry width too large; may not " @@ -2843,6 +2849,11 @@ int qcow2_update_header(BlockDriverState *bs) .bit =3D QCOW2_INCOMPAT_DATA_FILE_BITNR, .name =3D "external data file", }, + { + .type =3D QCOW2_FEAT_TYPE_INCOMPATIBLE, + .bit =3D QCOW2_INCOMPAT_EXTL2_BITNR, + .name =3D "extended L2 entries", + }, { .type =3D QCOW2_FEAT_TYPE_COMPATIBLE, .bit =3D QCOW2_COMPAT_LAZY_REFCOUNTS_BITNR, @@ -3176,7 +3187,8 @@ static int64_t qcow2_calc_prealloc_size(int64_t total= _size, return meta_size + aligned_total_size; } =20 -static bool validate_cluster_size(size_t cluster_size, Error **errp) +static bool validate_cluster_size(size_t cluster_size, bool extended_l2, + Error **errp) { int cluster_bits =3D ctz32(cluster_size); if (cluster_bits < MIN_CLUSTER_BITS || cluster_bits > MAX_CLUSTER_BITS= || @@ -3186,16 +3198,28 @@ static bool validate_cluster_size(size_t cluster_si= ze, Error **errp) "%dk", 1 << MIN_CLUSTER_BITS, 1 << (MAX_CLUSTER_BITS - = 10)); return false; } + + if (extended_l2) { + unsigned min_cluster_size =3D + (1 << MIN_CLUSTER_BITS) * QCOW_EXTL2_SUBCLUSTERS_PER_CLUSTER; + if (cluster_size < min_cluster_size) { + error_setg(errp, "Extended L2 entries are only supported with " + "cluster sizes of at least %u bytes", min_cluster_s= ize); + return false; + } + } + return true; } =20 -static size_t qcow2_opt_get_cluster_size_del(QemuOpts *opts, Error **errp) +static size_t qcow2_opt_get_cluster_size_del(QemuOpts *opts, bool extended= _l2, + Error **errp) { size_t cluster_size; =20 cluster_size =3D qemu_opt_get_size_del(opts, BLOCK_OPT_CLUSTER_SIZE, DEFAULT_CLUSTER_SIZE); - if (!validate_cluster_size(cluster_size, errp)) { + if (!validate_cluster_size(cluster_size, extended_l2, errp)) { return 0; } return cluster_size; @@ -3309,7 +3333,20 @@ qcow2_co_create(BlockdevCreateOptions *create_option= s, Error **errp) cluster_size =3D DEFAULT_CLUSTER_SIZE; } =20 - if (!validate_cluster_size(cluster_size, errp)) { + if (!qcow2_opts->has_extended_l2) { + qcow2_opts->extended_l2 =3D false; + } + if (qcow2_opts->extended_l2) { + if (version < 3) { + error_setg(errp, "Extended L2 entries are only supported with " + "compatibility level 1.1 and above (use version=3Dv= 3 or " + "greater)"); + ret =3D -EINVAL; + goto out; + } + } + + if (!validate_cluster_size(cluster_size, qcow2_opts->extended_l2, errp= )) { ret =3D -EINVAL; goto out; } @@ -3429,6 +3466,11 @@ qcow2_co_create(BlockdevCreateOptions *create_option= s, Error **errp) cpu_to_be64(QCOW2_AUTOCLEAR_DATA_FILE_RAW); } =20 + if (qcow2_opts->extended_l2) { + header->incompatible_features |=3D + cpu_to_be64(QCOW2_INCOMPAT_EXTL2); + } + ret =3D blk_pwrite(blk, 0, header, cluster_size, 0); g_free(header); if (ret < 0) { @@ -3607,6 +3649,7 @@ static int coroutine_fn qcow2_co_create_opts(const ch= ar *filename, QemuOpts *opt { BLOCK_OPT_BACKING_FMT, "backing-fmt" }, { BLOCK_OPT_CLUSTER_SIZE, "cluster-size" }, { BLOCK_OPT_LAZY_REFCOUNTS, "lazy-refcounts" }, + { BLOCK_OPT_EXTL2, "extended-l2" }, { BLOCK_OPT_REFCOUNT_BITS, "refcount-bits" }, { BLOCK_OPT_ENCRYPT, BLOCK_OPT_ENCRYPT_FORMAT }, { BLOCK_OPT_COMPAT_LEVEL, "version" }, @@ -4636,9 +4679,13 @@ static BlockMeasureInfo *qcow2_measure(QemuOpts *opt= s, BlockDriverState *in_bs, PreallocMode prealloc; bool has_backing_file; bool has_luks; + bool extended_l2; =20 /* Parse image creation options */ - cluster_size =3D qcow2_opt_get_cluster_size_del(opts, &local_err); + extended_l2 =3D qemu_opt_get_bool_del(opts, BLOCK_OPT_EXTL2, false); + + cluster_size =3D qcow2_opt_get_cluster_size_del(opts, extended_l2, + &local_err); if (local_err) { goto err; } @@ -4832,6 +4879,8 @@ static ImageInfoSpecific *qcow2_get_specific_info(Blo= ckDriverState *bs, .corrupt =3D s->incompatible_features & QCOW2_INCOMPAT_CORRUPT, .has_corrupt =3D true, + .has_extended_l2 =3D true, + .extended_l2 =3D has_subclusters(s), .refcount_bits =3D s->refcount_bits, .has_bitmaps =3D !!bitmaps, .bitmaps =3D bitmaps, @@ -5490,6 +5539,12 @@ static QemuOptsList qcow2_create_opts =3D { .help =3D "Postpone refcount updates", .def_value_str =3D "off" }, + { + .name =3D BLOCK_OPT_EXTL2, + .type =3D QEMU_OPT_BOOL, + .help =3D "Extended L2 tables", + .def_value_str =3D "off" + }, { .name =3D BLOCK_OPT_REFCOUNT_BITS, .type =3D QEMU_OPT_NUMBER, diff --git a/tests/qemu-iotests/031.out b/tests/qemu-iotests/031.out index d535e407bc..d9cfdad79b 100644 --- a/tests/qemu-iotests/031.out +++ b/tests/qemu-iotests/031.out @@ -117,7 +117,7 @@ header_length 104 =20 Header extension: magic 0x6803f857 -length 192 +length 240 data =20 Header extension: @@ -150,7 +150,7 @@ header_length 104 =20 Header extension: magic 0x6803f857 -length 192 +length 240 data =20 Header extension: @@ -164,7 +164,7 @@ No errors were found on the image. =20 magic 0x514649fb version 3 -backing_file_offset 0x178 +backing_file_offset 0x1a8 backing_file_size 0x17 cluster_bits 16 size 67108864 @@ -188,7 +188,7 @@ data 'host_device' =20 Header extension: magic 0x6803f857 -length 192 +length 240 data =20 Header extension: diff --git a/tests/qemu-iotests/036.out b/tests/qemu-iotests/036.out index 0b52b934e1..fb509f6357 100644 --- a/tests/qemu-iotests/036.out +++ b/tests/qemu-iotests/036.out @@ -26,7 +26,7 @@ compatible_features [] autoclear_features [63] Header extension: magic 0x6803f857 -length 192 +length 240 data =20 =20 @@ -38,7 +38,7 @@ compatible_features [] autoclear_features [] Header extension: magic 0x6803f857 -length 192 +length 240 data =20 *** done diff --git a/tests/qemu-iotests/049.out b/tests/qemu-iotests/049.out index affa55b341..191637dfaf 100644 --- a/tests/qemu-iotests/049.out +++ b/tests/qemu-iotests/049.out @@ -4,90 +4,90 @@ QA output created by 049 =3D=3D 1. Traditional size parameter =3D=3D =20 qemu-img create -f qcow2 TEST_DIR/t.qcow2 1024 -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1024 cluster_size=3D6553= 6 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1024 cluster_size=3D6553= 6 lazy_refcounts=3Doff extended_l2=3Doff refcount_bits=3D16 =20 qemu-img create -f qcow2 TEST_DIR/t.qcow2 1024b -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1024 cluster_size=3D6553= 6 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1024 cluster_size=3D6553= 6 lazy_refcounts=3Doff extended_l2=3Doff refcount_bits=3D16 =20 qemu-img create -f qcow2 TEST_DIR/t.qcow2 1k -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1024 cluster_size=3D6553= 6 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1024 cluster_size=3D6553= 6 lazy_refcounts=3Doff extended_l2=3Doff refcount_bits=3D16 =20 qemu-img create -f qcow2 TEST_DIR/t.qcow2 1K -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1024 cluster_size=3D6553= 6 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1024 cluster_size=3D6553= 6 lazy_refcounts=3Doff extended_l2=3Doff refcount_bits=3D16 =20 qemu-img create -f qcow2 TEST_DIR/t.qcow2 1M -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1048576 cluster_size=3D6= 5536 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1048576 cluster_size=3D6= 5536 lazy_refcounts=3Doff extended_l2=3Doff refcount_bits=3D16 =20 qemu-img create -f qcow2 TEST_DIR/t.qcow2 1G -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1073741824 cluster_size= =3D65536 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1073741824 cluster_size= =3D65536 lazy_refcounts=3Doff extended_l2=3Doff refcount_bits=3D16 =20 qemu-img create -f qcow2 TEST_DIR/t.qcow2 1T -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1099511627776 cluster_si= ze=3D65536 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1099511627776 cluster_si= ze=3D65536 lazy_refcounts=3Doff extended_l2=3Doff refcount_bits=3D16 =20 qemu-img create -f qcow2 TEST_DIR/t.qcow2 1024.0 -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1024 cluster_size=3D6553= 6 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1024 cluster_size=3D6553= 6 lazy_refcounts=3Doff extended_l2=3Doff refcount_bits=3D16 =20 qemu-img create -f qcow2 TEST_DIR/t.qcow2 1024.0b -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1024 cluster_size=3D6553= 6 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1024 cluster_size=3D6553= 6 lazy_refcounts=3Doff extended_l2=3Doff refcount_bits=3D16 =20 qemu-img create -f qcow2 TEST_DIR/t.qcow2 1.5k -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1536 cluster_size=3D6553= 6 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1536 cluster_size=3D6553= 6 lazy_refcounts=3Doff extended_l2=3Doff refcount_bits=3D16 =20 qemu-img create -f qcow2 TEST_DIR/t.qcow2 1.5K -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1536 cluster_size=3D6553= 6 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1536 cluster_size=3D6553= 6 lazy_refcounts=3Doff extended_l2=3Doff refcount_bits=3D16 =20 qemu-img create -f qcow2 TEST_DIR/t.qcow2 1.5M -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1572864 cluster_size=3D6= 5536 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1572864 cluster_size=3D6= 5536 lazy_refcounts=3Doff extended_l2=3Doff refcount_bits=3D16 =20 qemu-img create -f qcow2 TEST_DIR/t.qcow2 1.5G -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1610612736 cluster_size= =3D65536 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1610612736 cluster_size= =3D65536 lazy_refcounts=3Doff extended_l2=3Doff refcount_bits=3D16 =20 qemu-img create -f qcow2 TEST_DIR/t.qcow2 1.5T -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1649267441664 cluster_si= ze=3D65536 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1649267441664 cluster_si= ze=3D65536 lazy_refcounts=3Doff extended_l2=3Doff refcount_bits=3D16 =20 =3D=3D 2. Specifying size via -o =3D=3D =20 qemu-img create -f qcow2 -o size=3D1024 TEST_DIR/t.qcow2 -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1024 cluster_size=3D6553= 6 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1024 cluster_size=3D6553= 6 lazy_refcounts=3Doff extended_l2=3Doff refcount_bits=3D16 =20 qemu-img create -f qcow2 -o size=3D1024b TEST_DIR/t.qcow2 -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1024 cluster_size=3D6553= 6 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1024 cluster_size=3D6553= 6 lazy_refcounts=3Doff extended_l2=3Doff refcount_bits=3D16 =20 qemu-img create -f qcow2 -o size=3D1k TEST_DIR/t.qcow2 -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1024 cluster_size=3D6553= 6 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1024 cluster_size=3D6553= 6 lazy_refcounts=3Doff extended_l2=3Doff refcount_bits=3D16 =20 qemu-img create -f qcow2 -o size=3D1K TEST_DIR/t.qcow2 -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1024 cluster_size=3D6553= 6 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1024 cluster_size=3D6553= 6 lazy_refcounts=3Doff extended_l2=3Doff refcount_bits=3D16 =20 qemu-img create -f qcow2 -o size=3D1M TEST_DIR/t.qcow2 -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1048576 cluster_size=3D6= 5536 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1048576 cluster_size=3D6= 5536 lazy_refcounts=3Doff extended_l2=3Doff refcount_bits=3D16 =20 qemu-img create -f qcow2 -o size=3D1G TEST_DIR/t.qcow2 -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1073741824 cluster_size= =3D65536 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1073741824 cluster_size= =3D65536 lazy_refcounts=3Doff extended_l2=3Doff refcount_bits=3D16 =20 qemu-img create -f qcow2 -o size=3D1T TEST_DIR/t.qcow2 -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1099511627776 cluster_si= ze=3D65536 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1099511627776 cluster_si= ze=3D65536 lazy_refcounts=3Doff extended_l2=3Doff refcount_bits=3D16 =20 qemu-img create -f qcow2 -o size=3D1024.0 TEST_DIR/t.qcow2 -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1024 cluster_size=3D6553= 6 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1024 cluster_size=3D6553= 6 lazy_refcounts=3Doff extended_l2=3Doff refcount_bits=3D16 =20 qemu-img create -f qcow2 -o size=3D1024.0b TEST_DIR/t.qcow2 -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1024 cluster_size=3D6553= 6 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1024 cluster_size=3D6553= 6 lazy_refcounts=3Doff extended_l2=3Doff refcount_bits=3D16 =20 qemu-img create -f qcow2 -o size=3D1.5k TEST_DIR/t.qcow2 -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1536 cluster_size=3D6553= 6 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1536 cluster_size=3D6553= 6 lazy_refcounts=3Doff extended_l2=3Doff refcount_bits=3D16 =20 qemu-img create -f qcow2 -o size=3D1.5K TEST_DIR/t.qcow2 -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1536 cluster_size=3D6553= 6 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1536 cluster_size=3D6553= 6 lazy_refcounts=3Doff extended_l2=3Doff refcount_bits=3D16 =20 qemu-img create -f qcow2 -o size=3D1.5M TEST_DIR/t.qcow2 -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1572864 cluster_size=3D6= 5536 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1572864 cluster_size=3D6= 5536 lazy_refcounts=3Doff extended_l2=3Doff refcount_bits=3D16 =20 qemu-img create -f qcow2 -o size=3D1.5G TEST_DIR/t.qcow2 -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1610612736 cluster_size= =3D65536 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1610612736 cluster_size= =3D65536 lazy_refcounts=3Doff extended_l2=3Doff refcount_bits=3D16 =20 qemu-img create -f qcow2 -o size=3D1.5T TEST_DIR/t.qcow2 -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1649267441664 cluster_si= ze=3D65536 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1649267441664 cluster_si= ze=3D65536 lazy_refcounts=3Doff extended_l2=3Doff refcount_bits=3D16 =20 =3D=3D 3. Invalid sizes =3D=3D =20 @@ -129,84 +129,84 @@ qemu-img: TEST_DIR/t.qcow2: The image size must be sp= ecified only once =3D=3D Check correct interpretation of suffixes for cluster size =3D=3D =20 qemu-img create -f qcow2 -o cluster_size=3D1024 TEST_DIR/t.qcow2 64M -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D67108864 cluster_size=3D= 1024 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D67108864 cluster_size=3D= 1024 lazy_refcounts=3Doff extended_l2=3Doff refcount_bits=3D16 =20 qemu-img create -f qcow2 -o cluster_size=3D1024b TEST_DIR/t.qcow2 64M -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D67108864 cluster_size=3D= 1024 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D67108864 cluster_size=3D= 1024 lazy_refcounts=3Doff extended_l2=3Doff refcount_bits=3D16 =20 qemu-img create -f qcow2 -o cluster_size=3D1k TEST_DIR/t.qcow2 64M -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D67108864 cluster_size=3D= 1024 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D67108864 cluster_size=3D= 1024 lazy_refcounts=3Doff extended_l2=3Doff refcount_bits=3D16 =20 qemu-img create -f qcow2 -o cluster_size=3D1K TEST_DIR/t.qcow2 64M -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D67108864 cluster_size=3D= 1024 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D67108864 cluster_size=3D= 1024 lazy_refcounts=3Doff extended_l2=3Doff refcount_bits=3D16 =20 qemu-img create -f qcow2 -o cluster_size=3D1M TEST_DIR/t.qcow2 64M -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D67108864 cluster_size=3D= 1048576 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D67108864 cluster_size=3D= 1048576 lazy_refcounts=3Doff extended_l2=3Doff refcount_bits=3D16 =20 qemu-img create -f qcow2 -o cluster_size=3D1024.0 TEST_DIR/t.qcow2 64M -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D67108864 cluster_size=3D= 1024 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D67108864 cluster_size=3D= 1024 lazy_refcounts=3Doff extended_l2=3Doff refcount_bits=3D16 =20 qemu-img create -f qcow2 -o cluster_size=3D1024.0b TEST_DIR/t.qcow2 64M -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D67108864 cluster_size=3D= 1024 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D67108864 cluster_size=3D= 1024 lazy_refcounts=3Doff extended_l2=3Doff refcount_bits=3D16 =20 qemu-img create -f qcow2 -o cluster_size=3D0.5k TEST_DIR/t.qcow2 64M -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D67108864 cluster_size=3D= 512 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D67108864 cluster_size=3D= 512 lazy_refcounts=3Doff extended_l2=3Doff refcount_bits=3D16 =20 qemu-img create -f qcow2 -o cluster_size=3D0.5K TEST_DIR/t.qcow2 64M -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D67108864 cluster_size=3D= 512 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D67108864 cluster_size=3D= 512 lazy_refcounts=3Doff extended_l2=3Doff refcount_bits=3D16 =20 qemu-img create -f qcow2 -o cluster_size=3D0.5M TEST_DIR/t.qcow2 64M -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D67108864 cluster_size=3D= 524288 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D67108864 cluster_size=3D= 524288 lazy_refcounts=3Doff extended_l2=3Doff refcount_bits=3D16 =20 =3D=3D Check compat level option =3D=3D =20 qemu-img create -f qcow2 -o compat=3D0.10 TEST_DIR/t.qcow2 64M -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D67108864 compat=3D0.10 c= luster_size=3D65536 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D67108864 compat=3D0.10 c= luster_size=3D65536 lazy_refcounts=3Doff extended_l2=3Doff refcount_bits=3D= 16 =20 qemu-img create -f qcow2 -o compat=3D1.1 TEST_DIR/t.qcow2 64M -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D67108864 compat=3D1.1 cl= uster_size=3D65536 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D67108864 compat=3D1.1 cl= uster_size=3D65536 lazy_refcounts=3Doff extended_l2=3Doff refcount_bits=3D16 =20 qemu-img create -f qcow2 -o compat=3D0.42 TEST_DIR/t.qcow2 64M qemu-img: TEST_DIR/t.qcow2: Invalid parameter '0.42' -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D67108864 compat=3D0.42 c= luster_size=3D65536 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D67108864 compat=3D0.42 c= luster_size=3D65536 lazy_refcounts=3Doff extended_l2=3Doff refcount_bits=3D= 16 =20 qemu-img create -f qcow2 -o compat=3Dfoobar TEST_DIR/t.qcow2 64M qemu-img: TEST_DIR/t.qcow2: Invalid parameter 'foobar' -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D67108864 compat=3Dfoobar= cluster_size=3D65536 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D67108864 compat=3Dfoobar= cluster_size=3D65536 lazy_refcounts=3Doff extended_l2=3Doff refcount_bits= =3D16 =20 =3D=3D Check preallocation option =3D=3D =20 qemu-img create -f qcow2 -o preallocation=3Doff TEST_DIR/t.qcow2 64M -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D67108864 cluster_size=3D= 65536 preallocation=3Doff lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D67108864 cluster_size=3D= 65536 preallocation=3Doff lazy_refcounts=3Doff extended_l2=3Doff refcount_b= its=3D16 =20 qemu-img create -f qcow2 -o preallocation=3Dmetadata TEST_DIR/t.qcow2 64M -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D67108864 cluster_size=3D= 65536 preallocation=3Dmetadata lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D67108864 cluster_size=3D= 65536 preallocation=3Dmetadata lazy_refcounts=3Doff extended_l2=3Doff refco= unt_bits=3D16 =20 qemu-img create -f qcow2 -o preallocation=3D1234 TEST_DIR/t.qcow2 64M qemu-img: TEST_DIR/t.qcow2: Invalid parameter '1234' -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D67108864 cluster_size=3D= 65536 preallocation=3D1234 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D67108864 cluster_size=3D= 65536 preallocation=3D1234 lazy_refcounts=3Doff extended_l2=3Doff refcount_= bits=3D16 =20 =3D=3D Check encryption option =3D=3D =20 qemu-img create -f qcow2 -o encryption=3Doff TEST_DIR/t.qcow2 64M -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D67108864 encryption=3Dof= f cluster_size=3D65536 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D67108864 encryption=3Dof= f cluster_size=3D65536 lazy_refcounts=3Doff extended_l2=3Doff refcount_bits= =3D16 =20 qemu-img create -f qcow2 --object secret,id=3Dsec0,data=3D123456 -o encryp= tion=3Don,encrypt.key-secret=3Dsec0 TEST_DIR/t.qcow2 64M -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D67108864 encryption=3Don= encrypt.key-secret=3Dsec0 cluster_size=3D65536 lazy_refcounts=3Doff refcou= nt_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D67108864 encryption=3Don= encrypt.key-secret=3Dsec0 cluster_size=3D65536 lazy_refcounts=3Doff extend= ed_l2=3Doff refcount_bits=3D16 =20 =3D=3D Check lazy_refcounts option (only with v3) =3D=3D =20 qemu-img create -f qcow2 -o compat=3D1.1,lazy_refcounts=3Doff TEST_DIR/t.q= cow2 64M -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D67108864 compat=3D1.1 cl= uster_size=3D65536 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D67108864 compat=3D1.1 cl= uster_size=3D65536 lazy_refcounts=3Doff extended_l2=3Doff refcount_bits=3D16 =20 qemu-img create -f qcow2 -o compat=3D1.1,lazy_refcounts=3Don TEST_DIR/t.qc= ow2 64M -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D67108864 compat=3D1.1 cl= uster_size=3D65536 lazy_refcounts=3Don refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D67108864 compat=3D1.1 cl= uster_size=3D65536 lazy_refcounts=3Don extended_l2=3Doff refcount_bits=3D16 =20 qemu-img create -f qcow2 -o compat=3D0.10,lazy_refcounts=3Doff TEST_DIR/t.= qcow2 64M -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D67108864 compat=3D0.10 c= luster_size=3D65536 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D67108864 compat=3D0.10 c= luster_size=3D65536 lazy_refcounts=3Doff extended_l2=3Doff refcount_bits=3D= 16 =20 qemu-img create -f qcow2 -o compat=3D0.10,lazy_refcounts=3Don TEST_DIR/t.q= cow2 64M qemu-img: TEST_DIR/t.qcow2: Lazy refcounts only supported with compatibili= ty level 1.1 and above (use version=3Dv3 or greater) -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D67108864 compat=3D0.10 c= luster_size=3D65536 lazy_refcounts=3Don refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D67108864 compat=3D0.10 c= luster_size=3D65536 lazy_refcounts=3Don extended_l2=3Doff refcount_bits=3D16 =20 *** done diff --git a/tests/qemu-iotests/060.out b/tests/qemu-iotests/060.out index d27692a33c..8c56e5f062 100644 --- a/tests/qemu-iotests/060.out +++ b/tests/qemu-iotests/060.out @@ -20,6 +20,7 @@ Format specific information: lazy refcounts: false refcount bits: 16 corrupt: true + extended l2: false qemu-io: can't open device TEST_DIR/t.IMGFMT: IMGFMT: Image is corrupt; ca= nnot be opened read/write no file open, try 'help open' read 512/512 bytes at offset 0 diff --git a/tests/qemu-iotests/061.out b/tests/qemu-iotests/061.out index 5d009867a2..4390458bf5 100644 --- a/tests/qemu-iotests/061.out +++ b/tests/qemu-iotests/061.out @@ -26,7 +26,7 @@ header_length 104 =20 Header extension: magic 0x6803f857 -length 192 +length 240 data =20 magic 0x514649fb @@ -84,7 +84,7 @@ header_length 104 =20 Header extension: magic 0x6803f857 -length 192 +length 240 data =20 magic 0x514649fb @@ -140,7 +140,7 @@ header_length 104 =20 Header extension: magic 0x6803f857 -length 192 +length 240 data =20 ERROR cluster 5 refcount=3D0 reference=3D1 @@ -195,7 +195,7 @@ header_length 104 =20 Header extension: magic 0x6803f857 -length 192 +length 240 data =20 magic 0x514649fb @@ -264,7 +264,7 @@ header_length 104 =20 Header extension: magic 0x6803f857 -length 192 +length 240 data =20 read 65536/65536 bytes at offset 44040192 @@ -298,7 +298,7 @@ header_length 104 =20 Header extension: magic 0x6803f857 -length 192 +length 240 data =20 ERROR cluster 5 refcount=3D0 reference=3D1 @@ -327,7 +327,7 @@ header_length 104 =20 Header extension: magic 0x6803f857 -length 192 +length 240 data =20 read 131072/131072 bytes at offset 0 @@ -496,6 +496,7 @@ Format specific information: data file: TEST_DIR/t.IMGFMT.data data file raw: false corrupt: false + extended l2: false No errors were found on the image. =20 =3D=3D=3D Testing version downgrade with extended L2 entries =3D=3D=3D @@ -521,6 +522,7 @@ Format specific information: data file: foo data file raw: false corrupt: false + extended l2: false =20 qemu-img: Could not open 'TEST_DIR/t.IMGFMT': 'data-file' is required for = this image image: TEST_DIR/t.IMGFMT @@ -533,6 +535,7 @@ Format specific information: refcount bits: 16 data file raw: false corrupt: false + extended l2: false =20 =3D=3D=3D Clearing and setting data-file-raw =3D=3D=3D =20 @@ -548,6 +551,7 @@ Format specific information: data file: TEST_DIR/t.IMGFMT.data data file raw: true corrupt: false + extended l2: false No errors were found on the image. image: TEST_DIR/t.IMGFMT file format: IMGFMT @@ -560,6 +564,7 @@ Format specific information: data file: TEST_DIR/t.IMGFMT.data data file raw: false corrupt: false + extended l2: false No errors were found on the image. qemu-img: data-file-raw cannot be set on existing images image: TEST_DIR/t.IMGFMT @@ -573,5 +578,6 @@ Format specific information: data file: TEST_DIR/t.IMGFMT.data data file raw: false corrupt: false + extended l2: false No errors were found on the image. *** done diff --git a/tests/qemu-iotests/065 b/tests/qemu-iotests/065 index 6426474271..386add05ae 100755 --- a/tests/qemu-iotests/065 +++ b/tests/qemu-iotests/065 @@ -95,17 +95,21 @@ class TestQCow3NotLazy(TestQemuImgInfo): '''Testing a qcow2 version 3 image with lazy refcounts disabled''' img_options =3D 'compat=3D1.1,lazy_refcounts=3Doff' json_compare =3D { 'compat': '1.1', 'lazy-refcounts': False, - 'refcount-bits': 16, 'corrupt': False } + 'refcount-bits': 16, 'corrupt': False, + 'extended-l2': False } human_compare =3D [ 'compat: 1.1', 'lazy refcounts: false', - 'refcount bits: 16', 'corrupt: false' ] + 'refcount bits: 16', 'corrupt: false', + 'extended l2: false' ] =20 class TestQCow3Lazy(TestQemuImgInfo): '''Testing a qcow2 version 3 image with lazy refcounts enabled''' img_options =3D 'compat=3D1.1,lazy_refcounts=3Don' json_compare =3D { 'compat': '1.1', 'lazy-refcounts': True, - 'refcount-bits': 16, 'corrupt': False } + 'refcount-bits': 16, 'corrupt': False, + 'extended-l2': False } human_compare =3D [ 'compat: 1.1', 'lazy refcounts: true', - 'refcount bits: 16', 'corrupt: false' ] + 'refcount bits: 16', 'corrupt: false', + 'extended l2: false' ] =20 class TestQCow3NotLazyQMP(TestQMP): '''Testing a qcow2 version 3 image with lazy refcounts disabled, openi= ng @@ -113,7 +117,8 @@ class TestQCow3NotLazyQMP(TestQMP): img_options =3D 'compat=3D1.1,lazy_refcounts=3Doff' qemu_options =3D 'lazy-refcounts=3Don' compare =3D { 'compat': '1.1', 'lazy-refcounts': False, - 'refcount-bits': 16, 'corrupt': False } + 'refcount-bits': 16, 'corrupt': False, + 'extended-l2': False } =20 =20 class TestQCow3LazyQMP(TestQMP): @@ -122,7 +127,8 @@ class TestQCow3LazyQMP(TestQMP): img_options =3D 'compat=3D1.1,lazy_refcounts=3Don' qemu_options =3D 'lazy-refcounts=3Doff' compare =3D { 'compat': '1.1', 'lazy-refcounts': True, - 'refcount-bits': 16, 'corrupt': False } + 'refcount-bits': 16, 'corrupt': False, + 'extended-l2': False } =20 TestImageInfoSpecific =3D None TestQemuImgInfo =3D None diff --git a/tests/qemu-iotests/082.out b/tests/qemu-iotests/082.out index 9d4ed4dc9d..2a01e8bac2 100644 --- a/tests/qemu-iotests/082.out +++ b/tests/qemu-iotests/082.out @@ -3,14 +3,14 @@ QA output created by 082 =3D=3D=3D create: Options specified more than once =3D=3D=3D =20 Testing: create -f foo -f qcow2 TEST_DIR/t.qcow2 128M -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D134217728 cluster_size= =3D65536 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D134217728 cluster_size= =3D65536 lazy_refcounts=3Doff extended_l2=3Doff refcount_bits=3D16 image: TEST_DIR/t.IMGFMT file format: IMGFMT virtual size: 128 MiB (134217728 bytes) cluster_size: 65536 =20 Testing: create -f qcow2 -o cluster_size=3D4k -o lazy_refcounts=3Don TEST_= DIR/t.qcow2 128M -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D134217728 cluster_size= =3D4096 lazy_refcounts=3Don refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D134217728 cluster_size= =3D4096 lazy_refcounts=3Don extended_l2=3Doff refcount_bits=3D16 image: TEST_DIR/t.IMGFMT file format: IMGFMT virtual size: 128 MiB (134217728 bytes) @@ -20,9 +20,10 @@ Format specific information: lazy refcounts: true refcount bits: 16 corrupt: false + extended l2: false =20 Testing: create -f qcow2 -o cluster_size=3D4k -o lazy_refcounts=3Don -o cl= uster_size=3D8k TEST_DIR/t.qcow2 128M -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D134217728 cluster_size= =3D8192 lazy_refcounts=3Don refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D134217728 cluster_size= =3D8192 lazy_refcounts=3Don extended_l2=3Doff refcount_bits=3D16 image: TEST_DIR/t.IMGFMT file format: IMGFMT virtual size: 128 MiB (134217728 bytes) @@ -32,9 +33,10 @@ Format specific information: lazy refcounts: true refcount bits: 16 corrupt: false + extended l2: false =20 Testing: create -f qcow2 -o cluster_size=3D4k,cluster_size=3D8k TEST_DIR/t= .qcow2 128M -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D134217728 cluster_size= =3D8192 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D134217728 cluster_size= =3D8192 lazy_refcounts=3Doff extended_l2=3Doff refcount_bits=3D16 image: TEST_DIR/t.IMGFMT file format: IMGFMT virtual size: 128 MiB (134217728 bytes) @@ -59,6 +61,7 @@ Supported options: encrypt.ivgen-hash-alg=3D - Name of IV generator hash algorithm encrypt.key-secret=3D - ID of secret providing qcow AES key or LUKS= passphrase encryption=3D - Encrypt the image with format 'aes'. (Dep= recated in favor of encrypt.format=3Daes) + extended_l2=3D - Extended L2 tables lazy_refcounts=3D - Postpone refcount updates nocow=3D - Turn off copy-on-write (valid only on btrfs) preallocation=3D - Preallocation mode (allowed values: off, meta= data, falloc, full) @@ -82,6 +85,7 @@ Supported options: encrypt.ivgen-hash-alg=3D - Name of IV generator hash algorithm encrypt.key-secret=3D - ID of secret providing qcow AES key or LUKS= passphrase encryption=3D - Encrypt the image with format 'aes'. (Dep= recated in favor of encrypt.format=3Daes) + extended_l2=3D - Extended L2 tables lazy_refcounts=3D - Postpone refcount updates nocow=3D - Turn off copy-on-write (valid only on btrfs) preallocation=3D - Preallocation mode (allowed values: off, meta= data, falloc, full) @@ -105,6 +109,7 @@ Supported options: encrypt.ivgen-hash-alg=3D - Name of IV generator hash algorithm encrypt.key-secret=3D - ID of secret providing qcow AES key or LUKS= passphrase encryption=3D - Encrypt the image with format 'aes'. (Dep= recated in favor of encrypt.format=3Daes) + extended_l2=3D - Extended L2 tables lazy_refcounts=3D - Postpone refcount updates nocow=3D - Turn off copy-on-write (valid only on btrfs) preallocation=3D - Preallocation mode (allowed values: off, meta= data, falloc, full) @@ -128,6 +133,7 @@ Supported options: encrypt.ivgen-hash-alg=3D - Name of IV generator hash algorithm encrypt.key-secret=3D - ID of secret providing qcow AES key or LUKS= passphrase encryption=3D - Encrypt the image with format 'aes'. (Dep= recated in favor of encrypt.format=3Daes) + extended_l2=3D - Extended L2 tables lazy_refcounts=3D - Postpone refcount updates nocow=3D - Turn off copy-on-write (valid only on btrfs) preallocation=3D - Preallocation mode (allowed values: off, meta= data, falloc, full) @@ -151,6 +157,7 @@ Supported options: encrypt.ivgen-hash-alg=3D - Name of IV generator hash algorithm encrypt.key-secret=3D - ID of secret providing qcow AES key or LUKS= passphrase encryption=3D - Encrypt the image with format 'aes'. (Dep= recated in favor of encrypt.format=3Daes) + extended_l2=3D - Extended L2 tables lazy_refcounts=3D - Postpone refcount updates nocow=3D - Turn off copy-on-write (valid only on btrfs) preallocation=3D - Preallocation mode (allowed values: off, meta= data, falloc, full) @@ -174,6 +181,7 @@ Supported options: encrypt.ivgen-hash-alg=3D - Name of IV generator hash algorithm encrypt.key-secret=3D - ID of secret providing qcow AES key or LUKS= passphrase encryption=3D - Encrypt the image with format 'aes'. (Dep= recated in favor of encrypt.format=3Daes) + extended_l2=3D - Extended L2 tables lazy_refcounts=3D - Postpone refcount updates nocow=3D - Turn off copy-on-write (valid only on btrfs) preallocation=3D - Preallocation mode (allowed values: off, meta= data, falloc, full) @@ -197,6 +205,7 @@ Supported options: encrypt.ivgen-hash-alg=3D - Name of IV generator hash algorithm encrypt.key-secret=3D - ID of secret providing qcow AES key or LUKS= passphrase encryption=3D - Encrypt the image with format 'aes'. (Dep= recated in favor of encrypt.format=3Daes) + extended_l2=3D - Extended L2 tables lazy_refcounts=3D - Postpone refcount updates nocow=3D - Turn off copy-on-write (valid only on btrfs) preallocation=3D - Preallocation mode (allowed values: off, meta= data, falloc, full) @@ -220,6 +229,7 @@ Supported options: encrypt.ivgen-hash-alg=3D - Name of IV generator hash algorithm encrypt.key-secret=3D - ID of secret providing qcow AES key or LUKS= passphrase encryption=3D - Encrypt the image with format 'aes'. (Dep= recated in favor of encrypt.format=3Daes) + extended_l2=3D - Extended L2 tables lazy_refcounts=3D - Postpone refcount updates nocow=3D - Turn off copy-on-write (valid only on btrfs) preallocation=3D - Preallocation mode (allowed values: off, meta= data, falloc, full) @@ -227,10 +237,10 @@ Supported options: size=3D - Virtual disk size =20 Testing: create -f qcow2 -u -o backing_file=3DTEST_DIR/t.qcow2,,help TEST_= DIR/t.qcow2 128M -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D134217728 backing_file= =3DTEST_DIR/t.qcow2,,help cluster_size=3D65536 lazy_refcounts=3Doff refcoun= t_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D134217728 backing_file= =3DTEST_DIR/t.qcow2,,help cluster_size=3D65536 lazy_refcounts=3Doff extende= d_l2=3Doff refcount_bits=3D16 =20 Testing: create -f qcow2 -u -o backing_file=3DTEST_DIR/t.qcow2,,? TEST_DIR= /t.qcow2 128M -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D134217728 backing_file= =3DTEST_DIR/t.qcow2,,? cluster_size=3D65536 lazy_refcounts=3Doff refcount_b= its=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D134217728 backing_file= =3DTEST_DIR/t.qcow2,,? cluster_size=3D65536 lazy_refcounts=3Doff extended_l= 2=3Doff refcount_bits=3D16 =20 Testing: create -f qcow2 -o backing_file=3DTEST_DIR/t.qcow2, -o help TEST_= DIR/t.qcow2 128M qemu-img: Invalid option list: backing_file=3DTEST_DIR/t.qcow2, @@ -258,6 +268,7 @@ Supported qcow2 options: encrypt.ivgen-hash-alg=3D - Name of IV generator hash algorithm encrypt.key-secret=3D - ID of secret providing qcow AES key or LUKS= passphrase encryption=3D - Encrypt the image with format 'aes'. (Dep= recated in favor of encrypt.format=3Daes) + extended_l2=3D - Extended L2 tables lazy_refcounts=3D - Postpone refcount updates preallocation=3D - Preallocation mode (allowed values: off, meta= data, falloc, full) refcount_bits=3D - Width of a reference count entry in bits @@ -279,7 +290,7 @@ qemu-img: Format driver 'bochs' does not support image = creation =3D=3D=3D convert: Options specified more than once =3D=3D=3D =20 Testing: create -f qcow2 TEST_DIR/t.qcow2 128M -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D134217728 cluster_size= =3D65536 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D134217728 cluster_size= =3D65536 lazy_refcounts=3Doff extended_l2=3Doff refcount_bits=3D16 =20 Testing: convert -f foo -f qcow2 TEST_DIR/t.qcow2 TEST_DIR/t.qcow2.base image: TEST_DIR/t.IMGFMT.base @@ -302,6 +313,7 @@ Format specific information: lazy refcounts: true refcount bits: 16 corrupt: false + extended l2: false =20 Testing: convert -O qcow2 -o cluster_size=3D4k -o lazy_refcounts=3Don -o c= luster_size=3D8k TEST_DIR/t.qcow2 TEST_DIR/t.qcow2.base image: TEST_DIR/t.IMGFMT.base @@ -313,6 +325,7 @@ Format specific information: lazy refcounts: true refcount bits: 16 corrupt: false + extended l2: false =20 Testing: convert -O qcow2 -o cluster_size=3D4k,cluster_size=3D8k TEST_DIR/= t.qcow2 TEST_DIR/t.qcow2.base image: TEST_DIR/t.IMGFMT.base @@ -339,6 +352,7 @@ Supported options: encrypt.ivgen-hash-alg=3D - Name of IV generator hash algorithm encrypt.key-secret=3D - ID of secret providing qcow AES key or LUKS= passphrase encryption=3D - Encrypt the image with format 'aes'. (Dep= recated in favor of encrypt.format=3Daes) + extended_l2=3D - Extended L2 tables lazy_refcounts=3D - Postpone refcount updates nocow=3D - Turn off copy-on-write (valid only on btrfs) preallocation=3D - Preallocation mode (allowed values: off, meta= data, falloc, full) @@ -362,6 +376,7 @@ Supported options: encrypt.ivgen-hash-alg=3D - Name of IV generator hash algorithm encrypt.key-secret=3D - ID of secret providing qcow AES key or LUKS= passphrase encryption=3D - Encrypt the image with format 'aes'. (Dep= recated in favor of encrypt.format=3Daes) + extended_l2=3D - Extended L2 tables lazy_refcounts=3D - Postpone refcount updates nocow=3D - Turn off copy-on-write (valid only on btrfs) preallocation=3D - Preallocation mode (allowed values: off, meta= data, falloc, full) @@ -385,6 +400,7 @@ Supported options: encrypt.ivgen-hash-alg=3D - Name of IV generator hash algorithm encrypt.key-secret=3D - ID of secret providing qcow AES key or LUKS= passphrase encryption=3D - Encrypt the image with format 'aes'. (Dep= recated in favor of encrypt.format=3Daes) + extended_l2=3D - Extended L2 tables lazy_refcounts=3D - Postpone refcount updates nocow=3D - Turn off copy-on-write (valid only on btrfs) preallocation=3D - Preallocation mode (allowed values: off, meta= data, falloc, full) @@ -408,6 +424,7 @@ Supported options: encrypt.ivgen-hash-alg=3D - Name of IV generator hash algorithm encrypt.key-secret=3D - ID of secret providing qcow AES key or LUKS= passphrase encryption=3D - Encrypt the image with format 'aes'. (Dep= recated in favor of encrypt.format=3Daes) + extended_l2=3D - Extended L2 tables lazy_refcounts=3D - Postpone refcount updates nocow=3D - Turn off copy-on-write (valid only on btrfs) preallocation=3D - Preallocation mode (allowed values: off, meta= data, falloc, full) @@ -431,6 +448,7 @@ Supported options: encrypt.ivgen-hash-alg=3D - Name of IV generator hash algorithm encrypt.key-secret=3D - ID of secret providing qcow AES key or LUKS= passphrase encryption=3D - Encrypt the image with format 'aes'. (Dep= recated in favor of encrypt.format=3Daes) + extended_l2=3D - Extended L2 tables lazy_refcounts=3D - Postpone refcount updates nocow=3D - Turn off copy-on-write (valid only on btrfs) preallocation=3D - Preallocation mode (allowed values: off, meta= data, falloc, full) @@ -454,6 +472,7 @@ Supported options: encrypt.ivgen-hash-alg=3D - Name of IV generator hash algorithm encrypt.key-secret=3D - ID of secret providing qcow AES key or LUKS= passphrase encryption=3D - Encrypt the image with format 'aes'. (Dep= recated in favor of encrypt.format=3Daes) + extended_l2=3D - Extended L2 tables lazy_refcounts=3D - Postpone refcount updates nocow=3D - Turn off copy-on-write (valid only on btrfs) preallocation=3D - Preallocation mode (allowed values: off, meta= data, falloc, full) @@ -477,6 +496,7 @@ Supported options: encrypt.ivgen-hash-alg=3D - Name of IV generator hash algorithm encrypt.key-secret=3D - ID of secret providing qcow AES key or LUKS= passphrase encryption=3D - Encrypt the image with format 'aes'. (Dep= recated in favor of encrypt.format=3Daes) + extended_l2=3D - Extended L2 tables lazy_refcounts=3D - Postpone refcount updates nocow=3D - Turn off copy-on-write (valid only on btrfs) preallocation=3D - Preallocation mode (allowed values: off, meta= data, falloc, full) @@ -500,6 +520,7 @@ Supported options: encrypt.ivgen-hash-alg=3D - Name of IV generator hash algorithm encrypt.key-secret=3D - ID of secret providing qcow AES key or LUKS= passphrase encryption=3D - Encrypt the image with format 'aes'. (Dep= recated in favor of encrypt.format=3Daes) + extended_l2=3D - Extended L2 tables lazy_refcounts=3D - Postpone refcount updates nocow=3D - Turn off copy-on-write (valid only on btrfs) preallocation=3D - Preallocation mode (allowed values: off, meta= data, falloc, full) @@ -538,6 +559,7 @@ Supported qcow2 options: encrypt.ivgen-hash-alg=3D - Name of IV generator hash algorithm encrypt.key-secret=3D - ID of secret providing qcow AES key or LUKS= passphrase encryption=3D - Encrypt the image with format 'aes'. (Dep= recated in favor of encrypt.format=3Daes) + extended_l2=3D - Extended L2 tables lazy_refcounts=3D - Postpone refcount updates preallocation=3D - Preallocation mode (allowed values: off, meta= data, falloc, full) refcount_bits=3D - Width of a reference count entry in bits @@ -582,6 +604,7 @@ Format specific information: lazy refcounts: true refcount bits: 16 corrupt: false + extended l2: false =20 Testing: amend -f qcow2 -o size=3D130M -o lazy_refcounts=3Doff TEST_DIR/t.= qcow2 image: TEST_DIR/t.IMGFMT @@ -593,6 +616,7 @@ Format specific information: lazy refcounts: false refcount bits: 16 corrupt: false + extended l2: false =20 Testing: amend -f qcow2 -o size=3D8M -o lazy_refcounts=3Don -o size=3D132M= TEST_DIR/t.qcow2 image: TEST_DIR/t.IMGFMT @@ -604,6 +628,7 @@ Format specific information: lazy refcounts: true refcount bits: 16 corrupt: false + extended l2: false =20 Testing: amend -f qcow2 -o size=3D4M,size=3D148M TEST_DIR/t.qcow2 image: TEST_DIR/t.IMGFMT @@ -630,6 +655,7 @@ Creation options for 'qcow2': encrypt.ivgen-hash-alg=3D - Name of IV generator hash algorithm encrypt.key-secret=3D - ID of secret providing qcow AES key or LUKS= passphrase encryption=3D - Encrypt the image with format 'aes'. (Dep= recated in favor of encrypt.format=3Daes) + extended_l2=3D - Extended L2 tables lazy_refcounts=3D - Postpone refcount updates preallocation=3D - Preallocation mode (allowed values: off, meta= data, falloc, full) refcount_bits=3D - Width of a reference count entry in bits @@ -654,6 +680,7 @@ Creation options for 'qcow2': encrypt.ivgen-hash-alg=3D - Name of IV generator hash algorithm encrypt.key-secret=3D - ID of secret providing qcow AES key or LUKS= passphrase encryption=3D - Encrypt the image with format 'aes'. (Dep= recated in favor of encrypt.format=3Daes) + extended_l2=3D - Extended L2 tables lazy_refcounts=3D - Postpone refcount updates preallocation=3D - Preallocation mode (allowed values: off, meta= data, falloc, full) refcount_bits=3D - Width of a reference count entry in bits @@ -678,6 +705,7 @@ Creation options for 'qcow2': encrypt.ivgen-hash-alg=3D - Name of IV generator hash algorithm encrypt.key-secret=3D - ID of secret providing qcow AES key or LUKS= passphrase encryption=3D - Encrypt the image with format 'aes'. (Dep= recated in favor of encrypt.format=3Daes) + extended_l2=3D - Extended L2 tables lazy_refcounts=3D - Postpone refcount updates preallocation=3D - Preallocation mode (allowed values: off, meta= data, falloc, full) refcount_bits=3D - Width of a reference count entry in bits @@ -702,6 +730,7 @@ Creation options for 'qcow2': encrypt.ivgen-hash-alg=3D - Name of IV generator hash algorithm encrypt.key-secret=3D - ID of secret providing qcow AES key or LUKS= passphrase encryption=3D - Encrypt the image with format 'aes'. (Dep= recated in favor of encrypt.format=3Daes) + extended_l2=3D - Extended L2 tables lazy_refcounts=3D - Postpone refcount updates preallocation=3D - Preallocation mode (allowed values: off, meta= data, falloc, full) refcount_bits=3D - Width of a reference count entry in bits @@ -726,6 +755,7 @@ Creation options for 'qcow2': encrypt.ivgen-hash-alg=3D - Name of IV generator hash algorithm encrypt.key-secret=3D - ID of secret providing qcow AES key or LUKS= passphrase encryption=3D - Encrypt the image with format 'aes'. (Dep= recated in favor of encrypt.format=3Daes) + extended_l2=3D - Extended L2 tables lazy_refcounts=3D - Postpone refcount updates preallocation=3D - Preallocation mode (allowed values: off, meta= data, falloc, full) refcount_bits=3D - Width of a reference count entry in bits @@ -750,6 +780,7 @@ Creation options for 'qcow2': encrypt.ivgen-hash-alg=3D - Name of IV generator hash algorithm encrypt.key-secret=3D - ID of secret providing qcow AES key or LUKS= passphrase encryption=3D - Encrypt the image with format 'aes'. (Dep= recated in favor of encrypt.format=3Daes) + extended_l2=3D - Extended L2 tables lazy_refcounts=3D - Postpone refcount updates preallocation=3D - Preallocation mode (allowed values: off, meta= data, falloc, full) refcount_bits=3D - Width of a reference count entry in bits @@ -774,6 +805,7 @@ Creation options for 'qcow2': encrypt.ivgen-hash-alg=3D - Name of IV generator hash algorithm encrypt.key-secret=3D - ID of secret providing qcow AES key or LUKS= passphrase encryption=3D - Encrypt the image with format 'aes'. (Dep= recated in favor of encrypt.format=3Daes) + extended_l2=3D - Extended L2 tables lazy_refcounts=3D - Postpone refcount updates preallocation=3D - Preallocation mode (allowed values: off, meta= data, falloc, full) refcount_bits=3D - Width of a reference count entry in bits @@ -798,6 +830,7 @@ Creation options for 'qcow2': encrypt.ivgen-hash-alg=3D - Name of IV generator hash algorithm encrypt.key-secret=3D - ID of secret providing qcow AES key or LUKS= passphrase encryption=3D - Encrypt the image with format 'aes'. (Dep= recated in favor of encrypt.format=3Daes) + extended_l2=3D - Extended L2 tables lazy_refcounts=3D - Postpone refcount updates preallocation=3D - Preallocation mode (allowed values: off, meta= data, falloc, full) refcount_bits=3D - Width of a reference count entry in bits @@ -839,6 +872,7 @@ Creation options for 'qcow2': encrypt.ivgen-hash-alg=3D - Name of IV generator hash algorithm encrypt.key-secret=3D - ID of secret providing qcow AES key or LUKS= passphrase encryption=3D - Encrypt the image with format 'aes'. (Dep= recated in favor of encrypt.format=3Daes) + extended_l2=3D - Extended L2 tables lazy_refcounts=3D - Postpone refcount updates preallocation=3D - Preallocation mode (allowed values: off, meta= data, falloc, full) refcount_bits=3D - Width of a reference count entry in bits diff --git a/tests/qemu-iotests/085.out b/tests/qemu-iotests/085.out index fd11aae678..0142b2265f 100644 --- a/tests/qemu-iotests/085.out +++ b/tests/qemu-iotests/085.out @@ -13,7 +13,7 @@ Formatting 'TEST_DIR/t.IMGFMT.2', fmt=3DIMGFMT size=3D134= 217728 =3D=3D=3D Create a single snapshot on virtio0 =3D=3D=3D =20 { 'execute': 'blockdev-snapshot-sync', 'arguments': { 'device': 'virtio0',= 'snapshot-file':'TEST_DIR/1-snapshot-v0.IMGFMT', 'format': 'IMGFMT' } } -Formatting 'TEST_DIR/1-snapshot-v0.qcow2', fmt=3Dqcow2 size=3D134217728 ba= cking_file=3DTEST_DIR/t.qcow2.1 backing_fmt=3Dqcow2 cluster_size=3D65536 la= zy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/1-snapshot-v0.qcow2', fmt=3Dqcow2 size=3D134217728 ba= cking_file=3DTEST_DIR/t.qcow2.1 backing_fmt=3Dqcow2 cluster_size=3D65536 la= zy_refcounts=3Doff extended_l2=3Doff refcount_bits=3D16 {"return": {}} =20 =3D=3D=3D Invalid command - missing device and nodename =3D=3D=3D @@ -30,40 +30,40 @@ Formatting 'TEST_DIR/1-snapshot-v0.qcow2', fmt=3Dqcow2 = size=3D134217728 backing_file =3D=3D=3D Create several transactional group snapshots =3D=3D=3D =20 { 'execute': 'transaction', 'arguments': {'actions': [ { 'type': 'blockdev= -snapshot-sync', 'data' : { 'device': 'virtio0', 'snapshot-file': 'TEST_DIR= /2-snapshot-v0.IMGFMT' } }, { 'type': 'blockdev-snapshot-sync', 'data' : { = 'device': 'virtio1', 'snapshot-file': 'TEST_DIR/2-snapshot-v1.IMGFMT' } } ]= } } -Formatting 'TEST_DIR/2-snapshot-v0.qcow2', fmt=3Dqcow2 size=3D134217728 ba= cking_file=3DTEST_DIR/1-snapshot-v0.qcow2 backing_fmt=3Dqcow2 cluster_size= =3D65536 lazy_refcounts=3Doff refcount_bits=3D16 -Formatting 'TEST_DIR/2-snapshot-v1.qcow2', fmt=3Dqcow2 size=3D134217728 ba= cking_file=3DTEST_DIR/t.qcow2.2 backing_fmt=3Dqcow2 cluster_size=3D65536 la= zy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/2-snapshot-v0.qcow2', fmt=3Dqcow2 size=3D134217728 ba= cking_file=3DTEST_DIR/1-snapshot-v0.qcow2 backing_fmt=3Dqcow2 cluster_size= =3D65536 lazy_refcounts=3Doff extended_l2=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/2-snapshot-v1.qcow2', fmt=3Dqcow2 size=3D134217728 ba= cking_file=3DTEST_DIR/t.qcow2.2 backing_fmt=3Dqcow2 cluster_size=3D65536 la= zy_refcounts=3Doff extended_l2=3Doff refcount_bits=3D16 {"return": {}} { 'execute': 'transaction', 'arguments': {'actions': [ { 'type': 'blockdev= -snapshot-sync', 'data' : { 'device': 'virtio0', 'snapshot-file': 'TEST_DIR= /3-snapshot-v0.IMGFMT' } }, { 'type': 'blockdev-snapshot-sync', 'data' : { = 'device': 'virtio1', 'snapshot-file': 'TEST_DIR/3-snapshot-v1.IMGFMT' } } ]= } } -Formatting 'TEST_DIR/3-snapshot-v0.qcow2', fmt=3Dqcow2 size=3D134217728 ba= cking_file=3DTEST_DIR/2-snapshot-v0.qcow2 backing_fmt=3Dqcow2 cluster_size= =3D65536 lazy_refcounts=3Doff refcount_bits=3D16 -Formatting 'TEST_DIR/3-snapshot-v1.qcow2', fmt=3Dqcow2 size=3D134217728 ba= cking_file=3DTEST_DIR/2-snapshot-v1.qcow2 backing_fmt=3Dqcow2 cluster_size= =3D65536 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/3-snapshot-v0.qcow2', fmt=3Dqcow2 size=3D134217728 ba= cking_file=3DTEST_DIR/2-snapshot-v0.qcow2 backing_fmt=3Dqcow2 cluster_size= =3D65536 lazy_refcounts=3Doff extended_l2=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/3-snapshot-v1.qcow2', fmt=3Dqcow2 size=3D134217728 ba= cking_file=3DTEST_DIR/2-snapshot-v1.qcow2 backing_fmt=3Dqcow2 cluster_size= =3D65536 lazy_refcounts=3Doff extended_l2=3Doff refcount_bits=3D16 {"return": {}} { 'execute': 'transaction', 'arguments': {'actions': [ { 'type': 'blockdev= -snapshot-sync', 'data' : { 'device': 'virtio0', 'snapshot-file': 'TEST_DIR= /4-snapshot-v0.IMGFMT' } }, { 'type': 'blockdev-snapshot-sync', 'data' : { = 'device': 'virtio1', 'snapshot-file': 'TEST_DIR/4-snapshot-v1.IMGFMT' } } ]= } } -Formatting 'TEST_DIR/4-snapshot-v0.qcow2', fmt=3Dqcow2 size=3D134217728 ba= cking_file=3DTEST_DIR/3-snapshot-v0.qcow2 backing_fmt=3Dqcow2 cluster_size= =3D65536 lazy_refcounts=3Doff refcount_bits=3D16 -Formatting 'TEST_DIR/4-snapshot-v1.qcow2', fmt=3Dqcow2 size=3D134217728 ba= cking_file=3DTEST_DIR/3-snapshot-v1.qcow2 backing_fmt=3Dqcow2 cluster_size= =3D65536 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/4-snapshot-v0.qcow2', fmt=3Dqcow2 size=3D134217728 ba= cking_file=3DTEST_DIR/3-snapshot-v0.qcow2 backing_fmt=3Dqcow2 cluster_size= =3D65536 lazy_refcounts=3Doff extended_l2=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/4-snapshot-v1.qcow2', fmt=3Dqcow2 size=3D134217728 ba= cking_file=3DTEST_DIR/3-snapshot-v1.qcow2 backing_fmt=3Dqcow2 cluster_size= =3D65536 lazy_refcounts=3Doff extended_l2=3Doff refcount_bits=3D16 {"return": {}} { 'execute': 'transaction', 'arguments': {'actions': [ { 'type': 'blockdev= -snapshot-sync', 'data' : { 'device': 'virtio0', 'snapshot-file': 'TEST_DIR= /5-snapshot-v0.IMGFMT' } }, { 'type': 'blockdev-snapshot-sync', 'data' : { = 'device': 'virtio1', 'snapshot-file': 'TEST_DIR/5-snapshot-v1.IMGFMT' } } ]= } } -Formatting 'TEST_DIR/5-snapshot-v0.qcow2', fmt=3Dqcow2 size=3D134217728 ba= cking_file=3DTEST_DIR/4-snapshot-v0.qcow2 backing_fmt=3Dqcow2 cluster_size= =3D65536 lazy_refcounts=3Doff refcount_bits=3D16 -Formatting 'TEST_DIR/5-snapshot-v1.qcow2', fmt=3Dqcow2 size=3D134217728 ba= cking_file=3DTEST_DIR/4-snapshot-v1.qcow2 backing_fmt=3Dqcow2 cluster_size= =3D65536 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/5-snapshot-v0.qcow2', fmt=3Dqcow2 size=3D134217728 ba= cking_file=3DTEST_DIR/4-snapshot-v0.qcow2 backing_fmt=3Dqcow2 cluster_size= =3D65536 lazy_refcounts=3Doff extended_l2=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/5-snapshot-v1.qcow2', fmt=3Dqcow2 size=3D134217728 ba= cking_file=3DTEST_DIR/4-snapshot-v1.qcow2 backing_fmt=3Dqcow2 cluster_size= =3D65536 lazy_refcounts=3Doff extended_l2=3Doff refcount_bits=3D16 {"return": {}} { 'execute': 'transaction', 'arguments': {'actions': [ { 'type': 'blockdev= -snapshot-sync', 'data' : { 'device': 'virtio0', 'snapshot-file': 'TEST_DIR= /6-snapshot-v0.IMGFMT' } }, { 'type': 'blockdev-snapshot-sync', 'data' : { = 'device': 'virtio1', 'snapshot-file': 'TEST_DIR/6-snapshot-v1.IMGFMT' } } ]= } } -Formatting 'TEST_DIR/6-snapshot-v0.qcow2', fmt=3Dqcow2 size=3D134217728 ba= cking_file=3DTEST_DIR/5-snapshot-v0.qcow2 backing_fmt=3Dqcow2 cluster_size= =3D65536 lazy_refcounts=3Doff refcount_bits=3D16 -Formatting 'TEST_DIR/6-snapshot-v1.qcow2', fmt=3Dqcow2 size=3D134217728 ba= cking_file=3DTEST_DIR/5-snapshot-v1.qcow2 backing_fmt=3Dqcow2 cluster_size= =3D65536 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/6-snapshot-v0.qcow2', fmt=3Dqcow2 size=3D134217728 ba= cking_file=3DTEST_DIR/5-snapshot-v0.qcow2 backing_fmt=3Dqcow2 cluster_size= =3D65536 lazy_refcounts=3Doff extended_l2=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/6-snapshot-v1.qcow2', fmt=3Dqcow2 size=3D134217728 ba= cking_file=3DTEST_DIR/5-snapshot-v1.qcow2 backing_fmt=3Dqcow2 cluster_size= =3D65536 lazy_refcounts=3Doff extended_l2=3Doff refcount_bits=3D16 {"return": {}} { 'execute': 'transaction', 'arguments': {'actions': [ { 'type': 'blockdev= -snapshot-sync', 'data' : { 'device': 'virtio0', 'snapshot-file': 'TEST_DIR= /7-snapshot-v0.IMGFMT' } }, { 'type': 'blockdev-snapshot-sync', 'data' : { = 'device': 'virtio1', 'snapshot-file': 'TEST_DIR/7-snapshot-v1.IMGFMT' } } ]= } } -Formatting 'TEST_DIR/7-snapshot-v0.qcow2', fmt=3Dqcow2 size=3D134217728 ba= cking_file=3DTEST_DIR/6-snapshot-v0.qcow2 backing_fmt=3Dqcow2 cluster_size= =3D65536 lazy_refcounts=3Doff refcount_bits=3D16 -Formatting 'TEST_DIR/7-snapshot-v1.qcow2', fmt=3Dqcow2 size=3D134217728 ba= cking_file=3DTEST_DIR/6-snapshot-v1.qcow2 backing_fmt=3Dqcow2 cluster_size= =3D65536 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/7-snapshot-v0.qcow2', fmt=3Dqcow2 size=3D134217728 ba= cking_file=3DTEST_DIR/6-snapshot-v0.qcow2 backing_fmt=3Dqcow2 cluster_size= =3D65536 lazy_refcounts=3Doff extended_l2=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/7-snapshot-v1.qcow2', fmt=3Dqcow2 size=3D134217728 ba= cking_file=3DTEST_DIR/6-snapshot-v1.qcow2 backing_fmt=3Dqcow2 cluster_size= =3D65536 lazy_refcounts=3Doff extended_l2=3Doff refcount_bits=3D16 {"return": {}} { 'execute': 'transaction', 'arguments': {'actions': [ { 'type': 'blockdev= -snapshot-sync', 'data' : { 'device': 'virtio0', 'snapshot-file': 'TEST_DIR= /8-snapshot-v0.IMGFMT' } }, { 'type': 'blockdev-snapshot-sync', 'data' : { = 'device': 'virtio1', 'snapshot-file': 'TEST_DIR/8-snapshot-v1.IMGFMT' } } ]= } } -Formatting 'TEST_DIR/8-snapshot-v0.qcow2', fmt=3Dqcow2 size=3D134217728 ba= cking_file=3DTEST_DIR/7-snapshot-v0.qcow2 backing_fmt=3Dqcow2 cluster_size= =3D65536 lazy_refcounts=3Doff refcount_bits=3D16 -Formatting 'TEST_DIR/8-snapshot-v1.qcow2', fmt=3Dqcow2 size=3D134217728 ba= cking_file=3DTEST_DIR/7-snapshot-v1.qcow2 backing_fmt=3Dqcow2 cluster_size= =3D65536 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/8-snapshot-v0.qcow2', fmt=3Dqcow2 size=3D134217728 ba= cking_file=3DTEST_DIR/7-snapshot-v0.qcow2 backing_fmt=3Dqcow2 cluster_size= =3D65536 lazy_refcounts=3Doff extended_l2=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/8-snapshot-v1.qcow2', fmt=3Dqcow2 size=3D134217728 ba= cking_file=3DTEST_DIR/7-snapshot-v1.qcow2 backing_fmt=3Dqcow2 cluster_size= =3D65536 lazy_refcounts=3Doff extended_l2=3Doff refcount_bits=3D16 {"return": {}} { 'execute': 'transaction', 'arguments': {'actions': [ { 'type': 'blockdev= -snapshot-sync', 'data' : { 'device': 'virtio0', 'snapshot-file': 'TEST_DIR= /9-snapshot-v0.IMGFMT' } }, { 'type': 'blockdev-snapshot-sync', 'data' : { = 'device': 'virtio1', 'snapshot-file': 'TEST_DIR/9-snapshot-v1.IMGFMT' } } ]= } } -Formatting 'TEST_DIR/9-snapshot-v0.qcow2', fmt=3Dqcow2 size=3D134217728 ba= cking_file=3DTEST_DIR/8-snapshot-v0.qcow2 backing_fmt=3Dqcow2 cluster_size= =3D65536 lazy_refcounts=3Doff refcount_bits=3D16 -Formatting 'TEST_DIR/9-snapshot-v1.qcow2', fmt=3Dqcow2 size=3D134217728 ba= cking_file=3DTEST_DIR/8-snapshot-v1.qcow2 backing_fmt=3Dqcow2 cluster_size= =3D65536 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/9-snapshot-v0.qcow2', fmt=3Dqcow2 size=3D134217728 ba= cking_file=3DTEST_DIR/8-snapshot-v0.qcow2 backing_fmt=3Dqcow2 cluster_size= =3D65536 lazy_refcounts=3Doff extended_l2=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/9-snapshot-v1.qcow2', fmt=3Dqcow2 size=3D134217728 ba= cking_file=3DTEST_DIR/8-snapshot-v1.qcow2 backing_fmt=3Dqcow2 cluster_size= =3D65536 lazy_refcounts=3Doff extended_l2=3Doff refcount_bits=3D16 {"return": {}} { 'execute': 'transaction', 'arguments': {'actions': [ { 'type': 'blockdev= -snapshot-sync', 'data' : { 'device': 'virtio0', 'snapshot-file': 'TEST_DIR= /10-snapshot-v0.IMGFMT' } }, { 'type': 'blockdev-snapshot-sync', 'data' : {= 'device': 'virtio1', 'snapshot-file': 'TEST_DIR/10-snapshot-v1.IMGFMT' } }= ] } } -Formatting 'TEST_DIR/10-snapshot-v0.qcow2', fmt=3Dqcow2 size=3D134217728 b= acking_file=3DTEST_DIR/9-snapshot-v0.qcow2 backing_fmt=3Dqcow2 cluster_size= =3D65536 lazy_refcounts=3Doff refcount_bits=3D16 -Formatting 'TEST_DIR/10-snapshot-v1.qcow2', fmt=3Dqcow2 size=3D134217728 b= acking_file=3DTEST_DIR/9-snapshot-v1.qcow2 backing_fmt=3Dqcow2 cluster_size= =3D65536 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/10-snapshot-v0.qcow2', fmt=3Dqcow2 size=3D134217728 b= acking_file=3DTEST_DIR/9-snapshot-v0.qcow2 backing_fmt=3Dqcow2 cluster_size= =3D65536 lazy_refcounts=3Doff extended_l2=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/10-snapshot-v1.qcow2', fmt=3Dqcow2 size=3D134217728 b= acking_file=3DTEST_DIR/9-snapshot-v1.qcow2 backing_fmt=3Dqcow2 cluster_size= =3D65536 lazy_refcounts=3Doff extended_l2=3Doff refcount_bits=3D16 {"return": {}} =20 =3D=3D=3D Create a couple of snapshots using blockdev-snapshot =3D=3D=3D diff --git a/tests/qemu-iotests/144.out b/tests/qemu-iotests/144.out index c7aa2e4820..5d9aceaf13 100644 --- a/tests/qemu-iotests/144.out +++ b/tests/qemu-iotests/144.out @@ -9,7 +9,7 @@ Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D5368709= 12 { 'execute': 'qmp_capabilities' } {"return": {}} { 'execute': 'blockdev-snapshot-sync', 'arguments': { 'device': 'virtio0',= 'snapshot-file':'TEST_DIR/tmp.IMGFMT', 'format': 'IMGFMT' } } -Formatting 'TEST_DIR/tmp.qcow2', fmt=3Dqcow2 size=3D536870912 backing_file= =3DTEST_DIR/t.qcow2 backing_fmt=3Dqcow2 cluster_size=3D65536 lazy_refcounts= =3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/tmp.qcow2', fmt=3Dqcow2 size=3D536870912 backing_file= =3DTEST_DIR/t.qcow2 backing_fmt=3Dqcow2 cluster_size=3D65536 lazy_refcounts= =3Doff extended_l2=3Doff refcount_bits=3D16 {"return": {}} =20 =3D=3D=3D Performing block-commit on active layer =3D=3D=3D @@ -31,6 +31,6 @@ Formatting 'TEST_DIR/tmp.qcow2', fmt=3Dqcow2 size=3D53687= 0912 backing_file=3DTEST_DIR/ =3D=3D=3D Performing Live Snapshot 2 =3D=3D=3D =20 { 'execute': 'blockdev-snapshot-sync', 'arguments': { 'device': 'virtio0',= 'snapshot-file':'TEST_DIR/tmp2.IMGFMT', 'format': 'IMGFMT' } } -Formatting 'TEST_DIR/tmp2.qcow2', fmt=3Dqcow2 size=3D536870912 backing_fil= e=3DTEST_DIR/t.qcow2 backing_fmt=3Dqcow2 cluster_size=3D65536 lazy_refcount= s=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/tmp2.qcow2', fmt=3Dqcow2 size=3D536870912 backing_fil= e=3DTEST_DIR/t.qcow2 backing_fmt=3Dqcow2 cluster_size=3D65536 lazy_refcount= s=3Doff extended_l2=3Doff refcount_bits=3D16 {"return": {}} *** done diff --git a/tests/qemu-iotests/182.out b/tests/qemu-iotests/182.out index a8eea166c3..84dc7a2360 100644 --- a/tests/qemu-iotests/182.out +++ b/tests/qemu-iotests/182.out @@ -13,7 +13,7 @@ Is another process using the image [TEST_DIR/t.qcow2]? {'execute': 'blockdev-add', 'arguments': { 'node-name': 'node0', 'driver':= 'file', 'filename': 'TEST_DIR/t.IMGFMT', 'locking': 'on' } } {"return": {}} {'execute': 'blockdev-snapshot-sync', 'arguments': { 'node-name': 'node0',= 'snapshot-file': 'TEST_DIR/t.IMGFMT.overlay', 'snapshot-node-name': 'node1= ' } } -Formatting 'TEST_DIR/t.qcow2.overlay', fmt=3Dqcow2 size=3D197120 backing_f= ile=3DTEST_DIR/t.qcow2 backing_fmt=3Dfile cluster_size=3D65536 lazy_refcoun= ts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2.overlay', fmt=3Dqcow2 size=3D197120 backing_f= ile=3DTEST_DIR/t.qcow2 backing_fmt=3Dfile cluster_size=3D65536 lazy_refcoun= ts=3Doff extended_l2=3Doff refcount_bits=3D16 {"return": {}} {'execute': 'blockdev-add', 'arguments': { 'node-name': 'node1', 'driver':= 'file', 'filename': 'TEST_DIR/t.IMGFMT', 'locking': 'on' } } {"return": {}} diff --git a/tests/qemu-iotests/185.out b/tests/qemu-iotests/185.out index 9a3b65782b..859fa7daaa 100644 --- a/tests/qemu-iotests/185.out +++ b/tests/qemu-iotests/185.out @@ -9,14 +9,14 @@ Formatting 'TEST_DIR/t.IMGFMT.base', fmt=3DIMGFMT size=3D= 67108864 =3D=3D=3D Creating backing chain =3D=3D=3D =20 { 'execute': 'blockdev-snapshot-sync', 'arguments': { 'device': 'disk', 's= napshot-file': 'TEST_DIR/t.IMGFMT.mid', 'format': 'IMGFMT', 'mode': 'absolu= te-paths' } } -Formatting 'TEST_DIR/t.qcow2.mid', fmt=3Dqcow2 size=3D67108864 backing_fil= e=3DTEST_DIR/t.qcow2.base backing_fmt=3Dqcow2 cluster_size=3D65536 lazy_ref= counts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2.mid', fmt=3Dqcow2 size=3D67108864 backing_fil= e=3DTEST_DIR/t.qcow2.base backing_fmt=3Dqcow2 cluster_size=3D65536 lazy_ref= counts=3Doff extended_l2=3Doff refcount_bits=3D16 {"return": {}} { 'execute': 'human-monitor-command', 'arguments': { 'command-line': 'qemu= -io disk "write 0 4M"' } } wrote 4194304/4194304 bytes at offset 0 4 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) {"return": ""} { 'execute': 'blockdev-snapshot-sync', 'arguments': { 'device': 'disk', 's= napshot-file': 'TEST_DIR/t.IMGFMT', 'format': 'IMGFMT', 'mode': 'absolute-p= aths' } } -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D67108864 backing_file=3D= TEST_DIR/t.qcow2.mid backing_fmt=3Dqcow2 cluster_size=3D65536 lazy_refcount= s=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D67108864 backing_file=3D= TEST_DIR/t.qcow2.mid backing_fmt=3Dqcow2 cluster_size=3D65536 lazy_refcount= s=3Doff extended_l2=3Doff refcount_bits=3D16 {"return": {}} =20 =3D=3D=3D Start commit job and exit qemu =3D=3D=3D @@ -48,7 +48,7 @@ Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D6710886= 4 backing_file=3DTEST_DIR/t.q { 'execute': 'qmp_capabilities' } {"return": {}} { 'execute': 'drive-mirror', 'arguments': { 'device': 'disk', 'target': 'T= EST_DIR/t.IMGFMT.copy', 'format': 'IMGFMT', 'sync': 'full', 'speed': 65536 = } } -Formatting 'TEST_DIR/t.qcow2.copy', fmt=3Dqcow2 size=3D67108864 cluster_si= ze=3D65536 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2.copy', fmt=3Dqcow2 size=3D67108864 cluster_si= ze=3D65536 lazy_refcounts=3Doff extended_l2=3Doff refcount_bits=3D16 {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event"= : "JOB_STATUS_CHANGE", "data": {"status": "created", "id": "disk"}} {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event"= : "JOB_STATUS_CHANGE", "data": {"status": "running", "id": "disk"}} {"return": {}} @@ -62,7 +62,7 @@ Formatting 'TEST_DIR/t.qcow2.copy', fmt=3Dqcow2 size=3D67= 108864 cluster_size=3D65536 l { 'execute': 'qmp_capabilities' } {"return": {}} { 'execute': 'drive-backup', 'arguments': { 'device': 'disk', 'target': 'T= EST_DIR/t.IMGFMT.copy', 'format': 'IMGFMT', 'sync': 'full', 'speed': 65536 = } } -Formatting 'TEST_DIR/t.qcow2.copy', fmt=3Dqcow2 size=3D67108864 cluster_si= ze=3D65536 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2.copy', fmt=3Dqcow2 size=3D67108864 cluster_si= ze=3D65536 lazy_refcounts=3Doff extended_l2=3Doff refcount_bits=3D16 {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event"= : "JOB_STATUS_CHANGE", "data": {"status": "created", "id": "disk"}} {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event"= : "JOB_STATUS_CHANGE", "data": {"status": "running", "id": "disk"}} {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event"= : "JOB_STATUS_CHANGE", "data": {"status": "paused", "id": "disk"}} diff --git a/tests/qemu-iotests/198.out b/tests/qemu-iotests/198.out index 831ce3a289..f1e8cf7bab 100644 --- a/tests/qemu-iotests/198.out +++ b/tests/qemu-iotests/198.out @@ -72,6 +72,7 @@ Format specific information: key offset: 1810432 payload offset: 2068480 master key iters: 1024 + extended l2: false =20 =3D=3D checking image layer =3D=3D image: json:{ /* filtered */ } @@ -115,4 +116,5 @@ Format specific information: key offset: 1810432 payload offset: 2068480 master key iters: 1024 + extended l2: false *** done diff --git a/tests/qemu-iotests/206.out b/tests/qemu-iotests/206.out index 61e7241e0b..d2efc0394a 100644 --- a/tests/qemu-iotests/206.out +++ b/tests/qemu-iotests/206.out @@ -21,6 +21,7 @@ Format specific information: lazy refcounts: false refcount bits: 16 corrupt: false + extended l2: false =20 =3D=3D=3D Successful image creation (inline blockdev-add, explicit default= s) =3D=3D=3D =20 @@ -43,6 +44,7 @@ Format specific information: lazy refcounts: false refcount bits: 16 corrupt: false + extended l2: false =20 =3D=3D=3D Successful image creation (v3 non-default options) =3D=3D=3D =20 @@ -65,6 +67,7 @@ Format specific information: lazy refcounts: true refcount bits: 1 corrupt: false + extended l2: false =20 =3D=3D=3D Successful image creation (v2 non-default options) =3D=3D=3D =20 @@ -141,6 +144,7 @@ Format specific information: payload offset: 528384 master key iters: XXX corrupt: false + extended l2: false =20 =3D=3D=3D Invalid BlockdevRef =3D=3D=3D =20 diff --git a/tests/qemu-iotests/242.out b/tests/qemu-iotests/242.out index 7ac8404d11..0d32dd9148 100644 --- a/tests/qemu-iotests/242.out +++ b/tests/qemu-iotests/242.out @@ -15,6 +15,7 @@ Format specific information: lazy refcounts: false refcount bits: 16 corrupt: false + extended l2: false =20 No bitmap in JSON format output =20 @@ -40,6 +41,7 @@ Format specific information: granularity: 32768 refcount bits: 16 corrupt: false + extended l2: false =20 The same bitmaps in JSON format: [ @@ -77,6 +79,7 @@ Format specific information: granularity: 65536 refcount bits: 16 corrupt: false + extended l2: false =20 The same bitmaps in JSON format: [ @@ -119,6 +122,7 @@ Format specific information: granularity: 65536 refcount bits: 16 corrupt: false + extended l2: false =20 The same bitmaps in JSON format: [ @@ -162,5 +166,6 @@ Format specific information: granularity: 16384 refcount bits: 16 corrupt: false + extended l2: false =20 Test complete diff --git a/tests/qemu-iotests/255.out b/tests/qemu-iotests/255.out index 348909fdef..4e1b917a0f 100644 --- a/tests/qemu-iotests/255.out +++ b/tests/qemu-iotests/255.out @@ -3,9 +3,9 @@ Finishing a commit job with background reads =20 =3D=3D=3D Create backing chain and start VM =3D=3D=3D =20 -Formatting 'TEST_DIR/PID-t.qcow2.mid', fmt=3Dqcow2 size=3D134217728 cluste= r_size=3D65536 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/PID-t.qcow2.mid', fmt=3Dqcow2 size=3D134217728 cluste= r_size=3D65536 lazy_refcounts=3Doff extended_l2=3Doff refcount_bits=3D16 =20 -Formatting 'TEST_DIR/PID-t.qcow2', fmt=3Dqcow2 size=3D134217728 cluster_si= ze=3D65536 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/PID-t.qcow2', fmt=3Dqcow2 size=3D134217728 cluster_si= ze=3D65536 lazy_refcounts=3Doff extended_l2=3Doff refcount_bits=3D16 =20 =3D=3D=3D Start background read requests =3D=3D=3D =20 @@ -23,9 +23,9 @@ Closing the VM while a job is being cancelled =20 =3D=3D=3D Create images and start VM =3D=3D=3D =20 -Formatting 'TEST_DIR/PID-src.qcow2', fmt=3Dqcow2 size=3D134217728 cluster_= size=3D65536 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/PID-src.qcow2', fmt=3Dqcow2 size=3D134217728 cluster_= size=3D65536 lazy_refcounts=3Doff extended_l2=3Doff refcount_bits=3D16 =20 -Formatting 'TEST_DIR/PID-dst.qcow2', fmt=3Dqcow2 size=3D134217728 cluster_= size=3D65536 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/PID-dst.qcow2', fmt=3Dqcow2 size=3D134217728 cluster_= size=3D65536 lazy_refcounts=3Doff extended_l2=3Doff refcount_bits=3D16 =20 wrote 1048576/1048576 bytes at offset 0 1 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) diff --git a/tests/qemu-iotests/280.out b/tests/qemu-iotests/280.out index 5d382faaa8..ef1aad1ae1 100644 --- a/tests/qemu-iotests/280.out +++ b/tests/qemu-iotests/280.out @@ -1,4 +1,4 @@ -Formatting 'TEST_DIR/PID-base', fmt=3Dqcow2 size=3D67108864 cluster_size= =3D65536 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/PID-base', fmt=3Dqcow2 size=3D67108864 cluster_size= =3D65536 lazy_refcounts=3Doff extended_l2=3Doff refcount_bits=3D16 =20 =3D=3D=3D Launch VM =3D=3D=3D Enabling migration QMP events on VM... diff --git a/tests/qemu-iotests/common.filter b/tests/qemu-iotests/common.f= ilter index 3f8ee3e5f7..db9793e7d9 100644 --- a/tests/qemu-iotests/common.filter +++ b/tests/qemu-iotests/common.filter @@ -146,6 +146,7 @@ _filter_img_create() -e "s# adapter_type=3D[^ ]*##g" \ -e "s# hwversion=3D[^ ]*##g" \ -e "s# lazy_refcounts=3D\\(on\\|off\\)##g" \ + -e "s# extended_l2=3D\\(on\\|off\\)##g" \ -e "s# block_size=3D[0-9]\\+##g" \ -e "s# block_state_zero=3D\\(on\\|off\\)##g" \ -e "s# log_size=3D[0-9]\\+##g" \ --=20 2.20.1 From nobody Tue May 7 09:01:18 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1584469172; cv=none; d=zohomail.com; s=zohoarc; b=PgMiR78QxndYtxtPL50wynPlW2Ud9Njiu2A/xPNUmaqeRqfSdjHQwcka7ds5egpCYphTZTN1DJUm70Jg7JPQkcy0Hw7Xir0k1gjhB4qZHm4oSDWVoCnUgBBtiU76URLCu6tQZ9EQttsxVcTApqyGyGW/qdUCfmj3XiROhkr9kGk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1584469172; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=LjK5j2bf8Ro+XMHhvP6jjCCoC2fozdNxPBv9pecMwAM=; b=IMKkO0avJrZ7AdD3tukDSCpZmaGuBAHDsrMmA0a/FMekw+cjFJA89Vj21ZD2NNYckkgxCjAPnJDb8qY9d0yErJzFEW1P/UWhiBTc+iOoxopIy7DGX+/KbaBxCzIJWinyuvMtBS85HSiYi4GVlMudwrbE7pS7SzLcel/pgHKgs+4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1584469171615599.403040822519; Tue, 17 Mar 2020 11:19:31 -0700 (PDT) Received: from localhost ([::1]:38938 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEGoM-0004oV-6c for importer@patchew.org; Tue, 17 Mar 2020 14:19:30 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48361) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEGmc-0002p1-62 for qemu-devel@nongnu.org; Tue, 17 Mar 2020 14:17:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jEGmZ-0007Vr-3K for qemu-devel@nongnu.org; Tue, 17 Mar 2020 14:17:41 -0400 Received: from fanzine.igalia.com ([178.60.130.6]:57765) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jEGmX-0005YS-Ao; Tue, 17 Mar 2020 14:17:38 -0400 Received: from [81.0.35.138] (helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1jEGmD-00014s-0S; Tue, 17 Mar 2020 19:17:17 +0100 Received: from berto by perseus.local with local (Exim 4.92) (envelope-from ) id 1jEGlx-0006Oz-0s; Tue, 17 Mar 2020 19:17:01 +0100 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=LjK5j2bf8Ro+XMHhvP6jjCCoC2fozdNxPBv9pecMwAM=; b=YgSsHHqFVMST/uUh3mSGJEGcDcNgip6AUrRRDri8/J9KR6ctkzwGGc2QK6hD/WvNkdxnpnq7BFsvEq6cf99ep6RDmVpe/ncX3VvZC+DAeSCBA3rkE+Jis74YhR95Yw7AgOw4eCFvUSA6VzmuaBzxRhjBrOs1+9rljEyMNl6Is9UpUSA6hrDOgEkvYQzkJsWstnVJLKFuXgvRzK1F6iDN5TEi+nj3UJVEeCJw3Jrt1AohcafFc4OE7Kg6ptT/+Jqo0+ThuQkkE/Q3/4DrsaITrkakqSobk79++4aTsMfAYv4fHeAhZutHOS3s+CcVx1wZUXSWvmzn05c1kc5gwxH5nw==; From: Alberto Garcia To: qemu-devel@nongnu.org Subject: [PATCH v4 29/30] qcow2: Add subcluster support to qcow2_measure() Date: Tue, 17 Mar 2020 19:16:26 +0100 Message-Id: X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy] X-Received-From: 178.60.130.6 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Anton Nefedov , Alberto Garcia , qemu-block@nongnu.org, Max Reitz , Vladimir Sementsov-Ogievskiy , "Denis V . Lunev" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Extended L2 entries are bigger than normal L2 entries so this has an impact on the amount of metadata needed for a qcow2 file. Signed-off-by: Alberto Garcia Reviewed-by: Max Reitz --- block/qcow2.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/block/qcow2.c b/block/qcow2.c index 77b2713533..aefac85b23 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -3154,28 +3154,31 @@ int64_t qcow2_refcount_metadata_size(int64_t cluste= rs, size_t cluster_size, * @total_size: virtual disk size in bytes * @cluster_size: cluster size in bytes * @refcount_order: refcount bits power-of-2 exponent + * @extended_l2: true if the image has extended L2 entries * * Returns: Total number of bytes required for the fully allocated image * (including metadata). */ static int64_t qcow2_calc_prealloc_size(int64_t total_size, size_t cluster_size, - int refcount_order) + int refcount_order, + bool extended_l2) { int64_t meta_size =3D 0; uint64_t nl1e, nl2e; int64_t aligned_total_size =3D ROUND_UP(total_size, cluster_size); + size_t l2e_size =3D extended_l2 ? L2E_SIZE_EXTENDED : L2E_SIZE_NORMAL; =20 /* header: 1 cluster */ meta_size +=3D cluster_size; =20 /* total size of L2 tables */ nl2e =3D aligned_total_size / cluster_size; - nl2e =3D ROUND_UP(nl2e, cluster_size / sizeof(uint64_t)); - meta_size +=3D nl2e * sizeof(uint64_t); + nl2e =3D ROUND_UP(nl2e, cluster_size / l2e_size); + meta_size +=3D nl2e * l2e_size; =20 /* total size of L1 tables */ - nl1e =3D nl2e * sizeof(uint64_t) / cluster_size; + nl1e =3D nl2e * l2e_size / cluster_size; nl1e =3D ROUND_UP(nl1e, cluster_size / sizeof(uint64_t)); meta_size +=3D nl1e * sizeof(uint64_t); =20 @@ -4680,6 +4683,7 @@ static BlockMeasureInfo *qcow2_measure(QemuOpts *opts= , BlockDriverState *in_bs, bool has_backing_file; bool has_luks; bool extended_l2; + size_t l2e_size; =20 /* Parse image creation options */ extended_l2 =3D qemu_opt_get_bool_del(opts, BLOCK_OPT_EXTL2, false); @@ -4748,8 +4752,9 @@ static BlockMeasureInfo *qcow2_measure(QemuOpts *opts= , BlockDriverState *in_bs, virtual_size =3D ROUND_UP(virtual_size, cluster_size); =20 /* Check that virtual disk size is valid */ + l2e_size =3D extended_l2 ? L2E_SIZE_EXTENDED : L2E_SIZE_NORMAL; l2_tables =3D DIV_ROUND_UP(virtual_size / cluster_size, - cluster_size / sizeof(uint64_t)); + cluster_size / l2e_size); if (l2_tables * sizeof(uint64_t) > QCOW_MAX_L1_SIZE) { error_setg(&local_err, "The image size is too large " "(try using a larger cluster size)"); @@ -4812,9 +4817,9 @@ static BlockMeasureInfo *qcow2_measure(QemuOpts *opts= , BlockDriverState *in_bs, } =20 info =3D g_new(BlockMeasureInfo, 1); - info->fully_allocated =3D + info->fully_allocated =3D luks_payload_size + qcow2_calc_prealloc_size(virtual_size, cluster_size, - ctz32(refcount_bits)) + luks_payload_size; + ctz32(refcount_bits), extended_l2); =20 /* Remove data clusters that are not required. This overestimates the * required size because metadata needed for the fully allocated file = is --=20 2.20.1 From nobody Tue May 7 09:01:18 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1584470557; cv=none; d=zohomail.com; s=zohoarc; b=Hro9oFICL9gZ1PsqVHCgWDEBo8JCKxMA93OwUcl2SfRJ5F8VBR2oPAd2TmIZXomJZrhKEpTEEqUDINGYCDCOfKbYHZ1vFjjkvqlkN8lbiIHEVmC+D1pYc07db4e7+rnDC7dFVWcorfNuTJDv6lElZwxlL0vMtWtBmUfLS/hG0nE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1584470557; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=RPN/yHP4znLKszxyOoU+Ptsu4yTPY7OKYSkTrSXwvTY=; b=eLg6tVClkDO0WP8lMTGhKd/gu6c9sKIQZWuycaLeDlUoJguWUEZRs6sxjlb/KSiCP7Xx/eegShQ9vjhd78MIUWSsNbmxLXmcRMYD6epbW524Cbr2FaNnBPMiBg2OPsgpaigQe/N53Kf7kNuLS7wBo3tasFtQfRpUz9PFixLJC8s= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1584470557682881.3108367863256; Tue, 17 Mar 2020 11:42:37 -0700 (PDT) Received: from localhost ([::1]:39658 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEHAi-0006Ek-Ex for importer@patchew.org; Tue, 17 Mar 2020 14:42:36 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49107) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEGn4-0003j5-Gy for qemu-devel@nongnu.org; Tue, 17 Mar 2020 14:18:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jEGmv-00009z-A8 for qemu-devel@nongnu.org; Tue, 17 Mar 2020 14:18:10 -0400 Received: from fanzine.igalia.com ([178.60.130.6]:58021) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jEGmu-0005yT-4H; Tue, 17 Mar 2020 14:18:01 -0400 Received: from [81.0.35.138] (helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1jEGmD-00015R-0h; Tue, 17 Mar 2020 19:17:17 +0100 Received: from berto by perseus.local with local (Exim 4.92) (envelope-from ) id 1jEGlx-0006P1-2D; Tue, 17 Mar 2020 19:17:01 +0100 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=RPN/yHP4znLKszxyOoU+Ptsu4yTPY7OKYSkTrSXwvTY=; b=Oxuo4lVXUoOvsLlBJXN24+Zq1WO5QU8AnYp3gJ6aTn8icz+kebFV6nG3niAVhQkyRw6V7ewU0pKp5WEVDj8+XlDFcWWuMUE17ZbqQW0Zianp5WuFjCwakK5j9qwPZczUgvvKzgSQYUQD2vjmeys4W99pfJp/VwxtJqv/oTc/41afsM6fyFYrOc15kW23wQDXN6p/LltYHt7UTAD0PElH7Pg/vajt5AGoEEkWu3iMO3TbpC+j3bvCLNRON5T1K4w+JiwtqU38zpbW4dcc5Wu6fRpbeC6gvfyx8XMD1cv+1k9O1eHtkaYqfaNzqpKH+opetXowOF2XdVq/9WXuTl2tGQ==; From: Alberto Garcia To: qemu-devel@nongnu.org Subject: [PATCH v4 30/30] iotests: Add tests for qcow2 images with extended L2 entries Date: Tue, 17 Mar 2020 19:16:27 +0100 Message-Id: <420b76fbe25d5e2eeda53490a1c646935dab61c4.1584468724.git.berto@igalia.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy] X-Received-From: 178.60.130.6 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Anton Nefedov , Alberto Garcia , qemu-block@nongnu.org, Max Reitz , Vladimir Sementsov-Ogievskiy , "Denis V . Lunev" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Signed-off-by: Alberto Garcia --- tests/qemu-iotests/271 | 359 +++++++++++++++++++++++++++++++++++++ tests/qemu-iotests/271.out | 244 +++++++++++++++++++++++++ tests/qemu-iotests/group | 1 + 3 files changed, 604 insertions(+) create mode 100755 tests/qemu-iotests/271 create mode 100644 tests/qemu-iotests/271.out diff --git a/tests/qemu-iotests/271 b/tests/qemu-iotests/271 new file mode 100755 index 0000000000..48f4d8d8ce --- /dev/null +++ b/tests/qemu-iotests/271 @@ -0,0 +1,359 @@ +#!/bin/bash +# +# Test qcow2 images with extended L2 entries +# +# Copyright (C) 2019-2020 Igalia, S.L. +# Author: Alberto Garcia +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# + +# creator +owner=3Dberto@igalia.com + +seq=3D"$(basename $0)" +echo "QA output created by $seq" + +here=3D"$PWD" +status=3D1 # failure is the default! + +_cleanup() +{ + _cleanup_test_img + rm -f "$TEST_IMG.raw" + rm -f "$TEST_IMG.backing" +} +trap "_cleanup; exit \$status" 0 1 2 3 15 + +# get standard environment, filters and checks +. ./common.rc +. ./common.filter + +_supported_fmt qcow2 +_supported_proto file nfs +_supported_os Linux + +IMGOPTS=3D"extended_l2=3Don" +l2_offset=3D262144 # 0x40000 + +_verify_img() +{ + $QEMU_IMG compare "$TEST_IMG" "$TEST_IMG.raw" | grep -v 'Images are id= entical' + $QEMU_IMG check "$TEST_IMG" | _filter_qemu_img_check | \ + grep -v 'No errors were found on the image' +} + +# Compare the bitmap of an extended L2 entry against an expected value +_verify_l2_bitmap() +{ + entry_no=3D"$1" # L2 entry number, starting from 0 + expected_alloc=3D"$2" # Space-separated list of allocated subcluster = indexes + expected_zero=3D"$3" # Space-separated list of zero subcluster index= es + + offset=3D$(($l2_offset + $entry_no * 16)) + entry=3D`peek_file_be "$TEST_IMG" $offset 8` + offset=3D$(($offset + 8)) + bitmap=3D`peek_file_be "$TEST_IMG" $offset 8` + + expected_bitmap=3D0 + for bit in $expected_alloc; do + expected_bitmap=3D$(($expected_bitmap | (1 << $bit))) + done + for bit in $expected_zero; do + expected_bitmap=3D$(($expected_bitmap | (1 << (32 + $bit)))) + done + expected_bitmap=3D`printf "%llu" $expected_bitmap` + + printf "L2 entry #%d: 0x%016lx %016lx\n" "$entry_no" "$entry" "$bitmap" + if [ "$bitmap" !=3D "$expected_bitmap" ]; then + printf "ERROR: expecting bitmap 0x%016lx\n" "$expected_bitma= p" + fi +} + +_test_write() +{ + cmd=3D"$1" + alloc_bitmap=3D"$2" + zero_bitmap=3D"$3" + l2_entry_idx=3D"$4" + [ -n "$l2_entry_idx" ] || l2_entry_idx=3D0 + raw_cmd=3D`echo $cmd | sed s/-c//` # Raw images don't support -c + echo "$cmd" + $QEMU_IO -c "$cmd" "$TEST_IMG" | _filter_qemu_io + $QEMU_IO -c "$raw_cmd" -f raw "$TEST_IMG.raw" | _filter_qemu_io + _verify_img + _verify_l2_bitmap "$l2_entry_idx" "$alloc_bitmap" "$zero_bitmap" +} + +_reset_img() +{ + $QEMU_IMG create -f raw "$TEST_IMG.raw" 1M | _filter_img_create + if [ "$use_backing_file" =3D "yes" ]; then + $QEMU_IMG create -f raw "$TEST_IMG.backing" 1M | _filter_img_create + $QEMU_IO -c 'write -q -P 0xFF 0 1M' -f raw "$TEST_IMG.backing" | _= filter_qemu_io + $QEMU_IO -c 'write -q -P 0xFF 0 1M' -f raw "$TEST_IMG.raw" | _filt= er_qemu_io + _make_test_img -b "$TEST_IMG.backing" 1M + else + _make_test_img 1M + fi +} + +# Test that writing to an image with subclusters produces the expected +# results, in images with and without backing files +for use_backing_file in yes no; do + echo + echo "### Standard write tests (backing file: $use_backing_file) ###" + echo + _reset_img + ### Write subcluster #0 (beginning of subcluster) ### + alloc=3D"0"; zero=3D"" + _test_write 'write -q -P 1 0 1k' "$alloc" "$zero" + + ### Write subcluster #1 (middle of subcluster) ### + alloc=3D"0 1"; zero=3D"" + _test_write 'write -q -P 2 3k 512' "$alloc" "$zero" + + ### Write subcluster #2 (end of subcluster) ### + alloc=3D"0 1 2"; zero=3D"" + _test_write 'write -q -P 3 5k 1k' "$alloc" "$zero" + + ### Write subcluster #3 (full subcluster) ### + alloc=3D"0 1 2 3"; zero=3D"" + _test_write 'write -q -P 4 6k 2k' "$alloc" "$zero" + + ### Write subclusters #4-6 (full subclusters) ### + alloc=3D"`seq 0 6`"; zero=3D"" + _test_write 'write -q -P 5 8k 6k' "$alloc" "$zero" + + ### Write subclusters #7-9 (partial subclusters) ### + alloc=3D"`seq 0 9`"; zero=3D"" + _test_write 'write -q -P 6 15k 4k' "$alloc" "$zero" + + ### Write subcluster #16 (partial subcluster) ### + alloc=3D"`seq 0 9` 16"; zero=3D"" + _test_write 'write -q -P 7 32k 1k' "$alloc" "$zero" + + ### Write subcluster #31-#34 (cluster overlap) ### + alloc=3D"`seq 0 9` 16 31"; zero=3D"" + _test_write 'write -q -P 8 63k 4k' "$alloc" "$zero" + alloc=3D"0 1" ; zero=3D"" + _verify_l2_bitmap 1 "$alloc" "$zero" + + ### Zero subcluster #1 (TODO: use the "all zeros" bit) + alloc=3D"`seq 0 9` 16 31"; zero=3D"" + _test_write 'write -q -z 2k 2k' "$alloc" "$zero" + + ### Zero cluster #0 + alloc=3D""; zero=3D"`seq 0 31`" + _test_write 'write -q -z 0 64k' "$alloc" "$zero" + + ### Fill cluster #0 with data + alloc=3D"`seq 0 31`"; zero=3D"" + _test_write 'write -q -P 9 0 64k' "$alloc" "$zero" + + ### Zero and unmap half of cluster #0 (this won't unmap it) + alloc=3D"`seq 0 31`"; zero=3D"" + _test_write 'write -q -z -u 0 32k' "$alloc" "$zero" + + ### Zero and unmap cluster #0 + alloc=3D""; zero=3D"`seq 0 31`" + _test_write 'write -q -z -u 0 64k' "$alloc" "$zero" + + ### Write subcluster #1 (middle of subcluster) + alloc=3D"1"; zero=3D"0 `seq 2 31`" + _test_write 'write -q -P 10 3k 512' "$alloc" "$zero" + + ### Fill cluster #0 with data + alloc=3D"`seq 0 31`"; zero=3D"" + _test_write 'write -q -P 11 0 64k' "$alloc" "$zero" + + ### Discard cluster #0 + alloc=3D""; zero=3D"`seq 0 31`" + _test_write 'discard -q 0 64k' "$alloc" "$zero" + + ### Write compressed data to cluster #0 + alloc=3D""; zero=3D"" + _test_write 'write -q -c -P 12 0 64k' "$alloc" "$zero" + + ### Write subcluster #2 (middle of subcluster) + alloc=3D"`seq 0 31`"; zero=3D"" + _test_write 'write -q -P 13 3k 512' "$alloc" "$zero" + + ### Zeroize an unallocated cluster (#2) + alloc=3D""; zero=3D"`seq 0 31`" + _test_write 'write -q -z 128k 64k' "$alloc" "$zero" 2 + + ### Partially zeroize an unallocated cluster (#3) + if [ "$use_backing_file" =3D "yes" ]; then + alloc=3D"`seq 0 15`"; zero=3D"" + else + alloc=3D""; zero=3D"`seq 0 31`" + fi + _test_write 'write -q -z 192k 32k' "$alloc" "$zero" 3 +done + +for use_backing_file in yes no; do + echo + echo "### Discarding clusters with non-zero bitmaps (backing file: $us= e_backing_file) ###" + echo + if [ "$use_backing_file" =3D "yes" ]; then + _make_test_img -b "$TEST_IMG.backing" 1M + else + _make_test_img 1M + fi + # Write clusters #0-#2 and then discard them + $QEMU_IO -c 'write -q 0 128k' "$TEST_IMG" + $QEMU_IO -c 'discard -q 0 128k' "$TEST_IMG" + # 'qemu-io discard' doesn't do a full discard, it zeroizes the + # cluster, so both clusters have all zero bits set now + alloc=3D""; zero=3D"`seq 0 31`" + _verify_l2_bitmap 0 "$alloc" "$zero" + _verify_l2_bitmap 1 "$alloc" "$zero" + # Now deallocate half of the subclusters of the first cluster + poke_file "$TEST_IMG" $(($l2_offset+8)) "\x00\x00" + # Discard cluster #0 again to see how the zero bits have changed + $QEMU_IO -c 'discard -q 0 64k' "$TEST_IMG" + # And do a full discard of cluster #1 by shrinking and growing the ima= ge + $QEMU_IMG resize --shrink "$TEST_IMG" 64k + $QEMU_IMG resize "$TEST_IMG" 1M + # A normal discard sets all 'zero' bits only if the image has a + # backing file, otherwise it won't touch them. + if [ "$use_backing_file" =3D "yes" ]; then + alloc=3D""; zero=3D"`seq 0 31`" + else + alloc=3D""; zero=3D"`seq 0 15`" + fi + _verify_l2_bitmap 0 "$alloc" "$zero" + # A full discard should clear the L2 entry completely + alloc=3D""; zero=3D"" + _verify_l2_bitmap 1 "$alloc" "$zero" +done + +# Test that corrupted L2 entries are detected in both read and write +# operations +for corruption_test_cmd in read write; do + echo + echo "### Corrupted L2 entries - $corruption_test_cmd test (allocated)= ###" + echo + echo "# 'cluster is zero' bit set on the standard cluster descriptor" + echo + _make_test_img 1M + $QEMU_IO -c 'write -q 0 2k' "$TEST_IMG" + poke_file "$TEST_IMG" $(($l2_offset+7)) "\x01" + alloc=3D"0"; zero=3D"" + _verify_l2_bitmap 0 "$alloc" "$zero" + $QEMU_IO -c "$corruption_test_cmd 0 1k" "$TEST_IMG" + + echo + echo "# Both 'subcluster is zero' and 'subcluster is allocated' bits s= et" + echo + _make_test_img 1M + $QEMU_IO -c 'write -q 0 2k' "$TEST_IMG" + poke_file "$TEST_IMG" $(($l2_offset+11)) "\x01" + alloc=3D"0"; zero=3D"0" + _verify_l2_bitmap 0 "$alloc" "$zero" + $QEMU_IO -c "$corruption_test_cmd 0 1k" "$TEST_IMG" + + echo + echo "### Corrupted L2 entries - $corruption_test_cmd test (unallocate= d) ###" + echo + echo "# 'cluster is zero' bit set on the standard cluster descriptor" + echo + _make_test_img 1M + # We want to corrupt the (empty) L2 entry from cluster #0, + # but we write to #4 in order to initialize the L2 table first + $QEMU_IO -c 'write -q 256k 1k' "$TEST_IMG" + poke_file "$TEST_IMG" $(($l2_offset+7)) "\x01" + alloc=3D""; zero=3D"" + _verify_l2_bitmap 0 "$alloc" "$zero" + $QEMU_IO -c "$corruption_test_cmd 0 1k" "$TEST_IMG" + + echo + echo "# 'subcluster is allocated' bit set" + echo + _make_test_img 1M + # We want to corrupt the (empty) L2 entry from cluster #0, + # but we write to #4 in order to initialize the L2 table first + $QEMU_IO -c 'write -q 256k 1k' "$TEST_IMG" + poke_file "$TEST_IMG" $(($l2_offset+15)) "\x01" + alloc=3D"0"; zero=3D"" + _verify_l2_bitmap 0 "$alloc" "$zero" + $QEMU_IO -c "$corruption_test_cmd 0 1k" "$TEST_IMG" + + echo + echo "# Both 'subcluster is zero' and 'subcluster is allocated' bits s= et" + echo + _make_test_img 1M + # We want to corrupt the (empty) L2 entry from cluster #0, + # but we write to #4 in order to initialize the L2 table first + $QEMU_IO -c 'write -q 256k 1k' "$TEST_IMG" + poke_file "$TEST_IMG" $(($l2_offset+8)) "\x00\x00\x00\x01\x00\x00\x00\= x01" + alloc=3D"0"; zero=3D"0" + _verify_l2_bitmap 0 "$alloc" "$zero" + $QEMU_IO -c "$corruption_test_cmd 0 1k" "$TEST_IMG" + + echo + echo "### Compressed cluster with subcluster bitmap !=3D 0 - $corrupti= on_test_cmd test ###" + echo + # We actually don't consider this a corrupted image. + # The bitmap in compressed clusters is unused so QEMU should just igno= re it. + _make_test_img 1M + $QEMU_IO -c 'write -q -P 11 -c 0 64k' "$TEST_IMG" + poke_file "$TEST_IMG" $(($l2_offset+11)) "\x01\x01" + alloc=3D"24"; zero=3D"0" + _verify_l2_bitmap 0 "$alloc" "$zero" + $QEMU_IO -c "$corruption_test_cmd -P 11 0 64k" "$TEST_IMG" | _filter_q= emu_io +done + +echo +echo "### Image creation options ###" +echo +echo "# cluster_size < 16k" +IMGOPTS=3D"extended_l2=3Don,cluster_size=3D8k" _make_test_img 1M + +echo "# backing file and preallocation=3Dmetadata" +IMGOPTS=3D"extended_l2=3Don,preallocation=3Dmetadata" _make_test_img -b "$= TEST_IMG.backing" 1M + +echo "# backing file and preallocation=3Dfalloc" +IMGOPTS=3D"extended_l2=3Don,preallocation=3Dfalloc" _make_test_img -b "$TE= ST_IMG.backing" 1M + +echo "# backing file and preallocation=3Dfull" +IMGOPTS=3D"extended_l2=3Don,preallocation=3Dfull" _make_test_img -b "$TEST= _IMG.backing" 1M + +echo +echo "### qemu-img measure ###" +echo +echo "# 512MB, extended_l2=3Doff" # This needs one L2 table +$QEMU_IMG measure --size 512M -O qcow2 -o extended_l2=3Doff +echo "# 512MB, extended_l2=3Don" # This needs two L2 tables +$QEMU_IMG measure --size 512M -O qcow2 -o extended_l2=3Don + +echo "# 16K clusters, 64GB, extended_l2=3Doff" # This needs one L1 table +$QEMU_IMG measure --size 64G -O qcow2 -o cluster_size=3D16k,extended_l2=3D= off +echo "# 16K clusters, 64GB, extended_l2=3Don" # This needs two L2 tables +$QEMU_IMG measure --size 64G -O qcow2 -o cluster_size=3D16k,extended_l2=3D= on + +echo "# 8k clusters" # This should fail +$QEMU_IMG measure --size 1M -O qcow2 -o cluster_size=3D8k,extended_l2=3Don + +echo "# 1024 TB" # Maximum allowed size with extended_l2=3Don and 64K clus= ters +$QEMU_IMG measure --size 1024T -O qcow2 -o extended_l2=3Don +echo "# 1025 TB" # This should fail +$QEMU_IMG measure --size 1025T -O qcow2 -o extended_l2=3Don + +# success, all done +echo "*** done" +rm -f $seq.full +status=3D0 + diff --git a/tests/qemu-iotests/271.out b/tests/qemu-iotests/271.out new file mode 100644 index 0000000000..c36dcaafc4 --- /dev/null +++ b/tests/qemu-iotests/271.out @@ -0,0 +1,244 @@ +QA output created by 271 + +### Standard write tests (backing file: yes) ### + +Formatting 'TEST_DIR/t.IMGFMT.raw', fmt=3Draw size=3D1048576 +Formatting 'TEST_DIR/t.IMGFMT.backing', fmt=3Draw size=3D1048576 +Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D1048576 backing_file= =3DTEST_DIR/t.IMGFMT.backing +write -q -P 1 0 1k +L2 entry #0: 0x8000000000050000 0000000000000001 +write -q -P 2 3k 512 +L2 entry #0: 0x8000000000050000 0000000000000003 +write -q -P 3 5k 1k +L2 entry #0: 0x8000000000050000 0000000000000007 +write -q -P 4 6k 2k +L2 entry #0: 0x8000000000050000 000000000000000f +write -q -P 5 8k 6k +L2 entry #0: 0x8000000000050000 000000000000007f +write -q -P 6 15k 4k +L2 entry #0: 0x8000000000050000 00000000000003ff +write -q -P 7 32k 1k +L2 entry #0: 0x8000000000050000 00000000000103ff +write -q -P 8 63k 4k +L2 entry #0: 0x8000000000050000 00000000800103ff +L2 entry #1: 0x8000000000060000 0000000000000003 +write -q -z 2k 2k +L2 entry #0: 0x8000000000050000 00000000800103ff +write -q -z 0 64k +L2 entry #0: 0x8000000000050000 ffffffff00000000 +write -q -P 9 0 64k +L2 entry #0: 0x8000000000050000 00000000ffffffff +write -q -z -u 0 32k +L2 entry #0: 0x8000000000050000 00000000ffffffff +write -q -z -u 0 64k +L2 entry #0: 0x0000000000000000 ffffffff00000000 +write -q -P 10 3k 512 +L2 entry #0: 0x8000000000050000 fffffffd00000002 +write -q -P 11 0 64k +L2 entry #0: 0x8000000000050000 00000000ffffffff +discard -q 0 64k +L2 entry #0: 0x0000000000000000 ffffffff00000000 +write -q -c -P 12 0 64k +L2 entry #0: 0x4000000000050000 0000000000000000 +write -q -P 13 3k 512 +L2 entry #0: 0x8000000000070000 00000000ffffffff +write -q -z 128k 64k +L2 entry #2: 0x0000000000000000 ffffffff00000000 +write -q -z 192k 32k +L2 entry #3: 0x8000000000050000 000000000000ffff + +### Standard write tests (backing file: no) ### + +Formatting 'TEST_DIR/t.IMGFMT.raw', fmt=3Draw size=3D1048576 +Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D1048576 +write -q -P 1 0 1k +L2 entry #0: 0x8000000000050000 0000000000000001 +write -q -P 2 3k 512 +L2 entry #0: 0x8000000000050000 0000000000000003 +write -q -P 3 5k 1k +L2 entry #0: 0x8000000000050000 0000000000000007 +write -q -P 4 6k 2k +L2 entry #0: 0x8000000000050000 000000000000000f +write -q -P 5 8k 6k +L2 entry #0: 0x8000000000050000 000000000000007f +write -q -P 6 15k 4k +L2 entry #0: 0x8000000000050000 00000000000003ff +write -q -P 7 32k 1k +L2 entry #0: 0x8000000000050000 00000000000103ff +write -q -P 8 63k 4k +L2 entry #0: 0x8000000000050000 00000000800103ff +L2 entry #1: 0x8000000000060000 0000000000000003 +write -q -z 2k 2k +L2 entry #0: 0x8000000000050000 00000000800103ff +write -q -z 0 64k +L2 entry #0: 0x8000000000050000 ffffffff00000000 +write -q -P 9 0 64k +L2 entry #0: 0x8000000000050000 00000000ffffffff +write -q -z -u 0 32k +L2 entry #0: 0x8000000000050000 00000000ffffffff +write -q -z -u 0 64k +L2 entry #0: 0x0000000000000000 ffffffff00000000 +write -q -P 10 3k 512 +L2 entry #0: 0x8000000000050000 fffffffd00000002 +write -q -P 11 0 64k +L2 entry #0: 0x8000000000050000 00000000ffffffff +discard -q 0 64k +L2 entry #0: 0x0000000000000000 ffffffff00000000 +write -q -c -P 12 0 64k +L2 entry #0: 0x4000000000050000 0000000000000000 +write -q -P 13 3k 512 +L2 entry #0: 0x8000000000070000 00000000ffffffff +write -q -z 128k 64k +L2 entry #2: 0x0000000000000000 ffffffff00000000 +write -q -z 192k 32k +L2 entry #3: 0x0000000000000000 ffffffff00000000 + +### Discarding clusters with non-zero bitmaps (backing file: yes) ### + +Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D1048576 backing_file= =3DTEST_DIR/t.IMGFMT.backing +L2 entry #0: 0x0000000000000000 ffffffff00000000 +L2 entry #1: 0x0000000000000000 ffffffff00000000 +Image resized. +Image resized. +L2 entry #0: 0x0000000000000000 ffffffff00000000 +L2 entry #1: 0x0000000000000000 0000000000000000 + +### Discarding clusters with non-zero bitmaps (backing file: no) ### + +Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D1048576 +L2 entry #0: 0x0000000000000000 ffffffff00000000 +L2 entry #1: 0x0000000000000000 ffffffff00000000 +Image resized. +Image resized. +L2 entry #0: 0x0000000000000000 0000ffff00000000 +L2 entry #1: 0x0000000000000000 0000000000000000 + +### Corrupted L2 entries - read test (allocated) ### + +# 'cluster is zero' bit set on the standard cluster descriptor + +Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D1048576 +L2 entry #0: 0x8000000000050001 0000000000000001 +qcow2: Marking image as corrupt: Invalid cluster entry found (L2 offset: = 0x40000, L2 index: 0); further corruption events will be suppressed +read failed: Input/output error + +# Both 'subcluster is zero' and 'subcluster is allocated' bits set + +Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D1048576 +L2 entry #0: 0x8000000000050000 0000000100000001 +qcow2: Marking image as corrupt: Invalid cluster entry found (L2 offset: = 0x40000, L2 index: 0); further corruption events will be suppressed +read failed: Input/output error + +### Corrupted L2 entries - read test (unallocated) ### + +# 'cluster is zero' bit set on the standard cluster descriptor + +Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D1048576 +L2 entry #0: 0x0000000000000001 0000000000000000 +qcow2: Marking image as corrupt: Invalid cluster entry found (L2 offset: = 0x40000, L2 index: 0); further corruption events will be suppressed +read failed: Input/output error + +# 'subcluster is allocated' bit set + +Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D1048576 +L2 entry #0: 0x0000000000000000 0000000000000001 +qcow2: Marking image as corrupt: Invalid cluster entry found (L2 offset: = 0x40000, L2 index: 0); further corruption events will be suppressed +read failed: Input/output error + +# Both 'subcluster is zero' and 'subcluster is allocated' bits set + +Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D1048576 +L2 entry #0: 0x0000000000000000 0000000100000001 +qcow2: Marking image as corrupt: Invalid cluster entry found (L2 offset: = 0x40000, L2 index: 0); further corruption events will be suppressed +read failed: Input/output error + +### Compressed cluster with subcluster bitmap !=3D 0 - read test ### + +Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D1048576 +L2 entry #0: 0x4000000000050000 0000000101000000 +read 65536/65536 bytes at offset 0 +64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +### Corrupted L2 entries - write test (allocated) ### + +# 'cluster is zero' bit set on the standard cluster descriptor + +Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D1048576 +L2 entry #0: 0x8000000000050001 0000000000000001 +qcow2: Marking image as corrupt: Invalid cluster entry found (L2 offset: = 0x40000, L2 index: 0); further corruption events will be suppressed +write failed: Input/output error + +# Both 'subcluster is zero' and 'subcluster is allocated' bits set + +Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D1048576 +L2 entry #0: 0x8000000000050000 0000000100000001 +qcow2: Marking image as corrupt: Invalid cluster entry found (L2 offset: = 0x40000, L2 index: 0); further corruption events will be suppressed +write failed: Input/output error + +### Corrupted L2 entries - write test (unallocated) ### + +# 'cluster is zero' bit set on the standard cluster descriptor + +Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D1048576 +L2 entry #0: 0x0000000000000001 0000000000000000 +qcow2: Marking image as corrupt: Invalid cluster entry found (L2 offset: = 0x40000, L2 index: 0); further corruption events will be suppressed +write failed: Input/output error + +# 'subcluster is allocated' bit set + +Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D1048576 +L2 entry #0: 0x0000000000000000 0000000000000001 +qcow2: Marking image as corrupt: Invalid cluster entry found (L2 offset: = 0x40000, L2 index: 0); further corruption events will be suppressed +write failed: Input/output error + +# Both 'subcluster is zero' and 'subcluster is allocated' bits set + +Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D1048576 +L2 entry #0: 0x0000000000000000 0000000100000001 +qcow2: Marking image as corrupt: Invalid cluster entry found (L2 offset: = 0x40000, L2 index: 0); further corruption events will be suppressed +write failed: Input/output error + +### Compressed cluster with subcluster bitmap !=3D 0 - write test ### + +Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D1048576 +L2 entry #0: 0x4000000000050000 0000000101000000 +wrote 65536/65536 bytes at offset 0 +64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +### Image creation options ### + +# cluster_size < 16k +qemu-img: TEST_DIR/t.IMGFMT: Extended L2 entries are only supported with c= luster sizes of at least 16384 bytes +Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D1048576 +# backing file and preallocation=3Dmetadata +qemu-img: TEST_DIR/t.IMGFMT: Backing file and preallocation cannot be used= at the same time +Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D1048576 backing_file= =3DTEST_DIR/t.IMGFMT.backing preallocation=3Dmetadata +# backing file and preallocation=3Dfalloc +qemu-img: TEST_DIR/t.IMGFMT: Backing file and preallocation cannot be used= at the same time +Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D1048576 backing_file= =3DTEST_DIR/t.IMGFMT.backing preallocation=3Dfalloc +# backing file and preallocation=3Dfull +qemu-img: TEST_DIR/t.IMGFMT: Backing file and preallocation cannot be used= at the same time +Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D1048576 backing_file= =3DTEST_DIR/t.IMGFMT.backing preallocation=3Dfull + +### qemu-img measure ### + +# 512MB, extended_l2=3Doff +required size: 327680 +fully allocated size: 537198592 +# 512MB, extended_l2=3Don +required size: 393216 +fully allocated size: 537264128 +# 16K clusters, 64GB, extended_l2=3Doff +required size: 42008576 +fully allocated size: 68761485312 +# 16K clusters, 64GB, extended_l2=3Don +required size: 75579392 +fully allocated size: 68795056128 +# 8k clusters +qemu-img: Extended L2 entries are only supported with cluster sizes of at = least 16384 bytes +# 1024 TB +required size: 309285027840 +fully allocated size: 1126209191870464 +# 1025 TB +qemu-img: The image size is too large (try using a larger cluster size) +*** done diff --git a/tests/qemu-iotests/group b/tests/qemu-iotests/group index ec2b2302e5..d7b0e03737 100644 --- a/tests/qemu-iotests/group +++ b/tests/qemu-iotests/group @@ -284,6 +284,7 @@ 267 rw auto quick snapshot 268 rw auto quick 270 rw backing quick +271 rw auto 272 rw 273 backing quick 277 rw quick --=20 2.20.1