From patchwork Wed Sep 2 08:51:09 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wen Congyang X-Patchwork-Id: 513415 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)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id A61B214027F for ; Wed, 2 Sep 2015 19:01:55 +1000 (AEST) Received: from localhost ([::1]:35380 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZX3vV-0006ur-Uf for incoming@patchwork.ozlabs.org; Wed, 02 Sep 2015 05:01:53 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50522) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZX3m6-0007XV-O9 for qemu-devel@nongnu.org; Wed, 02 Sep 2015 04:52:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZX3m5-0004UB-IV for qemu-devel@nongnu.org; Wed, 02 Sep 2015 04:52:10 -0400 Received: from [59.151.112.132] (port=8817 helo=heian.cn.fujitsu.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZX3m4-00047B-CS; Wed, 02 Sep 2015 04:52:09 -0400 X-IronPort-AV: E=Sophos;i="5.15,520,1432569600"; d="scan'208";a="100276470" Received: from unknown (HELO edo.cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 02 Sep 2015 16:55:02 +0800 Received: from G08CNEXCHPEKD01.g08.fujitsu.local (localhost.localdomain [127.0.0.1]) by edo.cn.fujitsu.com (8.14.3/8.13.1) with ESMTP id t828pnar020281; Wed, 2 Sep 2015 16:51:49 +0800 Received: from G08FNSTD140052.g08.fujitsu.local (10.167.226.52) by G08CNEXCHPEKD01.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.181.6; Wed, 2 Sep 2015 16:51:58 +0800 From: Wen Congyang To: qemu devel , Fam Zheng , Max Reitz , Paolo Bonzini , Stefan Hajnoczi Date: Wed, 2 Sep 2015 16:51:09 +0800 Message-ID: <1441183880-26993-6-git-send-email-wency@cn.fujitsu.com> X-Mailer: git-send-email 2.4.3 In-Reply-To: <1441183880-26993-1-git-send-email-wency@cn.fujitsu.com> References: <1441183880-26993-1-git-send-email-wency@cn.fujitsu.com> MIME-Version: 1.0 X-Originating-IP: [10.167.226.52] X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 59.151.112.132 Cc: Kevin Wolf , qemu block , Jiang Yunhong , Dong Eddie , "Dr. David Alan Gilbert" , "Michael R. Hines" , Gonglei , Yang Hongyang , zhanghailiang Subject: [Qemu-devel] [PATCH 05/16] introduce a new API qemu_opts_absorb_qdict_by_index() 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 Signed-off-by: Wen Congyang Signed-off-by: zhanghailiang Signed-off-by: Gonglei --- include/qemu/option.h | 2 ++ util/qemu-option.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/include/qemu/option.h b/include/qemu/option.h index 57e51c9..725a781 100644 --- a/include/qemu/option.h +++ b/include/qemu/option.h @@ -129,6 +129,8 @@ 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); +void qemu_opts_absorb_qdict_by_index(QemuOpts *opts, QDict *qdict, + const char *index, Error **errp); typedef int (*qemu_opts_loopfunc)(void *opaque, QemuOpts *opts, Error **errp); int qemu_opts_foreach(QemuOptsList *list, qemu_opts_loopfunc func, diff --git a/util/qemu-option.c b/util/qemu-option.c index efe9d27..a93a269 100644 --- a/util/qemu-option.c +++ b/util/qemu-option.c @@ -1021,6 +1021,50 @@ void qemu_opts_absorb_qdict(QemuOpts *opts, QDict *qdict, Error **errp) } /* + * Adds all QDict entries to the QemuOpts that can be added and removes them + * from the QDict. The key starts with "%index." in 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_by_index(QemuOpts *opts, QDict *qdict, + const char *index, Error **errp) +{ + const QDictEntry *entry, *next; + const char *key; + int len = strlen(index); + + entry = qdict_first(qdict); + + while (entry != NULL) { + Error *local_err = NULL; + OptsFromQDictState state = { + .errp = &local_err, + .opts = opts, + }; + + next = qdict_next(qdict, entry); + if (strncmp(entry->key, index, len) || *(entry->key + len) != '.') { + entry = next; + continue; + } + + key = entry->key + len + 1; + + if (find_desc_by_name(opts->list->desc, key)) { + qemu_opts_from_qdict_1(key, entry->value, &state); + if (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