]> git.proxmox.com Git - mirror_qemu.git/commit - tests/check-block-qdict.c
block: Fix -blockdev / blockdev-add for empty objects and arrays
authorMarkus Armbruster <armbru@redhat.com>
Thu, 14 Jun 2018 19:14:41 +0000 (21:14 +0200)
committerKevin Wolf <kwolf@redhat.com>
Fri, 15 Jun 2018 12:49:44 +0000 (14:49 +0200)
commit2860b2b2cb883969c8f6464bd9f8bc88742c5c73
tree02c5e733d23f7724eca138267e4a3b8ad51a529a
parentbef96b1549907b005ce1fa1456d2a0910d2a1aa5
block: Fix -blockdev / blockdev-add for empty objects and arrays

-blockdev and blockdev-add silently ignore empty objects and arrays in
their argument.  That's because qmp_blockdev_add() converts the
argument to a flat QDict, and qdict_flatten() eats empty QDict and
QList members.  For instance, we ignore an empty BlockdevOptions
member @cache.  No real harm, as absent means the same as empty there.

Thus, the flaw puts an artificial restriction on the QAPI schema: we
can't have potentially empty objects and arrays within
BlockdevOptions, except when they're optional and "empty" has the same
meaning as "absent".

Our QAPI schema satisfies this restriction (I checked), but it's a
trap for the unwary, and a temptation to employ awkward workarounds
for the wary.  Let's get rid of it.

Change qdict_flatten() and qdict_crumple() to treat empty dictionaries
and lists exactly like scalars.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
qobject/block-qdict.c
tests/check-block-qdict.c