QOM infrastructure fixes and device conversions
* Fixes for -device foo,help -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.22 (GNU/Linux) iQIcBAABAgAGBQJUWQyNAAoJEPou0S0+fgE/0WUQALOxYaPH1GoXepXj0nwcnH9/ Faz00Kk0MbxT0kt7iE5QQtMHFjEEZ3PewKljTGEanfFtFl2xxenVJO6k0uk5JScw C4KVzAYUE5tvJQ7YjjMllNxN5FZnGz4vukmGePmtAPFtgtDJbGmzxevzg38M0c6K pyWdtj8/V+mCeW+EaQQlnW346TJk+eePF2V9qDvZ5L13MeYB9xPhmUZUSe0yscbP 3b25nGMOsfM8efj5fErPVn/eLiUSMlNcd57L5yB3lkwWYnfwqGs3Yc1oc10iZVMo qGHJdFhWhliQD1SpJf6Ee4EM9CTbUETCHoegzCNJqf2Adnl3Mu3vNyXuZ9wpYnaU z1udbMOAxOK6H9LGZrlPyXEcYqr9fl89fEbvxl/A6WvYy5Bgor4dnoqVLbD8AbjX iolaxZP/qknmt6OUSQD649up6v5F1RiuHXjodYtOIDgf2t6FmA46yZaby0Ue4gG1 T9lwRCLpu9K8q9q0WQ7JlRNhIpMYYSsQyOyWO1T97cEJYdzWJOjqDsntNBlpAnNB dVCb1y+8uvy6ZG1HwS12JCbyQkCqIHaRUkp64rE3v6Uh05CkUELfLLpLBPNvCXLK PxNvRg4G1jhQO1cWDF0L/w3QwonCo2kmuH6NGrW1bvxqu7FVRqV/vgy8pFFjkkHE ekqGJ4uIG6QnzoOhnE5g =CIXW -----END PGP SIGNATURE----- Merge remote-tracking branch 'remotes/afaerber/tags/qom-devices-for-peter' into staging QOM infrastructure fixes and device conversions * Fixes for -device foo,help # gpg: Signature made Tue 04 Nov 2014 17:27:41 GMT using RSA key ID 3E7E013F # gpg: Good signature from "Andreas Färber <afaerber@suse.de>" # gpg: aka "Andreas Färber <afaerber@suse.com>" * remotes/afaerber/tags/qom-devices-for-peter: qdev: Use qdev_get_device_class() for -device <type>,help qdev: Move error printing to the end of qdev_device_help() qdev: Create qdev_get_device_class() function Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
This commit is contained in:
commit
d5b4dc3b50
@ -180,6 +180,44 @@ static const char *find_typename_by_alias(const char *alias)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static DeviceClass *qdev_get_device_class(const char **driver, Error **errp)
|
||||
{
|
||||
ObjectClass *oc;
|
||||
DeviceClass *dc;
|
||||
|
||||
oc = object_class_by_name(*driver);
|
||||
if (!oc) {
|
||||
const char *typename = find_typename_by_alias(*driver);
|
||||
|
||||
if (typename) {
|
||||
*driver = typename;
|
||||
oc = object_class_by_name(*driver);
|
||||
}
|
||||
}
|
||||
|
||||
if (!object_class_dynamic_cast(oc, TYPE_DEVICE)) {
|
||||
error_setg(errp, "'%s' is not a valid device model name", *driver);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (object_class_is_abstract(oc)) {
|
||||
error_set(errp, QERR_INVALID_PARAMETER_VALUE, "driver",
|
||||
"non-abstract device type");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
dc = DEVICE_CLASS(oc);
|
||||
if (dc->cannot_instantiate_with_device_add_yet ||
|
||||
(qdev_hotplug && !dc->hotpluggable)) {
|
||||
error_set(errp, QERR_INVALID_PARAMETER_VALUE, "driver",
|
||||
"pluggable device type");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return dc;
|
||||
}
|
||||
|
||||
|
||||
int qdev_device_help(QemuOpts *opts)
|
||||
{
|
||||
Error *local_err = NULL;
|
||||
@ -197,19 +235,14 @@ int qdev_device_help(QemuOpts *opts)
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!object_class_by_name(driver)) {
|
||||
const char *typename = find_typename_by_alias(driver);
|
||||
|
||||
if (typename) {
|
||||
driver = typename;
|
||||
}
|
||||
qdev_get_device_class(&driver, &local_err);
|
||||
if (local_err) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
prop_list = qmp_device_list_properties(driver, &local_err);
|
||||
if (local_err) {
|
||||
error_printf("%s\n", error_get_pretty(local_err));
|
||||
error_free(local_err);
|
||||
return 1;
|
||||
goto error;
|
||||
}
|
||||
|
||||
for (prop = prop_list; prop; prop = prop->next) {
|
||||
@ -225,6 +258,11 @@ int qdev_device_help(QemuOpts *opts)
|
||||
|
||||
qapi_free_DevicePropertyInfoList(prop_list);
|
||||
return 1;
|
||||
|
||||
error:
|
||||
error_printf("%s\n", error_get_pretty(local_err));
|
||||
error_free(local_err);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static Object *qdev_get_peripheral(void)
|
||||
@ -455,7 +493,6 @@ static BusState *qbus_find(const char *path)
|
||||
|
||||
DeviceState *qdev_device_add(QemuOpts *opts)
|
||||
{
|
||||
ObjectClass *oc;
|
||||
DeviceClass *dc;
|
||||
const char *driver, *path, *id;
|
||||
DeviceState *dev;
|
||||
@ -469,33 +506,10 @@ DeviceState *qdev_device_add(QemuOpts *opts)
|
||||
}
|
||||
|
||||
/* find driver */
|
||||
oc = object_class_by_name(driver);
|
||||
if (!oc) {
|
||||
const char *typename = find_typename_by_alias(driver);
|
||||
|
||||
if (typename) {
|
||||
driver = typename;
|
||||
oc = object_class_by_name(driver);
|
||||
}
|
||||
}
|
||||
|
||||
if (!object_class_dynamic_cast(oc, TYPE_DEVICE)) {
|
||||
qerror_report(ERROR_CLASS_GENERIC_ERROR,
|
||||
"'%s' is not a valid device model name", driver);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (object_class_is_abstract(oc)) {
|
||||
qerror_report(QERR_INVALID_PARAMETER_VALUE, "driver",
|
||||
"non-abstract device type");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
dc = DEVICE_CLASS(oc);
|
||||
if (dc->cannot_instantiate_with_device_add_yet ||
|
||||
(qdev_hotplug && !dc->hotpluggable)) {
|
||||
qerror_report(QERR_INVALID_PARAMETER_VALUE, "driver",
|
||||
"pluggable device type");
|
||||
dc = qdev_get_device_class(&driver, &err);
|
||||
if (err) {
|
||||
qerror_report_err(err);
|
||||
error_free(err);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user