From nobody Tue May 14 15:45:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1620905003; cv=none; d=zohomail.com; s=zohoarc; b=dm2aPa2EDaxbNRhOXmj4GhE5CokTAlr1gUfmFWtNPuf9DaA2JiBqprI8fff9jErDOEcKXpzGF2H+AovWEEyEs0BFQNpk2xlnPWMiY8pVcSuHxYwjQpMqYBJ3oBeLIgJrBkdfqx3xoUZFVr2mrViFXd2yr6uyW+cTdsvgOzzZJ2M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620905003; h=Content-Type:Content-Transfer-Encoding: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=DapgYTv/TNADkWMOcQgkc8rfWrGR+V8TMl2/8P+J7aM=; b=C10pw5v77yVIM/gdtbaZ5nfuG1uNe4ul+4Wx7l1uUiMuf5K2dbo37LvAmVVTdlkrkC3EB7lwliFZKf+nWkNur9XGAkMUeVCo5moUs6oDMq1SyoL8zRB9w5w6xmX8wyHftov4agCSETekuefLCYVvt7HkBp2Gorceq35dLic9ueA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1620905003851176.82328512085462; Thu, 13 May 2021 04:23:23 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-491-RCzI15JmMgKixJHQ9qUAKg-1; Thu, 13 May 2021 07:23:20 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B75518186E1; Thu, 13 May 2021 11:23:14 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 580AC19D7C; Thu, 13 May 2021 11:23:14 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id A366218005B6; Thu, 13 May 2021 11:23:11 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 14DBNBf3000392 for ; Thu, 13 May 2021 07:23:11 -0400 Received: by smtp.corp.redhat.com (Postfix) id 271BD5D736; Thu, 13 May 2021 11:23:11 +0000 (UTC) Received: from antique-work.lan (unknown [10.40.194.205]) by smtp.corp.redhat.com (Postfix) with ESMTP id 70C2E6249C for ; Thu, 13 May 2021 11:23:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1620905002; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=DapgYTv/TNADkWMOcQgkc8rfWrGR+V8TMl2/8P+J7aM=; b=icRXMCWMpCMVxELYWsvIE5ZYreEhZkSXOzBq0SDePDk0Qm+uxiO0uWl4k9MI8zKla/9iaL glfKUP1TfKdnquSOJr8vioZBsN1Mm/AZX+eopRjdNJBBLSPQgYs5JhDbNPa/ldXlq/mtQj LL8sTpwJTmOMmme4OUFEpjRBR29UvzM= X-MC-Unique: RCzI15JmMgKixJHQ9qUAKg-1 From: Pavel Hrdina To: libvir-list@redhat.com Subject: [libvirt PATCH 1/2] storage: add support for QCOW2 cluster_size option Date: Thu, 13 May 2021 13:23:04 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" The default value hard-coded in QEMU (64KiB) is not always the ideal. Having a possibility to set the cluster_size by user may in specific use-cases improve performance for QCOW2 images. QEMU internally has some limits, the value has to be between 512B and 2048KiB and must by power of two, except when the image has Extended L2 Entries the minimal value has to be 16KiB. Since qemu-img ensures the value is correct and the limit is not always the same libvirt will not duplicate any of these checks as the error message from qemu-img is good enough: Cluster size must be a power of two between 512 and 2048k Resolves: https://gitlab.com/libvirt/libvirt/-/issues/154 Signed-off-by: Pavel Hrdina Reviewed-by: Han Han Tested-by: Han Han --- docs/formatstorage.html.in | 6 ++++++ docs/schemas/storagecommon.rng | 7 +++++++ docs/schemas/storagevol.rng | 3 +++ src/conf/storage_conf.c | 12 ++++++++++++ src/storage/storage_util.c | 5 +++++ .../qcow2-clusterSize.argv | 6 ++++++ tests/storagevolxml2argvtest.c | 4 ++++ .../vol-qcow2-clusterSize.xml | 17 +++++++++++++++++ .../vol-qcow2-clusterSize.xml | 17 +++++++++++++++++ tests/storagevolxml2xmltest.c | 1 + 10 files changed, 78 insertions(+) create mode 100644 tests/storagevolxml2argvdata/qcow2-clusterSize.argv create mode 100644 tests/storagevolxml2xmlin/vol-qcow2-clusterSize.xml create mode 100644 tests/storagevolxml2xmlout/vol-qcow2-clusterSize.xml diff --git a/docs/formatstorage.html.in b/docs/formatstorage.html.in index cac44503da..1cf65b0b18 100644 --- a/docs/formatstorage.html.in +++ b/docs/formatstorage.html.in @@ -791,6 +791,7 @@ </encryption> <compat>1.1</compat> <nocow/> + <clusterSize unit=3D'KiB'>64</clusterSize> <features> <lazy_refcounts/> </features> @@ -867,6 +868,11 @@ the file image is used in VM. To create non-raw file images, it requires QEMU version since 2.1. Since 1.2.7= +
clusterSize
+
Changes the qcow2 cluster size where smaller size can improve i= mage + file size whereas larger size can improve performance. + Since 7.4.0 +
features
Format-specific features. Only used for qcow2 now. Valid sub-elements are: diff --git a/docs/schemas/storagecommon.rng b/docs/schemas/storagecommon.rng index e3d08a8410..9ebb27700d 100644 --- a/docs/schemas/storagecommon.rng +++ b/docs/schemas/storagecommon.rng @@ -110,6 +110,13 @@ + + + + + + + diff --git a/docs/schemas/storagevol.rng b/docs/schemas/storagevol.rng index 22ce5eaa8d..3e0f482007 100644 --- a/docs/schemas/storagevol.rng +++ b/docs/schemas/storagevol.rng @@ -124,6 +124,9 @@ + + + diff --git a/src/conf/storage_conf.c b/src/conf/storage_conf.c index e481cac75c..0ecdb0969a 100644 --- a/src/conf/storage_conf.c +++ b/src/conf/storage_conf.c @@ -1416,6 +1416,13 @@ virStorageVolDefParseXML(virStoragePoolDef *pool, if (virXPathNode("./target/nocow", ctxt)) def->target.nocow =3D true; =20 + if (virParseScaledValue("./target/clusterSize", + "./target/clusterSize/@unit", + ctxt, &def->target.clusterSize, + 1, ULLONG_MAX, false) < 0) { + return NULL; + } + if (virXPathNode("./target/features", ctxt)) { if ((n =3D virXPathNodeSet("./target/features/*", ctxt, &nodes)) <= 0) return NULL; @@ -1580,6 +1587,11 @@ virStorageVolTargetDefFormat(virStorageVolOptions *o= ptions, =20 virBufferEscapeString(buf, "%s\n", def->compat); =20 + if (def->clusterSize > 0) { + virBufferAsprintf(buf, "%llu= \n", + def->clusterSize); + } + if (def->features) { size_t i; bool empty =3D virBitmapIsAllClear(def->features); diff --git a/src/storage/storage_util.c b/src/storage/storage_util.c index 2b0d08c65d..c8299852a3 100644 --- a/src/storage/storage_util.c +++ b/src/storage/storage_util.c @@ -664,6 +664,7 @@ struct _virStorageBackendQemuImgInfo { const char *path; unsigned long long size_arg; unsigned long long allocation; + unsigned long long clusterSize; bool encryption; bool preallocate; const char *compat; @@ -780,6 +781,9 @@ storageBackendCreateQemuImgOpts(virStorageEncryptionInf= oDef *encinfo, else if (info->format =3D=3D VIR_STORAGE_FILE_QCOW2) virBufferAddLit(&buf, "compat=3D0.10,"); =20 + if (info->clusterSize > 0) + virBufferAsprintf(&buf, "cluster_size=3D%llu,", info->clusterSize); + if (info->features && info->format =3D=3D VIR_STORAGE_FILE_QCOW2) { if (virBitmapIsBitSet(info->features, VIR_STORAGE_FILE_FEATURE_LAZY_REFCOUNTS)) { @@ -1130,6 +1134,7 @@ virStorageBackendCreateQemuImgCmdFromVol(virStoragePo= olObj *pool, .compat =3D vol->target.compat, .features =3D vol->target.features, .nocow =3D vol->target.nocow, + .clusterSize =3D vol->target.clusterSize, .secretAlias =3D NULL, }; virStorageEncryption *enc =3D vol->target.encryption; diff --git a/tests/storagevolxml2argvdata/qcow2-clusterSize.argv b/tests/st= oragevolxml2argvdata/qcow2-clusterSize.argv new file mode 100644 index 0000000000..94b1110ccc --- /dev/null +++ b/tests/storagevolxml2argvdata/qcow2-clusterSize.argv @@ -0,0 +1,6 @@ +qemu-img \ +create \ +-f qcow2 \ +-o compat=3D0.10,cluster_size=3D131072 \ +/var/lib/libvirt/images/OtherDemo.img \ +5242880K \ No newline at end of file diff --git a/tests/storagevolxml2argvtest.c b/tests/storagevolxml2argvtest.c index 6058d2b689..9597509f00 100644 --- a/tests/storagevolxml2argvtest.c +++ b/tests/storagevolxml2argvtest.c @@ -238,6 +238,10 @@ mymain(void) "pool-dir", "vol-qcow2-nocapacity-backing", NULL, NULL, "qcow2-nocapacity", 0); =20 + DO_TEST("pool-dir", "vol-qcow2-clusterSize", + NULL, NULL, + "qcow2-clusterSize", 0); + DO_TEST("pool-dir", "vol-file-iso", NULL, NULL, "iso", 0); diff --git a/tests/storagevolxml2xmlin/vol-qcow2-clusterSize.xml b/tests/st= oragevolxml2xmlin/vol-qcow2-clusterSize.xml new file mode 100644 index 0000000000..22534982a1 --- /dev/null +++ b/tests/storagevolxml2xmlin/vol-qcow2-clusterSize.xml @@ -0,0 +1,17 @@ + + OtherDemo.img + /var/lib/libvirt/images/OtherDemo.img + 5 + 294912 + + /var/lib/libvirt/images/OtherDemo.img + + + 0644 + 0 + 0 + + + 128 + + diff --git a/tests/storagevolxml2xmlout/vol-qcow2-clusterSize.xml b/tests/s= toragevolxml2xmlout/vol-qcow2-clusterSize.xml new file mode 100644 index 0000000000..393a492536 --- /dev/null +++ b/tests/storagevolxml2xmlout/vol-qcow2-clusterSize.xml @@ -0,0 +1,17 @@ + + OtherDemo.img + /var/lib/libvirt/images/OtherDemo.img + 5368709120 + 294912 + + /var/lib/libvirt/images/OtherDemo.img + + + 0644 + 0 + 0 + + + 131072 + + diff --git a/tests/storagevolxml2xmltest.c b/tests/storagevolxml2xmltest.c index ed24d98426..be38f50a51 100644 --- a/tests/storagevolxml2xmltest.c +++ b/tests/storagevolxml2xmltest.c @@ -88,6 +88,7 @@ mymain(void) DO_TEST("pool-dir", "vol-qcow2-nobacking"); DO_TEST("pool-dir", "vol-qcow2-encryption"); DO_TEST("pool-dir", "vol-qcow2-luks"); + DO_TEST("pool-dir", "vol-qcow2-clusterSize"); DO_TEST("pool-dir", "vol-luks"); DO_TEST("pool-dir", "vol-luks-cipher"); DO_TEST("pool-disk", "vol-partition"); --=20 2.31.1 From nobody Tue May 14 15:45:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1620905014; cv=none; d=zohomail.com; s=zohoarc; b=PzVzAHVlSj3eHNNbVyBgx0j5k7SgrUseA1xWVGaHdIL6s3td1eGueLWcCZsxZrtV/NdWS0Pv3KxFh0oyMyH2Wy5H3TmBnoAHpevMYH14JQk9a7fLhwI9tGhXkLvWYF3hD3JnN9ISnyxqAmYS/naIG3KkQq37FJLThGJcq8qQXjc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620905014; h=Content-Type:Content-Transfer-Encoding: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=UgTmH3DcO0OWNn5nYvVxpI4PN8GwZjj7O13Cpy1UheU=; b=Lh9y4Gk7LkeP+E5LKJ8WgEkb5b7RhEXgxpkrxvj1PkZXPCzGJXVTYxC3wJGzrn/DQ70D13xPyOM7ZMS0UcRYNJKHQ7ljKobVzNDzVRCudIGJkBa8ceai1PGNg/r4N1r7BL6aXuRyb+j0H/r0RDySZbFHaN3jIiwGnsIYZODLq9E= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1620905014928149.1218294296981; Thu, 13 May 2021 04:23:34 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-129-LyQAEBSONlOFFOU7btfGvw-1; Thu, 13 May 2021 07:23:31 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C7D45107ACCA; Thu, 13 May 2021 11:23:24 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A620B5D9E3; Thu, 13 May 2021 11:23:24 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 729C7180B463; Thu, 13 May 2021 11:23:24 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 14DBNCev000400 for ; Thu, 13 May 2021 07:23:12 -0400 Received: by smtp.corp.redhat.com (Postfix) id 05C9A5D736; Thu, 13 May 2021 11:23:12 +0000 (UTC) Received: from antique-work.lan (unknown [10.40.194.205]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7A17D5B6A3 for ; Thu, 13 May 2021 11:23:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1620905013; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=UgTmH3DcO0OWNn5nYvVxpI4PN8GwZjj7O13Cpy1UheU=; b=ECn7F+ATEJ2c5I/ic0I1MKGByrUqYC2nCKhUUHx4F7jn6GNa2pkicUeG5QqSwIF+9ifOVp aTcPQm1yVcl5IYR4JrrDbNf21qZDDiybkz25xxGhoWemrLXBwEc0hrthynxkR84b2xaVc3 G3wuPQ/cawBl3eZf0N5v/uqVuUtU/24= X-MC-Unique: LyQAEBSONlOFFOU7btfGvw-1 From: Pavel Hrdina To: libvir-list@redhat.com Subject: [libvirt PATCH 2/2] storage_file: add support to probe cluster_size from QCOW2 images Date: Thu, 13 May 2021 13:23:05 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" >From QEMU docs/interop/qcow2.txt : Byte 20 - 23: cluster_bits Number of bits that are used for addressing an offset within a cluster (1 << cluster_bits is the cluster size= ). With this patch libvirt will be able to report the current cluster_size for all existing storage volumes managed by storage driver. Signed-off-by: Pavel Hrdina Reviewed-by: Han Han Tested-by: Han Han --- src/storage/storage_util.c | 3 ++ src/storage_file/storage_file_probe.c | 55 +++++++++++++++++++-------- 2 files changed, 42 insertions(+), 16 deletions(-) diff --git a/src/storage/storage_util.c b/src/storage/storage_util.c index c8299852a3..a7c9355bf9 100644 --- a/src/storage/storage_util.c +++ b/src/storage/storage_util.c @@ -3483,6 +3483,9 @@ storageBackendProbeTarget(virStorageSource *target, if (meta->capacity) target->capacity =3D meta->capacity; =20 + if (meta->clusterSize > 0) + target->clusterSize =3D meta->clusterSize; + if (encryption && meta->encryption) { if (meta->encryption->payload_offset !=3D -1) target->capacity -=3D meta->encryption->payload_offset * 512; diff --git a/src/storage_file/storage_file_probe.c b/src/storage_file/stora= ge_file_probe.c index afe64da02e..423597049f 100644 --- a/src/storage_file/storage_file_probe.c +++ b/src/storage_file/storage_file_probe.c @@ -94,6 +94,9 @@ struct FileTypeInfo { /* Store a COW base image path (possibly relativ= e), * or NULL if there is no COW base image, to RES; * return BACKING_STORE_* */ + int clusterBitsOffset; /* Byte offset from start of file where we find + * number of cluster bits, -1 to skip. */ + int clusterBitsSize; /* Number of bytes for cluster bits. */ const struct FileEncryptionInfo *cryptInfo; /* Encryption info */ int (*getBackingStore)(char **res, int *format, const char *buf, size_t buf_size); @@ -116,7 +119,8 @@ qedGetBackingStore(char **, int *, const char *, size_t= ); #define QCOWX_HDR_VERSION (4) #define QCOWX_HDR_BACKING_FILE_OFFSET (QCOWX_HDR_VERSION+4) #define QCOWX_HDR_BACKING_FILE_SIZE (QCOWX_HDR_BACKING_FILE_OFFSET+8) -#define QCOWX_HDR_IMAGE_SIZE (QCOWX_HDR_BACKING_FILE_SIZE+4+4) +#define QCOWX_HDR_CLUSTER_BITS_OFFSET (QCOWX_HDR_BACKING_FILE_SIZE+4) +#define QCOWX_HDR_IMAGE_SIZE (QCOWX_HDR_CLUSTER_BITS_OFFSET+4) =20 #define QCOW1_HDR_CRYPT (QCOWX_HDR_IMAGE_SIZE+8+1+1+2) #define QCOW2_HDR_CRYPT (QCOWX_HDR_IMAGE_SIZE+8) @@ -238,18 +242,18 @@ static struct FileEncryptionInfo const qcow2Encryptio= nInfo[] =3D { =20 static struct FileTypeInfo const fileTypeInfo[] =3D { [VIR_STORAGE_FILE_NONE] =3D { 0, NULL, LV_LITTLE_ENDIAN, - -1, 0, {0}, 0, 0, 0, NULL, NULL, NULL }, + -1, 0, {0}, 0, 0, 0, -1, 0, NULL, NULL, NU= LL }, [VIR_STORAGE_FILE_RAW] =3D { 0, NULL, LV_LITTLE_ENDIAN, - -1, 0, {0}, 0, 0, 0, + -1, 0, {0}, 0, 0, 0, -1, 0, luksEncryptionInfo, NULL, NULL }, [VIR_STORAGE_FILE_DIR] =3D { 0, NULL, LV_LITTLE_ENDIAN, - -1, 0, {0}, 0, 0, 0, NULL, NULL, NULL }, + -1, 0, {0}, 0, 0, 0, -1, 0, NULL, NULL, NUL= L }, [VIR_STORAGE_FILE_BOCHS] =3D { /*"Bochs Virtual HD Image", */ /* Untested */ 0, NULL, LV_LITTLE_ENDIAN, 64, 4, {0x20000}, - 32+16+16+4+4+4+4+4, 8, 1, NULL, NULL, NULL + 32+16+16+4+4+4+4+4, 8, 1, -1, 0, NULL, NULL, NULL }, [VIR_STORAGE_FILE_CLOOP] =3D { /* #!/bin/sh @@ -258,7 +262,7 @@ static struct FileTypeInfo const fileTypeInfo[] =3D { */ /* Untested */ 0, NULL, LV_LITTLE_ENDIAN, -1, 0, {0}, - -1, 0, 0, NULL, NULL, NULL + -1, 0, 0, -1, 0, NULL, NULL, NULL }, [VIR_STORAGE_FILE_DMG] =3D { /* XXX QEMU says there's no magic for dmg, @@ -266,43 +270,44 @@ static struct FileTypeInfo const fileTypeInfo[] =3D { * would have to match) but then disables that check. */ 0, NULL, 0, -1, 0, {0}, - -1, 0, 0, NULL, NULL, NULL + -1, 0, 0, -1, 0, NULL, NULL, NULL }, [VIR_STORAGE_FILE_ISO] =3D { 32769, "CD001", LV_LITTLE_ENDIAN, -2, 0, {0}, - -1, 0, 0, NULL, NULL, NULL + -1, 0, 0, -1, 0, NULL, NULL, NULL }, [VIR_STORAGE_FILE_VPC] =3D { 0, "conectix", LV_BIG_ENDIAN, 12, 4, {0x10000}, - 8 + 4 + 4 + 8 + 4 + 4 + 2 + 2 + 4, 8, 1, NULL, NULL, NULL + 8 + 4 + 4 + 8 + 4 + 4 + 2 + 2 + 4, 8, 1, -1, 0, NULL, NULL, NULL }, /* TODO: add getBackingStore function */ [VIR_STORAGE_FILE_VDI] =3D { 64, "\x7f\x10\xda\xbe", LV_LITTLE_ENDIAN, 68, 4, {0x00010001}, - 64 + 5 * 4 + 256 + 7 * 4, 8, 1, NULL, NULL, NULL}, + 64 + 5 * 4 + 256 + 7 * 4, 8, 1, -1, 0, NULL, NULL, NULL}, =20 /* Not direct file formats, but used for various drivers */ [VIR_STORAGE_FILE_FAT] =3D { 0, NULL, LV_LITTLE_ENDIAN, - -1, 0, {0}, 0, 0, 0, NULL, NULL, NULL }, + -1, 0, {0}, 0, 0, 0, -1, 0, NULL, NULL, NUL= L }, [VIR_STORAGE_FILE_VHD] =3D { 0, NULL, LV_LITTLE_ENDIAN, - -1, 0, {0}, 0, 0, 0, NULL, NULL, NULL }, + -1, 0, {0}, 0, 0, 0, -1, 0, NULL, NULL, NUL= L }, [VIR_STORAGE_FILE_PLOOP] =3D { 0, "WithouFreSpacExt", LV_LITTLE_ENDIAN, -2, 0, {0}, PLOOP_IMAGE_SIZE_OFFSET, 0, - PLOOP_SIZE_MULTIPLIER, NULL, NULL, NULL }, + PLOOP_SIZE_MULTIPLIER, -1, 0, NULL, NULL,= NULL }, =20 /* All formats with a backing store probe below here */ [VIR_STORAGE_FILE_COW] =3D { 0, "OOOM", LV_BIG_ENDIAN, 4, 4, {2}, - 4+4+1024+4, 8, 1, NULL, cowGetBackingStore, NULL + 4+4+1024+4, 8, 1, -1, 0, NULL, cowGetBackingStore, NULL }, [VIR_STORAGE_FILE_QCOW] =3D { 0, "QFI", LV_BIG_ENDIAN, 4, 4, {1}, QCOWX_HDR_IMAGE_SIZE, 8, 1, + -1, 0, qcow1EncryptionInfo, qcowXGetBackingStore, NULL }, @@ -310,6 +315,7 @@ static struct FileTypeInfo const fileTypeInfo[] =3D { 0, "QFI", LV_BIG_ENDIAN, 4, 4, {2, 3}, QCOWX_HDR_IMAGE_SIZE, 8, 1, + QCOWX_HDR_CLUSTER_BITS_OFFSET, 4, qcow2EncryptionInfo, qcowXGetBackingStore, qcow2GetFeatures @@ -318,12 +324,12 @@ static struct FileTypeInfo const fileTypeInfo[] =3D { /* https://wiki.qemu.org/Features/QED */ 0, "QED", LV_LITTLE_ENDIAN, -2, 0, {0}, - QED_HDR_IMAGE_SIZE, 8, 1, NULL, qedGetBackingStore, NULL + QED_HDR_IMAGE_SIZE, 8, 1, -1, 0, NULL, qedGetBackingStore, NULL }, [VIR_STORAGE_FILE_VMDK] =3D { 0, "KDMV", LV_LITTLE_ENDIAN, 4, 4, {1, 2, 3}, - 4+4+4, 8, 512, NULL, vmdk4GetBackingStore, NULL + 4+4+4, 8, 512, -1, 0, NULL, vmdk4GetBackingStore, NULL }, }; G_STATIC_ASSERT(G_N_ELEMENTS(fileTypeInfo) =3D=3D VIR_STORAGE_FILE_LAST); @@ -890,6 +896,23 @@ virStorageFileProbeGetMetadata(virStorageSource *meta, meta->capacity *=3D fileTypeInfo[meta->format].sizeMultiplier; } =20 + if (fileTypeInfo[meta->format].clusterBitsOffset !=3D -1) { + int clusterBits =3D 0; + + if ((fileTypeInfo[meta->format].clusterBitsOffset + 4) > len) + return 0; + + if (fileTypeInfo[meta->format].endian =3D=3D LV_LITTLE_ENDIAN) + clusterBits =3D virReadBufInt32LE(buf + + fileTypeInfo[meta->format].clu= sterBitsOffset); + else + clusterBits =3D virReadBufInt32BE(buf + + fileTypeInfo[meta->format].clu= sterBitsOffset); + + if (clusterBits > 0) + meta->clusterSize =3D 1 << clusterBits; + } + VIR_FREE(meta->backingStoreRaw); if (fileTypeInfo[meta->format].getBackingStore !=3D NULL) { int store =3D fileTypeInfo[meta->format].getBackingStore(&meta->ba= ckingStoreRaw, --=20 2.31.1