From patchwork Fri Feb 21 21:30:37 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Reitz X-Patchwork-Id: 323038 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id C15692C02FA for ; Sat, 22 Feb 2014 08:28:48 +1100 (EST) Received: from localhost ([::1]:47063 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WGxeI-0000An-Id for incoming@patchwork.ozlabs.org; Fri, 21 Feb 2014 16:28:46 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41837) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WGxde-0008Rk-3A for qemu-devel@nongnu.org; Fri, 21 Feb 2014 16:28:11 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WGxdZ-0002nK-2G for qemu-devel@nongnu.org; Fri, 21 Feb 2014 16:28:06 -0500 Received: from mx1.redhat.com ([209.132.183.28]:4858) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WGxdY-0002nC-R5 for qemu-devel@nongnu.org; Fri, 21 Feb 2014 16:28:00 -0500 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s1LLRxmM032387 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 21 Feb 2014 16:27:59 -0500 Received: from localhost (ovpn-116-27.ams2.redhat.com [10.36.116.27]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s1LLRuhl009932 (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=NO); Fri, 21 Feb 2014 16:27:58 -0500 From: Max Reitz To: qemu-devel@nongnu.org Date: Fri, 21 Feb 2014 22:30:37 +0100 Message-Id: <1393018238-15068-2-git-send-email-mreitz@redhat.com> In-Reply-To: <1393018238-15068-1-git-send-email-mreitz@redhat.com> References: <1393018238-15068-1-git-send-email-mreitz@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Kevin Wolf , =?UTF-8?q?Beno=C3=AEt=20Canet?= , Stefan Hajnoczi , Max Reitz Subject: [Qemu-devel] [PATCH v2 1/2] quorum: Simplify quorum_open() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 Reviewed-by: Benoit Canet --- block/quorum.c | 66 ++++++++++++++++++++++++++++++++++------------------------ 1 file changed, 39 insertions(+), 27 deletions(-) diff --git a/block/quorum.c b/block/quorum.c index 73dd45b..6c28239 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,15 @@ static int quorum_open(BlockDriverState *bs, QDict *options, int flags, qdict_extract_subqdict(options, &sub, "children."); qdict_array_split(sub, &list); - /* count how many different children are present and validate - * qdict_size(sub) address the open by reference case - */ - s->num_children = !qlist_size(list) ? qdict_size(sub) : qlist_size(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 */ + 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 +771,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);