#include "hw/sysbus.h"
#include "monitor/monitor.h"
#include "monitor/qdev.h"
-#include "qmp-commands.h"
#include "sysemu/arch_init.h"
+#include "qapi/error.h"
+#include "qapi/qapi-commands-misc.h"
+#include "qapi/qmp/qdict.h"
#include "qapi/qmp/qerror.h"
#include "qemu/config-file.h"
#include "qemu/error-report.h"
#include "qemu/help_option.h"
+#include "qemu/option.h"
#include "sysemu/block-backend.h"
+#include "migration/misc.h"
/*
* Aliases were a bad idea from the start. Let's keep them
static const QDevAlias qdev_alias_table[] = {
{ "e1000", "e1000-82540em" },
{ "ich9-ahci", "ahci" },
- { "kvm-pci-assign", "pci-assign" },
{ "lsi53c895a", "lsi" },
{ "virtio-9p-ccw", "virtio-9p", QEMU_ARCH_S390X },
{ "virtio-9p-pci", "virtio-9p", QEMU_ARCH_ALL & ~QEMU_ARCH_S390X },
if (dc->desc) {
error_printf(", desc \"%s\"", dc->desc);
}
- if (dc->cannot_instantiate_with_device_add_yet) {
+ if (!dc->user_creatable) {
error_printf(", no-user");
}
error_printf("\n");
}
-static gint devinfo_cmp(gconstpointer a, gconstpointer b)
-{
- return strcasecmp(object_class_get_name((ObjectClass *)a),
- object_class_get_name((ObjectClass *)b));
-}
-
static void qdev_print_devinfos(bool show_no_user)
{
static const char *cat_name[DEVICE_CATEGORY_MAX + 1] = {
[DEVICE_CATEGORY_DISPLAY] = "Display",
[DEVICE_CATEGORY_SOUND] = "Sound",
[DEVICE_CATEGORY_MISC] = "Misc",
+ [DEVICE_CATEGORY_CPU] = "CPU",
[DEVICE_CATEGORY_MAX] = "Uncategorized",
};
GSList *list, *elt;
int i;
bool cat_printed;
- list = g_slist_sort(object_class_get_list(TYPE_DEVICE, false),
- devinfo_cmp);
+ list = object_class_get_list_sorted(TYPE_DEVICE, false);
for (i = 0; i <= DEVICE_CATEGORY_MAX; i++) {
cat_printed = false;
? !test_bit(i, dc->categories)
: !bitmap_empty(dc->categories, DEVICE_CATEGORY_MAX))
|| (!show_no_user
- && dc->cannot_instantiate_with_device_add_yet)) {
+ && !dc->user_creatable)) {
continue;
}
if (!cat_printed) {
}
dc = DEVICE_CLASS(oc);
- if (dc->cannot_instantiate_with_device_add_yet ||
+ if (!dc->user_creatable ||
(qdev_hotplug && !dc->hotpluggable)) {
error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "driver",
"pluggable device type");
{
Error *local_err = NULL;
const char *driver;
- DevicePropertyInfoList *prop_list;
- DevicePropertyInfoList *prop;
+ ObjectPropertyInfoList *prop_list;
+ ObjectPropertyInfoList *prop;
driver = qemu_opt_get(opts, "driver");
if (driver && is_help_option(driver)) {
}
}
- qapi_free_DevicePropertyInfoList(prop_list);
+ qapi_free_ObjectPropertyInfoList(prop_list);
return 1;
error:
return bus;
}
+void qdev_set_id(DeviceState *dev, const char *id)
+{
+ if (id) {
+ dev->id = id;
+ }
+
+ if (dev->id) {
+ object_property_add_child(qdev_get_peripheral(), dev->id,
+ OBJECT(dev), NULL);
+ } else {
+ static int anon_count;
+ gchar *name = g_strdup_printf("device[%d]", anon_count++);
+ object_property_add_child(qdev_get_peripheral_anon(), name,
+ OBJECT(dev), NULL);
+ g_free(name);
+ }
+}
+
DeviceState *qdev_device_add(QemuOpts *opts, Error **errp)
{
DeviceClass *dc;
- const char *driver, *path, *id;
+ const char *driver, *path;
DeviceState *dev;
BusState *bus = NULL;
Error *err = NULL;
return NULL;
}
+ if (!migration_is_idle()) {
+ error_setg(errp, "device_add not allowed while migrating");
+ return NULL;
+ }
+
/* create device */
dev = DEVICE(object_new(driver));
if (bus) {
qdev_set_parent_bus(dev, bus);
+ } else if (qdev_hotplug && !qdev_get_machine_hotplug_handler(dev)) {
+ /* No bus, no machine hotplug handler --> device is not hotpluggable */
+ error_setg(&err, "Device '%s' can not be hotplugged on this machine",
+ driver);
+ goto err_del_dev;
}
- id = qemu_opts_id(opts);
- if (id) {
- dev->id = id;
- }
-
- if (dev->id) {
- object_property_add_child(qdev_get_peripheral(), dev->id,
- OBJECT(dev), NULL);
- } else {
- static int anon_count;
- gchar *name = g_strdup_printf("device[%d]", anon_count++);
- object_property_add_child(qdev_get_peripheral_anon(), name,
- OBJECT(dev), NULL);
- g_free(name);
- }
+ qdev_set_id(dev, qemu_opts_id(opts));
/* set properties */
if (qemu_opt_foreach(opts, set_property, dev, &err)) {
- error_propagate(errp, err);
- object_unparent(OBJECT(dev));
- object_unref(OBJECT(dev));
- return NULL;
+ goto err_del_dev;
}
dev->opts = opts;
object_property_set_bool(OBJECT(dev), true, "realized", &err);
if (err != NULL) {
- error_propagate(errp, err);
dev->opts = NULL;
- object_unparent(OBJECT(dev));
- object_unref(OBJECT(dev));
- return NULL;
+ goto err_del_dev;
}
return dev;
+
+err_del_dev:
+ error_propagate(errp, err);
+ object_unparent(OBJECT(dev));
+ object_unref(OBJECT(dev));
+ return NULL;
}
return DEVICE(obj);
}
+void qdev_unplug(DeviceState *dev, Error **errp)
+{
+ DeviceClass *dc = DEVICE_GET_CLASS(dev);
+ HotplugHandler *hotplug_ctrl;
+ HotplugHandlerClass *hdc;
+
+ if (dev->parent_bus && !qbus_is_hotpluggable(dev->parent_bus)) {
+ error_setg(errp, QERR_BUS_NO_HOTPLUG, dev->parent_bus->name);
+ return;
+ }
+
+ if (!dc->hotpluggable) {
+ error_setg(errp, QERR_DEVICE_NO_HOTPLUG,
+ object_get_typename(OBJECT(dev)));
+ return;
+ }
+
+ if (!migration_is_idle()) {
+ error_setg(errp, "device_del not allowed while migrating");
+ return;
+ }
+
+ qdev_hot_removed = true;
+
+ hotplug_ctrl = qdev_get_hotplug_handler(dev);
+ /* hotpluggable device MUST have HotplugHandler, if it doesn't
+ * then something is very wrong with it */
+ g_assert(hotplug_ctrl);
+
+ /* If device supports async unplug just request it to be done,
+ * otherwise just remove it synchronously */
+ hdc = HOTPLUG_HANDLER_GET_CLASS(hotplug_ctrl);
+ if (hdc->unplug_request) {
+ hotplug_handler_unplug_request(hotplug_ctrl, dev, errp);
+ } else {
+ hotplug_handler_unplug(hotplug_ctrl, dev, errp);
+ }
+}
+
void qmp_device_del(const char *id, Error **errp)
{
DeviceState *dev = find_device_state(id, errp);