From patchwork Fri Jul 14 09:56:39 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Lieven X-Patchwork-Id: 9840411 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 4558060381 for ; Fri, 14 Jul 2017 09:58:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 36D0B2874F for ; Fri, 14 Jul 2017 09:58:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2BB362876E; Fri, 14 Jul 2017 09:58:30 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id C0C8F2874F for ; Fri, 14 Jul 2017 09:58:29 +0000 (UTC) Received: from localhost ([::1]:36624 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dVxMj-0003i6-1P for patchwork-qemu-devel@patchwork.kernel.org; Fri, 14 Jul 2017 05:58:29 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38260) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dVxLU-0003fR-Qh for qemu-devel@nongnu.org; Fri, 14 Jul 2017 05:57:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dVxLT-00081O-GA for qemu-devel@nongnu.org; Fri, 14 Jul 2017 05:57:12 -0400 Received: from mx-v6.kamp.de ([2a02:248:0:51::16]:36078 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 1dVxLT-00080B-6I for qemu-devel@nongnu.org; Fri, 14 Jul 2017 05:57:11 -0400 Received: (qmail 28916 invoked by uid 89); 14 Jul 2017 09:57:09 -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/23562. avast: 1.2.2/17010300. spamassassin: 3.4.1. Clear:RC:1(195.62.97.28):. Processed in 0.309181 secs); 14 Jul 2017 09:57:09 -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); 14 Jul 2017 09:57:05 -0000 X-GL_Whitelist: yes Received: (qmail 21455 invoked from network); 14 Jul 2017 09:57:00 -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; 14 Jul 2017 09:57:00 -0000 Received: by lieven-pc (Postfix, from userid 1000) id 7CD7A20D80; Fri, 14 Jul 2017 11:57:00 +0200 (CEST) From: Peter Lieven To: qemu-block@nongnu.org Date: Fri, 14 Jul 2017 11:56:39 +0200 Message-Id: <1500026205-15542-4-git-send-email-pl@kamp.de> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1500026205-15542-1-git-send-email-pl@kamp.de> References: <1500026205-15542-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 V3 3/9] 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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 c144ea5..6bf4ea5 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_format, int flags, size_t cluster_size, PreallocMode prealloc, QemuOpts *opts, int version, int refcount_order, - const char *encryptfmt, Error **errp) + const char *encryptfmt, Qcow2Compress *compress, + Error **errp) { QDict *options; @@ -2898,6 +2901,7 @@ static int qcow2_create(const char *filename, QemuOpts *opts, Error **errp) char *backing_file = NULL; char *backing_fmt = NULL; char *buf = NULL; + Qcow2Compress compress, *compress_ptr = NULL; uint64_t size = 0; int flags = 0; size_t cluster_size = DEFAULT_CLUSTER_SIZE; @@ -2975,9 +2979,43 @@ static int qcow2_create(const char *filename, QemuOpts *opts, Error **errp) refcount_order = ctz32(refcount_bits); + if (qemu_opt_get(opts, BLOCK_OPT_COMPRESS_FORMAT) || + qemu_opt_get(opts, BLOCK_OPT_COMPRESS_LEVEL)) { + QDict *options, *compressopts = NULL; + Visitor *v; + options = qemu_opts_to_qdict(opts, NULL); + qdict_extract_subqdict(options, &compressopts, "compress."); + v = 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 = -EINVAL; + goto finish; + } + visit_type_Qcow2Compress_members(v, &compress, &local_err); + if (local_err) { + error_propagate(errp, local_err); + ret = -EINVAL; + goto finish; + } + visit_end_struct(v, NULL); + visit_free(v); + QDECREF(compressopts); + QDECREF(options); + if (compress.format == QCOW2_COMPRESS_FORMAT_ZLIB && + compress.level > 9) { + error_setg(errp, "Compress level %" PRIu8 " is not supported for" + " format '%s'", compress.level, + Qcow2CompressFormat_lookup[compress.format]); + ret = -EINVAL; + goto finish; + } + compress_ptr = &compress; + } + ret = qcow2_create2(filename, size, backing_file, backing_fmt, flags, cluster_size, prealloc, opts, version, refcount_order, - encryptfmt, &local_err); + encryptfmt, compress_ptr, &local_err); error_propagate(errp, local_err); finish: @@ -4287,6 +4325,17 @@ static QemuOptsList qcow2_create_opts = { .help = "Width of a reference count entry in bits", .def_value_str = "16" }, + { + .name = BLOCK_OPT_COMPRESS_FORMAT, + .type = QEMU_OPT_STRING, + .help = "Compress format used for compressed clusters (zlib)", + }, + { + .name = BLOCK_OPT_COMPRESS_LEVEL, + .type = QEMU_OPT_NUMBER, + .help = "Compress level used for compressed clusters (0 = default," + " 1=fastest, x=best; x varies depending on compress.format)", + }, { /* end of list */ } } }; diff --git a/include/block/block_int.h b/include/block/block_int.h index 669a279..eac61cd 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" #define BLOCK_PROBE_BUF_SIZE 512