qemu with hax to log dma reads & writes jcs.org/2018/11/12/vfio

qom: Avoid unvisited 'id'/'qom-type' in user_creatable_add_opts

A regression in commit 15c2f669e caused us to silently ignore
excess input to the QemuOpts visitor. Later, commit ea4641
accidentally abused that situation, by removing "qom-type" and
"id" from the corresponding QDict but leaving them defined in
the QemuOpts, when using the pair of containers to create a
user-defined object. Note that since we are already traversing
two separate items (a QDict and a QemuOpts), we are already
able to flag bogus arguments, as in:

$ ./x86_64-softmmu/qemu-system-x86_64 -nodefaults -nographic -qmp stdio -object memory-backend-ram,id=mem1,size=4k,bogus=huh
qemu-system-x86_64: -object memory-backend-ram,id=mem1,size=4k,bogus=huh: Property '.bogus' not found

So the only real concern is that when we re-enable strict checking
in the QemuOpts visitor, we do not want to start flagging the two
leftover keys as unvisited. Rearrange the code to clean out the
QemuOpts listing in advance, rather than removing items from the
QDict. Since "qom-type" is usually an automatic implicit default,
we don't have to restore it (this does mean that once instantiated,
QemuOpts is not necessarily an accurate representation of the
original command line - but this is not the first place to do that);
however "id" has to be put back (requiring us to cast away a const).

[As a side note, hmp_object_add() turns a QDict into a QemuOpts,
then calls user_creatable_add_opts() which converts QemuOpts into
a new QDict. There are probably a lot of wasteful conversions like
this, but cleaning them up is a much bigger task than the immediate
regression fix.]

CC: qemu-stable@nongnu.org
Signed-off-by: Eric Blake <eblake@redhat.com>
Message-Id: <20170322144525.18964-3-eblake@redhat.com>
Tested-by: Laurent Vivier <lvivier@redhat.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>

authored by

Eric Blake and committed by
Markus Armbruster
9a6d1acb 76861f6b

+5 -3
+5 -3
qom/object_interfaces.c
··· 114 114 QDict *pdict; 115 115 Object *obj; 116 116 const char *id = qemu_opts_id(opts); 117 - const char *type = qemu_opt_get(opts, "qom-type"); 117 + char *type = qemu_opt_get_del(opts, "qom-type"); 118 118 119 119 if (!type) { 120 120 error_setg(errp, QERR_MISSING_PARAMETER, "qom-type"); ··· 122 122 } 123 123 if (!id) { 124 124 error_setg(errp, QERR_MISSING_PARAMETER, "id"); 125 + g_free(type); 125 126 return NULL; 126 127 } 127 128 129 + qemu_opts_set_id(opts, NULL); 128 130 pdict = qemu_opts_to_qdict(opts, NULL); 129 - qdict_del(pdict, "qom-type"); 130 - qdict_del(pdict, "id"); 131 131 132 132 v = opts_visitor_new(opts); 133 133 obj = user_creatable_add_type(type, id, pdict, v, errp); 134 134 visit_free(v); 135 135 136 + qemu_opts_set_id(opts, (char *) id); 137 + g_free(type); 136 138 QDECREF(pdict); 137 139 return obj; 138 140 }