2016-01-29 18:50:02 +01:00
|
|
|
#include "qemu/osdep.h"
|
2019-10-11 19:20:12 +02:00
|
|
|
|
|
|
|
#include "qemu/cutils.h"
|
include/qemu/osdep.h: Don't include qapi/error.h
Commit 57cb38b included qapi/error.h into qemu/osdep.h to get the
Error typedef. Since then, we've moved to include qemu/osdep.h
everywhere. Its file comment explains: "To avoid getting into
possible circular include dependencies, this file should not include
any other QEMU headers, with the exceptions of config-host.h,
compiler.h, os-posix.h and os-win32.h, all of which are doing a
similar job to this file and are under similar constraints."
qapi/error.h doesn't do a similar job, and it doesn't adhere to
similar constraints: it includes qapi-types.h. That's in excess of
100KiB of crap most .c files don't actually need.
Add the typedef to qemu/typedefs.h, and include that instead of
qapi/error.h. Include qapi/error.h in .c files that need it and don't
get it now. Include qapi-types.h in qom/object.h for uint16List.
Update scripts/clean-includes accordingly. Update it further to match
reality: replace config.h by config-target.h, add sysemu/os-posix.h,
sysemu/os-win32.h. Update the list of includes in the qemu/osdep.h
comment quoted above similarly.
This reduces the number of objects depending on qapi/error.h from "all
of them" to less than a third. Unfortunately, the number depending on
qapi-types.h shrinks only a little. More work is needed for that one.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
[Fix compilation without the spice devel packages. - Paolo]
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2016-03-14 09:01:28 +01:00
|
|
|
#include "qapi/error.h"
|
2021-02-17 12:06:20 +01:00
|
|
|
#include "qapi/qapi-visit-qom.h"
|
2022-12-19 14:31:00 +01:00
|
|
|
#include "qapi/qmp/qobject.h"
|
2018-02-01 12:18:39 +01:00
|
|
|
#include "qapi/qmp/qdict.h"
|
2018-02-11 10:35:39 +01:00
|
|
|
#include "qapi/qmp/qerror.h"
|
2020-01-10 16:30:37 +01:00
|
|
|
#include "qapi/qmp/qjson.h"
|
2020-04-16 17:04:20 +02:00
|
|
|
#include "qapi/qobject-input-visitor.h"
|
2021-02-17 12:06:20 +01:00
|
|
|
#include "qapi/qobject-output-visitor.h"
|
2014-01-16 17:34:38 +01:00
|
|
|
#include "qom/object_interfaces.h"
|
2019-10-11 19:20:12 +02:00
|
|
|
#include "qemu/help_option.h"
|
2021-03-02 18:16:23 +01:00
|
|
|
#include "qemu/id.h"
|
2014-01-16 17:34:38 +01:00
|
|
|
#include "qemu/module.h"
|
2018-02-01 12:18:46 +01:00
|
|
|
#include "qemu/option.h"
|
2021-02-17 15:27:54 +01:00
|
|
|
#include "qemu/qemu-print.h"
|
2016-02-10 19:40:59 +01:00
|
|
|
#include "qapi/opts-visitor.h"
|
monitor: fix object_del for command-line-created objects
Currently objects specified on the command-line are only partially
cleaned up when 'object_del' is issued in either HMP or QMP: the
object itself is fully finalized, but the QemuOpts are not removed.
This results in the following behavior:
x86_64-softmmu/qemu-system-x86_64 -monitor stdio \
-object memory-backend-ram,id=ram1,size=256M
QEMU 2.7.91 monitor - type 'help' for more information
(qemu) object_del ram1
(qemu) object_del ram1
object 'ram1' not found
(qemu) object_add memory-backend-ram,id=ram1,size=256M
Duplicate ID 'ram1' for object
Try "help object_add" for more information
which can be an issue for use-cases like memory hotplug.
This happens on the HMP side because hmp_object_add() attempts to
create a temporary QemuOpts entry with ID 'ram1', which ends up
conflicting with the command-line-created entry, since it was never
cleaned up during the previous hmp_object_del() call.
We address this by adding a check in user_creatable_del(), which
is called by both qmp_object_del() and hmp_object_del() to handle
the actual object cleanup, to determine whether an option group entry
matching the object's ID is present and removing it if it is.
Note that qmp_object_add() never attempts to create a temporary
QemuOpts entry, so it does not encounter the duplicate ID error,
which is why this isn't generally visible in libvirt.
Cc: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
Cc: Markus Armbruster <armbru@redhat.com>
Cc: Eric Blake <eblake@redhat.com>
Cc: Daniel Berrange <berrange@redhat.com>
Cc: qemu-stable@nongnu.org
Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
Reviewed-by: Daniel P. Berrange <berrange@redhat.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Message-Id: <1496531612-22166-3-git-send-email-mdroth@linux.vnet.ibm.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2017-06-04 01:13:32 +02:00
|
|
|
#include "qemu/config-file.h"
|
2022-04-20 15:26:06 +02:00
|
|
|
#include "qemu/keyval.h"
|
2014-01-16 17:34:38 +01:00
|
|
|
|
2020-07-07 18:05:55 +02:00
|
|
|
bool user_creatable_complete(UserCreatable *uc, Error **errp)
|
2014-01-16 17:34:38 +01:00
|
|
|
{
|
2018-12-04 15:20:07 +01:00
|
|
|
UserCreatableClass *ucc = USER_CREATABLE_GET_CLASS(uc);
|
2020-07-07 18:05:55 +02:00
|
|
|
Error *err = NULL;
|
2014-01-16 17:34:38 +01:00
|
|
|
|
|
|
|
if (ucc->complete) {
|
2020-07-07 18:05:55 +02:00
|
|
|
ucc->complete(uc, &err);
|
|
|
|
error_propagate(errp, err);
|
2014-01-16 17:34:38 +01:00
|
|
|
}
|
2020-07-07 18:05:55 +02:00
|
|
|
return !err;
|
2014-01-16 17:34:38 +01:00
|
|
|
}
|
|
|
|
|
2017-08-30 00:03:37 +02:00
|
|
|
bool user_creatable_can_be_deleted(UserCreatable *uc)
|
2015-03-30 10:36:28 +02:00
|
|
|
{
|
|
|
|
|
|
|
|
UserCreatableClass *ucc = USER_CREATABLE_GET_CLASS(uc);
|
|
|
|
|
|
|
|
if (ucc->can_be_deleted) {
|
2017-08-30 00:03:37 +02:00
|
|
|
return ucc->can_be_deleted(uc);
|
2015-03-30 10:36:28 +02:00
|
|
|
} else {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-02 17:08:07 +01:00
|
|
|
static void object_set_properties_from_qdict(Object *obj, const QDict *qdict,
|
|
|
|
Visitor *v, Error **errp)
|
|
|
|
{
|
|
|
|
const QDictEntry *e;
|
|
|
|
|
2021-10-08 15:34:31 +02:00
|
|
|
if (!visit_start_struct(v, NULL, NULL, 0, errp)) {
|
|
|
|
return;
|
2020-11-02 17:08:07 +01:00
|
|
|
}
|
|
|
|
for (e = qdict_first(qdict); e; e = qdict_next(qdict, e)) {
|
2021-10-08 15:34:31 +02:00
|
|
|
if (!object_property_set(obj, e->key, v, errp)) {
|
|
|
|
goto out;
|
2020-11-02 17:08:07 +01:00
|
|
|
}
|
|
|
|
}
|
2021-10-08 15:34:31 +02:00
|
|
|
visit_check_struct(v, errp);
|
2020-11-02 17:08:07 +01:00
|
|
|
out:
|
2021-10-08 15:34:31 +02:00
|
|
|
visit_end_struct(v, NULL);
|
2020-11-02 17:08:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void object_set_properties_from_keyval(Object *obj, const QDict *qdict,
|
|
|
|
bool from_json, Error **errp)
|
|
|
|
{
|
|
|
|
Visitor *v;
|
|
|
|
if (from_json) {
|
|
|
|
v = qobject_input_visitor_new(QOBJECT(qdict));
|
|
|
|
} else {
|
|
|
|
v = qobject_input_visitor_new_keyval(QOBJECT(qdict));
|
|
|
|
}
|
|
|
|
object_set_properties_from_qdict(obj, qdict, v, errp);
|
|
|
|
visit_free(v);
|
|
|
|
}
|
|
|
|
|
2016-02-10 19:40:59 +01:00
|
|
|
Object *user_creatable_add_type(const char *type, const char *id,
|
|
|
|
const QDict *qdict,
|
|
|
|
Visitor *v, Error **errp)
|
|
|
|
{
|
2021-03-02 18:16:23 +01:00
|
|
|
ERRP_GUARD();
|
2016-02-10 19:40:59 +01:00
|
|
|
Object *obj;
|
|
|
|
ObjectClass *klass;
|
|
|
|
Error *local_err = NULL;
|
|
|
|
|
2021-03-02 18:16:23 +01:00
|
|
|
if (id != NULL && !id_wellformed(id)) {
|
|
|
|
error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "id", "an identifier");
|
|
|
|
error_append_hint(errp, "Identifiers consist of letters, digits, "
|
|
|
|
"'-', '.', '_', starting with a letter.\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2016-02-10 19:40:59 +01:00
|
|
|
klass = object_class_by_name(type);
|
|
|
|
if (!klass) {
|
|
|
|
error_setg(errp, "invalid object type: %s", type);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!object_class_dynamic_cast(klass, TYPE_USER_CREATABLE)) {
|
|
|
|
error_setg(errp, "object type '%s' isn't supported by object-add",
|
|
|
|
type);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (object_class_is_abstract(klass)) {
|
|
|
|
error_setg(errp, "object type '%s' is abstract", type);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
qom: Wrap prop visit in visit_start_struct
The qmp-input visitor was allowing callers to play rather fast
and loose: when visiting a QDict, you could grab members of the
root dictionary without first pushing into the dict; the final
such culprit was the QOM code for converting to and from object
properties. But we are about to tighten the input visitor, at
which point user_creatable_add_type() as called with a QMP input
visitor via qmp_object_add() MUST follow the same paradigms as
everyone else, of pushing into the struct before grabbing its
keys.
The use of 'err ? NULL : &err' is temporary; a later patch will
clean that up when it splits visit_end_struct().
Furthermore, note that both callers always pass qdict, so we can
convert the conditional into an assert and reduce indentation.
The change has no impact to the testsuite now, but is required to
avoid a failure in tests/test-netfilter once qmp-input is made
stricter to detect inconsistent 'name' arguments on the root visit.
Since user_creatable_add_type() is also called with OptsVisitor
through user_creatable_add_opts(), we must also check that there
is no negative impact there; both pre- and post-patch, we see:
$ ./x86_64-softmmu/qemu-system-x86_64 -nographic -nodefaults -qmp stdio -object secret,id=sec0,data=letmein,format=raw,foo=bar
qemu-system-x86_64: -object secret,id=sec0,data=letmein,format=raw,foo=bar: Property '.foo' not found
That is, the only new checking that the new visit_end_struct() can
perform is for excess input, but we already catch excess input
earlier in object_property_set().
Signed-off-by: Eric Blake <eblake@redhat.com>
Message-Id: <1461879932-9020-10-git-send-email-eblake@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2016-04-28 23:45:17 +02:00
|
|
|
assert(qdict);
|
2016-02-10 19:40:59 +01:00
|
|
|
obj = object_new(type);
|
2020-11-02 17:08:07 +01:00
|
|
|
object_set_properties_from_qdict(obj, qdict, v, &local_err);
|
qom: Wrap prop visit in visit_start_struct
The qmp-input visitor was allowing callers to play rather fast
and loose: when visiting a QDict, you could grab members of the
root dictionary without first pushing into the dict; the final
such culprit was the QOM code for converting to and from object
properties. But we are about to tighten the input visitor, at
which point user_creatable_add_type() as called with a QMP input
visitor via qmp_object_add() MUST follow the same paradigms as
everyone else, of pushing into the struct before grabbing its
keys.
The use of 'err ? NULL : &err' is temporary; a later patch will
clean that up when it splits visit_end_struct().
Furthermore, note that both callers always pass qdict, so we can
convert the conditional into an assert and reduce indentation.
The change has no impact to the testsuite now, but is required to
avoid a failure in tests/test-netfilter once qmp-input is made
stricter to detect inconsistent 'name' arguments on the root visit.
Since user_creatable_add_type() is also called with OptsVisitor
through user_creatable_add_opts(), we must also check that there
is no negative impact there; both pre- and post-patch, we see:
$ ./x86_64-softmmu/qemu-system-x86_64 -nographic -nodefaults -qmp stdio -object secret,id=sec0,data=letmein,format=raw,foo=bar
qemu-system-x86_64: -object secret,id=sec0,data=letmein,format=raw,foo=bar: Property '.foo' not found
That is, the only new checking that the new visit_end_struct() can
perform is for excess input, but we already catch excess input
earlier in object_property_set().
Signed-off-by: Eric Blake <eblake@redhat.com>
Message-Id: <1461879932-9020-10-git-send-email-eblake@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2016-04-28 23:45:17 +02:00
|
|
|
if (local_err) {
|
|
|
|
goto out;
|
|
|
|
}
|
2016-02-10 19:40:59 +01:00
|
|
|
|
2018-06-15 17:39:35 +02:00
|
|
|
if (id != NULL) {
|
2020-06-29 21:34:22 +02:00
|
|
|
object_property_try_add_child(object_get_objects_root(),
|
|
|
|
id, obj, &local_err);
|
|
|
|
if (local_err) {
|
|
|
|
goto out;
|
|
|
|
}
|
2016-02-10 19:40:59 +01:00
|
|
|
}
|
|
|
|
|
qom: Use returned bool to check for failure, Coccinelle part
The previous commit enables conversion of
foo(..., &err);
if (err) {
...
}
to
if (!foo(..., errp)) {
...
}
for QOM functions that now return true / false on success / error.
Coccinelle script:
@@
identifier fun = {
object_apply_global_props, object_initialize_child_with_props,
object_initialize_child_with_propsv, object_property_get,
object_property_get_bool, object_property_parse, object_property_set,
object_property_set_bool, object_property_set_int,
object_property_set_link, object_property_set_qobject,
object_property_set_str, object_property_set_uint, object_set_props,
object_set_propv, user_creatable_add_dict,
user_creatable_complete, user_creatable_del
};
expression list args, args2;
typedef Error;
Error *err;
@@
- fun(args, &err, args2);
- if (err)
+ if (!fun(args, &err, args2))
{
...
}
Fails to convert hw/arm/armsse.c, because Coccinelle gets confused by
ARMSSE being used both as typedef and function-like macro there.
Convert manually.
Line breaks tidied up manually.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Message-Id: <20200707160613.848843-29-armbru@redhat.com>
2020-07-07 18:05:56 +02:00
|
|
|
if (!user_creatable_complete(USER_CREATABLE(obj), &local_err)) {
|
2018-06-15 17:39:35 +02:00
|
|
|
if (id != NULL) {
|
2020-05-05 17:29:26 +02:00
|
|
|
object_property_del(object_get_objects_root(), id);
|
2018-06-15 17:39:35 +02:00
|
|
|
}
|
2016-02-10 19:40:59 +01:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
out:
|
|
|
|
if (local_err) {
|
|
|
|
error_propagate(errp, local_err);
|
|
|
|
object_unref(obj);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
2021-02-17 12:06:20 +01:00
|
|
|
void user_creatable_add_qapi(ObjectOptions *options, Error **errp)
|
|
|
|
{
|
|
|
|
Visitor *v;
|
|
|
|
QObject *qobj;
|
|
|
|
QDict *props;
|
|
|
|
Object *obj;
|
|
|
|
|
|
|
|
v = qobject_output_visitor_new(&qobj);
|
|
|
|
visit_type_ObjectOptions(v, NULL, &options, &error_abort);
|
|
|
|
visit_complete(v, &qobj);
|
|
|
|
visit_free(v);
|
|
|
|
|
|
|
|
props = qobject_to(QDict, qobj);
|
|
|
|
qdict_del(props, "qom-type");
|
|
|
|
qdict_del(props, "id");
|
|
|
|
|
|
|
|
v = qobject_input_visitor_new(QOBJECT(props));
|
|
|
|
obj = user_creatable_add_type(ObjectType_str(options->qom_type),
|
|
|
|
options->id, props, v, errp);
|
|
|
|
object_unref(obj);
|
|
|
|
qobject_unref(qobj);
|
|
|
|
visit_free(v);
|
|
|
|
}
|
|
|
|
|
2020-01-10 16:30:37 +01:00
|
|
|
char *object_property_help(const char *name, const char *type,
|
|
|
|
QObject *defval, const char *description)
|
|
|
|
{
|
|
|
|
GString *str = g_string_new(NULL);
|
|
|
|
|
|
|
|
g_string_append_printf(str, " %s=<%s>", name, type);
|
|
|
|
if (description || defval) {
|
|
|
|
if (str->len < 24) {
|
|
|
|
g_string_append_printf(str, "%*s", 24 - (int)str->len, "");
|
|
|
|
}
|
|
|
|
g_string_append(str, " - ");
|
|
|
|
}
|
|
|
|
if (description) {
|
|
|
|
g_string_append(str, description);
|
|
|
|
}
|
|
|
|
if (defval) {
|
2020-12-11 18:11:37 +01:00
|
|
|
g_autofree char *def_json = g_string_free(qobject_to_json(defval),
|
2021-03-24 09:41:30 +01:00
|
|
|
false);
|
2020-01-10 16:30:37 +01:00
|
|
|
g_string_append_printf(str, " (default: %s)", def_json);
|
|
|
|
}
|
|
|
|
|
|
|
|
return g_string_free(str, false);
|
|
|
|
}
|
|
|
|
|
2020-10-07 18:49:01 +02:00
|
|
|
static void user_creatable_print_types(void)
|
|
|
|
{
|
|
|
|
GSList *l, *list;
|
|
|
|
|
2021-02-17 15:27:54 +01:00
|
|
|
qemu_printf("List of user creatable objects:\n");
|
2020-10-07 18:49:01 +02:00
|
|
|
list = object_class_get_list_sorted(TYPE_USER_CREATABLE, false);
|
|
|
|
for (l = list; l != NULL; l = l->next) {
|
|
|
|
ObjectClass *oc = OBJECT_CLASS(l->data);
|
2021-02-17 15:27:54 +01:00
|
|
|
qemu_printf(" %s\n", object_class_get_name(oc));
|
2020-10-07 18:49:01 +02:00
|
|
|
}
|
|
|
|
g_slist_free(list);
|
|
|
|
}
|
|
|
|
|
2020-11-02 17:08:07 +01:00
|
|
|
bool type_print_class_properties(const char *type)
|
2019-10-11 19:20:12 +02:00
|
|
|
{
|
|
|
|
ObjectClass *klass;
|
2020-10-07 18:49:01 +02:00
|
|
|
ObjectPropertyIterator iter;
|
|
|
|
ObjectProperty *prop;
|
|
|
|
GPtrArray *array;
|
|
|
|
int i;
|
2019-10-11 19:20:12 +02:00
|
|
|
|
2020-10-07 18:49:01 +02:00
|
|
|
klass = object_class_by_name(type);
|
|
|
|
if (!klass) {
|
|
|
|
return false;
|
|
|
|
}
|
2019-10-11 19:20:12 +02:00
|
|
|
|
2020-10-07 18:49:01 +02:00
|
|
|
array = g_ptr_array_new();
|
|
|
|
object_class_property_iter_init(&iter, klass);
|
|
|
|
while ((prop = object_property_iter_next(&iter))) {
|
|
|
|
if (!prop->set) {
|
|
|
|
continue;
|
2019-10-11 19:20:12 +02:00
|
|
|
}
|
2020-10-07 18:49:01 +02:00
|
|
|
|
|
|
|
g_ptr_array_add(array,
|
|
|
|
object_property_help(prop->name, prop->type,
|
|
|
|
prop->defval, prop->description));
|
2019-10-11 19:20:12 +02:00
|
|
|
}
|
2020-10-07 18:49:01 +02:00
|
|
|
g_ptr_array_sort(array, (GCompareFunc)qemu_pstrcmp0);
|
|
|
|
if (array->len > 0) {
|
2021-02-17 15:27:54 +01:00
|
|
|
qemu_printf("%s options:\n", type);
|
2020-10-07 18:49:01 +02:00
|
|
|
} else {
|
2021-02-17 15:27:54 +01:00
|
|
|
qemu_printf("There are no options for %s.\n", type);
|
2020-10-07 18:49:01 +02:00
|
|
|
}
|
|
|
|
for (i = 0; i < array->len; i++) {
|
2021-02-17 15:27:54 +01:00
|
|
|
qemu_printf("%s\n", (char *)array->pdata[i]);
|
2020-10-07 18:49:01 +02:00
|
|
|
}
|
|
|
|
g_ptr_array_set_free_func(array, g_free);
|
|
|
|
g_ptr_array_free(array, true);
|
|
|
|
return true;
|
|
|
|
}
|
2019-10-11 19:20:12 +02:00
|
|
|
|
2020-10-07 18:49:01 +02:00
|
|
|
bool user_creatable_print_help(const char *type, QemuOpts *opts)
|
|
|
|
{
|
|
|
|
if (is_help_option(type)) {
|
|
|
|
user_creatable_print_types();
|
2019-10-11 19:20:12 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-10-07 18:49:01 +02:00
|
|
|
if (qemu_opt_has_help_opt(opts)) {
|
2020-11-02 17:08:07 +01:00
|
|
|
return type_print_class_properties(type);
|
2020-10-07 18:49:01 +02:00
|
|
|
}
|
|
|
|
|
2019-10-11 19:20:12 +02:00
|
|
|
return false;
|
|
|
|
}
|
2016-02-10 19:40:59 +01:00
|
|
|
|
2021-02-17 12:06:20 +01:00
|
|
|
static void user_creatable_print_help_from_qdict(QDict *args)
|
2020-10-07 18:49:02 +02:00
|
|
|
{
|
|
|
|
const char *type = qdict_get_try_str(args, "qom-type");
|
|
|
|
|
2020-11-02 17:08:07 +01:00
|
|
|
if (!type || !type_print_class_properties(type)) {
|
2020-10-07 18:49:02 +02:00
|
|
|
user_creatable_print_types();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-19 18:14:01 +01:00
|
|
|
ObjectOptions *user_creatable_parse_str(const char *optarg, Error **errp)
|
2021-02-17 12:06:20 +01:00
|
|
|
{
|
2021-02-17 14:59:06 +01:00
|
|
|
ERRP_GUARD();
|
2021-03-12 14:19:21 +01:00
|
|
|
QObject *obj;
|
2021-02-17 12:06:20 +01:00
|
|
|
bool help;
|
|
|
|
Visitor *v;
|
|
|
|
ObjectOptions *options;
|
|
|
|
|
2021-03-12 14:19:21 +01:00
|
|
|
if (optarg[0] == '{') {
|
|
|
|
obj = qobject_from_json(optarg, errp);
|
|
|
|
if (!obj) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
v = qobject_input_visitor_new(obj);
|
|
|
|
} else {
|
|
|
|
QDict *args = keyval_parse(optarg, "qom-type", &help, errp);
|
|
|
|
if (*errp) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
if (help) {
|
|
|
|
user_creatable_print_help_from_qdict(args);
|
|
|
|
qobject_unref(args);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
obj = QOBJECT(args);
|
|
|
|
v = qobject_input_visitor_new_keyval(obj);
|
2021-02-17 12:06:20 +01:00
|
|
|
}
|
|
|
|
|
2021-02-17 14:59:06 +01:00
|
|
|
visit_type_ObjectOptions(v, NULL, &options, errp);
|
2021-02-17 12:06:20 +01:00
|
|
|
visit_free(v);
|
2021-03-12 14:19:21 +01:00
|
|
|
qobject_unref(obj);
|
2021-02-17 12:06:20 +01:00
|
|
|
|
2021-02-19 18:14:01 +01:00
|
|
|
return options;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool user_creatable_add_from_str(const char *optarg, Error **errp)
|
|
|
|
{
|
|
|
|
ERRP_GUARD();
|
|
|
|
ObjectOptions *options;
|
|
|
|
|
|
|
|
options = user_creatable_parse_str(optarg, errp);
|
|
|
|
if (!options) {
|
|
|
|
return false;
|
2021-02-17 14:59:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
user_creatable_add_qapi(options, errp);
|
2021-02-17 12:06:20 +01:00
|
|
|
qapi_free_ObjectOptions(options);
|
2021-02-17 14:59:06 +01:00
|
|
|
return !*errp;
|
|
|
|
}
|
|
|
|
|
|
|
|
void user_creatable_process_cmdline(const char *optarg)
|
|
|
|
{
|
|
|
|
if (!user_creatable_add_from_str(optarg, &error_fatal)) {
|
|
|
|
/* Help was printed */
|
|
|
|
exit(EXIT_SUCCESS);
|
|
|
|
}
|
2021-02-17 12:06:20 +01:00
|
|
|
}
|
|
|
|
|
2020-07-07 18:05:55 +02:00
|
|
|
bool user_creatable_del(const char *id, Error **errp)
|
2016-02-10 19:40:59 +01:00
|
|
|
{
|
2021-02-22 15:29:27 +01:00
|
|
|
QemuOptsList *opts_list;
|
2016-02-10 19:40:59 +01:00
|
|
|
Object *container;
|
|
|
|
Object *obj;
|
|
|
|
|
|
|
|
container = object_get_objects_root();
|
|
|
|
obj = object_resolve_path_component(container, id);
|
|
|
|
if (!obj) {
|
|
|
|
error_setg(errp, "object '%s' not found", id);
|
2020-07-07 18:05:55 +02:00
|
|
|
return false;
|
2016-02-10 19:40:59 +01:00
|
|
|
}
|
|
|
|
|
2017-08-30 00:03:37 +02:00
|
|
|
if (!user_creatable_can_be_deleted(USER_CREATABLE(obj))) {
|
2016-02-10 19:40:59 +01:00
|
|
|
error_setg(errp, "object '%s' is in use, can not be deleted", id);
|
2020-07-07 18:05:55 +02:00
|
|
|
return false;
|
2016-02-10 19:40:59 +01:00
|
|
|
}
|
monitor: fix object_del for command-line-created objects
Currently objects specified on the command-line are only partially
cleaned up when 'object_del' is issued in either HMP or QMP: the
object itself is fully finalized, but the QemuOpts are not removed.
This results in the following behavior:
x86_64-softmmu/qemu-system-x86_64 -monitor stdio \
-object memory-backend-ram,id=ram1,size=256M
QEMU 2.7.91 monitor - type 'help' for more information
(qemu) object_del ram1
(qemu) object_del ram1
object 'ram1' not found
(qemu) object_add memory-backend-ram,id=ram1,size=256M
Duplicate ID 'ram1' for object
Try "help object_add" for more information
which can be an issue for use-cases like memory hotplug.
This happens on the HMP side because hmp_object_add() attempts to
create a temporary QemuOpts entry with ID 'ram1', which ends up
conflicting with the command-line-created entry, since it was never
cleaned up during the previous hmp_object_del() call.
We address this by adding a check in user_creatable_del(), which
is called by both qmp_object_del() and hmp_object_del() to handle
the actual object cleanup, to determine whether an option group entry
matching the object's ID is present and removing it if it is.
Note that qmp_object_add() never attempts to create a temporary
QemuOpts entry, so it does not encounter the duplicate ID error,
which is why this isn't generally visible in libvirt.
Cc: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
Cc: Markus Armbruster <armbru@redhat.com>
Cc: Eric Blake <eblake@redhat.com>
Cc: Daniel Berrange <berrange@redhat.com>
Cc: qemu-stable@nongnu.org
Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
Reviewed-by: Daniel P. Berrange <berrange@redhat.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Message-Id: <1496531612-22166-3-git-send-email-mdroth@linux.vnet.ibm.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2017-06-04 01:13:32 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* if object was defined on the command-line, remove its corresponding
|
|
|
|
* option group entry
|
|
|
|
*/
|
2021-02-22 15:29:27 +01:00
|
|
|
opts_list = qemu_find_opts_err("object", NULL);
|
|
|
|
if (opts_list) {
|
|
|
|
qemu_opts_del(qemu_opts_find(opts_list, id));
|
|
|
|
}
|
monitor: fix object_del for command-line-created objects
Currently objects specified on the command-line are only partially
cleaned up when 'object_del' is issued in either HMP or QMP: the
object itself is fully finalized, but the QemuOpts are not removed.
This results in the following behavior:
x86_64-softmmu/qemu-system-x86_64 -monitor stdio \
-object memory-backend-ram,id=ram1,size=256M
QEMU 2.7.91 monitor - type 'help' for more information
(qemu) object_del ram1
(qemu) object_del ram1
object 'ram1' not found
(qemu) object_add memory-backend-ram,id=ram1,size=256M
Duplicate ID 'ram1' for object
Try "help object_add" for more information
which can be an issue for use-cases like memory hotplug.
This happens on the HMP side because hmp_object_add() attempts to
create a temporary QemuOpts entry with ID 'ram1', which ends up
conflicting with the command-line-created entry, since it was never
cleaned up during the previous hmp_object_del() call.
We address this by adding a check in user_creatable_del(), which
is called by both qmp_object_del() and hmp_object_del() to handle
the actual object cleanup, to determine whether an option group entry
matching the object's ID is present and removing it if it is.
Note that qmp_object_add() never attempts to create a temporary
QemuOpts entry, so it does not encounter the duplicate ID error,
which is why this isn't generally visible in libvirt.
Cc: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
Cc: Markus Armbruster <armbru@redhat.com>
Cc: Eric Blake <eblake@redhat.com>
Cc: Daniel Berrange <berrange@redhat.com>
Cc: qemu-stable@nongnu.org
Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
Reviewed-by: Daniel P. Berrange <berrange@redhat.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Message-Id: <1496531612-22166-3-git-send-email-mdroth@linux.vnet.ibm.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2017-06-04 01:13:32 +02:00
|
|
|
|
2016-02-10 19:40:59 +01:00
|
|
|
object_unparent(obj);
|
2020-07-07 18:05:55 +02:00
|
|
|
return true;
|
2016-02-10 19:40:59 +01:00
|
|
|
}
|
|
|
|
|
2017-08-24 21:23:13 +02:00
|
|
|
void user_creatable_cleanup(void)
|
|
|
|
{
|
|
|
|
object_unparent(object_get_objects_root());
|
|
|
|
}
|
|
|
|
|
2014-01-16 17:34:38 +01:00
|
|
|
static void register_types(void)
|
|
|
|
{
|
|
|
|
static const TypeInfo uc_interface_info = {
|
|
|
|
.name = TYPE_USER_CREATABLE,
|
|
|
|
.parent = TYPE_INTERFACE,
|
|
|
|
.class_size = sizeof(UserCreatableClass),
|
|
|
|
};
|
|
|
|
|
|
|
|
type_register_static(&uc_interface_info);
|
|
|
|
}
|
|
|
|
|
|
|
|
type_init(register_types)
|