From: Kevin Wolf <kwolf@redhat.com>
To: Fam Zheng <famz@redhat.com>
Cc: qemu-devel@nongnu.org, Stefan Hajnoczi <stefanha@redhat.com>,
Max Reitz <mreitz@redhat.com>
Subject: Re: [Qemu-devel] [PATCH v3 2/3] qcow2: Implement bdrv_amend_options
Date: Mon, 2 Sep 2013 09:55:53 +0200 [thread overview]
Message-ID: <20130902075553.GA3423@dhcp-200-207.str.redhat.com> (raw)
In-Reply-To: <20130902034307.GA10844@T430s.nay.redhat.com>
Am 02.09.2013 um 05:43 hat Fam Zheng geschrieben:
> On Fri, 08/30 12:27, Max Reitz wrote:
> > Implement bdrv_amend_options for compat, size, backing_file, backing_fmt
> > and lazy_refcounts.
> >
> > Downgrading images from compat=1.1 to compat=0.10 is achieved through
> > handling all incompatible flags accordingly, clearing all compatible and
> > autoclear flags and expanding all zero clusters.
> >
> > Signed-off-by: Max Reitz <mreitz@redhat.com>
> > ---
> > block/qcow2-cluster.c | 165 ++++++++++++++++++++++++++++++++++++++++++
> > block/qcow2.c | 194 +++++++++++++++++++++++++++++++++++++++++++++++++-
> > block/qcow2.h | 3 +
> > 3 files changed, 361 insertions(+), 1 deletion(-)
> > +static int qcow2_amend_options(BlockDriverState *bs,
> > + QEMUOptionParameter *options)
> > +{
> > + BDRVQcowState *s = bs->opaque;
> > + int old_version = s->qcow_version, new_version = old_version;
> > + uint64_t new_size = 0;
> > + const char *backing_file = NULL, *backing_format = NULL;
> > + bool lazy_refcounts = s->use_lazy_refcounts;
> > + int ret;
> > + int i;
> > +
> > + for (i = 0; options[i].name; i++)
> > + {
> > + if (!strcmp(options[i].name, "compat")) {
> > + if (!options[i].value.s) {
> > + /* preserve default */
> > + } else if (!strcmp(options[i].value.s, "0.10")) {
> > + new_version = 2;
> > + } else if (!strcmp(options[i].value.s, "1.1")) {
> > + new_version = 3;
> > + } else {
> > + fprintf(stderr, "Unknown compatibility level %s.\n",
> > + options[i].value.s);
> > + return -EINVAL;
> > + }
> > + } else if (!strcmp(options[i].name, "preallocation")) {
> > + if (options[i].assigned) {
>
> For encryption flag and cluster_size, you checked the original value and only
> error out on actual change, should check the original preallocation value here
> as well?
>
> > + fprintf(stderr, "Cannot change preallocation mode.\n");
> > + return -ENOTSUP;
> > + }
> > + } else if (!strcmp(options[i].name, "size")) {
> > + new_size = options[i].value.n;
> > + } else if (!strcmp(options[i].name, "backing_file")) {
> > + backing_file = options[i].value.s;
> > + } else if (!strcmp(options[i].name, "backing_fmt")) {
> > + backing_format = options[i].value.s;
> > + } else if (!strcmp(options[i].name, "encryption")) {
> > + if (options[i].assigned &&
> > + (options[i].value.n != !!s->crypt_method)) {
> > + fprintf(stderr, "Changing the encryption flag is not "
> > + "supported.\n");
> > + return -ENOTSUP;
> > + }
> > + } else if (!strcmp(options[i].name, "cluster_size")) {
> > + if (options[i].assigned && (options[i].value.n != s->cluster_size))
> > + {
> > + fprintf(stderr, "Changing the cluster size is not "
> > + "supported.\n");
> > + return -ENOTSUP;
> > + }
> > + } else if (!strcmp(options[i].name, "lazy_refcounts")) {
> > + if (options[i].assigned) {
> > + lazy_refcounts = options[i].value.n;
> > + }
> > + } else {
> > + /* if this assertion fails, this probably means a new option was
> > + * added without having it covered here */
> > + assert(false);
>
> A unknown option reported as -ENOTSUP with a proper message is good enough,
> it's not that critical for an assert.
assert() has nothing to do with being critical.
This is not code for handling a user error, but for catching programming
errors. If the else branch is reached, this is a bug, and you want it to
be detected as quickly as possible (and without having to debug a lot in
order to find out where a bogus -ENOTSUP comes from)
Kevin
next prev parent reply other threads:[~2013-09-02 7:56 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-08-30 10:27 [Qemu-devel] [PATCH v3 0/3] block/qcow2: Image file option amendment Max Reitz
2013-08-30 10:27 ` [Qemu-devel] [PATCH v3 1/3] block: " Max Reitz
2013-08-30 10:27 ` [Qemu-devel] [PATCH v3 2/3] qcow2: Implement bdrv_amend_options Max Reitz
2013-09-02 3:43 ` Fam Zheng
2013-09-02 7:43 ` Max Reitz
2013-09-02 7:55 ` Kevin Wolf [this message]
2013-08-30 10:27 ` [Qemu-devel] [PATCH v3 3/3] qemu-iotest: qcow2 image option amendment Max Reitz
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=20130902075553.GA3423@dhcp-200-207.str.redhat.com \
--to=kwolf@redhat.com \
--cc=famz@redhat.com \
--cc=mreitz@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).