[PATCH 1/3] NEWS: Mention UNDEFINE_TPM and UNDEFINE_KEEP_TPM flags

2022-10-31 Thread Han Han
Signed-off-by: Han Han 
---
 NEWS.rst | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/NEWS.rst b/NEWS.rst
index 893ad6f370..1d4fb62d5e 100644
--- a/NEWS.rst
+++ b/NEWS.rst
@@ -17,6 +17,13 @@ v8.9.0 (unreleased)
 
 * **New features**
 
+  * qemu: Add flags to keep or remove TPM state for the virDomainUndefineFlags
+
+``VIR_DOMAIN_UNDEFINE_TPM`` and ``VIR_DOMAIN_UNDEFINE_KEEP_TPM`` specify
+accordingly to delete or keep a TPM's persistent state directory structure
+and files when undefine a domain. In virsh, they are the ``--tpm`` and
+``--keep-tpm`` for the sub-command undefine.
+
   * qemu: Core Scheduling support
 
 To avoid side channel attacks, the Linux kernel allows creating groups of
-- 
2.38.1



[PATCH 2/3] NEWS: Mention the tool virt-qemu-qmp-proxy

2022-10-31 Thread Han Han
Signed-off-by: Han Han 
---
 NEWS.rst | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/NEWS.rst b/NEWS.rst
index 1d4fb62d5e..7b856f4d3f 100644
--- a/NEWS.rst
+++ b/NEWS.rst
@@ -17,6 +17,13 @@ v8.9.0 (unreleased)
 
 * **New features**
 
+  * tools: Add the tool for proxying QMP via libvirt QEMU guests
+
+This tool ``virt-qemu-qmp-proxy`` provides a way to expose a QMP proxy 
server
+that communicates with a QEMU guest managed by libvirt. This enables 
standard
+QMP client tools to interact with libvirt managed guests.
+
+
   * qemu: Add flags to keep or remove TPM state for the virDomainUndefineFlags
 
 ``VIR_DOMAIN_UNDEFINE_TPM`` and ``VIR_DOMAIN_UNDEFINE_KEEP_TPM`` specify
-- 
2.38.1



[PATCH 3/3] NEWS: Add the stats VIR_DOMAIN_STATS_VM of virConnectGetAllDomainStats

2022-10-31 Thread Han Han
Signed-off-by: Han Han 
---
 NEWS.rst | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/NEWS.rst b/NEWS.rst
index 7b856f4d3f..06fd4fa84f 100644
--- a/NEWS.rst
+++ b/NEWS.rst
@@ -41,6 +41,12 @@ v8.9.0 (unreleased)
 
 * **Improvements**
 
+  * qemu: Add the stats of VM for virConnectGetAllDomainStats
+
+The stats ``VIR_DOMAIN_STATS_VM`` of virConnectGetAllDomainStats is to
+get the fd-based KVM statistics for the target VM. It could be used by
+the command line ``virsh domstats --vm``
+
   * Add ``vendor`` attribute for CPU models in domain capabilities
 
 Users can now see the vendor of each CPU model in domain capabilities and
-- 
2.38.1



[PATCH 0/3] The NEWS for v8.9

2022-10-31 Thread Han Han
Han Han (3):
  NEWS: Mention UNDEFINE_TPM and UNDEFINE_KEEP_TPM flags
  NEWS: Mention the tool virt-qemu-qmp-proxy
  NEWS: Add the stats VIR_DOMAIN_STATS_VM of virConnectGetAllDomainStats

 NEWS.rst | 20 
 1 file changed, 20 insertions(+)

-- 
2.38.1



[PATCH] include: Fix the introduced version for VIR_DOMAIN_STATS_VM

2022-10-31 Thread Han Han
Fixes: 8c9e3dae14

Signed-off-by: Han Han 
---
 include/libvirt/libvirt-domain.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/libvirt/libvirt-domain.h b/include/libvirt/libvirt-domain.h
index a37244e4b1..295fd30c93 100644
--- a/include/libvirt/libvirt-domain.h
+++ b/include/libvirt/libvirt-domain.h
@@ -2710,7 +2710,7 @@ typedef enum {
 VIR_DOMAIN_STATS_IOTHREAD = (1 << 7), /* return iothread poll info (Since: 
4.10.0) */
 VIR_DOMAIN_STATS_MEMORY = (1 << 8), /* return domain memory info (Since: 
6.0.0) */
 VIR_DOMAIN_STATS_DIRTYRATE = (1 << 9), /* return domain dirty rate info 
(Since: 7.2.0) */
-VIR_DOMAIN_STATS_VM = (1 << 10), /* return vm info (Since: 8.6.0) */
+VIR_DOMAIN_STATS_VM = (1 << 10), /* return vm info (Since: 8.9.0) */
 } virDomainStatsTypes;
 
 /**
-- 
2.38.1



[PATCH 1/2] qemu_namespace: Don't leak memory in qemuDomainGetPreservedMounts()

2022-10-31 Thread Michal Privoznik
The aim of qemuDomainGetPreservedMounts() is to get a list of
filesystems mounted under /dev and optionally generate a path for
each one where they are moved temporarily when building the
namespace. And the function tries to be a bit clever about it.
For instance, if /dev/shm mount point exists, there's no need to
consider /dev/shm/a nor /dev/shm/b as preserving just 'top level'
/dev/shm gives the same result. To achieve this, the function
iterates over the list of filesystem as returned by
virFileGetMountSubtree() and removes the nested ones. However, it
does so in a bit clumsy way: plain VIR_DELETE_ELEMENT() is used
without freeing the string itself. Therefore, if all three
aforementioned example paths appeared on the list, /dev/shm/a and
/dev/shm/b strings would be leaked.

And when I think about it more, there's no real need to shrink
the array down (realloc()). It's going to be free()-d when
returning from the function. Switch to
VIR_DELETE_ELEMENT_INPLACE() then.

Fixes: cdd9205dfffa3aaed935446a41f0d2dd1357c268
Signed-off-by: Michal Privoznik 
---
 src/qemu/qemu_namespace.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/qemu/qemu_namespace.c b/src/qemu/qemu_namespace.c
index 311c66d46e..9fed6871e8 100644
--- a/src/qemu/qemu_namespace.c
+++ b/src/qemu/qemu_namespace.c
@@ -159,7 +159,8 @@ qemuDomainGetPreservedMounts(virQEMUDriverConfig *cfg,
 
 if (c && (*c == '/' || *c == '\0')) {
 VIR_DEBUG("Dropping path %s because of %s", mounts[j], 
mounts[i]);
-VIR_DELETE_ELEMENT(mounts, j, nmounts);
+VIR_FREE(mounts[j]);
+VIR_DELETE_ELEMENT_INPLACE(mounts, j, nmounts);
 } else {
 j++;
 }
-- 
2.37.4



[PATCH 0/2] qemu_namespace: Memleak and a small improvement

2022-10-31 Thread Michal Privoznik
*** BLURB HERE ***

Michal Prívozník (2):
  qemu_namespace: Don't leak memory in qemuDomainGetPreservedMounts()
  qemu_namespace: Make qemuDomainGetPreservedMounts() more robust wrt
running VMs

 src/qemu/qemu_namespace.c | 14 +-
 1 file changed, 13 insertions(+), 1 deletion(-)

-- 
2.37.4



[PATCH 2/2] qemu_namespace: Make qemuDomainGetPreservedMounts() more robust wrt running VMs

2022-10-31 Thread Michal Privoznik
The aim of qemuDomainGetPreservedMounts() is to get a list of
filesystems mounted under /dev and optionally generate a path for
each one where they are moved temporarily when building the
namespace. And if given domain is also running it looks into its
mount table rather than at the host one. But if it did look at
the domain's private mount table, it find /dev mounted twice: the
first time by udev, the second time the tmpfs mounted by us.

Now, later in the function there's a "sorting" algorithm that
tries to reduce number of mount points needing preservation, by
identifying nested mount points. And if we keep the second
occurrence of /dev on the list, well, after the "sorting" we are
left with nothing but "/dev" because all other mount points are
nested.

Fixes: 46b03819ae8d833b11c2aaccb2c2a0361727f51b
Signed-off-by: Michal Privoznik 
---
 src/qemu/qemu_namespace.c | 11 +++
 1 file changed, 11 insertions(+)

diff --git a/src/qemu/qemu_namespace.c b/src/qemu/qemu_namespace.c
index 9fed6871e8..8189cc37ba 100644
--- a/src/qemu/qemu_namespace.c
+++ b/src/qemu/qemu_namespace.c
@@ -154,6 +154,17 @@ qemuDomainGetPreservedMounts(virQEMUDriverConfig *cfg,
 for (i = 1; i < nmounts; i++) {
 size_t j = i + 1;
 
+/* If we looked into mount table of already running VM,
+ * we might have found /dev twice. Remove the other
+ * occurrence as it would jeopardize the rest of the prune
+ * algorithm.
+ */
+if (STREQ(mounts[i], "/dev")) {
+VIR_FREE(mounts[i]);
+VIR_DELETE_ELEMENT_INPLACE(mounts, i, nmounts);
+continue;
+}
+
 while (j < nmounts) {
 char *c = STRSKIP(mounts[j], mounts[i]);
 
-- 
2.37.4



Re: [libvirt PATCH v2 03/24] cpu: make x86 feature alias names machine readable

2022-10-31 Thread Jiri Denemark
On Mon, Oct 31, 2022 at 09:38:13 +, Daniel P. Berrangé wrote:
> On Fri, Oct 28, 2022 at 05:06:34PM +0200, Tim Wiederhake wrote:
> > Signed-off-by: Tim Wiederhake 
> > Reviewed-by: Jiri Denemark 
> > ---
> >  src/cpu_map/x86_features.xml | 55 +---
> >  1 file changed, 38 insertions(+), 17 deletions(-)
> > 
> > diff --git a/src/cpu_map/x86_features.xml b/src/cpu_map/x86_features.xml
> > index 4cf3ff0804..90d0f43fc6 100644
> > --- a/src/cpu_map/x86_features.xml
> > +++ b/src/cpu_map/x86_features.xml
> > @@ -98,10 +98,12 @@
> >
> >  
> >
> > -   
> > +  
> > +
> 
> IMHO, we should distinguish this as internal data via a NS to
> re-inforce to our future selves that its only used when syncing
> data from QEMU.
> 
>
> 
> And add xmlns:qemu="https://libvirt.org/cpufeature/qemu/1.0"; on
> the top level.

Well, the existing alternative names in comments were not just different
QEMU spellings. Some of them were names used by the kernel. But I don't
really mind either way.

Jirka



Re: [libvirt PATCH v2 03/24] cpu: make x86 feature alias names machine readable

2022-10-31 Thread Daniel P . Berrangé
On Fri, Oct 28, 2022 at 05:06:34PM +0200, Tim Wiederhake wrote:
> Signed-off-by: Tim Wiederhake 
> Reviewed-by: Jiri Denemark 
> ---
>  src/cpu_map/x86_features.xml | 55 +---
>  1 file changed, 38 insertions(+), 17 deletions(-)
> 
> diff --git a/src/cpu_map/x86_features.xml b/src/cpu_map/x86_features.xml
> index 4cf3ff0804..90d0f43fc6 100644
> --- a/src/cpu_map/x86_features.xml
> +++ b/src/cpu_map/x86_features.xml
> @@ -98,10 +98,12 @@
>
>  
>
> -   
> +  
> +

IMHO, we should distinguish this as internal data via a NS to
re-inforce to our future selves that its only used when syncing
data from QEMU.

   

And add xmlns:qemu="https://libvirt.org/cpufeature/qemu/1.0"; on
the top level.

>  
>
> -   
> +  
> +
>  
>
>
> @@ -110,7 +112,8 @@
>
>  
>
> -   
> +  
> +
>  
>
>
> @@ -149,10 +152,14 @@
>
>  
>
> -   
> +  
> +
> +
>  
>
> -   
> +  
> +
> +
>  
>
>
> @@ -198,7 +205,8 @@
>
>  
>
> -   
> +  
> +
>  
>
>
> @@ -225,7 +233,8 @@
>
>  
>
> -   
> +  
> +
>  
>
>
> @@ -341,7 +350,8 @@
>
>  
>
> -   
> +  
> +
>  
>
>
> @@ -353,7 +363,9 @@
>
>  
>
> -   
> +  
> +
> +
>  
>
>
> @@ -396,13 +408,16 @@
>
>  
>
> -   
> +  
> +
>  
>
>
>  
>
> -   
> +  
> +
> +
>  
>
>
> @@ -411,7 +426,8 @@
>
>  
>
> -   
> +  
> +
>  
>
>
> @@ -422,10 +438,12 @@
>
>  
>
> -   
> +  
> +
>  
>
> -   
> +  
> +
>  
>
>
> @@ -476,7 +494,8 @@
>
>  
>
> -   
> +  
> +
>  
>
>
> @@ -485,10 +504,12 @@
>
>  
>
> -   
> +  
> +
>  
>
> -   
> +  
> +
>  
>
>  
> -- 
> 2.36.1
> 

With regards,
Daniel
-- 
|: https://berrange.com  -o-https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org -o-https://fstop138.berrange.com :|
|: https://entangle-photo.org-o-https://www.instagram.com/dberrange :|



Re: [libvirt PATCH v2 02/24] cpu_x86: Ignore alias names

2022-10-31 Thread Daniel P . Berrangé
On Fri, Oct 28, 2022 at 05:06:33PM +0200, Tim Wiederhake wrote:
> A later patch will add alias names to the feature map. Ignore them for now.
> 
> Signed-off-by: Tim Wiederhake 
> Reviewed-by: Jiri Denemark 
> ---
>  src/cpu/cpu_x86.c | 10 --
>  1 file changed, 8 insertions(+), 2 deletions(-)
> 
> diff --git a/src/cpu/cpu_x86.c b/src/cpu/cpu_x86.c
> index 4d2379803c..d2560de497 100644
> --- a/src/cpu/cpu_x86.c
> +++ b/src/cpu/cpu_x86.c
> @@ -1089,7 +1089,7 @@ static int
>  x86ParseDataItemList(virCPUx86Data *cpudata,
>   xmlNodePtr node)
>  {
> -size_t i;
> +size_t i = 0;
>  
>  if (xmlChildElementCount(node) <= 0) {
>  virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("no x86 CPU data 
> found"));
> @@ -1097,9 +1097,14 @@ x86ParseDataItemList(virCPUx86Data *cpudata,
>  }
>  
>  node = xmlFirstElementChild(node);
> -for (i = 0; node; ++i) {
> +while (node) {
>  virCPUx86DataItem item;
>  
> +if (virXMLNodeNameEqual(node, "alias")) {
> +node = xmlNextElementSibling(node);
> +continue;
> +}

Please put a comment here describing that we're ignoring this because
it is only intended for use by the QEMU sync script.


With regards,
Daniel
-- 
|: https://berrange.com  -o-https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org -o-https://fstop138.berrange.com :|
|: https://entangle-photo.org-o-https://www.instagram.com/dberrange :|