qdev: Base object creation on QDict rather than QemuOpts

QDicts are both what QMP natively uses and what the keyval parser
produces. Going through QemuOpts isn't useful for either one, so switch
the main device creation function to QDicts. By sharing more code with
the -object/object-add code path, we can even reduce the code size a
bit.

This commit doesn't remove the detour through QemuOpts from any code
path yet, but it allows the following commits to do so.

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Message-Id: <20211008133442.141332-15-kwolf@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Tested-by: Peter Krempa <pkrempa@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
This commit is contained in:
Kevin Wolf 2021-10-08 15:34:41 +02:00
parent 12b2fad7dc
commit f3558b1b76
7 changed files with 61 additions and 59 deletions

View file

@ -28,6 +28,7 @@
#include "qemu/osdep.h"
#include "qapi/error.h"
#include "qapi/qapi-events-qdev.h"
#include "qapi/qmp/qdict.h"
#include "qapi/qmp/qerror.h"
#include "qapi/visitor.h"
#include "qemu/error-report.h"
@ -211,14 +212,14 @@ void device_listener_unregister(DeviceListener *listener)
QTAILQ_REMOVE(&device_listeners, listener, link);
}
bool qdev_should_hide_device(QemuOpts *opts, Error **errp)
bool qdev_should_hide_device(const QDict *opts, bool from_json, Error **errp)
{
ERRP_GUARD();
DeviceListener *listener;
QTAILQ_FOREACH(listener, &device_listeners, link) {
if (listener->hide_device) {
if (listener->hide_device(listener, opts, errp)) {
if (listener->hide_device(listener, opts, from_json, errp)) {
return true;
} else if (*errp) {
return false;
@ -958,7 +959,7 @@ static void device_finalize(Object *obj)
dev->canonical_path = NULL;
}
qemu_opts_del(dev->opts);
qobject_unref(dev->opts);
g_free(dev->id);
}