From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56117) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z5VSU-00050A-Kj for qemu-devel@nongnu.org; Thu, 18 Jun 2015 04:46:03 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Z5VSS-0004HP-9T for qemu-devel@nongnu.org; Thu, 18 Jun 2015 04:46:02 -0400 From: Wen Congyang Date: Thu, 18 Jun 2015 16:49:19 +0800 Message-ID: <1434617361-17778-15-git-send-email-wency@cn.fujitsu.com> In-Reply-To: <1434617361-17778-1-git-send-email-wency@cn.fujitsu.com> References: <1434617361-17778-1-git-send-email-wency@cn.fujitsu.com> MIME-Version: 1.0 Content-Type: text/plain Subject: [Qemu-devel] [PATCH COLO-Block v6 14/16] introduce a new API qemu_opts_absorb_qdict_by_index() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu devel , Fam Zheng , Max Reitz , Paolo Bonzini Cc: Kevin Wolf , qemu block , Lai Jiangshan , Jiang Yunhong , Dong Eddie , "Dr. David Alan Gilbert" , Gonglei , Stefan Hajnoczi , Yang Hongyang , zhanghailiang 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 ac0e43b..f868893 100644 --- a/include/qemu/option.h +++ b/include/qemu/option.h @@ -126,6 +126,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 840f5f7..0c8e898 100644 --- a/util/qemu-option.c +++ b/util/qemu-option.c @@ -1006,6 +1006,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 -- 2.4.3