From: "Daniel P. Berrange" <berrange@redhat.com>
To: Peter Lieven <pl@kamp.de>
Cc: qemu-block@nongnu.org, qemu-devel@nongnu.org, kwolf@redhat.com,
lersek@redhat.com, den@openvz.org, mreitz@redhat.com,
eblake@redhat.com
Subject: Re: [Qemu-devel] [PATCH V2 3/8] block/qcow2: parse compress create options
Date: Mon, 10 Jul 2017 14:52:42 +0100 [thread overview]
Message-ID: <20170710135242.GC6770@redhat.com> (raw)
In-Reply-To: <1498733831-15254-4-git-send-email-pl@kamp.de>
On Thu, Jun 29, 2017 at 12:57:06PM +0200, Peter Lieven wrote:
> this adds parsing and validation for the compress create
> options. They are only validated but not yet used.
>
> Signed-off-by: Peter Lieven <pl@kamp.de>
> ---
> block/qcow2.c | 56 +++++++++++++++++++++++++++++++++++++++++++++--
> block/qcow2.h | 9 ++++++++
> include/block/block_int.h | 2 ++
> 3 files changed, 65 insertions(+), 2 deletions(-)
>
> diff --git a/block/qcow2.c b/block/qcow2.c
> index 2f94f03..308121a 100644
> --- a/block/qcow2.c
> +++ b/block/qcow2.c
> @@ -2144,7 +2144,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,
> - Error **errp)
> + const char *compress_format_name,
> + uint8_t compress_level, Error **errp)
> {
> int cluster_bits;
> QDict *options;
> @@ -2390,11 +2391,24 @@ out:
> return ret;
> }
>
> +static int qcow2_compress_format_from_name(char *fmt)
> +{
> + if (!fmt || !fmt[0]) {
> + return QCOW2_COMPRESS_ZLIB_COMPAT;
> + } else if (g_str_equal(fmt, "zlib")) {
> + return QCOW2_COMPRESS_ZLIB;
> + } else {
> + return -EINVAL;
> + }
> +}
> +
> static int qcow2_create(const char *filename, QemuOpts *opts, Error **errp)
> {
> char *backing_file = NULL;
> char *backing_fmt = NULL;
> char *buf = NULL;
> + char *compress_format_name = NULL;
> + uint64_t compress_level = 0;
> uint64_t size = 0;
> int flags = 0;
> size_t cluster_size = DEFAULT_CLUSTER_SIZE;
> @@ -2475,15 +2489,40 @@ static int qcow2_create(const char *filename, QemuOpts *opts, Error **errp)
>
> refcount_order = ctz32(refcount_bits);
>
> + compress_format_name = qemu_opt_get_del(opts,
> + BLOCK_OPT_COMPRESS_FORMAT);
> + ret = qcow2_compress_format_from_name(compress_format_name);
> + if (ret < 0) {
> + error_setg(errp, "Compress format '%s' is not supported",
> + compress_format_name);
> + goto finish;
> + }
> + compress_level = qemu_opt_get_number_del(opts, BLOCK_OPT_COMPRESS_LEVEL,
> + compress_level);
> + if (ret == QCOW2_COMPRESS_ZLIB_COMPAT && compress_level > 0) {
> + error_setg(errp, "Compress level can only be defined in conjunction"
> + " with compress format");
> + ret = -EINVAL;
> + goto finish;
> + }
> + if ((ret == QCOW2_COMPRESS_ZLIB && compress_level > 9) ||
> + compress_level > 0xff) {
> + error_setg(errp, "Compress level %" PRIu64 " is not supported for"
> + " format '%s'", compress_level, compress_format_name);
> + ret = -EINVAL;
> + goto finish;
> + }
This is where the QAPI schema bits would fit in. eg instead of calling the
various qemu_opts_get* functions, do something like this:
QDict *options, *compressopts = NULL;
Qcow2Compress *compress = NULL;
options = qemu_opts_to_qdict(opts, NULL);
qdict_extract_subqdict(options, &compressopts, "compress.");
v = qobject_input_visitor_new_keyval(QOBJECT(compressopts));
visit_type_Qcow2Compress(v, &compress, &local_err);
if (local_err) {
ret= -EINVAL;
goto finish;
}
..do whatever you need with the 'compress' object now...
visit_free(v);
QDECREF(encryptopts);
QDECREF(options);
Eventually the entire of the qcow2 create codepath will be qemu opts based,
so all the subdict/visitor steps will be able to go away, leaving you to
just use the Qcow2Compress struct immediately.
Regards,
Daniel
--
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org -o- https://fstop138.berrange.com :|
|: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
next prev parent reply other threads:[~2017-07-10 13:53 UTC|newest]
Thread overview: 50+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-06-29 10:57 [Qemu-devel] [PATCH V2 0/8] add Qcow2 compress format extension Peter Lieven
2017-06-29 10:57 ` [Qemu-devel] [PATCH V2 1/8] docs: add compress format extension to qcow2 spec Peter Lieven
2017-07-10 12:58 ` Kevin Wolf
2017-07-10 13:27 ` Peter Lieven
2017-07-10 13:50 ` Kevin Wolf
2017-07-10 14:31 ` Eric Blake
2017-06-29 10:57 ` [Qemu-devel] [PATCH V2 2/8] qapi: add compress parameters to Qcow2 Blockdev options Peter Lieven
2017-07-10 13:10 ` Kevin Wolf
2017-07-10 13:24 ` Peter Lieven
2017-07-10 13:27 ` Daniel P. Berrange
2017-07-10 13:30 ` Kevin Wolf
2017-07-10 13:32 ` Peter Lieven
2017-07-13 8:45 ` Peter Lieven
2017-07-13 8:52 ` Kevin Wolf
2017-07-13 9:18 ` Daniel P. Berrange
2017-06-29 10:57 ` [Qemu-devel] [PATCH V2 3/8] block/qcow2: parse compress create options Peter Lieven
2017-07-10 13:52 ` Daniel P. Berrange [this message]
2017-06-29 10:57 ` [Qemu-devel] [PATCH V2 4/8] qemu-img: add documentation for compress settings Peter Lieven
2017-07-10 13:21 ` Kevin Wolf
2017-06-29 10:57 ` [Qemu-devel] [PATCH V2 5/8] block/qcow2: read and write the compress format extension Peter Lieven
2017-07-10 13:25 ` Kevin Wolf
2017-07-10 13:29 ` Peter Lieven
2017-07-10 13:34 ` Kevin Wolf
2017-07-10 13:44 ` Daniel P. Berrange
2017-07-10 13:46 ` Peter Lieven
2017-07-10 13:58 ` Daniel P. Berrange
2017-07-10 13:52 ` Kevin Wolf
2017-07-10 13:55 ` Daniel P. Berrange
2017-07-13 8:44 ` Peter Lieven
2017-07-13 9:21 ` Daniel P. Berrange
2017-07-13 13:49 ` Peter Lieven
2017-07-13 14:00 ` Daniel P. Berrange
2017-07-13 14:03 ` Peter Lieven
2017-07-13 14:07 ` Daniel P. Berrange
2017-07-13 14:18 ` Peter Lieven
2017-07-13 14:58 ` Daniel P. Berrange
2017-07-13 15:00 ` Peter Lieven
2017-07-13 15:01 ` Daniel P. Berrange
2017-07-13 15:02 ` Peter Lieven
2017-07-13 15:06 ` Daniel P. Berrange
2017-07-13 15:13 ` Peter Lieven
2017-07-13 15:17 ` Daniel P. Berrange
2017-07-13 15:21 ` Peter Lieven
2017-07-13 15:21 ` Eric Blake
2017-06-29 10:57 ` [Qemu-devel] [PATCH V2 6/8] block/qcow2: optimize qcow2_co_pwritev_compressed Peter Lieven
2017-06-29 10:57 ` [Qemu-devel] [PATCH V2 7/8] block/qcow2: start using the compress format extension Peter Lieven
2017-06-29 10:57 ` [Qemu-devel] [PATCH V2 8/8] block/qcow2: add lzo compress format Peter Lieven
2017-07-06 23:49 ` [Qemu-devel] [PATCH V2 0/8] add Qcow2 compress format extension no-reply
2017-07-07 0:02 ` Fam Zheng
2017-07-10 12:36 ` Peter Lieven
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170710135242.GC6770@redhat.com \
--to=berrange@redhat.com \
--cc=den@openvz.org \
--cc=eblake@redhat.com \
--cc=kwolf@redhat.com \
--cc=lersek@redhat.com \
--cc=mreitz@redhat.com \
--cc=pl@kamp.de \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.