[PATCH v2 4/5] virsh: add --disable-deprecated-features flag to domcapabilities

Collin Walling posted 5 patches 1 month ago
There is a newer version of this series
[PATCH v2 4/5] virsh: add --disable-deprecated-features flag to domcapabilities
Posted by Collin Walling 1 month ago
Add a new flag, --disable-deprecated-features, to the domcapabilities
command.  This will modify the output to show the 'host-model' CPU
with features flagged as deprecated paired with the 'disable' policy.

virsh domcapabilities --disable-deprecated-features

Signed-off-by: Collin Walling <walling@linux.ibm.com>
---
 docs/manpages/virsh.rst          |  6 ++++++
 include/libvirt/libvirt-domain.h | 12 ++++++++++++
 src/libvirt-domain.c             |  2 +-
 src/qemu/qemu_capabilities.c     | 20 ++++++++++++++++++++
 src/qemu/qemu_capabilities.h     |  3 +++
 src/qemu/qemu_driver.c           |  8 +++++++-
 tools/virsh-host.c               |  9 ++++++++-
 7 files changed, 57 insertions(+), 3 deletions(-)

diff --git a/docs/manpages/virsh.rst b/docs/manpages/virsh.rst
index 2e525d3fac..d3b8ff4e1c 100644
--- a/docs/manpages/virsh.rst
+++ b/docs/manpages/virsh.rst
@@ -568,6 +568,7 @@ domcapabilities
 
    domcapabilities [virttype] [emulatorbin] [arch] [machine]
                    [--xpath EXPRESSION] [--wrap]
+                   [--disabled-deprecated-features]
 
 
 Print an XML document describing the domain capabilities for the
@@ -609,6 +610,11 @@ a standalone document, however, for ease of additional processing,
 the **--wrap** argument will cause the matching node to be wrapped
 in a common root node.
 
+The **--disabled-deprecated-features** argument will modify the contents
+of host-model CPU XML, updating the features list with any features
+flagged as deprecated for the CPU model by the hypervisor. These
+features will be paired with the "disable" policy.
+
 
 pool-capabilities
 -----------------
diff --git a/include/libvirt/libvirt-domain.h b/include/libvirt/libvirt-domain.h
index d4f1573954..0d7e54a3dc 100644
--- a/include/libvirt/libvirt-domain.h
+++ b/include/libvirt/libvirt-domain.h
@@ -1491,6 +1491,18 @@ int virDomainMigrateGetMaxSpeed(virDomainPtr domain,
 int virDomainMigrateStartPostCopy(virDomainPtr domain,
                                   unsigned int flags);
 
+/**
+ * virConnectGetDomainCapabilitiesFlags:
+ *
+ * Domain capabilities flags.
+ *
+ * Since: 10.10.0
+ */
+typedef enum {
+    /* Report host model with deprecated features disabled. (Since: 10.10.0) */
+    VIR_CONNECT_GET_DOMAIN_CAPABILITIES_DISABLE_DEPRECATED_FEATURES = (1 << 0),
+} virConnectGetDomainCapabilitiesFlags;
+
 char * virConnectGetDomainCapabilities(virConnectPtr conn,
                                        const char *emulatorbin,
                                        const char *arch,
diff --git a/src/libvirt-domain.c b/src/libvirt-domain.c
index 7c6b93963c..e8e5379672 100644
--- a/src/libvirt-domain.c
+++ b/src/libvirt-domain.c
@@ -12166,7 +12166,7 @@ virDomainSetUserPassword(virDomainPtr dom,
  * @arch: domain architecture
  * @machine: machine type
  * @virttype: virtualization type
- * @flags: extra flags; not used yet, so callers should always pass 0
+ * @flags: extra flags; bitwise-OR of virConnectGetDomainCapabilitiesFlags
  *
  * Prior creating a domain (for instance via virDomainCreateXML
  * or virDomainDefineXML) it may be suitable to know what the
diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index 50905750fb..0701b2f4b0 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -3326,6 +3326,26 @@ virQEMUCapsGetCPUFeatures(virQEMUCaps *qemuCaps,
 }
 
 
+void
+virQEMUCapsUpdateCPUDeprecatedFeatures(virQEMUCaps *qemuCaps,
+                                       virDomainVirtType virtType,
+                                       virCPUDef *cpu)
+{
+    qemuMonitorCPUModelInfo *modelInfo;
+    size_t i;
+
+    modelInfo = virQEMUCapsGetCPUModelInfo(qemuCaps, virtType);
+
+    if (!modelInfo || !modelInfo->deprecated_props)
+        return;
+
+    for (i = 0; i < g_strv_length(modelInfo->deprecated_props); i++) {
+        virCPUDefUpdateFeature(cpu, modelInfo->deprecated_props[i],
+                               VIR_CPU_FEATURE_DISABLE);
+    }
+}
+
+
 struct tpmTypeToCaps {
     int type;
     virQEMUCapsFlags caps;
diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h
index 8347fd7fbb..6bfe99fce4 100644
--- a/src/qemu/qemu_capabilities.h
+++ b/src/qemu/qemu_capabilities.h
@@ -764,6 +764,9 @@ int virQEMUCapsGetCPUFeatures(virQEMUCaps *qemuCaps,
                               virDomainVirtType virtType,
                               bool migratable,
                               char ***features);
+void virQEMUCapsUpdateCPUDeprecatedFeatures(virQEMUCaps *qemuCaps,
+                                            virDomainVirtType virtType,
+                                            virCPUDef *cpu);
 
 virDomainVirtType virQEMUCapsGetVirtType(virQEMUCaps *qemuCaps);
 
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 5b9c55f704..86ab0bd39a 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -16521,7 +16521,8 @@ qemuConnectGetDomainCapabilities(virConnectPtr conn,
     virDomainVirtType virttype;
     g_autoptr(virDomainCaps) domCaps = NULL;
 
-    virCheckFlags(0, NULL);
+    virCheckFlags(VIR_CONNECT_GET_DOMAIN_CAPABILITIES_DISABLE_DEPRECATED_FEATURES,
+                  NULL);
 
     if (virConnectGetDomainCapabilitiesEnsureACL(conn) < 0)
         return NULL;
@@ -16540,6 +16541,11 @@ qemuConnectGetDomainCapabilities(virConnectPtr conn,
                                                        arch, virttype)))
         return NULL;
 
+    if (flags & VIR_CONNECT_GET_DOMAIN_CAPABILITIES_DISABLE_DEPRECATED_FEATURES) {
+        virQEMUCapsUpdateCPUDeprecatedFeatures(qemuCaps, virttype,
+                                               domCaps->cpu.hostModel);
+    }
+
     return virDomainCapsFormat(domCaps);
 }
 
diff --git a/tools/virsh-host.c b/tools/virsh-host.c
index 2fe64e415f..f4e7324f42 100644
--- a/tools/virsh-host.c
+++ b/tools/virsh-host.c
@@ -114,6 +114,10 @@ static const vshCmdOptDef opts_domcapabilities[] = {
      .type = VSH_OT_BOOL,
      .help = N_("wrap xpath results in an common root element"),
     },
+    {.name = "disable-deprecated-features",
+     .type = VSH_OT_BOOL,
+     .help = N_("report host CPU model with deprecated features disabled"),
+    },
     {.name = NULL}
 };
 
@@ -126,10 +130,13 @@ cmdDomCapabilities(vshControl *ctl, const vshCmd *cmd)
     const char *arch = NULL;
     const char *machine = NULL;
     const char *xpath = NULL;
-    const unsigned int flags = 0; /* No flags so far */
+    unsigned int flags = 0;
     bool wrap = vshCommandOptBool(cmd, "wrap");
     virshControl *priv = ctl->privData;
 
+    if (vshCommandOptBool(cmd, "disable-deprecated-features"))
+        flags |= VIR_CONNECT_GET_DOMAIN_CAPABILITIES_DISABLE_DEPRECATED_FEATURES;
+
     if (vshCommandOptString(ctl, cmd, "virttype", &virttype) < 0 ||
         vshCommandOptString(ctl, cmd, "emulatorbin", &emulatorbin) < 0 ||
         vshCommandOptString(ctl, cmd, "arch", &arch) < 0 ||
-- 
2.45.1
Re: [PATCH v2 4/5] virsh: add --disable-deprecated-features flag to domcapabilities
Posted by Jiri Denemark 4 weeks, 1 day ago
On Mon, Nov 25, 2024 at 14:46:38 -0500, Collin Walling wrote:
> Add a new flag, --disable-deprecated-features, to the domcapabilities
> command.  This will modify the output to show the 'host-model' CPU
> with features flagged as deprecated paired with the 'disable' policy.
> 
> virsh domcapabilities --disable-deprecated-features
> 
> Signed-off-by: Collin Walling <walling@linux.ibm.com>
> ---
>  docs/manpages/virsh.rst          |  6 ++++++
>  include/libvirt/libvirt-domain.h | 12 ++++++++++++
>  src/libvirt-domain.c             |  2 +-
>  src/qemu/qemu_capabilities.c     | 20 ++++++++++++++++++++
>  src/qemu/qemu_capabilities.h     |  3 +++
>  src/qemu/qemu_driver.c           |  8 +++++++-
>  tools/virsh-host.c               |  9 ++++++++-
>  7 files changed, 57 insertions(+), 3 deletions(-)

I would split this patch to at least separate virsh changes from the
rest, but even splitting it into three patches (public API, qemu, virsh)
would work as well.

> 
> diff --git a/docs/manpages/virsh.rst b/docs/manpages/virsh.rst
> index 2e525d3fac..d3b8ff4e1c 100644
> --- a/docs/manpages/virsh.rst
> +++ b/docs/manpages/virsh.rst
> @@ -568,6 +568,7 @@ domcapabilities
>  
>     domcapabilities [virttype] [emulatorbin] [arch] [machine]
>                     [--xpath EXPRESSION] [--wrap]
> +                   [--disabled-deprecated-features]

s/disabled/disable/

>  
>  
>  Print an XML document describing the domain capabilities for the
> @@ -609,6 +610,11 @@ a standalone document, however, for ease of additional processing,
>  the **--wrap** argument will cause the matching node to be wrapped
>  in a common root node.
>  
> +The **--disabled-deprecated-features** argument will modify the contents

s/disabled/disable/

> +of host-model CPU XML, updating the features list with any features
> +flagged as deprecated for the CPU model by the hypervisor. These
> +features will be paired with the "disable" policy.
> +
>  
>  pool-capabilities
>  -----------------
> diff --git a/include/libvirt/libvirt-domain.h b/include/libvirt/libvirt-domain.h
> index d4f1573954..0d7e54a3dc 100644
> --- a/include/libvirt/libvirt-domain.h
> +++ b/include/libvirt/libvirt-domain.h
> @@ -1491,6 +1491,18 @@ int virDomainMigrateGetMaxSpeed(virDomainPtr domain,
>  int virDomainMigrateStartPostCopy(virDomainPtr domain,
>                                    unsigned int flags);
>  
> +/**
> + * virConnectGetDomainCapabilitiesFlags:
> + *
> + * Domain capabilities flags.
> + *
> + * Since: 10.10.0

Obviously 11.0.0 here and a few lines below

> + */
> +typedef enum {
> +    /* Report host model with deprecated features disabled. (Since: 10.10.0) */
> +    VIR_CONNECT_GET_DOMAIN_CAPABILITIES_DISABLE_DEPRECATED_FEATURES = (1 << 0),
> +} virConnectGetDomainCapabilitiesFlags;
> +
>  char * virConnectGetDomainCapabilities(virConnectPtr conn,
>                                         const char *emulatorbin,
>                                         const char *arch,

Jirka