Re: [libvirt PATCH] API: virDomainLookupByID: s/UUId/UUID/

2020-10-04 Thread Pino Toscano
On Monday, 5 October 2020 00:25:53 CEST Ján Tomko wrote:
> Signed-off-by: Ján Tomko 
> ---
>  src/libvirt-domain.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/src/libvirt-domain.c b/src/libvirt-domain.c
> index 415482a526..a7266ccd88 100644
> --- a/src/libvirt-domain.c
> +++ b/src/libvirt-domain.c
> @@ -284,7 +284,7 @@ virDomainCreateLinux(virConnectPtr conn, const char 
> *xmlDesc,
>   *
>   * Try to find a domain based on the hypervisor ID number
>   * Note that this won't work for inactive domains which have an ID of -1,
> - * in that case a lookup based on the Name or UUId need to be done instead.
> + * in that case a lookup based on the Name or UUID need to be done instead.
>   *
>   * virDomainFree should be used to free the resources after the
>   * domain object is no longer needed.

Reviewed-by: Pino Toscano 

-- 
Pino Toscano

signature.asc
Description: This is a digitally signed message part.


Re: [PATCH 7/8] hyperv: implement connectGetVersion

2020-10-04 Thread Pino Toscano
On Saturday, 3 October 2020 01:02:47 CEST Matt Coleman wrote:
> On Oct 2, 2020, at 2:48 AM, Pino Toscano  wrote:
> > IMHO these explanations should be documented in the Hyper-V driver
> > page: docs/drvhyperv.html.in. This way, users know about the different
> > value returned by virConnectGetVersion() by the Hyper-V driver, and
> > can unmangle it to get the real Hyper-V version.
> 
> You’re absolutely right. I’ll add some documentation about this. Would 
> you prefer it as a separate commit or included with the code changes?

IMHO it makes sense in the same commit, as it would be the new logic
and the documentation for it (in both code comments and rST for users)
added at the same time.

-- 
Pino Toscano

signature.asc
Description: This is a digitally signed message part.


Re: [PATCH 3/8] hyperv: break out common lookups into separate functions

2020-10-04 Thread Pino Toscano
On Friday, 2 October 2020 23:50:22 CEST Matt Coleman wrote:
> On Oct 2, 2020, at 2:25 AM, Pino Toscano  wrote:
> > Note that now hypervGetVirtualSystemByID() issues VIR_ERR_INTERNAL_ERROR
> > in case  / *computerSystemList is null, instead of
> > VIR_ERR_NO_DOMAIN. Shouldn't this still be able to explicitly report
> > when the requested domain does not exist?
> 
> I’ll split it up into two conditionals. Would you prefer to see the NULL 
> check that produces the VIR_ERR_NO_DOMAIN error in the new helper 
> function (hypervGetVirtualSystemByID) or its caller 
> (hypervDomainLookupByID)?

This depends on the callers: if the logic for checking whether a domain
is considered "not already existing" makes sense for all the callers of
hypervGetVirtualSystemByID, then I'd say to add it there.

-- 
Pino Toscano

signature.asc
Description: This is a digitally signed message part.


[PATCH] rpm: Enable Xen support on AArch64

2020-10-04 Thread Neal Gompa
Starting with Linux 5.9, Xen Dom0 works on commonly available
AArch64 devices, such as the Raspberry Pi 4.

Reference: https://xenproject.org/2020/09/29/xen-on-raspberry-pi-4-adventures/

Signed-off-by: Neal Gompa 
---
 libvirt.spec.in | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libvirt.spec.in b/libvirt.spec.in
index aa2bc84be9..470782b23e 100644
--- a/libvirt.spec.in
+++ b/libvirt.spec.in
@@ -97,8 +97,8 @@
 
 # Finally set the OS / architecture specific special cases
 
-# Xen is available only on i386 x86_64 ia64
-%ifnarch %{ix86} x86_64 ia64
+# Xen is available only on i386 x86_64 ia64 aarch64
+%ifnarch %{ix86} x86_64 ia64 aarch64
 %define with_libxl 0
 %endif
 
-- 
2.26.2



Re: [PATCH] rpm: Simplify qemu+kvm conditionals and eliminate duplication

2020-10-04 Thread Neal Gompa
On Thu, Sep 24, 2020 at 4:05 PM Neal Gompa  wrote:
>
> The conditionals for enabling qemu+kvm were unnecessarily complex.
> In practice, there were far fewer cases where the functionality would
> be disabled than what the conditional logic expressed, and this change
> simplifies it to the realistic set of options.
>
> Signed-off-by: Neal Gompa 
> ---
>  libvirt.spec.in | 49 +++--
>  1 file changed, 23 insertions(+), 26 deletions(-)
>
> diff --git a/libvirt.spec.in b/libvirt.spec.in
> index c4a7c30737..6940066de9 100644
> --- a/libvirt.spec.in
> +++ b/libvirt.spec.in
> @@ -20,31 +20,12 @@
>
>  %define with_qemu_tcg  %{with_qemu}
>
> -%define qemu_kvm_arches %{ix86} x86_64
> -
> -%if 0%{?fedora}
> -%define qemu_kvm_arches %{ix86} x86_64 %{power64} s390x %{arm} aarch64
> -%endif
> -
> -%if 0%{?rhel}
> -%define with_qemu_tcg 0
> -%define qemu_kvm_arches x86_64 %{power64} aarch64 s390x
> -%endif
> -
>  # On RHEL 7 and older macro _vpath_builddir is not defined.
>  %if 0%{?rhel} && 0%{?rhel} <= 7
>  %define _vpath_builddir %{_target_platform}
>  %endif
>
> -%ifarch %{qemu_kvm_arches}
> -%define with_qemu_kvm  %{with_qemu}
> -%else
> -%define with_qemu_kvm  0
> -%endif
> -
> -%if ! %{with_qemu_tcg} && ! %{with_qemu_kvm}
> -%define with_qemu 0
> -%endif
> +%define with_qemu_kvm  %{with_qemu}
>
>  # Then the hypervisor drivers that run outside libvirtd, in libvirt.so
>  %define with_openvz0%{!?_without_openvz:1}
> @@ -61,12 +42,6 @@
>  %endif
>
>  %define with_storage_gluster 0%{!?_without_storage_gluster:1}
> -%ifnarch %{qemu_kvm_arches}
> -# gluster is only built where qemu driver is enabled on RHEL 8
> -%if 0%{?rhel} >= 8
> -%define with_storage_gluster 0
> -%endif
> -%endif
>
>  %define with_numactl  0%{!?_without_numactl:1}
>
> @@ -97,6 +72,11 @@
>
>  # Finally set the OS / architecture specific special cases
>
> +# KVM is available on most architectures
> +%ifnarch %{ix86} x86_64 %{power64} s390x %{arm} aarch64
> +%define with_qemu_kvm 0
> +%endif
> +
>  # Xen is available only on i386 x86_64 ia64
>  %ifnarch %{ix86} x86_64 ia64
>  %define with_libxl 0
> @@ -122,6 +102,23 @@
>  %define with_storage_rbd 0
>  %endif
>
> +# RHEL does not ship qemu-tcg
> +%if 0%{?rhel}
> +%define with_qemu_tcg 0
> +%endif
> +
> +# In the event that qemu-tcg and qemu-kvm are unavailable, don't ship qemu
> +%if ! %{with_qemu_tcg} && ! %{with_qemu_kvm}
> +%define with_qemu 0
> +%endif
> +
> +%if ! %{with_qemu_kvm}
> +# gluster is only built where qemu driver is enabled on RHEL 8
> +%if 0%{?rhel} >= 8
> +%define with_storage_gluster 0
> +%endif
> +%endif
> +
>  # RHEL doesn't ship OpenVZ, VBox, PowerHypervisor,
>  # VMware, libxenlight (Xen 4.1 and newer),
>  # or HyperV.
> --
> 2.26.2
>

Anyone seen this yet?


-- 
真実はいつも一つ!/ Always, there's only one truth!




[libvirt PATCH] API: discourage usage of non-ListAll APIs

2020-10-04 Thread Ján Tomko
They require the caller to provide the maximum number
of array elements upfront, leading to either incomplete
results or violations of the zero-one-infinity rule.

Signed-off-by: Ján Tomko 
---
 src/libvirt-domain-snapshot.c | 6 --
 src/libvirt-domain.c  | 8 
 src/libvirt-interface.c   | 6 --
 src/libvirt-network.c | 6 --
 src/libvirt-nodedev.c | 3 ++-
 src/libvirt-nwfilter.c| 3 +++
 src/libvirt-secret.c  | 3 +++
 src/libvirt-storage.c | 9 ++---
 8 files changed, 30 insertions(+), 14 deletions(-)

diff --git a/src/libvirt-domain-snapshot.c b/src/libvirt-domain-snapshot.c
index f856e5b9b8..74d5e16281 100644
--- a/src/libvirt-domain-snapshot.c
+++ b/src/libvirt-domain-snapshot.c
@@ -378,8 +378,10 @@ virDomainSnapshotNum(virDomainPtr domain, unsigned int 
flags)
  * snapshots were listed if the return is less than @nameslen.  Likewise,
  * you should be prepared for virDomainSnapshotLookupByName() to fail when
  * converting a name from this call into a snapshot object, if another
- * connection deletes the snapshot in the meantime.  For more control over
- * the results, see virDomainListAllSnapshots().
+ * connection deletes the snapshot in the meantime.
+ *
+ * The use of this function in new code is discouraged. Instead, use
+ * virDomainListAllSnapshots().
  *
  * Returns the number of domain snapshots found or -1 in case of error.
  * The caller is responsible to call free() for each member of the array.
diff --git a/src/libvirt-domain.c b/src/libvirt-domain.c
index 415482a526..03eca1196a 100644
--- a/src/libvirt-domain.c
+++ b/src/libvirt-domain.c
@@ -41,8 +41,8 @@ VIR_LOG_INIT("libvirt.domain");
  *
  * Collect the list of active domains, and store their IDs in array @ids
  *
- * For inactive domains, see virConnectListDefinedDomains().  For more
- * control over the results, see virConnectListAllDomains().
+ * The use of this function in new code is discouraged. Instead, use
+ * virConnectListAllDomains().
  *
  * Returns the number of domains found or -1 in case of error.  Note that
  * this command is inherently racy; a domain can be started between a
@@ -6366,8 +6366,8 @@ virConnectNumOfDefinedDomains(virConnectPtr conn)
  * list the defined but inactive domains, stores the pointers to the names
  * in @names
  *
- * For active domains, see virConnectListDomains().  For more control over
- * the results, see virConnectListAllDomains().
+ * The use of this function in new code is discouraged. Instead, use
+ * virConnectListAllDomains().
  *
  * Returns the number of names provided in the array or -1 in case of error.
  * Note that this command is inherently racy; a domain can be defined between
diff --git a/src/libvirt-interface.c b/src/libvirt-interface.c
index 5eb5980483..271f21b7b5 100644
--- a/src/libvirt-interface.c
+++ b/src/libvirt-interface.c
@@ -150,7 +150,8 @@ virConnectNumOfInterfaces(virConnectPtr conn)
  * Collect the list of active physical host interfaces,
  * and store their names in @names
  *
- * For more control over the results, see virConnectListAllInterfaces().
+ * The use of this function in new code is discouraged. Instead, use
+ * virConnectListAllInterfaces().
  *
  * Returns the number of interfaces found or -1 in case of error.  Note that
  * this command is inherently racy; a interface can be started between a call
@@ -227,7 +228,8 @@ virConnectNumOfDefinedInterfaces(virConnectPtr conn)
  * Collect the list of defined (inactive) physical host interfaces,
  * and store their names in @names.
  *
- * For more control over the results, see virConnectListAllInterfaces().
+ * The use of this function in new code is discouraged. Instead, use
+ * virConnectListAllInterfaces().
  *
  * Returns the number of names provided in the array or -1 in case of error.
  * Note that this command is inherently racy; a interface can be defined 
between
diff --git a/src/libvirt-network.c b/src/libvirt-network.c
index f691b672c7..e6ea66a234 100644
--- a/src/libvirt-network.c
+++ b/src/libvirt-network.c
@@ -159,7 +159,8 @@ virConnectNumOfNetworks(virConnectPtr conn)
  *
  * Collect the list of active networks, and store their names in @names
  *
- * For more control over the results, see virConnectListAllNetworks().
+ * The use of this function in new code is discouraged. Instead, use
+ * virConnectListAllNetworks().
  *
  * Returns the number of networks found or -1 in case of error.  Note that
  * this command is inherently racy; a network can be started between a call
@@ -235,7 +236,8 @@ virConnectNumOfDefinedNetworks(virConnectPtr conn)
  *
  * list the inactive networks, stores the pointers to the names in @names
  *
- * For more control over the results, see virConnectListAllNetworks().
+ * The use of this function in new code is discouraged. Instead, use
+ * virConnectListAllNetworks().
  *
  * Returns the number of names provided in the array or -1 in case of error.
  * Note that this command is inherently 

[libvirt PATCH] API: virDomainLookupByID: s/UUId/UUID/

2020-10-04 Thread Ján Tomko
Signed-off-by: Ján Tomko 
---
 src/libvirt-domain.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/libvirt-domain.c b/src/libvirt-domain.c
index 415482a526..a7266ccd88 100644
--- a/src/libvirt-domain.c
+++ b/src/libvirt-domain.c
@@ -284,7 +284,7 @@ virDomainCreateLinux(virConnectPtr conn, const char 
*xmlDesc,
  *
  * Try to find a domain based on the hypervisor ID number
  * Note that this won't work for inactive domains which have an ID of -1,
- * in that case a lookup based on the Name or UUId need to be done instead.
+ * in that case a lookup based on the Name or UUID need to be done instead.
  *
  * virDomainFree should be used to free the resources after the
  * domain object is no longer needed.
-- 
2.26.2



[libvirt PATCH 3/4] vbox: refactor vboxNetworkGetXMLDesc a bit

2020-10-04 Thread Ján Tomko
Error out on allocation failure to reduce the nesting.

Signed-off-by: Ján Tomko 
---
 src/vbox/vbox_network.c | 102 +++-
 1 file changed, 49 insertions(+), 53 deletions(-)

diff --git a/src/vbox/vbox_network.c b/src/vbox/vbox_network.c
index dafbc114f6..ceffc2053d 100644
--- a/src/vbox/vbox_network.c
+++ b/src/vbox/vbox_network.c
@@ -821,69 +821,65 @@ static char *vboxNetworkGetXMLDesc(virNetworkPtr network, 
unsigned int flags)
   networkNameUtf16,
   );
 if (dhcpServer) {
+PRUnichar *ipAddressUtf16 = NULL;
+PRUnichar *networkMaskUtf16 = NULL;
+PRUnichar *fromIPAddressUtf16 = NULL;
+PRUnichar *toIPAddressUtf16 = NULL;
+PRUnichar *macAddressUtf16 = NULL;
+bool errorOccurred = false;
+
 ipdef->nranges = 1;
-if (VIR_ALLOC_N(ipdef->ranges, ipdef->nranges) >= 0) {
-PRUnichar *ipAddressUtf16 = NULL;
-PRUnichar *networkMaskUtf16 = NULL;
-PRUnichar *fromIPAddressUtf16 = NULL;
-PRUnichar *toIPAddressUtf16 = NULL;
-bool errorOccurred = false;
 
-gVBoxAPI.UIDHCPServer.GetIPAddress(dhcpServer, );
-gVBoxAPI.UIDHCPServer.GetNetworkMask(dhcpServer, 
);
-gVBoxAPI.UIDHCPServer.GetLowerIP(dhcpServer, );
-gVBoxAPI.UIDHCPServer.GetUpperIP(dhcpServer, );
-/* Currently virtualbox supports only one dhcp server per network
- * with contiguous address space from start to end
- */
-addr = ipdef->ranges[0].addr;
-if (vboxSocketParseAddrUtf16(data, ipAddressUtf16,
- >address) < 0 ||
-vboxSocketParseAddrUtf16(data, networkMaskUtf16,
- >netmask) < 0 ||
-vboxSocketParseAddrUtf16(data, fromIPAddressUtf16,
- ) < 0 ||
-vboxSocketParseAddrUtf16(data, toIPAddressUtf16,
- ) < 0) {
-errorOccurred = true;
-}
+if (VIR_ALLOC_N(ipdef->ranges, ipdef->nranges) < 0)
+goto cleanup;
 
-VBOX_UTF16_FREE(ipAddressUtf16);
-VBOX_UTF16_FREE(networkMaskUtf16);
-VBOX_UTF16_FREE(fromIPAddressUtf16);
-VBOX_UTF16_FREE(toIPAddressUtf16);
-
-if (errorOccurred)
-goto cleanup;
-} else {
-ipdef->nranges = 0;
+gVBoxAPI.UIDHCPServer.GetIPAddress(dhcpServer, );
+gVBoxAPI.UIDHCPServer.GetNetworkMask(dhcpServer, );
+gVBoxAPI.UIDHCPServer.GetLowerIP(dhcpServer, );
+gVBoxAPI.UIDHCPServer.GetUpperIP(dhcpServer, );
+/* Currently virtualbox supports only one dhcp server per network
+ * with contiguous address space from start to end
+ */
+addr = ipdef->ranges[0].addr;
+if (vboxSocketParseAddrUtf16(data, ipAddressUtf16,
+ >address) < 0 ||
+vboxSocketParseAddrUtf16(data, networkMaskUtf16,
+ >netmask) < 0 ||
+vboxSocketParseAddrUtf16(data, fromIPAddressUtf16,
+ ) < 0 ||
+vboxSocketParseAddrUtf16(data, toIPAddressUtf16,
+ ) < 0) {
+errorOccurred = true;
 }
 
+VBOX_UTF16_FREE(ipAddressUtf16);
+VBOX_UTF16_FREE(networkMaskUtf16);
+VBOX_UTF16_FREE(fromIPAddressUtf16);
+VBOX_UTF16_FREE(toIPAddressUtf16);
+
+if (errorOccurred)
+goto cleanup;
+
 ipdef->nhosts = 1;
-if (VIR_ALLOC_N(ipdef->hosts, ipdef->nhosts) >= 0) {
-PRUnichar *macAddressUtf16 = NULL;
-PRUnichar *ipAddressUtf16 = NULL;
-bool errorOccurred = false;
+if (VIR_ALLOC_N(ipdef->hosts, ipdef->nhosts) < 0)
+goto cleanup;
 
-ipdef->hosts[0].name = g_strdup(network->name);
-gVBoxAPI.UIHNInterface.GetHardwareAddress(networkInterface, 
);
-gVBoxAPI.UIHNInterface.GetIPAddress(networkInterface, 
);
+ipdef->hosts[0].name = g_strdup(network->name);
+gVBoxAPI.UIHNInterface.GetHardwareAddress(networkInterface, 
);
+gVBoxAPI.UIHNInterface.GetIPAddress(networkInterface, );
 
-VBOX_UTF16_TO_UTF8(macAddressUtf16, >hosts[0].mac);
+VBOX_UTF16_TO_UTF8(macAddressUtf16, >hosts[0].mac);
 
-if (vboxSocketParseAddrUtf16(data, ipAddressUtf16,
- >hosts[0].ip) < 0) {
-errorOccurred = true;
-}
-
-VBOX_UTF16_FREE(macAddressUtf16);
-VBOX_UTF16_FREE(ipAddressUtf16);
-
-if (errorOccurred)
-goto cleanup;
-} else {
-

[libvirt PATCH 3/4] vz: vzEatCookie: separate allocation

2020-10-04 Thread Ján Tomko
Use g_new0 outside of the error condition.

Signed-off-by: Ján Tomko 
---
 src/vz/vz_driver.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/vz/vz_driver.c b/src/vz/vz_driver.c
index dad7fe37b7..a83d4117a4 100644
--- a/src/vz/vz_driver.c
+++ b/src/vz/vz_driver.c
@@ -2807,9 +2807,9 @@ vzEatCookie(const char *cookiein, int cookieinlen, 
unsigned int flags)
 
 if (flags & VZ_MIGRATION_COOKIE_SESSION_UUID) {
 g_autofree char *tmp = NULL;
+mig->session_uuid = g_new0(unsigned char, VIR_UUID_BUFLEN);
 
 if ((!(tmp = virXPathString("string(./session-uuid[1])", ctx))
-|| (VIR_ALLOC_N(mig->session_uuid, VIR_UUID_BUFLEN) < 0)
 || (virUUIDParse(tmp, mig->session_uuid) < 0))) {
 virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("missing or malformed session-uuid element "
@@ -2820,9 +2820,9 @@ vzEatCookie(const char *cookiein, int cookieinlen, 
unsigned int flags)
 
 if (flags & VZ_MIGRATION_COOKIE_DOMAIN_UUID) {
 g_autofree char *tmp = NULL;
+mig->uuid = g_new0(unsigned char, VIR_UUID_BUFLEN);
 
 if ((!(tmp = virXPathString("string(./uuid[1])", ctx))
-|| (VIR_ALLOC_N(mig->uuid, VIR_UUID_BUFLEN) < 0)
 || (virUUIDParse(tmp, mig->uuid) < 0))) {
 virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("missing or malformed uuid element in migration 
data"));
-- 
2.26.2



[libvirt PATCH 2/4] vz: vzEatCookie: use distinct 'tmp' variables

2020-10-04 Thread Ján Tomko
Mark both as g_autofree within their separate scopes.

Signed-off-by: Ján Tomko 
---
 src/vz/vz_driver.c | 9 -
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/src/vz/vz_driver.c b/src/vz/vz_driver.c
index 5b40f9a835..dad7fe37b7 100644
--- a/src/vz/vz_driver.c
+++ b/src/vz/vz_driver.c
@@ -2790,7 +2790,6 @@ vzEatCookie(const char *cookiein, int cookieinlen, 
unsigned int flags)
 {
 xmlDocPtr doc = NULL;
 xmlXPathContextPtr ctx = NULL;
-char *tmp = NULL;
 vzMigrationCookiePtr mig = NULL;
 
 if (VIR_ALLOC(mig) < 0)
@@ -2807,29 +2806,29 @@ vzEatCookie(const char *cookiein, int cookieinlen, 
unsigned int flags)
 goto error;
 
 if (flags & VZ_MIGRATION_COOKIE_SESSION_UUID) {
+g_autofree char *tmp = NULL;
+
 if ((!(tmp = virXPathString("string(./session-uuid[1])", ctx))
 || (VIR_ALLOC_N(mig->session_uuid, VIR_UUID_BUFLEN) < 0)
 || (virUUIDParse(tmp, mig->session_uuid) < 0))) {
 virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("missing or malformed session-uuid element "
  "in migration data"));
-VIR_FREE(tmp);
 goto error;
 }
 }
-VIR_FREE(tmp);
 
 if (flags & VZ_MIGRATION_COOKIE_DOMAIN_UUID) {
+g_autofree char *tmp = NULL;
+
 if ((!(tmp = virXPathString("string(./uuid[1])", ctx))
 || (VIR_ALLOC_N(mig->uuid, VIR_UUID_BUFLEN) < 0)
 || (virUUIDParse(tmp, mig->uuid) < 0))) {
 virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("missing or malformed uuid element in migration 
data"));
-VIR_FREE(tmp);
 goto error;
 }
 }
-VIR_FREE(tmp);
 
 if ((flags & VZ_MIGRATION_COOKIE_DOMAIN_NAME)
 && !(mig->name = virXPathString("string(./name[1])", ctx))) {
-- 
2.26.2



[libvirt PATCH 4/4] vz: use g_new0 instead of VIR_ALLOC

2020-10-04 Thread Ján Tomko
Signed-off-by: Ján Tomko 
---
 src/vz/vz_driver.c | 12 
 src/vz/vz_sdk.c| 46 ++
 src/vz/vz_utils.c  |  3 +--
 3 files changed, 19 insertions(+), 42 deletions(-)

diff --git a/src/vz/vz_driver.c b/src/vz/vz_driver.c
index a83d4117a4..8d47b90bdb 100644
--- a/src/vz/vz_driver.c
+++ b/src/vz/vz_driver.c
@@ -380,8 +380,7 @@ vzConnectOpen(virConnectPtr conn,
 if (!(driver = vzGetDriverConnection()))
 return VIR_DRV_OPEN_ERROR;
 
-if (VIR_ALLOC(privconn) < 0)
-goto error;
+privconn = g_new0(vzConn, 1);
 
 conn->privateData = privconn;
 privconn->driver = driver;
@@ -2792,8 +2791,7 @@ vzEatCookie(const char *cookiein, int cookieinlen, 
unsigned int flags)
 xmlXPathContextPtr ctx = NULL;
 vzMigrationCookiePtr mig = NULL;
 
-if (VIR_ALLOC(mig) < 0)
-return NULL;
+mig = g_new0(vzMigrationCookie, 1);
 
 if (!cookiein || cookieinlen <= 0 || cookiein[cookieinlen - 1] != '\0') {
 virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
@@ -3717,8 +3715,7 @@ vzDomainGetAllStats(virConnectPtr conn,
 virDomainStatsRecordPtr stat;
 int maxparams = 0;
 
-if (VIR_ALLOC(stat) < 0)
-return NULL;
+stat = g_new0(virDomainStatsRecord, 1);
 
 if (vzDomainGetStateStats(dom, stat, ) < 0)
 goto error;
@@ -3802,8 +3799,7 @@ vzConnectGetAllDomainStats(virConnectPtr conn,
 return -1;
 }
 
-if (VIR_ALLOC_N(tmpstats, ndoms + 1) < 0)
-goto cleanup;
+tmpstats = g_new0(virDomainStatsRecordPtr, ndoms + 1);
 
 for (i = 0; i < ndoms; i++) {
 virDomainStatsRecordPtr tmp;
diff --git a/src/vz/vz_sdk.c b/src/vz/vz_sdk.c
index 3e7d55c50b..c6ed9bf9ce 100644
--- a/src/vz/vz_sdk.c
+++ b/src/vz/vz_sdk.c
@@ -70,16 +70,14 @@ logPrlErrorHelper(PRL_RESULT err, const char *filename,
 /* Get required buffer length */
 PrlApi_GetResultDescription(err, PRL_TRUE, PRL_FALSE, NULL, );
 
-if (VIR_ALLOC_N(msg1, len) < 0)
-goto cleanup;
+msg1 = g_new0(char, len);
 
 /* get short error description */
 PrlApi_GetResultDescription(err, PRL_TRUE, PRL_FALSE, msg1, );
 
 PrlApi_GetResultDescription(err, PRL_FALSE, PRL_FALSE, NULL, );
 
-if (VIR_ALLOC_N(msg2, len) < 0)
-goto cleanup;
+msg2 = g_new0(char, len);
 
 /* get long error description */
 PrlApi_GetResultDescription(err, PRL_FALSE, PRL_FALSE, msg2, );
@@ -88,7 +86,6 @@ logPrlErrorHelper(PRL_RESULT err, const char *filename,
  filename, funcname, linenr,
  _("%s %s"), msg1, msg2);
 
- cleanup:
 VIR_FREE(msg1);
 VIR_FREE(msg2);
 }
@@ -122,22 +119,19 @@ logPrlEventErrorHelper(PRL_HANDLE event, const char 
*filename,
 
 PrlEvent_GetErrString(event, PRL_TRUE, PRL_FALSE, NULL, );
 
-if (VIR_ALLOC_N(msg1, len) < 0)
-goto cleanup;
+msg1 = g_new0(char, len);
 
 PrlEvent_GetErrString(event, PRL_TRUE, PRL_FALSE, msg1, );
 
 PrlEvent_GetErrString(event, PRL_FALSE, PRL_FALSE, NULL, );
 
-if (VIR_ALLOC_N(msg2, len) < 0)
-goto cleanup;
+msg2 = g_new0(char, len);
 
 PrlEvent_GetErrString(event, PRL_FALSE, PRL_FALSE, msg2, );
 
 virReportErrorHelper(VIR_FROM_THIS, VIR_ERR_INTERNAL_ERROR,
  filename, funcname, linenr,
  _("%s %s"), msg1, msg2);
- cleanup:
 VIR_FREE(msg1);
 VIR_FREE(msg2);
 }
@@ -306,8 +300,7 @@ prlsdkGetStringParamVar(prlsdkParamGetterType getter, 
PRL_HANDLE handle)
 pret = getter(handle, NULL, );
 prlsdkCheckRetGoto(pret, error);
 
-if (VIR_ALLOC_N(str, buflen) < 0)
-goto error;
+str = g_new0(char, buflen);
 
 pret = getter(handle, str, );
 prlsdkCheckRetGoto(pret, error);
@@ -582,11 +575,8 @@ prlsdkAddDomainVideoInfoVm(PRL_HANDLE sdkdom, 
virDomainDefPtr def)
 ret = PrlVmCfg_GetVideoRamSize(sdkdom, );
 prlsdkCheckRetGoto(ret, error);
 
-if (VIR_ALLOC(video) < 0)
-goto error;
-
-if (VIR_ALLOC(accel) < 0)
-goto error;
+video = g_new0(virDomainVideoDef, 1);
+accel = g_new0(virDomainVideoAccelDef, 1);
 
 if (VIR_APPEND_ELEMENT_COPY(def->videos, def->nvideos, video) < 0)
 goto error;
@@ -773,8 +763,7 @@ prlsdkGetFSInfo(PRL_HANDLE prldisk,
 goto cleanup;
 }
 fs->type = VIR_DOMAIN_FS_TYPE_VOLUME;
-if (VIR_ALLOC(fs->src->srcpool) < 0)
-goto cleanup;
+fs->src->srcpool = g_new0(virStorageSourcePoolDef, 1);
 fs->src->srcpool->pool = g_strdup(matches[1]);
 fs->src->srcpool->volume = g_strdup(matches[2]);
 VIR_FREE(buf);
@@ -914,8 +903,7 @@ prlsdkParseNetAddress(char *addr)
 *maskstr = '\0';
 ++maskstr;
 
-if (VIR_ALLOC(ip) < 0)
-goto cleanup;
+ip = g_new0(virNetDevIPAddr, 1);
 
 if (virSocketAddrParse(>address, addr, AF_UNSPEC) < 0)
 goto cleanup;
@@ -962,8 +950,7 @@ prlsdkGetNetAddresses(PRL_HANDLE sdknet, 

[libvirt PATCH 1/4] vz: separate if conditions in vzEatCookie

2020-10-04 Thread Ján Tomko
Create a separate scope where 'tmp' variable can be used.

Signed-off-by: Ján Tomko 
---
 src/vz/vz_driver.c | 28 +++-
 1 file changed, 15 insertions(+), 13 deletions(-)

diff --git a/src/vz/vz_driver.c b/src/vz/vz_driver.c
index 40b1828eb2..5b40f9a835 100644
--- a/src/vz/vz_driver.c
+++ b/src/vz/vz_driver.c
@@ -2806,26 +2806,28 @@ vzEatCookie(const char *cookiein, int cookieinlen, 
unsigned int flags)
   _("(_migration_cookie)"), )))
 goto error;
 
-if ((flags & VZ_MIGRATION_COOKIE_SESSION_UUID)
-&& (!(tmp = virXPathString("string(./session-uuid[1])", ctx))
+if (flags & VZ_MIGRATION_COOKIE_SESSION_UUID) {
+if ((!(tmp = virXPathString("string(./session-uuid[1])", ctx))
 || (VIR_ALLOC_N(mig->session_uuid, VIR_UUID_BUFLEN) < 0)
 || (virUUIDParse(tmp, mig->session_uuid) < 0))) {
-virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-   _("missing or malformed session-uuid element "
- "in migration data"));
-VIR_FREE(tmp);
-goto error;
+virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+   _("missing or malformed session-uuid element "
+ "in migration data"));
+VIR_FREE(tmp);
+goto error;
+}
 }
 VIR_FREE(tmp);
 
-if ((flags & VZ_MIGRATION_COOKIE_DOMAIN_UUID)
-&& (!(tmp = virXPathString("string(./uuid[1])", ctx))
+if (flags & VZ_MIGRATION_COOKIE_DOMAIN_UUID) {
+if ((!(tmp = virXPathString("string(./uuid[1])", ctx))
 || (VIR_ALLOC_N(mig->uuid, VIR_UUID_BUFLEN) < 0)
 || (virUUIDParse(tmp, mig->uuid) < 0))) {
-virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-   _("missing or malformed uuid element in migration 
data"));
-VIR_FREE(tmp);
-goto error;
+virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+   _("missing or malformed uuid element in migration 
data"));
+VIR_FREE(tmp);
+goto error;
+}
 }
 VIR_FREE(tmp);
 
-- 
2.26.2



[libvirt PATCH] vmware: use g_new0 instead of VIR_ALLOC (glib chronicles)

2020-10-04 Thread Ján Tomko
Signed-off-by: Ján Tomko 
---
 src/vmware/vmware_driver.c |  6 ++---
 src/vmx/vmx.c  | 46 ++
 2 files changed, 14 insertions(+), 38 deletions(-)

diff --git a/src/vmware/vmware_driver.c b/src/vmware/vmware_driver.c
index e82edf2a11..087664a341 100644
--- a/src/vmware/vmware_driver.c
+++ b/src/vmware/vmware_driver.c
@@ -97,8 +97,7 @@ vmwareDataAllocFunc(void *opaque G_GNUC_UNUSED)
 {
 vmwareDomainPtr dom;
 
-if (VIR_ALLOC(dom) < 0)
-return NULL;
+dom = g_new0(vmwareDomain, 1);
 
 dom->vmxPath = NULL;
 dom->gui = true;
@@ -184,8 +183,7 @@ vmwareConnectOpen(virConnectPtr conn,
 /* We now know the URI is definitely for this driver, so beyond
  * here, don't return DECLINED, always use ERROR */
 
-if (VIR_ALLOC(driver) < 0)
-return VIR_DRV_OPEN_ERROR;
+driver = g_new0(struct vmware_driver, 1);
 
 /* Find vmrun, which is what this driver uses to communicate to
  * the VMware hypervisor. We look this up first since we use it
diff --git a/src/vmx/vmx.c b/src/vmx/vmx.c
index 9894d5c0ce..0e8a690d0d 100644
--- a/src/vmx/vmx.c
+++ b/src/vmx/vmx.c
@@ -637,8 +637,7 @@ virVMXEscapeHex(const char *string, char escape, const char 
*special)
 ++length;
 }
 
-if (VIR_ALLOC_N(escaped, length) < 0)
-return NULL;
+escaped = g_new0(char, length);
 
 tmp1 = string; /* reading from this one */
 tmp2 = escaped; /* writing to this one */
@@ -1150,8 +1149,7 @@ virVMXGatherSCSIControllers(virVMXContext *ctx, 
virDomainDefPtr def,
 int count = 0;
 int *autodetectedModels;
 
-if (VIR_ALLOC_N(autodetectedModels, def->ndisks) < 0)
-return -1;
+autodetectedModels = g_new0(int, def->ndisks);
 
 for (i = 0; i < def->ncontrollers; ++i) {
 controller = def->controllers[i];
@@ -1611,9 +1609,7 @@ virVMXParseConfig(virVMXContext *ctx,
 /* FIXME */
 
 /* def:graphics */
-if (VIR_ALLOC_N(def->graphics, 1) < 0)
-goto cleanup;
-
+def->graphics = g_new0(virDomainGraphicsDefPtr, 1);
 def->ngraphics = 0;
 
 if (virVMXParseVNC(conf, >graphics[def->ngraphics]) < 0)
@@ -1623,9 +1619,7 @@ virVMXParseConfig(virVMXContext *ctx,
 ++def->ngraphics;
 
 /* def:disks: 4 * 15 scsi + 2 * 2 ide + 2 floppy = 66 */
-if (VIR_ALLOC_N(def->disks, 66) < 0)
-goto cleanup;
-
+def->disks = g_new0(virDomainDiskDefPtr, 66);
 def->ndisks = 0;
 
 /* def:disks (scsi) */
@@ -1733,9 +1727,7 @@ virVMXParseConfig(virVMXContext *ctx,
 if (sharedFolder_maxNum > 0) {
 int number;
 
-if (VIR_ALLOC_N(def->fss, sharedFolder_maxNum) < 0)
-goto cleanup;
-
+def->fss = g_new0(virDomainFSDefPtr, sharedFolder_maxNum);
 def->nfss = 0;
 
 for (number = 0; number < sharedFolder_maxNum; ++number) {
@@ -1767,9 +1759,7 @@ virVMXParseConfig(virVMXContext *ctx,
 /* FIXME */
 
 /* def:videos */
-if (VIR_ALLOC_N(def->videos, 1) < 0)
-goto cleanup;
-
+def->videos = g_new0(virDomainVideoDefPtr, 1);
 def->nvideos = 0;
 
 if (virVMXParseSVGA(conf, >videos[def->nvideos]) < 0)
@@ -1784,9 +1774,7 @@ virVMXParseConfig(virVMXContext *ctx,
 /* FIXME */
 
 /* def:serials */
-if (VIR_ALLOC_N(def->serials, 4) < 0)
-goto cleanup;
-
+def->serials = g_new0(virDomainChrDefPtr, 4);
 def->nserials = 0;
 
 for (port = 0; port < 4; ++port) {
@@ -1800,9 +1788,7 @@ virVMXParseConfig(virVMXContext *ctx,
 }
 
 /* def:parallels */
-if (VIR_ALLOC_N(def->parallels, 3) < 0)
-goto cleanup;
-
+def->parallels = g_new0(virDomainChrDefPtr, 3);
 def->nparallels = 0;
 
 for (port = 0; port < 3; ++port) {
@@ -1819,10 +1805,7 @@ virVMXParseConfig(virVMXContext *ctx,
 if (ctx->datacenterPath || ctx->moref) {
 struct virVMXDomainDefNamespaceData *nsdata = NULL;
 
-if (VIR_ALLOC(nsdata) < 0) {
-virVMXDomainDefNamespaceFree(nsdata);
-goto cleanup;
-}
+nsdata = g_new0(struct virVMXDomainDefNamespaceData, 1);
 
 nsdata->datacenterPath = g_strdup(ctx->datacenterPath);
 
@@ -1891,9 +1874,7 @@ virVMXParseVNC(virConfPtr conf, virDomainGraphicsDefPtr 
*def)
 if (! enabled)
 return 0;
 
-if (VIR_ALLOC(*def) < 0)
-goto failure;
-
+*def = g_new0(virDomainGraphicsDef, 1);
 (*def)->type = VIR_DOMAIN_GRAPHICS_TYPE_VNC;
 
 if (virVMXGetConfigLong(conf, "RemoteDisplay.vnc.port", , -1,
@@ -2588,8 +2569,7 @@ virVMXParseEthernet(virConfPtr conf, int controller, 
virDomainNetDefPtr *def)
 if (! present/* && ! startConnected*/)
 return 0;
 
-if (VIR_ALLOC(*def) < 0)
-return -1;
+*def = g_new0(virDomainNetDef, 1);
 
 /* vmx:connectionType -> def:type */
 if (virVMXGetConfigString(conf, connectionType_name, ,
@@ -3040,9 +3020,7 @@ virVMXParseSVGA(virConfPtr conf, virDomainVideoDefPtr 
*def)
 return -1;
 

[libvirt PATCH 0/4] vz: use g_new0 (glib chronicles)

2020-10-04 Thread Ján Tomko
Ján Tomko (4):
  vz: separate if conditions in vzEatCookie
  vz: vzEatCookie: use distinct 'tmp' variables
  vz: vzEatCookie: separate allocation
  vz: use g_new0 instead of VIR_ALLOC

 src/vz/vz_driver.c | 49 ++
 src/vz/vz_sdk.c| 46 +--
 src/vz/vz_utils.c  |  3 +--
 3 files changed, 38 insertions(+), 60 deletions(-)

-- 
2.26.2



[libvirt PATCH 4/4] vbox: use g_new0 instead of VIR_ALLOC

2020-10-04 Thread Ján Tomko
Signed-off-by: Ján Tomko 
---
 src/vbox/vbox_common.c| 90 +++
 src/vbox/vbox_network.c   | 13 ++---
 src/vbox/vbox_snapshot_conf.c | 48 ---
 3 files changed, 53 insertions(+), 98 deletions(-)

diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c
index f59af697ea..317fb5ce92 100644
--- a/src/vbox/vbox_common.c
+++ b/src/vbox/vbox_common.c
@@ -3010,8 +3010,7 @@ vboxHostDeviceGetXMLDesc(vboxDriverPtr data, 
virDomainDefPtr def, IMachine *mach
 goto release_filters;
 
 /* Alloc mem needed for the filters now */
-if (VIR_ALLOC_N(def->hostdevs, def->nhostdevs) < 0)
-goto release_filters;
+def->hostdevs = g_new0(virDomainHostdevDefPtr, def->nhostdevs);
 
 for (i = 0; i < def->nhostdevs; i++) {
 def->hostdevs[i] = virDomainHostdevDefNew();
@@ -3219,8 +3218,7 @@ vboxDumpDisks(virDomainDefPtr def, vboxDriverPtr data, 
IMachine *machine)
 }
 
 /* Allocate mem, if fails return error */
-if (VIR_ALLOC_N(def->disks, def->ndisks) < 0)
-goto cleanup;
+def->disks = g_new0(virDomainDiskDefPtr, def->ndisks);
 
 for (i = 0; i < def->ndisks; i++) {
 disk = virDomainDiskDefNew(NULL);
@@ -3452,12 +3450,10 @@ vboxDumpVideo(virDomainDefPtr def, vboxDriverPtr data 
G_GNUC_UNUSED,
 PRBool accelerate2DEnabled = PR_FALSE;
 
 /* Currently supports only one graphics card */
-if (VIR_ALLOC_N(def->videos, 1) < 0)
-return -1;
+def->videos = g_new0(virDomainVideoDefPtr, 1);
 def->nvideos = 1;
 
-if (VIR_ALLOC(def->videos[0]) < 0)
-return -1;
+def->videos[0] = g_new0(virDomainVideoDef, 1);
 
 gVBoxAPI.UIMachine.GetVRAMSize(machine, );
 gVBoxAPI.UIMachine.GetMonitorCount(machine, );
@@ -3467,8 +3463,7 @@ vboxDumpVideo(virDomainDefPtr def, vboxDriverPtr data 
G_GNUC_UNUSED,
 def->videos[0]->type = VIR_DOMAIN_VIDEO_TYPE_VBOX;
 def->videos[0]->vram = VRAMSize * 1024;
 def->videos[0]->heads = monitorCount;
-if (VIR_ALLOC(def->videos[0]->accel) < 0)
-return -1;
+def->videos[0]->accel = g_new0(virDomainVideoAccelDef, 1);
 def->videos[0]->accel->accel3d = accelerate3DEnabled ?
 VIR_TRISTATE_BOOL_YES : VIR_TRISTATE_BOOL_NO;
 def->videos[0]->accel->accel2d = accelerate2DEnabled ?
@@ -3506,8 +3501,7 @@ vboxDumpDisplay(virDomainDefPtr def, vboxDriverPtr data, 
IMachine *machine)
 PRUnichar *valueDisplayUtf16 = NULL;
 char *valueDisplayUtf8 = NULL;
 
-if (VIR_ALLOC(graphics) < 0)
-goto cleanup;
+graphics = g_new0(virDomainGraphicsDef, 1);
 
 VBOX_UTF8_TO_UTF16("FRONTEND/Display", );
 gVBoxAPI.UIMachine.GetExtraData(machine, keyUtf16, );
@@ -3534,8 +3528,7 @@ vboxDumpDisplay(virDomainDefPtr def, vboxDriverPtr data, 
IMachine *machine)
 }
 VBOX_UTF8_FREE(valueDisplayUtf8);
 } else if (STRNEQ_NULLABLE(valueTypeUtf8, "vrdp")) {
-if (VIR_ALLOC(graphics) < 0)
-goto cleanup;
+graphics = g_new0(virDomainGraphicsDef, 1);
 
 graphics->type = VIR_DOMAIN_GRAPHICS_TYPE_DESKTOP;
 graphics->data.desktop.display = g_strdup(getenv("DISPLAY"));
@@ -3554,8 +3547,7 @@ vboxDumpDisplay(virDomainDefPtr def, vboxDriverPtr data, 
IMachine *machine)
 PRBool allowMultiConnection = PR_FALSE;
 PRBool reuseSingleConnection = PR_FALSE;
 
-if (VIR_ALLOC(graphics) < 0)
-goto cleanup;
+graphics = g_new0(virDomainGraphicsDef, 1);
 
 gVBoxAPI.UIVRDEServer.GetPorts(data, VRDEServer, machine, graphics);
 
@@ -3612,8 +3604,7 @@ vboxDumpSharedFolders(virDomainDefPtr def, vboxDriverPtr 
data, IMachine *machine
 goto cleanup;
 }
 
-if (VIR_ALLOC_N(def->fss, sharedFolders.count) < 0)
-goto cleanup;
+def->fss = g_new0(virDomainFSDefPtr, sharedFolders.count);
 
 for (i = 0; i < sharedFolders.count; i++) {
 ISharedFolder *sharedFolder = sharedFolders.items[i];
@@ -3798,10 +3789,8 @@ vboxDumpAudio(virDomainDefPtr def, vboxDriverPtr data 
G_GNUC_UNUSED,
 PRUint32 audioController = AudioControllerType_AC97;
 
 def->nsounds = 1;
-if (VIR_ALLOC_N(def->sounds, def->nsounds) < 0)
-return;
-if (VIR_ALLOC(def->sounds[0]) < 0)
-return;
+def->sounds = g_new0(virDomainSoundDefPtr, def->nsounds);
+def->sounds[0] = g_new0(virDomainSoundDef, 1);
 
 gVBoxAPI.UIAudioAdapter.GetAudioController(audioAdapter, 
);
 if (audioController == AudioControllerType_SB16) {
@@ -3839,8 +3828,7 @@ vboxDumpSerial(virDomainDefPtr def, vboxDriverPtr data, 
IMachine *machine, PRUin
 
 /* Allocate memory for the serial ports which are enabled */
 if (def->nserials > 0) {
-if (VIR_ALLOC_N(def->serials, def->nserials) < 0)
-return -1;
+def->serials = g_new0(virDomainChrDefPtr, def->nserials);
 
 for (i = 0; i < 

[libvirt PATCH 5/8] esx: esxConnectOpen: use allocated buffer

2020-10-04 Thread Ján Tomko
Signed-off-by: Ján Tomko 
---
 src/esx/esx_driver.c | 7 ---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/src/esx/esx_driver.c b/src/esx/esx_driver.c
index e82e5ed835..0798493296 100644
--- a/src/esx/esx_driver.c
+++ b/src/esx/esx_driver.c
@@ -813,7 +813,7 @@ esxConnectOpen(virConnectPtr conn, virConnectAuthPtr auth,
 virDrvOpenStatus result = VIR_DRV_OPEN_ERROR;
 esxPrivate *priv = NULL;
 char *potentialVCenterIPAddress = NULL;
-char vCenterIPAddress[NI_MAXHOST] = "";
+g_autofree char *vCenterIPAddress = g_new0(char, NI_MAXHOST);
 
 virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR);
 
@@ -875,8 +875,9 @@ esxConnectOpen(virConnectPtr conn, virConnectAuthPtr auth,
 goto cleanup;
 }
 
-if (virStrcpyStatic(vCenterIPAddress,
-potentialVCenterIPAddress) < 0) {
+if (virStrcpy(vCenterIPAddress,
+  potentialVCenterIPAddress,
+  NI_MAXHOST) < 0) {
 virReportError(VIR_ERR_INTERNAL_ERROR,
_("vCenter IP address %s too big for 
destination"),
potentialVCenterIPAddress);
-- 
2.26.2



[libvirt PATCH 3/8] libxl: libxlDomainStart: use g_auto more

2020-10-04 Thread Ján Tomko
Signed-off-by: Ján Tomko 
---
 src/libxl/libxl_domain.c | 9 +++--
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/src/libxl/libxl_domain.c b/src/libxl/libxl_domain.c
index 034be2ddd7..b49ca83c10 100644
--- a/src/libxl/libxl_domain.c
+++ b/src/libxl/libxl_domain.c
@@ -1266,16 +1266,16 @@ libxlDomainStart(libxlDriverPrivatePtr driver,
 libxlSavefileHeader hdr;
 int ret = -1;
 uint32_t domid = 0;
-char *dom_xml = NULL;
+g_autofree char *dom_xml = NULL;
 g_autofree char *managed_save_path = NULL;
-int managed_save_fd = -1;
+VIR_AUTOCLOSE managed_save_fd = -1;
 libxlDomainObjPrivatePtr priv = vm->privateData;
 g_autoptr(libxlDriverConfig) cfg = libxlDriverConfigGet(driver);
 virHostdevManagerPtr hostdev_mgr = driver->hostdevMgr;
 libxl_asyncprogress_how aop_console_how;
 libxl_domain_restore_params params;
 unsigned int hostdev_flags = VIR_HOSTDEV_SP_PCI;
-char *config_json = NULL;
+g_autofree char *config_json = NULL;
 
 #ifdef LIBXL_HAVE_PVUSB
 hostdev_flags |= VIR_HOSTDEV_SP_USB;
@@ -1516,9 +1516,6 @@ libxlDomainStart(libxlDriverPrivatePtr driver,
 
  cleanup:
 libxl_domain_config_dispose(_config);
-VIR_FREE(config_json);
-VIR_FREE(dom_xml);
-VIR_FORCE_CLOSE(managed_save_fd);
 return ret;
 }
 
-- 
2.26.2



[libvirt PATCH 2/4] vbox: invert condition in vboxSnapshotGetReadOnlyDisks

2020-10-04 Thread Ján Tomko
Error out on (impossible) failed allocation, to reduce
indentation.

Signed-off-by: Ján Tomko 
---
 src/vbox/vbox_common.c | 15 +++
 1 file changed, 7 insertions(+), 8 deletions(-)

diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c
index 45fd670a11..f59af697ea 100644
--- a/src/vbox/vbox_common.c
+++ b/src/vbox/vbox_common.c
@@ -5971,15 +5971,14 @@ vboxSnapshotGetReadOnlyDisks(virDomainSnapshotDefPtr 
def,
 }
 
 /* Allocate mem, if fails return error */
-if (VIR_ALLOC_N(defdom->disks, defdom->ndisks) >= 0) {
-for (i = 0; i < defdom->ndisks; i++) {
-virDomainDiskDefPtr diskDef = virDomainDiskDefNew(NULL);
-if (!diskDef)
-goto cleanup;
-defdom->disks[i] = diskDef;
-}
-} else {
+if (VIR_ALLOC_N(defdom->disks, defdom->ndisks) < 0)
 goto cleanup;
+
+for (i = 0; i < defdom->ndisks; i++) {
+virDomainDiskDefPtr diskDef = virDomainDiskDefNew(NULL);
+if (!diskDef)
+goto cleanup;
+defdom->disks[i] = diskDef;
 }
 
 /* get the attachment details here */
-- 
2.26.2



[libvirt PATCH 0/4] vbox: use g_new0 (glib chronicles)

2020-10-04 Thread Ján Tomko
Ján Tomko (4):
  vbox: use g_new0 in vboxDumpAudio
  vbox: invert condition in vboxSnapshotGetReadOnlyDisks
  vbox: refactor vboxNetworkGetXMLDesc a bit
  vbox: use g_new0 instead of VIR_ALLOC

 src/vbox/vbox_common.c| 119 --
 src/vbox/vbox_network.c   | 107 ++
 src/vbox/vbox_snapshot_conf.c |  48 ++
 3 files changed, 110 insertions(+), 164 deletions(-)

-- 
2.26.2



[libvirt PATCH 8/8] build: lower maximum frame size to 1792

2020-10-04 Thread Ján Tomko
This number is the closest multiple of 1
above the largest frame value reported by clang
in the current codebase.

Signed-off-by: Ján Tomko 
---
 meson.build | 7 +++
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/meson.build b/meson.build
index a5ce8e17a8..8bef701f67 100644
--- a/meson.build
+++ b/meson.build
@@ -419,10 +419,9 @@ cc_flags += [
   # but need to rewrite various areas of code first
   '-Wno-format-truncation',
 
-  # This should be < 256 really. Currently we're down to 4096,
-  # but using 1024 bytes sized buffers (mostly for virStrerror)
-  # stops us from going down further
-  '-Wframe-larger-than=4096',
+  # This should be < 256 really.
+  # Using 1024 bytes sized buffers stops us from going down further
+  '-Wframe-larger-than=1792',
 
   # extra special flags
   '-fexceptions',
-- 
2.26.2



[libvirt PATCH 1/4] vbox: use g_new0 in vboxDumpAudio

2020-10-04 Thread Ján Tomko
Elimination of the positive conditions reduces
the indentation by two levels.

Signed-off-by: Ján Tomko 
---
 src/vbox/vbox_common.c | 24 ++--
 1 file changed, 10 insertions(+), 14 deletions(-)

diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c
index 9f6ef2f2ac..45fd670a11 100644
--- a/src/vbox/vbox_common.c
+++ b/src/vbox/vbox_common.c
@@ -3798,20 +3798,16 @@ vboxDumpAudio(virDomainDefPtr def, vboxDriverPtr data 
G_GNUC_UNUSED,
 PRUint32 audioController = AudioControllerType_AC97;
 
 def->nsounds = 1;
-if (VIR_ALLOC_N(def->sounds, def->nsounds) >= 0) {
-if (VIR_ALLOC(def->sounds[0]) >= 0) {
-gVBoxAPI.UIAudioAdapter.GetAudioController(audioAdapter, 
);
-if (audioController == AudioControllerType_SB16) {
-def->sounds[0]->model = VIR_DOMAIN_SOUND_MODEL_SB16;
-} else if (audioController == AudioControllerType_AC97) {
-def->sounds[0]->model = VIR_DOMAIN_SOUND_MODEL_AC97;
-}
-} else {
-VIR_FREE(def->sounds);
-def->nsounds = 0;
-}
-} else {
-def->nsounds = 0;
+if (VIR_ALLOC_N(def->sounds, def->nsounds) < 0)
+return;
+if (VIR_ALLOC(def->sounds[0]) < 0)
+return;
+
+gVBoxAPI.UIAudioAdapter.GetAudioController(audioAdapter, 
);
+if (audioController == AudioControllerType_SB16) {
+def->sounds[0]->model = VIR_DOMAIN_SOUND_MODEL_SB16;
+} else if (audioController == AudioControllerType_AC97) {
+def->sounds[0]->model = VIR_DOMAIN_SOUND_MODEL_AC97;
 }
 }
 VBOX_RELEASE(audioAdapter);
-- 
2.26.2



[libvirt PATCH 1/8] libxl: libxlDomainStart: use g_autoptr for virDomainDef

2020-10-04 Thread Ján Tomko
Signed-off-by: Ján Tomko 
---
 src/libxl/libxl_domain.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/src/libxl/libxl_domain.c b/src/libxl/libxl_domain.c
index a3f362a0c8..c96aeab04b 100644
--- a/src/libxl/libxl_domain.c
+++ b/src/libxl/libxl_domain.c
@@ -1261,7 +1261,7 @@ libxlDomainStart(libxlDriverPrivatePtr driver,
  uint32_t restore_ver LIBXL_DOMSTART_RESTORE_VER_ATTR)
 {
 libxl_domain_config d_config;
-virDomainDefPtr def = NULL;
+g_autoptr(virDomainDef) def = NULL;
 virObjectEventPtr event = NULL;
 libxlSavefileHeader hdr;
 int ret = -1;
@@ -1520,7 +1520,6 @@ libxlDomainStart(libxlDriverPrivatePtr driver,
 VIR_FREE(config_json);
 VIR_FREE(dom_xml);
 VIR_FREE(managed_save_path);
-virDomainDefFree(def);
 VIR_FORCE_CLOSE(managed_save_fd);
 return ret;
 }
-- 
2.26.2



[libvirt PATCH 2/8] libxl: libxlDomainStart: autofree managed_save_path

2020-10-04 Thread Ján Tomko
It is only used once, so it's pointless to free it both in the code
and in the cleanup section.

Signed-off-by: Ján Tomko 
---
 src/libxl/libxl_domain.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/src/libxl/libxl_domain.c b/src/libxl/libxl_domain.c
index c96aeab04b..034be2ddd7 100644
--- a/src/libxl/libxl_domain.c
+++ b/src/libxl/libxl_domain.c
@@ -1267,7 +1267,7 @@ libxlDomainStart(libxlDriverPrivatePtr driver,
 int ret = -1;
 uint32_t domid = 0;
 char *dom_xml = NULL;
-char *managed_save_path = NULL;
+g_autofree char *managed_save_path = NULL;
 int managed_save_fd = -1;
 libxlDomainObjPrivatePtr priv = vm->privateData;
 g_autoptr(libxlDriverConfig) cfg = libxlDriverConfigGet(driver);
@@ -1323,7 +1323,6 @@ libxlDomainStart(libxlDriverPrivatePtr driver,
 
 vm->hasManagedSave = false;
 }
-VIR_FREE(managed_save_path);
 }
 
 if (virDomainObjSetDefTransient(driver->xmlopt, vm, NULL) < 0)
@@ -1519,7 +1518,6 @@ libxlDomainStart(libxlDriverPrivatePtr driver,
 libxl_domain_config_dispose(_config);
 VIR_FREE(config_json);
 VIR_FREE(dom_xml);
-VIR_FREE(managed_save_path);
 VIR_FORCE_CLOSE(managed_save_fd);
 return ret;
 }
-- 
2.26.2



[libvirt PATCH 4/8] libxl: allocate d_config

2020-10-04 Thread Ján Tomko
clang reports:

  stack frame size of 2152 bytes in function 'libxlDomainStart'

This is mostly due to the d_config variable:

  sizeof(libxl_domain_config) = 1232

Use g_new0 to allocate it and bring the frame size down.

Signed-off-by: Ján Tomko 
---
 src/libxl/libxl_domain.c | 24 +---
 1 file changed, 13 insertions(+), 11 deletions(-)

diff --git a/src/libxl/libxl_domain.c b/src/libxl/libxl_domain.c
index b49ca83c10..6336c87746 100644
--- a/src/libxl/libxl_domain.c
+++ b/src/libxl/libxl_domain.c
@@ -1260,7 +1260,7 @@ libxlDomainStart(libxlDriverPrivatePtr driver,
  int restore_fd,
  uint32_t restore_ver LIBXL_DOMSTART_RESTORE_VER_ATTR)
 {
-libxl_domain_config d_config;
+g_autofree libxl_domain_config *d_config = NULL;
 g_autoptr(virDomainDef) def = NULL;
 virObjectEventPtr event = NULL;
 libxlSavefileHeader hdr;
@@ -1281,7 +1281,9 @@ libxlDomainStart(libxlDriverPrivatePtr driver,
 hostdev_flags |= VIR_HOSTDEV_SP_USB;
 #endif
 
-libxl_domain_config_init(_config);
+d_config = g_new0(libxl_domain_config, 1);
+
+libxl_domain_config_init(d_config);
 
 /* If there is a managed saved state restore it instead of starting
  * from scratch. The old state is removed once the restoring succeeded. */
@@ -1356,10 +1358,10 @@ libxlDomainStart(libxlDriverPrivatePtr driver,
 goto cleanup_dom;
 
 if (libxlBuildDomainConfig(driver->reservedGraphicsPorts, vm->def,
-   cfg, _config) < 0)
+   cfg, d_config) < 0)
 goto cleanup_dom;
 
-if (cfg->autoballoon && libxlDomainFreeMem(cfg->ctx, _config) < 0)
+if (cfg->autoballoon && libxlDomainFreeMem(cfg->ctx, d_config) < 0)
 goto cleanup_dom;
 
 if (virHostdevPrepareDomainDevices(hostdev_mgr, LIBXL_DRIVER_INTERNAL_NAME,
@@ -1399,14 +1401,14 @@ libxlDomainStart(libxlDriverPrivatePtr driver,
 aop_console_how.for_callback = vm;
 aop_console_how.callback = libxlConsoleCallback;
 if (restore_fd < 0) {
-ret = libxl_domain_create_new(cfg->ctx, _config,
+ret = libxl_domain_create_new(cfg->ctx, d_config,
   , NULL, _console_how);
 } else {
 libxl_domain_restore_params_init();
 #ifdef LIBXL_HAVE_SRM_V2
 params.stream_version = restore_ver;
 #endif
-ret = libxl_domain_create_restore(cfg->ctx, _config, ,
+ret = libxl_domain_create_restore(cfg->ctx, d_config, ,
   restore_fd, , NULL,
   _console_how);
 libxl_domain_restore_params_dispose();
@@ -1417,11 +1419,11 @@ libxlDomainStart(libxlDriverPrivatePtr driver,
 if (restore_fd < 0)
 virReportError(VIR_ERR_INTERNAL_ERROR,
_("libxenlight failed to create new domain '%s'"),
-   d_config.c_info.name);
+   d_config->c_info.name);
 else
 virReportError(VIR_ERR_INTERNAL_ERROR,
_("libxenlight failed to restore domain '%s'"),
-   d_config.c_info.name);
+   d_config->c_info.name);
 goto cleanup_dom;
 }
 
@@ -1430,7 +1432,7 @@ libxlDomainStart(libxlDriverPrivatePtr driver,
  * be cleaned up if there are any subsequent failures.
  */
 vm->def->id = domid;
-config_json = libxl_domain_config_to_json(cfg->ctx, _config);
+config_json = libxl_domain_config_to_json(cfg->ctx, d_config);
 
 libxlLoggerOpenFile(cfg->logger, domid, vm->def->name, config_json);
 
@@ -1445,7 +1447,7 @@ libxlDomainStart(libxlDriverPrivatePtr driver,
 if (libxl_evenable_domain_death(cfg->ctx, vm->def->id, 0, >deathW))
 goto destroy_dom;
 
-libxlDomainCreateIfaceNames(vm->def, _config);
+libxlDomainCreateIfaceNames(vm->def, d_config);
 libxlDomainUpdateDiskParams(vm->def, cfg->ctx);
 
 #ifdef LIBXL_HAVE_DEVICE_CHANNEL
@@ -1515,7 +1517,7 @@ libxlDomainStart(libxlDriverPrivatePtr driver,
 libxlDomainCleanup(driver, vm);
 
  cleanup:
-libxl_domain_config_dispose(_config);
+libxl_domain_config_dispose(d_config);
 return ret;
 }
 
-- 
2.26.2



[libvirt PATCH 6/8] lxc: virLXCProcessStart: use allocated buffers

2020-10-04 Thread Ján Tomko
Lower the stack frame by using allocated buffers.

Signed-off-by: Ján Tomko 
---
 src/lxc/lxc_process.c | 19 +++
 1 file changed, 11 insertions(+), 8 deletions(-)

diff --git a/src/lxc/lxc_process.c b/src/lxc/lxc_process.c
index 16969dbf33..bf050416c0 100644
--- a/src/lxc/lxc_process.c
+++ b/src/lxc/lxc_process.c
@@ -1185,7 +1185,6 @@ int virLXCProcessStart(virConnectPtr conn,
 VIR_AUTOSTRINGLIST veths = NULL;
 int handshakefds[2] = { -1, -1 };
 off_t pos = -1;
-char ebuf[1024];
 g_autofree char *timestamp = NULL;
 int nsInheritFDs[VIR_LXC_DOMAIN_NAMESPACE_LAST];
 virCommandPtr cmd = NULL;
@@ -1402,13 +1401,14 @@ int virLXCProcessStart(virConnectPtr conn,
 goto cleanup;
 
 if (status != 0) {
+g_autofree char *ebuf = g_new0(char, BUFSIZ);
 if (virLXCProcessReadLogOutput(vm, logfile, pos, ebuf,
-   sizeof(ebuf)) <= 0) {
+   BUFSIZ) <= 0) {
 if (WIFEXITED(status))
-g_snprintf(ebuf, sizeof(ebuf), _("unexpected exit status %d"),
+g_snprintf(ebuf, BUFSIZ, _("unexpected exit status %d"),
WEXITSTATUS(status));
 else
-g_snprintf(ebuf, sizeof(ebuf), "%s", _("terminated 
abnormally"));
+g_snprintf(ebuf, BUFSIZ, "%s", _("terminated abnormally"));
 }
 virReportError(VIR_ERR_INTERNAL_ERROR,
_("guest failed to start: %s"), ebuf);
@@ -1417,7 +1417,8 @@ int virLXCProcessStart(virConnectPtr conn,
 
 /* It has started running, so get its pid */
 if ((r = virPidFileReadPath(pidfile, >pid)) < 0) {
-if (virLXCProcessReadLogOutput(vm, logfile, pos, ebuf, sizeof(ebuf)) > 
0)
+g_autofree char *ebuf = g_new0(char, BUFSIZ);
+if (virLXCProcessReadLogOutput(vm, logfile, pos, ebuf, BUFSIZ) > 0)
 virReportError(VIR_ERR_INTERNAL_ERROR,
_("guest failed to start: %s"), ebuf);
 else
@@ -1454,9 +1455,9 @@ int virLXCProcessStart(virConnectPtr conn,
 driver->inhibitCallback(true, driver->inhibitOpaque);
 
 if (lxcContainerWaitForContinue(handshakefds[0]) < 0) {
-char out[1024];
+g_autofree char *out = g_new0(char, BUFSIZ);
 
-if (!(virLXCProcessReadLogOutput(vm, logfile, pos, out, 1024) < 0)) {
+if (!(virLXCProcessReadLogOutput(vm, logfile, pos, out, BUFSIZ) < 0)) {
 virReportError(VIR_ERR_INTERNAL_ERROR,
_("guest failed to start: %s"), out);
 }
@@ -1486,10 +1487,12 @@ int virLXCProcessStart(virConnectPtr conn,
 
 /* And we can get the first monitor connection now too */
 if (!(priv->monitor = virLXCProcessConnectMonitor(driver, vm))) {
+g_autofree char *ebuf = g_new0(char, BUFSIZ);
+
 /* Intentionally overwrite the real monitor error message,
  * since a better one is almost always found in the logs
  */
-if (virLXCProcessReadLogOutput(vm, logfile, pos, ebuf, sizeof(ebuf)) > 
0) {
+if (virLXCProcessReadLogOutput(vm, logfile, pos, ebuf, BUFSIZ) > 0) {
 virResetLastError();
 virReportError(VIR_ERR_INTERNAL_ERROR,
_("guest failed to start: %s"), ebuf);
-- 
2.26.2



[libvirt PATCH 7/8] remote: allocate virDomainDef for ACL check

2020-10-04 Thread Ján Tomko
Use explicit g_free in the cleanup section, since we're not
dealing with a proper virDomainDef, but just a shallow
copy.

Signed-off-by: Ján Tomko 
---
 src/remote/remote_daemon_dispatch.c | 19 ++-
 1 file changed, 10 insertions(+), 9 deletions(-)

diff --git a/src/remote/remote_daemon_dispatch.c 
b/src/remote/remote_daemon_dispatch.c
index c187932a3c..fc90bd1251 100644
--- a/src/remote/remote_daemon_dispatch.c
+++ b/src/remote/remote_daemon_dispatch.c
@@ -158,25 +158,25 @@ static bool
 remoteRelayDomainEventCheckACL(virNetServerClientPtr client,
virConnectPtr conn, virDomainPtr dom)
 {
-virDomainDef def;
+virDomainDefPtr def = g_new0(virDomainDef, 1);
 g_autoptr(virIdentity) identity = NULL;
 bool ret = false;
 
 /* For now, we just create a virDomainDef with enough contents to
  * satisfy what viraccessdriverpolkit.c references.  This is a bit
  * fragile, but I don't know of anything better.  */
-memset(, 0, sizeof(def));
-def.name = dom->name;
-memcpy(def.uuid, dom->uuid, VIR_UUID_BUFLEN);
+def->name = dom->name;
+memcpy(def->uuid, dom->uuid, VIR_UUID_BUFLEN);
 
 if (!(identity = virNetServerClientGetIdentity(client)))
 goto cleanup;
 if (virIdentitySetCurrent(identity) < 0)
 goto cleanup;
-ret = virConnectDomainEventRegisterAnyCheckACL(conn, );
+ret = virConnectDomainEventRegisterAnyCheckACL(conn, def);
 
  cleanup:
 ignore_value(virIdentitySetCurrent(NULL));
+g_free(def); /* shallow free */
 return ret;
 }
 
@@ -288,24 +288,25 @@ static bool
 remoteRelayDomainQemuMonitorEventCheckACL(virNetServerClientPtr client,
   virConnectPtr conn, virDomainPtr dom)
 {
-virDomainDef def;
+virDomainDefPtr def = g_new0(virDomainDef, 1);
 g_autoptr(virIdentity) identity = NULL;
 bool ret = false;
 
 /* For now, we just create a virDomainDef with enough contents to
  * satisfy what viraccessdriverpolkit.c references.  This is a bit
  * fragile, but I don't know of anything better.  */
-def.name = dom->name;
-memcpy(def.uuid, dom->uuid, VIR_UUID_BUFLEN);
+def->name = dom->name;
+memcpy(def->uuid, dom->uuid, VIR_UUID_BUFLEN);
 
 if (!(identity = virNetServerClientGetIdentity(client)))
 goto cleanup;
 if (virIdentitySetCurrent(identity) < 0)
 goto cleanup;
-ret = virConnectDomainQemuMonitorEventRegisterCheckACL(conn, );
+ret = virConnectDomainQemuMonitorEventRegisterCheckACL(conn, def);
 
  cleanup:
 ignore_value(virIdentitySetCurrent(NULL));
+g_free(def); /* shallow free */
 return ret;
 }
 
-- 
2.26.2



[libvirt PATCH 0/8] build: lower maximum frame size to 1792

2020-10-04 Thread Ján Tomko
Ján Tomko (8):
  libxl: libxlDomainStart: use g_autoptr for virDomainDef
  libxl: libxlDomainStart: autofree managed_save_path
  libxl: libxlDomainStart: use g_auto more
  libxl: allocate d_config
  esx: esxConnectOpen: use allocated buffer
  lxc: virLXCProcessStart: use allocated buffers
  remote: allocate virDomainDef for ACL check
  build: lower maximum frame size to 1792

 meson.build |  7 +++--
 src/esx/esx_driver.c|  7 ++---
 src/libxl/libxl_domain.c| 40 +
 src/lxc/lxc_process.c   | 19 --
 src/remote/remote_daemon_dispatch.c | 19 +++---
 5 files changed, 46 insertions(+), 46 deletions(-)

-- 
2.26.2



Re: [PATCH 4/4] docs: formatdomain: add spicevmc example

2020-10-04 Thread Ján Tomko

On a Sunday in 2020, Cole Robinson wrote:

spicevmc is the most common  usage. This adds an XML example
for it.

Signed-off-by: Cole Robinson 
---
docs/formatdomain.rst | 1 +
1 file changed, 1 insertion(+)



Reviewed-by: Ján Tomko 

Jano


signature.asc
Description: PGP signature


Re: [PATCH 3/4] docs: formatdomain: fix net downscript 'since'

2020-10-04 Thread Ján Tomko

On a Sunday in 2020, Cole Robinson wrote:

It was added in 6.4.0, not 5.1.0

Signed-off-by: Cole Robinson 


Fixes: 61ba6f09b181ec8c1591dc1df8c3cd8e093ca67b

Reviewed-by: Ján Tomko 

Jano


---
docs/formatdomain.rst | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)



signature.asc
Description: PGP signature


[libvirt PATCH] news: move section about downscript to v6.4.0

2020-10-04 Thread Ján Tomko
The feature was merged in v6.3.0-175-g61ba6f09b1

Signed-off-by: Ján Tomko 
Fixes: 4eda71a8d05d968e73ab9b0fdc8a90123c57d39e
---
 NEWS.rst | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/NEWS.rst b/NEWS.rst
index f6074d9fe8..5da6174e42 100644
--- a/NEWS.rst
+++ b/NEWS.rst
@@ -404,6 +404,12 @@ v6.4.0 (2020-06-02)
 ``virsh capabilities`` will now include information about the host CPU when
 run on ARM machines.
 
+  * qemu: support network interface downscript
+
+QEMU has the ability to run a script when a NIC is brought up and down.
+Libvirt only enables use of the up script. Now add support for postscript
+when NIC is down/detached.
+
 * **Improvements**
 
   * qemu: stricter validation for disk type='lun'
@@ -454,12 +460,6 @@ v6.3.0 (2020-05-05)
 
 * **New features**
 
-  * qemu: support network interface downscript
-
-QEMU has the ability to run a script when a NIC is brought up and down.
-Libvirt only enables use of the up script. Now add support for postscript
-when NIC is down/detached.
-
   * qemu: support disabling hotplug/unplug of PCIe devices
 
 libvirt can now set the "hotplug" option for pcie-root-ports and
-- 
2.26.2



Re: [PATCH 1/4] docs: formatdomain: remove doubled filesystem

2020-10-04 Thread Ján Tomko

On a Sunday in 2020, Cole Robinson wrote:

libvirt doesn't reject this but only one  element takes
effect.

Drop the instance that is already referenced in the previous example

Signed-off-by: Cole Robinson 
---
docs/formatdomain.rst | 1 -
1 file changed, 1 deletion(-)



Reviewed-by: Ján Tomko 

Jano


signature.asc
Description: PGP signature


Re: [PATCH 2/4] docs: formatdomain: fix incorrect 'Vsock' heading indent

2020-10-04 Thread Ján Tomko

On a Sunday in 2020, Cole Robinson wrote:

Currently it is visually at the same indent as . This
fixes it to be grouped it with 

Signed-off-by: Cole Robinson 


Fixes: d4abb7b45d48aba77c2464dbea95f02a43a60834


---
docs/formatdomain.rst | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)



Reviewed-by: Ján Tomko 

Jano


signature.asc
Description: PGP signature


[PATCH] qemu: Taint cpu host-passthrough only after migration

2020-10-04 Thread Cole Robinson
>From a discussion last year[1], Dan recommended libvirt drop the tain
flag for cpu host-passthrough, unless the VM has been migrated.

This repurposes the existing host-cpu taint flag to do just that.

[1]: https://www.redhat.com/archives/virt-tools-list/2019-February/msg00041.html

https://bugzilla.redhat.com/show_bug.cgi?id=1673098

Signed-off-by: Cole Robinson 
---
 src/conf/domain_conf.h  | 2 +-
 src/qemu/qemu_domain.c  | 7 +--
 src/qemu/qemu_domain.h  | 3 ++-
 src/qemu/qemu_process.c | 2 +-
 4 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 9a44315519..450686dfb5 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -2736,7 +2736,7 @@ typedef enum {
 VIR_DOMAIN_TAINT_SHELL_SCRIPTS,/* Network configuration using opaque 
shell scripts */
 VIR_DOMAIN_TAINT_DISK_PROBING, /* Relying on potentially unsafe disk 
format probing */
 VIR_DOMAIN_TAINT_EXTERNAL_LAUNCH,  /* Externally launched guest domain */
-VIR_DOMAIN_TAINT_HOST_CPU, /* Host CPU passthrough in use */
+VIR_DOMAIN_TAINT_HOST_CPU, /* Host CPU passthrough in use after 
migration */
 VIR_DOMAIN_TAINT_HOOK, /* Domain (possibly) changed via hook 
script */
 VIR_DOMAIN_TAINT_CDROM_PASSTHROUGH,/* CDROM passthrough */
 VIR_DOMAIN_TAINT_CUSTOM_DTB,   /* Custom device tree blob was 
specified */
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 0331fd55e0..ed4bdbd7fb 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -6115,7 +6115,8 @@ void qemuDomainObjTaint(virQEMUDriverPtr driver,
 
 void qemuDomainObjCheckTaint(virQEMUDriverPtr driver,
  virDomainObjPtr obj,
- qemuDomainLogContextPtr logCtxt)
+ qemuDomainLogContextPtr logCtxt,
+ bool incomingMigration)
 {
 size_t i;
 g_autoptr(virQEMUDriverConfig) cfg = virQEMUDriverGetConfig(driver);
@@ -6144,7 +6145,9 @@ void qemuDomainObjCheckTaint(virQEMUDriverPtr driver,
VIR_DOMAIN_TAINT_CUSTOM_HYPERVISOR_FEATURE, 
logCtxt);
 }
 
-if (obj->def->cpu && obj->def->cpu->mode == VIR_CPU_MODE_HOST_PASSTHROUGH)
+if (obj->def->cpu &&
+obj->def->cpu->mode == VIR_CPU_MODE_HOST_PASSTHROUGH &&
+incomingMigration)
 qemuDomainObjTaint(driver, obj, VIR_DOMAIN_TAINT_HOST_CPU, logCtxt);
 
 for (i = 0; i < obj->def->ndisks; i++)
diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h
index ec776ced72..9bf32e16c9 100644
--- a/src/qemu/qemu_domain.h
+++ b/src/qemu/qemu_domain.h
@@ -567,7 +567,8 @@ void qemuDomainObjTaint(virQEMUDriverPtr driver,
 
 void qemuDomainObjCheckTaint(virQEMUDriverPtr driver,
  virDomainObjPtr obj,
- qemuDomainLogContextPtr logCtxt);
+ qemuDomainLogContextPtr logCtxt,
+ bool incomingMigration);
 void qemuDomainObjCheckDiskTaint(virQEMUDriverPtr driver,
  virDomainObjPtr obj,
  virDomainDiskDefPtr disk,
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index 9122069cc9..57d764014a 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -6856,7 +6856,7 @@ qemuProcessLaunch(virConnectPtr conn,
 
 qemuLogOperation(vm, "starting up", cmd, logCtxt);
 
-qemuDomainObjCheckTaint(driver, vm, logCtxt);
+qemuDomainObjCheckTaint(driver, vm, logCtxt, incoming != NULL);
 
 qemuDomainLogContextMarkPosition(logCtxt);
 
-- 
2.28.0



[PATCH] tests: cover disk, interface

2020-10-04 Thread Cole Robinson
There is present no XML test coverage for this.
Add genericxml parse + formatting coverage.

Signed-off-by: Cole Robinson 
---
 .../device-backenddomain.xml  | 30 +++
 .../device-backenddomain.xml  |  1 +
 tests/genericxml2xmltest.c|  1 +
 3 files changed, 32 insertions(+)
 create mode 100644 tests/genericxml2xmlindata/device-backenddomain.xml
 create mode 12 tests/genericxml2xmloutdata/device-backenddomain.xml

diff --git a/tests/genericxml2xmlindata/device-backenddomain.xml 
b/tests/genericxml2xmlindata/device-backenddomain.xml
new file mode 100644
index 00..8e89c7fec3
--- /dev/null
+++ b/tests/genericxml2xmlindata/device-backenddomain.xml
@@ -0,0 +1,30 @@
+
+  foo
+  c7a5fdbd-edaf-9455-926a-d65c16db1809
+  219136
+  219136
+  1
+  
+hvm
+
+  
+  
+  destroy
+  restart
+  destroy
+  
+
+  
+  
+  
+  
+  
+
+
+
+  
+  
+  
+
+  
+
diff --git a/tests/genericxml2xmloutdata/device-backenddomain.xml 
b/tests/genericxml2xmloutdata/device-backenddomain.xml
new file mode 12
index 00..f19471e3b5
--- /dev/null
+++ b/tests/genericxml2xmloutdata/device-backenddomain.xml
@@ -0,0 +1 @@
+../genericxml2xmlindata/device-backenddomain.xml
\ No newline at end of file
diff --git a/tests/genericxml2xmltest.c b/tests/genericxml2xmltest.c
index 102abfdec2..5110bfba86 100644
--- a/tests/genericxml2xmltest.c
+++ b/tests/genericxml2xmltest.c
@@ -233,6 +233,7 @@ mymain(void)
 DO_TEST("launch-security-sev");
 
 DO_TEST_DIFFERENT("cputune");
+DO_TEST("device-backenddomain");
 
 #define DO_TEST_BACKUP_FULL(name, intrnl) \
 do { \
-- 
2.28.0



[PATCH 4/4] docs: formatdomain: add spicevmc example

2020-10-04 Thread Cole Robinson
spicevmc is the most common  usage. This adds an XML example
for it.

Signed-off-by: Cole Robinson 
---
 docs/formatdomain.rst | 1 +
 1 file changed, 1 insertion(+)

diff --git a/docs/formatdomain.rst b/docs/formatdomain.rst
index 8fc08c5fd2..9316dab9cc 100644
--- a/docs/formatdomain.rst
+++ b/docs/formatdomain.rst
@@ -4066,6 +4066,7 @@ after 0.9.5 (KVM only)` :
 
...

+ 
  


-- 
2.28.0



[PATCH 3/4] docs: formatdomain: fix net downscript 'since'

2020-10-04 Thread Cole Robinson
It was added in 6.4.0, not 5.1.0

Signed-off-by: Cole Robinson 
---
 docs/formatdomain.rst | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/docs/formatdomain.rst b/docs/formatdomain.rst
index 37c65add4d..8fc08c5fd2 100644
--- a/docs/formatdomain.rst
+++ b/docs/formatdomain.rst
@@ -,7 +,7 @@ After creating/opening the tap device, an optional shell 
script (given in the
 ``path`` attribute of the 

[PATCH 1/4] docs: formatdomain: remove doubled filesystem

2020-10-04 Thread Cole Robinson
libvirt doesn't reject this but only one  element takes
effect.

Drop the instance that is already referenced in the previous example

Signed-off-by: Cole Robinson 
---
 docs/formatdomain.rst | 1 -
 1 file changed, 1 deletion(-)

diff --git a/docs/formatdomain.rst b/docs/formatdomain.rst
index f3cf9e1fb3..d75a91bbf4 100644
--- a/docs/formatdomain.rst
+++ b/docs/formatdomain.rst
@@ -3064,7 +3064,6 @@ A directory on the host that can be accessed directly 
from the guest.
  
  

-   



-- 
2.28.0



[PATCH 2/4] docs: formatdomain: fix incorrect 'Vsock' heading indent

2020-10-04 Thread Cole Robinson
Currently it is visually at the same indent as . This
fixes it to be grouped it with 

Signed-off-by: Cole Robinson 
---
 docs/formatdomain.rst | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/docs/formatdomain.rst b/docs/formatdomain.rst
index d75a91bbf4..37c65add4d 100644
--- a/docs/formatdomain.rst
+++ b/docs/formatdomain.rst
@@ -7286,7 +7286,7 @@ Example:
 :anchor:``
 
 Vsock
--
+~
 
 A vsock host/guest interface. The ``model`` attribute defaults to ``virtio``.
 :since:`Since 5.2.0` ``model`` can also be 'virtio-transitional' and
-- 
2.28.0



[PATCH 0/4] docs: formatdomain: misc fixes

2020-10-04 Thread Cole Robinson
A collection of formatdomain fixes that I've noticed over the past
few months

Cole Robinson (4):
  docs: formatdomain: remove doubled filesystem 
  docs: formatdomain: fix incorrect 'Vsock' heading indent
  docs: formatdomain: fix net downscript 'since'
  docs: formatdomain: add spicevmc  example

 docs/formatdomain.rst | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

-- 
2.28.0



Re: [libvirt PATCH] tests: fix incorrect free of GVariant in our GLib mock functions

2020-10-04 Thread Cole Robinson
On 10/2/20 6:36 AM, Pavel Hrdina wrote:
> GLib implementation of g_dbus_connection_call_sync() calls
> g_variant_ref_sink() on the passed @parameters to make sure they have
> proper reference. If the original reference is floating the
> g_dbus_connection_call_sync() consumes it, but if it's normal reference
> it will just add another one.
> 
> Our mock functions were only freeing the @parameters which is incorrect
> and doesn't reflect how the real implementation works.
> 
> Reported-by: Cole Robinson 
> Signed-off-by: Pavel Hrdina 

I added this to Fedora and the build passed. Thanks!

- Cole