]> xenbits.xensource.com Git - libvirt.git/log
libvirt.git
7 years agoutil: Umark virBufferCheckErrorInternal as ATTRIBUTE_RETURN_CHECK
Martin Kletzander [Wed, 16 Aug 2017 09:09:47 +0000 (11:09 +0200)]
util: Umark virBufferCheckErrorInternal as ATTRIBUTE_RETURN_CHECK

The function is useful even without using the return value.  And if
needed, the return value can be obtained by other calls as well.  The
potential for clean-up can be seen in the following patch.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
7 years agodocs: Update news with domain name bug fixes
Martin Kletzander [Wed, 23 Aug 2017 11:46:36 +0000 (13:46 +0200)]
docs: Update news with domain name bug fixes

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
7 years agoqemu: Use short domain name in qemuDomainGetPreservedMountPath
Martin Kletzander [Wed, 23 Aug 2017 08:39:57 +0000 (10:39 +0200)]
qemu: Use short domain name in qemuDomainGetPreservedMountPath

Otherwise longer domain names might generate paths that are too long
to be created.  This follows what other parts of the code do as well.

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

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
7 years agoconf: Properly truncate wide character names in virDomainObjGetShortName
Martin Kletzander [Wed, 23 Aug 2017 11:18:19 +0000 (13:18 +0200)]
conf: Properly truncate wide character names in virDomainObjGetShortName

We always truncated the name at 20 bytes instead of characters.  In
case 20 bytes were in the middle of a multi-byte character, then the
string became invalid and various parts of the code would error
out (e.g. XML parsing of that string).  Let's instead properly
truncate it after 20 characters instead.

We cannot test this in our test suite because we would need to know
what locales are installed on the system where the tests are ran and
if there is supported one (most probably there will be, but we cannot
be 100% sure), we could initialize gettext in qemuxml2argvtest, but
there would still be a chance of getting two different (both valid,
though) results.

In order to test this it is enough to start a machine with a name for
which trimming it after 20 bytes would create invalid sequence (e.g.
1234567890123456789č where č is any multi-byte character).  Then start
the domain and restart libvirtd.  The domain would disappear because
such illegal sequence will not go through the XML parser.  And that's
not a bug of the parser, it should not be in the XML in the first
place, but since we don't use any sophisticated formatter, just
mash some strings together, the formatting succeeds.

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

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
7 years agovirsh: Honour --readonly with cmdConnect and no name
Martin Kletzander [Fri, 18 Aug 2017 14:35:23 +0000 (16:35 +0200)]
virsh: Honour --readonly with cmdConnect and no name

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

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
7 years agodocs: Update news with virtio-vga/gpu's max_outputs= parameter
Martin Kletzander [Wed, 23 Aug 2017 12:10:57 +0000 (14:10 +0200)]
docs: Update news with virtio-vga/gpu's max_outputs= parameter

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
7 years agoqemu: Add support for virtio-vga/gpu's max_outputs= parameter
Martin Kletzander [Wed, 23 Aug 2017 12:06:41 +0000 (14:06 +0200)]
qemu: Add support for virtio-vga/gpu's max_outputs= parameter

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

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
7 years agoqemu: Add capabilities for virtio-vga/gpu's max_outputs= parameter
Martin Kletzander [Wed, 23 Aug 2017 12:06:17 +0000 (14:06 +0200)]
qemu: Add capabilities for virtio-vga/gpu's max_outputs= parameter

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
7 years agotests: add qemu chardev source reconnect tests
Pavel Hrdina [Fri, 25 Aug 2017 17:11:24 +0000 (19:11 +0200)]
tests: add qemu chardev source reconnect tests

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
7 years agoqemu: implement chardev source reconnect
Pavel Hrdina [Fri, 25 Aug 2017 16:57:15 +0000 (18:57 +0200)]
qemu: implement chardev source reconnect

The reconnect attribute for chardev devices in QEMU is used to
configure the reconnect timeout in seconds.  Setting '0' value disables
the reconnect functionality thus we don't allow to set '0' for QEMU.
To disable the reconnect user should use <reconnect enabled='no'/>.

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

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
7 years agotests: add generic xml chardev source reconnect tests
Pavel Hrdina [Wed, 23 Aug 2017 15:48:14 +0000 (17:48 +0200)]
tests: add generic xml chardev source reconnect tests

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
7 years agoconf: introduce reconnect element for chardev source
Pavel Hrdina [Wed, 23 Aug 2017 15:08:07 +0000 (17:08 +0200)]
conf: introduce reconnect element for chardev source

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
7 years agoqemu: introduce QEMU_CAPS_CHARDEV_RECONNECT
Pavel Hrdina [Wed, 9 Aug 2017 13:06:40 +0000 (15:06 +0200)]
qemu: introduce QEMU_CAPS_CHARDEV_RECONNECT

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
7 years agonetwork: Fix virNetworkObjBridgeInUse return type
John Ferlan [Thu, 17 Aug 2017 19:41:37 +0000 (15:41 -0400)]
network: Fix virNetworkObjBridgeInUse return type

Rather than an int, it returns a bool - so let's define it that way

Signed-off-by: John Ferlan <jferlan@redhat.com>
7 years agoRevert "interface: Consume @def in virInterfaceObjNew"
John Ferlan [Sat, 29 Jul 2017 11:20:59 +0000 (07:20 -0400)]
Revert "interface: Consume @def in virInterfaceObjNew"

This reverts commit 92840eb3a7e47cdf761e52afccc41d2a35327fbd.

More recent reviews/changes don't have the vir*ObjNew APIs
consuming the @def, so remove from Interface as well. Changes
needed to also deal with conflicts from commit id '46f5eca4'.

Signed-off-by: John Ferlan <jferlan@redhat.com>
7 years agomaint: correct quoting for gl_WARN_ADD
Eric Blake [Thu, 24 Aug 2017 19:36:36 +0000 (14:36 -0500)]
maint: correct quoting for gl_WARN_ADD

3 out of 4 uses of gl_WARN_ADD() were incorrectly adding "" around
the argument, which in turn resulted in the argument being used
unquoted (configure had gl_positive=""-fstack-protector-all"",
rather than the intended gl_positive="-fstack-protector-all").

Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Andrea Bolognani <abologna@redhat.com>
7 years agodaemon: logging: Fix --verbose option being ignored by the daemon
Erik Skultety [Fri, 25 Aug 2017 14:58:51 +0000 (16:58 +0200)]
daemon: logging: Fix --verbose option being ignored by the daemon

Commit 94c465d0 refactored the logging setup phase but introduced an
issue, where the daemon ignores verbose mode when there are no outputs
defined and the default must be used. The problem is that the default
output was determined too early, thus ignoring the potential '--verbose'
option taking effect. This patch postpones the creation of the default
output to the very last moment when nothing else can change. Since the
default output is only created during the init phase, it's safe to leave
the pointer as NULL for a while, but it will be set eventually, thus not
affecting runtime.
Patch also adjusts both the other daemons.

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

Signed-off-by: Erik Skultety <eskultet@redhat.com>
7 years agoqemu: Handle host devices not being available better
Andrea Bolognani [Thu, 24 Aug 2017 14:33:29 +0000 (16:33 +0200)]
qemu: Handle host devices not being available better

We can't retrieve the isolation group of a device that's not present
in the system. However, it's very common for VFs to be created late
in the boot, so they might not be present yet when libvirtd starts,
which would cause the guests using them to disappear.

Moreover, for other architectures and even ppc64 before isolation
groups were introduced, it's considered perfectly fine to configure a
guest to use a device that's not yet (or no longer) available to the
host, with the obvious caveat that such a guest won't be able to
start before the device is available.

In order to be consistent, when a device's isolation group can't be
determined fall back to not isolating it rather than erroring out or,
worse, making the guest disappear.

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

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
7 years agoconf: don't close the source element inside different function
Pavel Hrdina [Thu, 24 Aug 2017 14:46:58 +0000 (16:46 +0200)]
conf: don't close the source element inside different function

While formatting disk or chardev element they both uses
virDomainDiskSourceDefFormatSeclabel() function which also closes
the source element.  This is not extendable.

Use the new virXMLFormatElement() to properly format the source
element with possible child elements.

As a side effect it fixes a bug in disk source formatting.

Reviewed-by: John Ferlan <jferlan@redhat.com>
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
7 years agoutil: introduce virXMLFormatElement helper
Pavel Hrdina [Thu, 24 Aug 2017 13:08:23 +0000 (15:08 +0200)]
util: introduce virXMLFormatElement helper

This helper allows you to better structurize the code if some element
may or may not contains attributes and/or child elements.

Reviewed-by: John Ferlan <jferlan@redhat.com>
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
7 years agoutil: introduce virBufferSetChildIndent macro
Pavel Hrdina [Thu, 24 Aug 2017 12:54:56 +0000 (14:54 +0200)]
util: introduce virBufferSetChildIndent macro

Reviewed-by: John Ferlan <jferlan@redhat.com>
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
7 years agomaint: Update to latest gnulib
Erik Skultety [Mon, 28 Aug 2017 10:12:51 +0000 (12:12 +0200)]
maint: Update to latest gnulib

This pulls in, among other new things, vc-list-files fix to make
syntax-check work with git worktrees.

Signed-off-by: Erik Skultety <eskultet@redhat.com>
7 years agoconf: add virDomainVideoDefNew
Cole Robinson [Wed, 28 Jun 2017 14:24:33 +0000 (10:24 -0400)]
conf: add virDomainVideoDefNew

To handle setting a default heads value. Convert callers that were
doing it by hand

Reviewed-by: John Ferlan <jferlan@redhat.com>
Signed-off-by: Cole Robinson <crobinso@redhat.com>
7 years agoqemu: domain: Move some validation out of DeviceDefPostParse
Cole Robinson [Wed, 28 Jun 2017 14:53:23 +0000 (10:53 -0400)]
qemu: domain: Move some validation out of DeviceDefPostParse

And into DeviceDefValidate which is the expected place

Reviewed-by: John Ferlan <jferlan@redhat.com>
Signed-off-by: Cole Robinson <crobinso@redhat.com>
7 years agoqemu: parse: drop redundant video config
Cole Robinson [Wed, 28 Jun 2017 13:54:16 +0000 (09:54 -0400)]
qemu: parse: drop redundant video config

The ram/vram = 0 bits aren't needed, and PostParse will fill in the
needed QXL default

Reviewed-by: John Ferlan <jferlan@redhat.com>
Signed-off-by: Cole Robinson <crobinso@redhat.com>
7 years agoqemu: Remove remnants of xenner support
Cole Robinson [Sun, 27 Aug 2017 13:29:50 +0000 (09:29 -0400)]
qemu: Remove remnants of xenner support

Both of these are dead code: qemu_command.c explicitly rejects
VIRT_XEN earlier in the call chain, and qemu_parse_command.c
will never set VIRT_XEN anymore

Reviewed-by: John Ferlan <jferlan@redhat.com>
Signed-off-by: Cole Robinson <crobinso@redhat.com>
7 years agodocs: document migrate-getmaxdowntime support
Scott Garfinkle [Thu, 17 Aug 2017 22:17:22 +0000 (17:17 -0500)]
docs: document migrate-getmaxdowntime support

7 years agovirsh: Add support for virDomainMigrateGetMaxDowntime
Scott Garfinkle [Thu, 17 Aug 2017 22:17:21 +0000 (17:17 -0500)]
virsh: Add support for virDomainMigrateGetMaxDowntime

Implement a migrate-getmaxdowntime command to complement migrate-setmaxdowntime.

7 years agoqemu: Implement virDomainMigrateGetMaxDowntime
Scott Garfinkle [Thu, 17 Aug 2017 22:17:20 +0000 (17:17 -0500)]
qemu: Implement virDomainMigrateGetMaxDowntime

Add code to support querying maximum allowable downtime during live migration.

7 years agoAdd virDomainMigrateGetMaxDowntime public API
Scott Garfinkle [Thu, 17 Aug 2017 22:17:19 +0000 (17:17 -0500)]
Add virDomainMigrateGetMaxDowntime public API

Add virDomainMigrateGetMaxDowntime to support querying maximum allowable
downtime during live migration.

7 years agoqemu: Report error on failure to set isolation group
Andrea Bolognani [Thu, 24 Aug 2017 14:07:07 +0000 (16:07 +0200)]
qemu: Report error on failure to set isolation group

This is more user-friendly because the error will be
displayed directly instead of being buried in the log.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
7 years agovirt-host-validate: Fix warning for IOMMU detection on PPC
Nitesh Konkar [Thu, 17 Aug 2017 13:48:05 +0000 (19:18 +0530)]
virt-host-validate: Fix warning for IOMMU detection on PPC

Fix the warning generated on PPC by virt-host-validate for IOMMU.
In case of PPC, IOMMU in the host kernel either has it or it's not
compiled in. The /sys/kernel/iommu_groups check is good enough to
verify if it was compiled with the kernel or not.

Modify the error message when "if (sb.st_nlink <= 2)" to indicate
what the problem would be since there would be no @bootarg.

Signed-off-by: Nitesh Konkar <nitkon12@linux.vnet.ibm.com>
7 years agoRevert "maint: Update to latest gnulib"
Erik Skultety [Thu, 24 Aug 2017 17:07:53 +0000 (19:07 +0200)]
Revert "maint: Update to latest gnulib"

Revert @f8172388c which broke the build on Centos 6, because of old
autoconf (< 2.63b) not properly quoting arguments for shell.

7 years agolibxl: Avoid a variable named 'stat'
George Dunlap [Thu, 24 Aug 2017 11:34:13 +0000 (12:34 +0100)]
libxl: Avoid a variable named 'stat'

Using a variable named 'stat' clashes with the system function
'stat()' causing compiler warnings on some platforms:

libxl/libxl_driver.c: In function 'libxlDomainBlockStatsVBD':
libxl/libxl_driver.c:5387: error: declaration of 'stat' shadows a global declaration [-Wshadow]
/usr/include/sys/stat.h:455: error: shadowed declaration is here [-Wshadow]

Signed-off-by: George Dunlap <george.dunlap@citrix.com>
Reviewed-by: Andrea Bolognani <abologna@redhat.com>
7 years agomaint: Update to latest gnulib
Erik Skultety [Thu, 24 Aug 2017 08:40:06 +0000 (10:40 +0200)]
maint: Update to latest gnulib

This pulls in, among other new things, vc-list-files fix to make
syntax-check work with git worktrees.

Signed-off-by: Erik Skultety <eskultet@redhat.com>
7 years agovmx: do not treat controllers as implicit devices
Ján Tomko [Mon, 21 Aug 2017 14:44:42 +0000 (16:44 +0200)]
vmx: do not treat controllers as implicit devices

When parsing the config, we look for the SCSI controllers one by one,
remembering their models, then let virDomainDefAddImplicitDevices
add them if any SCSI disk is using them.

Since these controllers are not really implicit (they are present
in the source config), add them explicitly.

This patch maintains the behavior of not adding a controller
if it was present in the config, but no disk was using it.

This also resolves the memory leak of virVMXParseConfig overwriting
the video device added by calling virDomainDefAddImplicitDevices
before the parsing is finished.

Reported-by: Michal Privoznik <mprivozn@redhat.com>
7 years agovz: build fix
Nikolay Shirokovskiy [Thu, 24 Aug 2017 07:08:35 +0000 (10:08 +0300)]
vz: build fix

6e6faf6d changed vzDomObjAlloc signature in source but not in header file.

Signed-off-by: Erik Skultety <eskultet@redhat.com>
7 years agoconf: check address type for USB hostdevs
Ján Tomko [Wed, 23 Aug 2017 14:32:28 +0000 (16:32 +0200)]
conf: check address type for USB hostdevs

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

7 years agoconf: move hostdev address validation to virDomainHostdevDefValidate
Ján Tomko [Wed, 23 Aug 2017 14:27:36 +0000 (16:27 +0200)]
conf: move hostdev address validation to virDomainHostdevDefValidate

For selected hostdev types, we validate that the address type
matches the subsystem type when parsing the XML.

Move it to the validation phase, to allow extending the checks
to other subsystem types without making existing domains disappear.

7 years agotests: Fix leak in securityselinuxtest
John Ferlan [Wed, 23 Aug 2017 16:32:23 +0000 (12:32 -0400)]
tests: Fix leak in securityselinuxtest

If we jump to the error: label and @secbuf is allocated, then it's not
free'd at all.

Found by Coverity

7 years agovz: support disabled items in vz boot order
Nikolay Shirokovskiy [Fri, 30 Jun 2017 06:34:27 +0000 (09:34 +0300)]
vz: support disabled items in vz boot order

At the time the check was written virtuozzo did not use disabled items in boot
order configuration. Boot items were always enabled. Now they can be disabled
as well. Supporting such items is easy - they just should be ignored.

7 years agodocs: Define anchors correctly in pci-hotplug
Andrea Bolognani [Wed, 23 Aug 2017 11:55:01 +0000 (13:55 +0200)]
docs: Define anchors correctly in pci-hotplug

HTML5 obsoletes the 'name' attribute in favor of 'id',
and our TOC generator apparently follows the recommendation
to the letter, resulting in a broken TOC if you use the
old-school attribute.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
7 years agoconf: do not count per-device boot elements when parsing <os><boot>
Ján Tomko [Fri, 18 Aug 2017 15:55:54 +0000 (17:55 +0200)]
conf: do not count per-device boot elements when parsing <os><boot>

When parsing bootable devices, we maintain a bitmap of used
<boot order=""> elements. Use it in the post-parse function
to figure out whether the user tried to mix per-device and
per-domain boot elements.

This removes the need to count them twice.

7 years agoconf: create a thin wrapper above virDomainDefPostParse
Ján Tomko [Tue, 22 Aug 2017 11:38:35 +0000 (13:38 +0200)]
conf: create a thin wrapper above virDomainDefPostParse

Rename the original function to virDomainDefPostParseInternal
to allow adding arguments that will be only used by the internal
version.

7 years agoconf: rename virDomain*PostParseInternal to virDomain*PostParseCommon
Ján Tomko [Tue, 22 Aug 2017 11:29:24 +0000 (13:29 +0200)]
conf: rename virDomain*PostParseInternal to virDomain*PostParseCommon

These functions contain the post-parse steps common for all drivers.
Rename it to use the 'Common' prefix, instead of the vagueness
of 'Internal', leaving 'Internal' available for other vague uses.

7 years agoconf: move chardev validation into virDomainDeviceDefValidateInternal
Pavel Hrdina [Fri, 18 Aug 2017 20:00:12 +0000 (22:00 +0200)]
conf: move chardev validation into virDomainDeviceDefValidateInternal

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
7 years agoconf: separate PTY chardev source parsing
Pavel Hrdina [Fri, 18 Aug 2017 16:19:48 +0000 (18:19 +0200)]
conf: separate PTY chardev source parsing

There is no reason why to share the same code for PTY and other file
based chardev source types.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
7 years agoconf: move FILE chardev source parsing to separate function
Pavel Hrdina [Fri, 18 Aug 2017 16:17:28 +0000 (18:17 +0200)]
conf: move FILE chardev source parsing to separate function

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
7 years agoconf: assign parsed strings directly into chardev source definition
Pavel Hrdina [Fri, 18 Aug 2017 16:12:08 +0000 (18:12 +0200)]
conf: assign parsed strings directly into chardev source definition

Since the source element is parsed only once for these type of
character devices we don't have to use temporary variable and
check whether the variable was already set.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
7 years agoconf: move UNIX chardev source parsing to separate function
Pavel Hrdina [Fri, 18 Aug 2017 17:25:11 +0000 (19:25 +0200)]
conf: move UNIX chardev source parsing to separate function

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
7 years agoconf: move UDP chardev source parsing to separate function
Pavel Hrdina [Fri, 18 Aug 2017 17:05:20 +0000 (19:05 +0200)]
conf: move UDP chardev source parsing to separate function

The extra check whether (connect|bind)(Host|Service) was set is
required because for UDP chardev there can be two source elements.
Without the check there could be a memory leak.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
7 years agoconf: move TCP chardev source parsing to separate function
Pavel Hrdina [Fri, 18 Aug 2017 17:01:13 +0000 (19:01 +0200)]
conf: move TCP chardev source parsing to separate function

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
7 years agoconf: move mode parsing of chardev source to separate function
Pavel Hrdina [Fri, 18 Aug 2017 15:32:27 +0000 (17:32 +0200)]
conf: move mode parsing of chardev source to separate function

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
7 years agoconf: move chardev log parsing to separate function
Pavel Hrdina [Fri, 18 Aug 2017 15:19:26 +0000 (17:19 +0200)]
conf: move chardev log parsing to separate function

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
7 years agoconf: move chardev protocol parsing to separate function
Pavel Hrdina [Fri, 18 Aug 2017 13:37:08 +0000 (15:37 +0200)]
conf: move chardev protocol parsing to separate function

In order to ensure that the default protocol is RAW, explicitly
assigning VIR_DOMAIN_CHR_TCP_PROTOCOL_RAW = 0.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
7 years agoconf: error out for multiple protocol elements while parsing chardev
Pavel Hrdina [Fri, 18 Aug 2017 13:17:34 +0000 (15:17 +0200)]
conf: error out for multiple protocol elements while parsing chardev

Remove check whether a variable was already set because the element
is parsed only once now.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
7 years agoconf: error out for multiple log elements while parsing chardev
Pavel Hrdina [Fri, 18 Aug 2017 13:15:28 +0000 (15:15 +0200)]
conf: error out for multiple log elements while parsing chardev

Remove check whether a variable was already set because the element
is parsed only once now.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
7 years agoconf: error out for multiple source elements while parsing chardev
Pavel Hrdina [Fri, 18 Aug 2017 15:14:34 +0000 (17:14 +0200)]
conf: error out for multiple source elements while parsing chardev

Currently we accept and correctly parse this chardev XML:

  ...
  <channel type='tcp'>
    <source mode='connect'/>
    <source mode='bind' host='localhost'/>
    <source service='4567'/>
    <target type='virtio' name='test'/>
  </channel>
  ...

The parsed formatted XML is:

  ...
  <channel type='tcp'>
    <source mode='connect' host='localhost' service='4567'/>
    <target type='virtio' name='test'/>
  </channel>
  ...

That behavior is super wrong and should not be allowed.  If you notice
the current parse takes the first found attribute and uses that value,
so for example from the "<source mode='bind' host='localhost'/>" only
the "host" attribute is used.  It works the same way for all possible
attributes that we are able to parse for source element.

This patch enforces providing only one source element for all character
devices, only for UDP type we allow to provide two source elements
since you can specify both modes.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
7 years agoconf: switch from while to for loop for chardev parsing
Pavel Hrdina [Fri, 18 Aug 2017 15:12:59 +0000 (17:12 +0200)]
conf: switch from while to for loop for chardev parsing

This removes one level of indentation.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
7 years agotests: introduce genericxml test for UNIX chardev
Pavel Hrdina [Thu, 17 Aug 2017 12:55:11 +0000 (14:55 +0200)]
tests: introduce genericxml test for UNIX chardev

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
7 years agotests: introduce genericxml test for UDP chardev
Pavel Hrdina [Thu, 17 Aug 2017 12:26:36 +0000 (14:26 +0200)]
tests: introduce genericxml test for UDP chardev

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
7 years agotests: introduce genericxml test for TCP chardev
Pavel Hrdina [Thu, 17 Aug 2017 10:45:48 +0000 (12:45 +0200)]
tests: introduce genericxml test for TCP chardev

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
7 years agoconf: useserial: drop useless check for serial devices
Ján Tomko [Fri, 18 Aug 2017 15:05:35 +0000 (17:05 +0200)]
conf: useserial: drop useless check for serial devices

Since its introduction in commit 874e65aa, if someone requests:
<os><bios useserial="yes"/><os/>
we report an error if we cannot successfully count the number
of serial devices via an XPath query.

Instead of fixing the check (and moving it to the validation phase,
to prevent existing domains from disappearing), drop it completely.
For QEMU, the number of serials is checked when building the command
line.

7 years agoDon't autogenerate seclabels of type 'none'
Jim Fehlig [Wed, 16 Aug 2017 21:46:55 +0000 (15:46 -0600)]
Don't autogenerate seclabels of type 'none'

When security drivers are active but confinement is not enabled,
there is no need to autogenerate <seclabel> elements when starting
a domain def that contains no <seclabel> elements. In fact,
autogenerating the elements can result in needless save/restore and
migration failures when the security driver is not active on the
restore/migration target.

This patch changes the virSecurityManagerGenLabel function in
src/security_manager.c to only autogenerate a <seclabel> element
if none is already defined for the domain *and* default
confinement is enabled. Otherwise the needless <seclabel>
autogeneration is skipped.

Resolves: https://bugzilla.opensuse.org/show_bug.cgi?id=1051017

7 years agoFix building domain def in securityselinuxtest
Jim Fehlig [Wed, 16 Aug 2017 21:45:54 +0000 (15:45 -0600)]
Fix building domain def in securityselinuxtest

The virDomainDef created by testBuildDomainDef in securityselinuxtest
adds a seclabel but does not increment nseclabels. Also, it should
populate seclabel->model with 'selinux'.

While at it, use the secdef itself to populate values instead of
the indirection through def->seclabels[0].

7 years agotools: Fix docs in libvirt-guests configuration file
Lily Zhu [Mon, 14 Aug 2017 16:39:36 +0000 (00:39 +0800)]
tools: Fix docs in libvirt-guests configuration file

It was not entirely clear that PARALLEL_SHUTDOWN setting is applied only
when the desired action is "shutdown".

Signed-off-by: Lily Zhu <lizhu@redhat.com>
7 years agodocs: Improve PCI topology and hotplug guidelines
Andrea Bolognani [Thu, 17 Aug 2017 12:11:56 +0000 (14:11 +0200)]
docs: Improve PCI topology and hotplug guidelines

Address some minor flaws in the original document that
were pointed out during review.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
7 years agoconf: Use the correct limit for the number of PHBs
Andrea Bolognani [Thu, 17 Aug 2017 15:19:57 +0000 (17:19 +0200)]
conf: Use the correct limit for the number of PHBs

I mistakenly thought pSeries guests supported 32 PHBs,
but it turns out they only support 31. Validate the
target index accordingly.

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

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
7 years agoconf: Move target index validation
Andrea Bolognani [Thu, 17 Aug 2017 14:22:14 +0000 (16:22 +0200)]
conf: Move target index validation

Validation should happen after parsing, so the proper
location for it is virDomainControllerDefValidate()
rather than virDomainControllerDefParseXML().

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
7 years agotests: Improve target index validation coverage
Andrea Bolognani [Thu, 17 Aug 2017 14:45:28 +0000 (16:45 +0200)]
tests: Improve target index validation coverage

Split one of the existing tests to ensure both configuration
errors it contained cause a failure, and introduce a new
test case.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
7 years agoqemu: Implement postParse callback skipping on config reload
Peter Krempa [Wed, 16 Aug 2017 14:00:25 +0000 (16:00 +0200)]
qemu: Implement postParse callback skipping on config reload

Use the new facility which allows to ignore failures in post parse
callbacks if they are not fatal so that VM configs are not lost if the
emulator binary is missing.

If qemuCaps can't be populated on daemon restart skip certain portions
of the post parse callbacks during config reload and re-run the callback
during VM startup.

This fixes VMs vanishing if the emulator binary was broken or
uninstalled and libvirtd was restarted.

7 years agoqemu: domain: Don't set default USB model if qemuCaps is missing
Peter Krempa [Wed, 16 Aug 2017 13:54:10 +0000 (15:54 +0200)]
qemu: domain: Don't set default USB model if qemuCaps is missing

qemuDomainControllerDefPostParse assigns the default USB controller
model when it was not specified by the user. Skip this step if @qemuCaps
is missing so that we don't fill wrong data. This will then be fixes by
re-running the post parse callback.

7 years agoqemu: domain: Don't return default NIC model if @qemuCaps are missing
Peter Krempa [Wed, 16 Aug 2017 13:49:15 +0000 (15:49 +0200)]
qemu: domain: Don't return default NIC model if @qemuCaps are missing

Return NULL in qemuDomainDefaultNetModel if qemuCaps is missing and the
network card model would be determined by the capabilities.

7 years agoqemu: capabilities: Tolerate missing @qemuCaps in virQEMUCapsSupportsGICVersion
Peter Krempa [Wed, 16 Aug 2017 13:44:35 +0000 (15:44 +0200)]
qemu: capabilities: Tolerate missing @qemuCaps in virQEMUCapsSupportsGICVersion

Report the given GIC version as unsupported if @qemuCapsi is NULL. This
will be helpful to run post parse callbacks even if qemu is not
currently installed.

7 years agoqemu: capabilities: Tolerate missing @qemuCaps in virQEMUCapsGetCanonicalMachine
Peter Krempa [Wed, 16 Aug 2017 13:37:18 +0000 (15:37 +0200)]
qemu: capabilities: Tolerate missing @qemuCaps in virQEMUCapsGetCanonicalMachine

If qemuCaps are not present, just return the original machine type name.

This will help in situations when qemuCaps is not available in the post
parse callback.

7 years agoconf: add infrastructure for tolerating certain post parse callback failures
Peter Krempa [Tue, 15 Aug 2017 16:41:59 +0000 (18:41 +0200)]
conf: add infrastructure for tolerating certain post parse callback failures

Some failures of the post parse callback can be tolerated. This is
specifically desired when loading the configs of existing VMs. In such
case the post parse callback should not really be modifying anything
in the definition.

This patch adds a parse flag VIR_DOMAIN_DEF_PARSE_ALLOW_POST_PARSE_FAIL
which will allow the callbacks to report non-fatal failures by returning
a positive return value. In such case the field 'postParseFailed' in the
domain definition is set to true, to notify the drivers that the
callback failed and possibly needs to be re-run.

7 years agoconf: Return any non-zero value from virDomainDeviceInfoIterateInternal callback
Peter Krempa [Tue, 15 Aug 2017 16:09:32 +0000 (18:09 +0200)]
conf: Return any non-zero value from virDomainDeviceInfoIterateInternal callback

Post parse callbacks will need to be able to signal that they failed
non-fatally. This means that we need to return the value returned by the
callback without modification.

7 years agoqemu: domain: Don't re-allocate qemuCaps in post parse callbacks
Peter Krempa [Tue, 15 Aug 2017 13:25:23 +0000 (15:25 +0200)]
qemu: domain: Don't re-allocate qemuCaps in post parse callbacks

The domain post parse callback, domain address callback and the domain
device callback (for every single device) would each grab qemuCaps for
the current emulator. This is quite wasteful. Use the new callback to do
this just once.

7 years agoconf: Add callbacks that allocate per-def private data
Peter Krempa [Tue, 15 Aug 2017 13:18:51 +0000 (15:18 +0200)]
conf: Add callbacks that allocate per-def private data

Some drivers use def-specific private data across callbacks (e.g.
qemuCaps in the qemu driver). Currently it's mostly allocated in every
single callback. This is rather wasteful, given that every single call
to the device callback allocates it.

The new callback will allocate the data (if not provided externally) and
then use it for the VM, address and device post parse callbacks.

7 years agoqemu: Move assignment of default emulator to the basic post parse callback
Peter Krempa [Tue, 15 Aug 2017 13:16:20 +0000 (15:16 +0200)]
qemu: Move assignment of default emulator to the basic post parse callback

7 years agoconf: Add 'basic' post parse callback
Peter Krempa [Tue, 15 Aug 2017 13:11:45 +0000 (15:11 +0200)]
conf: Add 'basic' post parse callback

Add yet another post parse callback, which is executed prior the real
one without @parseOpaque. This is meant to set basics before
@parseOpaque (in case of the qemu driver qemuCaps) can be allocated.

This callback will allow to optimize passing of custom parseOpaque
through the callbacks.

7 years agoconf: domainlist: Explicitly report failure to load domain config
Peter Krempa [Thu, 10 Aug 2017 15:18:52 +0000 (17:18 +0200)]
conf: domainlist: Explicitly report failure to load domain config

When dropping a domain report which one was dropped so that it's not
necessary to rummage through the logs.

7 years agoqemu: don't check whether offline migration is safe
Pavel Hrdina [Thu, 17 Aug 2017 16:36:46 +0000 (18:36 +0200)]
qemu: don't check whether offline migration is safe

Offline migration transfers only the domain definition.

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

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
7 years agoutil: string: Introduce virStringHasChars
Peter Krempa [Wed, 26 Apr 2017 14:26:53 +0000 (16:26 +0200)]
util: string: Introduce virStringHasChars

The helper returns true if a string contains any of the given chars.
virStringHasControlChars can be reimplemented using that helper.

Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
7 years agonodedev: Introduce udevHandleOneDevice
Erik Skultety [Tue, 25 Jul 2017 15:41:31 +0000 (17:41 +0200)]
nodedev: Introduce udevHandleOneDevice

Let this new method handle the device object we obtained from the
monitor in order to enhance readability.

Signed-off-by: Erik Skultety <eskultet@redhat.com>
7 years agonodedev: udev: Remove the udevEventHandleCallback on fatal error
Erik Skultety [Wed, 28 Jun 2017 13:39:51 +0000 (15:39 +0200)]
nodedev: udev: Remove the udevEventHandleCallback on fatal error

So we have a sanity check for the udev monitor fd. Theoretically, it
could happen that the udev monitor fd changes (due to our own wrongdoing,
hence the 'sanity' here) and if that happens it means we are handling an
event from a different entity than we think, thus we should remove the
handle if someone somewhere somehow hits this hypothetical case.

Signed-off-by: Erik Skultety <eskultet@redhat.com>
7 years agonodedev: mdev: Report an error when mdev path resolution fails
Erik Skultety [Tue, 20 Jun 2017 14:50:26 +0000 (16:50 +0200)]
nodedev: mdev: Report an error when mdev path resolution fails

It might happen that virFileResolveLinkHelper fails on the lstat system
call. virFileResolveLink expects the caller to report an error when it
fails, however this wasn't the case for udevProcessMediatedDevice.

Signed-off-by: Erik Skultety <eskultet@redhat.com>
7 years agovirt-aa-helper: locking loader/nvram for qemu 2.10
Christian Ehrhardt [Thu, 17 Aug 2017 08:55:43 +0000 (10:55 +0200)]
virt-aa-helper: locking loader/nvram for qemu 2.10

Testing qemu-2.10-rc3 shows issues like:
  qemu-system-aarch64: -drive file=/home/ubuntu/vm-start-stop/vms/
  7936-0_CODE.fd,if=pflash,format=raw,unit=1: Failed to unlock byte 100

There is an apparmor deny due to qemu now locking those files:
 apparmor="DENIED" operation="file_lock" [...]
 name="/home/ubuntu/vm-start-stop/vms/7936-0_CODE.fd"
 name="/var/lib/uvtool/libvirt/images/kvmguest-artful-normal.qcow"
 [...] comm="qemu-system-aarch64" requested_mask="k" denied_mask="k"

The profile needs to allow locking for loader and nvram files via
the locking (k) rule.

Signed-off-by: Christian Ehrhardt <christian.ehrhardt@canonical.com>
7 years agovirt-aa-helper: locking disk files for qemu 2.10
Christian Ehrhardt [Thu, 10 Aug 2017 09:19:19 +0000 (11:19 +0200)]
virt-aa-helper: locking disk files for qemu 2.10

Testing qemu-2.10-rc2 shows issues like:
  qemu-system-x86_64: -drive file=/var/lib/uvtool/libvirt/images/kvmguest- \
  artful-normal.qcow,format=qcow2,if=none,id=drive-virtio-disk0:
  Failed to lock byte 100

It seems the following qemu commit changed the needs for the backing
image rules:

(qemu) commit 244a5668106297378391b768e7288eb157616f64
Author: Fam Zheng <famz@redhat.com>
    file-posix: Add image locking to perm operations

The block appears as:
 apparmor="DENIED" operation="file_lock" [...]
 name="/var/lib/uvtool/libvirt/images/kvmguest-artful-normal.qcow"
 [...] comm="qemu-system-x86" requested_mask="k" denied_mask="k"

With that qemu change in place the rules generated for the image
and backing files need the allowance to also lock (k) the files.

Disks are added via add_file_path and with this fix rules now get
that permission, but no other rules are changed, example:
  -  "/var/lib/uvtool/libvirt/images/kvmguest-artful-normal-a2.qcow" rw,
  +  "/var/lib/uvtool/libvirt/images/kvmguest-artful-normal-a2.qcow" rwk

Signed-off-by: Christian Ehrhardt <christian.ehrhardt@canonical.com>
7 years agoconf: use virXMLPropString and virXMLNodeContentString for vcpu parsing
Pavel Hrdina [Wed, 16 Aug 2017 08:45:14 +0000 (10:45 +0200)]
conf: use virXMLPropString and virXMLNodeContentString for vcpu parsing

XPath is good for random search of elements, not for accessing
attributes of one node.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
7 years agoconf: use virXMLNodeContentString for boot options parsing
Pavel Hrdina [Wed, 16 Aug 2017 08:28:16 +0000 (10:28 +0200)]
conf: use virXMLNodeContentString for boot options parsing

Using XPath here doesn't add any benefit.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
7 years agoconf: use virXMLPropStringLimit where it makes sense
Pavel Hrdina [Tue, 15 Aug 2017 13:31:06 +0000 (15:31 +0200)]
conf: use virXMLPropStringLimit where it makes sense

The XPath call for these cases is more expensive than accessing the
XML dom node directly.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
7 years agoconf: use virXMLPropString for actual network parsing
Pavel Hrdina [Wed, 16 Aug 2017 12:01:54 +0000 (14:01 +0200)]
conf: use virXMLPropString for actual network parsing

XPath is good for random search of elements, not for accessing
attributes of one node.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
7 years agoconf: use virXMLPropString for boot parsing
Pavel Hrdina [Wed, 16 Aug 2017 08:23:20 +0000 (10:23 +0200)]
conf: use virXMLPropString for boot parsing

XPath is good for random search of elements, not for accessing
attributes of one node.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
7 years agoconf: use virXMLPropString for network parsing
Pavel Hrdina [Wed, 16 Aug 2017 08:20:30 +0000 (10:20 +0200)]
conf: use virXMLPropString for network parsing

XPath is good for random search of elements, not for accessing
attributes of one node.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
7 years agoconf: use virXMLPropString for IOMMU def parsing
Pavel Hrdina [Tue, 15 Aug 2017 13:52:38 +0000 (15:52 +0200)]
conf: use virXMLPropString for IOMMU def parsing

XPath is good for random search of elements, not for accessing
attributes of one node.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
7 years agoconf: use virXMLPropString for virDomainVirtioOptionsParseXML
Pavel Hrdina [Tue, 15 Aug 2017 11:51:37 +0000 (13:51 +0200)]
conf: use virXMLPropString for virDomainVirtioOptionsParseXML

XPath is good for random search of elements, not for accessing
attributes of one node.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
7 years agoutil: introduce virXMLNodeContentString
Pavel Hrdina [Wed, 16 Aug 2017 08:26:09 +0000 (10:26 +0200)]
util: introduce virXMLNodeContentString

It's equivalent of calling virXPathString("string(.)", ctxt) but it
doesn't have to use the XPath resolving and parsing.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
7 years agoutil: introduce virXMLPropStringLimit
Pavel Hrdina [Tue, 15 Aug 2017 13:20:55 +0000 (15:20 +0200)]
util: introduce virXMLPropStringLimit

The virXMLPropStringLimit is an equivalent of virXPathStringLimit
which should be preferred if you already have a XML dom node or
if you need to parse more than one property.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
7 years agonetwork: Use self inflating bitmap for class IDs
Michal Privoznik [Wed, 16 Aug 2017 10:55:03 +0000 (12:55 +0200)]
network: Use self inflating bitmap for class IDs

Back in the day when I was implementing QoS for networks there
were no self inflating virBitmaps. Only the static ones.
Therefore, I had to allocate the whole 8KB of memory in order to
keep track of used/unused class IDs. This is rather wasteful
because nobody is ever gonna use that much classes (kernel
overhead would drastically lower the bandwidth). Anyway, now that
we have self inflating bitmaps we can start small and allocate
more if there's need for it.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>