Commit Graph

15817 Commits

Author SHA1 Message Date
Peter Krempa
356e28b35e util: buffer: Sanitize comment for virBufferAddBuffer
Idioms are usually weird and obscure when translated literally.
2016-01-25 17:53:08 +01:00
Peter Krempa
7141fc7a27 test: Touch up error message when attempting to pin invalid vCPU
Report
error: invalid argument: requested vcpu '100' is not present in the domain
instead of
error: invalid argument: requested vcpu is higher than allocated vcpus
2016-01-25 17:53:08 +01:00
Peter Krempa
51f07d8f0f (qemu|lxc)DomainGetCPUStats: Clean up
Remove unnecessary condition and variable.
2016-01-25 17:45:09 +01:00
Peter Krempa
68ee703bfe vz: Fix invalid iteration of def->cputune.vcpupin
The array doesn't necessarily have the same cardinality as the count of
vCPUs for a domain. Iterating it can cause access beyond the end of the
array.
2016-01-25 17:45:09 +01:00
Peter Krempa
b3c91b8a50 qemu: process: Disallow VMs with 0 vcpus
Counterintuitively the user would end up with a VM with maximum number
of vCPUs available.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1290324
2016-01-25 17:45:09 +01:00
Peter Krempa
adca15cf15 qemu: process: refactor and rename qemuValidateCpuMax to qemuValidateCpuCount
Next patch will add minimum checking, so use a more generic name.
Refactor return values to the commonly used semantics.
2016-01-25 17:45:09 +01:00
Michal Privoznik
35c3aab44d vmx: Adapt to emptyBackingString for cdrom-image
https://bugzilla.redhat.com/show_bug.cgi?id=1266088

We are missing this value for cdrom-image device. It seems like
there's no added value to extend this to other types of disk
devices [1].

1: https://www.redhat.com/archives/libvir-list/2016-January/msg01038.html

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2016-01-25 08:34:23 +01:00
Peter Krempa
4ac14cde9a qemu: snapshot: Correctly report qemu error on 'savevm'
Since 'savevm' was not converted to QMP libvirt has to parse for error
strings in the text monitor output. One of the unhandled errors is
produced when qemu treats a device as unmigratable.

As current qemu actually does support AHCI migration this bug is
applicable only to older versions of qemu.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1293899
2016-01-25 07:21:25 +01:00
Peter Krempa
0c1b0d83bb qemu: monitor: Refactor error handling for 'savevm'
Unify few error conditions into a single error reporting case.
2016-01-25 07:21:25 +01:00
Roman Bogorodskiy
ef01addb38 bhyve: bhyveload: respect boot dev and boot order
Make bhyveload respect boot order as specified by os.boot section of the
domain XML or by "boot order" for specific devices. As bhyve does not
support a real boot order specification right now, it's just about
choosing a single device to boot from.
2016-01-25 04:19:33 +03:00
Roman Bogorodskiy
318ae9f3be conf: expose virDomainBootType(From|To)String
These functions are going to be used by the Bhyve driver.
2016-01-25 03:54:07 +03:00
Laine Stump
29cc45cb79 util: reset MAC address of macvtap passthrough physdev after disassociate
libvirt always resets the MAC address of the physdev used for macvtap
passthrough when the guest is finished with it. This was happening
prior to the 802.1Qb[gh] DISASSOCIATE command, and was quite often
failing, presumably because the driver wouldn't allow the MAC address
to be reset while the association was still active, with a log message
like this:

virNetDevSetMAC:168 : Cannot set interface MAC to 00:00:00:00:00:00 on 'eth13': Cannot assign requested address

This patch changes the order - we now do the 802.1Qb[gh] disassociate
and delete the macvtap interface first, then and reset the MAC
address.
2016-01-22 13:16:24 -05:00
Cole Robinson
81da8bc73b lxc: fuse: Stub out Slab bits in /proc/meminfo
'free' on fedora23 wants to use the Slab field for calculated used
memory. The equation is:

used = MemTotal - MemFree - (Cached + Slab) - Buffers

We already set Cached and Buffers to 0, do the same for Slab and its
related values

https://bugzilla.redhat.com/show_bug.cgi?id=1300781
2016-01-22 08:32:00 -05:00
Cole Robinson
c7be484d11 lxc: fuse: Fill in MemAvailable for /proc/meminfo
'free' on Fedora 23 will use MemAvailable to calculate its 'available'
field, but we are passing through the host's value. Set it to match
MemFree, which is what 'free' will do for older linux that don't have
MemAvailable

https://bugzilla.redhat.com/show_bug.cgi?id=1300781
2016-01-22 08:32:00 -05:00
Cole Robinson
8418245a7e lxc: fuse: Fix /proc/meminfo size calculation
We virtualize bits of /proc/meminfo by replacing host values with
values specific to the container.

However for calculating the final size of the returned data, we are
using the size of the original file and not the altered copy, which
could give garbelled output.
2016-01-22 08:32:00 -05:00
Cole Robinson
f65dcfcd14 lxc: fuse: Unindent meminfo logic
Reverse the conditional at the start so we aren't stuffing all the logic
in an 'if' block
2016-01-22 08:32:00 -05:00
Ian Campbell
daeace5c5d libxl: Support cmdline= in xl config files
... and consolidate the cmdline/extra/root parsing to facilitate doing
so.

The logic is the same as xl's parse_cmdline from the current xen.git master
branch (e6f0e099d2c17de47fd86e817b1998db903cab61).

On the formatting side switch to producing cmdline= instead of extra=.

Update a few tests and add serveral more.
  - test-cmdline is added to test the exclusive use of cmdline.
  - test-fullvirt-direct-kernel-boot.cfg is updated due to the switch
    on the formatting side and now tests the exclusive use of cmdline=.
  - Tests are added for both paravirt and fullvirt where the .cfg uses
    extra= and (paravirt only) root=. These are format (xl->xml) only
    since the inverse will generate cmdline= hence is not a round trip
    (which was already true if using root=, which used to generate
    extra= on the way back).
  - Tests are added for both paravirt and fullvirt where the .cfg
    declares cmdline= as well as bogus extra= and (paravirt only) root=
    entries which should be ignored. Again these are format only tests
    since the inverse won't include the bogus lines.

The last two bullets here required splitting the DO_TEST macro into
two halves, as is done in the xmconfigtest.c case.

In order to introduce a use of VIR_WARN for logging I had to add
virerror.h and VIR_LOG_INIT.

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
2016-01-21 10:48:44 -07:00
Joao Martins
d18d6a85f9 libxl: dispose libxl_dominfo after libxl_domain_info()
As suggested in a previous thread [0] this patch adds some missing calls
to libxl_dominfo_{init,dispose} when doing some of the libxl_domain_info
operations which would otherwise lead to memory leaks.

[0]
https://www.redhat.com/archives/libvir-list/2015-September/msg00519.html

Signed-off-by: Joao Martins <joao.m.martins@oracle.com>
2016-01-21 09:49:57 -07:00
Jim Fehlig
8c3c32f16a Xen: add XENXL to virErrorDomain enum
Add "Xen XL Config" to the virErrorDomain enum and use it in
src/xenconfig/xen_xl.c.
2016-01-21 09:31:39 -07:00
Jim Fehlig
7d3698b47c Xen: VIR_FROM_THIS cleanup
The virErrorDomain enum has VIR_FROM_XEN, VIR_FROM_XEND,
VIR_FROM_XENSTORE, VIR_FROM_SEXPR, and VIR_FROM_XENXM. Use
these elements in the corresponding .c files. While at it,
remove the VIR_FROM_THIS define in src/xenconfig/xenxs_private.h.
2016-01-21 09:31:39 -07:00
Jiri Denemark
56635345ad qemu: Add support for migration iteration event
The corresponding event in QEMU is called MIGRATION_PASS.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-01-21 16:36:08 +01:00
Jiri Denemark
0b50f4a025 Introduce migration iteration event
The VIR_DOMAIN_EVENT_ID_MIGRATION_ITERATION event will be triggered
whenever VIR_DOMAIN_JOB_MEMORY_ITERATION changes its value, i.e.,
whenever a new iteration over guest memory pages is started during
migration.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-01-21 16:36:08 +01:00
Dmitry Andreev
e2b86f580c qemuDomainReboot: use fakeReboot=true only for acpi mode
When acpi is used to reboot/shutdown qemu domain, qemu emits
SHUTDOWN event. Libvirt uses fakeReboot variable in order to
differentiate reboot or shutdown. fakeReboot value is reseted
to false after domain restart/reset.

When mode=agent is used to reboot qemu domain, qemu doesn't emit
SHUTDOWN event and libvirt doesn't reset fakeReboot value to false.
In this case next 'shutdown -h now' performs reboot. That's why
we don't need to set fakeReboot=true for mode=agent.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-01-21 15:03:56 +01:00
Cole Robinson
a1edb05c60 build: predictably generate systemtap tapsets (bz 1173641)
The generated output is dependent on perl hashtable ordering, which
gives different results for i686 and x86_64. Fix this by sorting
the hash keys before iterating over them

https://bugzilla.redhat.com/show_bug.cgi?id=1173641
2016-01-20 10:26:02 -05:00
Ján Tomko
ce9085eba1 leaseshelper: reduce indentation level in virLeaseReadCustomLeaseFile
Instead of nested ifs, jump out early.

Mostly whitespace changes.
2016-01-20 10:01:52 +01:00
Ján Tomko
d7049a67b6 leaseshelper: remove useless comparison
We do not care if the mac was specified in the delete section,
we are going to delete the record anyway.
2016-01-20 09:35:50 +01:00
Ján Tomko
99569948d3 leaseshelper: move comment about adding IPv6 leases
The comment is relevant to the ADD action, not DEL.
2016-01-20 09:34:47 +01:00
Ján Tomko
21fb379549 leaseshelper: split out virLeasePrintLeases
Introduce a function for printing the leases on the 'init' operation.
2016-01-20 09:33:44 +01:00
Ján Tomko
7f9c425bfb leaseshelper: split out custom leases file read
Introduce virLeaseReadCustomLeaseFile which will populate
the new leases array with all the leases, except for expired
ones and the ones matching 'ip_to_delete'.

This removes five variables from main().
2016-01-20 09:33:44 +01:00
Ján Tomko
9e7e7662bf leaseshelper: store server_duid as an allocated string
We either use the value from the environment variable, or learn it from
the existing lease file.

In the second case, the pointer would be pointing into the JSON object
of the first lease with a DUID, owned by leases_array, then
leases_array_new.

Always allocate the string instead, making obvious who should free the
string.
2016-01-20 09:33:44 +01:00
Ján Tomko
df9fe124d6 leaseshelper: fix crash when no mac is specified
If dnsmasq specified DNSMASQ_IAID (so we're dealing with an IPv6
lease) but no DNSMASQ_MAC, we skip creation of the new lease object.

Also skip adding it to the leases array.

https://bugzilla.redhat.com/show_bug.cgi?id=1202350
2016-01-20 09:32:59 +01:00
John Ferlan
020135dc85 storage: Add new flag for libvirt_parthelper
https://bugzilla.redhat.com/show_bug.cgi?id=1265694

In order to be able to process disk storage pool's using a multipath
device to handle the partitions, libvirt_parthelper will need a way to
not automatically add a partition separator "p" to the generated device
name for each partition found. This is designed to mimic the multipath
features known as 'user_friendly_names' and custom 'alias' name.

If the part_separator attribute is set to "no", then generation of the
multipath partition name will not include the "p" partition separator
unless the source device path name ends with a number. The generated
partition names that get passed back to libvirt are processed in order
to find the device mapper multipath (dm-#) path device.

For example, device path "/dev/mapper/mpatha" would create partitions
"/dev/mapper/mpatha1", "/dev/mapper/mpatha2", etc. instead of
"/dev/mapper/mpathap1", "/dev/mapper/mpathap2", etc. If the device
path ends with a number "/dev/mapper/mpatha1", then the algorithm
to generate names "/dev/mapper/mpatha1p1", "/dev/mapper/mpatha1p2", etc.
would be utilized.

Signed-off-by: John Ferlan <jferlan@redhat.com>
2016-01-19 13:02:59 -05:00
John Ferlan
4f84617078 conf: Add storage pool device attribute part_separator
Add a new storage pool source device attribute 'part_separator=[yes|no]'
in order to allow a 'disk' storage pool using a device mapper multipath
device to not add the "p" partition separator to the generated device
name when libvirt_parthelper is run.

This will allow libvirt to find device mapper multipath devices which were
configured in /etc/multipath.conf to use 'user_friendly_names' or custom
'alias' names for the LUN.
2016-01-19 13:02:59 -05:00
Michal Privoznik
c03fbecc7c virLogManagerDomainReadLogFile: Don't do dummy allocs
Since we pass dummy variables @fdout and @fdoutlen into
virNetClientProgramCall() we make it alloc @fdout array (even
though it's an array of 0 elements since vitlogd can hardly pass
us some FDs at this stage). Nevertheless, it's an allocation not
followed by free():

==29385== 0 bytes in 60 blocks are definitely lost in loss record 2 of 1,009
==29385==    at 0x4C2C070: calloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==29385==    by 0x54B99EF: virAllocN (viralloc.c:191)
==29385==    by 0x56821B1: virNetClientProgramCall (virnetclientprogram.c:359)
==29385==    by 0x563B304: virLogManagerDomainReadLogFile (log_manager.c:272)
==29385==    by 0x217CD613: qemuDomainLogContextRead (qemu_domain.c:2485)
==29385==    by 0x217EDC76: qemuProcessReadLog (qemu_process.c:1660)
==29385==    by 0x217EDE1D: qemuProcessReportLogError (qemu_process.c:1696)
==29385==    by 0x217EE8C1: qemuProcessWaitForMonitor (qemu_process.c:1957)
==29385==    by 0x217F6636: qemuProcessLaunch (qemu_process.c:4955)
==29385==    by 0x217F71A4: qemuProcessStart (qemu_process.c:5152)
==29385==    by 0x21846582: qemuDomainObjStart (qemu_driver.c:7396)
==29385==    by 0x218467DE: qemuDomainCreateWithFlags (qemu_driver.c:7450)

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2016-01-18 17:14:16 +01:00
Michal Privoznik
105b51f42e qemuProcessReadLog: Fix memmove arguments
So I can observe this crasher that with freshly started daemon
(and virtlogd enabled) I am trying to startup a domain that
immediately dies (because it's said to use huge pages but I
haven't allocated a single one in the pool). Hardly reproducible
with -O0 or under valgrind. But I just got lucky:

==20469== Invalid write of size 8
==20469==    at 0x4C2E99B: memcpy@GLIBC_2.2.5 (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==20469==    by 0x217EDD07: qemuProcessReadLog (qemu_process.c:1670)
==20469==    by 0x217EDE1D: qemuProcessReportLogError (qemu_process.c:1696)
==20469==    by 0x217EE8C1: qemuProcessWaitForMonitor (qemu_process.c:1957)
==20469==    by 0x217F6636: qemuProcessLaunch (qemu_process.c:4955)
==20469==    by 0x217F71A4: qemuProcessStart (qemu_process.c:5152)
==20469==    by 0x21846582: qemuDomainObjStart (qemu_driver.c:7396)
==20469==    by 0x218467DE: qemuDomainCreateWithFlags (qemu_driver.c:7450)
==20469==    by 0x21846845: qemuDomainCreate (qemu_driver.c:7468)
==20469==    by 0x5611CD0: virDomainCreate (libvirt-domain.c:6753)
==20469==    by 0x125D9A: remoteDispatchDomainCreate (remote_dispatch.h:3613)
==20469==    by 0x125CB7: remoteDispatchDomainCreateHelper (remote_dispatch.h:3589)
==20469==  Address 0x27a52ad0 is 0 bytes after a block of size 5,584 alloc'd
==20469==    at 0x4C29F80: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==20469==    by 0x9B8D1DB: xdr_string (in /lib64/libc-2.21.so)
==20469==    by 0x563B39C: xdr_virLogManagerProtocolNonNullString (log_protocol.c:24)
==20469==    by 0x563B6B7: xdr_virLogManagerProtocolDomainReadLogFileRet (log_protocol.c:123)
==20469==    by 0x164B34: virNetMessageDecodePayload (virnetmessage.c:407)
==20469==    by 0x5682360: virNetClientProgramCall (virnetclientprogram.c:379)
==20469==    by 0x563B30E: virLogManagerDomainReadLogFile (log_manager.c:272)
==20469==    by 0x217CD613: qemuDomainLogContextRead (qemu_domain.c:2485)
==20469==    by 0x217EDC76: qemuProcessReadLog (qemu_process.c:1660)
==20469==    by 0x217EDE1D: qemuProcessReportLogError (qemu_process.c:1696)
==20469==    by 0x217EE8C1: qemuProcessWaitForMonitor (qemu_process.c:1957)
==20469==    by 0x217F6636: qemuProcessLaunch (qemu_process.c:4955)

This points to memmove() in qemuProcessReadLog(). Imagine we just
read the following string from qemu:

"abc\n2016-01-18T09:40:44.022744Z qemu-system-x86_64: Error\n"

After the first pass of the while() loop in the
qemuProcessReadLog() (in which we have taken the false branch in
the if) @buf still points to the beginning of the string,
@filter_next points to the beginning of the second line.  So we
start second iteration because there is yet another newline
character at the end. In this iteration @eol points to it
actually. Now, the control gets inside true branch of if(). Just
to remind you:

got = 58
filter_next = buf + 5,
eol = buf + 58.

Therefore skip = 54 which is correct. The message we want to skip
is 54 bytes long. However:

memmove(filter_next, eol + 1, (got - skip) +1);

which is

memmove(filter_next, eol + 1, 5)

is obviously wrong as there is only one byte we can access, not 5!

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2016-01-18 17:14:16 +01:00
Martin Kletzander
4b47f9b82c Fix make check with gcc version 5
When building with gcc-5 (particularly gcc-5.3.0 now) and having pdwtags
installed (package dwarves) make check fails with the following error:

  $ make lock_protocol-struct
  GEN      lock_protocol-struct
  --- lock_protocol-structs	2016-01-13 15:04:59.318809607 +0100
  +++ lock_protocol-struct-t3	2016-01-13 15:05:17.703501234 +0100
  @@ -26,10 +26,6 @@
           virLockSpaceProtocolNonNullString name;
           u_int                      flags;
   };
  -enum virLockSpaceProtocolAcquireResourceFlags {
  -        VIR_LOCK_SPACE_PROTOCOL_ACQUIRE_RESOURCE_SHARED = 1,
  -        VIR_LOCK_SPACE_PROTOCOL_ACQUIRE_RESOURCE_AUTOCREATE = 2,
  -};
   struct virLockSpaceProtocolAcquireResourceArgs {
           virLockSpaceProtocolNonNullString path;
           virLockSpaceProtocolNonNullString name;
  Makefile:10415: recipe for target 'lock_protocol-struct' failed
  make: *** [lock_protocol-struct] Error 1

That happens because without any specific options gcc doesn't keep enum
information in the resulting binary object.  I managed to isolate the
parameters of gcc that caused this issue to disappear, however I
remember that they influenced the resulting binaries quite a bit and
were definitely not something we would want to add as mandatory to the
build process.

So to deal with this cleanly, let's take that enum and separate it out
to its own header file.  Since it is only used in the lockd driver and
the protocol, lock_driver_lockd.h feels like a suitable name.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2016-01-18 15:19:21 +01:00
Wido den Hollander
a5a383adc1 rbd: Set r variable so it can be returned should an error occur
This was reported in bug #1298024 where r would be filled with the
return code of rbd_open().

Should rbd_snap_unprotect() fail for any reason the virReportSystemError
call would return 'Success' since rbd_open() succeeded.

https://bugzilla.redhat.com/show_bug.cgi?id=1298024
Signed-off-by: Wido den Hollander <wido@widodh.nl>
2016-01-18 14:06:24 +01:00
Jiri Denemark
8f0a15727f security: Do not restore labels on device tree binary
A device tree binary file specified by /domain/os/dtb element is a
read-only resource similar to kernel and initrd files. We shouldn't
restore its label when destroying a domain to avoid breaking other
domains configure with the same device tree.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-01-15 16:34:37 +01:00
Jiri Denemark
68acc701bd security: Do not restore kernel and initrd labels
Kernel/initrd files are essentially read-only shareable images and thus
should be handled in the same way. We already use the appropriate label
for kernel/initrd files when starting a domain, but when a domain gets
destroyed we would remove the labels which would make other running
domains using the same files very unhappy.

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

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-01-15 10:55:58 +01:00
Yaniv Kaul
c1e0df918b qemu: Print better warning in qemuAgentNotifyEvent
We have this function qemuAgentNotifyEvent() which is supposed to
be called from thread pool responsible for processing qemu
monitor events. The function then should wake up other thread
that is waiting for a guest to shutdown or reboot. However, if we
have received a different error a warning is printed out. This
warning lacks info on which event is expected.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2016-01-15 08:33:49 +01:00
John Ferlan
d6d7e2885b cgroup: Fix possible bug as a result of code motion for vcpu cgroup setup
Commit id '90b721e43' moved where the virCgroupAddTask was made until
after the check for the vcpupin checks. However, in doing so it missed
an option where if the cpumap didn't exist, then the code would continue
back to the top of the current vcpu loop. The results was that the
virCgroupAddTask wouldn't be called.

Signed-off-by: John Ferlan <jferlan@redhat.com>
2016-01-14 11:02:53 -05:00
John Ferlan
344d480611 Revert "lxc_cgroup: Add check for NULL cgroup before AddTask call"
This reverts commit ae09988eb7.

Since commit id '71ce4759' has been reverted, this one is no
longer necessary.
2016-01-14 11:01:50 -05:00
John Ferlan
d41bd09596 Revert "util: cgroups do not implicitly add task to new machine cgroup"
This reverts commit 71ce475967.

Since commit id 'a41c00b47' has been reverted, this no longer is
necessary
2016-01-14 11:00:25 -05:00
John Ferlan
f8f6907284 Revert "qemu: do not put a task into machine cgroup"
This reverts commit a41c00b472.

After much testing and upstream discussion this has been deemed to be
the incorrect operation since it means we no longer have any guarantee
about which resource controllers the QEMU processes in general are in.
2016-01-14 10:56:53 -05:00
Cédric Bosdonnat
c726af2d5a virt-aa-helper: don't deny writes to readonly mounts
There is no need to deny writes on a readonly mount: write still
won't be accepted, even if the user remounts the folder as RW in
the guest as qemu sets the 9p mount as ro.

This deny rule was leading to problems for example with readonly /:
The qemu process had to write to a bunch of files in / like logs,
sockets, etc. This deny rule was also preventing auditing of these
denials, making it harder to debug.
2016-01-14 15:42:05 +01:00
John Ferlan
3e2d637458 conf: Initialize 'deflate' for balloon parse XML
Commit id '7bf3198df' neglected to initialize deflate leading to a
possibility if model allocation/checks fail, then the VIR_FREE(deflate)
would be erroneous. Noted by Jan Tomko.
2016-01-14 05:54:58 -05:00
Michal Privoznik
e988ba94aa qemuProcessCleanupChardevDevice: Don't unlink NULL paths
So, you try to start a domain, but before we even get to the part
where chardev part of qemu command line is generated (and
possibly missing path to unix sockets is made up) an error occurs
which results in calling qemuProcessStop. This will then try to
clean up the mess and possibly ends up calling unlink(NULL).

==8085== Thread 3:
==8085== Syscall param unlink(pathname) points to unaddressable byte(s)
==8085==    at 0xA85EA57: unlink (in /lib64/libc-2.21.so)
==8085==    by 0x213D3C24: qemuProcessCleanupChardevDevice (qemu_process.c:2866)
==8085==    by 0x558D6B1: virDomainChrDefForeach (domain_conf.c:22924)
==8085==    by 0x213DA9AE: qemuProcessStop (qemu_process.c:5326)
==8085==    by 0x213DA2F2: qemuProcessStart (qemu_process.c:5190)
==8085==    by 0x2142957F: qemuDomainObjStart (qemu_driver.c:7396)
==8085==    by 0x214297DB: qemuDomainCreateWithFlags (qemu_driver.c:7450)
==8085==    by 0x21429842: qemuDomainCreate (qemu_driver.c:7468)
==8085==    by 0x5611B95: virDomainCreate (libvirt-domain.c:6753)
==8085==    by 0x125D9A: remoteDispatchDomainCreate (remote_dispatch.h:3613)
==8085==    by 0x125CB7: remoteDispatchDomainCreateHelper (remote_dispatch.h:3589)
==8085==    by 0x568BF41: virNetServerProgramDispatchCall (virnetserverprogram.c:437)
==8085==  Address 0x0 is not stack'd, malloc'd or (recently) free'd
==8085==

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2016-01-13 11:30:38 +01:00
Jim Fehlig
71daae9671 xenconfig: check return value of regcomp
Commit ec63000a missed checking the return value of regcomp(),
which coverity promptly identified.
2016-01-12 14:22:54 -07:00
Jim Fehlig
6564de5e95 Xen: use correct domctl version in domaininfolist union
Commmit fd2e3c4c used the domctl version 8 structure for version 9
in the xen_getdomaininfolist union, resulting in insufficient buffer
size (and subsequent memory corruption) for the GETDOMAININFOLIST
ioctl.

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
2016-01-12 10:37:56 -07:00
Dmitry Andreev
981c01d419 qemu: add support of optional 'autodeflate' attribute
Autodeflate can be enabled/disabled for memballon device
of model 'virtio'.

xml:
<devices>
  <memballoon model='virtio' autodeflate='on'/>
</devices>

qemu:
qemu -device virtio-balloon-pci,...,deflate-on-oom=on

Autodeflate cannot be enabled/disabled for running domain.
2016-01-12 10:48:21 -05:00
Dmitry Andreev
3522a311ea qemu: add capability check for memballoon 'deflate-on-oom' feature
Add appropriate capability check and new virQEMUCaps flag for the new
virtio balloon feature. QEMU commit with the complete feature description:
http://git.qemu.org/?p=qemu.git;a=commit;h=e3816255bf4b6377bb405331e2ee0dc14d841b80
2016-01-12 10:48:21 -05:00
Dmitry Andreev
7bf3198df6 conf: introduce 'autodeflate' attribute for memballoon device
Excessive memory balloon inflation can cause invocation of OOM-killer,
when Linux is under severe memory pressure. QEMU memballoon device
has a feature to release some memory at the last moment before some
process will be get killed by OOM-killer.

Introduce a new optional balloon device attribute 'autodeflate' to
enable or disable this feature.
2016-01-12 10:48:21 -05:00
Cole Robinson
2eb7a97575 rpc: socket: Don't repeatedly attempt to launch daemon
On every socket connect(2) attempt we were re-launching session
libvirtd, up to 100 times in 5 seconds.

This understandably caused some weird load races and intermittent
qemu:///session startup failures

https://bugzilla.redhat.com/show_bug.cgi?id=1271183
2016-01-12 10:45:45 -05:00
Cole Robinson
8da02d5280 rpc: socket: Explicitly error if we exceed retry count
When we autolaunch libvirtd for session URIs, we spin in a retry
loop waiting for the daemon to start and the connect(2) to succeed.

However if we exceed the retry count, we don't explicitly raise an
error, which can yield a slew of different error messages elsewhere
in the code.

Explicitly raise the last connect(2) failure if we run out of retries.
2016-01-12 10:45:45 -05:00
Cole Robinson
f102c7146e rpc: socket: Minor cleanups
- Add some debugging
- Make the loop dependent only on retries
- Make it explicit that connect(2) success exits the loop
- Invert the error checking logic
2016-01-12 10:45:45 -05:00
Roman Bogorodskiy
bc451c4980 Add missing virxdrdefs.h include to log_protocol
Commit 2b6f6ad introduced the virxdrdefs.h header with
common definitions to be included in the protocol files,
but logging/log_protocol.x was missed, so add it there as well.

Hopefully this fixes build on OS X.
2016-01-12 18:15:09 +03:00
Ben Gray
133c511b52 rpc: Don't rewrite msg->fds on every read dispatch
When we are receiving data in smaller chunks it might happen that
virNetServerClientDispatchRead() will be called multiple times.  And as
that happens, if it is a message that also transfer headers, we decode
the number of them every single time and, unfortunately, also allocate
the memory for them.  That causes a leak, in the best scenario.

Best viewed with '-w'.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2016-01-12 08:56:50 +01:00
Laine Stump
21e63916dc util: eliminate bogus error log in virNetDevVPortProfileGetStatus
if instanceId is NULL

When virNetDevVPortProfileGetStatus() was called with instanceId =
NULL (which is the case for all DISASSOCIATE requests in 802.1Qbh) it
would log the following error:

   Could not find netlink response with expected parameters

even though the disassociate had been successfully completely. Then,
due to the fortunate coincidence of status having been initialized to
0 and then not changed when the "failure" was encountered, it would
still return a status of 0 (PORT_VDP_RESPONSE_SUCCESS), so the caller
would assume a successful operation.

This would result in a spurious log message though, and would fill in
LastErrorMessage, so that the API would return that error if it
happened during cleanup from some other error. That, in turn, would
lead to an incorrect supposition that the response to the port profile
disassociate was the cause of the failure.

During debugging, I noticed that the VF in question usually had *no
uuid* associated with it (big surprise)by the time the disassociate
completed, so the solution is *not* to send the previous instanceId
down.

This patch fixes virNetDevVPortProfileGetStatus() to only check the
VF's uuid in the status if it was given an instanceId to check against
when originally called. Otherwise it only checks that the particular
VF is present (it will be).

This does cause a slight difference in behavior - rather than
returning with status unchanged (and thus always 0) it will actually
get the IFLA_PORT_RESPONSE. This could lead to revelation of error
conditions we were previously ignoring. Or not. So far "not".
2016-01-11 17:09:28 -05:00
Laine Stump
47b830370a qemu: use enum when setting PCI "multi" value, not 0 or 1
Use the VIR_TRISTATE_SWITCH_* enums appropriately.

No functional change.
2016-01-11 15:13:54 -05:00
Laine Stump
bd04ad42e7 qemu: auto-add a USB2 controller set for Q35 machines
Use virDomainDefAddUSBController() to add an EHCI1+UHCI1+UHCI2+UHCI3
controller set to newly defined Q35 domains that don't have any USB
controllers defined.
2016-01-11 13:21:10 -05:00
Laine Stump
8ebca27bb7 qemu: define virDomainDevAddUSBController()
This new function will add a single controller of the given model,
except the case of ich9-usb-ehci1 (the master controller for a USB2
controller set) in which case a set of related controllers will be
added (EHCI1, UHCI1, UHCI2, UHCI3). These controllers will not be
given PCI addresses, but should be otherwise ready to use.

"-1" is allowed for controller model, and means "default for this
machinetype". This matches the existing practice in
qemuDomainDefPostParse(), which always adds the default controller
with model = -1, and relies on the commandline builder to set a model
(that is wrong, but will be fixed later).
2016-01-11 13:16:51 -05:00
Laine Stump
ed64d92bea conf: add virDomainDefAddController()
We need a virDomainDefAddController() that doesn't check for an
existing controller at the same index (since USB2 controllers must be
added in sets of 4 that are all at the same index), so rather than
duplicating the code in virDomainDefMaybeAddController(), split it
into two functions, in the process eliminating existing duplicated
code that loops through the controller list by calling
virDomainControllerFind(), which does the same thing).
2016-01-11 13:08:26 -05:00
Laine Stump
163338ec28 qemu: prefer 00:1D.x and 00:1A.x for USB2 controllers on Q35
The real Q35 machine puts the first USB controller set (EHCI+(UHCIx4))
on bus 0 slot 0x1D, and the 2nd USB controller set on bus 0 slot 0x1A,
so let's attempt to make the virtual machine match that for
controllers with auto-assigned addresses when possible.

Three test cases were added to assure that the proper addresses are
assigned - one with a single set of unaddressed USB controllers, one
with 3 (to grab both preferred slots plus one more), and one with the
order of the controller definitions reordered, to assure that the
auto-assignment isn't mixed up by order.
2016-01-11 13:04:17 -05:00
Laine Stump
7dbb5fce06 qemu: don't assume slot 0 is unused/reserved.
When qemuAssignDevicePCISlots() is looking for companion controllers
for a USB controller that has no PCI address specified, it initializes
a virDevicePCIAddress to 0000:00:00.0, fills it in with the
companion's address if one is found, then checks whether or not there
was a find based on slot == 0. On a system with a single PCI bus, that
is a valid way to check, because slot 0 is reserved, but on most other
PCI buses, slot 0 is not reserved, and is open for use by any
device. This patch adds a separate bool that is set when a companion
is found rather than relying on the faulty information provided with
"slot == 0".
2016-01-11 12:58:40 -05:00
Jasper Lievisse Adriaanse
2b6f6ad64b Unify int types handling in protocol files
Some of the protocol files already include handing of the missing int
types such as xdr_uint64_t, some don't. To fix it everywhere, move out
of the appropriate defines to the utils/virxdrdefs.h file and include
it where needed.

Signed-off-by: Roman Bogorodskiy <bogorodskiy@gmail.com>
2016-01-11 19:56:06 +03:00
Jasper Lievisse Adriaanse
91b423beb7 Use struct sockpeercred when available
OpenBSD uses 'struct sockpeercred' instead of 'struct ucred'. Add a
configure check that detects its presence and use if in the code that
could be compiled on OpenBSD.

Signed-off-by: Roman Bogorodskiy <bogorodskiy@gmail.com>
2016-01-11 19:56:06 +03:00
Jasper Lievisse Adriaanse
1b60f1b401 cgroup: don't include sys/mount.h if not needed
As cgroup implementation only works on Linux, it does not
make much sense to include sys/mount.h if other requirements are
not met, such as HAVE_MNTENT_H and HAVE_GETMNTENT_R.

Also, it fixes build on OpenBSD that requires to include sys/param.h
along with sys/mount.h.

Signed-off-by: Roman Bogorodskiy <bogorodskiy@gmail.com>
2016-01-11 19:56:06 +03:00
Michal Privoznik
0a84286d8f qemu: Introduce QEMU_CAPS_VSERPORT_CHANGE
This capability tells if qemu is capable of vserport_change
events.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2016-01-11 17:17:52 +01:00
Michal Privoznik
d5762cc034 qemu: change qemuFindAgentConfig return type
While this is no functional change, whole channel definition is
going to be needed very soon. Moreover, while touching this obey
const correctness rule in qemuAgentOpen() - so far it was passed
regular pointer to channel config even though the function is
expected to not change pointee at all. Pass const pointer
instead.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2016-01-11 17:17:52 +01:00
Michal Privoznik
2f50445537 qemu: Set virtio channel state sooner
In qemu driver we listen to virtio channel events like an agent
connected to or disconnected from the guest part of socket.
However, with a little exception - when we find out that the
socket in question is the guest agent one, we connect or
disconnect guest agent which is done prior setting new state in
internal structure. Due to a bug in our code it may happen that
we got the event but failed to set it in internal structure
representing the channel.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2016-01-11 17:16:29 +01:00
Martin Kletzander
6dc0e4f171 Fix LSB requirements in service script and sync them
Commit b22344f328 mistakenly reordered
Default-* lines.  Thanks to that I noticed that we are very inconsistent
with our init scripts, so I took the liberty of synchronizing them,
updating them and making them all look shiny and new.  So apart from
fixing the LSB requirements, I also fixed the ordering, specified
runlevels and fix the link to the reference specification.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2016-01-11 15:49:13 +01:00
Michal Privoznik
506e9d6c2d virDomainGetTime: Deny on RO connections
We have a policy that if API may end up talking to a guest agent
it should require RW connection. We don't obey the rule in
virDomainGetTime().

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2016-01-11 13:36:19 +01:00
Michal Privoznik
95c370f0ee virDomainInterfaceAddresses: Allow API on RO connection too
This API does not change domain state. However, we have a policy
that an API talking to a guest agent requires RW access. But that
happens only if source == VIR_DOMAIN_INTERFACE_ADDRESSES_SRC_AGENT.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2016-01-11 13:36:19 +01:00
Martin Kletzander
8223bd22ed Don't clear libvirt-internal paths when parsing status XML
Earlier commit 7140807917 forgot to deal
properly with status XMLs where we want the libvirt-internal paths to be
kept in place and not cleared, otherwise we could end up copying a NULL
string and segfaulting th daemon.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2016-01-11 10:54:50 +01:00
Martin Kletzander
93103da84b Provide parse flags to PostParse functions
This way both Domain and Device PostParse functions can act based on the
flags.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2016-01-11 10:54:50 +01:00
Cole Robinson
fde937bda0 qemu: command: wire up usage of q35/ich9 disable s3/s4
If the q35 specific disable s3/s4 setting isn't supported, fallback to
specifying the PIIX setting, which is the previous behavior. It doesn't
have any effect, but qemu will just warn about it rather than error:

  qemu-system-x86_64: Warning: global PIIX4_PM.disable_s3=1 not used
  qemu-system-x86_64: Warning: global PIIX4_PM.disable_s4=1 not used

Since it doesn't error, I don't think we should either, since there
may be configs in the wild that already have q35 + disable_s3/4 (via
virt-manager)
2016-01-10 15:16:38 -05:00
Cole Robinson
c77fd89000 qemu: caps: check for q35/ICH9 disable S3/S4
Update test data to match
2016-01-10 14:59:53 -05:00
Cole Robinson
5900356efb qemu: caps: Rename CAPS_DISABLE_S[34] to CAPS_PIIX_DISABLE_S[34]
These settings are specific to PIIX, so clarify it
2016-01-10 14:59:53 -05:00
Cole Robinson
ab963449dc qemu: capabilities: s/Pixx/Piix/g
The chipset is called PIIX; the functions are misnamed
2016-01-10 14:59:53 -05:00
Michal Privoznik
b7fac9f77f virDomainMigrateUnmanagedParams: Don't blindly dereference @dconnuri
This function may be called with @dconnuri == NULL, e.g. from
virDomainMigrateToURI3() if the flags are missing
VIR_MIGRATE_PEER2PEER flag. Moreover, all later functions called
from here do wrap it into NULLSTR() so why not do the same here?

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2016-01-09 18:44:44 +01:00
Martin Kletzander
8156493d8d Fix USB model defaults for ppc64
The condition was checking for UHCI (and OHCI for ppc64) availability so
that it can specify the proper device instead of legacy usb.  However,
for ppc64, we don't need to check both OHCI and UHCI, but only OHCI as
that is the legacy default.  The condition is so big that it was just a
matter of time when someone will make a mistake there, so let's use more
lines so that it is visible what the condition checks for.

This fixes usage of -device instead of -usb for ppc64 that supports
pci-usb-ohci and does not support piix3-usb-uhci.

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

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2016-01-09 18:39:17 +01:00
Jim Fehlig
f988ecfb34 libxl: support vif outgoing bandwidth QoS
The libxl_device_nic structure supports specifying an outgoing rate
limit based on a time interval and bytes allowed per interval. In xl
config a rate limit is specified as "<RATE>/s@<INTERVAL>". INTERVAL
is optional and defaults to 50ms.

libvirt expresses outgoing limits by average (required), peak, burst,
and floor attributes in units of KB/s. This patch supports the outgoing
bandwidth limit by converting the average KB/s to bytes per interval
based on the same default interval (50ms) used by xl.

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
2016-01-08 18:56:00 -07:00
Jim Fehlig
ec63000a62 xenconfig: support vif bandwidth in xm and xl parser and formatter
Both xm and xl config have long supported specifying vif rate
limiting, e.g.

vif = [ 'mac=00:16:3E:74:3d:76,bridge=br0,rate=10MB/s' ]

Add support for mapping rate to and from <bandwidth> in the xenconfig
parser and formatter. rate is mapped to the required 'average' attribute
of the <outbound> element, e.g.

  <interface type='bridge'>
    ...
    <bandwidth>
      <outbound average='10240'/>
    </bandwidth>
  </interface>

Also add a unit test to check the conversion logic.

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
2016-01-08 18:56:00 -07:00
Jim Fehlig
1dd34bbb4b xenconfig: support vif bandwidth in sexpr parser and formatter
The xen sexpr config format has long supported specifying vif rate
limiting, e.g.

  (device
    (vif
      (mac '00:16:3e:1b:b1:47')
      (rate '10240KB/s')
      ...
    )
  )

Add support for mapping rate to and from <bandwidth> in the xenconfig
sexpr parser and formatter. rate is mapped to the required 'average'
attribute of the <outbound> element, e.g.

  <interface type='bridge'>
    ...
    <bandwidth>
      <outbound average='10240'/>
    </bandwidth>
  </interface>

Also add unit tests to check the conversion logic.

This patch benefits both the old xen driver and the libxl driver.
Both drivers gain support for vif bandwidth when converting to/from
domXML and xen-sxpr. In addition, the old xen driver will now be
able to handle vif 'rate' setting when communicating with xend.
2016-01-08 18:56:00 -07:00
Cole Robinson
3d92a000ff qemu: Fix crash when defining XML with bogus emulator
We weren't checking for failure of qemuCaps lookup
2016-01-08 20:05:31 -05:00
Laine Stump
79ba107670 util: add missing newline
Somehow I managed to backspace over the newline between the closing
brace and goto cleanup; in commit 36e244f3.
2016-01-08 14:09:31 -05:00
Cole Robinson
74abc3deac qemu: Handle SecurityManagerVerify in post parse
Rather than open coding calls. I can't see any reason not to
2016-01-08 13:25:21 -05:00
Cole Robinson
a8b628e7a8 qemu: Handle CanonicalizeMachine in post parse
Rather than open coding calls. I can't see any reason not to
2016-01-08 13:25:20 -05:00
Cole Robinson
9cec6239c1 qemu: domain: split out post parse default device handling
Should be a no-op
2016-01-08 13:25:20 -05:00
Cole Robinson
ee719cdcca domain: separate out function for post parse timer validation
This should be a no-op
2016-01-08 13:25:20 -05:00
Cole Robinson
11de45bb71 domain: separate out function for post parse console compat
This should be a no-op
2016-01-08 13:25:20 -05:00
Jiri Denemark
b2334e433a qemu: Refactor qemuMigrationFinish
To get rid of a giant if-else block which is very easy to get lost in.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-01-08 18:18:58 +01:00
Jiri Denemark
eb084a733b qemu: Report more migration statistics
memory_dirty_rate corresponds to dirty-pages-rate in QEMU and
memory_iteration is what QEMU reports in dirty-sync-count.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-01-08 18:18:58 +01:00
Jiri Denemark
b638b9b35c qemu: Create a proper type for migration status enum
The enum will be called qemuMonitorMigrationStatus.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-01-08 18:18:58 +01:00
Jiri Denemark
09bbd96239 qemu: Rename qemuMonitorMigrationStatus struct
The structure actually contains migration statistics rather than just
the status as the name suggests. Renaming it as
qemuMonitorMigrationStats removes the confusion.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-01-08 18:18:58 +01:00
Jiri Denemark
5fed699a2d qemu: Reorder migration status enum
A migration is in "setup" state after it was "inactive" and before it
becomes "active". Let's reflect this in our migration status enum.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-01-08 18:18:58 +01:00
Pavel Hrdina
4100aecd13 xen: move virDomainDefPostParse to xenParseSxpr
This patch partially reverts previous commit 91a00424 and moves the post
parse function to xenParseSxpr.  This update is required because xen
driver calls xenParseSxpr directly.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2016-01-08 14:45:20 +01:00
Martin Kletzander
f0df0dcaa0 Remove non-breaking space in comment
It was added by mistake before the 'If' by commit 7140807917.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2016-01-08 14:22:42 +01:00
Jiri Denemark
f87668b70e qemu: Fix NBD migration with default listenAddress
My commit 674afcb09e moved computing the
default listen address from qemuMigrationPrepareAny to
qemuMigrationPrepareIncoming. However, I didn't notice listenAddress was
later passed to qemuMigrationStartNBDServer. Thus, it would be called
with the original value of listenAddress (NULL).

Let's add the updated listen address to qemuProcessIncomingDef and use
it when starting NBD servers.

Reported-by: Michael Chapman <mike@very.puzzling.org>
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-01-08 10:39:20 +01:00
Andrea Bolognani
4e1f37f812 pci: Log debug messages when manipulating the inactive list
Most of the changes to the list of active and inactive PCI devices
happen in virHostdev, where they are properly logged.

virPCIDeviceDetach() and virPCIDeviceReattach(), however, change the
inactive list as well, so they should be logging similar messages.
2016-01-08 09:52:33 +01:00