From nobody Sun May 5 10:35:17 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 15005607473971000.8476419153394; Thu, 20 Jul 2017 07:25:47 -0700 (PDT) Received: from localhost ([::1]:38296 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dYCOg-0003pK-38 for importer@patchew.org; Thu, 20 Jul 2017 10:25:46 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41050) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dYCK0-0008BY-Kn for qemu-devel@nongnu.org; Thu, 20 Jul 2017 10:20:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dYCJw-0007t8-8v for qemu-devel@nongnu.org; Thu, 20 Jul 2017 10:20:56 -0400 Received: from mx-v6.kamp.de ([2a02:248:0:51::16]:34363 helo=mx01.kamp.de) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dYCJv-0007rs-Vo for qemu-devel@nongnu.org; Thu, 20 Jul 2017 10:20:52 -0400 Received: (qmail 14719 invoked by uid 89); 20 Jul 2017 14:20:47 -0000 Received: from [195.62.97.28] by client-16-kamp (envelope-from , uid 89) with qmail-scanner-2010/03/19-MF (clamdscan: 0.99.2/23580. avast: 1.2.2/17010300. spamassassin: 3.4.1. Clear:RC:1(195.62.97.28):. Processed in 0.225296 secs); 20 Jul 2017 14:20:47 -0000 Received: from smtp.kamp.de (HELO submission.kamp.de) ([195.62.97.28]) by mx01.kamp.de with ESMTPS (DHE-RSA-AES256-GCM-SHA384 encrypted); 20 Jul 2017 14:20:44 -0000 Received: (qmail 5125 invoked from network); 20 Jul 2017 14:20:43 -0000 Received: from lieven-pc.kamp-intra.net (HELO lieven-pc) (relay@kamp.de@::ffff:172.21.12.60) by submission.kamp.de with ESMTPS (DHE-RSA-AES256-GCM-SHA384 encrypted) ESMTPA; 20 Jul 2017 14:20:43 -0000 Received: by lieven-pc (Postfix, from userid 1000) id 1A364202CD; Thu, 20 Jul 2017 16:20:43 +0200 (CEST) X-GL_Whitelist: yes From: Peter Lieven To: qemu-block@nongnu.org Date: Thu, 20 Jul 2017 16:20:32 +0200 Message-Id: <1500560441-5670-2-git-send-email-pl@kamp.de> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1500560441-5670-1-git-send-email-pl@kamp.de> References: <1500560441-5670-1-git-send-email-pl@kamp.de> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a02:248:0:51::16 Subject: [Qemu-devel] [PATCH V4 01/10] specs/qcow2: add compress format extension X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, Peter Lieven , qemu-devel@nongnu.org, mreitz@redhat.com, den@openvz.org, lersek@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Peter Lieven --- docs/interop/qcow2.txt | 43 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/docs/interop/qcow2.txt b/docs/interop/qcow2.txt index d7fdb1f..ef5abb2 100644 --- a/docs/interop/qcow2.txt +++ b/docs/interop/qcow2.txt @@ -86,7 +86,12 @@ in the description of a field. be written to (unless for regaining consistency). =20 - Bits 2-63: Reserved (set to 0) + Bit 2: Compress format bit. If and only if this = bit + is set then the compress format extension + MUST be present and MUST be parsed and che= cked + for compatibility. + + Bits 3-63: Reserved (set to 0) =20 80 - 87: compatible_features Bitmask of compatible features. An implementation can @@ -137,6 +142,7 @@ be stored. Each extension has a structure like the foll= owing: 0x6803f857 - Feature name table 0x23852875 - Bitmaps extension 0x0537be77 - Full disk encryption header pointer + 0xC03183A3 - Compress format extension other - Unknown header extension, can be safe= ly ignored =20 @@ -311,6 +317,41 @@ The algorithms used for encryption vary depending on t= he method in the LUKS header, with the physical disk sector as the input tweak. =20 + +=3D=3D Compress format extension =3D=3D + +The compress format extension is an optional header extension. It provides +the ability to specify the compress algorithm and compress parameters +that are used for compressed clusters. This new header MUST be present if +the incompatible-feature bit "compress format bit" is set and MUST be abse= nt +otherwise. + +Note: Ommitting the incompatible "Compress format bit" results in the usage +of zlib compression with default compression level (default before QEMU 2.= 10). +However, this old default has a smaller compression window size which resu= lts in +lower compression ratio and slightly worse compression speed compared to +explicity specifying zlib compression with default compression level in the +compress format extension. + +The fields of the compress format extension are: + + Byte 0 - 14: compress_format_name (padded with zeros, but not + necessarily null terminated if it has full length). + Valid compression format names currently are: + + zlib: Standard zlib deflate compression + + 15: compress_level (uint8_t) + + 0 =3D default compress level (valid for all formats, de= fault) + + Additional valid compression levels for zlib compressio= n: + + All values between 1 and 9. 1 gives best speed, 9 gives= best + compression. The default compression level is defined b= y zlib + and currently defaults to 6. + + =3D=3D Host cluster management =3D=3D =20 qcow2 manages the allocation of host clusters by maintaining a reference c= ount --=20 1.9.1 From nobody Sun May 5 10:35:17 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1500560589423194.74007069614743; Thu, 20 Jul 2017 07:23:09 -0700 (PDT) Received: from localhost ([::1]:38282 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dYCM4-000115-Mw for importer@patchew.org; Thu, 20 Jul 2017 10:23:04 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41054) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dYCK0-0008Bc-LI for qemu-devel@nongnu.org; Thu, 20 Jul 2017 10:20:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dYCJx-0007tt-Mf for qemu-devel@nongnu.org; Thu, 20 Jul 2017 10:20:56 -0400 Received: from mx-v6.kamp.de ([2a02:248:0:51::16]:34530 helo=mx01.kamp.de) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dYCJx-0007sz-DJ for qemu-devel@nongnu.org; Thu, 20 Jul 2017 10:20:53 -0400 Received: (qmail 14916 invoked by uid 89); 20 Jul 2017 14:20:51 -0000 Received: from [195.62.97.28] by client-16-kamp (envelope-from , uid 89) with qmail-scanner-2010/03/19-MF (clamdscan: 0.99.2/23580. avast: 1.2.2/17010300. spamassassin: 3.4.1. Clear:RC:1(195.62.97.28):. Processed in 0.233284 secs); 20 Jul 2017 14:20:51 -0000 Received: from smtp.kamp.de (HELO submission.kamp.de) ([195.62.97.28]) by mx01.kamp.de with ESMTPS (DHE-RSA-AES256-GCM-SHA384 encrypted); 20 Jul 2017 14:20:48 -0000 Received: (qmail 5131 invoked from network); 20 Jul 2017 14:20:43 -0000 Received: from lieven-pc.kamp-intra.net (HELO lieven-pc) (relay@kamp.de@::ffff:172.21.12.60) by submission.kamp.de with ESMTPS (DHE-RSA-AES256-GCM-SHA384 encrypted) ESMTPA; 20 Jul 2017 14:20:43 -0000 Received: by lieven-pc (Postfix, from userid 1000) id 1DDE726C35; Thu, 20 Jul 2017 16:20:43 +0200 (CEST) X-GL_Whitelist: yes From: Peter Lieven To: qemu-block@nongnu.org Date: Thu, 20 Jul 2017 16:20:33 +0200 Message-Id: <1500560441-5670-3-git-send-email-pl@kamp.de> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1500560441-5670-1-git-send-email-pl@kamp.de> References: <1500560441-5670-1-git-send-email-pl@kamp.de> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a02:248:0:51::16 Subject: [Qemu-devel] [PATCH V4 02/10] qapi/block-core: add Qcow2Compress parameters X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, Peter Lieven , qemu-devel@nongnu.org, mreitz@redhat.com, den@openvz.org, lersek@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Peter Lieven --- qapi/block-core.json | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/qapi/block-core.json b/qapi/block-core.json index ff8e2ba..95e5393 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -2454,6 +2454,44 @@ '*encrypt': 'BlockdevQcow2Encryption' } } =20 ## +# @Qcow2CompressFormat: +# @zlib: standard zlib deflate compression +# +# Since: 2.10 +## +{ 'enum': 'Qcow2CompressFormat', + 'data': [ 'zlib' ] } + +## +# @Qcow2CompressZLib: +# +# Since: 2.10 +## +{ 'struct': 'Qcow2CompressZLib', + 'data': { } } + +## +# @Qcow2Compress: +# +# Specifies the compression format and compression level that should +# be used for compressed Qcow2 clusters. +# +# @format: specifies the compression format to use. (defaults to zlib) +# +# @level: specifies the compression level. 0 =3D default compression, +# 1 =3D fastest compression, x =3D highest compresion (x may very = between +# different compression formats) +# +# Since: 2.10 +## +{ 'union': 'Qcow2Compress', + 'base': { 'format': 'Qcow2CompressFormat', + '*level': 'uint8' }, + 'discriminator': 'format', + 'data': { 'zlib': 'Qcow2CompressZLib' } } + + +## # @BlockdevOptionsSsh: # # @server: host address --=20 1.9.1 From nobody Sun May 5 10:35:17 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1500561029405692.2734657179885; Thu, 20 Jul 2017 07:30:29 -0700 (PDT) Received: from localhost ([::1]:38327 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dYCTD-0008Mx-66 for importer@patchew.org; Thu, 20 Jul 2017 10:30:27 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41213) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dYCKC-0008NG-1w for qemu-devel@nongnu.org; Thu, 20 Jul 2017 10:21:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dYCKA-0007zu-TY for qemu-devel@nongnu.org; Thu, 20 Jul 2017 10:21:08 -0400 Received: from mx-v6.kamp.de ([2a02:248:0:51::16]:38380 helo=mx01.kamp.de) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dYCKA-0007zG-Kj for qemu-devel@nongnu.org; Thu, 20 Jul 2017 10:21:06 -0400 Received: (qmail 15550 invoked by uid 89); 20 Jul 2017 14:21:05 -0000 Received: from [195.62.97.28] by client-16-kamp (envelope-from , uid 89) with qmail-scanner-2010/03/19-MF (clamdscan: 0.99.2/23580. avast: 1.2.2/17010300. spamassassin: 3.4.1. Clear:RC:1(195.62.97.28):. Processed in 0.286202 secs); 20 Jul 2017 14:21:05 -0000 Received: from smtp.kamp.de (HELO submission.kamp.de) ([195.62.97.28]) by mx01.kamp.de with ESMTPS (DHE-RSA-AES256-GCM-SHA384 encrypted); 20 Jul 2017 14:21:02 -0000 Received: (qmail 5140 invoked from network); 20 Jul 2017 14:20:43 -0000 Received: from lieven-pc.kamp-intra.net (HELO lieven-pc) (relay@kamp.de@::ffff:172.21.12.60) by submission.kamp.de with ESMTPS (DHE-RSA-AES256-GCM-SHA384 encrypted) ESMTPA; 20 Jul 2017 14:20:43 -0000 Received: by lieven-pc (Postfix, from userid 1000) id 1F3CA21E0B; Thu, 20 Jul 2017 16:20:43 +0200 (CEST) X-GL_Whitelist: yes From: Peter Lieven To: qemu-block@nongnu.org Date: Thu, 20 Jul 2017 16:20:34 +0200 Message-Id: <1500560441-5670-4-git-send-email-pl@kamp.de> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1500560441-5670-1-git-send-email-pl@kamp.de> References: <1500560441-5670-1-git-send-email-pl@kamp.de> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a02:248:0:51::16 Subject: [Qemu-devel] [PATCH V4 03/10] block/qcow2: parse compress create options X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, Peter Lieven , qemu-devel@nongnu.org, mreitz@redhat.com, den@openvz.org, lersek@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" this adds parsing and validation for the compress create options. They are only validated but not yet used. Signed-off-by: Peter Lieven --- block/qcow2.c | 53 +++++++++++++++++++++++++++++++++++++++++++= ++-- include/block/block_int.h | 2 ++ 2 files changed, 53 insertions(+), 2 deletions(-) diff --git a/block/qcow2.c b/block/qcow2.c index d5790af..073d50f 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -31,6 +31,8 @@ #include "qapi/qmp/qerror.h" #include "qapi/qmp/qbool.h" #include "qapi/util.h" +#include "qapi-visit.h" +#include "qapi/qobject-input-visitor.h" #include "qapi/qmp/types.h" #include "qapi-event.h" #include "trace.h" @@ -2706,7 +2708,8 @@ static int qcow2_create2(const char *filename, int64_= t total_size, const char *backing_file, const char *backing_for= mat, int flags, size_t cluster_size, PreallocMode prea= lloc, QemuOpts *opts, int version, int refcount_order, - const char *encryptfmt, Error **errp) + const char *encryptfmt, Qcow2Compress *compress, + Error **errp) { QDict *options; =20 @@ -2898,6 +2901,7 @@ static int qcow2_create(const char *filename, QemuOpt= s *opts, Error **errp) char *backing_file =3D NULL; char *backing_fmt =3D NULL; char *buf =3D NULL; + Qcow2Compress compress, *compress_ptr =3D NULL; uint64_t size =3D 0; int flags =3D 0; size_t cluster_size =3D DEFAULT_CLUSTER_SIZE; @@ -2975,9 +2979,43 @@ static int qcow2_create(const char *filename, QemuOp= ts *opts, Error **errp) =20 refcount_order =3D ctz32(refcount_bits); =20 + if (qemu_opt_get(opts, BLOCK_OPT_COMPRESS_FORMAT) || + qemu_opt_get(opts, BLOCK_OPT_COMPRESS_LEVEL)) { + QDict *options, *compressopts =3D NULL; + Visitor *v; + options =3D qemu_opts_to_qdict(opts, NULL); + qdict_extract_subqdict(options, &compressopts, "compress."); + v =3D qobject_input_visitor_new_keyval(QOBJECT(compressopts)); + visit_start_struct(v, NULL, NULL, 0, &local_err); + if (local_err) { + error_propagate(errp, local_err); + ret =3D -EINVAL; + goto finish; + } + visit_type_Qcow2Compress_members(v, &compress, &local_err); + if (local_err) { + error_propagate(errp, local_err); + ret =3D -EINVAL; + goto finish; + } + visit_end_struct(v, NULL); + visit_free(v); + QDECREF(compressopts); + QDECREF(options); + if (compress.format =3D=3D QCOW2_COMPRESS_FORMAT_ZLIB && + compress.level > 9) { + error_setg(errp, "Compress level %" PRIu8 " is not supported f= or" + " format '%s'", compress.level, + Qcow2CompressFormat_lookup[compress.format]); + ret =3D -EINVAL; + goto finish; + } + compress_ptr =3D &compress; + } + ret =3D qcow2_create2(filename, size, backing_file, backing_fmt, flags, cluster_size, prealloc, opts, version, refcount_or= der, - encryptfmt, &local_err); + encryptfmt, compress_ptr, &local_err); error_propagate(errp, local_err); =20 finish: @@ -4287,6 +4325,17 @@ static QemuOptsList qcow2_create_opts =3D { .help =3D "Width of a reference count entry in bits", .def_value_str =3D "16" }, + { + .name =3D BLOCK_OPT_COMPRESS_FORMAT, + .type =3D QEMU_OPT_STRING, + .help =3D "Compress format used for compressed clusters (zlib)= ", + }, + { + .name =3D BLOCK_OPT_COMPRESS_LEVEL, + .type =3D QEMU_OPT_NUMBER, + .help =3D "Compress level used for compressed clusters (0 =3D = default," + " 1=3Dfastest, x=3Dbest; x varies depending on compres= s.format)", + }, { /* end of list */ } } }; diff --git a/include/block/block_int.h b/include/block/block_int.h index 5c6b761..8245963 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -57,6 +57,8 @@ #define BLOCK_OPT_NOCOW "nocow" #define BLOCK_OPT_OBJECT_SIZE "object_size" #define BLOCK_OPT_REFCOUNT_BITS "refcount_bits" +#define BLOCK_OPT_COMPRESS_FORMAT "compress.format" +#define BLOCK_OPT_COMPRESS_LEVEL "compress.level" =20 #define BLOCK_PROBE_BUF_SIZE 512 =20 --=20 1.9.1 From nobody Sun May 5 10:35:17 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1500560584272664.0270318651814; Thu, 20 Jul 2017 07:23:04 -0700 (PDT) Received: from localhost ([::1]:38281 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dYCLx-0000un-Kp for importer@patchew.org; Thu, 20 Jul 2017 10:22:57 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41051) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dYCK0-0008BZ-Kq for qemu-devel@nongnu.org; Thu, 20 Jul 2017 10:20:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dYCJx-0007u3-Qw for qemu-devel@nongnu.org; Thu, 20 Jul 2017 10:20:56 -0400 Received: from mx-v6.kamp.de ([2a02:248:0:51::16]:35333 helo=mx01.kamp.de) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dYCJx-0007t2-Hc for qemu-devel@nongnu.org; Thu, 20 Jul 2017 10:20:53 -0400 Received: (qmail 14925 invoked by uid 89); 20 Jul 2017 14:20:51 -0000 Received: from [195.62.97.28] by client-16-kamp (envelope-from , uid 89) with qmail-scanner-2010/03/19-MF (clamdscan: 0.99.2/23580. avast: 1.2.2/17010300. spamassassin: 3.4.1. Clear:RC:1(195.62.97.28):. Processed in 0.246545 secs); 20 Jul 2017 14:20:51 -0000 Received: from smtp.kamp.de (HELO submission.kamp.de) ([195.62.97.28]) by mx01.kamp.de with ESMTPS (DHE-RSA-AES256-GCM-SHA384 encrypted); 20 Jul 2017 14:20:48 -0000 Received: (qmail 5138 invoked from network); 20 Jul 2017 14:20:43 -0000 Received: from lieven-pc.kamp-intra.net (HELO lieven-pc) (relay@kamp.de@::ffff:172.21.12.60) by submission.kamp.de with ESMTPS (DHE-RSA-AES256-GCM-SHA384 encrypted) ESMTPA; 20 Jul 2017 14:20:43 -0000 Received: by lieven-pc (Postfix, from userid 1000) id 22B7B26C3A; Thu, 20 Jul 2017 16:20:43 +0200 (CEST) X-GL_Whitelist: yes From: Peter Lieven To: qemu-block@nongnu.org Date: Thu, 20 Jul 2017 16:20:35 +0200 Message-Id: <1500560441-5670-5-git-send-email-pl@kamp.de> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1500560441-5670-1-git-send-email-pl@kamp.de> References: <1500560441-5670-1-git-send-email-pl@kamp.de> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a02:248:0:51::16 Subject: [Qemu-devel] [PATCH V4 04/10] qemu-img: add documentation for compress settings X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, Peter Lieven , qemu-devel@nongnu.org, mreitz@redhat.com, den@openvz.org, lersek@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Peter Lieven --- qemu-img.texi | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/qemu-img.texi b/qemu-img.texi index 72dabd6..fcc4c1d 100644 --- a/qemu-img.texi +++ b/qemu-img.texi @@ -676,6 +676,26 @@ file which is COW and has data blocks already, it coul= dn't be changed to NOCOW by setting @code{nocow=3Don}. One can issue @code{lsattr filename} to chec= k if the NOCOW flag is set or not (Capital 'C' is NOCOW flag). =20 +@item compress.format +Defines which compression algorithm is should be used for compressed clust= ers. +The following options are available if support for the respective libraries +has been enabled at compile time: + + zlib Uses standard zlib compression + +The compression algorithm can only be defined at image create time and can= not +be changed later. + +Note: defining a compression format will result in the compression format + extension being written to the Qcow2 image. Versions of QEMU before = 2.10 + will not be able to open images with this extension. + +@item compress.level +Valid for compress.format=3Dzlib defines the compression level to use for +selected compression format. The default of @code{compress.level=3D0} will= use +the default compression level for the format. Alternate values range from = 1 for +fastest compression to 9 for the best compression. + @end table =20 @item Other --=20 1.9.1 From nobody Sun May 5 10:35:17 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1500560748745398.4139279173962; Thu, 20 Jul 2017 07:25:48 -0700 (PDT) Received: from localhost ([::1]:38297 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dYCOg-0003qo-F2 for importer@patchew.org; Thu, 20 Jul 2017 10:25:46 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41196) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dYCKB-0008Ms-OJ for qemu-devel@nongnu.org; Thu, 20 Jul 2017 10:21:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dYCK7-0007yh-4K for qemu-devel@nongnu.org; Thu, 20 Jul 2017 10:21:07 -0400 Received: from mx-v6.kamp.de ([2a02:248:0:51::16]:53092 helo=mx01.kamp.de) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dYCK6-0007xg-Ql for qemu-devel@nongnu.org; Thu, 20 Jul 2017 10:21:03 -0400 Received: (qmail 15365 invoked by uid 89); 20 Jul 2017 14:21:01 -0000 Received: from [195.62.97.28] by client-16-kamp (envelope-from , uid 89) with qmail-scanner-2010/03/19-MF (clamdscan: 0.99.2/23580. avast: 1.2.2/17010300. spamassassin: 3.4.1. Clear:RC:1(195.62.97.28):. Processed in 0.394537 secs); 20 Jul 2017 14:21:01 -0000 Received: from smtp.kamp.de (HELO submission.kamp.de) ([195.62.97.28]) by mx01.kamp.de with ESMTPS (DHE-RSA-AES256-GCM-SHA384 encrypted); 20 Jul 2017 14:20:57 -0000 Received: (qmail 5154 invoked from network); 20 Jul 2017 14:20:43 -0000 Received: from lieven-pc.kamp-intra.net (HELO lieven-pc) (relay@kamp.de@::ffff:172.21.12.60) by submission.kamp.de with ESMTPS (DHE-RSA-AES256-GCM-SHA384 encrypted) ESMTPA; 20 Jul 2017 14:20:43 -0000 Received: by lieven-pc (Postfix, from userid 1000) id 259A526C3D; Thu, 20 Jul 2017 16:20:43 +0200 (CEST) X-GL_Whitelist: yes From: Peter Lieven To: qemu-block@nongnu.org Date: Thu, 20 Jul 2017 16:20:36 +0200 Message-Id: <1500560441-5670-6-git-send-email-pl@kamp.de> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1500560441-5670-1-git-send-email-pl@kamp.de> References: <1500560441-5670-1-git-send-email-pl@kamp.de> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a02:248:0:51::16 Subject: [Qemu-devel] [PATCH V4 05/10] block/qcow2: read and write the compress format extension X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, Peter Lieven , qemu-devel@nongnu.org, mreitz@redhat.com, den@openvz.org, lersek@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" we now read the extension on open and write it on update, but do not yet use it. Signed-off-by: Peter Lieven --- block/qcow2.c | 94 +++++++++++++++++++++++++++++++++++++++++++++++++++++++= ---- block/qcow2.h | 21 +++++++++---- 2 files changed, 105 insertions(+), 10 deletions(-) diff --git a/block/qcow2.c b/block/qcow2.c index 073d50f..1dff87e 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -70,6 +70,7 @@ typedef struct { #define QCOW2_EXT_MAGIC_FEATURE_TABLE 0x6803f857 #define QCOW2_EXT_MAGIC_CRYPTO_HEADER 0x0537be77 #define QCOW2_EXT_MAGIC_BITMAPS 0x23852875 +#define QCOW2_EXT_MAGIC_COMPRESS_FORMAT 0xC03183A3 =20 static int qcow2_probe(const uint8_t *buf, int buf_size, const char *filen= ame) { @@ -164,6 +165,17 @@ static ssize_t qcow2_crypto_hdr_write_func(QCryptoBloc= k *block, size_t offset, } =20 =20 +static void qcow2_compress_level_supported(int format, uint8_t level, + Error **errp) +{ + if (format =3D=3D QCOW2_COMPRESS_FORMAT_ZLIB && level > 9) { + error_setg(errp, "ERROR: compress level %" PRIu8 " is not" + " supported for format '%s'", level, + Qcow2CompressFormat_lookup[format]); + } +} + + /*=20 * read qcow2 extension and fill bs * start reading from start_offset @@ -241,6 +253,48 @@ static int qcow2_read_extensions(BlockDriverState *bs,= uint64_t start_offset, #endif break; =20 + case QCOW2_EXT_MAGIC_COMPRESS_FORMAT: + { + Qcow2CompressFormatExt compress_ext; + Error *local_err =3D NULL; + if (ext.len !=3D sizeof(compress_ext)) { + error_setg(errp, "ERROR: ext_compress_format: len=3D%" + PRIu32 " invalid (!=3D%zu)", ext.len, + sizeof(compress_ext)); + return 2; + } + ret =3D bdrv_pread(bs->file, offset, &compress_ext, + ext.len); + if (ret < 0) { + error_setg_errno(errp, -ret, "ERROR: ext_compress_fromat:" + " Could not read extension"); + return 3; + } + + s->compress_format =3D + qapi_enum_parse(Qcow2CompressFormat_lookup, + compress_ext.name, QCOW2_COMPRESS_FORMAT__= MAX, + -1, &local_err); + if (local_err) { + error_propagate(errp, local_err); + return 4; + } + + qcow2_compress_level_supported(s->compress_format, + compress_ext.level, &local_err); + if (local_err) { + error_propagate(errp, local_err); + return 5; + } + s->compress_level =3D compress_ext.level; + +#ifdef DEBUG_EXT + printf("Qcow2: Got compress format %s with compress level %" + PRIu8 "\n", Qcow2CompressFormat_lookup[s->compress_form= at], + s->compress_level); +#endif + break; + } case QCOW2_EXT_MAGIC_FEATURE_TABLE: if (p_feature_table !=3D NULL) { void* feature_table =3D g_malloc0(ext.len + 2 * sizeof(Qco= w2Feature)); @@ -1374,6 +1428,7 @@ static int qcow2_do_open(BlockDriverState *bs, QDict = *options, int flags, =20 s->cluster_cache_offset =3D -1; s->flags =3D flags; + s->compress_format =3D -1; =20 ret =3D qcow2_refcount_init(bs); if (ret !=3D 0) { @@ -2292,6 +2347,25 @@ int qcow2_update_header(BlockDriverState *bs) buflen -=3D ret; } =20 + /* Compress Format header extension */ + if (s->compress_format >=3D 0) { + Qcow2CompressFormatExt ext; + assert(s->compress_format < QCOW2_COMPRESS_FORMAT__MAX); + strncpy((char *) &ext.name, + Qcow2CompressFormat_lookup[s->compress_format], + sizeof(ext.name)); + ext.level =3D s->compress_level; + ret =3D header_ext_add(buf, QCOW2_EXT_MAGIC_COMPRESS_FORMAT, + &ext, sizeof(ext), + buflen); + if (ret < 0) { + goto fail; + } + buf +=3D ret; + buflen -=3D ret; + header->incompatible_features |=3D cpu_to_be64(QCOW2_INCOMPAT_COMP= RESS); + } + /* Feature table */ if (s->qcow_version >=3D 3) { Qcow2Feature features[] =3D { @@ -2306,6 +2380,11 @@ int qcow2_update_header(BlockDriverState *bs) .name =3D "corrupt bit", }, { + .type =3D QCOW2_FEAT_TYPE_INCOMPATIBLE, + .bit =3D QCOW2_INCOMPAT_COMPRESS_BITNR, + .name =3D "compress format bit", + }, + { .type =3D QCOW2_FEAT_TYPE_COMPATIBLE, .bit =3D QCOW2_COMPAT_LAZY_REFCOUNTS_BITNR, .name =3D "lazy refcounts", @@ -2827,6 +2906,12 @@ static int qcow2_create2(const char *filename, int64= _t total_size, abort(); } =20 + if (compress) { + BDRVQcow2State *s =3D blk_bs(blk)->opaque; + s->compress_format =3D compress->format; + s->compress_level =3D compress->level; + } + /* Create a full header (including things like feature table) */ ret =3D qcow2_update_header(blk_bs(blk)); if (ret < 0) { @@ -3002,11 +3087,10 @@ static int qcow2_create(const char *filename, QemuO= pts *opts, Error **errp) visit_free(v); QDECREF(compressopts); QDECREF(options); - if (compress.format =3D=3D QCOW2_COMPRESS_FORMAT_ZLIB && - compress.level > 9) { - error_setg(errp, "Compress level %" PRIu8 " is not supported f= or" - " format '%s'", compress.level, - Qcow2CompressFormat_lookup[compress.format]); + qcow2_compress_level_supported(compress.format, compress.level, + &local_err); + if (local_err) { + error_propagate(errp, local_err); ret =3D -EINVAL; goto finish; } diff --git a/block/qcow2.h b/block/qcow2.h index 96a8d43..9a564d4 100644 --- a/block/qcow2.h +++ b/block/qcow2.h @@ -188,13 +188,16 @@ enum { =20 /* Incompatible feature bits */ enum { - QCOW2_INCOMPAT_DIRTY_BITNR =3D 0, - QCOW2_INCOMPAT_CORRUPT_BITNR =3D 1, - QCOW2_INCOMPAT_DIRTY =3D 1 << QCOW2_INCOMPAT_DIRTY_BITNR, - QCOW2_INCOMPAT_CORRUPT =3D 1 << QCOW2_INCOMPAT_CORRUPT_BITNR, + QCOW2_INCOMPAT_DIRTY_BITNR =3D 0, + QCOW2_INCOMPAT_CORRUPT_BITNR =3D 1, + QCOW2_INCOMPAT_COMPRESS_BITNR =3D 2, + QCOW2_INCOMPAT_DIRTY =3D 1 << QCOW2_INCOMPAT_DIRTY_BITNR, + QCOW2_INCOMPAT_CORRUPT =3D 1 << QCOW2_INCOMPAT_CORRUPT_BITNR, + QCOW2_INCOMPAT_COMPRESS =3D 1 << QCOW2_INCOMPAT_COMPRESS_BITNR, =20 QCOW2_INCOMPAT_MASK =3D QCOW2_INCOMPAT_DIRTY - | QCOW2_INCOMPAT_CORRUPT, + | QCOW2_INCOMPAT_CORRUPT + | QCOW2_INCOMPAT_COMPRESS, }; =20 /* Compatible feature bits */ @@ -228,6 +231,11 @@ typedef struct Qcow2Feature { char name[46]; } QEMU_PACKED Qcow2Feature; =20 +typedef struct Qcow2CompressFormatExt { + char name[15]; + uint8_t level; +} QEMU_PACKED Qcow2CompressFormatExt; + typedef struct Qcow2DiscardRegion { BlockDriverState *bs; uint64_t offset; @@ -304,6 +312,9 @@ typedef struct BDRVQcow2State { int refcount_bits; uint64_t refcount_max; =20 + int compress_format; + uint8_t compress_level; + Qcow2GetRefcountFunc *get_refcount; Qcow2SetRefcountFunc *set_refcount; =20 --=20 1.9.1 From nobody Sun May 5 10:35:17 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1500560760049289.44541041081266; Thu, 20 Jul 2017 07:26:00 -0700 (PDT) Received: from localhost ([::1]:38298 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dYCOn-0003wx-Mq for importer@patchew.org; Thu, 20 Jul 2017 10:25:53 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41206) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dYCKB-0008N3-RV for qemu-devel@nongnu.org; Thu, 20 Jul 2017 10:21:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dYCKA-0007zi-Ob for qemu-devel@nongnu.org; Thu, 20 Jul 2017 10:21:07 -0400 Received: from mx-v6.kamp.de ([2a02:248:0:51::16]:51329 helo=mx01.kamp.de) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dYCKA-0007zC-FH for qemu-devel@nongnu.org; Thu, 20 Jul 2017 10:21:06 -0400 Received: (qmail 15511 invoked by uid 89); 20 Jul 2017 14:21:05 -0000 Received: from [195.62.97.28] by client-16-kamp (envelope-from , uid 89) with qmail-scanner-2010/03/19-MF (clamdscan: 0.99.2/23580. avast: 1.2.2/17010300. spamassassin: 3.4.1. Clear:RC:1(195.62.97.28):. Processed in 0.194875 secs); 20 Jul 2017 14:21:05 -0000 Received: from smtp.kamp.de (HELO submission.kamp.de) ([195.62.97.28]) by mx01.kamp.de with ESMTPS (DHE-RSA-AES256-GCM-SHA384 encrypted); 20 Jul 2017 14:21:02 -0000 Received: (qmail 5152 invoked from network); 20 Jul 2017 14:20:43 -0000 Received: from lieven-pc.kamp-intra.net (HELO lieven-pc) (relay@kamp.de@::ffff:172.21.12.60) by submission.kamp.de with ESMTPS (DHE-RSA-AES256-GCM-SHA384 encrypted) ESMTPA; 20 Jul 2017 14:20:43 -0000 Received: by lieven-pc (Postfix, from userid 1000) id 27A2C26C3F; Thu, 20 Jul 2017 16:20:43 +0200 (CEST) X-GL_Whitelist: yes From: Peter Lieven To: qemu-block@nongnu.org Date: Thu, 20 Jul 2017 16:20:37 +0200 Message-Id: <1500560441-5670-7-git-send-email-pl@kamp.de> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1500560441-5670-1-git-send-email-pl@kamp.de> References: <1500560441-5670-1-git-send-email-pl@kamp.de> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a02:248:0:51::16 Subject: [Qemu-devel] [PATCH V4 06/10] block/qcow2: simplify ret usage in qcow2_create X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, Peter Lieven , qemu-devel@nongnu.org, mreitz@redhat.com, den@openvz.org, lersek@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Peter Lieven --- block/qcow2.c | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/block/qcow2.c b/block/qcow2.c index 1dff87e..67e48e1 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -2996,7 +2996,7 @@ static int qcow2_create(const char *filename, QemuOpt= s *opts, Error **errp) int refcount_order; const char *encryptfmt =3D NULL; Error *local_err =3D NULL; - int ret; + int ret =3D -EINVAL; =20 /* Read out options */ size =3D ROUND_UP(qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0), @@ -3008,7 +3008,6 @@ static int qcow2_create(const char *filename, QemuOpt= s *opts, Error **errp) if (qemu_opt_get_del(opts, BLOCK_OPT_ENCRYPT)) { error_setg(errp, "Options " BLOCK_OPT_ENCRYPT " and " BLOCK_OPT_ENCRYPT_FORMAT " are mutually exclusive"); - ret =3D -EINVAL; goto finish; } } else if (qemu_opt_get_bool_del(opts, BLOCK_OPT_ENCRYPT, false)) { @@ -3017,7 +3016,6 @@ static int qcow2_create(const char *filename, QemuOpt= s *opts, Error **errp) cluster_size =3D qcow2_opt_get_cluster_size_del(opts, &local_err); if (local_err) { error_propagate(errp, local_err); - ret =3D -EINVAL; goto finish; } buf =3D qemu_opt_get_del(opts, BLOCK_OPT_PREALLOC); @@ -3026,14 +3024,12 @@ static int qcow2_create(const char *filename, QemuO= pts *opts, Error **errp) &local_err); if (local_err) { error_propagate(errp, local_err); - ret =3D -EINVAL; goto finish; } =20 version =3D qcow2_opt_get_version_del(opts, &local_err); if (local_err) { error_propagate(errp, local_err); - ret =3D -EINVAL; goto finish; } =20 @@ -3044,21 +3040,18 @@ static int qcow2_create(const char *filename, QemuO= pts *opts, Error **errp) if (backing_file && prealloc !=3D PREALLOC_MODE_OFF) { error_setg(errp, "Backing file and preallocation cannot be used at= " "the same time"); - ret =3D -EINVAL; goto finish; } =20 if (version < 3 && (flags & BLOCK_FLAG_LAZY_REFCOUNTS)) { error_setg(errp, "Lazy refcounts only supported with compatibility= " "level 1.1 and above (use compat=3D1.1 or greater)"); - ret =3D -EINVAL; goto finish; } =20 refcount_bits =3D qcow2_opt_get_refcount_bits_del(opts, version, &loca= l_err); if (local_err) { error_propagate(errp, local_err); - ret =3D -EINVAL; goto finish; } =20 @@ -3074,13 +3067,11 @@ static int qcow2_create(const char *filename, QemuO= pts *opts, Error **errp) visit_start_struct(v, NULL, NULL, 0, &local_err); if (local_err) { error_propagate(errp, local_err); - ret =3D -EINVAL; goto finish; } visit_type_Qcow2Compress_members(v, &compress, &local_err); if (local_err) { error_propagate(errp, local_err); - ret =3D -EINVAL; goto finish; } visit_end_struct(v, NULL); @@ -3091,12 +3082,12 @@ static int qcow2_create(const char *filename, QemuO= pts *opts, Error **errp) &local_err); if (local_err) { error_propagate(errp, local_err); - ret =3D -EINVAL; goto finish; } compress_ptr =3D &compress; } =20 + /* ret is still -EINVAL until here */ ret =3D qcow2_create2(filename, size, backing_file, backing_fmt, flags, cluster_size, prealloc, opts, version, refcount_or= der, encryptfmt, compress_ptr, &local_err); --=20 1.9.1 From nobody Sun May 5 10:35:17 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1500560593975223.0174063686602; Thu, 20 Jul 2017 07:23:13 -0700 (PDT) Received: from localhost ([::1]:38284 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dYCMA-00017P-OI for importer@patchew.org; Thu, 20 Jul 2017 10:23:10 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41138) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dYCK3-0008Db-KF for qemu-devel@nongnu.org; Thu, 20 Jul 2017 10:21:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dYCK2-0007wc-Kx for qemu-devel@nongnu.org; Thu, 20 Jul 2017 10:20:59 -0400 Received: from mx-v6.kamp.de ([2a02:248:0:51::16]:60098 helo=mx01.kamp.de) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dYCK2-0007vi-BR for qemu-devel@nongnu.org; Thu, 20 Jul 2017 10:20:58 -0400 Received: (qmail 15157 invoked by uid 89); 20 Jul 2017 14:20:56 -0000 Received: from [195.62.97.28] by client-16-kamp (envelope-from , uid 89) with qmail-scanner-2010/03/19-MF (clamdscan: 0.99.2/23580. avast: 1.2.2/17010300. spamassassin: 3.4.1. Clear:RC:1(195.62.97.28):. Processed in 0.284044 secs); 20 Jul 2017 14:20:56 -0000 Received: from smtp.kamp.de (HELO submission.kamp.de) ([195.62.97.28]) by mx01.kamp.de with ESMTPS (DHE-RSA-AES256-GCM-SHA384 encrypted); 20 Jul 2017 14:20:53 -0000 Received: (qmail 5158 invoked from network); 20 Jul 2017 14:20:43 -0000 Received: from lieven-pc.kamp-intra.net (HELO lieven-pc) (relay@kamp.de@::ffff:172.21.12.60) by submission.kamp.de with ESMTPS (DHE-RSA-AES256-GCM-SHA384 encrypted) ESMTPA; 20 Jul 2017 14:20:43 -0000 Received: by lieven-pc (Postfix, from userid 1000) id 29ED726C38; Thu, 20 Jul 2017 16:20:43 +0200 (CEST) X-GL_Whitelist: yes From: Peter Lieven To: qemu-block@nongnu.org Date: Thu, 20 Jul 2017 16:20:38 +0200 Message-Id: <1500560441-5670-8-git-send-email-pl@kamp.de> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1500560441-5670-1-git-send-email-pl@kamp.de> References: <1500560441-5670-1-git-send-email-pl@kamp.de> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a02:248:0:51::16 Subject: [Qemu-devel] [PATCH V4 07/10] block/qcow2: optimize qcow2_co_pwritev_compressed X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, Peter Lieven , qemu-devel@nongnu.org, mreitz@redhat.com, den@openvz.org, lersek@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" if we specify exactly one iov of s->cluster_size bytes we can avoid the bounce buffer. Signed-off-by: Peter Lieven --- block/qcow2.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/block/qcow2.c b/block/qcow2.c index 67e48e1..978e8d2 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -3393,7 +3393,7 @@ qcow2_co_pwritev_compressed(BlockDriverState *bs, uin= t64_t offset, struct iovec iov; z_stream strm; int ret, out_len; - uint8_t *buf, *out_buf; + uint8_t *buf, *out_buf, *local_buf =3D NULL; uint64_t cluster_offset; =20 if (bytes =3D=3D 0) { @@ -3403,8 +3403,8 @@ qcow2_co_pwritev_compressed(BlockDriverState *bs, uin= t64_t offset, return bdrv_truncate(bs->file, cluster_offset, PREALLOC_MODE_OFF, = NULL); } =20 - buf =3D qemu_blockalign(bs, s->cluster_size); - if (bytes !=3D s->cluster_size) { + if (bytes !=3D s->cluster_size || qiov->niov !=3D 1) { + buf =3D local_buf =3D qemu_blockalign(bs, s->cluster_size); if (bytes > s->cluster_size || offset + bytes !=3D bs->total_sectors << BDRV_SECTOR_BITS) { @@ -3413,8 +3413,10 @@ qcow2_co_pwritev_compressed(BlockDriverState *bs, ui= nt64_t offset, } /* Zero-pad last write if image size is not cluster aligned */ memset(buf + bytes, 0, s->cluster_size - bytes); + qemu_iovec_to_buf(qiov, 0, buf, bytes); + } else { + buf =3D qiov->iov[0].iov_base; } - qemu_iovec_to_buf(qiov, 0, buf, bytes); =20 out_buf =3D g_malloc(s->cluster_size); =20 @@ -3482,7 +3484,7 @@ qcow2_co_pwritev_compressed(BlockDriverState *bs, uin= t64_t offset, success: ret =3D 0; fail: - qemu_vfree(buf); + qemu_vfree(local_buf); g_free(out_buf); return ret; } --=20 1.9.1 From nobody Sun May 5 10:35:17 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1500560590397139.33059820742994; Thu, 20 Jul 2017 07:23:10 -0700 (PDT) Received: from localhost ([::1]:38283 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dYCM4-000117-Ss for importer@patchew.org; Thu, 20 Jul 2017 10:23:04 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41049) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dYCK0-0008BX-Kl for qemu-devel@nongnu.org; Thu, 20 Jul 2017 10:20:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dYCJy-0007uT-UP for qemu-devel@nongnu.org; Thu, 20 Jul 2017 10:20:56 -0400 Received: from mx-v6.kamp.de ([2a02:248:0:51::16]:41686 helo=mx01.kamp.de) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dYCJy-0007tj-Ka for qemu-devel@nongnu.org; Thu, 20 Jul 2017 10:20:54 -0400 Received: (qmail 14951 invoked by uid 89); 20 Jul 2017 14:20:51 -0000 Received: from [195.62.97.28] by client-16-kamp (envelope-from , uid 89) with qmail-scanner-2010/03/19-MF (clamdscan: 0.99.2/23580. avast: 1.2.2/17010300. spamassassin: 3.4.1. Clear:RC:1(195.62.97.28):. Processed in 0.296065 secs); 20 Jul 2017 14:20:51 -0000 Received: from smtp.kamp.de (HELO submission.kamp.de) ([195.62.97.28]) by mx01.kamp.de with ESMTPS (DHE-RSA-AES256-GCM-SHA384 encrypted); 20 Jul 2017 14:20:48 -0000 Received: (qmail 5162 invoked from network); 20 Jul 2017 14:20:43 -0000 Received: from lieven-pc.kamp-intra.net (HELO lieven-pc) (relay@kamp.de@::ffff:172.21.12.60) by submission.kamp.de with ESMTPS (DHE-RSA-AES256-GCM-SHA384 encrypted) ESMTPA; 20 Jul 2017 14:20:43 -0000 Received: by lieven-pc (Postfix, from userid 1000) id 2D1B026C5D; Thu, 20 Jul 2017 16:20:43 +0200 (CEST) X-GL_Whitelist: yes From: Peter Lieven To: qemu-block@nongnu.org Date: Thu, 20 Jul 2017 16:20:39 +0200 Message-Id: <1500560441-5670-9-git-send-email-pl@kamp.de> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1500560441-5670-1-git-send-email-pl@kamp.de> References: <1500560441-5670-1-git-send-email-pl@kamp.de> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a02:248:0:51::16 Subject: [Qemu-devel] [PATCH V4 08/10] block/qcow2: start using the compress format extension X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, Peter Lieven , qemu-devel@nongnu.org, mreitz@redhat.com, den@openvz.org, lersek@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" we now pass the parameters to the zlib compressor if the extension is present and use the old default values if the extension is absent. Signed-off-by: Peter Lieven --- block/qcow2-cluster.c | 58 ++++++++++++++++++++++++++++++-----------------= ---- block/qcow2.c | 57 +++++++++++++++++++++++++++--------------------= --- 2 files changed, 65 insertions(+), 50 deletions(-) diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c index f06c08f..6c14d59 100644 --- a/block/qcow2-cluster.c +++ b/block/qcow2-cluster.c @@ -1479,30 +1479,39 @@ again: } =20 static int decompress_buffer(uint8_t *out_buf, int out_buf_size, - const uint8_t *buf, int buf_size) + const uint8_t *buf, int buf_size, + int compress_format) { - z_stream strm1, *strm =3D &strm1; - int ret, out_len; - - memset(strm, 0, sizeof(*strm)); - - strm->next_in =3D (uint8_t *)buf; - strm->avail_in =3D buf_size; - strm->next_out =3D out_buf; - strm->avail_out =3D out_buf_size; - - ret =3D inflateInit2(strm, -12); - if (ret !=3D Z_OK) - return -1; - ret =3D inflate(strm, Z_FINISH); - out_len =3D strm->next_out - out_buf; - if ((ret !=3D Z_STREAM_END && ret !=3D Z_BUF_ERROR) || - out_len !=3D out_buf_size) { - inflateEnd(strm); - return -1; - } - inflateEnd(strm); - return 0; + int ret =3D 0, out_len; + + switch (compress_format) { + case QCOW2_COMPRESS_FORMAT_ZLIB: + case -1: { + z_stream z_strm =3D {}; + + z_strm.next_in =3D (uint8_t *)buf; + z_strm.avail_in =3D buf_size; + z_strm.next_out =3D out_buf; + z_strm.avail_out =3D out_buf_size; + + ret =3D inflateInit2(&z_strm, -15); + if (ret !=3D Z_OK) { + return -1; + } + ret =3D inflate(&z_strm, Z_FINISH); + out_len =3D z_strm.next_out - out_buf; + ret =3D -(ret !=3D Z_STREAM_END); + inflateEnd(&z_strm); + break; + } + default: + abort(); /* should never reach this point */ + } + + if (out_len !=3D out_buf_size) { + ret =3D -1; + } + return ret; } =20 int qcow2_decompress_cluster(BlockDriverState *bs, uint64_t cluster_offset) @@ -1523,7 +1532,8 @@ int qcow2_decompress_cluster(BlockDriverState *bs, ui= nt64_t cluster_offset) return ret; } if (decompress_buffer(s->cluster_cache, s->cluster_size, - s->cluster_data + sector_offset, csize) < 0)= { + s->cluster_data + sector_offset, csize, + s->compress_format) < 0) { return -EIO; } s->cluster_cache_offset =3D coffset; diff --git a/block/qcow2.c b/block/qcow2.c index 978e8d2..57249cc 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -3391,9 +3391,10 @@ qcow2_co_pwritev_compressed(BlockDriverState *bs, ui= nt64_t offset, BDRVQcow2State *s =3D bs->opaque; QEMUIOVector hd_qiov; struct iovec iov; - z_stream strm; - int ret, out_len; - uint8_t *buf, *out_buf, *local_buf =3D NULL; + z_stream z_strm =3D {}; + int z_windowBits =3D -15, z_level =3D Z_DEFAULT_COMPRESSION; + int ret, out_len =3D 0; + uint8_t *buf, *out_buf =3D NULL, *local_buf =3D NULL; uint64_t cluster_offset; =20 if (bytes =3D=3D 0) { @@ -3418,34 +3419,38 @@ qcow2_co_pwritev_compressed(BlockDriverState *bs, u= int64_t offset, buf =3D qiov->iov[0].iov_base; } =20 - out_buf =3D g_malloc(s->cluster_size); + switch (s->compress_format) { + case -1: + z_windowBits =3D -12; + case QCOW2_COMPRESS_FORMAT_ZLIB: + out_buf =3D g_malloc(s->cluster_size); + if (s->compress_level > 0) { + z_level =3D s->compress_level; + } =20 - /* best compression, small window, no zlib header */ - memset(&strm, 0, sizeof(strm)); - ret =3D deflateInit2(&strm, Z_DEFAULT_COMPRESSION, - Z_DEFLATED, -12, - 9, Z_DEFAULT_STRATEGY); - if (ret !=3D 0) { - ret =3D -EINVAL; - goto fail; - } + ret =3D deflateInit2(&z_strm, z_level, Z_DEFLATED, z_windowBits, 9, + Z_DEFAULT_STRATEGY); + if (ret !=3D Z_OK) { + ret =3D -EINVAL; + goto fail; + } =20 - strm.avail_in =3D s->cluster_size; - strm.next_in =3D (uint8_t *)buf; - strm.avail_out =3D s->cluster_size; - strm.next_out =3D out_buf; + z_strm.avail_in =3D s->cluster_size; + z_strm.next_in =3D (uint8_t *)buf; + z_strm.avail_out =3D s->cluster_size; + z_strm.next_out =3D out_buf; =20 - ret =3D deflate(&strm, Z_FINISH); - if (ret !=3D Z_STREAM_END && ret !=3D Z_OK) { - deflateEnd(&strm); - ret =3D -EINVAL; - goto fail; - } - out_len =3D strm.next_out - out_buf; + ret =3D deflate(&z_strm, Z_FINISH); + out_len =3D z_strm.next_out - out_buf; + deflateEnd(&z_strm); =20 - deflateEnd(&strm); + ret =3D ret !=3D Z_STREAM_END; + break; + default: + abort(); /* should never reach this point */ + } =20 - if (ret !=3D Z_STREAM_END || out_len >=3D s->cluster_size) { + if (ret || out_len >=3D s->cluster_size) { /* could not compress: write normal cluster */ ret =3D qcow2_co_pwritev(bs, offset, bytes, qiov, 0); if (ret < 0) { --=20 1.9.1 From nobody Sun May 5 10:35:17 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1500560913034985.6547490714165; Thu, 20 Jul 2017 07:28:33 -0700 (PDT) Received: from localhost ([::1]:38312 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dYCRH-00062l-6D for importer@patchew.org; Thu, 20 Jul 2017 10:28:27 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41199) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dYCKB-0008My-Ot for qemu-devel@nongnu.org; Thu, 20 Jul 2017 10:21:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dYCK6-0007yR-PA for qemu-devel@nongnu.org; Thu, 20 Jul 2017 10:21:07 -0400 Received: from mx-v6.kamp.de ([2a02:248:0:51::16]:42650 helo=mx01.kamp.de) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dYCK6-0007xa-GC for qemu-devel@nongnu.org; Thu, 20 Jul 2017 10:21:02 -0400 Received: (qmail 15331 invoked by uid 89); 20 Jul 2017 14:21:00 -0000 Received: from [195.62.97.28] by client-16-kamp (envelope-from , uid 89) with qmail-scanner-2010/03/19-MF (clamdscan: 0.99.2/23580. avast: 1.2.2/17010300. spamassassin: 3.4.1. Clear:RC:1(195.62.97.28):. Processed in 0.283847 secs); 20 Jul 2017 14:21:00 -0000 Received: from smtp.kamp.de (HELO submission.kamp.de) ([195.62.97.28]) by mx01.kamp.de with ESMTPS (DHE-RSA-AES256-GCM-SHA384 encrypted); 20 Jul 2017 14:20:57 -0000 Received: (qmail 5157 invoked from network); 20 Jul 2017 14:20:43 -0000 Received: from lieven-pc.kamp-intra.net (HELO lieven-pc) (relay@kamp.de@::ffff:172.21.12.60) by submission.kamp.de with ESMTPS (DHE-RSA-AES256-GCM-SHA384 encrypted) ESMTPA; 20 Jul 2017 14:20:43 -0000 Received: by lieven-pc (Postfix, from userid 1000) id 30D1C26C5E; Thu, 20 Jul 2017 16:20:43 +0200 (CEST) X-GL_Whitelist: yes From: Peter Lieven To: qemu-block@nongnu.org Date: Thu, 20 Jul 2017 16:20:40 +0200 Message-Id: <1500560441-5670-10-git-send-email-pl@kamp.de> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1500560441-5670-1-git-send-email-pl@kamp.de> References: <1500560441-5670-1-git-send-email-pl@kamp.de> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a02:248:0:51::16 Subject: [Qemu-devel] [PATCH V4 09/10] block/qcow2: add lzo compress format X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, Peter Lieven , qemu-devel@nongnu.org, mreitz@redhat.com, den@openvz.org, lersek@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Peter Lieven --- block/qcow2-cluster.c | 15 +++++++++++++++ block/qcow2.c | 42 +++++++++++++++++++++++++++++++++++------- configure | 2 +- qapi/block-core.json | 14 ++++++++++++-- qemu-img.texi | 1 + 5 files changed, 64 insertions(+), 10 deletions(-) diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c index 6c14d59..7d47dde 100644 --- a/block/qcow2-cluster.c +++ b/block/qcow2-cluster.c @@ -24,6 +24,9 @@ =20 #include "qemu/osdep.h" #include +#ifdef CONFIG_LZO +#include +#endif =20 #include "qapi/error.h" #include "qemu-common.h" @@ -1504,6 +1507,18 @@ static int decompress_buffer(uint8_t *out_buf, int o= ut_buf_size, inflateEnd(&z_strm); break; } +#ifdef CONFIG_LZO + case QCOW2_COMPRESS_FORMAT_LZO: + out_len =3D out_buf_size; + ret =3D lzo1x_decompress_safe(buf, buf_size, out_buf, + (lzo_uint *) &out_len, NULL); + if (ret =3D=3D LZO_E_INPUT_NOT_CONSUMED) { + /* We always read up to the next sector boundary. Thus + * buf_size may be larger than the original compressed size. */ + ret =3D 0; + } + break; +#endif default: abort(); /* should never reach this point */ } diff --git a/block/qcow2.c b/block/qcow2.c index 57249cc..0ba5977 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -26,6 +26,9 @@ #include "sysemu/block-backend.h" #include "qemu/module.h" #include +#ifdef CONFIG_LZO +#include +#endif #include "block/qcow2.h" #include "qemu/error-report.h" #include "qapi/qmp/qerror.h" @@ -165,10 +168,18 @@ static ssize_t qcow2_crypto_hdr_write_func(QCryptoBlo= ck *block, size_t offset, } =20 =20 -static void qcow2_compress_level_supported(int format, uint8_t level, +static void qcow2_compress_settings_supported(int format, uint8_t level, Error **errp) { - if (format =3D=3D QCOW2_COMPRESS_FORMAT_ZLIB && level > 9) { +#ifndef CONFIG_LZO + if (format =3D=3D QCOW2_COMPRESS_FORMAT_LZO) { + error_setg(errp, "ERROR: compress format '%s' is not supported", + Qcow2CompressFormat_lookup[format]); + return; + } +#endif + if ((format =3D=3D QCOW2_COMPRESS_FORMAT_ZLIB && level > 9) || + (format =3D=3D QCOW2_COMPRESS_FORMAT_LZO && level > 0)) { error_setg(errp, "ERROR: compress level %" PRIu8 " is not" " supported for format '%s'", level, Qcow2CompressFormat_lookup[format]); @@ -280,14 +291,22 @@ static int qcow2_read_extensions(BlockDriverState *bs= , uint64_t start_offset, return 4; } =20 - qcow2_compress_level_supported(s->compress_format, - compress_ext.level, &local_err); + qcow2_compress_settings_supported(s->compress_format, + compress_ext.level, &local_e= rr); if (local_err) { error_propagate(errp, local_err); return 5; } s->compress_level =3D compress_ext.level; =20 +#ifdef CONFIG_LZO + if (s->compress_format =3D=3D QCOW2_COMPRESS_FORMAT_LZO && + lzo_init() !=3D LZO_E_OK) { + error_setg(errp, "ERROR: internal error - lzo_init() faile= d"); + return 6; + } +#endif + #ifdef DEBUG_EXT printf("Qcow2: Got compress format %s with compress level %" PRIu8 "\n", Qcow2CompressFormat_lookup[s->compress_form= at], @@ -3078,8 +3097,8 @@ static int qcow2_create(const char *filename, QemuOpt= s *opts, Error **errp) visit_free(v); QDECREF(compressopts); QDECREF(options); - qcow2_compress_level_supported(compress.format, compress.level, - &local_err); + qcow2_compress_settings_supported(compress.format, compress.level, + &local_err); if (local_err) { error_propagate(errp, local_err); goto finish; @@ -3394,7 +3413,7 @@ qcow2_co_pwritev_compressed(BlockDriverState *bs, uin= t64_t offset, z_stream z_strm =3D {}; int z_windowBits =3D -15, z_level =3D Z_DEFAULT_COMPRESSION; int ret, out_len =3D 0; - uint8_t *buf, *out_buf =3D NULL, *local_buf =3D NULL; + uint8_t *buf, *out_buf =3D NULL, *local_buf =3D NULL, *work_buf =3D NU= LL; uint64_t cluster_offset; =20 if (bytes =3D=3D 0) { @@ -3446,6 +3465,14 @@ qcow2_co_pwritev_compressed(BlockDriverState *bs, ui= nt64_t offset, =20 ret =3D ret !=3D Z_STREAM_END; break; +#ifdef CONFIG_LZO + case QCOW2_COMPRESS_FORMAT_LZO: + out_buf =3D g_malloc(s->cluster_size + s->cluster_size / 16 + 64 += 3); + work_buf =3D g_malloc(LZO1X_1_MEM_COMPRESS); + ret =3D lzo1x_1_compress(buf, s->cluster_size, out_buf, + (lzo_uint *) &out_len, work_buf); + break; +#endif default: abort(); /* should never reach this point */ } @@ -3491,6 +3518,7 @@ success: fail: qemu_vfree(local_buf); g_free(out_buf); + g_free(work_buf); return ret; } =20 diff --git a/configure b/configure index befebe2..c28a45d 100755 --- a/configure +++ b/configure @@ -1982,7 +1982,7 @@ if test "$lzo" !=3D "no" ; then int main(void) { lzo_version(); return 0; } EOF if compile_prog "" "-llzo2" ; then - libs_softmmu=3D"$libs_softmmu -llzo2" + LIBS=3D"$LIBS -llzo2" lzo=3D"yes" else if test "$lzo" =3D "yes"; then diff --git a/qapi/block-core.json b/qapi/block-core.json index 95e5393..9eb76df 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -2456,11 +2456,12 @@ ## # @Qcow2CompressFormat: # @zlib: standard zlib deflate compression +# @lzo: lzo1x compression # # Since: 2.10 ## { 'enum': 'Qcow2CompressFormat', - 'data': [ 'zlib' ] } + 'data': [ 'zlib', 'lzo' ] } =20 ## # @Qcow2CompressZLib: @@ -2471,6 +2472,14 @@ 'data': { } } =20 ## +# @Qcow2CompressLZO: +# +# Since: 2.10 +## +{ 'struct': 'Qcow2CompressLZO', + 'data': { } } + +## # @Qcow2Compress: # # Specifies the compression format and compression level that should @@ -2488,7 +2497,8 @@ 'base': { 'format': 'Qcow2CompressFormat', '*level': 'uint8' }, 'discriminator': 'format', - 'data': { 'zlib': 'Qcow2CompressZLib' } } + 'data': { 'zlib': 'Qcow2CompressZLib', + 'lzo': 'Qcow2CompressLZO' } } =20 =20 ## diff --git a/qemu-img.texi b/qemu-img.texi index fcc4c1d..17a17e5 100644 --- a/qemu-img.texi +++ b/qemu-img.texi @@ -682,6 +682,7 @@ The following options are available if support for the = respective libraries has been enabled at compile time: =20 zlib Uses standard zlib compression + lzo Uses LZO1X compression =20 The compression algorithm can only be defined at image create time and can= not be changed later. --=20 1.9.1 From nobody Sun May 5 10:35:17 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1500560917969524.7251904842594; Thu, 20 Jul 2017 07:28:37 -0700 (PDT) Received: from localhost ([::1]:38314 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dYCRO-0006AD-QC for importer@patchew.org; Thu, 20 Jul 2017 10:28:34 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41124) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dYCK2-0008Cj-WD for qemu-devel@nongnu.org; Thu, 20 Jul 2017 10:20:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dYCK2-0007wI-5I for qemu-devel@nongnu.org; Thu, 20 Jul 2017 10:20:58 -0400 Received: from mx-v6.kamp.de ([2a02:248:0:51::16]:58981 helo=mx01.kamp.de) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dYCK1-0007uu-S6 for qemu-devel@nongnu.org; Thu, 20 Jul 2017 10:20:58 -0400 Received: (qmail 15120 invoked by uid 89); 20 Jul 2017 14:20:56 -0000 Received: from [195.62.97.28] by client-16-kamp (envelope-from , uid 89) with qmail-scanner-2010/03/19-MF (clamdscan: 0.99.2/23580. avast: 1.2.2/17010300. spamassassin: 3.4.1. Clear:RC:1(195.62.97.28):. Processed in 0.217753 secs); 20 Jul 2017 14:20:56 -0000 Received: from smtp.kamp.de (HELO submission.kamp.de) ([195.62.97.28]) by mx01.kamp.de with ESMTPS (DHE-RSA-AES256-GCM-SHA384 encrypted); 20 Jul 2017 14:20:53 -0000 Received: (qmail 5160 invoked from network); 20 Jul 2017 14:20:43 -0000 Received: from lieven-pc.kamp-intra.net (HELO lieven-pc) (relay@kamp.de@::ffff:172.21.12.60) by submission.kamp.de with ESMTPS (DHE-RSA-AES256-GCM-SHA384 encrypted) ESMTPA; 20 Jul 2017 14:20:43 -0000 Received: by lieven-pc (Postfix, from userid 1000) id 33F70202CD; Thu, 20 Jul 2017 16:20:43 +0200 (CEST) X-GL_Whitelist: yes From: Peter Lieven To: qemu-block@nongnu.org Date: Thu, 20 Jul 2017 16:20:41 +0200 Message-Id: <1500560441-5670-11-git-send-email-pl@kamp.de> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1500560441-5670-1-git-send-email-pl@kamp.de> References: <1500560441-5670-1-git-send-email-pl@kamp.de> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a02:248:0:51::16 Subject: [Qemu-devel] [PATCH V4 10/10] block/qcow2: add compress info to image specific info X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, Peter Lieven , qemu-devel@nongnu.org, mreitz@redhat.com, den@openvz.org, lersek@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Peter Lieven --- block/qcow2.c | 9 +++++++++ qapi/block-core.json | 6 +++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/block/qcow2.c b/block/qcow2.c index 0ba5977..59cf3b3 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -3942,6 +3942,15 @@ static ImageInfoSpecific *qcow2_get_specific_info(Bl= ockDriverState *bs) spec_info->u.qcow2.data->encrypt =3D qencrypt; } =20 + if (s->compress_format !=3D -1) { + Qcow2Compress *qcompress =3D g_new0(Qcow2Compress, 1); + qcompress->format =3D s->compress_format; + qcompress->level =3D s->compress_level; + qcompress->has_level =3D true; + spec_info->u.qcow2.data->compress =3D qcompress; + spec_info->u.qcow2.data->has_compress =3D true; + } + return spec_info; } =20 diff --git a/qapi/block-core.json b/qapi/block-core.json index 9eb76df..9310715 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -68,6 +68,9 @@ # @encrypt: details about encryption parameters; only set if image # is encrypted (since 2.10) # +# @compress: details about parameters for compressed clusters; only set if +# the compress format header extension is present (since 2.10) +# # Since: 1.7 ## { 'struct': 'ImageInfoSpecificQCow2', @@ -76,7 +79,8 @@ '*lazy-refcounts': 'bool', '*corrupt': 'bool', 'refcount-bits': 'int', - '*encrypt': 'ImageInfoSpecificQCow2Encryption' + '*encrypt': 'ImageInfoSpecificQCow2Encryption', + '*compress': 'Qcow2Compress' } } =20 ## --=20 1.9.1