From patchwork Fri Mar 15 15:14:02 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Hajnoczi X-Patchwork-Id: 228075 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 306A02C00E7 for ; Sat, 16 Mar 2013 02:43:31 +1100 (EST) Received: from localhost ([::1]:47545 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UGWNI-0002WI-8y for incoming@patchwork.ozlabs.org; Fri, 15 Mar 2013 11:16:52 -0400 Received: from eggs.gnu.org ([208.118.235.92]:42840) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UGWLC-0007Ru-7U for qemu-devel@nongnu.org; Fri, 15 Mar 2013 11:14:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UGWL7-00041w-UG for qemu-devel@nongnu.org; Fri, 15 Mar 2013 11:14:42 -0400 Received: from mx1.redhat.com ([209.132.183.28]:53424) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UGWL7-00040X-Kb for qemu-devel@nongnu.org; Fri, 15 Mar 2013 11:14:37 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r2FFEaG9009262 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 15 Mar 2013 11:14:36 -0400 Received: from localhost (ovpn-112-50.ams2.redhat.com [10.36.112.50]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r2FFEZj9001377; Fri, 15 Mar 2013 11:14:36 -0400 From: Stefan Hajnoczi To: Date: Fri, 15 Mar 2013 16:14:02 +0100 Message-Id: <1363360465-5247-6-git-send-email-stefanha@redhat.com> In-Reply-To: <1363360465-5247-1-git-send-email-stefanha@redhat.com> References: <1363360465-5247-1-git-send-email-stefanha@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Anthony Liguori Subject: [Qemu-devel] [PATCH 05/28] qemu-option: Add qemu_opts_absorb_qdict() 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 From: Kevin Wolf This adds a function that adds all entries of a QDict to a QemuOpts if the keys are known, and leaves only the rest in the QDict. This way a single QDict of -drive options can be processed in multiple places (generic block layer, block driver, backing file block driver, etc.), where each part picks the options it knows. If at the end of the process the QDict isn't empty, the user specified an invalid option. Signed-off-by: Kevin Wolf Reviewed-by: Eric Blake Reviewed-by: Stefan Hajnoczi Signed-off-by: Stefan Hajnoczi --- include/qemu/option.h | 1 + util/qemu-option.c | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/include/qemu/option.h b/include/qemu/option.h index ba197cd..bdb6d21 100644 --- a/include/qemu/option.h +++ b/include/qemu/option.h @@ -149,6 +149,7 @@ void qemu_opts_set_defaults(QemuOptsList *list, const char *params, QemuOpts *qemu_opts_from_qdict(QemuOptsList *list, const QDict *qdict, Error **errp); QDict *qemu_opts_to_qdict(QemuOpts *opts, QDict *qdict); +void qemu_opts_absorb_qdict(QemuOpts *opts, QDict *qdict, Error **errp); typedef int (*qemu_opts_loopfunc)(QemuOpts *opts, void *opaque); int qemu_opts_print(QemuOpts *opts, void *dummy); diff --git a/util/qemu-option.c b/util/qemu-option.c index 5a1d03c..8b74bf1 100644 --- a/util/qemu-option.c +++ b/util/qemu-option.c @@ -1067,6 +1067,40 @@ QemuOpts *qemu_opts_from_qdict(QemuOptsList *list, const QDict *qdict, } /* + * Adds all QDict entries to the QemuOpts that can be added and removes them + * from the QDict. When this function returns, the QDict contains only those + * entries that couldn't be added to the QemuOpts. + */ +void qemu_opts_absorb_qdict(QemuOpts *opts, QDict *qdict, Error **errp) +{ + const QDictEntry *entry, *next; + + entry = qdict_first(qdict); + + while (entry != NULL) { + Error *local_err = NULL; + OptsFromQDictState state = { + .errp = &local_err, + .opts = opts, + }; + + next = qdict_next(qdict, entry); + + if (find_desc_by_name(opts->list->desc, entry->key)) { + qemu_opts_from_qdict_1(entry->key, entry->value, &state); + if (error_is_set(&local_err)) { + error_propagate(errp, local_err); + return; + } else { + qdict_del(qdict, entry->key); + } + } + + entry = next; + } +} + +/* * Convert from QemuOpts to QDict. * The QDict values are of type QString. * TODO We'll want to use types appropriate for opt->desc->type, but