Skip to content

Commit

Permalink
qom: Allow optional sugar props
Browse files Browse the repository at this point in the history
Global properties have an @optional field, which allows to apply a given
property to a given type even if one of its subclasses doesn't support
it. This is especially used in the compat code when dealing with the
"disable-modern" and "disable-legacy" properties and the "virtio-pci"
type.

Allow object_register_sugar_prop() to set this field as well.

Signed-off-by: Greg Kurz <[email protected]>
Message-Id: <[email protected]>
Signed-off-by: David Gibson <[email protected]>
Reviewed-by: Eduardo Habkost <[email protected]>
Reviewed-by: Cornelia Huck <[email protected]>
Reviewed-by: Philippe Mathieu-Daudé <[email protected]>
  • Loading branch information
gkurz authored and dgibson committed Feb 8, 2021
1 parent 5b19cb6 commit a8dc82c
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 9 deletions.
3 changes: 2 additions & 1 deletion include/qom/object.h
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,8 @@ bool object_apply_global_props(Object *obj, const GPtrArray *props,
Error **errp);
void object_set_machine_compat_props(GPtrArray *compat_props);
void object_set_accelerator_compat_props(GPtrArray *compat_props);
void object_register_sugar_prop(const char *driver, const char *prop, const char *value);
void object_register_sugar_prop(const char *driver, const char *prop,
const char *value, bool optional);
void object_apply_compat_props(Object *obj);

/**
Expand Down
4 changes: 3 additions & 1 deletion qom/object.c
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,8 @@ static GPtrArray *object_compat_props[3];
* other than "-global". These are generally used for syntactic
* sugar and legacy command line options.
*/
void object_register_sugar_prop(const char *driver, const char *prop, const char *value)
void object_register_sugar_prop(const char *driver, const char *prop,
const char *value, bool optional)
{
GlobalProperty *g;
if (!object_compat_props[2]) {
Expand All @@ -452,6 +453,7 @@ void object_register_sugar_prop(const char *driver, const char *prop, const char
g->driver = g_strdup(driver);
g->property = g_strdup(prop);
g->value = g_strdup(value);
g->optional = optional;
g_ptr_array_add(object_compat_props[2], g);
}

Expand Down
3 changes: 2 additions & 1 deletion softmmu/rtc.c
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,8 @@ void configure_rtc(QemuOpts *opts)
if (!strcmp(value, "slew")) {
object_register_sugar_prop("mc146818rtc",
"lost_tick_policy",
"slew");
"slew",
false);
} else if (!strcmp(value, "none")) {
/* discard is default */
} else {
Expand Down
17 changes: 11 additions & 6 deletions softmmu/vl.c
Original file line number Diff line number Diff line change
Expand Up @@ -1663,16 +1663,20 @@ static int machine_set_property(void *opaque,
return 0;
}
if (g_str_equal(qom_name, "igd-passthru")) {
object_register_sugar_prop(ACCEL_CLASS_NAME("xen"), qom_name, value);
object_register_sugar_prop(ACCEL_CLASS_NAME("xen"), qom_name, value,
false);
return 0;
}
if (g_str_equal(qom_name, "kvm-shadow-mem")) {
object_register_sugar_prop(ACCEL_CLASS_NAME("kvm"), qom_name, value);
object_register_sugar_prop(ACCEL_CLASS_NAME("kvm"), qom_name, value,
false);
return 0;
}
if (g_str_equal(qom_name, "kernel-irqchip")) {
object_register_sugar_prop(ACCEL_CLASS_NAME("kvm"), qom_name, value);
object_register_sugar_prop(ACCEL_CLASS_NAME("whpx"), qom_name, value);
object_register_sugar_prop(ACCEL_CLASS_NAME("kvm"), qom_name, value,
false);
object_register_sugar_prop(ACCEL_CLASS_NAME("whpx"), qom_name, value,
false);
return 0;
}

Expand Down Expand Up @@ -2298,9 +2302,10 @@ static void qemu_process_sugar_options(void)

val = g_strdup_printf("%d",
(uint32_t) qemu_opt_get_number(qemu_find_opts_singleton("smp-opts"), "cpus", 1));
object_register_sugar_prop("memory-backend", "prealloc-threads", val);
object_register_sugar_prop("memory-backend", "prealloc-threads", val,
false);
g_free(val);
object_register_sugar_prop("memory-backend", "prealloc", "on");
object_register_sugar_prop("memory-backend", "prealloc", "on", false);
}

if (watchdog) {
Expand Down

0 comments on commit a8dc82c

Please sign in to comment.