[libvirt][PATCH v1 0/1] introduce an attribute "migratable" to numatune memory element

2020-10-05 Thread Luyao Zhong
RFC discussion record link:
https://www.redhat.com/archives/libvir-list/2020-August/msg00960.html

Luyao Zhong (1):
  introduce an attribute "migratable" to numatune memory element

 docs/formatdomain.rst |  8 +++-
 docs/schemas/domaincommon.rng |  5 +++
 src/conf/numa_conf.c  | 45 +++
 src/conf/numa_conf.h  |  3 ++
 src/libvirt_private.syms  |  1 +
 src/qemu/qemu_command.c   |  6 ++-
 src/qemu/qemu_process.c   | 21 +
 .../numatune-memory-migratable.args   | 34 ++
 .../numatune-memory-migratable.err|  1 +
 .../numatune-memory-migratable.xml| 33 ++
 tests/qemuxml2argvtest.c  |  5 +++
 11 files changed, 160 insertions(+), 2 deletions(-)
 create mode 100644 tests/qemuxml2argvdata/numatune-memory-migratable.args
 create mode 100644 tests/qemuxml2argvdata/numatune-memory-migratable.err
 create mode 100644 tests/qemuxml2argvdata/numatune-memory-migratable.xml

-- 
2.25.4



[libvirt][PATCH v1 1/1] introduce an attribute "migratable" to numatune memory element

2020-10-05 Thread Luyao Zhong
  



  

Attribute ``migratable`` will be 'no' by default, and 'yes' indicates
that it allows operating system or hypervisor migrating the memory
pages between different memory nodes, that also means we will not
rely on hypervisor to set the memory policy or memory affinity, we only
use cgroups to restrict the memory nodes, so if ``migratable`` is 'yes',
the ``mode`` which indicates memory policy will be ignored.
---
 docs/formatdomain.rst |  8 +++-
 docs/schemas/domaincommon.rng |  5 +++
 src/conf/numa_conf.c  | 45 +++
 src/conf/numa_conf.h  |  3 ++
 src/libvirt_private.syms  |  1 +
 src/qemu/qemu_command.c   |  6 ++-
 src/qemu/qemu_process.c   | 21 +
 .../numatune-memory-migratable.args   | 34 ++
 .../numatune-memory-migratable.err|  1 +
 .../numatune-memory-migratable.xml| 33 ++
 tests/qemuxml2argvtest.c  |  5 +++
 11 files changed, 160 insertions(+), 2 deletions(-)
 create mode 100644 tests/qemuxml2argvdata/numatune-memory-migratable.args
 create mode 100644 tests/qemuxml2argvdata/numatune-memory-migratable.err
 create mode 100644 tests/qemuxml2argvdata/numatune-memory-migratable.xml

diff --git a/docs/formatdomain.rst b/docs/formatdomain.rst
index cc4f91d4ea..4e386a0c3d 100644
--- a/docs/formatdomain.rst
+++ b/docs/formatdomain.rst
@@ -1072,7 +1072,7 @@ NUMA Node Tuning

  ...
  
-   
+   


  
@@ -1097,6 +1097,12 @@ NUMA Node Tuning
will be ignored if it's specified. If ``placement`` of ``vcpu`` is 'auto',
and ``numatune`` is not specified, a default ``numatune`` with ``placement``
'auto' and ``mode`` 'strict' will be added implicitly. :since:`Since 0.9.3`
+   Attribute ``migratable`` is 'no' by default, and 'yes' indicates that it
+   allows operating system or hypervisor migrating the memory pages between
+   different memory nodes, that also means we will not rely on hypervisor to
+   set the memory policy or memory affinity, we only use cgroups to restrict
+   the memory nodes, so if ``migratable`` is 'yes', the ``mode`` which 
indicates
+   memory policy will be ignored.
 ``memnode``
Optional ``memnode`` elements can specify memory allocation policies per 
each
guest NUMA node. For those nodes having no corresponding ``memnode`` 
element,
diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng
index 316d93fb69..a0283e8449 100644
--- a/docs/schemas/domaincommon.rng
+++ b/docs/schemas/domaincommon.rng
@@ -1078,6 +1078,11 @@
   
 
   
+
+  
+
+  
+
 
   
 
diff --git a/src/conf/numa_conf.c b/src/conf/numa_conf.c
index 6653ba05a6..c14ba1295c 100644
--- a/src/conf/numa_conf.c
+++ b/src/conf/numa_conf.c
@@ -99,6 +99,7 @@ struct _virDomainNuma {
 virBitmapPtr nodeset;
 virDomainNumatuneMemMode mode;
 virDomainNumatunePlacement placement;
+virTristateBool migratable;
 } memory;   /* pinning for all the memory */
 
 struct _virDomainNumaNode {
@@ -275,6 +276,7 @@ virDomainNumatuneParseXML(virDomainNumaPtr numa,
 int ret = -1;
 virBitmapPtr nodeset = NULL;
 xmlNodePtr node = NULL;
+int migratable = 0;
 
 if (virXPathInt("count(./numatune)", ctxt, ) < 0) {
 virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
@@ -292,6 +294,15 @@ virDomainNumatuneParseXML(virDomainNumaPtr numa,
 placement = VIR_DOMAIN_NUMATUNE_PLACEMENT_AUTO;
 
 if (node) {
+if ((tmp = virXMLPropString(node, "migratable")) &&
+(migratable = virTristateBoolTypeFromString(tmp)) <= 0) {
+virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+   _("Invalid 'migratable' attribute value '%s'"), 
tmp);
+goto cleanup;
+}
+numa->memory.migratable = migratable;
+VIR_FREE(tmp);
+
 if ((tmp = virXMLPropString(node, "mode")) &&
 (mode = virDomainNumatuneMemModeTypeFromString(tmp)) < 0) {
 virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
@@ -369,6 +380,11 @@ virDomainNumatuneFormatXML(virBufferPtr buf,
 tmp = virDomainNumatuneMemModeTypeToString(numatune->memory.mode);
 virBufferAsprintf(buf, "memory.migratable) {
+tmp = virTristateBoolTypeToString(numatune->memory.migratable);
+virBufferAsprintf(buf, "migratable='%s' ", tmp);
+}
+
 if (numatune->memory.placement == 
VIR_DOMAIN_NUMATUNE_PLACEMENT_STATIC) {
 if (!(nodeset = virBitmapFormat(numatune->memory.nodeset)))
 return -1;
@@ -427,6 +443,35 @@ virDomainNumaFree(virDomainNumaPtr numa)
 VIR_FREE(numa);
 }
 
+/**
+ * virDomainNumatuneGetMigratable:
+ * @numatune: pointer 

Re: [PATCH v2 01/10] hyperv: make Msvm_ComputerSystem WQL queries locale agnostic

2020-10-05 Thread Matt Coleman
> On Oct 5, 2020, at 8:54 PM, Neal Gompa  wrote:
> 
> Should we require a bump to openwsman 2.6 for this?

That won’t make any difference: openwsman 2.6+ supports specifying the 
locale, but Windows ignores it. So, this patch changes the queries to 
not use localized strings.

-- 
Matt




Re: [PATCH] mailmap: consolidate my email addresses

2020-10-05 Thread Neal Gompa
On Mon, Oct 5, 2020 at 3:15 PM Matt Coleman  wrote:
>
> Signed-off-by: Matt Coleman 
> ---
>  .mailmap | 1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/.mailmap b/.mailmap
> index 2b080568bc..9dfb7a832b 100644
> --- a/.mailmap
> +++ b/.mailmap
> @@ -47,6 +47,7 @@
>   
>   
>   
> + 
>
>  # Name consolidation:
>  # Preferred author spelling 
> --
> 2.27.0
>
>

Reviewed-by: Neal Gompa 


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




Re: [PATCH v2 01/10] hyperv: make Msvm_ComputerSystem WQL queries locale agnostic

2020-10-05 Thread Neal Gompa
On Mon, Oct 5, 2020 at 9:13 PM Matt Coleman  wrote:
>
> > On Oct 5, 2020, at 8:54 PM, Neal Gompa  wrote:
> >
> > Should we require a bump to openwsman 2.6 for this?
>
> That won’t make any difference: openwsman 2.6+ supports specifying the
> locale, but Windows ignores it. So, this patch changes the queries to
> not use localized strings.
>
> --
> Matt
>

Ahh, okay then.

Reviewed-by: Neal Gompa 


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




Re: [PATCH v2 00/10] hyperv: implement new APIs & more

2020-10-05 Thread Neal Gompa
On Mon, Oct 5, 2020 at 12:20 PM Matt Coleman  wrote:
>
> These patches fix a couple bugs, consolidate duplicate code, and
> implement several APIs.
>
> Currently, some interactions with Hyper-V systems fail when the system
> is not configured for the "en-US" locale. Additionally, some CPU names
> also contain the clock frequency, making it too long for
> _virNodeInfo.model. The first two patches fix these bugs.
>
> The second two patches clean up the code a little: one moves repeated
> operations into new helper functions; the other replaces the generic
> "get WMI class list" functions with a macro.
>
> The next four patches implement the following APIs in the Hyper-V
> driver:
> * virConnectGetCapabilities()
> * virConnectGetMaxVcpus()
> * virConnectGetVersion()
> * virDomainGetAutostart()
>
> Changes since v1:
> * all NEWS updates are now in a single commit at the end
> * long function calls have been split up into multiple lines
> * improved error handling in hypervDomainLookupBy*(): they now throw
>   VIR_ERR_NO_DOMAIN when appropriate
> * unnecessary calls to virReportError() have been removed from
>   hypervDomainGetInfo() and hypervDomainGetXMLDesc()
> * HTML documentation for the unusual Hyper-V versions
> * the WMI schema fix has been split into a separate commit
> * hypervConnectGetVersion() uses a new hypervParseVersionString() and
>   directly produces the unsigned long instead of calling
>   virParseVersionString()
>
> Matt Coleman (10):
>   hyperv: make Msvm_ComputerSystem WQL queries locale agnostic
>   hyperv: fix nodeGetInfo failures caused by long CPU names
>   hyperv: break out common lookups into separate functions
>   hyperv: replace generic WMI class list helpers with a macro
>   hyperv: implement connectGetCapabilities
>   hyperv: implement connectGetMaxVcpus
>   hyperv: fix Win32_OperatingSystem WMI queries
>   hyperv: implement connectGetVersion
>   hyperv: implement domainGetAutostart
>   news: document new Hyper-V features and bug fixes
>
>  NEWS.rst  |  10 +
>  docs/drvhyperv.html.in|  50 ++
>  src/hyperv/hyperv_driver.c| 751 ++
>  src/hyperv/hyperv_private.h   |   2 +
>  src/hyperv/hyperv_wmi.c   |  83 +--
>  src/hyperv/hyperv_wmi.h   |  28 +-
>  src/hyperv/hyperv_wmi_classes.h   |   4 +-
>  src/hyperv/hyperv_wmi_generator.input |   2 +-
>  8 files changed, 596 insertions(+), 334 deletions(-)
>
> --
> 2.27.0
>
>

In general, the series looks good to me, though please take a look at
my feedback for Patch 1.


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




Re: [PATCH v2 09/10] hyperv: implement domainGetAutostart

2020-10-05 Thread Neal Gompa
On Mon, Oct 5, 2020 at 12:21 PM Matt Coleman  wrote:
>
> Co-authored-by: Sri Ramanujam 
> Signed-off-by: Matt Coleman 
> ---
>  src/hyperv/hyperv_driver.c | 40 ++
>  1 file changed, 40 insertions(+)
>
> diff --git a/src/hyperv/hyperv_driver.c b/src/hyperv/hyperv_driver.c
> index 528c826e16..dcde469442 100644
> --- a/src/hyperv/hyperv_driver.c
> +++ b/src/hyperv/hyperv_driver.c
> @@ -1274,6 +1274,45 @@ hypervDomainCreate(virDomainPtr domain)
>
>
>
> +static int
> +hypervDomainGetAutostart(virDomainPtr domain, int *autostart)
> +{
> +int result = -1;
> +char uuid_string[VIR_UUID_STRING_BUFLEN];
> +hypervPrivate *priv = domain->conn->privateData;
> +g_auto(virBuffer) query = VIR_BUFFER_INITIALIZER;
> +Msvm_VirtualSystemGlobalSettingData *vsgsd = NULL;
> +Msvm_VirtualSystemSettingData *vssd = NULL;
> +
> +virUUIDFormat(domain->uuid, uuid_string);
> +
> +if (priv->wmiVersion == HYPERV_WMI_VERSION_V1) {
> +virBufferEscapeSQL(,
> +   MSVM_VIRTUALSYSTEMGLOBALSETTINGDATA_WQL_SELECT
> +   "WHERE SystemName = \"%s\"", uuid_string);
> +
> +if (hypervGetWmiClass(Msvm_VirtualSystemGlobalSettingData, ) < 
> 0)
> +goto cleanup;
> +
> +*autostart = vsgsd->data.common->AutomaticStartupAction == 2;
> +result = 0;
> +} else {
> +if (hypervGetVSSDFromUUID(priv, uuid_string, ) < 0)
> +goto cleanup;
> +
> +*autostart = vssd->data.v2->AutomaticStartupAction == 4;
> +result = 0;
> +}
> +
> +cleanup:
> +hypervFreeObject(priv, (hypervObject *) vsgsd);
> +hypervFreeObject(priv, (hypervObject *) vssd);
> +
> +return result;
> +}
> +
> +
> +
>  static int
>  hypervConnectIsEncrypted(virConnectPtr conn)
>  {
> @@ -1824,6 +1863,7 @@ static virHypervisorDriver hypervHypervisorDriver = {
>  .connectNumOfDefinedDomains = hypervConnectNumOfDefinedDomains, /* 0.9.5 
> */
>  .domainCreate = hypervDomainCreate, /* 0.9.5 */
>  .domainCreateWithFlags = hypervDomainCreateWithFlags, /* 0.9.5 */
> +.domainGetAutostart = hypervDomainGetAutostart, /* 6.9.0 */
>  .connectIsEncrypted = hypervConnectIsEncrypted, /* 0.9.5 */
>  .connectIsSecure = hypervConnectIsSecure, /* 0.9.5 */
>  .domainIsActive = hypervDomainIsActive, /* 0.9.5 */
> --
> 2.27.0
>
>

Reviewed-by: Neal Gompa 


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




Re: [PATCH v2 10/10] news: document new Hyper-V features and bug fixes

2020-10-05 Thread Neal Gompa
On Mon, Oct 5, 2020 at 12:22 PM Matt Coleman  wrote:
>
> Signed-off-by: Matt Coleman 
> ---
>  NEWS.rst | 10 ++
>  1 file changed, 10 insertions(+)
>
> diff --git a/NEWS.rst b/NEWS.rst
> index b2ed661c8e..e708f06e9e 100644
> --- a/NEWS.rst
> +++ b/NEWS.rst
> @@ -19,10 +19,20 @@ v6.9.0 (unreleased)
>  local file-backed disks to configure a disk which discards changes made 
> to
>  it while the VM was active.
>
> +  * hyperv: implement new APIs
> +
> +The ``virConnectGetCapabilities()``, ``virConnectGetMaxVcpus()``,
> +``virConnectGetVersion()``, and ``virDomainGetAutostart()`` APIs have 
> been
> +implemented in the Hyper-V driver.
> +
>  * **Improvements**
>
>  * **Bug fixes**
>
> +  * hyperv: ensure WQL queries work in all locales
> +
> +Relying on the "Description" field caused queries to fail on non-"en-US"
> +systems. The queries have been updated to avoid using localized strings.
>
>  v6.8.0 (2020-10-01)
>  ===
> --
> 2.27.0
>
>

Reviewed-by: Neal Gompa 


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




Re: [PATCH v2 07/10] hyperv: fix Win32_OperatingSystem WMI queries

2020-10-05 Thread Neal Gompa
On Mon, Oct 5, 2020 at 12:21 PM Matt Coleman  wrote:
>
> CurrentTimeZone's type is a signed integer, not unsigned.
>
> Signed-off-by: Matt Coleman 
> ---
>  src/hyperv/hyperv_wmi_generator.input | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/src/hyperv/hyperv_wmi_generator.input 
> b/src/hyperv/hyperv_wmi_generator.input
> index 77543cf6ef..bbca550790 100644
> --- a/src/hyperv/hyperv_wmi_generator.input
> +++ b/src/hyperv/hyperv_wmi_generator.input
> @@ -673,7 +673,7 @@ class Win32_OperatingSystem
>  string   CSCreationClassName
>  string   CSDVersion
>  string   CSName
> -uint16   CurrentTimeZone
> +int16CurrentTimeZone
>  boolean  DataExecutionPrevention_Available
>  boolean  DataExecutionPrevention_32BitApplications
>  boolean  DataExecutionPrevention_Drivers
> --
> 2.27.0
>
>

Reviewed-by: Neal Gompa 

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




Re: [PATCH v2 08/10] hyperv: implement connectGetVersion

2020-10-05 Thread Neal Gompa
On Mon, Oct 5, 2020 at 12:22 PM Matt Coleman  wrote:
>
> Hyper-V version numbers are not compatible with the encoding in
> virParseVersionString():
> https://gitlab.com/libvirt/libvirt/-/blob/master/src/util/virutil.c#L246
>
> For example, the Windows Server 2016 Hyper-V version is 10.0.14393: its
> micro is over 14 times larger than the encoding allows.
>
> This commit repacks the Hyper-V version number in order to preserve all
> of the digits. The major and minor are concatenated (with minor zero-
> padded to two digits) to form the repacked major value. This works
> because Microsoft's major and minor versions numbers are unlikely to
> exceed 99. The repacked minor value is derived from the digits in the
> thousands, ten-thousands, and hundred-thousands places of Hyper-V's
> micro. The repacked micro is derived from the digits in the ones, tens,
> and hundreds places of Hyper-V's micro.
>
> Co-authored-by: Sri Ramanujam 
> Signed-off-by: Matt Coleman 
> ---
>  docs/drvhyperv.html.in | 50 +++
>  src/hyperv/hyperv_driver.c | 81 ++
>  2 files changed, 131 insertions(+)
>
> diff --git a/docs/drvhyperv.html.in b/docs/drvhyperv.html.in
> index 78f61aaee2..e8e2113f70 100644
> --- a/docs/drvhyperv.html.in
> +++ b/docs/drvhyperv.html.in
> @@ -112,4 +112,54 @@ winrm set winrm/config/service @{AllowUnencrypted="true"}
>  
>
>
> +Version Numbers
> +
> +Since Microsoft's build numbers are almost always over 1000, this 
> driver
> +needs to pack the value differently compared to the format defined by
> +virConnectGetVersion.
> +To preserve all of the digits, the following format is used:
> +
> +major * 1 + minor * 100 + micro
> +
> +This results in virsh version producing unexpected 
> output.
> +
> +
> +
> +Windows Release
> +Kernel Version
> +libvirt Representation
> +
> +
> +Windows Server 2008
> +6.0.6001
> +600.6.1
> +
> +
> +Windows Server 2008 R2
> +6.1.7600
> +601.7.600
> +
> +
> +Windows Server 2012
> +6.2.9200
> +602.9.200
> +
> +
> +Windows Server 2012 R2
> +6.3.9600
> +603.9.600
> +
> +
> +Windows Server 2016
> +10.0.14393
> +1000.14.393
> +
> +
> +Windows Server 2019
> +10.0.17763
> +1000.17.763
> +
> +
> +
> +
>  
> diff --git a/src/hyperv/hyperv_driver.c b/src/hyperv/hyperv_driver.c
> index bbe892fd62..528c826e16 100644
> --- a/src/hyperv/hyperv_driver.c
> +++ b/src/hyperv/hyperv_driver.c
> @@ -29,6 +29,7 @@
>  #include "viralloc.h"
>  #include "virlog.h"
>  #include "viruuid.h"
> +#include "virutil.h"
>  #include "hyperv_driver.h"
>  #include "hyperv_private.h"
>  #include "hyperv_util.h"
> @@ -288,6 +289,24 @@ hypervGetMemSDByVSSDInstanceId(hypervPrivate *priv, 
> const char *id,
>   * API-specific utility functions
>   */
>
> +static int
> +hypervParseVersionString(const char *str, unsigned int *major,
> + unsigned int *minor, unsigned int *micro)
> +{
> +char *suffix = NULL;
> +
> +if (virStrToLong_ui(str, , 10, major) < 0)
> +return -1;
> +
> +if (virStrToLong_ui(suffix + 1, , 10, minor) < 0)
> +return -1;
> +
> +if (virStrToLong_ui(suffix + 1, NULL, 10, micro) < 0)
> +return -1;
> +
> +return 0;
> +}
> +
>  static int
>  hypervLookupHostSystemBiosUuid(hypervPrivate *priv, unsigned char *uuid)
>  {
> @@ -523,6 +542,67 @@ hypervConnectGetType(virConnectPtr conn G_GNUC_UNUSED)
>
>
>
> +static int
> +hypervConnectGetVersion(virConnectPtr conn, unsigned long *version)
> +{
> +int result = -1;
> +hypervPrivate *priv = conn->privateData;
> +Win32_OperatingSystem *os = NULL;
> +g_auto(virBuffer) query = { 
> g_string_new(WIN32_OPERATINGSYSTEM_WQL_SELECT), 0 };
> +unsigned int major, minor, micro;
> +
> +if (hypervGetWmiClass(Win32_OperatingSystem, ) < 0 ||
> +!os) {
> +virReportError(VIR_ERR_INTERNAL_ERROR,
> +   _("Could not get version information for host %s"),
> +   conn->uri->server);
> +goto cleanup;
> +}
> +
> +if (hypervParseVersionString(os->data.common->Version,
> + , , ) < 0) {
> +virReportError(VIR_ERR_INTERNAL_ERROR,
> +   _("Could not parse version from '%s'"),
> +   os->data.common->Version);
> +goto cleanup;
> +}
> +
> +/*
> + * Pack the version into an unsigned long while retaining all the digits.
> + *
> + * Since Microsoft's build numbers are almost always over 1000, this 
> driver
> + * needs to pack the value 

Re: [PATCH v2 06/10] hyperv: implement connectGetMaxVcpus

2020-10-05 Thread Neal Gompa
On Mon, Oct 5, 2020 at 12:21 PM Matt Coleman  wrote:
>
> Co-authored-by: Sri Ramanujam 
> Signed-off-by: Matt Coleman 
> ---
>  src/hyperv/hyperv_driver.c | 34 ++
>  1 file changed, 34 insertions(+)
>
> diff --git a/src/hyperv/hyperv_driver.c b/src/hyperv/hyperv_driver.c
> index 93e08c54c0..bbe892fd62 100644
> --- a/src/hyperv/hyperv_driver.c
> +++ b/src/hyperv/hyperv_driver.c
> @@ -553,6 +553,39 @@ hypervConnectGetCapabilities(virConnectPtr conn)
>
>
>
> +static int
> +hypervConnectGetMaxVcpus(virConnectPtr conn, const char *type G_GNUC_UNUSED)
> +{
> +int result = -1;
> +hypervPrivate *priv = conn->privateData;
> +g_auto(virBuffer) query = VIR_BUFFER_INITIALIZER;
> +Msvm_ProcessorSettingData *processorSettingData = NULL;
> +
> +/* Get max processors definition */
> +virBufferAddLit(,
> +MSVM_PROCESSORSETTINGDATA_WQL_SELECT
> +"WHERE InstanceID LIKE 'Microsoft:Definition%Maximum'");
> +
> +if (hypervGetWmiClass(Msvm_ProcessorSettingData, ) 
> < 0)
> +goto cleanup;
> +
> +if (!processorSettingData) {
> +virReportError(VIR_ERR_INTERNAL_ERROR,
> +   _("Could not get maximum definition of 
> Msvm_ProcessorSettingData for host %s"),
> +   conn->uri->server);
> +goto cleanup;
> +}
> +
> +result = processorSettingData->data.common->VirtualQuantity;
> +
> + cleanup:
> +hypervFreeObject(priv, (hypervObject *) processorSettingData);
> +
> +return result;
> +}
> +
> +
> +
>  static int
>  hypervNodeGetInfo(virConnectPtr conn, virNodeInfoPtr info)
>  {
> @@ -1689,6 +1722,7 @@ static virHypervisorDriver hypervHypervisorDriver = {
>  .connectClose = hypervConnectClose, /* 0.9.5 */
>  .connectGetType = hypervConnectGetType, /* 0.9.5 */
>  .connectGetHostname = hypervConnectGetHostname, /* 0.9.5 */
> +.connectGetMaxVcpus = hypervConnectGetMaxVcpus, /* 6.9.0 */
>  .nodeGetInfo = hypervNodeGetInfo, /* 0.9.5 */
>  .connectGetCapabilities = hypervConnectGetCapabilities, /* 6.9.0 */
>  .connectListDomains = hypervConnectListDomains, /* 0.9.5 */
> --
> 2.27.0
>
>

Reviewed-by: Neal Gompa 

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




Re: [PATCH v2 05/10] hyperv: implement connectGetCapabilities

2020-10-05 Thread Neal Gompa
On Mon, Oct 5, 2020 at 12:21 PM Matt Coleman  wrote:
>
> Co-authored-by: Sri Ramanujam 
> Signed-off-by: Matt Coleman 
> ---
>  src/hyperv/hyperv_driver.c  | 90 +
>  src/hyperv/hyperv_private.h |  2 +
>  2 files changed, 92 insertions(+)
>
> diff --git a/src/hyperv/hyperv_driver.c b/src/hyperv/hyperv_driver.c
> index 3e4563252e..93e08c54c0 100644
> --- a/src/hyperv/hyperv_driver.c
> +++ b/src/hyperv/hyperv_driver.c
> @@ -36,6 +36,7 @@
>  #include "openwsman.h"
>  #include "virstring.h"
>  #include "virkeycode.h"
> +#include "domain_conf.h"
>
>  #define VIR_FROM_THIS VIR_FROM_HYPERV
>
> @@ -283,6 +284,76 @@ hypervGetMemSDByVSSDInstanceId(hypervPrivate *priv, 
> const char *id,
>
>
>
> +/*
> + * API-specific utility functions
> + */
> +
> +static int
> +hypervLookupHostSystemBiosUuid(hypervPrivate *priv, unsigned char *uuid)
> +{
> +Win32_ComputerSystemProduct *computerSystem = NULL;
> +g_auto(virBuffer) query = VIR_BUFFER_INITIALIZER;
> +int result = -1;
> +
> +virBufferAddLit(, WIN32_COMPUTERSYSTEMPRODUCT_WQL_SELECT);
> +if (hypervGetWmiClass(Win32_ComputerSystemProduct, ) < 0)
> +goto cleanup;
> +
> +if (virUUIDParse(computerSystem->data.common->UUID, uuid) < 0) {
> +virReportError(VIR_ERR_INTERNAL_ERROR,
> +   _("Could not parse UUID from string '%s'"),
> +   computerSystem->data.common->UUID);
> +goto cleanup;
> +}
> +result = 0;
> +
> + cleanup:
> +hypervFreeObject(priv, (hypervObject *) computerSystem);
> +
> +return result;
> +}
> +
> +static virCapsPtr
> +hypervCapsInit(hypervPrivate *priv)
> +{
> +virCapsPtr caps = NULL;
> +virCapsGuestPtr guest = NULL;
> +
> +caps = virCapabilitiesNew(VIR_ARCH_X86_64, 1, 1);
> +
> +if (!caps)
> +return NULL;
> +
> +if (hypervLookupHostSystemBiosUuid(priv, caps->host.host_uuid) < 0)
> +goto error;
> +
> +/* i686 caps */
> +guest = virCapabilitiesAddGuest(caps, VIR_DOMAIN_OSTYPE_HVM, 
> VIR_ARCH_I686,
> +NULL, NULL, 0, NULL);
> +if (!guest)
> +goto error;
> +
> +if (!virCapabilitiesAddGuestDomain(guest, VIR_DOMAIN_VIRT_HYPERV, NULL, 
> NULL, 0, NULL))
> +goto error;
> +
> +/* x86_64 caps */
> +guest = virCapabilitiesAddGuest(caps, VIR_DOMAIN_OSTYPE_HVM, 
> VIR_ARCH_X86_64,
> +NULL, NULL, 0, NULL);
> +if (!guest)
> +goto error;
> +
> +if (!virCapabilitiesAddGuestDomain(guest, VIR_DOMAIN_VIRT_HYPERV, NULL, 
> NULL, 0, NULL))
> +goto error;
> +
> +return caps;
> +
> + error:
> +virObjectUnref(caps);
> +return NULL;
> +}
> +
> +
> +
>  /*
>   * Driver functions
>   */
> @@ -298,6 +369,9 @@ hypervFreePrivate(hypervPrivate **priv)
>  wsmc_release((*priv)->client);
>  }
>
> +if ((*priv)->caps)
> +virObjectUnref((*priv)->caps);
> +
>  hypervFreeParsedUri(&(*priv)->parsedUri);
>  VIR_FREE(*priv);
>  }
> @@ -408,6 +482,11 @@ hypervConnectOpen(virConnectPtr conn, virConnectAuthPtr 
> auth,
>  if (hypervInitConnection(conn, priv, username, password) < 0)
>  goto cleanup;
>
> +/* set up capabilities */
> +priv->caps = hypervCapsInit(priv);
> +if (!priv->caps)
> +goto cleanup;
> +
>  conn->privateData = priv;
>  priv = NULL;
>  result = VIR_DRV_OPEN_SUCCESS;
> @@ -464,6 +543,16 @@ hypervConnectGetHostname(virConnectPtr conn)
>
>
>
> +static char*
> +hypervConnectGetCapabilities(virConnectPtr conn)
> +{
> +hypervPrivate *priv = conn->privateData;
> +
> +return virCapabilitiesFormatXML(priv->caps);
> +}
> +
> +
> +
>  static int
>  hypervNodeGetInfo(virConnectPtr conn, virNodeInfoPtr info)
>  {
> @@ -1601,6 +1690,7 @@ static virHypervisorDriver hypervHypervisorDriver = {
>  .connectGetType = hypervConnectGetType, /* 0.9.5 */
>  .connectGetHostname = hypervConnectGetHostname, /* 0.9.5 */
>  .nodeGetInfo = hypervNodeGetInfo, /* 0.9.5 */
> +.connectGetCapabilities = hypervConnectGetCapabilities, /* 6.9.0 */
>  .connectListDomains = hypervConnectListDomains, /* 0.9.5 */
>  .connectNumOfDomains = hypervConnectNumOfDomains, /* 0.9.5 */
>  .connectListAllDomains = hypervConnectListAllDomains, /* 0.10.2 */
> diff --git a/src/hyperv/hyperv_private.h b/src/hyperv/hyperv_private.h
> index b502e71d83..cf08bf542b 100644
> --- a/src/hyperv/hyperv_private.h
> +++ b/src/hyperv/hyperv_private.h
> @@ -26,6 +26,7 @@
>  #include "virerror.h"
>  #include "hyperv_util.h"
>  #include "openwsman.h"
> +#include "capabilities.h"
>
>  typedef enum _hypervWmiVersion hypervWmiVersion;
>  enum _hypervWmiVersion {
> @@ -38,4 +39,5 @@ struct _hypervPrivate {
>  hypervParsedUri *parsedUri;
>  WsManClient *client;
>  hypervWmiVersion wmiVersion;
> +virCapsPtr caps;
>  };
> --
> 2.27.0
>
>

Reviewed-by: Neal Gompa 


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




Re: [PATCH v2 04/10] hyperv: replace generic WMI class list helpers with a macro

2020-10-05 Thread Neal Gompa
On Mon, Oct 5, 2020 at 12:21 PM Matt Coleman  wrote:
>
> Signed-off-by: Matt Coleman 
> ---
>  src/hyperv/hyperv_driver.c | 39 --
>  src/hyperv/hyperv_wmi.c| 83 --
>  src/hyperv/hyperv_wmi.h| 28 ++---
>  3 files changed, 36 insertions(+), 114 deletions(-)
>
> diff --git a/src/hyperv/hyperv_driver.c b/src/hyperv/hyperv_driver.c
> index 5e09c8f4af..3e4563252e 100644
> --- a/src/hyperv/hyperv_driver.c
> +++ b/src/hyperv/hyperv_driver.c
> @@ -47,6 +47,20 @@ VIR_LOG_INIT("hyperv.hyperv_driver");
>   * wrapper functions for commonly-accessed WMI objects and interfaces.
>   */
>
> +/**
> + * hypervGetWmiClass:
> + * @type: the type of the class being retrieved from WMI
> + * @class: double pointer where the class data will be stored
> + *
> + * Retrieve one or more classes from WMI.
> + *
> + * The following variables must exist in the caller:
> + *   1. hypervPrivate *priv
> + *   2. virBuffer query
> + */
> +#define hypervGetWmiClass(type, class) \
> +hypervGetWmiClassList(priv, type ## _WmiInfo, , (hypervObject 
> **)class)
> +
>  static int
>  hypervGetProcessorsByName(hypervPrivate *priv, const char *name,
>Win32_Processor **processorList)
> @@ -58,7 +72,7 @@ hypervGetProcessorsByName(hypervPrivate *priv, const char 
> *name,
> "ResultClass = Win32_Processor",
> name);
>
> -if (hypervGetWin32ProcessorList(priv, , processorList) < 0 ||
> +if (hypervGetWmiClass(Win32_Processor, processorList) < 0 ||
>  !processorList) {
>  virReportError(VIR_ERR_INTERNAL_ERROR,
> _("Could not look up processor(s) on '%s'"),
> @@ -77,7 +91,7 @@ hypervGetActiveVirtualSystemList(hypervPrivate *priv,
>   "WHERE " 
> MSVM_COMPUTERSYSTEM_WQL_VIRTUAL
>   "AND " 
> MSVM_COMPUTERSYSTEM_WQL_ACTIVE), 0 };
>
> -if (hypervGetMsvmComputerSystemList(priv, , computerSystemList) < 
> 0 ||
> +if (hypervGetWmiClass(Msvm_ComputerSystem, computerSystemList) < 0 ||
>  !*computerSystemList) {
>  virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
> _("Could not look up active virtual machines"));
> @@ -96,7 +110,7 @@ hypervGetInactiveVirtualSystemList(hypervPrivate *priv,
>   "WHERE " 
> MSVM_COMPUTERSYSTEM_WQL_VIRTUAL
>   "AND " 
> MSVM_COMPUTERSYSTEM_WQL_INACTIVE), 0 };
>
> -if (hypervGetMsvmComputerSystemList(priv, , computerSystemList) < 
> 0 ||
> +if (hypervGetWmiClass(Msvm_ComputerSystem, computerSystemList) < 0 ||
>  !*computerSystemList) {
>  virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
> _("Could not look up inactive virtual machines"));
> @@ -112,7 +126,7 @@ hypervGetPhysicalSystemList(hypervPrivate *priv,
>  {
>  g_auto(virBuffer) query = { 
> g_string_new(WIN32_COMPUTERSYSTEM_WQL_SELECT), 0 };
>
> -if (hypervGetWin32ComputerSystemList(priv, , computerSystemList) < 
> 0 ||
> +if (hypervGetWmiClass(Win32_ComputerSystem, computerSystemList) < 0 ||
>  !*computerSystemList) {
>  virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
> _("Could not look up Win32_ComputerSystem"));
> @@ -133,7 +147,7 @@ hypervGetVirtualSystemByID(hypervPrivate *priv, int id,
>"AND ProcessID = %d",
>id);
>
> -if (hypervGetMsvmComputerSystemList(priv, , computerSystemList) < 
> 0) {
> +if (hypervGetWmiClass(Msvm_ComputerSystem, computerSystemList) < 0) {
>  virReportError(VIR_ERR_OPERATION_FAILED,
> _("Could not look up virtual system with ID %d"), id);
>  return -1;
> @@ -158,7 +172,7 @@ hypervGetVirtualSystemByUUID(hypervPrivate *priv, const 
> char *uuid,
> "AND Name = \"%s\"",
> uuid);
>
> -if (hypervGetMsvmComputerSystemList(priv, , computerSystemList) < 
> 0) {
> +if (hypervGetWmiClass(Msvm_ComputerSystem, computerSystemList) < 0) {
>  virReportError(VIR_ERR_OPERATION_FAILED,
> _("Could not look up virtual system with UUID '%s'"),
> uuid);
> @@ -186,7 +200,7 @@ hypervGetVirtualSystemByName(hypervPrivate *priv, const 
> char *name,
> "AND ElementName = \"%s\"",
> name);
>
> -if (hypervGetMsvmComputerSystemList(priv, , computerSystemList) < 
> 0) {
> +if (hypervGetWmiClass(Msvm_ComputerSystem, computerSystemList) < 0) {
>  virReportError(VIR_ERR_OPERATION_FAILED,
> _("Could not look up virtual system named '%s'"), 
> name);
>  return -1;
> @@ -212,7 +226,7 @@ hypervGetVSSDFromUUID(hypervPrivate *priv, const char 
> *uuid,
> "ResultClass = 

Re: [PATCH v2 03/10] hyperv: break out common lookups into separate functions

2020-10-05 Thread Neal Gompa
On Mon, Oct 5, 2020 at 12:21 PM Matt Coleman  wrote:
>
> This eliminates some duplicate code and simplifies the driver functions.
>
> Co-authored-by: Sri Ramanujam 
> Signed-off-by: Matt Coleman 
> ---
>  src/hyperv/hyperv_driver.c | 489 -
>  1 file changed, 259 insertions(+), 230 deletions(-)
>
> diff --git a/src/hyperv/hyperv_driver.c b/src/hyperv/hyperv_driver.c
> index 9bbc2f67fb..5e09c8f4af 100644
> --- a/src/hyperv/hyperv_driver.c
> +++ b/src/hyperv/hyperv_driver.c
> @@ -41,6 +41,238 @@
>
>  VIR_LOG_INIT("hyperv.hyperv_driver");
>
> +/*
> + * WMI utility functions
> + *
> + * wrapper functions for commonly-accessed WMI objects and interfaces.
> + */
> +
> +static int
> +hypervGetProcessorsByName(hypervPrivate *priv, const char *name,
> +  Win32_Processor **processorList)
> +{
> +g_auto(virBuffer) query = VIR_BUFFER_INITIALIZER;
> +virBufferEscapeSQL(,
> +   "ASSOCIATORS OF {Win32_ComputerSystem.Name=\"%s\"} "
> +   "WHERE AssocClass = Win32_ComputerSystemProcessor "
> +   "ResultClass = Win32_Processor",
> +   name);
> +
> +if (hypervGetWin32ProcessorList(priv, , processorList) < 0 ||
> +!processorList) {
> +virReportError(VIR_ERR_INTERNAL_ERROR,
> +   _("Could not look up processor(s) on '%s'"),
> +   name);
> +return -1;
> +}
> +
> +return 0;
> +}
> +
> +static int
> +hypervGetActiveVirtualSystemList(hypervPrivate *priv,
> + Msvm_ComputerSystem **computerSystemList)
> +{
> +g_auto(virBuffer) query = { g_string_new(MSVM_COMPUTERSYSTEM_WQL_SELECT
> + "WHERE " 
> MSVM_COMPUTERSYSTEM_WQL_VIRTUAL
> + "AND " 
> MSVM_COMPUTERSYSTEM_WQL_ACTIVE), 0 };
> +
> +if (hypervGetMsvmComputerSystemList(priv, , computerSystemList) < 
> 0 ||
> +!*computerSystemList) {
> +virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
> +   _("Could not look up active virtual machines"));
> +return -1;
> +}
> +
> +return 0;
> +}
> +
> +/* gets all the vms including the ones that are marked inactive. */
> +static int
> +hypervGetInactiveVirtualSystemList(hypervPrivate *priv,
> +   Msvm_ComputerSystem **computerSystemList)
> +{
> +g_auto(virBuffer) query = { g_string_new(MSVM_COMPUTERSYSTEM_WQL_SELECT
> + "WHERE " 
> MSVM_COMPUTERSYSTEM_WQL_VIRTUAL
> + "AND " 
> MSVM_COMPUTERSYSTEM_WQL_INACTIVE), 0 };
> +
> +if (hypervGetMsvmComputerSystemList(priv, , computerSystemList) < 
> 0 ||
> +!*computerSystemList) {
> +virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
> +   _("Could not look up inactive virtual machines"));
> +return -1;
> +}
> +
> +return 0;
> +}
> +
> +static int
> +hypervGetPhysicalSystemList(hypervPrivate *priv,
> +Win32_ComputerSystem **computerSystemList)
> +{
> +g_auto(virBuffer) query = { 
> g_string_new(WIN32_COMPUTERSYSTEM_WQL_SELECT), 0 };
> +
> +if (hypervGetWin32ComputerSystemList(priv, , computerSystemList) < 
> 0 ||
> +!*computerSystemList) {
> +virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
> +   _("Could not look up Win32_ComputerSystem"));
> +return -1;
> +}
> +
> +return 0;
> +}
> +
> +static int
> +hypervGetVirtualSystemByID(hypervPrivate *priv, int id,
> +   Msvm_ComputerSystem **computerSystemList)
> +{
> +g_auto(virBuffer) query = VIR_BUFFER_INITIALIZER;
> +virBufferAsprintf(,
> +  MSVM_COMPUTERSYSTEM_WQL_SELECT
> +  "WHERE " MSVM_COMPUTERSYSTEM_WQL_VIRTUAL
> +  "AND ProcessID = %d",
> +  id);
> +
> +if (hypervGetMsvmComputerSystemList(priv, , computerSystemList) < 
> 0) {
> +virReportError(VIR_ERR_OPERATION_FAILED,
> +   _("Could not look up virtual system with ID %d"), id);
> +return -1;
> +}
> +
> +if (*computerSystemList == NULL) {
> +virReportError(VIR_ERR_NO_DOMAIN, _("No domain with ID %d"), id);
> +return -1;
> +}
> +
> +return 0;
> +}
> +
> +static int
> +hypervGetVirtualSystemByUUID(hypervPrivate *priv, const char *uuid,
> + Msvm_ComputerSystem **computerSystemList)
> +{
> +g_auto(virBuffer) query = VIR_BUFFER_INITIALIZER;
> +virBufferEscapeSQL(,
> +   MSVM_COMPUTERSYSTEM_WQL_SELECT
> +   "WHERE " MSVM_COMPUTERSYSTEM_WQL_VIRTUAL
> +   "AND Name = \"%s\"",
> +   uuid);
> +
> +if (hypervGetMsvmComputerSystemList(priv, , computerSystemList) < 
> 0) {

Re: [PATCH v2 02/10] hyperv: fix nodeGetInfo failures caused by long CPU names

2020-10-05 Thread Neal Gompa
On Mon, Oct 5, 2020 at 12:21 PM Matt Coleman  wrote:
>
> Some CPU model names were too long for _virNodeInfo.model.
> For example: Intel Xeon CPU E5-2620 v2 @ 2.10GHz
> This commit removes the clock frequency suffix.
>
> Signed-off-by: Matt Coleman 
> ---
>  src/hyperv/hyperv_driver.c | 4 
>  1 file changed, 4 insertions(+)
>
> diff --git a/src/hyperv/hyperv_driver.c b/src/hyperv/hyperv_driver.c
> index b57325f2a5..9bbc2f67fb 100644
> --- a/src/hyperv/hyperv_driver.c
> +++ b/src/hyperv/hyperv_driver.c
> @@ -285,6 +285,10 @@ hypervNodeGetInfo(virConnectPtr conn, virNodeInfoPtr 
> info)
>  } else if (STRPREFIX(tmp, "(TM)")) {
>  memmove(tmp, tmp + 4, strlen(tmp + 4) + 1);
>  continue;
> +} else if (STRPREFIX(tmp, " @ ")) {
> +/* Remove " @ X.YZGHz" from the end. */
> +*tmp = '\0';
> +break;
>  }
>
>  ++tmp;
> --
> 2.27.0
>
>

Reviewed-by: Neal Gompa 

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




Re: [PATCH v2 01/10] hyperv: make Msvm_ComputerSystem WQL queries locale agnostic

2020-10-05 Thread Neal Gompa
On Mon, Oct 5, 2020 at 12:21 PM Matt Coleman  wrote:
>
> There are two specific WQL queries we're using to get either a list of
> virtual machines or the hypervisor host itself from Msvm_ComputerSystem.
> Those queries rely on filtering results based on the "Description"
> field. Since the "Description" field is locale sensitive, the queries
> will fail if the Windows host is using a language pack. While the WSMAN
> spec allows the client to set the requested locale (and it is supported
> since openwsman 2.6.x), the Windows WinRM service does not respect this
> setting: it returns non-English strings despite the WSMAN request
> properly setting the locale to 'en-US'. Therefore, this patch changes
> the WQL query to make use of the "__SERVER" field to stop relying on
> English strings in queries and side step the issue.
>
> Co-authored-by: Dawid Zamirski 
> Signed-off-by: Matt Coleman 
> ---
>  src/hyperv/hyperv_wmi_classes.h | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/src/hyperv/hyperv_wmi_classes.h b/src/hyperv/hyperv_wmi_classes.h
> index a19b6a656d..7465684d6e 100644
> --- a/src/hyperv/hyperv_wmi_classes.h
> +++ b/src/hyperv/hyperv_wmi_classes.h
> @@ -44,10 +44,10 @@
>   */
>
>  #define MSVM_COMPUTERSYSTEM_WQL_VIRTUAL \
> -"Description = \"Microsoft Virtual Machine\" "
> +"Name != __SERVER "
>
>  #define MSVM_COMPUTERSYSTEM_WQL_PHYSICAL \
> -"Description = \"Microsoft Hosting Computer System\" "
> +"Name = __SERVER "
>
>  #define MSVM_COMPUTERSYSTEM_WQL_ACTIVE \
>  "(EnabledState != 0 and EnabledState != 3 and EnabledState != 32769) "
> --
> 2.27.0
>
>

Should we require a bump to openwsman 2.6 for this?


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




Re: [libvirt PATCH 7/9] spec: Drop s390 architecture from conditionals

2020-10-05 Thread Neal Gompa
On Mon, Oct 5, 2020 at 2:41 PM Andrea Bolognani  wrote:
>
> Neither Fedora nor RHEL build packages on this architecture.
>
> Signed-off-by: Andrea Bolognani 
> ---
>  libvirt.spec.in | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/libvirt.spec.in b/libvirt.spec.in
> index d8f689e651..e036307d30 100644
> --- a/libvirt.spec.in
> +++ b/libvirt.spec.in
> @@ -109,12 +109,12 @@
>  %endif
>
>  # Numactl is not available on many non-x86 archs
> -%ifarch s390 s390x %{arm} riscv64
> +%ifarch s390x %{arm} riscv64
>  %define with_numactl 0
>  %endif
>
>  # zfs-fuse is not available on some architectures
> -%ifarch s390 s390x aarch64 riscv64
> +%ifarch s390x aarch64 riscv64
>  %define with_storage_zfs 0
>  %endif
>
> @@ -179,7 +179,7 @@
>  %if %{with_qemu} || %{with_lxc}
>  # numad is used to manage the CPU and memory placement dynamically,
>  # it's not available on many non-x86 architectures.
> -%ifnarch s390 s390x %{arm} riscv64
> +%ifnarch s390x %{arm} riscv64
>  %define with_numad0%{!?_without_numad:1}
>  %endif
>  %endif
> --
> 2.26.2
>

Good riddance to bad architectures...

Reviewed-by: Neal Gompa 


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




Re: [libvirt PATCH 8/9] spec: Refactor qemu_kvm_arches definition

2020-10-05 Thread Neal Gompa
On Mon, Oct 5, 2020 at 2:41 PM Andrea Bolognani  wrote:
>
> There's no need to set a default for it if we're going to override
> it immediately afterwards anyway, and setting with_qemu_tcg at the
> same time only makes things more confusing.
>
> Signed-off-by: Andrea Bolognani 
> ---
>  libvirt.spec.in | 26 +-
>  1 file changed, 13 insertions(+), 13 deletions(-)
>
> diff --git a/libvirt.spec.in b/libvirt.spec.in
> index e036307d30..b62b17ee80 100644
> --- a/libvirt.spec.in
> +++ b/libvirt.spec.in
> @@ -17,31 +17,31 @@
>  %define _vpath_builddir %{_target_platform}
>  %endif
>
> +%if 0%{?fedora}
> +%define qemu_kvm_arches %{ix86} x86_64 %{power64} s390x %{arm} 
> aarch64
> +%else
> +%define qemu_kvm_arches x86_64 %{power64} aarch64 s390x
> +%endif
> +
>  # The hypervisor drivers that run in libvirtd
>  %define with_qemu  0%{!?_without_qemu:1}
>  %define with_lxc   0%{!?_without_lxc:1}
>  %define with_libxl 0%{!?_without_libxl:1}
>  %define with_vbox  0%{!?_without_vbox:1}
>
> -%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
> -
>  %ifarch %{qemu_kvm_arches}
>  %define with_qemu_kvm  %{with_qemu}
>  %else
>  %define with_qemu_kvm  0
>  %endif
>
> +%define with_qemu_tcg  %{with_qemu}
> +
> +# RHEL disables TCG on all architectures
> +%if 0%{?rhel}
> +%define with_qemu_tcg 0
> +%endif
> +
>  %if ! %{with_qemu_tcg} && ! %{with_qemu_kvm}
>  %define with_qemu 0
>  %endif
> --
> 2.26.2
>

Reviewed-by: Neal Gompa 

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




Re: [libvirt PATCH 6/9] spec: Move _vpath_builddir definition

2020-10-05 Thread Neal Gompa
On Mon, Oct 5, 2020 at 2:41 PM Andrea Bolognani  wrote:
>
> It belongs before package-specific feature flags are defined.
>
> Signed-off-by: Andrea Bolognani 
> ---
>  libvirt.spec.in | 10 +-
>  1 file changed, 5 insertions(+), 5 deletions(-)
>
> diff --git a/libvirt.spec.in b/libvirt.spec.in
> index 2401404008..d8f689e651 100644
> --- a/libvirt.spec.in
> +++ b/libvirt.spec.in
> @@ -12,6 +12,11 @@
>  %define supported_platform 0
>  %endif
>
> +# On RHEL 7 and older macro _vpath_builddir is not defined.
> +%if 0%{?rhel} && 0%{?rhel} <= 7
> +%define _vpath_builddir %{_target_platform}
> +%endif
> +
>  # The hypervisor drivers that run in libvirtd
>  %define with_qemu  0%{!?_without_qemu:1}
>  %define with_lxc   0%{!?_without_lxc:1}
> @@ -31,11 +36,6 @@
>  %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
> --
> 2.26.2
>

Do we still need this anymore? Meson in EPEL 7 works without this definition...

But otherwise...

Reviewed-by: Neal Gompa 


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




Re: [libvirt PATCH 5/9] spec: Introduce with_dmidecode

2020-10-05 Thread Neal Gompa
On Mon, Oct 5, 2020 at 2:41 PM Andrea Bolognani  wrote:
>
> To keep things maintainable, we want to have architecture handling
> all in one spot instead of sprinkling %ifarch conditionals all over
> the place.
>
> Signed-off-by: Andrea Bolognani 
> ---
>  libvirt.spec.in | 7 ++-
>  1 file changed, 6 insertions(+), 1 deletion(-)
>
> diff --git a/libvirt.spec.in b/libvirt.spec.in
> index 65df7dc79f..2401404008 100644
> --- a/libvirt.spec.in
> +++ b/libvirt.spec.in
> @@ -94,6 +94,7 @@
>  %define with_libssh2  0
>  %define with_wireshark0
>  %define with_libssh   0
> +%define with_dmidecode0
>
>  # Finally set the OS / architecture specific special cases
>
> @@ -183,6 +184,10 @@
>  %endif
>  %endif
>
> +%ifarch %{ix86} x86_64
> +%define with_dmidecode 0%{!?_without_dmidecode:1}
> +%endif
> +
>  # Force QEMU to run as non-root
>  %define qemu_user  qemu
>  %define qemu_group  qemu
> @@ -434,7 +439,7 @@ Requires: iproute-tc
>  %endif
>
>  Requires: polkit >= 0.112
> -%ifarch %{ix86} x86_64
> +%if %{with_dmidecode}
>  # For virConnectGetSysinfo
>  Requires: dmidecode
>  %endif
> --
> 2.26.2
>

Reviewed-by: Neal Gompa 


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




Re: [libvirt PATCH 4/9] spec: Move with_numactl definition

2020-10-05 Thread Neal Gompa
On Mon, Oct 5, 2020 at 2:40 PM Andrea Bolognani  wrote:
>
> Keep it close to similar ones.
>
> Signed-off-by: Andrea Bolognani 
> ---
>  libvirt.spec.in | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/libvirt.spec.in b/libvirt.spec.in
> index 9e4c5d2b81..65df7dc79f 100644
> --- a/libvirt.spec.in
> +++ b/libvirt.spec.in
> @@ -68,8 +68,6 @@
>  %endif
>  %endif
>
> -%define with_numactl  0%{!?_without_numactl:1}
> -
>  # F25+ has zfs-fuse
>  %if 0%{?fedora}
>  %define with_storage_zfs  0%{!?_without_storage_zfs:1}
> @@ -86,6 +84,7 @@
>
>  # Other optional features
>  %define with_bash_completion  0%{!?_without_bash_completion:1}
> +%define with_numactl  0%{!?_without_numactl:1}
>
>  # A few optional bits off by default, we enable later
>  %define with_fuse 0
> --
> 2.26.2
>

Reviewed-by: Neal Gompa 


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




Re: [libvirt PATCH 3/9] spec: bash completion actually defaults to on

2020-10-05 Thread Neal Gompa
On Mon, Oct 5, 2020 at 2:41 PM Andrea Bolognani  wrote:
>
> Remove the red herring.
>
> Signed-off-by: Andrea Bolognani 
> ---
>  libvirt.spec.in | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/libvirt.spec.in b/libvirt.spec.in
> index 4572044d2d..9e4c5d2b81 100644
> --- a/libvirt.spec.in
> +++ b/libvirt.spec.in
> @@ -84,6 +84,9 @@
>  %define with_storage_iscsi_direct 0
>  %endif
>
> +# Other optional features
> +%define with_bash_completion  0%{!?_without_bash_completion:1}
> +
>  # A few optional bits off by default, we enable later
>  %define with_fuse 0
>  %define with_sanlock  0
> @@ -92,7 +95,6 @@
>  %define with_libssh2  0
>  %define with_wireshark0
>  %define with_libssh   0
> -%define with_bash_completion  0
>
>  # Finally set the OS / architecture specific special cases
>
> @@ -174,8 +176,6 @@
>  %define with_libssh 0%{!?_without_libssh:1}
>  %endif
>
> -%define with_bash_completion  0%{!?_without_bash_completion:1}
> -
>  %if %{with_qemu} || %{with_lxc}
>  # numad is used to manage the CPU and memory placement dynamically,
>  # it's not available on many non-x86 architectures.
> --
> 2.26.2
>

This is more crappy fake-%bcond goop, except in the other direction...

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




Re: [libvirt PATCH 2/9] spec: firewalld is always enabled

2020-10-05 Thread Neal Gompa
On Mon, Oct 5, 2020 at 2:40 PM Andrea Bolognani  wrote:
>
> Knowing this, we can remove some code.
>
> Signed-off-by: Andrea Bolognani 
> ---
>  libvirt.spec.in | 11 +--
>  1 file changed, 1 insertion(+), 10 deletions(-)
>
> diff --git a/libvirt.spec.in b/libvirt.spec.in
> index 815ab246e9..4572044d2d 100644
> --- a/libvirt.spec.in
> +++ b/libvirt.spec.in
> @@ -88,7 +88,6 @@
>  %define with_fuse 0
>  %define with_sanlock  0
>  %define with_numad0
> -%define with_firewalld0
>  %define with_firewalld_zone   0
>  %define with_libssh2  0
>  %define with_wireshark0
> @@ -138,8 +137,6 @@
>  %endif
>  %endif
>
> -%define with_firewalld 1
> -
>  %if 0%{?fedora} || 0%{?rhel} > 7
>  %define with_firewalld_zone 0%{!?_without_firewalld_zone:1}
>  %endif
> @@ -1088,12 +1085,6 @@ exit 1
>  %define arg_sanlock -Dsanlock=disabled
>  %endif
>
> -%if %{with_firewalld}
> -%define arg_firewalld -Dfirewalld=enabled
> -%else
> -%define arg_firewalld -Dfirewalld=disabled
> -%endif
> -
>  %if %{with_firewalld_zone}
>  %define arg_firewalld_zone -Dfirewalld_zone=enabled
>  %else
> @@ -1169,7 +1160,7 @@ export SOURCE_DATE_EPOCH=$(stat --printf='%Y' 
> %{_specdir}/%{name}.spec)
> -Dlibpcap=enabled \
> -Daudit=enabled \
> -Ddtrace=enabled \
> -   %{?arg_firewalld} \
> +   -Dfirewalld=enabled \
> %{?arg_firewalld_zone} \
> %{?arg_wireshark} \
> -Dpm_utils=disabled \
> --
> 2.26.2
>

Reviewed-by: Neal Gompa 

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




Re: [libvirt PATCH 1/9] spec: Simplify setting features off by default

2020-10-05 Thread Neal Gompa
On Mon, Oct 5, 2020 at 2:40 PM Andrea Bolognani  wrote:
>
> The right-hand side of these expressions will always evaluate to
> zero. Stop obfuscating this fact.
>
> Signed-off-by: Andrea Bolognani 
> ---
>  libvirt.spec.in | 18 +-
>  1 file changed, 9 insertions(+), 9 deletions(-)
>
> diff --git a/libvirt.spec.in b/libvirt.spec.in
> index d13aae5cf5..815ab246e9 100644
> --- a/libvirt.spec.in
> +++ b/libvirt.spec.in
> @@ -85,15 +85,15 @@
>  %endif
>
>  # A few optional bits off by default, we enable later
> -%define with_fuse  0%{!?_without_fuse:0}
> -%define with_sanlock   0%{!?_without_sanlock:0}
> -%define with_numad 0%{!?_without_numad:0}
> -%define with_firewalld 0%{!?_without_firewalld:0}
> -%define with_firewalld_zone 0%{!?_without_firewalld_zone:0}
> -%define with_libssh2   0%{!?_without_libssh2:0}
> -%define with_wireshark 0%{!?_without_wireshark:0}
> -%define with_libssh0%{!?_without_libssh:0}
> -%define with_bash_completion  0%{!?_without_bash_completion:0}
> +%define with_fuse 0
> +%define with_sanlock  0
> +%define with_numad0
> +%define with_firewalld0
> +%define with_firewalld_zone   0
> +%define with_libssh2  0
> +%define with_wireshark0
> +%define with_libssh   0
> +%define with_bash_completion  0
>
>  # Finally set the OS / architecture specific special cases
>

This crazy setup is an attempt to implement rpm %bcond behavior
without actually using %bcond statements. Instead of removing the
right-hand-side conditionals, perhaps it'd be better to just finally
make the switch to %bcond statements.


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




Re: [libvirt PATCH 9/9] spec: Introduce arches_*

2020-10-05 Thread Neal Gompa
On Mon, Oct 5, 2020 at 2:41 PM Andrea Bolognani  wrote:
>
> With this commit, all architecture lists that we base feature
> enablement decisions on are defined within a few lines of each
> other, increasing maintainability.
>
> Additionally, generic architecture lists that appear in the
> conditions for multiple features are defined, so that repetition
> is reduced.
>
> Note that a few checks (numactl, zfs, ceph) have been changed
> from %ifarch to %ifnarch for consistency: while doing so, the
> corresponding list of architectures has also been replaced with
> the complement of the original one to ensure the overall behavior
> would be preserved.
>
> Signed-off-by: Andrea Bolognani 
> ---
>  libvirt.spec.in | 48 ++--
>  1 file changed, 26 insertions(+), 22 deletions(-)
>
> diff --git a/libvirt.spec.in b/libvirt.spec.in
> index b62b17ee80..32bc51b33c 100644
> --- a/libvirt.spec.in
> +++ b/libvirt.spec.in
> @@ -17,10 +17,22 @@
>  %define _vpath_builddir %{_target_platform}
>  %endif
>
> +%define arches_64bitx86_64 %{power64} aarch64 s390x riscv64
> +%define arches_x86  %{ix86} x86_64
> +
> +%define arches_systemtap_64bit  %{arches_64bit}
> +%define arches_dmidecode%{arches_x86}
> +%define arches_xen  %{arches_x86}
> +%define arches_vbox %{arches_x86}
> +%define arches_ceph %{arches_64bit}
> +%define arches_zfs  %{arches_x86} %{power64} %{arm}
> +%define arches_numactl  %{arches_x86} %{power64} aarch64
> +%define arches_numad%{arches_x86} %{power64} aarch64
> +
>  %if 0%{?fedora}
> -%define qemu_kvm_arches %{ix86} x86_64 %{power64} s390x %{arm} 
> aarch64
> +%define arches_qemu_kvm %{arches_x86} %{power64} s390x %{arm} aarch64
>  %else
> -%define qemu_kvm_arches x86_64 %{power64} aarch64 s390x
> +%define arches_qemu_kvm x86_64 %{power64} aarch64 s390x
>  %endif
>

This conditional is functionally irrelevant. The superset defined for
Fedora does not change how things work for RHEL, and it'd be easier to
just use the one architecture set.


>  # The hypervisor drivers that run in libvirtd
> @@ -29,7 +41,7 @@
>  %define with_libxl 0%{!?_without_libxl:1}
>  %define with_vbox  0%{!?_without_vbox:1}
>
> -%ifarch %{qemu_kvm_arches}
> +%ifarch %{arches_qemu_kvm}
>  %define with_qemu_kvm  %{with_qemu}
>  %else
>  %define with_qemu_kvm  0
> @@ -61,7 +73,7 @@
>  %endif
>
>  %define with_storage_gluster 0%{!?_without_storage_gluster:1}
> -%ifnarch %{qemu_kvm_arches}
> +%ifnarch %{arches_qemu_kvm}
>  # gluster is only built where qemu driver is enabled on RHEL 8
>  %if 0%{?rhel} >= 8
>  %define with_storage_gluster 0
> @@ -98,28 +110,20 @@
>
>  # Finally set the OS / architecture specific special cases
>
> -# Xen is available only on i386 x86_64
> -%ifnarch %{ix86} x86_64
> +# Architecture-dependent features
> +%ifnarch %{arches_xen}
>  %define with_libxl 0
>  %endif
> -
> -# vbox is available only on i386 x86_64
> -%ifnarch %{ix86} x86_64
> +%ifnarch %{arches_vbox}
>  %define with_vbox 0
>  %endif
> -
> -# Numactl is not available on many non-x86 archs
> -%ifarch s390x %{arm} riscv64
> +%ifnarch %{arches_numactl}
>  %define with_numactl 0
>  %endif
> -
> -# zfs-fuse is not available on some architectures
> -%ifarch s390x aarch64 riscv64
> +%ifnarch %{arches_zfs}
>  %define with_storage_zfs 0
>  %endif
> -
> -# Ceph dropped support for 32-bit hosts
> -%ifarch %{arm} %{ix86}
> +%ifnarch %{arches_ceph}
>  %define with_storage_rbd 0
>  %endif
>
> @@ -155,7 +159,7 @@
>  %define with_sanlock 0%{!?_without_sanlock:1}
>  %endif
>  %if 0%{?rhel}
> -%ifarch %{qemu_kvm_arches}
> +%ifarch %{arches_qemu_kvm}
>  %define with_sanlock 0%{!?_without_sanlock:1}
>  %endif
>  %endif
> @@ -179,12 +183,12 @@
>  %if %{with_qemu} || %{with_lxc}
>  # numad is used to manage the CPU and memory placement dynamically,
>  # it's not available on many non-x86 architectures.
> -%ifnarch s390x %{arm} riscv64
> +%ifnarch %{arches_numad}
>  %define with_numad0%{!?_without_numad:1}
>  %endif
>  %endif
>
> -%ifarch %{ix86} x86_64
> +%ifarch %{arches_dmidecode}
>  %define with_dmidecode 0%{!?_without_dmidecode:1}
>  %endif
>
> @@ -1256,7 +1260,7 @@ rm -f 
> $RPM_BUILD_ROOT%{_datadir}/augeas/lenses/tests/test_libvirtd_libxl.aug
>  # Copied into libvirt-docs subpackage eventually
>  mv $RPM_BUILD_ROOT%{_datadir}/doc/libvirt libvirt-docs
>
> -%ifarch %{power64} s390x x86_64 aarch64 riscv64
> +%ifarch %{arches_systemtap_64bit}
>  mv $RPM_BUILD_ROOT%{_datadir}/systemtap/tapset/libvirt_probes.stp \
> $RPM_BUILD_ROOT%{_datadir}/systemtap/tapset/libvirt_probes-64.stp
>
> --
> 2.26.2
>


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




[PATCH] mailmap: consolidate my email addresses

2020-10-05 Thread Matt Coleman
Signed-off-by: Matt Coleman 
---
 .mailmap | 1 +
 1 file changed, 1 insertion(+)

diff --git a/.mailmap b/.mailmap
index 2b080568bc..9dfb7a832b 100644
--- a/.mailmap
+++ b/.mailmap
@@ -47,6 +47,7 @@
  
  
  
+ 
 
 # Name consolidation:
 # Preferred author spelling 
-- 
2.27.0




[PATCH v2 08/10] hyperv: implement connectGetVersion

2020-10-05 Thread Matt Coleman
Hyper-V version numbers are not compatible with the encoding in
virParseVersionString():
https://gitlab.com/libvirt/libvirt/-/blob/master/src/util/virutil.c#L246

For example, the Windows Server 2016 Hyper-V version is 10.0.14393: its
micro is over 14 times larger than the encoding allows.

This commit repacks the Hyper-V version number in order to preserve all
of the digits. The major and minor are concatenated (with minor zero-
padded to two digits) to form the repacked major value. This works
because Microsoft's major and minor versions numbers are unlikely to
exceed 99. The repacked minor value is derived from the digits in the
thousands, ten-thousands, and hundred-thousands places of Hyper-V's
micro. The repacked micro is derived from the digits in the ones, tens,
and hundreds places of Hyper-V's micro.

Co-authored-by: Sri Ramanujam 
Signed-off-by: Matt Coleman 
---
 docs/drvhyperv.html.in | 50 +++
 src/hyperv/hyperv_driver.c | 81 ++
 2 files changed, 131 insertions(+)

diff --git a/docs/drvhyperv.html.in b/docs/drvhyperv.html.in
index 78f61aaee2..e8e2113f70 100644
--- a/docs/drvhyperv.html.in
+++ b/docs/drvhyperv.html.in
@@ -112,4 +112,54 @@ winrm set winrm/config/service @{AllowUnencrypted="true"}
 
 
 
+Version Numbers
+
+Since Microsoft's build numbers are almost always over 1000, this 
driver
+needs to pack the value differently compared to the format defined by
+virConnectGetVersion.
+To preserve all of the digits, the following format is used:
+
+major * 1 + minor * 100 + micro
+
+This results in virsh version producing unexpected output.
+
+
+
+Windows Release
+Kernel Version
+libvirt Representation
+
+
+Windows Server 2008
+6.0.6001
+600.6.1
+
+
+Windows Server 2008 R2
+6.1.7600
+601.7.600
+
+
+Windows Server 2012
+6.2.9200
+602.9.200
+
+
+Windows Server 2012 R2
+6.3.9600
+603.9.600
+
+
+Windows Server 2016
+10.0.14393
+1000.14.393
+
+
+Windows Server 2019
+10.0.17763
+1000.17.763
+
+
+
+
 
diff --git a/src/hyperv/hyperv_driver.c b/src/hyperv/hyperv_driver.c
index bbe892fd62..528c826e16 100644
--- a/src/hyperv/hyperv_driver.c
+++ b/src/hyperv/hyperv_driver.c
@@ -29,6 +29,7 @@
 #include "viralloc.h"
 #include "virlog.h"
 #include "viruuid.h"
+#include "virutil.h"
 #include "hyperv_driver.h"
 #include "hyperv_private.h"
 #include "hyperv_util.h"
@@ -288,6 +289,24 @@ hypervGetMemSDByVSSDInstanceId(hypervPrivate *priv, const 
char *id,
  * API-specific utility functions
  */
 
+static int
+hypervParseVersionString(const char *str, unsigned int *major,
+ unsigned int *minor, unsigned int *micro)
+{
+char *suffix = NULL;
+
+if (virStrToLong_ui(str, , 10, major) < 0)
+return -1;
+
+if (virStrToLong_ui(suffix + 1, , 10, minor) < 0)
+return -1;
+
+if (virStrToLong_ui(suffix + 1, NULL, 10, micro) < 0)
+return -1;
+
+return 0;
+}
+
 static int
 hypervLookupHostSystemBiosUuid(hypervPrivate *priv, unsigned char *uuid)
 {
@@ -523,6 +542,67 @@ hypervConnectGetType(virConnectPtr conn G_GNUC_UNUSED)
 
 
 
+static int
+hypervConnectGetVersion(virConnectPtr conn, unsigned long *version)
+{
+int result = -1;
+hypervPrivate *priv = conn->privateData;
+Win32_OperatingSystem *os = NULL;
+g_auto(virBuffer) query = { 
g_string_new(WIN32_OPERATINGSYSTEM_WQL_SELECT), 0 };
+unsigned int major, minor, micro;
+
+if (hypervGetWmiClass(Win32_OperatingSystem, ) < 0 ||
+!os) {
+virReportError(VIR_ERR_INTERNAL_ERROR,
+   _("Could not get version information for host %s"),
+   conn->uri->server);
+goto cleanup;
+}
+
+if (hypervParseVersionString(os->data.common->Version,
+ , , ) < 0) {
+virReportError(VIR_ERR_INTERNAL_ERROR,
+   _("Could not parse version from '%s'"),
+   os->data.common->Version);
+goto cleanup;
+}
+
+/*
+ * Pack the version into an unsigned long while retaining all the digits.
+ *
+ * Since Microsoft's build numbers are almost always over 1000, this driver
+ * needs to pack the value differently compared to the format defined by
+ * virConnectGetVersion().
+ *
+ * This results in `virsh version` producing unexpected output.
+ *
+ * For example...
+ * 2008:  6.0.6001 =>   600.6.1
+ * 2008 R2:   6.1.7600 =>   601.7.600
+ * 2012:  6.2.9200 =>   602.9.200
+ * 2012 R2:   6.3.9600 =>   

[PATCH v2 10/10] news: document new Hyper-V features and bug fixes

2020-10-05 Thread Matt Coleman
Signed-off-by: Matt Coleman 
---
 NEWS.rst | 10 ++
 1 file changed, 10 insertions(+)

diff --git a/NEWS.rst b/NEWS.rst
index b2ed661c8e..e708f06e9e 100644
--- a/NEWS.rst
+++ b/NEWS.rst
@@ -19,10 +19,20 @@ v6.9.0 (unreleased)
 local file-backed disks to configure a disk which discards changes made to
 it while the VM was active.
 
+  * hyperv: implement new APIs
+
+The ``virConnectGetCapabilities()``, ``virConnectGetMaxVcpus()``,
+``virConnectGetVersion()``, and ``virDomainGetAutostart()`` APIs have been
+implemented in the Hyper-V driver.
+
 * **Improvements**
 
 * **Bug fixes**
 
+  * hyperv: ensure WQL queries work in all locales
+
+Relying on the "Description" field caused queries to fail on non-"en-US"
+systems. The queries have been updated to avoid using localized strings.
 
 v6.8.0 (2020-10-01)
 ===
-- 
2.27.0




[PATCH v2 09/10] hyperv: implement domainGetAutostart

2020-10-05 Thread Matt Coleman
Co-authored-by: Sri Ramanujam 
Signed-off-by: Matt Coleman 
---
 src/hyperv/hyperv_driver.c | 40 ++
 1 file changed, 40 insertions(+)

diff --git a/src/hyperv/hyperv_driver.c b/src/hyperv/hyperv_driver.c
index 528c826e16..dcde469442 100644
--- a/src/hyperv/hyperv_driver.c
+++ b/src/hyperv/hyperv_driver.c
@@ -1274,6 +1274,45 @@ hypervDomainCreate(virDomainPtr domain)
 
 
 
+static int
+hypervDomainGetAutostart(virDomainPtr domain, int *autostart)
+{
+int result = -1;
+char uuid_string[VIR_UUID_STRING_BUFLEN];
+hypervPrivate *priv = domain->conn->privateData;
+g_auto(virBuffer) query = VIR_BUFFER_INITIALIZER;
+Msvm_VirtualSystemGlobalSettingData *vsgsd = NULL;
+Msvm_VirtualSystemSettingData *vssd = NULL;
+
+virUUIDFormat(domain->uuid, uuid_string);
+
+if (priv->wmiVersion == HYPERV_WMI_VERSION_V1) {
+virBufferEscapeSQL(,
+   MSVM_VIRTUALSYSTEMGLOBALSETTINGDATA_WQL_SELECT
+   "WHERE SystemName = \"%s\"", uuid_string);
+
+if (hypervGetWmiClass(Msvm_VirtualSystemGlobalSettingData, ) < 0)
+goto cleanup;
+
+*autostart = vsgsd->data.common->AutomaticStartupAction == 2;
+result = 0;
+} else {
+if (hypervGetVSSDFromUUID(priv, uuid_string, ) < 0)
+goto cleanup;
+
+*autostart = vssd->data.v2->AutomaticStartupAction == 4;
+result = 0;
+}
+
+cleanup:
+hypervFreeObject(priv, (hypervObject *) vsgsd);
+hypervFreeObject(priv, (hypervObject *) vssd);
+
+return result;
+}
+
+
+
 static int
 hypervConnectIsEncrypted(virConnectPtr conn)
 {
@@ -1824,6 +1863,7 @@ static virHypervisorDriver hypervHypervisorDriver = {
 .connectNumOfDefinedDomains = hypervConnectNumOfDefinedDomains, /* 0.9.5 */
 .domainCreate = hypervDomainCreate, /* 0.9.5 */
 .domainCreateWithFlags = hypervDomainCreateWithFlags, /* 0.9.5 */
+.domainGetAutostart = hypervDomainGetAutostart, /* 6.9.0 */
 .connectIsEncrypted = hypervConnectIsEncrypted, /* 0.9.5 */
 .connectIsSecure = hypervConnectIsSecure, /* 0.9.5 */
 .domainIsActive = hypervDomainIsActive, /* 0.9.5 */
-- 
2.27.0




[PATCH v2 07/10] hyperv: fix Win32_OperatingSystem WMI queries

2020-10-05 Thread Matt Coleman
CurrentTimeZone's type is a signed integer, not unsigned.

Signed-off-by: Matt Coleman 
---
 src/hyperv/hyperv_wmi_generator.input | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/hyperv/hyperv_wmi_generator.input 
b/src/hyperv/hyperv_wmi_generator.input
index 77543cf6ef..bbca550790 100644
--- a/src/hyperv/hyperv_wmi_generator.input
+++ b/src/hyperv/hyperv_wmi_generator.input
@@ -673,7 +673,7 @@ class Win32_OperatingSystem
 string   CSCreationClassName
 string   CSDVersion
 string   CSName
-uint16   CurrentTimeZone
+int16CurrentTimeZone
 boolean  DataExecutionPrevention_Available
 boolean  DataExecutionPrevention_32BitApplications
 boolean  DataExecutionPrevention_Drivers
-- 
2.27.0




[PATCH v2 00/10] hyperv: implement new APIs & more

2020-10-05 Thread Matt Coleman
These patches fix a couple bugs, consolidate duplicate code, and 
implement several APIs.

Currently, some interactions with Hyper-V systems fail when the system 
is not configured for the "en-US" locale. Additionally, some CPU names 
also contain the clock frequency, making it too long for 
_virNodeInfo.model. The first two patches fix these bugs.

The second two patches clean up the code a little: one moves repeated 
operations into new helper functions; the other replaces the generic 
"get WMI class list" functions with a macro.

The next four patches implement the following APIs in the Hyper-V 
driver:
* virConnectGetCapabilities()
* virConnectGetMaxVcpus()
* virConnectGetVersion()
* virDomainGetAutostart()

Changes since v1:
* all NEWS updates are now in a single commit at the end
* long function calls have been split up into multiple lines
* improved error handling in hypervDomainLookupBy*(): they now throw
  VIR_ERR_NO_DOMAIN when appropriate
* unnecessary calls to virReportError() have been removed from
  hypervDomainGetInfo() and hypervDomainGetXMLDesc()
* HTML documentation for the unusual Hyper-V versions
* the WMI schema fix has been split into a separate commit
* hypervConnectGetVersion() uses a new hypervParseVersionString() and
  directly produces the unsigned long instead of calling
  virParseVersionString()

Matt Coleman (10):
  hyperv: make Msvm_ComputerSystem WQL queries locale agnostic
  hyperv: fix nodeGetInfo failures caused by long CPU names
  hyperv: break out common lookups into separate functions
  hyperv: replace generic WMI class list helpers with a macro
  hyperv: implement connectGetCapabilities
  hyperv: implement connectGetMaxVcpus
  hyperv: fix Win32_OperatingSystem WMI queries
  hyperv: implement connectGetVersion
  hyperv: implement domainGetAutostart
  news: document new Hyper-V features and bug fixes

 NEWS.rst  |  10 +
 docs/drvhyperv.html.in|  50 ++
 src/hyperv/hyperv_driver.c| 751 ++
 src/hyperv/hyperv_private.h   |   2 +
 src/hyperv/hyperv_wmi.c   |  83 +--
 src/hyperv/hyperv_wmi.h   |  28 +-
 src/hyperv/hyperv_wmi_classes.h   |   4 +-
 src/hyperv/hyperv_wmi_generator.input |   2 +-
 8 files changed, 596 insertions(+), 334 deletions(-)

-- 
2.27.0




[PATCH v2 04/10] hyperv: replace generic WMI class list helpers with a macro

2020-10-05 Thread Matt Coleman
Signed-off-by: Matt Coleman 
---
 src/hyperv/hyperv_driver.c | 39 --
 src/hyperv/hyperv_wmi.c| 83 --
 src/hyperv/hyperv_wmi.h| 28 ++---
 3 files changed, 36 insertions(+), 114 deletions(-)

diff --git a/src/hyperv/hyperv_driver.c b/src/hyperv/hyperv_driver.c
index 5e09c8f4af..3e4563252e 100644
--- a/src/hyperv/hyperv_driver.c
+++ b/src/hyperv/hyperv_driver.c
@@ -47,6 +47,20 @@ VIR_LOG_INIT("hyperv.hyperv_driver");
  * wrapper functions for commonly-accessed WMI objects and interfaces.
  */
 
+/**
+ * hypervGetWmiClass:
+ * @type: the type of the class being retrieved from WMI
+ * @class: double pointer where the class data will be stored
+ *
+ * Retrieve one or more classes from WMI.
+ *
+ * The following variables must exist in the caller:
+ *   1. hypervPrivate *priv
+ *   2. virBuffer query
+ */
+#define hypervGetWmiClass(type, class) \
+hypervGetWmiClassList(priv, type ## _WmiInfo, , (hypervObject 
**)class)
+
 static int
 hypervGetProcessorsByName(hypervPrivate *priv, const char *name,
   Win32_Processor **processorList)
@@ -58,7 +72,7 @@ hypervGetProcessorsByName(hypervPrivate *priv, const char 
*name,
"ResultClass = Win32_Processor",
name);
 
-if (hypervGetWin32ProcessorList(priv, , processorList) < 0 ||
+if (hypervGetWmiClass(Win32_Processor, processorList) < 0 ||
 !processorList) {
 virReportError(VIR_ERR_INTERNAL_ERROR,
_("Could not look up processor(s) on '%s'"),
@@ -77,7 +91,7 @@ hypervGetActiveVirtualSystemList(hypervPrivate *priv,
  "WHERE " 
MSVM_COMPUTERSYSTEM_WQL_VIRTUAL
  "AND " 
MSVM_COMPUTERSYSTEM_WQL_ACTIVE), 0 };
 
-if (hypervGetMsvmComputerSystemList(priv, , computerSystemList) < 0 
||
+if (hypervGetWmiClass(Msvm_ComputerSystem, computerSystemList) < 0 ||
 !*computerSystemList) {
 virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("Could not look up active virtual machines"));
@@ -96,7 +110,7 @@ hypervGetInactiveVirtualSystemList(hypervPrivate *priv,
  "WHERE " 
MSVM_COMPUTERSYSTEM_WQL_VIRTUAL
  "AND " 
MSVM_COMPUTERSYSTEM_WQL_INACTIVE), 0 };
 
-if (hypervGetMsvmComputerSystemList(priv, , computerSystemList) < 0 
||
+if (hypervGetWmiClass(Msvm_ComputerSystem, computerSystemList) < 0 ||
 !*computerSystemList) {
 virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("Could not look up inactive virtual machines"));
@@ -112,7 +126,7 @@ hypervGetPhysicalSystemList(hypervPrivate *priv,
 {
 g_auto(virBuffer) query = { g_string_new(WIN32_COMPUTERSYSTEM_WQL_SELECT), 
0 };
 
-if (hypervGetWin32ComputerSystemList(priv, , computerSystemList) < 0 
||
+if (hypervGetWmiClass(Win32_ComputerSystem, computerSystemList) < 0 ||
 !*computerSystemList) {
 virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("Could not look up Win32_ComputerSystem"));
@@ -133,7 +147,7 @@ hypervGetVirtualSystemByID(hypervPrivate *priv, int id,
   "AND ProcessID = %d",
   id);
 
-if (hypervGetMsvmComputerSystemList(priv, , computerSystemList) < 0) 
{
+if (hypervGetWmiClass(Msvm_ComputerSystem, computerSystemList) < 0) {
 virReportError(VIR_ERR_OPERATION_FAILED,
_("Could not look up virtual system with ID %d"), id);
 return -1;
@@ -158,7 +172,7 @@ hypervGetVirtualSystemByUUID(hypervPrivate *priv, const 
char *uuid,
"AND Name = \"%s\"",
uuid);
 
-if (hypervGetMsvmComputerSystemList(priv, , computerSystemList) < 0) 
{
+if (hypervGetWmiClass(Msvm_ComputerSystem, computerSystemList) < 0) {
 virReportError(VIR_ERR_OPERATION_FAILED,
_("Could not look up virtual system with UUID '%s'"),
uuid);
@@ -186,7 +200,7 @@ hypervGetVirtualSystemByName(hypervPrivate *priv, const 
char *name,
"AND ElementName = \"%s\"",
name);
 
-if (hypervGetMsvmComputerSystemList(priv, , computerSystemList) < 0) 
{
+if (hypervGetWmiClass(Msvm_ComputerSystem, computerSystemList) < 0) {
 virReportError(VIR_ERR_OPERATION_FAILED,
_("Could not look up virtual system named '%s'"), name);
 return -1;
@@ -212,7 +226,7 @@ hypervGetVSSDFromUUID(hypervPrivate *priv, const char *uuid,
"ResultClass = Msvm_VirtualSystemSettingData",
uuid);
 
-if (hypervGetMsvmVirtualSystemSettingDataList(priv, , data) < 0 ||
+if (hypervGetWmiClass(Msvm_VirtualSystemSettingData, data) < 0 ||
 !*data) {
 

[PATCH v2 02/10] hyperv: fix nodeGetInfo failures caused by long CPU names

2020-10-05 Thread Matt Coleman
Some CPU model names were too long for _virNodeInfo.model.
For example: Intel Xeon CPU E5-2620 v2 @ 2.10GHz
This commit removes the clock frequency suffix.

Signed-off-by: Matt Coleman 
---
 src/hyperv/hyperv_driver.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/src/hyperv/hyperv_driver.c b/src/hyperv/hyperv_driver.c
index b57325f2a5..9bbc2f67fb 100644
--- a/src/hyperv/hyperv_driver.c
+++ b/src/hyperv/hyperv_driver.c
@@ -285,6 +285,10 @@ hypervNodeGetInfo(virConnectPtr conn, virNodeInfoPtr info)
 } else if (STRPREFIX(tmp, "(TM)")) {
 memmove(tmp, tmp + 4, strlen(tmp + 4) + 1);
 continue;
+} else if (STRPREFIX(tmp, " @ ")) {
+/* Remove " @ X.YZGHz" from the end. */
+*tmp = '\0';
+break;
 }
 
 ++tmp;
-- 
2.27.0




[PATCH v2 06/10] hyperv: implement connectGetMaxVcpus

2020-10-05 Thread Matt Coleman
Co-authored-by: Sri Ramanujam 
Signed-off-by: Matt Coleman 
---
 src/hyperv/hyperv_driver.c | 34 ++
 1 file changed, 34 insertions(+)

diff --git a/src/hyperv/hyperv_driver.c b/src/hyperv/hyperv_driver.c
index 93e08c54c0..bbe892fd62 100644
--- a/src/hyperv/hyperv_driver.c
+++ b/src/hyperv/hyperv_driver.c
@@ -553,6 +553,39 @@ hypervConnectGetCapabilities(virConnectPtr conn)
 
 
 
+static int
+hypervConnectGetMaxVcpus(virConnectPtr conn, const char *type G_GNUC_UNUSED)
+{
+int result = -1;
+hypervPrivate *priv = conn->privateData;
+g_auto(virBuffer) query = VIR_BUFFER_INITIALIZER;
+Msvm_ProcessorSettingData *processorSettingData = NULL;
+
+/* Get max processors definition */
+virBufferAddLit(,
+MSVM_PROCESSORSETTINGDATA_WQL_SELECT
+"WHERE InstanceID LIKE 'Microsoft:Definition%Maximum'");
+
+if (hypervGetWmiClass(Msvm_ProcessorSettingData, ) < 
0)
+goto cleanup;
+
+if (!processorSettingData) {
+virReportError(VIR_ERR_INTERNAL_ERROR,
+   _("Could not get maximum definition of 
Msvm_ProcessorSettingData for host %s"),
+   conn->uri->server);
+goto cleanup;
+}
+
+result = processorSettingData->data.common->VirtualQuantity;
+
+ cleanup:
+hypervFreeObject(priv, (hypervObject *) processorSettingData);
+
+return result;
+}
+
+
+
 static int
 hypervNodeGetInfo(virConnectPtr conn, virNodeInfoPtr info)
 {
@@ -1689,6 +1722,7 @@ static virHypervisorDriver hypervHypervisorDriver = {
 .connectClose = hypervConnectClose, /* 0.9.5 */
 .connectGetType = hypervConnectGetType, /* 0.9.5 */
 .connectGetHostname = hypervConnectGetHostname, /* 0.9.5 */
+.connectGetMaxVcpus = hypervConnectGetMaxVcpus, /* 6.9.0 */
 .nodeGetInfo = hypervNodeGetInfo, /* 0.9.5 */
 .connectGetCapabilities = hypervConnectGetCapabilities, /* 6.9.0 */
 .connectListDomains = hypervConnectListDomains, /* 0.9.5 */
-- 
2.27.0




[PATCH v2 05/10] hyperv: implement connectGetCapabilities

2020-10-05 Thread Matt Coleman
Co-authored-by: Sri Ramanujam 
Signed-off-by: Matt Coleman 
---
 src/hyperv/hyperv_driver.c  | 90 +
 src/hyperv/hyperv_private.h |  2 +
 2 files changed, 92 insertions(+)

diff --git a/src/hyperv/hyperv_driver.c b/src/hyperv/hyperv_driver.c
index 3e4563252e..93e08c54c0 100644
--- a/src/hyperv/hyperv_driver.c
+++ b/src/hyperv/hyperv_driver.c
@@ -36,6 +36,7 @@
 #include "openwsman.h"
 #include "virstring.h"
 #include "virkeycode.h"
+#include "domain_conf.h"
 
 #define VIR_FROM_THIS VIR_FROM_HYPERV
 
@@ -283,6 +284,76 @@ hypervGetMemSDByVSSDInstanceId(hypervPrivate *priv, const 
char *id,
 
 
 
+/*
+ * API-specific utility functions
+ */
+
+static int
+hypervLookupHostSystemBiosUuid(hypervPrivate *priv, unsigned char *uuid)
+{
+Win32_ComputerSystemProduct *computerSystem = NULL;
+g_auto(virBuffer) query = VIR_BUFFER_INITIALIZER;
+int result = -1;
+
+virBufferAddLit(, WIN32_COMPUTERSYSTEMPRODUCT_WQL_SELECT);
+if (hypervGetWmiClass(Win32_ComputerSystemProduct, ) < 0)
+goto cleanup;
+
+if (virUUIDParse(computerSystem->data.common->UUID, uuid) < 0) {
+virReportError(VIR_ERR_INTERNAL_ERROR,
+   _("Could not parse UUID from string '%s'"),
+   computerSystem->data.common->UUID);
+goto cleanup;
+}
+result = 0;
+
+ cleanup:
+hypervFreeObject(priv, (hypervObject *) computerSystem);
+
+return result;
+}
+
+static virCapsPtr
+hypervCapsInit(hypervPrivate *priv)
+{
+virCapsPtr caps = NULL;
+virCapsGuestPtr guest = NULL;
+
+caps = virCapabilitiesNew(VIR_ARCH_X86_64, 1, 1);
+
+if (!caps)
+return NULL;
+
+if (hypervLookupHostSystemBiosUuid(priv, caps->host.host_uuid) < 0)
+goto error;
+
+/* i686 caps */
+guest = virCapabilitiesAddGuest(caps, VIR_DOMAIN_OSTYPE_HVM, VIR_ARCH_I686,
+NULL, NULL, 0, NULL);
+if (!guest)
+goto error;
+
+if (!virCapabilitiesAddGuestDomain(guest, VIR_DOMAIN_VIRT_HYPERV, NULL, 
NULL, 0, NULL))
+goto error;
+
+/* x86_64 caps */
+guest = virCapabilitiesAddGuest(caps, VIR_DOMAIN_OSTYPE_HVM, 
VIR_ARCH_X86_64,
+NULL, NULL, 0, NULL);
+if (!guest)
+goto error;
+
+if (!virCapabilitiesAddGuestDomain(guest, VIR_DOMAIN_VIRT_HYPERV, NULL, 
NULL, 0, NULL))
+goto error;
+
+return caps;
+
+ error:
+virObjectUnref(caps);
+return NULL;
+}
+
+
+
 /*
  * Driver functions
  */
@@ -298,6 +369,9 @@ hypervFreePrivate(hypervPrivate **priv)
 wsmc_release((*priv)->client);
 }
 
+if ((*priv)->caps)
+virObjectUnref((*priv)->caps);
+
 hypervFreeParsedUri(&(*priv)->parsedUri);
 VIR_FREE(*priv);
 }
@@ -408,6 +482,11 @@ hypervConnectOpen(virConnectPtr conn, virConnectAuthPtr 
auth,
 if (hypervInitConnection(conn, priv, username, password) < 0)
 goto cleanup;
 
+/* set up capabilities */
+priv->caps = hypervCapsInit(priv);
+if (!priv->caps)
+goto cleanup;
+
 conn->privateData = priv;
 priv = NULL;
 result = VIR_DRV_OPEN_SUCCESS;
@@ -464,6 +543,16 @@ hypervConnectGetHostname(virConnectPtr conn)
 
 
 
+static char*
+hypervConnectGetCapabilities(virConnectPtr conn)
+{
+hypervPrivate *priv = conn->privateData;
+
+return virCapabilitiesFormatXML(priv->caps);
+}
+
+
+
 static int
 hypervNodeGetInfo(virConnectPtr conn, virNodeInfoPtr info)
 {
@@ -1601,6 +1690,7 @@ static virHypervisorDriver hypervHypervisorDriver = {
 .connectGetType = hypervConnectGetType, /* 0.9.5 */
 .connectGetHostname = hypervConnectGetHostname, /* 0.9.5 */
 .nodeGetInfo = hypervNodeGetInfo, /* 0.9.5 */
+.connectGetCapabilities = hypervConnectGetCapabilities, /* 6.9.0 */
 .connectListDomains = hypervConnectListDomains, /* 0.9.5 */
 .connectNumOfDomains = hypervConnectNumOfDomains, /* 0.9.5 */
 .connectListAllDomains = hypervConnectListAllDomains, /* 0.10.2 */
diff --git a/src/hyperv/hyperv_private.h b/src/hyperv/hyperv_private.h
index b502e71d83..cf08bf542b 100644
--- a/src/hyperv/hyperv_private.h
+++ b/src/hyperv/hyperv_private.h
@@ -26,6 +26,7 @@
 #include "virerror.h"
 #include "hyperv_util.h"
 #include "openwsman.h"
+#include "capabilities.h"
 
 typedef enum _hypervWmiVersion hypervWmiVersion;
 enum _hypervWmiVersion {
@@ -38,4 +39,5 @@ struct _hypervPrivate {
 hypervParsedUri *parsedUri;
 WsManClient *client;
 hypervWmiVersion wmiVersion;
+virCapsPtr caps;
 };
-- 
2.27.0




[PATCH v2 01/10] hyperv: make Msvm_ComputerSystem WQL queries locale agnostic

2020-10-05 Thread Matt Coleman
There are two specific WQL queries we're using to get either a list of
virtual machines or the hypervisor host itself from Msvm_ComputerSystem.
Those queries rely on filtering results based on the "Description"
field. Since the "Description" field is locale sensitive, the queries
will fail if the Windows host is using a language pack. While the WSMAN
spec allows the client to set the requested locale (and it is supported
since openwsman 2.6.x), the Windows WinRM service does not respect this
setting: it returns non-English strings despite the WSMAN request
properly setting the locale to 'en-US'. Therefore, this patch changes
the WQL query to make use of the "__SERVER" field to stop relying on
English strings in queries and side step the issue.

Co-authored-by: Dawid Zamirski 
Signed-off-by: Matt Coleman 
---
 src/hyperv/hyperv_wmi_classes.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/hyperv/hyperv_wmi_classes.h b/src/hyperv/hyperv_wmi_classes.h
index a19b6a656d..7465684d6e 100644
--- a/src/hyperv/hyperv_wmi_classes.h
+++ b/src/hyperv/hyperv_wmi_classes.h
@@ -44,10 +44,10 @@
  */
 
 #define MSVM_COMPUTERSYSTEM_WQL_VIRTUAL \
-"Description = \"Microsoft Virtual Machine\" "
+"Name != __SERVER "
 
 #define MSVM_COMPUTERSYSTEM_WQL_PHYSICAL \
-"Description = \"Microsoft Hosting Computer System\" "
+"Name = __SERVER "
 
 #define MSVM_COMPUTERSYSTEM_WQL_ACTIVE \
 "(EnabledState != 0 and EnabledState != 3 and EnabledState != 32769) "
-- 
2.27.0




[PATCH v2 03/10] hyperv: break out common lookups into separate functions

2020-10-05 Thread Matt Coleman
This eliminates some duplicate code and simplifies the driver functions.

Co-authored-by: Sri Ramanujam 
Signed-off-by: Matt Coleman 
---
 src/hyperv/hyperv_driver.c | 489 -
 1 file changed, 259 insertions(+), 230 deletions(-)

diff --git a/src/hyperv/hyperv_driver.c b/src/hyperv/hyperv_driver.c
index 9bbc2f67fb..5e09c8f4af 100644
--- a/src/hyperv/hyperv_driver.c
+++ b/src/hyperv/hyperv_driver.c
@@ -41,6 +41,238 @@
 
 VIR_LOG_INIT("hyperv.hyperv_driver");
 
+/*
+ * WMI utility functions
+ *
+ * wrapper functions for commonly-accessed WMI objects and interfaces.
+ */
+
+static int
+hypervGetProcessorsByName(hypervPrivate *priv, const char *name,
+  Win32_Processor **processorList)
+{
+g_auto(virBuffer) query = VIR_BUFFER_INITIALIZER;
+virBufferEscapeSQL(,
+   "ASSOCIATORS OF {Win32_ComputerSystem.Name=\"%s\"} "
+   "WHERE AssocClass = Win32_ComputerSystemProcessor "
+   "ResultClass = Win32_Processor",
+   name);
+
+if (hypervGetWin32ProcessorList(priv, , processorList) < 0 ||
+!processorList) {
+virReportError(VIR_ERR_INTERNAL_ERROR,
+   _("Could not look up processor(s) on '%s'"),
+   name);
+return -1;
+}
+
+return 0;
+}
+
+static int
+hypervGetActiveVirtualSystemList(hypervPrivate *priv,
+ Msvm_ComputerSystem **computerSystemList)
+{
+g_auto(virBuffer) query = { g_string_new(MSVM_COMPUTERSYSTEM_WQL_SELECT
+ "WHERE " 
MSVM_COMPUTERSYSTEM_WQL_VIRTUAL
+ "AND " 
MSVM_COMPUTERSYSTEM_WQL_ACTIVE), 0 };
+
+if (hypervGetMsvmComputerSystemList(priv, , computerSystemList) < 0 
||
+!*computerSystemList) {
+virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+   _("Could not look up active virtual machines"));
+return -1;
+}
+
+return 0;
+}
+
+/* gets all the vms including the ones that are marked inactive. */
+static int
+hypervGetInactiveVirtualSystemList(hypervPrivate *priv,
+   Msvm_ComputerSystem **computerSystemList)
+{
+g_auto(virBuffer) query = { g_string_new(MSVM_COMPUTERSYSTEM_WQL_SELECT
+ "WHERE " 
MSVM_COMPUTERSYSTEM_WQL_VIRTUAL
+ "AND " 
MSVM_COMPUTERSYSTEM_WQL_INACTIVE), 0 };
+
+if (hypervGetMsvmComputerSystemList(priv, , computerSystemList) < 0 
||
+!*computerSystemList) {
+virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+   _("Could not look up inactive virtual machines"));
+return -1;
+}
+
+return 0;
+}
+
+static int
+hypervGetPhysicalSystemList(hypervPrivate *priv,
+Win32_ComputerSystem **computerSystemList)
+{
+g_auto(virBuffer) query = { g_string_new(WIN32_COMPUTERSYSTEM_WQL_SELECT), 
0 };
+
+if (hypervGetWin32ComputerSystemList(priv, , computerSystemList) < 0 
||
+!*computerSystemList) {
+virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+   _("Could not look up Win32_ComputerSystem"));
+return -1;
+}
+
+return 0;
+}
+
+static int
+hypervGetVirtualSystemByID(hypervPrivate *priv, int id,
+   Msvm_ComputerSystem **computerSystemList)
+{
+g_auto(virBuffer) query = VIR_BUFFER_INITIALIZER;
+virBufferAsprintf(,
+  MSVM_COMPUTERSYSTEM_WQL_SELECT
+  "WHERE " MSVM_COMPUTERSYSTEM_WQL_VIRTUAL
+  "AND ProcessID = %d",
+  id);
+
+if (hypervGetMsvmComputerSystemList(priv, , computerSystemList) < 0) 
{
+virReportError(VIR_ERR_OPERATION_FAILED,
+   _("Could not look up virtual system with ID %d"), id);
+return -1;
+}
+
+if (*computerSystemList == NULL) {
+virReportError(VIR_ERR_NO_DOMAIN, _("No domain with ID %d"), id);
+return -1;
+}
+
+return 0;
+}
+
+static int
+hypervGetVirtualSystemByUUID(hypervPrivate *priv, const char *uuid,
+ Msvm_ComputerSystem **computerSystemList)
+{
+g_auto(virBuffer) query = VIR_BUFFER_INITIALIZER;
+virBufferEscapeSQL(,
+   MSVM_COMPUTERSYSTEM_WQL_SELECT
+   "WHERE " MSVM_COMPUTERSYSTEM_WQL_VIRTUAL
+   "AND Name = \"%s\"",
+   uuid);
+
+if (hypervGetMsvmComputerSystemList(priv, , computerSystemList) < 0) 
{
+virReportError(VIR_ERR_OPERATION_FAILED,
+   _("Could not look up virtual system with UUID '%s'"),
+   uuid);
+return -1;
+}
+
+if (*computerSystemList == NULL) {
+virReportError(VIR_ERR_NO_DOMAIN,
+   _("No domain with UUID %s"), uuid);
+  

Re: [libvirt PATCH 9/9] spec: Introduce arches_*

2020-10-05 Thread Andrea Bolognani
On Mon, 2020-10-05 at 20:40 +0200, Andrea Bolognani wrote:
> +++ b/libvirt.spec.in
> @@ -17,10 +17,22 @@
>  %define _vpath_builddir %{_target_platform}
>  %endif
>  
> +%define arches_64bitx86_64 %{power64} aarch64 s390x riscv64
> +%define arches_x86  %{ix86} x86_64
> +
> +%define arches_systemtap_64bit  %{arches_64bit}
> +%define arches_dmidecode%{arches_x86}
> +%define arches_xen  %{arches_x86}
> +%define arches_vbox %{arches_x86}
> +%define arches_ceph %{arches_64bit}
> +%define arches_zfs  %{arches_x86} %{power64} %{arm}
> +%define arches_numactl  %{arches_x86} %{power64} aarch64
> +%define arches_numad%{arches_x86} %{power64} aarch64

Pushing

  commit 5ebf0638972c5922d32e9819f2f979f3345bd9c2
  Author: Neal Gompa 
  Date:   Sun Oct 4 22:16:57 2020 -0400

rpm: Enable Xen support on AArch64

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 
Reviewed-by: Andrea Bolognani 

caused a conflict with this patch, which luckily can be trivially
addressed; in addition, the diff below should be squashed in.


diff --git a/libvirt.spec.in b/libvirt.spec.in
index 32bc51b33c..4bd68f6a9e 100644
--- a/libvirt.spec.in
+++ b/libvirt.spec.in
@@ -22,7 +22,7 @@

 %define arches_systemtap_64bit  %{arches_64bit}
 %define arches_dmidecode%{arches_x86}
-%define arches_xen  %{arches_x86}
+%define arches_xen  %{arches_x86} aarch64
 %define arches_vbox %{arches_x86}
 %define arches_ceph %{arches_64bit}
 %define arches_zfs  %{arches_x86} %{power64} %{arm}
-- 
Andrea Bolognani / Red Hat / Virtualization



Re: [PATCH] rpm: Enable Xen support on AArch64

2020-10-05 Thread Andrea Bolognani
On Mon, 2020-10-05 at 12:33 -0400, Neal Gompa wrote:
> On Mon, Oct 5, 2020 at 6:18 AM Andrea Bolognani  wrote:
> > On Sun, 2020-10-04 at 22:16 -0400, Neal Gompa wrote:
> > > +++ b/libvirt.spec.in
> > > +# Xen is available only on i386 x86_64 ia64 aarch64
> > > +%ifnarch %{ix86} x86_64 ia64 aarch64
> > >  %define with_libxl 0
> > >  %endif
> > 
> > The code change is okay, but duplicating the list of architectures in
> > the comment is kinda pointless and results in unnecessary churn; I
> > would reword it as
> > 
> >   Xen is available only on some architectures
> > 
> > Are you okay with that change? If so, I will add my
> > 
> >   Reviewed-by: Andrea Bolognani 
> > 
> > and push the patch.
> 
> I'm fine with that. I debated making that change myself, too. :)

Fixed the obvious conflict with

  commit 5eb6d5401ded7896d6f5b30c10499157a08d6833
  Author: Daniel P. Berrangé 
  Date:   Mon Oct 5 13:17:02 2020 +0100

rpm: drop ia64, sparc64 and alpha architectures

None of these arches are relevant to current Fedora or RHEL distros.

Reviewed-by: Andrea Bolognani 
Signed-off-by: Daniel P. Berrangé 

adjusted the comment as agreed and pushed.

-- 
Andrea Bolognani / Red Hat / Virtualization



[libvirt PATCH 8/9] spec: Refactor qemu_kvm_arches definition

2020-10-05 Thread Andrea Bolognani
There's no need to set a default for it if we're going to override
it immediately afterwards anyway, and setting with_qemu_tcg at the
same time only makes things more confusing.

Signed-off-by: Andrea Bolognani 
---
 libvirt.spec.in | 26 +-
 1 file changed, 13 insertions(+), 13 deletions(-)

diff --git a/libvirt.spec.in b/libvirt.spec.in
index e036307d30..b62b17ee80 100644
--- a/libvirt.spec.in
+++ b/libvirt.spec.in
@@ -17,31 +17,31 @@
 %define _vpath_builddir %{_target_platform}
 %endif
 
+%if 0%{?fedora}
+%define qemu_kvm_arches %{ix86} x86_64 %{power64} s390x %{arm} aarch64
+%else
+%define qemu_kvm_arches x86_64 %{power64} aarch64 s390x
+%endif
+
 # The hypervisor drivers that run in libvirtd
 %define with_qemu  0%{!?_without_qemu:1}
 %define with_lxc   0%{!?_without_lxc:1}
 %define with_libxl 0%{!?_without_libxl:1}
 %define with_vbox  0%{!?_without_vbox:1}
 
-%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
-
 %ifarch %{qemu_kvm_arches}
 %define with_qemu_kvm  %{with_qemu}
 %else
 %define with_qemu_kvm  0
 %endif
 
+%define with_qemu_tcg  %{with_qemu}
+
+# RHEL disables TCG on all architectures
+%if 0%{?rhel}
+%define with_qemu_tcg 0
+%endif
+
 %if ! %{with_qemu_tcg} && ! %{with_qemu_kvm}
 %define with_qemu 0
 %endif
-- 
2.26.2



[libvirt PATCH 3/9] spec: bash completion actually defaults to on

2020-10-05 Thread Andrea Bolognani
Remove the red herring.

Signed-off-by: Andrea Bolognani 
---
 libvirt.spec.in | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/libvirt.spec.in b/libvirt.spec.in
index 4572044d2d..9e4c5d2b81 100644
--- a/libvirt.spec.in
+++ b/libvirt.spec.in
@@ -84,6 +84,9 @@
 %define with_storage_iscsi_direct 0
 %endif
 
+# Other optional features
+%define with_bash_completion  0%{!?_without_bash_completion:1}
+
 # A few optional bits off by default, we enable later
 %define with_fuse 0
 %define with_sanlock  0
@@ -92,7 +95,6 @@
 %define with_libssh2  0
 %define with_wireshark0
 %define with_libssh   0
-%define with_bash_completion  0
 
 # Finally set the OS / architecture specific special cases
 
@@ -174,8 +176,6 @@
 %define with_libssh 0%{!?_without_libssh:1}
 %endif
 
-%define with_bash_completion  0%{!?_without_bash_completion:1}
-
 %if %{with_qemu} || %{with_lxc}
 # numad is used to manage the CPU and memory placement dynamically,
 # it's not available on many non-x86 architectures.
-- 
2.26.2



[libvirt PATCH 6/9] spec: Move _vpath_builddir definition

2020-10-05 Thread Andrea Bolognani
It belongs before package-specific feature flags are defined.

Signed-off-by: Andrea Bolognani 
---
 libvirt.spec.in | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/libvirt.spec.in b/libvirt.spec.in
index 2401404008..d8f689e651 100644
--- a/libvirt.spec.in
+++ b/libvirt.spec.in
@@ -12,6 +12,11 @@
 %define supported_platform 0
 %endif
 
+# On RHEL 7 and older macro _vpath_builddir is not defined.
+%if 0%{?rhel} && 0%{?rhel} <= 7
+%define _vpath_builddir %{_target_platform}
+%endif
+
 # The hypervisor drivers that run in libvirtd
 %define with_qemu  0%{!?_without_qemu:1}
 %define with_lxc   0%{!?_without_lxc:1}
@@ -31,11 +36,6 @@
 %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
-- 
2.26.2



[libvirt PATCHv3 1/4] qemu: capabilities: add QEMU_CAPS_FSDEV_CREATEMODE

2020-10-05 Thread Brian Turek
The QEMU 9pfs 'fmode' and 'dmode' options have existed since QEMU 2.10.
Probe QEMU's command line set to check whether these options are
available, and if yes, enable this new QEMU_CAPS_FSDEV_CREATEMODE
capability on libvirt side.

Signed-off-by: Brian Turek 
---
 src/qemu/qemu_capabilities.c   | 2 ++
 src/qemu/qemu_capabilities.h   | 1 +
 tests/qemucapabilitiesdata/caps_2.10.0.aarch64.xml | 1 +
 tests/qemucapabilitiesdata/caps_2.10.0.ppc64.xml   | 1 +
 tests/qemucapabilitiesdata/caps_2.10.0.s390x.xml   | 1 +
 tests/qemucapabilitiesdata/caps_2.10.0.x86_64.xml  | 1 +
 tests/qemucapabilitiesdata/caps_2.11.0.s390x.xml   | 1 +
 tests/qemucapabilitiesdata/caps_2.11.0.x86_64.xml  | 1 +
 tests/qemucapabilitiesdata/caps_2.12.0.aarch64.xml | 1 +
 tests/qemucapabilitiesdata/caps_2.12.0.ppc64.xml   | 1 +
 tests/qemucapabilitiesdata/caps_2.12.0.s390x.xml   | 1 +
 tests/qemucapabilitiesdata/caps_2.12.0.x86_64.xml  | 1 +
 tests/qemucapabilitiesdata/caps_3.0.0.ppc64.xml| 1 +
 tests/qemucapabilitiesdata/caps_3.0.0.riscv32.xml  | 1 +
 tests/qemucapabilitiesdata/caps_3.0.0.riscv64.xml  | 1 +
 tests/qemucapabilitiesdata/caps_3.0.0.s390x.xml| 1 +
 tests/qemucapabilitiesdata/caps_3.0.0.x86_64.xml   | 1 +
 tests/qemucapabilitiesdata/caps_3.1.0.ppc64.xml| 1 +
 tests/qemucapabilitiesdata/caps_3.1.0.x86_64.xml   | 1 +
 tests/qemucapabilitiesdata/caps_4.0.0.aarch64.xml  | 1 +
 tests/qemucapabilitiesdata/caps_4.0.0.ppc64.xml| 1 +
 tests/qemucapabilitiesdata/caps_4.0.0.riscv32.xml  | 1 +
 tests/qemucapabilitiesdata/caps_4.0.0.riscv64.xml  | 1 +
 tests/qemucapabilitiesdata/caps_4.0.0.s390x.xml| 1 +
 tests/qemucapabilitiesdata/caps_4.0.0.x86_64.xml   | 1 +
 tests/qemucapabilitiesdata/caps_4.1.0.x86_64.xml   | 1 +
 tests/qemucapabilitiesdata/caps_4.2.0.aarch64.xml  | 1 +
 tests/qemucapabilitiesdata/caps_4.2.0.ppc64.xml| 1 +
 tests/qemucapabilitiesdata/caps_4.2.0.s390x.xml| 1 +
 tests/qemucapabilitiesdata/caps_4.2.0.x86_64.xml   | 1 +
 tests/qemucapabilitiesdata/caps_5.0.0.aarch64.xml  | 1 +
 tests/qemucapabilitiesdata/caps_5.0.0.ppc64.xml| 1 +
 tests/qemucapabilitiesdata/caps_5.0.0.riscv64.xml  | 1 +
 tests/qemucapabilitiesdata/caps_5.0.0.x86_64.xml   | 1 +
 tests/qemucapabilitiesdata/caps_5.1.0.x86_64.xml   | 1 +
 tests/qemucapabilitiesdata/caps_5.2.0.x86_64.xml   | 1 +
 36 files changed, 37 insertions(+)

diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index 38b901a6c4..d2a745d8c5 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -600,6 +600,7 @@ VIR_ENUM_IMPL(virQEMUCaps,
 
   /* 380 */
   "usb-host.hostdevice",
+  "fsdev.createmode",
 );
 
 
@@ -3322,6 +3323,7 @@ static struct virQEMUCapsCommandLineProps 
virQEMUCapsCommandLine[] = {
 { "smp-opts", "dies", QEMU_CAPS_SMP_DIES },
 { "fsdev", "multidevs", QEMU_CAPS_FSDEV_MULTIDEVS },
 { "fw_cfg", "file", QEMU_CAPS_FW_CFG },
+{ "fsdev", "fmode", QEMU_CAPS_FSDEV_CREATEMODE }, /* Could have also 
checked fsdev->dmode */
 };
 
 static int
diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h
index 107056ba17..bd7412d6f7 100644
--- a/src/qemu/qemu_capabilities.h
+++ b/src/qemu/qemu_capabilities.h
@@ -580,6 +580,7 @@ typedef enum { /* virQEMUCapsFlags grouping marker for 
syntax-check */
 
 /* 380 */
 QEMU_CAPS_USB_HOST_HOSTDEVICE, /* -device usb-host.hostdevice */
+QEMU_CAPS_FSDEV_CREATEMODE, /* fsdev.createmode */
 
 QEMU_CAPS_LAST /* this must always be the last item */
 } virQEMUCapsFlags;
diff --git a/tests/qemucapabilitiesdata/caps_2.10.0.aarch64.xml 
b/tests/qemucapabilitiesdata/caps_2.10.0.aarch64.xml
index b0fcbc4218..77af6b0d7a 100644
--- a/tests/qemucapabilitiesdata/caps_2.10.0.aarch64.xml
+++ b/tests/qemucapabilitiesdata/caps_2.10.0.aarch64.xml
@@ -145,6 +145,7 @@
   
   
   
+  
   201
   0
   61700287
diff --git a/tests/qemucapabilitiesdata/caps_2.10.0.ppc64.xml 
b/tests/qemucapabilitiesdata/caps_2.10.0.ppc64.xml
index edf01d2e2f..5fce7540f9 100644
--- a/tests/qemucapabilitiesdata/caps_2.10.0.ppc64.xml
+++ b/tests/qemucapabilitiesdata/caps_2.10.0.ppc64.xml
@@ -145,6 +145,7 @@
   
   
   
+  
   201
   0
   42900287
diff --git a/tests/qemucapabilitiesdata/caps_2.10.0.s390x.xml 
b/tests/qemucapabilitiesdata/caps_2.10.0.s390x.xml
index 98a3c0eec2..7b0153e272 100644
--- a/tests/qemucapabilitiesdata/caps_2.10.0.s390x.xml
+++ b/tests/qemucapabilitiesdata/caps_2.10.0.s390x.xml
@@ -111,6 +111,7 @@
   
   
   
+  
   201
   0
   39100287
diff --git a/tests/qemucapabilitiesdata/caps_2.10.0.x86_64.xml 
b/tests/qemucapabilitiesdata/caps_2.10.0.x86_64.xml
index 98b1a94349..7f45a473cb 100644
--- a/tests/qemucapabilitiesdata/caps_2.10.0.x86_64.xml
+++ b/tests/qemucapabilitiesdata/caps_2.10.0.x86_64.xml
@@ -189,6 +189,7 @@
   
   
   
+  
   201
   0
   43100287
diff --git a/tests/qemucapabilitiesdata/caps_2.11.0.s390x.xml 

[libvirt PATCHv3 2/4] qemu: add support for 'fmode' and 'dmode' options

2020-10-05 Thread Brian Turek
Expose QEMU's 9pfs 'fmode' and 'dmode' options via attributes on the
'filesystem' node in the domain XML. These options control the creation
mode of files and directories, respectively, when using
accessmode=mapped.  QEMU defaults to creating files with mode 0600 and
directories with mode 0700.

Signed-off-by: Brian Turek 
---
 src/conf/domain_conf.c| 27 
 src/conf/domain_conf.h|  2 +
 src/qemu/qemu_command.c   |  6 ++
 src/qemu/qemu_validate.c  | 18 ++
 .../virtio-9p-createmode.x86_64-latest.args   | 45 ++
 .../qemuxml2argvdata/virtio-9p-createmode.xml | 58 ++
 .../virtio-9p-createmode.x86_64-latest.xml| 61 +++
 tests/qemuxml2xmltest.c   |  1 +
 8 files changed, 218 insertions(+)
 create mode 100644 
tests/qemuxml2argvdata/virtio-9p-createmode.x86_64-latest.args
 create mode 100644 tests/qemuxml2argvdata/virtio-9p-createmode.xml
 create mode 100644 
tests/qemuxml2xmloutdata/virtio-9p-createmode.x86_64-latest.xml

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 175b632a38..e80b3b7ef6 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -11496,6 +11496,8 @@ virDomainFSDefParseXML(virDomainXMLOptionPtr xmlopt,
 g_autofree char *units = NULL;
 g_autofree char *model = NULL;
 g_autofree char *multidevs = NULL;
+g_autofree char *fmode = NULL;
+g_autofree char *dmode = NULL;
 
 ctxt->node = node;
 
@@ -11524,6 +11526,24 @@ virDomainFSDefParseXML(virDomainXMLOptionPtr xmlopt,
 def->accessmode = VIR_DOMAIN_FS_ACCESSMODE_PASSTHROUGH;
 }
 
+fmode = virXMLPropString(node, "fmode");
+if (fmode) {
+if (virStrToLong_uip(fmode, NULL, 8, >fmode) < 0) {
+virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+   _("invalid fmode: '%s'"), fmode);
+goto error;
+}
+}
+
+dmode = virXMLPropString(node, "dmode");
+if (dmode) {
+if (virStrToLong_uip(dmode, NULL, 8, >dmode) < 0) {
+virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+   _("invalid dmode: '%s'"), dmode);
+goto error;
+}
+}
+
 model = virXMLPropString(node, "model");
 if (model) {
 if ((def->model = virDomainFSModelTypeFromString(model)) < 0 ||
@@ -26211,6 +26231,13 @@ virDomainFSDefFormat(virBufferPtr buf,
 }
 if (def->multidevs)
 virBufferAsprintf(buf, " multidevs='%s'", multidevs);
+
+if (def->fmode)
+virBufferAsprintf(buf, " fmode='%04o'", def->fmode);
+
+if (def->dmode)
+virBufferAsprintf(buf, " dmode='%04o'", def->dmode);
+
 virBufferAddLit(buf, ">\n");
 
 virBufferAdjustIndent(buf, 2);
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 450686dfb5..51f70f9dd4 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -849,6 +849,8 @@ struct _virDomainFSDef {
 int wrpolicy; /* enum virDomainFSWrpolicy */
 int format; /* virStorageFileFormat */
 int model; /* virDomainFSModel */
+unsigned int fmode;
+unsigned int dmode;
 int multidevs; /* virDomainFSMultidevs */
 unsigned long long usage; /* in bytes */
 virStorageSourcePtr src;
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 476cf6972e..b2da53c664 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -2275,6 +2275,12 @@ qemuBuildFSStr(virDomainFSDefPtr fs)
 } else if (fs->multidevs == VIR_DOMAIN_FS_MULTIDEVS_WARN) {
 virBufferAddLit(, ",multidevs=warn");
 }
+if (fs->fmode) {
+virBufferAsprintf(, ",fmode=%04o", fs->fmode);
+}
+if (fs->dmode) {
+virBufferAsprintf(, ",dmode=%04o", fs->dmode);
+}
 } else if (fs->fsdriver == VIR_DOMAIN_FS_DRIVER_TYPE_HANDLE) {
 /* removed since qemu 4.0.0 see v3.1.0-29-g93aee84f57 */
 virBufferAddLit(, "handle");
diff --git a/src/qemu/qemu_validate.c b/src/qemu/qemu_validate.c
index a212605579..4757c55e13 100644
--- a/src/qemu/qemu_validate.c
+++ b/src/qemu/qemu_validate.c
@@ -3530,6 +3530,19 @@ qemuValidateDomainDeviceDefFS(virDomainFSDefPtr fs,
 return -1;
 }
 
+if ((fs->fmode != 0) || (fs->dmode != 0)) {
+if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_FSDEV_CREATEMODE)) {
+virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+_("fmode and dmode are not supported with this QEMU 
binary"));
+return -1;
+}
+if (fs->accessmode != VIR_DOMAIN_FS_ACCESSMODE_MAPPED) {
+virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+   _("fmode and dmode must be used with 
accessmode=mapped"));
+return -1;
+}
+}
+
 switch ((virDomainFSDriverType) fs->fsdriver) {
 case VIR_DOMAIN_FS_DRIVER_TYPE_DEFAULT:
 case 

[libvirt PATCH 9/9] spec: Introduce arches_*

2020-10-05 Thread Andrea Bolognani
With this commit, all architecture lists that we base feature
enablement decisions on are defined within a few lines of each
other, increasing maintainability.

Additionally, generic architecture lists that appear in the
conditions for multiple features are defined, so that repetition
is reduced.

Note that a few checks (numactl, zfs, ceph) have been changed
from %ifarch to %ifnarch for consistency: while doing so, the
corresponding list of architectures has also been replaced with
the complement of the original one to ensure the overall behavior
would be preserved.

Signed-off-by: Andrea Bolognani 
---
 libvirt.spec.in | 48 ++--
 1 file changed, 26 insertions(+), 22 deletions(-)

diff --git a/libvirt.spec.in b/libvirt.spec.in
index b62b17ee80..32bc51b33c 100644
--- a/libvirt.spec.in
+++ b/libvirt.spec.in
@@ -17,10 +17,22 @@
 %define _vpath_builddir %{_target_platform}
 %endif
 
+%define arches_64bitx86_64 %{power64} aarch64 s390x riscv64
+%define arches_x86  %{ix86} x86_64
+
+%define arches_systemtap_64bit  %{arches_64bit}
+%define arches_dmidecode%{arches_x86}
+%define arches_xen  %{arches_x86}
+%define arches_vbox %{arches_x86}
+%define arches_ceph %{arches_64bit}
+%define arches_zfs  %{arches_x86} %{power64} %{arm}
+%define arches_numactl  %{arches_x86} %{power64} aarch64
+%define arches_numad%{arches_x86} %{power64} aarch64
+
 %if 0%{?fedora}
-%define qemu_kvm_arches %{ix86} x86_64 %{power64} s390x %{arm} aarch64
+%define arches_qemu_kvm %{arches_x86} %{power64} s390x %{arm} aarch64
 %else
-%define qemu_kvm_arches x86_64 %{power64} aarch64 s390x
+%define arches_qemu_kvm x86_64 %{power64} aarch64 s390x
 %endif
 
 # The hypervisor drivers that run in libvirtd
@@ -29,7 +41,7 @@
 %define with_libxl 0%{!?_without_libxl:1}
 %define with_vbox  0%{!?_without_vbox:1}
 
-%ifarch %{qemu_kvm_arches}
+%ifarch %{arches_qemu_kvm}
 %define with_qemu_kvm  %{with_qemu}
 %else
 %define with_qemu_kvm  0
@@ -61,7 +73,7 @@
 %endif
 
 %define with_storage_gluster 0%{!?_without_storage_gluster:1}
-%ifnarch %{qemu_kvm_arches}
+%ifnarch %{arches_qemu_kvm}
 # gluster is only built where qemu driver is enabled on RHEL 8
 %if 0%{?rhel} >= 8
 %define with_storage_gluster 0
@@ -98,28 +110,20 @@
 
 # Finally set the OS / architecture specific special cases
 
-# Xen is available only on i386 x86_64
-%ifnarch %{ix86} x86_64
+# Architecture-dependent features
+%ifnarch %{arches_xen}
 %define with_libxl 0
 %endif
-
-# vbox is available only on i386 x86_64
-%ifnarch %{ix86} x86_64
+%ifnarch %{arches_vbox}
 %define with_vbox 0
 %endif
-
-# Numactl is not available on many non-x86 archs
-%ifarch s390x %{arm} riscv64
+%ifnarch %{arches_numactl}
 %define with_numactl 0
 %endif
-
-# zfs-fuse is not available on some architectures
-%ifarch s390x aarch64 riscv64
+%ifnarch %{arches_zfs}
 %define with_storage_zfs 0
 %endif
-
-# Ceph dropped support for 32-bit hosts
-%ifarch %{arm} %{ix86}
+%ifnarch %{arches_ceph}
 %define with_storage_rbd 0
 %endif
 
@@ -155,7 +159,7 @@
 %define with_sanlock 0%{!?_without_sanlock:1}
 %endif
 %if 0%{?rhel}
-%ifarch %{qemu_kvm_arches}
+%ifarch %{arches_qemu_kvm}
 %define with_sanlock 0%{!?_without_sanlock:1}
 %endif
 %endif
@@ -179,12 +183,12 @@
 %if %{with_qemu} || %{with_lxc}
 # numad is used to manage the CPU and memory placement dynamically,
 # it's not available on many non-x86 architectures.
-%ifnarch s390x %{arm} riscv64
+%ifnarch %{arches_numad}
 %define with_numad0%{!?_without_numad:1}
 %endif
 %endif
 
-%ifarch %{ix86} x86_64
+%ifarch %{arches_dmidecode}
 %define with_dmidecode 0%{!?_without_dmidecode:1}
 %endif
 
@@ -1256,7 +1260,7 @@ rm -f 
$RPM_BUILD_ROOT%{_datadir}/augeas/lenses/tests/test_libvirtd_libxl.aug
 # Copied into libvirt-docs subpackage eventually
 mv $RPM_BUILD_ROOT%{_datadir}/doc/libvirt libvirt-docs
 
-%ifarch %{power64} s390x x86_64 aarch64 riscv64
+%ifarch %{arches_systemtap_64bit}
 mv $RPM_BUILD_ROOT%{_datadir}/systemtap/tapset/libvirt_probes.stp \
$RPM_BUILD_ROOT%{_datadir}/systemtap/tapset/libvirt_probes-64.stp
 
-- 
2.26.2



[libvirt PATCH 4/9] spec: Move with_numactl definition

2020-10-05 Thread Andrea Bolognani
Keep it close to similar ones.

Signed-off-by: Andrea Bolognani 
---
 libvirt.spec.in | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/libvirt.spec.in b/libvirt.spec.in
index 9e4c5d2b81..65df7dc79f 100644
--- a/libvirt.spec.in
+++ b/libvirt.spec.in
@@ -68,8 +68,6 @@
 %endif
 %endif
 
-%define with_numactl  0%{!?_without_numactl:1}
-
 # F25+ has zfs-fuse
 %if 0%{?fedora}
 %define with_storage_zfs  0%{!?_without_storage_zfs:1}
@@ -86,6 +84,7 @@
 
 # Other optional features
 %define with_bash_completion  0%{!?_without_bash_completion:1}
+%define with_numactl  0%{!?_without_numactl:1}
 
 # A few optional bits off by default, we enable later
 %define with_fuse 0
-- 
2.26.2



[libvirt PATCH 0/9] spec: Improve feature and architecture handling

2020-10-05 Thread Andrea Bolognani
Make things more maintainable.

Andrea Bolognani (9):
  spec: Simplify setting features off by default
  spec: firewalld is always enabled
  spec: bash completion actually defaults to on
  spec: Move with_numactl definition
  spec: Introduce with_dmidecode
  spec: Move _vpath_builddir definition
  spec: Drop s390 architecture from conditionals
  spec: Refactor qemu_kvm_arches definition
  spec: Introduce arches_*

 libvirt.spec.in | 117 
 1 file changed, 58 insertions(+), 59 deletions(-)

-- 
2.26.2




[libvirt PATCHv3 3/4] qemu: add schema 'fmode' and 'dmode' options

2020-10-05 Thread Brian Turek
Adds schema to validate the 'fmode' and 'dmode' attributes on a
'fileystem' node.  Checks to ensure that the values are 1-4 octal
digits long.

Signed-off-by: Brian Turek 
---
 docs/schemas/domaincommon.rng | 16 
 1 file changed, 16 insertions(+)

diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng
index 316d93fb69..6c814d600a 100644
--- a/docs/schemas/domaincommon.rng
+++ b/docs/schemas/domaincommon.rng
@@ -26,6 +26,12 @@
 
   
 
+  
+
+  [0-7]{1,4}
+
+  
+
   
@@ -2736,6 +2742,16 @@
 
   
 
+
+  
+
+  
+
+
+  
+
+  
+
 
   
 
-- 
2.25.1



[libvirt PATCH 7/9] spec: Drop s390 architecture from conditionals

2020-10-05 Thread Andrea Bolognani
Neither Fedora nor RHEL build packages on this architecture.

Signed-off-by: Andrea Bolognani 
---
 libvirt.spec.in | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/libvirt.spec.in b/libvirt.spec.in
index d8f689e651..e036307d30 100644
--- a/libvirt.spec.in
+++ b/libvirt.spec.in
@@ -109,12 +109,12 @@
 %endif
 
 # Numactl is not available on many non-x86 archs
-%ifarch s390 s390x %{arm} riscv64
+%ifarch s390x %{arm} riscv64
 %define with_numactl 0
 %endif
 
 # zfs-fuse is not available on some architectures
-%ifarch s390 s390x aarch64 riscv64
+%ifarch s390x aarch64 riscv64
 %define with_storage_zfs 0
 %endif
 
@@ -179,7 +179,7 @@
 %if %{with_qemu} || %{with_lxc}
 # numad is used to manage the CPU and memory placement dynamically,
 # it's not available on many non-x86 architectures.
-%ifnarch s390 s390x %{arm} riscv64
+%ifnarch s390x %{arm} riscv64
 %define with_numad0%{!?_without_numad:1}
 %endif
 %endif
-- 
2.26.2



[libvirt PATCHv3 0/4] Add support for QEMU's fmode and dmode

2020-10-05 Thread Brian Turek
Apologies for the second submission here. I got a kickback on two of the
emails saying it was "rejected due to security policies."

This third version of the patches fixes a bug where QEMU interpreted the
command line value passed to it as base-10 rather than base-8.  This new
version ensures there is always a preceeding 0 in the QEMU args (using
%04o formatting) and explictly sets it in the generated XML.

Brian Turek (4):
  qemu: capabilities: add QEMU_CAPS_FSDEV_CREATEMODE
  qemu: add support for 'fmode' and 'dmode' options
  qemu: add schema 'fmode' and 'dmode' options
  qemu: add docs for 'fmode' and 'dmode' options

 docs/formatdomain.rst | 12 
 docs/schemas/domaincommon.rng | 16 +
 src/conf/domain_conf.c| 27 
 src/conf/domain_conf.h|  2 +
 src/qemu/qemu_capabilities.c  |  2 +
 src/qemu/qemu_capabilities.h  |  1 +
 src/qemu/qemu_command.c   |  6 ++
 src/qemu/qemu_validate.c  | 18 ++
 .../caps_2.10.0.aarch64.xml   |  1 +
 .../caps_2.10.0.ppc64.xml |  1 +
 .../caps_2.10.0.s390x.xml |  1 +
 .../caps_2.10.0.x86_64.xml|  1 +
 .../caps_2.11.0.s390x.xml |  1 +
 .../caps_2.11.0.x86_64.xml|  1 +
 .../caps_2.12.0.aarch64.xml   |  1 +
 .../caps_2.12.0.ppc64.xml |  1 +
 .../caps_2.12.0.s390x.xml |  1 +
 .../caps_2.12.0.x86_64.xml|  1 +
 .../qemucapabilitiesdata/caps_3.0.0.ppc64.xml |  1 +
 .../caps_3.0.0.riscv32.xml|  1 +
 .../caps_3.0.0.riscv64.xml|  1 +
 .../qemucapabilitiesdata/caps_3.0.0.s390x.xml |  1 +
 .../caps_3.0.0.x86_64.xml |  1 +
 .../qemucapabilitiesdata/caps_3.1.0.ppc64.xml |  1 +
 .../caps_3.1.0.x86_64.xml |  1 +
 .../caps_4.0.0.aarch64.xml|  1 +
 .../qemucapabilitiesdata/caps_4.0.0.ppc64.xml |  1 +
 .../caps_4.0.0.riscv32.xml|  1 +
 .../caps_4.0.0.riscv64.xml|  1 +
 .../qemucapabilitiesdata/caps_4.0.0.s390x.xml |  1 +
 .../caps_4.0.0.x86_64.xml |  1 +
 .../caps_4.1.0.x86_64.xml |  1 +
 .../caps_4.2.0.aarch64.xml|  1 +
 .../qemucapabilitiesdata/caps_4.2.0.ppc64.xml |  1 +
 .../qemucapabilitiesdata/caps_4.2.0.s390x.xml |  1 +
 .../caps_4.2.0.x86_64.xml |  1 +
 .../caps_5.0.0.aarch64.xml|  1 +
 .../qemucapabilitiesdata/caps_5.0.0.ppc64.xml |  1 +
 .../caps_5.0.0.riscv64.xml|  1 +
 .../caps_5.0.0.x86_64.xml |  1 +
 .../caps_5.1.0.x86_64.xml |  1 +
 .../caps_5.2.0.x86_64.xml |  1 +
 .../virtio-9p-createmode.x86_64-latest.args   | 45 ++
 .../qemuxml2argvdata/virtio-9p-createmode.xml | 58 ++
 .../virtio-9p-createmode.x86_64-latest.xml| 61 +++
 tests/qemuxml2xmltest.c   |  1 +
 46 files changed, 283 insertions(+)
 create mode 100644 
tests/qemuxml2argvdata/virtio-9p-createmode.x86_64-latest.args
 create mode 100644 tests/qemuxml2argvdata/virtio-9p-createmode.xml
 create mode 100644 
tests/qemuxml2xmloutdata/virtio-9p-createmode.x86_64-latest.xml

-- 
2.25.1



[libvirt PATCHv3 4/4] qemu: add docs for 'fmode' and 'dmode' options

2020-10-05 Thread Brian Turek
Adds documentation for QEMU 9pfs 'fmode' and 'dmode' options.

Signed-off-by: Brian Turek 
---
 docs/formatdomain.rst | 12 
 1 file changed, 12 insertions(+)

diff --git a/docs/formatdomain.rst b/docs/formatdomain.rst
index cc4f91d4ea..085f29ef8f 100644
--- a/docs/formatdomain.rst
+++ b/docs/formatdomain.rst
@@ -3062,6 +3062,12 @@ A directory on the host that can be accessed directly 
from the guest.


  
+ 
+   
+   
+   
+   
+ 
  


@@ -3140,6 +3146,12 @@ A directory on the host that can be accessed directly 
from the guest.
"virtio-non-transitional", or "virtio". See `Virtio transitional
devices <#elementsVirtioTransitional>`__ for more details.
 
+   The filesystem element has optional attributes ``fmode`` and ``dmode``.
+   These two attributes control the creation mode for files and directories
+   when used with the ``mapped`` value for ``accessmode`` (:since:`since 6.9.0,
+   requires QEMU 2.10` ).  If not specified, QEMU creates files with mode
+   ``600`` and directories with mode ``700``.
+
The filesystem element has an optional attribute ``multidevs`` which
specifies how to deal with a filesystem export containing more than one
device, in order to avoid file ID collisions on guest when using 9pfs (
-- 
2.25.1



[libvirt PATCH 2/9] spec: firewalld is always enabled

2020-10-05 Thread Andrea Bolognani
Knowing this, we can remove some code.

Signed-off-by: Andrea Bolognani 
---
 libvirt.spec.in | 11 +--
 1 file changed, 1 insertion(+), 10 deletions(-)

diff --git a/libvirt.spec.in b/libvirt.spec.in
index 815ab246e9..4572044d2d 100644
--- a/libvirt.spec.in
+++ b/libvirt.spec.in
@@ -88,7 +88,6 @@
 %define with_fuse 0
 %define with_sanlock  0
 %define with_numad0
-%define with_firewalld0
 %define with_firewalld_zone   0
 %define with_libssh2  0
 %define with_wireshark0
@@ -138,8 +137,6 @@
 %endif
 %endif
 
-%define with_firewalld 1
-
 %if 0%{?fedora} || 0%{?rhel} > 7
 %define with_firewalld_zone 0%{!?_without_firewalld_zone:1}
 %endif
@@ -1088,12 +1085,6 @@ exit 1
 %define arg_sanlock -Dsanlock=disabled
 %endif
 
-%if %{with_firewalld}
-%define arg_firewalld -Dfirewalld=enabled
-%else
-%define arg_firewalld -Dfirewalld=disabled
-%endif
-
 %if %{with_firewalld_zone}
 %define arg_firewalld_zone -Dfirewalld_zone=enabled
 %else
@@ -1169,7 +1160,7 @@ export SOURCE_DATE_EPOCH=$(stat --printf='%Y' 
%{_specdir}/%{name}.spec)
-Dlibpcap=enabled \
-Daudit=enabled \
-Ddtrace=enabled \
-   %{?arg_firewalld} \
+   -Dfirewalld=enabled \
%{?arg_firewalld_zone} \
%{?arg_wireshark} \
-Dpm_utils=disabled \
-- 
2.26.2



[libvirt PATCH 5/9] spec: Introduce with_dmidecode

2020-10-05 Thread Andrea Bolognani
To keep things maintainable, we want to have architecture handling
all in one spot instead of sprinkling %ifarch conditionals all over
the place.

Signed-off-by: Andrea Bolognani 
---
 libvirt.spec.in | 7 ++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/libvirt.spec.in b/libvirt.spec.in
index 65df7dc79f..2401404008 100644
--- a/libvirt.spec.in
+++ b/libvirt.spec.in
@@ -94,6 +94,7 @@
 %define with_libssh2  0
 %define with_wireshark0
 %define with_libssh   0
+%define with_dmidecode0
 
 # Finally set the OS / architecture specific special cases
 
@@ -183,6 +184,10 @@
 %endif
 %endif
 
+%ifarch %{ix86} x86_64
+%define with_dmidecode 0%{!?_without_dmidecode:1}
+%endif
+
 # Force QEMU to run as non-root
 %define qemu_user  qemu
 %define qemu_group  qemu
@@ -434,7 +439,7 @@ Requires: iproute-tc
 %endif
 
 Requires: polkit >= 0.112
-%ifarch %{ix86} x86_64
+%if %{with_dmidecode}
 # For virConnectGetSysinfo
 Requires: dmidecode
 %endif
-- 
2.26.2



[libvirt PATCH 1/9] spec: Simplify setting features off by default

2020-10-05 Thread Andrea Bolognani
The right-hand side of these expressions will always evaluate to
zero. Stop obfuscating this fact.

Signed-off-by: Andrea Bolognani 
---
 libvirt.spec.in | 18 +-
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/libvirt.spec.in b/libvirt.spec.in
index d13aae5cf5..815ab246e9 100644
--- a/libvirt.spec.in
+++ b/libvirt.spec.in
@@ -85,15 +85,15 @@
 %endif
 
 # A few optional bits off by default, we enable later
-%define with_fuse  0%{!?_without_fuse:0}
-%define with_sanlock   0%{!?_without_sanlock:0}
-%define with_numad 0%{!?_without_numad:0}
-%define with_firewalld 0%{!?_without_firewalld:0}
-%define with_firewalld_zone 0%{!?_without_firewalld_zone:0}
-%define with_libssh2   0%{!?_without_libssh2:0}
-%define with_wireshark 0%{!?_without_wireshark:0}
-%define with_libssh0%{!?_without_libssh:0}
-%define with_bash_completion  0%{!?_without_bash_completion:0}
+%define with_fuse 0
+%define with_sanlock  0
+%define with_numad0
+%define with_firewalld0
+%define with_firewalld_zone   0
+%define with_libssh2  0
+%define with_wireshark0
+%define with_libssh   0
+%define with_bash_completion  0
 
 # Finally set the OS / architecture specific special cases
 
-- 
2.26.2



Re: restrictions for virtiofs (related to commit: 88957116c9 for libvirt 6.9.0)

2020-10-05 Thread Masayoshi Mizuma
On Mon, Oct 05, 2020 at 10:50:08AM +0200, Michal Privoznik wrote:
> On 10/3/20 1:15 AM, Masayoshi Mizuma wrote:
> > On Fri, Oct 02, 2020 at 11:31:32AM -0400, Masayoshi Mizuma wrote:
> > > Hello Jan, and Michal,
> > > 
> > > commit: 88957116c9 ("qemu: Use memory-backend-* for regular guest 
> > > memory") gets
> > > the system memory sharable without numa config.
> > > The qemu options with the patch will be like as:
> > > 
> > >-machine 
> > > pc-q35-5.2,accel=kvm,usb=off,vmport=off,smm=on,dump-guest-core=off,memory-backend=pc.ram
> > >  \
> > >-object 
> > > memory-backend-file,id=pc.ram,mem-path=/var/lib/libvirt/qemu/ram/2-Test/pc.ram,share=yes,size=17179869184
> > >  \
> > > 
> > > So, we can remove the numa restriction of virtiofs, right?
> > > The patch to remove that is the bottom of this email.
> > > 
> > > And, 88957116c9 seems to introduce another restriction which we
> > > cannot create numa nodes on the machine. I got the following
> > > message when I set the numa config and started the VM:
> > > 
> > > 2020-10-02T00:31:46.780374Z qemu-system-x86_64: '-machine 
> > > memory-backend' and '-numa memdev' properties are mutually exclusive
> > 
> > It seems that this isn't a restriction for virtiofs. It's a bug introduced
> > by commit: 88957116c9.  element doesn't work regardless of virtiofs 
> > config...
> 
> Do you have domain XML that is failing?

Yes, I got the issue while virsh start:

  # virsh start Test
  error: Failed to start domain Test
  error: internal error: qemu unexpectedly closed the monitor: 
2020-10-05T17:31:21.078134Z qemu-system-x86_64: '-machine memory-backend' and 
'-numa memdev' properties are mutually exclusive

  # 

Here is the domain XML. I'm using libvirt with the head commit: 7d77fdb90f,
and qemu with the head commit: 36d9c2883e.
=

  Test
  12785e5c-542e-4896-87f3-2e068fb7107f
  8388608
  8388608
  4
  
hvm
  
  





  
  

  

  
  



  
  destroy
  restart
  destroy
  
/usr/local/bin/qemu-system-x86_64

  
  
  
  
  



  
  
  


  
  
  


  
  
  


  
  
  


  
  
  


  
  
  


  


  


  


  
  
  
  


  

  


  


  
  




  


  /dev/urandom
  

  

=

Thanks,
Masa



[PATCHv3 3/5] qemu: add schema 'fmode' and 'dmode' options

2020-10-05 Thread Brian Turek
Adds schema to validate the 'fmode' and 'dmode' attributes on a
'fileystem' node.  Checks to ensure that the values are 1-4 octal
digits long.

Signed-off-by: Brian Turek 
---
 docs/schemas/domaincommon.rng | 16 
 1 file changed, 16 insertions(+)

diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng
index 316d93fb69..6c814d600a 100644
--- a/docs/schemas/domaincommon.rng
+++ b/docs/schemas/domaincommon.rng
@@ -26,6 +26,12 @@
 
   
 
+  
+
+  [0-7]{1,4}
+
+  
+
   
@@ -2736,6 +2742,16 @@
 
   
 
+
+  
+
+  
+
+
+  
+
+  
+
 
   
 
-- 
2.25.1



[PATCHv3 2/5] qemu: add support for 'fmode' and 'dmode' options

2020-10-05 Thread Brian Turek
Expose QEMU's 9pfs 'fmode' and 'dmode' options via attributes on the
'filesystem' node in the domain XML. These options control the creation
mode of files and directories, respectively, when using
accessmode=mapped.  QEMU defaults to creating files with mode 0600 and
directories with mode 0700.

Signed-off-by: Brian Turek 
---
 src/conf/domain_conf.c| 27 
 src/conf/domain_conf.h|  2 +
 src/qemu/qemu_command.c   |  6 ++
 src/qemu/qemu_validate.c  | 18 ++
 .../virtio-9p-createmode.x86_64-latest.args   | 45 ++
 .../qemuxml2argvdata/virtio-9p-createmode.xml | 58 ++
 .../virtio-9p-createmode.x86_64-latest.xml| 61 +++
 tests/qemuxml2xmltest.c   |  1 +
 8 files changed, 218 insertions(+)
 create mode 100644 
tests/qemuxml2argvdata/virtio-9p-createmode.x86_64-latest.args
 create mode 100644 tests/qemuxml2argvdata/virtio-9p-createmode.xml
 create mode 100644 
tests/qemuxml2xmloutdata/virtio-9p-createmode.x86_64-latest.xml

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 175b632a38..e80b3b7ef6 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -11496,6 +11496,8 @@ virDomainFSDefParseXML(virDomainXMLOptionPtr xmlopt,
 g_autofree char *units = NULL;
 g_autofree char *model = NULL;
 g_autofree char *multidevs = NULL;
+g_autofree char *fmode = NULL;
+g_autofree char *dmode = NULL;
 
 ctxt->node = node;
 
@@ -11524,6 +11526,24 @@ virDomainFSDefParseXML(virDomainXMLOptionPtr xmlopt,
 def->accessmode = VIR_DOMAIN_FS_ACCESSMODE_PASSTHROUGH;
 }
 
+fmode = virXMLPropString(node, "fmode");
+if (fmode) {
+if (virStrToLong_uip(fmode, NULL, 8, >fmode) < 0) {
+virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+   _("invalid fmode: '%s'"), fmode);
+goto error;
+}
+}
+
+dmode = virXMLPropString(node, "dmode");
+if (dmode) {
+if (virStrToLong_uip(dmode, NULL, 8, >dmode) < 0) {
+virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+   _("invalid dmode: '%s'"), dmode);
+goto error;
+}
+}
+
 model = virXMLPropString(node, "model");
 if (model) {
 if ((def->model = virDomainFSModelTypeFromString(model)) < 0 ||
@@ -26211,6 +26231,13 @@ virDomainFSDefFormat(virBufferPtr buf,
 }
 if (def->multidevs)
 virBufferAsprintf(buf, " multidevs='%s'", multidevs);
+
+if (def->fmode)
+virBufferAsprintf(buf, " fmode='%04o'", def->fmode);
+
+if (def->dmode)
+virBufferAsprintf(buf, " dmode='%04o'", def->dmode);
+
 virBufferAddLit(buf, ">\n");
 
 virBufferAdjustIndent(buf, 2);
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 450686dfb5..51f70f9dd4 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -849,6 +849,8 @@ struct _virDomainFSDef {
 int wrpolicy; /* enum virDomainFSWrpolicy */
 int format; /* virStorageFileFormat */
 int model; /* virDomainFSModel */
+unsigned int fmode;
+unsigned int dmode;
 int multidevs; /* virDomainFSMultidevs */
 unsigned long long usage; /* in bytes */
 virStorageSourcePtr src;
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 476cf6972e..b2da53c664 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -2275,6 +2275,12 @@ qemuBuildFSStr(virDomainFSDefPtr fs)
 } else if (fs->multidevs == VIR_DOMAIN_FS_MULTIDEVS_WARN) {
 virBufferAddLit(, ",multidevs=warn");
 }
+if (fs->fmode) {
+virBufferAsprintf(, ",fmode=%04o", fs->fmode);
+}
+if (fs->dmode) {
+virBufferAsprintf(, ",dmode=%04o", fs->dmode);
+}
 } else if (fs->fsdriver == VIR_DOMAIN_FS_DRIVER_TYPE_HANDLE) {
 /* removed since qemu 4.0.0 see v3.1.0-29-g93aee84f57 */
 virBufferAddLit(, "handle");
diff --git a/src/qemu/qemu_validate.c b/src/qemu/qemu_validate.c
index a212605579..4757c55e13 100644
--- a/src/qemu/qemu_validate.c
+++ b/src/qemu/qemu_validate.c
@@ -3530,6 +3530,19 @@ qemuValidateDomainDeviceDefFS(virDomainFSDefPtr fs,
 return -1;
 }
 
+if ((fs->fmode != 0) || (fs->dmode != 0)) {
+if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_FSDEV_CREATEMODE)) {
+virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+_("fmode and dmode are not supported with this QEMU 
binary"));
+return -1;
+}
+if (fs->accessmode != VIR_DOMAIN_FS_ACCESSMODE_MAPPED) {
+virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+   _("fmode and dmode must be used with 
accessmode=mapped"));
+return -1;
+}
+}
+
 switch ((virDomainFSDriverType) fs->fsdriver) {
 case VIR_DOMAIN_FS_DRIVER_TYPE_DEFAULT:
 case 

[PATCHv3 1/5] qemu: capabilities: add QEMU_CAPS_FSDEV_CREATEMODE

2020-10-05 Thread Brian Turek
The QEMU 9pfs 'fmode' and 'dmode' options have existed since QEMU 2.10.
Probe QEMU's command line set to check whether these options are
available, and if yes, enable this new QEMU_CAPS_FSDEV_CREATEMODE
capability on libvirt side.

Signed-off-by: Brian Turek 
---
 src/qemu/qemu_capabilities.c   | 2 ++
 src/qemu/qemu_capabilities.h   | 1 +
 tests/qemucapabilitiesdata/caps_2.10.0.aarch64.xml | 1 +
 tests/qemucapabilitiesdata/caps_2.10.0.ppc64.xml   | 1 +
 tests/qemucapabilitiesdata/caps_2.10.0.s390x.xml   | 1 +
 tests/qemucapabilitiesdata/caps_2.10.0.x86_64.xml  | 1 +
 tests/qemucapabilitiesdata/caps_2.11.0.s390x.xml   | 1 +
 tests/qemucapabilitiesdata/caps_2.11.0.x86_64.xml  | 1 +
 tests/qemucapabilitiesdata/caps_2.12.0.aarch64.xml | 1 +
 tests/qemucapabilitiesdata/caps_2.12.0.ppc64.xml   | 1 +
 tests/qemucapabilitiesdata/caps_2.12.0.s390x.xml   | 1 +
 tests/qemucapabilitiesdata/caps_2.12.0.x86_64.xml  | 1 +
 tests/qemucapabilitiesdata/caps_3.0.0.ppc64.xml| 1 +
 tests/qemucapabilitiesdata/caps_3.0.0.riscv32.xml  | 1 +
 tests/qemucapabilitiesdata/caps_3.0.0.riscv64.xml  | 1 +
 tests/qemucapabilitiesdata/caps_3.0.0.s390x.xml| 1 +
 tests/qemucapabilitiesdata/caps_3.0.0.x86_64.xml   | 1 +
 tests/qemucapabilitiesdata/caps_3.1.0.ppc64.xml| 1 +
 tests/qemucapabilitiesdata/caps_3.1.0.x86_64.xml   | 1 +
 tests/qemucapabilitiesdata/caps_4.0.0.aarch64.xml  | 1 +
 tests/qemucapabilitiesdata/caps_4.0.0.ppc64.xml| 1 +
 tests/qemucapabilitiesdata/caps_4.0.0.riscv32.xml  | 1 +
 tests/qemucapabilitiesdata/caps_4.0.0.riscv64.xml  | 1 +
 tests/qemucapabilitiesdata/caps_4.0.0.s390x.xml| 1 +
 tests/qemucapabilitiesdata/caps_4.0.0.x86_64.xml   | 1 +
 tests/qemucapabilitiesdata/caps_4.1.0.x86_64.xml   | 1 +
 tests/qemucapabilitiesdata/caps_4.2.0.aarch64.xml  | 1 +
 tests/qemucapabilitiesdata/caps_4.2.0.ppc64.xml| 1 +
 tests/qemucapabilitiesdata/caps_4.2.0.s390x.xml| 1 +
 tests/qemucapabilitiesdata/caps_4.2.0.x86_64.xml   | 1 +
 tests/qemucapabilitiesdata/caps_5.0.0.aarch64.xml  | 1 +
 tests/qemucapabilitiesdata/caps_5.0.0.ppc64.xml| 1 +
 tests/qemucapabilitiesdata/caps_5.0.0.riscv64.xml  | 1 +
 tests/qemucapabilitiesdata/caps_5.0.0.x86_64.xml   | 1 +
 tests/qemucapabilitiesdata/caps_5.1.0.x86_64.xml   | 1 +
 tests/qemucapabilitiesdata/caps_5.2.0.x86_64.xml   | 1 +
 36 files changed, 37 insertions(+)

diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index 38b901a6c4..d2a745d8c5 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -600,6 +600,7 @@ VIR_ENUM_IMPL(virQEMUCaps,
 
   /* 380 */
   "usb-host.hostdevice",
+  "fsdev.createmode",
 );
 
 
@@ -3322,6 +3323,7 @@ static struct virQEMUCapsCommandLineProps 
virQEMUCapsCommandLine[] = {
 { "smp-opts", "dies", QEMU_CAPS_SMP_DIES },
 { "fsdev", "multidevs", QEMU_CAPS_FSDEV_MULTIDEVS },
 { "fw_cfg", "file", QEMU_CAPS_FW_CFG },
+{ "fsdev", "fmode", QEMU_CAPS_FSDEV_CREATEMODE }, /* Could have also 
checked fsdev->dmode */
 };
 
 static int
diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h
index 107056ba17..bd7412d6f7 100644
--- a/src/qemu/qemu_capabilities.h
+++ b/src/qemu/qemu_capabilities.h
@@ -580,6 +580,7 @@ typedef enum { /* virQEMUCapsFlags grouping marker for 
syntax-check */
 
 /* 380 */
 QEMU_CAPS_USB_HOST_HOSTDEVICE, /* -device usb-host.hostdevice */
+QEMU_CAPS_FSDEV_CREATEMODE, /* fsdev.createmode */
 
 QEMU_CAPS_LAST /* this must always be the last item */
 } virQEMUCapsFlags;
diff --git a/tests/qemucapabilitiesdata/caps_2.10.0.aarch64.xml 
b/tests/qemucapabilitiesdata/caps_2.10.0.aarch64.xml
index b0fcbc4218..77af6b0d7a 100644
--- a/tests/qemucapabilitiesdata/caps_2.10.0.aarch64.xml
+++ b/tests/qemucapabilitiesdata/caps_2.10.0.aarch64.xml
@@ -145,6 +145,7 @@
   
   
   
+  
   201
   0
   61700287
diff --git a/tests/qemucapabilitiesdata/caps_2.10.0.ppc64.xml 
b/tests/qemucapabilitiesdata/caps_2.10.0.ppc64.xml
index edf01d2e2f..5fce7540f9 100644
--- a/tests/qemucapabilitiesdata/caps_2.10.0.ppc64.xml
+++ b/tests/qemucapabilitiesdata/caps_2.10.0.ppc64.xml
@@ -145,6 +145,7 @@
   
   
   
+  
   201
   0
   42900287
diff --git a/tests/qemucapabilitiesdata/caps_2.10.0.s390x.xml 
b/tests/qemucapabilitiesdata/caps_2.10.0.s390x.xml
index 98a3c0eec2..7b0153e272 100644
--- a/tests/qemucapabilitiesdata/caps_2.10.0.s390x.xml
+++ b/tests/qemucapabilitiesdata/caps_2.10.0.s390x.xml
@@ -111,6 +111,7 @@
   
   
   
+  
   201
   0
   39100287
diff --git a/tests/qemucapabilitiesdata/caps_2.10.0.x86_64.xml 
b/tests/qemucapabilitiesdata/caps_2.10.0.x86_64.xml
index 98b1a94349..7f45a473cb 100644
--- a/tests/qemucapabilitiesdata/caps_2.10.0.x86_64.xml
+++ b/tests/qemucapabilitiesdata/caps_2.10.0.x86_64.xml
@@ -189,6 +189,7 @@
   
   
   
+  
   201
   0
   43100287
diff --git a/tests/qemucapabilitiesdata/caps_2.11.0.s390x.xml 

[PATCHv3 4/5] qemu: add docs for 'fmode' and 'dmode' options

2020-10-05 Thread Brian Turek
Adds documentation for QEMU 9pfs 'fmode' and 'dmode' options.

Signed-off-by: Brian Turek 
---
 docs/formatdomain.rst | 12 
 1 file changed, 12 insertions(+)

diff --git a/docs/formatdomain.rst b/docs/formatdomain.rst
index cc4f91d4ea..085f29ef8f 100644
--- a/docs/formatdomain.rst
+++ b/docs/formatdomain.rst
@@ -3062,6 +3062,12 @@ A directory on the host that can be accessed directly 
from the guest.


  
+ 
+   
+   
+   
+   
+ 
  


@@ -3140,6 +3146,12 @@ A directory on the host that can be accessed directly 
from the guest.
"virtio-non-transitional", or "virtio". See `Virtio transitional
devices <#elementsVirtioTransitional>`__ for more details.
 
+   The filesystem element has optional attributes ``fmode`` and ``dmode``.
+   These two attributes control the creation mode for files and directories
+   when used with the ``mapped`` value for ``accessmode`` (:since:`since 6.9.0,
+   requires QEMU 2.10` ).  If not specified, QEMU creates files with mode
+   ``600`` and directories with mode ``700``.
+
The filesystem element has an optional attribute ``multidevs`` which
specifies how to deal with a filesystem export containing more than one
device, in order to avoid file ID collisions on guest when using 9pfs (
-- 
2.25.1



[libvirt PATCH 09/12] util: firewall: use g_new0

2020-10-05 Thread Ján Tomko
Signed-off-by: Ján Tomko 
---
 src/util/virfirewall.c  | 9 +++--
 src/util/virfirewalld.c | 6 ++
 2 files changed, 5 insertions(+), 10 deletions(-)

diff --git a/src/util/virfirewall.c b/src/util/virfirewall.c
index 22e717bce4..f6a8beec95 100644
--- a/src/util/virfirewall.c
+++ b/src/util/virfirewall.c
@@ -211,8 +211,7 @@ virFirewallGroupNew(void)
 {
 virFirewallGroupPtr group;
 
-if (VIR_ALLOC(group) < 0)
-return NULL;
+group = g_new0(virFirewallGroup, 1);
 
 return group;
 }
@@ -235,8 +234,7 @@ virFirewallPtr virFirewallNew(void)
 if (virFirewallInitialize() < 0)
 return NULL;
 
-if (VIR_ALLOC(firewall) < 0)
-return NULL;
+firewall = g_new0(virFirewall, 1);
 
 return firewall;
 }
@@ -346,8 +344,7 @@ virFirewallAddRuleFullV(virFirewallPtr firewall,
 group = firewall->groups[firewall->currentGroup];
 
 
-if (VIR_ALLOC(rule) < 0)
-goto no_memory;
+rule = g_new0(virFirewallRule, 1);
 
 rule->layer = layer;
 rule->queryCB = cb;
diff --git a/src/util/virfirewalld.c b/src/util/virfirewalld.c
index a94ac7c183..3178bf4b3d 100644
--- a/src/util/virfirewalld.c
+++ b/src/util/virfirewalld.c
@@ -139,8 +139,7 @@ virFirewallDGetBackend(void)
 if (!sysbus)
 return -1;
 
-if (VIR_ALLOC(error) < 0)
-return -1;
+error = g_new0(virError, 1);
 
 message = g_variant_new("(ss)",
 "org.fedoraproject.FirewallD1.config",
@@ -289,8 +288,7 @@ virFirewallDApplyRule(virFirewallLayer layer,
 return -1;
 }
 
-if (VIR_ALLOC(error) < 0)
-return -1;
+error = g_new0(virError, 1);
 
 message = g_variant_new("(s@as)",
 ipv,
-- 
2.26.2



[libvirt PATCH 04/12] util: storagefile: use g_new0

2020-10-05 Thread Ján Tomko
Signed-off-by: Ján Tomko 
---
 src/util/virstoragefile.c | 82 ---
 1 file changed, 25 insertions(+), 57 deletions(-)

diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c
index 459a7be5e4..82388ae544 100644
--- a/src/util/virstoragefile.c
+++ b/src/util/virstoragefile.c
@@ -520,8 +520,7 @@ qcow2GetExtensions(const char *buf,
 if (!backingFormat)
 break;
 
-if (VIR_ALLOC_N(tmp, len + 1) < 0)
-return -1;
+tmp = g_new0(char, len + 1);
 memcpy(tmp, buf + offset, len);
 tmp[len] = '\0';
 
@@ -575,8 +574,7 @@ qcowXGetBackingStore(char **res,
 return BACKING_STORE_INVALID;
 if (offset + size > buf_size || offset + size < offset)
 return BACKING_STORE_INVALID;
-if (VIR_ALLOC_N(*res, size + 1) < 0)
-return BACKING_STORE_ERROR;
+*res = g_new0(char, size + 1);
 memcpy(*res, buf + offset, size);
 (*res)[size] = '\0';
 
@@ -598,8 +596,7 @@ vmdk4GetBackingStore(char **res,
 size_t len;
 g_autofree char *desc = NULL;
 
-if (VIR_ALLOC_N(desc, VIR_STORAGE_MAX_HEADER) < 0)
-return BACKING_STORE_ERROR;
+desc = g_new0(char, VIR_STORAGE_MAX_HEADER);
 
 *res = NULL;
 /*
@@ -669,8 +666,7 @@ qedGetBackingStore(char **res,
 return BACKING_STORE_OK;
 if (offset + size > buf_size || offset + size < offset)
 return BACKING_STORE_INVALID;
-if (VIR_ALLOC_N(*res, size + 1) < 0)
-return BACKING_STORE_ERROR;
+*res = g_new0(char, size + 1);
 memcpy(*res, buf + offset, size);
 (*res)[size] = '\0';
 
@@ -959,9 +955,7 @@ virStorageFileGetMetadataInternal(virStorageSourcePtr meta,
   buf, len)) {
 int expt_fmt = fileTypeInfo[meta->format].cryptInfo[i].format;
 if (!meta->encryption) {
-if (VIR_ALLOC(meta->encryption) < 0)
-return -1;
-
+meta->encryption = g_new0(virStorageEncryption, 1);
 meta->encryption->format = expt_fmt;
 } else {
 if (meta->encryption->format != expt_fmt) {
@@ -1735,8 +1729,7 @@ virStorageNetHostDefCopy(size_t nhosts,
 virStorageNetHostDefPtr ret = NULL;
 size_t i;
 
-if (VIR_ALLOC_N(ret, nhosts) < 0)
-goto error;
+ret = g_new0(virStorageNetHostDef, nhosts);
 
 for (i = 0; i < nhosts; i++) {
 virStorageNetHostDefPtr src = [i];
@@ -1750,10 +1743,6 @@ virStorageNetHostDefCopy(size_t nhosts,
 }
 
 return ret;
-
- error:
-virStorageNetHostDefFree(nhosts, ret);
-return NULL;
 }
 
 
@@ -1775,8 +1764,7 @@ virStorageAuthDefCopy(const virStorageAuthDef *src)
 {
 g_autoptr(virStorageAuthDef) authdef = NULL;
 
-if (VIR_ALLOC(authdef) < 0)
-return NULL;
+authdef = g_new0(virStorageAuthDef, 1);
 
 authdef->username = g_strdup(src->username);
 /* Not present for storage pool, but used for disk source */
@@ -1801,8 +1789,7 @@ virStorageAuthDefParse(xmlNodePtr node,
 
 ctxt->node = node;
 
-if (VIR_ALLOC(authdef) < 0)
-goto cleanup;
+authdef = g_new0(virStorageAuthDef, 1);
 
 if (!(authdef->username = virXPathString("string(./@username)", ctxt))) {
 virReportError(VIR_ERR_XML_ERROR, "%s",
@@ -1891,8 +1878,7 @@ virStoragePRDefParseXML(xmlXPathContextPtr ctxt)
 g_autofree char *path = NULL;
 g_autofree char *mode = NULL;
 
-if (VIR_ALLOC(prd) < 0)
-return NULL;
+prd = g_new0(virStoragePRDef, 1);
 
 if (!(managed = virXPathString("string(./@managed)", ctxt))) {
 virReportError(VIR_ERR_XML_ERROR, "%s",
@@ -2020,8 +2006,7 @@ virStoragePRDefCopy(virStoragePRDefPtr src)
 virStoragePRDefPtr copy = NULL;
 virStoragePRDefPtr ret = NULL;
 
-if (VIR_ALLOC(copy) < 0)
-return NULL;
+copy = g_new0(virStoragePRDef, 1);
 
 copy->managed = src->managed;
 
@@ -2129,8 +2114,7 @@ virStorageSourceSeclabelsCopy(virStorageSourcePtr to,
 if (from->nseclabels == 0)
 return 0;
 
-if (VIR_ALLOC_N(to->seclabels, from->nseclabels) < 0)
-return -1;
+to->seclabels = g_new0(virSecurityDeviceLabelDefPtr, from->nseclabels);
 to->nseclabels = from->nseclabels;
 
 for (i = 0; i < to->nseclabels; i++) {
@@ -2280,8 +2264,7 @@ virStorageTimestampsCopy(const virStorageTimestamps *src)
 {
 virStorageTimestampsPtr ret;
 
-if (VIR_ALLOC(ret) < 0)
-return NULL;
+ret = g_new0(virStorageTimestamps, 1);
 
 memcpy(ret, src, sizeof(*src));
 
@@ -2294,8 +2277,7 @@ virStoragePermsCopy(const virStoragePerms *src)
 {
 virStoragePermsPtr ret;
 
-if (VIR_ALLOC(ret) < 0)
-return NULL;
+ret = g_new0(virStoragePerms, 1);
 
 ret->mode = src->mode;
 ret->uid = src->uid;
@@ -2312,8 +2294,7 @@ virStorageSourcePoolDefCopy(const virStorageSourcePoolDef 
*src)
 {
 

[libvirt PATCH 00/12] util: use g_new0 (glib chronicles)

2020-10-05 Thread Ján Tomko
Ján Tomko (12):
  util: resctrl fix spacing in comment
  util: split out VIR_ALLOC calls
  util: resctrl: use g_new0
  util: storagefile: use g_new0
  util: sysinfo: use g_new0
  util: command: use g_new0
  util: netdev: use g_new0
  util: systemd: use g_new0
  util: firewall: use g_new0
  util: conf: use g_new0
  util: a-n: use g_new0
  util: o-z: use g_new0

 src/util/iohelper.c  |  3 +-
 src/util/virarptable.c   |  3 +-
 src/util/virauthconfig.c |  6 +--
 src/util/virbitmap.c |  4 +-
 src/util/vircgroup.c |  7 +--
 src/util/vircommand.c| 31 +---
 src/util/virconf.c   | 23 +++--
 src/util/vircrypto.c |  6 +--
 src/util/virdnsmasq.c| 12 ++---
 src/util/virebtables.c   |  3 +-
 src/util/virfile.c   | 12 ++---
 src/util/virfirewall.c   |  9 ++--
 src/util/virfirewalld.c  |  6 +--
 src/util/virfirmware.c   |  6 +--
 src/util/virhash.c   |  8 +---
 src/util/virhostcpu.c|  9 ++--
 src/util/virjson.c   | 15 ++
 src/util/virlockspace.c  | 17 ++-
 src/util/virlog.c|  5 +-
 src/util/virmdev.c   |  6 +--
 src/util/virnetdev.c | 25 --
 src/util/virnetdevbandwidth.c| 22 ++---
 src/util/virnetdevip.c   |  3 +-
 src/util/virnetdevmacvlan.c  |  6 +--
 src/util/virnetdevtap.c  |  3 +-
 src/util/virnetdevvlan.c |  4 +-
 src/util/virnetdevvportprofile.c |  7 +--
 src/util/virnetlink.c|  3 +-
 src/util/virnuma.c   |  7 +--
 src/util/virpci.c| 12 ++---
 src/util/virperf.c   |  3 +-
 src/util/virpolkit.c |  3 +-
 src/util/virportallocator.c  |  3 +-
 src/util/virprocess.c|  3 +-
 src/util/virresctrl.c| 79 ++
 src/util/virrotatingfile.c   | 15 ++
 src/util/virscsi.c   |  6 +--
 src/util/virscsivhost.c  |  3 +-
 src/util/virseclabel.c   | 13 ++---
 src/util/virstorageencryption.c  | 16 ++-
 src/util/virstoragefile.c| 82 ++--
 src/util/virstring.c |  3 +-
 src/util/virsysinfo.c| 33 +
 src/util/virsystemd.c| 19 ++--
 src/util/virthreadpool.c |  9 ++--
 src/util/virtime.c   |  6 +--
 src/util/virtypedparam.c | 20 +++-
 src/util/viruri.c|  3 +-
 src/util/virusb.c|  3 +-
 src/util/virutil.c   | 15 ++
 src/util/virxml.c| 11 ++---
 51 files changed, 196 insertions(+), 435 deletions(-)

-- 
2.26.2



[libvirt PATCH 11/12] util: a-n: use g_new0

2020-10-05 Thread Ján Tomko
Signed-off-by: Ján Tomko 
---
 src/util/iohelper.c  |  3 +--
 src/util/virarptable.c   |  3 +--
 src/util/virauthconfig.c |  6 ++
 src/util/virbitmap.c |  4 +---
 src/util/vircgroup.c |  7 ++-
 src/util/vircrypto.c |  6 ++
 src/util/virdnsmasq.c| 12 
 src/util/virebtables.c   |  3 +--
 src/util/virfile.c   | 12 +++-
 src/util/virfirmware.c   |  6 ++
 src/util/virhash.c   |  8 ++--
 src/util/virhostcpu.c|  9 +++--
 src/util/virjson.c   | 15 +--
 src/util/virlockspace.c  | 17 +
 src/util/virlog.c|  5 +
 src/util/virmdev.c   |  6 ++
 src/util/virnetlink.c|  3 +--
 src/util/virnuma.c   |  7 ++-
 18 files changed, 40 insertions(+), 92 deletions(-)

diff --git a/src/util/iohelper.c b/src/util/iohelper.c
index c3eb6f8c54..49d939d290 100644
--- a/src/util/iohelper.c
+++ b/src/util/iohelper.c
@@ -63,8 +63,7 @@ runIO(const char *path, int fd, int oflags)
 }
 buf = base;
 #else
-if (VIR_ALLOC_N(buf, buflen + alignMask) < 0)
-goto cleanup;
+buf = g_new0(char, buflen + alignMask);
 base = buf;
 buf = (char *) (((intptr_t) base + alignMask) & ~alignMask);
 #endif
diff --git a/src/util/virarptable.c b/src/util/virarptable.c
index c4b46604a9..01a27c0093 100644
--- a/src/util/virarptable.c
+++ b/src/util/virarptable.c
@@ -74,8 +74,7 @@ virArpTableGet(void)
 if (msglen < 0)
 return NULL;
 
-if (VIR_ALLOC(table) < 0)
-return NULL;
+table = g_new0(virArpTable, 1);
 
 nh = (struct nlmsghdr*)nlData;
 
diff --git a/src/util/virauthconfig.c b/src/util/virauthconfig.c
index 2e50609531..6b5487c4b0 100644
--- a/src/util/virauthconfig.c
+++ b/src/util/virauthconfig.c
@@ -40,8 +40,7 @@ virAuthConfigPtr virAuthConfigNew(const char *path)
 {
 virAuthConfigPtr auth;
 
-if (VIR_ALLOC(auth) < 0)
-goto error;
+auth = g_new0(virAuthConfig, 1);
 
 auth->path = g_strdup(path);
 
@@ -65,8 +64,7 @@ virAuthConfigPtr virAuthConfigNewData(const char *path,
 {
 virAuthConfigPtr auth;
 
-if (VIR_ALLOC(auth) < 0)
-goto error;
+auth = g_new0(virAuthConfig, 1);
 
 auth->path = g_strdup(path);
 
diff --git a/src/util/virbitmap.c b/src/util/virbitmap.c
index 319bd7b7ce..4fde6f4fd2 100644
--- a/src/util/virbitmap.c
+++ b/src/util/virbitmap.c
@@ -704,9 +704,7 @@ virBitmapToData(virBitmapPtr bitmap,
 else
 len = (len + CHAR_BIT) / CHAR_BIT;
 
-if (VIR_ALLOC_N(*data, len) < 0)
-return -1;
-
+*data = g_new0(unsigned char, len);
 *dataLen = len;
 
 virBitmapToDataBuf(bitmap, *data, *dataLen);
diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c
index 08758b5306..5c0543c66a 100644
--- a/src/util/vircgroup.c
+++ b/src/util/vircgroup.c
@@ -664,10 +664,8 @@ virCgroupNew(pid_t pid,
 {
 VIR_DEBUG("pid=%lld path=%s parent=%p controllers=%d group=%p",
   (long long) pid, path, parent, controllers, group);
-*group = NULL;
 
-if (VIR_ALLOC((*group)) < 0)
-goto error;
+*group = g_new0(virCgroup, 1);
 
 if (path[0] == '/' || !parent) {
 (*group)->path = g_strdup(path);
@@ -2170,8 +2168,7 @@ virCgroupGetPercpuStats(virCgroupPtr group,
 param_idx = 1;
 
 if (guestvcpus && param_idx < nparams) {
-if (VIR_ALLOC_N(sum_cpu_time, need_cpus) < 0)
-goto cleanup;
+sum_cpu_time = g_new0(unsigned long long, need_cpus);
 if (virCgroupGetPercpuVcpuSum(group, guestvcpus, sum_cpu_time,
   need_cpus, cpumap) < 0)
 goto cleanup;
diff --git a/src/util/vircrypto.c b/src/util/vircrypto.c
index 90aed32c53..c4874550af 100644
--- a/src/util/vircrypto.c
+++ b/src/util/vircrypto.c
@@ -88,8 +88,7 @@ virCryptoHashString(virCryptoHash hash,
 
 hashstrlen = (rc * 2) + 1;
 
-if (VIR_ALLOC_N(*output, hashstrlen) < 0)
-return -1;
+*output = g_new0(char, hashstrlen);
 
 for (i = 0; i < rc; i++) {
 (*output)[i * 2] = hex[(buf[i] >> 4) & 0xf];
@@ -167,8 +166,7 @@ virCryptoEncryptDataAESgnutls(gnutls_cipher_algorithm_t 
gnutls_enc_alg,
  * data from non-padded data. Hence datalen + 1
  */
 ciphertextlen = VIR_ROUND_UP(datalen + 1, 16);
-if (VIR_ALLOC_N(ciphertext, ciphertextlen) < 0)
-return -1;
+ciphertext = g_new0(uint8_t, ciphertextlen);
 memcpy(ciphertext, data, datalen);
 
  /* Fill in the padding of the buffer with the size of the padding
diff --git a/src/util/virdnsmasq.c b/src/util/virdnsmasq.c
index 44aa7ad95d..9030f9218a 100644
--- a/src/util/virdnsmasq.c
+++ b/src/util/virdnsmasq.c
@@ -109,8 +109,7 @@ addnhostsAdd(dnsmasqAddnHostsfile *addnhostsfile,
 goto error;
 
 idx = addnhostsfile->nhosts;
-if (VIR_ALLOC(addnhostsfile->hosts[idx].hostnames) < 0)
-goto error;
+addnhostsfile->hosts[idx].hostnames = g_new0(char *, 1);
 
 addnhostsfile->hosts[idx].ip 

[libvirt PATCH 01/12] util: resctrl fix spacing in comment

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

diff --git a/src/util/virresctrl.c b/src/util/virresctrl.c
index aea3fe8687..2535627d63 100644
--- a/src/util/virresctrl.c
+++ b/src/util/virresctrl.c
@@ -1879,7 +1879,7 @@ virResctrlAllocNewFromInfo(virResctrlInfoPtr info)
 }
 }
 
-/* set default free memory bandwidth to 100%*/
+/* set default free memory bandwidth to 100% */
 if (info->membw_info) {
 if (VIR_ALLOC(ret->mem_bw) < 0)
 goto error;
-- 
2.26.2



[libvirt PATCH 05/12] util: sysinfo: use g_new0

2020-10-05 Thread Ján Tomko
Signed-off-by: Ján Tomko 
---
 src/util/virsysinfo.c | 33 +++--
 1 file changed, 11 insertions(+), 22 deletions(-)

diff --git a/src/util/virsysinfo.c b/src/util/virsysinfo.c
index 0e9b281caf..217f842a37 100644
--- a/src/util/virsysinfo.c
+++ b/src/util/virsysinfo.c
@@ -225,8 +225,7 @@ virSysinfoParsePPCSystem(const char *base, 
virSysinfoSystemDefPtr *sysdef)
 if ((cur = strstr(base, "platform")) == NULL)
 return 0;
 
-if (VIR_ALLOC(def) < 0)
-return ret;
+def = g_new0(virSysinfoSystemDef, 1);
 
 base = cur;
 /* Account for format 'platform: '*/
@@ -318,8 +317,7 @@ virSysinfoReadPPC(void)
 g_auto(virSysinfoDefPtr) ret = NULL;
 g_autofree char *outbuf = NULL;
 
-if (VIR_ALLOC(ret) < 0)
-return NULL;
+ret = g_new0(virSysinfoDef, 1);
 
 if (virFileReadAll(CPUINFO, CPUINFO_FILE_LEN, ) < 0) {
 virReportError(VIR_ERR_INTERNAL_ERROR,
@@ -350,8 +348,7 @@ virSysinfoParseARMSystem(const char *base, 
virSysinfoSystemDefPtr *sysdef)
 if ((cur = strstr(base, "platform")) == NULL)
 return 0;
 
-if (VIR_ALLOC(def) < 0)
-return ret;
+def = g_new0(virSysinfoSystemDef, 1);
 
 base = cur;
 /* Account for format 'platform: '*/
@@ -453,8 +450,7 @@ virSysinfoReadARM(void)
 /* Well, we've tried. Fall back to parsing cpuinfo */
 virResetLastError();
 
-if (VIR_ALLOC(ret) < 0)
-return NULL;
+ret = g_new0(virSysinfoDef, 1);
 
 if (virFileReadAll(CPUINFO, CPUINFO_FILE_LEN, ) < 0) {
 virReportError(VIR_ERR_INTERNAL_ERROR,
@@ -507,8 +503,7 @@ virSysinfoParseS390System(const char *base, 
virSysinfoSystemDefPtr *sysdef)
 int ret = -1;
 virSysinfoSystemDefPtr def;
 
-if (VIR_ALLOC(def) < 0)
-return ret;
+def = g_new0(virSysinfoSystemDef, 1);
 
 if (!virSysinfoParseS390Line(base, "Manufacturer", >manufacturer))
 goto cleanup;
@@ -612,8 +607,7 @@ virSysinfoReadS390(void)
 g_auto(virSysinfoDefPtr) ret = NULL;
 g_autofree char *outbuf = NULL;
 
-if (VIR_ALLOC(ret) < 0)
-return NULL;
+ret = g_new0(virSysinfoDef, 1);
 
 /* Gather info from /proc/cpuinfo */
 if (virFileReadAll(CPUINFO, CPUINFO_FILE_LEN, ) < 0) {
@@ -653,8 +647,7 @@ virSysinfoParseBIOS(const char *base, virSysinfoBIOSDefPtr 
*bios)
 if ((cur = strstr(base, "BIOS Information")) == NULL)
 return 0;
 
-if (VIR_ALLOC(def) < 0)
-return ret;
+def = g_new0(virSysinfoBIOSDef, 1);
 
 base = cur;
 if ((cur = strstr(base, "Vendor: ")) != NULL) {
@@ -710,8 +703,7 @@ virSysinfoParseX86System(const char *base, 
virSysinfoSystemDefPtr *sysdef)
 if ((cur = strstr(base, "System Information")) == NULL)
 return 0;
 
-if (VIR_ALLOC(def) < 0)
-return ret;
+def = g_new0(virSysinfoSystemDef, 1);
 
 base = cur;
 if ((cur = strstr(base, "Manufacturer: ")) != NULL) {
@@ -877,8 +869,7 @@ virSysinfoParseX86Chassis(const char *base,
 if ((cur = strstr(base, "Chassis Information")) == NULL)
 return 0;
 
-if (VIR_ALLOC(def) < 0)
-return ret;
+def = g_new0(virSysinfoChassisDef, 1);
 
 base = cur;
 if ((cur = strstr(base, "Manufacturer: ")) != NULL) {
@@ -968,8 +959,7 @@ virSysinfoParseOEMStrings(const char *base,
 if (!(cur = strstr(base, "OEM Strings")))
 return 0;
 
-if (VIR_ALLOC(strings) < 0)
-return -1;
+strings = g_new0(virSysinfoOEMStringsDef, 1);
 
 while ((cur = strstr(cur, "String "))) {
 char *eol;
@@ -1237,8 +1227,7 @@ virSysinfoReadDMI(void)
 if (virCommandRun(cmd, NULL) < 0)
 return NULL;
 
-if (VIR_ALLOC(ret) < 0)
-return NULL;
+ret = g_new0(virSysinfoDef, 1);
 
 ret->type = VIR_SYSINFO_SMBIOS;
 
-- 
2.26.2



[libvirt PATCH 03/12] util: resctrl: use g_new0

2020-10-05 Thread Ján Tomko
Signed-off-by: Ján Tomko 
---
 src/util/virresctrl.c | 77 ++-
 1 file changed, 25 insertions(+), 52 deletions(-)

diff --git a/src/util/virresctrl.c b/src/util/virresctrl.c
index 2535627d63..400c8e9981 100644
--- a/src/util/virresctrl.c
+++ b/src/util/virresctrl.c
@@ -552,9 +552,7 @@ virResctrlGetCacheInfo(virResctrlInfoPtr resctrl,
 continue;
 }
 
-if (VIR_ALLOC(i_type) < 0)
-goto cleanup;
-
+i_type = g_new0(virResctrlInfoPerType, 1);
 i_type->control.scope = type;
 
 rv = virFileReadValueUint(_type->control.max_allocation,
@@ -617,13 +615,9 @@ virResctrlGetCacheInfo(virResctrlInfoPtr resctrl,
 if (!resctrl->levels[level]) {
 virResctrlInfoPerTypePtr *types = NULL;
 
-if (VIR_ALLOC_N(types, VIR_CACHE_TYPE_LAST) < 0)
-goto cleanup;
+types = g_new0(virResctrlInfoPerTypePtr, VIR_CACHE_TYPE_LAST);
 
-if (VIR_ALLOC(resctrl->levels[level]) < 0) {
-VIR_FREE(types);
-goto cleanup;
-}
+resctrl->levels[level] = g_new0(virResctrlInfoPerLevel, 1);
 resctrl->levels[level]->types = types;
 }
 
@@ -654,8 +648,7 @@ virResctrlGetMemoryBandwidthInfo(virResctrlInfoPtr resctrl)
 virResctrlInfoMemBWPtr i_membw = NULL;
 
 /* query memory bandwidth allocation info */
-if (VIR_ALLOC(i_membw) < 0)
-goto cleanup;
+i_membw = g_new0(virResctrlInfoMemBW, 1);
 rv = virFileReadValueUint(_membw->bandwidth_granularity,
   SYSFS_RESCTRL_PATH "/info/MB/bandwidth_gran");
 if (rv == -2) {
@@ -721,8 +714,7 @@ virResctrlGetMonitorInfo(virResctrlInfoPtr resctrl)
 size_t nfeatures = 0;
 virResctrlInfoMongrpPtr info_monitor = NULL;
 
-if (VIR_ALLOC(info_monitor) < 0)
-return -1;
+info_monitor = g_new0(virResctrlInfoMongrp, 1);
 
 /* For now, monitor only exists in level 3 cache */
 info_monitor->cache_level = 3;
@@ -947,9 +939,7 @@ virResctrlInfoGetCache(virResctrlInfoPtr resctrl,
 
 if (VIR_EXPAND_N(*controls, *ncontrols, 1) < 0)
 goto error;
-if (VIR_ALLOC((*controls)[*ncontrols - 1]) < 0)
-goto error;
-
+(*controls)[*ncontrols - 1] = g_new0(virResctrlInfoPerCache, 1);
 memcpy((*controls)[*ncontrols - 1], _type->control, 
sizeof(i_type->control));
 }
 
@@ -1004,8 +994,7 @@ virResctrlInfoGetMonitorPrefix(virResctrlInfoPtr resctrl,
 
 for (i = 0; i < VIR_RESCTRL_MONITOR_TYPE_LAST; i++) {
 if (STREQ(prefix, virResctrlMonitorPrefixTypeToString(i))) {
-if (VIR_ALLOC(mon) < 0)
-goto cleanup;
+mon = g_new0(virResctrlInfoMon, 1);
 mon->type = i;
 break;
 }
@@ -1121,20 +1110,16 @@ virResctrlAllocGetType(virResctrlAllocPtr alloc,
 if (!alloc->levels[level]) {
 virResctrlAllocPerTypePtr *types = NULL;
 
-if (VIR_ALLOC_N(types, VIR_CACHE_TYPE_LAST) < 0)
-return NULL;
+types = g_new0(virResctrlAllocPerTypePtr, VIR_CACHE_TYPE_LAST);
 
-if (VIR_ALLOC(alloc->levels[level]) < 0) {
-VIR_FREE(types);
-return NULL;
-}
+alloc->levels[level] = g_new0(virResctrlAllocPerLevel, 1);
 alloc->levels[level]->types = types;
 }
 
 a_level = alloc->levels[level];
 
-if (!a_level->types[type] && VIR_ALLOC(a_level->types[type]) < 0)
-return NULL;
+if (!a_level->types[type])
+a_level->types[type] = g_new0(virResctrlAllocPerType, 1);
 
 return a_level->types[type];
 }
@@ -1181,8 +1166,8 @@ virResctrlAllocUpdateSize(virResctrlAllocPtr alloc,
  cache - a_type->nsizes + 1) < 0)
 return -1;
 
-if (!a_type->sizes[cache] && VIR_ALLOC(a_type->sizes[cache]) < 0)
-return -1;
+if (!a_type->sizes[cache])
+a_type->sizes[cache] = g_new0(unsigned long long, 1);
 
 *(a_type->sizes[cache]) = size;
 
@@ -1332,8 +1317,7 @@ virResctrlAllocSetMemoryBandwidth(virResctrlAllocPtr 
alloc,
 }
 
 if (!mem_bw) {
-if (VIR_ALLOC(mem_bw) < 0)
-return -1;
+mem_bw = g_new0(virResctrlAllocMemBW, 1);
 alloc->mem_bw = mem_bw;
 }
 
@@ -1349,9 +1333,7 @@ virResctrlAllocSetMemoryBandwidth(virResctrlAllocPtr 
alloc,
 return -1;
 }
 
-if (VIR_ALLOC(mem_bw->bandwidths[id]) < 0)
-return -1;
-
+mem_bw->bandwidths[id] = g_new0(unsigned int, 1);
 *(mem_bw->bandwidths[id]) = memory_bandwidth;
 return 0;
 }
@@ -1497,10 +1479,8 @@ 
virResctrlAllocParseProcessMemoryBandwidth(virResctrlInfoPtr resctrl,
  id - alloc->mem_bw->nbandwidths + 1) < 0) {
 return -1;
 }
-if (!alloc->mem_bw->bandwidths[id]) {
-if (VIR_ALLOC(alloc->mem_bw->bandwidths[id]) < 0)
-return -1;
-}
+if (!alloc->mem_bw->bandwidths[id])
+

[libvirt PATCH 07/12] util: netdev: use g_new0

2020-10-05 Thread Ján Tomko
Signed-off-by: Ján Tomko 
---
 src/util/virnetdev.c | 25 +
 src/util/virnetdevbandwidth.c| 22 --
 src/util/virnetdevip.c   |  3 +--
 src/util/virnetdevmacvlan.c  |  6 ++
 src/util/virnetdevtap.c  |  3 +--
 src/util/virnetdevvlan.c |  4 +---
 src/util/virnetdevvportprofile.c |  7 ++-
 7 files changed, 20 insertions(+), 50 deletions(-)

diff --git a/src/util/virnetdev.c b/src/util/virnetdev.c
index 76aeeba22a..e711a6dc8a 100644
--- a/src/util/virnetdev.c
+++ b/src/util/virnetdev.c
@@ -1209,8 +1209,7 @@ virNetDevGetVirtualFunctions(const char *pfname,
   n_vfname, max_vfs) < 0)
 goto cleanup;
 
-if (VIR_ALLOC_N(*vfname, *n_vfname) < 0)
-goto cleanup;
+*vfname = g_new0(char *, *n_vfname);
 
 for (i = 0; i < *n_vfname; i++) {
 g_autofree char *pciConfigAddr = NULL;
@@ -2039,8 +2038,7 @@ virNetDevReadNetConfig(const char *linkdev, int vf,
 }
 
 if (MACStr) {
-if (VIR_ALLOC(*MAC) < 0)
-goto cleanup;
+*MAC = g_new0(virMacAddr, 1);
 
 if (virMacAddrParse(MACStr, *MAC) < 0) {
 virReportError(VIR_ERR_INTERNAL_ERROR,
@@ -2051,8 +2049,7 @@ virNetDevReadNetConfig(const char *linkdev, int vf,
 }
 
 if (adminMACStr) {
-if (VIR_ALLOC(*adminMAC) < 0)
-goto cleanup;
+*adminMAC = g_new0(virMacAddr, 1);
 
 if (virMacAddrParse(adminMACStr, *adminMAC) < 0) {
 virReportError(VIR_ERR_INTERNAL_ERROR,
@@ -2064,10 +2061,8 @@ virNetDevReadNetConfig(const char *linkdev, int vf,
 
 if (vlanTag != -1) {
 /* construct a simple virNetDevVlan object with a single tag */
-if (VIR_ALLOC(*vlan) < 0)
-goto cleanup;
-if (VIR_ALLOC((*vlan)->tag) < 0)
-goto cleanup;
+*vlan = g_new0(virNetDevVlan, 1);
+(*vlan)->tag = g_new0(unsigned int, 1);
 (*vlan)->nTags = 1;
 (*vlan)->tag[0] = vlanTag;
 }
@@ -2664,8 +2659,8 @@ static int virNetDevGetMcastList(const char *ifname,
 
 cur = buf;
 while (cur) {
-if (!entry && VIR_ALLOC(entry) < 0)
-return -1;
+if (!entry)
+entry = g_new0(virNetDevMcastEntry, 1);
 
 next = strchr(cur, '\n');
 if (next)
@@ -2709,8 +2704,7 @@ static int virNetDevGetMulticastTable(const char *ifname,
 goto cleanup;
 
 if (mcast.nentries > 0) {
-if (VIR_ALLOC_N(filter->multicast.table, mcast.nentries) < 0)
-goto cleanup;
+filter->multicast.table = g_new0(virMacAddr, mcast.nentries);
 
 for (i = 0; i < mcast.nentries; i++) {
 virMacAddrSet(>multicast.table[i],
@@ -2733,8 +2727,7 @@ virNetDevRxFilterNew(void)
 {
 virNetDevRxFilterPtr filter;
 
-if (VIR_ALLOC(filter) < 0)
-return NULL;
+filter = g_new0(virNetDevRxFilter, 1);
 return filter;
 }
 
diff --git a/src/util/virnetdevbandwidth.c b/src/util/virnetdevbandwidth.c
index 5fd7186760..c8eb5cfc79 100644
--- a/src/util/virnetdevbandwidth.c
+++ b/src/util/virnetdevbandwidth.c
@@ -442,39 +442,25 @@ int
 virNetDevBandwidthCopy(virNetDevBandwidthPtr *dest,
const virNetDevBandwidth *src)
 {
-int ret = -1;
-
 *dest = NULL;
 if (!src) {
 /* nothing to be copied */
 return 0;
 }
 
-if (VIR_ALLOC(*dest) < 0)
-goto cleanup;
+*dest = g_new0(virNetDevBandwidth, 1);
 
 if (src->in) {
-if (VIR_ALLOC((*dest)->in) < 0)
-goto cleanup;
+(*dest)->in = g_new0(virNetDevBandwidthRate, 1);
 memcpy((*dest)->in, src->in, sizeof(*src->in));
 }
 
 if (src->out) {
-if (VIR_ALLOC((*dest)->out) < 0) {
-VIR_FREE((*dest)->in);
-goto cleanup;
-}
+(*dest)->out = g_new0(virNetDevBandwidthRate, 1);
 memcpy((*dest)->out, src->out, sizeof(*src->out));
 }
 
-ret = 0;
-
- cleanup:
-if (ret < 0) {
-virNetDevBandwidthFree(*dest);
-*dest = NULL;
-}
-return ret;
+return 0;
 }
 
 bool
diff --git a/src/util/virnetdevip.c b/src/util/virnetdevip.c
index a69567da6f..fc7808cbaa 100644
--- a/src/util/virnetdevip.c
+++ b/src/util/virnetdevip.c
@@ -180,8 +180,7 @@ virNetDevIPAddrAdd(const char *ifname,
 if (VIR_SOCKET_ADDR_FAMILY(addr) == AF_INET &&
 !(peer && VIR_SOCKET_ADDR_VALID(peer))) {
 /* compute a broadcast address if this is IPv4 */
-if (VIR_ALLOC(broadcast) < 0)
-return -1;
+broadcast = g_new0(virSocketAddr, 1);
 
 if (virSocketAddrBroadcastByPrefix(addr, prefix, broadcast) < 0) {
 virReportError(VIR_ERR_INTERNAL_ERROR,
diff --git a/src/util/virnetdevmacvlan.c b/src/util/virnetdevmacvlan.c
index f301a9e96c..72f0d67086 100644
--- a/src/util/virnetdevmacvlan.c
+++ b/src/util/virnetdevmacvlan.c
@@ -726,11 +726,9 @@ 

[libvirt PATCH 08/12] util: systemd: use g_new0

2020-10-05 Thread Ján Tomko
Signed-off-by: Ján Tomko 
---
 src/util/virsystemd.c | 19 +--
 1 file changed, 5 insertions(+), 14 deletions(-)

diff --git a/src/util/virsystemd.c b/src/util/virsystemd.c
index 8456085476..8373ee6509 100644
--- a/src/util/virsystemd.c
+++ b/src/util/virsystemd.c
@@ -364,8 +364,7 @@ int virSystemdCreateMachine(const char *name,
 if (g_atomic_int_get()) {
 g_autoptr(virError) error = NULL;
 
-if (VIR_ALLOC(error) < 0)
-return -1;
+error = g_new0(virError, 1);
 
 guuid = g_variant_new_fixed_array(G_VARIANT_TYPE("y"),
   uuid, 16, sizeof(unsigned char));
@@ -495,8 +494,7 @@ int virSystemdTerminateMachine(const char *name)
 if (!(conn = virGDBusGetSystemBus()))
 return -1;
 
-if (VIR_ALLOC(error) < 0)
-return -1;
+error = g_new0(virError, 1);
 
 /*
  * The systemd DBus API we're invoking has the
@@ -655,14 +653,8 @@ virSystemdActivationAddFD(virSystemdActivationPtr act,
 virSystemdActivationEntryPtr ent = virHashLookup(act->fds, name);
 
 if (!ent) {
-if (VIR_ALLOC(ent) < 0)
-return -1;
-
-if (VIR_ALLOC_N(ent->fds, 1) < 0) {
-virSystemdActivationEntryFree(ent);
-return -1;
-}
-
+ent = g_new0(virSystemdActivationEntry, 1);
+ent->fds = g_new0(int, 1);
 ent->fds[ent->nfds++] = fd;
 
 VIR_DEBUG("Record first FD %d with name %s", fd, name);
@@ -902,8 +894,7 @@ virSystemdActivationNew(virSystemdActivationMap *map,
 const char *fdnames;
 
 VIR_DEBUG("Activated with %d FDs", nfds);
-if (VIR_ALLOC(act) < 0)
-return NULL;
+act = g_new0(virSystemdActivation, 1);
 
 if (!(act->fds = virHashCreate(10, virSystemdActivationEntryFree)))
 goto error;
-- 
2.26.2



[libvirt PATCH 10/12] util: conf: use g_new0

2020-10-05 Thread Ján Tomko
Signed-off-by: Ján Tomko 
---
 src/util/virconf.c | 23 ++-
 1 file changed, 6 insertions(+), 17 deletions(-)

diff --git a/src/util/virconf.c b/src/util/virconf.c
index 8575dd8849..e983a769ee 100644
--- a/src/util/virconf.c
+++ b/src/util/virconf.c
@@ -163,8 +163,7 @@ virConfNew(void)
 {
 virConfPtr ret;
 
-if (VIR_ALLOC(ret) < 0)
-return NULL;
+ret = g_new0(virConf, 1);
 ret->filename = NULL;
 ret->flags = 0;
 
@@ -219,8 +218,7 @@ virConfAddEntry(virConfPtr conf, char *name, 
virConfValuePtr value, char *comm)
 if (name)
 VIR_DEBUG("Add entry %s %p", name, value);
 
-if (VIR_ALLOC(ret) < 0)
-return NULL;
+ret = g_new0(virConfEntry, 1);
 
 ret->name = name;
 ret->value = value;
@@ -522,11 +520,7 @@ virConfParseValue(virConfParserCtxtPtr ctxt)
 virConfError(ctxt, VIR_ERR_CONF_SYNTAX, _("expecting a value"));
 return NULL;
 }
-if (VIR_ALLOC(ret) < 0) {
-virConfFreeList(lst);
-VIR_FREE(str);
-return NULL;
-}
+ret = g_new0(virConfValue, 1);
 ret->type = type;
 ret->l = l;
 ret->str = str;
@@ -947,8 +941,7 @@ int virConfGetValueStringList(virConfPtr conf,
 }
 }
 
-if (VIR_ALLOC_N(*values, len + 1) < 0)
-return -1;
+*values = g_new0(char *, len + 1);
 
 for (len = 0, eval = cval->list; eval; len++, eval = eval->next)
 (*values)[len] = g_strdup(eval->str);
@@ -956,8 +949,7 @@ int virConfGetValueStringList(virConfPtr conf,
 
 case VIR_CONF_STRING:
 if (compatString) {
-if (VIR_ALLOC_N(*values, cval->str ? 2 : 1) < 0)
-return -1;
+*values = g_new0(char *, cval->str ? 2 : 1);
 if (cval->str)
 (*values)[0] = g_strdup(cval->str);
 break;
@@ -1356,10 +1348,7 @@ virConfSetValue(virConfPtr conf,
 }
 
 if (!cur) {
-if (VIR_ALLOC(cur) < 0) {
-virConfFreeValue(value);
-return -1;
-}
+cur = g_new0(virConfEntry, 1);
 cur->comment = NULL;
 cur->name = g_strdup(setting);
 cur->value = value;
-- 
2.26.2



[libvirt PATCH 12/12] util: o-z: use g_new0

2020-10-05 Thread Ján Tomko
Signed-off-by: Ján Tomko 
---
 src/util/virpci.c   | 12 
 src/util/virperf.c  |  3 +--
 src/util/virpolkit.c|  3 +--
 src/util/virportallocator.c |  3 +--
 src/util/virprocess.c   |  3 +--
 src/util/virrotatingfile.c  | 15 +--
 src/util/virscsi.c  |  6 ++
 src/util/virscsivhost.c |  3 +--
 src/util/virseclabel.c  | 13 +++--
 src/util/virstorageencryption.c | 16 +---
 src/util/virstring.c|  3 +--
 src/util/virthreadpool.c|  9 +++--
 src/util/virtime.c  |  6 ++
 src/util/virtypedparam.c| 20 +++-
 src/util/viruri.c   |  3 +--
 src/util/virusb.c   |  3 +--
 src/util/virutil.c  | 15 +--
 src/util/virxml.c   |  7 ++-
 18 files changed, 46 insertions(+), 97 deletions(-)

diff --git a/src/util/virpci.c b/src/util/virpci.c
index 47c671daa0..6fa8acd246 100644
--- a/src/util/virpci.c
+++ b/src/util/virpci.c
@@ -1372,8 +1372,7 @@ virPCIDeviceNew(unsigned int domain,
 g_autofree char *vendor = NULL;
 g_autofree char *product = NULL;
 
-if (VIR_ALLOC(dev) < 0)
-return NULL;
+dev = g_new0(virPCIDevice, 1);
 
 dev->address.domain = domain;
 dev->address.bus = bus;
@@ -1422,8 +1421,7 @@ virPCIDeviceCopy(virPCIDevicePtr dev)
 {
 virPCIDevicePtr copy;
 
-if (VIR_ALLOC(copy) < 0)
-return NULL;
+copy = g_new0(virPCIDevice, 1);
 
 /* shallow copy to take care of most attributes */
 *copy = *dev;
@@ -1871,8 +1869,7 @@ virPCIGetIOMMUGroupAddressesAddOne(virPCIDeviceAddressPtr 
newDevAddr, void *opaq
 virPCIDeviceAddressPtr copyAddr;
 
 /* make a copy to insert onto the list */
-if (VIR_ALLOC(copyAddr) < 0)
-goto cleanup;
+copyAddr = g_new0(virPCIDeviceAddress, 1);
 
 *copyAddr = *newDevAddr;
 
@@ -2204,8 +2201,7 @@ virPCIGetDeviceAddressFromSysfsLink(const char 
*device_link)
 }
 
 config_address = g_path_get_basename(device_path);
-if (VIR_ALLOC(bdf) < 0)
-return NULL;
+bdf = g_new0(virPCIDeviceAddress, 1);
 
 if (virPCIDeviceAddressParse(config_address, bdf) < 0) {
 virReportError(VIR_ERR_INTERNAL_ERROR,
diff --git a/src/util/virperf.c b/src/util/virperf.c
index 2e95509caf..7f260d2da6 100644
--- a/src/util/virperf.c
+++ b/src/util/virperf.c
@@ -368,8 +368,7 @@ virPerfNew(void)
 size_t i;
 virPerfPtr perf;
 
-if (VIR_ALLOC(perf) < 0)
-return NULL;
+perf = g_new0(virPerf, 1);
 
 for (i = 0; i < VIR_PERF_EVENT_LAST; i++) {
 perf->events[i].fd = -1;
diff --git a/src/util/virpolkit.c b/src/util/virpolkit.c
index aad924a065..1d6be443f7 100644
--- a/src/util/virpolkit.c
+++ b/src/util/virpolkit.c
@@ -178,8 +178,7 @@ virPolkitAgentCreate(void)
 if (virPipe(pipe_fd) < 0)
 goto error;
 
-if (VIR_ALLOC(agent) < 0)
-goto error;
+agent = g_new0(virPolkitAgent, 1);
 
 agent->cmd = virCommandNewArgList(PKTTYAGENT, "--process", NULL);
 
diff --git a/src/util/virportallocator.c b/src/util/virportallocator.c
index f450740318..76c6e43726 100644
--- a/src/util/virportallocator.c
+++ b/src/util/virportallocator.c
@@ -102,8 +102,7 @@ virPortAllocatorRangeNew(const char *name,
 return NULL;
 }
 
-if (VIR_ALLOC(range) < 0)
-return NULL;
+range = g_new0(virPortAllocatorRange, 1);
 
 range->start = start;
 range->end = end;
diff --git a/src/util/virprocess.c b/src/util/virprocess.c
index d379f7446f..9366f0630c 100644
--- a/src/util/virprocess.c
+++ b/src/util/virprocess.c
@@ -1351,8 +1351,7 @@ virProcessNamespaceAvailable(unsigned int ns)
 /* Signal parent as soon as the child dies. RIP. */
 flags |= SIGCHLD;
 
-if (VIR_ALLOC_N(stack, stacksize) < 0)
-return -1;
+stack = g_new0(char, stacksize);
 
 childStack = stack + stacksize;
 
diff --git a/src/util/virrotatingfile.c b/src/util/virrotatingfile.c
index b77e30dba7..a88c332cf4 100644
--- a/src/util/virrotatingfile.c
+++ b/src/util/virrotatingfile.c
@@ -105,8 +105,7 @@ virRotatingFileWriterEntryNew(const char *path,
 
 VIR_DEBUG("Opening %s mode=0%02o", path, mode);
 
-if (VIR_ALLOC(entry) < 0)
-return NULL;
+entry = g_new0(virRotatingFileWriterEntry, 1);
 
 if ((entry->fd = open(path, O_CREAT|O_APPEND|O_WRONLY|O_CLOEXEC, mode)) < 
0) {
 virReportSystemError(errno,
@@ -148,8 +147,7 @@ virRotatingFileReaderEntryNew(const char *path)
 
 VIR_DEBUG("Opening %s", path);
 
-if (VIR_ALLOC(entry) < 0)
-return NULL;
+entry = g_new0(virRotatingFileReaderEntry, 1);
 
 if ((entry->fd = open(path, O_RDONLY|O_CLOEXEC)) < 0) {
 if (errno != ENOENT) {
@@ -238,8 +236,7 @@ virRotatingFileWriterNew(const char *path,
 {
 virRotatingFileWriterPtr file;
 
-if (VIR_ALLOC(file) < 0)
-goto error;
+file = g_new0(virRotatingFileWriter, 1);
 
   

[libvirt PATCH 06/12] util: command: use g_new0

2020-10-05 Thread Ján Tomko
Signed-off-by: Ján Tomko 
---
 src/util/vircommand.c | 29 +
 1 file changed, 9 insertions(+), 20 deletions(-)

diff --git a/src/util/vircommand.c b/src/util/vircommand.c
index 8060cdfada..6350e77523 100644
--- a/src/util/vircommand.c
+++ b/src/util/vircommand.c
@@ -935,8 +935,7 @@ virCommandNewArgs(const char *const*args)
 {
 virCommandPtr cmd;
 
-if (VIR_ALLOC(cmd) < 0)
-return NULL;
+cmd = g_new0(virCommand, 1);
 
 cmd->handshakeWait[0] = -1;
 cmd->handshakeWait[1] = -1;
@@ -2183,21 +2182,18 @@ virCommandProcessIO(virCommandPtr cmd)
 if (cmd->outbuf) {
 outfd = cmd->outfd;
 VIR_FREE(*cmd->outbuf);
-if (VIR_ALLOC_N(*cmd->outbuf, 1) < 0)
-ret = -1;
+*cmd->outbuf = g_new0(char, 1);
 }
 if (cmd->errbuf) {
 errfd = cmd->errfd;
 VIR_FREE(*cmd->errbuf);
-if (VIR_ALLOC_N(*cmd->errbuf, 1) < 0)
-ret = -1;
+*cmd->errbuf = g_new0(char, 1);
 }
 if (ret == -1)
 goto cleanup;
 ret = -1;
 
-if (VIR_ALLOC_N(fds, 3 + virCommandGetNumSendBuffers(cmd)) < 0)
-goto cleanup;
+fds = g_new0(struct pollfd, 3 + virCommandGetNumSendBuffers(cmd));
 
 for (;;) {
 size_t i;
@@ -2636,8 +2632,7 @@ virCommandRunAsync(virCommandPtr cmd, pid_t *pid)
 VIR_FORCE_CLOSE(cmd->infd);
 /* clear any error so we can catch if the helper thread reports one */
 cmd->has_error = 0;
-if (VIR_ALLOC(cmd->asyncioThread) < 0)
-ret = -1;
+cmd->asyncioThread = g_new0(virThread, 1);
 
 if (virThreadCreateFull(cmd->asyncioThread, true,
 virCommandDoAsyncIOHelper,
@@ -2854,10 +2849,7 @@ int virCommandHandshakeWait(virCommandPtr cmd)
 if (c != '1') {
 g_autofree char *msg = NULL;
 ssize_t len;
-if (VIR_ALLOC_N(msg, 1024) < 0) {
-VIR_FORCE_CLOSE(cmd->handshakeWait[0]);
-return -1;
-}
+msg = g_new0(char, 1024);
 /* Close the handshakeNotify fd before trying to read anything
  * further on the handshakeWait pipe; so that a child waiting
  * on our acknowledgment will die rather than deadlock.  */
@@ -3193,8 +3185,7 @@ virCommandRunRegex(virCommandPtr cmd,
 int ret = -1;
 
 /* Compile all regular expressions */
-if (VIR_ALLOC_N(reg, nregex) < 0)
-return -1;
+reg = g_new0(GRegex *, nregex);
 
 for (i = 0; i < nregex; i++) {
 g_autoptr(GError) err = NULL;
@@ -3212,8 +3203,7 @@ virCommandRunRegex(virCommandPtr cmd,
 }
 
 /* Storage for matched variables */
-if (VIR_ALLOC_N(groups, totgroups) < 0)
-goto cleanup;
+groups = g_new0(char *, totgroups);
 
 virCommandSetOutputBuffer(cmd, );
 if (virCommandRun(cmd, exitstatus) < 0)
@@ -3299,8 +3289,7 @@ virCommandRunNul(virCommandPtr cmd,
 if (n_columns == 0)
 return -1;
 
-if (VIR_ALLOC_N(v, n_columns) < 0)
-return -1;
+v = g_new0(char *, n_columns);
 for (i = 0; i < n_columns; i++)
 v[i] = NULL;
 
-- 
2.26.2



[libvirt PATCH 02/12] util: split out VIR_ALLOC calls

2020-10-05 Thread Ján Tomko
To make the following commits simpler.

Signed-off-by: Ján Tomko 
---
 src/util/vircommand.c |  6 --
 src/util/virxml.c | 10 --
 2 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/src/util/vircommand.c b/src/util/vircommand.c
index 859d6b0ce5..8060cdfada 100644
--- a/src/util/vircommand.c
+++ b/src/util/vircommand.c
@@ -2636,8 +2636,10 @@ virCommandRunAsync(virCommandPtr cmd, pid_t *pid)
 VIR_FORCE_CLOSE(cmd->infd);
 /* clear any error so we can catch if the helper thread reports one */
 cmd->has_error = 0;
-if (VIR_ALLOC(cmd->asyncioThread) < 0 ||
-virThreadCreateFull(cmd->asyncioThread, true,
+if (VIR_ALLOC(cmd->asyncioThread) < 0)
+ret = -1;
+
+if (virThreadCreateFull(cmd->asyncioThread, true,
 virCommandDoAsyncIOHelper,
 "cmd-async-io", false, cmd) < 0) {
 virReportSystemError(errno, "%s",
diff --git a/src/util/virxml.c b/src/util/virxml.c
index 5315d4ff6f..1927ff490f 100644
--- a/src/util/virxml.c
+++ b/src/util/virxml.c
@@ -672,12 +672,10 @@ virXPathNodeSet(const char *xpath,
 
 ret = obj->nodesetval->nodeNr;
 if (list != NULL && ret) {
-if (VIR_ALLOC_N(*list, ret) < 0) {
-ret = -1;
-} else {
-memcpy(*list, obj->nodesetval->nodeTab,
-   ret * sizeof(xmlNodePtr));
-}
+if (VIR_ALLOC_N(*list, ret) < 0)
+return -1;
+
+memcpy(*list, obj->nodesetval->nodeTab, ret * sizeof(xmlNodePtr));
 }
 xmlXPathFreeObject(obj);
 return ret;
-- 
2.26.2



[libvirt PATCH 3/4] virsh: delete vsh[CM]alloc

2020-10-05 Thread Ján Tomko
Signed-off-by: Ján Tomko 
---
 tools/vsh.c | 18 --
 tools/vsh.h |  6 --
 2 files changed, 24 deletions(-)

diff --git a/tools/vsh.c b/tools/vsh.c
index 98066d17bf..ca92bcd78c 100644
--- a/tools/vsh.c
+++ b/tools/vsh.c
@@ -100,24 +100,6 @@ vshPrettyCapacity(unsigned long long val, const char 
**unit)
 }
 
 
-void *
-_vshMalloc(vshControl *ctl, size_t size, const char *filename, int line)
-{
-char *x;
-
-if (VIR_ALLOC_N(x, size) == 0)
-return x;
-vshError(ctl, _("%s: %d: failed to allocate %d bytes"),
- filename, line, (int) size);
-exit(EXIT_FAILURE);
-}
-
-void *
-vshCalloc(vshControl *ctl G_GNUC_UNUSED, size_t nmemb, size_t size)
-{
-return g_malloc0_n(nmemb, size);
-}
-
 int
 vshNameSorter(const void *a, const void *b)
 {
diff --git a/tools/vsh.h b/tools/vsh.h
index 0a40995bf5..5583fef9cc 100644
--- a/tools/vsh.h
+++ b/tools/vsh.h
@@ -465,12 +465,6 @@ char * vshReadline(vshControl *ctl, const char *prompt);
 
 void vshReadlineHistoryAdd(const char *cmd);
 
-/* allocation wrappers */
-void *_vshMalloc(vshControl *ctl, size_t sz, const char *filename, int line);
-#define vshMalloc(_ctl, _sz)_vshMalloc(_ctl, _sz, __FILE__, __LINE__)
-
-void *vshCalloc(vshControl *ctl, size_t nmemb, size_t sz);
-
 /* Macros to help dealing with mutually exclusive options. */
 
 /* VSH_EXCLUSIVE_OPTIONS_EXPR:
-- 
2.26.2



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

2020-10-05 Thread Ján Tomko
Ján Tomko (4):
  virsh: do not add bools into size calculations
  virsh: use g_new0 instead of vsh[CM]alloc
  virsh: delete vsh[CM]alloc
  virsh: network-port: remove pointless comment

 tools/virsh-checkpoint.c | 11 +++
 tools/virsh-domain-monitor.c | 11 +--
 tools/virsh-domain.c | 24 
 tools/virsh-host.c   | 22 +++---
 tools/virsh-interface.c  |  8 
 tools/virsh-network.c|  9 -
 tools/virsh-nodedev.c| 12 ++--
 tools/virsh-nwfilter.c   |  8 
 tools/virsh-pool.c   |  8 
 tools/virsh-secret.c |  6 +++---
 tools/virsh-snapshot.c   | 14 --
 tools/virsh-volume.c |  8 
 tools/vsh.c  | 30 ++
 tools/vsh.h  |  6 --
 14 files changed, 78 insertions(+), 99 deletions(-)

-- 
2.26.2



[libvirt PATCH 2/4] virsh: use g_new0 instead of vsh[CM]alloc

2020-10-05 Thread Ján Tomko
Signed-off-by: Ján Tomko 
---
 tools/virsh-checkpoint.c |  5 +++--
 tools/virsh-domain-monitor.c | 11 +--
 tools/virsh-domain.c | 24 
 tools/virsh-host.c   | 22 +++---
 tools/virsh-interface.c  |  8 
 tools/virsh-network.c|  8 
 tools/virsh-nodedev.c| 12 ++--
 tools/virsh-nwfilter.c   |  8 
 tools/virsh-pool.c   |  8 
 tools/virsh-secret.c |  6 +++---
 tools/virsh-snapshot.c   |  8 
 tools/virsh-volume.c |  8 
 tools/vsh.c  | 12 ++--
 13 files changed, 70 insertions(+), 70 deletions(-)

diff --git a/tools/virsh-checkpoint.c b/tools/virsh-checkpoint.c
index cefdfd7800..ac9d5bd348 100644
--- a/tools/virsh-checkpoint.c
+++ b/tools/virsh-checkpoint.c
@@ -583,11 +583,12 @@ virshCheckpointListCollect(vshControl *ctl,
 size_t i;
 int count = -1;
 virDomainCheckpointPtr *chks;
-virshCheckpointListPtr checkpointlist = vshMalloc(ctl,
-  sizeof(*checkpointlist));
+virshCheckpointListPtr checkpointlist = NULL;
 virshCheckpointListPtr ret = NULL;
 unsigned int flags = orig_flags;
 
+checkpointlist = g_new0(struct virshCheckpointList, 1);
+
 if (from)
 count = virDomainCheckpointListAllChildren(from, , flags);
 else
diff --git a/tools/virsh-domain-monitor.c b/tools/virsh-domain-monitor.c
index c8a7c0f1b7..e0491d48ac 100644
--- a/tools/virsh-domain-monitor.c
+++ b/tools/virsh-domain-monitor.c
@@ -1063,8 +1063,7 @@ cmdDomblkstat(vshControl *ctl, const vshCmd *cmd)
 DOMBLKSTAT_LEGACY_PRINT(3, stats.wr_bytes);
 DOMBLKSTAT_LEGACY_PRINT(4, stats.errs);
 } else {
-params = vshCalloc(ctl, nparams, sizeof(*params));
-
+params = g_new0(virTypedParameter, nparams);
 if (virDomainBlockStatsFlags(dom, device, params, , 0) < 0) {
 vshError(ctl, _("Failed to get block stats for domain '%s' device 
'%s'"), name, device);
 goto cleanup;
@@ -1618,7 +1617,7 @@ virshDomainListFree(virshDomainListPtr domlist)
 static virshDomainListPtr
 virshDomainListCollect(vshControl *ctl, unsigned int flags)
 {
-virshDomainListPtr list = vshMalloc(ctl, sizeof(*list));
+virshDomainListPtr list = g_new0(struct virshDomainList, 1);
 size_t i;
 int ret;
 int *ids = NULL;
@@ -1680,7 +1679,7 @@ virshDomainListCollect(vshControl *ctl, unsigned int 
flags)
 }
 
 if (nids) {
-ids = vshMalloc(ctl, sizeof(int) * nids);
+ids = g_new0(int, nids);
 
 if ((nids = virConnectListDomains(priv->conn, ids, nids)) < 0) {
 vshError(ctl, "%s", _("Failed to list active domains"));
@@ -1697,7 +1696,7 @@ virshDomainListCollect(vshControl *ctl, unsigned int 
flags)
 }
 
 if (nnames) {
-names = vshMalloc(ctl, sizeof(char *) * nnames);
+names = g_new0(char *, nnames);
 
 if ((nnames = virConnectListDefinedDomains(priv->conn, names,
   nnames)) < 0) {
@@ -1707,7 +1706,7 @@ virshDomainListCollect(vshControl *ctl, unsigned int 
flags)
 }
 }
 
-list->domains = vshMalloc(ctl, sizeof(virDomainPtr) * (nids + nnames));
+list->domains = g_new0(virDomainPtr, nids + nnames);
 list->ndomains = 0;
 
 /* get active domains */
diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index b5e7d8f705..8f11393197 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -1431,7 +1431,7 @@ cmdBlkdeviotune(vshControl *ctl, const vshCmd *cmd)
 goto cleanup;
 }
 
-params = vshCalloc(ctl, nparams, sizeof(*params));
+params = g_new0(virTypedParameter, nparams);
 
 if (virDomainGetBlockIoTune(dom, disk, params, , flags) != 0) {
 vshError(ctl, "%s",
@@ -1629,7 +1629,7 @@ cmdBlkiotune(vshControl * ctl, const vshCmd * cmd)
 }
 
 /* now go get all the blkio parameters */
-params = vshCalloc(ctl, nparams, sizeof(*params));
+params = g_new0(virTypedParameter, nparams);
 if (virDomainGetBlkioParameters(dom, params, , flags) != 0) {
 vshError(ctl, "%s", _("Unable to get blkio parameters"));
 goto cleanup;
@@ -2372,7 +2372,7 @@ cmdBlockcopy(vshControl *ctl, const vshCmd *cmd)
 transientjob) {
 /* New API */
 if (bandwidth || granularity || buf_size) {
-params = vshCalloc(ctl, 3, sizeof(*params));
+params = g_new0(virTypedParameter, 3);
 if (bandwidth) {
 if (!bytes) {
 /* bandwidth is ulong MiB/s, but the typed parameter is
@@ -3375,7 +3375,7 @@ cmdDomIftune(vshControl *ctl, const vshCmd *cmd)
 }
 
 /* get all interface parameters */
-params = vshCalloc(ctl, nparams, sizeof(*params));
+

[libvirt PATCH 4/4] virsh: network-port: remove pointless comment

2020-10-05 Thread Ján Tomko
We do not have a legacy API for listing network ports
so there's nothing to fall back on.

Signed-off-by: Ján Tomko 
---
 tools/virsh-network.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/tools/virsh-network.c b/tools/virsh-network.c
index c5347660de..745afc537d 100644
--- a/tools/virsh-network.c
+++ b/tools/virsh-network.c
@@ -1693,7 +1693,6 @@ virshNetworkPortListCollect(vshControl *ctl,
 if (!(network = virshCommandOptNetwork(ctl, cmd, NULL)))
 goto cleanup;
 
-/* try the list with flags support (0.10.2 and later) */
 if ((ret = virNetworkListAllPorts(network,
   >ports,
   flags)) < 0)
-- 
2.26.2



[libvirt PATCH 1/4] virsh: do not add bools into size calculations

2020-10-05 Thread Ján Tomko
Switch the allocation in virshSnapshotListCollect and
its cargo-culted Checkpoint counterpart to two separate
g_new0 calls and move the boolean expression to
the if condition that chooses between them.

Signed-off-by: Ján Tomko 
---
 tools/virsh-checkpoint.c | 6 --
 tools/virsh-snapshot.c   | 6 --
 2 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/tools/virsh-checkpoint.c b/tools/virsh-checkpoint.c
index f3c4fe90ba..cefdfd7800 100644
--- a/tools/virsh-checkpoint.c
+++ b/tools/virsh-checkpoint.c
@@ -600,8 +600,10 @@ virshCheckpointListCollect(vshControl *ctl,
 
 /* When mixing --from and --tree, we also want a copy of from
  * in the list, but with no parent for that one entry.  */
-checkpointlist->chks = vshCalloc(ctl, count + (tree && from),
- sizeof(*checkpointlist->chks));
+if (from && tree)
+checkpointlist->chks = g_new0(struct virshChk, count + 1);
+else
+checkpointlist->chks = g_new0(struct virshChk, count);
 checkpointlist->nchks = count;
 for (i = 0; i < count; i++)
 checkpointlist->chks[i].chk = chks[i];
diff --git a/tools/virsh-snapshot.c b/tools/virsh-snapshot.c
index 99e3d98c6f..b4498df298 100644
--- a/tools/virsh-snapshot.c
+++ b/tools/virsh-snapshot.c
@@ -1102,8 +1102,10 @@ virshSnapshotListCollect(vshControl *ctl, virDomainPtr 
dom,
 if (count >= 0) {
 /* When mixing --from and --tree, we also want a copy of from
  * in the list, but with no parent for that one entry.  */
-snaplist->snaps = vshCalloc(ctl, count + (tree && from),
-sizeof(*snaplist->snaps));
+if (tree && from)
+snaplist->snaps = g_new0(struct virshSnap, count + 1);
+else
+snaplist->snaps = g_new0(struct virshSnap, count);
 snaplist->nsnaps = count;
 for (i = 0; i < count; i++)
 snaplist->snaps[i].snap = snaps[i];
-- 
2.26.2



Re: [PATCH] rpm: Enable Xen support on AArch64

2020-10-05 Thread Neal Gompa
On Mon, Oct 5, 2020 at 6:18 AM Andrea Bolognani  wrote:
>
> On Sun, 2020-10-04 at 22:16 -0400, Neal Gompa wrote:
> > +++ b/libvirt.spec.in
> > +# Xen is available only on i386 x86_64 ia64 aarch64
> > +%ifnarch %{ix86} x86_64 ia64 aarch64
> >  %define with_libxl 0
> >  %endif
>
> The code change is okay, but duplicating the list of architectures in
> the comment is kinda pointless and results in unnecessary churn; I
> would reword it as
>
>   Xen is available only on some architectures
>
> Are you okay with that change? If so, I will add my
>
>   Reviewed-by: Andrea Bolognani 
>
> and push the patch.
>

I'm fine with that. I debated making that change myself, too. :)

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




Re: [libvirt PATCH] rpm: include aarch64 & riscv64 in systemtap 64-bit arch tapset rename

2020-10-05 Thread Neal Gompa
On Mon, Oct 5, 2020 at 8:55 AM Daniel P. Berrangé  wrote:
>
> Signed-off-by: Daniel P. Berrangé 
> ---
>  libvirt.spec.in | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/libvirt.spec.in b/libvirt.spec.in
> index 682d43c290..d13aae5cf5 100644
> --- a/libvirt.spec.in
> +++ b/libvirt.spec.in
> @@ -1261,7 +1261,7 @@ rm -f 
> $RPM_BUILD_ROOT%{_datadir}/augeas/lenses/tests/test_libvirtd_libxl.aug
>  # Copied into libvirt-docs subpackage eventually
>  mv $RPM_BUILD_ROOT%{_datadir}/doc/libvirt libvirt-docs
>
> -%ifarch %{power64} s390x x86_64
> +%ifarch %{power64} s390x x86_64 aarch64 riscv64
>  mv $RPM_BUILD_ROOT%{_datadir}/systemtap/tapset/libvirt_probes.stp \
> $RPM_BUILD_ROOT%{_datadir}/systemtap/tapset/libvirt_probes-64.stp
>
> --
> 2.26.2
>

Reviewed-by: Neal Gompa 


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




Re: [PATCH V4] Modify virCPUarmCompare to perform compare actions

2020-10-05 Thread Michal Privoznik

On 10/2/20 3:45 PM, Daniel Henrique Barboza wrote:



On 9/24/20 11:12 AM, Zhenyu Zheng wrote:

Modify virCPUarmCompare in cpu_arm.c to perform compare action.
This patch only adds host to host CPU compare, the rest cases
remains the same. This is useful for source and destination host
compare during migrations to avoid migration between different
CPU models that have different CPU freatures.

Signed-off-by: Zhenyu Zheng 
---


Reviewed-by: Daniel Henrique Barboza 


Pushed now.

Michal



Re: [PATCH] tests: cover disk, interface

2020-10-05 Thread Michal Privoznik

On 10/4/20 9:05 PM, Cole Robinson wrote:

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


Reviewed-by: Michal Privoznik 

Michal



Re: [libvirt PATCH] rpm: include aarch64 & riscv64 in systemtap 64-bit arch tapset rename

2020-10-05 Thread Andrea Bolognani
On Mon, 2020-10-05 at 13:54 +0100, Daniel P. Berrangé wrote:
> Signed-off-by: Daniel P. Berrangé 
> ---
>  libvirt.spec.in | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

Reviewed-by: Andrea Bolognani 

-- 
Andrea Bolognani / Red Hat / Virtualization



Re: [PATCH 1/1] Optional free-page-reporting can be enabled/disabled for memballon device of model 'virtio'.

2020-10-05 Thread Nico Pache
Thanks for the reviews!

I'll get started on a V2 :)

--Nico

On Mon, Oct 5, 2020 at 5:32 AM Peter Krempa  wrote:

> On Mon, Oct 05, 2020 at 11:11:54 +0200, David Hildenbrand wrote:
> > On 05.10.20 10:06, Peter Krempa wrote:
> > > On Fri, Oct 02, 2020 at 11:59:43 -0400, Nico Pache wrote:
> > >> xml:
> > >> 
> > >>   
> > >
> > > according to what you state in the cover-letter this is a
> > > 'virtio-balloon-pci' feature. We usually put stuff which depends on a
> > > specific model of the device into the  subelement of the device
> > > element.
> >
> > IIRC, this should work for virtio-balloon-*, including
> virtio-balloon-ccw.
>
> In that case the qemu capability detection should be added also for the
> ccw version and capability name needs to be modified to not include pci.
>
>


Re: [PATCH v2 0/4] Add support for QEMU's 'fmode' and 'dmode'

2020-10-05 Thread Brian Turek
I did some further testing and it appears that QEMU is reading the flags as
base-10 which causes issues. I'll need to make some tweaks and release a v3
of the patches later today.

Please ignore this set.

On Fri, Oct 2, 2020, 11:55 AM Brian Turek  wrote:

> This second version of the patch incorporates Peter Krempa's feedback
> by tweaking a few things in the code and, more importantly, splitting
> up the singular large patch into smaller patches.
>
> Brian Turek (4):
>   qemu: capabilities: add QEMU_CAPS_FSDEV_CREATEMODE
>   qemu: add support for 'fmode' and 'dmode' options
>   qemu: add schema 'fmode' and 'dmode' options
>   qemu: add docs for 'fmode' and 'dmode' options
>
>  docs/formatdomain.rst | 12 
>  docs/schemas/domaincommon.rng | 16 +
>  src/conf/domain_conf.c| 27 
>  src/conf/domain_conf.h|  2 +
>  src/qemu/qemu_capabilities.c  |  2 +
>  src/qemu/qemu_capabilities.h  |  1 +
>  src/qemu/qemu_command.c   |  6 ++
>  src/qemu/qemu_validate.c  | 18 ++
>  .../caps_2.10.0.aarch64.xml   |  1 +
>  .../caps_2.10.0.ppc64.xml |  1 +
>  .../caps_2.10.0.s390x.xml |  1 +
>  .../caps_2.10.0.x86_64.xml|  1 +
>  .../caps_2.11.0.s390x.xml |  1 +
>  .../caps_2.11.0.x86_64.xml|  1 +
>  .../caps_2.12.0.aarch64.xml   |  1 +
>  .../caps_2.12.0.ppc64.xml |  1 +
>  .../caps_2.12.0.s390x.xml |  1 +
>  .../caps_2.12.0.x86_64.xml|  1 +
>  .../qemucapabilitiesdata/caps_3.0.0.ppc64.xml |  1 +
>  .../caps_3.0.0.riscv32.xml|  1 +
>  .../caps_3.0.0.riscv64.xml|  1 +
>  .../qemucapabilitiesdata/caps_3.0.0.s390x.xml |  1 +
>  .../caps_3.0.0.x86_64.xml |  1 +
>  .../qemucapabilitiesdata/caps_3.1.0.ppc64.xml |  1 +
>  .../caps_3.1.0.x86_64.xml |  1 +
>  .../caps_4.0.0.aarch64.xml|  1 +
>  .../qemucapabilitiesdata/caps_4.0.0.ppc64.xml |  1 +
>  .../caps_4.0.0.riscv32.xml|  1 +
>  .../caps_4.0.0.riscv64.xml|  1 +
>  .../qemucapabilitiesdata/caps_4.0.0.s390x.xml |  1 +
>  .../caps_4.0.0.x86_64.xml |  1 +
>  .../caps_4.1.0.x86_64.xml |  1 +
>  .../caps_4.2.0.aarch64.xml|  1 +
>  .../qemucapabilitiesdata/caps_4.2.0.ppc64.xml |  1 +
>  .../qemucapabilitiesdata/caps_4.2.0.s390x.xml |  1 +
>  .../caps_4.2.0.x86_64.xml |  1 +
>  .../caps_5.0.0.aarch64.xml|  1 +
>  .../qemucapabilitiesdata/caps_5.0.0.ppc64.xml |  1 +
>  .../caps_5.0.0.riscv64.xml|  1 +
>  .../caps_5.0.0.x86_64.xml |  1 +
>  .../caps_5.1.0.x86_64.xml |  1 +
>  .../caps_5.2.0.x86_64.xml |  1 +
>  .../virtio-9p-createmode.x86_64-latest.args   | 45 ++
>  .../qemuxml2argvdata/virtio-9p-createmode.xml | 58 ++
>  .../virtio-9p-createmode.x86_64-latest.xml| 61 +++
>  tests/qemuxml2xmltest.c   |  1 +
>  46 files changed, 283 insertions(+)
>  create mode 100644
> tests/qemuxml2argvdata/virtio-9p-createmode.x86_64-latest.args
>  create mode 100644 tests/qemuxml2argvdata/virtio-9p-createmode.xml
>  create mode 100644
> tests/qemuxml2xmloutdata/virtio-9p-createmode.x86_64-latest.xml
>
> --
> 2.25.1
>
>


Re: [libvirt PATCH 0/9] qemu: use g_new0 (glib chronicles)

2020-10-05 Thread Erik Skultety
On Mon, Oct 05, 2020 at 12:36:30PM +0200, Ján Tomko wrote:
> With the exception of qemu_migrate_cookie and qemu_slirp which
> should be dealt with by Peter's series.

[1-5, 6v2, 7-9]:
Reviewed-by: Erik Skultety 



Re: [libvirt PATCH 2/2] esx: switch esxUtil_ResolveHostname to return a new string

2020-10-05 Thread Laine Stump

On 10/5/20 7:41 AM, Pino Toscano wrote:

Change the interface of esxUtil_ResolveHostname() to return a newly
allocated string with the result address, instead of forcing the callers
to provide a buffer and its size. This way we can simply (auto)free the
string, and make the function stacks smaller.

Signed-off-by: Pino Toscano 



Reviewed-by: Laine Stump 



---
  src/esx/esx_driver.c | 20 +++-
  src/esx/esx_util.c   | 11 +++
  src/esx/esx_util.h   |  3 +--
  3 files changed, 15 insertions(+), 19 deletions(-)

diff --git a/src/esx/esx_driver.c b/src/esx/esx_driver.c
index e82e5ed835..a17bf58a51 100644
--- a/src/esx/esx_driver.c
+++ b/src/esx/esx_driver.c
@@ -602,7 +602,7 @@ esxConnectToHost(esxPrivate *priv,
   char **vCenterIPAddress)
  {
  int result = -1;
-char ipAddress[NI_MAXHOST] = "";
+g_autofree char *ipAddress = NULL;
  char *username = NULL;
  char *password = NULL;
  char *url = NULL;
@@ -615,7 +615,7 @@ esxConnectToHost(esxPrivate *priv,
  
  ESX_VI_CHECK_ARG_LIST(vCenterIPAddress);
  
-if (esxUtil_ResolveHostname(conn->uri->server, ipAddress, NI_MAXHOST) < 0)

+if (esxUtil_ResolveHostname(conn->uri->server, ) < 0)
  return -1;
  
  if (conn->uri->user) {

@@ -692,7 +692,7 @@ esxConnectToVCenter(esxPrivate *priv,
  const char *hostSystemIPAddress)
  {
  int result = -1;
-char ipAddress[NI_MAXHOST] = "";
+g_autofree char *ipAddress = NULL;
  char *username = NULL;
  char *password = NULL;
  char *url = NULL;
@@ -704,7 +704,7 @@ esxConnectToVCenter(esxPrivate *priv,
  return -1;
  }
  
-if (esxUtil_ResolveHostname(hostname, ipAddress, NI_MAXHOST) < 0)

+if (esxUtil_ResolveHostname(hostname, ) < 0)
  return -1;
  
  if (conn->uri->user) {

@@ -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 = NULL;
  
  virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR);
  
@@ -875,16 +875,10 @@ esxConnectOpen(virConnectPtr conn, virConnectAuthPtr auth,

  goto cleanup;
  }
  
-if (virStrcpyStatic(vCenterIPAddress,

-potentialVCenterIPAddress) < 0) {
-virReportError(VIR_ERR_INTERNAL_ERROR,
-   _("vCenter IP address %s too big for 
destination"),
-   potentialVCenterIPAddress);
-goto cleanup;
-}
+vCenterIPAddress = g_strdup(potentialVCenterIPAddress);
  } else {
  if (esxUtil_ResolveHostname(priv->parsedUri->vCenter,
-vCenterIPAddress, NI_MAXHOST) < 0) 
{
+) < 0) {
  goto cleanup;
  }
  
diff --git a/src/esx/esx_util.c b/src/esx/esx_util.c

index 555158f953..d9e7641d67 100644
--- a/src/esx/esx_util.c
+++ b/src/esx/esx_util.c
@@ -278,12 +278,12 @@ esxUtil_ParseDatastorePath(const char *datastorePath, 
char **datastoreName,
  
  
  int

-esxUtil_ResolveHostname(const char *hostname,
-char *ipAddress, size_t ipAddress_length)
+esxUtil_ResolveHostname(const char *hostname, char **ipAddress)
  {
  struct addrinfo hints;
  struct addrinfo *result = NULL;
  int errcode;
+g_autofree char *address = NULL;
  
  memset(, 0, sizeof(hints));
  
@@ -308,8 +308,9 @@ esxUtil_ResolveHostname(const char *hostname,

  return -1;
  }
  
-errcode = getnameinfo(result->ai_addr, result->ai_addrlen, ipAddress,

-  ipAddress_length, NULL, 0, NI_NUMERICHOST);
+address = g_new0(char, NI_MAXHOST);
+errcode = getnameinfo(result->ai_addr, result->ai_addrlen, address,
+  NI_MAXHOST, NULL, 0, NI_NUMERICHOST);
  freeaddrinfo(result);
  
  if (errcode != 0) {

@@ -319,6 +320,8 @@ esxUtil_ResolveHostname(const char *hostname,
  return -1;
  }
  
+*ipAddress = g_strdup(address);

+
  return 0;
  }
  
diff --git a/src/esx/esx_util.h b/src/esx/esx_util.h

index 97b6d82a2b..9bfbff1d42 100644
--- a/src/esx/esx_util.h
+++ b/src/esx/esx_util.h
@@ -55,8 +55,7 @@ int esxUtil_ParseVirtualMachineIDString(const char 
*id_string, int *id);
  int esxUtil_ParseDatastorePath(const char *datastorePath, char 
**datastoreName,
 char **directoryName, char 
**directoryAndFileName);
  
-int esxUtil_ResolveHostname(const char *hostname,

-char *ipAddress, size_t ipAddress_length);
+int esxUtil_ResolveHostname(const char *hostname, char **ipAddress);
  
  int esxUtil_ReformatUuid(const char *input, 

Re: [libvirt PATCH 1/2] esx: call freeaddrinfo earlier in esxUtil_ResolveHostname

2020-10-05 Thread Laine Stump

On 10/5/20 7:41 AM, Pino Toscano wrote:

Call freeaddrinfo() as soon as @result is not needed anymore, i.e. right
after getnameinfo(); this avoids calling freeaddrinfo() in two branches.

Signed-off-by: Pino Toscano 



Reviewed-by: Laine Stump 


---
  src/esx/esx_util.c | 4 +---
  1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/src/esx/esx_util.c b/src/esx/esx_util.c
index 9100873326..555158f953 100644
--- a/src/esx/esx_util.c
+++ b/src/esx/esx_util.c
@@ -310,17 +310,15 @@ esxUtil_ResolveHostname(const char *hostname,
  
  errcode = getnameinfo(result->ai_addr, result->ai_addrlen, ipAddress,

ipAddress_length, NULL, 0, NI_NUMERICHOST);
+freeaddrinfo(result);
  
  if (errcode != 0) {

  virReportError(VIR_ERR_INTERNAL_ERROR,
 _("Formatting IP address for host '%s' failed: %s"), 
hostname,
 gai_strerror(errcode));
-freeaddrinfo(result);
  return -1;
  }
  
-freeaddrinfo(result);

-
  return 0;
  }
  





[PATCH v2] docs/submitting-patches: add reference to DCO

2020-10-05 Thread Mauro Matteo Cascella
Signed-off-by: Mauro Matteo Cascella 
---
Rephrased sentence.

 docs/submitting-patches.rst | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/docs/submitting-patches.rst b/docs/submitting-patches.rst
index 17b072655d..7cb5c2e172 100644
--- a/docs/submitting-patches.rst
+++ b/docs/submitting-patches.rst
@@ -22,6 +22,9 @@ patch. However, the usual workflow of libvirt developer is:
   (hack, committing any changes along the way)
 
 More hints on compiling can be found `here `__.
+Make sure to express your agreement with the `Developer Certificate
+of Origin `__ by
+adding a "Signed-off-by" line to every commit message.
 When you want to post your patches:
 
 ::
-- 
2.26.2



Re: [PATCH] docs/submitting-patches: add reference to DCO

2020-10-05 Thread Mauro Matteo Cascella
On Fri, Oct 2, 2020 at 3:49 PM Peter Krempa  wrote:
>
> On Fri, Oct 02, 2020 at 15:32:48 +0200, Mauro Matteo Cascella wrote:
> > Signed-off-by: Mauro Matteo Cascella 
> > ---
> >  docs/submitting-patches.rst | 3 ++-
> >  1 file changed, 2 insertions(+), 1 deletion(-)
> >
> > diff --git a/docs/submitting-patches.rst b/docs/submitting-patches.rst
> > index 17b072655d..3ce8b347a0 100644
> > --- a/docs/submitting-patches.rst
> > +++ b/docs/submitting-patches.rst
> > @@ -22,7 +22,8 @@ patch. However, the usual workflow of libvirt developer 
> > is:
> >(hack, committing any changes along the way)
> >
> >  More hints on compiling can be found `here `__.
> > -When you want to post your patches:
> > +Make sure to `sign off `__
> > +your commit(s). When you want to post your patches:
>
> IMO this doesn't express the underlying certification of complience
> enough.
>
> I'd suggest something like:
>
> Make sure to express your agreement with the 'Developer Certificate of
> Origin'  by adding your 'sign-off'.
>

I didn't think too much about the form, just wanted to put a reference
to the DCO paragraph where this is already well explained. That being
said, I agree the sentence could be better rephrased. Will send a new
version of the patch, thanks for your suggestion.

--
Mauro Matteo Cascella, Red Hat Product Security
6F78 E20B 5935 928C F0A8  1A9D 4E55 23B8 BB34 10B0



Re: [python-libvirt] RFC:PEP 484 type annotation - how to continue

2020-10-05 Thread Daniel P . Berrangé
On Mon, Oct 05, 2020 at 09:12:26AM +0200, Philipp Hahn wrote:
> Hello,
> 
> currently my Merge Quests
>  is stuck
> because there are some open technical discussions:
> 
> 1. The Python binding consists of two layers:
>- libvirtmod* is the low-level C-like API, which mostly is just a
> thin wrapper around the C-library. It is generated from the API.xml files
>   - The high-level libvirt* modules, providing an object oriented API,
> which is also generated from the API.xml files.
>   In both cases there are many exceptions defines via
> libvirt*-override-api.xml or coded in generator.py:
>   - skip_impl: Generate Python code, but skip C implementation
>   - custom_function: Generate neither C nor Python code - hand crafted code
>   - skip_function: Generate neither C nor Python code - not used at all
>   - function_skip_python_impl: Generate C code, but skip python impl
> 
> Previously the functions listed in "skip_impl" were also duplicated in
> the "libvirt-*override-api.xml" files, which is somehow hard to
> maintain. With d19699e48ce9c17481f94b4dc0715e18e05d5adb I removed all
> those names from "skip_impl", which are also listed in the overrides and
> added code to add them back when "generator.py" is invoked.
> For this to work I had to change several "files" attributes to start
> with "python", which looks okay to me, but still would like to get verified.

The generator.py is such a big hack I don't think it matters too much.
The real important thing is that the resulting code is sane.

> 
> 2. The low-level library works mostly with bytes, but the high-level
> Python API uses nested Lists, Tuples and Dicts. To get most out of the
> Python static type annotations the input and output parameters should be
> modled in as much detail as possible.
> This requires to store those types somewhere. My current
> 46592e28124858ed863bceba65c3dafa2bbb02cd adds some often used types to
> generator.py and then references them from the overrides.xml:
> 
> > +'PyListSecret': ('', 'List["virSecret"]', '', ''),
> > +'PyDictAny': ('', 'Dict[str, Any]', '', ''),
> 
> > +  
> 
> This still is very painful as there are many "used-once" types, which
> still must be declared and used in two places.
> So far the "return" type was used for the "C" type and currently I
> mis-use it for referencing it for my Python types. This doesn't look
> right, so I would prefer adding a new attribute which can be used to
> override the Python type.
> This also would probably nicely fit with functions like
> "virDomainOpenConsole", when "dev_name" is optional and can be "None",
> which the current type hint requires a "string".
> 
> Is extending the libvirt*-override-api.xml files okay or must this be
> coordinated with the other parts of the project?

These files follow the same schema as the main api.xml files shipped by
libvirt itself. That is just a matter of convenience though - the
overrides are only used in the libvirt-python generator.py, so there
is no reason why we can't record extra information in them.


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: [PATCH] rpm: Enable Xen support on AArch64

2020-10-05 Thread Daniel P . Berrangé
On Mon, Oct 05, 2020 at 12:33:23PM +0200, Ján Tomko wrote:
> On a Sunday in 2020, Neal Gompa wrote:
> > Starting with Linux 5.9, Xen Dom0 works on commonly available
> > AArch64 devices, such as the Raspberry Pi 4.
> > 
> 
> My Fedora 32 does not even have 5.9 yet, does it make sense to allow it
> regardless of the version?

New kernels get pushed to all Fedora stable releases, so I'd expect it
to appear in F32 in time.

The "xen" RPM in Fedora as aarch64 enabled in F32 already, so libxl
is available for libvirt to build against.

> 
> Jano
> 
> > 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
> > 



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 :|



[libvirt PATCH] rpm: include aarch64 & riscv64 in systemtap 64-bit arch tapset rename

2020-10-05 Thread Daniel P . Berrangé
Signed-off-by: Daniel P. Berrangé 
---
 libvirt.spec.in | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libvirt.spec.in b/libvirt.spec.in
index 682d43c290..d13aae5cf5 100644
--- a/libvirt.spec.in
+++ b/libvirt.spec.in
@@ -1261,7 +1261,7 @@ rm -f 
$RPM_BUILD_ROOT%{_datadir}/augeas/lenses/tests/test_libvirtd_libxl.aug
 # Copied into libvirt-docs subpackage eventually
 mv $RPM_BUILD_ROOT%{_datadir}/doc/libvirt libvirt-docs
 
-%ifarch %{power64} s390x x86_64
+%ifarch %{power64} s390x x86_64 aarch64 riscv64
 mv $RPM_BUILD_ROOT%{_datadir}/systemtap/tapset/libvirt_probes.stp \
$RPM_BUILD_ROOT%{_datadir}/systemtap/tapset/libvirt_probes-64.stp
 
-- 
2.26.2



Re: [libvirt PATCH] rpm: drop ia64, sparc64 and alpha architectures

2020-10-05 Thread Andrea Bolognani
On Mon, 2020-10-05 at 13:17 +0100, Daniel P. Berrangé wrote:
> +++ b/libvirt.spec.in
> -%ifarch %{power64} s390x x86_64 ia64 alpha sparc64
> +%ifarch %{power64} s390x x86_64
>  mv $RPM_BUILD_ROOT%{_datadir}/systemtap/tapset/libvirt_probes.stp \
> $RPM_BUILD_ROOT%{_datadir}/systemtap/tapset/libvirt_probes-64.stp

I'm pretty sure aarch64 has systemtap support, so we might want to
reconsider this architecture list.

Anyway that's work for another patch, so

  Reviewed-by: Andrea Bolognani 

for this one.

-- 
Andrea Bolognani / Red Hat / Virtualization



Re: [PATCH v2 7/7] virbitmaptest: Remove unnecessary error/cleanup labels

2020-10-05 Thread Ján Tomko

On a Monday in 2020, Peter Krempa wrote:

Signed-off-by: Peter Krempa 
---
tests/virbitmaptest.c | 270 +-
1 file changed, 107 insertions(+), 163 deletions(-)



Reviewed-by: Ján Tomko 

Jano


signature.asc
Description: PGP signature


Re: [PATCH v2 6/7] virbitmaptest: Use g_auto(free) for cleanup

2020-10-05 Thread Ján Tomko

On a Monday in 2020, Peter Krempa wrote:

Signed-off-by: Peter Krempa 
---
tests/virbitmaptest.c | 79 ++-
1 file changed, 25 insertions(+), 54 deletions(-)



Reviewed-by: Ján Tomko 

Jano


signature.asc
Description: PGP signature


Re: [PATCH v2 5/7] virbitmaptest: Refactor checks in 'test6'

2020-10-05 Thread Ján Tomko

On a Monday in 2020, Peter Krempa wrote:

The 'checkBitmap' helper uses 'virBitmapFormat' internally and also
reports better errors. Use it instead of the open-coded checks.

Signed-off-by: Peter Krempa 
---
tests/virbitmaptest.c | 44 ++-
1 file changed, 6 insertions(+), 38 deletions(-)



Reviewed-by: Ján Tomko 

Jano


signature.asc
Description: PGP signature


Re: [PATCH v2 4/7] virbitmaptest: Turn 'TEST_MAP' macro into a helper function

2020-10-05 Thread Ján Tomko

On a Monday in 2020, Peter Krempa wrote:

The function will also be reusable in other places of the code by making
the size check optional. For now only test12* is refactored since it
used TEST_MAP directly.

Signed-off-by: Peter Krempa 
---
tests/virbitmaptest.c | 63 +--
1 file changed, 37 insertions(+), 26 deletions(-)



Reviewed-by: Ján Tomko 

Jano


signature.asc
Description: PGP signature


Re: [PATCH v2 3/7] virbitmaptest: Use separate output strings in 'test5'

2020-10-05 Thread Ján Tomko

On a Monday in 2020, Peter Krempa wrote:

The test validates two outputs. Don't reuse 'str' for both.

Signed-off-by: Peter Krempa 
---
tests/virbitmaptest.c | 13 ++---
1 file changed, 6 insertions(+), 7 deletions(-)



Reviewed-by: Ján Tomko 

Jano


signature.asc
Description: PGP signature


Re: [PATCH v2 1/7] virbitmaptest: Split up test12

2020-10-05 Thread Ján Tomko

On a Monday in 2020, Peter Krempa wrote:

'test12' was testing two distinct operations on two instances of a
bitmap. Split it up into 'test12a' and 'test12b' so that the 'bitmap'


'map'

or just drop the quotes.


variable is not reused.

Signed-off-by: Peter Krempa 
---
tests/virbitmaptest.c | 19 +--
1 file changed, 17 insertions(+), 2 deletions(-)



Reviewed-by: Ján Tomko 

Jano


signature.asc
Description: PGP signature


Re: [PATCH v2 2/7] virbitmaptest: Split up test4

2020-10-05 Thread Ján Tomko

On a Monday in 2020, Peter Krempa wrote:

'test4' was testing three distinct operations on separate instances of a
bitmap. Split it up into 'test4a', 'test4b' and 'test4c' so that the
'bitmap' variable is not reused.

Signed-off-by: Peter Krempa 
---
tests/virbitmaptest.c | 64 +++
1 file changed, 46 insertions(+), 18 deletions(-)



Reviewed-by: Ján Tomko 

Jano


signature.asc
Description: PGP signature


  1   2   >