Currently, object_property_parse() is used for both internal property
settings and external user configurations (e.g., via HMP or global
properties).
To properly manage property flags (specifically OBJ_PROP_FLAG_USER_SET),
it is necessary to identify the source of the property setting.
Update object_property_parse() to accept a 'from_user' argument and
set the USER_SET flag for the property if 'from_user=true'.
As a first step, all existing callers are updated to have 'from_user=
false'. Next the cases set by specific external user will be identified
(like HMP and global properties) and will update 'from_user' argument to
'true'.
Signed-off-by: Zhao Liu <zhao1.liu@intel.com>
---
hw/i386/sgx.c | 2 +-
include/qom/object.h | 5 +++--
qom/object.c | 20 +++++++++++++++-----
qom/qom-hmp-cmds.c | 2 +-
system/vl.c | 2 +-
target/i386/cpu.c | 4 ++--
6 files changed, 23 insertions(+), 12 deletions(-)
diff --git a/hw/i386/sgx.c b/hw/i386/sgx.c
index 5e792e8e6e96..8cb71be689ff 100644
--- a/hw/i386/sgx.c
+++ b/hw/i386/sgx.c
@@ -316,7 +316,7 @@ void pc_machine_init_sgx_epc(PCMachineState *pcms)
/* set the memdev link with memory backend */
object_property_parse(OBJECT(dev), SGX_EPC_MEMDEV_PROP,
- list->value->memdev, &error_fatal);
+ list->value->memdev, false, &error_fatal);
/* set the numa node property for sgx epc object */
object_property_set_uint(OBJECT(dev), SGX_EPC_NUMA_NODE_PROP,
list->value->node, &error_fatal);
diff --git a/include/qom/object.h b/include/qom/object.h
index 1b77429aa28b..c78e1c03a106 100644
--- a/include/qom/object.h
+++ b/include/qom/object.h
@@ -1655,14 +1655,15 @@ bool object_property_set(Object *obj, const char *name, Visitor *v,
* @obj: the object
* @name: the name of the property
* @string: the string that will be used to parse the property value.
+ * @from_user: whether the property is being set by a external user.
* @errp: returns an error if this function fails
*
* Parses a string and writes the result into a property of an object.
*
* Returns: %true on success, %false on failure.
*/
-bool object_property_parse(Object *obj, const char *name,
- const char *string, Error **errp);
+bool object_property_parse(Object *obj, const char *name, const char *string,
+ bool from_user, Error **errp);
/**
* object_property_print:
diff --git a/qom/object.c b/qom/object.c
index 75a1fe7ea1d3..7140e3f629aa 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -460,7 +460,7 @@ bool object_apply_global_props(Object *obj, const GPtrArray *props,
continue;
}
p->used = true;
- if (!object_property_parse(obj, p->property, p->value, &err)) {
+ if (!object_property_parse(obj, p->property, p->value, false, &err)) {
error_prepend(&err, "can't apply global %s.%s=%s: ",
p->driver, p->property, p->value);
/*
@@ -882,7 +882,7 @@ bool object_set_propv(Object *obj,
const char *value = va_arg(vargs, char *);
g_assert(value != NULL);
- if (!object_property_parse(obj, propname, value, errp)) {
+ if (!object_property_parse(obj, propname, value, false, errp)) {
return false;
}
propname = va_arg(vargs, char *);
@@ -1802,13 +1802,23 @@ int object_property_get_enum(Object *obj, const char *name,
return ret;
}
-bool object_property_parse(Object *obj, const char *name,
- const char *string, Error **errp)
+bool object_property_parse(Object *obj, const char *name, const char *string,
+ bool from_user, Error **errp)
{
Visitor *v = string_input_visitor_new(string);
- bool ok = object_property_set(obj, name, v, errp);
+ bool ok;
+ ok = object_property_set(obj, name, v, errp);
visit_free(v);
+
+ if (!ok) {
+ return false;
+ }
+
+ if (from_user) {
+ ok = object_property_set_flags(obj, name,
+ OBJ_PROP_FLAG_USER_SET, errp);
+ }
return ok;
}
diff --git a/qom/qom-hmp-cmds.c b/qom/qom-hmp-cmds.c
index 32e40630c96a..6bdb241e54bd 100644
--- a/qom/qom-hmp-cmds.c
+++ b/qom/qom-hmp-cmds.c
@@ -58,7 +58,7 @@ void hmp_qom_set(Monitor *mon, const QDict *qdict)
error_set(&err, ERROR_CLASS_DEVICE_NOT_FOUND,
"Device '%s' not found", path);
} else {
- object_property_parse(obj, property, value, &err);
+ object_property_parse(obj, property, value, false, &err);
}
} else {
QObject *obj = qobject_from_json(value, &err);
diff --git a/system/vl.c b/system/vl.c
index aa9a15504174..6d8167a50006 100644
--- a/system/vl.c
+++ b/system/vl.c
@@ -1708,7 +1708,7 @@ static int object_parse_property_opt(Object *obj,
return 0;
}
- if (!object_property_parse(obj, name, value, errp)) {
+ if (!object_property_parse(obj, name, value, false, errp)) {
return -1;
}
diff --git a/target/i386/cpu.c b/target/i386/cpu.c
index 0a7b884528ea..94a9dcde1eb1 100644
--- a/target/i386/cpu.c
+++ b/target/i386/cpu.c
@@ -8089,7 +8089,7 @@ void x86_cpu_apply_props(X86CPU *cpu, PropValue *props)
continue;
}
object_property_parse(OBJECT(cpu), pv->prop, pv->value,
- &error_abort);
+ false, &error_abort);
}
}
@@ -8112,7 +8112,7 @@ static void x86_cpu_apply_version_props(X86CPU *cpu, const X86CPUModel *model)
for (p = vdef->props; p && p->prop; p++) {
object_property_parse(OBJECT(cpu), p->prop, p->value,
- &error_abort);
+ false, &error_abort);
}
if (vdef->version == version) {
--
2.34.1