From patchwork Tue May 5 17:38:09 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alberto Garcia X-Patchwork-Id: 1283817 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=2001:470:142::17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=igalia.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=igalia.com header.i=@igalia.com header.a=rsa-sha256 header.s=20170329 header.b=ngOBJkid; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:470:142::17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49GnHD23BNz9sSd for ; Wed, 6 May 2020 03:47:20 +1000 (AEST) Received: from localhost ([::1]:33270 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jW1f3-0001Ng-AQ for incoming@patchwork.ozlabs.org; Tue, 05 May 2020 13:47:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44006) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jW1XN-0006Ha-3h; Tue, 05 May 2020 13:39:21 -0400 Received: from fanzine.igalia.com ([178.60.130.6]:38806) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jW1XJ-00089d-9I; Tue, 05 May 2020 13:39:20 -0400 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=kk1LPkVj3R9x3+LY3iQIo7R9NJAWgBHF21IX+kgx5L0=; b=ngOBJkidR0Ut28DXBKPPbB1KsKecsKUL/+hkBkXG9oAzCmMwWLPnm6lQ7q5TlyFmJYy5LQw1GPBuZ5DfeoWCTqPONIirZMXBcILxbrrBcY2Fd0LtpuxWx7kRihCLmskr+swEOOFV7nyvxpT4xpx/VlduTnK+r10oNk/fTNVOrCluXJjdW2/szEbg6jHgTS4wS4sd7WOucuO75nyHQLAP6m20pvMI97vX6QdrzoqONiut93fAc079kWdp2ndap6plI0f5gjskpKN2Y4B4qVFnp1+9v4KDGiok4zM0SCnnd1rcLqiUfs3uGHyOAy3vAWJvYSVTbQ+MrxVlzcZPI85zAQ==; Received: from static.160.43.0.81.ibercom.com ([81.0.43.160] helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1jW1Ws-00025L-8A; Tue, 05 May 2020 19:38:50 +0200 Received: from berto by perseus.local with local (Exim 4.92) (envelope-from ) id 1jW1Wc-00043p-Nb; Tue, 05 May 2020 19:38:34 +0200 From: Alberto Garcia To: qemu-devel@nongnu.org Subject: [PATCH v5 09/31] qcow2: Add subcluster-related fields to BDRVQcow2State Date: Tue, 5 May 2020 19:38:09 +0200 Message-Id: <6afe86287abec085c4cac2ee409b5bcca48d1442.1588699789.git.berto@igalia.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 Received-SPF: pass client-ip=178.60.130.6; envelope-from=berto@igalia.com; helo=fanzine.igalia.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/05/05 13:38:50 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action 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 , Vladimir Sementsov-Ogievskiy , Alberto Garcia , qemu-block@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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 = subcluster_size Images without subclusters are treated as if they had exactly one subcluster per cluster (i.e. subcluster_size = 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 5e8036c3dd..9d8ca8068c 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) +#define QCOW_EXTL2_SUBCLUSTERS_PER_CLUSTER 32 + #define MIN_CLUSTER_BITS 9 #define MAX_CLUSTER_BITS 21 @@ -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 951fc19dd2..e5ae8aaff7 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -1380,6 +1380,11 @@ static int coroutine_fn qcow2_do_open(BlockDriverState *bs, QDict *options, } } + s->subclusters_per_cluster = + has_subclusters(s) ? QCOW_EXTL2_SUBCLUSTERS_PER_CLUSTER : 1; + s->subcluster_size = s->cluster_size / s->subclusters_per_cluster; + s->subcluster_bits = 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 "