]> xenbits.xensource.com Git - libvirt.git/log
libvirt.git
6 years agoqemu: Use the 'device_id' property of SCSI disks to avoid regressing
Peter Krempa [Mon, 28 Jan 2019 15:57:35 +0000 (16:57 +0100)]
qemu: Use the 'device_id' property of SCSI disks to avoid regressing

QEMU accidentally exposed the id of -drive (or same value as disk
serial, if provided) in one of the identifiers visible from the guest.

To avoid regression in case when -blockdev will be used we need to
always specify it ourselves.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
6 years agoqemu: caps: Introduce capability for 'device_id' property of 'scsi-disk'
Peter Krempa [Mon, 28 Jan 2019 08:30:41 +0000 (09:30 +0100)]
qemu: caps: Introduce capability for 'device_id' property of 'scsi-disk'

The property allows to control the guest-visible content of the vendor
specific designator of the 'Device Identification' page of a SCSI
device's VPD (vital product data).

QEMU was leaking the id string of -drive as the value if the 'serial' of
the disk was not specified. Switching to -blockdev would impose an ABI
change.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
6 years agotest: qemucaps: Update caps with scsi 'device_id' property
Peter Krempa [Mon, 28 Jan 2019 08:06:37 +0000 (09:06 +0100)]
test: qemucaps: Update caps with scsi 'device_id' property

Based on qemu commit 'v3.1.0-1445-ga61faa3d02'. Will allow checking
for the scsi 'device_id' property.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
6 years agotests: qemuxml2argv: Add a 'serial' value for a SCSI disk
Peter Krempa [Mon, 28 Jan 2019 16:04:05 +0000 (17:04 +0100)]
tests: qemuxml2argv: Add a 'serial' value for a SCSI disk

Upcoming addition of a new field will need to make sure that SCSI disk
serial is tested as well. Add a case to one of the existing tests.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
6 years agoqemu: command: Drop formatting of 'media=cdrom' from -drive
Peter Krempa [Mon, 28 Jan 2019 16:18:56 +0000 (17:18 +0100)]
qemu: command: Drop formatting of 'media=cdrom' from -drive

For SCSI, IDE, and AHCI cdroms the appropriate device types which select
the correct media are used. In qemu there's one other code path that
looks at -drive media=cdrom in the XEN pv code. Thankfully we don't
support it with qemu (see qemuBuildDiskDeviceStr). All other devices
ignore it as the comment states, thus we can drop that code.

The test fallout is expectedly only in the test added for uncommon cdrom
types.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
6 years agotests: qemuxml2argv: Add CDROM disks for all untested buses
Peter Krempa [Mon, 28 Jan 2019 14:59:36 +0000 (15:59 +0100)]
tests: qemuxml2argv: Add CDROM disks for all untested buses

Add full and empty cdroms on 'usb' and 'sd' bus to have test
coverage. Note that this does not guarantee that qemu will accept them.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
6 years agoqemu: Forbid cdroms on virtio bus
Peter Krempa [Mon, 28 Jan 2019 16:18:55 +0000 (17:18 +0100)]
qemu: Forbid cdroms on virtio bus

Attempting to create an empty virtio-blk drive results into:
-device virtio-blk-pci,scsi=off,bus=pci.0,addr=0xc,drive=drive-virtio-disk1,id=virtio-disk1: Device needs media, but drive is empty

Attempting to eject media from virtio-blk based drive results into:
error: internal error: unable to execute QEMU command 'eject': Device 'drive-virtio-disk0' is not removable

Forbid configurations where users would attempt to use cdroms in virtio
bus.

Fix few wrong examples which are not really relevant to the tested code.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
6 years agoqemu: command: Use correct type for switch in qemuBuildDiskDeviceStr
Peter Krempa [Mon, 28 Jan 2019 14:46:41 +0000 (15:46 +0100)]
qemu: command: Use correct type for switch in qemuBuildDiskDeviceStr

Cast disk->bus to proper type and add missing values to the enum so it's
more obvious what types are supported.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
6 years agoqemu: caps: Always assume presence of 'ide-hd' and 'ide-cd' devices
Peter Krempa [Mon, 28 Jan 2019 13:44:57 +0000 (14:44 +0100)]
qemu: caps: Always assume presence of 'ide-hd' and 'ide-cd' devices

The split of ide-disk into the two separate devices was introduced by
qemu commit 1f56e32a7f4b3 released in qemu v0.15.

Note that when compared to the previous commit which made sure that no
disk related tests were touched, in this case it's not as careful.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
6 years agoqemu: caps: Always assume presence of 'scsi-hd' and 'scsi-cd' device
Peter Krempa [Mon, 28 Jan 2019 13:29:10 +0000 (14:29 +0100)]
qemu: caps: Always assume presence of 'scsi-hd' and 'scsi-cd' device

The split of scsi-disk into the two separate devices was introduced by
qemu commit b443ae67 released in qemu v0.15.

All changes to test files are not really related to disk testing thanks
to previous refactors.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
6 years agotests: qemuxml2argv: Remove 'disk-virtio-scsi-ccw' test
Peter Krempa [Mon, 28 Jan 2019 13:21:11 +0000 (14:21 +0100)]
tests: qemuxml2argv: Remove 'disk-virtio-scsi-ccw' test

It's a subset of 'iothreads-virtio-scsi-ccw'.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
6 years agotests: qemuxml2argv: Modernize virtio-scsi iothread tests
Peter Krempa [Mon, 28 Jan 2019 13:17:15 +0000 (14:17 +0100)]
tests: qemuxml2argv: Modernize virtio-scsi iothread tests

Use DO_TEST_CAPS_LATEST to obtain modern results.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
6 years agotests: qemuxml2argv: Use 1.5.3 version for the oldest case of 'disk-cache'
Peter Krempa [Mon, 28 Jan 2019 13:11:36 +0000 (14:11 +0100)]
tests: qemuxml2argv: Use 1.5.3 version for the oldest case of 'disk-cache'

Rather than testing random set of flags add a case also for the oldest
supported qemu.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
6 years agotests: qemu: Merge 'disk-scsi-vscsi' test into 'disk-scsi'
Peter Krempa [Mon, 28 Jan 2019 12:51:44 +0000 (13:51 +0100)]
tests: qemu: Merge 'disk-scsi-vscsi' test into 'disk-scsi'

As we support multiple scsi controllers there's no need to have a
special test for this controller.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
6 years agotests: qemu: Merge 'disk-scsi-mptsas1068' test into 'disk-scsi'
Peter Krempa [Mon, 28 Jan 2019 12:51:44 +0000 (13:51 +0100)]
tests: qemu: Merge 'disk-scsi-mptsas1068' test into 'disk-scsi'

As we support multiple scsi controllers there's no need to have a
special test for this controller.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
6 years agotests: qemu: Merge 'disk-scsi-megasas' test into 'disk-scsi'
Peter Krempa [Mon, 28 Jan 2019 12:51:44 +0000 (13:51 +0100)]
tests: qemu: Merge 'disk-scsi-megasas' test into 'disk-scsi'

As we support multiple scsi controllers there's no need to have a
special test for this controller.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
6 years agotests: qemuxml2argv: Modernize 'disk-scsi' test
Peter Krempa [Mon, 28 Jan 2019 11:59:49 +0000 (12:59 +0100)]
tests: qemuxml2argv: Modernize 'disk-scsi' test

Use DO_TEST_CAPS_LATEST rather than a predetermined set of caps.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
6 years agotests: qemu: Rename 'disk-scsi-device' to 'disk-scsi'
Peter Krempa [Mon, 28 Jan 2019 11:56:11 +0000 (12:56 +0100)]
tests: qemu: Rename 'disk-scsi-device' to 'disk-scsi'

Drop the 'device' suffix which is quite pointless.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
6 years agotests: qemuxml2argv: Move cases from 'disk-shared-locking' into 'disk-shared'
Peter Krempa [Mon, 28 Jan 2019 10:45:50 +0000 (11:45 +0100)]
tests: qemuxml2argv: Move cases from 'disk-shared-locking' into 'disk-shared'

The tests are for the same feature. Move all the cases to 'disk-shared'
case as it's already using DO_TEST_CAPS_LATEST

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
6 years agotests: qemuxml2argv: Remove the 'after startup XML' testing machinery
Peter Krempa [Mon, 28 Jan 2019 11:50:25 +0000 (12:50 +0100)]
tests: qemuxml2argv: Remove the 'after startup XML' testing machinery

A lot of code with no real impact and popularity. Remove all the helpers
now that the only test case is gone.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
6 years agotests: qemuxml2argv: Remove testing of post startup change to 'cachemode' for shared...
Peter Krempa [Mon, 28 Jan 2019 11:43:13 +0000 (12:43 +0100)]
tests: qemuxml2argv: Remove testing of post startup change to 'cachemode' for shared disks

Testing that the cachemode is properly recorded to the configuration
after startup does not add much value and overcomplicates the xml2argv
test.

Remove the 'disk-shared' test with old capabilities as the test with
real capabilities covers the code sufficiently.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
6 years agotests: qemuxml2argv: Use real caps when auto-generating SCSI controller type
Peter Krempa [Mon, 28 Jan 2019 10:25:12 +0000 (11:25 +0100)]
tests: qemuxml2argv: Use real caps when auto-generating SCSI controller type

Using an old strict set of capabilities is not of much use if a code
path would select a more modern controller by accident.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
6 years agotests: qemuxml: Merge 'ioeventfd' variant of 'virtio-scsi' test into the common file
Peter Krempa [Mon, 28 Jan 2019 09:52:36 +0000 (10:52 +0100)]
tests: qemuxml: Merge 'ioeventfd' variant of 'virtio-scsi' test into the common file

We don't need separate files for this test. Also modernize it in the
process.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
6 years agotests: qemuxml: Merge 'max_sectors' variant of 'virtio-scsi' test into the common...
Peter Krempa [Mon, 28 Jan 2019 09:52:36 +0000 (10:52 +0100)]
tests: qemuxml: Merge 'max_sectors' variant of 'virtio-scsi' test into the common file

We don't need separate files for this test. Also modernize it in the
process.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
6 years agotests: qemuxml: Merge 'cmd_per_lun' variant of 'virtio-scsi' test into the common...
Peter Krempa [Mon, 28 Jan 2019 09:52:36 +0000 (10:52 +0100)]
tests: qemuxml: Merge 'cmd_per_lun' variant of 'virtio-scsi' test into the common file

We don't need separate files for this test. Also modernize it in the
process.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
6 years agotests: qemuxml: Merge 'num-queues' variant of 'virtio-scsi' test into the common...
Peter Krempa [Mon, 28 Jan 2019 09:52:36 +0000 (10:52 +0100)]
tests: qemuxml: Merge 'num-queues' variant of 'virtio-scsi' test into the common file

We don't need separate files for this test. Also modernize it in the
process.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
6 years agotests: qemu: Remove 'disk-scsi-virtio-scsi' test
Peter Krempa [Mon, 28 Jan 2019 12:17:10 +0000 (13:17 +0100)]
tests: qemu: Remove 'disk-scsi-virtio-scsi' test

Now that we have a specific test for testing the 'virtio-scsi'
controller and other tests which test a combination of scsi and non-scsi
devices this test no longer makes sense.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
6 years agotests: qemuxml: Add a common test file for the 'virtio-scsi' controller
Peter Krempa [Mon, 28 Jan 2019 09:47:21 +0000 (10:47 +0100)]
tests: qemuxml: Add a common test file for the 'virtio-scsi' controller

Add a file to aggregate testing for 'virtio-scsi' based on the modern
framework.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
6 years agoqemu: capabilities: Probe caps for 'ide-hd' instead of 'ide-drive'
Peter Krempa [Mon, 28 Jan 2019 13:52:22 +0000 (14:52 +0100)]
qemu: capabilities: Probe caps for 'ide-hd' instead of 'ide-drive'

Since commit a4cda054e7 we are using 'ide-hd' and 'ide-cd' instead of
'ide-drive'. We also should probe capabilities for 'ide-hd' instead of
'ide-drive'. It is safe to do as 'ide-drive' is the common denominator
of both 'ide-hd' and 'ide-cd' so all the properties were common.

For now the test data are modified by just changing the appropriate type
when probing for caps.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
6 years agoqemu: capabilities: Probe caps for 'scsi-hd' instead of 'scsi-disk'
Peter Krempa [Mon, 28 Jan 2019 09:03:25 +0000 (10:03 +0100)]
qemu: capabilities: Probe caps for 'scsi-hd' instead of 'scsi-disk'

Since commit 02e8d0cfdf8 we are using 'scsi-hd' and 'scsi-cd' instead of
'scsi-disk'. We also should probe capabilities for 'scsi-hd' instead of
'scsi-disk'. It is safe to do as 'scsi-disk' is the common denominator
of both 'scsi-hd' and 'scsi-cd' so all the properties were common.

For now the test data are modified by just changing the appropriate type
when probing for caps.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
6 years agotests: qemucaps: Make fake 'microcodeVersion' depend on filename instead of length
Peter Krempa [Mon, 28 Jan 2019 09:22:00 +0000 (10:22 +0100)]
tests: qemucaps: Make fake 'microcodeVersion' depend on filename instead of length

To avoid changes to the filled in microcode in case we change the caps
replies file for any reason make the number depend on the filename.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
6 years agovirsh: Add support for setting post-copy migration bandwidth
Jiri Denemark [Thu, 31 Jan 2019 09:45:35 +0000 (10:45 +0100)]
virsh: Add support for setting post-copy migration bandwidth

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoqemu: Implement VIR_DOMAIN_MIGRATE_MAX_SPEED_POSTCOPY flag
Jiri Denemark [Mon, 4 Feb 2019 16:10:38 +0000 (17:10 +0100)]
qemu: Implement VIR_DOMAIN_MIGRATE_MAX_SPEED_POSTCOPY flag

This flag tells virDomainMigrateSetMaxSpeed and
virDomainMigrateGetMaxSpeed APIs to work on post-copy migration
bandwidth.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoqemu: Implement VIR_MIGRATE_PARAM_BANDWIDTH_POSTCOPY
Jiri Denemark [Thu, 31 Jan 2019 09:25:11 +0000 (10:25 +0100)]
qemu: Implement VIR_MIGRATE_PARAM_BANDWIDTH_POSTCOPY

This typed parameter for virDomainMigrate3 and virDomainMigrateToURI3
APIs may be used for setting maximum post-copy migration bandwidth.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoPublic API for post-copy migration bandwidth
Jiri Denemark [Mon, 4 Feb 2019 16:08:36 +0000 (17:08 +0100)]
Public API for post-copy migration bandwidth

This patch adds a new VIR_MIGRATE_PARAM_BANDWIDTH_POSTCOPY typed
parameter for virDomainMigrate3 and virDomainMigrateToURI3 for setting
maximum post-copy migration bandwidth.

In case the initial VIR_MIGRATE_PARAM_BANDWIDTH_POSTCOPY value turns out
to be suboptimal a new VIR_DOMAIN_MIGRATE_MAX_SPEED_POSTCOPY flag for
virDomainMigrateSetMaxSpeed and virDomainMigrateGetMaxSpeed may be used
to set/get the maximum post-copy migration bandwidth while migration is
already running.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoqemu: Make migration params usable outside migration
Jiri Denemark [Mon, 4 Feb 2019 16:11:42 +0000 (17:11 +0100)]
qemu: Make migration params usable outside migration

So far migration parameters were changed only at the beginning of
migration mostly via an automatic translation from flags and typed
parameters. We need to export a few more functions to support APIs which
may set migration parameters while migration is already running.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoqemu: Rework qemuDomainMigrateSetMaxSpeed
Jiri Denemark [Mon, 4 Feb 2019 15:52:05 +0000 (16:52 +0100)]
qemu: Rework qemuDomainMigrateSetMaxSpeed

Let's make the code flow easier to follow and get rid of the ugly endjob
label inside if branch.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoqemu: Add optional unit to qemuMigrationParamsTPMapItem
Jiri Denemark [Thu, 31 Jan 2019 09:02:17 +0000 (10:02 +0100)]
qemu: Add optional unit to qemuMigrationParamsTPMapItem

Some migration parameters supported by libvirt may use units that differ
from the units used by QEMU for the corresponding parameters. For
example, libvirt defines migration bandwidth in MiB/s while QEMU expects
B/s. Let's add a unit field to qemuMigrationParamsTPMapItem for
automatic conversion when translating between libvirt's migration typed
parameters and QEMU's migration paramteres.

This patch is a preparation for future parameters as the existing
VIR_MIGRATE_PARAM_BANDWIDTH parameter is set using "migrate_set_speed"
QMP command rather than "migrate-set-parameters" for backward
compatibility.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoqemu: Use C99 initializers for qemuMigrationParamsTPMap
Jiri Denemark [Thu, 31 Jan 2019 08:32:42 +0000 (09:32 +0100)]
qemu: Use C99 initializers for qemuMigrationParamsTPMap

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agovirinitctl: Provide a stub list of init fifos for non-Linux
Michal Privoznik [Thu, 7 Feb 2019 11:47:26 +0000 (12:47 +0100)]
virinitctl: Provide a stub list of init fifos for non-Linux

The virInitctlFifos list is exported, but lacks definition for
non-Linux and/or non-BSD case.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
6 years agoqemu: Use data in qemuBlockJobDataPtr instead of re-generating job name
Peter Krempa [Thu, 24 Jan 2019 16:50:59 +0000 (17:50 +0100)]
qemu: Use data in qemuBlockJobDataPtr instead of re-generating job name

qemuDomainBlockPivot and qemuDomainBlockJobAbort need the job name for
cancelling or pivoting but were generating it locally instead of
accessing the existing copy in the job data structure.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoqemu: Remove unused 'cfg' qemuDomainBlockPivot
Peter Krempa [Thu, 24 Jan 2019 16:37:48 +0000 (17:37 +0100)]
qemu: Remove unused 'cfg' qemuDomainBlockPivot

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoqemu: Move shareable disk check for block copy
Peter Krempa [Thu, 24 Jan 2019 16:24:56 +0000 (17:24 +0100)]
qemu: Move shareable disk check for block copy

The writing to an image actually starts when the copy job is initiated,
so checking this at the time of the pivot operation is too late.

Move the check to qemuDomainBlockCopyCommon. Note that modern qemu would
have prevented two writers with qcow2 so the slim possibility of a job
started with libvirtd without this patch missing the check is not really
worth worrying about.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoqemu: Always save status XML in qemuDomainBlockJobAbort
Peter Krempa [Thu, 24 Jan 2019 16:13:58 +0000 (17:13 +0100)]
qemu: Always save status XML in qemuDomainBlockJobAbort

For copy and active commit jobs we record the state of the mirror so
that we can recover. The status XML was not saved in case of
qemuDomainBlockPivot due to an oversight.

Save the XML always when invoking qemuDomainBlockJobAbort even if
the job is not currently tracking any state. This will change later and
also this is not a particularly hot code path.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agolxc: Don't reboot host on virDomainReboot
Michal Privoznik [Fri, 25 Jan 2019 11:42:54 +0000 (12:42 +0100)]
lxc: Don't reboot host on virDomainReboot

If the container is really a simple one (init is just bash and
the whole root is passed through) then virDomainReboot and
virDomainShutdown will talk to the actual init within the host.
Therefore, 'virsh shutdown $dom' will result in shutting down the
host. True, at that point the container is shut down too but
looks a bit harsh to me.

The solution is to check if the init inside the container is or
is not the same as the init running on the host.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
6 years agovirinitctl: Expose fifo paths and allow caller to chose one
Michal Privoznik [Fri, 25 Jan 2019 11:37:53 +0000 (12:37 +0100)]
virinitctl: Expose fifo paths and allow caller to chose one

So far the virInitctlSetRunLevel() is fully automatic. It finds
the correct fifo to use to talk to the init and it will set the
desired runlevel. Well, callers (so far there is just one) will
need to inspect the fifo a bit just before the runlevel is set.
Therefore, expose the internal list of fifos and also allow
caller to explicitly use one.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
6 years agolxc: Restore seclabels after the container is killed
Michal Privoznik [Thu, 24 Jan 2019 16:38:10 +0000 (17:38 +0100)]
lxc: Restore seclabels after the container is killed

Due to a bug the seclabels are restored before any PID in the
container is killed. This should be done afterwards in
virLXCProcessCleanup.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
6 years agovircgroup: Try harder to kill cgroup
Michal Privoznik [Thu, 24 Jan 2019 16:20:58 +0000 (17:20 +0100)]
vircgroup: Try harder to kill cgroup

Prior to rewrite of cgroup code we only had one backend to try.
After the rewrite the virCgroupBackendGetAll() returns both
backends (for v1 and v2). However, not both have to really be
present on the system which results in killRecursive callback
failing which in turn might mean we won't try the other backend.

At the same time, this function reports no error as it should.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
6 years agolxc: Use correct job type for destroying a domain
Michal Privoznik [Thu, 24 Jan 2019 07:32:27 +0000 (08:32 +0100)]
lxc: Use correct job type for destroying a domain

Not that it would matter because LXC driver doesn't differentiate
the job types so far, but nevertheless the Destroy() should grab
LXC_JOB_DESTROY.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
6 years agoconf: Remove iothreads restriction in virDomainDefCheckABIStabilityFlags
Jie Wang [Thu, 31 Jan 2019 12:50:31 +0000 (20:50 +0800)]
conf: Remove iothreads restriction in virDomainDefCheckABIStabilityFlags

The number of iothreads is not part of the vm state sent during
migration, nor exposed to the guest ABI, so this restriction is
a mistake in libvirt. Let's remove that bit of code.

Reviewed-by: Cole Robinson <crobinso@redhat.com>
Signed-off-by: Jie Wang <wangjie88@huawei.com>
6 years agodosc: schema: fix usb source address device attribute format
Nikolay Shirokovskiy [Mon, 21 Jan 2019 08:40:09 +0000 (11:40 +0300)]
dosc: schema: fix usb source address device attribute format

Device attribute does not have dotted "portAddr" format. Instead it
has single number format described but "usbAddr" which corresponds
to device parsing code in virDomainHostdevSubsysUSBDefParseXML.

Looks like [1] mistakenly changed device format for hostdev devices.
And [2] copy-n-paste this for hostdev network interfaces.

[1] 31710a53 Modify USB port to be defined as a port path
[2] 3b1c191f conf: parse/format type='hostdev' network interfaces

Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
6 years agoqemu: Refactor virtio-input capabilities checks
Andrea Bolognani [Wed, 5 Sep 2018 16:28:58 +0000 (18:28 +0200)]
qemu: Refactor virtio-input capabilities checks

The checks and error messages are mostly the same across
all virtio-input devices, so we can avoid having multiple
copies of the same code.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agotests: Unify qemucaps2xml output files
Andrea Bolognani [Fri, 1 Feb 2019 12:16:18 +0000 (13:16 +0100)]
tests: Unify qemucaps2xml output files

Turns out different versions of QEMU on the same architecture
produce the same output, so we can have a single output file
per architecture instead of duplicating the same data over and
over again.

Spotted-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Andrea Bolognani <abologna@redhat.com>
6 years agoqemu: caps: Don't try to ask for CAP_DAC_OVERRIDE if non-root
Peter Krempa [Mon, 4 Feb 2019 15:24:15 +0000 (16:24 +0100)]
qemu: caps: Don't try to ask for CAP_DAC_OVERRIDE if non-root

It will not work. This breaks qemu capabilities probing as a user.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
6 years agoqemu: Refresh state before starting the VCPUs
Marc Hartmayer [Mon, 4 Feb 2019 12:36:24 +0000 (13:36 +0100)]
qemu: Refresh state before starting the VCPUs

For normal starts (no incoming migration) the refresh of the QEMU
state must be done before the VCPUs getting started since otherwise
there might be a race condition between a possible shutdown of the
guest OS and the QEMU monitor queries.

This fixes "qemu: migration: Refresh device information after
transferring state" (93db7eea1b864).

Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
6 years agoqemu: Assume migration with a network disk migration is safe
Michal Privoznik [Thu, 24 Jan 2019 08:58:38 +0000 (09:58 +0100)]
qemu: Assume migration with a network disk migration is safe

If a domain has a disk that is type='network' we require specific
cache mode to allow migration with it (either 'directsync' or
'none'). This doesn't make much sense since network disks are
supposed to be safe to migrate by default.

At the same time, we should be checking for the actual source
type, not apparent type set in the domain XML.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
6 years agoqemu: domain: Use 'raw' for 'volume' disks without format
Peter Krempa [Thu, 31 Jan 2019 14:37:53 +0000 (15:37 +0100)]
qemu: domain: Use 'raw' for 'volume' disks without format

Storage pools might want to specify format of the image when translating
the volume thus we can't add any default format when parsing the XML.

Add a explicit format when starting the VM and format is not present
neither by user specifying it nor by the storage pool translation
function.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoqemu: domain: Assume 'raw' default storage format also for network storage
Peter Krempa [Thu, 4 Oct 2018 12:43:46 +0000 (14:43 +0200)]
qemu: domain: Assume 'raw' default storage format also for network storage

Post parse callback adds the 'raw' type only for local files. Remote
files can also have backing store (even local) so we should do this also
for network backed storage.

Note that virStorageFileGetMetadata always considers files with no type
as raw so we will not accidentally traverse the backing chain and allow
unexpected files being labelled with svirt labels.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agotests: qemu: Test network disks without format specified explicitly
Peter Krempa [Mon, 8 Oct 2018 13:30:36 +0000 (15:30 +0200)]
tests: qemu: Test network disks without format specified explicitly

Modify some existing tests of network-based disks to omit the storage
format specification.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoqemu: command: Don't skip 'readonly' and throttling info for empty drive
Peter Krempa [Fri, 1 Feb 2019 16:54:46 +0000 (17:54 +0100)]
qemu: command: Don't skip 'readonly' and throttling info for empty drive

In commit f80eae8c2ae I was too agresive in removing properties of
-drive for empty drives. It turns out that qemu actually persists the
state of 'readonly' and the throttling information even for the empty
drive.

Removing 'readonly' thus made qemu open any subsequent images added via
the 'change' command as RW which was forbidden by selinux thanks to the
restrictive sVirt label for readonly media.

Fix this by formating the property again and bump the tests and leave a
note detailing why the rest of the properties needs to be skipped.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
6 years agonews: Fix typo
Andrea Bolognani [Mon, 4 Feb 2019 08:22:31 +0000 (09:22 +0100)]
news: Fix typo

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
6 years agoRequire a semicolon for VIR_ONCE_GLOBAL_INIT calls
Cole Robinson [Sun, 20 Jan 2019 17:23:29 +0000 (12:23 -0500)]
Require a semicolon for VIR_ONCE_GLOBAL_INIT calls

Missing semicolon at the end of macros can confuse some analyzers
(like cppcheck <filename>). VIR_ONCE_GLOBAL_INIT is almost
exclusively called without an ending semicolon, but let's
standardize on using one like the other macros.

Add a dummy struct definition at the end of the macro, so
the compiler will require callers to add a semicolon.

Reviewed-by: John Ferlan <jferlan@redhat.com>
Signed-off-by: Cole Robinson <crobinso@redhat.com>
6 years agoRequire a semicolon for VIR_LOG_INIT calls
Cole Robinson [Sun, 20 Jan 2019 16:32:42 +0000 (11:32 -0500)]
Require a semicolon for VIR_LOG_INIT calls

Missing semicolon at the end of macros can confuse some analyzers
(like cppcheck <filename>), and we have a mix of semicolon and
non-semicolon usage through the code. Let's standardize on using
a semicolon for VIR_LOG_INIT calls.

Drop the semicolon from the final statement of the macro, so
the compiler will require callers to add a semicolon.

Reviewed-by: John Ferlan <jferlan@redhat.com>
Signed-off-by: Cole Robinson <crobinso@redhat.com>
6 years agoRequire a semicolon for VIR_ENUM_IMPL calls
Cole Robinson [Sun, 20 Jan 2019 16:30:15 +0000 (11:30 -0500)]
Require a semicolon for VIR_ENUM_IMPL calls

Missing semicolon at the end of macros can confuse some analyzers
(like cppcheck <filename>), and we have a mix of semicolon and
non-semicolon usage through the code. Let's standardize on using
a semicolon for VIR_ENUM_IMPL calls.

Move the verify() statement to the end of the macro and drop
the semicolon, so the compiler will require callers to add a
semicolon.

While we are touching these call sites, standardize on putting
the closing parenth on its own line, as discussed here:
https://www.redhat.com/archives/libvir-list/2019-January/msg00750.html

Reviewed-by: John Ferlan <jferlan@redhat.com>
Signed-off-by: Cole Robinson <crobinso@redhat.com>
6 years agoRequire a semicolon to VIR_ENUM_DECL calls
Cole Robinson [Sun, 20 Jan 2019 16:04:56 +0000 (11:04 -0500)]
Require a semicolon to VIR_ENUM_DECL calls

Missing semicolon at the end of macros can confuse some analyzers
(like cppcheck <filename>), and we have a mix of semicolon and
non-semicolon usage through the code. Let's standardize on using
a semicolon for VIR_ENUM_DECL calls.

Drop the semicolon from the final statement of the macro, so
the compiler will require callers to add a semicolon.

Reviewed-by: John Ferlan <jferlan@redhat.com>
Signed-off-by: Cole Robinson <crobinso@redhat.com>
6 years agoutil: remove test code accidentally committed to virFirewallDZoneExists
Laine Stump [Sun, 3 Feb 2019 04:21:42 +0000 (23:21 -0500)]
util: remove test code accidentally committed to virFirewallDZoneExists

Just before pushing the series containing commit 3bba4825 I had added
a "return true" to the top of virFirewallDZoneExists() to measure the
impact of calling that function once per network during startup. I
found that the effect was minimal, but forgot to remove the "return
true" before pushing. This unfortunately causes a failure to start
networks on systems that have a firewalld version that doesn't support
our libvirt zone file (i.e. pretty much everyone).

This patch removes the unintended line.

Signed-off-by: Laine Stump <laine@laine.org>
6 years agodocs: bhyve: warn about bhyve:commandline risks
Roman Bogorodskiy [Thu, 31 Jan 2019 12:38:01 +0000 (16:38 +0400)]
docs: bhyve: warn about bhyve:commandline risks

Document that using bhyve:commandline is not fully
supported and may cause issues.

Signed-off-by: Roman Bogorodskiy <bogorodskiy@gmail.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
6 years agobhyve: emit warning when using bhyve:commandline
Roman Bogorodskiy [Thu, 31 Jan 2019 12:37:01 +0000 (16:37 +0400)]
bhyve: emit warning when using bhyve:commandline

When using custom command line arguments, warn that
this configuration is not fully supported.

Signed-off-by: Roman Bogorodskiy <bogorodskiy@gmail.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
6 years agobhyve: bhyveDomainDefNamespaceFormatXML cleanup
Roman Bogorodskiy [Thu, 31 Jan 2019 12:05:17 +0000 (16:05 +0400)]
bhyve: bhyveDomainDefNamespaceFormatXML cleanup

 - Remove ATTRIBUTE_UNUSED for the "buf" argument, it's
   not unused
 - Indent fix

Signed-off-by: Roman Bogorodskiy <bogorodskiy@gmail.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
6 years agodocs: update news.xml for firewalld zone changes
Laine Stump [Wed, 30 Jan 2019 18:18:09 +0000 (13:18 -0500)]
docs: update news.xml for firewalld zone changes

Signed-off-by: Laine Stump <laine@laine.org>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
6 years agonetwork: allow configuring firewalld zone for virtual network bridge device
Laine Stump [Wed, 9 Jan 2019 21:51:31 +0000 (16:51 -0500)]
network: allow configuring firewalld zone for virtual network bridge device

Since we're setting the zone anyway, it will be useful to allow
setting a different (custom) zone for each network. This will be done
by adding a "zone" attribute to the "bridge" element, e.g.:

   ...
   <bridge name='virbr0' zone='myzone'/>
   ...

If a zone is specified in the config and it can't be honored, this
will be an error.

Signed-off-by: Laine Stump <laine@laine.org>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
6 years agonetwork: set firewalld zone of bridges to "libvirt" zone when appropriate
Laine Stump [Tue, 16 Oct 2018 00:31:02 +0000 (20:31 -0400)]
network: set firewalld zone of bridges to "libvirt" zone when appropriate

This patch restores broken guest network connectivity after a host
firewalld is switched to using an nftables backend. It does this by
adding libvirt networks' bridge interfaces to the new "libvirt" zone
in firewalld.

After this patch, the bridge interface of any network created by
libvirt (when firewalld is active) will be added to the firewalld
zone called "libvirt" if it exists (regardless of the firewalld
backend setting). This behavior does *not* depend on whether or not
libvirt has installed the libvirt zone file (set with
"--with[out]-firewalld-zone" during the configure phase of the package
build).

If the libvirt zone doesn't exist (either because the package was
configured to not install it, or possibly it was installed, but
firewalld doesn't support rule priorities, resulting in a parse
error), the bridge will remain in firewalld's default zone, which
could be innocuous (in the case that the firewalld backend is
iptables, guest networking will still function properly with the
bridge in the default zone), or it could be disastrous (if the
firewalld backend is nftables, we can be assured that guest networking
will fail). In order to be unobtrusive in the former case, and
informative in the latter, when the libvirt zone doesn't exist we
then check the firewalld version to see if it's new enough to support
the nftables backend, and then if the backend is actually set to
nftables, before logging an error (and failing the net-start
operation, since the network couldn't possibly work anyway).

When the libvirt zone is used, network behavior is *slightly*
different from behavior of previous libvirt. In the past, libvirt
network behavior would be affected by the configuration of firewalld's
default zone (usually "public"), but now it is affected only by the
"libvirt" zone), and thus almost surely warrants a release note for
any distro upgrading to libvirt 5.1 or above. Although it's
unfortunate that we have to deal with a mandatory behavior change, the
architecture of multiple hooks makes it impossible to *not* change
behavior in some way, and the new behavior is arguably better (since
it will now be possible to manage access to the host from virtual
machines vs from public interfaces separately).

Creates-and-Resolves: https://bugzilla.redhat.com/1650320
Resolves: https://bugzilla.redhat.com/1638342
Signed-off-by: Laine Stump <laine@laine.org>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
6 years agoconfigure: selectively install a firewalld 'libvirt' zone
Laine Stump [Sat, 26 Jan 2019 04:52:37 +0000 (23:52 -0500)]
configure: selectively install a firewalld 'libvirt' zone

In the past (when both libvirt and firewalld used iptables), if either
libvirt's rules *OR* firewalld's rules accepted a packet, it would
be accepted. This was because libvirt and firewalld rules were
processed during the same kernel hook, and a single ACCEPT result
would terminate the rule traversal and cause the packet to be
accepted.

But now firewalld can use nftables for its backend, while libvirt's
firewall rules are still using iptables; iptables rules are still
processed, but at a different time during packet processing
(i.e. during a different hook) than the firewalld nftables rules. The
result is that a packet must be accepted by *BOTH* the libvirt
iptables rules *AND* the firewalld nftable rules in order to be
accepted.

This causes pain because

1) libvirt always adds rules to permit DNS and DHCP (and sometimes
TFTP) from guests to the host network's bridge interface. But
libvirt's bridges are in firewalld's "default" zone (which is usually
the zone called "public"). The public zone allows ssh, but doesn't
allow DNS, DHCP, or TFTP. So even though libvirt's rules allow the
DHCP and DNS traffic, the firewalld rules (now processed during a
different hook) dont, thus guests connected to libvirt's bridges can't
acquire an IP address from DHCP, nor can they make DNS queries to the
DNS server libvirt has setup on the host. (This could be solved by
modifying the default firewalld zone to allow DNS and DHCP, but that
would open *all* interfaces in the default zone to those services,
which is most likely not what the host's admin wants.)

2) Even though libvirt adds iptables rules to allow forwarded traffic
to pass the iptables hook, firewalld's higher level "rich rules" don't
yet have the ability to configure the acceptance of forwarded traffic
(traffic that is going somewhere beyond the host), so any traffic that
needs to be forwarded from guests to the network beyond the host is
rejected during the nftables hook by the default zone's "default
reject" policy (which rejects all traffic in the zone not specifically
allowed by the rules in the zone, whether that traffic is destined to
be forwarded or locally received by the host).

libvirt can't send "direct" nftables rules (firewalld only supports
direct/passthrough rules for iptables), so we can't solve this problem
by just sending explicit nftables rules instead of explicit iptables
rules (which, if it could be done, would place libvirt's rules in the
same hook as firewalld's native rules, and thus eliminate the need for
packets to be accepted by both libvirt's and firewalld's own rules).

However, we can take advantage of a quirk in firewalld zones that have
a default policy of "accept" (meaning any packet that doesn't match a
specific rule in the zone will be *accepted*) - this default accept will
also accept forwarded traffic (not just traffic destined for the host).

Of course we don't want to modify firewalld's default zone in that
way, because that would affect the filtering of traffic coming into
the host from other interfaces using that zone. Instead, we will
create a new zone called "libvirt". The libvirt zone will have a
default policy of accept so that forwarded traffic can pass and list
specific services that will be allowed into the host from guests (DNS,
DHCP, SSH, and TFTP).

But the same default accept policy that fixes forwarded traffic also
causes *all* traffic from guest to host to be accepted. To close this
new hole, the libvirt zone can take advantage of a new feature in
firewalld (currently slated for firewalld-0.7.0) - priorities for rich
rules - to add a low priority rule that rejects all local traffic (but
leaves alone all forwarded traffic).

So, our new zone will start with a list of services that are allowed
(dhcp, dns, tftp, and ssh to start, but configurable via any firewalld
management application, or direct editing of the zone file in
/etc/firewalld/zones/libvirt.xml), followed by a low priority
<reject/> rule (to reject all other traffic from guest to host), and
finally with a default policy of accept (to allow forwarded traffic).

This patch only creates the zonefile for the new zone, and implements
a configure.ac option to selectively enable/disable installation of
the new zone. A separate patch contains the necessary code to actually
place bridge interfaces in the libvirt zone.

Why do we need a configure option to disable installation of the new
libvirt zone? It uses a new firewalld attribute that sets the priority
of a rich rule; this feature first appears in firewalld-0.7.0 (unless
it has been backported to am earlier firewalld by a downstream
maintainer). If the file were installed on a system with firewalld
that didn't support rule priorities, firewalld would log an error
every time it restarted, causing confusion and lots of extra bug
reports.

So we add two new configure.ac switches to avoid polluting the system
logs with this error on systems that don't support rule priorities -
"--with-firewalld-zone" and "--without-firewalld-zone". A package
builder can use these to include/exclude the libvirt zone file in the
installation. If firewalld is enabled (--with-firewalld), the default
is --with-firewalld-zone, but it can be disabled during configure
(using --without-firewalld-zone). Targets that are using a firewalld
version too old to support the rule priority setting in the libvirt
zone file can simply add --without-firewalld-zone to their configure
commandline.

These switches only affect whether or not the libvirt zone file is
*installed* in /usr/lib/firewalld/zones, but have no effect on whether
or not libvirt looks for a zone called libvirt and tries to use it.

NB: firewalld zones can only be added to the permanent config of
firewalld, and won't be loaded/enabled until firewalld is restarted,
so at package install/upgrade time we have to restart firewalld. For
rpm-based distros, this is done in the libvirt.spec file by calling
the %firewalld_restart rpm macro, which is a part of the
firewalld-filesystem package. (For distros that don't use rpm
packages, the command "firewalld-cmd --reload" will have the same
effect).

Signed-off-by: Laine Stump <laine@laine.org>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
6 years agoutil: new virFirewallD APIs + docs
Laine Stump [Wed, 9 Jan 2019 19:40:51 +0000 (14:40 -0500)]
util: new virFirewallD APIs + docs

virFirewallDGetBackend() reports whether firewalld is currently using
an iptables or an nftables backend.

virFirewallDGetVersion() learns the version of the firewalld running
on this system and returns it as 1000000*major + 1000*minor + micro.

virFirewallDGetZones() gets a list of all currently active firewalld
zones.

virFirewallDInterfaceSetZone() sets the firewalld zone of the given
interface.

virFirewallDZoneExists() can be used to learn whether or not a
particular zone is present and active in firewalld.

Signed-off-by: Laine Stump <laine@laine.org>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
6 years agoutil: move all firewalld-specific stuff into its own files
Laine Stump [Wed, 9 Jan 2019 19:11:32 +0000 (14:11 -0500)]
util: move all firewalld-specific stuff into its own files

In preparation for adding several other firewalld-specific functions,
separate the code that's unique to firewalld from the more-generic
"firewall" file.

Signed-off-by: Laine Stump <laine@laine.org>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
6 years agoconfigure: change HAVE_FIREWALLD to WITH_FIREWALLD
Laine Stump [Sat, 26 Jan 2019 04:46:18 +0000 (23:46 -0500)]
configure: change HAVE_FIREWALLD to WITH_FIREWALLD

Support for firewalld is a feature that can be selectively enabled or
disabled (using --with-firewalld/--without-firewalld), not merely
something that must be accounted for in the code if it is present with
no exceptions. It is more consistent with other usage in libvirt to
use WITH_FIREWALLD rather than HAVE_FIREWALLD.

Signed-off-by: Laine Stump <laine@laine.org>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
6 years agoutil: Fix build issue with virStorageFileGetNPIVKey
John Ferlan [Fri, 1 Feb 2019 16:32:56 +0000 (11:32 -0500)]
util: Fix build issue with virStorageFileGetNPIVKey

Signed-off-by: John Ferlan <jferlan@redhat.com>
6 years agodocs: news: Update the release notes with the SEV permission fix
Erik Skultety [Fri, 1 Feb 2019 12:05:56 +0000 (13:05 +0100)]
docs: news: Update the release notes with the SEV permission fix

Signed-off-by: Erik Skultety <eskultet@redhat.com>
Reviewed-by: Andrea Bolognani <abologna@redhat.com>
6 years agostorage: Fetch a unique key for vHBA/NPIV LUNs
John Ferlan [Fri, 18 Jan 2019 13:33:10 +0000 (08:33 -0500)]
storage: Fetch a unique key for vHBA/NPIV LUNs

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

Commit be1bb6c95 changed the way volumes were stored from a forward
linked list to a hash table. In doing so, it required that each vol
object would have 3 unique values as keys into tables - key, name,
and path. Due to how vHBA/NPIV LUNs are created/used this resulted
in a failure to utilize all the LUN's found during processing.

During virStorageBackendSCSINewLun processing fetch the key (or
serial value) for NPIV LUN's using virStorageFileGetNPIVKey which
will formulate a more unique key based on the serial value and
the port for the LUN.

Signed-off-by: John Ferlan <jferlan@redhat.com>
ACKed-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoutil: Introduce virStorageFileGetNPIVKey
John Ferlan [Wed, 16 Jan 2019 00:07:07 +0000 (19:07 -0500)]
util: Introduce virStorageFileGetNPIVKey

The vHBA/NPIV LUNs created via the udev processing of the
VPORT_CREATE command end up using the same serial value
as seen/generated by the /lib/udev/scsi_id as returned
during virStorageFileGetSCSIKey. Therefore, in order to
generate a unique enough key to be used when adding the
LUN as a volume during virStoragePoolObjAddVol a more
unique key needs to be generated for an NPIV volume.

The problem is illustrated by the following example, where
scsi_host5 is a vHBA used with the following LUNs:

$ lsscsi -tg
...
[5:0:4:0]    disk    fc:0x5006016844602198,0x101f00  /dev/sdh   /dev/sg23
[5:0:5:0]    disk    fc:0x5006016044602198,0x102000  /dev/sdi   /dev/sg24
...

Calling virStorageFileGetSCSIKey would return:

/lib/udev/scsi_id --device /dev/sdh --whitelisted --replace-whitespace /dev/sdh
350060160c460219850060160c4602198
/lib/udev/scsi_id --device /dev/sdh --whitelisted --replace-whitespace /dev/sdi
350060160c460219850060160c4602198

Note that althrough /dev/sdh and /dev/sdi are separate LUNs, they
end up with the same serial number used for the vol->key value.
When virStoragePoolFCRefreshThread calls virStoragePoolObjAddVol
the second LUN fails to be added with the following message
getting logged:

    virHashAddOrUpdateEntry:341 : internal error: Duplicate key

To resolve this, virStorageFileGetNPIVKey will use a similar call
sequence as virStorageFileGetSCSIKey, except that it will add the
"--export" option to the call. This results in more detailed output
which needs to be parsed in order to formulate a unique enough key
to be used. In order to be unique enough, the returned value will
concatenate the target port as returned in the "ID_TARGET_PORT"
field from the command to the "ID_SERIAL" value.

Signed-off-by: John Ferlan <jferlan@redhat.com>
ACKed-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agostorage: Rework virStorageBackendSCSISerial
John Ferlan [Tue, 15 Jan 2019 20:59:21 +0000 (15:59 -0500)]
storage: Rework virStorageBackendSCSISerial

Alter the code to use the virStorageFileGetSCSIKey helper
to fetch the unique key for the SCSI disk. Alter the logic
to follow the former code which would return a duplicate
of @dev when either the virCommandRun succeeded, but returned
an empty string or when WITH_UDEV was not true.

Signed-off-by: John Ferlan <jferlan@redhat.com>
ACKed-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoutil: Modify virStorageFileGetSCSIKey return
John Ferlan [Tue, 15 Jan 2019 21:11:48 +0000 (16:11 -0500)]
util: Modify virStorageFileGetSCSIKey return

Alter the "real" code to return -2 on virCommandRun failure.
Alter the comments and function header to describe the function
and its returns.

Signed-off-by: John Ferlan <jferlan@redhat.com>
ACKed-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoqemu: Rework setting process affinity
Michal Privoznik [Wed, 30 Jan 2019 08:46:23 +0000 (09:46 +0100)]
qemu: Rework setting process affinity

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

The way we currently start qemu from CPU affinity POV is as
follows:

  1) the child process is set affinity to all online CPUs (unless
  some vcpu pinning was given in the domain XML)

  2) Once qemu is running, cpuset cgroup is configured taking
  memory pinning into account

Problem is that we let qemu allocate its memory just anywhere in
1) and then rely in 2) to be able to move the memory to
configured NUMA nodes. This might not be always possible (e.g.
qemu might lock some parts of its memory) and is very suboptimal
(copying large memory between NUMA nodes takes significant amount
of time).

The solution is to set affinity to one of (in priority order):
  - The CPUs associated with NUMA memory affinity mask
  - The CPUs associated with emulator pinning
  - All online host CPUs

Later (once QEMU has allocated its memory) we then change this
again to (again in priority order):
  - The CPUs associated with emulator pinning
  - The CPUs returned by numad
  - The CPUs associated with vCPU pinning
  - All online host CPUs

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
6 years agoqemu: caps: Use CAP_DAC_OVERRIDE for probing to avoid permission issues
Erik Skultety [Thu, 24 Jan 2019 09:33:01 +0000 (10:33 +0100)]
qemu: caps: Use CAP_DAC_OVERRIDE for probing to avoid permission issues

This is mainly about /dev/sev and its default permissions 0600. Of
course, rule of 'tinfoil' would be that we can't trust anything, but the
probing code in QEMU is considered safe from security's perspective + we
can't create an udev rule for this at the moment, because ioctls and
file system permissions aren't cross-checked in kernel and therefore a
user with read permissions could issue a 'privileged' operation on SEV
which is currently only limited to root.

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

Signed-off-by: Erik Skultety <eskultet@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
6 years agosecurity: dac: Relabel /dev/sev in the namespace
Erik Skultety [Thu, 31 Jan 2019 14:16:50 +0000 (15:16 +0100)]
security: dac: Relabel /dev/sev in the namespace

The default permissions (0600 root:root) are of no use to the qemu
process so we need to change the owner to qemu iff running with
namespaces.

Signed-off-by: Erik Skultety <eskultet@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
6 years agoqemu: domain: Add /dev/sev into the domain mount namespace selectively
Erik Skultety [Tue, 22 Jan 2019 12:46:16 +0000 (13:46 +0100)]
qemu: domain: Add /dev/sev into the domain mount namespace selectively

Instead of exposing /dev/sev to every domain, do it selectively.

Signed-off-by: Erik Skultety <eskultet@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
6 years agoqemu: cgroup: Expose /dev/sev/ only to domains that require SEV
Erik Skultety [Mon, 21 Jan 2019 13:50:11 +0000 (14:50 +0100)]
qemu: cgroup: Expose /dev/sev/ only to domains that require SEV

SEV has a limit on number of concurrent guests. From security POV we
should only expose resources (any resources for that matter) to domains
that truly need them.

Signed-off-by: Erik Skultety <eskultet@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
6 years agoqemu: conf: Remove /dev/sev from the default cgroup device acl list
Erik Skultety [Mon, 21 Jan 2019 13:48:02 +0000 (14:48 +0100)]
qemu: conf: Remove /dev/sev from the default cgroup device acl list

We should not give domains access to something they don't necessarily
need by default. Remove it from the qemu driver docs too.

Signed-off-by: Erik Skultety <eskultet@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
6 years agotests: Update qemucaps2xml for QEMU 4.0.0 on x86_64
Andrea Bolognani [Thu, 31 Jan 2019 13:02:47 +0000 (14:02 +0100)]
tests: Update qemucaps2xml for QEMU 4.0.0 on x86_64

Commit fb0d0d6c5492 added capabilities data and updated
qemucapabilitiestest but forgot to update qemucaps2xmltest
at the same time.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agonews: Update for PCI support on RISC-V
Andrea Bolognani [Thu, 31 Jan 2019 14:20:09 +0000 (15:20 +0100)]
news: Update for PCI support on RISC-V

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agotests: Add test for PCI usage on RISC-V
Andrea Bolognani [Thu, 31 Jan 2019 13:54:11 +0000 (14:54 +0100)]
tests: Add test for PCI usage on RISC-V

This shows users can now use PCI for RISC-V guests, as long
as they opt into it by manually assigning addresses.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoqemu: Add PCI support for RISC-V guests
Andrea Bolognani [Fri, 21 Sep 2018 13:29:38 +0000 (15:29 +0200)]
qemu: Add PCI support for RISC-V guests

virtio-mmio is still used by default, so if PCI is desired
it's necessary to explicitly opt-in by adding an appropriate

  <address type='pci' domain='0x0000' ... />

element to the corresponding device.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agotests: Add capabilities data for QEMU 4.0.0 on RISC-V
Andrea Bolognani [Thu, 31 Jan 2019 13:07:34 +0000 (14:07 +0100)]
tests: Add capabilities data for QEMU 4.0.0 on RISC-V

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agonetwork: set mtu as a DHCP option when specified
Casey Callendrello [Tue, 11 Dec 2018 16:05:43 +0000 (17:05 +0100)]
network: set mtu as a DHCP option when specified

This adds an additional directive to the dnsmasq configuration file that
notifies clients via dhcp about the link's MTU. Guests can then choose
adjust their link accordingly.

Signed-off-by: Casey Callendrello <cdc@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
6 years agostoragepoolxml2argvtest: run mountopts test conditionally
Ján Tomko [Thu, 31 Jan 2019 14:43:40 +0000 (15:43 +0100)]
storagepoolxml2argvtest: run mountopts test conditionally

This test relies on namespace support, which is only compiled in
if we have the 'fs' and 'netfs' backends.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Andrea Bolognani <abologna@redhat.com>
6 years agostoragepoolxml2argvtest: introduce DO_TEST_PLATFORM
Ján Tomko [Thu, 31 Jan 2019 14:40:22 +0000 (15:40 +0100)]
storagepoolxml2argvtest: introduce DO_TEST_PLATFORM

Instead of repeating the same platform for every test,
set it once, since we do the same tests with the same
input for all platforms, it's just the output that differs.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Andrea Bolognani <abologna@redhat.com>
6 years agostoragepoolxml2argvtest: pass the platform suffix as a string
Ján Tomko [Thu, 31 Jan 2019 14:10:58 +0000 (15:10 +0100)]
storagepoolxml2argvtest: pass the platform suffix as a string

Instead of a pair of bools.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Andrea Bolognani <abologna@redhat.com>
6 years agodocs: Drop /dev/net/tun from the list of shared devices
Erik Skultety [Thu, 31 Jan 2019 15:04:36 +0000 (16:04 +0100)]
docs: Drop /dev/net/tun from the list of shared devices

This was a left-over that should have been dropped along the change in
qemu.conf.

Signed-off-by: Erik Skultety <eskultet@redhat.com>
6 years agotests: Fix storagepoolxml2xmltest execution for XML namespaces
John Ferlan [Wed, 30 Jan 2019 15:26:48 +0000 (10:26 -0500)]
tests: Fix storagepoolxml2xmltest execution for XML namespaces

Only run the pool-netfs-ns-mountopts if built WITH_STORAGE_FS and only
run pool-rbd-ns-configopts if built with WITH_STORAGE_RBD since the
namespace support is only enabled if the pool is enabled.

Signed-off-by: John Ferlan <jferlan@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoqemu: remove check for 'qemu' binary
Daniel P. Berrangé [Thu, 31 Jan 2019 13:18:39 +0000 (13:18 +0000)]
qemu: remove check for 'qemu' binary

The 'qemu' binary used to provide the i386 emulator until it was renamed
to qemu-system-i386 in QEMU 1.0. Since we don't support such old
versions we don't need to check for 'qemu' when probing capabilities.

Reviewed-by: Erik Skultety <eskultet@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>