This patch adds the ability to get all the compat_props of the
corresponding supported machines for their comparison.
Example:
{ "execute" : "query-machines", "arguments" : { "is-full" : true } }
Signed-off-by: Maxim Davydov <maxim.davydov@openvz.org>
---
hw/core/machine-qmp-cmds.c | 25 +++++++++++++++-
qapi/machine.json | 58 +++++++++++++++++++++++++++++++++++--
tests/qtest/fuzz/qos_fuzz.c | 2 +-
3 files changed, 81 insertions(+), 4 deletions(-)
diff --git a/hw/core/machine-qmp-cmds.c b/hw/core/machine-qmp-cmds.c
index 4f4ab30f8c..8f3206ba8d 100644
--- a/hw/core/machine-qmp-cmds.c
+++ b/hw/core/machine-qmp-cmds.c
@@ -74,7 +74,8 @@ CpuInfoFastList *qmp_query_cpus_fast(Error **errp)
return head;
}
-MachineInfoList *qmp_query_machines(Error **errp)
+MachineInfoList *qmp_query_machines(bool has_is_full, bool is_full,
+ Error **errp)
{
GSList *el, *machines = object_class_get_list(TYPE_MACHINE, false);
MachineInfoList *mach_list = NULL;
@@ -107,6 +108,28 @@ MachineInfoList *qmp_query_machines(Error **errp)
info->default_ram_id = g_strdup(mc->default_ram_id);
info->has_default_ram_id = true;
}
+ if (has_is_full && is_full && mc->compat_props) {
+ int i;
+ info->compat_props = NULL;
+ info->has_compat_props = true;
+
+ for (i = 0; i < mc->compat_props->len; i++) {
+ GlobalProperty *mt_prop = g_ptr_array_index(mc->compat_props,
+ i);
+ ObjectClass *klass = object_class_by_name(mt_prop->driver);
+ CompatProperty *prop;
+
+ prop = g_malloc0(sizeof(*prop));
+ if (klass && object_class_is_abstract(klass)) {
+ prop->abstract = true;
+ }
+ prop->driver = g_strdup(mt_prop->driver);
+ prop->property = g_strdup(mt_prop->property);
+ prop->value = g_strdup(mt_prop->value);
+
+ QAPI_LIST_PREPEND(info->compat_props, prop);
+ }
+ }
QAPI_LIST_PREPEND(mach_list, info);
}
diff --git a/qapi/machine.json b/qapi/machine.json
index 42fc68403d..16e961477c 100644
--- a/qapi/machine.json
+++ b/qapi/machine.json
@@ -130,6 +130,28 @@
##
{ 'command': 'query-cpus-fast', 'returns': [ 'CpuInfoFast' ] }
+##
+# @CompatProperty:
+#
+# Machine type compatible property. It's based on GlobalProperty and created
+# for machine type compat properties (see scripts)
+#
+# @driver: name of the driver that has GlobalProperty
+#
+# @abstract: Bool value that shows that property is belonged to abstract class
+#
+# @property: global property name
+#
+# @value: global property value
+#
+# Since: 7.0
+##
+{ 'struct': 'CompatProperty',
+ 'data': { 'driver': 'str',
+ 'abstract': 'bool',
+ 'property': 'str',
+ 'value': 'str' } }
+
##
# @MachineInfo:
#
@@ -158,6 +180,9 @@
#
# @default-ram-id: the default ID of initial RAM memory backend (since 5.2)
#
+# @compat-props: List of compatible properties that defines machine type
+# (since 7.0)
+#
# Since: 1.2
##
{ 'struct': 'MachineInfo',
@@ -165,18 +190,47 @@
'*is-default': 'bool', 'cpu-max': 'int',
'hotpluggable-cpus': 'bool', 'numa-mem-supported': 'bool',
'deprecated': 'bool', '*default-cpu-type': 'str',
- '*default-ram-id': 'str' } }
+ '*default-ram-id': 'str', '*compat-props': ['CompatProperty'] } }
##
# @query-machines:
#
# Return a list of supported machines
#
+# @is-full: if true return will contain information about machine type
+# compatible properties (since 7.0)
+#
# Returns: a list of MachineInfo
#
# Since: 1.2
+#
+# Example:
+#
+# -> { "execute" : "query-machines", "arguments" : { "is-full" : true } }
+# <- { "return": [
+# {
+# "hotpluggable-cpus": true,
+# "name": "pc-q35-6.2",
+# "compat-props": [
+# {
+# "abstract": false,
+# "driver": "virtio-mem",
+# "property": "unplugged-inaccessible",
+# "value": "off"
+# }
+# ],
+# "numa-mem-supported": false,
+# "default-cpu-type": "qemu64-x86_64-cpu",
+# "cpu-max": 288,
+# "deprecated": false,
+# "default-ram-id": "pc.ram"
+# },
+# ...
+# }
##
-{ 'command': 'query-machines', 'returns': ['MachineInfo'] }
+{ 'command': 'query-machines',
+ 'data': { '*is-full': 'bool' },
+ 'returns': ['MachineInfo'] }
##
# @CurrentMachineParams:
diff --git a/tests/qtest/fuzz/qos_fuzz.c b/tests/qtest/fuzz/qos_fuzz.c
index 7a244c951e..3f9c1ede6e 100644
--- a/tests/qtest/fuzz/qos_fuzz.c
+++ b/tests/qtest/fuzz/qos_fuzz.c
@@ -47,7 +47,7 @@ static void qos_set_machines_devices_available(void)
MachineInfoList *mach_info;
ObjectTypeInfoList *type_info;
- mach_info = qmp_query_machines(&error_abort);
+ mach_info = qmp_query_machines(false, false, &error_abort);
machines_apply_to_node(mach_info);
qapi_free_MachineInfoList(mach_info);
--
2.31.1
29.03.2022 00:15, Maxim Davydov wrote:
> This patch adds the ability to get all the compat_props of the
> corresponding supported machines for their comparison.
>
> Example:
> { "execute" : "query-machines", "arguments" : { "is-full" : true } }
>
> Signed-off-by: Maxim Davydov <maxim.davydov@openvz.org>
> ---
> hw/core/machine-qmp-cmds.c | 25 +++++++++++++++-
> qapi/machine.json | 58 +++++++++++++++++++++++++++++++++++--
> tests/qtest/fuzz/qos_fuzz.c | 2 +-
> 3 files changed, 81 insertions(+), 4 deletions(-)
>
> diff --git a/hw/core/machine-qmp-cmds.c b/hw/core/machine-qmp-cmds.c
> index 4f4ab30f8c..8f3206ba8d 100644
> --- a/hw/core/machine-qmp-cmds.c
> +++ b/hw/core/machine-qmp-cmds.c
> @@ -74,7 +74,8 @@ CpuInfoFastList *qmp_query_cpus_fast(Error **errp)
> return head;
> }
>
> -MachineInfoList *qmp_query_machines(Error **errp)
> +MachineInfoList *qmp_query_machines(bool has_is_full, bool is_full,
> + Error **errp)
> {
> GSList *el, *machines = object_class_get_list(TYPE_MACHINE, false);
> MachineInfoList *mach_list = NULL;
> @@ -107,6 +108,28 @@ MachineInfoList *qmp_query_machines(Error **errp)
> info->default_ram_id = g_strdup(mc->default_ram_id);
> info->has_default_ram_id = true;
> }
> + if (has_is_full && is_full && mc->compat_props) {
is_full is guaranteed to be zero when has_is_full is zero. So, it's enough to write:
if (is_full && mc->compat_props) {
> + int i;
> + info->compat_props = NULL;
> + info->has_compat_props = true;
> +
> + for (i = 0; i < mc->compat_props->len; i++) {
> + GlobalProperty *mt_prop = g_ptr_array_index(mc->compat_props,
> + i);
> + ObjectClass *klass = object_class_by_name(mt_prop->driver);
> + CompatProperty *prop;
> +
> + prop = g_malloc0(sizeof(*prop));
> + if (klass && object_class_is_abstract(klass)) {
> + prop->abstract = true;
> + }
> + prop->driver = g_strdup(mt_prop->driver);
> + prop->property = g_strdup(mt_prop->property);
> + prop->value = g_strdup(mt_prop->value);
> +
> + QAPI_LIST_PREPEND(info->compat_props, prop);
> + }
> + }
>
> QAPI_LIST_PREPEND(mach_list, info);
> }
> diff --git a/qapi/machine.json b/qapi/machine.json
> index 42fc68403d..16e961477c 100644
> --- a/qapi/machine.json
> +++ b/qapi/machine.json
> @@ -130,6 +130,28 @@
> ##
> { 'command': 'query-cpus-fast', 'returns': [ 'CpuInfoFast' ] }
>
> +##
> +# @CompatProperty:
> +#
> +# Machine type compatible property. It's based on GlobalProperty and created
> +# for machine type compat properties (see scripts)
> +#
> +# @driver: name of the driver that has GlobalProperty
> +#
> +# @abstract: Bool value that shows that property is belonged to abstract class
> +#
> +# @property: global property name
> +#
> +# @value: global property value
> +#
> +# Since: 7.0
> +##
> +{ 'struct': 'CompatProperty',
> + 'data': { 'driver': 'str',
> + 'abstract': 'bool',
> + 'property': 'str',
> + 'value': 'str' } }
> +
> ##
> # @MachineInfo:
> #
> @@ -158,6 +180,9 @@
> #
> # @default-ram-id: the default ID of initial RAM memory backend (since 5.2)
> #
> +# @compat-props: List of compatible properties that defines machine type
> +# (since 7.0)
> +#
> # Since: 1.2
> ##
> { 'struct': 'MachineInfo',
> @@ -165,18 +190,47 @@
> '*is-default': 'bool', 'cpu-max': 'int',
> 'hotpluggable-cpus': 'bool', 'numa-mem-supported': 'bool',
> 'deprecated': 'bool', '*default-cpu-type': 'str',
> - '*default-ram-id': 'str' } }
> + '*default-ram-id': 'str', '*compat-props': ['CompatProperty'] } }
>
> ##
> # @query-machines:
> #
> # Return a list of supported machines
> #
> +# @is-full: if true return will contain information about machine type
> +# compatible properties (since 7.0)
Should be 7.1.
Also, maybe call it "compat-props" to be consistent with output and with documentation?
> +#
> # Returns: a list of MachineInfo
> #
> # Since: 1.2
> +#
> +# Example:
> +#
> +# -> { "execute" : "query-machines", "arguments" : { "is-full" : true } }
> +# <- { "return": [
> +# {
> +# "hotpluggable-cpus": true,
> +# "name": "pc-q35-6.2",
> +# "compat-props": [
> +# {
> +# "abstract": false,
> +# "driver": "virtio-mem",
> +# "property": "unplugged-inaccessible",
> +# "value": "off"
> +# }
> +# ],
> +# "numa-mem-supported": false,
> +# "default-cpu-type": "qemu64-x86_64-cpu",
> +# "cpu-max": 288,
> +# "deprecated": false,
> +# "default-ram-id": "pc.ram"
> +# },
> +# ...
> +# }
> ##
> -{ 'command': 'query-machines', 'returns': ['MachineInfo'] }
> +{ 'command': 'query-machines',
> + 'data': { '*is-full': 'bool' },
> + 'returns': ['MachineInfo'] }
>
> ##
> # @CurrentMachineParams:
> diff --git a/tests/qtest/fuzz/qos_fuzz.c b/tests/qtest/fuzz/qos_fuzz.c
> index 7a244c951e..3f9c1ede6e 100644
> --- a/tests/qtest/fuzz/qos_fuzz.c
> +++ b/tests/qtest/fuzz/qos_fuzz.c
> @@ -47,7 +47,7 @@ static void qos_set_machines_devices_available(void)
> MachineInfoList *mach_info;
> ObjectTypeInfoList *type_info;
>
> - mach_info = qmp_query_machines(&error_abort);
> + mach_info = qmp_query_machines(false, false, &error_abort);
> machines_apply_to_node(mach_info);
> qapi_free_MachineInfoList(mach_info);
>
weak:
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@openvz.org>
--
Best regards,
Vladimir
On 3/30/22 14:03, Vladimir Sementsov-Ogievskiy wrote:
> 29.03.2022 00:15, Maxim Davydov wrote:
>> This patch adds the ability to get all the compat_props of the
>> corresponding supported machines for their comparison.
>>
>> Example:
>> { "execute" : "query-machines", "arguments" : { "is-full" : true } }
>>
>> Signed-off-by: Maxim Davydov <maxim.davydov@openvz.org>
>> ---
>> hw/core/machine-qmp-cmds.c | 25 +++++++++++++++-
>> qapi/machine.json | 58 +++++++++++++++++++++++++++++++++++--
>> tests/qtest/fuzz/qos_fuzz.c | 2 +-
>> 3 files changed, 81 insertions(+), 4 deletions(-)
>>
>> diff --git a/hw/core/machine-qmp-cmds.c b/hw/core/machine-qmp-cmds.c
>> index 4f4ab30f8c..8f3206ba8d 100644
>> --- a/hw/core/machine-qmp-cmds.c
>> +++ b/hw/core/machine-qmp-cmds.c
>> @@ -74,7 +74,8 @@ CpuInfoFastList *qmp_query_cpus_fast(Error **errp)
>> return head;
>> }
>> -MachineInfoList *qmp_query_machines(Error **errp)
>> +MachineInfoList *qmp_query_machines(bool has_is_full, bool is_full,
>> + Error **errp)
>> {
>> GSList *el, *machines = object_class_get_list(TYPE_MACHINE,
>> false);
>> MachineInfoList *mach_list = NULL;
>> @@ -107,6 +108,28 @@ MachineInfoList *qmp_query_machines(Error **errp)
>> info->default_ram_id = g_strdup(mc->default_ram_id);
>> info->has_default_ram_id = true;
>> }
>> + if (has_is_full && is_full && mc->compat_props) {
>
> is_full is guaranteed to be zero when has_is_full is zero. So, it's
> enough to write:
>
> if (is_full && mc->compat_props) {
>
>> + int i;
>> + info->compat_props = NULL;
>> + info->has_compat_props = true;
>> +
>> + for (i = 0; i < mc->compat_props->len; i++) {
>> + GlobalProperty *mt_prop =
>> g_ptr_array_index(mc->compat_props,
>> + i);
>> + ObjectClass *klass =
>> object_class_by_name(mt_prop->driver);
>> + CompatProperty *prop;
>> +
>> + prop = g_malloc0(sizeof(*prop));
>> + if (klass && object_class_is_abstract(klass)) {
>> + prop->abstract = true;
>> + }
>> + prop->driver = g_strdup(mt_prop->driver);
>> + prop->property = g_strdup(mt_prop->property);
>> + prop->value = g_strdup(mt_prop->value);
>> +
>> + QAPI_LIST_PREPEND(info->compat_props, prop);
>> + }
>> + }
>> QAPI_LIST_PREPEND(mach_list, info);
>> }
>> diff --git a/qapi/machine.json b/qapi/machine.json
>> index 42fc68403d..16e961477c 100644
>> --- a/qapi/machine.json
>> +++ b/qapi/machine.json
>> @@ -130,6 +130,28 @@
>> ##
>> { 'command': 'query-cpus-fast', 'returns': [ 'CpuInfoFast' ] }
>> +##
>> +# @CompatProperty:
>> +#
>> +# Machine type compatible property. It's based on GlobalProperty and
>> created
>> +# for machine type compat properties (see scripts)
>> +#
>> +# @driver: name of the driver that has GlobalProperty
>> +#
>> +# @abstract: Bool value that shows that property is belonged to
>> abstract class
>> +#
>> +# @property: global property name
>> +#
>> +# @value: global property value
>> +#
>> +# Since: 7.0
>> +##
>> +{ 'struct': 'CompatProperty',
>> + 'data': { 'driver': 'str',
>> + 'abstract': 'bool',
>> + 'property': 'str',
>> + 'value': 'str' } }
>> +
>> ##
>> # @MachineInfo:
>> #
>> @@ -158,6 +180,9 @@
>> #
>> # @default-ram-id: the default ID of initial RAM memory backend
>> (since 5.2)
>> #
>> +# @compat-props: List of compatible properties that defines machine
>> type
>> +# (since 7.0)
>> +#
>> # Since: 1.2
>> ##
>> { 'struct': 'MachineInfo',
>> @@ -165,18 +190,47 @@
>> '*is-default': 'bool', 'cpu-max': 'int',
>> 'hotpluggable-cpus': 'bool', 'numa-mem-supported': 'bool',
>> 'deprecated': 'bool', '*default-cpu-type': 'str',
>> - '*default-ram-id': 'str' } }
>> + '*default-ram-id': 'str', '*compat-props':
>> ['CompatProperty'] } }
>> ##
>> # @query-machines:
>> #
>> # Return a list of supported machines
>> #
>> +# @is-full: if true return will contain information about machine type
>> +# compatible properties (since 7.0)
>
> Should be 7.1.
>
> Also, maybe call it "compat-props" to be consistent with output and
> with documentation?
>
>> +#
>> # Returns: a list of MachineInfo
>> #
>> # Since: 1.2
>> +#
>> +# Example:
>> +#
>> +# -> { "execute" : "query-machines", "arguments" : { "is-full" :
>> true } }
>> +# <- { "return": [
>> +# {
>> +# "hotpluggable-cpus": true,
>> +# "name": "pc-q35-6.2",
>> +# "compat-props": [
>> +# {
>> +# "abstract": false,
>> +# "driver": "virtio-mem",
>> +# "property": "unplugged-inaccessible",
>> +# "value": "off"
>> +# }
>> +# ],
>> +# "numa-mem-supported": false,
>> +# "default-cpu-type": "qemu64-x86_64-cpu",
>> +# "cpu-max": 288,
>> +# "deprecated": false,
>> +# "default-ram-id": "pc.ram"
>> +# },
>> +# ...
>> +# }
>> ##
>> -{ 'command': 'query-machines', 'returns': ['MachineInfo'] }
>> +{ 'command': 'query-machines',
>> + 'data': { '*is-full': 'bool' },
>> + 'returns': ['MachineInfo'] }
>> ##
>> # @CurrentMachineParams:
>> diff --git a/tests/qtest/fuzz/qos_fuzz.c b/tests/qtest/fuzz/qos_fuzz.c
>> index 7a244c951e..3f9c1ede6e 100644
>> --- a/tests/qtest/fuzz/qos_fuzz.c
>> +++ b/tests/qtest/fuzz/qos_fuzz.c
>> @@ -47,7 +47,7 @@ static void qos_set_machines_devices_available(void)
>> MachineInfoList *mach_info;
>> ObjectTypeInfoList *type_info;
>> - mach_info = qmp_query_machines(&error_abort);
>> + mach_info = qmp_query_machines(false, false, &error_abort);
>> machines_apply_to_node(mach_info);
>> qapi_free_MachineInfoList(mach_info);
>
> weak:
>
> Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@openvz.org>
>
Thank you for the review. Yes, the name "compat-props" seems more
appropriate than "is-full". It will be changed in the next version
--
Best regards,
Maxim Davydov
© 2016 - 2026 Red Hat, Inc.