[PATCH 3/4] virSecretLoadAllConfigs: Use g_autofree for @path

2023-10-16 Thread Michal Privoznik
When loading virSecret configs, the @path variable holds path to
individual config files. In each iteration it is freed explicitly
using VIR_FREE(). Switch it to g_autofree and remove those
explicit calls.

Signed-off-by: Michal Privoznik 
---
 src/conf/virsecretobj.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/src/conf/virsecretobj.c b/src/conf/virsecretobj.c
index e0393e6cec..2585b2c972 100644
--- a/src/conf/virsecretobj.c
+++ b/src/conf/virsecretobj.c
@@ -902,7 +902,7 @@ virSecretLoadAllConfigs(virSecretObjList *secrets,
 /* Ignore errors reported by readdir or other calls within the
  * loop (if any).  It's better to keep the secrets we managed to find. */
 while (virDirRead(dir, , NULL) > 0) {
-char *path;
+g_autofree char *path = NULL;
 virSecretObj *obj;
 
 if (!virStringHasSuffix(de->d_name, ".xml"))
@@ -914,11 +914,9 @@ virSecretLoadAllConfigs(virSecretObjList *secrets,
 if (!(obj = virSecretLoad(secrets, de->d_name, path, configDir))) {
 VIR_ERROR(_("Error reading secret: %1$s"),
   virGetLastErrorMessage());
-VIR_FREE(path);
 continue;
 }
 
-VIR_FREE(path);
 virSecretObjEndAPI();
 }
 
-- 
2.41.0



[PATCH 4/4] virSecretLoad: Simplify cleanup path

2023-10-16 Thread Michal Privoznik
When loading a secret value fails, the control jumps over to the
'cleanup' label where explicit call to virSecretDefFree()
happens. This is unnecessary as the corresponding variable can be
declared with g_autoptr() after which all error paths can just
return NULL instantly.

Signed-off-by: Michal Privoznik 
---
 src/conf/virsecretobj.c | 11 +--
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/src/conf/virsecretobj.c b/src/conf/virsecretobj.c
index 2585b2c972..455798d414 100644
--- a/src/conf/virsecretobj.c
+++ b/src/conf/virsecretobj.c
@@ -865,25 +865,24 @@ virSecretLoad(virSecretObjList *secrets,
   const char *path,
   const char *configDir)
 {
-virSecretDef *def = NULL;
+g_autoptr(virSecretDef) def = NULL;
 virSecretObj *obj = NULL;
 
 if (!(def = virSecretDefParse(NULL, path, 0)))
-goto cleanup;
+return NULL;
 
 if (virSecretLoadValidateUUID(def, file) < 0)
-goto cleanup;
+return NULL;
 
 if (!(obj = virSecretObjListAdd(secrets, , configDir, NULL)))
-goto cleanup;
+return NULL;
 
 if (virSecretLoadValue(obj) < 0) {
 virSecretObjListRemove(secrets, obj);
 g_clear_pointer(, virObjectUnref);
+return NULL;
 }
 
- cleanup:
-virSecretDefFree(def);
 return obj;
 }
 
-- 
2.41.0



[PATCH 2/4] virfile: Drop virBuildPathInternal()

2023-10-16 Thread Michal Privoznik
After previous cleanup the virBuildPathInternal() function is no
longer used. Drop it.

Signed-off-by: Michal Privoznik 
---
 src/libvirt_private.syms |  1 -
 src/util/virfile.c   | 22 --
 src/util/virfile.h   |  5 -
 3 files changed, 28 deletions(-)

diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 4e475d5b1a..553b01b8c0 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -2280,7 +2280,6 @@ virFDStreamSetInternalCloseCb;
 saferead;
 safewrite;
 safezero;
-virBuildPathInternal;
 virCloseFrom;
 virCloseRange;
 virCloseRangeInit;
diff --git a/src/util/virfile.c b/src/util/virfile.c
index bd36a9a31a..54708652fb 100644
--- a/src/util/virfile.c
+++ b/src/util/virfile.c
@@ -1490,28 +1490,6 @@ virFileFindMountPoint(const char *type G_GNUC_UNUSED)
 
 #endif /* defined WITH_MNTENT_H && defined WITH_GETMNTENT_R */
 
-void
-virBuildPathInternal(char **path, ...)
-{
-char *path_component = NULL;
-g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
-va_list ap;
-
-va_start(ap, path);
-
-path_component = va_arg(ap, char *);
-virBufferAdd(, path_component, -1);
-
-while ((path_component = va_arg(ap, char *)) != NULL) {
-virBufferAddChar(, '/');
-virBufferAdd(, path_component, -1);
-}
-
-va_end(ap);
-
-*path = virBufferContentAndReset();
-}
-
 /* Read no more than the specified maximum number of bytes. */
 static char *
 saferead_lim(int fd, size_t max_len, size_t *length)
diff --git a/src/util/virfile.h b/src/util/virfile.h
index adc032ba33..286401e0f5 100644
--- a/src/util/virfile.h
+++ b/src/util/virfile.h
@@ -307,11 +307,6 @@ int virFileOpenTty(int *ttymaster,
 
 char *virFileFindMountPoint(const char *type);
 
-/* NB: this should be combined with virFileBuildPath */
-#define virBuildPath(path, ...) \
-virBuildPathInternal(path, __VA_ARGS__, NULL)
-void virBuildPathInternal(char **path, ...) G_GNUC_NULL_TERMINATED;
-
 typedef struct _virHugeTLBFS virHugeTLBFS;
 struct _virHugeTLBFS {
 char *mnt_dir;  /* Where the FS is mount to */
-- 
2.41.0



[PATCH 1/4] lib: Replace virBuildPath() with g_build_filename()

2023-10-16 Thread Michal Privoznik
Our virBuildPath() constructs a path from given arguments.
Exactly like g_build_filename(), except the latter is more
generic as it uses backslashes on Windows. Therefore, replace the
former with the latter.

Signed-off-by: Michal Privoznik 
---
 docs/kbase/internals/command.rst | 2 +-
 src/util/virfcp.c| 2 +-
 src/util/virhook.c   | 4 ++--
 src/util/virpci.c| 4 ++--
 4 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/docs/kbase/internals/command.rst b/docs/kbase/internals/command.rst
index 738fb5930a..d958c9d16a 100644
--- a/docs/kbase/internals/command.rst
+++ b/docs/kbase/internals/command.rst
@@ -444,7 +444,7 @@ src/util/hooks.c
  g_autofree char *path = NULL;
  g_autoptr(virCommand) cmd = NULL;
 
- virBuildPath(, LIBVIRT_HOOK_DIR, drvstr);
+ path = g_build_filename(LIBVIRT_HOOK_DIR, drvstr);
 
  cmd = virCommandNew(path);
 
diff --git a/src/util/virfcp.c b/src/util/virfcp.c
index bb62fa9025..052a6c99e1 100644
--- a/src/util/virfcp.c
+++ b/src/util/virfcp.c
@@ -38,7 +38,7 @@ virFCIsCapableRport(const char *rport)
 {
 g_autofree char *path = NULL;
 
-virBuildPath(, SYSFS_FC_RPORT_PATH, rport);
+path = g_build_filename(SYSFS_FC_RPORT_PATH, rport, NULL);
 
 return virFileExists(path);
 }
diff --git a/src/util/virhook.c b/src/util/virhook.c
index 50e178723f..d012bb1825 100644
--- a/src/util/virhook.c
+++ b/src/util/virhook.c
@@ -153,7 +153,7 @@ virHookCheck(int no, const char *driver)
 return -1;
 }
 
-virBuildPath(, LIBVIRT_HOOK_DIR, driver);
+path = g_build_filename(LIBVIRT_HOOK_DIR, driver, NULL);
 
 if (!virFileExists(path)) {
 VIR_DEBUG("No hook script %s", path);
@@ -398,7 +398,7 @@ virHookCall(int driver,
 if (extra == NULL)
 extra = "-";
 
-virBuildPath(, LIBVIRT_HOOK_DIR, drvstr);
+path = g_build_filename(LIBVIRT_HOOK_DIR, drvstr, NULL);
 
 script_ret = 1;
 
diff --git a/src/util/virpci.c b/src/util/virpci.c
index 08b82708b1..baacde4c14 100644
--- a/src/util/virpci.c
+++ b/src/util/virpci.c
@@ -2396,7 +2396,7 @@ virPCIGetPhysicalFunction(const char *vf_sysfs_path,
 
 *pf = NULL;
 
-virBuildPath(_link, vf_sysfs_path, "physfn");
+device_link = g_build_filename(vf_sysfs_path, "physfn", NULL);
 
 if ((*pf = virPCIGetDeviceAddressFromSysfsLink(device_link))) {
 VIR_DEBUG("PF for VF device '%s': " VIR_PCI_DEVICE_ADDRESS_FMT,
@@ -2580,7 +2580,7 @@ virPCIGetNetName(const char *device_link_sysfs_path,
 return -1;
 }
 
-virBuildPath(_sysfs_net_path, device_link_sysfs_path, "net");
+pcidev_sysfs_net_path = g_build_filename(device_link_sysfs_path, "net", 
NULL);
 
 if (virDirOpenQuiet(, pcidev_sysfs_net_path) < 0) {
 /* this *isn't* an error - caller needs to check for netname == NULL */
-- 
2.41.0



[PATCH 0/4] Misc cleanups

2023-10-16 Thread Michal Privoznik
*** BLURB HERE ***

Michal Prívozník (4):
  lib: Replace virBuildPath() with g_build_filename()
  virfile: Drop virBuildPathInternal()
  virSecretLoadAllConfigs: Use g_autofree for @path
  virSecretLoad: Simplify cleanup path

 docs/kbase/internals/command.rst |  2 +-
 src/conf/virsecretobj.c  | 15 ++-
 src/libvirt_private.syms |  1 -
 src/util/virfcp.c|  2 +-
 src/util/virfile.c   | 22 --
 src/util/virfile.h   |  5 -
 src/util/virhook.c   |  4 ++--
 src/util/virpci.c|  4 ++--
 8 files changed, 12 insertions(+), 43 deletions(-)

-- 
2.41.0



[PATCH] virDomainMemoryDefValidate: Skip the same device on validation on memory device update

2023-10-16 Thread Michal Privoznik
In my recent commit of v9.8.0-rc1~7 I've introduced validation
wrt other memory devices. And mostly works, except when doing
memory device update ('virsh update-memory-device') because then
@mem is just parsed  device XML and thus its pointer is
not in the vm->def->mem, yet. Thus my algorithm which skips over
the same entry fails. Fortunately, we require full device XML on
device update and thus we can use device address and aliases to
detect duplicity.

Fixes: 3fd64fb0e236fc80ffa2cc977c0d471f11fc39bf
Signed-off-by: Michal Privoznik 
---
 src/conf/domain_validate.c | 15 +++
 1 file changed, 15 insertions(+)

diff --git a/src/conf/domain_validate.c b/src/conf/domain_validate.c
index 6962fe76bf..bc3d00f89c 100644
--- a/src/conf/domain_validate.c
+++ b/src/conf/domain_validate.c
@@ -2387,6 +2387,21 @@ virDomainMemoryDefValidate(const virDomainMemoryDef *mem,
 if (other == mem)
 continue;
 
+/* In case we're updating an existing memory device (e.g. virtio-mem),
+ * then pointers will be different. But addresses and aliases are the
+ * same. However, STREQ_NULLABLE() returns true if both strings are
+ * NULL which is not what we want. */
+if (virDomainDeviceInfoAddressIsEqual(>info,
+  >info)) {
+continue;
+}
+
+if (mem->info.alias &&
+STREQ_NULLABLE(other->info.alias,
+   mem->info.alias)) {
+continue;
+}
+
 switch (other->model) {
 case VIR_DOMAIN_MEMORY_MODEL_NONE:
 case VIR_DOMAIN_MEMORY_MODEL_DIMM:
-- 
2.41.0



[PATCH] NEWS: Document my contributions for upcoming release

2023-09-29 Thread Michal Privoznik
Signed-off-by: Michal Privoznik 
---
 NEWS.rst | 12 
 1 file changed, 12 insertions(+)

diff --git a/NEWS.rst b/NEWS.rst
index c17a1d002d..6f46e86ba8 100644
--- a/NEWS.rst
+++ b/NEWS.rst
@@ -43,8 +43,20 @@ v9.8.0 (unreleased)
 stability of qemu. Therefore, when available, libvirt will use nbdkit as a
 backend for these network disks and export an NBD disk to qemu.
 
+  * virnetdevopenvswitch: Propagate OVS error messages
+
+When configuring OVS interfaces/bridges libvirt used to report its own
+error messages instead of passing (more accurate) error messages from
+`ovs-vsctl`. This is now changed.
+
 * **Bug fixes**
 
+  * Various virtio-mem/virtio-pmem fixes
+
+It was discovered that libvirt did not validate some values wrt virtio-mem
+and virtio-pmem memory devices, e.g. overlapping memory addresses or
+alignment.
+
 
 v9.7.0 (2023-09-01)
 ===
-- 
2.41.0



[PATCH] NEWS: Fix placement of network metadata entry

2023-09-29 Thread Michal Privoznik
The network metadata support is a new feature in the upcoming
release, not a removed one. Place it accordingly.

Signed-off-by: Michal Privoznik 
---
 NEWS.rst | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/NEWS.rst b/NEWS.rst
index 768e6fc326..c17a1d002d 100644
--- a/NEWS.rst
+++ b/NEWS.rst
@@ -15,14 +15,14 @@ v9.8.0 (unreleased)
 
 * **Removed features**
 
+* **New features**
+
   * network: New metadata change event
 
 The network object now has a new event ID 
``VIR_NETWORK_EVENT_ID_METADATA_CHANGE``
 that can be used to get notifications upon changes in any of ,
  or .
 
-* **New features**
-
   * qemu: Add support for vDPA block devices
 
 With a new enough version of qemu, libvirt will allow you to assign vDPA 
block
-- 
2.41.0



[PATCH 0/3] A couple of virtio-mem/virtio-pmem address improvements

2023-09-22 Thread Michal Privoznik
*** BLURB HERE ***

Michal Prívozník (3):
  domain_validate: Validate VIRTIO_PMEM address alignment
  virDomainMemoryDefValidate: Fix VIRTIO_MEM alignment check
  virDomainMemoryDefValidate: Check for overlapping memory devices

 src/conf/domain_validate.c| 59 ++-
 ...rtio-mem-overlap-address.x86_64-latest.err |  1 +
 ...ory-hotplug-virtio-mem-overlap-address.xml | 50 
 tests/qemuxml2argvtest.c  |  1 +
 4 files changed, 110 insertions(+), 1 deletion(-)
 create mode 100644 
tests/qemuxml2argvdata/memory-hotplug-virtio-mem-overlap-address.x86_64-latest.err
 create mode 100644 
tests/qemuxml2argvdata/memory-hotplug-virtio-mem-overlap-address.xml

-- 
2.41.0



[PATCH 1/3] domain_validate: Validate VIRTIO_PMEM address alignment

2023-09-22 Thread Michal Privoznik
QEMU mandates the VIRTIO_PMEM address is aligned to a pagesize.
This is a very reasonable requirement. So much so, that it
deserves to be in hypervisor agnostic validation code
(virDomainMemoryDefValidate()). Not that any other hypervisor
would support VIRTIO_PMEM yet. But even if they did, this would
surely be still valid.

Signed-off-by: Michal Privoznik 
---
 src/conf/domain_validate.c | 9 +
 1 file changed, 9 insertions(+)

diff --git a/src/conf/domain_validate.c b/src/conf/domain_validate.c
index ac32fa1477..e423383e22 100644
--- a/src/conf/domain_validate.c
+++ b/src/conf/domain_validate.c
@@ -2221,6 +2221,7 @@ static int
 virDomainMemoryDefValidate(const virDomainMemoryDef *mem,
const virDomainDef *def)
 {
+const long pagesize = virGetSystemPageSize();
 unsigned long long thpSize;
 
 /* Guest NUMA nodes are continuous and indexed from zero. */
@@ -2295,6 +2296,14 @@ virDomainMemoryDefValidate(const virDomainMemoryDef *mem,
_("virtio-pmem does not support NUMA nodes"));
 return -1;
 }
+
+if (pagesize > 0 &&
+mem->target.virtio_pmem.address % pagesize != 0) {
+virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+   _("memory address must be aligned to %1$ld bytes"),
+   pagesize);
+return -1;
+}
 break;
 
 case VIR_DOMAIN_MEMORY_MODEL_VIRTIO_MEM:
-- 
2.41.0



[PATCH 3/3] virDomainMemoryDefValidate: Check for overlapping memory devices

2023-09-22 Thread Michal Privoznik
As of v9.4.0-rc2~5 it is possible to specify guest address where
a virtio-mem/virtio-pmem memory device is mapped to. What that
commit forgot to introduce was a check for overlaps.

And yes, this is technically an O(n^2) algorithm, as
virDomainMemoryDefValidate() is called over each memory device
and after this, virDomainMemoryDefValidate() also iterates over
each memory device. But given there's usually only a handful of
such devices, and this runs only when parsing domain XML I guess
code readability wins over some less obvious solution.

Resolves: https://issues.redhat.com/browse/RHEL-4452
Signed-off-by: Michal Privoznik 
---
 src/conf/domain_validate.c| 47 +
 ...rtio-mem-overlap-address.x86_64-latest.err |  1 +
 ...ory-hotplug-virtio-mem-overlap-address.xml | 50 +++
 tests/qemuxml2argvtest.c  |  1 +
 4 files changed, 99 insertions(+)
 create mode 100644 
tests/qemuxml2argvdata/memory-hotplug-virtio-mem-overlap-address.x86_64-latest.err
 create mode 100644 
tests/qemuxml2argvdata/memory-hotplug-virtio-mem-overlap-address.xml

diff --git a/src/conf/domain_validate.c b/src/conf/domain_validate.c
index d14559cd73..6962fe76bf 100644
--- a/src/conf/domain_validate.c
+++ b/src/conf/domain_validate.c
@@ -2223,6 +2223,9 @@ virDomainMemoryDefValidate(const virDomainMemoryDef *mem,
 {
 const long pagesize = virGetSystemPageSize();
 unsigned long long thpSize;
+unsigned long long thisStart = 0;
+unsigned long long thisEnd = 0;
+size_t i;
 
 /* Guest NUMA nodes are continuous and indexed from zero. */
 if (mem->targetNode != -1) {
@@ -2304,6 +2307,7 @@ virDomainMemoryDefValidate(const virDomainMemoryDef *mem,
pagesize);
 return -1;
 }
+thisStart = mem->target.virtio_pmem.address;
 break;
 
 case VIR_DOMAIN_MEMORY_MODEL_VIRTIO_MEM:
@@ -2347,6 +2351,7 @@ virDomainMemoryDefValidate(const virDomainMemoryDef *mem,
_("memory device address must be aligned to 
blocksize"));
 return -1;
 }
+thisStart = mem->target.virtio_mem.address;
 break;
 
 case VIR_DOMAIN_MEMORY_MODEL_DIMM:
@@ -2368,6 +2373,48 @@ virDomainMemoryDefValidate(const virDomainMemoryDef *mem,
 return -1;
 }
 
+if (thisStart == 0) {
+return 0;
+}
+
+/* thisStart and thisEnd are in bytes, mem->size in kibibytes */
+thisEnd = thisStart + mem->size * 1024;
+
+for (i = 0; i < def->nmems; i++) {
+const virDomainMemoryDef *other = def->mems[i];
+unsigned long long otherStart = 0;
+
+if (other == mem)
+continue;
+
+switch (other->model) {
+case VIR_DOMAIN_MEMORY_MODEL_NONE:
+case VIR_DOMAIN_MEMORY_MODEL_DIMM:
+case VIR_DOMAIN_MEMORY_MODEL_NVDIMM:
+case VIR_DOMAIN_MEMORY_MODEL_SGX_EPC:
+case VIR_DOMAIN_MEMORY_MODEL_LAST:
+continue;
+break;
+
+case VIR_DOMAIN_MEMORY_MODEL_VIRTIO_PMEM:
+otherStart = other->target.virtio_pmem.address;
+break;
+case VIR_DOMAIN_MEMORY_MODEL_VIRTIO_MEM:
+otherStart = other->target.virtio_mem.address;
+break;
+}
+
+if (otherStart == 0)
+continue;
+
+if (thisStart <= otherStart && thisEnd > otherStart) {
+virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+   _("memory device address [0x%1$llx:0x%2$llx] 
overlaps with other memory device (0x%3$llx)"),
+   thisStart, thisEnd, otherStart);
+return -1;
+}
+}
+
 return 0;
 }
 
diff --git 
a/tests/qemuxml2argvdata/memory-hotplug-virtio-mem-overlap-address.x86_64-latest.err
 
b/tests/qemuxml2argvdata/memory-hotplug-virtio-mem-overlap-address.x86_64-latest.err
new file mode 100644
index 00..36d5b8a6e6
--- /dev/null
+++ 
b/tests/qemuxml2argvdata/memory-hotplug-virtio-mem-overlap-address.x86_64-latest.err
@@ -0,0 +1 @@
+unsupported configuration: memory device address [0x14000:0x18000] 
overlaps with other memory device (0x17000)
diff --git 
a/tests/qemuxml2argvdata/memory-hotplug-virtio-mem-overlap-address.xml 
b/tests/qemuxml2argvdata/memory-hotplug-virtio-mem-overlap-address.xml
new file mode 100644
index 00..65999ccd99
--- /dev/null
+++ b/tests/qemuxml2argvdata/memory-hotplug-virtio-mem-overlap-address.xml
@@ -0,0 +1,50 @@
+
+  QEMUGuest1
+  c7a5fdbd-edaf-9455-926a-d65c16db1809
+  1099511627776
+  8388608
+  8388608
+  2
+  
+hvm
+
+  
+  
+qemu64
+
+
+  
+
+  
+  
+  destroy
+  restart
+  destroy
+  
+/usr/bin/qemu-system-x86_64
+
+  
+1048576
+0
+2048
+524288
+
+  
+  
+
+
+  
+1-3
+2048
+  

[PATCH 2/3] virDomainMemoryDefValidate: Fix VIRTIO_MEM alignment check

2023-09-22 Thread Michal Privoznik
Inside of virDomainMemoryDefValidate() there's a check that
address where a virtio-mem memory device is mapped to is a
multiple of its block size. But this check is off by a couple of
bits, because the memory address is in bytes while the block size
is in kibibytes. Therefore, when checking whether address is a
multiple of the block size, the latter has to be multiplied by a
factor of 1024.

Signed-off-by: Michal Privoznik 
---
 src/conf/domain_validate.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/conf/domain_validate.c b/src/conf/domain_validate.c
index e423383e22..d14559cd73 100644
--- a/src/conf/domain_validate.c
+++ b/src/conf/domain_validate.c
@@ -2341,7 +2341,8 @@ virDomainMemoryDefValidate(const virDomainMemoryDef *mem,
 return -1;
 }
 
-if (mem->target.virtio_mem.address % mem->target.virtio_mem.blocksize 
!= 0) {
+/* blocksize is stored in KiB while address is in bytes */
+if (mem->target.virtio_mem.address % (mem->target.virtio_mem.blocksize 
* 1024) != 0) {
 virReportError(VIR_ERR_XML_DETAIL, "%s",
_("memory device address must be aligned to 
blocksize"));
 return -1;
-- 
2.41.0



[PATCH] test_driver: Implement virConnectGetDomainCapabilities()

2023-09-20 Thread Michal Privoznik
Our test driver lacks implementation for
virConnectGetDomainCapabilities(). Provide one, though a trivial
one. Mostly so that something else than VIR_ERR_NO_SUPPORT error
is returned.

Signed-off-by: Michal Privoznik 
---
 src/test/test_driver.c | 36 
 1 file changed, 36 insertions(+)

diff --git a/src/test/test_driver.c b/src/test/test_driver.c
index c1d4d71b78..a8705a8da2 100644
--- a/src/test/test_driver.c
+++ b/src/test/test_driver.c
@@ -1,6 +1,41 @@ testNetworkSetMetadata(virNetworkPtr net,
 return ret;
 }
 
+static char *
+testConnectGetDomainCapabilities(virConnectPtr conn G_GNUC_UNUSED,
+ const char *emulatorbin,
+ const char *arch_str,
+ const char *machine,
+ const char *virttype_str,
+ unsigned int flags)
+{
+g_autoptr(virDomainCaps) domCaps = NULL;
+virArch arch = VIR_ARCH_NONE;
+int virttype = VIR_DOMAIN_VIRT_NONE;
+
+virCheckFlags(0, NULL);
+
+if (arch_str &&
+(arch = virArchFromString(arch_str)) == VIR_ARCH_NONE) {
+virReportError(VIR_ERR_INVALID_ARG,
+   _("unknown architecture: %1$s"), arch_str);
+return NULL;
+}
+
+if (virttype_str &&
+(virttype = virDomainVirtTypeFromString(virttype_str)) < 0) {
+virReportError(VIR_ERR_INVALID_ARG,
+   _("unknown virttype: %1$s"), virttype_str);
+return NULL;
+}
+
+if (!(domCaps = virDomainCapsNew(emulatorbin, machine, arch, virttype)))
+return NULL;
+
+return virDomainCapsFormat(domCaps);
+}
+
+
 /*
  * Test driver
  */
@@ -10167,6 +10202,7 @@ static virHypervisorDriver testHypervisorDriver = {
 .domainCheckpointGetParent = testDomainCheckpointGetParent, /* 5.6.0 */
 .domainCheckpointDelete = testDomainCheckpointDelete, /* 5.6.0 */
 .domainGetMessages = testDomainGetMessages, /* 7.6.0 */
+.connectGetDomainCapabilities = testConnectGetDomainCapabilities, /* 9.8.0 
*/
 };
 
 static virNetworkDriver testNetworkDriver = {
-- 
2.41.0



[PATCH 4/4] virerror: Make virReportEnumRangeError() check for type mismatch

2023-09-19 Thread Michal Privoznik
As can be seen from previous commits, it's fairly easy to pass a
different type to virReportEnumRangeError() than the actual
variable is of. So far, we have a sizeof() hack to check if some
nonsensical types are not passed, e.g. it catches cases where a
function name is passed instead of an enum. Extend the hack to
check whether proper enum was passed.

Signed-off-by: Michal Privoznik 
---
 src/util/virerror.h | 14 --
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/src/util/virerror.h b/src/util/virerror.h
index ee85247433..d4b2679a09 100644
--- a/src/util/virerror.h
+++ b/src/util/virerror.h
@@ -161,16 +161,18 @@ void virReportSystemErrorFull(int domcode,
 #define virReportRestrictedError(...) \
 virReportErrorHelper(VIR_FROM_THIS, VIR_ERR_OPERATION_DENIED, \
  __FILE__, __FUNCTION__, __LINE__, __VA_ARGS__)
-/* The sizeof(...) comparison here is a hack to catch typos
- * in the name of the enum by triggering a compile error, as well
- * as detecting if you passed a typename that refers to a function
- * or struct type, instead of an enum. It should get optimized away
- * since sizeof() is known at compile time  */
+/* The ternary operator here is a hack to catch typos in the name of
+ * the enum and mismatching enum by triggering a compile error, as
+ * well as detecting if you passed a typename that refers to a
+ * function or struct type, instead of an enum. It should get
+ * optimized away since the value is constant and thus is known at
+ * compile time.  */
 #define virReportEnumRangeError(typname, value) \
 virReportErrorHelper(VIR_FROM_THIS, VIR_ERR_INTERNAL_ERROR, \
  __FILE__, __FUNCTION__, __LINE__, \
  "Unexpected enum value %d for %s", \
- value, sizeof((typname)1) != 0 ? #typname : #typname);
+ value, \
+ (__typeof__(value))1 == (typname)1 && 
sizeof((typname)1) != 0 ? #typname : #typname)
 
 #define virReportError(code, ...) \
 virReportErrorHelper(VIR_FROM_THIS, code, __FILE__, \
-- 
2.41.0



[PATCH 1/4] virnetdevvportprofile: Turn virNetDevVPortProfileLinkOp enum into a proper typedef

2023-09-19 Thread Michal Privoznik
This allows us to declare variables without using 'enum
virNetDev' and will become more useful in the near future
(when virReportEnumRangeError() is fixed).

Signed-off-by: Michal Privoznik 
---
 src/util/virnetdevvportprofile.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/util/virnetdevvportprofile.c b/src/util/virnetdevvportprofile.c
index 33bcd350c4..6d5bfbe870 100644
--- a/src/util/virnetdevvportprofile.c
+++ b/src/util/virnetdevvportprofile.c
@@ -69,12 +69,12 @@ VIR_LOG_INIT("util.netdevvportprofile");
 # define LLDPAD_PID_FILE  "/var/run/lldpad.pid"
 
 
-enum virNetDevVPortProfileLinkOp {
+typedef enum {
 VIR_NETDEV_VPORT_PROFILE_LINK_OP_ASSOCIATE = 0x1,
 VIR_NETDEV_VPORT_PROFILE_LINK_OP_DISASSOCIATE = 0x2,
 VIR_NETDEV_VPORT_PROFILE_LINK_OP_PREASSOCIATE = 0x3,
 VIR_NETDEV_VPORT_PROFILE_LINK_OP_PREASSOCIATE_RR = 0x4,
-};
+} virNetDevVPortProfileLinkOp;
 
 #endif
 
@@ -1024,7 +1024,7 @@ virNetDevVPortProfileOp8021Qbg(const char *ifname,
const virMacAddr *macaddr,
int vf,
const virNetDevVPortProfile *virtPort,
-   enum virNetDevVPortProfileLinkOp virtPortOp,
+   virNetDevVPortProfileLinkOp virtPortOp,
bool setlink_only)
 {
 int op = PORT_REQUEST_ASSOCIATE;
@@ -1093,7 +1093,7 @@ virNetDevVPortProfileOp8021Qbh(const char *ifname,
int32_t vf,
const virNetDevVPortProfile *virtPort,
const unsigned char *vm_uuid,
-   enum virNetDevVPortProfileLinkOp virtPortOp)
+   virNetDevVPortProfileLinkOp virtPortOp)
 {
 int rc = 0;
 char *physfndev = NULL;
-- 
2.41.0



[PATCH 2/4] virNetDevVPortProfileOp8021Qbh: Use proper type in virReportEnumRangeError()

2023-09-19 Thread Michal Privoznik
The @virtPortOp variable inside of virNetDevVPortProfileOp8021Qbh
is of type virNetDevVPortProfileLinkOp. Pass the proper type to
virReportEnumRangeError().

Signed-off-by: Michal Privoznik 
---
 src/util/virnetdevvportprofile.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/util/virnetdevvportprofile.c b/src/util/virnetdevvportprofile.c
index 6d5bfbe870..c755fa79ec 100644
--- a/src/util/virnetdevvportprofile.c
+++ b/src/util/virnetdevvportprofile.c
@@ -1182,7 +1182,7 @@ virNetDevVPortProfileOp8021Qbh(const char *ifname,
 rc = -1;
 break;
 default:
-virReportEnumRangeError(virNetDevVPortProfileType, virtPortOp);
+virReportEnumRangeError(virNetDevVPortProfileLinkOp, virtPortOp);
 rc = -1;
 break;
 }
-- 
2.41.0



[PATCH 3/4] virDomainVideoDefValidate: Use proper type in virReportEnumRangeError()

2023-09-19 Thread Michal Privoznik
The @backend member of _virDomainVideoDef struct is of type
virDomainVideoBackendType. Pass the proper type to
virReportEnumRangeError().

Signed-off-by: Michal Privoznik 
---
 src/conf/domain_validate.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/conf/domain_validate.c b/src/conf/domain_validate.c
index e70841c1d6..ac32fa1477 100644
--- a/src/conf/domain_validate.c
+++ b/src/conf/domain_validate.c
@@ -181,7 +181,7 @@ virDomainVideoDefValidate(const virDomainVideoDef *video,
 break;
 case VIR_DOMAIN_VIDEO_BACKEND_TYPE_LAST:
 default:
-virReportEnumRangeError(virDomainInputType, video->backend);
+virReportEnumRangeError(virDomainVideoBackendType, video->backend);
 return -1;
 }
 
-- 
2.41.0



[PATCH 0/4] virerror: Make virReportEnumRangeError() check for type mismatch

2023-09-19 Thread Michal Privoznik
There are few cases where virReportEnumRangeError() is passed to a
mismatching enum. With patch 4/4 we can check for this at compile time
(assuming -Wenum-compare is available).

For instance with clang I get:

FAILED: src/conf/libvirt_conf.a.p/domain_validate.c.o 
clang ...
../src/conf/domain_validate.c:184:9: error: comparison of different enumeration 
types ('virDomainVideoBackendType' and 'virDomainInputType') 
[-Werror,-Wenum-compare]
virReportEnumRangeError(virDomainInputType, video->backend);
^~~
../src/util/virerror.h:175:47: note: expanded from macro 
'virReportEnumRangeError'
 (__typeof__(value))1 == (typname)1 && 
sizeof((typname)1) != 0 ? #typname : #typname)
  ^  ~~

Whereas with gcc I get more obscure error:

FAILED: src/conf/libvirt_conf.a.p/domain_validate.c.o 
cc ...
In file included from ../src/util/virthread.h:25,
 from ../src/util/virobject.h:25,
 from ../src/conf/capabilities.h:28,
 from ../src/conf/domain_conf.h:31,
 from ../src/conf/domain_validate.h:25,
 from ../src/conf/domain_validate.c:23:
../src/conf/domain_validate.c: In function ‘virDomainVideoDefValidate’:
../src/util/virerror.h:175:47: error: comparison between ‘enum ’ and 
‘enum ’ [-Werror=enum-compare]
  175 |  (__typeof__(value))1 == (typname)1 && 
sizeof((typname)1) != 0 ? #typname : #typname)
  |   ^~
../src/conf/domain_validate.c:184:9: note: in expansion of macro 
‘virReportEnumRangeError’
  184 | virReportEnumRangeError(virDomainInputType, video->backend);
  | ^~~

But I guess this is also okay-ish - it reports there is a problem with
code.

NB this only works with variables that are of a certain enum types. It
does not work with those generic 'int var /* someEnum */' declarations,
understandably. But as we use virXMLPropEnum() more, we can declare
variables of their true type (enum) and get more and more calls to
virReportEnumRangeError() checked.

Michal Prívozník (4):
  virnetdevvportprofile: Turn virNetDevVPortProfileLinkOp enum into a
proper typedef
  virNetDevVPortProfileOp8021Qbh: Use proper type in
virReportEnumRangeError()
  virDomainVideoDefValidate: Use proper type in
virReportEnumRangeError()
  virerror: Make virReportEnumRangeError() check for type mismatch

 src/conf/domain_validate.c   |  2 +-
 src/util/virerror.h  | 14 --
 src/util/virnetdevvportprofile.c | 10 +-
 3 files changed, 14 insertions(+), 12 deletions(-)

-- 
2.41.0



[PATCH] src: Avoid needless checks before calling g_strdup()

2023-09-18 Thread Michal Privoznik
There are few places where the following pattern occurs:

  if (var)
  other = g_strdup(var);

where @other wasn't initialized before g_strdup(). Checking for
var != NULL is useless in this case, as that's exactly what
g_strdup() does (in which case it returns NULL).

Signed-off-by: Michal Privoznik 
---
 src/conf/domain_event.c  | 3 +--
 src/libxl/libxl_conf.c   | 6 ++
 src/lxc/lxc_native.c | 3 +--
 src/qemu/qemu_monitor_json.c | 3 +--
 src/util/virconf.c   | 3 +--
 5 files changed, 6 insertions(+), 12 deletions(-)

diff --git a/src/conf/domain_event.c b/src/conf/domain_event.c
index 75603a933a..09f3368064 100644
--- a/src/conf/domain_event.c
+++ b/src/conf/domain_event.c
@@ -1561,8 +1561,7 @@ virDomainEventMetadataChangeNew(int id,
 return NULL;
 
 ev->type = type;
-if (nsuri)
-ev->nsuri = g_strdup(nsuri);
+ev->nsuri = g_strdup(nsuri);
 
 return (virObjectEvent *)ev;
 }
diff --git a/src/libxl/libxl_conf.c b/src/libxl/libxl_conf.c
index 3ffb46fddd..4582126d19 100644
--- a/src/libxl/libxl_conf.c
+++ b/src/libxl/libxl_conf.c
@@ -583,8 +583,7 @@ libxlMakeDomBuildInfo(virDomainDef *def,
 #endif
 
 /* copy SLIC table path to acpi_firmware */
-if (def->os.slic_table)
-b_info->u.hvm.acpi_firmware = g_strdup(def->os.slic_table);
+b_info->u.hvm.acpi_firmware = g_strdup(def->os.slic_table);
 
 if (def->nsounds > 0) {
 /*
@@ -1198,8 +1197,7 @@ libxlMakeDisk(virDomainDiskDef *l_disk, libxl_device_disk 
*x_disk)
 return -1;
 }
 
-if (l_disk->domain_name)
-x_disk->backend_domname = g_strdup(l_disk->domain_name);
+x_disk->backend_domname = g_strdup(l_disk->domain_name);
 
 return 0;
 }
diff --git a/src/lxc/lxc_native.c b/src/lxc/lxc_native.c
index 5a63efc35f..c0011e0600 100644
--- a/src/lxc/lxc_native.c
+++ b/src/lxc/lxc_native.c
@@ -67,8 +67,7 @@ lxcCreateFSDef(int type,
 
 def->type = type;
 def->accessmode = VIR_DOMAIN_FS_ACCESSMODE_PASSTHROUGH;
-if (src)
-def->src->path = g_strdup(src);
+def->src->path = g_strdup(src);
 def->dst = g_strdup(dst);
 def->readonly = readonly;
 def->usage = usage;
diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
index 137cb4e293..8152eea9a0 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -2960,8 +2960,7 @@ qemuMonitorJSONGetMigrationStatsReply(virJSONValue *reply,
 case QEMU_MONITOR_MIGRATION_STATUS_ERROR:
 if (error) {
 tmp = virJSONValueObjectGetString(ret, "error-desc");
-if (tmp)
-*error = g_strdup(tmp);
+*error = g_strdup(tmp);
 }
 break;
 
diff --git a/src/util/virconf.c b/src/util/virconf.c
index 934632a35f..8fdf40e9d0 100644
--- a/src/util/virconf.c
+++ b/src/util/virconf.c
@@ -939,8 +939,7 @@ int virConfGetValueStringList(virConf *conf,
 case VIR_CONF_STRING:
 if (compatString) {
 *values = g_new0(char *, cval->str ? 2 : 1);
-if (cval->str)
-(*values)[0] = g_strdup(cval->str);
+(*values)[0] = g_strdup(cval->str);
 break;
 }
 G_GNUC_FALLTHROUGH;
-- 
2.41.0



[PATCH merged] bhyveBuildControllerArgStr: Fill in missing cases to switch() statement

2023-09-15 Thread Michal Privoznik
When making 'type' member of virDomainControllerDef to be of
virDomainControllerType rather than an int I forgot to update
bhyve_command.c.

Fixes: 27a653b8931051991d44b8776a8cdc08c666b729
Signed-off-by: Michal Privoznik 
---

Pushed as build breaker fix.

 src/bhyve/bhyve_command.c | 12 
 1 file changed, 12 insertions(+)

diff --git a/src/bhyve/bhyve_command.c b/src/bhyve/bhyve_command.c
index 82e7e96816..bcef836eca 100644
--- a/src/bhyve/bhyve_command.c
+++ b/src/bhyve/bhyve_command.c
@@ -367,6 +367,18 @@ bhyveBuildControllerArgStr(const virDomainDef *def,
 virCommandAddArgFormat(cmd, "%d:0,lpc",
 controller->info.addr.pci.slot);
 break;
+case VIR_DOMAIN_CONTROLLER_TYPE_IDE:
+case VIR_DOMAIN_CONTROLLER_TYPE_FDC:
+case VIR_DOMAIN_CONTROLLER_TYPE_SCSI:
+case VIR_DOMAIN_CONTROLLER_TYPE_VIRTIO_SERIAL:
+case VIR_DOMAIN_CONTROLLER_TYPE_CCID:
+case VIR_DOMAIN_CONTROLLER_TYPE_XENBUS:
+case VIR_DOMAIN_CONTROLLER_TYPE_LAST:
+default:
+virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+   _("unsupported controller device"));
+return -1;
+
 }
 return 0;
 }
-- 
2.41.0



[PATCH 08/20] virDomainHostdevSubsysSCSI: Convert 'protocol' field to proper enum type

2023-09-14 Thread Michal Privoznik
Convert the field and adjust the XML parser to use
virXMLPropEnum().

Signed-off-by: Michal Privoznik 
---
 src/conf/domain_conf.c  | 18 ++
 src/conf/domain_conf.h  |  2 +-
 src/qemu/qemu_command.c |  4 ++--
 src/qemu/qemu_domain.c  |  4 ++--
 4 files changed, 11 insertions(+), 17 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 306547e798..ef5f02a23b 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -6065,20 +6065,14 @@ virDomainHostdevSubsysSCSIDefParseXML(xmlNodePtr 
sourcenode,
   unsigned int flags,
   virDomainXMLOption *xmlopt)
 {
-g_autofree char *protocol = NULL;
-
-if ((protocol = virXMLPropString(sourcenode, "protocol"))) {
-scsisrc->protocol =
-virDomainHostdevSubsysSCSIProtocolTypeFromString(protocol);
-if (scsisrc->protocol < 0) {
-virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-   _("Unknown SCSI subsystem protocol '%1$s'"),
-   protocol);
-return -1;
-}
+if (virXMLPropEnum(sourcenode, "protocol",
+   virDomainHostdevSubsysSCSIProtocolTypeFromString,
+   VIR_XML_PROP_NONE,
+   >protocol) < 0) {
+return -1;
 }
 
-switch ((virDomainHostdevSCSIProtocolType) scsisrc->protocol) {
+switch (scsisrc->protocol) {
 case VIR_DOMAIN_HOSTDEV_SCSI_PROTOCOL_TYPE_NONE:
 return virDomainHostdevSubsysSCSIHostDefParseXML(sourcenode, ctxt, 
scsisrc,
  flags, xmlopt);
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index ca195a52d2..5cce60420f 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -273,7 +273,7 @@ typedef enum {
 } virDomainDeviceSGIO;
 
 struct _virDomainHostdevSubsysSCSI {
-int protocol; /* enum virDomainHostdevSCSIProtocolType */
+virDomainHostdevSCSIProtocolType protocol;
 virDomainDeviceSGIO sgio;
 virTristateBool rawio;
 union {
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index be5814663c..ccbf41a0f7 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -5033,7 +5033,7 @@ qemuBuildHostdevSCSIDetachPrepare(virDomainHostdevDef 
*hostdev,
 virStorageSource *src;
 qemuDomainStorageSourcePrivate *srcpriv;
 
-switch ((virDomainHostdevSCSIProtocolType) scsisrc->protocol) {
+switch (scsisrc->protocol) {
 case VIR_DOMAIN_HOSTDEV_SCSI_PROTOCOL_TYPE_NONE:
 src = scsisrc->u.host.src;
 break;
@@ -5068,7 +5068,7 @@ qemuBuildHostdevSCSIAttachPrepare(virDomainHostdevDef 
*hostdev,
 g_autoptr(qemuBlockStorageSourceAttachData) ret = 
g_new0(qemuBlockStorageSourceAttachData, 1);
 virStorageSource *src = NULL;
 
-switch ((virDomainHostdevSCSIProtocolType) scsisrc->protocol) {
+switch (scsisrc->protocol) {
 case VIR_DOMAIN_HOSTDEV_SCSI_PROTOCOL_TYPE_NONE:
 src = scsisrc->u.host.src;
 break;
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index e578df624b..069f145d26 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -6008,7 +6008,7 @@ 
qemuDomainDeviceHostdevDefPostParseRestoreBackendAlias(virDomainHostdevDef *host
 hostdev->source.subsys.type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI)
 return 0;
 
-switch ((virDomainHostdevSCSIProtocolType) scsisrc->protocol) {
+switch (scsisrc->protocol) {
 case VIR_DOMAIN_HOSTDEV_SCSI_PROTOCOL_TYPE_NONE:
 if (!scsisrc->u.host.src)
 scsisrc->u.host.src = virStorageSourceNew();
@@ -11373,7 +11373,7 @@ qemuDomainPrepareHostdevSCSI(virDomainHostdevDef 
*hostdev,
 virStorageSource *src = NULL;
 g_autofree char *devstr = NULL;
 
-switch ((virDomainHostdevSCSIProtocolType) scsisrc->protocol) {
+switch (scsisrc->protocol) {
 case VIR_DOMAIN_HOSTDEV_SCSI_PROTOCOL_TYPE_NONE:
 virObjectUnref(scsisrc->u.host.src);
 scsisrc->u.host.src = virStorageSourceNew();
-- 
2.41.0



[PATCH 13/20] virDomainControllerDef: Convert 'type' field to proper enum type

2023-09-14 Thread Michal Privoznik
Convert the field and fill in missing cases to switch()
statements.

Signed-off-by: Michal Privoznik 
---
 src/conf/domain_conf.c | 26 ++
 src/conf/domain_conf.h |  9 ++---
 src/qemu/qemu_command.c|  2 +-
 src/qemu/qemu_domain.c |  2 +-
 src/qemu/qemu_domain_address.c | 12 +++-
 src/qemu/qemu_hotplug.c|  4 ++--
 src/qemu/qemu_validate.c   |  2 +-
 src/vbox/vbox_common.c |  2 +-
 8 files changed, 41 insertions(+), 18 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 35cb14b986..95a71b204f 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -2473,7 +2473,7 @@ virDomainControllerDefNew(virDomainControllerType type)
 def->model = -1;
 def->idx = -1;
 
-switch ((virDomainControllerType) def->type) {
+switch (def->type) {
 case VIR_DOMAIN_CONTROLLER_TYPE_VIRTIO_SERIAL:
 def->opts.vioserial.ports = -1;
 def->opts.vioserial.vectors = -1;
@@ -8265,7 +8265,7 @@ static int
 virDomainControllerModelTypeFromString(const virDomainControllerDef *def,
const char *model)
 {
-switch ((virDomainControllerType)def->type) {
+switch (def->type) {
 case VIR_DOMAIN_CONTROLLER_TYPE_SCSI:
 return virDomainControllerModelSCSITypeFromString(model);
 case VIR_DOMAIN_CONTROLLER_TYPE_USB:
@@ -8293,7 +8293,7 @@ static const char *
 virDomainControllerModelTypeToString(virDomainControllerDef *def,
  int model)
 {
-switch ((virDomainControllerType)def->type) {
+switch (def->type) {
 case VIR_DOMAIN_CONTROLLER_TYPE_SCSI:
 return virDomainControllerModelSCSITypeToString(model);
 case VIR_DOMAIN_CONTROLLER_TYPE_USB:
@@ -8324,7 +8324,7 @@ virDomainControllerDefParseXML(virDomainXMLOption *xmlopt,
unsigned int flags)
 {
 g_autoptr(virDomainControllerDef) def = NULL;
-virDomainControllerType type = 0;
+virDomainControllerType type = VIR_DOMAIN_CONTROLLER_TYPE_IDE;
 xmlNodePtr driver = NULL;
 g_autofree xmlNodePtr *targetNodes = NULL;
 int ntargetNodes = 0;
@@ -8539,6 +8539,13 @@ virDomainControllerDefParseXML(virDomainXMLOption 
*xmlopt,
 break;
 }
 
+case VIR_DOMAIN_CONTROLLER_TYPE_IDE:
+case VIR_DOMAIN_CONTROLLER_TYPE_FDC:
+case VIR_DOMAIN_CONTROLLER_TYPE_SCSI:
+case VIR_DOMAIN_CONTROLLER_TYPE_SATA:
+case VIR_DOMAIN_CONTROLLER_TYPE_CCID:
+case VIR_DOMAIN_CONTROLLER_TYPE_ISA:
+case VIR_DOMAIN_CONTROLLER_TYPE_LAST:
 default:
 break;
 }
@@ -16031,7 +16038,10 @@ virDomainEmulatorPinDefParseXML(xmlNodePtr node)
 
 
 virDomainControllerDef *
-virDomainDefAddController(virDomainDef *def, int type, int idx, int model)
+virDomainDefAddController(virDomainDef *def,
+  virDomainControllerType type,
+  int idx,
+  int model)
 {
 virDomainControllerDef *cont;
 
@@ -16106,7 +16116,7 @@ virDomainDefAddUSBController(virDomainDef *def, int 
idx, int model)
 
 int
 virDomainDefMaybeAddController(virDomainDef *def,
-   int type,
+   virDomainControllerType type,
int idx,
int model)
 {
@@ -21719,7 +21729,7 @@ virDomainDefCheckABIStability(virDomainDef *src,
 
 static int
 virDomainDefAddDiskControllersForType(virDomainDef *def,
-  int controllerType,
+  virDomainControllerType controllerType,
   int diskBus)
 {
 size_t i;
@@ -22981,7 +22991,7 @@ virDomainControllerDefFormat(virBuffer *buf,
 if (model)
 virBufferEscapeString(, " model='%s'", model);
 
-switch ((virDomainControllerType) def->type) {
+switch (def->type) {
 case VIR_DOMAIN_CONTROLLER_TYPE_VIRTIO_SERIAL:
 if (def->opts.vioserial.ports != -1) {
 virBufferAsprintf(, " ports='%d'",
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index fc612f3adb..9dadda2d1d 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -784,7 +784,7 @@ struct _virDomainXenbusControllerOpts {
 
 /* Stores the virtual disk controller configuration */
 struct _virDomainControllerDef {
-int type;
+virDomainControllerType type;
 int idx;
 int model; /* -1 == undef */
 unsigned int queues;
@@ -4280,12 +4280,15 @@ VIR_ENUM_DECL(virDomainCpuPlacementMode);
 VIR_ENUM_DECL(virDomainStartupPolicy);
 
 virDomainControllerDef *
-virDomainDefAddController(virDomainDef *def, int type, int idx, int model);
+virDomainDefAddController(virDomainDef *def,
+  virDomainControllerType type,
+  int idx,
+  int model);
 int
 virDoma

[PATCH 10/20] virDomainHostdevDef: Convert 'mode' field to proper enum type

2023-09-14 Thread Michal Privoznik
Convert the field, adjust the XML parser to use
virXMLPropEnumDefault() and fill in missing cases to switch()
statements.

Signed-off-by: Michal Privoznik 
---
 src/conf/domain_audit.c |  2 +-
 src/conf/domain_conf.c  | 23 +--
 src/conf/domain_conf.h  |  2 +-
 src/lxc/lxc_cgroup.c|  1 +
 src/lxc/lxc_controller.c|  1 +
 src/lxc/lxc_driver.c|  2 ++
 src/lxc/lxc_hostdev.c   |  1 +
 src/qemu/qemu_domain.c  |  2 +-
 src/qemu/qemu_migration.c   |  2 +-
 src/security/security_selinux.c |  2 ++
 10 files changed, 24 insertions(+), 14 deletions(-)

diff --git a/src/conf/domain_audit.c b/src/conf/domain_audit.c
index ae875188bd..d4d303a214 100644
--- a/src/conf/domain_audit.c
+++ b/src/conf/domain_audit.c
@@ -351,7 +351,7 @@ virDomainAuditHostdev(virDomainObj *vm, virDomainHostdevDef 
*hostdev,
 return;
 }
 
-switch ((virDomainHostdevMode) hostdev->mode) {
+switch (hostdev->mode) {
 case VIR_DOMAIN_HOSTDEV_MODE_SUBSYS:
 switch ((virDomainHostdevSubsysType) hostdev->source.subsys.type) {
 case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI:
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 65b7b44ccb..c93f89ced6 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -2648,6 +2648,8 @@ virDomainHostdevDefClear(virDomainHostdevDef *def)
 break;
 }
 break;
+case VIR_DOMAIN_HOSTDEV_MODE_LAST:
+break;
 }
 }
 
@@ -12917,7 +12919,6 @@ virDomainHostdevDefParseXML(virDomainXMLOption *xmlopt,
 {
 virDomainHostdevDef *def;
 VIR_XPATH_NODE_AUTORESTORE(ctxt)
-g_autofree char *mode = virXMLPropString(node, "mode");
 g_autofree char *type = virXMLPropString(node, "type");
 
 ctxt->node = node;
@@ -12925,15 +12926,11 @@ virDomainHostdevDefParseXML(virDomainXMLOption 
*xmlopt,
 if (!(def = virDomainHostdevDefNew()))
 goto error;
 
-if (mode) {
-if ((def->mode = virDomainHostdevModeTypeFromString(mode)) < 0) {
-virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-   _("unknown hostdev mode '%1$s'"), mode);
-goto error;
-}
-} else {
-def->mode = VIR_DOMAIN_HOSTDEV_MODE_SUBSYS;
-}
+if (virXMLPropEnumDefault(node, "mode", virDomainHostdevModeTypeFromString,
+  VIR_XML_PROP_NONE,
+  >mode,
+  VIR_DOMAIN_HOSTDEV_MODE_SUBSYS) < 0)
+goto error;
 
 switch (def->mode) {
 case VIR_DOMAIN_HOSTDEV_MODE_SUBSYS:
@@ -12947,6 +12944,7 @@ virDomainHostdevDefParseXML(virDomainXMLOption *xmlopt,
 goto error;
 break;
 default:
+case VIR_DOMAIN_HOSTDEV_MODE_LAST:
 virReportError(VIR_ERR_INTERNAL_ERROR,
_("Unexpected hostdev mode %1$d"), def->mode);
 goto error;
@@ -14182,6 +14180,8 @@ virDomainHostdevMatch(virDomainHostdevDef *a,
 return virDomainHostdevMatchSubsys(a, b);
 case VIR_DOMAIN_HOSTDEV_MODE_CAPABILITIES:
 return virDomainHostdevMatchCaps(a, b);
+case VIR_DOMAIN_HOSTDEV_MODE_LAST:
+break;
 }
 return 0;
 }
@@ -26087,6 +26087,7 @@ virDomainHostdevDefFormat(virBuffer *buf,
 }
 break;
 default:
+case VIR_DOMAIN_HOSTDEV_MODE_LAST:
 virReportError(VIR_ERR_INTERNAL_ERROR,
_("unexpected hostdev mode %1$d"), def->mode);
 return -1;
@@ -26139,6 +26140,8 @@ virDomainHostdevDefFormat(virBuffer *buf,
 if (virDomainHostdevDefFormatCaps(buf, def) < 0)
 return -1;
 break;
+case VIR_DOMAIN_HOSTDEV_MODE_LAST:
+break;
 }
 
 virDomainNetTeamingInfoFormat(def->teaming, buf);
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index d6d0799f63..1f977ef1c8 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -371,7 +371,7 @@ struct _virDomainHostdevDef {
  */
 virDomainNetDef *parentnet;
 
-int mode; /* enum virDomainHostdevMode */
+virDomainHostdevMode mode;
 virDomainStartupPolicy startupPolicy;
 bool managed;
 bool missing;
diff --git a/src/lxc/lxc_cgroup.c b/src/lxc/lxc_cgroup.c
index bc39b16928..21d9b456e8 100644
--- a/src/lxc/lxc_cgroup.c
+++ b/src/lxc/lxc_cgroup.c
@@ -313,6 +313,7 @@ static int virLXCCgroupSetupDeviceACL(virDomainDef *def,
 break;
 }
 default:
+case VIR_DOMAIN_HOSTDEV_MODE_LAST:
 break;
 }
 }
diff --git a/src/lxc/lxc_controller.c b/src/lxc/lxc_controller.c
index 6c20429998..e2d67d504d 100644
--- a/src/lxc/lxc_controller.c
+++ b/src/lxc/lxc_controller.c
@@ -1837,6 +1837,7 @@ virLXCControllerSetupAllHostdevs(virLXCController *ctrl)
 return -1;
 break;
 defau

[PATCH 12/20] virDomainHostdevSubsys: Convert 'type' field to proper enum type

2023-09-14 Thread Michal Privoznik
Convert the field, and fill in missing cases to switch()
statements.

Signed-off-by: Michal Privoznik 
---
 src/conf/domain_audit.c  |  2 +-
 src/conf/domain_conf.c   | 57 +++-
 src/conf/domain_conf.h   |  2 +-
 src/conf/domain_validate.c   |  2 +-
 src/libxl/libxl_driver.c | 12 +++
 src/lxc/lxc_controller.c |  5 +++
 src/lxc/lxc_driver.c | 10 ++
 src/lxc/lxc_hostdev.c|  5 +++
 src/qemu/qemu_command.c  |  2 +-
 src/qemu/qemu_domain.c   |  4 +--
 src/qemu/qemu_hotplug.c  |  4 ++-
 src/qemu/qemu_migration.c|  2 +-
 src/qemu/qemu_validate.c |  2 +-
 src/security/security_apparmor.c |  2 +-
 src/security/security_dac.c  |  4 +--
 src/security/security_selinux.c  |  4 +--
 src/security/virt-aa-helper.c|  3 ++
 17 files changed, 85 insertions(+), 37 deletions(-)

diff --git a/src/conf/domain_audit.c b/src/conf/domain_audit.c
index 0bf1768acd..4294b50c3a 100644
--- a/src/conf/domain_audit.c
+++ b/src/conf/domain_audit.c
@@ -353,7 +353,7 @@ virDomainAuditHostdev(virDomainObj *vm, virDomainHostdevDef 
*hostdev,
 
 switch (hostdev->mode) {
 case VIR_DOMAIN_HOSTDEV_MODE_SUBSYS:
-switch ((virDomainHostdevSubsysType) hostdev->source.subsys.type) {
+switch (hostdev->source.subsys.type) {
 case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI:
 address = virPCIDeviceAddressAsString(>addr);
 break;
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index cf1bd4df74..35cb14b986 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -2632,7 +2632,7 @@ virDomainHostdevDefClear(virDomainHostdevDef *def)
 }
 break;
 case VIR_DOMAIN_HOSTDEV_MODE_SUBSYS:
-switch ((virDomainHostdevSubsysType) def->source.subsys.type) {
+switch (def->source.subsys.type) {
 case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI:
 virDomainHostdevSubsysSCSIClear(>source.subsys.u.scsi);
 break;
@@ -6168,7 +6168,7 @@ 
virDomainHostdevSubsysMediatedDevDefParseXML(virDomainHostdevDef *def,
 static int
 virDomainHostdevDefParseXMLSubsys(xmlNodePtr node,
   xmlXPathContextPtr ctxt,
-  const char *type,
+  virDomainHostdevSubsysType type,
   virDomainHostdevDef *def,
   unsigned int flags,
   virDomainXMLOption *xmlopt)
@@ -6202,18 +6202,7 @@ virDomainHostdevDefParseXMLSubsys(xmlNodePtr node,
  * .  (the functions we're going to call expect address
  * type to already be known).
  */
-if (!type) {
-virReportError(VIR_ERR_XML_ERROR,
-   "%s", _("missing source address type"));
-return -1;
-}
-
-if ((def->source.subsys.type = virDomainHostdevSubsysTypeFromString(type)) 
< 0) {
-virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-   _("unknown host device source address type '%1$s'"),
-   type);
-return -1;
-}
+def->source.subsys.type = type;
 
 if (!(sourcenode = virXPathNode("./source", ctxt))) {
 virReportError(VIR_ERR_XML_ERROR, "%s",
@@ -6322,6 +6311,7 @@ virDomainHostdevDefParseXMLSubsys(xmlNodePtr node,
 return -1;
 break;
 
+case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_LAST:
 default:
 virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("address type='%1$s' not supported in hostdev 
interfaces"),
@@ -8868,6 +8858,7 @@ virDomainActualNetDefParseXML(xmlNodePtr node,
 }
 } else if (actual->type == VIR_DOMAIN_NET_TYPE_HOSTDEV) {
 virDomainHostdevDef *hostdev = >data.hostdev.def;
+int type;
 
 hostdev->parentnet = parent;
 hostdev->info = >info;
@@ -8879,8 +8870,16 @@ virDomainActualNetDefParseXML(xmlNodePtr node,
 /* if not explicitly stated, source/vendor implies usb device */
 if (!addrtype && virXPathNode("./source/vendor", ctxt))
 addrtype = g_strdup("usb");
+
+if ((type = virDomainHostdevSubsysTypeFromString(addrtype)) < 0) {
+virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+   _("unknown host device source address type '%1$s'"),
+   addrtype);
+goto error;
+}
+
 hostdev->mode = VIR_DOMAIN_HOSTDEV_MODE_SUBSYS;
-if (virDomainHostdevDefParseXMLSubsys(node, ctxt, addrtype,
+if (virDomainHostdevDefParseXMLSubsys(node, ctxt, type,
   hostdev, flags, xmlopt) < 0) {
 goto error;
 }
@@ -9544,6 +9543,7 @@ virDomainNetDefParseXML(virDomainX

[PATCH 20/20] virDomainDiskSourceNVMeParse: Use virXMLPropULongLong()

2023-09-14 Thread Michal Privoznik
Inside of virDomainDiskSourceNVMeParse() we have
virXMLPropString() + virStrToLong_ull() combo. Switch to
virXMLPropULongLong() which does the same thing.

Signed-off-by: Michal Privoznik 
---
 src/conf/domain_conf.c | 14 +++---
 1 file changed, 3 insertions(+), 11 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 5f4146b4e3..0efac66f61 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -7229,7 +7229,6 @@ virDomainDiskSourceNVMeParse(xmlNodePtr node,
 {
 g_autoptr(virStorageSourceNVMeDef) nvme = NULL;
 g_autofree char *type = NULL;
-g_autofree char *namespc = NULL;
 xmlNodePtr address;
 
 nvme = g_new0(virStorageSourceNVMeDef, 1);
@@ -7247,16 +7246,9 @@ virDomainDiskSourceNVMeParse(xmlNodePtr node,
 return -1;
 }
 
-if (!(namespc = virXMLPropString(node, "namespace"))) {
-virReportError(VIR_ERR_XML_ERROR, "%s",
-   _("missing 'namespace' attribute to disk source"));
-return -1;
-}
-
-if (virStrToLong_ull(namespc, NULL, 10, >namespc) < 0) {
-virReportError(VIR_ERR_XML_ERROR,
-   _("malformed namespace '%1$s'"),
-   namespc);
+if (virXMLPropULongLong(node, "namespace", 10,
+VIR_XML_PROP_REQUIRED,
+>namespc) < 0) {
 return -1;
 }
 
-- 
2.41.0



[PATCH 01/20] lxc_controller: Access correct union member in virLXCControllerSetupHostdevCaps()

2023-09-14 Thread Michal Privoznik
The point of virLXCControllerSetupHostdevCaps() is to access
.caps union member of given  source. And it does so in
the switch, but then, when reporting an error the .subsys member
is accessed.

Signed-off-by: Michal Privoznik 
---
 src/lxc/lxc_controller.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/lxc/lxc_controller.c b/src/lxc/lxc_controller.c
index d79b8e1dd6..6c20429998 100644
--- a/src/lxc/lxc_controller.c
+++ b/src/lxc/lxc_controller.c
@@ -1807,7 +1807,7 @@ virLXCControllerSetupHostdevCaps(virDomainDef *vmDef,
 default:
 virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("Unsupported host device mode %1$s"),
-   
virDomainHostdevCapsTypeToString(def->source.subsys.type));
+   
virDomainHostdevCapsTypeToString(def->source.caps.type));
 return -1;
 }
 }
-- 
2.41.0



[PATCH 19/20] virStorageNetHostDef: Convert 'transport' field to proper enum type

2023-09-14 Thread Michal Privoznik
Convert the field and adjust the XML parsers to use
virXMLPropEnumDefault().

Signed-off-by: Michal Privoznik 
---
 src/conf/domain_conf.c  | 16 ++--
 src/conf/storage_source_conf.h  |  2 +-
 src/qemu/qemu_backup.c  |  2 +-
 src/qemu/qemu_block.c   |  2 +-
 src/qemu/qemu_monitor_json.c|  2 +-
 src/storage_file/storage_file_backend_gluster.c |  2 +-
 src/storage_file/storage_source_backingstore.c  | 15 +--
 7 files changed, 20 insertions(+), 21 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index a743a0628c..5f4146b4e3 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -5834,17 +5834,13 @@ virDomainStorageNetworkParseHost(xmlNodePtr hostnode,
 g_autofree char *port = NULL;
 
 memset(host, 0, sizeof(*host));
-host->transport = VIR_STORAGE_NET_HOST_TRANS_TCP;
 
-/* transport can be tcp (default), unix or rdma.  */
-if ((transport = virXMLPropString(hostnode, "transport"))) {
-host->transport = virStorageNetHostTransportTypeFromString(transport);
-if (host->transport < 0) {
-virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-   _("unknown protocol transport type '%1$s'"),
-   transport);
-goto cleanup;
-}
+if (virXMLPropEnumDefault(hostnode, "transport",
+  virStorageNetHostTransportTypeFromString,
+  VIR_XML_PROP_NONE,
+  >transport,
+  VIR_STORAGE_NET_HOST_TRANS_TCP) < 0) {
+goto cleanup;
 }
 
 host->socket = virXMLPropString(hostnode, "socket");
diff --git a/src/conf/storage_source_conf.h b/src/conf/storage_source_conf.h
index f99579bce2..9791fb25ee 100644
--- a/src/conf/storage_source_conf.h
+++ b/src/conf/storage_source_conf.h
@@ -151,7 +151,7 @@ typedef struct _virStorageNetHostDef virStorageNetHostDef;
 struct _virStorageNetHostDef {
 char *name;
 unsigned int port;
-int transport; /* virStorageNetHostTransport */
+virStorageNetHostTransport transport;
 char *socket;  /* path to unix socket */
 };
 
diff --git a/src/qemu/qemu_backup.c b/src/qemu/qemu_backup.c
index a94869522d..e4db967e2c 100644
--- a/src/qemu/qemu_backup.c
+++ b/src/qemu/qemu_backup.c
@@ -68,7 +68,7 @@ qemuBackupPrepare(virDomainBackupDef *def)
 def->server->name = g_strdup("localhost");
 }
 
-switch ((virStorageNetHostTransport) def->server->transport) {
+switch (def->server->transport) {
 case VIR_STORAGE_NET_HOST_TRANS_TCP:
 /* TODO: Update qemu.conf to provide a port range,
  * probably starting at 10809, for obtaining automatic
diff --git a/src/qemu/qemu_block.c b/src/qemu/qemu_block.c
index d31bbde0f4..97f03002fd 100644
--- a/src/qemu/qemu_block.c
+++ b/src/qemu/qemu_block.c
@@ -130,7 +130,7 @@ 
qemuBlockStorageSourceBuildJSONSocketAddress(virStorageNetHostDef *host)
 g_autoptr(virJSONValue) server = NULL;
 g_autofree char *port = NULL;
 
-switch ((virStorageNetHostTransport) host->transport) {
+switch (host->transport) {
 case VIR_STORAGE_NET_HOST_TRANS_TCP:
 port = g_strdup_printf("%u", host->port);
 
diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
index 5b9edadcf7..137cb4e293 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -6176,7 +6176,7 @@ qemuMonitorJSONNBDServerStart(qemuMonitor *mon,
 g_autoptr(virJSONValue) addr = NULL;
 g_autofree char *port_str = NULL;
 
-switch ((virStorageNetHostTransport)server->transport) {
+switch (server->transport) {
 case VIR_STORAGE_NET_HOST_TRANS_TCP:
 port_str = g_strdup_printf("%u", server->port);
 addr = qemuMonitorJSONBuildInetSocketAddress(server->name, port_str);
diff --git a/src/storage_file/storage_file_backend_gluster.c 
b/src/storage_file/storage_file_backend_gluster.c
index d018d5422e..950f8e81fe 100644
--- a/src/storage_file/storage_file_backend_gluster.c
+++ b/src/storage_file/storage_file_backend_gluster.c
@@ -63,7 +63,7 @@ 
virStorageFileBackendGlusterInitServer(virStorageFileBackendGlusterPriv *priv,
 const char *hoststr = NULL;
 int port = 0;
 
-switch ((virStorageNetHostTransport) host->transport) {
+switch (host->transport) {
 case VIR_STORAGE_NET_HOST_TRANS_RDMA:
 case VIR_STORAGE_NET_HOST_TRANS_TCP:
 hoststr = host->name;
diff --git a/src/storage_file/storage_source_backingstore.c 
b/src/storage_file/storage_source_backingstore.c
index 00fcfe9fd7..80681924ea 100644
--- a/src/storage_file/storage_source_backingstore.c
+++ b/src/storage_file/storage_source_backingstore.c
@@ -42,6 +42,7 @@ vi

[PATCH 18/20] virDomainDeviceInfo: Convert 'type' field to proper enum type

2023-09-14 Thread Michal Privoznik
Convert the field, adjust the XML parsers to use virXMLPropEnum()
and fill in missing cases to switch() statements.

Signed-off-by: Michal Privoznik 
---
 src/conf/device_conf.c | 12 +++-
 src/conf/device_conf.h |  4 ++--
 src/conf/domain_conf.c | 21 +++--
 src/conf/domain_validate.c |  2 +-
 src/qemu/qemu_command.c|  4 ++--
 src/qemu/qemu_monitor.c| 12 
 src/qemu/qemu_validate.c   |  2 +-
 7 files changed, 36 insertions(+), 21 deletions(-)

diff --git a/src/conf/device_conf.c b/src/conf/device_conf.c
index aa0cc8945c..f3d977f2b7 100644
--- a/src/conf/device_conf.c
+++ b/src/conf/device_conf.c
@@ -98,7 +98,7 @@ virDomainDeviceInfoAddressIsEqual(const virDomainDeviceInfo 
*a,
 if (a->type != b->type)
 return false;
 
-switch ((virDomainDeviceAddressType) a->type) {
+switch (a->type) {
 case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE:
 case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_LAST:
 /* address types below don't have any specific data */
@@ -427,6 +427,16 @@ virDomainDeviceAddressIsValid(virDomainDeviceInfo *info,
 
 case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_USB:
 return true;
+
+case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE:
+case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_VIRTIO_SERIAL:
+case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_CCID:
+case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_SPAPRVIO:
+case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_ISA:
+case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_DIMM:
+case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_UNASSIGNED:
+case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_LAST:
+break;
 }
 
 return false;
diff --git a/src/conf/device_conf.h b/src/conf/device_conf.h
index f2907dc596..a83377417a 100644
--- a/src/conf/device_conf.h
+++ b/src/conf/device_conf.h
@@ -32,7 +32,7 @@
 #include "virenum.h"
 
 typedef enum {
-VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE,
+VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE = 0,
 VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI,
 VIR_DOMAIN_DEVICE_ADDRESS_TYPE_DRIVE,
 VIR_DOMAIN_DEVICE_ADDRESS_TYPE_VIRTIO_SERIAL,
@@ -116,7 +116,7 @@ struct _virDomainDeviceDimmAddress {
 typedef struct _virDomainDeviceInfo virDomainDeviceInfo;
 struct _virDomainDeviceInfo {
 char *alias;
-int type; /* virDomainDeviceAddressType */
+virDomainDeviceAddressType type;
 union {
 virPCIDeviceAddress pci;
 virDomainDeviceDriveAddress drive;
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index f48020f893..a743a0628c 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -5366,7 +5366,7 @@ virDomainDeviceInfoFormat(virBuffer *buf,
 virBufferAsprintf(, " type='%s'",
   virDomainDeviceAddressTypeToString(info->type));
 
-switch ((virDomainDeviceAddressType) info->type) {
+switch (info->type) {
 case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI:
 if (!virPCIDeviceAddressIsEmpty(>addr.pci)) {
 virBufferAsprintf(, " domain='0x%04x' bus='0x%02x' "
@@ -5539,21 +5539,14 @@ static int
 virDomainDeviceAddressParseXML(xmlNodePtr address,
virDomainDeviceInfo *info)
 {
-g_autofree char *type = virXMLPropString(address, "type");
-
-if (!type) {
-virReportError(VIR_ERR_INTERNAL_ERROR,
-   "%s", _("No type specified for device address"));
-return -1;
-}
-
-if ((info->type = virDomainDeviceAddressTypeFromString(type)) <= 0) {
-virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-   _("unknown address type '%1$s'"), type);
+if (virXMLPropEnum(address, "type",
+   virDomainDeviceAddressTypeFromString,
+   VIR_XML_PROP_REQUIRED | VIR_XML_PROP_NONZERO,
+   >type) < 0) {
 return -1;
 }
 
-switch ((virDomainDeviceAddressType) info->type) {
+switch (info->type) {
 case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI:
 if (virPCIDeviceAddressParseXML(address, >addr.pci) < 0)
 return -1;
@@ -19625,7 +19618,7 @@ 
virDomainDeviceInfoCheckABIStability(virDomainDeviceInfo *src,
 return false;
 }
 
-switch ((virDomainDeviceAddressType) src->type) {
+switch (src->type) {
 case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI:
 if (src->addr.pci.domain != dst->addr.pci.domain ||
 src->addr.pci.bus != dst->addr.pci.bus ||
diff --git a/src/conf/domain_validate.c b/src/conf/domain_validate.c
index 1d25aa32c2..e70841c1d6 100644
--- a/src/conf/domain_validate.c
+++ b/src/conf/domain_validate.c
@@ -2806,7 +2806,7 @@ virDomainDeviceInfoValidate(const virDomainDeviceDef *dev)
 if (!(info = virDomainDeviceGetInfo(dev)))
 return 0;
 
-switch ((virDomainDeviceAddressType) info->type) {
+switch (info->type) {
 case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI:
 case VIR_DOMAIN_DEVI

[PATCH 17/20] virDomainWatchdogDef: Convert 'action' field to proper enum type

2023-09-14 Thread Michal Privoznik
Convert the field and adjust the XML parser to use
virXMLPropEnumDefault().

Signed-off-by: Michal Privoznik 
---
 src/conf/domain_conf.c | 17 ++---
 src/conf/domain_conf.h |  2 +-
 2 files changed, 7 insertions(+), 12 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 5c1712cb46..f48020f893 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -12065,7 +12065,6 @@ virDomainWatchdogDefParseXML(virDomainXMLOption *xmlopt,
  unsigned int flags)
 {
 virDomainWatchdogDef *def;
-g_autofree char *action = NULL;
 
 def = g_new0(virDomainWatchdogDef, 1);
 
@@ -12076,16 +12075,12 @@ virDomainWatchdogDefParseXML(virDomainXMLOption 
*xmlopt,
 goto error;
 }
 
-action = virXMLPropString(node, "action");
-if (action == NULL) {
-def->action = VIR_DOMAIN_WATCHDOG_ACTION_RESET;
-} else {
-def->action = virDomainWatchdogActionTypeFromString(action);
-if (def->action < 0) {
-virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-   _("unknown watchdog action '%1$s'"), action);
-goto error;
-}
+if (virXMLPropEnumDefault(node, "action",
+  virDomainWatchdogActionTypeFromString,
+  VIR_XML_PROP_NONE,
+  >action,
+  VIR_DOMAIN_WATCHDOG_ACTION_RESET) < 0) {
+goto error;
 }
 
 if (virDomainDeviceInfoParseXML(xmlopt, node, ctxt, >info, flags) < 0)
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index e7c663b0e9..77e5b26957 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -1760,7 +1760,7 @@ typedef enum {
 
 struct _virDomainWatchdogDef {
 virDomainWatchdogModel model;
-int action;
+virDomainWatchdogAction action;
 virDomainDeviceInfo info;
 };
 
-- 
2.41.0



[PATCH 16/20] virDomainWatchdogDef: Convert 'model' field to proper enum type

2023-09-14 Thread Michal Privoznik
Convert the field and adjust the XML parsers to use
virXMLPropEnum().

Signed-off-by: Michal Privoznik 
---
 src/conf/domain_conf.c | 15 ---
 src/conf/domain_conf.h |  2 +-
 src/qemu/qemu_domain_address.c |  2 +-
 src/qemu/qemu_validate.c   |  2 +-
 4 files changed, 7 insertions(+), 14 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 47c4170f29..5c1712cb46 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -12065,21 +12065,14 @@ virDomainWatchdogDefParseXML(virDomainXMLOption 
*xmlopt,
  unsigned int flags)
 {
 virDomainWatchdogDef *def;
-g_autofree char *model = NULL;
 g_autofree char *action = NULL;
 
 def = g_new0(virDomainWatchdogDef, 1);
 
-model = virXMLPropString(node, "model");
-if (model == NULL) {
-virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-   _("watchdog must contain model name"));
-goto error;
-}
-def->model = virDomainWatchdogModelTypeFromString(model);
-if (def->model < 0) {
-virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-   _("unknown watchdog model '%1$s'"), model);
+if (virXMLPropEnum(node, "model",
+   virDomainWatchdogModelTypeFromString,
+   VIR_XML_PROP_REQUIRED,
+   >model) < 0) {
 goto error;
 }
 
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index c9b9fbabd3..e7c663b0e9 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -1759,7 +1759,7 @@ typedef enum {
 } virDomainWatchdogAction;
 
 struct _virDomainWatchdogDef {
-int model;
+virDomainWatchdogModel model;
 int action;
 virDomainDeviceInfo info;
 };
diff --git a/src/qemu/qemu_domain_address.c b/src/qemu/qemu_domain_address.c
index 0ed70e5b86..099778b2a8 100644
--- a/src/qemu/qemu_domain_address.c
+++ b/src/qemu/qemu_domain_address.c
@@ -927,7 +927,7 @@ qemuDomainDeviceCalculatePCIConnectFlags(virDomainDeviceDef 
*dev,
 
 case VIR_DOMAIN_DEVICE_WATCHDOG:
 /* only one model connects using PCI */
-switch ((virDomainWatchdogModel) dev->data.watchdog->model) {
+switch (dev->data.watchdog->model) {
 case VIR_DOMAIN_WATCHDOG_MODEL_I6300ESB:
 return pciFlags;
 
diff --git a/src/qemu/qemu_validate.c b/src/qemu/qemu_validate.c
index fc61c489e9..27fd5b9a99 100644
--- a/src/qemu/qemu_validate.c
+++ b/src/qemu/qemu_validate.c
@@ -2251,7 +2251,7 @@ qemuValidateDomainWatchdogDef(const virDomainWatchdogDef 
*dev,
 return -1;
 }
 
-switch ((virDomainWatchdogModel) dev->model) {
+switch (dev->model) {
 case VIR_DOMAIN_WATCHDOG_MODEL_I6300ESB:
 if (dev->info.type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE &&
 dev->info.type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI) {
-- 
2.41.0



[PATCH 02/20] src: Access hostdev->source.subsys iff VIR_DOMAIN_HOSTDEV_MODE_SUBSYS

2023-09-14 Thread Michal Privoznik
There are few places where a virDomainHostdevDef->source.subsys
is accessed without ->mode being checked. Mind you,
virDomainHostdevDef can be also in
VIR_DOMAIN_HOSTDEV_MODE_CAPABILITIES mode.

Signed-off-by: Michal Privoznik 
---
 src/conf/domain_conf.c| 3 ++-
 src/conf/domain_validate.c| 3 ++-
 src/security/virt-aa-helper.c | 4 
 3 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 1f14ef6f23..9d819c3dab 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -5099,7 +5099,8 @@ virDomainDriveAddressIsUsedByHostdev(const virDomainDef 
*def,
 for (i = 0; i < def->nhostdevs; i++) {
 hostdev = def->hostdevs[i];
 
-if (hostdev->source.subsys.type != type ||
+if (hostdev->mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS ||
+hostdev->source.subsys.type != type ||
 hostdev->info->type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_DRIVE)
 continue;
 
diff --git a/src/conf/domain_validate.c b/src/conf/domain_validate.c
index b050f21edb..53d920b2b3 100644
--- a/src/conf/domain_validate.c
+++ b/src/conf/domain_validate.c
@@ -1283,7 +1283,8 @@ virDomainDefHostdevValidate(const virDomainDef *def)
 }
 }
 
-if (dev->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV &&
+if (dev->mode == VIR_DOMAIN_HOSTDEV_MODE_SUBSYS &&
+dev->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV &&
 dev->source.subsys.u.mdev.ramfb == VIR_TRISTATE_SWITCH_ON) {
 if (ramfbEnabled) {
 virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
diff --git a/src/security/virt-aa-helper.c b/src/security/virt-aa-helper.c
index c50629d096..4638451183 100644
--- a/src/security/virt-aa-helper.c
+++ b/src/security/virt-aa-helper.c
@@ -1049,6 +1049,10 @@ get_files(vahControl * ctl)
 if (ctl->def->hostdevs[i]) {
 virDomainHostdevDef *dev = ctl->def->hostdevs[i];
 virDomainHostdevSubsysUSB *usbsrc = >source.subsys.u.usb;
+
+if (dev->mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS)
+continue;
+
 switch (dev->source.subsys.type) {
 case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB: {
 virUSBDevice *usb =
-- 
2.41.0



[PATCH 15/20] virDomainRNGDef: Convert 'backend' field to proper enum type

2023-09-14 Thread Michal Privoznik
Convert the field and adjust the XML parser to use
virXMLPropEnum().

Signed-off-by: Michal Privoznik 
---
 src/conf/domain_audit.c   |  4 ++--
 src/conf/domain_conf.c| 22 --
 src/conf/domain_conf.h|  2 +-
 src/qemu/qemu_command.c   |  4 ++--
 src/qemu/qemu_namespace.c |  2 +-
 src/qemu/qemu_validate.c  |  2 +-
 6 files changed, 15 insertions(+), 21 deletions(-)

diff --git a/src/conf/domain_audit.c b/src/conf/domain_audit.c
index 4294b50c3a..7a6bb02203 100644
--- a/src/conf/domain_audit.c
+++ b/src/conf/domain_audit.c
@@ -215,7 +215,7 @@ virDomainAuditRNG(virDomainObj *vm,
 const char *oldsrcpath = NULL;
 
 if (newDef) {
-switch ((virDomainRNGBackend) newDef->backend) {
+switch (newDef->backend) {
 case VIR_DOMAIN_RNG_BACKEND_RANDOM:
 newsrcpath = newDef->source.file;
 break;
@@ -231,7 +231,7 @@ virDomainAuditRNG(virDomainObj *vm,
 }
 
 if (oldDef) {
-switch ((virDomainRNGBackend) oldDef->backend) {
+switch (oldDef->backend) {
 case VIR_DOMAIN_RNG_BACKEND_RANDOM:
 oldsrcpath = oldDef->source.file;
 break;
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 3b24d0218d..47c4170f29 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -12116,7 +12116,6 @@ virDomainRNGDefParseXML(virDomainXMLOption *xmlopt,
 VIR_XPATH_NODE_AUTORESTORE(ctxt)
 int nbackends;
 g_autofree xmlNodePtr *backends = NULL;
-g_autofree char *backend = NULL;
 g_autofree char *type = NULL;
 
 def = g_new0(virDomainRNGDef, 1);
@@ -12151,19 +12150,14 @@ virDomainRNGDefParseXML(virDomainXMLOption *xmlopt,
 goto error;
 }
 
-if (!(backend = virXMLPropString(backends[0], "model"))) {
-virReportError(VIR_ERR_XML_ERROR, "%s",
-   _("missing RNG device backend model"));
+if (virXMLPropEnum(backends[0], "model",
+   virDomainRNGBackendTypeFromString,
+   VIR_XML_PROP_REQUIRED,
+   >backend) < 0) {
 goto error;
 }
 
-if ((def->backend = virDomainRNGBackendTypeFromString(backend)) < 0) {
-virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-   _("unknown RNG backend model '%1$s'"), backend);
-goto error;
-}
-
-switch ((virDomainRNGBackend) def->backend) {
+switch (def->backend) {
 case VIR_DOMAIN_RNG_BACKEND_RANDOM:
 def->source.file = virXPathString("string(./backend)", ctxt);
 break;
@@ -15197,7 +15191,7 @@ virDomainRNGFind(virDomainDef *def,
 if (rng->rate != tmp->rate || rng->period != tmp->period)
 continue;
 
-switch ((virDomainRNGBackend) rng->backend) {
+switch (rng->backend) {
 case VIR_DOMAIN_RNG_BACKEND_RANDOM:
 if (STRNEQ_NULLABLE(rng->source.file, tmp->source.file))
 continue;
@@ -25076,7 +25070,7 @@ virDomainRNGDefFormat(virBuffer *buf,
 }
 virBufferAsprintf(buf, "backend) {
+switch (def->backend) {
 case VIR_DOMAIN_RNG_BACKEND_RANDOM:
 virBufferEscapeString(buf, ">%s\n", def->source.file);
 break;
@@ -25117,7 +25111,7 @@ virDomainRNGDefFree(virDomainRNGDef *def)
 if (!def)
 return;
 
-switch ((virDomainRNGBackend) def->backend) {
+switch (def->backend) {
 case VIR_DOMAIN_RNG_BACKEND_RANDOM:
 g_free(def->source.file);
 break;
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index f56c04ce36..c9b9fbabd3 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -2610,7 +2610,7 @@ typedef enum {
 
 struct _virDomainRNGDef {
 virDomainRNGModel model;
-int backend;
+virDomainRNGBackend backend;
 unsigned int rate; /* bytes per period */
 unsigned int period; /* milliseconds */
 
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 17d7bfcfd3..11ede25c0b 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -5361,7 +5361,7 @@ qemuBuildRNGBackendChrdev(virCommand *cmd,
 {
 g_autofree char *charAlias = qemuAliasChardevFromDevAlias(rng->info.alias);
 
-switch ((virDomainRNGBackend) rng->backend) {
+switch (rng->backend) {
 case VIR_DOMAIN_RNG_BACKEND_RANDOM:
 case VIR_DOMAIN_RNG_BACKEND_BUILTIN:
 case VIR_DOMAIN_RNG_BACKEND_LAST:
@@ -5390,7 +5390,7 @@ qemuBuildRNGBackendProps(virDomainRNGDef *rng,
 
 objAlias = g_strdup_printf("obj%s", rng->info.alias);
 
-switch ((virDomainRNGBackend) rng->backend) {
+switch (rng->backend) {
 case VIR_DOMAIN_RNG_BACKEND_RANDOM:
 if (qemuMonitorCreateObjectProps(props, "rng-random", objAlias,
  "s:filename", rng->source.file,
diff --git

[PATCH 11/20] virDomainHostdevCaps: Convert 'type' field to proper enum type

2023-09-14 Thread Michal Privoznik
Convert the field, adjust the XML parsers to use virXMLPropEnum()
and fill in missing cases to switch() statements.

Signed-off-by: Michal Privoznik 
---
 src/conf/domain_audit.c |  2 ++
 src/conf/domain_conf.c  | 29 ++---
 src/conf/domain_conf.h  |  2 +-
 src/lxc/lxc_cgroup.c|  2 ++
 src/lxc/lxc_controller.c|  1 +
 src/lxc/lxc_driver.c|  4 
 src/lxc/lxc_hostdev.c   |  1 +
 src/security/security_selinux.c |  4 
 8 files changed, 29 insertions(+), 16 deletions(-)

diff --git a/src/conf/domain_audit.c b/src/conf/domain_audit.c
index d4d303a214..0bf1768acd 100644
--- a/src/conf/domain_audit.c
+++ b/src/conf/domain_audit.c
@@ -428,6 +428,8 @@ virDomainAuditHostdev(virDomainObj *vm, virDomainHostdevDef 
*hostdev,
   virt, reason, vmname, uuidstr, device);
 break;
 
+case VIR_DOMAIN_HOSTDEV_CAPS_TYPE_NET:
+case VIR_DOMAIN_HOSTDEV_CAPS_TYPE_LAST:
 default:
 VIR_WARN("Unexpected hostdev type while encoding audit message: 
%d",
  hostdev->source.caps.type);
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index c93f89ced6..cf1bd4df74 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -2616,7 +2616,7 @@ virDomainHostdevDefClear(virDomainHostdevDef *def)
 
 switch (def->mode) {
 case VIR_DOMAIN_HOSTDEV_MODE_CAPABILITIES:
-switch ((virDomainHostdevCapsType) def->source.caps.type) {
+switch (def->source.caps.type) {
 case VIR_DOMAIN_HOSTDEV_CAPS_TYPE_STORAGE:
 VIR_FREE(def->source.caps.u.storage.block);
 break;
@@ -6502,7 +6502,7 @@ virDomainNetDefCoalesceFormatXML(virBuffer *buf,
 static int
 virDomainHostdevDefParseXMLCaps(xmlNodePtr node G_GNUC_UNUSED,
 xmlXPathContextPtr ctxt,
-const char *type,
+virDomainHostdevCapsType type,
 virDomainHostdevDef *def)
 {
 /* @type is passed in from the caller rather than read from the
@@ -6513,18 +6513,7 @@ virDomainHostdevDefParseXMLCaps(xmlNodePtr node 
G_GNUC_UNUSED,
  * .  (the functions we're going to call expect address
  * type to already be known).
  */
-if (!type) {
-virReportError(VIR_ERR_XML_ERROR,
-   "%s", _("missing source address type"));
-return -1;
-}
-
-if ((def->source.caps.type = virDomainHostdevCapsTypeFromString(type)) < 
0) {
-virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-   _("unknown host device source address type '%1$s'"),
-   type);
-return -1;
-}
+def->source.caps.type = type;
 
 if (!virXPathNode("./source", ctxt)) {
 virReportError(VIR_ERR_XML_ERROR, "%s",
@@ -6560,6 +6549,7 @@ virDomainHostdevDefParseXMLCaps(xmlNodePtr node 
G_GNUC_UNUSED,
ctxt, >source.caps.u.net.ip) < 0)
 return -1;
 break;
+case VIR_DOMAIN_HOSTDEV_CAPS_TYPE_LAST:
 default:
 virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("address type='%1$s' not supported in hostdev 
interfaces"),
@@ -12920,6 +12910,7 @@ virDomainHostdevDefParseXML(virDomainXMLOption *xmlopt,
 virDomainHostdevDef *def;
 VIR_XPATH_NODE_AUTORESTORE(ctxt)
 g_autofree char *type = virXMLPropString(node, "type");
+unsigned int typeU;
 
 ctxt->node = node;
 
@@ -12940,7 +12931,12 @@ virDomainHostdevDefParseXML(virDomainXMLOption *xmlopt,
 break;
 case VIR_DOMAIN_HOSTDEV_MODE_CAPABILITIES:
 /* parse managed/mode/type, and the  element */
-if (virDomainHostdevDefParseXMLCaps(node, ctxt, type, def) < 0)
+if (virXMLPropEnum(node, "type",
+   virDomainHostdevCapsTypeFromString,
+   VIR_XML_PROP_REQUIRED, ) < 0)
+goto error;
+
+if (virDomainHostdevDefParseXMLCaps(node, ctxt, typeU, def) < 0)
 goto error;
 break;
 default:
@@ -14163,6 +14159,8 @@ virDomainHostdevMatchCaps(virDomainHostdevDef *a,
 return virDomainHostdevMatchCapsMisc(a, b);
 case VIR_DOMAIN_HOSTDEV_CAPS_TYPE_NET:
 return virDomainHostdevMatchCapsNet(a, b);
+case VIR_DOMAIN_HOSTDEV_CAPS_TYPE_LAST:
+break;
 }
 return 0;
 }
@@ -23486,6 +23484,7 @@ virDomainHostdevDefFormatCaps(virBuffer *buf,
 virBufferEscapeString(buf, "%s\n",
   def->source.caps.u.net.ifname);
 break;
+case VIR_DOMAIN_HOSTDEV_CAPS_TYPE_LAST:
 default:
 virReportError(VIR_ERR_INTERNAL_ERROR,
_("unexpected hostdev type %1$d"),
diff --git a/src/conf/domai

[PATCH 14/20] virDomainRNGDef: Convert 'model' field to proper enum type

2023-09-14 Thread Michal Privoznik
Convert the field and adjust the XML parser to use
virXMLPropEnum().

Signed-off-by: Michal Privoznik 
---
 src/conf/domain_conf.c | 13 -
 src/conf/domain_conf.h |  2 +-
 src/qemu/qemu_domain_address.c |  2 +-
 3 files changed, 6 insertions(+), 11 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 95a71b204f..3b24d0218d 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -12116,21 +12116,16 @@ virDomainRNGDefParseXML(virDomainXMLOption *xmlopt,
 VIR_XPATH_NODE_AUTORESTORE(ctxt)
 int nbackends;
 g_autofree xmlNodePtr *backends = NULL;
-g_autofree char *model = NULL;
 g_autofree char *backend = NULL;
 g_autofree char *type = NULL;
 
 def = g_new0(virDomainRNGDef, 1);
 
-if (!(model = virXMLPropString(node, "model"))) {
-virReportError(VIR_ERR_XML_ERROR, "%s", _("missing RNG device model"));
+if (virXMLPropEnum(node, "model",
+   virDomainRNGModelTypeFromString,
+   VIR_XML_PROP_REQUIRED,
+   >model) < 0)
 goto error;
-}
-
-if ((def->model = virDomainRNGModelTypeFromString(model)) < 0) {
-virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("unknown RNG model 
'%1$s'"), model);
-goto error;
-}
 
 ctxt->node = node;
 
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 9dadda2d1d..f56c04ce36 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -2609,7 +2609,7 @@ typedef enum {
 } virDomainRNGBackend;
 
 struct _virDomainRNGDef {
-int model;
+virDomainRNGModel model;
 int backend;
 unsigned int rate; /* bytes per period */
 unsigned int period; /* milliseconds */
diff --git a/src/qemu/qemu_domain_address.c b/src/qemu/qemu_domain_address.c
index 2e58930eec..0ed70e5b86 100644
--- a/src/qemu/qemu_domain_address.c
+++ b/src/qemu/qemu_domain_address.c
@@ -912,7 +912,7 @@ qemuDomainDeviceCalculatePCIConnectFlags(virDomainDeviceDef 
*dev,
 break;
 
 case VIR_DOMAIN_DEVICE_RNG:
-switch ((virDomainRNGModel) dev->data.rng->model) {
+switch (dev->data.rng->model) {
 case VIR_DOMAIN_RNG_MODEL_VIRTIO_TRANSITIONAL:
 /* Transitional devices only work in conventional PCI slots */
 return pciFlags;
-- 
2.41.0



[PATCH 07/20] src: Drop needless typecast to virDomainDiskBus

2023-09-14 Thread Michal Privoznik
The 'bus' member of _virDomainDiskDef is already declared of
virDomainDiskModel type. Hence, there is no need to typecast the
variable when passing to switch() statements.

Signed-off-by: Michal Privoznik 
---
 src/qemu/qemu_alias.c  | 2 +-
 src/qemu/qemu_command.c| 4 ++--
 src/qemu/qemu_domain_address.c | 2 +-
 src/qemu/qemu_hotplug.c| 4 ++--
 src/qemu/qemu_validate.c   | 4 ++--
 src/vbox/vbox_common.c | 2 +-
 6 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/src/qemu/qemu_alias.c b/src/qemu/qemu_alias.c
index 161d30cf72..e58c488f8a 100644
--- a/src/qemu/qemu_alias.c
+++ b/src/qemu/qemu_alias.c
@@ -244,7 +244,7 @@ qemuAssignDeviceDiskAlias(virDomainDef *def,
  * need the full path into /machine/peripheral as a historical artifact.
  */
 if (!diskPriv->qomName) {
-switch ((virDomainDiskBus) disk->bus) {
+switch (disk->bus) {
 case VIR_DOMAIN_DISK_BUS_FDC:
 case VIR_DOMAIN_DISK_BUS_IDE:
 case VIR_DOMAIN_DISK_BUS_SATA:
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 6de0bdf977..be5814663c 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -409,7 +409,7 @@ qemuBuildDeviceAddresDriveProps(virJSONValue *props,
 virDomainControllerDef *controller = NULL;
 const char *controllerAlias = NULL;
 
-switch ((virDomainDiskBus) info->addr.drive.diskbus) {
+switch (info->addr.drive.diskbus) {
 case VIR_DOMAIN_DISK_BUS_IDE:
 /* When domain has builtin IDE controller we don't put it onto cmd
  * line. Therefore we can't set its alias. In that case, use the
@@ -1770,7 +1770,7 @@ qemuBuildDiskDeviceProps(const virDomainDef *def,
 const char *wpolicy = NULL;
 const char *rpolicy = NULL;
 
-switch ((virDomainDiskBus) disk->bus) {
+switch (disk->bus) {
 case VIR_DOMAIN_DISK_BUS_IDE:
 case VIR_DOMAIN_DISK_BUS_SATA:
 if (disk->device == VIR_DOMAIN_DISK_DEVICE_CDROM)
diff --git a/src/qemu/qemu_domain_address.c b/src/qemu/qemu_domain_address.c
index 0875ed0401..00742d3c0e 100644
--- a/src/qemu/qemu_domain_address.c
+++ b/src/qemu/qemu_domain_address.c
@@ -790,7 +790,7 @@ qemuDomainDeviceCalculatePCIConnectFlags(virDomainDeviceDef 
*dev,
 break;
 
 case VIR_DOMAIN_DEVICE_DISK:
-switch ((virDomainDiskBus) dev->data.disk->bus) {
+switch (dev->data.disk->bus) {
 case VIR_DOMAIN_DISK_BUS_VIRTIO:
 /* only virtio disks use PCI */
 switch (dev->data.disk->model) {
diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index 0d5f253bb9..d4f01cfd93 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -926,7 +926,7 @@ qemuDomainAttachDeviceDiskLiveInternal(virQEMUDriver 
*driver,
 goto cleanup;
 }
 
-switch ((virDomainDiskBus) disk->bus) {
+switch (disk->bus) {
 case VIR_DOMAIN_DISK_BUS_USB:
 if (disk->device == VIR_DOMAIN_DISK_DEVICE_LUN) {
 virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
@@ -5468,7 +5468,7 @@ qemuDomainDetachPrepDisk(virDomainObj *vm,
 case VIR_DOMAIN_DISK_DEVICE_DISK:
 case VIR_DOMAIN_DISK_DEVICE_LUN:
 
-switch ((virDomainDiskBus) disk->bus) {
+switch (disk->bus) {
 case VIR_DOMAIN_DISK_BUS_VIRTIO:
 case VIR_DOMAIN_DISK_BUS_USB:
 case VIR_DOMAIN_DISK_BUS_SCSI:
diff --git a/src/qemu/qemu_validate.c b/src/qemu/qemu_validate.c
index 3b57fa3c21..18d34e7f59 100644
--- a/src/qemu/qemu_validate.c
+++ b/src/qemu/qemu_validate.c
@@ -1371,7 +1371,7 @@ 
qemuValidateDomainDeviceDefAddressDrive(virDomainDeviceInfo *info,
 {
 virDomainControllerDef *controller = NULL;
 
-switch ((virDomainDiskBus) info->addr.drive.diskbus) {
+switch (info->addr.drive.diskbus) {
 case VIR_DOMAIN_DISK_BUS_SCSI:
 /* Setting bus= attr for SCSI drives, causes a controller
  * to be created. Yes this is slightly odd. It is not possible
@@ -2673,7 +2673,7 @@ static bool
 qemuValidateDomainDeviceDefDiskIOThreads(const virDomainDef *def,
  const virDomainDiskDef *disk)
 {
-switch ((virDomainDiskBus)disk->bus) {
+switch (disk->bus) {
 case VIR_DOMAIN_DISK_BUS_VIRTIO:
 break;
 
diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c
index dba4af1a44..490f337a56 100644
--- a/src/vbox/vbox_common.c
+++ b/src/vbox/vbox_common.c
@@ -1206,7 +1206,7 @@ vboxAttachDrives(virDomainDef *def, struct _vboxDriver 
*data, IMachine *machine)
 goto cleanup;
 }
 
-switch ((virDomainDiskBus) disk->bus) {
+switch (disk->bus) {
 case VIR_DOMAIN_DISK_BUS_IDE:
 VBOX_UTF8_TO_UTF16(VBOX_CONTROLLER_IDE_NAME, );
 devicePort = def->disks[i]->info.addr.drive.bus;
-- 
2.41.0



[PATCH 09/20] virDomainHostdevSubsysSCSIVHost: Convert 'protocol' field to proper enum type

2023-09-14 Thread Michal Privoznik
Convert the field and adjust the XML parser to use
virXMLPropEnum().

Signed-off-by: Michal Privoznik 
---
 src/conf/domain_conf.c | 17 +
 src/conf/domain_conf.h |  4 ++--
 2 files changed, 7 insertions(+), 14 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index ef5f02a23b..65b7b44ccb 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -6095,24 +6095,17 @@ virDomainHostdevSubsysSCSIVHostDefParseXML(xmlNodePtr 
sourcenode,
virDomainHostdevDef *def)
 {
 virDomainHostdevSubsysSCSIVHost *hostsrc = >source.subsys.u.scsi_host;
-g_autofree char *protocol = NULL;
 g_autofree char *wwpn = NULL;
 
-if (!(protocol = virXMLPropString(sourcenode, "protocol"))) {
-virReportError(VIR_ERR_XML_ERROR, "%s",
-   _("Missing scsi_host subsystem protocol"));
-return -1;
-}
 
-if ((hostsrc->protocol =
- virDomainHostdevSubsysSCSIHostProtocolTypeFromString(protocol)) <= 0) 
{
-virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-   _("Unknown scsi_host subsystem protocol '%1$s'"),
-   protocol);
+if (virXMLPropEnum(sourcenode, "protocol",
+   virDomainHostdevSubsysSCSIHostProtocolTypeFromString,
+   VIR_XML_PROP_REQUIRED | VIR_XML_PROP_NONZERO,
+   >protocol) < 0) {
 return -1;
 }
 
-switch ((virDomainHostdevSubsysSCSIHostProtocolType) hostsrc->protocol) {
+switch (hostsrc->protocol) {
 case VIR_DOMAIN_HOSTDEV_SUBSYS_SCSI_HOST_PROTOCOL_TYPE_VHOST:
 if (!(wwpn = virXMLPropString(sourcenode, "wwpn"))) {
 virReportError(VIR_ERR_XML_ERROR, "%s",
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 5cce60420f..d6d0799f63 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -290,7 +290,7 @@ struct _virDomainHostdevSubsysMediatedDev {
 };
 
 typedef enum {
-VIR_DOMAIN_HOSTDEV_SUBSYS_SCSI_HOST_PROTOCOL_TYPE_NONE,
+VIR_DOMAIN_HOSTDEV_SUBSYS_SCSI_HOST_PROTOCOL_TYPE_NONE = 0,
 VIR_DOMAIN_HOSTDEV_SUBSYS_SCSI_HOST_PROTOCOL_TYPE_VHOST,
 
 VIR_DOMAIN_HOSTDEV_SUBSYS_SCSI_HOST_PROTOCOL_TYPE_LAST,
@@ -310,7 +310,7 @@ typedef enum {
 VIR_ENUM_DECL(virDomainHostdevSubsysSCSIVHostModel);
 
 struct _virDomainHostdevSubsysSCSIVHost {
-int protocol; /* enum virDomainHostdevSubsysSCSIHostProtocolType */
+virDomainHostdevSubsysSCSIHostProtocolType protocol;
 char *wwpn;
 virDomainHostdevSubsysSCSIVHostModelType model;
 };
-- 
2.41.0



[PATCH 06/20] qemu_domain_address: Drop needless typecast to virDomainDiskModel

2023-09-14 Thread Michal Privoznik
The 'mode' member of _virDomainDiskDef is already declared of
virDomainDiskModel type. Hence, there is no need to typecast the
variable when passing to switch() statements.

Signed-off-by: Michal Privoznik 
---
 src/qemu/qemu_domain_address.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/qemu/qemu_domain_address.c b/src/qemu/qemu_domain_address.c
index 38411b4872..0875ed0401 100644
--- a/src/qemu/qemu_domain_address.c
+++ b/src/qemu/qemu_domain_address.c
@@ -793,7 +793,7 @@ qemuDomainDeviceCalculatePCIConnectFlags(virDomainDeviceDef 
*dev,
 switch ((virDomainDiskBus) dev->data.disk->bus) {
 case VIR_DOMAIN_DISK_BUS_VIRTIO:
 /* only virtio disks use PCI */
-switch ((virDomainDiskModel) dev->data.disk->model) {
+switch (dev->data.disk->model) {
 case VIR_DOMAIN_DISK_MODEL_VIRTIO_TRANSITIONAL:
 /* Transitional devices only work in conventional PCI slots */
 return pciFlags;
-- 
2.41.0



[PATCH 05/20] src: Drop needless typecast to virDomainDeviceType

2023-09-14 Thread Michal Privoznik
The 'type' member of _virDomainDeviceDef is already declared of
virDomainDeviceType type. Hence, there is no need to typecast the
variable when passing to switch() statements.

Signed-off-by: Michal Privoznik 
---
 src/ch/ch_domain.c |  2 +-
 src/conf/domain_conf.c |  8 
 src/conf/domain_postparse.c|  2 +-
 src/conf/domain_validate.c |  2 +-
 src/qemu/qemu_command.c|  2 +-
 src/qemu/qemu_domain.c |  6 +++---
 src/qemu/qemu_domain_address.c |  4 ++--
 src/qemu/qemu_driver.c |  6 +++---
 src/qemu/qemu_hotplug.c| 10 +-
 src/qemu/qemu_validate.c   |  2 +-
 10 files changed, 22 insertions(+), 22 deletions(-)

diff --git a/src/ch/ch_domain.c b/src/ch/ch_domain.c
index d6b64b6c59..866f0d899a 100644
--- a/src/ch/ch_domain.c
+++ b/src/ch/ch_domain.c
@@ -146,7 +146,7 @@ chValidateDomainDeviceDef(const virDomainDeviceDef *dev,
   void *opaque G_GNUC_UNUSED,
   void *parseOpaque G_GNUC_UNUSED)
 {
-switch ((virDomainDeviceType)dev->type) {
+switch (dev->type) {
 case VIR_DOMAIN_DEVICE_DISK:
 case VIR_DOMAIN_DEVICE_NET:
 case VIR_DOMAIN_DEVICE_MEMORY:
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 9d819c3dab..306547e798 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -3520,7 +3520,7 @@ void virDomainDeviceDefFree(virDomainDeviceDef *def)
 if (!def)
 return;
 
-switch ((virDomainDeviceType) def->type) {
+switch (def->type) {
 case VIR_DOMAIN_DEVICE_DISK:
 virDomainDiskDefFree(def->data.disk);
 break;
@@ -4468,7 +4468,7 @@ virDomainObjGetOneDef(virDomainObj *vm,
 virDomainDeviceInfo *
 virDomainDeviceGetInfo(const virDomainDeviceDef *device)
 {
-switch ((virDomainDeviceType) device->type) {
+switch (device->type) {
 case VIR_DOMAIN_DEVICE_DISK:
 return >data.disk->info;
 case VIR_DOMAIN_DEVICE_FS:
@@ -4541,7 +4541,7 @@ void
 virDomainDeviceSetData(virDomainDeviceDef *device,
void *devicedata)
 {
-switch ((virDomainDeviceType) device->type) {
+switch (device->type) {
 case VIR_DOMAIN_DEVICE_DISK:
 device->data.disk = devicedata;
 break;
@@ -13777,7 +13777,7 @@ virDomainDeviceDefParse(const char *xmlStr,
 if (virDomainDeviceDefParseType((const char *)node->name, >type) < 0)
 return NULL;
 
-switch ((virDomainDeviceType) dev->type) {
+switch (dev->type) {
 case VIR_DOMAIN_DEVICE_DISK:
 if (!(dev->data.disk = virDomainDiskDefParseXML(xmlopt, node, ctxt,
 flags)))
diff --git a/src/conf/domain_postparse.c b/src/conf/domain_postparse.c
index b76e8dcc5c..e79913b73f 100644
--- a/src/conf/domain_postparse.c
+++ b/src/conf/domain_postparse.c
@@ -684,7 +684,7 @@ virDomainDeviceDefPostParseCommon(virDomainDeviceDef *dev,
 {
 int ret = -1;
 
-switch ((virDomainDeviceType)dev->type) {
+switch (dev->type) {
 case VIR_DOMAIN_DEVICE_CHR:
 ret = virDomainChrDefPostParse(dev->data.chr, def);
 break;
diff --git a/src/conf/domain_validate.c b/src/conf/domain_validate.c
index 53d920b2b3..a8f90af3aa 100644
--- a/src/conf/domain_validate.c
+++ b/src/conf/domain_validate.c
@@ -2847,7 +2847,7 @@ virDomainDeviceDefValidateInternal(const 
virDomainDeviceDef *dev,
 if (virDomainDeviceInfoValidate(dev) < 0)
 return -1;
 
-switch ((virDomainDeviceType) dev->type) {
+switch (dev->type) {
 case VIR_DOMAIN_DEVICE_DISK:
 return virDomainDiskDefValidate(def, dev->data.disk);
 
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index f9e4de9bd7..6de0bdf977 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -796,7 +796,7 @@ qemuBuildVirtioDevGetConfigDev(const virDomainDeviceDef 
*device,
bool *has_ntmodel,
bool *useBusSuffix)
 {
-switch ((virDomainDeviceType) device->type) {
+switch (device->type) {
 case VIR_DOMAIN_DEVICE_DISK:
 if (virStorageSourceGetActualType(device->data.disk->src) == 
VIR_STORAGE_TYPE_VHOST_USER)
 *baseName = "vhost-user-blk";
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 52ea8f649d..e578df624b 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -6175,7 +6175,7 @@ qemuDomainDeviceDefPostParse(virDomainDeviceDef *dev,
 virQEMUCaps *qemuCaps = parseOpaque;
 int ret = -1;
 
-switch ((virDomainDeviceType) dev->type) {
+switch (dev->type) {
 case VIR_DOMAIN_DEVICE_NET:
 ret = qemuDomainDeviceNetDefPostParse(dev->data.net, def, qemuCaps);
 break;
@@ -10297,7 +10297,7 @@ qemuDomainPrepareChardevSourceOne(virDomainDeviceDef 
*dev,
 struct qemuDomainPrepareChardevSour

[PATCH 03/20] qemu_domain_address: Drop needless typecast in qemuDomainDeviceCalculatePCIConnectFlags()

2023-09-14 Thread Michal Privoznik
Inside of qemuDomainDeviceCalculatePCIConnectFlags() there's a
switch() which typecasts a variable of
virDomainHostdevSubsysSCSIVHostModelType type to the very same
type. This is useless.

Signed-off-by: Michal Privoznik 
---
 src/qemu/qemu_domain_address.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/qemu/qemu_domain_address.c b/src/qemu/qemu_domain_address.c
index e26dc38f76..e5f0a9e883 100644
--- a/src/qemu/qemu_domain_address.c
+++ b/src/qemu/qemu_domain_address.c
@@ -864,7 +864,7 @@ qemuDomainDeviceCalculatePCIConnectFlags(virDomainDeviceDef 
*dev,
  * are the same as virtio-scsi, so they should follow virtio logic
  */
 if (hostdev->source.subsys.type == 
VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI_HOST) {
-switch ((virDomainHostdevSubsysSCSIVHostModelType) 
hostdev->source.subsys.u.scsi_host.model) {
+switch (hostdev->source.subsys.u.scsi_host.model) {
 case 
VIR_DOMAIN_HOSTDEV_SUBSYS_SCSI_VHOST_MODEL_TYPE_VIRTIO_TRANSITIONAL:
 /* Transitional devices only work in conventional PCI slots */
 return pciFlags;
-- 
2.41.0



[PATCH 00/20] Misc cleanups (pt. 1)

2023-09-14 Thread Michal Privoznik
I had these sitting on a local branch for a while. My initial plan was
to use virXMLPropEnum() more and while working on that I found one bug
(patch 01/20), one improvement (patch 02/20) and a couple of useless
typecats.

Michal Prívozník (20):
  lxc_controller: Access correct union member in
virLXCControllerSetupHostdevCaps()
  src: Access hostdev->source.subsys iff VIR_DOMAIN_HOSTDEV_MODE_SUBSYS
  qemu_domain_address: Drop needless typecast in
qemuDomainDeviceCalculatePCIConnectFlags()
  qemu: Drop needless typecast to virDomainFSDriverType
  src: Drop needless typecast to virDomainDeviceType
  qemu_domain_address: Drop needless typecast to virDomainDiskModel
  src: Drop needless typecast to virDomainDiskBus
  virDomainHostdevSubsysSCSI: Convert 'protocol' field to proper enum
type
  virDomainHostdevSubsysSCSIVHost: Convert 'protocol' field to proper
enum type
  virDomainHostdevDef: Convert 'mode' field to proper enum type
  virDomainHostdevCaps: Convert 'type' field to proper enum type
  virDomainHostdevSubsys: Convert 'type' field to proper enum type
  virDomainControllerDef: Convert 'type' field to proper enum type
  virDomainRNGDef: Convert 'model' field to proper enum type
  virDomainRNGDef: Convert 'backend' field to proper enum type
  virDomainWatchdogDef: Convert 'model' field to proper enum type
  virDomainWatchdogDef: Convert 'action' field to proper enum type
  virDomainDeviceInfo: Convert 'type' field to proper enum type
  virStorageNetHostDef: Convert 'transport' field to proper enum type
  virDomainDiskSourceNVMeParse: Use virXMLPropULongLong()

 src/ch/ch_domain.c|   2 +-
 src/conf/device_conf.c|  12 +-
 src/conf/device_conf.h|   4 +-
 src/conf/domain_audit.c   |  10 +-
 src/conf/domain_conf.c| 291 --
 src/conf/domain_conf.h|  29 +-
 src/conf/domain_postparse.c   |   2 +-
 src/conf/domain_validate.c|   9 +-
 src/conf/storage_source_conf.h|   2 +-
 src/libxl/libxl_driver.c  |  12 +
 src/lxc/lxc_cgroup.c  |   3 +
 src/lxc/lxc_controller.c  |   9 +-
 src/lxc/lxc_driver.c  |  16 +
 src/lxc/lxc_hostdev.c |   7 +
 src/qemu/qemu_alias.c |   2 +-
 src/qemu/qemu_backup.c|   2 +-
 src/qemu/qemu_block.c |   2 +-
 src/qemu/qemu_command.c   |  26 +-
 src/qemu/qemu_domain.c|  18 +-
 src/qemu/qemu_domain_address.c|  28 +-
 src/qemu/qemu_driver.c|   6 +-
 src/qemu/qemu_hotplug.c   |  22 +-
 src/qemu/qemu_migration.c |   4 +-
 src/qemu/qemu_monitor.c   |  12 +
 src/qemu/qemu_monitor_json.c  |   2 +-
 src/qemu/qemu_namespace.c |   2 +-
 src/qemu/qemu_validate.c  |  18 +-
 src/security/security_apparmor.c  |   2 +-
 src/security/security_dac.c   |   4 +-
 src/security/security_selinux.c   |  10 +-
 src/security/virt-aa-helper.c |   7 +
 .../storage_file_backend_gluster.c|   2 +-
 .../storage_source_backingstore.c |  15 +-
 src/vbox/vbox_common.c|   4 +-
 34 files changed, 333 insertions(+), 263 deletions(-)

-- 
2.41.0



[PATCH 04/20] qemu: Drop needless typecast to virDomainFSDriverType

2023-09-14 Thread Michal Privoznik
The 'fsdriver' member of _virDomainFSDef is already declared of
virDomainFSDriverType type. Hence, there is no need to typecast
the variable when passing to switch() statements.

Signed-off-by: Michal Privoznik 
---
 src/qemu/qemu_command.c| 4 ++--
 src/qemu/qemu_domain_address.c | 2 +-
 src/qemu/qemu_validate.c   | 2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index e84374b4cf..f9e4de9bd7 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -831,7 +831,7 @@ qemuBuildVirtioDevGetConfigDev(const virDomainDeviceDef 
*device,
 break;
 
 case VIR_DOMAIN_DEVICE_FS:
-switch ((virDomainFSDriverType) device->data.fs->fsdriver) {
+switch (device->data.fs->fsdriver) {
 case VIR_DOMAIN_FS_DRIVER_TYPE_DEFAULT:
 case VIR_DOMAIN_FS_DRIVER_TYPE_PATH:
 case VIR_DOMAIN_FS_DRIVER_TYPE_HANDLE:
@@ -2434,7 +2434,7 @@ qemuBuildFilesystemCommandLine(virCommand *cmd,
 size_t i;
 
 for (i = 0; i < def->nfss; i++) {
-switch ((virDomainFSDriverType) def->fss[i]->fsdriver) {
+switch (def->fss[i]->fsdriver) {
 case VIR_DOMAIN_FS_DRIVER_TYPE_DEFAULT:
 case VIR_DOMAIN_FS_DRIVER_TYPE_PATH:
 case VIR_DOMAIN_FS_DRIVER_TYPE_HANDLE:
diff --git a/src/qemu/qemu_domain_address.c b/src/qemu/qemu_domain_address.c
index e5f0a9e883..01f44a4991 100644
--- a/src/qemu/qemu_domain_address.c
+++ b/src/qemu/qemu_domain_address.c
@@ -707,7 +707,7 @@ qemuDomainDeviceCalculatePCIConnectFlags(virDomainDeviceDef 
*dev,
 break;
 
 case VIR_DOMAIN_DEVICE_FS:
-switch ((virDomainFSDriverType) dev->data.fs->fsdriver) {
+switch (dev->data.fs->fsdriver) {
 case VIR_DOMAIN_FS_DRIVER_TYPE_DEFAULT:
 case VIR_DOMAIN_FS_DRIVER_TYPE_PATH:
 case VIR_DOMAIN_FS_DRIVER_TYPE_HANDLE:
diff --git a/src/qemu/qemu_validate.c b/src/qemu/qemu_validate.c
index 5bae56b00f..c7deac6251 100644
--- a/src/qemu/qemu_validate.c
+++ b/src/qemu/qemu_validate.c
@@ -4286,7 +4286,7 @@ qemuValidateDomainDeviceDefFS(virDomainFSDef *fs,
 return -1;
 }
 
-switch ((virDomainFSDriverType) fs->fsdriver) {
+switch (fs->fsdriver) {
 case VIR_DOMAIN_FS_DRIVER_TYPE_DEFAULT:
 case VIR_DOMAIN_FS_DRIVER_TYPE_PATH:
 break;
-- 
2.41.0



[PATCH 2/2] virutil: Check retval of capng_apply()

2023-09-11 Thread Michal Privoznik
Inside of virSetUIDGIDWithCaps() there's a naked call to
capng_apply(), i.e. without any retval check. This is potentially
dangerous as capng_apply() may fail. Do the check and report an
error.

This also fixes the build on bleeding edge distros - like Fedora
rawhide - where the function is declared with 'warn unused
result' [1].

1: 
https://github.com/stevegrubb/libcap-ng/commit/a0743c335c9a16a2fda9b25120a5523742119e47

Signed-off-by: Michal Privoznik 
---
 src/util/virutil.c | 8 ++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/src/util/virutil.c b/src/util/virutil.c
index b5b65fb415..edc39b981f 100644
--- a/src/util/virutil.c
+++ b/src/util/virutil.c
@@ -1200,8 +1200,12 @@ virSetUIDGIDWithCaps(uid_t uid, gid_t gid, gid_t 
*groups, int ngroups,
  * do this if we failed to get the capability above, so ignore the
  * return value.
  */
-if (!need_setpcap)
-capng_apply(CAPNG_SELECT_BOUNDS);
+if (!need_setpcap &&
+(capng_ret = capng_apply(CAPNG_SELECT_BOUNDS)) < 0) {
+virReportError(VIR_ERR_INTERNAL_ERROR,
+   _("cannot apply process capabilities %1$d"), capng_ret);
+return -1;
+}
 
 /* Drop the caps that allow setuid/gid (unless they were requested) */
 if (need_setgid)
-- 
2.41.0



[PATCH 1/2] lxc_container: Check retval of capng_get_caps_process()

2023-09-11 Thread Michal Privoznik
Added in v0.6.5~14 the call to capng_get_caps_process() inside of
lxcContainerDropCapabilities() is not really explained in the
commit message. But looking into the libcap-ng sources it's to
initialize the internal state of the library.

But with recent libcap-ng commit [1] (which some bleeding edge
distros - like Fedora rawhide - already picked up) the function
has been marked as 'warn unused result'. Well, check for its
retval then.

1: 
https://github.com/stevegrubb/libcap-ng/commit/a0743c335c9a16a2fda9b25120a5523742119e47

Signed-off-by: Michal Privoznik 
---
 src/lxc/lxc_container.c | 8 +++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/src/lxc/lxc_container.c b/src/lxc/lxc_container.c
index 21220661f7..4c37fcd012 100644
--- a/src/lxc/lxc_container.c
+++ b/src/lxc/lxc_container.c
@@ -1725,7 +1725,13 @@ static int lxcContainerDropCapabilities(virDomainDef 
*def,
 CAP_SYSLOG,
 CAP_WAKE_ALARM};
 
-capng_get_caps_process();
+/* Init the internal state of capng */
+if ((ret = capng_get_caps_process()) < 0) {
+virReportError(VIR_ERR_INTERNAL_ERROR,
+   _("Failed to get current process capabilities %1$d"),
+   ret);
+return -1;
+}
 
 /* Make sure we drop everything if required by the user */
 if (policy == VIR_DOMAIN_CAPABILITIES_POLICY_DENY)
-- 
2.41.0



[PATCH 0/2] Check for capng_*() retvals

2023-09-11 Thread Michal Privoznik
There's a commit inside of (yet-unreleased) libcap-ng which marks some
functions as 'warned unused result'. Fedora rawhide already picked up
the commit, but since we are not checking for all retvals we got a build
failure on rawhide.

https://src.fedoraproject.org/rpms/libcap-ng/c/fed9b23c8d0020e07c937a3ac0d6dcc4534715fb?branch=rawhide

Green pipeline:

https://gitlab.com/MichalPrivoznik/libvirt/-/pipelines/999435445

Michal Prívozník (2):
  lxc_container: Check retval of capng_get_caps_process()
  virutil: Check retval of capng_apply()

 src/lxc/lxc_container.c | 8 +++-
 src/util/virutil.c  | 8 ++--
 2 files changed, 13 insertions(+), 3 deletions(-)

-- 
2.41.0



[PATCH] virnetdevopenvswitch: Propagate OVS error messages

2023-09-08 Thread Michal Privoznik
When configuring OVS interfaces/bridges we spawn 'ovs-vsctl' with
appropriate arguments and if it exited with a non-zero status we
report a generic error message, like "Unable to add port vnet0 to
OVS bridge ovsbr0". This is all cool, but the real reason why
operation failed is hidden in (debug) logs because that's where
virCommandRun() reports it unless caller requested otherwise.

This is a bit clumsy because then we have to ask users to turn on
debug logs and reproduce the problem again, e.g. [1].

Therefore, in cases where an error is reported to the user - just
read ovs-vsctl's stderr and include it in the error message. For
other cases (like VIR_DEBUG/VIR_WARN) - well they are meant to
end up in (debug) logs anyway.

1: https://mail.openvswitch.org/pipermail/ovs-discuss/2023-September/052640.html
Signed-off-by: Michal Privoznik 
---
 src/util/virnetdevopenvswitch.c | 93 -
 1 file changed, 58 insertions(+), 35 deletions(-)

diff --git a/src/util/virnetdevopenvswitch.c b/src/util/virnetdevopenvswitch.c
index 8dad6ed2bd..d836d05845 100644
--- a/src/util/virnetdevopenvswitch.c
+++ b/src/util/virnetdevopenvswitch.c
@@ -54,10 +54,14 @@ virNetDevOpenvswitchSetTimeout(unsigned int timeout)
 }
 
 static virCommand *
-virNetDevOpenvswitchCreateCmd(void)
+virNetDevOpenvswitchCreateCmd(char **errbuf)
 {
 virCommand *cmd = virCommandNew(OVS_VSCTL);
+
 virCommandAddArgFormat(cmd, "--timeout=%u", virNetDevOpenvswitchTimeout);
+if (errbuf)
+virCommandSetErrorBuffer(cmd, errbuf);
+
 return cmd;
 }
 
@@ -137,6 +141,7 @@ int virNetDevOpenvswitchAddPort(const char *brname, const 
char *ifname,
 char ifuuidstr[VIR_UUID_STRING_BUFLEN];
 char vmuuidstr[VIR_UUID_STRING_BUFLEN];
 g_autoptr(virCommand) cmd = NULL;
+g_autofree char *errbuf = NULL;
 g_autofree char *attachedmac_ex_id = NULL;
 g_autofree char *ifaceid_ex_id = NULL;
 g_autofree char *profile_ex_id = NULL;
@@ -157,7 +162,7 @@ int virNetDevOpenvswitchAddPort(const char *brname, const 
char *ifname,
 ovsport->profileID);
 }
 
-cmd = virNetDevOpenvswitchCreateCmd();
+cmd = virNetDevOpenvswitchCreateCmd();
 virCommandAddArgList(cmd, "--", "--may-exist",
  "add-port", brname, ifname, NULL);
 
@@ -185,8 +190,8 @@ int virNetDevOpenvswitchAddPort(const char *brname, const 
char *ifname,
 
 if (virCommandRun(cmd, NULL) < 0) {
 virReportError(VIR_ERR_INTERNAL_ERROR,
-   _("Unable to add port %1$s to OVS bridge %2$s"),
-   ifname, brname);
+   _("Unable to add port %1$s to OVS bridge %2$s: %3$s"),
+   ifname, brname, NULLSTR(errbuf));
 return -1;
 }
 
@@ -203,13 +208,15 @@ int virNetDevOpenvswitchAddPort(const char *brname, const 
char *ifname,
  */
 int virNetDevOpenvswitchRemovePort(const char *brname G_GNUC_UNUSED, const 
char *ifname)
 {
-g_autoptr(virCommand) cmd = virNetDevOpenvswitchCreateCmd();
+g_autofree char *errbuf = NULL;
+g_autoptr(virCommand) cmd = virNetDevOpenvswitchCreateCmd();
 
 virCommandAddArgList(cmd, "--", "--if-exists", "del-port", ifname, NULL);
 
 if (virCommandRun(cmd, NULL) < 0) {
 virReportError(VIR_ERR_INTERNAL_ERROR,
-   _("Unable to delete port %1$s from OVS"), ifname);
+   _("Unable to delete port %1$s from OVS: %2$s"),
+   ifname, NULLSTR(errbuf));
 return -1;
 }
 
@@ -228,7 +235,8 @@ int virNetDevOpenvswitchRemovePort(const char *brname 
G_GNUC_UNUSED, const char
 int virNetDevOpenvswitchGetMigrateData(char **migrate, const char *ifname)
 {
 size_t len;
-g_autoptr(virCommand) cmd = virNetDevOpenvswitchCreateCmd();
+g_autofree char *errbuf = NULL;
+g_autoptr(virCommand) cmd = virNetDevOpenvswitchCreateCmd();
 
 virCommandAddArgList(cmd, "--if-exists", "get", "Interface",
  ifname, "external_ids:PortData", NULL);
@@ -238,8 +246,8 @@ int virNetDevOpenvswitchGetMigrateData(char **migrate, 
const char *ifname)
 /* Run the command */
 if (virCommandRun(cmd, NULL) < 0) {
 virReportError(VIR_ERR_INTERNAL_ERROR,
-   _("Unable to run command to get OVS port data for 
interface %1$s"),
-   ifname);
+   _("Unable to run command to get OVS port data for 
interface %1$s: %2$s"),
+   ifname, NULLSTR(errbuf));
 return -1;
 }
 
@@ -263,21 +271,22 @@ int virNetDevOpenvswitchGetMigrateData(char **migrate, 
const char *ifname)
 int virNetDevOpenvswitchSetMigrateData(char *migrate, const char *ifname)
 {
 g_autoptr(virCommand) cmd = NULL;
+g_autofr

[PATCH] virsh-snapshot: Avoid passing NULL to qsort() in virshSnapshotListCollect()

2023-09-07 Thread Michal Privoznik
If a domain has no snapshots and 'virsh snapshot-list' is called,
this gets all the way down to virshSnapshotListCollect() which
then collects all snapshots (none), and passes them to qsort()
which doesn't like being called with NULL:

  extern void qsort (void *__base, size_t __nmemb, size_t __size,
 __compar_fn_t __compar) __nonnull ((1, 4));

Resolves: https://gitlab.com/libvirt/libvirt/-/issues/533
Signed-off-by: Michal Privoznik 
---
 tools/virsh-snapshot.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/tools/virsh-snapshot.c b/tools/virsh-snapshot.c
index d7889a38e4..ecb935b2b4 100644
--- a/tools/virsh-snapshot.c
+++ b/tools/virsh-snapshot.c
@@ -1310,9 +1310,11 @@ virshSnapshotListCollect(vshControl *ctl, virDomainPtr 
dom,
 }
 }
 }
-if (!(orig_flags & VIR_DOMAIN_SNAPSHOT_LIST_TOPOLOGICAL))
+if (!(orig_flags & VIR_DOMAIN_SNAPSHOT_LIST_TOPOLOGICAL) &&
+snaplist->snaps) {
 qsort(snaplist->snaps, snaplist->nsnaps, sizeof(*snaplist->snaps),
   virshSnapSorter);
+}
 snaplist->nsnaps -= deleted;
 
 ret = g_steal_pointer();
-- 
2.41.0



[PATCH] storage_util: Drop getDeviceType()

2023-09-05 Thread Michal Privoznik
The sole purpose of getDeviceType() is to parse a file that
contains one integer (and a newline character). Well, we already
have a function for that: virFileReadValueInt(). Use the latter
and drop the former.

Signed-off-by: Michal Privoznik 
---
 src/storage/storage_util.c | 75 --
 1 file changed, 15 insertions(+), 60 deletions(-)

diff --git a/src/storage/storage_util.c b/src/storage/storage_util.c
index bf8de2475d..7243308a02 100644
--- a/src/storage/storage_util.c
+++ b/src/storage/storage_util.c
@@ -3847,62 +3847,6 @@ getBlockDevice(uint32_t host,
 }
 
 
-/* Function to check if the type file in the given sysfs_path is a
- * Direct-Access device (i.e. type 0).  Return -1 on failure, type of
- * the device otherwise.
- */
-static int
-getDeviceType(uint32_t host,
-  uint32_t bus,
-  uint32_t target,
-  uint32_t lun,
-  int *type)
-{
-char typestr[3];
-char *gottype, *p;
-FILE *typefile;
-g_autofree char *type_path = NULL;
-
-type_path = g_strdup_printf("/sys/bus/scsi/devices/%u:%u:%u:%u/type", host,
-bus, target, lun);
-
-typefile = fopen(type_path, "r");
-if (typefile == NULL) {
-virReportSystemError(errno,
- _("Could not find typefile '%1$s'"),
- type_path);
-/* there was no type file; that doesn't seem right */
-return -1;
-}
-
-gottype = fgets(typestr, 3, typefile);
-VIR_FORCE_FCLOSE(typefile);
-
-if (gottype == NULL) {
-virReportSystemError(errno,
- _("Could not read typefile '%1$s'"),
- type_path);
-/* we couldn't read the type file; have to give up */
-return -1;
-}
-
-/* we don't actually care about p, but if you pass NULL and the last
- * character is not \0, virStrToLong_i complains
- */
-if (virStrToLong_i(typestr, , 10, type) < 0) {
-virReportError(VIR_ERR_INTERNAL_ERROR,
-   _("Device type '%1$s' is not an integer"),
-   typestr);
-/* Hm, type wasn't an integer; seems strange */
-return -1;
-}
-
-VIR_DEBUG("Device type is %d", *type);
-
-return 0;
-}
-
-
 /*
  * Process a Logical Unit entry from the scsi host device directory
  *
@@ -3921,18 +3865,29 @@ processLU(virStoragePoolObj *pool,
 {
 int retval = -1;
 int device_type;
+int rc;
 g_autofree char *block_device = NULL;
 
 VIR_DEBUG("Processing LU %u:%u:%u:%u",
   host, bus, target, lun);
 
-if (getDeviceType(host, bus, target, lun, _type) < 0) {
-virReportError(VIR_ERR_INTERNAL_ERROR,
-   _("Failed to determine if %1$u:%2$u:%3$u:%4$u is a 
Direct-Access LUN"),
-   host, bus, target, lun);
+if ((rc = virFileReadValueInt(_type,
+  "/sys/bus/scsi/devices/%u:%u:%u:%u/type",
+  host, bus, target, lun)) < 0) {
+
+/* Report an error if file doesn't exist. Appropriate
+ * error was reported otherwise. */
+if (rc == -2) {
+virReportError(VIR_ERR_INTERNAL_ERROR,
+   _("Failed to determine if %1$u:%2$u:%3$u:%4$u is a 
Direct-Access LUN"),
+   host, bus, target, lun);
+}
+
 return -1;
 }
 
+VIR_DEBUG("Device type is %d", device_type);
+
 /* We don't create volumes for devices other than disk and cdrom
  * devices, but finding a device that isn't one of those types
  * isn't an error, either. */
-- 
2.41.0



[PATCH 3/3] ch: Use proper format directive for @i in virCHProcessSetupIOThreads()

2023-09-05 Thread Michal Privoznik
The @i variable inside of virCHProcessSetupIOThreads() is a
typical loop counter - it's declared as size_t. But when passed
to VIR_DEBUG an invalid format directive is used (%ld). Fix that.

Signed-off-by: Michal Privoznik 
---
 src/ch/ch_process.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/ch/ch_process.c b/src/ch/ch_process.c
index 44c5b0611e..6d3a9612bd 100644
--- a/src/ch/ch_process.c
+++ b/src/ch/ch_process.c
@@ -332,7 +332,7 @@ virCHProcessSetupIOThreads(virDomainObj *vm)
 return -1;
 
 for (i = 0; i < niothreads; i++) {
-VIR_DEBUG("IOThread index = %ld , tid = %d", i, 
iothreads[i]->iothread_id);
+VIR_DEBUG("IOThread index = %zu , tid = %d", i, 
iothreads[i]->iothread_id);
 if (virCHProcessSetupIOThread(vm, iothreads[i]) < 0)
 return -1;
 }
-- 
2.41.0



[PATCH 1/3] ch: Use uint for @maxvcpus in virCHDomainRefreshThreadInfo()

2023-09-05 Thread Michal Privoznik
The @maxvcpus variable inside of virCHDomainRefreshThreadInfo()
holds retval of virDomainDefGetVcpusMax() which returns an
unsigned int. Also, the variable is then passed to VIR_WARN()
with incorrect format directive (%ld). Switch variable to uint
and fix the format directive.

Signed-off-by: Michal Privoznik 
---
 src/ch/ch_domain.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/ch/ch_domain.c b/src/ch/ch_domain.c
index 35e3471cba..d6b64b6c59 100644
--- a/src/ch/ch_domain.c
+++ b/src/ch/ch_domain.c
@@ -225,7 +225,7 @@ chValidateDomainDeviceDef(const virDomainDeviceDef *dev,
 int
 virCHDomainRefreshThreadInfo(virDomainObj *vm)
 {
-size_t maxvcpus = virDomainDefGetVcpusMax(vm->def);
+unsigned int maxvcpus = virDomainDefGetVcpusMax(vm->def);
 virCHMonitorThreadInfo *info = NULL;
 size_t nthreads;
 size_t ncpus = 0;
@@ -252,7 +252,7 @@ virCHDomainRefreshThreadInfo(virDomainObj *vm)
 
 /* TODO: Remove the warning when hotplug is implemented.*/
 if (ncpus != maxvcpus)
-VIR_WARN("Mismatch in the number of cpus, expected: %ld, actual: %ld",
+VIR_WARN("Mismatch in the number of cpus, expected: %u, actual: %zu",
  maxvcpus, ncpus);
 
 return 0;
-- 
2.41.0



[PATCH 2/3] ch: Use int for @niothreads in virCHMonitorGetIOThreads()

2023-09-05 Thread Michal Privoznik
The @niothreads inside of virCHMonitorGetIOThreads() is declared
as of size_t type. This would work, except the variable is then
passed to VIR_DEBUG with incorrect format directive (%ld) and
returned.  But the function returns an int not size_t. Fix the
variable declaration and format directive.

Signed-off-by: Michal Privoznik 
---
 src/ch/ch_monitor.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/ch/ch_monitor.c b/src/ch/ch_monitor.c
index 4f32b1ee4c..200ad6c77b 100644
--- a/src/ch/ch_monitor.c
+++ b/src/ch/ch_monitor.c
@@ -937,7 +937,7 @@ virCHMonitorGetIOThreads(virCHMonitor *mon,
  virDomainIOThreadInfo ***iothreads)
 {
 size_t nthreads = 0;
-size_t niothreads = 0;
+int niothreads = 0;
 int thd_index;
 virDomainIOThreadInfo **iothreadinfolist = NULL;
 virDomainIOThreadInfo *iothreadinfo = NULL;
@@ -969,7 +969,7 @@ virCHMonitorGetIOThreads(virCHMonitor *mon,
 }
 }
 
-VIR_DEBUG("niothreads = %ld", niothreads);
+VIR_DEBUG("niothreads = %d", niothreads);
 *iothreads = g_steal_pointer();
 return niothreads;
 
-- 
2.41.0



[PATCH 0/3] ch: Couple of format directive fixes

2023-09-05 Thread Michal Privoznik
*** BLURB HERE ***

Michal Prívozník (3):
  ch: Use uint for @maxvcpus in virCHDomainRefreshThreadInfo()
  ch: Use int for @niothreads in virCHMonitorGetIOThreads()
  ch: Use proper format directive for @i in virCHProcessSetupIOThreads()

 src/ch/ch_domain.c  | 4 ++--
 src/ch/ch_monitor.c | 4 ++--
 src/ch/ch_process.c | 2 +-
 3 files changed, 5 insertions(+), 5 deletions(-)

-- 
2.41.0



[PATCH 2/2] syntax-check: Introduce a rule for one line error messages

2023-09-04 Thread Michal Privoznik
Okay, this is a shortcut. Our coding style says that error
messages are exempt from '80 chars long lines' rule. But in the
very same paragraph it is said that all error messages need to be
marked for translation (as they might be presented to user).

Therefore, the syntax-check rule can check if _("...") is
formatted on one line. With exception of _("...\n" ...) (e.g.
various outputs from helper binaries like leaseshelper,
sshhelper, or daemons like lockd, logd). I believe nobody would
chose a substring that contains '\n' for git grep-ping the error
message.

Signed-off-by: Michal Privoznik 
---
 build-aux/syntax-check.mk | 8 
 1 file changed, 8 insertions(+)

diff --git a/build-aux/syntax-check.mk b/build-aux/syntax-check.mk
index 64c1e2773e..618c0546aa 100644
--- a/build-aux/syntax-check.mk
+++ b/build-aux/syntax-check.mk
@@ -440,6 +440,11 @@ sc_prohibit_newline_at_end_of_diagnostic:
  && { echo 'newline at end of message(s)' 1>&2; \
exit 1; } || :
 
+sc_prohibit_error_message_on_multiple_lines:
+   @prohibit='[^N]_\(".*[^\\n]"$$' \
+   halt='found error message on multiple lines' \
+   $(_sc_search_regexp)
+
 # Look for diagnostics that lack a % in the format string, except that we
 # allow VIR_ERROR to do this, and ignore functions that take a single
 # string rather than a format argument.
@@ -1386,6 +1391,9 @@ exclude_file_name_regexp--sc_prohibit_raw_virclassnew = \
 exclude_file_name_regexp--sc_prohibit_newline_at_end_of_diagnostic = \
   ^src/rpc/gendispatch\.pl$$
 
+exclude_file_name_regexp--sc_prohibit_error_message_on_multiple_lines = \
+  ^(build-aux/syntax-check\.mk|docs/coding-style.rst)
+
 exclude_file_name_regexp--sc_prohibit_nonreentrant = \
   
^((po|tests|examples)/|docs/.*(py|js|html\.in|.rst)|run.in$$|tools/wireshark/util/genxdrstub\.pl|tools/virt-login-shell\.c$$)
 
-- 
2.41.0



[PATCH 1/2] tools: Reformat --help output of virsh and virt-admin

2023-09-04 Thread Michal Privoznik
The --help output of virsh and virt-admin shows supported options
and commands and as such contains new lines. Both these strings
are marked for translation btw. But the way they are formatted
now ('\n' being at the start of new line instead at the end of
the previous) makes it hard to create a syntax-check rule for
'translation message on one line' (next commit).

Reformat both strings a bit (no user visible change though).

Signed-off-by: Michal Privoznik 
---
 tools/virsh.c  | 6 --
 tools/virt-admin.c | 6 --
 2 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/tools/virsh.c b/tools/virsh.c
index d9922a35fc..7b71131db3 100644
--- a/tools/virsh.c
+++ b/tools/virsh.c
@@ -436,8 +436,10 @@ virshUsage(void)
 const vshCmdGrp *grp;
 const vshCmdDef *cmd;
 
-fprintf(stdout, _("\n%1$s [options]... []"
-  "\n%2$s [options]...  [args...]\n\n"
+fprintf(stdout, _("\n"
+  "%1$s [options]... []\n"
+  "%2$s [options]...  [args...]\n"
+  "\n"
   "  options:\n"
   "-c | --connect=URI  hypervisor connection URI\n"
   "-d | --debug=NUMdebug level [0-4]\n"
diff --git a/tools/virt-admin.c b/tools/virt-admin.c
index 15a639f1ea..1e22a3c8a9 100644
--- a/tools/virt-admin.c
+++ b/tools/virt-admin.c
@@ -1242,8 +1242,10 @@ vshAdmUsage(void)
 const vshCmdGrp *grp;
 const vshCmdDef *cmd;
 
-fprintf(stdout, _("\n%1$s [options]... []"
-  "\n%2$s [options]...  [args...]\n\n"
+fprintf(stdout, _("\n"
+  "%1$s [options]... []\n"
+  "%2$s [options]...  [args...]\n"
+  "\n"
   "  options:\n"
   "-c | --connect=URI  daemon admin connection 
URI\n"
   "-d | --debug=NUMdebug level [0-4]\n"
-- 
2.41.0



[PATCH 0/2] syntax-check: Introduce a rule for one line error messages

2023-09-04 Thread Michal Privoznik
This is a follow up of:

https://listman.redhat.com/archives/libvir-list/2023-August/241416.html

And while the regular expression in patch 2/2 is very trivial it mostly
works. But I'm open for suggestions.

Michal Prívozník (2):
  tools: Reformat --help output of virsh and virt-admin
  syntax-check: Introduce a rule for one line error messages

 build-aux/syntax-check.mk | 8 
 tools/virsh.c | 6 --
 tools/virt-admin.c| 6 --
 3 files changed, 16 insertions(+), 4 deletions(-)

-- 
2.41.0



[PATCH 2/4] vircommand: Isolate FD dir parsing into a separate function

2023-08-29 Thread Michal Privoznik
So far, virCommandMassCloseGetFDsLinux() opens "/proc/self/fd",
iterates over it marking opened FDs in @fds bitmap. Well, we can
do the same on other systems (with altered path), like MacOS or
FreeBSD. Therefore, isolate dir iteration into a separate
function that accepts dir path as an argument.

Unfortunately, this function might be unused on some systems
(e.g. mingw), therefore mark it as such.

Signed-off-by: Michal Privoznik 
---
 src/util/vircommand.c | 31 +--
 1 file changed, 13 insertions(+), 18 deletions(-)

diff --git a/src/util/vircommand.c b/src/util/vircommand.c
index 60d419a695..822b9487f9 100644
--- a/src/util/vircommand.c
+++ b/src/util/vircommand.c
@@ -479,17 +479,12 @@ virExecCommon(virCommand *cmd, gid_t *groups, int ngroups)
 return 0;
 }
 
-# ifdef __linux__
-/* On Linux, we can utilize procfs and read the table of opened
- * FDs and selectively close only those FDs we don't want to pass
- * onto child process (well, the one we will exec soon since this
- * is called from the child). */
-static int
-virCommandMassCloseGetFDsLinux(virBitmap *fds)
+static int G_GNUC_UNUSED
+virCommandMassCloseGetFDsDir(virBitmap *fds,
+ const char *dirName)
 {
 g_autoptr(DIR) dp = NULL;
 struct dirent *entry;
-const char *dirName = "/proc/self/fd";
 int rc;
 
 if (virDirOpen(, dirName) < 0)
@@ -514,15 +509,20 @@ virCommandMassCloseGetFDsLinux(virBitmap *fds)
 return 0;
 }
 
-# else /* !__linux__ */
-
 static int
-virCommandMassCloseGetFDsGeneric(virBitmap *fds)
+virCommandMassCloseGetFDs(virBitmap *fds)
 {
+# ifdef __linux__
+/* On Linux, we can utilize procfs and read the table of opened
+ * FDs and selectively close only those FDs we don't want to pass
+ * onto child process (well, the one we will exec soon since this
+ * is called from the child). */
+return virCommandMassCloseGetFDsDir(fds, "/proc/self/fd");
+# else
 virBitmapSetAll(fds);
 return 0;
+# endif
 }
-# endif /* !__linux__ */
 
 static int
 virCommandMassCloseFrom(virCommand *cmd,
@@ -551,13 +551,8 @@ virCommandMassCloseFrom(virCommand *cmd,
 
 fds = virBitmapNew(openmax);
 
-# ifdef __linux__
-if (virCommandMassCloseGetFDsLinux(fds) < 0)
+if (virCommandMassCloseGetFDs(fds) < 0)
 return -1;
-# else
-if (virCommandMassCloseGetFDsGeneric(fds) < 0)
-return -1;
-# endif
 
 lastfd = MAX(lastfd, childin);
 lastfd = MAX(lastfd, childout);
-- 
2.41.0



[PATCH 1/4] vircommand: Drop unused arguments from virCommandMassCloseGetFDs*()

2023-08-29 Thread Michal Privoznik
Both virCommandMassCloseGetFDsLinux() and
virCommandMassCloseGetFDsGeneric() take @cmd argument only to
mark it as unused. Drop it from both.

Signed-off-by: Michal Privoznik 
---
 src/util/vircommand.c | 10 --
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/src/util/vircommand.c b/src/util/vircommand.c
index 5f094c625a..60d419a695 100644
--- a/src/util/vircommand.c
+++ b/src/util/vircommand.c
@@ -485,8 +485,7 @@ virExecCommon(virCommand *cmd, gid_t *groups, int ngroups)
  * onto child process (well, the one we will exec soon since this
  * is called from the child). */
 static int
-virCommandMassCloseGetFDsLinux(virCommand *cmd G_GNUC_UNUSED,
-   virBitmap *fds)
+virCommandMassCloseGetFDsLinux(virBitmap *fds)
 {
 g_autoptr(DIR) dp = NULL;
 struct dirent *entry;
@@ -518,8 +517,7 @@ virCommandMassCloseGetFDsLinux(virCommand *cmd 
G_GNUC_UNUSED,
 # else /* !__linux__ */
 
 static int
-virCommandMassCloseGetFDsGeneric(virCommand *cmd G_GNUC_UNUSED,
- virBitmap *fds)
+virCommandMassCloseGetFDsGeneric(virBitmap *fds)
 {
 virBitmapSetAll(fds);
 return 0;
@@ -554,10 +552,10 @@ virCommandMassCloseFrom(virCommand *cmd,
 fds = virBitmapNew(openmax);
 
 # ifdef __linux__
-if (virCommandMassCloseGetFDsLinux(cmd, fds) < 0)
+if (virCommandMassCloseGetFDsLinux(fds) < 0)
 return -1;
 # else
-if (virCommandMassCloseGetFDsGeneric(cmd, fds) < 0)
+if (virCommandMassCloseGetFDsGeneric(fds) < 0)
 return -1;
 # endif
 
-- 
2.41.0



[PATCH 0/4] vircommand: Various mass close improvements

2023-08-29 Thread Michal Privoznik
*** BLURB HERE ***

Michal Prívozník (4):
  vircommand: Drop unused arguments from virCommandMassCloseGetFDs*()
  vircommand: Isolate FD dir parsing into a separate function
  vircommand: Make sysconf(_SC_OPEN_MAX) failure non-fatal
  vircommand: Parse /dev/fd on *BSD-like systems when looking for opened
FDs

 src/util/vircommand.c | 43 ++-
 1 file changed, 18 insertions(+), 25 deletions(-)

-- 
2.41.0



[PATCH 3/4] vircommand: Make sysconf(_SC_OPEN_MAX) failure non-fatal

2023-08-29 Thread Michal Privoznik
The point of calling sysconf(_SC_OPEN_MAX) is to allocate big
enough bitmap so that subsequent call to
virCommandMassCloseGetFDsDir() can just set the bit instead of
expanding memory (this code runs in a forked off child and thus
using async-signal-unsafe functions like malloc() is a bit
tricky).

But on some systems the limit for opened FDs is virtually
non-existent (typically macOS Ventura started reporting EINVAL).

But with both glibc and musl using malloc() after fork() is safe.
And with sufficiently new glib too, as it's using malloc() with
newer releases instead of their own allocator.

Therefore, pick a sufficiently large value (glibc falls back to
256, [1], so 1024 should be good enough) to fall back to and make
the error non-fatal.

1: 
https://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/unix/sysv/linux/getdtsz.c;h=4c5a6208067d2f9eaaac6dba652702fb4af9b7e3;hb=HEAD
Signed-off-by: Michal Privoznik 
---
 src/util/vircommand.c | 8 +++-
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/src/util/vircommand.c b/src/util/vircommand.c
index 822b9487f9..8c06e19723 100644
--- a/src/util/vircommand.c
+++ b/src/util/vircommand.c
@@ -500,7 +500,7 @@ virCommandMassCloseGetFDsDir(virBitmap *fds,
 return -1;
 }
 
-ignore_value(virBitmapSetBit(fds, fd));
+virBitmapSetBitExpand(fds, fd);
 }
 
 if (rc < 0)
@@ -544,10 +544,8 @@ virCommandMassCloseFrom(virCommand *cmd,
  * Therefore we can safely allocate memory here (and transitively call
  * opendir/readdir) without a deadlock. */
 
-if (openmax < 0) {
-virReportSystemError(errno, "%s", _("sysconf(_SC_OPEN_MAX) failed"));
-return -1;
-}
+if (openmax <= 0)
+openmax = 1024;
 
 fds = virBitmapNew(openmax);
 
-- 
2.41.0



[PATCH 4/4] vircommand: Parse /dev/fd on *BSD-like systems when looking for opened FDs

2023-08-29 Thread Michal Privoznik
On BSD-like systems "/dev/fd" serves the same purpose as
"/proc/self/fd". And since procfs is usually not mounted, on such
systems we can use "/dev/fd" instead.

Resolves: https://gitlab.com/libvirt/libvirt/-/issues/518
Signed-off-by: Michal Privoznik 
---
 src/util/vircommand.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/src/util/vircommand.c b/src/util/vircommand.c
index 8c06e19723..2b3b125e5f 100644
--- a/src/util/vircommand.c
+++ b/src/util/vircommand.c
@@ -518,6 +518,8 @@ virCommandMassCloseGetFDs(virBitmap *fds)
  * onto child process (well, the one we will exec soon since this
  * is called from the child). */
 return virCommandMassCloseGetFDsDir(fds, "/proc/self/fd");
+# elif defined(__APPLE__) || defined(__FreeBSD__)
+return virCommandMassCloseGetFDsDir(fds, "/dev/fd");
 # else
 virBitmapSetAll(fds);
 return 0;
-- 
2.41.0



[PATCH 1/3] docs: Document that libxl hooks are also given full domain XML

2023-08-29 Thread Michal Privoznik
Our hooks.rst document existence of libxl hook scripts, but
mentions only qemu and lxc as receivers of full domain XML. But
since their introduction in v2.2.0-rc1~201 they are also given
full domain XML. Fix our wording.

Signed-off-by: Michal Privoznik 
---
 docs/hooks.rst | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/docs/hooks.rst b/docs/hooks.rst
index 9387676a55..b127ec4202 100644
--- a/docs/hooks.rst
+++ b/docs/hooks.rst
@@ -89,7 +89,7 @@ Script arguments
 The hook scripts are called with specific command line arguments, depending 
upon
 the script, and the operation being performed.
 
-The guest hook scripts, qemu and lxc, are also given the **full** XML
+The guest hook scripts, qemu, lxc and libxl are also given the **full** XML
 description for the domain on their stdin. This includes items such the UUID of
 the domain and its storage information, and is intended to provide all the
 libvirt information the script needs.
@@ -126,8 +126,8 @@ followed with the full XML description of the port:

 
 Please note that this approach is different from other cases such as 
``daemon``,
-``qemu`` or ``lxc`` hook scripts, because two XMLs may be passed here, while in
-the other cases only a single XML is passed.
+``qemu``, ``lxc`` or ``libxl`` hook scripts, because two XMLs may be passed
+here, while in the other cases only a single XML is passed.
 
 The command line arguments take this approach:
 
-- 
2.41.0



[PATCH 3/3] bhyve: Feed hook scripts with domain XML

2023-08-29 Thread Michal Privoznik
Domain related hook scripts are all fed with domain XML on their
stdin, except for bhyve. Fix this.

Resolves: https://gitlab.com/libvirt/libvirt/-/issues/528
Signed-off-by: Michal Privoznik 
---
 docs/hooks.rst| 10 +-
 src/bhyve/bhyve_process.c | 35 ---
 2 files changed, 29 insertions(+), 16 deletions(-)

diff --git a/docs/hooks.rst b/docs/hooks.rst
index 4e02ba0f8f..bd197c0d6e 100644
--- a/docs/hooks.rst
+++ b/docs/hooks.rst
@@ -92,9 +92,9 @@ Script arguments
 The hook scripts are called with specific command line arguments, depending 
upon
 the script, and the operation being performed.
 
-The guest hook scripts, qemu, lxc and libxl are also given the **full** XML
-description for the domain on their stdin. This includes items such the UUID of
-the domain and its storage information, and is intended to provide all the
+The guest hook scripts, qemu, lxc, libxl and bhyve are also given the **full**
+XML description for the domain on their stdin. This includes items such the 
UUID
+of the domain and its storage information, and is intended to provide all the
 libvirt information the script needs.
 
 For all cases, stdin of the network hook script is provided with the full XML
@@ -129,8 +129,8 @@ followed with the full XML description of the port:

 
 Please note that this approach is different from other cases such as 
``daemon``,
-``qemu``, ``lxc`` or ``libxl`` hook scripts, because two XMLs may be passed
-here, while in the other cases only a single XML is passed.
+``qemu``, ``lxc``, ``libxl`` or ``bhyve`` hook scripts, because two XMLs may be
+passed here, while in the other cases only a single XML is passed.
 
 The command line arguments take this approach:
 
diff --git a/src/bhyve/bhyve_process.c b/src/bhyve/bhyve_process.c
index 80d5a8804f..d476ff401f 100644
--- a/src/bhyve/bhyve_process.c
+++ b/src/bhyve/bhyve_process.c
@@ -94,21 +94,34 @@ virBhyveFormatDevMapFile(const char *vm_name, char **fn_out)
 }
 
 static int
-bhyveProcessStartHook(virDomainObj *vm, virHookBhyveOpType op)
+bhyveProcessStartHook(struct _bhyveConn *driver,
+  virDomainObj *vm,
+  virHookBhyveOpType op)
 {
+g_autofree char *xml = NULL;
+
 if (!virHookPresent(VIR_HOOK_DRIVER_BHYVE))
 return 0;
 
+xml = virDomainDefFormat(vm->def, driver->xmlopt, 0);
+
 return virHookCall(VIR_HOOK_DRIVER_BHYVE, vm->def->name, op,
-   VIR_HOOK_SUBOP_BEGIN, NULL, NULL, NULL);
+   VIR_HOOK_SUBOP_BEGIN, NULL, xml, NULL);
 }
 
 static void
-bhyveProcessStopHook(virDomainObj *vm, virHookBhyveOpType op)
+bhyveProcessStopHook(struct _bhyveConn *driver,
+ virDomainObj *vm,
+ virHookBhyveOpType op)
 {
-if (virHookPresent(VIR_HOOK_DRIVER_BHYVE))
-virHookCall(VIR_HOOK_DRIVER_BHYVE, vm->def->name, op,
-VIR_HOOK_SUBOP_END, NULL, NULL, NULL);
+g_autofree char *xml = NULL;
+if (!virHookPresent(VIR_HOOK_DRIVER_BHYVE))
+return;
+
+xml = virDomainDefFormat(vm->def, driver->xmlopt, 0);
+
+virHookCall(VIR_HOOK_DRIVER_BHYVE, vm->def->name, op,
+VIR_HOOK_SUBOP_END, NULL, xml, NULL);
 }
 
 static int
@@ -194,7 +207,7 @@ virBhyveProcessStartImpl(struct _bhyveConn *driver,
 goto cleanup;
 }
 
-if (bhyveProcessStartHook(vm, VIR_HOOK_BHYVE_OP_START) < 0)
+if (bhyveProcessStartHook(driver, vm, VIR_HOOK_BHYVE_OP_START) < 0)
 goto cleanup;
 
 /* Now we can start the domain */
@@ -216,7 +229,7 @@ virBhyveProcessStartImpl(struct _bhyveConn *driver,
  BHYVE_STATE_DIR) < 0)
 goto cleanup;
 
-if (bhyveProcessStartHook(vm, VIR_HOOK_BHYVE_OP_STARTED) < 0)
+if (bhyveProcessStartHook(driver, vm, VIR_HOOK_BHYVE_OP_STARTED) < 0)
 goto cleanup;
 
 ret = 0;
@@ -265,7 +278,7 @@ virBhyveProcessStart(virConnectPtr conn,
 struct _bhyveConn *driver = conn->privateData;
 
 /* Run an early hook to setup missing devices. */
-if (bhyveProcessStartHook(vm, VIR_HOOK_BHYVE_OP_PREPARE) < 0)
+if (bhyveProcessStartHook(driver, vm, VIR_HOOK_BHYVE_OP_PREPARE) < 0)
 return -1;
 
 if (flags & VIR_BHYVE_PROCESS_START_AUTODESTROY)
@@ -307,7 +320,7 @@ virBhyveProcessStop(struct _bhyveConn *driver,
 if ((priv != NULL) && (priv->mon != NULL))
  bhyveMonitorClose(priv->mon);
 
-bhyveProcessStopHook(vm, VIR_HOOK_BHYVE_OP_STOPPED);
+bhyveProcessStopHook(driver, vm, VIR_HOOK_BHYVE_OP_STOPPED);
 
 /* Cleanup network interfaces */
 bhyveNetCleanup(vm);
@@ -329,7 +342,7 @@ virBhyveProcessStop(struct _bhyveConn *driver,
 vm->pid = 0;
 vm->def->id = -1;
 
-bhyveProcessStopHook(vm, VIR_HOOK_BHYVE_OP_RELEASE);
+bhyveProcessStopHook(driver, vm, VIR_HOOK_BHYVE_OP_RELEASE);
 
  cleanup:
 virPidFileDelete(BHYVE_STATE_DIR, vm->def->name);
-- 
2.41.0



[PATCH 2/3] docs: Document bhyve hook scripts

2023-08-29 Thread Michal Privoznik
We have bhyve hook scripts since v6.1.0-rc1~42 but never mention
them in hooks.rst. Fill the blanks.

Signed-off-by: Michal Privoznik 
---
 docs/hooks.rst | 46 ++
 1 file changed, 46 insertions(+)

diff --git a/docs/hooks.rst b/docs/hooks.rst
index b127ec4202..4e02ba0f8f 100644
--- a/docs/hooks.rst
+++ b/docs/hooks.rst
@@ -20,6 +20,7 @@ occur:
 -  A QEMU guest is started or stopped ( :since:`since 0.8.0` )
 -  An LXC guest is started or stopped ( :since:`since 0.8.0` )
 -  A libxl-handled Xen guest is started or stopped ( :since:`since 2.1.0` )
+-  An bhyve guest is started or stopped ( :since:`since 6.1.0` )
 -  A network is started or stopped or an interface is plugged/unplugged to/from
the network ( :since:`since 1.2.2` )
 
@@ -53,6 +54,8 @@ At present, there are five hook scripts that can be called:
Executed when an LXC guest is started or stopped
 -  ``/etc/libvirt/hooks/libxl``
Executed when a libxl-handled Xen guest is started, stopped, or migrated
+-  ``/etc/libvirt/hooks/bhyve``
+   Executed when an bhyve guest is started or stopped
 -  ``/etc/libvirt/hooks/network``
Executed when a network is started or stopped or an interface is
plugged/unplugged to/from the network
@@ -393,6 +396,49 @@ operation. There is no specific operation to indicate a 
"restart" is occurring.
 
   /etc/libvirt/hooks/libxl guest_name reconnect begin -
 
+/etc/libvirt/hooks/bhyve
+
+
+-  | Before an bhyve guest is started, the bhyve hook script is called in three
+ locations; if any location fails, the guest is not started. The first
+ location, :since:`since 6.1.0` , is before libvirt performs any resource
+ labeling, and the hook can allocate resources not managed by libvirt. 
This is
+ called as:
+
+   ::
+
+  /etc/libvirt/hooks/bhyve guest_name prepare begin -
+
+   | The second location, available :since:`Since 6.1.0` , occurs after libvirt
+ has finished labeling all resources, but has not yet started the guest,
+ called as:
+
+   ::
+
+  /etc/libvirt/hooks/bhyve guest_name start begin -
+
+   | The third location, :since:`6.1.0` , occurs after the bhyve process has
+ successfully started up:
+
+   ::
+
+  /etc/libvirt/hooks/bhyve guest_name started begin -
+
+-  | When an bhyve guest is stopped, the bhyve hook script is called in two
+ locations, to match the startup. First, :since:`since 6.1.0` , the hook is
+ called before libvirt restores any labels:
+
+   ::
+
+  /etc/libvirt/hooks/bhyve guest_name stopped end -
+
+   | Then, after libvirt has released all resources, the hook is called again,
+ :since:`since 6.1.0` , to allow any additional resource cleanup:
+
+   ::
+
+  /etc/libvirt/hooks/bhyve guest_name release end -
+
 /etc/libvirt/hooks/network
 ^^
 
-- 
2.41.0



[PATCH 0/3] bhyve: Feed hook scripts with domain XML

2023-08-29 Thread Michal Privoznik
*** BLURB HERE ***

Michal Prívozník (3):
  docs: Document that libxl hooks are also given full domain XML
  docs: Document bhyve hook scripts
  bhyve: Feed hook scripts with domain XML

 docs/hooks.rst| 56 +++
 src/bhyve/bhyve_process.c | 35 
 2 files changed, 75 insertions(+), 16 deletions(-)

-- 
2.41.0



[PATCH] virsh-network: Drop unused variables in cmdNetworkMetadata()

2023-08-25 Thread Michal Privoznik
In one of recent commits two variable were introduced (@ctxt and
@doc) that are not used. This breaks a build with clang who's
able to identify that.

Signed-off-by: Michal Privoznik 
---

Pushed under trivial and build breaker rules.

 tools/virsh-network.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/tools/virsh-network.c b/tools/virsh-network.c
index f9fea0a126..5655254699 100644
--- a/tools/virsh-network.c
+++ b/tools/virsh-network.c
@@ -597,7 +597,6 @@ static bool
 cmdNetworkMetadata(vshControl *ctl, const vshCmd *cmd)
 {
 g_autoptr(virshNetwork) net = NULL;
-g_autoptr(xmlXPathContext) ctxt = NULL;
 bool config = vshCommandOptBool(cmd, "config");
 bool live = vshCommandOptBool(cmd, "live");
 bool current = vshCommandOptBool(cmd, "current");
@@ -661,7 +660,7 @@ cmdNetworkMetadata(vshControl *ctl, const vshCmd *cmd)
 vshPrintExtra(ctl, "%s\n", _("Metadata modified"));
 } else {
 g_autofree char *data = NULL;
-g_autoptr(xmlDoc) doc = NULL;
+
 /* get */
 if (!(data = virNetworkGetMetadata(net, VIR_NETWORK_METADATA_ELEMENT,
uri, flags)))
-- 
2.41.0



[PATCH 11/27] node_device: Move error messages onto a single line

2023-08-25 Thread Michal Privoznik
Error messages are exempt from the 80 columns rule. Move them
onto one line.

Signed-off-by: Michal Privoznik 
---
 src/node_device/node_device_udev.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/src/node_device/node_device_udev.c 
b/src/node_device/node_device_udev.c
index dfdef483cb..911325600e 100644
--- a/src/node_device/node_device_udev.c
+++ b/src/node_device/node_device_udev.c
@@ -1889,8 +1889,7 @@ udevEventHandleThread(void *opaque G_GNUC_UNUSED)
 if (errno != EAGAIN && errno != EWOULDBLOCK && errno != EINVAL) {
 VIR_WARNINGS_RESET
 virReportSystemError(errno, "%s",
- _("failed to receive device from udev "
-   "monitor"));
+ _("failed to receive device from udev 
monitor"));
 return;
 }
 
-- 
2.41.0



[PATCH 18/27] storage: Move error messages onto a single line

2023-08-25 Thread Michal Privoznik
Error messages are exempt from the 80 columns rule. Move them
onto one line.

Signed-off-by: Michal Privoznik 
---
 src/storage/storage_backend_disk.c |  3 +-
 src/storage/storage_backend_fs.c   |  3 +-
 src/storage/storage_backend_zfs.c  |  3 +-
 src/storage/storage_driver.c   | 21 +
 src/storage/storage_util.c | 48 ++
 5 files changed, 26 insertions(+), 52 deletions(-)

diff --git a/src/storage/storage_backend_disk.c 
b/src/storage/storage_backend_disk.c
index 7466f0e234..996395de4a 100644
--- a/src/storage/storage_backend_disk.c
+++ b/src/storage/storage_backend_disk.c
@@ -659,8 +659,7 @@ virStorageBackendDiskPartFormat(virStoragePoolObj *pool,
 *partFormat = g_strdup_printf("logical %s", partedFormat);
 } else {
 virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-   _("no extended partition found and no "
- "primary partition available"));
+   _("no extended partition found and no 
primary partition available"));
 return -1;
 }
 break;
diff --git a/src/storage/storage_backend_fs.c b/src/storage/storage_backend_fs.c
index a80d228201..1851704d21 100644
--- a/src/storage/storage_backend_fs.c
+++ b/src/storage/storage_backend_fs.c
@@ -219,8 +219,7 @@ virStorageBackendFileSystemIsValid(virStoragePoolObj *pool)
_("missing source device"));
 else
 virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-   _("expected exactly 1 device for the "
- "storage pool"));
+   _("expected exactly 1 device for the storage 
pool"));
 return -1;
 }
 }
diff --git a/src/storage/storage_backend_zfs.c 
b/src/storage/storage_backend_zfs.c
index 4e243a738a..178b505e92 100644
--- a/src/storage/storage_backend_zfs.c
+++ b/src/storage/storage_backend_zfs.c
@@ -310,8 +310,7 @@ virStorageBackendZFSCreateVol(virStoragePoolObj *pool,
 
 if (vol->target.encryption != NULL) {
 virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-   "%s", _("storage pool does not support encrypted "
-   "volumes"));
+   "%s", _("storage pool does not support encrypted 
volumes"));
 return -1;
 }
 
diff --git a/src/storage/storage_driver.c b/src/storage/storage_driver.c
index 5a9dcbd193..314fe930e0 100644
--- a/src/storage/storage_driver.c
+++ b/src/storage/storage_driver.c
@@ -1903,8 +1903,7 @@ storageVolCreateXML(virStoragePoolPtr pool,
 
 if (!voldef->target.capacity && !backend->buildVol) {
 virReportError(VIR_ERR_NO_SUPPORT,
-   "%s", _("volume capacity required for this "
-   "storage pool"));
+   "%s", _("volume capacity required for this storage 
pool"));
 goto cleanup;
 }
 
@@ -1919,8 +1918,7 @@ storageVolCreateXML(virStoragePoolPtr pool,
 
 if (!backend->createVol) {
 virReportError(VIR_ERR_NO_SUPPORT,
-   "%s", _("storage pool does not support volume "
-   "creation"));
+   "%s", _("storage pool does not support volume 
creation"));
 goto cleanup;
 }
 
@@ -2103,8 +2101,7 @@ storageVolCreateXMLFrom(virStoragePoolPtr pool,
 
 if (!backend->buildVolFrom) {
 virReportError(VIR_ERR_NO_SUPPORT,
-   "%s", _("storage pool does not support"
-   " volume creation from an existing volume"));
+   "%s", _("storage pool does not support volume creation 
from an existing volume"));
 goto cleanup;
 }
 
@@ -2274,8 +2271,7 @@ virStorageBackendPloopRestoreDesc(char *path)
 
 if (virFileRemove(desc, 0, 0) < 0) {
 virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-   _("refresh ploop failed:"
- " unable to delete DiskDescriptor.xml"));
+   _("refresh ploop failed: unable to delete 
DiskDescriptor.xml"));
 return -1;
 }
 
@@ -2497,16 +2493,14 @@ storageVolResize(virStorageVolPtr vol,
 
 if (abs_capacity < voldef->target.allocation) {
 virReportError(VIR_ERR_INVALID_ARG, "%s",
-   _("can't shrink capacity below "
- "existing allocation"));
+   

[PATCH 16/27] rpc: Move error messages onto a single line

2023-08-25 Thread Michal Privoznik
Error messages are exempt from the 80 columns rule. Move them
onto one line.

Signed-off-by: Michal Privoznik 
---
 src/rpc/virnetclient.c|  9 +++
 src/rpc/virnetlibsshsession.c | 28 +++---
 src/rpc/virnetserver.c|  9 +++
 src/rpc/virnetserverclient.c  |  3 +--
 src/rpc/virnetsshsession.c| 45 ---
 src/rpc/virnettlscontext.c|  6 +
 6 files changed, 32 insertions(+), 68 deletions(-)

diff --git a/src/rpc/virnetclient.c b/src/rpc/virnetclient.c
index 18f87653f5..4ab8af68c5 100644
--- a/src/rpc/virnetclient.c
+++ b/src/rpc/virnetclient.c
@@ -1011,8 +1011,7 @@ int virNetClientSetTLSSession(virNetClient *client,
 }
 if (len != 1 || buf[0] != '\1') {
 virReportError(VIR_ERR_RPC, "%s",
-   _("server verification (of our certificate or IP "
- "address) failed"));
+   _("server verification (of our certificate or IP 
address) failed"));
 goto error;
 }
 
@@ -2069,15 +2068,13 @@ virNetClientCallNew(virNetMessage *msg,
 (msg->bufferLength != 0) &&
 (msg->header.status == VIR_NET_CONTINUE)) {
 virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-   _("Attempt to send an asynchronous message with"
- " a synchronous reply"));
+   _("Attempt to send an asynchronous message with a 
synchronous reply"));
 goto error;
 }
 
 if (expectReply && nonBlock) {
 virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-   _("Attempt to send a non-blocking message with"
- " a synchronous reply"));
+   _("Attempt to send a non-blocking message with a 
synchronous reply"));
 goto error;
 }
 
diff --git a/src/rpc/virnetlibsshsession.c b/src/rpc/virnetlibsshsession.c
index 8cb57e857f..6632e4a9ef 100644
--- a/src/rpc/virnetlibsshsession.c
+++ b/src/rpc/virnetlibsshsession.c
@@ -195,8 +195,7 @@ virLibsshServerKeyAsString(virNetLibsshSession *sess)
 
 if (ssh_get_server_publickey(sess->session, ) != SSH_OK) {
 virReportError(VIR_ERR_LIBSSH, "%s",
-   _("failed to get the key of the current "
- "session"));
+   _("failed to get the key of the current session"));
 return NULL;
 }
 
@@ -261,8 +260,7 @@ virNetLibsshCheckHostKey(virNetLibsshSession *sess)
 
 /* host key verification failed */
 virReportError(VIR_ERR_AUTH_FAILED,
-   _("!!! SSH HOST KEY VERIFICATION FAILED !!!: Identity 
of host '%1$s:%2$d' differs from stored identity. "
- "Please verify the new host key '%3$s' to avoid 
possible man in the middle attack. The key is stored in '%4$s'."),
+   _("!!! SSH HOST KEY VERIFICATION FAILED !!!: Identity 
of host '%1$s:%2$d' differs from stored identity. Please verify the new host 
key '%3$s' to avoid possible man in the middle attack. The key is stored in 
'%4$s'."),
sess->hostname, sess->port,
keyhashstr, sess->knownHostsFile);
 
@@ -279,8 +277,7 @@ virNetLibsshCheckHostKey(virNetLibsshSession *sess)
 /* ask to add the key */
 if (!sess->cred || !sess->cred->cb) {
 virReportError(VIR_ERR_LIBSSH, "%s",
-   _("No user interaction callback provided: "
- "Can't verify the session host key"));
+   _("No user interaction callback provided: Can't 
verify the session host key"));
 return -1;
 }
 
@@ -355,8 +352,7 @@ virNetLibsshAuthenticatePrivkeyCb(const char *prompt,
 /* request user's key password */
 if (!sess->cred || !sess->cred->cb) {
 virReportError(VIR_ERR_LIBSSH, "%s",
-   _("No user interaction callback provided: "
- "Can't retrieve private key passphrase"));
+   _("No user interaction callback provided: Can't 
retrieve private key passphrase"));
 return -1;
 }
 
@@ -505,8 +501,7 @@ virNetLibsshAuthenticatePassword(virNetLibsshSession *sess)
 /* password authentication with interactive password request */
 if (!sess->cred || !sess->cred->cb) {
 virReportError(VIR_ERR_LIBSSH, "%s",
-   _("Can't perform authentication: "
- "Authentication callback not provided"));
+   _("Can't perform authentication: A

[PATCH 27/27] tools: Move error messages onto a single line

2023-08-25 Thread Michal Privoznik
Error messages are exempt from the 80 columns rule. Move them
onto one line.

Signed-off-by: Michal Privoznik 
---
 tools/virsh-domain-event.c  | 15 +-
 tools/virsh-domain.c| 36 +++--
 tools/virsh-host.c  |  9 +++--
 tools/virsh-network.c   |  6 ++
 tools/virsh-nodedev.c   |  3 +--
 tools/virsh-pool.c  |  3 +--
 tools/virsh.c   |  9 +++--
 tools/virt-admin.c  | 21 +++
 tools/virt-host-validate-ch.c   | 12 ---
 tools/virt-host-validate-qemu.c | 15 +-
 tools/vsh.c | 12 ---
 11 files changed, 47 insertions(+), 94 deletions(-)

diff --git a/tools/virsh-domain-event.c b/tools/virsh-domain-event.c
index 2969c22a91..6887c195a0 100644
--- a/tools/virsh-domain-event.c
+++ b/tools/virsh-domain-event.c
@@ -418,8 +418,7 @@ virshEventGraphicsPrint(virConnectPtr conn G_GNUC_UNUSED,
 g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
 size_t i;
 
-virBufferAsprintf(, _("event 'graphics' for domain '%1$s': "
-  "%2$s local[%3$s %4$s %5$s] remote[%6$s %7$s 
%8$s] %9$s\n"),
+virBufferAsprintf(, _("event 'graphics' for domain '%1$s': %2$s 
local[%3$s %4$s %5$s] remote[%6$s %7$s %8$s] %9$s\n"),
   virDomainGetName(dom),
   virshGraphicsPhaseToString(phase),
   virshGraphicsAddressToString(local->family),
@@ -497,8 +496,7 @@ virshEventDiskChangePrint(virConnectPtr conn G_GNUC_UNUSED,
 {
 g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
 
-virBufferAsprintf(, _("event 'disk-change' for domain '%1$s' disk 
%2$s: "
-  "%3$s -> %4$s: %5$s\n"),
+virBufferAsprintf(, _("event 'disk-change' for domain '%1$s' disk 
%2$s: %3$s -> %4$s: %5$s\n"),
   virDomainGetName(dom),
   alias,
   NULLSTR(oldSrc),
@@ -633,8 +631,7 @@ virshEventAgentLifecyclePrint(virConnectPtr conn 
G_GNUC_UNUSED,
 {
 g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
 
-virBufferAsprintf(, _("event 'agent-lifecycle' for domain '%1$s': 
state: "
-  "'%2$s' reason: '%3$s'\n"),
+virBufferAsprintf(, _("event 'agent-lifecycle' for domain '%1$s': 
state: '%2$s' reason: '%3$s'\n"),
   virDomainGetName(dom),
   
UNKNOWNSTR(virshEventAgentLifecycleStateTypeToString(state)),
   
UNKNOWNSTR(virshEventAgentLifecycleReasonTypeToString(reason)));
@@ -649,8 +646,7 @@ virshEventMigrationIterationPrint(virConnectPtr conn 
G_GNUC_UNUSED,
 {
 g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
 
-virBufferAsprintf(, _("event 'migration-iteration' for domain '%1$s': "
-  "iteration: '%2$d'\n"),
+virBufferAsprintf(, _("event 'migration-iteration' for domain '%1$s': 
iteration: '%2$d'\n"),
   virDomainGetName(dom),
   iteration);
 
@@ -727,8 +723,7 @@ virshEventBlockThresholdPrint(virConnectPtr conn 
G_GNUC_UNUSED,
 {
 g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
 
-virBufferAsprintf(, _("event 'block-threshold' for domain '%1$s': "
-  "dev: %2$s(%3$s) %4$llu %5$llu\n"),
+virBufferAsprintf(, _("event 'block-threshold' for domain '%1$s': dev: 
%2$s(%3$s) %4$llu %5$llu\n"),
   virDomainGetName(dom),
   dev, NULLSTR(path), threshold, excess);
 virshEventPrint(opaque, );
diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index e0776c991f..7250c1989e 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -2143,14 +2143,12 @@ cmdBlockcommit(vshControl *ctl, const vshCmd *cmd)
 
 if (!blocking) {
 if (verbose) {
-vshError(ctl, "%s", _("--verbose requires at least one of 
--timeout, "
-  "--wait, --pivot, or --keep-overlay"));
+vshError(ctl, "%s", _("--verbose requires at least one of 
--timeout, --wait, --pivot, or --keep-overlay"));
 return false;
 }
 
 if (async) {
-vshError(ctl, "%s", _("--async requires at least one of --timeout, 
"
-  "--wait, --pivot, or --keep-overlay"));
+vshError(ctl, "%s", _("--async requires at least one of --timeout, 
--wait, --pivot, or --keep-overlay"));
 return false;
 }
 }
@@ -2214,8 +2212,7 @@ cmdBlockcommit(vshControl *ctl, const vshCmd *cmd)
 goto cleanup;
 }
 
-vshPrintExtra(ctl, "\n%s", _("Commit complete, 

[PATCH 23/27] vmware: Move error messages onto a single line

2023-08-25 Thread Michal Privoznik
Error messages are exempt from the 80 columns rule. Move them
onto one line.

Signed-off-by: Michal Privoznik 
---
 src/vmware/vmware_conf.c   | 9 +++--
 src/vmware/vmware_driver.c | 6 ++
 2 files changed, 5 insertions(+), 10 deletions(-)

diff --git a/src/vmware/vmware_conf.c b/src/vmware/vmware_conf.c
index ba4e4d28dc..a598b512dc 100644
--- a/src/vmware/vmware_conf.c
+++ b/src/vmware/vmware_conf.c
@@ -355,8 +355,7 @@ vmwareVmxPath(virDomainDef *vmdef, char **vmxPath)
  */
 if (vmdef->ndisks < 1) {
 virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-   _("Domain XML doesn't contain any disks, "
- "cannot deduce datastore and path for VMX file"));
+   _("Domain XML doesn't contain any disks, cannot deduce 
datastore and path for VMX file"));
 return -1;
 }
 
@@ -370,16 +369,14 @@ vmwareVmxPath(virDomainDef *vmdef, char **vmxPath)
 
 if (disk == NULL) {
 virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-   _("Domain XML doesn't contain any file-based harddisks, 
"
- "cannot deduce datastore and path for VMX file"));
+   _("Domain XML doesn't contain any file-based harddisks, 
cannot deduce datastore and path for VMX file"));
 return -1;
 }
 
 src = virDomainDiskGetSource(disk);
 if (!src) {
 virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-   _("First file-based harddisk has no source, cannot "
- "deduce datastore and path for VMX file"));
+   _("First file-based harddisk has no source, cannot 
deduce datastore and path for VMX file"));
 return -1;
 }
 
diff --git a/src/vmware/vmware_driver.c b/src/vmware/vmware_driver.c
index 259d00cacd..416ce126e8 100644
--- a/src/vmware/vmware_driver.c
+++ b/src/vmware/vmware_driver.c
@@ -509,8 +509,7 @@ vmwareDomainSuspend(virDomainPtr dom)
 
 if (driver->type == VMWARE_DRIVER_PLAYER) {
 virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-   _("vmplayer does not support libvirt suspend/resume"
- " (vmware pause/unpause) operation "));
+   _("vmplayer does not support libvirt suspend/resume 
(vmware pause/unpause) operation "));
 return ret;
 }
 
@@ -549,8 +548,7 @@ vmwareDomainResume(virDomainPtr dom)
 
 if (driver->type == VMWARE_DRIVER_PLAYER) {
 virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-   _("vmplayer does not support libvirt suspend/resume "
- "(vmware pause/unpause) operation "));
+   _("vmplayer does not support libvirt suspend/resume 
(vmware pause/unpause) operation "));
 return ret;
 }
 
-- 
2.41.0



[PATCH 14/27] qemu: Move error messages onto a single line

2023-08-25 Thread Michal Privoznik
Error messages are exempt from the 80 columns rule. Move them
onto one line.

Signed-off-by: Michal Privoznik 
---
 src/qemu/qemu_agent.c|  18 +--
 src/qemu/qemu_capabilities.c |  45 +++
 src/qemu/qemu_command.c  |  42 ++-
 src/qemu/qemu_conf.c |   5 +-
 src/qemu/qemu_domain.c   |  51 +++-
 src/qemu/qemu_domain_address.c   |  15 +--
 src/qemu/qemu_driver.c   | 120 ++
 src/qemu/qemu_hostdev.c  |   3 +-
 src/qemu/qemu_hotplug.c  |  18 +--
 src/qemu/qemu_migration.c|  48 +++
 src/qemu/qemu_migration_params.c |   6 +-
 src/qemu/qemu_monitor.c  |   3 +-
 src/qemu/qemu_monitor_json.c | 102 +--
 src/qemu/qemu_process.c  |  20 +--
 src/qemu/qemu_snapshot.c |  27 ++--
 src/qemu/qemu_tpm.c  |   4 +-
 src/qemu/qemu_validate.c | 209 ++-
 17 files changed, 243 insertions(+), 493 deletions(-)

diff --git a/src/qemu/qemu_agent.c b/src/qemu/qemu_agent.c
index 7fc412c17e..f9bcf38dfb 100644
--- a/src/qemu/qemu_agent.c
+++ b/src/qemu/qemu_agent.c
@@ -160,8 +160,7 @@ qemuAgentOpenUnix(const char *socketpath)
 
 if (virSetCloseExec(agentfd) < 0) {
 virReportSystemError(errno, "%s",
- _("Unable to set agent "
-   "close-on-exec flag"));
+ _("Unable to set agent close-on-exec flag"));
 goto error;
 }
 
@@ -757,8 +756,7 @@ static int qemuAgentSend(qemuAgent *agent,
 ret = -2;
 } else {
 virReportSystemError(errno, "%s",
- _("Unable to wait on agent socket "
-   "condition"));
+ _("Unable to wait on agent socket 
condition"));
 }
 agent->inSync = false;
 goto cleanup;
@@ -1344,8 +1342,7 @@ qemuAgentGetVCPUs(qemuAgent *agent,
 
 if (!entry) {
 virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-   _("array element missing in guest-get-vcpus return "
- "value"));
+   _("array element missing in guest-get-vcpus return 
value"));
 return -1;
 }
 
@@ -1862,8 +1859,7 @@ qemuAgentGetFSInfo(qemuAgent *agent,
 
 if (!(result = virJSONValueObjectGetString(entry, "mountpoint"))) {
 virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-   _("'mountpoint' missing in reply of "
- "guest-get-fsinfo"));
+   _("'mountpoint' missing in reply of 
guest-get-fsinfo"));
 goto cleanup;
 }
 
@@ -2207,8 +2203,7 @@ qemuAgentGetUsers(qemuAgent *agent,
 
 if (!entry) {
 virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-   _("array element missing in guest-get-users return "
- "value"));
+   _("array element missing in guest-get-users return 
value"));
 return -1;
 }
 
@@ -2522,8 +2517,7 @@ int qemuAgentGetDisks(qemuAgent *agent,
 
 if (!entry) {
 virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-   _("array element missing in guest-get-disks return "
- "value"));
+   _("array element missing in guest-get-disks return 
value"));
 goto error;
 }
 
diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index 05cc11218a..bdb20b47ba 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -3957,8 +3957,7 @@ virQEMUCapsLoadHostCPUModelInfo(virQEMUCapsAccel *caps,
 
 if (!(hostCPU->name = virXMLPropString(hostCPUNode, "model"))) {
 virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-   _("missing host CPU model name in QEMU "
- "capabilities cache"));
+   _("missing host CPU model name in QEMU capabilities 
cache"));
 return -1;
 }
 
@@ -3983,16 +3982,14 @@ virQEMUCapsLoadHostCPUModelInfo(virQEMUCapsAccel *caps,
 
 if (!(prop->name = virXMLPropString(ctxt->node, "name"))) {
 virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-   _("missing 'name' attribute for a host CPU"
- " model property in QEMU capabilities 
cache"));
+   _("missing 'name' attribute for a ho

[PATCH 08/27] locking: Move error messages onto a single line

2023-08-25 Thread Michal Privoznik
Error messages are exempt from the 80 columns rule. Move them
onto one line.

Signed-off-by: Michal Privoznik 
---
 src/locking/lock_driver_sanlock.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/src/locking/lock_driver_sanlock.c 
b/src/locking/lock_driver_sanlock.c
index dc24862a6f..a07f3652c1 100644
--- a/src/locking/lock_driver_sanlock.c
+++ b/src/locking/lock_driver_sanlock.c
@@ -831,8 +831,7 @@ virLockManagerSanlockRegisterKillscript(int sock,
 VIR_FREE(err);
 } else {
 virReportSystemError(-rv, "%s",
- _("Failed to register lock failure"
-   " action"));
+ _("Failed to register lock failure action"));
 }
 return -1;
 }
-- 
2.41.0



[PATCH 05/27] esx: Move error messages onto a single line

2023-08-25 Thread Michal Privoznik
Error messages are exempt from the 80 columns rule. Move them
onto one line.

Signed-off-by: Michal Privoznik 
---
 src/esx/esx_driver.c   | 21 +++--
 src/esx/esx_network_driver.c   |  3 +--
 src/esx/esx_storage_backend_vmfs.c |  3 +--
 src/esx/esx_util.c |  3 +--
 src/esx/esx_vi.c   | 19 ++-
 src/esx/esx_vi_types.c |  3 +--
 6 files changed, 17 insertions(+), 35 deletions(-)

diff --git a/src/esx/esx_driver.c b/src/esx/esx_driver.c
index b243bbf411..554fb3e18f 100644
--- a/src/esx/esx_driver.c
+++ b/src/esx/esx_driver.c
@@ -2916,8 +2916,7 @@ esxDomainDefineXMLFlags(virConnectPtr conn, const char 
*xml, unsigned int flags)
 if (virtualMachine) {
 /* FIXME */
 virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-   _("Domain already exists, editing existing domains is 
not "
- "supported yet"));
+   _("Domain already exists, editing existing domains is 
not supported yet"));
 goto cleanup;
 }
 
@@ -2952,8 +2951,7 @@ esxDomainDefineXMLFlags(virConnectPtr conn, const char 
*xml, unsigned int flags)
  */
 if (def->ndisks < 1) {
 virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-   _("Domain XML doesn't contain any disks, cannot deduce "
- "datastore and path for VMX file"));
+   _("Domain XML doesn't contain any disks, cannot deduce 
datastore and path for VMX file"));
 goto cleanup;
 }
 
@@ -2967,16 +2965,14 @@ esxDomainDefineXMLFlags(virConnectPtr conn, const char 
*xml, unsigned int flags)
 
 if (!disk) {
 virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-   _("Domain XML doesn't contain any file-based harddisks, 
"
- "cannot deduce datastore and path for VMX file"));
+   _("Domain XML doesn't contain any file-based harddisks, 
cannot deduce datastore and path for VMX file"));
 goto cleanup;
 }
 
 src = virDomainDiskGetSource(disk);
 if (!src) {
 virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-   _("First file-based harddisk has no source, cannot 
deduce "
- "datastore and path for VMX file"));
+   _("First file-based harddisk has no source, cannot 
deduce datastore and path for VMX file"));
 goto cleanup;
 }
 
@@ -3241,8 +3237,7 @@ esxDomainSetAutostart(virDomainPtr domain, int autostart)
  powerInfo = powerInfo->_next) {
 if (STRNEQ(powerInfo->key->value, virtualMachine->obj->value)) 
{
 virReportError(VIR_ERR_OPERATION_INVALID, "%s",
-   _("Cannot enable general autostart option "
- "without affecting other domains"));
+   _("Cannot enable general autostart option 
without affecting other domains"));
 goto cleanup;
 }
 }
@@ -3685,8 +3680,7 @@ esxDomainMigratePerform(virDomainPtr domain,
 
 if (STRCASENEQ(priv->vCenter->ipAddress, parsedUri->server)) {
 virReportError(VIR_ERR_INVALID_ARG, "%s",
-   _("Migration source and destination have to refer to "
- "the same vCenter"));
+   _("Migration source and destination have to refer to 
the same vCenter"));
 goto cleanup;
 }
 
@@ -3734,8 +3728,7 @@ esxDomainMigratePerform(virDomainPtr domain,
eventList->fullFormattedMessage);
 } else {
 virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-   _("Could not migrate domain, validation reported a "
- "problem"));
+   _("Could not migrate domain, validation reported a 
problem"));
 }
 
 goto cleanup;
diff --git a/src/esx/esx_network_driver.c b/src/esx/esx_network_driver.c
index 273147af40..1ee4d6c34f 100644
--- a/src/esx/esx_network_driver.c
+++ b/src/esx/esx_network_driver.c
@@ -311,8 +311,7 @@ esxNetworkDefineXMLFlags(virConnectPtr conn, const char 
*xml,
 if (hostVirtualSwitch) {
 /* FIXME */
 virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-   _("HostVirtualSwitch already exists, editing existing "
- "ones is not supported yet"));
+   _("HostVirtualSwitch already exists, editing existing 
ones is not supported yet"));
 goto cl

[PATCH 22/27] vbox: Move error messages onto a single line

2023-08-25 Thread Michal Privoznik
Error messages are exempt from the 80 columns rule. Move them
onto one line.

Signed-off-by: Michal Privoznik 
---
 src/vbox/vbox_snapshot_conf.c | 6 ++
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/src/vbox/vbox_snapshot_conf.c b/src/vbox/vbox_snapshot_conf.c
index 6dbd18d657..84f7aceac2 100644
--- a/src/vbox/vbox_snapshot_conf.c
+++ b/src/vbox/vbox_snapshot_conf.c
@@ -736,8 +736,7 @@ 
virVBoxSnapshotConfAddSnapshotToXmlMachine(virVBoxSnapshotConfSnapshot *snapshot
 if (snapshotParentName == NULL) {
 if (machine->snapshot != NULL) {
 virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-   _("Unable to add this snapshot, there is already a 
snapshot "
- "linked to the machine"));
+   _("Unable to add this snapshot, there is already a 
snapshot linked to the machine"));
 return -1;
 }
 machine->snapshot = snapshot;
@@ -840,8 +839,7 @@ 
virVBoxSnapshotConfRemoveSnapshot(virVBoxSnapshotConfMachine *machine,
 }
 if (snapshot->nchildren > 0) {
 virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-   _("This snapshot has children, "
- "please delete these snapshots before"));
+   _("This snapshot has children, please delete these 
snapshots before"));
 return -1;
 }
 
-- 
2.41.0



[PATCH 21/27] util: Move error messages onto a single line

2023-08-25 Thread Michal Privoznik
Error messages are exempt from the 80 columns rule. Move them
onto one line.

Signed-off-by: Michal Privoznik 
---
 src/util/vircgroupv2devices.c| 13 -
 src/util/vircommand.c|  3 +--
 src/util/virfile.c   |  3 +--
 src/util/virhostcpu.c|  3 +--
 src/util/virhostmem.c|  6 ++
 src/util/virjson.c   |  3 +--
 src/util/virmdev.c   |  3 +--
 src/util/virnetdev.c | 12 
 src/util/virnetdevbandwidth.c|  6 ++
 src/util/virnetdevopenvswitch.c  |  6 ++
 src/util/virnetdevvportprofile.c |  6 ++
 src/util/virnetlink.c|  3 +--
 src/util/virnuma.c   |  6 ++
 src/util/virpci.c|  3 +--
 src/util/virprocess.c|  9 +++--
 src/util/virqemu.c   |  3 +--
 src/util/virresctrl.c|  9 +++--
 src/util/virthreadpool.c |  3 +--
 18 files changed, 33 insertions(+), 67 deletions(-)

diff --git a/src/util/vircgroupv2devices.c b/src/util/vircgroupv2devices.c
index f740127bbc..7deb233c06 100644
--- a/src/util/vircgroupv2devices.c
+++ b/src/util/vircgroupv2devices.c
@@ -444,9 +444,7 @@ virCgroupV2DevicesCreateMap(size_t size)
 if (mapfd < 0) {
 if (errno == EPERM) {
 virReportSystemError(errno, "%s",
- _("failed to initialize device BPF map; "
-   "locked memory limit for libvirtd probably "
-   "needs to be raised"));
+ _("failed to initialize device BPF map; 
locked memory limit for libvirtd probably needs to be raised"));
 return -1;
 } else {
 virReportSystemError(errno, "%s",
@@ -595,8 +593,7 @@ int
 virCgroupV2DevicesDetectProg(virCgroup *group G_GNUC_UNUSED)
 {
 virReportSystemError(ENOSYS, "%s",
- _("cgroups v2 BPF devices not supported "
-   "with this kernel"));
+ _("cgroups v2 BPF devices not supported with this 
kernel"));
 return -1;
 }
 
@@ -605,8 +602,7 @@ int
 virCgroupV2DevicesCreateProg(virCgroup *group G_GNUC_UNUSED)
 {
 virReportSystemError(ENOSYS, "%s",
- _("cgroups v2 BPF devices not supported "
-   "with this kernel"));
+ _("cgroups v2 BPF devices not supported with this 
kernel"));
 return -1;
 }
 
@@ -615,8 +611,7 @@ int
 virCgroupV2DevicesPrepareProg(virCgroup *group G_GNUC_UNUSED)
 {
 virReportSystemError(ENOSYS, "%s",
- _("cgroups v2 BPF devices not supported "
-   "with this kernel"));
+ _("cgroups v2 BPF devices not supported with this 
kernel"));
 return -1;
 }
 
diff --git a/src/util/vircommand.c b/src/util/vircommand.c
index 5f094c625a..704069815a 100644
--- a/src/util/vircommand.c
+++ b/src/util/vircommand.c
@@ -2691,8 +2691,7 @@ virCommandRunAsync(virCommand *cmd, pid_t *pid)
 virCommandDoAsyncIOHelper,
 "cmd-async-io", false, cmd) < 0) {
 virReportSystemError(errno, "%s",
- _("Unable to create thread "
-   "to process command's IO"));
+ _("Unable to create thread to process 
command's IO"));
 VIR_FREE(cmd->asyncioThread);
 virCommandAbort(cmd);
 ret = -1;
diff --git a/src/util/virfile.c b/src/util/virfile.c
index 0600e4a172..bd36a9a31a 100644
--- a/src/util/virfile.c
+++ b/src/util/virfile.c
@@ -1094,8 +1094,7 @@ virFileNBDLoadDriver(void)
 {
 if (virKModIsProhibited(NBD_DRIVER)) {
 virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-   _("Failed to load nbd module: "
- "administratively prohibited"));
+   _("Failed to load nbd module: administratively 
prohibited"));
 return false;
 } else {
 g_autofree char *errbuf = NULL;
diff --git a/src/util/virhostcpu.c b/src/util/virhostcpu.c
index a15731e9ea..0389012ef7 100644
--- a/src/util/virhostcpu.c
+++ b/src/util/virhostcpu.c
@@ -892,8 +892,7 @@ virHostCPUStatsAssign(virNodeCPUStatsPtr param,
 {
 if (virStrcpyStatic(param->field, name) < 0) {
 virReportError(VIR_ERR_INTERNAL_ERROR,
-   "%s", _("kernel cpu time field is too long"
-   " for the destination"));
+   "%s", _("kernel cpu time field is too long for the 
des

[PATCH 26/27] src: Move error messages onto a single line

2023-08-25 Thread Michal Privoznik
Error messages are exempt from the 80 columns rule. Move them
onto one line.

Signed-off-by: Michal Privoznik 
---
 src/libvirt-domain.c | 54 +++-
 1 file changed, 18 insertions(+), 36 deletions(-)

diff --git a/src/libvirt-domain.c b/src/libvirt-domain.c
index ec42bb9a53..6616294fc1 100644
--- a/src/libvirt-domain.c
+++ b/src/libvirt-domain.c
@@ -3569,8 +3569,7 @@ virDomainMigrateUnmanagedProto2(virDomainPtr domain,
 if (!virTypedParamsCheck(params, nparams, compatParams,
  G_N_ELEMENTS(compatParams))) {
 virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, "%s",
-   _("Some parameters are not supported by migration "
- "protocol 2"));
+   _("Some parameters are not supported by migration 
protocol 2"));
 return -1;
 }
 
@@ -3618,8 +3617,7 @@ virDomainMigrateUnmanagedProto3(virDomainPtr domain,
 if (!virTypedParamsCheck(params, nparams, compatParams,
  G_N_ELEMENTS(compatParams))) {
 virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, "%s",
-   _("Some parameters are not supported by migration "
- "protocol 3"));
+   _("Some parameters are not supported by migration 
protocol 3"));
 return -1;
 }
 
@@ -3822,8 +3820,7 @@ virDomainMigrate(virDomainPtr domain,
 if (rc <= 0) {
 if (rc == 0)
 virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, "%s",
-   _("offline migration is not supported by "
- "the source host"));
+   _("offline migration is not supported by the 
source host"));
 goto error;
 }
 
@@ -3832,8 +3829,7 @@ virDomainMigrate(virDomainPtr domain,
 if (rc <= 0) {
 if (rc == 0)
 virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, "%s",
-   _("offline migration is not supported by "
- "the destination host"));
+   _("offline migration is not supported by the 
destination host"));
 goto error;
 }
 }
@@ -4021,8 +4017,7 @@ virDomainMigrate2(virDomainPtr domain,
 if (rc <= 0) {
 if (rc == 0)
 virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, "%s",
-   _("offline migration is not supported by "
- "the source host"));
+   _("offline migration is not supported by the 
source host"));
 goto error;
 }
 rc = VIR_DRV_SUPPORTS_FEATURE(dconn->driver, dconn,
@@ -4030,8 +4025,7 @@ virDomainMigrate2(virDomainPtr domain,
 if (rc <= 0) {
 if (rc == 0)
 virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, "%s",
-   _("offline migration is not supported by "
- "the destination host"));
+   _("offline migration is not supported by the 
destination host"));
 goto error;
 }
 }
@@ -4233,14 +4227,12 @@ virDomainMigrate3(virDomainPtr domain,
 
 if (flags & VIR_MIGRATE_PEER2PEER) {
 virReportInvalidArg(flags, "%s",
-_("use virDomainMigrateToURI3 for peer-to-peer "
-  "migration"));
+_("use virDomainMigrateToURI3 for peer-to-peer 
migration"));
 goto error;
 }
 if (flags & VIR_MIGRATE_TUNNELLED) {
 virReportInvalidArg(flags, "%s",
-_("cannot perform tunnelled migration "
-  "without using peer2peer flag"));
+_("cannot perform tunnelled migration without 
using peer2peer flag"));
 goto error;
 }
 
@@ -4250,8 +4242,7 @@ virDomainMigrate3(virDomainPtr domain,
 if (rc <= 0) {
 if (rc == 0)
 virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, "%s",
-   _("offline migration is not supported by "
- "the source host"));
+   _("offline migration is not supported by the 
source host"));
 goto error;
 }
 
@@ -4260,8 +4251,7 @@ virDomainMigrate3(virDomainPtr domain,
 if (rc <= 0) {
 if (rc == 0)
 virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, "%s"

[PATCH 15/27] remote: Move error messages onto a single line

2023-08-25 Thread Michal Privoznik
Error messages are exempt from the 80 columns rule. Move them
onto one line.

Signed-off-by: Michal Privoznik 
---
 src/remote/remote_daemon.c  |  3 +--
 src/remote/remote_driver.c  | 27 +--
 src/remote/remote_sockets.c |  3 +--
 3 files changed, 11 insertions(+), 22 deletions(-)

diff --git a/src/remote/remote_daemon.c b/src/remote/remote_daemon.c
index d4d999e53a..657c053f6f 100644
--- a/src/remote/remote_daemon.c
+++ b/src/remote/remote_daemon.c
@@ -219,8 +219,7 @@ daemonSetupNetworking(virNetServer *srv,
 #ifdef WITH_IP
 # ifdef LIBVIRTD
 if (act && ipsock) {
-VIR_ERROR(_("--listen parameter not permitted with systemd activation "
-"sockets, see 'man libvirtd' for further guidance"));
+VIR_ERROR(_("--listen parameter not permitted with systemd activation 
sockets, see 'man libvirtd' for further guidance"));
 return -1;
 }
 # else /* ! LIBVIRTD */
diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c
index faad7292ed..2f8c9800a7 100644
--- a/src/remote/remote_driver.c
+++ b/src/remote/remote_driver.c
@@ -1103,8 +1103,7 @@ doRemoteOpen(virConnectPtr conn,
 case REMOTE_DRIVER_TRANSPORT_SSH:
 case REMOTE_DRIVER_TRANSPORT_EXT:
 virReportError(VIR_ERR_INVALID_ARG, "%s",
-   _("transport methods unix, ssh and ext are not 
supported "
- "under Windows"));
+   _("transport methods unix, ssh and ext are not 
supported under Windows"));
 goto error;
 
 #endif /* WIN32 */
@@ -1478,8 +1477,7 @@ remoteNodeGetCPUStats(virConnectPtr conn,
 if (ret.params.params_len > REMOTE_NODE_CPU_STATS_MAX ||
 ret.params.params_len > *nparams) {
 virReportError(VIR_ERR_RPC, "%s",
-   _("remoteNodeGetCPUStats: "
- "returned number of stats exceeds limit"));
+   _("remoteNodeGetCPUStats: returned number of stats 
exceeds limit"));
 goto cleanup;
 }
 /* Handle the case when the caller does not know the number of stats
@@ -1538,8 +1536,7 @@ remoteNodeGetMemoryStats(virConnectPtr conn,
 if (ret.params.params_len > REMOTE_NODE_MEMORY_STATS_MAX ||
 ret.params.params_len > *nparams) {
 virReportError(VIR_ERR_RPC, "%s",
-   _("remoteNodeGetMemoryStats: "
- "returned number of stats exceeds limit"));
+   _("remoteNodeGetMemoryStats: returned number of stats 
exceeds limit"));
 goto cleanup;
 }
 /* Handle the case when the caller does not know the number of stats
@@ -1703,8 +1700,7 @@ remoteDomainBlockStatsFlags(virDomainPtr domain,
 if (ret.params.params_len > REMOTE_DOMAIN_BLOCK_STATS_PARAMETERS_MAX ||
 ret.params.params_len > *nparams) {
 virReportError(VIR_ERR_RPC, "%s",
-   _("remoteDomainBlockStatsFlags: "
- "returned number of stats exceeds limit"));
+   _("remoteDomainBlockStatsFlags: returned number of 
stats exceeds limit"));
 goto cleanup;
 }
 
@@ -2760,8 +2756,7 @@ static int remoteDomainGetCPUStats(virDomainPtr domain,
 (ret.params.params_len &&
  ((ret.params.params_len % ret.nparams) || ret.nparams > nparams))) {
 virReportError(VIR_ERR_RPC, "%s",
-   _("remoteDomainGetCPUStats: "
- "returned number of stats exceeds limit"));
+   _("remoteDomainGetCPUStats: returned number of stats 
exceeds limit"));
 memset(params, 0, sizeof(*params) * nparams * ncpus);
 goto cleanup;
 }
@@ -6114,8 +6109,7 @@ remoteConnectSetKeepAlive(virConnectPtr conn, int 
interval, unsigned int count)
 
 if (!virNetClientKeepAliveIsSupported(priv->client)) {
 virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-   _("the caller doesn't support keepalive protocol;"
- " perhaps it's missing event loop implementation"));
+   _("the caller doesn't support keepalive protocol; 
perhaps it's missing event loop implementation"));
 return -1;
 }
 
@@ -7562,8 +7556,7 @@ remoteDomainAuthorizedSSHKeysGet(virDomainPtr domain,
 
 if (ret.keys.keys_len > REMOTE_DOMAIN_AUTHORIZED_SSH_KEYS_MAX) {
 virReportError(VIR_ERR_RPC, "%s",
-   _("remoteDomainAuthorizedSSHKeysGet: "
- "returned number of keys exceeds limit"));
+   _("remoteDomainAuthorizedSSHKeysGet: returned number of 
keys exceeds 

[PATCH 25/27] vz: Move error messages onto a single line

2023-08-25 Thread Michal Privoznik
Error messages are exempt from the 80 columns rule. Move them
onto one line.

Signed-off-by: Michal Privoznik 
---
 src/vz/vz_driver.c |  15 ++---
 src/vz/vz_sdk.c| 135 +++--
 src/vz/vz_utils.c  |  66 --
 3 files changed, 72 insertions(+), 144 deletions(-)

diff --git a/src/vz/vz_driver.c b/src/vz/vz_driver.c
index 401ca041ed..c7ceec2339 100644
--- a/src/vz/vz_driver.c
+++ b/src/vz/vz_driver.c
@@ -842,8 +842,7 @@ vzDomainDefineXMLFlags(virConnectPtr conn, const char *xml, 
unsigned int flags)
 
 if (!virDomainDefCheckABIStability(dom->def, def, driver->xmlopt)) 
{
 virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, "%s",
-   _("Can't change domain configuration "
- "in managed save state"));
+   _("Can't change domain configuration in managed 
save state"));
 goto cleanup;
 }
 } else {
@@ -1461,15 +1460,13 @@ static int vzCheckConfigUpdateFlags(virDomainObj *dom, 
unsigned int *flags)
 
 if (!(*flags & VIR_DOMAIN_AFFECT_CONFIG)) {
 virReportError(VIR_ERR_OPERATION_INVALID, "%s",
-   _("domain config update needs VIR_DOMAIN_AFFECT_CONFIG "
- "flag to be set"));
+   _("domain config update needs VIR_DOMAIN_AFFECT_CONFIG 
flag to be set"));
 return -1;
 }
 
 if (virDomainObjIsActive(dom) && !(*flags & VIR_DOMAIN_AFFECT_LIVE)) {
 virReportError(VIR_ERR_OPERATION_INVALID, "%s",
-   _("Updates on a running domain need "
- "VIR_DOMAIN_AFFECT_LIVE flag"));
+   _("Updates on a running domain need 
VIR_DOMAIN_AFFECT_LIVE flag"));
 return -1;
 }
 
@@ -2793,8 +2790,7 @@ vzEatCookie(const char *cookiein, int cookieinlen, 
unsigned int flags)
 if ((!(tmp = virXPathString("string(./session-uuid[1])", ctx))
 || (virUUIDParse(tmp, mig->session_uuid) < 0))) {
 virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-   _("missing or malformed session-uuid element "
- "in migration data"));
+   _("missing or malformed session-uuid element in 
migration data"));
 goto error;
 }
 }
@@ -2921,8 +2917,7 @@ vzMigrationCreateURI(void)
 
 if (STRPREFIX(hostname, "localhost")) {
 virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-   _("hostname on destination resolved to localhost,"
- " but migration requires an FQDN"));
+   _("hostname on destination resolved to localhost, but 
migration requires an FQDN"));
 goto cleanup;
 }
 
diff --git a/src/vz/vz_sdk.c b/src/vz/vz_sdk.c
index 286b52a29e..6a15d60577 100644
--- a/src/vz/vz_sdk.c
+++ b/src/vz/vz_sdk.c
@@ -2415,15 +2415,13 @@ prlsdkCheckUnsupportedParams(PRL_HANDLE sdkdom, 
virDomainDef *def)
 
 if (def->blkio.ndevices > 0) {
 virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-   _("blkio parameters are not supported "
- "by vz driver"));
+   _("blkio parameters are not supported by vz driver"));
 return -1;
 }
 
 if (virDomainDefGetMemoryTotal(def) != def->mem.cur_balloon) {
 virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-   _("changing balloon parameters is not supported "
- "by vz driver"));
+   _("changing balloon parameters is not supported by vz 
driver"));
 return -1;
 }
 
@@ -2440,8 +2438,7 @@ prlsdkCheckUnsupportedParams(PRL_HANDLE sdkdom, 
virDomainDef *def)
 virMemoryLimitIsSet(def->mem.swap_hard_limit)) {
 
 virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-   _("Memory parameter is not supported "
- "by vz driver"));
+   _("Memory parameter is not supported by vz driver"));
 return -1;
 }
 
@@ -2453,8 +2450,7 @@ prlsdkCheckUnsupportedParams(PRL_HANDLE sdkdom, 
virDomainDef *def)
 
 if (def->placement_mode) {
 virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-   _("changing cpu placement mode is not supported "
- "by vz driver"));
+   _("changing cpu placement mode is not supported by vz 
driver"));
 return -1;
 }
 
@@ -24

[PATCH 12/27] nwfilter: Move error messages onto a single line

2023-08-25 Thread Michal Privoznik
Error messages are exempt from the 80 columns rule. Move them
onto one line.

Signed-off-by: Michal Privoznik 
---
 src/nwfilter/nwfilter_dhcpsnoop.c   | 12 
 src/nwfilter/nwfilter_learnipaddr.c |  8 ++--
 2 files changed, 6 insertions(+), 14 deletions(-)

diff --git a/src/nwfilter/nwfilter_dhcpsnoop.c 
b/src/nwfilter/nwfilter_dhcpsnoop.c
index 2f89923856..26072ec26e 100644
--- a/src/nwfilter/nwfilter_dhcpsnoop.c
+++ b/src/nwfilter/nwfilter_dhcpsnoop.c
@@ -1441,9 +1441,7 @@ virNWFilterDHCPSnoopReq(virNWFilterTechDriver *techdriver,
 /* check that all tools are available for applying the filters (late) */
 if (!techdriver->canApplyBasicRules()) {
 virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-   _("IP parameter must be provided since "
- "snooping the IP address does not work "
- "possibly due to missing tools"));
+   _("IP parameter must be provided since snooping the IP 
address does not work possibly due to missing tools"));
 goto exit_snoopreqput;
 }
 
@@ -1454,8 +1452,7 @@ virNWFilterDHCPSnoopReq(virNWFilterTechDriver *techdriver,
>binding->mac,
dhcpsrvrs, false) < 0) {
 virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-   _("applyDHCPOnlyRules "
- "failed - spoofing not protected!"));
+   _("applyDHCPOnlyRules failed - spoofing not 
protected!"));
 goto exit_snoopreqput;
 }
 
@@ -1990,9 +1987,8 @@ virNWFilterDHCPSnoopReq(virNWFilterTechDriver *techdriver 
G_GNUC_UNUSED,
 virNWFilterDriverState *driver G_GNUC_UNUSED)
 {
 virReportError(VIR_ERR_INTERNAL_ERROR,
-   _("libvirt was not compiled with libpcap and \""
- NWFILTER_VARNAME_CTRL_IP_LEARNING
- "='dhcp'\" requires it."));
+   _("libvirt was not compiled with libpcap and \"%1$s\" 
requires it"),
+ NWFILTER_VARNAME_CTRL_IP_LEARNING "='dhcp'");
 return -1;
 }
 #endif /* WITH_LIBPCAP */
diff --git a/src/nwfilter/nwfilter_learnipaddr.c 
b/src/nwfilter/nwfilter_learnipaddr.c
index 90e9a21a4e..73d8302c13 100644
--- a/src/nwfilter/nwfilter_learnipaddr.c
+++ b/src/nwfilter/nwfilter_learnipaddr.c
@@ -669,9 +669,7 @@ virNWFilterLearnIPAddress(virNWFilterTechDriver *techdriver,
 
 if (!techdriver->canApplyBasicRules()) {
 virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-   _("IP parameter must be provided since "
- "snooping the IP address does not work "
- "possibly due to missing tools"));
+   _("IP parameter must be provided since snooping the IP 
address does not work possibly due to missing tools"));
 return -1;
 }
 
@@ -717,9 +715,7 @@ virNWFilterLearnIPAddress(virNWFilterTechDriver *techdriver 
G_GNUC_UNUSED,
   int howDetect G_GNUC_UNUSED)
 {
 virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-   _("IP parameter must be given since libvirt "
- "was not compiled with IP address learning "
- "support"));
+   _("IP parameter must be given since libvirt was not 
compiled with IP address learning support"));
 return -1;
 }
 #endif /* WITH_LIBPCAP */
-- 
2.41.0



[PATCH 20/27] test: Move error messages onto a single line

2023-08-25 Thread Michal Privoznik
Error messages are exempt from the 80 columns rule. Move them
onto one line.

Signed-off-by: Michal Privoznik 
---
 src/test/test_driver.c | 39 +--
 1 file changed, 13 insertions(+), 26 deletions(-)

diff --git a/src/test/test_driver.c b/src/test/test_driver.c
index 905be3853b..5908489a50 100644
--- a/src/test/test_driver.c
+++ b/src/test/test_driver.c
@@ -2691,8 +2691,7 @@ static int testDomainSetMemoryStatsPeriod(virDomainPtr 
dom,
 
 if (!virDomainDefHasMemballoon(def)) {
 virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-   _("No memory balloon device configured, "
- "can not set the collection period"));
+   _("No memory balloon device configured, can not set the 
collection period"));
 goto cleanup;
 }
 
@@ -2727,22 +2726,19 @@ static int testDomainSetMemoryFlags(virDomainPtr domain,
 if (flags & VIR_DOMAIN_MEM_MAXIMUM) {
 if (live) {
 virReportError(VIR_ERR_OPERATION_INVALID, "%s",
-   _("cannot resize the maximum memory on an "
- "active domain"));
+   _("cannot resize the maximum memory on an active 
domain"));
 goto cleanup;
 }
 
 if (virDomainNumaGetNodeCount(def->numa) > 0) {
 virReportError(VIR_ERR_OPERATION_INVALID, "%s",
-   _("initial memory size of a domain with NUMA "
- "nodes cannot be modified with this API"));
+   _("initial memory size of a domain with NUMA nodes 
cannot be modified with this API"));
 goto cleanup;
 }
 
 if (def->mem.max_memory && def->mem.max_memory < memory) {
 virReportError(VIR_ERR_OPERATION_INVALID, "%s",
-   _("cannot set initial memory size greater than "
- "the maximum memory size"));
+   _("cannot set initial memory size greater than the 
maximum memory size"));
 goto cleanup;
 }
 
@@ -3413,8 +3409,7 @@ testDomainSetMemoryParameters(virDomainPtr dom,
 
 if (mem_limit > swap_limit) {
 virReportError(VIR_ERR_INVALID_ARG, "%s",
-   _("memory hard_limit tunable value must be lower "
- "than or equal to swap_hard_limit"));
+   _("memory hard_limit tunable value must be lower 
than or equal to swap_hard_limit"));
 goto cleanup;
 }
 }
@@ -3945,32 +3940,28 @@ testDomainSetBlockIoTune(virDomainPtr dom,
 if ((info.total_bytes_sec && info.read_bytes_sec) ||
 (info.total_bytes_sec && info.write_bytes_sec)) {
 virReportError(VIR_ERR_INVALID_ARG, "%s",
-   _("total and read/write of bytes_sec "
- "cannot be set at the same time"));
+   _("total and read/write of bytes_sec cannot be set at 
the same time"));
 goto cleanup;
 }
 
 if ((info.total_iops_sec && info.read_iops_sec) ||
 (info.total_iops_sec && info.write_iops_sec)) {
 virReportError(VIR_ERR_INVALID_ARG, "%s",
-   _("total and read/write of iops_sec "
- "cannot be set at the same time"));
+   _("total and read/write of iops_sec cannot be set at 
the same time"));
 goto cleanup;
 }
 
 if ((info.total_bytes_sec_max && info.read_bytes_sec_max) ||
 (info.total_bytes_sec_max && info.write_bytes_sec_max)) {
 virReportError(VIR_ERR_INVALID_ARG, "%s",
-   _("total and read/write of bytes_sec_max "
- "cannot be set at the same time"));
+   _("total and read/write of bytes_sec_max cannot be set 
at the same time"));
 goto cleanup;
 }
 
 if ((info.total_iops_sec_max && info.read_iops_sec_max) ||
 (info.total_iops_sec_max && info.write_iops_sec_max)) {
 virReportError(VIR_ERR_INVALID_ARG, "%s",
-   _("total and read/write of iops_sec_max "
- "cannot be set at the same time"));
+   _("total and read/write of iops_sec_max cannot be set 
at the same time"));
 goto cleanup;
 }
 
@@ -4578,8 +4569,7 @@ static int testDomainUndefineFlags(virDomainPtr domain,
 if (privdom->hasManagedSave &&
 

[PATCH 13/27] openvz: Move error messages onto a single line

2023-08-25 Thread Michal Privoznik
Error messages are exempt from the 80 columns rule. Move them
onto one line.

Signed-off-by: Michal Privoznik 
---
 src/openvz/openvz_driver.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/src/openvz/openvz_driver.c b/src/openvz/openvz_driver.c
index 69e4c9899b..1bd96dfb56 100644
--- a/src/openvz/openvz_driver.c
+++ b/src/openvz/openvz_driver.c
@@ -2033,8 +2033,7 @@ openvzDomainMigratePrepare3Params(virConnectPtr dconn,
 
 if (STRPREFIX(my_hostname, "localhost")) {
 virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-   _("hostname on destination resolved to localhost,"
- " but migration requires an FQDN"));
+   _("hostname on destination resolved to localhost, 
but migration requires an FQDN"));
 goto error;
 }
 
-- 
2.41.0



[PATCH 24/27] vmx: Move error messages onto a single line

2023-08-25 Thread Michal Privoznik
Error messages are exempt from the 80 columns rule. Move them
onto one line.

Signed-off-by: Michal Privoznik 
---
 src/vmx/vmx.c | 21 +++--
 1 file changed, 7 insertions(+), 14 deletions(-)

diff --git a/src/vmx/vmx.c b/src/vmx/vmx.c
index 5c6925be22..26b89776e1 100644
--- a/src/vmx/vmx.c
+++ b/src/vmx/vmx.c
@@ -938,8 +938,7 @@ virVMXSCSIDiskNameToControllerAndUnit(const char *name, int 
*controller, int *un
 
 if (! STRPREFIX(name, "sd")) {
 virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-   _("Expecting domain XML attribute 'dev' of entry "
- "'devices/disk/target' to start with 'sd'"));
+   _("Expecting domain XML attribute 'dev' of entry 
'devices/disk/target' to start with 'sd'"));
 return -1;
 }
 
@@ -977,8 +976,7 @@ virVMXIDEDiskNameToBusAndUnit(const char *name, int *bus, 
int *unit)
 
 if (! STRPREFIX(name, "hd")) {
 virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-   _("Expecting domain XML attribute 'dev' of entry "
- "'devices/disk/target' to start with 'hd'"));
+   _("Expecting domain XML attribute 'dev' of entry 
'devices/disk/target' to start with 'hd'"));
 return -1;
 }
 
@@ -1012,8 +1010,7 @@ virVMXFloppyDiskNameToUnit(const char *name, int *unit)
 
 if (! STRPREFIX(name, "fd")) {
 virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-   _("Expecting domain XML attribute 'dev' of entry "
- "'devices/disk/target' to start with 'fd'"));
+   _("Expecting domain XML attribute 'dev' of entry 
'devices/disk/target' to start with 'fd'"));
 return -1;
 }
 
@@ -1505,8 +1502,7 @@ virVMXParseConfig(virVMXContext *ctx,
 if (def->description != NULL) {
 if (virVMXUnescapeHexPipe(def->description) < 0) {
 virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-   _("VMX entry 'annotation' contains invalid escape "
- "sequence"));
+   _("VMX entry 'annotation' contains invalid escape 
sequence"));
 goto cleanup;
 }
 }
@@ -1583,8 +1579,7 @@ virVMXParseConfig(virVMXContext *ctx,
 cpu->sockets = numvcpus / coresPerSocket;
 if (cpu->sockets <= 0) {
 virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-   _("VMX entry 'cpuid.coresPerSocket' smaller than "
- "'numvcpus'"));
+   _("VMX entry 'cpuid.coresPerSocket' smaller than 
'numvcpus'"));
 goto cleanup;
 }
 cpu->dies = 1;
@@ -3348,15 +3343,13 @@ virVMXFormatConfig(virVMXContext *ctx, 
virDomainXMLOption *xmlopt, virDomainDef
 /* def:maxvcpus -> vmx:numvcpus */
 if (virDomainDefHasVcpusOffline(def)) {
 virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-   _("No support for domain XML entry 'vcpu' attribute "
- "'current'"));
+   _("No support for domain XML entry 'vcpu' attribute 
'current'"));
 goto cleanup;
 }
 maxvcpus = virDomainDefGetVcpusMax(def);
 if (maxvcpus == 0) {
 virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-   _("Expecting domain XML entry 'vcpu' to be greater "
- "than 0"));
+   _("Expecting domain XML entry 'vcpu' to be greater than 
0"));
 goto cleanup;
 }
 
-- 
2.41.0



[PATCH 17/27] security: Move error messages onto a single line

2023-08-25 Thread Michal Privoznik
Error messages are exempt from the 80 columns rule. Move them
onto one line.

Signed-off-by: Michal Privoznik 
---
 src/security/security_dac.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/src/security/security_dac.c b/src/security/security_dac.c
index 20e0998fbc..4667328b26 100644
--- a/src/security/security_dac.c
+++ b/src/security/security_dac.c
@@ -2320,8 +2320,7 @@ virSecurityDACGenLabel(virSecurityManager *mgr,
 
 if (seclabel->imagelabel) {
 virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-   _("security image label already "
- "defined for VM"));
+   _("security image label already defined for VM"));
 return rc;
 }
 
-- 
2.41.0



[PATCH 19/27] storage_file: Move error messages onto a single line

2023-08-25 Thread Michal Privoznik
Error messages are exempt from the 80 columns rule. Move them
onto one line.

Signed-off-by: Michal Privoznik 
---
 src/storage_file/storage_source.c |  3 +-
 .../storage_source_backingstore.c | 36 +++
 2 files changed, 13 insertions(+), 26 deletions(-)

diff --git a/src/storage_file/storage_source.c 
b/src/storage_file/storage_source.c
index 3c50239e29..b97bbde619 100644
--- a/src/storage_file/storage_source.c
+++ b/src/storage_file/storage_source.c
@@ -762,8 +762,7 @@ virStorageSourceGetRelativeBackingPath(virStorageSource 
*top,
 
 if (next != base) {
 virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-   _("failed to resolve relative backing name: "
- "base image is not in backing chain"));
+   _("failed to resolve relative backing name: base image 
is not in backing chain"));
 return -1;
 }
 
diff --git a/src/storage_file/storage_source_backingstore.c 
b/src/storage_file/storage_source_backingstore.c
index a4ee2a5d78..00fcfe9fd7 100644
--- a/src/storage_file/storage_source_backingstore.c
+++ b/src/storage_file/storage_source_backingstore.c
@@ -441,8 +441,7 @@ virStorageSourceParseBackingJSONPath(virStorageSource *src,
 
 if (!(path = virJSONValueObjectGetString(json, "filename"))) {
 virReportError(VIR_ERR_INVALID_ARG, "%s",
-   _("missing 'filename' field in JSON backing volume "
- "definition"));
+   _("missing 'filename' field in JSON backing volume 
definition"));
 return -1;
 }
 
@@ -597,8 +596,7 @@ 
virStorageSourceParseBackingJSONInetSocketAddress(virStorageNetHostDef *host,
 
 if (!json) {
 virReportError(VIR_ERR_INVALID_ARG, "%s",
-   _("missing remote server specification in JSON "
- "backing volume definition"));
+   _("missing remote server specification in JSON backing 
volume definition"));
 return -1;
 }
 
@@ -607,8 +605,7 @@ 
virStorageSourceParseBackingJSONInetSocketAddress(virStorageNetHostDef *host,
 
 if (!hostname) {
 virReportError(VIR_ERR_INVALID_ARG, "%s",
-   _("missing hostname for tcp backing server in "
- "JSON backing volume definition"));
+   _("missing hostname for tcp backing server in JSON 
backing volume definition"));
 return -1;
 }
 
@@ -631,15 +628,13 @@ 
virStorageSourceParseBackingJSONSocketAddress(virStorageNetHostDef *host,
 
 if (!json) {
 virReportError(VIR_ERR_INVALID_ARG, "%s",
-   _("missing remote server specification in JSON "
- "backing volume definition"));
+   _("missing remote server specification in JSON backing 
volume definition"));
 return -1;
 }
 
 if (!(type = virJSONValueObjectGetString(json, "type"))) {
 virReportError(VIR_ERR_INVALID_ARG, "%s",
-   _("missing socket address type in "
- "JSON backing volume definition"));
+   _("missing socket address type in JSON backing volume 
definition"));
 return -1;
 }
 
@@ -657,8 +652,7 @@ 
virStorageSourceParseBackingJSONSocketAddress(virStorageNetHostDef *host,
 
 if (!socket) {
 virReportError(VIR_ERR_INVALID_ARG, "%s",
-   _("missing socket path for udp backing server in "
- "JSON backing volume definition"));
+   _("missing socket path for udp backing server in 
JSON backing volume definition"));
 return -1;
 }
 
@@ -694,8 +688,7 @@ virStorageSourceParseBackingJSONGluster(virStorageSource 
*src,
 
 if (!volume || !path || !server) {
 virReportError(VIR_ERR_INVALID_ARG, "%s",
-   _("missing 'volume', 'path' or 'server' attribute in "
- "JSON backing definition for gluster volume"));
+   _("missing 'volume', 'path' or 'server' attribute in 
JSON backing definition for gluster volume"));
 return -1;
 }
 
@@ -708,8 +701,7 @@ virStorageSourceParseBackingJSONGluster(virStorageSource 
*src,
 nservers = virJSONValueArraySize(server);
 if (nservers == 0) {
 virReportError(VIR_ERR_INVALID_ARG, "%s",
-   _("at least 1 server is necessary in "
- "JSON backing definition for gluster volume"));
+

[PATCH 10/27] network: Move error messages onto a single line

2023-08-25 Thread Michal Privoznik
Error messages are exempt from the 80 columns rule. Move them
onto one line.

Signed-off-by: Michal Privoznik 
---
 src/network/bridge_driver.c   | 14 --
 src/network/bridge_driver_linux.c | 10 +-
 2 files changed, 5 insertions(+), 19 deletions(-)

diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c
index 9eb543a0a3..e1cdc83025 100644
--- a/src/network/bridge_driver.c
+++ b/src/network/bridge_driver.c
@@ -1302,8 +1302,7 @@ networkDnsmasqConfContents(virNetworkObj *obj,
 if (ipdef->nranges || ipdef->nhosts) {
 if (ipv4def) {
 virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-   _("For IPv4, multiple DHCP definitions "
- "cannot be specified."));
+   _("For IPv4, multiple DHCP definitions 
cannot be specified."));
 return -1;
 } else {
 ipv4def = ipdef;
@@ -1316,8 +1315,7 @@ networkDnsmasqConfContents(virNetworkObj *obj,
 if (ipdef->nranges || ipdef->nhosts) {
 if (ipv6def) {
 virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-   _("For IPv6, multiple DHCP definitions "
- "cannot be specified."));
+   _("For IPv6, multiple DHCP definitions 
cannot be specified."));
 return -1;
 } else {
 ipv6def = ipdef;
@@ -2869,9 +2867,7 @@ networkValidate(virNetworkDriverState *driver,
 if (ipdef->nranges || ipdef->nhosts) {
 if (ipv4def) {
 virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-   _("Multiple IPv4 dhcp sections found -- "
- "dhcp is supported only for a "
- "single IPv4 address on each network"));
+   _("Multiple IPv4 dhcp sections found -- dhcp is 
supported only for a single IPv4 address on each network"));
 return -1;
 } else {
 ipv4def = true;
@@ -2882,9 +2878,7 @@ networkValidate(virNetworkDriverState *driver,
 if (ipdef->nranges || ipdef->nhosts) {
 if (ipv6def) {
 virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-   _("Multiple IPv6 dhcp sections found -- "
- "dhcp is supported only for a "
- "single IPv6 address on each network"));
+   _("Multiple IPv6 dhcp sections found -- dhcp is 
supported only for a single IPv6 address on each network"));
 return -1;
 } else {
 ipv6def = true;
diff --git a/src/network/bridge_driver_linux.c 
b/src/network/bridge_driver_linux.c
index 1ef5b9d917..b8893bfed2 100644
--- a/src/network/bridge_driver_linux.c
+++ b/src/network/bridge_driver_linux.c
@@ -884,15 +884,7 @@ int networkAddFirewallRules(virNetworkDef *def)
 if (version >= 6000 &&
 virFirewallDGetBackend() == 
VIR_FIREWALLD_BACKEND_NFTABLES) {
 virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-   _("firewalld is set to use the nftables "
- "backend, but the required firewalld "
- "'libvirt' zone is missing. Either set "
- "the firewalld backend to 'iptables', or "
- "ensure that firewalld has a 'libvirt' "
- "zone by upgrading firewalld to a "
- "version supporting rule priorities "
- "(0.7.0+) and/or rebuilding "
- "libvirt with --with-firewalld-zone"));
+   _("firewalld is set to use the nftables 
backend, but the required firewalld 'libvirt' zone is missing. Either set the 
firewalld backend to 'iptables', or ensure that firewalld has a 'libvirt' zone 
by upgrading firewalld to a version supporting rule priorities (0.7.0+) and/or 
rebuilding libvirt with --with-firewalld-zone"));
 return -1;
 }
 }
-- 
2.41.0



[PATCH 09/27] lxc: Move error messages onto a single line

2023-08-25 Thread Michal Privoznik
Error messages are exempt from the 80 columns rule. Move them
onto one line.

Signed-off-by: Michal Privoznik 
---
 src/lxc/lxc_container.c | 3 +--
 src/lxc/lxc_driver.c| 3 +--
 src/lxc/lxc_native.c| 3 +--
 src/lxc/lxc_process.c   | 3 +--
 4 files changed, 4 insertions(+), 8 deletions(-)

diff --git a/src/lxc/lxc_container.c b/src/lxc/lxc_container.c
index 19d4f92728..21220661f7 100644
--- a/src/lxc/lxc_container.c
+++ b/src/lxc/lxc_container.c
@@ -2182,8 +2182,7 @@ int lxcContainerStart(virDomainDef *def,
 } else {
 if (lxcNeedNetworkNamespace(def)) {
 virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-   _("Config asks for inherit net namespace "
- "as well as private network interfaces"));
+   _("Config asks for inherit net namespace as well as 
private network interfaces"));
 goto cleanup;
 }
 VIR_DEBUG("Inheriting a net namespace");
diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c
index f284798f1c..f3d3e4eb50 100644
--- a/src/lxc/lxc_driver.c
+++ b/src/lxc/lxc_driver.c
@@ -654,8 +654,7 @@ static int lxcDomainSetMemoryFlags(virDomainPtr dom, 
unsigned long newmem,
 if (flags & VIR_DOMAIN_MEM_MAXIMUM) {
 if (def) {
 virReportError(VIR_ERR_OPERATION_INVALID, "%s",
-   _("Cannot resize the max memory "
- "on an active domain"));
+   _("Cannot resize the max memory on an active 
domain"));
 goto endjob;
 }
 
diff --git a/src/lxc/lxc_native.c b/src/lxc/lxc_native.c
index 0ae208ef11..5a63efc35f 100644
--- a/src/lxc/lxc_native.c
+++ b/src/lxc/lxc_native.c
@@ -1126,8 +1126,7 @@ lxcParseConfigString(const char *config,
 if (virConfGetValue(properties, "lxc.mount.fstab") ||
 virConfGetValue(properties, "lxc.mount")) {
 virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, "%s",
-   _("lxc.mount.fstab or lxc.mount found, use "
- "lxc.mount.entry lines instead"));
+   _("lxc.mount.fstab or lxc.mount found, use 
lxc.mount.entry lines instead"));
 return NULL;
 }
 
diff --git a/src/lxc/lxc_process.c b/src/lxc/lxc_process.c
index 04642b56dd..20cd3a3d57 100644
--- a/src/lxc/lxc_process.c
+++ b/src/lxc/lxc_process.c
@@ -452,8 +452,7 @@ static int virLXCProcessSetupNamespaceNet(int ns_type, 
const char *name)
 int fd;
 if (ns_type != VIR_LXC_DOMAIN_NAMESPACE_SHARENET) {
 virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-   _("'netns' namespace source can only be "
- "used with sharenet"));
+   _("'netns' namespace source can only be used with 
sharenet"));
 return -1;
 }
 
-- 
2.41.0



[PATCH 07/27] libxl: Move error messages onto a single line

2023-08-25 Thread Michal Privoznik
Error messages are exempt from the 80 columns rule. Move them
onto one line.

Signed-off-by: Michal Privoznik 
---
 src/libxl/libxl_conf.c  | 12 
 src/libxl/libxl_driver.c|  6 ++
 src/libxl/libxl_migration.c | 11 ---
 3 files changed, 10 insertions(+), 19 deletions(-)

diff --git a/src/libxl/libxl_conf.c b/src/libxl/libxl_conf.c
index 14ad320023..3ffb46fddd 100644
--- a/src/libxl/libxl_conf.c
+++ b/src/libxl/libxl_conf.c
@@ -1284,8 +1284,7 @@ libxlMakeNic(virDomainDef *def,
 if (l_nic->script && !(actual_type == VIR_DOMAIN_NET_TYPE_BRIDGE ||
actual_type == VIR_DOMAIN_NET_TYPE_ETHERNET)) {
 virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-   _("specifying a script is only supported with "
- "interface types bridge and ethernet"));
+   _("specifying a script is only supported with interface 
types bridge and ethernet"));
 return -1;
 }
 
@@ -1310,8 +1309,7 @@ libxlMakeNic(virDomainDef *def,
 def->os.type == VIR_DOMAIN_OSTYPE_XENPVH) &&
 l_nic->model != VIR_DOMAIN_NET_MODEL_NETFRONT) {
 virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-   _("only model 'netfront' is supported for "
- "Xen PV(H) domains"));
+   _("only model 'netfront' is supported for Xen PV(H) 
domains"));
 return -1;
 }
 x_nic->model = g_strdup(virDomainNetGetModelString(l_nic));
@@ -1802,14 +1800,12 @@ libxlDriverConfigInit(libxlDriverConfig *cfg)
 }
 
 if (libxl_ctx_alloc(>ctx, LIBXL_VERSION, 0, (xentoollog_logger 
*)cfg->logger)) {
-VIR_ERROR(_("cannot initialize libxenlight context, probably not "
-"running in a Xen Dom0, disabling driver"));
+VIR_ERROR(_("cannot initialize libxenlight context, probably not 
running in a Xen Dom0, disabling driver"));
 return -1;
 }
 
 if ((cfg->verInfo = libxl_get_version_info(cfg->ctx)) == NULL) {
-VIR_ERROR(_("cannot version information from libxenlight, "
-"disabling driver"));
+VIR_ERROR(_("cannot version information from libxenlight, disabling 
driver"));
 return -1;
 }
 cfg->version = (cfg->verInfo->xen_version_major * 100) +
diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c
index 079922dd32..c8ca903050 100644
--- a/src/libxl/libxl_driver.c
+++ b/src/libxl/libxl_driver.c
@@ -2904,8 +2904,7 @@ libxlDomainUndefineFlags(virDomainPtr dom,
 }
 } else {
 virReportError(VIR_ERR_OPERATION_INVALID, "%s",
-   _("Refusing to undefine while domain managed "
- "save image exists"));
+   _("Refusing to undefine while domain managed save 
image exists"));
 goto cleanup;
 }
 }
@@ -3212,8 +3211,7 @@ libxlDomainAttachHostUSBDevice(libxlDriverPrivate *driver,
 
 if (libxlDomainAttachControllerDevice(driver, vm, controller) < 0) {
 virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-   _("No available USB controller and port, and "
- "failed to attach a new one"));
+   _("No available USB controller and port, and failed 
to attach a new one"));
 virDomainControllerDefFree(controller);
 goto cleanup;
 }
diff --git a/src/libxl/libxl_migration.c b/src/libxl/libxl_migration.c
index a91091f5e8..f5dee7627b 100644
--- a/src/libxl/libxl_migration.c
+++ b/src/libxl/libxl_migration.c
@@ -679,8 +679,7 @@ libxlDomainMigrationDstPrepare(virConnectPtr dconn,
 
 if (STRPREFIX(hostname, "localhost")) {
 virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-   _("hostname on destination resolved to localhost,"
- " but migration requires an FQDN"));
+   _("hostname on destination resolved to localhost, 
but migration requires an FQDN"));
 goto endjob;
 }
 
@@ -1142,8 +1141,7 @@ libxlDomainMigrationSrcPerformP2P(libxlDriverPrivate 
*driver,
 if (useParams <= 0) {
 if (useParams == 0)
 virReportError(VIR_ERR_OPERATION_FAILED, "%s",
-   _("Destination libvirt does not support migration"
- " with extensible parameters"));
+   _("Destination libvirt does not support migration 
with extensible parameters

[PATCH 06/27] hypervisor: Move error messages onto a single line

2023-08-25 Thread Michal Privoznik
Error messages are exempt from the 80 columns rule. Move them
onto one line.

Signed-off-by: Michal Privoznik 
---
 src/hypervisor/domain_cgroup.c | 3 +--
 src/hypervisor/virhostdev.c| 9 +++--
 2 files changed, 4 insertions(+), 8 deletions(-)

diff --git a/src/hypervisor/domain_cgroup.c b/src/hypervisor/domain_cgroup.c
index 20ad96b11c..2b9a1cc9b1 100644
--- a/src/hypervisor/domain_cgroup.c
+++ b/src/hypervisor/domain_cgroup.c
@@ -233,8 +233,7 @@ virDomainCgroupSetMemoryLimitParameters(virCgroup *cgroup,
 
 if (mem_limit > swap_limit) {
 virReportError(VIR_ERR_INVALID_ARG, "%s",
-   _("memory hard_limit tunable value must be lower "
- "than or equal to swap_hard_limit"));
+   _("memory hard_limit tunable value must be lower 
than or equal to swap_hard_limit"));
 return -1;
 }
 }
diff --git a/src/hypervisor/virhostdev.c b/src/hypervisor/virhostdev.c
index b95d6bf3d6..4672bd8785 100644
--- a/src/hypervisor/virhostdev.c
+++ b/src/hypervisor/virhostdev.c
@@ -423,8 +423,7 @@ virHostdevSaveNetConfig(virDomainHostdevDef *hostdev,
 
 if (virHostdevIsVirtualFunction(hostdev) != 1) {
 virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-   _("Interface type hostdev is currently supported on"
- " SR-IOV Virtual Functions only"));
+   _("Interface type hostdev is currently supported on 
SR-IOV Virtual Functions only"));
 return -1;
 }
 
@@ -511,8 +510,7 @@ virHostdevRestoreNetConfig(virDomainHostdevDef *hostdev,
 
 if (virHostdevIsVirtualFunction(hostdev) != 1) {
 virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-   _("Interface type hostdev is currently supported on"
- " SR-IOV Virtual Functions only"));
+   _("Interface type hostdev is currently supported on 
SR-IOV Virtual Functions only"));
 return -1;
 }
 
@@ -688,8 +686,7 @@ virHostdevPreparePCIDevicesImpl(virHostdevManager *mgr,
 
 if (hdrType != VIR_PCI_HEADER_ENDPOINT) {
 virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-   _("Non-endpoint PCI devices cannot be assigned "
- "to guests"));
+   _("Non-endpoint PCI devices cannot be assigned to 
guests"));
 goto cleanup;
 }
 
-- 
2.41.0



[PATCH 02/27] ch: Move error messages onto a single line

2023-08-25 Thread Michal Privoznik
Error messages are exempt from the 80 columns rule. Move them
onto one line.

Signed-off-by: Michal Privoznik 
---
 src/ch/ch_driver.c  | 3 +--
 src/ch/ch_monitor.c | 3 +--
 2 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/src/ch/ch_driver.c b/src/ch/ch_driver.c
index 45cdbfd37c..b62645a8c8 100644
--- a/src/ch/ch_driver.c
+++ b/src/ch/ch_driver.c
@@ -1379,8 +1379,7 @@ chDomainPinEmulator(virDomainPtr dom,
 
 if (virDomainCgroupSetupCpusetCpus(cgroup_emulator, pcpumap) < 0) {
 virReportError(VIR_ERR_OPERATION_INVALID, "%s",
-   _("failed to set cpuset.cpus in cgroup"
- " for emulator threads"));
+   _("failed to set cpuset.cpus in cgroup for 
emulator threads"));
 goto endjob;
 }
 }
diff --git a/src/ch/ch_monitor.c b/src/ch/ch_monitor.c
index a4b921931b..4f32b1ee4c 100644
--- a/src/ch/ch_monitor.c
+++ b/src/ch/ch_monitor.c
@@ -637,8 +637,7 @@ virCHMonitorCurlPerform(CURL *handle)
 
 if (responseCode < 0) {
 virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-   _("curl_easy_getinfo(CURLINFO_RESPONSE_CODE) returned a 
"
- "negative response code"));
+   _("curl_easy_getinfo(CURLINFO_RESPONSE_CODE) returned a 
negative response code"));
 return -1;
 }
 
-- 
2.41.0



[PATCH 01/27] bhyve: Move error messages onto a single line

2023-08-25 Thread Michal Privoznik
Error messages are exempt from the 80 columns rule. Move them
onto one line.

Signed-off-by: Michal Privoznik 
---
 src/bhyve/bhyve_command.c | 31 ++-
 src/bhyve/bhyve_domain.c  |  3 +--
 src/bhyve/bhyve_driver.c  |  3 +--
 3 files changed, 12 insertions(+), 25 deletions(-)

diff --git a/src/bhyve/bhyve_command.c b/src/bhyve/bhyve_command.c
index 563651336e..82e7e96816 100644
--- a/src/bhyve/bhyve_command.c
+++ b/src/bhyve/bhyve_command.c
@@ -60,8 +60,7 @@ bhyveBuildNetArgStr(const virDomainDef *def,
 nic_model = g_strdup("e1000");
 } else {
 virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-   _("NIC model 'e1000' is not supported "
- "by given bhyve binary"));
+   _("NIC model 'e1000' is not supported by given 
bhyve binary"));
 return -1;
 }
 } else {
@@ -190,8 +189,7 @@ bhyveBuildAHCIControllerArgStr(const virDomainDef *def,
 if ((disk->device == VIR_DOMAIN_DISK_DEVICE_CDROM) &&
 (disk_source == NULL)) {
 virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-   _("cdrom device without source path "
- "not supported"));
+   _("cdrom device without source path not 
supported"));
 return -1;
 }
 
@@ -341,8 +339,7 @@ bhyveBuildControllerArgStr(const virDomainDef *def,
 case VIR_DOMAIN_CONTROLLER_TYPE_PCI:
 if (controller->model != VIR_DOMAIN_CONTROLLER_MODEL_PCI_ROOT) {
 virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-   _("unsupported PCI controller model: "
- "only PCI root supported"));
+   _("unsupported PCI controller model: only PCI root 
supported"));
 return -1;
 }
 break;
@@ -391,8 +388,7 @@ bhyveBuildGraphicsArgStr(const virDomainDef *def,
 def->os.bootloader ||
 !def->os.loader) {
 virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-   _("Graphics are only supported"
- " when booting using UEFI"));
+   _("Graphics are only supported when booting using 
UEFI"));
 return -1;
 }
 
@@ -465,8 +461,7 @@ bhyveBuildGraphicsArgStr(const virDomainDef *def,
 if (graphics->data.vnc.auth.passwd) {
 if (!(bhyveDriverGetBhyveCaps(driver) & BHYVE_CAP_VNC_PASSWORD)) {
 virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-   _("VNC Password authentication not supported "
- "by bhyve"));
+   _("VNC Password authentication not supported by 
bhyve"));
 return -1;
 }
 
@@ -510,8 +505,7 @@ bhyveBuildSoundArgStr(const virDomainDef *def G_GNUC_UNUSED,
 /* Currently, bhyve only supports "hda" sound devices, so
if it's not supported, sound devices are not supported at all */
 virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-   _("Sound devices emulation is not supported "
- "by given bhyve binary"));
+   _("Sound devices emulation is not supported by given 
bhyve binary"));
 return -1;
 }
 
@@ -667,9 +661,7 @@ virBhyveProcessBuildBhyveCmd(struct _bhyveConn *driver, 
virDomainDef *def,
 }
 if (nvcpus != def->cpu->sockets * def->cpu->cores * def->cpu->threads) 
{
 virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-   _("Invalid CPU topology: total number of vCPUs "
- "must equal the product of sockets, cores, "
- "and threads"));
+   _("Invalid CPU topology: total number of vCPUs must 
equal the product of sockets, cores, and threads"));
 return NULL;
 }
 
@@ -681,8 +673,7 @@ virBhyveProcessBuildBhyveCmd(struct _bhyveConn *driver, 
virDomainDef *def,
def->cpu->threads);
 } else {
 virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-   _("Installed bhyve binary does not support "
- "defining CPU topology"));
+   _("Installed bhyve binary does not support defining 
CPU topology"));
 return NULL;
 }
 } else {
@@ -716,8 +707,7 @@ virBhyveProcessBuildBhyveCmd(struct _bhyveConn *driver, 
virDomainD

[PATCH 04/27] cpu: Move error messages onto a single line

2023-08-25 Thread Michal Privoznik
Error messages are exempt from the 80 columns rule. Move them
onto one line.

Signed-off-by: Michal Privoznik 
---
 src/cpu/cpu_x86.c | 6 ++
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/src/cpu/cpu_x86.c b/src/cpu/cpu_x86.c
index b9513e24d5..7a7f3b409d 100644
--- a/src/cpu/cpu_x86.c
+++ b/src/cpu/cpu_x86.c
@@ -1899,8 +1899,7 @@ x86Compute(virCPUDef *host,
 result = x86ModelCompare(host_model, cpu_require);
 if (result == SUBSET || result == UNRELATED) {
 x86DataSubtract(_require->data, _model->data);
-virX86CpuIncompatible(N_("Host CPU does not provide required "
- "features"),
+virX86CpuIncompatible(N_("Host CPU does not provide required 
features"),
   _require->data);
 return VIR_CPU_COMPARE_INCOMPATIBLE;
 }
@@ -1919,8 +1918,7 @@ x86Compute(virCPUDef *host,
 if (ret == VIR_CPU_COMPARE_SUPERSET
 && cpu->type == VIR_CPU_TYPE_GUEST
 && cpu->match == VIR_CPU_MATCH_STRICT) {
-virX86CpuIncompatible(N_("Host CPU does not strictly match guest CPU: "
- "Extra features"),
+virX86CpuIncompatible(N_("Host CPU does not strictly match guest CPU: 
Extra features"),
   >data);
 return VIR_CPU_COMPARE_INCOMPATIBLE;
 }
-- 
2.41.0



[PATCH 03/27] conf: Move error messages onto a single line

2023-08-25 Thread Michal Privoznik
Error messages are exempt from the 80 columns rule. Move them
onto one line.

Signed-off-by: Michal Privoznik 
---
 src/conf/cpu_conf.c  |   9 +-
 src/conf/domain_addr.c   |   3 +-
 src/conf/domain_conf.c   | 138 +++
 src/conf/domain_validate.c   |  54 
 src/conf/netdev_bandwidth_conf.c |   3 +-
 src/conf/netdev_vlan_conf.c  |   6 +-
 src/conf/network_conf.c  |  27 ++
 src/conf/node_device_conf.c  |   3 +-
 src/conf/node_device_util.c  |   3 +-
 src/conf/numa_conf.c |  25 ++
 src/conf/nwfilter_params.c   |   6 +-
 src/conf/snapshot_conf.c |   3 +-
 src/conf/storage_adapter_conf.c  |  18 ++--
 src/conf/virdomainjob.c  |   3 +-
 src/conf/virnetworkobj.c |   3 +-
 15 files changed, 101 insertions(+), 203 deletions(-)

diff --git a/src/conf/cpu_conf.c b/src/conf/cpu_conf.c
index 98adb0e5d5..7abe489733 100644
--- a/src/conf/cpu_conf.c
+++ b/src/conf/cpu_conf.c
@@ -394,8 +394,7 @@ virCPUDefParseXML(xmlXPathContextPtr ctxt,
 if (virXPathBoolean("boolean(./arch)", ctxt)) {
 if (virXPathBoolean("boolean(./@match)", ctxt)) {
 virReportError(VIR_ERR_XML_ERROR, "%s",
-   _("'arch' element cannot be used inside 'cpu'"
- " element with 'match' attribute'"));
+   _("'arch' element cannot be used inside 'cpu' 
element with 'match' attribute'"));
 return -1;
 }
 def->type = VIR_CPU_TYPE_HOST;
@@ -436,8 +435,7 @@ virCPUDefParseXML(xmlXPathContextPtr ctxt,
def->mode != VIR_CPU_MODE_HOST_PASSTHROUGH &&
def->mode != VIR_CPU_MODE_MAXIMUM) {
 virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-   _("Attribute migratable is only allowed for "
- "'host-passthrough' / 'maximum' CPU mode"));
+   _("Attribute migratable is only allowed for 
'host-passthrough' / 'maximum' CPU mode"));
 return -1;
 }
 
@@ -593,8 +591,7 @@ virCPUDefParseXML(xmlXPathContextPtr ctxt,
 if (n > 0) {
 if (!def->model && def->mode == VIR_CPU_MODE_CUSTOM) {
 virReportError(VIR_ERR_XML_ERROR, "%s",
-   _("Non-empty feature list specified without "
- "CPU model"));
+   _("Non-empty feature list specified without CPU 
model"));
 return -1;
 }
 
diff --git a/src/conf/domain_addr.c b/src/conf/domain_addr.c
index 23c06ff6a4..a53ff6df6c 100644
--- a/src/conf/domain_addr.c
+++ b/src/conf/domain_addr.c
@@ -905,8 +905,7 @@ virDomainPCIAddressEnsureAddr(virDomainPCIAddressSet *addrs,
  */
 if (dev->addr.pci.function != 0) {
 virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-   _("Only PCI device addresses with function=0"
- " are supported"));
+   _("Only PCI device addresses with function=0 are 
supported"));
 return -1;
 }
 
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 69934026ef..2d585e7470 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -2152,8 +2152,7 @@ virDomainDefSetVcpus(virDomainDef *def,
 
 if (vcpus > def->maxvcpus) {
 virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-   _("maximum vCPU count must not be less than current "
- "vCPU count"));
+   _("maximum vCPU count must not be less than current 
vCPU count"));
 return -1;
 }
 
@@ -4348,8 +4347,7 @@ virDomainObjUpdateModificationImpact(virDomainObj *vm,
 
 if (!vm->persistent && (*flags & VIR_DOMAIN_AFFECT_CONFIG)) {
 virReportError(VIR_ERR_OPERATION_INVALID, "%s",
-   _("transient domains do not have any "
- "persistent config"));
+   _("transient domains do not have any persistent 
config"));
 return -1;
 }
 
@@ -4429,9 +4427,7 @@ virDomainObjGetOneDefState(virDomainObj *vm,
 if (flags & VIR_DOMAIN_AFFECT_LIVE &&
 flags & VIR_DOMAIN_AFFECT_CONFIG) {
 virReportInvalidArg(flags, "%s",
-_("Flags 'VIR_DOMAIN_AFFECT_LIVE' and "
-  "'VIR_DOMAIN_AFFECT_CONFIG' are mutually "
-  "exclusive"));
+_("Flags 'VIR_DOMAIN_AFFECT_LIVE' and 
'VIR_DOMAIN_

[PATCH 00/27] Move error messages onto a single line

2023-08-25 Thread Michal Privoznik
This is inspired by the following discussion:

https://listman.redhat.com/archives/libvir-list/2023-August/241361.html

And ideally I'd present a green pipeline but for some reason, I can't:

https://gitlab.com/MichalPrivoznik/libvirt/-/pipelines/981105262

But the problem is not with my code rather than our CI.

Michal Prívozník (27):
  bhyve: Move error messages onto a single line
  ch: Move error messages onto a single line
  conf: Move error messages onto a single line
  cpu: Move error messages onto a single line
  esx: Move error messages onto a single line
  hypervisor: Move error messages onto a single line
  libxl: Move error messages onto a single line
  locking: Move error messages onto a single line
  lxc: Move error messages onto a single line
  network: Move error messages onto a single line
  node_device: Move error messages onto a single line
  nwfilter: Move error messages onto a single line
  openvz: Move error messages onto a single line
  qemu: Move error messages onto a single line
  remote: Move error messages onto a single line
  rpc: Move error messages onto a single line
  security: Move error messages onto a single line
  storage: Move error messages onto a single line
  storage_file: Move error messages onto a single line
  test: Move error messages onto a single line
  util: Move error messages onto a single line
  vbox: Move error messages onto a single line
  vmware: Move error messages onto a single line
  vmx: Move error messages onto a single line
  vz: Move error messages onto a single line
  src: Move error messages onto a single line
  tools: Move error messages onto a single line

 src/bhyve/bhyve_command.c |  31 +--
 src/bhyve/bhyve_domain.c  |   3 +-
 src/bhyve/bhyve_driver.c  |   3 +-
 src/ch/ch_driver.c|   3 +-
 src/ch/ch_monitor.c   |   3 +-
 src/conf/cpu_conf.c   |   9 +-
 src/conf/domain_addr.c|   3 +-
 src/conf/domain_conf.c| 138 
 src/conf/domain_validate.c|  54 ++---
 src/conf/netdev_bandwidth_conf.c  |   3 +-
 src/conf/netdev_vlan_conf.c   |   6 +-
 src/conf/network_conf.c   |  27 +--
 src/conf/node_device_conf.c   |   3 +-
 src/conf/node_device_util.c   |   3 +-
 src/conf/numa_conf.c  |  25 +--
 src/conf/nwfilter_params.c|   6 +-
 src/conf/snapshot_conf.c  |   3 +-
 src/conf/storage_adapter_conf.c   |  18 +-
 src/conf/virdomainjob.c   |   3 +-
 src/conf/virnetworkobj.c  |   3 +-
 src/cpu/cpu_x86.c |   6 +-
 src/esx/esx_driver.c  |  21 +-
 src/esx/esx_network_driver.c  |   3 +-
 src/esx/esx_storage_backend_vmfs.c|   3 +-
 src/esx/esx_util.c|   3 +-
 src/esx/esx_vi.c  |  19 +-
 src/esx/esx_vi_types.c|   3 +-
 src/hypervisor/domain_cgroup.c|   3 +-
 src/hypervisor/virhostdev.c   |   9 +-
 src/libvirt-domain.c  |  54 ++---
 src/libxl/libxl_conf.c|  12 +-
 src/libxl/libxl_driver.c  |   6 +-
 src/libxl/libxl_migration.c   |  11 +-
 src/locking/lock_driver_sanlock.c |   3 +-
 src/lxc/lxc_container.c   |   3 +-
 src/lxc/lxc_driver.c  |   3 +-
 src/lxc/lxc_native.c  |   3 +-
 src/lxc/lxc_process.c |   3 +-
 src/network/bridge_driver.c   |  14 +-
 src/network/bridge_driver_linux.c |  10 +-
 src/node_device/node_device_udev.c|   3 +-
 src/nwfilter/nwfilter_dhcpsnoop.c |  12 +-
 src/nwfilter/nwfilter_learnipaddr.c   |   8 +-
 src/openvz/openvz_driver.c|   3 +-
 src/qemu/qemu_agent.c |  18 +-
 src/qemu/qemu_capabilities.c  |  45 ++--
 src/qemu/qemu_command.c   |  42 ++--
 src/qemu/qemu_conf.c  |   5 +-
 src/qemu/qemu_domain.c|  51 ++---
 src/qemu/qemu_domain_address.c|  15 +-
 src/qemu/qemu_driver.c| 120 --
 src/qemu/qemu_hostdev.c   |   3 +-
 src/qemu/qemu_hotplug.c   |  18 +-
 src/qemu/qemu_migration.c |  48 ++--
 src/qemu/qemu_migration_params.c  |   6 +-
 src/qemu/qemu_monitor.c   |   3 +-
 src/qemu/qemu_monitor_json.c  | 102 +++--
 src/qemu/qemu_process.c   |  20 +-
 src/qemu/qemu_snapshot.c  |  27 +--
 

[PATCH 5/6] virMdevctlList: Don't check for !output

2023-08-24 Thread Michal Privoznik
After 'mdevctl' was ran, its stdout is captured in @output which
is then compared against NULL and if it is NULL a negative value
is returned (to indicate error to the caller). But this is
effectively a dead code, because virCommand (specifically
virCommandProcessIO()) makes sure both stdout and stderr buffers
are properly '\0' terminated. Therefore, this can never evaluate
to true. Also, if there really is no output from 'mdevctl' (which
was handled in one of earlier commits, but let just assume it
wasn't), then we should not error out and treat such scenario as
'no mdevs defined/active'.

Signed-off-by: Michal Privoznik 
---
 src/node_device/node_device_driver.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/src/node_device/node_device_driver.c 
b/src/node_device/node_device_driver.c
index ac50c96837..a59cd0875d 100644
--- a/src/node_device/node_device_driver.c
+++ b/src/node_device/node_device_driver.c
@@ -1650,9 +1650,6 @@ virMdevctlList(bool defined,
 return -1;
 }
 
-if (!output)
-return -1;
-
 return nodeDeviceParseMdevctlJSON(output, devs);
 }
 
-- 
2.41.0



[PATCH 6/6] virjsontest: Introduce a test case for an empty array

2023-08-24 Thread Michal Privoznik
Previous commits were all about empty strings and empty JSON
arrays. Introduce a test case for "[]" to make sure we pare it
correctly.

Signed-off-by: Michal Privoznik 
---
 tests/virjsontest.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/tests/virjsontest.c b/tests/virjsontest.c
index 294889a795..6b6a64d3d3 100644
--- a/tests/virjsontest.c
+++ b/tests/virjsontest.c
@@ -553,6 +553,7 @@ mymain(void)
 DO_TEST_PARSE("integer", "1", NULL);
 DO_TEST_PARSE("boolean", "true", NULL);
 DO_TEST_PARSE("null", "null", NULL);
+DO_TEST_PARSE("[]", "[]", NULL);
 
 DO_TEST_PARSE("escaping symbols", "[\"\\\"\\t\\n\"]", NULL);
 DO_TEST_PARSE("escaped strings", "[\"{\\\"blurb\\\":\\\"test\\\"}\"]", 
NULL);
-- 
2.41.0



[PATCH 4/6] node_device_driver: Deduplicate mediated devices listing

2023-08-24 Thread Michal Privoznik
We have virMdevctlListDefined() to list defined mdevs, and
virMdevctlListActive() to list active mdevs. Both have the same
body except for one boolean argument passed to
nodeDeviceGetMdevctlListCommand(). Join the two functions under
virMdevctlList() name and introduce @defined argument that is
then just passed to the cmd line builder function.

Signed-off-by: Michal Privoznik 
---
 src/node_device/node_device_driver.c | 30 ++--
 1 file changed, 6 insertions(+), 24 deletions(-)

diff --git a/src/node_device/node_device_driver.c 
b/src/node_device/node_device_driver.c
index 593bc64e25..ac50c96837 100644
--- a/src/node_device/node_device_driver.c
+++ b/src/node_device/node_device_driver.c
@@ -1636,32 +1636,14 @@ nodeDeviceGenerateName(virNodeDeviceDef *def,
 
 
 static int
-virMdevctlListDefined(virNodeDeviceDef ***devs, char **errmsg)
+virMdevctlList(bool defined,
+   virNodeDeviceDef ***devs,
+   char **errmsg)
 {
 int status;
 g_autofree char *output = NULL;
 g_autofree char *errbuf = NULL;
-g_autoptr(virCommand) cmd = nodeDeviceGetMdevctlListCommand(true, , 
);
-
-if (virCommandRun(cmd, ) < 0 || status != 0) {
-*errmsg = g_steal_pointer();
-return -1;
-}
-
-if (!output)
-return -1;
-
-return nodeDeviceParseMdevctlJSON(output, devs);
-}
-
-
-static int
-virMdevctlListActive(virNodeDeviceDef ***devs, char **errmsg)
-{
-int status;
-g_autofree char *output = NULL;
-g_autofree char *errbuf = NULL;
-g_autoptr(virCommand) cmd = nodeDeviceGetMdevctlListCommand(false, 
, );
+g_autoptr(virCommand) cmd = nodeDeviceGetMdevctlListCommand(defined, 
, );
 
 if (virCommandRun(cmd, ) < 0 || status != 0) {
 *errmsg = g_steal_pointer();
@@ -1750,7 +1732,7 @@ nodeDeviceUpdateMediatedDevices(void)
 return 0;
 }
 
-if ((data.ndefs = virMdevctlListDefined(, )) < 0) {
+if ((data.ndefs = virMdevctlList(true, , )) < 0) {
 virReportError(VIR_ERR_INTERNAL_ERROR,
_("failed to query mdevs from mdevctl: %1$s"), errmsg);
 return -1;
@@ -1767,7 +1749,7 @@ nodeDeviceUpdateMediatedDevices(void)
 return -1;
 
 /* Update active/transient mdev devices */
-if ((act_ndefs = virMdevctlListActive(_defs, )) < 0) {
+if ((act_ndefs = virMdevctlList(false, _defs, )) < 0) {
 virReportError(VIR_ERR_INTERNAL_ERROR,
_("failed to query mdevs from mdevctl: %1$s"), errmsg);
 return -1;
-- 
2.41.0



[PATCH 2/6] nodeDeviceParseMdevctlJSON: Accept empty string

2023-08-24 Thread Michal Privoznik
It is possible for 'mdevctl' to output nothing, an empty string
(e.g. when no mediated devices are defined on the host). What is
weird is that when passing '--defined' then 'mdevctl' outputs an
empty JSON array instead. Nevertheless, we should accept both and
threat them the same, i.e. as no mediated devices.

Resolves: https://gitlab.com/libvirt/libvirt/-/issues/523
Signed-off-by: Michal Privoznik 
---
 src/node_device/node_device_driver.c | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/src/node_device/node_device_driver.c 
b/src/node_device/node_device_driver.c
index 2ef9197adc..593bc64e25 100644
--- a/src/node_device/node_device_driver.c
+++ b/src/node_device/node_device_driver.c
@@ -43,6 +43,7 @@
 #include "virutil.h"
 #include "vircommand.h"
 #include "virlog.h"
+#include "virstring.h"
 
 #define VIR_FROM_THIS VIR_FROM_NODEDEV
 
@@ -1176,6 +1177,12 @@ nodeDeviceParseMdevctlJSON(const char *jsonstring,
 size_t j;
 virJSONValue *obj;
 
+if (virStringIsEmpty(jsonstring)) {
+VIR_DEBUG("mdevctl has no defined mediated devices");
+*devs = NULL;
+return 0;
+}
+
 json_devicelist = virJSONValueFromString(jsonstring);
 
 if (!json_devicelist || !virJSONValueIsArray(json_devicelist)) {
-- 
2.41.0



[PATCH 1/6] nodedevmdevctltest: Rename mdevctl-list-empty test case

2023-08-24 Thread Michal Privoznik
The mdevctl-list-empty test case is there to test whether an
empty JSON array "[]" is handled correctly by mdevctl handling
code. Well, mdevctl can output both, an empty JSON array or no
output at all.

Therefore, rename "mdevctl-list-empty" test case to
"mdevctl-list-empty-array" which is more descriptive and also
frees up slot for actual empty output (handled in next commits).

Signed-off-by: Michal Privoznik 
---
 .../{mdevctl-list-empty.json => mdevctl-list-empty-array.json}  | 0
 ...vctl-list-empty.out.xml => mdevctl-list-empty-array.out.xml} | 0
 tests/nodedevmdevctltest.c  | 2 +-
 3 files changed, 1 insertion(+), 1 deletion(-)
 rename tests/nodedevmdevctldata/{mdevctl-list-empty.json => 
mdevctl-list-empty-array.json} (100%)
 rename tests/nodedevmdevctldata/{mdevctl-list-empty.out.xml => 
mdevctl-list-empty-array.out.xml} (100%)

diff --git a/tests/nodedevmdevctldata/mdevctl-list-empty.json 
b/tests/nodedevmdevctldata/mdevctl-list-empty-array.json
similarity index 100%
rename from tests/nodedevmdevctldata/mdevctl-list-empty.json
rename to tests/nodedevmdevctldata/mdevctl-list-empty-array.json
diff --git a/tests/nodedevmdevctldata/mdevctl-list-empty.out.xml 
b/tests/nodedevmdevctldata/mdevctl-list-empty-array.out.xml
similarity index 100%
rename from tests/nodedevmdevctldata/mdevctl-list-empty.out.xml
rename to tests/nodedevmdevctldata/mdevctl-list-empty-array.out.xml
diff --git a/tests/nodedevmdevctltest.c b/tests/nodedevmdevctltest.c
index 4dc524b5a5..c04b05c417 100644
--- a/tests/nodedevmdevctltest.c
+++ b/tests/nodedevmdevctltest.c
@@ -470,7 +470,7 @@ mymain(void)
 
 DO_TEST_LIST_DEFINED();
 
-DO_TEST_PARSE_JSON("mdevctl-list-empty");
+DO_TEST_PARSE_JSON("mdevctl-list-empty-array");
 DO_TEST_PARSE_JSON("mdevctl-list-multiple");
 
 DO_TEST_DEFINE("mdev_d069d019_36ea_4111_8f0a_8c9a70e21366");
-- 
2.41.0



[PATCH 3/6] nodedevmdevctltest: Introduce a test case for empty mdevctl output

2023-08-24 Thread Michal Privoznik
As explained earlier, 'mdevctl' can output nothing. Add a test
case to nodedevmdevctltest which covers this situation.

Signed-off-by: Michal Privoznik 
---
 tests/nodedevmdevctldata/mdevctl-list-empty.json| 0
 tests/nodedevmdevctldata/mdevctl-list-empty.out.xml | 0
 tests/nodedevmdevctltest.c  | 1 +
 3 files changed, 1 insertion(+)
 create mode 100644 tests/nodedevmdevctldata/mdevctl-list-empty.json
 create mode 100644 tests/nodedevmdevctldata/mdevctl-list-empty.out.xml

diff --git a/tests/nodedevmdevctldata/mdevctl-list-empty.json 
b/tests/nodedevmdevctldata/mdevctl-list-empty.json
new file mode 100644
index 00..e69de29bb2
diff --git a/tests/nodedevmdevctldata/mdevctl-list-empty.out.xml 
b/tests/nodedevmdevctldata/mdevctl-list-empty.out.xml
new file mode 100644
index 00..e69de29bb2
diff --git a/tests/nodedevmdevctltest.c b/tests/nodedevmdevctltest.c
index c04b05c417..e403328e5a 100644
--- a/tests/nodedevmdevctltest.c
+++ b/tests/nodedevmdevctltest.c
@@ -470,6 +470,7 @@ mymain(void)
 
 DO_TEST_LIST_DEFINED();
 
+DO_TEST_PARSE_JSON("mdevctl-list-empty");
 DO_TEST_PARSE_JSON("mdevctl-list-empty-array");
 DO_TEST_PARSE_JSON("mdevctl-list-multiple");
 
-- 
2.41.0



[PATCH 0/6] Fix one corner case when parsing 'mdevctl' output

2023-08-24 Thread Michal Privoznik
See 2/6 for explanation.

Michal Prívozník (6):
  nodedevmdevctltest: Rename mdevctl-list-empty test case
  nodeDeviceParseMdevctlJSON: Accept empty string
  nodedevmdevctltest: Introduce a test case for empty mdevctl output
  node_device_driver: Deduplicate mediated devices listing
  virMdevctlList: Don't check for !output
  virjsontest: Introduce a test case for an empty array

 src/node_device/node_device_driver.c  | 40 ++-
 .../mdevctl-list-empty-array.json |  1 +
 .../mdevctl-list-empty-array.out.xml  |  0
 .../mdevctl-list-empty.json   |  1 -
 tests/nodedevmdevctltest.c|  1 +
 tests/virjsontest.c   |  1 +
 6 files changed, 16 insertions(+), 28 deletions(-)
 create mode 100644 tests/nodedevmdevctldata/mdevctl-list-empty-array.json
 create mode 100644 tests/nodedevmdevctldata/mdevctl-list-empty-array.out.xml

-- 
2.41.0



[PATCH v2 0/5] Improve closing of FDs for child processes

2023-08-22 Thread Michal Privoznik
This is a v2 of:

https://listman.redhat.com/archives/libvir-list/2023-June/240351.html

Hopefully, I've implemented all Dan's suggestions.

Michal Prívozník (5):
  virfile: Introduce virCloseRange()
  virfile: Introduce virCloseFrom()
  vircommand: Unify mass FD closing
  vircommand: Introduce virCommandMassCloseRange()
  src: Detect close_range syscall during virGlobalInit()

 src/libvirt.c|   4 +
 src/libvirt_private.syms |   4 +
 src/util/vircommand.c| 160 ---
 src/util/virfile.c   | 110 +++
 src/util/virfile.h   |   5 ++
 tests/commandtest.c  |   2 +
 6 files changed, 222 insertions(+), 63 deletions(-)

-- 
2.41.0



  1   2   3   4   5   6   7   8   9   10   >