[PATCH 8/8] qemu: command: Stop formatting of 'scsi=off' for virtio-blk-pci

2020-05-06 Thread Peter Krempa
The property was deprecated. Don't format it based on the new capability
if the user didn't explicitly request it.

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

Signed-off-by: Peter Krempa 
---
 src/qemu/qemu_command.c  |  4 +++-
 ...ch64-default-cpu-kvm-virt-4.2.aarch64-latest.args |  2 +-
 ...ch64-default-cpu-tcg-virt-4.2.aarch64-latest.args |  2 +-
 .../aarch64-virt-graphics.aarch64-latest.args|  2 +-
 .../aarch64-virt-headless.aarch64-latest.args|  2 +-
 .../disk-aio-io_uring.x86_64-latest.args |  2 +-
 .../disk-backing-chains-noindex.x86_64-latest.args   | 12 ++--
 tests/qemuxml2argvdata/disk-cache.x86_64-latest.args |  2 +-
 .../disk-cdrom-tray.x86_64-latest.args   |  2 +-
 .../disk-copy_on_read.x86_64-latest.args |  2 +-
 .../disk-detect-zeroes.x86_64-latest.args|  2 +-
 .../disk-network-gluster.x86_64-latest.args  |  6 +++---
 .../disk-network-http.x86_64-latest.args |  8 
 .../disk-network-iscsi.x86_64-latest.args|  8 
 .../disk-network-nbd.x86_64-latest.args  | 10 +-
 .../disk-network-rbd.x86_64-latest.args  | 12 ++--
 .../disk-network-sheepdog.x86_64-latest.args |  2 +-
 .../disk-network-source-auth.x86_64-latest.args  |  4 ++--
 .../disk-network-tlsx509.x86_64-latest.args  |  8 
 tests/qemuxml2argvdata/disk-nvme.x86_64-latest.args  |  8 
 .../qemuxml2argvdata/disk-shared.x86_64-latest.args  |  4 ++--
 .../qemuxml2argvdata/disk-slices.x86_64-latest.args  |  6 +++---
 .../iothreads-virtio-scsi-pci.x86_64-latest.args |  2 +-
 .../luks-disks-source-qcow2.x86_64-latest.args   | 12 ++--
 ...c64-default-cpu-kvm-pseries-2.7.ppc64-latest.args |  2 +-
 ...c64-default-cpu-kvm-pseries-3.1.ppc64-latest.args |  2 +-
 ...c64-default-cpu-kvm-pseries-4.2.ppc64-latest.args |  2 +-
 ...c64-default-cpu-tcg-pseries-2.7.ppc64-latest.args |  2 +-
 ...c64-default-cpu-tcg-pseries-3.1.ppc64-latest.args |  2 +-
 ...c64-default-cpu-tcg-pseries-4.2.ppc64-latest.args |  2 +-
 .../ppc64-pseries-graphics.ppc64-latest.args |  2 +-
 .../ppc64-pseries-headless.ppc64-latest.args |  2 +-
 .../riscv64-virt-graphics.riscv64-latest.args|  2 +-
 .../riscv64-virt-headless.riscv64-latest.args|  2 +-
 .../vhost-user-fs-hugepages.x86_64-latest.args   |  2 +-
 .../virtio-non-transitional.x86_64-latest.args   |  2 +-
 .../virtio-options-disk-ats.x86_64-latest.args   |  8 
 .../virtio-options-disk-iommu.x86_64-latest.args |  4 ++--
 .../virtio-options-disk-packed.x86_64-latest.args|  8 
 .../virtio-options.x86_64-latest.args|  4 ++--
 .../virtio-transitional.x86_64-latest.args   |  4 ++--
 .../x86_64-default-cpu-kvm-pc-4.2.x86_64-latest.args |  2 +-
 ...x86_64-default-cpu-kvm-q35-4.2.x86_64-latest.args |  2 +-
 .../x86_64-default-cpu-tcg-pc-4.2.x86_64-latest.args |  2 +-
 ...x86_64-default-cpu-tcg-q35-4.2.x86_64-latest.args |  2 +-
 .../x86_64-pc-graphics.x86_64-latest.args|  2 +-
 .../x86_64-pc-headless.x86_64-latest.args|  2 +-
 .../x86_64-q35-graphics.x86_64-latest.args   |  2 +-
 .../x86_64-q35-headless.x86_64-latest.args   |  2 +-
 49 files changed, 97 insertions(+), 95 deletions(-)

diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 269bdbaf56..31fc0b4340 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -2113,7 +2113,9 @@ qemuBuildDiskDeviceStr(const virDomainDef *def,
 virBufferAsprintf(, ",event_idx=%s",
   virTristateSwitchTypeToString(disk->event_idx));
 }
-if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_VIRTIO_BLK_SCSI)) {
+if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_VIRTIO_BLK_SCSI) &&
+!(virQEMUCapsGet(qemuCaps, 
QEMU_CAPS_VIRTIO_BLK_SCSI_DEFAULT_DISABLED) &&
+  disk->device != VIR_DOMAIN_DISK_DEVICE_LUN)) {
 /* if sg_io is true but the scsi option isn't supported,
  * that means it's just always on in this version of qemu.
  */
diff --git 
a/tests/qemuxml2argvdata/aarch64-default-cpu-kvm-virt-4.2.aarch64-latest.args 
b/tests/qemuxml2argvdata/aarch64-default-cpu-kvm-virt-4.2.aarch64-latest.args
index e8da16897f..8cb202a2c9 100644
--- 
a/tests/qemuxml2argvdata/aarch64-default-cpu-kvm-virt-4.2.aarch64-latest.args
+++ 
b/tests/qemuxml2argvdata/aarch64-default-cpu-kvm-virt-4.2.aarch64-latest.args
@@ -33,7 +33,7 @@ addr=0x1 \
 "node-name":"libvirt-1-storage","auto-read-only":true,"discard":"unmap"}' \
 -blockdev '{"node-name":"libvirt-1-format","read-only":false,"driver":"qcow2",\
 "file":"libvirt-1-storage"}' \
--device virtio-blk-pci,scsi=off,bus=pci.1,addr=0x0,drive=libvirt-1-format,\
+-device virtio-blk-pci,bus=pci.1,addr=0x0,drive=libvirt-1-format,\
 id=virtio-disk0,bootindex=1 \
 -sandbox 

[PATCH 3/8] virQEMUCapsProbeQMPObjectTypes: Fold in virQEMUCapsProbeQMPGenericProps

2020-05-06 Thread Peter Krempa
virQEMUCapsProbeQMPGenericProps is used only in one place now. Move the
code directly to virQEMUCapsProbeQMPObjectTypes.

Signed-off-by: Peter Krempa 
---
 src/qemu/qemu_capabilities.c | 60 +---
 1 file changed, 21 insertions(+), 39 deletions(-)

diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index 5e72dead45..42425fabbd 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -1483,10 +1483,6 @@ struct _virQEMUCapsObjectTypeProps {
 int capsCondition;
 };

-typedef int (*virQEMUCapsObjectTypePropsCB)(qemuMonitorPtr mon,
-const char *type,
-char ***props);
-
 static virQEMUCapsObjectTypeProps virQEMUCapsDeviceProps[] = {
 { "virtio-blk-pci", virQEMUCapsDevicePropsVirtioBlk,
   G_N_ELEMENTS(virQEMUCapsDevicePropsVirtioBlk),
@@ -2556,36 +2552,6 @@ virQEMUCapsProbeQMPEvents(virQEMUCapsPtr qemuCaps,
 return 0;
 }

-static int
-virQEMUCapsProbeQMPGenericProps(virQEMUCapsPtr qemuCaps,
-qemuMonitorPtr mon,
-virQEMUCapsObjectTypeProps *props,
-size_t nprops,
-virQEMUCapsObjectTypePropsCB propsGetCB)
-{
-int nvalues;
-char **values;
-size_t i;
-
-for (i = 0; i < nprops; i++) {
-const char *type = props[i].type;
-int cap = props[i].capsCondition;
-
-if (cap >= 0 && !virQEMUCapsGet(qemuCaps, cap))
-continue;
-
-if ((nvalues = propsGetCB(mon, type, )) < 0)
-return -1;
-virQEMUCapsProcessStringFlags(qemuCaps,
-  props[i].nprops,
-  props[i].props,
-  nvalues, values);
-virStringListFreeCount(values, nvalues);
-}
-
-return 0;
-}
-

 static int
 virQEMUCapsProbeQMPObjectTypes(virQEMUCapsPtr qemuCaps,
@@ -2638,14 +2604,30 @@ static int
 virQEMUCapsProbeQMPObjectProperties(virQEMUCapsPtr qemuCaps,
 qemuMonitorPtr mon)
 {
+size_t i;
+
 if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_QOM_LIST_PROPERTIES))
 return 0;

-return virQEMUCapsProbeQMPGenericProps(qemuCaps,
-   mon,
-   virQEMUCapsObjectProps,
-   
G_N_ELEMENTS(virQEMUCapsObjectProps),
-   qemuMonitorGetObjectProps);
+for (i = 0; i < G_N_ELEMENTS(virQEMUCapsObjectProps); i++) {
+virQEMUCapsObjectTypeProps *props = virQEMUCapsObjectProps + i;
+VIR_AUTOSTRINGLIST values = NULL;
+int nvalues;
+
+if (props->capsCondition >= 0 &&
+!virQEMUCapsGet(qemuCaps, props->capsCondition))
+continue;
+
+if ((nvalues = qemuMonitorGetObjectProps(mon, props->type, )) < 
0)
+return -1;
+
+virQEMUCapsProcessStringFlags(qemuCaps,
+  props->nprops,
+  props->props,
+  nvalues, values);
+}
+
+return 0;
 }


-- 
2.26.2



[PATCH 4/8] qemuMonitorJSONGetDeviceProps: Refactor to modern standards

2020-05-06 Thread Peter Krempa
Use automatic cleanup of variables and current style of header.

Signed-off-by: Peter Krempa 
---
 src/qemu/qemu_monitor_json.c | 26 ++
 1 file changed, 10 insertions(+), 16 deletions(-)

diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
index 619717eae5..9d1db07ccd 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -6745,13 +6745,13 @@ qemuMonitorJSONParsePropsList(virJSONValuePtr cmd,
 }


-int qemuMonitorJSONGetDeviceProps(qemuMonitorPtr mon,
-  const char *device,
-  char ***props)
+int
+qemuMonitorJSONGetDeviceProps(qemuMonitorPtr mon,
+  const char *device,
+  char ***props)
 {
-int ret = -1;
-virJSONValuePtr cmd;
-virJSONValuePtr reply = NULL;
+g_autoptr(virJSONValue) cmd = NULL;
+g_autoptr(virJSONValue) reply = NULL;

 *props = NULL;

@@ -6761,18 +6761,12 @@ int qemuMonitorJSONGetDeviceProps(qemuMonitorPtr mon,
 return -1;

 if (qemuMonitorJSONCommand(mon, cmd, ) < 0)
-goto cleanup;
+return -1;

-if (qemuMonitorJSONHasError(reply, "DeviceNotFound")) {
-ret = 0;
-goto cleanup;
-}
+if (qemuMonitorJSONHasError(reply, "DeviceNotFound"))
+return 0;

-ret = qemuMonitorJSONParsePropsList(cmd, reply, NULL, props);
- cleanup:
-virJSONValueFree(reply);
-virJSONValueFree(cmd);
-return ret;
+return qemuMonitorJSONParsePropsList(cmd, reply, NULL, props);
 }


-- 
2.26.2



[PATCH 2/8] virQEMUCapsProbeQMPDeviceProperties: Switch to local implementation

2020-05-06 Thread Peter Krempa
Reimplement device property detection directly rather than using
virQEMUCapsProbeQMPGenericProps in preparation for changes to the
detection code.

Signed-off-by: Peter Krempa 
---
 src/qemu/qemu_capabilities.c | 26 +-
 1 file changed, 21 insertions(+), 5 deletions(-)

diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index dadbef32a2..5e72dead45 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -2610,11 +2610,27 @@ static int
 virQEMUCapsProbeQMPDeviceProperties(virQEMUCapsPtr qemuCaps,
 qemuMonitorPtr mon)
 {
-return virQEMUCapsProbeQMPGenericProps(qemuCaps,
-   mon,
-   virQEMUCapsDeviceProps,
-   
G_N_ELEMENTS(virQEMUCapsDeviceProps),
-   qemuMonitorGetDeviceProps);
+size_t i;
+
+for (i = 0; i < G_N_ELEMENTS(virQEMUCapsDeviceProps); i++) {
+virQEMUCapsObjectTypeProps *device = virQEMUCapsDeviceProps + i;
+VIR_AUTOSTRINGLIST values = NULL;
+int nvalues;
+
+if (device->capsCondition >= 0 &&
+!virQEMUCapsGet(qemuCaps, device->capsCondition))
+continue;
+
+if ((nvalues = qemuMonitorGetDeviceProps(mon, device->type, )) 
< 0)
+return -1;
+
+virQEMUCapsProcessStringFlags(qemuCaps,
+  device->nprops,
+  device->props,
+  nvalues, values);
+}
+
+return 0;
 }


-- 
2.26.2



[PATCH 0/8] qemu: caps: Add detection of default device property values and remove deprecated 'scsi=off'

2020-05-06 Thread Peter Krempa
First part focuses on allowing the device property code to detect the
default values for the properties and the second part then uses it to
remove formatting of the deprecated 'scsi=off' for virti-blk-pci.

Peter Krempa (8):
  virQEMUCapsProbeQMPDevices: Split up into logical chunks
  virQEMUCapsProbeQMPDeviceProperties: Switch to local implementation
  virQEMUCapsProbeQMPObjectTypes: Fold in
virQEMUCapsProbeQMPGenericProps
  qemuMonitorJSONGetDeviceProps: Refactor to modern standards
  qemuMonitorGetDeviceProps: Return data in a hash table
  virQEMUCapsProbeQMPDeviceProperties: Add per-property callbacks
  qemu: capabilities: Introduce
QEMU_CAPS_VIRTIO_BLK_SCSI_DEFAULT_DISABLED
  qemu: command: Stop formatting of 'scsi=off' for virtio-blk-pci

 src/qemu/qemu_capabilities.c  | 347 ++
 src/qemu/qemu_capabilities.h  |   1 +
 src/qemu/qemu_command.c   |   4 +-
 src/qemu/qemu_monitor.c   |  11 +-
 src/qemu/qemu_monitor.h   |   5 +-
 src/qemu/qemu_monitor_json.c  |  58 ++-
 src/qemu/qemu_monitor_json.h  |   7 +-
 .../caps_5.0.0.aarch64.xml|   1 +
 .../qemucapabilitiesdata/caps_5.0.0.ppc64.xml |   1 +
 .../caps_5.0.0.riscv64.xml|   1 +
 .../caps_5.0.0.x86_64.xml |   1 +
 .../caps_5.1.0.x86_64.xml |   1 +
 ...fault-cpu-kvm-virt-4.2.aarch64-latest.args |   2 +-
 ...fault-cpu-tcg-virt-4.2.aarch64-latest.args |   2 +-
 .../aarch64-virt-graphics.aarch64-latest.args |   2 +-
 .../aarch64-virt-headless.aarch64-latest.args |   2 +-
 .../disk-aio-io_uring.x86_64-latest.args  |   2 +-
 ...-backing-chains-noindex.x86_64-latest.args |  12 +-
 .../disk-cache.x86_64-latest.args |   2 +-
 .../disk-cdrom-tray.x86_64-latest.args|   2 +-
 .../disk-copy_on_read.x86_64-latest.args  |   2 +-
 .../disk-detect-zeroes.x86_64-latest.args |   2 +-
 .../disk-network-gluster.x86_64-latest.args   |   6 +-
 .../disk-network-http.x86_64-latest.args  |   8 +-
 .../disk-network-iscsi.x86_64-latest.args |   8 +-
 .../disk-network-nbd.x86_64-latest.args   |  10 +-
 .../disk-network-rbd.x86_64-latest.args   |  12 +-
 .../disk-network-sheepdog.x86_64-latest.args  |   2 +-
 ...isk-network-source-auth.x86_64-latest.args |   4 +-
 .../disk-network-tlsx509.x86_64-latest.args   |   8 +-
 .../disk-nvme.x86_64-latest.args  |   8 +-
 .../disk-shared.x86_64-latest.args|   4 +-
 .../disk-slices.x86_64-latest.args|   6 +-
 ...threads-virtio-scsi-pci.x86_64-latest.args |   2 +-
 ...luks-disks-source-qcow2.x86_64-latest.args |  12 +-
 ...ault-cpu-kvm-pseries-2.7.ppc64-latest.args |   2 +-
 ...ault-cpu-kvm-pseries-3.1.ppc64-latest.args |   2 +-
 ...ault-cpu-kvm-pseries-4.2.ppc64-latest.args |   2 +-
 ...ault-cpu-tcg-pseries-2.7.ppc64-latest.args |   2 +-
 ...ault-cpu-tcg-pseries-3.1.ppc64-latest.args |   2 +-
 ...ault-cpu-tcg-pseries-4.2.ppc64-latest.args |   2 +-
 .../ppc64-pseries-graphics.ppc64-latest.args  |   2 +-
 .../ppc64-pseries-headless.ppc64-latest.args  |   2 +-
 .../riscv64-virt-graphics.riscv64-latest.args |   2 +-
 .../riscv64-virt-headless.riscv64-latest.args |   2 +-
 ...vhost-user-fs-hugepages.x86_64-latest.args |   2 +-
 ...virtio-non-transitional.x86_64-latest.args |   2 +-
 ...virtio-options-disk-ats.x86_64-latest.args |   8 +-
 ...rtio-options-disk-iommu.x86_64-latest.args |   4 +-
 ...tio-options-disk-packed.x86_64-latest.args |   8 +-
 .../virtio-options.x86_64-latest.args |   4 +-
 .../virtio-transitional.x86_64-latest.args|   4 +-
 ...-default-cpu-kvm-pc-4.2.x86_64-latest.args |   2 +-
 ...default-cpu-kvm-q35-4.2.x86_64-latest.args |   2 +-
 ...-default-cpu-tcg-pc-4.2.x86_64-latest.args |   2 +-
 ...default-cpu-tcg-q35-4.2.x86_64-latest.args |   2 +-
 .../x86_64-pc-graphics.x86_64-latest.args |   2 +-
 .../x86_64-pc-headless.x86_64-latest.args |   2 +-
 .../x86_64-q35-graphics.x86_64-latest.args|   2 +-
 .../x86_64-q35-headless.x86_64-latest.args|   2 +-
 60 files changed, 356 insertions(+), 270 deletions(-)

-- 
2.26.2



[PATCH 7/8] qemu: capabilities: Introduce QEMU_CAPS_VIRTIO_BLK_SCSI_DEFAULT_DISABLED

2020-05-06 Thread Peter Krempa
Historically the 'scsi' passthrough feature of virtio-blk-pci
was enabled by default. Libvirt was disabling it due to security
implications outlined in libvirt commit v0.9.9-4-g177db08775 if it was
not explicitly requested. In qemu commit v2.4.0-1566-ged65fd1a27 the
default value was changed to disabled in preparation for virtio-1.
Starting from QEMU-5.0 the 'scsi' property was also deprecated. There
replacement for the functionality is to use 'virtio-scsi' for the
purpose. This isn't a direct replacement though.

Add capability named QEMU_CAPS_VIRTIO_BLK_SCSI_DEFAULT_DISABLED which
allows us to stop formatting the 'scsi=' property if it's disabled by
default and not requested so that we don't use deprecated features.

Signed-off-by: Peter Krempa 
---
 src/qemu/qemu_capabilities.c  | 20 ++-
 src/qemu/qemu_capabilities.h  |  1 +
 .../caps_5.0.0.aarch64.xml|  1 +
 .../qemucapabilitiesdata/caps_5.0.0.ppc64.xml |  1 +
 .../caps_5.0.0.riscv64.xml|  1 +
 .../caps_5.0.0.x86_64.xml |  1 +
 .../caps_5.1.0.x86_64.xml |  1 +
 7 files changed, 25 insertions(+), 1 deletion(-)

diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index 94a1e5e3b8..0e7db2643a 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -580,6 +580,7 @@ VIR_ENUM_IMPL(virQEMUCaps,
   "machine.pseries.cap-sbbc",
   "machine.pseries.cap-ibs",
   "tcg",
+  "virtio-blk-pci.scsi.default.disabled",
 );


@@ -1319,10 +1320,27 @@ static struct virQEMUCapsDevicePropsFlags 
virQEMUCapsDevicePropsVirtioBalloon[]
 { "packed", QEMU_CAPS_VIRTIO_PACKED_QUEUES, NULL },
 };

+
+static int
+virQEMUCapsDevicePropsVirtioBlkSCSIDefault(virJSONValuePtr props,
+   virQEMUCapsPtr qemuCaps)
+{
+bool def = false;
+
+if (virJSONValueObjectGetBoolean(props, "default-value", ) < 0)
+return 0;
+
+if (def == false)
+virQEMUCapsSet(qemuCaps, QEMU_CAPS_VIRTIO_BLK_SCSI_DEFAULT_DISABLED);
+
+return 0;
+}
+
+
 static struct virQEMUCapsDevicePropsFlags virQEMUCapsDevicePropsVirtioBlk[] = {
 { "ioeventfd", QEMU_CAPS_VIRTIO_IOEVENTFD, NULL },
 { "event_idx", QEMU_CAPS_VIRTIO_BLK_EVENT_IDX, NULL },
-{ "scsi", QEMU_CAPS_VIRTIO_BLK_SCSI, NULL },
+{ "scsi", QEMU_CAPS_VIRTIO_BLK_SCSI, 
virQEMUCapsDevicePropsVirtioBlkSCSIDefault },
 { "logical_block_size", QEMU_CAPS_BLOCKIO, NULL },
 { "num-queues", QEMU_CAPS_VIRTIO_BLK_NUM_QUEUES, NULL },
 { "share-rw", QEMU_CAPS_DISK_SHARE_RW, NULL },
diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h
index cdeaf09cce..db8bebe3df 100644
--- a/src/qemu/qemu_capabilities.h
+++ b/src/qemu/qemu_capabilities.h
@@ -561,6 +561,7 @@ typedef enum { /* virQEMUCapsFlags grouping marker for 
syntax-check */
 QEMU_CAPS_MACHINE_PSERIES_CAP_SBBC, /* -machine pseries.cap-sbbc */
 QEMU_CAPS_MACHINE_PSERIES_CAP_IBS, /* -machine pseries.cap-ibs */
 QEMU_CAPS_TCG, /* QEMU does support TCG */
+QEMU_CAPS_VIRTIO_BLK_SCSI_DEFAULT_DISABLED, /* virtio-blk-pci.scsi 
disabled by default */

 QEMU_CAPS_LAST /* this must always be the last item */
 } virQEMUCapsFlags;
diff --git a/tests/qemucapabilitiesdata/caps_5.0.0.aarch64.xml 
b/tests/qemucapabilitiesdata/caps_5.0.0.aarch64.xml
index 1f743aaa11..618ad8ee14 100644
--- a/tests/qemucapabilitiesdata/caps_5.0.0.aarch64.xml
+++ b/tests/qemucapabilitiesdata/caps_5.0.0.aarch64.xml
@@ -191,6 +191,7 @@
   
   
   
+  
   500
   0
   61700241
diff --git a/tests/qemucapabilitiesdata/caps_5.0.0.ppc64.xml 
b/tests/qemucapabilitiesdata/caps_5.0.0.ppc64.xml
index a5f0bb538b..0f5dce9264 100644
--- a/tests/qemucapabilitiesdata/caps_5.0.0.ppc64.xml
+++ b/tests/qemucapabilitiesdata/caps_5.0.0.ppc64.xml
@@ -199,6 +199,7 @@
   
   
   
+  
   500
   0
   42900241
diff --git a/tests/qemucapabilitiesdata/caps_5.0.0.riscv64.xml 
b/tests/qemucapabilitiesdata/caps_5.0.0.riscv64.xml
index e9651ca581..bc6a27e87e 100644
--- a/tests/qemucapabilitiesdata/caps_5.0.0.riscv64.xml
+++ b/tests/qemucapabilitiesdata/caps_5.0.0.riscv64.xml
@@ -187,6 +187,7 @@
   
   
   
+  
   500
   0
   0
diff --git a/tests/qemucapabilitiesdata/caps_5.0.0.x86_64.xml 
b/tests/qemucapabilitiesdata/caps_5.0.0.x86_64.xml
index f127f38bcc..ed4c08e99e 100644
--- a/tests/qemucapabilitiesdata/caps_5.0.0.x86_64.xml
+++ b/tests/qemucapabilitiesdata/caps_5.0.0.x86_64.xml
@@ -232,6 +232,7 @@
   
   
   
+  
   500
   0
   43100241
diff --git a/tests/qemucapabilitiesdata/caps_5.1.0.x86_64.xml 
b/tests/qemucapabilitiesdata/caps_5.1.0.x86_64.xml
index 9611549bd7..f7018daa84 100644
--- a/tests/qemucapabilitiesdata/caps_5.1.0.x86_64.xml
+++ b/tests/qemucapabilitiesdata/caps_5.1.0.x86_64.xml
@@ -232,6 +232,7 @@
   
   
   
+  
   550
   0
   43100242
-- 
2.26.2



[PATCH 6/8] virQEMUCapsProbeQMPDeviceProperties: Add per-property callbacks

2020-05-06 Thread Peter Krempa
QEMU-5.0 added 'default-value' field for any applicable property
returned by 'device-list-properties'. Add an optional callback for any
device property definition which will allow detection of features and
default values based on this new data.

This unfortunately means that the description of properties had to move
from the slightly-too-generic 'struct virQEMUCapsStringFlags' to a new
type (virQEMUCapsDevicePropsFlags) which also has the callback property
and the corresponding change in the initializers.

Signed-off-by: Peter Krempa 
---
 src/qemu/qemu_capabilities.c | 226 +++
 1 file changed, 124 insertions(+), 102 deletions(-)

diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index ae1f0853f1..94a1e5e3b8 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -1303,154 +1303,162 @@ struct virQEMUCapsStringFlags 
virQEMUCapsObjectTypes[] = {
 { "tcg-accel", QEMU_CAPS_TCG },
 };

-static struct virQEMUCapsStringFlags virQEMUCapsDevicePropsVirtioBalloon[] = {
-{ "deflate-on-oom", QEMU_CAPS_VIRTIO_BALLOON_AUTODEFLATE },
-{ "disable-legacy", QEMU_CAPS_VIRTIO_PCI_DISABLE_LEGACY },
-{ "iommu_platform", QEMU_CAPS_VIRTIO_PCI_IOMMU_PLATFORM },
-{ "ats", QEMU_CAPS_VIRTIO_PCI_ATS },
-{ "packed", QEMU_CAPS_VIRTIO_PACKED_QUEUES },
+
+struct virQEMUCapsDevicePropsFlags {
+const char *value;
+int flag;
+int (*cb)(virJSONValuePtr props, virQEMUCapsPtr caps);
+};
+
+
+static struct virQEMUCapsDevicePropsFlags 
virQEMUCapsDevicePropsVirtioBalloon[] = {
+{ "deflate-on-oom", QEMU_CAPS_VIRTIO_BALLOON_AUTODEFLATE, NULL },
+{ "disable-legacy", QEMU_CAPS_VIRTIO_PCI_DISABLE_LEGACY, NULL },
+{ "iommu_platform", QEMU_CAPS_VIRTIO_PCI_IOMMU_PLATFORM, NULL },
+{ "ats", QEMU_CAPS_VIRTIO_PCI_ATS, NULL },
+{ "packed", QEMU_CAPS_VIRTIO_PACKED_QUEUES, NULL },
 };

-static struct virQEMUCapsStringFlags virQEMUCapsDevicePropsVirtioBlk[] = {
-{ "ioeventfd", QEMU_CAPS_VIRTIO_IOEVENTFD },
-{ "event_idx", QEMU_CAPS_VIRTIO_BLK_EVENT_IDX },
-{ "scsi", QEMU_CAPS_VIRTIO_BLK_SCSI },
-{ "logical_block_size", QEMU_CAPS_BLOCKIO },
-{ "num-queues", QEMU_CAPS_VIRTIO_BLK_NUM_QUEUES },
-{ "share-rw", QEMU_CAPS_DISK_SHARE_RW },
-{ "disable-legacy", QEMU_CAPS_VIRTIO_PCI_DISABLE_LEGACY },
-{ "iommu_platform", QEMU_CAPS_VIRTIO_PCI_IOMMU_PLATFORM },
-{ "ats", QEMU_CAPS_VIRTIO_PCI_ATS },
-{ "write-cache", QEMU_CAPS_DISK_WRITE_CACHE },
-{ "werror", QEMU_CAPS_STORAGE_WERROR },
-{ "packed", QEMU_CAPS_VIRTIO_PACKED_QUEUES },
+static struct virQEMUCapsDevicePropsFlags virQEMUCapsDevicePropsVirtioBlk[] = {
+{ "ioeventfd", QEMU_CAPS_VIRTIO_IOEVENTFD, NULL },
+{ "event_idx", QEMU_CAPS_VIRTIO_BLK_EVENT_IDX, NULL },
+{ "scsi", QEMU_CAPS_VIRTIO_BLK_SCSI, NULL },
+{ "logical_block_size", QEMU_CAPS_BLOCKIO, NULL },
+{ "num-queues", QEMU_CAPS_VIRTIO_BLK_NUM_QUEUES, NULL },
+{ "share-rw", QEMU_CAPS_DISK_SHARE_RW, NULL },
+{ "disable-legacy", QEMU_CAPS_VIRTIO_PCI_DISABLE_LEGACY, NULL },
+{ "iommu_platform", QEMU_CAPS_VIRTIO_PCI_IOMMU_PLATFORM, NULL },
+{ "ats", QEMU_CAPS_VIRTIO_PCI_ATS, NULL },
+{ "write-cache", QEMU_CAPS_DISK_WRITE_CACHE, NULL },
+{ "werror", QEMU_CAPS_STORAGE_WERROR, NULL },
+{ "packed", QEMU_CAPS_VIRTIO_PACKED_QUEUES, NULL },
 };

-static struct virQEMUCapsStringFlags virQEMUCapsDevicePropsVirtioNet[] = {
-{ "tx", QEMU_CAPS_VIRTIO_TX_ALG },
-{ "event_idx", QEMU_CAPS_VIRTIO_NET_EVENT_IDX },
-{ "rx_queue_size", QEMU_CAPS_VIRTIO_NET_RX_QUEUE_SIZE },
-{ "tx_queue_size", QEMU_CAPS_VIRTIO_NET_TX_QUEUE_SIZE },
-{ "host_mtu", QEMU_CAPS_VIRTIO_NET_HOST_MTU },
-{ "disable-legacy", QEMU_CAPS_VIRTIO_PCI_DISABLE_LEGACY },
-{ "iommu_platform", QEMU_CAPS_VIRTIO_PCI_IOMMU_PLATFORM },
-{ "ats", QEMU_CAPS_VIRTIO_PCI_ATS },
-{ "failover", QEMU_CAPS_VIRTIO_NET_FAILOVER },
-{ "packed", QEMU_CAPS_VIRTIO_PACKED_QUEUES },
+static struct virQEMUCapsDevicePropsFlags virQEMUCapsDevicePropsVirtioNet[] = {
+{ "tx", QEMU_CAPS_VIRTIO_TX_ALG, NULL },
+{ "event_idx", QEMU_CAPS_VIRTIO_NET_EVENT_IDX, NULL },
+{ "rx_queue_size", QEMU_CAPS_VIRTIO_NET_RX_QUEUE_SIZE, NULL },
+{ "tx_queue_size", QEMU_CAPS_VIRTIO_NET_TX_QUEUE_SIZE, NULL },
+{ "host_mtu", QEMU_CAPS_VIRTIO_NET_HOST_MTU, NULL },
+{ "disable-legacy", QEMU_CAPS_VIRTIO_PCI_DISABLE_LEGACY, NULL },
+{ "iommu_platform", QEMU_CAPS_VIRTIO_PCI_IOMMU_PLATFORM, NULL },
+{ "ats", QEMU_CAPS_VIRTIO_PCI_ATS, NULL },
+{ "failover", QEMU_CAPS_VIRTIO_NET_FAILOVER, NULL },
+{ "packed", QEMU_CAPS_VIRTIO_PACKED_QUEUES, NULL },
 };

-static struct virQEMUCapsStringFlags virQEMUCapsDevicePropsPCIeRootPort[] = {
-{ "hotplug", QEMU_CAPS_PCIE_ROOT_PORT_HOTPLUG },
+static struct virQEMUCapsDevicePropsFlags virQEMUCapsDevicePropsPCIeRootPort[] 
= {
+{ "hotplug", QEMU_CAPS_PCIE_ROOT_PORT_HOTPLUG, NULL },
 };

-static struct virQEMUCapsStringFlags 

[PATCH 5/8] qemuMonitorGetDeviceProps: Return data in a hash table

2020-05-06 Thread Peter Krempa
Create a hash table of device property names which also stores the
corresponding JSON object so that the detection code can look at the
recently added 'default-value' field and possibly others.

Signed-off-by: Peter Krempa 
---
 src/qemu/qemu_capabilities.c | 18 --
 src/qemu/qemu_monitor.c  | 11 -
 src/qemu/qemu_monitor.h  |  5 ++--
 src/qemu/qemu_monitor_json.c | 46 +---
 src/qemu/qemu_monitor_json.h |  7 +++---
 5 files changed, 58 insertions(+), 29 deletions(-)

diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index 42425fabbd..ae1f0853f1 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -2580,20 +2580,24 @@ virQEMUCapsProbeQMPDeviceProperties(virQEMUCapsPtr 
qemuCaps,

 for (i = 0; i < G_N_ELEMENTS(virQEMUCapsDeviceProps); i++) {
 virQEMUCapsObjectTypeProps *device = virQEMUCapsDeviceProps + i;
-VIR_AUTOSTRINGLIST values = NULL;
-int nvalues;
+g_autoptr(virHashTable) qemuprops = NULL;
+size_t j;

 if (device->capsCondition >= 0 &&
 !virQEMUCapsGet(qemuCaps, device->capsCondition))
 continue;

-if ((nvalues = qemuMonitorGetDeviceProps(mon, device->type, )) 
< 0)
+if (!(qemuprops = qemuMonitorGetDeviceProps(mon, device->type)))
 return -1;

-virQEMUCapsProcessStringFlags(qemuCaps,
-  device->nprops,
-  device->props,
-  nvalues, values);
+for (j = 0; j < device->nprops; j++) {
+virJSONValuePtr entry = virHashLookup(qemuprops, 
device->props[j].value);
+
+if (!entry)
+continue;
+
+virQEMUCapsSet(qemuCaps, device->props[j].flag);
+}
 }

 return 0;
diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
index 339facfad3..9c853ccb93 100644
--- a/src/qemu/qemu_monitor.c
+++ b/src/qemu/qemu_monitor.c
@@ -3764,16 +3764,15 @@ qemuMonitorGetObjectTypes(qemuMonitorPtr mon,
 }


-int
+virHashTablePtr
 qemuMonitorGetDeviceProps(qemuMonitorPtr mon,
-  const char *device,
-  char ***props)
+  const char *device)
 {
-VIR_DEBUG("device=%s props=%p", device, props);
+VIR_DEBUG("device=%s", device);

-QEMU_CHECK_MONITOR(mon);
+QEMU_CHECK_MONITOR_NULL(mon);

-return qemuMonitorJSONGetDeviceProps(mon, device, props);
+return qemuMonitorJSONGetDeviceProps(mon, device);
 }


diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h
index 68e21dcaee..2e35d94bda 100644
--- a/src/qemu/qemu_monitor.h
+++ b/src/qemu/qemu_monitor.h
@@ -1203,9 +1203,8 @@ int qemuMonitorGetKVMState(qemuMonitorPtr mon,

 int qemuMonitorGetObjectTypes(qemuMonitorPtr mon,
   char ***types);
-int qemuMonitorGetDeviceProps(qemuMonitorPtr mon,
-  const char *device,
-  char ***props);
+virHashTablePtr qemuMonitorGetDeviceProps(qemuMonitorPtr mon,
+  const char *device);
 int qemuMonitorGetObjectProps(qemuMonitorPtr mon,
   const char *object,
   char ***props);
diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
index 9d1db07ccd..505b31a78a 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -6745,28 +6745,56 @@ qemuMonitorJSONParsePropsList(virJSONValuePtr cmd,
 }


-int
+static int
+qemuMonitorJSONGetDevicePropsWorker(size_t pos G_GNUC_UNUSED,
+virJSONValuePtr item,
+void *opaque)
+{
+const char *name = virJSONValueObjectGetString(item, "name");
+virHashTablePtr devices = opaque;
+
+if (!name) {
+virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+   _("reply data was missing 'name'"));
+return -1;
+}
+
+if (virHashAddEntry(devices, name, item) < 0)
+return -1;
+
+return 0;
+}
+
+
+virHashTablePtr
 qemuMonitorJSONGetDeviceProps(qemuMonitorPtr mon,
-  const char *device,
-  char ***props)
+  const char *device)
 {
+g_autoptr(virHashTable) props = virHashNew(virJSONValueHashFree);
 g_autoptr(virJSONValue) cmd = NULL;
 g_autoptr(virJSONValue) reply = NULL;

-*props = NULL;
-
 if (!(cmd = qemuMonitorJSONMakeCommand("device-list-properties",
"s:typename", device,
NULL)))
-return -1;
+return NULL;

 if (qemuMonitorJSONCommand(mon, cmd, ) < 0)
-return -1;
+return NULL;

+/* return empty hash */
 if (qemuMonitorJSONHasError(reply, "DeviceNotFound"))
-return 

[PATCH 1/8] virQEMUCapsProbeQMPDevices: Split up into logical chunks

2020-05-06 Thread Peter Krempa
The function was parsing 'qom-list-types' and then also calling function
which parses 'device-list-properties' and also 'qom-list-properties'.
Split it up into individual functions.

Signed-off-by: Peter Krempa 
---
 src/qemu/qemu_capabilities.c | 51 
 1 file changed, 34 insertions(+), 17 deletions(-)

diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index 2c6e36685e..dadbef32a2 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -2586,9 +2586,10 @@ virQEMUCapsProbeQMPGenericProps(virQEMUCapsPtr qemuCaps,
 return 0;
 }

+
 static int
-virQEMUCapsProbeQMPDevices(virQEMUCapsPtr qemuCaps,
-   qemuMonitorPtr mon)
+virQEMUCapsProbeQMPObjectTypes(virQEMUCapsPtr qemuCaps,
+   qemuMonitorPtr mon)
 {
 int nvalues;
 char **values;
@@ -2601,22 +2602,34 @@ virQEMUCapsProbeQMPDevices(virQEMUCapsPtr qemuCaps,
   nvalues, values);
 virStringListFreeCount(values, nvalues);

-if (virQEMUCapsProbeQMPGenericProps(qemuCaps,
-mon,
-virQEMUCapsDeviceProps,
-G_N_ELEMENTS(virQEMUCapsDeviceProps),
-qemuMonitorGetDeviceProps) < 0)
-return -1;
+return 0;
+}

-if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_QOM_LIST_PROPERTIES) &&
-virQEMUCapsProbeQMPGenericProps(qemuCaps,
-mon,
-virQEMUCapsObjectProps,
-G_N_ELEMENTS(virQEMUCapsObjectProps),
-qemuMonitorGetObjectProps) < 0)
-return -1;

-return 0;
+static int
+virQEMUCapsProbeQMPDeviceProperties(virQEMUCapsPtr qemuCaps,
+qemuMonitorPtr mon)
+{
+return virQEMUCapsProbeQMPGenericProps(qemuCaps,
+   mon,
+   virQEMUCapsDeviceProps,
+   
G_N_ELEMENTS(virQEMUCapsDeviceProps),
+   qemuMonitorGetDeviceProps);
+}
+
+
+static int
+virQEMUCapsProbeQMPObjectProperties(virQEMUCapsPtr qemuCaps,
+qemuMonitorPtr mon)
+{
+if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_QOM_LIST_PROPERTIES))
+return 0;
+
+return virQEMUCapsProbeQMPGenericProps(qemuCaps,
+   mon,
+   virQEMUCapsObjectProps,
+   
G_N_ELEMENTS(virQEMUCapsObjectProps),
+   qemuMonitorGetObjectProps);
 }


@@ -5061,7 +5074,11 @@ virQEMUCapsInitQMPMonitor(virQEMUCapsPtr qemuCaps,

 if (virQEMUCapsProbeQMPEvents(qemuCaps, mon) < 0)
 return -1;
-if (virQEMUCapsProbeQMPDevices(qemuCaps, mon) < 0)
+if (virQEMUCapsProbeQMPObjectTypes(qemuCaps, mon) < 0)
+return -1;
+if (virQEMUCapsProbeQMPDeviceProperties(qemuCaps, mon) < 0)
+return -1;
+if (virQEMUCapsProbeQMPObjectProperties(qemuCaps, mon) < 0)
 return -1;
 if (virQEMUCapsProbeQMPMachineTypes(qemuCaps, type, mon) < 0)
 return -1;
-- 
2.26.2



Re: Release of libvirt-6.3.0

2020-05-06 Thread Jim Fehlig

Hi Daniel,

On 5/5/20 2:01 AM, Daniel Veillard wrote:

It's out, tagged in git and the signed sources tarball and rpm are
available from the usual place:

https://libvirt.org/sources/

I have also pushed the python bindings 6.3.0 release at their usual place

https://libvirt.org/sources/python/


I noticed there is no associated signature file for 6.3.0 python bindings.

Regards,
Jim




Re: [libvirt-ocaml PATCH 2/2] gitlab: add CONTRIBUTING.rst file to indicate use of merge requests

2020-05-06 Thread Andrea Bolognani
On Wed, 2020-05-06 at 16:24 +0100, Daniel P. Berrangé wrote:
> +++ b/CONTRIBUTING.rst
> @@ -0,0 +1,28 @@
> +=
> +Contributing to libvirt-ocaml
> +=
> +
> +The libvirt Ocaml API binding accepts code contributions via merge requests
> +on the GitLab project:

s/binding/bindings/

[...]
> +Contributions submitted to the project must be in compliance with the
> +Developer Certificate of Origin Version 1.1. This is documented at:
> +
> +   https://developercertificate.org/

Links should not be indented.

> +In indicate compliance, each commit in a series must have a "Signed-off-by"
> +tag with the submittor's name and email address. This can be added by passing
> +the ``-s`` flag to ``git commit`` when creating the patches.

s/submittor/submitter/

-- 
Andrea Bolognani / Red Hat / Virtualization



Re: [libvirt-ocaml PATCH 1/2] gitlab: introduce CI jobs testing git master & distro libvirt

2020-05-06 Thread Andrea Bolognani
On Wed, 2020-05-06 at 16:24 +0100, Daniel P. Berrangé wrote:
> +.git_build_job_template: _build_job_definition
> +  image: $CI_REGISTRY_IMAGE/ci-$NAME:latest
> +  stage: builds
> +  before_script:
> +- export MAKEFLAGS="-j$(getconf _NPROCESSORS_ONLN)"
> +- export SCRATCH_DIR="/tmp/scratch"
> +- export VROOT="$SCRATCH_DIR/vroot"
> +- export LD_LIBRARY_PATH="$VROOT/lib"
> +- export PATH="$VROOT/bin:$PATH"
> +- export PKG_CONFIG_PATH="$VROOT/lib/pkgconfig"
> +  script:
> +- pushd "$PWD"
> +- mkdir -p "$SCRATCH_DIR"
> +- cd "$SCRATCH_DIR"
> +- git clone --depth 1 https://gitlab.com/libvirt/libvirt.git
> +- mkdir libvirt/build
> +- cd libvirt/build
> +- ../autogen.sh --prefix="$VROOT" --without-libvirtd
> +- $MAKE install
> +- popd
> +- autoreconf -i -f
> +- ./configure
> +- $MAKE
> +- $MAKE check-manifest

The build steps for libvirt-ocaml that we have in the libvirt-ci
repository look like

  autoreconf -vfi
  ./configure
  $MAKE
  $MAKE opt
  $MAKE check-manifest

Please use the same here...

> +.dist_build_job_template: _build_job_definition
> +  image: $CI_REGISTRY_IMAGE/ci-$NAME:latest
> +  stage: builds
> +  before_script:
> +- export MAKEFLAGS="-j$(getconf _NPROCESSORS_ONLN)"
> +  script:
> +- autoreconf -i -f
> +- ./configure
> +- $MAKE
> +- $MAKE check-manifest

... and here.


With that addressed,

  Reviewed-by: Andrea Bolognani 

-- 
Andrea Bolognani / Red Hat / Virtualization



Re: [libvirt-php 6/6] gitlab: add CONTRIBUTING.rst file to indicate use of merge requests

2020-05-06 Thread Andrea Bolognani
On Mon, 2020-05-04 at 18:40 +0100, Daniel P. Berrangé wrote:
> +++ b/CONTRIBUTING.rst
> @@ -0,0 +1,28 @@
> +===
> +Contributing to libvirt-php
> +===
> +
> +The libvirt PHP API binding accepts code contributions via merge requests
> +on the GitLab project:

s/binding/bindings/


With that fixed,

  Reviewed-by: Andrea Bolognani 


As was the case for libvirt-php, I don't feel qualified reviewing
actual code changes... Hopefully Michal will take care of that :)

-- 
Andrea Bolognani / Red Hat / Virtualization



Re: [libvirt-php 5/6] gitlab: add CI jobs for validating build across platforms

2020-05-06 Thread Andrea Bolognani
On Mon, 2020-05-04 at 18:40 +0100, Daniel P. Berrangé wrote:
> This introduces CI jobs that replace the current jobs used on Jenkins
> for every platform except FreeBSD.

That would be correct, if not for the fact that we never actually
added libvirt-php to our Jenkins-based CI environment ;)

In general, I think you can use a much shorter commit message similar
to the one you've used for libvirt-rust, but as long as you remove
the bit above you can keep the current one too.

[...]
> +centos-7-git-build:
> +  <<: *git_build_job_definition
> +  variables:
> +NAME: centos-7
> +
> +debian-9-git-build:
> +  <<: *git_build_job_definition
> +  variables:
> +NAME: debian-9

So we're never building against the distro-provided libvirt package.
Is there a reason for that? Does it even make sense to build against
a git checkout on all these platforms?

-- 
Andrea Bolognani / Red Hat / Virtualization



Re: [libvirt-rust 2/2] gitlab: add CONTRIBUTING.rst file to indicate use of merge requests

2020-05-06 Thread Andrea Bolognani
On Tue, 2020-05-05 at 15:54 +0100, Daniel P. Berrangé wrote:
> +++ b/CONTRIBUTING.rst
> @@ -0,0 +1,28 @@
> +
> +Contributing to libvirt-rust
> +
> +
> +The libvirt Rust API binding accepts code contributions via merge requests
> +on the GitLab project:

s/binding/bindings/

[...]
> +Contributions submitted to the project must be in compliance with the
> +Developer Certificate of Origin Version 1.1. This is documented at:
> +
> +   https://developercertificate.org/

Links should not be indented, otherwise they will be interpreted
as part of a block quote.

> +In indicate compliance, each commit in a series must have a "Signed-off-by"
> +tag with the submittor's name and email address. This can be added by passing
> +the ``-s`` flag to ``git commit`` when creating the patches.

s/submittor/submitter/


With the above fixed,

  Reviewed-by: Andrea Bolognani 

-- 
Andrea Bolognani / Red Hat / Virtualization



Re: [libvirt-rust 1/2] gitlab: introduce GitLab CI job for build

2020-05-06 Thread Andrea Bolognani
On Tue, 2020-05-05 at 15:54 +0100, Daniel P. Berrangé wrote:
> +.dist_build_job_template: _build_job_definition
> +  image: $CI_REGISTRY_IMAGE/ci-$NAME:latest
> +  stage: builds
> +  before_script:
> +- export MAKEFLAGS="-j$(getconf _NPROCESSORS_ONLN)"
> +  script:
> +- cargo test --verbose

Setting MAKEFLAGS is not needed here.

With that removed,

  Reviewed-by: Andrea Bolognani 

-- 
Andrea Bolognani / Red Hat / Virtualization



Re: [PATCH libvirt v1 0/6] Fix ZPCI address auto-generation on s390

2020-05-06 Thread Andrea Bolognani
On Mon, 2020-04-20 at 21:55 +0200, Boris Fiuczynski wrote:
> On 4/10/20 2:06 PM, Andrea Bolognani wrote:
> > On Thu, 2020-04-09 at 12:30 +0200, Shalini Chellathurai Saroja wrote:
> > > The ZPCI address validation or autogeneration does not work as
> > > expected in the following scenarios
> > > 1. uid = 0 and fid = 0
> > > 2. uid = 0 and fid > 0
> > > 3. uid = 0 and fid not specified
> > > 4. uid not specified and fid > 0
> > > 5. 2 ZPCI devices with uid > 0 and fid not specified.
> > > 
> > > This is because of the following reasons
> > > 1. If uid = 0 or fid = 0 the code assumes that user has not specified
> > > the corresponding address
> > > 2. If either uid or fid is provided, the code assumes that both uid
> > > and fid addresses are specified by the user.
> > 
> > I'd have to dig up the old threads, but based on what I remember the
> > behaviors you describe are entirely intentional.
> > 
> > For PCI addresses, setting all parts of the address to zero or not
> > setting it at all is equivalent, and we wanted to be consistent with
> > that behavior for ZPCI; additionally, zero is not a valid value for
> > uid so of course neither is the address uid=0 fid=0, which means that
> > we're not preventing the user from specifying a valid address by
> > conflating the all-zero address with the unspecified address.
> > 
> > For partially-specified addresses, the behavior is also the same as
> > PCI: any part you don't specify is considered to be zero, which
> > results in
> > 
> >uid=0 fid=0 -> uid=0 fid=0 -> address gets autogenerated
> >uid=0 fid=x -> uid=0 fid=x -> address is rejected as invalid
> >uid=0   -> uid=0 fid=0 -> address gets autogenerated
> >  fid=x -> uid=0 fid=x -> address is rejected as invalid
> >uid=x   -> uid=x fid=0 -> address is accepted
> > 
> > So, just like for PCI addresses, you have basically two reasonable
> > options: either don't specify any zPCI address and leave allocation
> > entirely up to libvirt, or specify all of the addresses completely:
> > anything in between will likely not work as you'd expect or want.
> > 
> > Again, this is based purely on my recollection of design discussions
> > that happened one and a half years ago, so I might have gotten some
> > of the details wrong - in which case by all means call me out on
> > that O:-)
> > 
> Hi Andrea,
> sorry for the delayed answer. I (and some others as well) lost some 
> emails on my IMAP account and I just found your answer today.

No apologies needed: I also took a long time to reply to your
message, and in my case there's no mail server malfunction that I
can assign the blame to O:-)

> I can remember that you had a discussion with the original author of the 
> zpci code. There are a few issues with the currently implemented "rules" 
> which partially are not even working as you outlined above in more 
> complex scenarios.

I disagree with this assessment - they work exactly as designed and
as described above. Whether we *want* them to behave that way... Now
that's a different topic :)

I think the disconnect lies in what the user's expectations are and
what libvirt actually implements. Basically the user expects that

  * if either one of uid and fid is explictly assigned a value by
the user, then the guest will use that value - unless such value
is invalid, in which case libvirt will report an error;

  * if either one of uid and fid is absent from the user-provided
configuration, then libvirt will automatically pick a valid value
for the attribute.

This is not how the current zPCI implementation works, or how PCI
address assignment works in libvirt; on the other hand, I think these
expectations are in fact completely reasonable, as the examples you
provide illustrate quite well.

I think you successfully convinced me that the current approach is
not good for users and we should fix it; my only doubt at this point
is whether can we safely do that without breaking libvirt's backwards
compatibility guarantees.

Dan, Laine, what's your take?

-- 
Andrea Bolognani / Red Hat / Virtualization



Re: [libvirt PATCH] keycodemapdb: update submodule for win32 keycode fix

2020-05-06 Thread Laine Stump

On 5/5/20 8:58 AM, Daniel P. Berrangé wrote:

Fix win32 keycode for VK_OEM_102

Signed-off-by: Daniel P. Berrangé 
---
  src/keycodemapdb | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/keycodemapdb b/src/keycodemapdb
index 317d3eeb96..27acf0ef82 16
--- a/src/keycodemapdb
+++ b/src/keycodemapdb
@@ -1 +1 @@
-Subproject commit 317d3eeb963a515e15a63fa356d8ebcda7041a51
+Subproject commit 27acf0ef828bf719b2053ba398b195829413dbdd



Reviewed-by: Laine Stump 


(I didn't look up the win32 virtual-key codes, but there is no other 
change between the two commits, and everything still builds without 
error, so...)






Re: [PATCH v2] Improve blockpull man entry

2020-05-06 Thread Pavel Mores
On Tue, Apr 28, 2020 at 02:23:11PM +, Sebastian Mitterle wrote:
> 1. Fix usage of bandwidth, base arguments.
> 2. Explain valid arguments for `base`.
> 3. Move explanation for `--keep-relative` to end considering it's
>not a very frequent use case.
> 4. Add reference to documentation for relative paths in backing chains.
> 
> Signed-off-by: Sebastian Mitterle 
> ---
>  docs/manpages/virsh.rst | 19 ++-
>  1 file changed, 14 insertions(+), 5 deletions(-)
> 
> diff --git a/docs/manpages/virsh.rst b/docs/manpages/virsh.rst
> index dc404ddfe8..71bd968fab 100644
> --- a/docs/manpages/virsh.rst
> +++ b/docs/manpages/virsh.rst
> @@ -1345,7 +1345,7 @@ blockpull
>  
>  .. code-block::
>  
> -   blockpull domain path [bandwidth] [--bytes] [base]
> +   blockpull domain path [bandwidth [--bytes] [base]]

Shouldn't this be

+   blockpull domain path [bandwidth [--bytes]] [base]

or, perhaps better yet

+   blockpull domain path [--bandwidth  [--bytes]] [base]

>[--wait [--verbose] [--timeout seconds] [--async]]
>[--keep-relative]
>  
> @@ -1356,6 +1356,12 @@ the new backing file and only the intermediate portion 
> of the chain is
>  pulled.  Once all requested data from the backing image chain has been
>  pulled, the disk no longer depends on that portion of the backing chain.
>  
> +*base* can be specified in two ways: either as indexed target name 'name[i]'
> +where 'name' corresponds to the disk target name () and
> +'i' corresponds to the 'index' of the ''; or as the file name
> +of the backing file ().
> +
> +
>  By default, this command returns as soon as possible, and data for
>  the entire disk is pulled in the background; the progress of the
>  operation can be checked with ``blockjob``.  However, if *--wait* is
> @@ -1367,16 +1373,19 @@ is triggered, *--async* will return control to the 
> user as fast as
>  possible, otherwise the command may continue to block a little while
>  longer until the job is done cleaning up.
>  
> -Using the *--keep-relative* flag will keep the backing chain names
> -relative.
> -
>  *path* specifies fully-qualified path of the disk; it corresponds
>  to a unique target name () or source file (  file='name'/>) for one of the disk devices attached to *domain* (see
>  also ``domblklist`` for listing these names).
> +
>  *bandwidth* specifies copying bandwidth limit in MiB/s. For further 
> information
>  on the *bandwidth* argument see the corresponding section for the 
> ``blockjob``
> -command.
> +command. Using *--bytes* flag indicates the value in *bandwidth* is given in
> +bytes.
> +
> +Using the *--keep-relative* flag will keep the backing chain names
> +relative (details on `https://www.libvirt.org/kbase/backing_chains.html
> +`__).
>  
>  
>  blockresize
> -- 
> 2.25.2
> 



[libvirt-ocaml PATCH 1/2] gitlab: introduce CI jobs testing git master & distro libvirt

2020-05-06 Thread Daniel P . Berrangé
The ocaml build needs to validate two axis

 - A variety of libvirt versions
 - A variety of ocaml versions

We get coverage for both these axis by running a build against the
distro provided libvirt packages. All that is then missing is a build
against the latest libvirt git master, which only needs to be run on
a single distro, for which CentOS 8 is picked as a stable long life
base.

Signed-off-by: Daniel P. Berrangé 
---
 .gitlab-ci.yml   | 172 +++
 Makefile.in  |   2 +-
 ci/README.rst|  14 +++
 ci/libvirt-centos-7.Dockerfile   |  85 +
 ci/libvirt-centos-8.Dockerfile   |  63 ++
 ci/libvirt-debian-10.Dockerfile  |  55 +
 ci/libvirt-debian-9.Dockerfile   |  58 +
 ci/libvirt-debian-sid.Dockerfile |  55 +
 ci/libvirt-fedora-31.Dockerfile  |  52 
 ci/libvirt-fedora-32.Dockerfile  |  52 
 ci/libvirt-fedora-rawhide.Dockerfile |  53 +
 ci/libvirt-opensuse-151.Dockerfile   |  54 +
 ci/libvirt-ubuntu-1804.Dockerfile|  58 +
 ci/libvirt-ubuntu-2004.Dockerfile|  55 +
 ci/refresh   |  27 +
 15 files changed, 854 insertions(+), 1 deletion(-)
 create mode 100644 ci/README.rst
 create mode 100644 ci/libvirt-centos-7.Dockerfile
 create mode 100644 ci/libvirt-centos-8.Dockerfile
 create mode 100644 ci/libvirt-debian-10.Dockerfile
 create mode 100644 ci/libvirt-debian-9.Dockerfile
 create mode 100644 ci/libvirt-debian-sid.Dockerfile
 create mode 100644 ci/libvirt-fedora-31.Dockerfile
 create mode 100644 ci/libvirt-fedora-32.Dockerfile
 create mode 100644 ci/libvirt-fedora-rawhide.Dockerfile
 create mode 100644 ci/libvirt-opensuse-151.Dockerfile
 create mode 100644 ci/libvirt-ubuntu-1804.Dockerfile
 create mode 100644 ci/libvirt-ubuntu-2004.Dockerfile
 create mode 100755 ci/refresh

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 50dae92..a806975 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -1,6 +1,61 @@
 
 stages:
   - prebuild
+  - containers
+  - builds
+
+.container_job_template: _job_definition
+  image: docker:stable
+  stage: containers
+  services:
+- docker:dind
+  before_script:
+- export TAG="$CI_REGISTRY_IMAGE/ci-$NAME:latest"
+- export COMMON_TAG="$CI_REGISTRY/libvirt/libvirt-ocaml/ci-$NAME:latest"
+- docker info
+- docker login registry.gitlab.com -u "$CI_REGISTRY_USER" -p 
"$CI_REGISTRY_PASSWORD"
+  script:
+- docker pull "$TAG" || docker pull "$COMMON_TAG" || true
+- docker build --cache-from "$TAG" --cache-from "$COMMON_TAG" --tag "$TAG" 
-f "ci/libvirt-$NAME.Dockerfile" ci
+- docker push "$TAG"
+  after_script:
+- docker logout
+
+.git_build_job_template: _build_job_definition
+  image: $CI_REGISTRY_IMAGE/ci-$NAME:latest
+  stage: builds
+  before_script:
+- export MAKEFLAGS="-j$(getconf _NPROCESSORS_ONLN)"
+- export SCRATCH_DIR="/tmp/scratch"
+- export VROOT="$SCRATCH_DIR/vroot"
+- export LD_LIBRARY_PATH="$VROOT/lib"
+- export PATH="$VROOT/bin:$PATH"
+- export PKG_CONFIG_PATH="$VROOT/lib/pkgconfig"
+  script:
+- pushd "$PWD"
+- mkdir -p "$SCRATCH_DIR"
+- cd "$SCRATCH_DIR"
+- git clone --depth 1 https://gitlab.com/libvirt/libvirt.git
+- mkdir libvirt/build
+- cd libvirt/build
+- ../autogen.sh --prefix="$VROOT" --without-libvirtd
+- $MAKE install
+- popd
+- autoreconf -i -f
+- ./configure
+- $MAKE
+- $MAKE check-manifest
+
+.dist_build_job_template: _build_job_definition
+  image: $CI_REGISTRY_IMAGE/ci-$NAME:latest
+  stage: builds
+  before_script:
+- export MAKEFLAGS="-j$(getconf _NPROCESSORS_ONLN)"
+  script:
+- autoreconf -i -f
+- ./configure
+- $MAKE
+- $MAKE check-manifest
 
 # Check that all commits are signed-off for the DCO.
 # Skip on "libvirt" namespace, since we only need to run
@@ -14,3 +69,120 @@ check-dco:
   except:
 variables:
   - $CI_PROJECT_NAMESPACE == 'libvirt'
+
+centos-7-container:
+  <<: *container_job_definition
+  variables:
+NAME: centos-7
+
+centos-8-container:
+  <<: *container_job_definition
+  variables:
+NAME: centos-8
+
+debian-9-container:
+  <<: *container_job_definition
+  variables:
+NAME: debian-9
+
+debian-10-container:
+  <<: *container_job_definition
+  variables:
+NAME: debian-10
+
+debian-sid-container:
+  <<: *container_job_definition
+  variables:
+NAME: debian-sid
+
+fedora-31-container:
+  <<: *container_job_definition
+  variables:
+NAME: fedora-31
+
+fedora-32-container:
+  <<: *container_job_definition
+  variables:
+NAME: fedora-32
+
+fedora-rawhide-container:
+  <<: *container_job_definition
+  variables:
+NAME: fedora-rawhide
+
+opensuse-151-container:
+  <<: *container_job_definition
+  variables:
+NAME: opensuse-151
+
+ubuntu-1804-container:
+  <<: *container_job_definition
+  variables:
+NAME: ubuntu-1804
+

[libvirt-ocaml PATCH 2/2] gitlab: add CONTRIBUTING.rst file to indicate use of merge requests

2020-05-06 Thread Daniel P . Berrangé
With the introduction of automated CI pipelines, we are now ready to switch
to using merge requests for the project. With this switch we longer wish
to have patches sent to the mailing list.

Signed-off-by: Daniel P. Berrangé 
---
 CONTRIBUTING.rst | 28 
 MANIFEST |  1 +
 2 files changed, 29 insertions(+)
 create mode 100644 CONTRIBUTING.rst

diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst
new file mode 100644
index 000..8db0258
--- /dev/null
+++ b/CONTRIBUTING.rst
@@ -0,0 +1,28 @@
+=
+Contributing to libvirt-ocaml
+=
+
+The libvirt Ocaml API binding accepts code contributions via merge requests
+on the GitLab project:
+
+   https://gitlab.com/libvirt/libvirt-ocaml/-/merge_requests
+
+It is required that automated CI pipelines succeed before a merge request
+will be accepted. The global pipeline status for the ``master`` branch is
+visible at:
+
+   https://gitlab.com/libvirt/libvirt-ocaml/pipelines
+
+CI pipline results for merge requests will be visible via the contributors'
+own private repository fork:
+
+   https://gitlab.com/yourusername/libvirt-ocaml/pipelines
+
+Contributions submitted to the project must be in compliance with the
+Developer Certificate of Origin Version 1.1. This is documented at:
+
+   https://developercertificate.org/
+
+In indicate compliance, each commit in a series must have a "Signed-off-by"
+tag with the submittor's name and email address. This can be added by passing
+the ``-s`` flag to ``git commit`` when creating the patches.
diff --git a/MANIFEST b/MANIFEST
index b6a7707..4fec735 100644
--- a/MANIFEST
+++ b/MANIFEST
@@ -4,6 +4,7 @@ ChangeLog
 config.guess
 config.sub
 configure.ac
+CONTRIBUTING.rst
 COPYING
 COPYING.LIB
 contrib/0001-Add-Libvirt.Domain.get_cpu_stats_total.patch
-- 
2.26.2



[libvirt-ocaml PATCH 0/2] Introduce GitLab CI and merge requests

2020-05-06 Thread Daniel P . Berrangé
Add GitLab CI jobs for the build and basic test, along with use of
merge requests for contributions.

Daniel P. Berrangé (2):
  gitlab: introduce CI jobs testing git master & distro libvirt
  gitlab: add CONTRIBUTING.rst file to indicate use of merge requests

 .gitlab-ci.yml   | 172 +++
 CONTRIBUTING.rst |  28 +
 MANIFEST |   1 +
 Makefile.in  |   2 +-
 ci/README.rst|  14 +++
 ci/libvirt-centos-7.Dockerfile   |  85 +
 ci/libvirt-centos-8.Dockerfile   |  63 ++
 ci/libvirt-debian-10.Dockerfile  |  55 +
 ci/libvirt-debian-9.Dockerfile   |  58 +
 ci/libvirt-debian-sid.Dockerfile |  55 +
 ci/libvirt-fedora-31.Dockerfile  |  52 
 ci/libvirt-fedora-32.Dockerfile  |  52 
 ci/libvirt-fedora-rawhide.Dockerfile |  53 +
 ci/libvirt-opensuse-151.Dockerfile   |  54 +
 ci/libvirt-ubuntu-1804.Dockerfile|  58 +
 ci/libvirt-ubuntu-2004.Dockerfile|  55 +
 ci/refresh   |  27 +
 17 files changed, 883 insertions(+), 1 deletion(-)
 create mode 100644 CONTRIBUTING.rst
 create mode 100644 ci/README.rst
 create mode 100644 ci/libvirt-centos-7.Dockerfile
 create mode 100644 ci/libvirt-centos-8.Dockerfile
 create mode 100644 ci/libvirt-debian-10.Dockerfile
 create mode 100644 ci/libvirt-debian-9.Dockerfile
 create mode 100644 ci/libvirt-debian-sid.Dockerfile
 create mode 100644 ci/libvirt-fedora-31.Dockerfile
 create mode 100644 ci/libvirt-fedora-32.Dockerfile
 create mode 100644 ci/libvirt-fedora-rawhide.Dockerfile
 create mode 100644 ci/libvirt-opensuse-151.Dockerfile
 create mode 100644 ci/libvirt-ubuntu-1804.Dockerfile
 create mode 100644 ci/libvirt-ubuntu-2004.Dockerfile
 create mode 100755 ci/refresh

-- 
2.26.2



Re: [libvirt PATCH v2 1/1] tests: Introduce virhostdevmock

2020-05-06 Thread Andrea Bolognani
On Wed, 2020-05-06 at 15:55 +0200, Michal Privoznik wrote:
> On 5/6/20 2:54 PM, Andrea Bolognani wrote:
> > +++ b/tests/virhostdevmock.c
> > @@ -0,0 +1,29 @@
> > +/*
> > + * Copyright (C) 2020 Red Hat, Inc.
> > + * SPDX-License-Identifier: LGPL-2.1-or-later
> > + */
> > +
> > +#include 
> > +
> > +#include "virutil.h"
> > +#include "virmock.h"
> > +
> > +static char *(*real_virGetUserRuntimeDirectory)(void);
> 
> This is not needed, you are not calling the original function anywhere. 
> Moreover, the original function must be marked as attribute no-inline.

Good point! I've squashed your changes in and pushed. Thanks :)

-- 
Andrea Bolognani / Red Hat / Virtualization



Re: [PATCH 4/4] bhyve: add VNC password support

2020-05-06 Thread Fabian Freyer

On 6 May 2020, at 15:41, Daniel P. Berrangé wrote:
On Linux at least, providing passwords on the command line is 
considered

a security flaw, because any user can see the command line args of any
other process on the host.


Agreed. The only reason bhyve supports this is to support VNC clients 
that don’t support password-less authentication. Since it doesn’t 
have any configuration file, and stdin may be used by the client, I’m 
unsure what the alternative would be.


If CLI args of processes are similarly visible to other users on 
FreeBSD,

then this VNC password would be a security flaw.
They are by default, however FreeBSD does have a sysctl that disallows 
seeing other user’s processes. Since a few versions, users can easily 
configure this sysctl in the FreeBSD installer.


Of course VNC password auth scheme itself is a security flaw since it 
is

using Single-DES :-)


The bhyve(8) man page states that too:

This type of authentication is known to be cryptographically weak and 
is
not intended for use on untrusted networks.  Many implementations will 
want
to use stronger security, such as running the session over an 
encrypted

channel provided by IPsec or SSH.


(On a side note, it seems that Single-DES got even more broken recently: 
https://eprint.iacr.org/2020/523)


I guess this is something that should probably also be added to that man 
page.
Should we add a comment about this as well as the password being visible 
to the docs on libvirt’s side?





Re: [libvirt PATCH v2 1/1] tests: Introduce virhostdevmock

2020-05-06 Thread Michal Privoznik

On 5/6/20 2:54 PM, Andrea Bolognani wrote:

We need this for all tests that use virHostdevManager, because
during creation of this object for unprivileged connections
like those used in the test suite we would end up writing inside
the user's home directory.

That's bad manners in general, but when running the test suite
inside a purposefully constrained environment such as the one
exposed by pbuilder, it turns into an outright test failure:

   Could not initialize HostdevManager - operation failed: Failed
   to create state dir '/nonexistent/.cache/libvirt/hostdevmgr'

Signed-off-by: Andrea Bolognani 
---
  tests/Makefile.am   |  7 +++
  tests/qemuhotplugtest.c |  1 +
  tests/virhostdevmock.c  | 29 +
  tests/virhostdevtest.c  |  4 +++-
  4 files changed, 40 insertions(+), 1 deletion(-)
  create mode 100644 tests/virhostdevmock.c

diff --git a/tests/Makefile.am b/tests/Makefile.am
index ada5b8fc57..fc516376b4 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -212,6 +212,7 @@ test_libraries = libshunload.la \
libvirnetdaemonmock.la \
libvirnetserverclientmock.la \
libvircgroupmock.la \
+   libvirhostdevmock.la \
libvirpcimock.la \
libvirnetdevmock.la \
libvirrandommock.la \
@@ -1226,6 +1227,12 @@ libvirfilecachemock_la_SOURCES = \
  libvirfilecachemock_la_LDFLAGS = $(MOCKLIBS_LDFLAGS)
  libvirfilecachemock_la_LIBADD = $(MOCKLIBS_LIBS)
  
+libvirhostdevmock_la_SOURCES = \

+   virhostdevmock.c \
+   $(NULL)
+libvirhostdevmock_la_LDFLAGS = $(MOCKLIBS_LDFLAGS)
+libvirhostdevmock_la_LIBADD = $(MOCKLIBS_LIBS)
+
  if WITH_LINUX
  vircaps2xmltest_SOURCES = \
vircaps2xmltest.c testutils.h testutils.c virfilewrapper.h 
virfilewrapper.c
diff --git a/tests/qemuhotplugtest.c b/tests/qemuhotplugtest.c
index 9a215ab303..cf87de187f 100644
--- a/tests/qemuhotplugtest.c
+++ b/tests/qemuhotplugtest.c
@@ -900,6 +900,7 @@ mymain(void)
  }
  
  VIR_TEST_MAIN_PRELOAD(mymain,

+  VIR_TEST_MOCK("virhostdev"),
VIR_TEST_MOCK("virpci"),
VIR_TEST_MOCK("domaincaps"),
VIR_TEST_MOCK("virprocess"),
diff --git a/tests/virhostdevmock.c b/tests/virhostdevmock.c
new file mode 100644
index 00..8658d9affd
--- /dev/null
+++ b/tests/virhostdevmock.c
@@ -0,0 +1,29 @@
+/*
+ * Copyright (C) 2020 Red Hat, Inc.
+ * SPDX-License-Identifier: LGPL-2.1-or-later
+ */
+
+#include 
+
+#include "virutil.h"
+#include "virmock.h"
+
+static char *(*real_virGetUserRuntimeDirectory)(void);


This is not needed, you are not calling the original function anywhere. 
Moreover, the original function must be marked as attribute no-inline.


Squash this in:

diff --git i/src/util/virutil.h w/src/util/virutil.h
index ee23f0c1f4..49b4bf440f 100644
--- i/src/util/virutil.h
+++ w/src/util/virutil.h
@@ -99,7 +99,7 @@ char *virGetUserDirectory(void);
 char *virGetUserDirectoryByUID(uid_t uid);
 char *virGetUserConfigDirectory(void);
 char *virGetUserCacheDirectory(void);
-char *virGetUserRuntimeDirectory(void);
+char *virGetUserRuntimeDirectory(void) G_GNUC_NO_INLINE;
 char *virGetUserShell(uid_t uid);
 char *virGetUserName(uid_t uid) G_GNUC_NO_INLINE;
 char *virGetGroupName(gid_t gid) G_GNUC_NO_INLINE;
diff --git i/tests/virhostdevmock.c w/tests/virhostdevmock.c
index 8658d9affd..9b0e4dc2b0 100644
--- i/tests/virhostdevmock.c
+++ w/tests/virhostdevmock.c
@@ -6,24 +6,10 @@
 #include 

 #include "virutil.h"
-#include "virmock.h"
-
-static char *(*real_virGetUserRuntimeDirectory)(void);
-
-static void
-init_syms(void)
-{
-if (real_virGetUserRuntimeDirectory)
-return;
-
-VIR_MOCK_REAL_INIT(virGetUserRuntimeDirectory);
-}

 char *
 virGetUserRuntimeDirectory(void)
 {
-init_syms();
-
 return g_build_filename(g_getenv("LIBVIRT_FAKE_ROOT_DIR"),
 "user-runtime-directory", NULL);
 }



Reviewed-by: Michal Privoznik 

Michal



Re: [PATCH 4/4] bhyve: add VNC password support

2020-05-06 Thread Daniel P . Berrangé
On Wed, May 06, 2020 at 01:35:55PM +, Fabian Freyer wrote:
> Support setting a password for the VNC framebuffer using the passwd
> attribute on the  element, if the driver has the
> BHYVE_CAP_VNC_PASSWORD capability.
> 
> Note that virsh domxml-from-native does not output the password in the
> generated XML, as VIR_DOMAIN_DEF_FORMAT_SECURE is not set when
> formatting the domain definition.
> 
> Signed-off-by: Fabian Freyer 
> ---
>  docs/news.xml | 11 +
>  src/bhyve/bhyve_command.c | 33 ++-
>  src/bhyve/bhyve_parse_command.c   |  5 +++
>  .../bhyveargv2xml-vnc-password.args   | 10 +
>  .../bhyveargv2xml-vnc-password.xml| 22 ++
>  tests/bhyveargv2xmltest.c |  3 +-
>  .../bhyvexml2argv-vnc-password-comma.xml  | 26 
>  .../bhyvexml2argv-vnc-password.args   | 12 ++
>  .../bhyvexml2argv-vnc-password.ldargs |  1 +
>  .../bhyvexml2argv-vnc-password.xml| 26 
>  tests/bhyvexml2argvtest.c |  7 +++-
>  .../bhyvexml2xmlout-vnc-password.xml  | 41 +++
>  tests/bhyvexml2xmltest.c  |  1 +
>  13 files changed, 185 insertions(+), 13 deletions(-)
>  create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-vnc-password.args
>  create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-vnc-password.xml
>  create mode 100644 
> tests/bhyvexml2argvdata/bhyvexml2argv-vnc-password-comma.xml
>  create mode 100644 tests/bhyvexml2argvdata/bhyvexml2argv-vnc-password.args
>  create mode 100644 tests/bhyvexml2argvdata/bhyvexml2argv-vnc-password.ldargs
>  create mode 100644 tests/bhyvexml2argvdata/bhyvexml2argv-vnc-password.xml
>  create mode 100644 tests/bhyvexml2xmloutdata/bhyvexml2xmlout-vnc-password.xml

> diff --git a/tests/bhyveargv2xmldata/bhyveargv2xml-vnc-password.args 
> b/tests/bhyveargv2xmldata/bhyveargv2xml-vnc-password.args
> new file mode 100644
> index 00..c16e970795
> --- /dev/null
> +++ b/tests/bhyveargv2xmldata/bhyveargv2xml-vnc-password.args
> @@ -0,0 +1,10 @@
> +/usr/sbin/bhyve \
> +-c 1 \
> +-m 214 \
> +-u \
> +-H \
> +-P \
> +-s 0:0,hostbridge \
> +-l bootrom,/path/to/test.fd \
> +-s 4:0,fbuf,tcp=127.0.0.1:5904,password=s3cr3t \

On Linux at least, providing passwords on the command line is considered
a security flaw, because any user can see the command line args of any
other process on the host.

If CLI args of processes are similarly visible to other users on FreeBSD,
then this VNC password would be a security flaw.


Of course VNC password auth scheme itself is a security flaw since it is
using Single-DES :-)

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



[PATCH 1/4] bhyve: support parsing fbuf PCI device

2020-05-06 Thread Fabian Freyer
Add a new helper function, bhyveParsePCIFbuf, to parse the bhyve-argv
parameters for a frame-buffer device to  and 
definitions.

For now, only the listen address, port, and vga mode are detected.
Unsupported parameters are silently skipped.

This involves upgrading the private API to expose the
virDomainGraphicsDefNew helper function, which is used by
bhyveParsePCIFbuf.

Signed-off-by: Fabian Freyer 
---
 src/bhyve/bhyve_parse_command.c   | 91 ++-
 src/libvirt_private.syms  |  1 +
 .../bhyveargv2xml-vnc-listen.args | 10 ++
 .../bhyveargv2xml-vnc-listen.xml  | 22 +
 .../bhyveargv2xml-vnc-vga-io.args | 10 ++
 .../bhyveargv2xml-vnc-vga-io.xml  | 22 +
 .../bhyveargv2xml-vnc-vga-off.args| 10 ++
 .../bhyveargv2xml-vnc-vga-off.xml | 23 +
 .../bhyveargv2xml-vnc-vga-on.args | 10 ++
 .../bhyveargv2xml-vnc-vga-on.xml  | 23 +
 .../bhyveargv2xmldata/bhyveargv2xml-vnc.args  | 10 ++
 tests/bhyveargv2xmldata/bhyveargv2xml-vnc.xml | 22 +
 tests/bhyveargv2xmltest.c |  5 +
 13 files changed, 258 insertions(+), 1 deletion(-)
 create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-vnc-listen.args
 create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-vnc-listen.xml
 create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-vnc-vga-io.args
 create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-vnc-vga-io.xml
 create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-vnc-vga-off.args
 create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-vnc-vga-off.xml
 create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-vnc-vga-on.args
 create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-vnc-vga-on.xml
 create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-vnc.args
 create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-vnc.xml

diff --git a/src/bhyve/bhyve_parse_command.c b/src/bhyve/bhyve_parse_command.c
index 76423730d9..39cce67ea9 100644
--- a/src/bhyve/bhyve_parse_command.c
+++ b/src/bhyve/bhyve_parse_command.c
@@ -4,7 +4,7 @@
  * Copyright (C) 2006-2016 Red Hat, Inc.
  * Copyright (C) 2006 Daniel P. Berrange
  * Copyright (c) 2011 NetApp, Inc.
- * Copyright (C) 2016 Fabian Freyer
+ * Copyright (C) 2020 Fabian Freyer
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -552,6 +552,93 @@ bhyveParsePCINet(virDomainDefPtr def,
 return -1;
 }
 
+static int
+bhyveParsePCIFbuf(virDomainDefPtr def,
+  virDomainXMLOptionPtr xmlopt,
+  unsigned caps G_GNUC_UNUSED,
+  unsigned bus,
+  unsigned slot,
+  unsigned function,
+  const char *config)
+{
+/* -s slot,fbuf,wait,vga=on|io|off,rfb=:port,w=width,h=height */
+
+virDomainVideoDefPtr video = NULL;
+virDomainGraphicsDefPtr graphics = NULL;
+char **params = NULL;
+char *param = NULL, *separator = NULL;
+size_t nparams = 0;
+unsigned int i = 0;
+
+if (!(video = virDomainVideoDefNew(xmlopt)))
+goto cleanup;
+
+if (!(graphics = virDomainGraphicsDefNew(xmlopt)))
+goto cleanup;
+
+graphics->type = VIR_DOMAIN_GRAPHICS_TYPE_VNC;
+video->info.addr.pci.bus = bus;
+video->info.addr.pci.slot = slot;
+video->info.addr.pci.function = function;
+
+if (!config)
+goto error;
+
+if (!(params = virStringSplitCount(config, ",", 0, )))
+goto error;
+
+for (i = 0; i < nparams; i++) {
+param = params[i];
+if (!video->driver && VIR_ALLOC(video->driver) < 0)
+goto error;
+
+if (STREQ(param, "vga=on"))
+video->driver->vgaconf = VIR_DOMAIN_VIDEO_VGACONF_ON;
+
+if (STREQ(param, "vga=io"))
+video->driver->vgaconf = VIR_DOMAIN_VIDEO_VGACONF_IO;
+
+if (STREQ(param, "vga=off"))
+video->driver->vgaconf = VIR_DOMAIN_VIDEO_VGACONF_OFF;
+
+if (STRPREFIX(param, "rfb=") || STRPREFIX(param, "tcp=")) {
+/* fortunately, this is the same length as "tcp=" */
+param += strlen("rfb=");
+
+if (!(separator = strchr(param, ':')))
+goto error;
+
+*separator = '\0';
+
+if (separator != param)
+virDomainGraphicsListenAppendAddress(graphics, param);
+else
+/* Default to 127.0.0.1, just like bhyve does */
+virDomainGraphicsListenAppendAddress(graphics, "127.0.0.1");
+
+param = ++separator;
+if (virStrToLong_i(param, NULL, 10, >data.vnc.port))
+goto error;
+}
+}
+
+ cleanup:
+if (VIR_APPEND_ELEMENT(def->videos, def->nvideos, video) < 0)
+goto error;
+
+if (VIR_APPEND_ELEMENT(def->graphics, def->ngraphics, graphics) < 0)
+goto error;
+
+virStringListFree(params);
+   

[PATCH 0/4] bhyve: framebuffer resolution and VNC password

2020-05-06 Thread Fabian Freyer
Add support for setting the bhyve framebuffer resolution and probe
whether bhyve supports VNC password authentication. If it does, allow
setting the password.

While we're here, also add support for parsing bhyve's framebuffer
argument string.

Fabian Freyer (4):
  bhyve: support parsing fbuf PCI device
  bhyve: add support for setting fbuf resolution
  bhyve: probe for VNC password capability
  bhyve: add VNC password support

 docs/formatdomain.html.in |   2 +-
 docs/news.xml |  20 +++
 src/bhyve/bhyve_capabilities.c|  16 ++-
 src/bhyve/bhyve_capabilities.h|   1 +
 src/bhyve/bhyve_command.c |  36 --
 src/bhyve/bhyve_parse_command.c   | 116 +-
 src/libvirt_private.syms  |   1 +
 .../bhyveargv2xml-vnc-listen.args |  10 ++
 .../bhyveargv2xml-vnc-listen.xml  |  22 
 .../bhyveargv2xml-vnc-password.args   |  10 ++
 .../bhyveargv2xml-vnc-password.xml|  22 
 .../bhyveargv2xml-vnc-resolution.args |  10 ++
 .../bhyveargv2xml-vnc-resolution.xml  |  24 
 .../bhyveargv2xml-vnc-vga-io.args |  10 ++
 .../bhyveargv2xml-vnc-vga-io.xml  |  22 
 .../bhyveargv2xml-vnc-vga-off.args|  10 ++
 .../bhyveargv2xml-vnc-vga-off.xml |  23 
 .../bhyveargv2xml-vnc-vga-on.args |  10 ++
 .../bhyveargv2xml-vnc-vga-on.xml  |  23 
 .../bhyveargv2xmldata/bhyveargv2xml-vnc.args  |  10 ++
 tests/bhyveargv2xmldata/bhyveargv2xml-vnc.xml |  22 
 tests/bhyveargv2xmltest.c |   9 +-
 .../bhyvexml2argv-vnc-password-comma.xml  |  26 
 .../bhyvexml2argv-vnc-password.args   |  12 ++
 .../bhyvexml2argv-vnc-password.ldargs |   1 +
 .../bhyvexml2argv-vnc-password.xml|  26 
 .../bhyvexml2argv-vnc-resolution.args |  10 ++
 .../bhyvexml2argv-vnc-resolution.ldargs   |   1 +
 .../bhyvexml2argv-vnc-resolution.xml  |  20 +++
 tests/bhyvexml2argvtest.c |   8 +-
 .../bhyvexml2xmlout-vnc-password.xml  |  41 +++
 .../bhyvexml2xmlout-vnc-resolution.xml|  28 +
 tests/bhyvexml2xmltest.c  |   2 +
 33 files changed, 588 insertions(+), 16 deletions(-)
 create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-vnc-listen.args
 create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-vnc-listen.xml
 create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-vnc-password.args
 create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-vnc-password.xml
 create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-vnc-resolution.args
 create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-vnc-resolution.xml
 create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-vnc-vga-io.args
 create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-vnc-vga-io.xml
 create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-vnc-vga-off.args
 create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-vnc-vga-off.xml
 create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-vnc-vga-on.args
 create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-vnc-vga-on.xml
 create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-vnc.args
 create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-vnc.xml
 create mode 100644 tests/bhyvexml2argvdata/bhyvexml2argv-vnc-password-comma.xml
 create mode 100644 tests/bhyvexml2argvdata/bhyvexml2argv-vnc-password.args
 create mode 100644 tests/bhyvexml2argvdata/bhyvexml2argv-vnc-password.ldargs
 create mode 100644 tests/bhyvexml2argvdata/bhyvexml2argv-vnc-password.xml
 create mode 100644 tests/bhyvexml2argvdata/bhyvexml2argv-vnc-resolution.args
 create mode 100644 tests/bhyvexml2argvdata/bhyvexml2argv-vnc-resolution.ldargs
 create mode 100644 tests/bhyvexml2argvdata/bhyvexml2argv-vnc-resolution.xml
 create mode 100644 tests/bhyvexml2xmloutdata/bhyvexml2xmlout-vnc-password.xml
 create mode 100644 tests/bhyvexml2xmloutdata/bhyvexml2xmlout-vnc-resolution.xml

-- 
2.19.2




[PATCH 4/4] bhyve: add VNC password support

2020-05-06 Thread Fabian Freyer
Support setting a password for the VNC framebuffer using the passwd
attribute on the  element, if the driver has the
BHYVE_CAP_VNC_PASSWORD capability.

Note that virsh domxml-from-native does not output the password in the
generated XML, as VIR_DOMAIN_DEF_FORMAT_SECURE is not set when
formatting the domain definition.

Signed-off-by: Fabian Freyer 
---
 docs/news.xml | 11 +
 src/bhyve/bhyve_command.c | 33 ++-
 src/bhyve/bhyve_parse_command.c   |  5 +++
 .../bhyveargv2xml-vnc-password.args   | 10 +
 .../bhyveargv2xml-vnc-password.xml| 22 ++
 tests/bhyveargv2xmltest.c |  3 +-
 .../bhyvexml2argv-vnc-password-comma.xml  | 26 
 .../bhyvexml2argv-vnc-password.args   | 12 ++
 .../bhyvexml2argv-vnc-password.ldargs |  1 +
 .../bhyvexml2argv-vnc-password.xml| 26 
 tests/bhyvexml2argvtest.c |  7 +++-
 .../bhyvexml2xmlout-vnc-password.xml  | 41 +++
 tests/bhyvexml2xmltest.c  |  1 +
 13 files changed, 185 insertions(+), 13 deletions(-)
 create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-vnc-password.args
 create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-vnc-password.xml
 create mode 100644 tests/bhyvexml2argvdata/bhyvexml2argv-vnc-password-comma.xml
 create mode 100644 tests/bhyvexml2argvdata/bhyvexml2argv-vnc-password.args
 create mode 100644 tests/bhyvexml2argvdata/bhyvexml2argv-vnc-password.ldargs
 create mode 100644 tests/bhyvexml2argvdata/bhyvexml2argv-vnc-password.xml
 create mode 100644 tests/bhyvexml2xmloutdata/bhyvexml2xmlout-vnc-password.xml

diff --git a/docs/news.xml b/docs/news.xml
index d728dfa93c..bd951c2e04 100644
--- a/docs/news.xml
+++ b/docs/news.xml
@@ -44,6 +44,17 @@
 
   
 
+  
+
+  bhyve: support VNC password authentication
+
+
+  libvirt can now probe whether the bhyve binary supports
+  VNC password authentication. In case it does, a VNC password
+  can now be passed using the passwd attribute on
+  the graphics element.
+
+  
   
 
   bhyve: support setting the framebuffer resolution
diff --git a/src/bhyve/bhyve_command.c b/src/bhyve/bhyve_command.c
index db35cb9bd8..369278214c 100644
--- a/src/bhyve/bhyve_command.c
+++ b/src/bhyve/bhyve_command.c
@@ -425,17 +425,6 @@ bhyveBuildGraphicsArgStr(const virDomainDef *def,
 goto error;
 }
 
-if (graphics->data.vnc.auth.passwd) {
-virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-   _("vnc password auth not supported"));
-goto error;
-} else {
- /* Bhyve doesn't support VNC Auth yet, so print a warning about
-  * unauthenticated VNC sessions */
- VIR_WARN("%s", _("Security warning: currently VNC auth is not"
-  " supported."));
-}
-
 if (glisten->address) {
 escapeAddr = strchr(glisten->address, ':') != NULL;
 if (escapeAddr)
@@ -469,6 +458,28 @@ bhyveBuildGraphicsArgStr(const virDomainDef *def,
 goto error;
 }
 
+if (graphics->data.vnc.auth.passwd) {
+if (!(bhyveDriverGetBhyveCaps(driver) & BHYVE_CAP_VNC_PASSWORD)) {
+virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+   _("VNC Passwort authentication not supported "
+ "by bhyve"));
+goto error;
+}
+
+if (strchr(graphics->data.vnc.auth.passwd, ',')) {
+virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+   _("Password may not contain ',' character"));
+goto error;
+}
+
+virBufferAsprintf(, ",password=%s", 
graphics->data.vnc.auth.passwd);
+} else {
+if (!(bhyveDriverGetBhyveCaps(driver) & BHYVE_CAP_VNC_PASSWORD))
+VIR_WARN("%s", _("Security warning: VNC auth is not supported."));
+else
+VIR_WARN("%s", _("Security warning: VNC is used without 
authentication."));
+}
+
 if (video->res)
 virBufferAsprintf(, ",w=%d,h=%d", video->res->x, video->res->y);
 
diff --git a/src/bhyve/bhyve_parse_command.c b/src/bhyve/bhyve_parse_command.c
index 0414cb1ef1..af990f8e51 100644
--- a/src/bhyve/bhyve_parse_command.c
+++ b/src/bhyve/bhyve_parse_command.c
@@ -640,6 +640,11 @@ bhyveParsePCIFbuf(virDomainDefPtr def,
 if (virStrToLong_uip(param, NULL, 10, >res->y))
 goto error;
 }
+
+if (STRPREFIX(param, "password=")) {
+param += strlen("password=");
+graphics->data.vnc.auth.passwd = g_strdup(param);
+}
 }
 
  cleanup:
diff --git a/tests/bhyveargv2xmldata/bhyveargv2xml-vnc-password.args 
b/tests/bhyveargv2xmldata/bhyveargv2xml-vnc-password.args
new file 

[PATCH 3/4] bhyve: probe for VNC password capability

2020-05-06 Thread Fabian Freyer
Introduces the BHYVE_CAP_VNC_PASSWORD capability, which is probed by
parsing the error message from the bhyve command. When it is not
supported, bhyve -s 0,fbuf,password= will return an error message.

Signed-off-by: Fabian Freyer 
---
 src/bhyve/bhyve_capabilities.c | 16 +++-
 src/bhyve/bhyve_capabilities.h |  1 +
 2 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/src/bhyve/bhyve_capabilities.c b/src/bhyve/bhyve_capabilities.c
index fb8829d571..59783f8576 100644
--- a/src/bhyve/bhyve_capabilities.c
+++ b/src/bhyve/bhyve_capabilities.c
@@ -3,7 +3,7 @@
  *
  * Copyright (C) 2014 Roman Bogorodskiy
  * Copyright (C) 2014 Semihalf
- * Copyright (C) 2016 Fabian Freyer
+ * Copyright (C) 2020 Fabian Freyer
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -323,6 +323,17 @@ bhyveProbeCapsXHCIController(unsigned int *caps, char 
*binary)
 }
 
 
+static int
+bhyveProbeCapsVNCPassword(unsigned int *caps, char *binary)
+{
+return bhyveProbeCapsDeviceHelper(caps, binary,
+  "-s",
+  "0,fbuf,password=",
+  "Invalid fbuf emulation \"password\"",
+  BHYVE_CAP_VNC_PASSWORD);
+}
+
+
 int
 virBhyveProbeCaps(unsigned int *caps)
 {
@@ -351,6 +362,9 @@ virBhyveProbeCaps(unsigned int *caps)
 if ((ret = bhyveProbeCapsXHCIController(caps, binary)))
 goto out;
 
+if ((ret = bhyveProbeCapsVNCPassword(caps, binary)))
+goto out;
+
  out:
 VIR_FREE(binary);
 return ret;
diff --git a/src/bhyve/bhyve_capabilities.h b/src/bhyve/bhyve_capabilities.h
index 12926cf423..89f4b0308e 100644
--- a/src/bhyve/bhyve_capabilities.h
+++ b/src/bhyve/bhyve_capabilities.h
@@ -49,6 +49,7 @@ typedef enum {
 BHYVE_CAP_FBUF = 1 << 4,
 BHYVE_CAP_XHCI = 1 << 5,
 BHYVE_CAP_CPUTOPOLOGY = 1 << 6,
+BHYVE_CAP_VNC_PASSWORD = 1 << 7,
 } virBhyveCapsFlags;
 
 int virBhyveProbeGrubCaps(virBhyveGrubCapsFlags *caps);
-- 
2.19.2




[PATCH 2/4] bhyve: add support for setting fbuf resolution

2020-05-06 Thread Fabian Freyer
The resolution of the VNC framebuffer can now be set via the resolution
definition introduced in 5.9.0.

Also, add "gop" to the list of model types  the 
sub-element is valid for.

Signed-off-by: Fabian Freyer 
---
 docs/formatdomain.html.in |  2 +-
 docs/news.xml |  9 ++
 src/bhyve/bhyve_command.c |  3 ++
 src/bhyve/bhyve_parse_command.c   | 20 +
 .../bhyveargv2xml-vnc-resolution.args | 10 +++
 .../bhyveargv2xml-vnc-resolution.xml  | 24 
 tests/bhyveargv2xmltest.c |  1 +
 .../bhyvexml2argv-vnc-resolution.args | 10 +++
 .../bhyvexml2argv-vnc-resolution.ldargs   |  1 +
 .../bhyvexml2argv-vnc-resolution.xml  | 20 +
 tests/bhyvexml2argvtest.c |  1 +
 .../bhyvexml2xmlout-vnc-resolution.xml| 28 +++
 tests/bhyvexml2xmltest.c  |  1 +
 13 files changed, 129 insertions(+), 1 deletion(-)
 create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-vnc-resolution.args
 create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-vnc-resolution.xml
 create mode 100644 tests/bhyvexml2argvdata/bhyvexml2argv-vnc-resolution.args
 create mode 100644 tests/bhyvexml2argvdata/bhyvexml2argv-vnc-resolution.ldargs
 create mode 100644 tests/bhyvexml2argvdata/bhyvexml2argv-vnc-resolution.xml
 create mode 100644 tests/bhyvexml2xmloutdata/bhyvexml2xmlout-vnc-resolution.xml

diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
index 23eb029234..06bbbf7fea 100644
--- a/docs/formatdomain.html.in
+++ b/docs/formatdomain.html.in
@@ -7543,7 +7543,7 @@ qemu-kvm -net nic,model=? /dev/null
 element may also have an optional resolution sub-element.
 The resolution element has attributes x and
 y to set the minimum resolution for the video device. This
-sub-element is valid for model types "vga", "qxl", "bochs", and
+sub-element is valid for model types "vga", "qxl", "bochs", "gop", and
 "virtio".
 
   
diff --git a/docs/news.xml b/docs/news.xml
index 4cef804aac..d728dfa93c 100644
--- a/docs/news.xml
+++ b/docs/news.xml
@@ -44,6 +44,15 @@
 
   
 
+  
+
+  bhyve: support setting the framebuffer resolution
+
+
+  libvirt can now set the framebuffer's "w" and "h" parameters
+  using the resolution element.
+
+  
 
 
 
diff --git a/src/bhyve/bhyve_command.c b/src/bhyve/bhyve_command.c
index 5b1d80083a..db35cb9bd8 100644
--- a/src/bhyve/bhyve_command.c
+++ b/src/bhyve/bhyve_command.c
@@ -469,6 +469,9 @@ bhyveBuildGraphicsArgStr(const virDomainDef *def,
 goto error;
 }
 
+if (video->res)
+virBufferAsprintf(, ",w=%d,h=%d", video->res->x, video->res->y);
+
 if (video->driver)
 virBufferAsprintf(, ",vga=%s",
   
virDomainVideoVGAConfTypeToString(video->driver->vgaconf));
diff --git a/src/bhyve/bhyve_parse_command.c b/src/bhyve/bhyve_parse_command.c
index 39cce67ea9..0414cb1ef1 100644
--- a/src/bhyve/bhyve_parse_command.c
+++ b/src/bhyve/bhyve_parse_command.c
@@ -620,6 +620,26 @@ bhyveParsePCIFbuf(virDomainDefPtr def,
 if (virStrToLong_i(param, NULL, 10, >data.vnc.port))
 goto error;
 }
+
+if (STRPREFIX(param, "w=")) {
+param += strlen("w=");
+
+if (video->res == NULL)
+video->res = g_new0(virDomainVideoResolutionDef, 1);
+
+if (virStrToLong_uip(param, NULL, 10, >res->x))
+goto error;
+}
+
+if (STRPREFIX(param, "h=")) {
+param += strlen("h=");
+
+if (video->res == NULL)
+video->res = g_new0(virDomainVideoResolutionDef, 1);
+
+if (virStrToLong_uip(param, NULL, 10, >res->y))
+goto error;
+}
 }
 
  cleanup:
diff --git a/tests/bhyveargv2xmldata/bhyveargv2xml-vnc-resolution.args 
b/tests/bhyveargv2xmldata/bhyveargv2xml-vnc-resolution.args
new file mode 100644
index 00..e5e2c0f2e8
--- /dev/null
+++ b/tests/bhyveargv2xmldata/bhyveargv2xml-vnc-resolution.args
@@ -0,0 +1,10 @@
+/usr/sbin/bhyve \
+-c 1 \
+-m 214 \
+-u \
+-H \
+-P \
+-s 0:0,hostbridge \
+-l bootrom,/path/to/test.fd \
+-s 2:0,fbuf,tcp=127.0.0.1:5904,w=1920,h=1080 \
+-s 1,lpc bhyve
diff --git a/tests/bhyveargv2xmldata/bhyveargv2xml-vnc-resolution.xml 
b/tests/bhyveargv2xmldata/bhyveargv2xml-vnc-resolution.xml
new file mode 100644
index 00..f8fa0ed1ce
--- /dev/null
+++ b/tests/bhyveargv2xmldata/bhyveargv2xml-vnc-resolution.xml
@@ -0,0 +1,24 @@
+
+  bhyve
+  c7a5fdbd-edaf-9455-926a-d65c16db1809
+  219136
+  219136
+  1
+  
+hvm
+  
+  
+  destroy
+  destroy
+  destroy
+  
+
+  
+
+
+  
+
+  
+
+  
+
diff --git a/tests/bhyveargv2xmltest.c b/tests/bhyveargv2xmltest.c
index 

Re: [libvirt PATCH] cputest: Add data for AMD Ryzen 9 3900X 12-Core Processor

2020-05-06 Thread Michal Privoznik

On 5/6/20 2:22 PM, Jiri Denemark wrote:

Signed-off-by: Jiri Denemark 
---
  tests/cputest.c   |1 +
  ...4-cpuid-Ryzen-9-3900X-12-Core-disabled.xml |8 +
  ...64-cpuid-Ryzen-9-3900X-12-Core-enabled.xml |   10 +
  ...6_64-cpuid-Ryzen-9-3900X-12-Core-guest.xml |   28 +
  ...86_64-cpuid-Ryzen-9-3900X-12-Core-host.xml |   29 +
  ...86_64-cpuid-Ryzen-9-3900X-12-Core-json.xml |   24 +
  .../x86_64-cpuid-Ryzen-9-3900X-12-Core.json   | 1838 +
  .../x86_64-cpuid-Ryzen-9-3900X-12-Core.sig|4 +
  .../x86_64-cpuid-Ryzen-9-3900X-12-Core.xml|   66 +
  9 files changed, 2008 insertions(+)
  create mode 100644 
tests/cputestdata/x86_64-cpuid-Ryzen-9-3900X-12-Core-disabled.xml
  create mode 100644 
tests/cputestdata/x86_64-cpuid-Ryzen-9-3900X-12-Core-enabled.xml
  create mode 100644 
tests/cputestdata/x86_64-cpuid-Ryzen-9-3900X-12-Core-guest.xml
  create mode 100644 
tests/cputestdata/x86_64-cpuid-Ryzen-9-3900X-12-Core-host.xml
  create mode 100644 
tests/cputestdata/x86_64-cpuid-Ryzen-9-3900X-12-Core-json.xml
  create mode 100644 tests/cputestdata/x86_64-cpuid-Ryzen-9-3900X-12-Core.json
  create mode 100644 tests/cputestdata/x86_64-cpuid-Ryzen-9-3900X-12-Core.sig
  create mode 100644 tests/cputestdata/x86_64-cpuid-Ryzen-9-3900X-12-Core.xml


Reviewed-by: Michal Privoznik 

Michal



Re: [libvirt PATCH] tests: poison $HOME and $XDG_RUNTIME_DIR env variables

2020-05-06 Thread Michal Privoznik

On 5/4/20 4:39 PM, Daniel P. Berrangé wrote:

To attempt to catch unit tests which accidentally create files in $HOME,
or $XDG_RUNTIME_DIR, poison these env vars by pointing them to
directories which don't exist. This should give easier to debug test
failures. For example:

$ VIR_TEST_DEBUG=1 ./qemuhotplugtest
Could not initialize HostdevManager - operation failed: Failed to create state 
dir '/bad-test-used-env-xdg-runtime-dir/libvirt/hostdevmgr'

Signed-off-by: Daniel P. Berrangé 
---
  tests/testutils.c | 3 +++
  1 file changed, 3 insertions(+)



Reviewed-by: Michal Privoznik 

Michal



Re: [libvirt PATCH] docs: documented protected branches and tags

2020-05-06 Thread Daniel P . Berrangé
On Wed, May 06, 2020 at 03:02:07PM +0200, Andrea Bolognani wrote:
> On Wed, 2020-05-06 at 12:09 +0100, Daniel P. Berrangé wrote:
> > +* *Branch*: ``v*-maint``
> > +
> > +* *Allowed to merge*: Developers + Maintainers
> > +
> > +* *Allowed to push*: None (or Developers + Maintainers if MRs not used)
> > +
> > +* *Require approval from code owners*: disabled
> 
> These settings are the same for the master branch, no? So we could
> just use
> 
>   * *Branch*: ``master``, ``v*-maint``
> 
> instead of repeating the same instructions twice.

Sure, we can do that.


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



Re: [libvirt PATCH] tests: poison $HOME and $XDG_RUNTIME_DIR env variables

2020-05-06 Thread Andrea Bolognani
On Mon, 2020-05-04 at 15:39 +0100, Daniel P. Berrangé wrote:
> To attempt to catch unit tests which accidentally create files in $HOME,
> or $XDG_RUNTIME_DIR, poison these env vars by pointing them to
> directories which don't exist. This should give easier to debug test
> failures. For example:
> 
> $ VIR_TEST_DEBUG=1 ./qemuhotplugtest
> Could not initialize HostdevManager - operation failed: Failed to create 
> state dir '/bad-test-used-env-xdg-runtime-dir/libvirt/hostdevmgr'
> 
> Signed-off-by: Daniel P. Berrangé 
> ---
>  tests/testutils.c | 3 +++
>  1 file changed, 3 insertions(+)

This looks good, so

  Reviewed-by: Andrea Bolognani 

but please don't merge it until

  https://www.redhat.com/archives/libvir-list/2020-May/msg00212.html

is in or you'll break all builds :)

-- 
Andrea Bolognani / Red Hat / Virtualization



[libvirt PATCH] tests: Use qemu:///embed to simplify fakerootdir management

2020-05-06 Thread Andrea Bolognani
Now that the QEMU driver natively supports storing all its runtime
data inside an arbitrary directory, we can avoid having multiple
copies of this same logic in the test suite.

Signed-off-by: Andrea Bolognani 
---
 tests/qemuhotplugtest.c  | 15 --
 tests/qemumemlocktest.c  | 17 
 tests/qemuxml2argvtest.c | 16 ---
 tests/qemuxml2xmltest.c  | 16 ---
 tests/testutilsqemu.c| 43 ++--
 5 files changed, 15 insertions(+), 92 deletions(-)

diff --git a/tests/qemuhotplugtest.c b/tests/qemuhotplugtest.c
index 9a215ab303..e7443ff4b7 100644
--- a/tests/qemuhotplugtest.c
+++ b/tests/qemuhotplugtest.c
@@ -594,8 +594,6 @@ testQemuHotplugCpuIndividual(const void *opaque)
 return ret;
 }
 
-#define FAKEROOTDIRTEMPLATE abs_builddir "/fakerootdir-XX"
-
 
 static int
 mymain(void)
@@ -604,18 +602,8 @@ mymain(void)
 int ret = 0;
 struct qemuHotplugTestData data = {0};
 struct testQemuHotplugCpuParams cpudata;
-g_autofree char *fakerootdir = NULL;
 g_autoptr(virQEMUDriverConfig) cfg = NULL;
 
-fakerootdir = g_strdup(FAKEROOTDIRTEMPLATE);
-
-if (!g_mkdtemp(fakerootdir)) {
-fprintf(stderr, "Cannot create fakerootdir");
-abort();
-}
-
-g_setenv("LIBVIRT_FAKE_ROOT_DIR", fakerootdir, TRUE);
-
 if (qemuTestDriverInit() < 0)
 return EXIT_FAILURE;
 
@@ -891,9 +879,6 @@ mymain(void)
 DO_TEST_CPU_INDIVIDUAL("ppc64-modern-individual", "16-22", true, true, 
true);
 DO_TEST_CPU_INDIVIDUAL("ppc64-modern-individual", "17", true, true, true);
 
-if (getenv("LIBVIRT_SKIP_CLEANUP") == NULL)
-virFileDeleteTree(fakerootdir);
-
 qemuTestDriverFree();
 virObjectUnref(data.vm);
 return (ret == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
diff --git a/tests/qemumemlocktest.c b/tests/qemumemlocktest.c
index 3f18fed1c3..0e254bb3ce 100644
--- a/tests/qemumemlocktest.c
+++ b/tests/qemumemlocktest.c
@@ -51,26 +51,13 @@ testCompareMemLock(const void *data)
 return ret;
 }
 
-# define FAKEROOTDIRTEMPLATE abs_builddir "/fakerootdir-XX"
-
 static int
 mymain(void)
 {
 int ret = 0;
-char *fakerootdir;
 virQEMUCapsPtr qemuCaps = NULL;
 
-fakerootdir = g_strdup(FAKEROOTDIRTEMPLATE);
-
-if (!g_mkdtemp(fakerootdir)) {
-fprintf(stderr, "Cannot create fakerootdir");
-abort();
-}
-
-g_setenv("LIBVIRT_FAKE_ROOT_DIR", fakerootdir, TRUE);
-
 if (qemuTestDriverInit() < 0) {
-VIR_FREE(fakerootdir);
 return EXIT_FAILURE;
 }
 
@@ -150,11 +137,7 @@ mymain(void)
  cleanup:
 virObjectUnref(qemuCaps);
 
-if (getenv("LIBVIRT_SKIP_CLEANUP") == NULL)
-virFileDeleteTree(fakerootdir);
-
 qemuTestDriverFree();
-VIR_FREE(fakerootdir);
 
 return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
 }
diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
index 04febd1b0c..8bd6102d26 100644
--- a/tests/qemuxml2argvtest.c
+++ b/tests/qemuxml2argvtest.c
@@ -609,24 +609,12 @@ testInfoSetPaths(struct testQemuInfo *info,
 abs_srcdir, info->name, suffix ? suffix : 
"");
 }
 
-# define FAKEROOTDIRTEMPLATE abs_builddir "/fakerootdir-XX"
-
 static int
 mymain(void)
 {
 int ret = 0;
-char *fakerootdir;
 virHashTablePtr capslatest = NULL;
 
-fakerootdir = g_strdup(FAKEROOTDIRTEMPLATE);
-
-if (!g_mkdtemp(fakerootdir)) {
-fprintf(stderr, "Cannot create fakerootdir");
-abort();
-}
-
-g_setenv("LIBVIRT_FAKE_ROOT_DIR", fakerootdir, TRUE);
-
 /* Set the timezone because we are mocking the time() function.
  * If we don't do that, then localtime() may return unpredictable
  * results. In order to detect things that just work by a blind
@@ -3232,12 +3220,8 @@ mymain(void)
 
 DO_TEST_CAPS_LATEST("virtio-9p-multidevs");
 
-if (getenv("LIBVIRT_SKIP_CLEANUP") == NULL)
-virFileDeleteTree(fakerootdir);
-
 VIR_FREE(driver.config->nbdTLSx509certdir);
 qemuTestDriverFree();
-VIR_FREE(fakerootdir);
 virHashFree(capslatest);
 virFileWrapperClearPrefixes();
 
diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c
index 86f3d2c1f3..6a0adab603 100644
--- a/tests/qemuxml2xmltest.c
+++ b/tests/qemuxml2xmltest.c
@@ -126,13 +126,10 @@ testInfoSetStatusPaths(struct testQemuInfo *info)
 }
 
 
-# define FAKEROOTDIRTEMPLATE abs_builddir "/fakerootdir-XX"
-
 static int
 mymain(void)
 {
 int ret = 0;
-char *fakerootdir;
 virQEMUDriverConfigPtr cfg = NULL;
 virHashTablePtr capslatest = NULL;
 
@@ -140,15 +137,6 @@ mymain(void)
 if (!capslatest)
 return EXIT_FAILURE;
 
-fakerootdir = g_strdup(FAKEROOTDIRTEMPLATE);
-
-if (!g_mkdtemp(fakerootdir)) {
-fprintf(stderr, "Cannot create fakerootdir");
-abort();
-}
-
-g_setenv("LIBVIRT_FAKE_ROOT_DIR", fakerootdir, TRUE);
-
 /* Required for tpm-emulator tests
  */
 

Re: [libvirt PATCH] docs: documented protected branches and tags

2020-05-06 Thread Andrea Bolognani
On Wed, 2020-05-06 at 12:09 +0100, Daniel P. Berrangé wrote:
> +* *Branch*: ``v*-maint``
> +
> +* *Allowed to merge*: Developers + Maintainers
> +
> +* *Allowed to push*: None (or Developers + Maintainers if MRs not used)
> +
> +* *Require approval from code owners*: disabled

These settings are the same for the master branch, no? So we could
just use

  * *Branch*: ``master``, ``v*-maint``

instead of repeating the same instructions twice.


With that changed,

  Reviewed-by: Andrea Bolognani 

-- 
Andrea Bolognani / Red Hat / Virtualization



Re: [libvirt PATCH] tests: Mock virGetUserRuntimeDirectory() for qemuhotplug

2020-05-06 Thread Andrea Bolognani
On Mon, 2020-05-04 at 18:21 +0200, Andrea Bolognani wrote:
> On Mon, 2020-05-04 at 13:44 +0200, Michal Privoznik wrote:
> > On 5/1/20 2:30 PM, Andrea Bolognani wrote:
> > > +char *
> > > +virGetUserRuntimeDirectory(void)
> > > +{
> > > +return g_build_filename(g_getenv("LIBVIRT_FAKE_ROOT_DIR"),
> > > +"user-runtime-directory", NULL);
> > > +}
> > 
> > While the qemuhotplugtest is (currently) the only one that actually uses 
> > the runtimedir, this function is called basically from every qemu* test 
> > because (almost?) every qemu* test calls virQEMUDriverConfigNew(). 
> > Therefore I think we need to fix qemuTestDriverInit() too so that after 
> > it call ConfigNew() the path is replaced with some known value.
> 
> Good point! I'll look into making this more generic.

Unfortunately it's not possible to fix this the way you suggested,
because virHostdevManager attempts to create its state directory
during object allocation and so we can't just change it after the
fact.

I have, however, made the mock more generic and applied it to other
tests that use virHostdevManager[1]. That, along with Dan's patch
that poisons $HOME and $XDG_RUNTIME_DIR in the test suite, should be
enough to ensure more issues like this one don't sneak back in.


[1] https://www.redhat.com/archives/libvir-list/2020-May/msg00212.html
[2] https://www.redhat.com/archives/libvir-list/2020-May/msg00058.html
-- 
Andrea Bolognani / Red Hat / Virtualization



Re: [PATCH] qemuProcessStop: Reattach NVMe disks a domain is mirroring into

2020-05-06 Thread Peter Krempa
On Wed, May 06, 2020 at 14:41:36 +0200, Michal Privoznik wrote:
> In v5.10.0-rc1~42 (which was later fixed in v6.0.0-rc1~487) I am
> removing XATTRs for a file that QEMU is mirroring a disk into but
> it is killed meanwhile. Well, if we call
> qemuDomainStorageSourceAccessRevoke() instead of
> qemuBlockRemoveImageMetadata() then not only the file will have
> perms fixed (instead of left accessible to qemu) but if the
> mirror destination is not a file but a NVMe disk, then the disk
> will be reattached back to the host.
> 
> Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=1825785
> 
> Signed-off-by: Michal Privoznik 
> ---
>  src/qemu/qemu_process.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
> index 8ea470f75f..70c71e069c 100644
> --- a/src/qemu/qemu_process.c
> +++ b/src/qemu/qemu_process.c
> @@ -7605,7 +7605,7 @@ void qemuProcessStop(virQEMUDriverPtr driver,
>  virDomainDiskDefPtr disk = def->disks[i];
>  
>  if (disk->mirror)
> -qemuBlockRemoveImageMetadata(driver, vm, disk->dst, 
> disk->mirror);
> +qemuDomainStorageSourceAccessRevoke(driver, vm, 
> disk->mirror);

IMO this function is not designed to be called after the VM is dead.

Specifically this would try to tear down cgroup access which was removed
previously and would try to set memory locking limits using 'prlimit'
with -1 'pid'.

image locks are also lifted because of the qemu process has already
exitted.



[libvirt PATCH v2 1/1] tests: Introduce virhostdevmock

2020-05-06 Thread Andrea Bolognani
We need this for all tests that use virHostdevManager, because
during creation of this object for unprivileged connections
like those used in the test suite we would end up writing inside
the user's home directory.

That's bad manners in general, but when running the test suite
inside a purposefully constrained environment such as the one
exposed by pbuilder, it turns into an outright test failure:

  Could not initialize HostdevManager - operation failed: Failed
  to create state dir '/nonexistent/.cache/libvirt/hostdevmgr'

Signed-off-by: Andrea Bolognani 
---
 tests/Makefile.am   |  7 +++
 tests/qemuhotplugtest.c |  1 +
 tests/virhostdevmock.c  | 29 +
 tests/virhostdevtest.c  |  4 +++-
 4 files changed, 40 insertions(+), 1 deletion(-)
 create mode 100644 tests/virhostdevmock.c

diff --git a/tests/Makefile.am b/tests/Makefile.am
index ada5b8fc57..fc516376b4 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -212,6 +212,7 @@ test_libraries = libshunload.la \
libvirnetdaemonmock.la \
libvirnetserverclientmock.la \
libvircgroupmock.la \
+   libvirhostdevmock.la \
libvirpcimock.la \
libvirnetdevmock.la \
libvirrandommock.la \
@@ -1226,6 +1227,12 @@ libvirfilecachemock_la_SOURCES = \
 libvirfilecachemock_la_LDFLAGS = $(MOCKLIBS_LDFLAGS)
 libvirfilecachemock_la_LIBADD = $(MOCKLIBS_LIBS)
 
+libvirhostdevmock_la_SOURCES = \
+   virhostdevmock.c \
+   $(NULL)
+libvirhostdevmock_la_LDFLAGS = $(MOCKLIBS_LDFLAGS)
+libvirhostdevmock_la_LIBADD = $(MOCKLIBS_LIBS)
+
 if WITH_LINUX
 vircaps2xmltest_SOURCES = \
vircaps2xmltest.c testutils.h testutils.c virfilewrapper.h 
virfilewrapper.c
diff --git a/tests/qemuhotplugtest.c b/tests/qemuhotplugtest.c
index 9a215ab303..cf87de187f 100644
--- a/tests/qemuhotplugtest.c
+++ b/tests/qemuhotplugtest.c
@@ -900,6 +900,7 @@ mymain(void)
 }
 
 VIR_TEST_MAIN_PRELOAD(mymain,
+  VIR_TEST_MOCK("virhostdev"),
   VIR_TEST_MOCK("virpci"),
   VIR_TEST_MOCK("domaincaps"),
   VIR_TEST_MOCK("virprocess"),
diff --git a/tests/virhostdevmock.c b/tests/virhostdevmock.c
new file mode 100644
index 00..8658d9affd
--- /dev/null
+++ b/tests/virhostdevmock.c
@@ -0,0 +1,29 @@
+/*
+ * Copyright (C) 2020 Red Hat, Inc.
+ * SPDX-License-Identifier: LGPL-2.1-or-later
+ */
+
+#include 
+
+#include "virutil.h"
+#include "virmock.h"
+
+static char *(*real_virGetUserRuntimeDirectory)(void);
+
+static void
+init_syms(void)
+{
+if (real_virGetUserRuntimeDirectory)
+return;
+
+VIR_MOCK_REAL_INIT(virGetUserRuntimeDirectory);
+}
+
+char *
+virGetUserRuntimeDirectory(void)
+{
+init_syms();
+
+return g_build_filename(g_getenv("LIBVIRT_FAKE_ROOT_DIR"),
+"user-runtime-directory", NULL);
+}
diff --git a/tests/virhostdevtest.c b/tests/virhostdevtest.c
index b6260bd9c1..b0bad683a8 100644
--- a/tests/virhostdevtest.c
+++ b/tests/virhostdevtest.c
@@ -628,7 +628,9 @@ mymain(void)
 return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
 }
 
-VIR_TEST_MAIN_PRELOAD(mymain, VIR_TEST_MOCK("virpci"))
+VIR_TEST_MAIN_PRELOAD(mymain,
+  VIR_TEST_MOCK("virhostdev"),
+  VIR_TEST_MOCK("virpci"))
 #else
 int
 main(void)
-- 
2.25.4



[libvirt PATCH v2 0/1] tests: Introduce virhostdevmock

2020-05-06 Thread Andrea Bolognani
Changes from [v1]:

  * move function to a separate mock library;
  * load mock library for all tests that use virHostdevManager.

[v1] https://www.redhat.com/archives/libvir-list/2020-May/msg00020.html

Andrea Bolognani (1):
  tests: Introduce virhostdevmock

 tests/Makefile.am   |  7 +++
 tests/qemuhotplugtest.c |  1 +
 tests/virhostdevmock.c  | 29 +
 tests/virhostdevtest.c  |  4 +++-
 4 files changed, 40 insertions(+), 1 deletion(-)
 create mode 100644 tests/virhostdevmock.c

-- 
2.25.4




Re: [libvirt PATCH 0/3] tests: Update capabilities for QEMU 5.0.0

2020-05-06 Thread Michal Privoznik

On 5/6/20 11:43 AM, Andrea Bolognani wrote:

Now that QEMU 5.0.0 has been released, bring capabilities files for
non-x86 architectures up to date.

As usual, this series as posted to the mailing list is heavily
trimmed: for the unabridged version, fetch

   https://gitlab.com/abologna/libvirt caps-5.0.0

Andrea Bolognani (3):
   tests: Update capabilities for QEMU 5.0.0 on aarch64
   tests: Update capabilities for QEMU 5.0.0 on ppc64
   tests: Add capabilities for QEMU 5.0.0 on riscv64

  .../qemu_5.0.0-virt.aarch64.xml   |60 +-
  tests/domaincapsdata/qemu_5.0.0.aarch64.xml   |60 +-
  .../caps_5.0.0.aarch64.replies|  8937 ++---
  .../caps_5.0.0.aarch64.xml|   384 +-
  .../caps_5.0.0.ppc64.replies  |  2163 +-
  .../qemucapabilitiesdata/caps_5.0.0.ppc64.xml |15 +-
  ...h64.replies => caps_5.0.0.riscv64.replies} | 27491 +++-
  .../caps_5.0.0.riscv64.xml|   201 +
  ...default-video-type-ppc64.ppc64-latest.args | 2 +
  ...ory-hotplug-nvdimm-ppc64.ppc64-latest.args | 2 +
  ...ault-cpu-kvm-pseries-2.7.ppc64-latest.args | 4 +-
  ...ault-cpu-kvm-pseries-3.1.ppc64-latest.args | 4 +-
  ...ault-cpu-kvm-pseries-4.2.ppc64-latest.args | 4 +-
  ...ault-cpu-tcg-pseries-2.7.ppc64-latest.args | 2 +
  ...ault-cpu-tcg-pseries-3.1.ppc64-latest.args | 2 +
  ...ault-cpu-tcg-pseries-4.2.ppc64-latest.args | 2 +
  .../ppc64-pseries-graphics.ppc64-latest.args  | 2 +
  .../ppc64-pseries-headless.ppc64-latest.args  | 2 +
  .../riscv64-virt-graphics.riscv64-latest.args | 8 +-
  .../riscv64-virt-headless.riscv64-latest.args | 8 +-
  .../tpm-emulator-spapr.ppc64-latest.args  | 2 +
  ...fault-cpu-kvm-pseries-2.7.ppc64-latest.xml | 2 +-
  ...fault-cpu-kvm-pseries-3.1.ppc64-latest.xml | 2 +-
  ...fault-cpu-kvm-pseries-4.2.ppc64-latest.xml | 2 +-
  24 files changed, 19067 insertions(+), 20294 deletions(-)
  copy tests/qemucapabilitiesdata/{caps_5.0.0.aarch64.replies => 
caps_5.0.0.riscv64.replies} (78%)
  create mode 100644 tests/qemucapabilitiesdata/caps_5.0.0.riscv64.xml



Reviewed-by: Michal Privoznik 

Michal



[PATCH] qemuProcessStop: Reattach NVMe disks a domain is mirroring into

2020-05-06 Thread Michal Privoznik
In v5.10.0-rc1~42 (which was later fixed in v6.0.0-rc1~487) I am
removing XATTRs for a file that QEMU is mirroring a disk into but
it is killed meanwhile. Well, if we call
qemuDomainStorageSourceAccessRevoke() instead of
qemuBlockRemoveImageMetadata() then not only the file will have
perms fixed (instead of left accessible to qemu) but if the
mirror destination is not a file but a NVMe disk, then the disk
will be reattached back to the host.

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

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

diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index 8ea470f75f..70c71e069c 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -7605,7 +7605,7 @@ void qemuProcessStop(virQEMUDriverPtr driver,
 virDomainDiskDefPtr disk = def->disks[i];
 
 if (disk->mirror)
-qemuBlockRemoveImageMetadata(driver, vm, disk->dst, 
disk->mirror);
+qemuDomainStorageSourceAccessRevoke(driver, vm, disk->mirror);
 
 qemuBlockRemoveImageMetadata(driver, vm, disk->dst, disk->src);
 }
-- 
2.26.2



[libvirt PATCH] cputest: Add data for AMD Ryzen 9 3900X 12-Core Processor

2020-05-06 Thread Jiri Denemark
Signed-off-by: Jiri Denemark 
---
 tests/cputest.c   |1 +
 ...4-cpuid-Ryzen-9-3900X-12-Core-disabled.xml |8 +
 ...64-cpuid-Ryzen-9-3900X-12-Core-enabled.xml |   10 +
 ...6_64-cpuid-Ryzen-9-3900X-12-Core-guest.xml |   28 +
 ...86_64-cpuid-Ryzen-9-3900X-12-Core-host.xml |   29 +
 ...86_64-cpuid-Ryzen-9-3900X-12-Core-json.xml |   24 +
 .../x86_64-cpuid-Ryzen-9-3900X-12-Core.json   | 1838 +
 .../x86_64-cpuid-Ryzen-9-3900X-12-Core.sig|4 +
 .../x86_64-cpuid-Ryzen-9-3900X-12-Core.xml|   66 +
 9 files changed, 2008 insertions(+)
 create mode 100644 
tests/cputestdata/x86_64-cpuid-Ryzen-9-3900X-12-Core-disabled.xml
 create mode 100644 
tests/cputestdata/x86_64-cpuid-Ryzen-9-3900X-12-Core-enabled.xml
 create mode 100644 
tests/cputestdata/x86_64-cpuid-Ryzen-9-3900X-12-Core-guest.xml
 create mode 100644 
tests/cputestdata/x86_64-cpuid-Ryzen-9-3900X-12-Core-host.xml
 create mode 100644 
tests/cputestdata/x86_64-cpuid-Ryzen-9-3900X-12-Core-json.xml
 create mode 100644 tests/cputestdata/x86_64-cpuid-Ryzen-9-3900X-12-Core.json
 create mode 100644 tests/cputestdata/x86_64-cpuid-Ryzen-9-3900X-12-Core.sig
 create mode 100644 tests/cputestdata/x86_64-cpuid-Ryzen-9-3900X-12-Core.xml

diff --git a/tests/cputest.c b/tests/cputest.c
index 21f47a6853..2bef3eb52f 100644
--- a/tests/cputest.c
+++ b/tests/cputest.c
@@ -1252,6 +1252,7 @@ mymain(void)
 DO_TEST_CPUID(VIR_ARCH_X86_64, "Pentium-P6100", JSON_NONE);
 DO_TEST_CPUID(VIR_ARCH_X86_64, "Phenom-B95", JSON_HOST);
 DO_TEST_CPUID(VIR_ARCH_X86_64, "Ryzen-7-1800X-Eight-Core", JSON_HOST);
+DO_TEST_CPUID(VIR_ARCH_X86_64, "Ryzen-9-3900X-12-Core", JSON_MODELS);
 DO_TEST_CPUID(VIR_ARCH_X86_64, "Xeon-5110", JSON_NONE);
 DO_TEST_CPUID(VIR_ARCH_X86_64, "Xeon-E3-1225-v5", JSON_MODELS);
 DO_TEST_CPUID(VIR_ARCH_X86_64, "Xeon-E3-1245-v5", JSON_MODELS);
diff --git a/tests/cputestdata/x86_64-cpuid-Ryzen-9-3900X-12-Core-disabled.xml 
b/tests/cputestdata/x86_64-cpuid-Ryzen-9-3900X-12-Core-disabled.xml
new file mode 100644
index 00..7feb55f0b7
--- /dev/null
+++ b/tests/cputestdata/x86_64-cpuid-Ryzen-9-3900X-12-Core-disabled.xml
@@ -0,0 +1,8 @@
+
+
+  
+  
+  
+  
+  
+
diff --git a/tests/cputestdata/x86_64-cpuid-Ryzen-9-3900X-12-Core-enabled.xml 
b/tests/cputestdata/x86_64-cpuid-Ryzen-9-3900X-12-Core-enabled.xml
new file mode 100644
index 00..def2fed823
--- /dev/null
+++ b/tests/cputestdata/x86_64-cpuid-Ryzen-9-3900X-12-Core-enabled.xml
@@ -0,0 +1,10 @@
+
+
+  
+  
+  
+  
+  
+  
+  
+
diff --git a/tests/cputestdata/x86_64-cpuid-Ryzen-9-3900X-12-Core-guest.xml 
b/tests/cputestdata/x86_64-cpuid-Ryzen-9-3900X-12-Core-guest.xml
new file mode 100644
index 00..717e2fbfae
--- /dev/null
+++ b/tests/cputestdata/x86_64-cpuid-Ryzen-9-3900X-12-Core-guest.xml
@@ -0,0 +1,28 @@
+
+  EPYC-IBPB
+  AMD
+  
+  
+  
+  
+  
+  
+  
+  
+  
+  
+  
+  
+  
+  
+  
+  
+  
+  
+  
+  
+  
+  
+  
+  
+
diff --git a/tests/cputestdata/x86_64-cpuid-Ryzen-9-3900X-12-Core-host.xml 
b/tests/cputestdata/x86_64-cpuid-Ryzen-9-3900X-12-Core-host.xml
new file mode 100644
index 00..81930a84e7
--- /dev/null
+++ b/tests/cputestdata/x86_64-cpuid-Ryzen-9-3900X-12-Core-host.xml
@@ -0,0 +1,29 @@
+
+  x86_64
+  EPYC-IBPB
+  AMD
+  
+  
+  
+  
+  
+  
+  
+  
+  
+  
+  
+  
+  
+  
+  
+  
+  
+  
+  
+  
+  
+  
+  
+  
+
diff --git a/tests/cputestdata/x86_64-cpuid-Ryzen-9-3900X-12-Core-json.xml 
b/tests/cputestdata/x86_64-cpuid-Ryzen-9-3900X-12-Core-json.xml
new file mode 100644
index 00..5f495e0452
--- /dev/null
+++ b/tests/cputestdata/x86_64-cpuid-Ryzen-9-3900X-12-Core-json.xml
@@ -0,0 +1,24 @@
+
+  EPYC-IBPB
+  AMD
+  
+  
+  
+  
+  
+  
+  
+  
+  
+  
+  
+  
+  
+  
+  
+  
+  
+  
+  
+  
+
diff --git a/tests/cputestdata/x86_64-cpuid-Ryzen-9-3900X-12-Core.json 
b/tests/cputestdata/x86_64-cpuid-Ryzen-9-3900X-12-Core.json
new file mode 100644
index 00..fbdf1a794a
--- /dev/null
+++ b/tests/cputestdata/x86_64-cpuid-Ryzen-9-3900X-12-Core.json
@@ -0,0 +1,1838 @@
+{
+  "return": {
+"model": {
+  "name": "base",
+  "props": {
+"vmx-entry-load-rtit-ctl": false,
+"phys-bits": 0,
+"core-id": -1,
+"xlevel": 2147483679,
+"cmov": true,
+"ia64": false,
+"ssb-no": false,
+"aes": true,
+"vmx-apicv-xapic": false,
+"mmx": true,
+"arat": true,
+"rdpid": true,
+"vmx-page-walk-5": false,
+"vmx-page-walk-4": false,
+"vmx-desc-exit": false,
+"gfni": false,
+"ibrs-all": false,
+"pause-filter": false,
+"xsavec": true,
+"intel-pt": false,
+"vmx-cr8-store-exit": false,
+"hv-frequencies": false,
+"tsc-frequency": 0,
+"vmx-rdseed-exit": false,
+"xd": true,
+"x-intel-pt-auto-level": true,
+"hv-vendor-id": "",
+"vmx-eptp-switching": false,
+"kvm_asyncpf": true,
+

[PATCH 18/20] qemu: Handle cases when 'qomName' isn't present

2020-05-06 Thread Peter Krempa
Use the drive alias for all cases when we can't generate qomName. This
is meant to handle disks on 'sd' bus which are instantiated via -drive
if=sd as there isn't any specific QOM name for them.

Signed-off-by: Peter Krempa 
---
 src/qemu/qemu_driver.c  | 16 ++--
 src/qemu/qemu_process.c |  2 +-
 2 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index c7eb62f10d..1617f79d34 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -10892,7 +10892,7 @@ qemuDomainBlocksStatsGather(virQEMUDriverPtr driver,
 goto cleanup;
 }

-if (blockdev) {
+if (blockdev && QEMU_DOMAIN_DISK_PRIVATE(disk)->qomName) {
 entryname = QEMU_DOMAIN_DISK_PRIVATE(disk)->qomName;
 } else {
 if (!disk->info.alias) {
@@ -10948,7 +10948,7 @@ qemuDomainBlocksStatsGather(virQEMUDriverPtr driver,
 disk = vm->def->disks[i];
 entryname = disk->info.alias;

-if (blockdev)
+if (blockdev && QEMU_DOMAIN_DISK_PRIVATE(disk)->qomName)
 entryname = QEMU_DOMAIN_DISK_PRIVATE(disk)->qomName;

 if (!entryname)
@@ -19283,7 +19283,8 @@ qemuDomainSetBlockIoTune(virDomainPtr dom,
 if (!(disk = qemuDomainDiskByName(def, path)))
 goto endjob;

-if (virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_BLOCKDEV)) {
+if (virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_BLOCKDEV) &&
+QEMU_DOMAIN_DISK_PRIVATE(disk)->qomName) {
 qdevid = QEMU_DOMAIN_DISK_PRIVATE(disk)->qomName;
 } else {
 if (!(drivealias = qemuAliasDiskDriveFromDisk(disk)))
@@ -19473,7 +19474,8 @@ qemuDomainGetBlockIoTune(virDomainPtr dom,
 if (!(disk = qemuDomainDiskByName(def, path)))
 goto endjob;

-if (virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_BLOCKDEV)) {
+if (virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_BLOCKDEV) &&
+QEMU_DOMAIN_DISK_PRIVATE(disk)->qomName) {
 qdevid = QEMU_DOMAIN_DISK_PRIVATE(disk)->qomName;
 } else {
 if (!(drivealias = qemuAliasDiskDriveFromDisk(disk)))
@@ -19608,7 +19610,7 @@ qemuDomainGetDiskErrors(virDomainPtr dom,
 qemuDomainDiskPrivatePtr diskPriv = QEMU_DOMAIN_DISK_PRIVATE(disk);
 const char *entryname = disk->info.alias;

-if (blockdev)
+if (blockdev && diskPriv->qomName)
 entryname = diskPriv->qomName;

 if ((info = virHashLookup(table, entryname)) &&
@@ -21426,7 +21428,9 @@ qemuDomainGetStatsBlockExportDisk(virDomainDiskDefPtr 
disk,
 for (n = disk->src; virStorageSourceIsBacking(n); n = n->backingStore) {
 g_autofree char *alias = NULL;

-if (blockdev) {
+/* for 'sd' disks we won't be displaying stats for the backing chain
+ * as we don't update the stats correctly */
+if (blockdev && QEMU_DOMAIN_DISK_PRIVATE(disk)->qomName) {
 frontendalias = QEMU_DOMAIN_DISK_PRIVATE(disk)->qomName;
 backendalias = n->nodeformat;
 backendstoragealias = n->nodestorage;
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index 488ca91435..fe2ac2dcfe 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -7729,7 +7729,7 @@ qemuProcessRefreshDisks(virQEMUDriverPtr driver,
 struct qemuDomainDiskInfo *info;
 const char *entryname = disk->info.alias;

-if (blockdev)
+if (blockdev && diskpriv->qomName)
 entryname = diskpriv->qomName;

 if (!(info = virHashLookup(table, entryname)))
-- 
2.26.2



[PATCH 11/20] qemu: command: Remove 'virDomainDiskQEMUBus' enum converters

2020-05-06 Thread Peter Krempa
There are no users for the qemu-specific enum values. Remove it.

Signed-off-by: Peter Krempa 
---
 src/qemu/qemu_command.c | 15 ---
 1 file changed, 15 deletions(-)

diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 77f0d83054..07669ded44 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -73,21 +73,6 @@

 VIR_LOG_INIT("qemu.qemu_command");

-VIR_ENUM_DECL(virDomainDiskQEMUBus);
-VIR_ENUM_IMPL(virDomainDiskQEMUBus,
-  VIR_DOMAIN_DISK_BUS_LAST,
-  "ide",
-  "floppy",
-  "scsi",
-  "virtio",
-  "xen",
-  "usb",
-  "uml",
-  "sata",
-  "sd",
-);
-
-
 VIR_ENUM_DECL(qemuDiskCacheV2);

 VIR_ENUM_IMPL(qemuDiskCacheV2,
-- 
2.26.2



[PATCH 10/20] qemuBuildDiskDeviceStr: Use XML disk bus type names in error message

2020-05-06 Thread Peter Krempa
There's no point using the qemu-specific disk bus names in the error
message.

Signed-off-by: Peter Krempa 
---
 src/qemu/qemu_command.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 9836972234..77f0d83054 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -1581,7 +1581,6 @@ qemuBuildDiskDeviceStr(const virDomainDef *def,
virQEMUCapsPtr qemuCaps)
 {
 g_auto(virBuffer) opt = VIR_BUFFER_INITIALIZER;
-const char *bus = virDomainDiskQEMUBusTypeToString(disk->bus);
 const char *contAlias;
 g_autofree char *backendAlias = NULL;
 g_autofree char *scsiVPDDeviceId = NULL;
@@ -1838,7 +1837,8 @@ qemuBuildDiskDeviceStr(const virDomainDef *def,
 case VIR_DOMAIN_DISK_BUS_LAST:
 default:
 virReportError(VIR_ERR_INTERNAL_ERROR,
-   _("unsupported disk bus '%s' with device setup"), bus);
+   _("unsupported disk bus '%s' with device setup"),
+   NULLSTR(virDomainDiskBusTypeToString(disk->bus)));
 return NULL;
 }

-- 
2.26.2



[PATCH 05/20] qemu: Move disk config validation to qemuValidateDomainDeviceDefDiskFrontend

2020-05-06 Thread Peter Krempa
Previously we've validated it in qemuCheckDiskConfig which was directly
called from the command line generator. Move the checks to the validator
where they belong.

Signed-off-by: Peter Krempa 
---
 src/qemu/qemu_command.c  | 202 +-
 src/qemu/qemu_validate.c | 204 ++-
 tests/qemuxml2argvtest.c |   2 +-
 3 files changed, 205 insertions(+), 203 deletions(-)

diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 87cb78e350..2dfd17ad40 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -651,23 +651,6 @@ qemuBuildIoEventFdStr(virBufferPtr buf,
 return 0;
 }

-#define QEMU_SERIAL_PARAM_ACCEPTED_CHARS \
-  "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_ .+"
-
-static int
-qemuSafeSerialParamValue(const char *value)
-{
-if (strspn(value, QEMU_SERIAL_PARAM_ACCEPTED_CHARS) != strlen(value)) {
-virReportError(VIR_ERR_INTERNAL_ERROR,
-   _("driver serial '%s' contains unsafe characters"),
-   value);
-return -1;
-}
-
-return 0;
-}
-
-
 /**
  * qemuBuildSecretInfoProps:
  * @secinfo: pointer to the secret info object
@@ -1140,191 +1123,10 @@ qemuDiskConfigBlkdeviotuneEnabled(virDomainDiskDefPtr 
disk)
  * error reported.
  */
 int
-qemuCheckDiskConfig(virDomainDiskDefPtr disk,
+qemuCheckDiskConfig(virDomainDiskDefPtr disk G_GNUC_UNUSED,
 const virDomainDef *def G_GNUC_UNUSED,
-virQEMUCapsPtr qemuCaps)
+virQEMUCapsPtr qemuCaps G_GNUC_UNUSED)
 {
-if (disk->wwn) {
-if ((disk->bus != VIR_DOMAIN_DISK_BUS_IDE) &&
-(disk->bus != VIR_DOMAIN_DISK_BUS_SCSI)) {
-virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-   _("Only ide and scsi disk support wwn"));
-return -1;
-}
-}
-
-if ((disk->vendor || disk->product) &&
-disk->bus != VIR_DOMAIN_DISK_BUS_SCSI) {
-virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-   _("Only scsi disk supports vendor and product"));
-return -1;
-}
-
-if (disk->device == VIR_DOMAIN_DISK_DEVICE_LUN) {
-/* make sure that both the bus supports type='lun' (SG_IO). */
-if (disk->bus != VIR_DOMAIN_DISK_BUS_VIRTIO &&
-disk->bus != VIR_DOMAIN_DISK_BUS_SCSI) {
-virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-   _("disk device='lun' is not supported for 
bus='%s'"),
-   virDomainDiskBusTypeToString(disk->bus));
-return -1;
-}
-
-if (disk->bus == VIR_DOMAIN_DISK_BUS_SCSI &&
-disk->src->format != VIR_STORAGE_FILE_RAW) {
-virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-   _("disk device 'lun' using target 'scsi' must use "
- "'raw' format"));
-return -1;
-}
-
-if (qemuDomainDefValidateDiskLunSource(disk->src) < 0)
-return -1;
-
-if (disk->wwn) {
-virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-   _("Setting wwn is not supported for lun device"));
-return -1;
-}
-if (disk->vendor || disk->product) {
-virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-   _("Setting vendor or product is not supported "
- "for lun device"));
-return -1;
-}
-}
-
-switch (disk->bus) {
-case VIR_DOMAIN_DISK_BUS_SCSI:
-if (disk->info.type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_DRIVE) {
-virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-   _("unexpected address type for scsi disk"));
-return -1;
-}
-
-/* Setting bus= attr for SCSI drives, causes a controller
- * to be created. Yes this is slightly odd. It is not possible
- * to have > 1 bus on a SCSI controller (yet). */
-if (disk->info.addr.drive.bus != 0) {
-virReportError(VIR_ERR_INTERNAL_ERROR,
-   "%s", _("SCSI controller only supports 1 bus"));
-return -1;
-}
-break;
-
-case VIR_DOMAIN_DISK_BUS_IDE:
-if (disk->info.type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_DRIVE) {
-virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-   _("unexpected address type for ide disk"));
-return -1;
-}
-/* We can only have 1 IDE controller (currently) */
-if (disk->info.addr.drive.controller != 0) {
-virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-   _("Only 1 IDE controller is supported"));
-return -1;
-}
-break;
-
-case VIR_DOMAIN_DISK_BUS_FDC:
-if (disk->info.type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_DRIVE) {
-

[PATCH 17/20] qemu: Refuse blockjobs on disk bus='sd' with -blockdev

2020-05-06 Thread Peter Krempa
We still have to use -drive to instantiate sd disks. Combining that with
the new logic for blockjobs would be very complicated and not worth it
given that 'sd' cards work only on few rarely used machine types of
non-common architectures and libvirt didn't implement support for 'sd'
bus controllers. This will allow us to use -blockdev for other kinds on
such machines while sacrificing block jobs.

Note: this is currently no-op as we mask-out the QEMU_CAPS_BLOCKDEV
capability if any of the disks has bus='sd'.

Signed-off-by: Peter Krempa 
---
 src/qemu/qemu_backup.c |  3 +++
 src/qemu/qemu_checkpoint.c |  3 +++
 src/qemu/qemu_domain.c | 26 ++
 src/qemu/qemu_domain.h |  4 
 src/qemu/qemu_driver.c | 22 ++
 5 files changed, 54 insertions(+), 4 deletions(-)

diff --git a/src/qemu/qemu_backup.c b/src/qemu/qemu_backup.c
index 80fc5d77f8..b317b841cd 100644
--- a/src/qemu/qemu_backup.c
+++ b/src/qemu/qemu_backup.c
@@ -315,6 +315,9 @@ qemuBackupDiskPrepareDataOne(virDomainObjPtr vm,
 return -1;
 }

+if (!qemuDomainDiskBlockJobIsSupported(vm, dd->domdisk))
+return -1;
+
 if (!dd->store->format)
 dd->store->format = VIR_STORAGE_FILE_QCOW2;

diff --git a/src/qemu/qemu_checkpoint.c b/src/qemu/qemu_checkpoint.c
index 3f6aa36ef3..b71b4a7d14 100644
--- a/src/qemu/qemu_checkpoint.c
+++ b/src/qemu/qemu_checkpoint.c
@@ -445,6 +445,9 @@ qemuCheckpointPrepare(virQEMUDriverPtr driver,
vm->def->disks[i]->src->format));
 return -1;
 }
+
+if (!qemuDomainDiskBlockJobIsSupported(vm, vm->def->disks[i]))
+return -1;
 }

 return 0;
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 01f2792401..395cc3daee 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -13620,3 +13620,29 @@ 
qemuDomainInitializePflashStorageSource(virDomainObjPtr vm)

 return 0;
 }
+
+
+/**
+ * qemuDomainDiskBlockJobIsSupported:
+ *
+ * Returns true if block jobs are supported on @disk by @vm or false and 
reports
+ * an error otherwise.
+ *
+ * Note that this does not verify whether other block jobs are running etc.
+ */
+bool
+qemuDomainDiskBlockJobIsSupported(virDomainObjPtr vm,
+  virDomainDiskDefPtr disk)
+{
+qemuDomainObjPrivatePtr priv = vm->privateData;
+
+if (virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_BLOCKDEV) &&
+qemuDiskBusIsSD(disk->bus)) {
+virReportError(VIR_ERR_OPERATION_UNSUPPORTED,
+   _("block jobs are not supported on disk '%s' using bus 
'sd'"),
+   disk->dst);
+return false;
+}
+
+return true;
+}
diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h
index ea0fce64a8..41d3f1561d 100644
--- a/src/qemu/qemu_domain.h
+++ b/src/qemu/qemu_domain.h
@@ -1293,3 +1293,7 @@ qemuDomainMakeCPUMigratable(virCPUDefPtr cpu);

 int
 qemuDomainInitializePflashStorageSource(virDomainObjPtr vm);
+
+bool
+qemuDomainDiskBlockJobIsSupported(virDomainObjPtr vm,
+  virDomainDiskDefPtr disk);
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index cb0373bf76..c7eb62f10d 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -14603,7 +14603,8 @@ 
qemuDomainSnapshotPrepareDiskExternalInactive(virDomainSnapshotDiskDefPtr snapdi


 static int
-qemuDomainSnapshotPrepareDiskExternalActive(virDomainSnapshotDiskDefPtr 
snapdisk,
+qemuDomainSnapshotPrepareDiskExternalActive(virDomainObjPtr vm,
+virDomainSnapshotDiskDefPtr 
snapdisk,
 virDomainDiskDefPtr domdisk,
 bool blockdev)
 {
@@ -14616,6 +14617,9 @@ 
qemuDomainSnapshotPrepareDiskExternalActive(virDomainSnapshotDiskDefPtr snapdisk
 return -1;
 }

+if (!qemuDomainDiskBlockJobIsSupported(vm, domdisk))
+return -1;
+
 switch ((virStorageType)actualType) {
 case VIR_STORAGE_TYPE_BLOCK:
 case VIR_STORAGE_TYPE_FILE:
@@ -14671,7 +14675,8 @@ 
qemuDomainSnapshotPrepareDiskExternalActive(virDomainSnapshotDiskDefPtr snapdisk


 static int
-qemuDomainSnapshotPrepareDiskExternal(virDomainDiskDefPtr disk,
+qemuDomainSnapshotPrepareDiskExternal(virDomainObjPtr vm,
+  virDomainDiskDefPtr disk,
   virDomainSnapshotDiskDefPtr snapdisk,
   bool active,
   bool reuse,
@@ -14698,7 +14703,7 @@ 
qemuDomainSnapshotPrepareDiskExternal(virDomainDiskDefPtr disk,
 if (qemuDomainSnapshotPrepareDiskExternalInactive(snapdisk, disk) < 0)
 return -1;
 } else {
-if (qemuDomainSnapshotPrepareDiskExternalActive(snapdisk, disk, 
blockdev) < 0)
+if (qemuDomainSnapshotPrepareDiskExternalActive(vm, snapdisk, disk, 
blockdev) < 0)
  

[PATCH 19/20] qemu: Prepare for 'sd' card use together with blockdev

2020-05-06 Thread Peter Krempa
SD cards need to be instantiated via -drive if=sd. This means that all
cases where we use the blockdev path need to be special-cased for SD
cards.

Note that at this point QEMU_CAPS_BLOCKDEV is still cleared if the VM
config has a SD card.

Signed-off-by: Peter Krempa 
---
 src/qemu/qemu_command.c  |  3 ++-
 src/qemu/qemu_domain.c   | 13 +
 src/qemu/qemu_driver.c   |  3 ++-
 src/qemu/qemu_hotplug.c  |  3 ++-
 src/qemu/qemu_process.c  |  6 +-
 src/qemu/qemu_validate.c |  4 +++-
 6 files changed, 23 insertions(+), 9 deletions(-)

diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 07669ded44..5b803f106b 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -2089,7 +2089,8 @@ qemuBuildDiskSourceCommandLine(virCommandPtr cmd,
 g_autofree char *copyOnReadPropsStr = NULL;
 size_t i;

-if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_BLOCKDEV)) {
+if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_BLOCKDEV) &&
+!qemuDiskBusIsSD(disk->bus)) {
 if (virStorageSourceIsEmpty(disk->src))
 return 0;

diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 395cc3daee..0c122f300d 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -8216,6 +8216,8 @@ qemuDomainDetermineDiskChain(virQEMUDriverPtr driver,
 virStorageSourcePtr src; /* iterator for the backing chain declared in XML 
*/
 virStorageSourcePtr n; /* iterator for the backing chain detected from 
disk */
 qemuDomainObjPrivatePtr priv = vm->privateData;
+bool blockdev = virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_BLOCKDEV);
+bool isSD = qemuDiskBusIsSD(disk->bus);
 uid_t uid;
 gid_t gid;

@@ -8298,13 +8300,14 @@ qemuDomainDetermineDiskChain(virQEMUDriverPtr driver,
 if (n->format == VIR_STORAGE_FILE_ISO)
 n->format = VIR_STORAGE_FILE_RAW;

-if (qemuDomainValidateStorageSource(n, priv->qemuCaps, false) < 0)
+/* mask-out blockdev for 'sd' disks */
+if (qemuDomainValidateStorageSource(n, priv->qemuCaps, isSD) < 0)
 return -1;

 qemuDomainPrepareStorageSourceConfig(n, cfg, priv->qemuCaps);
 qemuDomainPrepareDiskSourceData(disk, n);

-if (virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_BLOCKDEV) &&
+if (blockdev && !isSD &&
 qemuDomainPrepareStorageSourceBlockdev(disk, n, priv, cfg) < 0)
 return -1;
 }
@@ -8362,7 +8365,8 @@ qemuDomainDiskGetBackendAlias(virDomainDiskDefPtr disk,
 {
 *backendAlias = NULL;

-if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_BLOCKDEV)) {
+if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_BLOCKDEV) ||
+qemuDiskBusIsSD(disk->bus)) {
 if (!(*backendAlias = qemuAliasDiskDriveFromDisk(disk)))
 return -1;

@@ -13238,7 +13242,8 @@ qemuDomainPrepareDiskSource(virDomainDiskDefPtr disk,
 disk->src->format = VIR_STORAGE_FILE_RAW;
 }

-if (virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_BLOCKDEV)) {
+if (virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_BLOCKDEV) &&
+!qemuDiskBusIsSD(disk->bus)) {
 if (qemuDomainPrepareDiskSourceBlockdev(disk, priv, cfg) < 0)
 return -1;
 } else {
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 1617f79d34..63b4a49c3c 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -10808,7 +10808,8 @@ qemuDomainBlockResize(virDomainPtr dom,
 disk->src->format == VIR_STORAGE_FILE_QED)
 size = VIR_ROUND_UP(size, 512);

-if (virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_BLOCKDEV)) {
+if (virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_BLOCKDEV) &&
+!qemuDiskBusIsSD(disk->bus)) {
 if (virStorageSourceIsEmpty(disk->src) || disk->src->readonly) {
 virReportError(VIR_ERR_OPERATION_UNSUPPORTED,
_("can't resize empty or readonly disk '%s'"),
diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index f1b2fbb1a8..ab5a7aef84 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -4270,7 +4270,8 @@ qemuDomainRemoveDiskDevice(virQEMUDriverPtr driver,
   disk->info.alias, vm, vm->def->name);


-if (blockdev) {
+if (blockdev &&
+!qemuDiskBusIsSD(disk->bus)) {
 corAlias = g_strdup(diskPriv->nodeCopyOnRead);

 if (diskPriv->blockjob) {
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index fe2ac2dcfe..b1751d4b52 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -6405,7 +6405,7 @@ qemuProcessPrepareHostStorage(virQEMUDriverPtr driver,
 continue;

 /* backing chain needs to be redetected if we aren't using blockdev */
-if (!blockdev)
+if (!blockdev || qemuDiskBusIsSD(disk->bus))
 virStorageSourceBackingStoreClear(disk->src);

 /*
@@ -6634,6 +6634,10 @@ qemuProcessSetupDiskThrottlingBlockdev(virQEMUDriverPtr 
driver,
 virDomainDiskDefPtr disk = vm->def->disks[i];
 qemuDomainDiskPrivatePtr 

[PATCH 01/20] qemuxml2(argv|xml): Modernize 'blkdeviotune' tests

2020-05-06 Thread Peter Krempa
Move the tests to DO_TEST_CAPS_LATEST. Since switch to blockdev stopped
us formatting the tunning parameters on the command line let's also add
version cases for qemu-4.1 data which doesn't enable blockdev.

Signed-off-by: Peter Krempa 
---
 ... blkdeviotune-group-num.x86_64-4.1.0.args} | 26 ++
 .../blkdeviotune-group-num.x86_64-latest.args | 50 +++
 .../blkdeviotune-group-num.xml|  5 +-
 ...blkdeviotune-max-length.x86_64-4.1.0.args} | 26 ++
 ...blkdeviotune-max-length.x86_64-latest.args | 50 +++
 .../blkdeviotune-max-length.xml   |  5 +-
 ...rgs => blkdeviotune-max.x86_64-4.1.0.args} | 26 ++
 .../blkdeviotune-max.x86_64-latest.args   | 50 +++
 tests/qemuxml2argvdata/blkdeviotune-max.xml   |  5 +-
 tests/qemuxml2argvtest.c  | 14 +++---
 ... blkdeviotune-group-num.x86_64-latest.xml} |  0
 ...blkdeviotune-max-length.x86_64-latest.xml} |  0
 ...xml => blkdeviotune-max.x86_64-latest.xml} |  0
 ...une.xml => blkdeviotune.x86_64-latest.xml} |  7 ++-
 tests/qemuxml2xmltest.c   |  8 +--
 15 files changed, 228 insertions(+), 44 deletions(-)
 rename tests/qemuxml2argvdata/{blkdeviotune-group-num.args => 
blkdeviotune-group-num.x86_64-4.1.0.args} (69%)
 create mode 100644 
tests/qemuxml2argvdata/blkdeviotune-group-num.x86_64-latest.args
 rename tests/qemuxml2argvdata/{blkdeviotune-max-length.args => 
blkdeviotune-max-length.x86_64-4.1.0.args} (71%)
 create mode 100644 
tests/qemuxml2argvdata/blkdeviotune-max-length.x86_64-latest.args
 rename tests/qemuxml2argvdata/{blkdeviotune-max.args => 
blkdeviotune-max.x86_64-4.1.0.args} (67%)
 create mode 100644 tests/qemuxml2argvdata/blkdeviotune-max.x86_64-latest.args
 rename tests/qemuxml2xmloutdata/{blkdeviotune-group-num.xml => 
blkdeviotune-group-num.x86_64-latest.xml} (100%)
 rename tests/qemuxml2xmloutdata/{blkdeviotune-max-length.xml => 
blkdeviotune-max-length.x86_64-latest.xml} (100%)
 rename tests/qemuxml2xmloutdata/{blkdeviotune-max.xml => 
blkdeviotune-max.x86_64-latest.xml} (100%)
 rename tests/qemuxml2xmloutdata/{blkdeviotune.xml => 
blkdeviotune.x86_64-latest.xml} (88%)

diff --git a/tests/qemuxml2argvdata/blkdeviotune-group-num.args 
b/tests/qemuxml2argvdata/blkdeviotune-group-num.x86_64-4.1.0.args
similarity index 69%
rename from tests/qemuxml2argvdata/blkdeviotune-group-num.args
rename to tests/qemuxml2argvdata/blkdeviotune-group-num.x86_64-4.1.0.args
index dfa7155b1e..8aa4c2be7d 100644
--- a/tests/qemuxml2argvdata/blkdeviotune-group-num.args
+++ b/tests/qemuxml2argvdata/blkdeviotune-group-num.x86_64-4.1.0.args
@@ -8,33 +8,41 @@ XDG_CACHE_HOME=/tmp/lib/domain--1-QEMUGuest1/.cache \
 XDG_CONFIG_HOME=/tmp/lib/domain--1-QEMUGuest1/.config \
 QEMU_AUDIO_DRV=none \
 /usr/bin/qemu-system-i386 \
--name QEMUGuest1 \
+-name guest=QEMUGuest1,debug-threads=on \
 -S \
--machine pc,accel=tcg,usb=off,dump-guest-core=off \
+-object secret,id=masterKey0,format=raw,\
+file=/tmp/lib/domain--1-QEMUGuest1/master-key.aes \
+-machine pc-i440fx-4.1,accel=tcg,usb=off,dump-guest-core=off \
+-cpu qemu64 \
 -m 214 \
--realtime mlock=off \
+-overcommit mem-lock=off \
 -smp 1,sockets=1,cores=1,threads=1 \
 -uuid c7a5fdbd-edaf-9455-926a-d65c16db1809 \
 -display none \
 -no-user-config \
 -nodefaults \
--chardev 
socket,id=charmonitor,path=/tmp/lib/domain--1-QEMUGuest1/monitor.sock,\
-server,nowait \
+-chardev socket,id=charmonitor,fd=1729,server,nowait \
 -mon chardev=charmonitor,id=monitor,mode=control \
 -rtc base=utc \
 -no-shutdown \
 -no-acpi \
--usb \
+-boot strict=on \
+-device piix3-usb-uhci,id=usb,bus=pci.0,addr=0x1.0x2 \
 -drive file=/dev/HostVG/QEMUGuest1,format=qcow2,if=none,id=drive-ide0-0-0,\
 cache=none,throttling.bps-total=5000,throttling.iops-total=6000,\
 throttling.bps-total-max=1,throttling.iops-total-max=11000,\
 throttling.group=libvirt_iotune_group1 \
--device ide-hd,bus=ide.0,unit=0,drive=drive-ide0-0-0,id=ide0-0-0,bootindex=1 \
+-device ide-hd,bus=ide.0,unit=0,drive=drive-ide0-0-0,id=ide0-0-0,bootindex=1,\
+write-cache=on \
 -drive file=/dev/HostVG/QEMUGuest2,format=qcow2,if=none,id=drive-ide0-0-1,\
 cache=none,throttling.bps-read=5000,throttling.bps-write=5500,\
 throttling.iops-read=3500,throttling.iops-write=4000,\
 throttling.bps-read-max=6000,throttling.bps-write-max=6500,\
 throttling.iops-read-max=7000,throttling.iops-write-max=7500,\
 throttling.iops-size=2000,throttling.group=libvirt_iotune_group2 \
--device ide-hd,bus=ide.0,unit=1,drive=drive-ide0-0-1,id=ide0-0-1 \
--device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x3
+-device ide-hd,bus=ide.0,unit=1,drive=drive-ide0-0-1,id=ide0-0-1,\
+write-cache=on \
+-device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x3 \
+-sandbox on,obsolete=deny,elevateprivileges=deny,spawn=deny,\
+resourcecontrol=deny \
+-msg timestamp=on
diff --git a/tests/qemuxml2argvdata/blkdeviotune-group-num.x86_64-latest.args 

[PATCH 00/20] qemu: Remove one of last two instances of -drive if=none usage

2020-05-06 Thread Peter Krempa
QEMU want's to deprecate -drive if=none. Stop clearing
QEMU_CAPS_BLOCKDEV when SD cards are used. Please see 17/20 and 20/20
for more explanation.

Obviously few cleanups snuck in as well.

Peter Krempa (20):
  qemuxml2(argv|xml): Modernize 'blkdeviotune' tests
  qemuxml2(argv|xml): Modernize 'discard'/'detect-zero' tests
  qemuValidateDomainDeviceDefDisk: Separate disk frontend config
validation
  qemu: validate: Validate blkdeviotune settings in the validator
  qemu: Move disk config validation to
qemuValidateDomainDeviceDefDiskFrontend
  qemuCheckDiskConfig: Remove and untangle callers
  qemu: Rename qemuDiskBusNeedsDriveArg to qemuDiskBusIsSD
  qemuBuildDiskCommandLine: Clarify logic around building -device for
disks
  qemuBuildDriveStr: Refactor formatting of command line for 'sd' cards
  qemuBuildDiskDeviceStr: Use XML disk bus type names in error message
  qemu: command: Remove 'virDomainDiskQEMUBus' enum converters
  qemuDomainSetBlockThreshold: Call qemuBlockNodeNamesDetect only
without blockdev
  qemuDomainValidateStorageSource: Extract check for BLOCKDEV capability
  qemuDomainValidateStorageSource: Allow masking out blockdev support
  tests: Add tests for a virtio and sd disk in a single machine
  qemu: Forbid 'cdrom' on 'sd' bus
  qemu: Refuse blockjobs on disk bus='sd' with -blockdev
  qemu: Handle cases when 'qomName' isn't present
  qemu: Prepare for 'sd' card use together with blockdev
  qemu: process: Don't clear QEMU_CAPS_BLOCKDEV when SD card is present

 src/qemu/qemu_backup.c|   3 +
 src/qemu/qemu_checkpoint.c|   3 +
 src/qemu/qemu_command.c   | 404 ++
 src/qemu/qemu_command.h   |   7 +-
 src/qemu/qemu_domain.c|  65 ++-
 src/qemu/qemu_domain.h|   7 +-
 src/qemu/qemu_driver.c|  46 +-
 src/qemu/qemu_hotplug.c   |   7 +-
 src/qemu/qemu_process.c   |  17 +-
 src/qemu/qemu_validate.c  | 383 +++--
 src/qemu/qemu_validate.h  |   1 +
 tests/qemublocktest.c |   7 +-
 ... blkdeviotune-group-num.x86_64-4.1.0.args} |  26 +-
 .../blkdeviotune-group-num.x86_64-latest.args |  50 +++
 .../blkdeviotune-group-num.xml|   5 +-
 ...blkdeviotune-max-length.x86_64-4.1.0.args} |  26 +-
 ...blkdeviotune-max-length.x86_64-latest.args |  50 +++
 .../blkdeviotune-max-length.xml   |   5 +-
 ...rgs => blkdeviotune-max.x86_64-4.1.0.args} |  26 +-
 .../blkdeviotune-max.x86_64-latest.args   |  50 +++
 tests/qemuxml2argvdata/blkdeviotune-max.xml   |   5 +-
 .../disk-arm-virtio-sd.aarch64-4.0.0.args |  39 ++
 .../disk-arm-virtio-sd.aarch64-latest.args|  43 ++
 tests/qemuxml2argvdata/disk-arm-virtio-sd.xml |  36 ++
 .../disk-cdrom-bus-other.x86_64-latest.args   |  13 +-
 .../qemuxml2argvdata/disk-cdrom-bus-other.xml |  11 -
 .../disk-detect-zeroes.x86_64-2.12.0.args |   1 +
 tests/qemuxml2argvdata/disk-detect-zeroes.xml |   5 +-
 ...rd.args => disk-discard.x86_64-4.1.0.args} |  22 +-
 .../disk-discard.x86_64-latest.args   |  46 ++
 tests/qemuxml2argvtest.c  |  26 +-
 ... blkdeviotune-group-num.x86_64-latest.xml} |   0
 ...blkdeviotune-max-length.x86_64-latest.xml} |   0
 ...xml => blkdeviotune-max.x86_64-latest.xml} |   0
 ...une.xml => blkdeviotune.x86_64-latest.xml} |   7 +-
 .../disk-arm-virtio-sd.aarch64-latest.xml |  41 ++
 .../disk-cdrom-bus-other.xml  |  11 -
 ...l => disk-detect-zeroes.x86_64-latest.xml} |   0
 ...ard.xml => disk-discard.x86_64-latest.xml} |   7 +-
 tests/qemuxml2xmltest.c   |  14 +-
 40 files changed, 958 insertions(+), 557 deletions(-)
 rename tests/qemuxml2argvdata/{blkdeviotune-group-num.args => 
blkdeviotune-group-num.x86_64-4.1.0.args} (69%)
 create mode 100644 
tests/qemuxml2argvdata/blkdeviotune-group-num.x86_64-latest.args
 rename tests/qemuxml2argvdata/{blkdeviotune-max-length.args => 
blkdeviotune-max-length.x86_64-4.1.0.args} (71%)
 create mode 100644 
tests/qemuxml2argvdata/blkdeviotune-max-length.x86_64-latest.args
 rename tests/qemuxml2argvdata/{blkdeviotune-max.args => 
blkdeviotune-max.x86_64-4.1.0.args} (67%)
 create mode 100644 tests/qemuxml2argvdata/blkdeviotune-max.x86_64-latest.args
 create mode 100644 tests/qemuxml2argvdata/disk-arm-virtio-sd.aarch64-4.0.0.args
 create mode 100644 
tests/qemuxml2argvdata/disk-arm-virtio-sd.aarch64-latest.args
 create mode 100644 tests/qemuxml2argvdata/disk-arm-virtio-sd.xml
 rename tests/qemuxml2argvdata/{disk-discard.args => 
disk-discard.x86_64-4.1.0.args} (59%)
 create mode 100644 tests/qemuxml2argvdata/disk-discard.x86_64-latest.args
 rename tests/qemuxml2xmloutdata/{blkdeviotune-group-num.xml => 
blkdeviotune-group-num.x86_64-latest.xml} (100%)
 rename tests/qemuxml2xmloutdata/{blkdeviotune-max-length.xml => 

[PATCH 12/20] qemuDomainSetBlockThreshold: Call qemuBlockNodeNamesDetect only without blockdev

2020-05-06 Thread Peter Krempa
Make sure that we don't try to reload node names with -blockdev. If
something doesn't have a node name the update will not make the
situation better.

Signed-off-by: Peter Krempa 
---
 src/qemu/qemu_driver.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index c5e6cab817..cb0373bf76 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -22597,7 +22597,8 @@ qemuDomainSetBlockThreshold(virDomainPtr dom,
 if (!(src = qemuDomainGetStorageSourceByDevstr(dev, vm->def)))
 goto endjob;

-if (!src->nodestorage &&
+if (!virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_BLOCKDEV) &&
+!src->nodestorage &&
 qemuBlockNodeNamesDetect(driver, vm, QEMU_ASYNC_JOB_NONE) < 0)
 goto endjob;

-- 
2.26.2



[PATCH 02/20] qemuxml2(argv|xml): Modernize 'discard'/'detect-zero' tests

2020-05-06 Thread Peter Krempa
Switch to DO_TEST_CAPS_LATEST for all of them and also add pre-blockdev
case for 'disk-discard' as we had it before.

Signed-off-by: Peter Krempa 
---
 .../disk-detect-zeroes.x86_64-2.12.0.args |  1 +
 tests/qemuxml2argvdata/disk-detect-zeroes.xml |  5 +-
 ...rd.args => disk-discard.x86_64-4.1.0.args} | 22 +
 .../disk-discard.x86_64-latest.args   | 46 +++
 tests/qemuxml2argvtest.c  |  7 +--
 ...l => disk-detect-zeroes.x86_64-latest.xml} |  0
 ...ard.xml => disk-discard.x86_64-latest.xml} |  7 ++-
 tests/qemuxml2xmltest.c   |  4 +-
 8 files changed, 73 insertions(+), 19 deletions(-)
 rename tests/qemuxml2argvdata/{disk-discard.args => 
disk-discard.x86_64-4.1.0.args} (59%)
 create mode 100644 tests/qemuxml2argvdata/disk-discard.x86_64-latest.args
 rename tests/qemuxml2xmloutdata/{disk-detect-zeroes.xml => 
disk-detect-zeroes.x86_64-latest.xml} (100%)
 rename tests/qemuxml2xmloutdata/{disk-discard.xml => 
disk-discard.x86_64-latest.xml} (87%)

diff --git a/tests/qemuxml2argvdata/disk-detect-zeroes.x86_64-2.12.0.args 
b/tests/qemuxml2argvdata/disk-detect-zeroes.x86_64-2.12.0.args
index 1da46d8987..090cccdb5c 100644
--- a/tests/qemuxml2argvdata/disk-detect-zeroes.x86_64-2.12.0.args
+++ b/tests/qemuxml2argvdata/disk-detect-zeroes.x86_64-2.12.0.args
@@ -13,6 +13,7 @@ QEMU_AUDIO_DRV=none \
 -object secret,id=masterKey0,format=raw,\
 file=/tmp/lib/domain--1-test/master-key.aes \
 -machine pc-i440fx-2.12,accel=tcg,usb=off,dump-guest-core=off \
+-cpu qemu64 \
 -m 1024 \
 -realtime mlock=off \
 -smp 1,sockets=1,cores=1,threads=1 \
diff --git a/tests/qemuxml2argvdata/disk-detect-zeroes.xml 
b/tests/qemuxml2argvdata/disk-detect-zeroes.xml
index d1ae37b81b..851077545e 100644
--- a/tests/qemuxml2argvdata/disk-detect-zeroes.xml
+++ b/tests/qemuxml2argvdata/disk-detect-zeroes.xml
@@ -10,6 +10,9 @@
 
 
   
+  
+qemu64
+  
   
   destroy
   restart
@@ -29,7 +32,7 @@
   
   
 
-
+
   
 
 
diff --git a/tests/qemuxml2argvdata/disk-discard.args 
b/tests/qemuxml2argvdata/disk-discard.x86_64-4.1.0.args
similarity index 59%
rename from tests/qemuxml2argvdata/disk-discard.args
rename to tests/qemuxml2argvdata/disk-discard.x86_64-4.1.0.args
index 163b1b0df2..4437922eee 100644
--- a/tests/qemuxml2argvdata/disk-discard.args
+++ b/tests/qemuxml2argvdata/disk-discard.x86_64-4.1.0.args
@@ -8,29 +8,33 @@ XDG_CACHE_HOME=/tmp/lib/domain--1-test/.cache \
 XDG_CONFIG_HOME=/tmp/lib/domain--1-test/.config \
 QEMU_AUDIO_DRV=none \
 /usr/bin/qemu-system-x86_64 \
--name test \
+-name guest=test,debug-threads=on \
 -S \
--machine pc,accel=tcg,usb=off,dump-guest-core=off \
+-object secret,id=masterKey0,format=raw,\
+file=/tmp/lib/domain--1-test/master-key.aes \
+-machine pc-i440fx-4.1,accel=tcg,usb=off,dump-guest-core=off \
 -m 1024 \
--realtime mlock=off \
+-overcommit mem-lock=off \
 -smp 1,sockets=1,cores=1,threads=1 \
 -uuid 92d7a226-cfae-425b-a6d3-00bbf9ec5c9e \
 -display none \
 -no-user-config \
 -nodefaults \
--chardev socket,id=charmonitor,path=/tmp/lib/domain--1-test/monitor.sock,\
-server,nowait \
+-chardev socket,id=charmonitor,fd=1729,server,nowait \
 -mon chardev=charmonitor,id=monitor,mode=control \
 -rtc base=utc \
 -no-shutdown \
 -no-acpi \
--boot menu=on \
--usb \
+-boot menu=on,strict=on \
+-device piix3-usb-uhci,id=usb,bus=pci.0,addr=0x1.0x2 \
 -drive file=/var/lib/libvirt/images/f14.img,format=qcow2,if=none,\
 id=drive-virtio-disk0,discard=unmap \
--device virtio-blk-pci,bus=pci.0,addr=0x4,drive=drive-virtio-disk0,\
+-device virtio-blk-pci,scsi=off,bus=pci.0,addr=0x4,drive=drive-virtio-disk0,\
 id=virtio-disk0,bootindex=2 \
 -drive file=/var/lib/libvirt/Fedora-14-x86_64-Live-KDE.iso,format=raw,if=none,\
 id=drive-ide0-1-0,readonly=on,discard=ignore \
 -device ide-cd,bus=ide.1,unit=0,drive=drive-ide0-1-0,id=ide0-1-0,bootindex=1 \
--device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x3
+-device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x2 \
+-sandbox on,obsolete=deny,elevateprivileges=deny,spawn=deny,\
+resourcecontrol=deny \
+-msg timestamp=on
diff --git a/tests/qemuxml2argvdata/disk-discard.x86_64-latest.args 
b/tests/qemuxml2argvdata/disk-discard.x86_64-latest.args
new file mode 100644
index 00..a7cbf567c8
--- /dev/null
+++ b/tests/qemuxml2argvdata/disk-discard.x86_64-latest.args
@@ -0,0 +1,46 @@
+LC_ALL=C \
+PATH=/bin \
+HOME=/tmp/lib/domain--1-test \
+USER=test \
+LOGNAME=test \
+XDG_DATA_HOME=/tmp/lib/domain--1-test/.local/share \
+XDG_CACHE_HOME=/tmp/lib/domain--1-test/.cache \
+XDG_CONFIG_HOME=/tmp/lib/domain--1-test/.config \
+QEMU_AUDIO_DRV=none \
+/usr/bin/qemu-system-x86_64 \
+-name guest=test,debug-threads=on \
+-S \
+-object secret,id=masterKey0,format=raw,\
+file=/tmp/lib/domain--1-test/master-key.aes \
+-machine pc,accel=tcg,usb=off,dump-guest-core=off \
+-cpu qemu64 \
+-m 1024 \
+-overcommit mem-lock=off \
+-smp 1,sockets=1,cores=1,threads=1 \
+-uuid 

[PATCH 07/20] qemu: Rename qemuDiskBusNeedsDriveArg to qemuDiskBusIsSD

2020-05-06 Thread Peter Krempa
The function effectively boils down to whether the disk is 'SD'. Since
we'll need to make more decisions based on the fact whether the disk is
on the SD bus, rename the function.

Signed-off-by: Peter Krempa 
---
 src/qemu/qemu_command.c | 8 
 src/qemu/qemu_command.h | 2 +-
 src/qemu/qemu_hotplug.c | 2 +-
 src/qemu/qemu_process.c | 2 +-
 4 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index d9c3a7a52e..1b3651a758 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -1141,7 +1141,7 @@ qemuCheckFips(void)


 /**
- * qemuDiskBusNeedsDriveArg:
+ * qemuDiskBusIsSD:
  * @bus: disk bus
  *
  * Unfortunately it is not possible to use -device for SD devices.
@@ -1149,7 +1149,7 @@ qemuCheckFips(void)
  * without -device.
  */
 bool
-qemuDiskBusNeedsDriveArg(int bus)
+qemuDiskBusIsSD(int bus)
 {
 return bus == VIR_DOMAIN_DISK_BUS_SD;
 }
@@ -1441,7 +1441,7 @@ qemuBuildDriveStr(virDomainDiskDefPtr disk,
 if (qemuBuildDriveSourceStr(disk, qemuCaps, ) < 0)
 return NULL;

-if (!qemuDiskBusNeedsDriveArg(disk->bus)) {
+if (!qemuDiskBusIsSD(disk->bus)) {
 g_autofree char *drivealias = qemuAliasDiskDriveFromDisk(disk);
 if (!drivealias)
 return NULL;
@@ -2158,7 +2158,7 @@ qemuBuildDiskCommandLine(virCommandPtr cmd,
 if (qemuBuildDiskSourceCommandLine(cmd, disk, qemuCaps) < 0)
 return -1;

-if (!qemuDiskBusNeedsDriveArg(disk->bus)) {
+if (!qemuDiskBusIsSD(disk->bus)) {
 if (disk->bus != VIR_DOMAIN_DISK_BUS_FDC ||
 virQEMUCapsGet(qemuCaps, QEMU_CAPS_BLOCKDEV)) {
 if (qemuCommandAddExtDevice(cmd, >info) < 0)
diff --git a/src/qemu/qemu_command.h b/src/qemu/qemu_command.h
index 0bb66c3f0b..53e05777e7 100644
--- a/src/qemu/qemu_command.h
+++ b/src/qemu/qemu_command.h
@@ -101,7 +101,7 @@ char *qemuBuildNicDevStr(virDomainDefPtr def,
  virQEMUCapsPtr qemuCaps);

 char *qemuDeviceDriveHostAlias(virDomainDiskDefPtr disk);
-bool qemuDiskBusNeedsDriveArg(int bus);
+bool qemuDiskBusIsSD(int bus);

 qemuBlockStorageSourceAttachDataPtr
 qemuBuildStorageSourceAttachPrepareDrive(virDomainDiskDefPtr disk,
diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index 641b6f1fe1..f1b2fbb1a8 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -1072,7 +1072,7 @@ qemuDomainAttachDeviceDiskLiveInternal(virQEMUDriverPtr 
driver,
 case VIR_DOMAIN_DISK_BUS_SD:
 /* Note that SD card hotplug support should be added only once
  * they support '-device' (don't require -drive only).
- * See also: qemuDiskBusNeedsDriveArg */
+ * See also: qemuDiskBusIsSD */
 case VIR_DOMAIN_DISK_BUS_LAST:
 virReportError(VIR_ERR_OPERATION_UNSUPPORTED,
_("disk bus '%s' cannot be hotplugged."),
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index 8ea470f75f..488ca91435 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -5499,7 +5499,7 @@ qemuProcessPrepareQEMUCaps(virDomainObjPtr vm,

 /* clear the 'blockdev' capability for VMs which have disks that need 
-drive */
 for (i = 0; i < vm->def->ndisks; i++) {
-if (qemuDiskBusNeedsDriveArg(vm->def->disks[i]->bus)) {
+if (qemuDiskBusIsSD(vm->def->disks[i]->bus)) {
 virQEMUCapsClear(priv->qemuCaps, QEMU_CAPS_BLOCKDEV);
 break;
 }
-- 
2.26.2



[PATCH 04/20] qemu: validate: Validate blkdeviotune settings in the validator

2020-05-06 Thread Peter Krempa
Move the code from qemuCheckDiskConfigBlkdeviotune in
src/qemu/qemu_commandline.c to
qemuValidateDomainDeviceDefDiskBlkdeviotune.

Signed-off-by: Peter Krempa 
---
 src/qemu/qemu_command.c  | 101 +-
 src/qemu/qemu_validate.c | 102 ++-
 src/qemu/qemu_validate.h |   1 +
 tests/qemublocktest.c|   2 +-
 4 files changed, 104 insertions(+), 102 deletions(-)

diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 269bdbaf56..87cb78e350 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -1131,102 +1131,6 @@ qemuDiskConfigBlkdeviotuneEnabled(virDomainDiskDefPtr 
disk)
 }


-/**
- * qemuCheckDiskConfigBlkdeviotune:
- * @disk: disk configuration
- * @qemuCaps: qemu capabilities, NULL if checking cold-configuration
- *
- * Checks whether block io tuning settings make sense. Returns -1 on error and
- * reports a proper libvirt error.
- */
-static int
-qemuCheckDiskConfigBlkdeviotune(virDomainDiskDefPtr disk,
-const virDomainDef *def,
-virQEMUCapsPtr qemuCaps)
-{
-/* group_name by itself is ignored by qemu */
-if (disk->blkdeviotune.group_name &&
-!virDomainBlockIoTuneInfoHasAny(>blkdeviotune)) {
-virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-   _("group_name can be configured only together with "
- "settings"));
-return -1;
-}
-
-/* checking def here is only for calling from tests */
-if (disk->blkdeviotune.group_name) {
-size_t i;
-
-for (i = 0; i < def->ndisks; i++) {
-virDomainDiskDefPtr d = def->disks[i];
-
-if (STREQ(d->dst, disk->dst) ||
-STRNEQ_NULLABLE(d->blkdeviotune.group_name,
-disk->blkdeviotune.group_name))
-continue;
-
-if (!virDomainBlockIoTuneInfoEqual(>blkdeviotune,
-   >blkdeviotune)) {
-virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-   _("different iotunes for disks %s and %s"),
-   disk->dst, d->dst);
-return -1;
-}
-}
-}
-
-if (disk->blkdeviotune.total_bytes_sec > QEMU_BLOCK_IOTUNE_MAX ||
-disk->blkdeviotune.read_bytes_sec > QEMU_BLOCK_IOTUNE_MAX ||
-disk->blkdeviotune.write_bytes_sec > QEMU_BLOCK_IOTUNE_MAX ||
-disk->blkdeviotune.total_iops_sec > QEMU_BLOCK_IOTUNE_MAX ||
-disk->blkdeviotune.read_iops_sec > QEMU_BLOCK_IOTUNE_MAX ||
-disk->blkdeviotune.write_iops_sec > QEMU_BLOCK_IOTUNE_MAX ||
-disk->blkdeviotune.total_bytes_sec_max > QEMU_BLOCK_IOTUNE_MAX ||
-disk->blkdeviotune.read_bytes_sec_max > QEMU_BLOCK_IOTUNE_MAX ||
-disk->blkdeviotune.write_bytes_sec_max > QEMU_BLOCK_IOTUNE_MAX ||
-disk->blkdeviotune.total_iops_sec_max > QEMU_BLOCK_IOTUNE_MAX ||
-disk->blkdeviotune.read_iops_sec_max > QEMU_BLOCK_IOTUNE_MAX ||
-disk->blkdeviotune.write_iops_sec_max > QEMU_BLOCK_IOTUNE_MAX ||
-disk->blkdeviotune.size_iops_sec > QEMU_BLOCK_IOTUNE_MAX) {
-virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED,
-  _("block I/O throttle limit must "
-"be no more than %llu using QEMU"), 
QEMU_BLOCK_IOTUNE_MAX);
-return -1;
-}
-
-if (qemuCaps) {
-/* block I/O throttling 1.7 */
-if (virDomainBlockIoTuneInfoHasMax(>blkdeviotune) &&
-!virQEMUCapsGet(qemuCaps, QEMU_CAPS_DRIVE_IOTUNE_MAX)) {
-virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-   _("there are some block I/O throttling parameters "
- "that are not supported with this QEMU binary"));
-return -1;
-}
-
-/* block I/O group 2.4 */
-if (disk->blkdeviotune.group_name &&
-!virQEMUCapsGet(qemuCaps, QEMU_CAPS_DRIVE_IOTUNE_GROUP)) {
-virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-   _("the block I/O throttling group parameter is "
- "not supported with this QEMU binary"));
-return -1;
-}
-
-/* block I/O throttling length 2.6 */
-if (virDomainBlockIoTuneInfoHasMaxLength(>blkdeviotune) &&
-!virQEMUCapsGet(qemuCaps, QEMU_CAPS_DRIVE_IOTUNE_MAX_LENGTH)) {
-virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-   _("there are some block I/O throttling length 
parameters "
- "that are not supported with this QEMU binary"));
-return -1;
-}
-}
-
-return 0;
-}
-
-
 /**
  * qemuCheckDiskConfig:
  * @disk: disk definition
@@ -1237,12 +1141,9 @@ qemuCheckDiskConfigBlkdeviotune(virDomainDiskDefPtr disk,
  */
 int
 qemuCheckDiskConfig(virDomainDiskDefPtr disk,
-  

[PATCH 08/20] qemuBuildDiskCommandLine: Clarify logic around building -device for disks

2020-05-06 Thread Peter Krempa
For 'SD' disks and floppies in the pre-blockdev era we don't format
-device. Extract the logic so that it's more clear and add comments.

Signed-off-by: Peter Krempa 
---
 src/qemu/qemu_command.c | 30 ++
 1 file changed, 18 insertions(+), 12 deletions(-)

diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 1b3651a758..3f3e3b69a8 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -2158,20 +2158,26 @@ qemuBuildDiskCommandLine(virCommandPtr cmd,
 if (qemuBuildDiskSourceCommandLine(cmd, disk, qemuCaps) < 0)
 return -1;

-if (!qemuDiskBusIsSD(disk->bus)) {
-if (disk->bus != VIR_DOMAIN_DISK_BUS_FDC ||
-virQEMUCapsGet(qemuCaps, QEMU_CAPS_BLOCKDEV)) {
-if (qemuCommandAddExtDevice(cmd, >info) < 0)
-return -1;
+/* SD cards are currently instantiated via -drive if=sd, so the -device
+ * part must be skipped */
+if (qemuDiskBusIsSD(disk->bus))
+return 0;

-virCommandAddArg(cmd, "-device");
+/* floppy devices are instantiated via -drive ...,if=none and bound to the
+ * controller via -global isa-fdc.driveA/B options in the pre-blockdev era 
*/
+if (disk->bus == VIR_DOMAIN_DISK_BUS_FDC &&
+!virQEMUCapsGet(qemuCaps, QEMU_CAPS_BLOCKDEV))
+return 0;

-if (!(optstr = qemuBuildDiskDeviceStr(def, disk, bootindex,
-  qemuCaps)))
-return -1;
-virCommandAddArg(cmd, optstr);
-}
-}
+if (qemuCommandAddExtDevice(cmd, >info) < 0)
+return -1;
+
+virCommandAddArg(cmd, "-device");
+
+if (!(optstr = qemuBuildDiskDeviceStr(def, disk, bootindex,
+  qemuCaps)))
+return -1;
+virCommandAddArg(cmd, optstr);

 return 0;
 }
-- 
2.26.2



[PATCH 14/20] qemuDomainValidateStorageSource: Allow masking out blockdev support

2020-05-06 Thread Peter Krempa
In case of 'sd' cards we'll use pre-blockdev code also if qemu supports
blockdev. In that specific case we'll need to mask out blockdev support
for 'sd' disks. Plumb in a boolean to allow it.

Signed-off-by: Peter Krempa 
---
 src/qemu/qemu_domain.c   | 12 
 src/qemu/qemu_domain.h   |  3 ++-
 src/qemu/qemu_validate.c |  2 +-
 tests/qemublocktest.c|  4 ++--
 4 files changed, 13 insertions(+), 8 deletions(-)

diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index e76a76021e..01f2792401 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -5137,11 +5137,15 @@ qemuDomainValidateActualNetDef(const virDomainNetDef 
*net,

 int
 qemuDomainValidateStorageSource(virStorageSourcePtr src,
-virQEMUCapsPtr qemuCaps)
+virQEMUCapsPtr qemuCaps,
+bool maskBlockdev)
 {
 int actualType = virStorageSourceGetActualType(src);
 bool blockdev = virQEMUCapsGet(qemuCaps, QEMU_CAPS_BLOCKDEV);

+if (maskBlockdev)
+blockdev = false;
+
 if (src->format == VIR_STORAGE_FILE_COW) {
 virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
   _("'cow' storage format is not supported"));
@@ -8294,7 +8298,7 @@ qemuDomainDetermineDiskChain(virQEMUDriverPtr driver,
 if (n->format == VIR_STORAGE_FILE_ISO)
 n->format = VIR_STORAGE_FILE_RAW;

-if (qemuDomainValidateStorageSource(n, priv->qemuCaps) < 0)
+if (qemuDomainValidateStorageSource(n, priv->qemuCaps, false) < 0)
 return -1;

 qemuDomainPrepareStorageSourceConfig(n, cfg, priv->qemuCaps);
@@ -13137,7 +13141,7 @@ qemuDomainPrepareDiskSourceLegacy(virDomainDiskDefPtr 
disk,
   qemuDomainObjPrivatePtr priv,
   virQEMUDriverConfigPtr cfg)
 {
-if (qemuDomainValidateStorageSource(disk->src, priv->qemuCaps) < 0)
+if (qemuDomainValidateStorageSource(disk->src, priv->qemuCaps, true) < 0)
 return -1;

 qemuDomainPrepareStorageSourceConfig(disk->src, cfg, priv->qemuCaps);
@@ -13173,7 +13177,7 @@ 
qemuDomainPrepareStorageSourceBlockdev(virDomainDiskDefPtr disk,
 if (qemuBlockStorageSourceNeedsStorageSliceLayer(src))
 src->sliceStorage->nodename = g_strdup_printf("libvirt-%u-slice-sto", 
src->id);

-if (qemuDomainValidateStorageSource(src, priv->qemuCaps) < 0)
+if (qemuDomainValidateStorageSource(src, priv->qemuCaps, false) < 0)
 return -1;

 qemuDomainPrepareStorageSourceConfig(src, cfg, priv->qemuCaps);
diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h
index 639d27d8a5..ea0fce64a8 100644
--- a/src/qemu/qemu_domain.h
+++ b/src/qemu/qemu_domain.h
@@ -1237,7 +1237,8 @@ qemuDomainPrepareDiskSourceData(virDomainDiskDefPtr disk,

 int
 qemuDomainValidateStorageSource(virStorageSourcePtr src,
-virQEMUCapsPtr qemuCaps);
+virQEMUCapsPtr qemuCaps,
+bool maskBlockdev);


 int
diff --git a/src/qemu/qemu_validate.c b/src/qemu/qemu_validate.c
index 63cde01762..a7c918e5fd 100644
--- a/src/qemu/qemu_validate.c
+++ b/src/qemu/qemu_validate.c
@@ -2297,7 +2297,7 @@ qemuValidateDomainDeviceDefDisk(const virDomainDiskDef 
*disk,
 }

 for (n = disk->src; virStorageSourceIsBacking(n); n = n->backingStore) {
-if (qemuDomainValidateStorageSource(n, qemuCaps) < 0)
+if (qemuDomainValidateStorageSource(n, qemuCaps, false) < 0)
 return -1;
 }

diff --git a/tests/qemublocktest.c b/tests/qemublocktest.c
index b80ee2ae6c..82c11311e2 100644
--- a/tests/qemublocktest.c
+++ b/tests/qemublocktest.c
@@ -294,7 +294,7 @@ testQemuDiskXMLToProps(const void *opaque)
 if (testQemuDiskXMLToJSONFakeSecrets(n) < 0)
 return -1;

-if (qemuDomainValidateStorageSource(n, data->qemuCaps) < 0)
+if (qemuDomainValidateStorageSource(n, data->qemuCaps, false) < 0)
 return -1;

 qemuDomainPrepareDiskSourceData(disk, n);
@@ -529,7 +529,7 @@ testQemuImageCreate(const void *opaque)
 src->capacity = UINT_MAX * 2ULL;
 src->physical = UINT_MAX + 1ULL;

-if (qemuDomainValidateStorageSource(src, data->qemuCaps) < 0)
+if (qemuDomainValidateStorageSource(src, data->qemuCaps, false) < 0)
 return -1;

 if (qemuBlockStorageSourceCreateGetStorageProps(src, ) < 0)
-- 
2.26.2



[PATCH 06/20] qemuCheckDiskConfig: Remove and untangle callers

2020-05-06 Thread Peter Krempa
Remove the function and passing of 'def' through the callers.

Signed-off-by: Peter Krempa 
---
 src/qemu/qemu_command.c | 36 
 src/qemu/qemu_command.h |  5 -
 src/qemu/qemu_driver.c  |  2 --
 src/qemu/qemu_hotplug.c |  2 +-
 tests/qemublocktest.c   |  3 +--
 5 files changed, 6 insertions(+), 42 deletions(-)

diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 2dfd17ad40..d9c3a7a52e 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -1114,23 +1114,6 @@ qemuDiskConfigBlkdeviotuneEnabled(virDomainDiskDefPtr 
disk)
 }


-/**
- * qemuCheckDiskConfig:
- * @disk: disk definition
- * @qemuCaps: qemu capabilities, may be NULL for cold-plug check
- *
- * Perform disk definition config validity checks. Returns -1 on error with
- * error reported.
- */
-int
-qemuCheckDiskConfig(virDomainDiskDefPtr disk G_GNUC_UNUSED,
-const virDomainDef *def G_GNUC_UNUSED,
-virQEMUCapsPtr qemuCaps G_GNUC_UNUSED)
-{
-return 0;
-}
-
-
 /* QEMU 1.2 and later have a binary flag -enable-fips that must be
  * used for VNC auth to obey FIPS settings; but the flag only
  * exists on Linux, and with no way to probe for it via QMP.  Our
@@ -1449,7 +1432,6 @@ qemuBuildDiskFrontendAttributes(virDomainDiskDefPtr disk,

 static char *
 qemuBuildDriveStr(virDomainDiskDefPtr disk,
-  const virDomainDef *def,
   virQEMUCapsPtr qemuCaps)
 {
 g_auto(virBuffer) opt = VIR_BUFFER_INITIALIZER;
@@ -1475,10 +1457,6 @@ qemuBuildDriveStr(virDomainDiskDefPtr disk,
 return NULL;
 }

-/* if we are using -device this will be checked elsewhere */
-if (qemuCheckDiskConfig(disk, def, qemuCaps) < 0)
-return NULL;
-
 virBufferAsprintf(, "if=%s",
   virDomainDiskQEMUBusTypeToString(disk->bus));
 virBufferAsprintf(, ",index=%d", idx);
@@ -1618,9 +1596,6 @@ qemuBuildDiskDeviceStr(const virDomainDef *def,
 g_autofree char *scsiVPDDeviceId = NULL;
 int controllerModel;

-if (qemuCheckDiskConfig(disk, def, qemuCaps) < 0)
-return NULL;
-
 if (!qemuDomainCheckCCWS390AddressSupport(def, >info, qemuCaps, 
disk->dst))
 return NULL;

@@ -2131,7 +2106,6 @@ 
qemuBuildBlockStorageSourceAttachDataCommandline(virCommandPtr cmd,
 static int
 qemuBuildDiskSourceCommandLine(virCommandPtr cmd,
virDomainDiskDefPtr disk,
-   const virDomainDef *def,
virQEMUCapsPtr qemuCaps)
 {
 g_autoptr(qemuBlockStorageSourceChainData) data = NULL;
@@ -2151,7 +2125,7 @@ qemuBuildDiskSourceCommandLine(virCommandPtr cmd,
 !(copyOnReadProps = qemuBlockStorageGetCopyOnReadProps(disk)))
 return -1;
 } else {
-if (!(data = qemuBuildStorageSourceChainAttachPrepareDrive(disk, def, 
qemuCaps)))
+if (!(data = qemuBuildStorageSourceChainAttachPrepareDrive(disk, 
qemuCaps)))
 return -1;
 }

@@ -2181,7 +2155,7 @@ qemuBuildDiskCommandLine(virCommandPtr cmd,
 {
 g_autofree char *optstr = NULL;

-if (qemuBuildDiskSourceCommandLine(cmd, disk, def, qemuCaps) < 0)
+if (qemuBuildDiskSourceCommandLine(cmd, disk, qemuCaps) < 0)
 return -1;

 if (!qemuDiskBusNeedsDriveArg(disk->bus)) {
@@ -9979,7 +9953,6 @@ qemuBuildHotpluggableCPUProps(const virDomainVcpuDef 
*vcpu)
  */
 qemuBlockStorageSourceAttachDataPtr
 qemuBuildStorageSourceAttachPrepareDrive(virDomainDiskDefPtr disk,
- const virDomainDef *def,
  virQEMUCapsPtr qemuCaps)
 {
 g_autoptr(qemuBlockStorageSourceAttachData) data = NULL;
@@ -9987,7 +9960,7 @@ 
qemuBuildStorageSourceAttachPrepareDrive(virDomainDiskDefPtr disk,
 if (VIR_ALLOC(data) < 0)
 return NULL;

-if (!(data->driveCmd = qemuBuildDriveStr(disk, def, qemuCaps)) ||
+if (!(data->driveCmd = qemuBuildDriveStr(disk, qemuCaps)) ||
 !(data->driveAlias = qemuAliasDiskDriveFromDisk(disk)))
 return NULL;

@@ -10049,7 +10022,6 @@ 
qemuBuildStorageSourceAttachPrepareCommon(virStorageSourcePtr src,
  */
 qemuBlockStorageSourceChainDataPtr
 qemuBuildStorageSourceChainAttachPrepareDrive(virDomainDiskDefPtr disk,
-  const virDomainDef *def,
   virQEMUCapsPtr qemuCaps)
 {
 g_autoptr(qemuBlockStorageSourceAttachData) elem = NULL;
@@ -10058,7 +10030,7 @@ 
qemuBuildStorageSourceChainAttachPrepareDrive(virDomainDiskDefPtr disk,
 if (VIR_ALLOC(data) < 0)
 return NULL;

-if (!(elem = qemuBuildStorageSourceAttachPrepareDrive(disk, def, 
qemuCaps)))
+if (!(elem = qemuBuildStorageSourceAttachPrepareDrive(disk, qemuCaps)))
 return NULL;

 if (qemuBuildStorageSourceAttachPrepareCommon(disk->src, elem, qemuCaps) < 
0)
diff --git 

[PATCH 03/20] qemuValidateDomainDeviceDefDisk: Separate disk frontend config validation

2020-05-06 Thread Peter Krempa
Agregate validation of frontend properties in a new function called
qemuValidateDomainDeviceDefDiskFrontend.

Signed-off-by: Peter Krempa 
---
 src/qemu/qemu_validate.c | 90 ++--
 1 file changed, 50 insertions(+), 40 deletions(-)

diff --git a/src/qemu/qemu_validate.c b/src/qemu/qemu_validate.c
index 9debac6b30..6f13a1df1b 100644
--- a/src/qemu/qemu_validate.c
+++ b/src/qemu/qemu_validate.c
@@ -1897,40 +1897,9 @@ qemuValidateDomainDeviceDefVideo(const virDomainVideoDef 
*video,
 }


-int
-qemuValidateDomainDeviceDefDisk(const virDomainDiskDef *disk,
-virQEMUCapsPtr qemuCaps)
+static int
+qemuValidateDomainDeviceDefDiskFrontend(const virDomainDiskDef *disk)
 {
-const char *driverName = virDomainDiskGetDriver(disk);
-virStorageSourcePtr n;
-int idx;
-int partition;
-
-if (disk->src->shared && !disk->src->readonly &&
-!qemuBlockStorageSourceSupportsConcurrentAccess(disk->src)) {
-virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-   _("shared access for disk '%s' requires use of "
- "supported storage format"), disk->dst);
-return -1;
-}
-
-if (disk->copy_on_read == VIR_TRISTATE_SWITCH_ON) {
-if (disk->src->readonly) {
-virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-   _("copy_on_read is not compatible with read-only 
disk '%s'"),
-   disk->dst);
-return -1;
-}
-
-if (disk->device == VIR_DOMAIN_DISK_DEVICE_CDROM ||
-disk->device == VIR_DOMAIN_DISK_DEVICE_FLOPPY) {
-virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-   _("copy_on_read is not supported with removable 
disk '%s'"),
-   disk->dst);
-return -1;
-}
-}
-
 if (disk->geometry.cylinders > 0 &&
 disk->geometry.heads > 0 &&
 disk->geometry.sectors > 0) {
@@ -1958,13 +1927,6 @@ qemuValidateDomainDeviceDefDisk(const virDomainDiskDef 
*disk,
 return -1;
 }

-if (driverName && STRNEQ(driverName, "qemu")) {
-virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-   _("unsupported driver name '%s' for disk '%s'"),
-   driverName, disk->dst);
-return -1;
-}
-
 if (disk->device == VIR_DOMAIN_DISK_DEVICE_CDROM &&
 disk->bus == VIR_DOMAIN_DISK_BUS_VIRTIO) {
 virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
@@ -1973,6 +1935,54 @@ qemuValidateDomainDeviceDefDisk(const virDomainDiskDef 
*disk,
 return -1;
 }

+if (disk->copy_on_read == VIR_TRISTATE_SWITCH_ON) {
+if (disk->src->readonly) {
+virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+   _("copy_on_read is not compatible with read-only 
disk '%s'"),
+   disk->dst);
+return -1;
+}
+
+if (disk->device == VIR_DOMAIN_DISK_DEVICE_CDROM ||
+disk->device == VIR_DOMAIN_DISK_DEVICE_FLOPPY) {
+virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+   _("copy_on_read is not supported with removable 
disk '%s'"),
+   disk->dst);
+return -1;
+}
+}
+
+return 0;
+}
+
+
+int
+qemuValidateDomainDeviceDefDisk(const virDomainDiskDef *disk,
+virQEMUCapsPtr qemuCaps)
+{
+const char *driverName = virDomainDiskGetDriver(disk);
+virStorageSourcePtr n;
+int idx;
+int partition;
+
+if (qemuValidateDomainDeviceDefDiskFrontend(disk) < 0)
+return -1;
+
+if (disk->src->shared && !disk->src->readonly &&
+!qemuBlockStorageSourceSupportsConcurrentAccess(disk->src)) {
+virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+   _("shared access for disk '%s' requires use of "
+ "supported storage format"), disk->dst);
+return -1;
+}
+
+if (driverName && STRNEQ(driverName, "qemu")) {
+virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+   _("unsupported driver name '%s' for disk '%s'"),
+   driverName, disk->dst);
+return -1;
+}
+
 if (virDiskNameParse(disk->dst, , ) < 0) {
 virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("invalid disk target '%s'"), disk->dst);
-- 
2.26.2



[PATCH 16/20] qemu: Forbid 'cdrom' on 'sd' bus

2020-05-06 Thread Peter Krempa
We can't set the type of the device on the 'sd' bus and realistically a
cdrom doesn't even make sense there. Forbid it.

Note that the output of in disk-cdrom-bus-other.x86_64-latest.args
switched to blockdev as it's no longer locked out due to use of a disk
on 'sd' bus.

Signed-off-by: Peter Krempa 
---
 src/qemu/qemu_validate.c|  5 +++--
 .../disk-cdrom-bus-other.x86_64-latest.args | 13 ++---
 tests/qemuxml2argvdata/disk-cdrom-bus-other.xml | 11 ---
 tests/qemuxml2xmloutdata/disk-cdrom-bus-other.xml   | 11 ---
 4 files changed, 9 insertions(+), 31 deletions(-)

diff --git a/src/qemu/qemu_validate.c b/src/qemu/qemu_validate.c
index a7c918e5fd..f49181b639 100644
--- a/src/qemu/qemu_validate.c
+++ b/src/qemu/qemu_validate.c
@@ -1946,9 +1946,10 @@ qemuValidateDomainDeviceDefDiskFrontend(const 
virDomainDiskDef *disk,
 }

 if (disk->device == VIR_DOMAIN_DISK_DEVICE_CDROM &&
-disk->bus == VIR_DOMAIN_DISK_BUS_VIRTIO) {
+(disk->bus == VIR_DOMAIN_DISK_BUS_VIRTIO ||
+ disk->bus == VIR_DOMAIN_DISK_BUS_SD)) {
 virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-   _("disk type 'virtio' of '%s' does not support 
ejectable media"),
+   _("disk type of '%s' does not support ejectable media"),
disk->dst);
 return -1;
 }
diff --git a/tests/qemuxml2argvdata/disk-cdrom-bus-other.x86_64-latest.args 
b/tests/qemuxml2argvdata/disk-cdrom-bus-other.x86_64-latest.args
index b1c30dd4d8..be091f150f 100644
--- a/tests/qemuxml2argvdata/disk-cdrom-bus-other.x86_64-latest.args
+++ b/tests/qemuxml2argvdata/disk-cdrom-bus-other.x86_64-latest.args
@@ -28,14 +28,13 @@ file=/tmp/lib/domain--1-QEMUGuest1/master-key.aes \
 -no-acpi \
 -boot strict=on \
 -device piix3-usb-uhci,id=usb,bus=pci.0,addr=0x1.0x2 \
--drive file=/root/boot.iso,format=raw,if=none,id=drive-usb-disk0,readonly=on \
--device usb-storage,bus=usb.0,port=1,drive=drive-usb-disk0,id=usb-disk0,\
+-blockdev '{"driver":"file","filename":"/root/boot.iso",\
+"node-name":"libvirt-2-storage","auto-read-only":true,"discard":"unmap"}' \
+-blockdev '{"node-name":"libvirt-2-format","read-only":true,"driver":"raw",\
+"file":"libvirt-2-storage"}' \
+-device usb-storage,bus=usb.0,port=1,drive=libvirt-2-format,id=usb-disk0,\
 removable=off \
--drive if=none,id=drive-usb-disk1,readonly=on \
--device usb-storage,bus=usb.0,port=2,drive=drive-usb-disk1,id=usb-disk1,\
-removable=off \
--drive file=/root/boot2.iso,format=raw,if=sd,index=2,readonly=on \
--drive if=sd,index=3,readonly=on \
+-device usb-storage,bus=usb.0,port=2,id=usb-disk1,removable=off \
 -sandbox on,obsolete=deny,elevateprivileges=deny,spawn=deny,\
 resourcecontrol=deny \
 -msg timestamp=on
diff --git a/tests/qemuxml2argvdata/disk-cdrom-bus-other.xml 
b/tests/qemuxml2argvdata/disk-cdrom-bus-other.xml
index e73db8c6ab..e6bf1ea797 100644
--- a/tests/qemuxml2argvdata/disk-cdrom-bus-other.xml
+++ b/tests/qemuxml2argvdata/disk-cdrom-bus-other.xml
@@ -26,17 +26,6 @@
   
   
 
-
-  
-  
-  
-  
-
-
-  
-  
-  
-
 
 
 
diff --git a/tests/qemuxml2xmloutdata/disk-cdrom-bus-other.xml 
b/tests/qemuxml2xmloutdata/disk-cdrom-bus-other.xml
index 10262e40d7..ec86d19f1d 100644
--- a/tests/qemuxml2xmloutdata/disk-cdrom-bus-other.xml
+++ b/tests/qemuxml2xmloutdata/disk-cdrom-bus-other.xml
@@ -26,17 +26,6 @@
   
   
 
-
-  
-  
-  
-  
-
-
-  
-  
-  
-
 
   
 
-- 
2.26.2



[PATCH 15/20] tests: Add tests for a virtio and sd disk in a single machine

2020-05-06 Thread Peter Krempa
The 'vexpress-a9' ARM board supports the native 'sd' bus as well as
virtio. Add a test case for proving that upcoming changes to handling of
'sd' work. This config was also tested with real qemu and the qemu
process starts correctly.

Signed-off-by: Peter Krempa 
---
 .../disk-arm-virtio-sd.aarch64-4.0.0.args | 39 ++
 .../disk-arm-virtio-sd.aarch64-latest.args| 40 ++
 tests/qemuxml2argvdata/disk-arm-virtio-sd.xml | 36 
 tests/qemuxml2argvtest.c  |  3 ++
 .../disk-arm-virtio-sd.aarch64-latest.xml | 41 +++
 tests/qemuxml2xmltest.c   |  2 +
 6 files changed, 161 insertions(+)
 create mode 100644 tests/qemuxml2argvdata/disk-arm-virtio-sd.aarch64-4.0.0.args
 create mode 100644 
tests/qemuxml2argvdata/disk-arm-virtio-sd.aarch64-latest.args
 create mode 100644 tests/qemuxml2argvdata/disk-arm-virtio-sd.xml
 create mode 100644 
tests/qemuxml2xmloutdata/disk-arm-virtio-sd.aarch64-latest.xml

diff --git a/tests/qemuxml2argvdata/disk-arm-virtio-sd.aarch64-4.0.0.args 
b/tests/qemuxml2argvdata/disk-arm-virtio-sd.aarch64-4.0.0.args
new file mode 100644
index 00..3c2a7cf240
--- /dev/null
+++ b/tests/qemuxml2argvdata/disk-arm-virtio-sd.aarch64-4.0.0.args
@@ -0,0 +1,39 @@
+LC_ALL=C \
+PATH=/bin \
+HOME=/tmp/lib/domain--1-armtest \
+USER=test \
+LOGNAME=test \
+XDG_DATA_HOME=/tmp/lib/domain--1-armtest/.local/share \
+XDG_CACHE_HOME=/tmp/lib/domain--1-armtest/.cache \
+XDG_CONFIG_HOME=/tmp/lib/domain--1-armtest/.config \
+QEMU_AUDIO_DRV=none \
+/usr/bin/qemu-system-arm \
+-name guest=armtest,debug-threads=on \
+-S \
+-object secret,id=masterKey0,format=raw,\
+file=/tmp/lib/domain--1-armtest/master-key.aes \
+-machine vexpress-a9,accel=tcg,usb=off,dump-guest-core=off \
+-m 1024 \
+-overcommit mem-lock=off \
+-smp 1,sockets=1,cores=1,threads=1 \
+-uuid 496d7ea8-9739-544b-4ebd-ef08be936e6a \
+-display none \
+-no-user-config \
+-nodefaults \
+-chardev socket,id=charmonitor,fd=1729,server,nowait \
+-mon chardev=charmonitor,id=monitor,mode=control \
+-rtc base=utc \
+-no-shutdown \
+-boot strict=on \
+-kernel /arm.kernel \
+-initrd /arm.initrd \
+-append 'console=ttyAMA0,\
+115200n8 rw root=/dev/vda3 rootwait physmap.enabled=0' \
+-dtb /arm.dtb \
+-usb \
+-drive file=/arm-sd.qcow2,format=qcow2,if=sd,index=0 \
+-drive file=/arm-virtio.qcow2,format=qcow2,if=none,id=drive-virtio-disk0 \
+-device virtio-blk-device,scsi=off,drive=drive-virtio-disk0,id=virtio-disk0 \
+-sandbox on,obsolete=deny,elevateprivileges=deny,spawn=deny,\
+resourcecontrol=deny \
+-msg timestamp=on
diff --git a/tests/qemuxml2argvdata/disk-arm-virtio-sd.aarch64-latest.args 
b/tests/qemuxml2argvdata/disk-arm-virtio-sd.aarch64-latest.args
new file mode 100644
index 00..7147dfee76
--- /dev/null
+++ b/tests/qemuxml2argvdata/disk-arm-virtio-sd.aarch64-latest.args
@@ -0,0 +1,40 @@
+LC_ALL=C \
+PATH=/bin \
+HOME=/tmp/lib/domain--1-armtest \
+USER=test \
+LOGNAME=test \
+XDG_DATA_HOME=/tmp/lib/domain--1-armtest/.local/share \
+XDG_CACHE_HOME=/tmp/lib/domain--1-armtest/.cache \
+XDG_CONFIG_HOME=/tmp/lib/domain--1-armtest/.config \
+QEMU_AUDIO_DRV=none \
+/usr/bin/qemu-system-arm \
+-name guest=armtest,debug-threads=on \
+-S \
+-object secret,id=masterKey0,format=raw,\
+file=/tmp/lib/domain--1-armtest/master-key.aes \
+-machine vexpress-a9,accel=tcg,usb=off,dump-guest-core=off \
+-cpu cortex-a9 \
+-m 1024 \
+-overcommit mem-lock=off \
+-smp 1,sockets=1,cores=1,threads=1 \
+-uuid 496d7ea8-9739-544b-4ebd-ef08be936e6a \
+-display none \
+-no-user-config \
+-nodefaults \
+-chardev socket,id=charmonitor,fd=1729,server,nowait \
+-mon chardev=charmonitor,id=monitor,mode=control \
+-rtc base=utc \
+-no-shutdown \
+-boot strict=on \
+-kernel /arm.kernel \
+-initrd /arm.initrd \
+-append 'console=ttyAMA0,\
+115200n8 rw root=/dev/vda3 rootwait physmap.enabled=0' \
+-dtb /arm.dtb \
+-usb \
+-drive file=/arm-sd.qcow2,format=qcow2,if=sd,index=0 \
+-drive file=/arm-virtio.qcow2,format=qcow2,if=none,id=drive-virtio-disk0 \
+-device virtio-blk-device,scsi=off,drive=drive-virtio-disk0,id=virtio-disk0 \
+-sandbox on,obsolete=deny,elevateprivileges=deny,spawn=deny,\
+resourcecontrol=deny \
+-msg timestamp=on
diff --git a/tests/qemuxml2argvdata/disk-arm-virtio-sd.xml 
b/tests/qemuxml2argvdata/disk-arm-virtio-sd.xml
new file mode 100644
index 00..0a6482fd4a
--- /dev/null
+++ b/tests/qemuxml2argvdata/disk-arm-virtio-sd.xml
@@ -0,0 +1,36 @@
+
+  armtest
+  496d7ea8-9739-544b-4ebd-ef08be936e6a
+  1048576
+  1048576
+  1
+  
+hvm
+/arm.kernel
+/arm.initrd
+/arm.dtb
+console=ttyAMA0,115200n8 rw root=/dev/vda3 rootwait 
physmap.enabled=0
+  
+  
+
+
+
+  
+  
+  destroy
+  restart
+  restart
+  
+/usr/bin/qemu-system-arm
+
+  
+  
+  
+
+
+  
+  
+  
+
+  
+
diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
index ad89353910..4ab664a846 100644
--- a/tests/qemuxml2argvtest.c

[PATCH 13/20] qemuDomainValidateStorageSource: Extract check for BLOCKDEV capability

2020-05-06 Thread Peter Krempa
Signed-off-by: Peter Krempa 
---
 src/qemu/qemu_domain.c | 16 ++--
 1 file changed, 6 insertions(+), 10 deletions(-)

diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 9c629c31a3..e76a76021e 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -5140,6 +5140,7 @@ qemuDomainValidateStorageSource(virStorageSourcePtr src,
 virQEMUCapsPtr qemuCaps)
 {
 int actualType = virStorageSourceGetActualType(src);
+bool blockdev = virQEMUCapsGet(qemuCaps, QEMU_CAPS_BLOCKDEV);

 if (src->format == VIR_STORAGE_FILE_COW) {
 virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
@@ -5224,8 +5225,7 @@ qemuDomainValidateStorageSource(virStorageSourcePtr src,
 /* In pre-blockdev era we can't configure the slice so we can allow 
them
  * only for detected backing store entries as they are populated
  * from a place that qemu would be able to read */
-if (!src->detected &&
-!virQEMUCapsGet(qemuCaps, QEMU_CAPS_BLOCKDEV)) {
+if (!src->detected && !blockdev) {
 virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("storage slice is not supported by this QEMU 
binary"));
 return -1;
@@ -5241,8 +5241,7 @@ qemuDomainValidateStorageSource(virStorageSourcePtr src,
 return -1;
 }

-if (!src->detected &&
-!virQEMUCapsGet(qemuCaps, QEMU_CAPS_BLOCKDEV)) {
+if (!src->detected && !blockdev) {
 virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("ssl verification setting is not supported by 
this QEMU binary"));
 return -1;
@@ -5258,8 +5257,7 @@ qemuDomainValidateStorageSource(virStorageSourcePtr src,
 return -1;
 }

-if (!src->detected &&
-!virQEMUCapsGet(qemuCaps, QEMU_CAPS_BLOCKDEV)) {
+if (!src->detected && !blockdev) {
 virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("http cookies are not supported by this QEMU 
binary"));
 return -1;
@@ -5280,8 +5278,7 @@ qemuDomainValidateStorageSource(virStorageSourcePtr src,
 return -1;
 }

-if (!src->detected &&
-!virQEMUCapsGet(qemuCaps, QEMU_CAPS_BLOCKDEV)) {
+if (!src->detected && !blockdev) {
 virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("readahead setting is not supported with this 
QEMU binary"));
 return -1;
@@ -5299,8 +5296,7 @@ qemuDomainValidateStorageSource(virStorageSourcePtr src,
 return -1;
 }

-if (!src->detected &&
-!virQEMUCapsGet(qemuCaps, QEMU_CAPS_BLOCKDEV)) {
+if (!src->detected && !blockdev) {
 virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("timeout setting is not supported with this QEMU 
binary"));
 return -1;
-- 
2.26.2



[PATCH 09/20] qemuBuildDriveStr: Refactor formatting of command line for 'sd' cards

2020-05-06 Thread Peter Krempa
Remove all the universal code since the 'else' part formats commandline
only for the SD card based disk. Note that we can use virDiskNameToIndex
without the check as we already validate that 'disk->dst' contains a
properly formatted string in the validation code.

Signed-off-by: Peter Krempa 
---
 src/qemu/qemu_command.c | 13 ++---
 1 file changed, 2 insertions(+), 11 deletions(-)

diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 3f3e3b69a8..9836972234 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -1449,17 +1449,8 @@ qemuBuildDriveStr(virDomainDiskDefPtr disk,
 virBufferAddLit(, "if=none");
 virBufferAsprintf(, ",id=%s", drivealias);
 } else {
-int idx = virDiskNameToIndex(disk->dst);
-
-if (idx < 0) {
-virReportError(VIR_ERR_INTERNAL_ERROR,
-   _("unsupported disk type '%s'"), disk->dst);
-return NULL;
-}
-
-virBufferAsprintf(, "if=%s",
-  virDomainDiskQEMUBusTypeToString(disk->bus));
-virBufferAsprintf(, ",index=%d", idx);
+virBufferAsprintf(, "if=sd,index=%d",
+  virDiskNameToIndex(disk->dst));
 }

 /* werror/rerror are really frontend attributes, but older
-- 
2.26.2



[PATCH 20/20] qemu: process: Don't clear QEMU_CAPS_BLOCKDEV when SD card is present

2020-05-06 Thread Peter Krempa
Help QEMU in deprecation of -drive if=none without the need to refactor
all old boards. Stop masking out -blockdev support when -drive if=sd
needs to be used. We achieve this by forbidding blockjobs and
special-casing all other code paths. Blockjobs are sacrificed in this
case as SD cards are a corner case for some ARM boards and are thus not
used commonly.

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

Signed-off-by: Peter Krempa 
---
 src/qemu/qemu_process.c  | 9 -
 .../disk-arm-virtio-sd.aarch64-latest.args   | 7 +--
 2 files changed, 5 insertions(+), 11 deletions(-)

diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index b1751d4b52..dee3f3fb63 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -5488,7 +5488,6 @@ qemuProcessPrepareQEMUCaps(virDomainObjPtr vm,
unsigned int processStartFlags)
 {
 qemuDomainObjPrivatePtr priv = vm->privateData;
-size_t i;

 virObjectUnref(priv->qemuCaps);
 if (!(priv->qemuCaps = virQEMUCapsCacheLookupCopy(qemuCapsCache,
@@ -5497,14 +5496,6 @@ qemuProcessPrepareQEMUCaps(virDomainObjPtr vm,
   vm->def->os.machine)))
 return -1;

-/* clear the 'blockdev' capability for VMs which have disks that need 
-drive */
-for (i = 0; i < vm->def->ndisks; i++) {
-if (qemuDiskBusIsSD(vm->def->disks[i]->bus)) {
-virQEMUCapsClear(priv->qemuCaps, QEMU_CAPS_BLOCKDEV);
-break;
-}
-}
-
 if (processStartFlags & VIR_QEMU_PROCESS_START_STANDALONE)
 virQEMUCapsClear(priv->qemuCaps, QEMU_CAPS_CHARDEV_FD_PASS);

diff --git a/tests/qemuxml2argvdata/disk-arm-virtio-sd.aarch64-latest.args 
b/tests/qemuxml2argvdata/disk-arm-virtio-sd.aarch64-latest.args
index 7147dfee76..f17dd2157a 100644
--- a/tests/qemuxml2argvdata/disk-arm-virtio-sd.aarch64-latest.args
+++ b/tests/qemuxml2argvdata/disk-arm-virtio-sd.aarch64-latest.args
@@ -33,8 +33,11 @@ file=/tmp/lib/domain--1-armtest/master-key.aes \
 -dtb /arm.dtb \
 -usb \
 -drive file=/arm-sd.qcow2,format=qcow2,if=sd,index=0 \
--drive file=/arm-virtio.qcow2,format=qcow2,if=none,id=drive-virtio-disk0 \
--device virtio-blk-device,scsi=off,drive=drive-virtio-disk0,id=virtio-disk0 \
+-blockdev '{"driver":"file","filename":"/arm-virtio.qcow2",\
+"node-name":"libvirt-1-storage","auto-read-only":true,"discard":"unmap"}' \
+-blockdev '{"node-name":"libvirt-1-format","read-only":false,"driver":"qcow2",\
+"file":"libvirt-1-storage"}' \
+-device virtio-blk-device,scsi=off,drive=libvirt-1-format,id=virtio-disk0 \
 -sandbox on,obsolete=deny,elevateprivileges=deny,spawn=deny,\
 resourcecontrol=deny \
 -msg timestamp=on
-- 
2.26.2



[libvirt-ci PATCH 01/12] requirements: Introduce a requirements.txt file

2020-05-06 Thread Erik Skultety
Right now, lcitool's users have 2 options to satisfy the tool's
dependencies: install them through the system package manager
system-wide or install through pip manually.
Since pip gives us the option to automate this process a tiny bit, let's
ship a requirements file. This targets users who are used to work
with Python virtual environments and install whatever it is necessary
inside.

Signed-off-by: Erik Skultety 
Reviewed-by: Andrea Bolognani 
---
 guests/requirements.txt | 2 ++
 1 file changed, 2 insertions(+)
 create mode 100644 guests/requirements.txt

diff --git a/guests/requirements.txt b/guests/requirements.txt
new file mode 100644
index 000..900cfd6
--- /dev/null
+++ b/guests/requirements.txt
@@ -0,0 +1,2 @@
+ansible
+jenkins-job-builder
-- 
2.25.3



[libvirt-ci PATCH 06/12] lcitool: Introduce methods to load and validate the YAML config

2020-05-06 Thread Erik Skultety
This patch introduce a set of class Config helper methods in order to
parse and validate the new global YAML config.
Currently, only 'install' and 'gitlab' sections are recognized with
the flavor setting defaulting to "test" (backwards compatibility) and
gitlab runner registration url defaulting to "https://gitlab.com;; the
rest of the options are currently mandatory.

Signed-off-by: Erik Skultety 
---
 guests/lcitool | 57 ++
 1 file changed, 57 insertions(+)

diff --git a/guests/lcitool b/guests/lcitool
index 2dca8b5..07d0b3c 100755
--- a/guests/lcitool
+++ b/guests/lcitool
@@ -133,6 +133,29 @@ class Util:
 
 class Config:
 
+def __init__(self):
+
+# Load the template config containing the defaults first, this must
+# always succeed.
+# NOTE: we should load this from /usr/share once we start packaging
+# lcitool
+base = Util.get_base()
+with open(os.path.join(base, "config.yaml"), "r") as fp:
+self.values = yaml.load(fp, Loader=yaml.Loader)
+
+try:
+with open(self._get_config_file("config.yaml"), "r") as fp:
+user_config = yaml.load(fp, Loader=yaml.Loader)
+except Exception as e:
+print("Missing or invalid config.yaml file: {}".format(e),
+  file=sys.stderr)
+sys.exit(1)
+
+# Validate the user provided config and use it to override the default
+# settings
+self._validate(user_config)
+self._update(user_config)
+
 @staticmethod
 def _get_config_file(name):
 try:
@@ -154,6 +177,40 @@ class Config:
 
 return os.path.join(config_dir, name)
 
+@staticmethod
+def _validate_section(config, section, keys):
+
+if config.get(section, None) is None:
+raise KeyError("Section '{}' not found".format(section))
+
+for key in keys:
+if config.get(section).get(key, None) is None:
+raise KeyError("Missing mandatory key '{}.{}'".format(section,
+  key))
+
+@staticmethod
+def _validate(config):
+
+# verify the [install] section and its mandatory options
+Config._validate_section(config, "install", ["root_password"])
+
+# we need to check flavor here, because later validations depend on it
+flavor = config.get("install").get("flavor", "test")
+if flavor not in ["test", "jenkins", "gitlab"]:
+raise ValueError(
+"Invalid value '{}' for 'install.flavor'".format(flavor)
+)
+
+# verify the optional [gitlab] section and its mandatory options
+if flavor == "gitlab":
+Config._validate_section(config, "gitlab", ["runner_secret"])
+
+def _update(self, values):
+self.values["install"].update(values["install"])
+
+if values.get("gitlab", None):
+self.values["gitlab"].update(values["gitlab"])
+
 def get_flavor(self):
 flavor_file = self._get_config_file("flavor")
 
-- 
2.25.3



[libvirt-ci PATCH 08/12] lcitool: Drop the get_flavor() method

2020-05-06 Thread Erik Skultety
We can now access this value directly in the config dictionary.

Signed-off-by: Erik Skultety 
---
 guests/lcitool | 36 
 1 file changed, 4 insertions(+), 32 deletions(-)

diff --git a/guests/lcitool b/guests/lcitool
index 818ae82..9c1a722 100755
--- a/guests/lcitool
+++ b/guests/lcitool
@@ -211,37 +211,12 @@ class Config:
 if values.get("gitlab", None):
 self.values["gitlab"].update(values["gitlab"])
 
-def get_flavor(self):
-flavor_file = self._get_config_file("flavor")
-
-try:
-with open(flavor_file, "r") as infile:
-flavor = infile.readline().strip()
-except Exception:
-# If the flavor has not been configured, we choose the default
-# and store it on disk to ensure consistent behavior from now on
-flavor = "test"
-try:
-with open(flavor_file, "w") as infile:
-infile.write("{}\n".format(flavor))
-except Exception as ex:
-raise Exception(
-"Can't write flavor file ({}): {}".format(
-flavor_file, ex
-)
-)
-
-if flavor not in ["test", "jenkins", "gitlab"]:
-raise Exception("Invalid flavor '{}'".format(flavor))
-
-return flavor
-
 def get_vault_password_file(self):
 vault_pass_file = None
 
 # The vault password is only needed for the jenkins flavor, but in
 # that case we want to make sure there's *something* in there
-if self.get_flavor() == "jenkins":
+if self.values["install"]["flavor"] == "jenkins":
 vault_pass_file = self._get_config_file("vault-password")
 
 try:
@@ -274,7 +249,7 @@ class Config:
 return root_pass_file
 
 def get_gitlab_runner_token_file(self):
-if self.get_flavor() != "gitlab":
+if self.values["install"]["flavor"] != "gitlab":
 return None
 
 gitlab_runner_token_file = self._get_config_file("gitlab-runner-token")
@@ -293,7 +268,7 @@ class Config:
 return gitlab_runner_token_file
 
 def get_gitlab_url_file(self):
-if self.get_flavor() != "gitlab":
+if self.values["install"]["flavor"] != "gitlab":
 return None
 
 gitlab_url_file = self._get_config_file("gitlab-url")
@@ -540,7 +515,6 @@ class Application:
 def _execute_playbook(self, playbook, hosts, projects, git_revision):
 base = Util.get_base()
 
-flavor = self._config.get_flavor()
 vault_pass_file = self._config.get_vault_password_file()
 root_pass_file = self._config.get_root_password_file()
 gitlab_url_file = self._config.get_gitlab_url_file()
@@ -618,8 +592,6 @@ class Application:
 def _action_install(self, args):
 base = Util.get_base()
 
-flavor = self._config.get_flavor()
-
 for host in self._inventory.expand_pattern(args.hosts):
 facts = self._inventory.get_facts(host)
 
@@ -715,7 +687,7 @@ class Application:
 cmd.append("--noautoconsole")
 
 # Only configure autostart for the guest for the jenkins flavor
-if flavor == "jenkins":
+if self._config.values["install"]["flavor"] == "jenkins":
 cmd += ["--autostart"]
 
 try:
-- 
2.25.3



[libvirt-ci PATCH 12/12] guests: README: Document the existence and usage of config.toml

2020-05-06 Thread Erik Skultety
Signed-off-by: Erik Skultety 
---
 guests/README.markdown | 18 ++
 1 file changed, 10 insertions(+), 8 deletions(-)

diff --git a/guests/README.markdown b/guests/README.markdown
index 7dbefed..a58c5cb 100644
--- a/guests/README.markdown
+++ b/guests/README.markdown
@@ -64,13 +64,15 @@ branches out of those with
 Host setup
 --
 
-Ansible and `virt-install` need to be available on the host.
+`ansible` and `virt-install` need to be available on the host, the former can
+be either installed system-wide using your package manager or using by `pip`
+(see the provided requirements.txt file). The latter can only be installed with
+your package manager as `virt-install` is not distributed via PyPI.
 
-Before you can start bringing up guests, you'll have to store your
-site-specific root password in the `~/.config/lcitool/root-password` file.
-This password will only be necessary for serial console access in case
-something goes horribly wrong; for day to day operations, SSH key
-authentication will be used instead.
+Before you can start bringing up guests, you need to create (ideally by
+copying the `config.yaml` template) ~/.config/lcitool/config.yaml and set at
+least the options marked as "(mandatory)" depending on the flavor (`test`,
+`jenkins`, `gitlab`) you wish to use with your machines.
 
 Ansible expects to be able to connect to the guests by name: installing and
 enabling the [libvirt NSS plugin](https://wiki.libvirt.org/page/NSS_module)
@@ -123,8 +125,8 @@ Jenkins CI use
 --
 
 You'll need to configure `lcitool` to use the `jenkins` flavor for
-guests: to do so, just write `jenkins` in the `~/.config/lcitool/flavor`
-file.
+guests. To do so, simply set the flavor to 'jenkins' in
+`~/.config/lcitool/config.yaml`.
 
 Once a guest has been prepared, you'll be able to log in as root either
 via SSH (your public key will have been authorized) or on the serial
-- 
2.25.3



[libvirt-ci PATCH 04/12] lcitool: Use a temporary JSON file to pass extra variables

2020-05-06 Thread Erik Skultety
This patch is a pre-requisite config file consolidation. Currently we've
got a number of files which serve as a configuration either to the
lcitool itself or to the ansible playbooks (majority).  Once we replace
these with a single global lcitool config, we'd end up passing tokens
(potentially some passwords) as ansible extra variables bare naked on
the cmdline. In order to prevent this security flaw use temporary JSON
file holding all these extra variables and pass it as follows:

$ ansible-playbook --extra-vars @extra_vars.json playbook.yml

Signed-off-by: Erik Skultety 
---
 guests/lcitool | 15 +++
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/guests/lcitool b/guests/lcitool
index 759e604..2dca8b5 100755
--- a/guests/lcitool
+++ b/guests/lcitool
@@ -504,11 +504,13 @@ class Application:
 git_remote = "default"
 git_branch = "master"
 
+tempdir = tempfile.TemporaryDirectory(prefix="lcitool")
+
 ansible_cfg_path = os.path.join(base, "ansible.cfg")
 playbook_base = os.path.join(base, "playbooks", playbook)
 playbook_path = os.path.join(playbook_base, "main.yml")
-
-extra_vars = json.dumps({
+extra_vars_path = os.path.join(tempdir.name, "extra_vars.json")
+extra_vars = {
 "base": base,
 "playbook_base": playbook_base,
 "root_password_file": root_pass_file,
@@ -518,7 +520,10 @@ class Application:
 "git_branch": git_branch,
 "gitlab_url_file": gitlab_url_file,
 "gitlab_runner_token_file": gitlab_runner_token_file,
-})
+}
+
+with open(extra_vars_path, "w") as fp:
+json.dump(extra_vars, fp)
 
 ansible_playbook = distutils.spawn.find_executable("ansible-playbook")
 if ansible_playbook is None:
@@ -527,7 +532,7 @@ class Application:
 cmd = [
 ansible_playbook,
 "--limit", ansible_hosts,
-"--extra-vars", extra_vars,
+"--extra-vars", "@" + extra_vars_path,
 ]
 
 # Provide the vault password if available
@@ -546,6 +551,8 @@ class Application:
 except Exception as ex:
 raise Exception(
 "Failed to run {} on '{}': {}".format(playbook, hosts, ex))
+finally:
+tempdir.cleanup()
 
 def _action_hosts(self, args):
 for host in self._inventory.expand_pattern("all"):
-- 
2.25.3



[libvirt-ci PATCH 09/12] lcitool: Drop the get_root_password_file() method

2020-05-06 Thread Erik Skultety
We can now access this value directly in the config dictionary.

Signed-off-by: Erik Skultety 
---
 guests/lcitool | 17 -
 1 file changed, 17 deletions(-)

diff --git a/guests/lcitool b/guests/lcitool
index 9c1a722..0725be9 100755
--- a/guests/lcitool
+++ b/guests/lcitool
@@ -232,22 +232,6 @@ class Config:
 
 return vault_pass_file
 
-def get_root_password_file(self):
-root_pass_file = self._get_config_file("root-password")
-
-try:
-with open(root_pass_file, "r") as infile:
-if not infile.readline().strip():
-raise ValueError
-except Exception as ex:
-raise Exception(
-"Missing or invalid root password file ({}): {}".format(
-root_pass_file, ex
-)
-)
-
-return root_pass_file
-
 def get_gitlab_runner_token_file(self):
 if self.values["install"]["flavor"] != "gitlab":
 return None
@@ -516,7 +500,6 @@ class Application:
 base = Util.get_base()
 
 vault_pass_file = self._config.get_vault_password_file()
-root_pass_file = self._config.get_root_password_file()
 gitlab_url_file = self._config.get_gitlab_url_file()
 gitlab_runner_token_file = self._config.get_gitlab_runner_token_file()
 
-- 
2.25.3



[libvirt-ci PATCH 10/12] lcitool: Drop the gitlab-related getter methods

2020-05-06 Thread Erik Skultety
We can now access the values directly in the config dictionary.

Signed-off-by: Erik Skultety 
---
 guests/lcitool | 40 
 1 file changed, 40 deletions(-)

diff --git a/guests/lcitool b/guests/lcitool
index 0725be9..6bbe314 100755
--- a/guests/lcitool
+++ b/guests/lcitool
@@ -232,44 +232,6 @@ class Config:
 
 return vault_pass_file
 
-def get_gitlab_runner_token_file(self):
-if self.values["install"]["flavor"] != "gitlab":
-return None
-
-gitlab_runner_token_file = self._get_config_file("gitlab-runner-token")
-
-try:
-with open(gitlab_runner_token_file, "r") as infile:
-if not infile.readline().strip():
-raise ValueError
-except Exception as ex:
-raise Exception(
-"Missing or invalid GitLab runner token file ({}): {}".format(
-gitlab_runner_token_file, ex
-)
-)
-
-return gitlab_runner_token_file
-
-def get_gitlab_url_file(self):
-if self.values["install"]["flavor"] != "gitlab":
-return None
-
-gitlab_url_file = self._get_config_file("gitlab-url")
-
-try:
-with open(gitlab_url_file, "r") as infile:
-if not infile.readline().strip():
-raise ValueError
-except Exception as ex:
-raise Exception(
-"Missing or invalid GitLab url file ({}): {}".format(
-gitlab_url_file, ex
-)
-)
-
-return gitlab_url_file
-
 
 class Inventory:
 
@@ -500,8 +462,6 @@ class Application:
 base = Util.get_base()
 
 vault_pass_file = self._config.get_vault_password_file()
-gitlab_url_file = self._config.get_gitlab_url_file()
-gitlab_runner_token_file = self._config.get_gitlab_runner_token_file()
 
 ansible_hosts = ",".join(self._inventory.expand_pattern(hosts))
 selected_projects = self._projects.expand_pattern(projects)
-- 
2.25.3



[libvirt-ci PATCH 11/12] config: Move the virt-install settings from install.yml to the config

2020-05-06 Thread Erik Skultety
Looking into the future where we're able to generate cloudinit images,
we'll need to configure some of the install options which is currently
not possible without editing the install.yml group vars file within the
repository. That is suboptimal, so let's move the install options to
the global config under the 'install' section so that further tweaking
is possible (but explicitly discouraged at the same time).

Signed-off-by: Erik Skultety 
---
 guests/config.yaml | 17 +
 guests/lcitool | 28 +++-
 2 files changed, 28 insertions(+), 17 deletions(-)

diff --git a/guests/config.yaml b/guests/config.yaml
index 291fd57..5f750e7 100644
--- a/guests/config.yaml
+++ b/guests/config.yaml
@@ -15,6 +15,23 @@ install:
   # instead. (Mandatory)
   #root_password:
 
+  # Settings mapping to the virt-install options - see virt-install(1).
+  # It is strongly recommended that you keep the following at their default
+  # values to produce machines which conform to the upstream libvirt standard,
+  # unless you have a reason to do otherwise.
+  #
+  # Sizes are expressed in GiB.
+  #
+  virt_type: kvm
+  arch: x86_64
+  machine: pc
+  cpu_model: host-passthrough
+  vcpus: 2
+  memory_size: 2
+  disk_size: 15
+  storage_pool: default
+  network: default
+
 gitlab:
   # GitLab runner agent registration options, applies only if flavor == 
'gitlab'.
   url: https://gitlab.com
diff --git a/guests/lcitool b/guests/lcitool
index 6bbe314..91582cb 100755
--- a/guests/lcitool
+++ b/guests/lcitool
@@ -534,23 +534,17 @@ class Application:
 
 def _action_install(self, args):
 base = Util.get_base()
+config = self._config
 
 for host in self._inventory.expand_pattern(args.hosts):
 facts = self._inventory.get_facts(host)
 
-# Both memory size and disk size are stored as GiB in the
-# inventory, but virt-install expects the disk size in GiB
-# and the memory size in *MiB*, so perform conversion here
-memory_arg = str(int(facts["install_memory_size"]) * 1024)
-
-vcpus_arg = str(facts["install_vcpus"])
-
 disk_arg = "size={},pool={},bus=virtio".format(
-facts["install_disk_size"],
-facts["install_storage_pool"],
+config.values["install"]["disk_size"],
+config.values["install"]["storage_pool"],
 )
 network_arg = "network={},model=virtio".format(
-facts["install_network"],
+config.values["install"]["network"],
 )
 
 # Different operating systems require different configuration
@@ -610,12 +604,12 @@ class Application:
 virt_install,
 "--name", host,
 "--location", facts["install_url"],
-"--virt-type", facts["install_virt_type"],
-"--arch", facts["install_arch"],
-"--machine", facts["install_machine"],
-"--cpu", facts["install_cpu_model"],
-"--vcpus", vcpus_arg,
-"--memory", memory_arg,
+"--virt-type", config.values["install"]["virt_type"],
+"--arch", config.values["install"]["arch"],
+"--machine", config.values["install"]["machine"],
+"--cpu", config.values["install"]["cpu_model"],
+"--vcpus", str(config.values["install"]["vcpus"]),
+"--memory", str(config.values["install"]["memory_size"] * 
1024),
 "--disk", disk_arg,
 "--network", network_arg,
 "--graphics", "none",
@@ -630,7 +624,7 @@ class Application:
 cmd.append("--noautoconsole")
 
 # Only configure autostart for the guest for the jenkins flavor
-if self._config.values["install"]["flavor"] == "jenkins":
+if config.values["install"]["flavor"] == "jenkins":
 cmd += ["--autostart"]
 
 try:
-- 
2.25.3



[libvirt-ci PATCH 07/12] lcitool: Update the config values with internal playbook settings

2020-05-06 Thread Erik Skultety
So, the idea is to pass our YAML config to the Ansible playbooks as
extra vars. However, not all variables we need to pass on to Ansible
are exposed in the config (and they shouldn't be). Update the config
values dictionary with these variables before passing on to Ansible.

Signed-off-by: Erik Skultety 
---
 guests/lcitool| 10 ++
 guests/playbooks/build/main.yml   |  2 +-
 guests/playbooks/update/main.yml  |  6 ++--
 guests/playbooks/update/tasks/gitlab.yml  |  4 +--
 guests/playbooks/update/tasks/kludges.yml |  2 +-
 guests/playbooks/update/tasks/users.yml   | 42 +++
 6 files changed, 30 insertions(+), 36 deletions(-)

diff --git a/guests/lcitool b/guests/lcitool
index 07d0b3c..818ae82 100755
--- a/guests/lcitool
+++ b/guests/lcitool
@@ -567,20 +567,16 @@ class Application:
 playbook_base = os.path.join(base, "playbooks", playbook)
 playbook_path = os.path.join(playbook_base, "main.yml")
 extra_vars_path = os.path.join(tempdir.name, "extra_vars.json")
-extra_vars = {
+self._config.values.update({
 "base": base,
 "playbook_base": playbook_base,
-"root_password_file": root_pass_file,
-"flavor": flavor,
 "selected_projects": selected_projects,
 "git_remote": git_remote,
 "git_branch": git_branch,
-"gitlab_url_file": gitlab_url_file,
-"gitlab_runner_token_file": gitlab_runner_token_file,
-}
+})
 
 with open(extra_vars_path, "w") as fp:
-json.dump(extra_vars, fp)
+json.dump(self._config.values, fp)
 
 ansible_playbook = distutils.spawn.find_executable("ansible-playbook")
 if ansible_playbook is None:
diff --git a/guests/playbooks/build/main.yml b/guests/playbooks/build/main.yml
index 8abda67..462764b 100644
--- a/guests/playbooks/build/main.yml
+++ b/guests/playbooks/build/main.yml
@@ -1,6 +1,6 @@
 ---
 - hosts: all
-  remote_user: '{{ flavor }}'
+  remote_user: '{{ install.flavor }}'
 
   vars_files:
 - '{{ playbook_base }}/jobs/defaults.yml'
diff --git a/guests/playbooks/update/main.yml b/guests/playbooks/update/main.yml
index 371e53d..1b97027 100644
--- a/guests/playbooks/update/main.yml
+++ b/guests/playbooks/update/main.yml
@@ -45,7 +45,7 @@
   vars:
 project: jenkins
   when:
-- flavor == "jenkins"
+- install.flavor == "jenkins"
 
 # Configure environment. Needs to happen after installing packages
 - include: '{{ playbook_base }}/tasks/kludges.yml'
@@ -57,9 +57,9 @@
 # Configure the Jenkins agent
 - include: '{{ playbook_base }}/tasks/jenkins.yml'
   when:
-- flavor == 'jenkins'
+- install.flavor == 'jenkins'
 
 # Install the Gitlab runner agent
 - include: '{{ playbook_base }}/tasks/gitlab.yml'
   when:
-- flavor == 'gitlab'
+- install.flavor == 'gitlab'
diff --git a/guests/playbooks/update/tasks/gitlab.yml 
b/guests/playbooks/update/tasks/gitlab.yml
index f07279c..07a376c 100644
--- a/guests/playbooks/update/tasks/gitlab.yml
+++ b/guests/playbooks/update/tasks/gitlab.yml
@@ -1,8 +1,6 @@
 ---
 - name: Define gitlab-related facts
   set_fact:
-gitlab_url: '{{ lookup("file", gitlab_url_file) }}'
-gitlab_runner_secret: '{{ lookup("file", gitlab_runner_token_file) }}'
 gitlab_runner_download_url: 
https://gitlab-runner-downloads.s3.amazonaws.com/latest/binaries/gitlab-runner-{{
 ansible_system|lower }}-amd64
 gitlab_runner_config_dir: '/etc/gitlab-runner'
 
@@ -14,7 +12,7 @@
 force: yes
 
 - name: Register the gitlab-runner agent
-  shell: 'gitlab-runner register --non-interactive --config "{{ 
gitlab_runner_config_dir }}/config.toml" --registration-token "{{ 
gitlab_runner_secret }}" --url "{{ gitlab_url }}" --executor shell --tag-list 
"{{ os.name|lower }}-{{ os.version }}"'
+  shell: 'gitlab-runner register --non-interactive --config "{{ 
gitlab_runner_config_dir }}/config.toml" --registration-token "{{ 
gitlab.runner_secret }}" --url "{{ gitlab.url }}" --executor shell --tag-list 
"{{ os.name|lower }}-{{ os.version }}"'
   args:
 creates: '{{ gitlab_runner_config_dir }}/config.toml'
 
diff --git a/guests/playbooks/update/tasks/kludges.yml 
b/guests/playbooks/update/tasks/kludges.yml
index 96fe1a5..33c6532 100644
--- a/guests/playbooks/update/tasks/kludges.yml
+++ b/guests/playbooks/update/tasks/kludges.yml
@@ -12,7 +12,7 @@
 group: wheel
   when:
 - os.name == 'FreeBSD'
-- flavor == "jenkins"
+- install.flavor == "jenkins"
 
 # FreeBSD compiles bash without defining SSH_SOURCE_BASHRC, which means
 # it won't try to detect when it's spawned by ssh and source ~/.bashrc
diff --git a/guests/playbooks/update/tasks/users.yml 
b/guests/playbooks/update/tasks/users.yml
index 5c6ce8f..bc3cc11 100644
--- a/guests/playbooks/update/tasks/users.yml
+++ b/guests/playbooks/update/tasks/users.yml
@@ -2,7 

[libvirt-ci PATCH 00/12] Introduce a new global YAML config file for lcitool

2020-05-06 Thread Erik Skultety
This series is trying to consolidate the number of config files we currently
recognize under ~/.config/lcitool to a single global YAML config file. Thanks
to this effort we can expose more seetings than we previously could which will
come handy in terms of generating cloudinit images for OpenStack.

Patches 1-4 patches are just a little extra - not heavily related to the series
Patches 1-3 (ACKed) only cosmetical changes (like moving requirements.txt)

Since RFC:
- replaced TOML with YAML which simplified some aspects of the code, thanks
Andrea
- instead of hardcoding the default values, the config within the repo is used
as a template and overriden with user-selected options

Erik Skultety (12):
  requirements: Introduce a requirements.txt file
  lcitool: Decrease the indent when creating a tempdir for initrd
injection
  lcitool: Prefer tempfile's native wrappers over low level primitives
  lcitool: Use a temporary JSON file to pass extra variables
  config: Introduce a new global config.yaml configuration file
  lcitool: Introduce methods to load and validate the YAML config
  lcitool: Update the config values with internal playbook settings
  lcitool: Drop the get_flavor() method
  lcitool: Drop the get_root_password_file() method
  lcitool: Drop the gitlab-related getter methods
  config: Move the virt-install settings from install.yml to the config
  guests: README: Document the existence and usage of config.toml

 guests/README.markdown|  18 +-
 guests/config.yaml|  40 +
 guests/lcitool| 192 +-
 guests/playbooks/build/main.yml   |   2 +-
 guests/playbooks/update/main.yml  |   6 +-
 guests/playbooks/update/tasks/gitlab.yml  |   4 +-
 guests/playbooks/update/tasks/kludges.yml |   2 +-
 guests/playbooks/update/tasks/users.yml   |  42 ++---
 guests/requirements.txt   |   2 +
 9 files changed, 159 insertions(+), 149 deletions(-)
 create mode 100644 guests/config.yaml
 create mode 100644 guests/requirements.txt

-- 
2.25.3




[libvirt-ci PATCH 03/12] lcitool: Prefer tempfile's native wrappers over low level primitives

2020-05-06 Thread Erik Skultety
Rather than requiring shutil module to get rid of the temporary
directory we're creating for virt-install, let's use the
TemporaryDirectory method instead which returns a file-like object which
can be used to clean up the standard Python way.
Although the internal exit handlers will take care of closing the
temporary directories (and thus removing their contents) automatically,
let's be explicit anyway and use the 'finally' clause to clean these up
on both success and failure.

Signed-off-by: Erik Skultety 
Reviewed-by: Andrea Bolognani 
---
 guests/lcitool | 9 -
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/guests/lcitool b/guests/lcitool
index c8d0d9a..759e604 100755
--- a/guests/lcitool
+++ b/guests/lcitool
@@ -23,7 +23,6 @@ import json
 import os
 import platform
 import random
-import shutil
 import string
 import subprocess
 import sys
@@ -608,8 +607,8 @@ class Application:
 facts[option]
 )
 
-tempdir = tempfile.mkdtemp()
-initrd_inject = os.path.join(tempdir, install_config)
+tempdir = tempfile.TemporaryDirectory(prefix="lcitool")
+initrd_inject = os.path.join(tempdir.name, install_config)
 
 with open(initrd_inject, "w") as inject:
 inject.write(content)
@@ -663,8 +662,8 @@ class Application:
 subprocess.check_call(cmd)
 except Exception as ex:
 raise Exception("Failed to install '{}': {}".format(host, ex))
-
-shutil.rmtree(tempdir, ignore_errors=True)
+finally:
+tempdir.cleanup()
 
 def _action_update(self, args):
 self._execute_playbook("update", args.hosts, args.projects,
-- 
2.25.3



[libvirt-ci PATCH 02/12] lcitool: Decrease the indent when creating a tempdir for initrd injection

2020-05-06 Thread Erik Skultety
The 'with' statement doesn't define a new code block [1], thus no local
namespace is created. Therefore, we can still access the @content
variable outside of the 'with' block. So, there's really no need to
hold the @initrd_template file open longer than necessary (not that it
would be a big deal anyway).

[1] https://docs.python.org/3.7/reference/executionmodel.html

Signed-off-by: Erik Skultety 
Reviewed-by: Andrea Bolognani 
---
 guests/lcitool | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/guests/lcitool b/guests/lcitool
index ab3b95f..c8d0d9a 100755
--- a/guests/lcitool
+++ b/guests/lcitool
@@ -608,11 +608,11 @@ class Application:
 facts[option]
 )
 
-tempdir = tempfile.mkdtemp()
-initrd_inject = os.path.join(tempdir, install_config)
+tempdir = tempfile.mkdtemp()
+initrd_inject = os.path.join(tempdir, install_config)
 
-with open(initrd_inject, "w") as inject:
-inject.write(content)
+with open(initrd_inject, "w") as inject:
+inject.write(content)
 
 # preseed files must use a well-known name to be picked up by
 # d-i; for kickstart files, we can use whatever name we please
-- 
2.25.3



[libvirt-ci PATCH 05/12] config: Introduce a new global config.yaml configuration file

2020-05-06 Thread Erik Skultety
Rather than having the configuration options split across multiple files
(root-password, flavor, gitlab-url, gitlab-runner-token, ...), let's
consolidate these settings into a global config file.

The YAML format has been chosen simply because it's the native data
format in Ansible and thus plays very nicely when accessing variables
within Ansible playbooks.

Signed-off-by: Erik Skultety 
---
 guests/config.yaml | 23 +++
 1 file changed, 23 insertions(+)
 create mode 100644 guests/config.yaml

diff --git a/guests/config.yaml b/guests/config.yaml
new file mode 100644
index 000..291fd57
--- /dev/null
+++ b/guests/config.yaml
@@ -0,0 +1,23 @@
+---
+# Configuration file for lcitool
+
+install:
+  # Installation flavor determining the target environment for the VM:
+  #
+  # test - VMs suitable for local testing, 'test' has passwordless sudo
+  # jenkins - VMs pluggable to a jenkins environment
+  # gitlab - VMs ready to be plugged to a GitLab environment
+  flavor: test
+
+  # Initial root password to be set by ansible on the appliance. This password
+  # will only be necessary for serial console access in case something goes
+  # horribly wrong, for all other use cases, SSH key authentication will be 
used
+  # instead. (Mandatory)
+  #root_password:
+
+gitlab:
+  # GitLab runner agent registration options, applies only if flavor == 
'gitlab'.
+  url: https://gitlab.com
+
+  # GitLab runner registration token. (Mandatory)
+  #runner_secret:
-- 
2.25.3



[libvirt PATCH v2 07/10] qemu: block: add function to launch all prepared blockcommits

2020-05-06 Thread Pavel Mores
This is the second phase of snapshot deletion.  We have all information
necessary to delete the snapshot by running blockcommits and we haven't
detected any problems that would make the deletion unsafe.

Now we just launch the blockcommits in parallel.

Signed-off-by: Pavel Mores 
---
 src/qemu/qemu_driver.c | 35 +++
 1 file changed, 35 insertions(+)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index dc1176bd9c..35b7fb69d5 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -154,6 +154,16 @@ static int qemuOpenFileAs(uid_t fallback_uid, gid_t 
fallback_gid,
 
 static virQEMUDriverPtr qemu_driver;
 
+static int
+qemuDomainBlockCommitCommon(virDomainObjPtr vm,
+virQEMUDriverPtr driver,
+virDomainDiskDefPtr disk,
+virStorageSourcePtr baseSource,
+virStorageSourcePtr topSource,
+virStorageSourcePtr topParentSource,
+unsigned long bandwidth,
+unsigned int flags);
+
 static int
 qemuDomainBlockCommitImpl(virDomainObjPtr vm,
   virQEMUDriverPtr driver,
@@ -16906,6 +16916,31 @@ 
qemuDomainSnapshotDeleteExternalGetJobDescriptors(virDomainObjPtr vm,
 }
 
 
+static int
+qemuDomainSnapshotDeleteExternalLaunchJobs(virDomainObjPtr vm,
+   virQEMUDriverPtr driver,
+   const virBlockCommitDesc 
*blockCommitDescs,
+   int numDescs)
+{
+size_t i;
+
+for (i = 0; i < numDescs; i++) {
+virDomainDiskDefPtr disk = blockCommitDescs[i].disk;
+virStorageSourcePtr baseSource = blockCommitDescs[i].baseSource;
+virStorageSourcePtr topSource = blockCommitDescs[i].topSource;
+virStorageSourcePtr topParentSource = 
blockCommitDescs[i].topParentSource;
+int blockCommitFlags = blockCommitDescs[i].blockCommitFlags;
+
+if (qemuDomainBlockCommitCommon(vm, driver, disk, baseSource,
+topSource, topParentSource,
+0, blockCommitFlags) < 0)
+return -1;
+}
+
+return 0;
+}
+
+
 static int
 qemuDomainSnapshotDelete(virDomainSnapshotPtr snapshot,
  unsigned int flags)
-- 
2.24.1



[libvirt PATCH v2 00/10] qemu: block: basic implementation of deletion of external snapshots

2020-05-06 Thread Pavel Mores
Deleting external snapshots has been unimplemented so far.  This series aims
to enable limited functionality in that direction, handling just the common
cases for now.  The intention is to subsequently build upon this to eventually
cover the more complex/exotic cases as well.

It works by blockcommitting the snapshot to be deleted into its parent.
Handles both deleting children as well and deleting children only (by
committing the children into the snapshot referred to by snapshot-delete
argument).  If the necessary block commit operations turns out to be active
(the snapshot referred to by snapshot-delete argument is current, or
deleting children is requested) pivot is performed as well.

This implemetation is limited to the straightforward case which assumes no
branching snapshot chains below the snapshot to be deleted, and the current
snapshot has to be the leaf of the (linear) chain starting at the snapshot
to be deleted.  These requirements are checked and enforced at the top of
qemuDomainSnapshotDeleteExternal().  They might even be too restrictive for
the case where deletion of children is not requested as in that case,
requiring that the parent of the snapshot to be deleted not be a branching
point in snapshot tree should be enough.

The above limitations do not appear too severe under the current state of
matters where a major source of branching snapshot structures,
snapshot-revert, is not even implemented for external snapshots yet.  The
only other known cause of branching in external snapshots thus seems to be
if a user creates branching by manually creating snapshot images and
metadata and applies them using snapshot-create --redefine.

Also, the snapshot images involved basically have to be files.  This does
not seem overly limiting either, at least for the time being, because it's
a limitation shared with the underlying blockcommit code.  Just as the
existing code, the new code ultimately relies on
virStorageFileChainLookup() as its image comparison and look-up engine and
is affected by its limitaions.

At any rate, this work should be understood as just a first step to a full
support of deleting external snapshots.

The first 5 commits of this series are just refactors used by the last 5
commits which actually implement snapshot deletion.  However, the
qemuDomainBlockCommit() refactor (the initial 2 commits of this series) was
affected by a rather hairy merge on rebasing to the current master and
although I tried to do my best to get the merge right I still feel a
careful review is in order for these two commits.

Pavel Mores (10):
  qemu: block: factor implementation out of qemuDomainBlockCommit()
  qemu: block: refactor blockcommit so that it's callable with storage
sources
  qemu: block: factor implementation out of qemuDomainBlockJobAbort()
  conf: rename virDomainMomentFindLeaf() to
virDomainMomentObjListFindLeaf()
  conf: add virDomainMomentFindLeaf() which operates on
virDomainMomentObjPtr
  qemu: block: add function to collect blockcommit params and verify
them
  qemu: block: add function to launch all prepared blockcommits
  qemu: block: add function to wait for blockcommits and collect results
  qemu: block: add external snapshot-delete top-level algorithm
  qemu: block: add actual invocation of external snapshot-delete

 src/conf/virdomaincheckpointobjlist.c |   2 +-
 src/conf/virdomainmomentobjlist.c |  27 +-
 src/conf/virdomainmomentobjlist.h |   3 +-
 src/libvirt_private.syms  |   1 +
 src/qemu/qemu_driver.c| 552 ++
 5 files changed, 485 insertions(+), 100 deletions(-)

-- 
2.24.1



[libvirt PATCH v2 01/10] qemu: block: factor implementation out of qemuDomainBlockCommit()

2020-05-06 Thread Pavel Mores
We'll need blockcommit to be callable from within the QEMU driver where we
have no virDomain instance available, just virDomainObj.

Signed-off-by: Pavel Mores 
---
 src/qemu/qemu_driver.c | 78 --
 1 file changed, 52 insertions(+), 26 deletions(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 1c7c87128d..b642b24fa2 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -154,6 +154,15 @@ static int qemuOpenFileAs(uid_t fallback_uid, gid_t 
fallback_gid,
 
 static virQEMUDriverPtr qemu_driver;
 
+static int
+qemuDomainBlockCommitImpl(virDomainObjPtr vm,
+  virQEMUDriverPtr driver,
+  const char *path,
+  const char *base,
+  const char *top,
+  unsigned long bandwidth,
+  unsigned int flags);
+
 /* Looks up the domain object from snapshot and unlocks the
  * driver. The returned domain object is locked and ref'd and the
  * caller must call virDomainObjEndAPI() on it. */
@@ -18431,18 +18440,16 @@ qemuDomainBlockPull(virDomainPtr dom, const char 
*path, unsigned long bandwidth,
 return qemuDomainBlockPullCommon(vm, path, NULL, bandwidth, flags);
 }
 
-
 static int
-qemuDomainBlockCommit(virDomainPtr dom,
-  const char *path,
-  const char *base,
-  const char *top,
-  unsigned long bandwidth,
-  unsigned int flags)
+qemuDomainBlockCommitImpl(virDomainObjPtr vm,
+  virQEMUDriverPtr driver,
+  const char *path,
+  const char *base,
+  const char *top,
+  unsigned long bandwidth,
+  unsigned int flags)
 {
-virQEMUDriverPtr driver = dom->conn->privateData;
-qemuDomainObjPrivatePtr priv;
-virDomainObjPtr vm = NULL;
+qemuDomainObjPrivatePtr priv = vm->privateData;
 const char *device = NULL;
 const char *jobname = NULL;
 int ret = -1;
@@ -18466,22 +18473,6 @@ qemuDomainBlockCommit(virDomainPtr dom,
 g_autoptr(virJSONValue) bitmapDisableActions = NULL;
 VIR_AUTOSTRINGLIST bitmapDisableList = NULL;
 
-virCheckFlags(VIR_DOMAIN_BLOCK_COMMIT_SHALLOW |
-  VIR_DOMAIN_BLOCK_COMMIT_ACTIVE |
-  VIR_DOMAIN_BLOCK_COMMIT_RELATIVE |
-  VIR_DOMAIN_BLOCK_COMMIT_DELETE |
-  VIR_DOMAIN_BLOCK_COMMIT_BANDWIDTH_BYTES, -1);
-
-if (!(vm = qemuDomainObjFromDomain(dom)))
-goto cleanup;
-priv = vm->privateData;
-
-if (virDomainBlockCommitEnsureACL(dom->conn, vm->def) < 0)
-goto cleanup;
-
-if (qemuDomainObjBeginJob(driver, vm, QEMU_JOB_MODIFY) < 0)
-goto cleanup;
-
 if (virDomainObjCheckActive(vm) < 0)
 goto endjob;
 
@@ -18730,6 +18721,40 @@ qemuDomainBlockCommit(virDomainPtr dom,
 virErrorRestore(_err);
 }
 qemuBlockJobStartupFinalize(vm, job);
+
+return ret;
+}
+
+
+static int
+qemuDomainBlockCommit(virDomainPtr dom,
+  const char *path,
+  const char *base,
+  const char *top,
+  unsigned long bandwidth,
+  unsigned int flags)
+{
+virQEMUDriverPtr driver = dom->conn->privateData;
+virDomainObjPtr vm = NULL;
+int ret = -1;
+
+virCheckFlags(VIR_DOMAIN_BLOCK_COMMIT_SHALLOW |
+  VIR_DOMAIN_BLOCK_COMMIT_ACTIVE |
+  VIR_DOMAIN_BLOCK_COMMIT_RELATIVE |
+  VIR_DOMAIN_BLOCK_COMMIT_DELETE |
+  VIR_DOMAIN_BLOCK_COMMIT_BANDWIDTH_BYTES, -1);
+
+if (!(vm = qemuDomainObjFromDomain(dom)))
+goto cleanup;
+
+if (virDomainBlockCommitEnsureACL(dom->conn, vm->def) < 0)
+goto cleanup;
+
+if (qemuDomainObjBeginJob(driver, vm, QEMU_JOB_MODIFY) < 0)
+goto cleanup;
+
+ret = qemuDomainBlockCommitImpl(vm, driver, path, base, top, bandwidth, 
flags);
+
 qemuDomainObjEndJob(driver, vm);
 
  cleanup:
@@ -18737,6 +18762,7 @@ qemuDomainBlockCommit(virDomainPtr dom,
 return ret;
 }
 
+
 static int
 qemuDomainOpenGraphics(virDomainPtr dom,
unsigned int idx,
-- 
2.24.1



[libvirt PATCH v2 08/10] qemu: block: add function to wait for blockcommits and collect results

2020-05-06 Thread Pavel Mores
This is the third phase of snapshot deletion.  Blockcommits to delete the
snapshot have been launched and now we can wait for them to finish, check
results and report errors if any.

Signed-off-by: Pavel Mores 
---
 src/qemu/qemu_driver.c | 59 ++
 1 file changed, 59 insertions(+)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 35b7fb69d5..a2629e9002 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -16941,6 +16941,65 @@ 
qemuDomainSnapshotDeleteExternalLaunchJobs(virDomainObjPtr vm,
 }
 
 
+static int
+qemuDomainSnapshotDeleteExternalWaitForJobs(virDomainObjPtr vm,
+virQEMUDriverPtr driver,
+const virBlockCommitDesc 
*blockCommitDescs,
+int numDescs)
+{
+size_t i;
+
+for (i = 0; i < numDescs; i++) {
+virDomainDiskDefPtr disk = blockCommitDescs[i].disk;
+bool isActive = blockCommitDescs[i].isActive;
+
+/* wait for the blockcommit job to finish (in particular, reach
+ * one of the finished QEMU_BLOCKJOB_STATE_* states)... */
+g_autoptr(qemuBlockJobData) job = NULL;
+
+if (!(job = qemuBlockJobDiskGetJob(disk))) {
+virReportError(VIR_ERR_OPERATION_INVALID,
+_("disk %s does not have an active block job"), 
disk->dst);
+return -1;
+}
+
+qemuBlockJobSyncBegin(job);
+qemuBlockJobUpdate(vm, job, QEMU_ASYNC_JOB_NONE);
+while (job->state != QEMU_BLOCKJOB_STATE_READY &&
+   job->state != QEMU_BLOCKJOB_STATE_FAILED &&
+   job->state != QEMU_BLOCKJOB_STATE_CANCELLED &&
+   job->state != QEMU_BLOCKJOB_STATE_COMPLETED) {
+
+if (virDomainObjWait(vm) < 0)
+return -1;
+qemuBlockJobUpdate(vm, job, QEMU_ASYNC_JOB_NONE);
+}
+qemuBlockJobSyncEnd(vm, job, QEMU_ASYNC_JOB_NONE);
+
+if ((isActive && job->state != QEMU_BLOCKJOB_STATE_READY) ||
+(!isActive && job->state != QEMU_BLOCKJOB_STATE_COMPLETED)) {
+virReportError(VIR_ERR_OPERATION_INVALID,
+_("blockcomit job failed for disk %s"), disk->dst);
+/* TODO Apr 30, 2020: how to handle this?  Bailing out doesn't
+ * seem an obvious option in this case as all blockjobs are now
+ * created and running - if any of them are to fail they will,
+ * regardless of whether we break here.  It might make more
+ * sense to continue and at least report all errors. */
+/*return -1;*/
+}
+
+/* ... and pivot if necessary */
+if (isActive) {
+if (qemuDomainBlockJobAbortImpl(driver, vm, disk->dst,
+VIR_DOMAIN_BLOCK_JOB_ABORT_PIVOT) 
< 0)
+return -1;
+}
+}
+
+return 0;
+}
+
+
 static int
 qemuDomainSnapshotDelete(virDomainSnapshotPtr snapshot,
  unsigned int flags)
-- 
2.24.1



[libvirt PATCH v2 02/10] qemu: block: refactor blockcommit so that it's callable with storage sources

2020-05-06 Thread Pavel Mores
So far, only paths could be used to specify blockcommit's base and top
images.  However, this is not general enough as paths have limitations
(most notably they can only work for file-based storage sources).

This commit preserves the path-based interface but factors out the core of
blockcommit implementation into a separate function that takes its base and
top as virStorageSources.  The path-based interface basically just converts
the paths into virStorageSource just as it was done before and calls the
virStorageSource-based implementation core.

Signed-off-by: Pavel Mores 
---
 src/qemu/qemu_driver.c | 108 +
 1 file changed, 65 insertions(+), 43 deletions(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index b642b24fa2..09300c1e90 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -18441,25 +18441,27 @@ qemuDomainBlockPull(virDomainPtr dom, const char 
*path, unsigned long bandwidth,
 }
 
 static int
-qemuDomainBlockCommitImpl(virDomainObjPtr vm,
-  virQEMUDriverPtr driver,
-  const char *path,
-  const char *base,
-  const char *top,
-  unsigned long bandwidth,
-  unsigned int flags)
+qemuDomainBlockCommitCommon(virDomainObjPtr vm,
+virQEMUDriverPtr driver,
+virDomainDiskDefPtr disk,
+virStorageSourcePtr baseSource,
+virStorageSourcePtr topSource,
+virStorageSourcePtr topParentSource,
+unsigned long bandwidth,
+unsigned int flags)
 {
 qemuDomainObjPrivatePtr priv = vm->privateData;
 const char *device = NULL;
 const char *jobname = NULL;
 int ret = -1;
-virDomainDiskDefPtr disk = NULL;
-virStorageSourcePtr topSource;
-unsigned int topIndex = 0;
-virStorageSourcePtr baseSource = NULL;
-unsigned int baseIndex = 0;
-virStorageSourcePtr top_parent = NULL;
 bool clean_access = false;
+/* TODO the following 2 are just for error reporting. Originally these
+ * could have been either paths or indexed identifiers (like 'vda[1]').
+ * Now the error reporting will always use paths instead of what the
+ * user originally specified.  Find out if this is fine, find a solution
+ * if it isn't. */
+const char *path = disk->src->path;
+const char *base = baseSource->path;
 g_autofree char *topPath = NULL;
 g_autofree char *basePath = NULL;
 g_autofree char *backingPath = NULL;
@@ -18473,9 +18475,6 @@ qemuDomainBlockCommitImpl(virDomainObjPtr vm,
 g_autoptr(virJSONValue) bitmapDisableActions = NULL;
 VIR_AUTOSTRINGLIST bitmapDisableList = NULL;
 
-if (virDomainObjCheckActive(vm) < 0)
-goto endjob;
-
 blockdev = virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_BLOCKDEV);
 
 /* Convert bandwidth MiB to bytes, if necessary */
@@ -18489,9 +18488,6 @@ qemuDomainBlockCommitImpl(virDomainObjPtr vm,
 speed <<= 20;
 }
 
-if (!(disk = qemuDomainDiskByName(vm->def, path)))
-goto endjob;
-
 if (virStorageSourceIsEmpty(disk->src)) {
 virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("disk %s has no source file to be committed"),
@@ -18511,14 +18507,6 @@ qemuDomainBlockCommitImpl(virDomainObjPtr vm,
 goto endjob;
 }
 
-if (!top || STREQ(top, disk->dst))
-topSource = disk->src;
-else if (virStorageFileParseChainIndex(disk->dst, top, ) < 0 ||
- !(topSource = virStorageFileChainLookup(disk->src, NULL,
- top, topIndex,
- _parent)))
-goto endjob;
-
 if (topSource == disk->src) {
 if (!virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_ACTIVE_COMMIT)) {
 virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
@@ -18546,13 +18534,6 @@ qemuDomainBlockCommitImpl(virDomainObjPtr vm,
 goto endjob;
 }
 
-if (!base && (flags & VIR_DOMAIN_BLOCK_COMMIT_SHALLOW))
-baseSource = topSource->backingStore;
-else if (virStorageFileParseChainIndex(disk->dst, base, ) < 0 ||
- !(baseSource = virStorageFileChainLookup(disk->src, topSource,
-  base, baseIndex, NULL)))
-goto endjob;
-
 if ((flags & VIR_DOMAIN_BLOCK_COMMIT_SHALLOW) &&
 baseSource != topSource->backingStore) {
 virReportError(VIR_ERR_INVALID_ARG,
@@ -18580,8 +18561,8 @@ qemuDomainBlockCommitImpl(virDomainObjPtr vm,
 goto endjob;
 }
 
-if (blockdev && top_parent &&
-qemuBlockUpdateRelativeBacking(vm, top_parent, disk->src) < 0)
+if (blockdev && topParentSource &&
+qemuBlockUpdateRelativeBacking(vm, 

[libvirt PATCH v2 06/10] qemu: block: add function to collect blockcommit params and verify them

2020-05-06 Thread Pavel Mores
Snapshot deletion is implemented as a three-phase process - first we
collect specifications of blockcommits used to perform the deletion and
run sanity checks to verify that the whole operation is reasonably safe,
then we launch the blockcommits and finally we wait for them to finish and
check the results.

This commit implements the first phase.  All information necessary to
launch and finish a blockcommit job per disk included in the snapshot is
collected in a blockcommit descriptor structure and checked to verify the
job makes sense and has a reasonable chance to succeed.  Broadly speaking,
the checks aim to ensure that the disks in the current running VM are the
same as they were when the snapshot was created.

Signed-off-by: Pavel Mores 
---
 src/qemu/qemu_driver.c | 154 +
 1 file changed, 154 insertions(+)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 6ffd53503b..dc1176bd9c 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -16752,6 +16752,160 @@ qemuDomainMomentReparentChildren(void *payload,
 }
 
 
+/* Blockcommit operation descriptor.  Holds data required to launch and
+ * conclude an individual blockcommit job.  Generic parameters
+ * (virDomainObjPtr, virQEMUDriverPtr) are not stored as they are assumed to be
+ * available at the point of blockcommit invocation. */
+
+typedef struct {
+virDomainDiskDefPtr disk;
+virStorageSourcePtr baseSource;
+virStorageSourcePtr topSource;
+virStorageSourcePtr topParentSource;
+int blockCommitFlags;
+bool isActive;  /* used to find out if pivot is needed to finish the job */
+} virBlockCommitDesc;
+
+/* Transforms a snapshot into an array of descriptors of blockcommit jobs
+ * required to delete the snapshot, one descriptor per affected disk.  Also
+ * runs sanity checks for each affected disk and each individual job to make
+ * sure the deletion is safe to perform.  Returns NULL if safety cannot be
+ * guaranteed.
+ *
+ * (A snapshot is considered safe to delete if, loosely speaking, we can be
+ * reasonably sure that all disks it touches are still those that were there
+ * when the snapshot was created.  For instance, a different disk might be
+ * attached to the VM under the same target name, or a disk included in the
+ * snapshot might be reattached to the VM under a different target name.  If
+ * any such thing happens between the times of snapshot creation and deletion,
+ * that shapshot would not be considered safe to delete.) */
+
+static virBlockCommitDesc *
+qemuDomainSnapshotDeleteExternalGetJobDescriptors(virDomainObjPtr vm,
+virDomainMomentObjPtr snap,
+unsigned int flags)
+{
+size_t i;
+bool isActive;
+virDomainSnapshotDefPtr snapdef = virDomainSnapshotObjGetDef(snap);
+virDomainMomentObjPtr parent = snap->parent;
+virDomainSnapshotDefPtr parentdef = virDomainSnapshotObjGetDef(parent);
+g_autofree virBlockCommitDesc *blockCommitDescs = 
g_new(virBlockCommitDesc, snapdef->ndisks);
+int blockCommitFlags = VIR_DOMAIN_BLOCK_COMMIT_DELETE;
+
+if (flags & (VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN |
+ VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN_ONLY)) {
+isActive = true;
+} else {
+isActive = snap == virDomainSnapshotGetCurrent(vm->snapshots);
+}
+
+if (isActive)
+blockCommitFlags |= VIR_DOMAIN_BLOCK_COMMIT_ACTIVE;
+
+for (i = 0; i < snapdef->ndisks; i++) {
+virDomainSnapshotDiskDefPtr snapDisk = &(snapdef->disks[i]);
+const char *diskName = snapDisk->name;
+virStorageSourcePtr baseSource = NULL;
+virStorageSourcePtr topSource = NULL;
+virStorageSourcePtr topParentSource = NULL;
+virDomainDiskDefPtr domDiskNow;
+virDomainDiskDefPtr domDiskThen = 
virDomainDiskByTarget(snapdef->parent.dom, diskName);
+virStorageSourcePtr snapSource = NULL;
+virStorageSourcePtr snapParentSource = NULL;
+unsigned int snapIndex;
+
+if (!(domDiskNow = qemuDomainDiskByName(vm->def, diskName))) {
+virReportError(VIR_ERR_OPERATION_INVALID,
+   _("can't delete %s, disk '%s' not found in running 
VM"),
+   snapdef->parent.name, diskName);
+return NULL;
+}
+if (snapDisk->src->type != VIR_STORAGE_TYPE_FILE ||
+domDiskNow->src->type != VIR_STORAGE_TYPE_FILE) {
+virReportError(VIR_ERR_OPERATION_UNSUPPORTED,
+   _("can't delete %s, only storage type 'file' is 
supported"),
+   snapdef->parent.name);
+return NULL;
+}
+
+/* TODO Apr 24, 2020: this is not great long-term as it still looks up
+ * essentially just by path (or target[index]), far from a full
+ * comparison operator for virStorageSources */
+if 

[libvirt PATCH v2 05/10] conf: add virDomainMomentFindLeaf() which operates on virDomainMomentObjPtr

2020-05-06 Thread Pavel Mores
The new function operates on virDomainMomentObjPtr which is indicated by
its name.  To avoid code duplication, virDomainMomentObjListFindLeaf()
was reimplemented in terms of the new function.

Signed-off-by: Pavel Mores 
---
 src/conf/virdomainmomentobjlist.c | 25 +++--
 src/conf/virdomainmomentobjlist.h |  1 +
 2 files changed, 16 insertions(+), 10 deletions(-)

diff --git a/src/conf/virdomainmomentobjlist.c 
b/src/conf/virdomainmomentobjlist.c
index 41e887ba18..c57d9cc787 100644
--- a/src/conf/virdomainmomentobjlist.c
+++ b/src/conf/virdomainmomentobjlist.c
@@ -207,6 +207,20 @@ virDomainMomentMoveChildren(virDomainMomentObjPtr from,
 }
 
 
+/* If there is exactly one leaf node, return that node. */
+virDomainMomentObjPtr
+virDomainMomentFindLeaf(virDomainMomentObjPtr moment)
+{
+if (moment->nchildren != 1)
+return NULL;
+while (moment->nchildren == 1)
+moment = moment->first_child;
+if (moment->nchildren == 0)
+return moment;
+return NULL;
+}
+
+
 static virDomainMomentObjPtr
 virDomainMomentObjNew(void)
 {
@@ -586,17 +600,8 @@ virDomainMomentCheckCycles(virDomainMomentObjListPtr list,
 return 0;
 }
 
-/* If there is exactly one leaf node, return that node. */
 virDomainMomentObjPtr
 virDomainMomentObjListFindLeaf(virDomainMomentObjListPtr list)
 {
-virDomainMomentObjPtr moment = >metaroot;
-
-if (moment->nchildren != 1)
-return NULL;
-while (moment->nchildren == 1)
-moment = moment->first_child;
-if (moment->nchildren == 0)
-return moment;
-return NULL;
+return virDomainMomentFindLeaf(>metaroot);
 }
diff --git a/src/conf/virdomainmomentobjlist.h 
b/src/conf/virdomainmomentobjlist.h
index cab51edbc4..9c2d01ff8f 100644
--- a/src/conf/virdomainmomentobjlist.h
+++ b/src/conf/virdomainmomentobjlist.h
@@ -62,6 +62,7 @@ void virDomainMomentMoveChildren(virDomainMomentObjPtr from,
  virDomainMomentObjPtr to);
 void virDomainMomentLinkParent(virDomainMomentObjListPtr moments,
virDomainMomentObjPtr moment);
+virDomainMomentObjPtr virDomainMomentFindLeaf(virDomainMomentObjPtr moment);
 
 virDomainMomentObjListPtr virDomainMomentObjListNew(void);
 void virDomainMomentObjListFree(virDomainMomentObjListPtr moments);
-- 
2.24.1



[libvirt PATCH v2 04/10] conf: rename virDomainMomentFindLeaf() to virDomainMomentObjListFindLeaf()

2020-05-06 Thread Pavel Mores
We'll need the original name for a function that finds leaf for a single
virDomainMomentObj.  The new name properly advertises that the function
actually works on a virDomainMomentObjList, as some (but not all) of
existing functions operating on lists do.

Signed-off-by: Pavel Mores 
---
 src/conf/virdomaincheckpointobjlist.c | 2 +-
 src/conf/virdomainmomentobjlist.c | 2 +-
 src/conf/virdomainmomentobjlist.h | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/conf/virdomaincheckpointobjlist.c 
b/src/conf/virdomaincheckpointobjlist.c
index a4942ea706..2df1c426a2 100644
--- a/src/conf/virdomaincheckpointobjlist.c
+++ b/src/conf/virdomaincheckpointobjlist.c
@@ -186,7 +186,7 @@ 
virDomainCheckpointUpdateRelations(virDomainCheckpointObjListPtr checkpoints,
 int ret = virDomainMomentUpdateRelations(checkpoints->base);
 
 if (ret == 0)
-*leaf = virDomainMomentFindLeaf(checkpoints->base);
+*leaf = virDomainMomentObjListFindLeaf(checkpoints->base);
 return ret;
 }
 
diff --git a/src/conf/virdomainmomentobjlist.c 
b/src/conf/virdomainmomentobjlist.c
index 18dbd434fb..41e887ba18 100644
--- a/src/conf/virdomainmomentobjlist.c
+++ b/src/conf/virdomainmomentobjlist.c
@@ -588,7 +588,7 @@ virDomainMomentCheckCycles(virDomainMomentObjListPtr list,
 
 /* If there is exactly one leaf node, return that node. */
 virDomainMomentObjPtr
-virDomainMomentFindLeaf(virDomainMomentObjListPtr list)
+virDomainMomentObjListFindLeaf(virDomainMomentObjListPtr list)
 {
 virDomainMomentObjPtr moment = >metaroot;
 
diff --git a/src/conf/virdomainmomentobjlist.h 
b/src/conf/virdomainmomentobjlist.h
index 75198909ba..cab51edbc4 100644
--- a/src/conf/virdomainmomentobjlist.h
+++ b/src/conf/virdomainmomentobjlist.h
@@ -121,4 +121,4 @@ int 
virDomainMomentUpdateRelations(virDomainMomentObjListPtr moments);
 int virDomainMomentCheckCycles(virDomainMomentObjListPtr list,
virDomainMomentDefPtr def,
const char *domname);
-virDomainMomentObjPtr virDomainMomentFindLeaf(virDomainMomentObjListPtr list);
+virDomainMomentObjPtr virDomainMomentObjListFindLeaf(virDomainMomentObjListPtr 
list);
-- 
2.24.1



[libvirt PATCH v2 03/10] qemu: block: factor implementation out of qemuDomainBlockJobAbort()

2020-05-06 Thread Pavel Mores
Just as with the qemuDomainBlockCommit() refactor in the commit before the
previous one, the motivation is primarily to make blockjob abortion
callable from within the QEMU driver where only virDomainObj instance is
available but no virDomain.

Signed-off-by: Pavel Mores 
---
 src/qemu/qemu_driver.c | 62 --
 1 file changed, 41 insertions(+), 21 deletions(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 09300c1e90..6ffd53503b 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -163,6 +163,12 @@ qemuDomainBlockCommitImpl(virDomainObjPtr vm,
   unsigned long bandwidth,
   unsigned int flags);
 
+static int
+qemuDomainBlockJobAbortImpl(virQEMUDriverPtr driver,
+virDomainObjPtr vm,
+const char *path,
+unsigned int flags);
+
 /* Looks up the domain object from snapshot and unlocks the
  * driver. The returned domain object is locked and ref'd and the
  * caller must call virDomainObjEndAPI() on it. */
@@ -17541,45 +17547,31 @@ qemuDomainBlockPullCommon(virDomainObjPtr vm,
 return ret;
 }
 
-
 static int
-qemuDomainBlockJobAbort(virDomainPtr dom,
-const char *path,
-unsigned int flags)
+qemuDomainBlockJobAbortImpl(virQEMUDriverPtr driver,
+virDomainObjPtr vm,
+const char *path,
+unsigned int flags)
 {
-virQEMUDriverPtr driver = dom->conn->privateData;
 virDomainDiskDefPtr disk = NULL;
 g_autoptr(virQEMUDriverConfig) cfg = virQEMUDriverGetConfig(driver);
 bool pivot = !!(flags & VIR_DOMAIN_BLOCK_JOB_ABORT_PIVOT);
 bool async = !!(flags & VIR_DOMAIN_BLOCK_JOB_ABORT_ASYNC);
 g_autoptr(qemuBlockJobData) job = NULL;
-virDomainObjPtr vm;
 qemuDomainObjPrivatePtr priv = NULL;
 bool blockdev = false;
 int ret = -1;
 
-virCheckFlags(VIR_DOMAIN_BLOCK_JOB_ABORT_ASYNC |
-  VIR_DOMAIN_BLOCK_JOB_ABORT_PIVOT, -1);
-
-if (!(vm = qemuDomainObjFromDomain(dom)))
-return -1;
-
-if (virDomainBlockJobAbortEnsureACL(dom->conn, vm->def) < 0)
-goto cleanup;
-
-if (qemuDomainObjBeginJob(driver, vm, QEMU_JOB_MODIFY) < 0)
-goto cleanup;
-
 if (virDomainObjCheckActive(vm) < 0)
-goto endjob;
+return -1;
 
 if (!(disk = qemuDomainDiskByName(vm->def, path)))
-goto endjob;
+return -1;
 
 if (!(job = qemuBlockJobDiskGetJob(disk))) {
 virReportError(VIR_ERR_INVALID_ARG,
_("disk %s does not have an active block job"), 
disk->dst);
-goto endjob;
+return -1;
 }
 
 priv = vm->privateData;
@@ -17650,6 +17642,34 @@ qemuDomainBlockJobAbort(virDomainPtr dom,
  endjob:
 if (job && !async)
 qemuBlockJobSyncEnd(vm, job, QEMU_ASYNC_JOB_NONE);
+
+return ret;
+}
+
+
+static int
+qemuDomainBlockJobAbort(virDomainPtr dom,
+const char *path,
+unsigned int flags)
+{
+virQEMUDriverPtr driver = dom->conn->privateData;
+virDomainObjPtr vm;
+int ret = -1;
+
+virCheckFlags(VIR_DOMAIN_BLOCK_JOB_ABORT_ASYNC |
+  VIR_DOMAIN_BLOCK_JOB_ABORT_PIVOT, -1);
+
+if (!(vm = qemuDomainObjFromDomain(dom)))
+return -1;
+
+if (virDomainBlockJobAbortEnsureACL(dom->conn, vm->def) < 0)
+goto cleanup;
+
+if (qemuDomainObjBeginJob(driver, vm, QEMU_JOB_MODIFY) < 0)
+goto cleanup;
+
+ret = qemuDomainBlockJobAbortImpl(driver, vm, path, flags);
+
 qemuDomainObjEndJob(driver, vm);
 
  cleanup:
-- 
2.24.1



[libvirt PATCH v2 10/10] qemu: block: add actual invocation of external snapshot-delete

2020-05-06 Thread Pavel Mores
Plug in the external snapshot deletion framework built in previous commits.

Signed-off-by: Pavel Mores 
---
 src/qemu/qemu_driver.c | 6 ++
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 57e81e3720..34c0e27eb9 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -17106,10 +17106,8 @@ qemuDomainSnapshotDelete(virDomainSnapshotPtr snapshot,
  qemuDomainSnapshotCountExternal,
  );
 if (external) {
-virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-   _("deletion of %d external disk snapshots not "
- "supported yet"), external);
-goto endjob;
+if (qemuDomainSnapshotDeleteExternal(vm, driver, snap, flags) < 0)
+goto endjob;
 }
 }
 
-- 
2.24.1



[libvirt PATCH v2 09/10] qemu: block: add external snapshot-delete top-level algorithm

2020-05-06 Thread Pavel Mores
This uses the helpers introduced in previous three commits and assembles
the top-level snapshot deletion algorithm in their terms.

Note that the third phase - waiting for blockcommits to finish - is
conceptually optional and a flag/parameter might be exposed to the user in
the future to skip the third phase.  This would make the whole operation
asynchronous and let the user deal with concluding the blockcommits
manually, using the generic blockjob tools.

Signed-off-by: Pavel Mores 
---
 src/libvirt_private.syms |  1 +
 src/qemu/qemu_driver.c   | 64 
 2 files changed, 65 insertions(+)

diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 935ef7303b..f68eb500ec 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1049,6 +1049,7 @@ virDomainListCheckpoints;
 # conf/virdomainmomentobjlist.h
 virDomainMomentDropChildren;
 virDomainMomentDropParent;
+virDomainMomentFindLeaf;
 virDomainMomentForEachChild;
 virDomainMomentForEachDescendant;
 virDomainMomentMoveChildren;
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index a2629e9002..57e81e3720 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -17000,6 +17000,70 @@ 
qemuDomainSnapshotDeleteExternalWaitForJobs(virDomainObjPtr vm,
 }
 
 
+static int
+qemuDomainSnapshotDeleteExternal(virDomainObjPtr vm,
+ virQEMUDriverPtr driver,
+ virDomainMomentObjPtr snap,
+ unsigned int flags)
+{
+/* TODO Apr 29, 2020: ultimately, use 'flags' to set this.  Until that
+ * is supported, just run always synchronously. */
+bool async = false;
+virDomainSnapshotDefPtr snapdef = virDomainSnapshotObjGetDef(snap);
+virDomainMomentObjPtr leaf = snap->nchildren ? 
virDomainMomentFindLeaf(snap) : snap;
+virDomainMomentObjPtr parent = snap->parent;
+g_autofree virBlockCommitDesc *blockCommitDescs = NULL;
+int numBlockCommits = snapdef->ndisks;
+
+/* This function only works if the chain below 'snap' is linear.  If
+ * there's no unique leaf it means the chain of 'snap's children
+ * branches at some point.  Also, if there *is* a leaf but it's not
+ * the current snapshot, bail out as well. */
+if (leaf == NULL) {
+virReportError(VIR_ERR_OPERATION_UNSUPPORTED,
+   _("can't delete '%s', snapshot chain branches"),
+   snapdef->parent.name);
+return -1;
+}
+if (leaf != virDomainSnapshotGetCurrent(vm->snapshots)) {
+virReportError(VIR_ERR_OPERATION_UNSUPPORTED,
+   _("can't delete '%s', leaf snapshot is not current"),
+   snapdef->parent.name);
+return -1;
+}
+if (parent->nchildren > 1) {
+/* TODO 'snap's parent has multiple children, meaning it's a
+ * branching point in snapshot tree.  This means we can't
+ * delete 'snap' by commiting into its parent as doing so would
+ * corrupt the other branches rooted in the parent.  We might
+ * still be able to delete 'snap' though by pulling into its
+ * child/children. */
+
+virReportError(VIR_ERR_OPERATION_UNSUPPORTED,
+   _("can't delete %s, its parent has multiple children"),
+   snapdef->parent.name);
+return -1;
+}
+
+if (!virDomainObjIsActive(vm))
+return -1;
+
+blockCommitDescs = qemuDomainSnapshotDeleteExternalGetJobDescriptors(vm, 
snap, flags);
+if (blockCommitDescs == NULL)
+return -1;
+
+if (qemuDomainSnapshotDeleteExternalLaunchJobs(vm, driver, 
blockCommitDescs, numBlockCommits) < 0)
+return -1;
+
+if (!async) {
+if (qemuDomainSnapshotDeleteExternalWaitForJobs(vm, driver, 
blockCommitDescs, numBlockCommits) < 0)
+return -1;
+}
+
+return 0;
+}
+
+
 static int
 qemuDomainSnapshotDelete(virDomainSnapshotPtr snapshot,
  unsigned int flags)
-- 
2.24.1



[libvirt PATCH] docs: documented protected branches and tags

2020-05-06 Thread Daniel P . Berrangé
We need to prevent accidental deletion of release tags and maint
branches.

We need to ensure that shared CI runners are enabled on all repos.

Signed-off-by: Daniel P. Berrangé 
---
 docs/newreposetup.rst | 20 
 1 file changed, 20 insertions(+)

diff --git a/docs/newreposetup.rst b/docs/newreposetup.rst
index ce54aa09d3..cac4f84813 100644
--- a/docs/newreposetup.rst
+++ b/docs/newreposetup.rst
@@ -71,6 +71,26 @@ required under the **Settings** page:
 
 * *Require approval from code owners*: disabled
 
+* *Branch*: ``v*-maint``
+
+* *Allowed to merge*: Developers + Maintainers
+
+* *Allowed to push*: None (or Developers + Maintainers if MRs not used)
+
+* *Require approval from code owners*: disabled
+
+  * **Protected tags**
+
+* *Tag*: ``v*``
+
+* *Allowed to create*: Developers + Maintainers
+
+* **CI/CD**
+
+  * **Runners**
+
+* *Shared runners*: Enable shared runners
+
 GitHub configuration
 
 
-- 
2.26.2



Re: [libvirt-dbus PATCH] meson: Exclude some files from releases

2020-05-06 Thread Andrea Bolognani
On Wed, 2020-05-06 at 11:29 +0100, Daniel P. Berrangé wrote:
> On Wed, May 06, 2020 at 12:16:24PM +0200, Andrea Bolognani wrote:
> > Both .mailmap and .travis.yml only make sense in the context of a
> > git checkout, so we should not include them in releases.
> 
> Does it really matter if we include them though ? AFAIK they don't cause
> any harm, and it feels like we're just creating extra work for ourselves
> by deciding to exclude them.  The same can be said of the .gitlab-ci.yml
> file, and supporting things we'll be introducing like the dockerfiles.
> 
> One of the things I like about meson is that we can essentially stop
> worrying about what goes into the dist tarball, and simply let it have
> the entire of git contents (aside from the couple of generated files
> we added). So my gut feeling says to not bother trying to exclude files.

It's certainly not a deal breaker to have a couple extra files in the
release archives, but I think it's much tidier not to have them
there. It's really not that much extra work anyway... But, if you and
Pavel share the opinion that we shouldn't bother, I will not try to
push this further :)

-- 
Andrea Bolognani / Red Hat / Virtualization



Re: [libvirt-dbus PATCH] meson: Exclude some files from releases

2020-05-06 Thread Daniel P . Berrangé
On Wed, May 06, 2020 at 12:16:24PM +0200, Andrea Bolognani wrote:
> Both .mailmap and .travis.yml only make sense in the context of a
> git checkout, so we should not include them in releases.

Does it really matter if we include them though ? AFAIK they don't cause
any harm, and it feels like we're just creating extra work for ourselves
by deciding to exclude them.  The same can be said of the .gitlab-ci.yml
file, and supporting things we'll be introducing like the dockerfiles.

One of the things I like about meson is that we can essentially stop
worrying about what goes into the dist tarball, and simply let it have
the entire of git contents (aside from the couple of generated files
we added). So my gut feeling says to not bother trying to exclude files.

> 
> Signed-off-by: Andrea Bolognani 
> ---
>  meson.build | 9 +
>  tools/nodist.sh | 5 +
>  2 files changed, 14 insertions(+)
>  create mode 100755 tools/nodist.sh
> 
> diff --git a/meson.build b/meson.build
> index e765ed6..341abe9 100644
> --- a/meson.build
> +++ b/meson.build
> @@ -263,6 +263,15 @@ if git
>  foreach file : [ 'libvirt-dbus.spec', 'AUTHORS.rst' ]
>  meson.add_dist_script('tools/dist.sh', meson.build_root(), file)
>  endforeach
> +
> +nodist_files = [
> +'.mailmap',
> +'.travis.yml',
> +]
> +
> +foreach file : nodist_files
> +meson.add_dist_script('tools/nodist.sh', file)
> +endforeach
>  endif
>  
>  
> diff --git a/tools/nodist.sh b/tools/nodist.sh
> new file mode 100755
> index 000..f820147
> --- /dev/null
> +++ b/tools/nodist.sh
> @@ -0,0 +1,5 @@
> +#!/bin/sh
> +
> +FILE=$1
> +
> +rm -f $MESON_DIST_ROOT/$FILE
> -- 
> 2.25.4
> 

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



Re: [libvirt PATCH] tests: Enable directory override for qemucapsprobe

2020-05-06 Thread Daniel P . Berrangé
On Wed, May 06, 2020 at 11:54:04AM +0200, Andrea Bolognani wrote:
> Currently, qemucapsprobe fails when libvirt is not already installed
> on the system:
> 
>   $ ./tests/qemucapsprobe /path/to/qemu-system-ppc64 >/dev/null
>   I/O warning : failed to load external entity 
> "/usr/share/libvirt/cpu_map/index.xml"
>   2020-05-06 09:49:59.136+: 269822: info : libvirt version: 6.4.0
>   2020-05-06 09:49:59.136+: 269822: info : hostname: [...]
>   2020-05-06 09:49:59.136+: 269822: warning : 
> virQEMUCapsLogProbeFailure:5127 :
>   Failed to probe capabilities for /path/to/qemu-system-ppc64: XML error: 
> failed to
>   parse xml document '/usr/share/libvirt/cpu_map/index.xml'
> 
> It would be great if the tool could work entirely out of the build
> directory, and this patch achieves just that.
> 
> Suggested-by: Peter Krempa 
> Signed-off-by: Andrea Bolognani 
> ---
>  tests/qemucapsprobe.c | 2 ++
>  1 file changed, 2 insertions(+)

Reviewed-by: Daniel P. Berrangé 

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



[libvirt-dbus PATCH] meson: Exclude some files from releases

2020-05-06 Thread Andrea Bolognani
Both .mailmap and .travis.yml only make sense in the context of a
git checkout, so we should not include them in releases.

Signed-off-by: Andrea Bolognani 
---
 meson.build | 9 +
 tools/nodist.sh | 5 +
 2 files changed, 14 insertions(+)
 create mode 100755 tools/nodist.sh

diff --git a/meson.build b/meson.build
index e765ed6..341abe9 100644
--- a/meson.build
+++ b/meson.build
@@ -263,6 +263,15 @@ if git
 foreach file : [ 'libvirt-dbus.spec', 'AUTHORS.rst' ]
 meson.add_dist_script('tools/dist.sh', meson.build_root(), file)
 endforeach
+
+nodist_files = [
+'.mailmap',
+'.travis.yml',
+]
+
+foreach file : nodist_files
+meson.add_dist_script('tools/nodist.sh', file)
+endforeach
 endif
 
 
diff --git a/tools/nodist.sh b/tools/nodist.sh
new file mode 100755
index 000..f820147
--- /dev/null
+++ b/tools/nodist.sh
@@ -0,0 +1,5 @@
+#!/bin/sh
+
+FILE=$1
+
+rm -f $MESON_DIST_ROOT/$FILE
-- 
2.25.4



[libvirt PATCH] tests: Enable directory override for qemucapsprobe

2020-05-06 Thread Andrea Bolognani
Currently, qemucapsprobe fails when libvirt is not already installed
on the system:

  $ ./tests/qemucapsprobe /path/to/qemu-system-ppc64 >/dev/null
  I/O warning : failed to load external entity 
"/usr/share/libvirt/cpu_map/index.xml"
  2020-05-06 09:49:59.136+: 269822: info : libvirt version: 6.4.0
  2020-05-06 09:49:59.136+: 269822: info : hostname: [...]
  2020-05-06 09:49:59.136+: 269822: warning : 
virQEMUCapsLogProbeFailure:5127 :
  Failed to probe capabilities for /path/to/qemu-system-ppc64: XML error: 
failed to
  parse xml document '/usr/share/libvirt/cpu_map/index.xml'

It would be great if the tool could work entirely out of the build
directory, and this patch achieves just that.

Suggested-by: Peter Krempa 
Signed-off-by: Andrea Bolognani 
---
 tests/qemucapsprobe.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/tests/qemucapsprobe.c b/tests/qemucapsprobe.c
index c7e8f3309d..ea88fd2e8a 100644
--- a/tests/qemucapsprobe.c
+++ b/tests/qemucapsprobe.c
@@ -55,6 +55,8 @@ main(int argc, char **argv)
 
 VIR_TEST_PRELOAD(mock);
 
+virFileActivateDirOverrideForProg(argv[0]);
+
 if (argc != 2) {
 fprintf(stderr, "%s QEMU_binary\n", argv[0]);
 return EXIT_FAILURE;
-- 
2.25.4



[libvirt PATCH 2/3] tests: Update capabilities for QEMU 5.0.0 on ppc64

2020-05-06 Thread Andrea Bolognani
The churn in the output files is caused primarily by the fact that
replies were generated on a POWER9 machine, which is good because
we didn't have coverage of that before.

Signed-off-by: Andrea Bolognani 
---
 .../caps_5.0.0.ppc64.replies  | 2163 +++--
 .../qemucapabilitiesdata/caps_5.0.0.ppc64.xml |   15 +-
 ...default-video-type-ppc64.ppc64-latest.args |2 +
 ...ory-hotplug-nvdimm-ppc64.ppc64-latest.args |2 +
 ...ault-cpu-kvm-pseries-2.7.ppc64-latest.args |4 +-
 ...ault-cpu-kvm-pseries-3.1.ppc64-latest.args |4 +-
 ...ault-cpu-kvm-pseries-4.2.ppc64-latest.args |4 +-
 ...ault-cpu-tcg-pseries-2.7.ppc64-latest.args |2 +
 ...ault-cpu-tcg-pseries-3.1.ppc64-latest.args |2 +
 ...ault-cpu-tcg-pseries-4.2.ppc64-latest.args |2 +
 .../ppc64-pseries-graphics.ppc64-latest.args  |2 +
 .../ppc64-pseries-headless.ppc64-latest.args  |2 +
 .../tpm-emulator-spapr.ppc64-latest.args  |2 +
 ...fault-cpu-kvm-pseries-2.7.ppc64-latest.xml |2 +-
 ...fault-cpu-kvm-pseries-3.1.ppc64-latest.xml |2 +-
 ...fault-cpu-kvm-pseries-4.2.ppc64-latest.xml |2 +-
 16 files changed, 1454 insertions(+), 758 deletions(-)

diff --git a/tests/qemucapabilitiesdata/caps_5.0.0.ppc64.replies 
b/tests/qemucapabilitiesdata/caps_5.0.0.ppc64.replies
index 8e754bfb80..a046b099b6 100644
--- a/tests/qemucapabilitiesdata/caps_5.0.0.ppc64.replies
+++ b/tests/qemucapabilitiesdata/caps_5.0.0.ppc64.replies
@@ -17,11 +17,11 @@
 {
   "return": {
 "qemu": {
-  "micro": 50,
-  "minor": 2,
-  "major": 4
+  "micro": 0,
+  "minor": 0,
+  "major": 5
 },
-"package": "v4.2.0-2387-g3189e9d38c"
+"package": "v5.0.0"
   },
   "id": "libvirt-2"
 }
[...]
diff --git a/tests/qemucapabilitiesdata/caps_5.0.0.ppc64.xml 
b/tests/qemucapabilitiesdata/caps_5.0.0.ppc64.xml
index a998bed430..a5f0bb538b 100644
--- a/tests/qemucapabilitiesdata/caps_5.0.0.ppc64.xml
+++ b/tests/qemucapabilitiesdata/caps_5.0.0.ppc64.xml
@@ -28,6 +28,7 @@
[...]
-  4002050
+  500
   0
   42900241
-  v4.2.0-2387-g3189e9d38c
+  v5.0.0
   ppc64
   
   
   
   
   
-  
+  
   
-  
+  
[...]
diff --git a/tests/qemuxml2argvdata/default-video-type-ppc64.ppc64-latest.args 
b/tests/qemuxml2argvdata/default-video-type-ppc64.ppc64-latest.args
index 5fadd1b61f..795c5a5c58 100644
--- a/tests/qemuxml2argvdata/default-video-type-ppc64.ppc64-latest.args
+++ b/tests/qemuxml2argvdata/default-video-type-ppc64.ppc64-latest.args
@@ -30,4 +30,6 @@ file=/tmp/lib/domain--1-default-video-type-p/master-key.aes \
 -device usb-mouse,id=input1,bus=usb.0,port=2 \
 -vnc 127.0.0.1:0 \
 -device VGA,id=video0,vgamem_mb=16,bus=pci.0,addr=0x2 \
+-sandbox on,obsolete=deny,elevateprivileges=deny,spawn=deny,\
+resourcecontrol=deny \
 -msg timestamp=on
diff --git 
a/tests/qemuxml2argvdata/memory-hotplug-nvdimm-ppc64.ppc64-latest.args 
b/tests/qemuxml2argvdata/memory-hotplug-nvdimm-ppc64.ppc64-latest.args
index 7f556a6668..eff80dcf80 100644
--- a/tests/qemuxml2argvdata/memory-hotplug-nvdimm-ppc64.ppc64-latest.args
+++ b/tests/qemuxml2argvdata/memory-hotplug-nvdimm-ppc64.ppc64-latest.args
@@ -33,4 +33,6 @@ 
uuid=49545eb3-75e1-2d0a-acdd-f0294406c99e,memdev=memnvdimm0,id=nvdimm0,slot=0 \
 -boot strict=on \
 -device pci-ohci,id=usb,bus=pci.0,addr=0x1 \
 -device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x2 \
+-sandbox on,obsolete=deny,elevateprivileges=deny,spawn=deny,\
+resourcecontrol=deny \
 -msg timestamp=on
diff --git 
a/tests/qemuxml2argvdata/ppc64-default-cpu-kvm-pseries-2.7.ppc64-latest.args 
b/tests/qemuxml2argvdata/ppc64-default-cpu-kvm-pseries-2.7.ppc64-latest.args
index c34821c7e8..03c2aeb7fb 100644
--- a/tests/qemuxml2argvdata/ppc64-default-cpu-kvm-pseries-2.7.ppc64-latest.args
+++ b/tests/qemuxml2argvdata/ppc64-default-cpu-kvm-pseries-2.7.ppc64-latest.args
@@ -13,7 +13,7 @@ QEMU_AUDIO_DRV=none \
 -object secret,id=masterKey0,format=raw,\
 file=/tmp/lib/domain--1-guest/master-key.aes \
 -machine pseries-2.7,accel=kvm,usb=off,dump-guest-core=off \
--cpu POWER8 \
+-cpu POWER9 \
 -m 4096 \
 -overcommit mem-lock=off \
 -smp 4,sockets=4,cores=1,threads=1 \
@@ -36,4 +36,6 @@ id=virtio-disk0,bootindex=1 \
 -chardev pty,id=charserial0 \
 -device spapr-vty,chardev=charserial0,id=serial0,reg=0x3000 \
 -device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x3 \
+-sandbox on,obsolete=deny,elevateprivileges=deny,spawn=deny,\
+resourcecontrol=deny \
 -msg timestamp=on
diff --git 
a/tests/qemuxml2argvdata/ppc64-default-cpu-kvm-pseries-3.1.ppc64-latest.args 
b/tests/qemuxml2argvdata/ppc64-default-cpu-kvm-pseries-3.1.ppc64-latest.args
index 3d02221d3f..3827978c66 100644
--- a/tests/qemuxml2argvdata/ppc64-default-cpu-kvm-pseries-3.1.ppc64-latest.args
+++ b/tests/qemuxml2argvdata/ppc64-default-cpu-kvm-pseries-3.1.ppc64-latest.args
@@ -13,7 +13,7 @@ QEMU_AUDIO_DRV=none \
 -object secret,id=masterKey0,format=raw,\
 file=/tmp/lib/domain--1-guest/master-key.aes \
 -machine pseries-3.1,accel=kvm,usb=off,dump-guest-core=off \

[libvirt PATCH 3/3] tests: Add capabilities for QEMU 5.0.0 on riscv64

2020-05-06 Thread Andrea Bolognani
The churn in the output files is caused primarily by the fact that
blockdev support has been introduced.

Signed-off-by: Andrea Bolognani 
---
 .../caps_5.0.0.riscv64.replies| 19902 
 .../caps_5.0.0.riscv64.xml|   201 +
 .../riscv64-virt-graphics.riscv64-latest.args | 8 +-
 .../riscv64-virt-headless.riscv64-latest.args | 8 +-
 4 files changed, 20113 insertions(+), 6 deletions(-)
 create mode 100644 tests/qemucapabilitiesdata/caps_5.0.0.riscv64.replies
 create mode 100644 tests/qemucapabilitiesdata/caps_5.0.0.riscv64.xml

diff --git a/tests/qemucapabilitiesdata/caps_5.0.0.riscv64.replies 
b/tests/qemucapabilitiesdata/caps_5.0.0.riscv64.replies
new file mode 100644
index 00..e2307a646e
--- /dev/null
+++ b/tests/qemucapabilitiesdata/caps_5.0.0.riscv64.replies
@@ -0,0 +1,19902 @@
[...]
+{
+  "execute": "query-version",
+  "id": "libvirt-2"
+}
+
+{
+  "return": {
+"qemu": {
+  "micro": 0,
+  "minor": 0,
+  "major": 5
+},
+"package": "v5.0.0"
+  },
+  "id": "libvirt-2"
+}
[...]
diff --git a/tests/qemucapabilitiesdata/caps_5.0.0.riscv64.xml 
b/tests/qemucapabilitiesdata/caps_5.0.0.riscv64.xml
new file mode 100644
index 00..e9651ca581
--- /dev/null
+++ b/tests/qemucapabilitiesdata/caps_5.0.0.riscv64.xml
@@ -0,0 +1,201 @@
[...]
+  500
+  0
+  0
+  v5.0.0
+  riscv64
[...]
diff --git a/tests/qemuxml2argvdata/riscv64-virt-graphics.riscv64-latest.args 
b/tests/qemuxml2argvdata/riscv64-virt-graphics.riscv64-latest.args
index f8e2154f8f..6e0de34d6e 100644
--- a/tests/qemuxml2argvdata/riscv64-virt-graphics.riscv64-latest.args
+++ b/tests/qemuxml2argvdata/riscv64-virt-graphics.riscv64-latest.args
@@ -35,9 +35,11 @@ addr=0x1 \
 -device pcie-root-port,port=0xf,chassis=8,id=pci.8,bus=pcie.0,addr=0x1.0x7 \
 -device qemu-xhci,p2=15,p3=15,id=usb,bus=pci.2,addr=0x0 \
 -device virtio-serial-pci,id=virtio-serial0,bus=pci.3,addr=0x0 \
--drive file=/var/lib/libvirt/images/guest.qcow2,format=qcow2,if=none,\
-id=drive-virtio-disk0 \
--device virtio-blk-pci,scsi=off,bus=pci.4,addr=0x0,drive=drive-virtio-disk0,\
+-blockdev '{"driver":"file","filename":"/var/lib/libvirt/images/guest.qcow2",\
+"node-name":"libvirt-1-storage","auto-read-only":true,"discard":"unmap"}' \
+-blockdev '{"node-name":"libvirt-1-format","read-only":false,"driver":"qcow2",\
+"file":"libvirt-1-storage"}' \
+-device virtio-blk-pci,scsi=off,bus=pci.4,addr=0x0,drive=libvirt-1-format,\
 id=virtio-disk0,bootindex=1 \
 -netdev user,id=hostnet0 \
 -device 
virtio-net-pci,netdev=hostnet0,id=net0,mac=52:54:00:09:a4:37,bus=pci.1,\
diff --git a/tests/qemuxml2argvdata/riscv64-virt-headless.riscv64-latest.args 
b/tests/qemuxml2argvdata/riscv64-virt-headless.riscv64-latest.args
index 9a595dc4ee..92a3021640 100644
--- a/tests/qemuxml2argvdata/riscv64-virt-headless.riscv64-latest.args
+++ b/tests/qemuxml2argvdata/riscv64-virt-headless.riscv64-latest.args
@@ -35,9 +35,11 @@ addr=0x1 \
 -device pcie-root-port,port=0xe,chassis=7,id=pci.7,bus=pcie.0,addr=0x1.0x6 \
 -device qemu-xhci,p2=15,p3=15,id=usb,bus=pci.2,addr=0x0 \
 -device virtio-serial-pci,id=virtio-serial0,bus=pci.3,addr=0x0 \
--drive file=/var/lib/libvirt/images/guest.qcow2,format=qcow2,if=none,\
-id=drive-virtio-disk0 \
--device virtio-blk-pci,scsi=off,bus=pci.4,addr=0x0,drive=drive-virtio-disk0,\
+-blockdev '{"driver":"file","filename":"/var/lib/libvirt/images/guest.qcow2",\
+"node-name":"libvirt-1-storage","auto-read-only":true,"discard":"unmap"}' \
+-blockdev '{"node-name":"libvirt-1-format","read-only":false,"driver":"qcow2",\
+"file":"libvirt-1-storage"}' \
+-device virtio-blk-pci,scsi=off,bus=pci.4,addr=0x0,drive=libvirt-1-format,\
 id=virtio-disk0,bootindex=1 \
 -netdev user,id=hostnet0 \
 -device 
virtio-net-pci,netdev=hostnet0,id=net0,mac=52:54:00:09:a4:37,bus=pci.1,\
-- 
2.25.4



[libvirt PATCH 1/3] tests: Update capabilities for QEMU 5.0.0 on aarch64

2020-05-06 Thread Andrea Bolognani
Signed-off-by: Andrea Bolognani 
---
 .../qemu_5.0.0-virt.aarch64.xml   |   60 +-
 tests/domaincapsdata/qemu_5.0.0.aarch64.xml   |   60 +-
 .../caps_5.0.0.aarch64.replies| 8937 +
 .../caps_5.0.0.aarch64.xml|  384 +-
 4 files changed, 5119 insertions(+), 4322 deletions(-)

diff --git a/tests/domaincapsdata/qemu_5.0.0-virt.aarch64.xml 
b/tests/domaincapsdata/qemu_5.0.0-virt.aarch64.xml
index f92ae951ca..7153a0b80d 100644
--- a/tests/domaincapsdata/qemu_5.0.0-virt.aarch64.xml
+++ b/tests/domaincapsdata/qemu_5.0.0-virt.aarch64.xml
@@ -30,43 +30,43 @@
 
 
 
-  pxa262
-  pxa270-a0
-  arm1136
[...]
diff --git a/tests/domaincapsdata/qemu_5.0.0.aarch64.xml 
b/tests/domaincapsdata/qemu_5.0.0.aarch64.xml
index 232aacec2f..a3e20cc3d8 100644
--- a/tests/domaincapsdata/qemu_5.0.0.aarch64.xml
+++ b/tests/domaincapsdata/qemu_5.0.0.aarch64.xml
@@ -28,43 +28,43 @@
 
 
 
-  pxa262
-  pxa270-a0
-  arm1136
[...]
diff --git a/tests/qemucapabilitiesdata/caps_5.0.0.aarch64.replies 
b/tests/qemucapabilitiesdata/caps_5.0.0.aarch64.replies
index 067cbb7e31..44f1bc6fb7 100644
--- a/tests/qemucapabilitiesdata/caps_5.0.0.aarch64.replies
+++ b/tests/qemucapabilitiesdata/caps_5.0.0.aarch64.replies
@@ -17,11 +17,11 @@
 {
   "return": {
 "qemu": {
-  "micro": 50,
-  "minor": 2,
-  "major": 4
+  "micro": 0,
+  "minor": 0,
+  "major": 5
 },
-"package": "v4.2.0-1157-gadcd6e93b9"
+"package": "v5.0.0"
   },
   "id": "libvirt-2"
 }
[...]
diff --git a/tests/qemucapabilitiesdata/caps_5.0.0.aarch64.xml 
b/tests/qemucapabilitiesdata/caps_5.0.0.aarch64.xml
index 3bacfe13dc..1f743aaa11 100644
--- a/tests/qemucapabilitiesdata/caps_5.0.0.aarch64.xml
+++ b/tests/qemucapabilitiesdata/caps_5.0.0.aarch64.xml
@@ -42,6 +42,8 @@
[...]
-  4002050
+  500
   0
   61700241
-  v4.2.0-1157-gadcd6e93b9
+  v5.0.0
[...]
-- 
2.25.4



[libvirt PATCH 0/3] tests: Update capabilities for QEMU 5.0.0

2020-05-06 Thread Andrea Bolognani
Now that QEMU 5.0.0 has been released, bring capabilities files for
non-x86 architectures up to date.

As usual, this series as posted to the mailing list is heavily
trimmed: for the unabridged version, fetch

  https://gitlab.com/abologna/libvirt caps-5.0.0

Andrea Bolognani (3):
  tests: Update capabilities for QEMU 5.0.0 on aarch64
  tests: Update capabilities for QEMU 5.0.0 on ppc64
  tests: Add capabilities for QEMU 5.0.0 on riscv64

 .../qemu_5.0.0-virt.aarch64.xml   |60 +-
 tests/domaincapsdata/qemu_5.0.0.aarch64.xml   |60 +-
 .../caps_5.0.0.aarch64.replies|  8937 ++---
 .../caps_5.0.0.aarch64.xml|   384 +-
 .../caps_5.0.0.ppc64.replies  |  2163 +-
 .../qemucapabilitiesdata/caps_5.0.0.ppc64.xml |15 +-
 ...h64.replies => caps_5.0.0.riscv64.replies} | 27491 +++-
 .../caps_5.0.0.riscv64.xml|   201 +
 ...default-video-type-ppc64.ppc64-latest.args | 2 +
 ...ory-hotplug-nvdimm-ppc64.ppc64-latest.args | 2 +
 ...ault-cpu-kvm-pseries-2.7.ppc64-latest.args | 4 +-
 ...ault-cpu-kvm-pseries-3.1.ppc64-latest.args | 4 +-
 ...ault-cpu-kvm-pseries-4.2.ppc64-latest.args | 4 +-
 ...ault-cpu-tcg-pseries-2.7.ppc64-latest.args | 2 +
 ...ault-cpu-tcg-pseries-3.1.ppc64-latest.args | 2 +
 ...ault-cpu-tcg-pseries-4.2.ppc64-latest.args | 2 +
 .../ppc64-pseries-graphics.ppc64-latest.args  | 2 +
 .../ppc64-pseries-headless.ppc64-latest.args  | 2 +
 .../riscv64-virt-graphics.riscv64-latest.args | 8 +-
 .../riscv64-virt-headless.riscv64-latest.args | 8 +-
 .../tpm-emulator-spapr.ppc64-latest.args  | 2 +
 ...fault-cpu-kvm-pseries-2.7.ppc64-latest.xml | 2 +-
 ...fault-cpu-kvm-pseries-3.1.ppc64-latest.xml | 2 +-
 ...fault-cpu-kvm-pseries-4.2.ppc64-latest.xml | 2 +-
 24 files changed, 19067 insertions(+), 20294 deletions(-)
 copy tests/qemucapabilitiesdata/{caps_5.0.0.aarch64.replies => 
caps_5.0.0.riscv64.replies} (78%)
 create mode 100644 tests/qemucapabilitiesdata/caps_5.0.0.riscv64.xml

-- 
2.25.4



Re: [libvirt PATCH] qemu: Don't use CPU from host capabilities as host-model on ARM

2020-05-06 Thread Daniel P . Berrangé
On Wed, May 06, 2020 at 10:08:29AM +0200, Jiri Denemark wrote:
> We never supported host-model CPUs on ARM and we don't want to support
> them even once patches for direct detection of host CPU are merged. And
> since using host CPU definition for host-model CPUs exist only for
> backward compatibility, we should not use it for any host-model support
> added in the future. Such enhancement should exclusively use the result
> of query-cpu-model-expansion. Until proper host-model support is
> implemented for ARM (if ever), we need to make sure the detected host
> CPU is not accidentally used for host-model CPUs.
> 
> Signed-off-by: Jiri Denemark 
> ---
>  src/qemu/qemu_capabilities.c | 2 ++
>  1 file changed, 2 insertions(+)

Reviewed-by: Daniel P. Berrangé 


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



  1   2   >