From: "Benoît Canet" <benoit.canet@irqsave.net>
To: Max Reitz <mreitz@redhat.com>
Cc: Kevin Wolf <kwolf@redhat.com>,
qemu-devel@nongnu.org, Stefan Hajnoczi <stefanha@redhat.com>
Subject: Re: [Qemu-devel] [PATCH 1/2] quorum: Simplify quorum_open()
Date: Fri, 21 Feb 2014 21:04:43 +0100 [thread overview]
Message-ID: <20140221200443.GA3165@irqsave.net> (raw)
In-Reply-To: <1393011848-18742-2-git-send-email-mreitz@redhat.com>
The Friday 21 Feb 2014 à 20:44:07 (+0100), Max Reitz wrote :
> Although it may not look like it, this patch simplifies quorum_open().
> qdict_array_split() is now able to return QLists with different objects
> than only QDicts, therefore it will now do all the work and
> quorum_open() does not have to handle reference strings by itself.
>
> This allows mixing full option dicts and reference strings for
> specifying the child block devices of quorum; furthermore, it improves
> handling of malformed specifications.
>
> Signed-off-by: Max Reitz <mreitz@redhat.com>
> ---
> block/quorum.c | 62 +++++++++++++++++++++++++++++++++++-----------------------
> 1 file changed, 38 insertions(+), 24 deletions(-)
>
> diff --git a/block/quorum.c b/block/quorum.c
> index 18721ba..8f5833d 100644
> --- a/block/quorum.c
> +++ b/block/quorum.c
> @@ -720,7 +720,6 @@ static int quorum_open(BlockDriverState *bs, QDict *options, int flags,
> QDict *sub = NULL;
> QList *list = NULL;
> const QListEntry *lentry;
> - const QDictEntry *dentry;
> int i;
> int ret = 0;
>
> @@ -728,10 +727,17 @@ static int quorum_open(BlockDriverState *bs, QDict *options, int flags,
> qdict_extract_subqdict(options, &sub, "children.");
> qdict_array_split(sub, &list);
>
> + if (qdict_size(sub)) {
> + error_setg(&local_err, "Invalid option children.%s",
> + qdict_first(sub)->key);
> + ret = -EINVAL;
> + goto exit;
> + }
> +
> /* count how many different children are present and validate
> * qdict_size(sub) address the open by reference case
> */
I think the second part of the comment about qlist_size(sub) is an extra now.
Aside from that:
Reviewed-by: Benoit Canet <benoit@irqsave.net>
> - s->num_children = !qlist_size(list) ? qdict_size(sub) : qlist_size(list);
> + s->num_children = qlist_size(list);
> if (s->num_children < 2) {
> error_setg(&local_err,
> "Number of provided children must be greater than 1");
> @@ -767,30 +773,38 @@ static int quorum_open(BlockDriverState *bs, QDict *options, int flags,
> s->bs = g_new0(BlockDriverState *, s->num_children);
> opened = g_new0(bool, s->num_children);
>
> - /* Open by file name or options dict (command line or QMP) */
> - if (s->num_children == qlist_size(list)) {
> - for (i = 0, lentry = qlist_first(list); lentry;
> - lentry = qlist_next(lentry), i++) {
> - QDict *d = qobject_to_qdict(lentry->value);
> - QINCREF(d);
> - ret = bdrv_open(&s->bs[i], NULL, NULL, d, flags, NULL, &local_err);
> - if (ret < 0) {
> - goto close_exit;
> - }
> - opened[i] = true;
> + for (i = 0, lentry = qlist_first(list); lentry;
> + lentry = qlist_next(lentry), i++) {
> + QDict *d;
> + QString *string;
> +
> + switch (qobject_type(lentry->value))
> + {
> + /* List of options */
> + case QTYPE_QDICT:
> + d = qobject_to_qdict(lentry->value);
> + QINCREF(d);
> + ret = bdrv_open(&s->bs[i], NULL, NULL, d, flags, NULL,
> + &local_err);
> + break;
> +
> + /* QMP reference */
> + case QTYPE_QSTRING:
> + string = qobject_to_qstring(lentry->value);
> + ret = bdrv_open(&s->bs[i], NULL, qstring_get_str(string), NULL,
> + flags, NULL, &local_err);
> + break;
> +
> + default:
> + error_setg(&local_err, "Specification of child block device %i "
> + "is invalid", i);
> + ret = -EINVAL;
> }
> - /* Open by QMP references */
> - } else {
> - for (i = 0, dentry = qdict_first(sub); dentry;
> - dentry = qdict_next(sub, dentry), i++) {
> - QString *string = qobject_to_qstring(dentry->value);
> - ret = bdrv_open(&s->bs[i], NULL, qstring_get_str(string), NULL,
> - flags, NULL, &local_err);
> - if (ret < 0) {
> - goto close_exit;
> - }
> - opened[i] = true;
> +
> + if (ret < 0) {
> + goto close_exit;
> }
> + opened[i] = true;
> }
>
> g_free(opened);
> --
> 1.9.0
>
next prev parent reply other threads:[~2014-02-21 20:04 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-02-21 19:44 [Qemu-devel] [PATCH 0/2] quorum: Simplify quorum_open() Max Reitz
2014-02-21 19:44 ` [Qemu-devel] [PATCH 1/2] " Max Reitz
2014-02-21 20:04 ` Benoît Canet [this message]
2014-02-21 19:44 ` [Qemu-devel] [PATCH 2/2] iotests: Mixed quorum child device specifications Max Reitz
2014-02-21 20:29 ` Benoît Canet
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=20140221200443.GA3165@irqsave.net \
--to=benoit.canet@irqsave.net \
--cc=kwolf@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 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.