Commit Graph

20746 Commits

Author SHA1 Message Date
Andrea Bolognani
4fb8ff9987 conf: Drop virDomainChrDeviceType.targetTypeAttr
This attribute was used to decide whether to format the type
attribute of the <target> element, but the logic didn't take into
account all possible cases and as such could lead to unexpected
results. Moreover, it's one more thing to keep track of, and can
easily fall out of sync with other attributes.

Now that we have VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_NONE, we can
use that value to signal that no specific target type has been
configured for the serial device and as such the attribute should
not be formatted at all. All other values are now formatted.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
2017-11-28 15:46:32 +01:00
Andrea Bolognani
6385c8c142 conf: Introduce VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_NONE
This is the first step in getting rid of the assumption that
isa-serial is the default target type for serial devices.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
2017-11-28 15:46:32 +01:00
Andrea Bolognani
2628afc143 conf: Run devicePostParse() again for the first serial device
The devicePostParse() callback is invoked for all devices so that
drivers have a chance to set their own specific values; however,
virDomainDefAddImplicitDevices() runs *after* the devicePostParse()
callbacks have been invoked and can add new devices, in which case
the driver wouldn't have a chance to customize them.

Work around the issue by invoking the devicePostParse() callback
after virDomainDefAddImplicitDevices(), only for the first serial
devices, which might have been added by it. The same was already
happening for the first video device for the very same reason.

This will become important later on, when we will change
virDomainDefAddConsoleCompat() not to set a targetType for
automatically added serial devices.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
2017-11-28 15:46:31 +01:00
Andrea Bolognani
f4b50cc1b9 qemu: Introduce qemuDomainChrDefPostParse()
Having a separate function for char device handling is better than
adding even more code to qemuDomainDeviceDefPostParse().

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Marc Hartmayer <mhartmay@linux.vnet.ibm.com>
2017-11-28 15:46:31 +01:00
John Ferlan
c5c96545c7 qemu: Use secret objects to pass iSCSI passwords
https://bugzilla.redhat.com/show_bug.cgi?id=1425757

The blockdev-add code provides a mechanism to sanely provide user
and password-secret arguments for iscsi without placing them on the
command line to be viewable by a 'ps -ef' type command or needing
to create separate -iscsi devices for each disk/volume found.

So modify the iSCSI command line building to check for the presence
of the capability in order properly setup and use the domain master
secret object to encrypt the password in a secret object and alter
the parameters for the command line to utilize.

Modify the xml2argvtest to exhibit the syntax for both disk and
hostdev configurations.
2017-11-24 11:47:26 -05:00
John Ferlan
4f44b8b5ae qemu: Get capabilities to use iscsi password-secret argument
Detect the capability via the query-qmp-schema for blockdev-add
to find the 'password-secret' parameter that will allow the iSCSI
code to use the master secret object to encrypt the secret for an
and only need to provide the object id of the secret on the command
line thus obsfuscating the passphrase.
2017-11-24 11:47:26 -05:00
John Ferlan
8001c2f3e4 qemu: Refactor qemuBuildSCSIiSCSIHostdevDrvStr slightly
Rather than building the "file" string in qemuBuildSCSIHostdevDrvStr
build it in the called helper.
2017-11-24 11:47:26 -05:00
John Ferlan
1d9108cf16 qemu: Remove private hostdev
Since it's not longer used to shuttle the @secinfo, let's remove
the private hostdev completely.
2017-11-24 11:47:26 -05:00
John Ferlan
16eef5c2b4 qemu: Use private storage source for iscsi instead of private hostdev
Rather than placing/using privateData about secinfo in the hostdev,
let's use the virStorageSource private data instead.
2017-11-24 11:47:26 -05:00
John Ferlan
626ea2d596 conf,qemu: Replace iscsisrc fields with virStorageSourcePtr
Rather than picking apart the two pieces we need/want (path, hosts,
and auth)- let's allocate/use a virStorageSourcePtr for iSCSI storage.

The end result is that qemuBuildSCSIiSCSIHostdevDrvStr doesn't need
to "fake" one for the qemuBuildNetworkDriveStr call.
2017-11-24 11:47:26 -05:00
Ján Tomko
2814f66f28 qemu: Properly label and create evdev on input device hotplug
Utilize all the newly introduced function to create the evdev node
and label it on hotplug and destroy it on hotunplug.

This was forgotten in commits bc9ffaf and 67486bb.

https://bugzilla.redhat.com/show_bug.cgi?id=1509866
2017-11-24 17:38:51 +01:00
Ján Tomko
c4c7a18c4b qemu: functions for dealing with input device namespaces and labels
Introudce functions that will let us create the evdevs in namespaces
and label the devices on input device hotplug/hotunplug.
2017-11-24 17:38:51 +01:00
Ján Tomko
f29612fd35 qemu: Introduce functions for input device cgroup manipulation
Export qemuSetupInputCgroup and introduce qemuTeardownInputCgroup
for hotunplug.
2017-11-24 17:38:51 +01:00
Ján Tomko
d8116b5a0a security: Introduce functions for input device hot(un)plug
Export the existing DAC and SELinux for separate use and introduce
functions for stack, nop and the security manager.
2017-11-24 17:38:51 +01:00
Ján Tomko
cbf4242db7 Introduce virDomainInputDefGetPath
Use it to denadify qemuDomainSetupInput.
2017-11-24 17:38:51 +01:00
Jason J. Herne
74fc32a955 s390: qemu-capabilities: Avoid error message when missing non-kvm host cpu info
Libvirt prints an error on startup when it is missing host cpu model
information for any queried qemu binary. On s390 we only have host cpu model
information for kvm enabled qemu instances. So when virt type is not kvm, this
is actually not an error on s390.

This patch adds virt type as a parameter to virQEMUCapsInitCPUModelS390, and a
new return code 2 for virQEMUCapsInitCPUModel and virQEMUCapsInitCPUModelS390.
If the virt type is not kvm then we skip printing the scary error message
and return 2 because this case is actually expected behavior. The new return
code is meant to differentiate between the failure case and the case where we
simply expect the cpu model information to be unattainable.

Signed-off-by: Jason J. Herne <jjherne@linux.vnet.ibm.com>
Reviewed-by: Boris Fiuczynski <fiuczy@linux.vnet.ibm.com>
Reviewed-by: Marc Hartmayer <mhartmay@linux.vnet.ibm.com>
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2017-11-24 16:53:56 +01:00
John Ferlan
6caf67f834 storage: Fix broken storage_driver build
Commit id '5d5c732d7' had an incorrect assignment and was found
by travis build:

storage/storage_driver.c:1668:14: error: equality comparison with extraneous
      parentheses [-Werror,-Wparentheses-equality]
    if ((obj == virStoragePoolObjListSearch(&driver->pools,

         ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2017-11-24 09:42:07 -05:00
John Ferlan
dcb5d8bb13 storage: Convert virStoragePoolObj into virObjectLockable
Now that we're moved the object into virstorageobj, let's make the
code use the lockable object.
2017-11-24 08:08:36 -05:00
John Ferlan
5d5c732d74 storage: Introduce virStoragePoolObjListSearch
Create an API to search through the storage pool objects looking for
a specific truism from a callback API in order to return the specific
storage pool object that is desired.
2017-11-24 08:08:32 -05:00
John Ferlan
d0258dd9d6 storage: Introduce virStoragePoolObjListForEach
Create an API to walk the pools->objs[] list in order to perform a
callback function for each element of the objs array that doesn't care
about whether the action succeeds or fails as the desire is to run the
code over every element in the array rather than fail as soon as or if
one fails.
2017-11-24 07:26:06 -05:00
John Ferlan
770aa08e48 storage: Introduce virStoragePoolObjEndAPI
For now it'll just call the virStoragePoolObjUnlock, but a future
adjustment will do something different. Since the new API will check
for a NULL object before the Unlock call, callers no longer need to
check for NULL before calling.

The virStoragePoolObjUnlock is now private/static to virstorageobj.c
with a short term forward reference.
2017-11-24 07:26:06 -05:00
John Ferlan
9bfcf3ccdd nodedev: Restore setting of privileged
Commit id '36555364' removed the setting of the driver->privileged,
which the udevProcessPCI would need in order to read the PCI device
configs.

Signed-off-by: John Ferlan <jferlan@redhat.com>
2017-11-24 07:17:37 -05:00
Peter Krempa
1455a91b33 qemu: command: Properly format disk 'debug' attribute
Move the setup of the disk attribute to the disk source prepare function
which will allow proper usage with JSON props and move the fallback
(legacy) generating code into the block which is executed with legacy
options.

As a side-effect of this change we can clean up propagation of 'cfg'
into the command generator.

Also it's nice to see that the test output is the same even when the
value is generated in a different place.
2017-11-23 18:50:04 +01:00
Peter Krempa
be50137aa0 qemu: domain: Unify disk source prepare steps
Aggregate setup of various aspects of a disk source (secrets, TLS, ...)
into one function so that we don't need to call multiple across the code
base.
2017-11-23 18:50:04 +01:00
Peter Krempa
7aa8a9a621 qemu: hotplug: Rename qemuDomainPrepareDisk to qemuHotplugPrepareDiskAccess
Match the prefix of the file and choose a name which better describes
what happens.
2017-11-23 18:50:04 +01:00
Peter Krempa
eeaf6657f7 qemu: block: Add support for formatting gluster debug level via JSON
Improve the formatter so that we can use the 'debug' property straight
away when using json.
2017-11-23 18:50:04 +01:00
Peter Krempa
0a1870ddd0 util: storage: Add fields for debug options for disk drivers
Some drive backends allow output of debugging information which can be
configured using properties of the image. Add fields to virStorageSource
which will allow configuring them.
2017-11-23 18:50:04 +01:00
Peter Krempa
6197d5726b qemu: command: Inject password-secret only when not using JSON props
The 'file.password-secret' injection should be used only if we are using
the old formatter. When formatting the source string from the JSON
properties, the property should be added there.

Also drop the comment which refers to stuff that will not be used in
libvirt since -blockdev is the way to go.
2017-11-23 18:50:04 +01:00
Peter Krempa
28907b0043 qemu: command: Mark <shared/> disks as such in qemu
Qemu has now an internal mechanism for locking images to fix specific
cases of disk corruption. This requires libvirt to mark the image as
shared so that qemu lifts certain restrictions.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1378242
2017-11-23 18:26:48 +01:00
Peter Krempa
860a3c4bea qemu: caps: Add capability for 'share-rw' disk option
'share-rw' for the disk device configures qemu to allow concurrent
access to the backing storage.

The capability is checked in various supported disk frontend buses since
it does not make sense to partially backport it.
2017-11-23 18:26:48 +01:00
Peter Krempa
2b41c86294 qemu: Disallow pivot of shared disks to unsupported storage
Pivoting to a unsupported storage type might break the assumption that
shared disks will not corrupt metadata.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1511480
2017-11-23 18:26:48 +01:00
Peter Krempa
9b2fbfa6f6 qemu: snapshot: Disallow snapshot of unsupported shared disks
Creating a snapshot would introduce a possibly unsupported member for
sharing into the backing chain. Add a check to prevent that from
happening.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1511480
2017-11-23 18:26:48 +01:00
Peter Krempa
3b03a27cd0 qemu: domain: Reject shared disk access if backing format does not support it
Disk sharing between two VMs may corrupt the images if the format driver
does not support it. Check that the user declared use of a supported
storage format when they want to share the disk.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1511480
2017-11-23 18:26:25 +01:00
Peter Krempa
1fc3cd8731 qemu: block: Add function to check if storage source allows concurrent access
Storage source format backing a shared device (e.g. running a cluster
filesystem) needs to support the sharing so that metadata are not
corrupted. Add a central function for checking this.
2017-11-23 18:26:25 +01:00
Peter Krempa
85b0e2f126 qemu: domain: Refactor domain device validation function
Use a style that will discourage from adding inline checks.
2017-11-23 18:26:25 +01:00
Peter Krempa
ab948b6299 qemu: domain: Move video device validation into separate function 2017-11-23 18:26:25 +01:00
Peter Krempa
a6936ec098 qemu: domain: Move hostdev validation into separate function 2017-11-23 18:26:25 +01:00
Peter Krempa
577ccd07c3 qemu: domain: Despaghettify qemuDomainDeviceDefValidate
Move network device validation into a separate function.
2017-11-23 18:26:14 +01:00
Peter Krempa
8ffdeed455 qemu: Move snapshot disk validation functions into one
Move the code so that both the new image and old image can be verified
in the same function.
2017-11-23 18:22:19 +01:00
Michal Privoznik
97a051f0f8 qemu: Support setting NUMA distances
Since we already have such support for libxl all we need is qemu
driver adjustment. And a test case.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2017-11-23 14:54:32 +01:00
Michal Privoznik
13e148ebda qemu_capabilities: Introcude QEMU_CAPS_NUMA_DIST
This capability says if qemu is capable of specifying distances
between NUMA nodes on the command line. Unfortunately, there's no
real way to check this and thus we have to go with version check.
QEMU introduced this in 0f203430dd8 (and friend) which was
released in 2.10.0.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2017-11-23 14:54:31 +01:00
Michal Privoznik
ab9baab729 numa: Introduce virDomainNumaNodeDistanceIsUsingDefaults
The function returns true/false depending on distance
configuration being present in the domain XML.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2017-11-23 14:54:31 +01:00
Michal Privoznik
0ededbb84e virDomainNumaGetNodeDistance: Fix input arguments validation
There's no point in checking if numa->mem_nodes[node].ndistances
is set if we check for numa->mem_nodes[node].distances. However,
it makes sense to check if the sibling node (@cellid) caller
passed falls within boundaries.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2017-11-23 14:54:31 +01:00
Jiri Denemark
96f7a045e9 qemu: Use the end of QEMU log for reporting errors
When QEMU dies, we read its output stored in a log file and use it for
reporting a hopefully useful error. However, virReportError will trim
the message to (VIR_ERROR_MAX_LENGTH - 1) characters, which means the
end of the log (which likely contains the error message we want to
report) may get lost. We should trim the beginning of the log instead.

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

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
2017-11-23 14:06:40 +01:00
Jiri Denemark
c88ce8ae74 vierror: Define VIR_ERROR_MAX_LENGTH macro
And use it instead of a magic 1024 constant.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
2017-11-23 14:06:40 +01:00
Jiri Denemark
7e0cd26db4 qemu: Properly skip "char device redirected to" in QEMU log
When reading QEMU log for reporting it as an error message, we want to
skip "char device redirected to" line. However, this string is not
printed at the beginning of a line, which means STRPREFIX will never
find it.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
2017-11-23 14:06:40 +01:00
Martin Kletzander
ea7b2a6d04 util: Fix leak in virStringTrimOptionalNewline
Do not access any data if strlen() == 0.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2017-11-23 11:31:52 +01:00
Peter Krempa
9baf50c414 qemu: command: Anotate formatting of the frontend attributes with -drive
Explain that certain attributes formatted with -drive are in fact
attributes of the drive itself and not the storage backing it.
2017-11-22 20:37:36 +01:00
Peter Krempa
1bf4dfc02a qemu: command: Move formatting of disk io error policy from -drive
That's a disk frontend attribute. Move the code to a separate function
since it's non-trivial and call it from the frontend attribute
formatter.
2017-11-22 20:37:36 +01:00
Peter Krempa
3443fddfea qemu: command: Move disk trhottling argument building into a separate function
Isolate it from the other code.
2017-11-22 20:37:36 +01:00
Peter Krempa
55a5d71825 qemu: command: Refactor logic when formatting -drive
Move all logic depending on whether we are solely formatting -drive (no
-device along with it) into one block.
2017-11-22 20:37:36 +01:00
Peter Krempa
b9dfed787d qemu: command: Move around order of generating -drive arguments
Move together sections which are conditionaly executed depending on
whether -device will be used together with the -drive.
2017-11-22 20:37:36 +01:00
Peter Krempa
ccc1d910ce qemu: command: Move disk 'serial' into frontend parameter formatter
Disk serial is not a property of the image but of the disk frontend.
Account for this appropriately.
2017-11-22 20:37:36 +01:00
Peter Krempa
401ddfa4e8 qemu: command: Split out geometry frontend attribute formatting from -drive
Historically we've formatted a lot of the attributes of a disk (disk
geometry, etc) with -drive. Since we use -device now, they should be
formatted there. Extract them to a separate function for keeping
compatibility with SDcards which still use only -drive.

Start this by moving the geometry into a separate function.
2017-11-22 20:37:35 +01:00
Peter Krempa
3746a38e7b qemu: domain: Don't call namespace setup for storage already accessed by vm
When doing block commit we need to allow write for members of the
backing chain so that we can commit the data into them.

qemuDomainDiskChainElementPrepare was used for this which since commit
786d8d91b4 calls qemuDomainNamespaceSetupDisk which has very adverse
side-effects, namely it relabels the nodes to the same label it has in
the main namespace. This was messing up permissions for the commit
operation since its touching various parts of a single backing chain.

Since we are are actually not introducing new images at that point add a
flag for qemuDomainDiskChainElementPrepare which will refrain from
calling to the namespace setup function.

Calls from qemuDomainSnapshotCreateSingleDiskActive and
qemuDomainBlockCopyCommon do introduce new members all calls from
qemuDomainBlockCommit do not, so the calls are anotated accordingly.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1506072
2017-11-22 17:35:17 +01:00
Michal Privoznik
937f319536 qemuBuildDeviceAddressStr: Prefer default alias for PCI bus
https://bugzilla.redhat.com/show_bug.cgi?id=1434451

Just like in 9324f67a57 we need to put default pci-root
alias onto the command line instead of the one provided by user.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2017-11-20 10:35:03 +01:00
Michal Privoznik
f66e5896ad qemuBuildDriveDevStr: Prefer default alias for SATA bus
https://bugzilla.redhat.com/show_bug.cgi?id=1434451

Just like in 9324f67a57 we need to put default sata alias
(which is hardcoded to "ide", obvious, right?) onto the command
line instead of the one provided by user.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2017-11-20 10:35:03 +01:00
Michal Privoznik
481f8fdca1 virQEMUCapsHasPCIMultiBus: Fix @def type
This function only queries domain @def. It doesn't change it.
Therefore it should take const pointer.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2017-11-20 10:35:03 +01:00
Andrea Bolognani
18dfc00145 conf,qemu: Use type-aware switches where possible
The compiler can warn us if we add a value to the
virDomainChrSerialTargetType enumeration but forget to handle
it properly in the code. Let's take advantage of that.

This commit is best viewed with 'git diff -w'.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
2017-11-20 10:14:44 +01:00
Pino Toscano
593639ffff qemu: add QEMU_CAPS_DEVICE_SCLPLMCONSOLE
Add a separate capability for the sclplmconsole device, and check it
specifically instead of using QEMU_CAPS_DEVICE_SCLPCONSOLE for that too.

Signed-off-by: Pino Toscano <ptoscano@redhat.com>
Reviewed-by: Andrea Bolognani <abologna@redhat.com>
2017-11-20 10:13:53 +01:00
Pino Toscano
98b55862ef qemu: rename QEMU_CAPS_SCLP_S390 to QEMU_CAPS_DEVICE_SCLPCONSOLE
Give a better name to the capability for the sclpconsole device.

Signed-off-by: Pino Toscano <ptoscano@redhat.com>
Reviewed-by: Andrea Bolognani <abologna@redhat.com>
2017-11-20 10:13:45 +01:00
Andrea Bolognani
87eabeb17d qemu: Add QEMU_CAPS_DEVICE_SPAPR_VTY
Up until now we assumed the spapr-vty device would always be
present, which is not very nice. Check for its availability before
using it instead.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
2017-11-20 10:13:32 +01:00
Marc-André Lureau
7e4177a35b qemu: add vmcoreinfo support
Starting from qemu 2.11, the `-device vmcoreinfo` will create a fw_cfg
entry for a guest to store dump details, necessary to process kernel
dump with KASLR enabled and providing additional kernel details.

In essence, it is similar to -fw_cfg name=etc/vmcoreinfo,file=X but in
this case it is not backed by a file, but collected by QEMU itself.

Since the device is a singleton and shouldn't use additional hardware
resources, it is presented as a <feature> element in the libvirt
domain XML.

The device is arm/x86 only for now (targets that support fw_cfg+dma).

Related to:
https://bugzilla.redhat.com/show_bug.cgi?id=1395248

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2017-11-18 10:45:10 +01:00
Martin Kletzander
63d95a19cc conf: Format cache banks in capabilities with virFormatIntPretty
Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2017-11-18 10:45:10 +01:00
Martin Kletzander
b4698edcb0 conf: Sort cache banks in capabilities XML
Because the cache banks are initialized based on the order in which their
respective directories exist on the filesystem, they can appear in different
order.  This is here mainly for tests because the cache directory might have
different order of children nodes and tests would fail otherwise.  It should not
be the case with sysfs, but one can never be sure.  And this does not take
almost any extra time, mainly because it gets initialized once per driver.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2017-11-18 10:45:10 +01:00
Martin Kletzander
baca005367 util: Introduce virBitmapShrink
Sometimes the size of the bitmap matters and it might not be guessed correctly
when parsing from some type of input.  For example virBitmapNewData() has Byte
granularity, virBitmapNewString() has nibble granularity and so on.
virBitmapParseUnlimited() can be tricked into creating huge bitmap that's not
needed (e.g.: "0-2,^99999999").  This function provides a way to shrink the
bitmap.  It is not supposed to free any memory.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2017-11-18 10:45:10 +01:00
Martin Kletzander
449442c34d util: Reintroduce virBitmapSubtract
Already introduced in the past with 9479642fd3, but then renamed to
virBitmapIntersect by a908e9e45e.  This time we'll really use it.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2017-11-18 10:45:10 +01:00
Martin Kletzander
2e5579a43b util: Introduce virBitmapNewString
Our bitmaps can be represented as data (raw bytes for which we have
virBitmapNewData() and virBitmapToData()), human representation (list
of numbers in a string for which we have virBitmapParse() and
virBitmapFormat()) and hexadecimal string (for which we have only
virBitmapToString()).  So let's add the missing complement for the
last one so that we can parse hexadecimal strings.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2017-11-18 10:45:10 +01:00
Martin Kletzander
fb10602875 util: Don't output too many zeros from virBitmapToString
Truncate the output so that it is only as big as is needed to fit all
the bits, not all the units from the map.  This will be needed in the
future in order to properly format bitmaps for kernel's sysfs files.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2017-11-18 10:45:10 +01:00
Martin Kletzander
5d893ed6ad util: Rename virBitmapDataToString to virBitmapDataFormat
It is literally only a wrapper around virBitmapNewData() and
virBitmapFormat(), only the naming was wrong since it was introduced.
And because we have virBitmap*String functions where the meaning of
the 'String' is constant, this might confuse someone.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2017-11-18 10:45:10 +01:00
Martin Kletzander
68d7cc649c util: Rename virBitmapString to virBitmapToString
This follows the virBitmapToData() function and, similarly to
virBitmapNewData(), we'll be able to have virBitmapNewString() later
on without name confusion.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2017-11-18 10:45:10 +01:00
Martin Kletzander
d127aced0a util: Make prefix optional in virBitampString
Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2017-11-18 10:45:10 +01:00
Martin Kletzander
87a8a30d61 util: Introduce virFormatIntPretty
We can't output better memory sizes if we want to be compatible with libvirt
older than the one which introduced /memory/unit, but for new things we can just
output nicer capacity to the user if available.  And this function enables that.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2017-11-18 10:45:10 +01:00
Jim Fehlig
ce3b585bc4 xenconfig: fix compilation error
Commit 03d0959a introduced a compilation error in
src/xenconfig/xen_xl.c on ARM. Found by Xen's osstest

http://logs.test-lab.xenproject.org/osstest/logs/116216/build-armhf-libvirt/6.ts-libvirt-build.log
2017-11-17 10:35:12 -07:00
John Ferlan
2dd70901db storage: Resolve storage driver crash
Resolve a storage driver crash as a result of a long running
storageVolCreateXML when the virStorageVolPoolRefreshThread is
run as a result of when a storageVolUpload completed and ran the
virStoragePoolObjClearVols without checking if the creation
code was currently processing a buildVol after incrementing
the driver->asyncjob count.

The refreshThread will now check the pool asyncjob count before
attempting to pursue the pool refresh. Adjust the documentation
to describe the condition.

Crash from valgrind is as follows (with a bit of editing):

==21309== Invalid read of size 8
==21309==    at 0x153E47AF: storageBackendUpdateVolTargetInfo
==21309==    by 0x153E4C30: virStorageBackendUpdateVolInfo
==21309==    by 0x153E52DE: virStorageBackendVolRefreshLocal
==21309==    by 0x153DE29E: storageVolCreateXML
==21309==    by 0x562035B: virStorageVolCreateXML
==21309==    by 0x147366: remoteDispatchStorageVolCreateXML
...
==21309==  Address 0x2590a720 is 64 bytes inside a block of size 336 free'd
==21309==    at 0x4C2F2BB: free
==21309==    by 0x54CB9FA: virFree
==21309==    by 0x55BC800: virStorageVolDefFree
==21309==    by 0x55BF1D8: virStoragePoolObjClearVols
==21309==    by 0x153D967E: virStorageVolPoolRefreshThread
...
==21309==  Block was alloc'd at
==21309==    at 0x4C300A5: calloc
==21309==    by 0x54CB483: virAlloc
==21309==    by 0x55BDC1F: virStorageVolDefParseXML
==21309==    by 0x55BDC1F: virStorageVolDefParseNode
==21309==    by 0x55BE5A4: virStorageVolDefParse
==21309==    by 0x153DDFF1: storageVolCreateXML
==21309==    by 0x562035B: virStorageVolCreateXML
==21309==    by 0x147366: remoteDispatchStorageVolCreateXML
...
2017-11-16 11:34:26 -05:00
Pavel Hrdina
b98add7571 qemu: taint domain if virDomainQemuAgentCommand API is used
This is similar to the virDomainQemuMonitorCommand API, it can change
the domain state in a way that libvirt may not understand.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2017-11-16 14:58:01 +01:00
Erik Skultety
996500d6fa daemon: virtlockd: Call virNetDaemonGetServer regardless of post exec
We need to call it anyway, so the else branch is redundant here.

Signed-off-by: Erik Skultety <eskultet@redhat.com>
2017-11-15 15:11:55 +01:00
Erik Skultety
700b0d2a2d daemon: virtlogd: Drop the server shortcut ref pointer
We put the server into a hash table as we do with the other daemons,
there is no compelling reason why it should have another pointer
dedicated just to the server. Besides, the locking daemon doesn't have
it and virtlogd is essentially a copy paste of virtlockd.

Signed-off-by: Erik Skultety <eskultet@redhat.com>
2017-11-15 15:11:54 +01:00
Andrea Bolognani
85b2ae96df qemu: Enable configuration of HPT resizing for pSeries guests
Most of the time it's okay to leave this up to negotiation between
the guest and the host, but in some situations it can be useful to
manually decide the behavior, especially to enforce its availability.

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

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2017-11-14 16:29:55 +01:00
Jiri Denemark
6118fd9cb9 qemu: Properly report errors from qemuDomainFixupCPUs
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
2017-11-13 17:42:44 +01:00
Peter Krempa
50712e14f4 conf: Fix message when maximum vCPU count is less than current
Reword the message and drop the numbers (which were reversed) from it
so that it actually makes sense.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1509151
2017-11-13 13:41:45 +01:00
Peter Krempa
acc15025ed qemu: process: Setup disk secrets when preparing disks
Setup everything related to disks in one place rather than calling in
from various places.

The change to ordering of the setup steps is necessary since secrets
need the master key to be present.
2017-11-13 13:29:58 +01:00
Peter Krempa
2c82fddca9 qemu: domain: Don't allocate storage source private data if not needed 2017-11-13 13:28:49 +01:00
Peter Krempa
8056721cbb qemu: Tolerate storage source private data being NULL
In some cases it does not make sense to pursue that the private data
will be allocated (especially when we don't need to put anything in it).

Ensure that the code works without it.

This also fixes few crashes pointed out in
https://bugzilla.redhat.com/show_bug.cgi?id=1510323
2017-11-13 13:28:49 +01:00
Peter Krempa
994c49ac34 qemu: parse: Allocate disk definition with private data
Use virDomainDiskDefNew instead of VIR_ALLOC in
qemuParseCommandLineDisk.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1510781
2017-11-13 13:28:49 +01:00
Peter Krempa
9249187f5b qemu: block: Don't leak server JSON object from protocol generators
If creation of the main JSON object containing the storage portion of a
virStorageSource would fail but we'd allocate the server structure we'd
leak it. Found by coverity.
2017-11-13 13:18:34 +01:00
Peter Krempa
bb15ac4599 qemu: block: Break out early on invalid storage sources
Return NULL right away in qemuBlockStorageSourceGetBackendProps when an
invalid storage source is presented so that virJSONValueObjectAdd isn't
called with a NULL argument.

Found by coverity.
2017-11-13 13:18:34 +01:00
Peter Krempa
19448a2561 conf: Properly parse <backingStore/>
The terminator would not be parsed properly since the XPath selector was
looking for an populated element, and also the code did not bother
assigning the terminating virStorageSourcePtr to the backingStore
property of the parent.

Some tests would catch it if there wasn't bigger fallout from the change
to backing store termination in a693fdba01. Fix them properly now.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1509110
2017-11-13 13:13:29 +01:00
Michal Privoznik
676768edeb Revert "virNetDevSupportBandwidth: Enable QoS for vhostuser"
https://bugzilla.redhat.com/show_bug.cgi?id=1497410

This reverts commit bc8a99ef06.

The vhostuser is not a TAP. Therefore our QoS code is not able to
set any bandwidth. I don't really understand what I was thinking.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2017-11-13 06:25:16 +01:00
Wim ten Have
c9a5682ffa libxl: vnuma support
This patch generates a NUMA distance-aware libxl description from the
information extracted from a NUMA distance-aware libvirt XML file.

By default, if no NUMA node distance information is supplied in the
libvirt XML file, this patch uses the distances 10 for local and 20
for remote nodes/sockets.

Signed-off-by: Wim ten Have <wim.ten.have@oracle.com>
Reviewed-by: Jim Fehlig <jfehlig@suse.com>
Signed-off-by: Jim Fehlig <jfehlig@suse.com>
2017-11-12 19:39:18 -07:00
Wim ten Have
03d0959af3 xenconfig: add domxml conversions for xen-xl
This patch converts NUMA configurations between the Xen libxl
configuration file format and libvirt's XML format.

XML HVM domain on a 4 node (2 cores/socket) configuration:

  <cpu>
    <numa>
      <cell id='0' cpus='0-1' memory='2097152' unit='KiB'>
        <distances>
          <sibling id='0' value='10'/>
          <sibling id='1' value='21'/>
          <sibling id='2' value='31'/>
          <sibling id='3' value='21'/>
        </distances>
      </cell>
      <cell id='1' cpus='2-3' memory='2097152' unit='KiB'>
        <distances>
          <sibling id='0' value='21'/>
          <sibling id='1' value='10'/>
          <sibling id='2' value='21'/>
          <sibling id='3' value='31'/>
        </distances>
      </cell>
      <cell id='2' cpus='3-4' memory='2097152' unit='KiB'>
        <distances>
          <sibling id='0' value='31'/>
          <sibling id='1' value='21'/>
          <sibling id='2' value='10'/>
          <sibling id='3' value='21'/>
        </distances>
      </cell>
      <cell id='3' cpus='5-6' memory='2097152' unit='KiB'>
        <distances>
          <sibling id='0' value='21'/>
          <sibling id='1' value='31'/>
          <sibling id='2' value='21'/>
          <sibling id='3' value='10'/>
        </distances>
      </cell>
    </numa>
  </cpu>

Xen xl.cfg domain configuration:

  vnuma = [["pnode=0","size=2048","vcpus=0-1","vdistances=10,21,31,21"],
           ["pnode=1","size=2048","vcpus=2-3","vdistances=21,10,21,31"],
           ["pnode=2","size=2048","vcpus=4-5","vdistances=31,21,10,21"],
           ["pnode=3","size=2048","vcpus=6-7","vdistances=21,31,21,10"]]

If there is no XML <distances> description amongst the <cell> data the
conversion schema from xml to native will generate 10 for local and 20
for all remote instances.

Signed-off-by: Wim ten Have <wim.ten.have@oracle.com>
Reviewed-by: Jim Fehlig <jfehlig@suse.com>
Signed-off-by: Jim Fehlig <jfehlig@suse.com>
2017-11-12 19:39:09 -07:00
Wim ten Have
74119a03f1 numa: describe siblings distances within cells
Add support for describing NUMA distances in a domain's <numa> <cell>
XML description.

Below is an example of a 4 node setup:

  <cpu>
    <numa>
      <cell id='0' cpus='0-3' memory='2097152' unit='KiB'>
        <distances>
          <sibling id='0' value='10'/>
          <sibling id='1' value='21'/>
          <sibling id='2' value='31'/>
          <sibling id='3' value='21'/>
        </distances>
      </cell>
      <cell id='1' cpus='4-7' memory='2097152' unit='KiB'>
        <distances>
          <sibling id='0' value='21'/>
          <sibling id='1' value='10'/>
          <sibling id='2' value='21'/>
          <sibling id='3' value='31'/>
        </distances>
      </cell>
      <cell id='2' cpus='8-11' memory='2097152' unit='KiB'>
        <distances>
          <sibling id='0' value='31'/>
          <sibling id='1' value='21'/>
          <sibling id='2' value='10'/>
          <sibling id='3' value='21'/>
        </distances>
      <cell id='3' cpus='12-15' memory='2097152' unit='KiB'>
        <distances>
          <sibling id='0' value='21'/>
          <sibling id='1' value='31'/>
          <sibling id='2' value='21'/>
          <sibling id='3' value='10'/>
        </distances>
      </cell>
    </numa>
  </cpu>

A <cell> defines a NUMA node. <distances> describes the NUMA distance
from the <cell> to the other NUMA nodes (the <sibling>s).  For example,
in above XML description, the distance between NUMA node0 <cell id='0'
...> and NUMA node2 <sibling id='2' ...> is 31.

Valid distance values are '10 <= value <= 255'.  A distance value of 10
represents the distance to the node itself.  A distance value of 20
represents the default value for remote nodes but other values are
possible depending on the physical topology of the system.

When distances are not fully described, any missing sibling distance
values will default to 10 for local nodes and 20 for remote nodes.

If distance is given for A -> B, then we default B -> A to the same
value instead of 20.

Signed-off-by: Wim ten Have <wim.ten.have@oracle.com>
Reviewed-by: Daniel P. Berrange <berrange@redhat.com>
Signed-off-by: Jim Fehlig <jfehlig@suse.com>
2017-11-12 19:39:00 -07:00
Michal Privoznik
9324f67a57 qemuBuildDriveDevStr: Prefer default aliases for IDE bus
https://bugzilla.redhat.com/show_bug.cgi?id=1434451

When testing user aliases it was discovered that for 440fx
machine type which has default IDE bus builtin, domain cannot
start if IDE controller has the user provided alias. This is
because for 440fx we don't put the IDE controller onto the
command line (since it is builtin) and therefore any device that
is plugged onto the bus must use the default alias.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2017-11-10 15:23:55 +01:00
Viktor Mihajlovski
010f88d5cb numa: avoid failure in nodememstats on non-NUMA systems
libvirt reports a fake NUMA topology in virConnectGetCapabilities
even if built without numactl support. The fake NUMA topology consists
of a single cell representing the host's cpu and memory resources.
Currently this is the case for ARM and s390[x] RPM builds.

A client iterating over NUMA cells obtained via virConnectGetCapabilities
and invoking virNodeGetMemoryStats on them will see an internal failure
"NUMA isn't available on this host" from virNumaGetMaxNode. An example
for such a client is VDSM.

Since the intention seems to be that libvirt always reports at least
a single cell it is necessary to return "fake" node memory statistics
matching the previously reported fake cell in case NUMA isn't supported
on the system.

Signed-off-by: Viktor Mihajlovski <mihajlov@linux.vnet.ibm.com>
2017-11-09 17:11:51 -05:00
Dawid Zamirski
0eda09f490 vbox: Add support for 5.2.x
Simply add the 5.2 SDK header to the existing unified framework. No
other special handling is needed as there's no API break between
existing 5.1 and the just added 5.2.
2017-11-09 17:09:41 -05:00
Dawid Zamirski
8f1c88d9d0 vbox: Add vbox 5.2 CAPI header file.
Extracted from 5.2 SDK and reindented with cppi
2017-11-09 17:09:41 -05:00
Jim Fehlig
299e97c4e8 virconf: properly set the end of content
There was a recent report of the xen-xl converter not handling
config files missing an ending newline

https://www.redhat.com/archives/libvir-list/2017-October/msg01353.html

Commit 3cc2a9e0 fixed a similar problem when parsing content of a
file but missed parsing in-memory content. But AFAICT, the better
fix is to properly set the end of the content when initializing the
virConfParserCtxt in virConfParse().

This commit reverts the part of 3cc2a9e0 that appends a newline to
files missing it, and fixes setting the end of content when
initializing virConfParserCtxt. A test is also added to check
parsing in-memory content missing an ending newline.

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
Reviewed-by: Daniel P. Berrange <berrange@redhat.com>
2017-11-09 08:04:26 -07:00
Peter Krempa
5af63c9aa3 conf: Fix type for @liveStatus in virDomainObjListLoadAllConfigs
Use bool instead of an int.
2017-11-09 10:37:58 +01:00
Michal Privoznik
3d899b9965 qemu-ns: Detect /dev/* mount point duplicates even better
In 4f15707202 I've tried to make duplicates detection for
nested /dev mount better. However, I've missed the obvious case
when there are two same mount points. For instance if:

  # mount --bind /dev/blah /dev/blah
  # mount --bind /dev/blah /dev/blah

Yeah, very unlikely (in qemu driver world) but possible.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2017-11-08 16:38:26 +01:00
Peter Krempa
0a3bae7d22 util: storage: Fix parsing of IPv6 portal address for iSCSI
Split on the last colon and avoid parsing port if the split remainder
contains the closing square bracket, so that IPv6 addresses are
interpreted correctly.
2017-11-08 13:10:40 +01:00
Michal Privoznik
fec8f9c49a qemu: Use predictable file names for memory-backend-file
In some cases management application needs to allocate memory for
qemu upfront and then just let qemu use that. Since we don't want
to expose path for memory-backend-file anywhere in the domain
XML, we can generate predictable paths. In this case:

  $memoryBackingDir/libvirt/qemu/$shortName/$alias

where $shortName is result of virDomainDefGetShortName().

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2017-11-08 10:17:17 +01:00
Michal Privoznik
bb3de478a6 qemu: Destroy whole memory tree
When removing path where huge pages are call virFileDeleteTree
instead of plain rmdir(). The reason is that in the near future
there's going to be more in the path than just files - some
subdirs. Therefore plain rmdir() is not going to be enough.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2017-11-08 10:17:11 +01:00
Michal Privoznik
eff2b2edb1 qemu: Rename qemuProcessBuildDestroyHugepagesPath
At the same time, move its internals into a separate function so
that they can be reused.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2017-11-08 10:17:10 +01:00
Michal Privoznik
d52e6043bc qemu: Set alias for memory cell in qemuBuildMemoryCellBackendStr
Very soon qemuBuildMemoryBackendStr() is going to use memory cell
aliases. Therefore set one. At the same time, move it a bit
further - if virAsprintf() fails, there's no point in setting
rest of the members.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2017-11-08 10:17:08 +01:00
Dawid Zamirski
8b5eefb6bc vbox: Add SAS controller support
In VirtualBox SAS and SCSI are separate controller types whereas libvirt
does not make such distinction. This patch adds support for attaching
the VBOX SAS controllers by mapping the 'lsisas1068' controller model in
libvirt XML to VBOX SAS controller type. If VBOX VM has disks attached
to both SCSI and SAS controller libvirt domain XML will have two
<controller type='scsci'> elements with index and model attributes set
accordingly. In this case, each respective <disk> element must have
<address> element specified to assign it to respective SCSI controller.
2017-11-07 15:38:43 -05:00
Dawid Zamirski
e0054c0e5d vbox: Generate disk address element in dumpxml
This patch adds <address> element to each <disk> device since device
names alone won't adequately reflect the storage device layout in the
VM. With this patch, the ouput produced by dumpxml will faithfully
reproduce the storage layout of the VM if used with define.
2017-11-07 15:38:43 -05:00
Dawid Zamirski
7c0a85e5be vbox: Process empty removable disks in dumpxml
Previously any removable storage device without media attached was
omitted from domain XML dump. They're still (rightfully) omitted in
snapshot XML dump but need to be accounted properly to for the device
names to stay in 'sync' between domain and snapshot XML dumps.
2017-11-07 15:38:35 -05:00
Dawid Zamirski
08b995c8d0 vbox: Cleanup vboxDumpDisks implementation
Primer the code for further changes:

* move variable declarations to the top of the function
* group together free/release statements
* error check and report VBOX API calls used
2017-11-07 14:45:51 -05:00
Dawid Zamirski
a4919338ba vbox: Correctly generate drive name in dumpxml
If a VBOX VM has e.g. a SATA and SCSI disk attached, the XML generated
by dumpxml used to produce "sda" for both of those disks. This is an
invalid domain XML as libvirt does not allow duplicate device names. To
address this, keep the running total of disks that will use "sd" prefix
for device name and pass it to the vboxGenerateMediumName which no
longer tries to "compute" the value based only on current and max
port and slot values. After this the vboxGetMaxPortSlotValues is not
needed and was deleted.
2017-11-07 14:45:51 -05:00
Dawid Zamirski
32a944115b vbox: Swap vboxSnapshotGetReadOnlyDisks arguments
So that the function signature matches vboxSnapshotGetReadWriteDisks
2017-11-07 14:45:51 -05:00
Dawid Zamirski
03a24da4c4 vbox: Do not free disk definitions on cleanup
Both vboxSnapshotGetReadWriteDisks and vboxSnapshotGetReadWriteDisks do
not need to free the def->disks on cleanup because it's being done by
the caller via virDomainSnaphotDefFree
2017-11-07 14:45:51 -05:00
Dawid Zamirski
60c519ee24 vbox: Cleanup/prepare snasphot dumpxml functions
This patch prepares the vboxSnapshotGetReadOnlyDisks and
vboxSnapshotGetReadWriteDisks functions for further changes so that
the code movement does not obstruct the gist of those future changes.
This is done primarily because we'll need to know the type of vbox
storage controller as early as possible and make decisions based on
that info.
2017-11-07 14:45:51 -05:00
Dawid Zamirski
c27f79a895 vbox: Rename vboxDumpIDEHDDs to vboxDumpDisks
Because it deals with other disk types as well not just IDE. Also this
function now returns -1 on error
2017-11-07 14:45:51 -05:00
Dawid Zamirski
8339d273bb vbox: Add vboxDumpStorageControllers 2017-11-07 14:45:51 -05:00
Dawid Zamirski
1cad92c421 vbox: Process <controller> element in domain XML
With this patch, the vbox driver will no longer attach all supported
storage controllers by default even if no disk devices are associated
with them. Instead, it will attach only those that are implicitly added
by virDomainDefAddImplicitController based on <disk> element or if
explicitly specified via the <controller> element.
2017-11-07 14:45:51 -05:00
Dawid Zamirski
8442d01a71 vbox: Cleanup partially-defined VM on failure
Since the VBOX API requires to register an initial VM before proceeding
to attach any remaining devices to it, any failure to attach such
devices should result in automatic cleanup of the initially registered
VM so that the state of VBOX registry remains clean without any leftover
"aborted" VMs in it. Failure to cleanup of such partial VMs results in a
warning log so that actual define error stays on the top of the error
stack.
2017-11-07 14:45:51 -05:00
John Ferlan
8fe48f20f8 storage: Privatize virStoragePoolObj and virStorageVolDefList
Move the structures into virstorageobj so that both are known
within virstorageobj.c.
2017-11-07 14:12:52 -05:00
John Ferlan
ba6575e2f6 storage: Use virStoragePoolObjGetDef accessor for new driver events
Missed from merge from commit id 'b0652192' into commit id 'bfcd8fc92'
were a couple of obj->def-> references.
2017-11-07 14:12:52 -05:00
John Ferlan
121cf746b2 storage: Use virStoragePoolObjGetDef accessor for ZFS backend
In preparation for privatizing the object, use the accessor.
2017-11-07 14:12:52 -05:00
John Ferlan
159f691fae storage: Use virStoragePoolObjGetDef accessor for VSTORAGE backend
In preparation for privatizing the object, use the accessor.
2017-11-07 14:12:52 -05:00
John Ferlan
d823466bc2 storage: Use virStoragePoolObjGetDef accessor for SCSI backend
In preparation for privatizing the object, use the accessor.
2017-11-07 14:12:52 -05:00
John Ferlan
4d95a14faf storage: Use virStoragePoolObjGetDef accessor for RBD backend
In preparation for privatizing the object, use the accessor.
2017-11-07 14:12:52 -05:00
John Ferlan
1d995fbebc storage: Use virStoragePoolObjGetDef accessor for MPATH backend
In preparation for privatizing the object, use the accessor.
2017-11-07 14:12:52 -05:00
John Ferlan
dc48de256e storage: Use virStoragePoolObjGetDef accessor for iSCSI backend
In preparation for privatizing the object, use the accessor.
2017-11-07 14:12:52 -05:00
Peter Krempa
31bbb15884 qemu: block: Add node-names to JSON backing storage strings
Format out the node-name if it was assigned for JSON-based storage
specification.
2017-11-07 16:12:52 +01:00
Peter Krempa
caf71b64fe qemu: block: Add JSON props generator for ssh storage backing 2017-11-07 16:12:52 +01:00
Peter Krempa
8da68d87ff qemu: block: Add JSON props generator for sheepdog storage backing 2017-11-07 16:12:52 +01:00
Peter Krempa
5e9e693262 qemu: block: Add JSON props generator for RBD storage backing 2017-11-07 16:12:29 +01:00
Peter Krempa
84955c6257 qemu: block: Add JSON props generator for NBD storage backing 2017-11-07 16:11:38 +01:00
John Ferlan
ea0cc4f4b0 qemu: block: Add JSON props generator for iSCSI protocol 2017-11-07 16:04:53 +01:00
Peter Krempa
97ee821a17 qemu: block: Add JSON props generator for 'curl' based storage backends
QEMU uses curl for accessing files using http(s) and ftp(s). They share
common options so let's generate them in one helper.
2017-11-07 14:58:48 +01:00
Peter Krempa
90521d0754 storage: Store RBD image name as pool and image name
Similarly to how we store gluster names, split the name into a pool and
image portions when paring the XML and store them separately.
2017-11-07 14:58:04 +01:00
Peter Krempa
bb14d9897b storage: Don't store leading '/' in image name when splitting out volume
Libvirt historically stores storage source path including the volume as
one string in the XML, but that is not really flexible enough when
dealing with the fields in the code. Previously we'd store the slash
separating the two as part of the image name. This was fine for gluster
but it's not necessary and does not scale well when converting other
protocols.

Don't store the slash as part of the path. The resulting change from
absolute to relative path within the gluster driver should be okay,
as the root directory is the default when accessing gluster.
2017-11-07 14:58:04 +01:00
Peter Krempa
1ee7d4d972 qemu: process: Split out useful parts from qemuBuildNetworkDriveURI
Extract the part formatting the basic URI part so that it can be reused
to format JSON backing definitions. Parts specific to the command line
format will remain in qemuBuildNetworkDriveURI. The new function is
called qemuBlockStorageSourceGetURI.
2017-11-07 14:57:58 +01:00
Peter Krempa
bd37213786 qemu: block: Use proper type for servers for VxHS disks
Original implementation used 'SocketAddress' equivalent from qemu for
the disk server field, while qemu documentation specifies
'InetSocketAddress'. The backing store parser uses the correct parsing
function but the formatter used the incorrect one (and also with the
legacy mode enabled which was wrong).
2017-11-07 14:43:12 +01:00
Peter Krempa
1f467d1ab1 qemu: command: Move disk serial validation to qemuCheckDiskConfig 2017-11-07 14:38:11 +01:00
Peter Krempa
cf1fcd7b51 qemu: command: Move blkiotune checks to qemuCheckDiskConfig 2017-11-07 14:33:38 +01:00
Peter Krempa
5121457cad qemu: command: Refactor blkiotune checks to tolerate NULL qemuCaps
To allow aggregating the checks, refactor the code to check capabilities
only if they were provided.
2017-11-07 14:33:23 +01:00
Peter Krempa
1055c1bf24 qemu: command: Merge checks from qemuBuildDriveStrValidate to qemuCheckDiskConfig
Stash all the disk definition and capability checks into one function.
2017-11-07 14:33:18 +01:00
Peter Krempa
5fb7ab2c9e qemu: command: Refactor qemuBuildDriveStrValidate to make qemuCaps optional
To allow merging this with other disk type checks we need to check
qemuCaps only when available, since some of the checks are executed on
disk cold-plug and thus capabilities should not be checked.

Make the checks optional by making them conditional on qemuCaps not
being NULL.
2017-11-07 14:31:21 +01:00
Peter Krempa
f15ed22757 qemu: command: Directly report bus type in qemuBuildDriveStrValidate
All of the error message are already in a conditional block with known
bus type. Inline the bus type rather than formatting it from a separate
variable.
2017-11-07 14:31:15 +01:00
Peter Krempa
dfd300a71d qemu: command: Move disk index validation closer to usage
The disk index validation is used only in very specific cases and does
not need to be performed otherwise. Move it out of the global check into
the usage place.
2017-11-07 14:29:37 +01:00
Peter Krempa
b60ce7b122 qemu: command: Remove dead code when formatting -drive
busid and unitid are ever used only if the device is an SD card due to
the check in qemuDiskBusNeedsDeviceArg. Since the SD card does not have
an bus or unit number, most of the code and command line formatter can
be removed since it will never be used.
2017-11-07 14:29:37 +01:00
Peter Krempa
e5580888f5 util: Fix condition check in virDiskNameToIndex
Use the more common '< 0' rather than the non-zero check.
2017-11-07 14:29:37 +01:00
Michal Privoznik
ae1b5d47e5 qemu: Move memPath generation from memoryBackingDir to a separate function
In near future we will need more than just a plain VIR_STRDUP().
Better implement that in a separate function and in
qemuBuildMemoryBackendStr() which is complicated enough already.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2017-11-07 13:43:06 +01:00
Michal Privoznik
fe70fd0c10 conf: s/virDomainObjGetShortName/virDomainDefGetShortName/
This function works over domain definition and not domain object.
Its name is thus misleading.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2017-11-07 13:43:00 +01:00
Nikolay Shirokovskiy
47eb77fb33 rpc,lockd: Add missing netserver refcount increment on reload
After the virNetDaemonAddServerPostExec call in virtlogd we should have
netserver refcount set to 2. One goes to netdaemon servers hashtable
and one goes to virt{logd,lock} own reference to netserver. Let's add
the missing increment in virNetDaemonAddServerPostExec itself while
holding the daemon lock.

Since lockd defers management of the @srv object by the presence
in the hash table, virLockDaemonNewPostExecRestart must Unref the
alloc'd Ref on the @srv object done as part of virNetDaemonAddServerPostExec
and virNetServerNewPostExecRestart processing. The virNetDaemonGetServer
in lock_daemon main will also take a reference which is Unref'd during
main cleanup.
2017-11-06 16:19:11 -05:00
John Ferlan
82fa7fc3ab lockd: Need to Unref @srv when done with it.
Commit id '252610f7d' used a hash table to store the @srv, but
didn't handle the virObjectUnref if virNetDaemonNew failed nor
did it use virObjectUnref once successfully placed into the table
which will now be managing it's lifetime (and would cause the
virObjectRef if successfully inserted into the table).
2017-11-06 15:53:41 -05:00
Jiri Denemark
bce925dada conf: Don't inline virDomainNetTypeSharesHostView
When coverage build is enabled, gcc complains about it:

In file included from qemu/qemu_agent.h:29:0,
                 from qemu/qemu_driver.c:47:
qemu/qemu_driver.c: In function 'qemuDomainSetInterfaceParameters':
./conf/domain_conf.h:3397:1: error: inlining failed in call to
'virDomainNetTypeSharesHostView': call is unlikely and code size would
grow [-Werror=inline]
 virDomainNetTypeSharesHostView(const virDomainNetDef *net)
 ^

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2017-11-06 10:58:46 +01:00
Dawid Zamirski
1ed22398c3 domain: Allow 'model' attribute for ide controller
The optional values are 'piix3', 'piix4' or 'ich6'. Those will be
needed to allow setting IDE controller model in VirtualBox driver.
2017-11-03 13:15:54 -04:00
Dawid Zamirski
06c4fd10fd vbox: Add more IStorageController API mappings
This patch exposes additional methods of the native VBOX API to the
libvirt 'unified' vbox API to deal with IStorageController. The exposed
methods are:

* IStorageController->GetStorageControllerType()
* IStorageController->SetStorageControllerType()
* IMachine->GetStorageControllers()
2017-11-03 13:15:54 -04:00
Dawid Zamirski
1bf7e97733 vbox: Support empty removable drives.
Original code was checking for non empty disk source before proceeding
to actually attach disk device to VM. This prevented from creating
empty removable devices like DVD or floppy. Therefore, this patch
re-organizes the loop work-flow to allow such configurations as well as
makes the code follow better libvirt practices. Additionally, adjusted
debug logs to be more helpful - removed old ones and added new which
give more valuable info for troubleshooting.
2017-11-03 13:15:54 -04:00
Dawid Zamirski
e3ecf4b8ce vbox: Errors in vboxAttachDrives are now critical
Previously, if one tried to define a VBOX VM and the API failed to
perform the requested actions for some reason, it would just log the
error and move on to process remaining disk definitions. This is not
desired as it could result in incorrectly defined VM without the caller
even knowing about it. So now all the code paths that call
virReportError are now treated as hard failures as they should have
been.
2017-11-03 13:15:54 -04:00
Dawid Zamirski
60227fd5ee vbox: Remove unused mediumEmpty
Remove the setting since it's unused as of commit 34364df3 which should
have never copied it in from the old code which ended up getting removed
as part of commit c7c286c6.
2017-11-03 13:15:54 -04:00
Dawid Zamirski
ff67685b17 vbox: Cleanup vboxAttachDrives implementation
This commit primes vboxAttachDrives for further changes so when they
are made, the diff is less noisy:

* move variable declarations to the top of the function
* add disk variable to replace all the def->disks[i] instances
* add cleanup at the end of the loop body, so it's all in one place
  rather than scattered through the loop body. It's purposefully
  called 'cleanup' rather than 'skip' or 'continue' because future
  commit will treat errors as hard-failures.
2017-11-03 13:15:50 -04:00
Dawid Zamirski
c739a6bdfe vbox: vboxAttachDrives now relies on address info
Previously, the driver was computing VBOX's devicePort/deviceSlot values
based on device name and max port/slot values. While this worked, it
completely ignored <address> values. Additionally, libvirt's built-in
virDomainDiskDefAssignAddress already does a good job  setting default
values on virDomainDeviceDriveAddress struct which we can use to set
devicePort and deviceSlot and accomplish the same result while allowing
the customizing those via XML. Also, this allows to remove some code
which will make further patches smaller.
2017-11-03 13:13:09 -04:00
Dawid Zamirski
7651debbc1 vbox: Close media when undefining domains
When registering a VM we call OpenMedium on each disk image which adds it
to vbox's global media registry. Therefore, we should make sure to call
Close when unregistering VM so we cleanup the media registry entries
after ourselves - this does not remove disk image files. This follows
the behaviour of the VBoxManage unregistervm command.
2017-11-03 13:13:09 -04:00
Dawid Zamirski
6f8ddbb83b vbox: Update ATTRIBUTE_UNUSED usage
Since the removal of VBOX <= 3x, the function arguments are actually
used so they should not be marked with ATTRIBUTE_UNUSED anymore.
2017-11-03 13:13:09 -04:00
Andrea Bolognani
3e7db8d3e8 Remove backslash alignment attempts
Right-aligning backslashes when defining macros or using complex
commands in Makefiles looks cute, but as soon as any changes is
required to the code you end up with either distractingly broken
alignment or unnecessarily big diffs where most of the changes
are just pushing all backslashes a few characters to one side.

Generated using

  $ git grep -El '[[:blank:]][[:blank:]]\\$' | \
    grep -E '*\.([chx]|am|mk)$$' | \
    while read f; do \
      sed -Ei 's/[[:blank:]]*[[:blank:]]\\$/ \\/g' "$f"; \
    done

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
2017-11-03 13:24:12 +01:00
Peter Krempa
a92c4f7537 qemu: domain: skip chain detection to end of backing chain
When a user provides the backing chain, we will not need to re-detect
all the backing stores again, but should move to the end of the user
specified chain. Additionally if a user provides a full terminated chain
we should not attempt any further detection.
2017-11-03 10:27:32 +01:00
Peter Krempa
b0a46b609e qemu: domain: Prepare TLS data for the whole backing chain
Iterate through the backing chain when setting up TLS for disks.
2017-11-03 10:23:21 +01:00
Peter Krempa
beb1661f3d qemu: domain: Remove pointless alias check
When attaching the disks, aliases are always generated.
2017-11-03 10:23:21 +01:00
Peter Krempa
d565877312 qemu: domain: Destroy secrets for complete backing chain 2017-11-03 10:23:21 +01:00
Peter Krempa
e53a42f0f6 qemu: domain: Extract setup for disk source secrets
Separate it so that it deals only with single virStorageSource, so that
it can later be reused for full backing chain support.

Two aliases are passed since authentication is more relevant to the
'storage backend' whereas encryption is more relevant to the protocol
layer. When using node names, the aliases will be different.
2017-11-03 10:23:16 +01:00
Peter Krempa
2b757b964b qemu: domain: Simplify using DAC permissions of top of backing chain
qemuDomainGetImageIds and qemuDomainStorageFileInit are helpful when
trying to access a virStorageSource from the qemu driver since they
figure out the correct uid and gid for the image.

When accessing members of a backing chain the permissions for the top
level would be used. To allow using specific permissions per backing
chain level but still allow inheritance from the parent of the chain we
need to add a new parameter to the image ID APIs.
2017-11-03 09:15:41 +01:00
Peter Krempa
cc16fa2a85 security: selinux: Take parent security label into account
Until now we ignored user-provided backing chains and while detecting
the code inherited labels of the parent device. With user provided
chains we should keep this functionality, so label of the parent image
in the backing chain will be applied if an image-specific label is not
present.
2017-11-03 09:15:41 +01:00
Peter Krempa
2742dfee28 security: dac: Take parent security label into account
Until now we ignored user-provided backing chains and while detecting
the code inherited labels of the parent device. With user provided
chains we should keep this functionality, so label of the parent image
in the backing chain will be applied if an image-specific label is not
present.
2017-11-03 09:15:41 +01:00
Peter Krempa
023da7ddbd security: selinux: Pass parent storage source into image labeling helper
virSecuritySELinuxSetImageLabelInternal assigns different labels to
backing chain members than to the parent image. This was done via the
'first' flag. Convert it to passing in pointer to the parent
virStorageSource. This will allow us to use the parent virStorageSource
in further changes.
2017-11-03 09:15:41 +01:00
Peter Krempa
b4daf6af9a storage: Extract error reporting for broken chains
Simplify reporting the error if backing chain is broken for further
callers by extracting it into a separate function.
2017-11-03 09:15:41 +01:00
Peter Krempa
a93d750a7e storage: Add feature check for storage file backend supporting access check
When the user provides backing chain, we don't need the full support for
traversing the backing chain. This patch adds a feature check for the
virStorageSourceAccess API.
2017-11-03 09:15:41 +01:00
Peter Krempa
8c6b6684a8 storage: Extract common code to retrieve driver backend for support check
The 'file access' module of the storage driver has few feature checks to
determine whether libvirt supports given storage driver method. The code
to retrieve the driver struct needed for the check is the same so it can
be extracted.
2017-11-03 09:15:41 +01:00
Jiri Denemark
a1e3e8ddbd qemu: Add support for block-incremental migration parameter
We handle incremental storage migration in a different way. The support
for this new (as of QEMU 2.10) parameter is only needed for full
coverage of migration parameters used by QEMU.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2017-11-02 22:14:20 +01:00
Jiri Denemark
f6e2a70ae2 qemu: Add support for max-bandwidth migration parameter
We already support several ways of setting migration bandwidth and this
is not adding another one. With this patch we are able to read and write
this parameter using query-migrate-parameters and migrate-set-parameters
in one call with all other parameters.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2017-11-02 22:14:20 +01:00
Jiri Denemark
af1d2fe270 qemu: Rename TLS related migration parameters
The parameters used "migrate" prefix which is pretty redundant and
qemuMonitorMigrationParams structure is our internal representation of
QEMU migration parameters and it is supposed to use names which match
QEMU names.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2017-11-02 22:14:20 +01:00
Jiri Denemark
2384b6f019 qemu: Add support for setting downtime-limit migration parameter
We already support setting the maximum downtime with a dedicated
virDomainMigrateSetMaxDowntime API. This patch does not implement
another way of setting the downtime by adding a new public migration
parameter. It just makes sure any parameter we are able to get from a
QEMU monitor by query-migrate-parameters can be passed back to QEMU via
migrate-set-parameters.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2017-11-02 22:14:19 +01:00
Jiri Denemark
487759126b qemu: Drop giant if statement from qemuMonitorSetMigrationParams
The check can be easily replaced with a simple test in the JSON
implementation and we don't need to update it every time a new parameter
is added.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2017-11-02 22:14:19 +01:00
Jiri Denemark
6bc3d06700 qemu: Use macro for setting string migration parameters
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2017-11-02 22:14:19 +01:00
Jiri Denemark
27e5633724 qemu: Generalize APPEND macro in qemuMonitorJSONSetMigrationParams
The APPEND macro is now be usable for any type.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2017-11-02 22:14:18 +01:00
Jiri Denemark
7ddcab891e qemu: Use macro for parsing ull migration parameters
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2017-11-02 22:14:18 +01:00
Jiri Denemark
4fabc0caa0 qemu: Use macro for parsing string migration parameters
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2017-11-02 22:14:18 +01:00
Jiri Denemark
c04fbbd9c9 qemu: Generalize PARSE macro in qemuMonitorJSONGetMigrationParams
The macro (now called PARSE_SET) is now usable for any type which needs
a *_set bool for indicating a valid value.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2017-11-02 22:14:18 +01:00
Jiri Denemark
3b2674ff63 cpu_map: Add cqm alternative name for cmt
Linux kernel shows our "cmt" feature as "cqm". Let's mention the name in
the cpu_map.xml to make it easier to find.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2017-11-02 21:44:29 +01:00
Michal Privoznik
bc8a99ef06 virNetDevSupportBandwidth: Enable QoS for vhostuser
Since vhostuser type is really a tap that is just plugged into
different type of bridge, supporting QoS is trivial.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2017-10-27 14:59:29 +02:00
Michal Privoznik
98696fd170 qemuDomainSetInterfaceParameters: Explicitly reject unsupported net types
For instance, NET_TYPE_MCAST doesn't support setting QoS. Instead
of claiming success and doing nothing, we should be explicit
about that and report an error.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2017-10-27 14:59:29 +02:00
John Ferlan
c9f7a04e28 qemu.conf: Clarify the various _tls_x509_cert_dir descriptions
https://bugzilla.redhat.com/show_bug.cgi?id=1458630

Apparantly commit id 'dc4c2f75a' wasn't specific enough, so here's
a few more clarifications.
2017-10-27 05:53:45 -04:00
John Ferlan
2518fd3b6a storage: Allow creation of a LUKS using logical volume
https://bugzilla.redhat.com/show_bug.cgi?id=1427049

Use virStorageBackendCreateVolUsingQemuImg to apply the LUKS information
to the logical volume just created.  As part of the processing of the
lvcreate command add 2MB to the capacity to account for the LUKS header
when it's determined that the volume desires to use encryption.
2017-10-27 05:46:35 -04:00
John Ferlan
29c5c7d27e storage: Introduce virStorageBackendCreateVolUsingQemuImg
Create a shim that will allow other backends to make use of qemu-img
functionality to create or possibly modify the volume.
2017-10-27 05:46:35 -04:00
John Ferlan
e32a9ef420 storage: Extract out the LVCREATE
Refactor to extract out the LVCREATE command.  This also removes the
need for the local @created since the error path can now only be reached
after the creation of the logical volume.

Signed-off-by: John Ferlan <jferlan@redhat.com>
2017-10-27 05:46:35 -04:00
John Ferlan
becb383a63 storage: Properly resize a local volume using LUKS
https://bugzilla.redhat.com/show_bug.cgi?id=1490279

Turns out the virStorageBackendVolResizeLocal did not differentiate
whether the target volume was a LUKS volume or not and just blindly
did the ftruncate() on the target volume.

Follow the volume creation logic (in general) and create a qemu-img
resize command to resize the target volume for LUKS ensuring that
the --object secret is provided as well as the '--image-opts' used
by the qemu-img resize logic to describe the path and secret ensuring
that it's using the luks driver on the volume of course.
2017-10-27 05:34:36 -04:00
John Ferlan
03984ae543 storage: Alter storageBackendCreateQemuImgSecretObject args
Since all that was really needed was a couple of fields and building
the object can be more generic, let's alter the args a bit. This will
be useful shortly for adding the secret object for a volume resize
operation on a luks volume that will need a secret object.
2017-10-27 05:31:19 -04:00
John Ferlan
07731f9917 storage: Add error path for virStorageBackendCreateQemuImgCmdFromVol
Rather than inline the various free's and return NULL, just create
an error label.
2017-10-27 05:31:19 -04:00
John Ferlan
ae94084b76 storage: Alter args to storageBackendResizeQemuImg
Rather than passing just the path, pass the virStorageVolDefPtr as we're
going to need it shortly.

Also fix the order of code and stack variables in the calling function
virStorageBackendVolResizeLocal.
2017-10-27 05:31:19 -04:00
Christian Ehrhardt
a150b86c4c virt-aa-helper: apparmor wildcards to forbidden chars
Some globbing chars in the domain name could be used to break out of
apparmor rules, so lets forbid these when in virt-aa-helper.

Also adding a test to ensure all those cases were detected as bad char.

Signed-off-by: Christian Ehrhardt <christian.ehrhardt@canonical.com>
2017-10-27 10:32:02 +02:00
Marc Hartmayer
a50b45a297 qemu: Fix memory leak in virQEMUCapsLoadCPUModels
Don't leak @blockNodes in the loop.

==226576== 7,120 bytes in 60 blocks are definitely lost in loss record 122 of 125
==226576==    at 0x4835214: calloc (vg_replace_malloc.c:711)
==226576==    by 0x4950D7B: virAllocN (viralloc.c:191)
==226576==    by 0x49EB5BB: virXPathNodeSet (virxml.c:676)
==226576==    by 0x104DB67: virQEMUCapsLoadCPUModels (qemu_capabilities.c:3738)
==226576==    by 0x105510D: virQEMUCapsLoadCache (qemu_capabilities.c:3929)
==226576==    by 0x104459F: qemuTestParseCapabilities (testutilsqemu.c:498)
==226576==    by 0x1040DC9: testQemuCapsCopy (qemucapabilitiestest.c:105)
==226576==    by 0x1041F07: virTestRun (testutils.c:180)
==226576==    by 0x1040B45: mymain (qemucapabilitiestest.c:181)
==226576==    by 0x104320F: virTestMain (testutils.c:1119)
==226576==    by 0x1041149: main (qemucapabilitiestest.c:193)

Signed-off-by: Marc Hartmayer <mhartmay@linux.vnet.ibm.com>
Reviewed-by: Bjoern Walk <bwalk@linux.vnet.ibm.com>
Reviewed-by: Boris Fiuczynski <fiuczy@linux.vnet.ibm.com>
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2017-10-27 10:13:43 +02:00
Christian Ehrhardt
07fc5c9c06 virt-aa-helper: grant locking permission on -f
Hot-adding disks does not parse the full XML to generate apparmor rules.
Instead it uses -f <PATH> to append a generic rule for that file path.

580cdaa7: "virt-aa-helper: locking disk files for qemu 2.10" implemented
the qemu 2.10 requirement to allow locking on disks images that are part of
the domain xml.

But on attach-device a user will still trigger an apparmor deny by going
through virt-aa-helper -f, to fix that add the lock "k" permission to the
append file case of virt-aa-helper.

Signed-off-by: Christian Ehrhardt <christian.ehrhardt@canonical.com>
2017-10-26 12:48:32 +02:00
Jiri Denemark
8def32157a conf: Avoid leaking blockers from virDomainCapsCPUModel
When adding CPU usability blockers I forgot to properly free them when
in virDomainCapsCPUModelsDispose.

Reported-by: Marc Hartmayer <mhartmay@linux.vnet.ibm.com>
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
2017-10-26 12:45:34 +02:00
Christian Ehrhardt
3080834fcd Increase default file handle limits for virtlockd
The assumption so far was an average of 4 disks per guest.
But some architectures, like s390x, still often use plenty of smaller disks.

To include those in the considerations an assumption of an average of 10
disks is more reasonable.

Signed-off-by: Christian Ehrhardt <christian.ehrhardt@canonical.com>
2017-10-26 12:29:28 +02:00
Christian Ehrhardt
d744476475 Increase default file handle limits for virtlogd
The initial assumption was ~2 files per guest, but some common setups
like Openstack drive up to 4 files per guest.

E.g. on Arm where the following XML leads to 4 file handles:
    <serial type='file'>
      <source path='/var/lib/nova/instances/7c0dcd78-.../console.log'/>
      <target port='0'/>
      <alias name='serial0'/>
    </serial>
    <console type='file'>
      <source path='/var/lib/nova/instances/7c0dcd78-.../console.log'/>
      <target type='serial' port='0'/>
      <alias name='serial0'/>
    </console>

With that in mind and the target to support 4k guests by default we
should raise the limit to 16k.

Signed-off-by: Christian Ehrhardt <christian.ehrhardt@canonical.com>
2017-10-26 12:29:28 +02:00
Jiri Denemark
32c29f10db qemu: Enabled pause-before-switchover migration capability
QEMU identified a race condition between the device state serialization
and the end of storage migration. Both QEMU and libvirt needs to be
updated to fix this.

Our migration work flow is modified so that after starting the migration
we to wait for QEMU to enter "pre-switchover", "postcopy-active", or
"completed" state. Once there, we cancel all block jobs as usual. But if
QEMU is in "pre-switchover", we need to resume the migration afterwards
and wait again for the real end (either "postcopy-active" or
"completed" state).

Old QEMU will just enter either "postcopy-active" or "completed"
directly, which is still correctly handled even by new libvirt. The
"pre-switchover" state will only be entered if QEMU supports it and the
pause-before-switchover capability was enabled. Thus all combinations of
libvirt and QEMU will work, but only new QEMU with new libvirt will
avoid the race condition.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2017-10-26 10:36:02 +02:00
Jiri Denemark
6addde24be qemu: Add pause-before-switchover migration capability
This new capability enables a pause before device state serialization so
that we can finish all block jobs without racing with the end of the
migration. The pause is indicated by "pre-switchover" state. Once we're
done QEMU enters "device" migration state.

This patch just defines the new capability and QEMU migration states and
their mapping to our job states.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2017-10-26 10:36:02 +02:00