From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54062) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VOnIO-0002ss-8N for qemu-devel@nongnu.org; Wed, 25 Sep 2013 07:30:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VOnIJ-0004o9-3l for qemu-devel@nongnu.org; Wed, 25 Sep 2013 07:30:16 -0400 Received: from nodalink.pck.nerim.net ([62.212.105.220]:38900 helo=paradis.irqsave.net) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VOnII-0004ns-P7 for qemu-devel@nongnu.org; Wed, 25 Sep 2013 07:30:11 -0400 From: =?UTF-8?q?Beno=C3=AEt=20Canet?= Date: Wed, 25 Sep 2013 13:30:01 +0200 Message-Id: <1380108601-5428-1-git-send-email-benoit@irqsave.net> Subject: [Qemu-devel] [PATCH] qdict: Extract qdict_extract_subqdict. List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: kwolf@redhat.com, =?UTF-8?q?Beno=C3=AEt=20Canet?= , stefanha@redhat.com Signed-off-by: Benoit Canet --- block.c | 23 ++--------------------- include/qapi/qmp/qdict.h | 2 ++ qobject/qdict.c | 21 +++++++++++++++++++++ 3 files changed, 25 insertions(+), 21 deletions(-) diff --git a/block.c b/block.c index 2778f28..989f908 100644 --- a/block.c +++ b/block.c @@ -963,25 +963,6 @@ int bdrv_open_backing_file(BlockDriverState *bs, QDict *options) return 0; } -static void extract_subqdict(QDict *src, QDict **dst, const char *start) -{ - const QDictEntry *entry, *next; - const char *p; - - *dst = qdict_new(); - entry = qdict_first(src); - - while (entry != NULL) { - next = qdict_next(src, entry); - if (strstart(entry->key, start, &p)) { - qobject_incref(entry->value); - qdict_put_obj(*dst, p, entry->value); - qdict_del(src, entry->key); - } - entry = next; - } -} - /* * Opens a disk image (raw, qcow2, vmdk, ...) * @@ -1079,7 +1060,7 @@ int bdrv_open(BlockDriverState *bs, const char *filename, QDict *options, flags |= BDRV_O_ALLOW_RDWR; } - extract_subqdict(options, &file_options, "file."); + qdict_extract_subqdict(options, &file_options, "file."); ret = bdrv_file_open(&file, filename, file_options, bdrv_open_flags(bs, flags | BDRV_O_UNMAP)); @@ -1117,7 +1098,7 @@ int bdrv_open(BlockDriverState *bs, const char *filename, QDict *options, if ((flags & BDRV_O_NO_BACKING) == 0) { QDict *backing_options; - extract_subqdict(options, &backing_options, "backing."); + qdict_extract_subqdict(options, &backing_options, "backing."); ret = bdrv_open_backing_file(bs, backing_options); if (ret < 0) { goto close_and_fail; diff --git a/include/qapi/qmp/qdict.h b/include/qapi/qmp/qdict.h index d6855d1..5cefd80 100644 --- a/include/qapi/qmp/qdict.h +++ b/include/qapi/qmp/qdict.h @@ -67,4 +67,6 @@ const char *qdict_get_try_str(const QDict *qdict, const char *key); QDict *qdict_clone_shallow(const QDict *src); void qdict_flatten(QDict *qdict); +void qdict_extract_subqdict(QDict *src, QDict **dst, const char *start); + #endif /* QDICT_H */ diff --git a/qobject/qdict.c b/qobject/qdict.c index 472f106..0f3e0a6 100644 --- a/qobject/qdict.c +++ b/qobject/qdict.c @@ -527,3 +527,24 @@ void qdict_flatten(QDict *qdict) { qdict_do_flatten(qdict, qdict, NULL); } + +/* extract all the src QDict entries starting by start into dst */ +void qdict_extract_subqdict(QDict *src, QDict **dst, const char *start) + +{ + const QDictEntry *entry, *next; + const char *p; + + *dst = qdict_new(); + entry = qdict_first(src); + + while (entry != NULL) { + next = qdict_next(src, entry); + if (strstart(entry->key, start, &p)) { + qobject_incref(entry->value); + qdict_put_obj(*dst, p, entry->value); + qdict_del(src, entry->key); + } + entry = next; + } +} -- 1.8.1.2