On Mon, Nov 25, 2024 at 14:46:36 -0500, Collin Walling wrote:
> query-cpu-model-expansion may report an array of deprecated properties.
> This array is optional, and may not be supported for a particular
> architecture or reported for a particular CPU model. If the output is
> present, then capture it and store in a qemuMonitorCPUModelInfo struct
> for later use.
>
> The deprecated features will be retained in qemuCaps->kvm->hostCPU.info
> and will be stored in the capabilities cache file under the <hostCPU>
> element using the following format:
>
> <deprecatedFeatures>
> <property name='bpb'/>
> <property name='csske'/>
> <property name='cte'/>
> <property name='te'/>
> </deprecatedFeatures>
>
> At this time the data is only queried, parsed, and cached. The data
> will be utilized in a subsequent patch.
>
> Signed-off-by: Collin Walling <[email protected]>
> ---
> src/qemu/qemu_capabilities.c | 31 +++++++++++++++++++
> src/qemu/qemu_monitor.c | 10 ++++++
> src/qemu/qemu_monitor.h | 1 +
> src/qemu/qemu_monitor_json.c | 18 +++++++++++
> .../qemucapabilitiesdata/caps_9.1.0_s390x.xml | 6 ++++
> .../qemucapabilitiesdata/caps_9.2.0_s390x.xml | 6 ++++
> 6 files changed, 72 insertions(+)
>
> diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
> index 5ac9f306f5..9fa868c8b7 100644
> --- a/src/qemu/qemu_capabilities.c
> +++ b/src/qemu/qemu_capabilities.c
...
> @@ -4107,6 +4108,24 @@ virQEMUCapsLoadHostCPUModelInfo(virQEMUCapsAccel *caps,
> }
> }
>
> + ctxt->node = hostCPUNode;
> +
> + if ((deprecated_props = virXPathNode("./deprecatedFeatures", ctxt))) {
> + g_autoptr(GPtrArray) props =
> virXMLNodeGetSubelementList(deprecated_props, NULL);
> +
> + hostCPU->deprecated_props = g_new0(char *, props->len);
hostCPU->deprecated_props is a NULL terminated array of strings so you
need to allocate it big enough for props->len + 1 items
> +
> + for (i = 0; i < props->len; i++) {
> + xmlNodePtr prop = g_ptr_array_index(props, i);
> +
> + if (!(hostCPU->deprecated_props[i] = virXMLPropString(prop,
> "name"))) {
> + virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
> + _("missing 'name' attribute for a host CPU
> model deprecated property in QEMU capabilities cache"));
> + return -1;
> + }
> + }
> + }
> +
> caps->hostCPU.info = g_steal_pointer(&hostCPU);
> return 0;
> }
...
> diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
> index 73f37d26eb..94089e1c1c 100644
> --- a/src/qemu/qemu_monitor.c
> +++ b/src/qemu/qemu_monitor.c
...
> @@ -3350,6 +3351,15 @@ qemuMonitorCPUModelInfoCopy(const
> qemuMonitorCPUModelInfo *orig)
> }
> }
>
> + if (orig->deprecated_props) {
> + copy->deprecated_props = g_new0(char *,
> +
> g_strv_length(orig->deprecated_props));
> +
> + for (i = 0; i < g_strv_length(orig->deprecated_props); i++) {
> + copy->deprecated_props[i] = g_strdup(orig->deprecated_props[i]);
> + }
> + }
Again, the array is too small, but instead of making the copy this way
you could just do
copy->deprecated_props = g_strdupv(orig->deprecated_props);
Perhaps with some typecasting if the compiler complains about GStrv not
being char **.
> +
> return copy;
> }
>
...
Jirka