From patchwork Tue Jul 7 08:43:02 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wen Congyang X-Patchwork-Id: 492085 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 9B8331402BD for ; Tue, 7 Jul 2015 18:41:20 +1000 (AEST) Received: from localhost ([::1]:55725 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZCORK-00089d-RK for incoming@patchwork.ozlabs.org; Tue, 07 Jul 2015 04:41:18 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41466) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZCOQY-0007BF-Ug for qemu-devel@nongnu.org; Tue, 07 Jul 2015 04:40:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZCOQX-0002SL-Vs for qemu-devel@nongnu.org; Tue, 07 Jul 2015 04:40:30 -0400 Received: from [59.151.112.132] (port=62005 helo=heian.cn.fujitsu.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZCOQW-0001Wo-54; Tue, 07 Jul 2015 04:40:29 -0400 X-IronPort-AV: E=Sophos;i="5.13,665,1427731200"; d="scan'208";a="98163932" Received: from unknown (HELO edo.cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 07 Jul 2015 16:43:27 +0800 Received: from G08CNEXCHPEKD02.g08.fujitsu.local (localhost.localdomain [127.0.0.1]) by edo.cn.fujitsu.com (8.14.3/8.13.1) with ESMTP id t678bptQ010434; Tue, 7 Jul 2015 16:37:51 +0800 Received: from G08FNSTD140052.g08.fujitsu.local (10.167.226.52) by G08CNEXCHPEKD02.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.181.6; Tue, 7 Jul 2015 16:39:32 +0800 From: Wen Congyang To: qemu devel , Fam Zheng , Max Reitz , Paolo Bonzini , Stefan Hajnoczi Date: Tue, 7 Jul 2015 16:43:02 +0800 Message-ID: <1436258596-1253-5-git-send-email-wency@cn.fujitsu.com> X-Mailer: git-send-email 2.4.3 In-Reply-To: <1436258596-1253-1-git-send-email-wency@cn.fujitsu.com> References: <1436258596-1253-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 COLO-BLOCK v8 04/18] 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