Commit Graph

21414 Commits

Author SHA1 Message Date
Radostin Stoyanov
94f417baa9 WmiClass: Don't share "versions" between instances
Lists in Python are mutable and when used as a default value of a
parameter for class constructor, its value will be shared between
all class instances.

Example:

	class Test:
	    def __init__(self, mylist=[]):
	        self.mylist = mylist

	A = Test()
	B = Test()
	A.mylist.append("mylist from instance A")
	print(B.mylist) # Will print ['mylist from instance A']

Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Signed-off-by: Radostin Stoyanov <rstoyanov1@gmail.com>
2018-03-20 12:13:35 +00:00
Radostin Stoyanov
5e870cbda4 python: Remove space around = in keyword args
PEP8 recommends not having spaces around = in a keyword argument or
a default parameter value.

https://www.python.org/dev/peps/pep-0008/#other-recommendations

Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Signed-off-by: Radostin Stoyanov <rstoyanov1@gmail.com>
2018-03-20 12:13:35 +00:00
Radostin Stoyanov
f3a99869ff esx_vi_generator: Simplify alignment function
Generate whitespace using the standard function ljust() that is
available in both Py3 [1] and Py2 [2].

1: https://docs.python.org/3/library/stdtypes.html?highlight=strip#str.ljust
2: https://docs.python.org/2.7/library/string.html#string.ljust

Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Signed-off-by: Radostin Stoyanov <rstoyanov1@gmail.com>
2018-03-20 12:13:35 +00:00
Radostin Stoyanov
b89111afed esx_vi_generator: Simplify get_occurrence_comment
Reduce the number of if-statements and use a single return.
Utilise a dictionary to map between occurrences and values.

Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Signed-off-by: Radostin Stoyanov <rstoyanov1@gmail.com>
2018-03-20 12:13:35 +00:00
Radostin Stoyanov
25409b2dd3 esx_vi_generator: Simplify generate_helper_header
The function generate_helper_header() only returns a formatted string.
This could be achieved without performing string concatenation.

Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Signed-off-by: Radostin Stoyanov <rstoyanov1@gmail.com>
2018-03-20 12:13:35 +00:00
Radostin Stoyanov
68106955da esx_vi_generator: Simplify generate_helper_source
The generate_helper_source() function returns a formatted string.
This could be achieved without the use of a local variable "source"
and string concatenation.

Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Signed-off-by: Radostin Stoyanov <rstoyanov1@gmail.com>
2018-03-20 12:13:35 +00:00
Radostin Stoyanov
28593b5b54 apibuild: Remove whitespace before ', ' and ':'
PEP8 recommends removing whitespace immediately before a comma,
semicolon, or colon [1]. In addition remove multiple spaces after
keyword (PEP8 - E271).

1: https://www.python.org/dev/peps/pep-0008/#whitespace-in-expressions-and-statements

Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Signed-off-by: Radostin Stoyanov <rstoyanov1@gmail.com>
2018-03-20 12:13:35 +00:00
Jiri Denemark
1554eafbe6 qemu: Don't assign alias to disabled balloon device
<memballoon model='none'/> is the only way to disable balloon driver
since libvirt will add one automatically if the memballoon element is
missing. In other words, there's no balloon device if model is 'none'
and generating an alias for it makes no sense. The alias will be ignored
when parsing the XML and it will disappear once libvirtd is restarted.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2018-03-19 21:22:43 +01:00
Christian Ehrhardt
77cd862fb5 virt-aa-helper: resolve file symlinks
In a recent change b932ed69: "virt-aa-helper: resolve yet to be created
paths" several cases with symlinks in paths were fixed, but it regressed
cases where the file being last element of the path was the actual link.

In the case of the last element being the symlink realpath can (and shall)
be called on the full path that was passed.

Examples would be zfs/lvm block devices like:
 <disk type='block' device='disk'>
    <driver name='qemu' type='raw'/>
    <source dev='/dev/mapper/testlvm-testvol1'/>
    <target dev='vdd' bus='virtio'/>
 </disk>
With the target being:
 /dev/mapper/testlvm-testvol1 -> ../dm-0

That currently is rendered as
 "/dev/mapper/testlvm-testvol1" rwk,
but instead should be (and is with the fix):
 "/dev/dm-0" rwk,

Fixes: b932ed69: "virt-aa-helper: resolve yet to be created paths"
Fixes: https://bugs.launchpad.net/ubuntu/+source/libvirt/+bug/1756394

Signed-off-by: Christian Ehrhardt <christian.ehrhardt@canonical.com>
2018-03-19 13:06:03 +01:00
Andrea Bolognani
677aaeb128 python: Drop explicit version where possible
Some of our scripts are known to work both with Python 2 and
Python 3, so for them we shouldn't be forcing any specific
version of the interpreter when they're called directly; we
always use $(PYTHON) explicitly in our build rules anyway.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
2018-03-19 11:22:02 +01:00
Erik Skultety
e02d102bac qemu: hostdev: Fix the error on VM start with an mdev when IOMMU is off
Commit b4c2ac8d56 made a false assumption that IOMMU support necessary
for an mdev device to be assigned to a VM. Unlike direct PCI assignment,
IOMMU support is not needed for mediated devices, as the physical parent
device provides the isolation, therefore, simply checking for VFIO
presence is enough to successfully start a VM.

Luckily, this issue is not serious, since as of yet, libvirt mandates
mdevs to be pre-created prior to a domain's launch - if it is,
everything does work smoothly even with IOMMU disabled, because the
parent device will ensure the iommu groups we try to access exist.
However, if there are *no* IOMMU groups yet, thus no mdev exists yet, one
would see the following error:

"unsupported configuration: Mediated host device assignment requires VFIO
support"

The error msg above is simply wrong and doesn't even reflect the IOMMU
reality, so after applying this patch one would rather see the following
error in such case instead:

"device not found: mediated device '<UUID>' not found"

Signed-off-by: Erik Skultety <eskultet@redhat.com>
2018-03-19 11:14:40 +01:00
Erik Skultety
3d2e4c3e53 util: mdev: Improve the error msg on non-existent mdev prior to VM start
What one currently gets is:
failed to read '/sys/bus/mdev/devices/<UUID>/mdev_type/device_api': No
such file or directory

This indicates that something is missing within the device's sysfs tree
which likely might be not be the case here because the device simply
doesn't exist yet. So, when creating our internal mdev obj, let's check
whether the device exists first prior to trying to verify the
user-provided model within domain XML.

Signed-off-by: Erik Skultety <eskultet@redhat.com>
2018-03-19 11:14:40 +01:00
Michal Privoznik
29d6bb7045 virNetlinkDumpCommand: Don't leak response buffer
==16451== 32,768 bytes in 2 blocks are definitely lost in loss record 1,007 of 1,013
==16451==    at 0x4C2AF0F: malloc (vg_replace_malloc.c:299)
==16451==    by 0x7CADB40: nl_recv (in /usr/lib64/libnl-3.so.200.23.0)
==16451==    by 0x532DFAC: virNetlinkDumpCommand (virnetlink.c:363)
==16451==    by 0x53236AE: virNetDevIPCheckIPv6Forwarding (virnetdevip.c:641)
==16451==    by 0xE3E4A1A: networkStartNetworkVirtual (bridge_driver.c:2490)
==16451==    by 0xE3E55F5: networkStartNetwork (bridge_driver.c:2832)
==16451==    by 0xE3DFFE5: networkAutostartConfig (bridge_driver.c:531)
==16451==    by 0x53F47E0: virNetworkObjListForEachHelper (virnetworkobj.c:1412)
==16451==    by 0x52FE69F: virHashForEach (virhash.c:606)
==16451==    by 0x53F4857: virNetworkObjListForEach (virnetworkobj.c:1439)
==16451==    by 0xE3E0BF4: networkStateAutoStart (bridge_driver.c:808)
==16451==    by 0x55689CE: virStateInitialize (libvirt.c:758)

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
2018-03-19 10:47:08 +01:00
Chen Hanxiao
3ee5a4ddf7 qemu: fix a mem leak
fix a mem leak

Signed-off-by: Chen Hanxiao <chenhanxiao@gmail.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2018-03-17 19:21:22 +01:00
Chen Hanxiao
70c67d4a15 virarptable: fix some leaks and format issue
fix some leaks and format issue
Also support virArpTableFree to get NULL.

Signed-off-by: Chen Hanxiao <chenhanxiao@gmail.com>
2018-03-17 13:19:07 +01:00
Jim Fehlig
60b3fcd90c libxl: MigratePrepare: use standard begin and end API pattern
libxlDomainMigrationPrepare adds the incoming domain def to the list
of domains via virDomainObjListAdd, but never adds its own ref to the
returned virDomainObj as other callers of virDomainObjListAdd do.
libxlDomainMigrationPrepareTunnel3 suffers the same discrepancy.

Change both to add a ref to the virDomainObj after a successful
virDomainObjListAdd, similar to other callers. This ensures a consistent
pattern throughout the drivers and allows using the virDomainObjEndAPI
function for cleanup.

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2018-03-16 14:37:01 -06:00
John Ferlan
fe51dbda56 libxl: Use virDomainObjListFindBy{UUID|ID}Ref
For libxlDomainLookupByID and libxlDomainLookupByUUID let's
return a locked and referenced @vm object so that callers can
then use the common and more consistent virDomainObjEndAPI in
order to handle cleanup rather than needing to know that the
returned object is locked and calling virObjectUnlock.

The LookupByName already returns the ref counted and locked object,
so this will make things more consistent.

Signed-off-by: John Ferlan <jferlan@redhat.com>
Reviewed-by: Jim Fehlig <jfehlig@suse.com>
2018-03-16 14:26:00 -06:00
John Ferlan
4e6fcdb6fa libxl: Properly cleanup after libxlDomObjFromDomain
Commit id '9ac945078' altered libxlDomObjFromDomain to return
a locked *and* ref counted object for some specific purposes;
however, it neglected to alter all the consumers of the helper
to use virDomainObjEndAPI thus leaving many objects with extra
ref counts.

Signed-off-by: John Ferlan <jferlan@redhat.com>
Reviewed-by: Jim Fehlig <jfehlig@suse.com>
2018-03-16 14:24:39 -06:00
Jim Fehlig
f5eacf2a9a libxl: MigratePerform: properly cleanup after libxlDomObjFromDomain
libxlDomObjFromDomain to returns locked and ref counted virDomainObj but
libxlDomainMigratePerform3Params only unlocks the object on exit. Convert
it to use the virDomainObjEndAPI function for cleanup.

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2018-03-16 11:14:58 -06:00
Jim Fehlig
99486799c3 libxl: MigrateConfirm: Dont unlock virDomainObj in helper function
The libxlDomainMigrateConfirm3Params API locks and ref counts the associated
virDomainObj but relies on the helper function libxlDomainMigrationConfirm
to unlock the object. Unref'ing the object is not done in either function.
libxlDomainMigrationConfirm is also used by libxlDomainMigratePerform3Params
for p2p migration, but in that case the lock/ref and unref/unlock are
properly handled in the API entry point.

Remove the unlock from libxlDomainMigrationConfirm and adjust
libxlDomainMigrateConfirm3Params to properly unref/unlock the virDomainObj
on success and error paths.

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2018-03-16 11:14:57 -06:00
Jim Fehlig
64370c4b81 libxl: MigrateBegin: Dont call EndAPI in helper function
The libxlDomainMigrateBegin3Params API locks and ref counts the associated
virDomainObj but relies on the helper function libxlDomainMigrationBegin
to unref/unlock the object. libxlDomainMigrationBegin is also used by
libxlDomainMigratePerform3Params for p2p migration, but in that case the
lock/ref and unref/unlock are properly handled in the API entry point. So
p2p migrations suffer a double unref/unlock in the Perform API.

Remove the unref/unlock (virDomainObjEndAPI) from libxlDomainMigrationBegin
and adjust libxlDomainMigrateBegin3Params to properly unref/unlock
the virDomainObj on success and error paths.

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2018-03-16 11:14:57 -06:00
Michal Privoznik
b133fac356 qemu: Build usb controller command line more wisely
https://bugzilla.redhat.com/show_bug.cgi?id=1552127

When building command line for USB controllers we have to do more
than just put controller's alias onto the command line. QEMU has
concept of these joined USB controllers. For instance ehci and
uhci controllers need to create the same USB bus. To achieve that
the slave controller needs to refer the master controller. This
worked until we've introduced user aliases because both master
and slave had the same alias. With user aliases slave can have
different alias than master. Therefore, when generating command
line for slave we need to look up the master's alias.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2018-03-16 16:37:14 +01:00
Farhan Ali
c8935705f1 qemu: Use correct bus type for input devices
commit 7210cef452 'qemu: build command line for virtio input devices'
introduced an error, by checking if input bus type is
VIR_DOMAIN_DISK_BUS_VIRTIO.

Fix it by using the correct bus type for input devices.

Signed-off-by: Farhan Ali <alifm@linux.vnet.ibm.com>
Reviewed-by: Boris Fiuczynski <fiuczy@linux.vnet.ibm.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2018-03-16 09:42:58 -04:00
Farhan Ali
21c6ec2ff7 qemu: Fix comment for 'qemuValidateDevicePCISlotsChipsets'
Commit id '177db487' renamed 'qemuValidateDevicePCISlotsChipsets' to
'qemuDomainValidateDevicePCISlotsChipsets', but didn't adjust comment.

Signed-off-by: Farhan Ali <alifm@linux.vnet.ibm.com>
Reviewed-by: Boris Fiuczynski <fiuczy@linux.vnet.ibm.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2018-03-16 09:42:52 -04:00
Michal Privoznik
72d3301db1 virnetlink: Provide virNetlinkGetNeighbor non-Linux stub
This function is exported and therefore we have to have
implementation for all platforms.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2018-03-16 09:02:42 +01:00
Michal Privoznik
9304d916a3 virarptable: Avoid cast align warnings
We have to use VIR_WARNINGS_NO_CAST_ALIGN to avoid clang warning
about increased required alignment caused by some netlink macros.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2018-03-16 09:02:34 +01:00
Marc Hartmayer
1bc7e2b8b5 remote: Set eventID explicitly to an invalid value
Set the eventID for remoteRelayDomainQemuMonitorEvent explicitly to an
invalid value. Although the value is not used by
remoteRelayDomainQemuMonitorEvent, but it might be less prone to
errors for further refactorings.

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>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2018-03-15 17:12:28 -04:00
Marc Hartmayer
8bd0261a72 stream: Access stream->prog instead of a hard-coded global variable
Use stream->prog instead of a hard-coded "remoteProgram" since at
stream creation in daemonCreateClientStream "remoteProgram" is used
so we should use that especially since these functions are intended
as generic helpers for streams.

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>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2018-03-15 17:12:28 -04:00
Marc Hartmayer
9f24004b82 remote: remove unneeded global variables
Remove unneeded global variables and convert them into local variables
where they're needed.

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>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2018-03-15 17:12:28 -04:00
Marc Hartmayer
1ee9c384da test: fix error path in testConnectOpen
In case of an error do the cleanup of the private data of the
connection.

Signed-off-by: Marc Hartmayer <mhartmay@linux.vnet.ibm.com>
Reviewed-by: Boris Fiuczynski <fiuczy@linux.vnet.ibm.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2018-03-15 17:12:28 -04:00
Marc Hartmayer
bc0f82adf8 test: introduce testDriverCloseInternal
Refactor testConnectClose as it's then obvious that conn->privateData
is set to NULL in all cases. In addition, 'testConnectCloseInternal'
can be better reused.

Signed-off-by: Marc Hartmayer <mhartmay@linux.vnet.ibm.com>
Reviewed-by: Boris Fiuczynski <fiuczy@linux.vnet.ibm.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2018-03-15 17:12:28 -04:00
Marc Hartmayer
55130c0b63 test: rename defaultConn to defaultPrivconn
Rename the variable @defaultConn to @defaultPrivconn as it doesn't
point to a default connection but to the private data used for the
shared default connection of the test driver.

Signed-off-by: Marc Hartmayer <mhartmay@linux.vnet.ibm.com>
Reviewed-by: Boris Fiuczynski <fiuczy@linux.vnet.ibm.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2018-03-15 17:12:28 -04:00
Marc Hartmayer
81b2a8e024 test: testConnectClose: Set privateData to NULL in all cases
Set privateData to NULL also for a connection that uses @defaultConn
as privateData regardless of whether @defaultConn was freed or
not. @defaultConn is shared between multiple connections and it's
ensured that there will be no memory leak by counting references.

Signed-off-by: Marc Hartmayer <mhartmay@linux.vnet.ibm.com>
Reviewed-by: Boris Fiuczynski <fiuczy@linux.vnet.ibm.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2018-03-15 17:12:28 -04:00
Marc Hartmayer
5428389b2b test: testConnectAuthenticate: Take the lock when accessing mutable values
Signed-off-by: Marc Hartmayer <mhartmay@linux.vnet.ibm.com>
Reviewed-by: Boris Fiuczynski <fiuczy@linux.vnet.ibm.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2018-03-15 17:12:28 -04:00
Marc Hartmayer
ba8bd17a6a test: testOpenFromFile: return VIR_DRV_OPEN_SUCCESS in case of success
Signed-off-by: Marc Hartmayer <mhartmay@linux.vnet.ibm.com>
Reviewed-by: Boris Fiuczynski <fiuczy@linux.vnet.ibm.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2018-03-15 17:12:28 -04:00
Marc Hartmayer
d8a24044b7 test: testOpenDefault: introduce cleanup path
The two code paths have some cleanup in common so lets refactor it.

Signed-off-by: Marc Hartmayer <mhartmay@linux.vnet.ibm.com>
Reviewed-by: Boris Fiuczynski <fiuczy@linux.vnet.ibm.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2018-03-15 17:12:28 -04:00
Marc Hartmayer
d1c89c9b2d driver: Add typedef for the anonymous enum used for driver features
Add typedef for the anonymous enum used for the driver features. This
allows the usage of the type in a switch statement and taking
advantage of the compilers feature to detect uncovered cases.

Signed-off-by: Marc Hartmayer <mhartmay@linux.vnet.ibm.com>
Reviewed-by: Boris Fiuczynski <fiuczy@linux.vnet.ibm.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2018-03-15 17:12:28 -04:00
Andrea Bolognani
b6f6a0d984 python3: Fix sort function
This deals with cls.version possibly being None.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
2018-03-15 17:48:47 +01:00
Andrea Bolognani
b98d4244c6 python3: Open files in text instead of binary mode
We use text operations on the contents after reading them.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
2018-03-15 17:48:45 +01:00
Andrea Bolognani
e379dcce57 python3: Replace keys() + sort() with sorted()
The keys() method no longer returns a list, so converting the
return value would be necessary before calling sort() on it;
alternatively, we can just call sorted(), which returns a
sorted list.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
2018-03-15 17:48:43 +01:00
Andrea Bolognani
b207817b49 python3: Use the print() function
It has replaced the 'print' statement.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
2018-03-15 17:47:14 +01:00
Jim Fehlig
fb327ac2c3 lockd: fix typo in virtlockd-admin.socket
Commit ce7ae55ea1 introduced a typo in virtlockd-admin socket file

/usr/lib/systemd/system/virtlockd-admin.socket:7: Unknown lvalue
'Server' in section 'Socket'

Change 'Server' to 'Service'.

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
2018-03-15 09:06:28 -06:00
Michal Privoznik
3ee5f8115d virarptable: Include rtnetlink.h only on Linux
And at the same time, do that from .c rather than .h file.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Chen Hanxiao<chenhanxiao@gmail.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
2018-03-15 14:59:12 +01:00
Michal Privoznik
944adb3106 src: Don't add virarptable.c to setuid library
The setuid-rpc-client.la is intended to be small and contain only
bare minimum of source files. virarptable.c is not one of them.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Chen Hanxiao<chenhanxiao@gmail.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
2018-03-15 14:59:12 +01:00
Chen Hanxiao
e24d4c9051 qemu: introduce qemuARPGetInterfaces to get IP from host's arp table
introduce VIR_DOMAIN_INTERFACE_ADDRESSES_SRC_ARP to get ip address
of VM from the message of netlink RTM_GETNEIGH

Signed-off-by: Chen Hanxiao <chenhanxiao@gmail.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2018-03-15 11:22:42 +01:00
Chen Hanxiao
a176d67cdf util: introduce helper to parse message from RTM_GETNEIGH query
introduce helper to parse RTM_GETNEIGH query message and
store it in struct virArpTable.

Signed-off-by: Chen Hanxiao <chenhanxiao@gmail.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2018-03-15 11:22:42 +01:00
Chen Hanxiao
414e61109c util: introduce virNetlinkGetNeighbor to get neighbor table entry
use RTM_GETNEIGH to query arp table entry by netlink socket

Signed-off-by: Chen Hanxiao <chenhanxiao@gmail.com>
2018-03-15 11:22:42 +01:00
Peter Krempa
892e37d5a4 qemu: hotplug: Clean up memory backing files after failed memory hotplug
Libvirt provides full path to the backing file since commit
fec8f9c49a. This made qemu create the backend object but did not
delete it. This was fixed for unplug case in 4d83a6722f but not in case
of failure to hotplug the frontend. We'd leave the files behind which
would make memory unusable in case of hugepages.

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

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
2018-03-15 10:04:40 +01:00
Jiri Denemark
6c2e34e1a7 qemu: Switch context for job related private XML parsing
Having to repeat "./job[1]/" XPath prefix for every single element or
attribute we want to parse is suboptimal. And even more so once we
further extract code from qemuDomainObjPrivateXMLParseJob into separate
functions.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2018-03-15 09:32:14 +01:00
Jiri Denemark
0a3a96b5c3 qemu: Parse all job related private XML in dedicated function
Commit dc567cc22b introduced qemuDomainObjPrivateXMLParseJob, but forgot
to move "./job[1]/@type" parsing into it.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2018-03-15 09:24:20 +01:00
Michal Privoznik
92a5d12157 daemonStreamHandleWriteData: Preserve error when aborting stream
The daemonStreamHandleWriteData() function is called whenever
server side of stream is able to receive some data. Nevertheless,
it calls virStreamSend() (to pass data down to virFDStream) and
depending on its return value it may abort the stream. However,
the functions it called when doing so are public APIs and as such
reset any error set previously. Therefore, if there was any error
in writing data to stream (i.e. repored in virStreamSend) it is
reset before virNetServerProgramSendReplyError() can get to it.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Andrea Bolognani <abologna@redhat.com>
2018-03-15 08:25:59 +01:00
Michal Privoznik
bc01d903c2 virsysinfo: Use more virSkipSpacesBackwards()
Some fields reported by dmidecode have plenty of useless spaces
(in fact some have nothing but spaces). To deal with this we have
introduced virSkipSpacesBackwards() and use it in
virSysinfoParseX86Processor() and virSysinfoParseX86Memory().
However, other functions (e.g. virSysinfoParseX86Chassis()) don't
use it at all and thus we are reporting nonsense:

  <sysinfo type='smbios'>
    <chassis>
      <entry name='manufacturer'>FUJITSU</entry>
      <entry name='version'>                      </entry>
      <entry name='serial'>                </entry>
      <entry name='asset'>                                        </entry>
      <entry name='sku'>Default string</entry>
    </chassis>
  </sysinfo>

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2018-03-14 17:43:40 +01:00
Daniel P. Berrangé
fbf31e1a4c qemu: avoid denial of service reading from QEMU guest agent (CVE-2018-1064)
We read from the agent until seeing a \r\n pair to indicate a completed
reply or event. To avoid memory denial-of-service though, we must have a
size limit on amount of data we buffer. 10 MB is large enough that it
ought to cope with normal agent replies, and small enough that we're not
consuming unreasonable mem.

This is identical to the flaw we had reading from the QEMU monitor
as CVE-2018-5748, so rather embarrassing that we forgot to fix
the agent code at the same time.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2018-03-14 12:16:42 +00:00
Ján Tomko
0d4b988b3e Merge WITH_POLKIT1 and WITH_POLKIT
There is just one polkit now.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
2018-03-14 12:46:26 +01:00
Ján Tomko
ab20f5059c Do not generate polkit rules file
This essentially reverts commit <e1019e9>, which added
an extra step for generating the policy file.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
2018-03-14 12:46:26 +01:00
Ján Tomko
af41cf5957 Remove Policy-Kit support
Policy-Kit has been replaced by polkit (referred to, respectively,
as POLKIT0 and POLKIT1 in our Makefiles).

The last build fix with old Policy-Kit was in May 2013:
commit <442eb2ba> and build with -Wunused-label was broken
since April 2016: commit <8437130>

Signed-off-by: Ján Tomko <jtomko@redhat.com>
2018-03-14 12:46:26 +01:00
Peter Krempa
07141541fb conf: Extract parsing of storage source related data
Split out the parser and separate it from the private data part so that
it can be later reused in other parts of the code.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
2018-03-14 12:19:44 +01:00
Peter Krempa
b17573fe09 conf: Parse and validate disk source seclabels together with the source
Since seclabels are formatted along with the source element and will
also make sense to be passed for the backing chain we should parse them
in the place where we parse the disk source. Same applies for
validation.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
2018-03-14 12:19:44 +01:00
Peter Krempa
3960aeb7a6 conf: Separate seclabel validation from parsing
Rather than checking that the security label is legal when parsing it
move the code into a separate function.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
2018-03-14 12:19:44 +01:00
Peter Krempa
28e1068c4f conf: Validate disk source configuration also for the backing store
Since we already parse the <backingStore> of a disk source, we should
also validate the configuration for the whole backing chain and not only
for the top level image.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
2018-03-14 12:19:44 +01:00
Peter Krempa
c4e7c1f212 conf: disk: Separate virStorageSource formatting
Move out formatting of 'startuPolicy' which is a property of the disk
out of the <source> element. Extracting the code formating the content
and attributes will also allow reuse in other parts of the code.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
2018-03-14 12:19:44 +01:00
Peter Krempa
2bbbc9798d conf: Refactor formatting of startupPolicy in virDomainDiskSourceFormatInternal
Move it to a single location which also allows to get rid of the
temporrary variable.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
2018-03-14 12:19:44 +01:00
Peter Krempa
8f5138829f conf: Remove virDomainDiskSourceDefFormatSeclabel
The wrapper functionality can be moved to the only user
virDomainDiskSourceFormatInternal. Also removes comment which does not
reflect the truth any more.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
2018-03-14 12:19:44 +01:00
Peter Krempa
6bec169759 conf: Refactor seclabel formatting in virDomainDiskSourceFormatInternal
Call the formatter function only once.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
2018-03-14 12:19:44 +01:00
Peter Krempa
bbacd6b113 conf: Remove unnecessary condition from virDomainDiskSourceFormatInternal
Now that the function is using virXMLFormatElement we don't need to
conditionally format anything, since we'll format the element according
to the presence of content.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
2018-03-14 12:19:44 +01:00
Michal Privoznik
ca250269b0 virSecurityDACChownListFree: Don't leak list->items array
We're freeing individual items in it but not the array itself.

==19200== 40 bytes in 1 blocks are definitely lost in loss record 847 of 1,059
==19200==    at 0x4C2D12F: realloc (vg_replace_malloc.c:785)
==19200==    by 0x52C5532: virReallocN (viralloc.c:245)
==19200==    by 0x52C5628: virExpandN (viralloc.c:294)
==19200==    by 0x52C58FC: virInsertElementsN (viralloc.c:436)
==19200==    by 0x542856B: virSecurityDACChownListAppend (security_dac.c:115)
==19200==    by 0x54286B4: virSecurityDACTransactionAppend (security_dac.c:167)
==19200==    by 0x542902F: virSecurityDACSetOwnershipInternal (security_dac.c:560)
==19200==    by 0x54295D6: virSecurityDACSetOwnership (security_dac.c:650)
==19200==    by 0x542AEE0: virSecurityDACSetInputLabel (security_dac.c:1472)
==19200==    by 0x542B61D: virSecurityDACSetAllLabel (security_dac.c:1693)
==19200==    by 0x542DD67: virSecurityManagerSetAllLabel (security_manager.c:869)
==19200==    by 0x54279C2: virSecurityStackSetAllLabel (security_stack.c:361)

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2018-03-13 15:38:17 +01:00
Michal Privoznik
fb0bdb6167 virSysinfoParseX86Chassis: Store asset tag into correct pointer
Probably due to copy-paste error we're storing asset tag into
def->sku which we even use in the next step to store SKU number
and thus the asset tag leaks.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2018-03-13 15:38:17 +01:00
Michal Privoznik
a02a52751f qemuAssignDeviceInputAlias: Be tolerant to pre-existent alias
https://bugzilla.redhat.com/show_bug.cgi?id=1554876

This is missing in 6bc4a371cf and therefore we are effectively
overwriting user provided aliases for <input/> devices.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2018-03-13 15:17:19 +01:00
Peter Krempa
dc567cc22b qemu: domain: Extract parsing of job-related private XML
Similarly to the formatter extract the parser code.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
2018-03-13 13:54:11 +01:00
Peter Krempa
d8be0f4bc3 qemu: domain: Use virXMLFormatElement in qemuDomainObjPrivateXMLFormatJob
Modernize the code by using the clever formatter rather than checking
manually when to format the end of the element.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
2018-03-13 13:54:11 +01:00
Peter Krempa
3a4649b532 qemu: domain: Return early in qemuDomainObjPrivateXMLFormatJob
Remove one level of nesting by returing early.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
2018-03-13 13:54:11 +01:00
Peter Krempa
d33adb9173 qemu: domain: Don't overwrite job type in private data
The code overwrote the internal job type and then fixed it back. Since
the job type is not accessed in the code this does not make much sense.
Use the temporary value instead.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
2018-03-13 13:54:11 +01:00
Peter Krempa
d2cd7215e7 qemu: domain: Split out formating of Job data from private data formatter
Separate the code for later refactoring

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
2018-03-13 13:54:11 +01:00
Ján Tomko
1ab2574731 qemuDomainUSBAddressAddHubs: use numeric comparison
Since data.count is not a pointer, but an integer,
compare it against an integer value instead of using
the implicit "boolean" conversion that is customarily
used for pointers.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
2018-03-13 10:38:48 +01:00
Ján Tomko
c8ab5aeb14 Adjust whitespace in virDomainDefHasUSB prototype
To match the rest of the file.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
2018-03-13 10:31:56 +01:00
Jim Fehlig
33c6eb9689 libvirtd: fix potential deadlock when reloading
It is possible to deadlock libvirtd when concurrently starting a domain
and restarting the daemon. Threads involved in the deadlock are

Thread 4 (Thread 0x7fc13b53e700 (LWP 64084)):
/lib64/libpthread.so.0
    at util/virthread.c:154
    at qemu/qemu_monitor.c:1083
    cmd=0x7fc110017700, scm_fd=-1, reply=0x7fc13b53d318) at
qemu/qemu_monitor_json.c:305
cmd=0x7fc110017700,
    reply=0x7fc13b53d318) at qemu/qemu_monitor_json.c:335
    at qemu/qemu_monitor_json.c:1298
    at qemu/qemu_monitor.c:1697
    vm=0x7fc110003d00, asyncJob=QEMU_ASYNC_JOB_START) at qemu/qemu_process.c:1763
vm=0x7fc110003d00,
    asyncJob=6, logCtxt=0x7fc1100089c0) at qemu/qemu_process.c:1835
    vm=0x7fc110003d00, asyncJob=6, logCtxt=0x7fc1100089c0) at
qemu/qemu_process.c:2180
driver=0x7fc12004e1e0,
    vm=0x7fc110003d00, asyncJob=QEMU_ASYNC_JOB_START, incoming=0x0, snapshot=0x0,
    vmop=VIR_NETDEV_VPORT_PROFILE_OP_CREATE, flags=17) at qemu/qemu_process.c:6111
driver=0x7fc12004e1e0,
    vm=0x7fc110003d00, updatedCPU=0x0, asyncJob=QEMU_ASYNC_JOB_START,
migrateFrom=0x0,
    migrateFd=-1, migratePath=0x0, snapshot=0x0,
vmop=VIR_NETDEV_VPORT_PROFILE_OP_CREATE,
    flags=17) at qemu/qemu_process.c:6334
    xml=0x7fc110000ed0 "<!--\nWARNING: THIS IS AN AUTO-GENERATED FILE.
CHANGES TO IT ARE LIKELY TO BE\nOVERWRITTEN AND LOST. Changes to this xml
configuration should be made using:\n  virsh edit testvv\nor other
applicati"..., flags=0) at qemu/qemu_driver.c:1776
...

Thread 1 (Thread 0x7fc143c66880 (LWP 64081)):
/lib64/libpthread.so.0
    at util/virthread.c:122
conf/nwfilter_conf.c:159
sig=0x7ffe0a831e30,
    opaque=0x0) at remote/remote_daemon.c:724
    opaque=0x558c5328b230) at rpc/virnetdaemon.c:654
    at util/vireventpoll.c:508
rpc/virnetdaemon.c:858
remote/remote_daemon.c:1496
(gdb) thr 1
[Switching to thread 1 (Thread 0x7fc143c66880 (LWP 64081))]
/lib64/libpthread.so.0
(gdb) f 1
    at util/virthread.c:122
122	    pthread_rwlock_wrlock(&m->lock);
(gdb) p updateLock
$1 = {lock = {__data = {__lock = 0, __nr_readers = 1, __readers_wakeup = 0,
      __writer_wakeup = 0, __nr_readers_queued = 0, __nr_writers_queued = 1,
__writer = 0,
      __shared = 0, __rwelision = 0 '\000', __pad1 = "\000\000\000\000\000\000",
      __pad2 = 0, __flags = 0},
    __size = "\000\000\000\000\001", '\000' <repeats 15 times>, "\001",
'\000' <repeats 34 times>, __align = 4294967296}}

Reloading of the nwfilter driver is stuck waiting for a write lock, which
already has a reader (from qemuDomainCreateXML) in the critical section.
Since the reload occurs in the context of the main event loop thread,
libvirtd becomes deadlocked. The deadlock can be avoided by offloading
the reload work to a thread.

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
2018-03-12 10:30:13 -06:00
Roman Bogorodskiy
de3fe191f5 bhyve: fix crash on missing interface model
The bhyve driver crashes in bhyveBuildNetArgStr() when
network interface model is not defined. As it has to be provided
explicitly, add a check to report an error if it's missing.

Signed-off-by: Roman Bogorodskiy <bogorodskiy@gmail.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2018-03-12 20:08:03 +04:00
Roman Bogorodskiy
1b6ff36c2f Fix build with clang 6.0.0
Clang 6.0.0 complains when initializing structure with { NULL }:

conf/domain_addr.c:1494:38: error: missing field 'type' initializer [-Werror,-Wmissing-field-initializers]
    virDomainDeviceInfo nfo = { NULL };

Use { 0 } instead to make it happy.

Signed-off-by: Roman Bogorodskiy <bogorodskiy@gmail.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2018-03-12 20:04:08 +04:00
Andrea Bolognani
ea9b0e580a keycodemapdb: Update submodule
This time around it's not enough to just pick the latest commit,
because with aed87bb2aa6ed83b49574eb982e3bdd4c36acf17 keycodemapdb
renamed the 'rfb' keycode to 'qnum' and we need to accept the new
name while maintaining backwards compatibility.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
2018-03-12 16:30:49 +01:00
Michal Privoznik
e43263601f conf: Check for user aliases duplicates only
https://bugzilla.redhat.com/show_bug.cgi?id=1553162

When validating a device XML config we check if user provided
alias is unique. We do this by maintaining a hash table of device
aliases as we iterated over all devices defined for the domain.
However, it may happen that what appears as two devices in domain
XML is in fact just one interface in hypervisor.  We can assume
libvirt generated aliases to be unique and thus really check user
provided ones only.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2018-03-12 13:27:24 +01:00
Michal Privoznik
e5673ed444 virDomainDeviceValidateAliasForHotplug: Use correct domain defintion
https://bugzilla.redhat.com/show_bug.cgi?id=1553075

For some weird reason this function is getting live and
persistent def for domain but then accesses vm->def and
vm->newDef directly. This is rather unsafe as we can be
accessing NULL pointer.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2018-03-12 13:27:24 +01:00
Julio Faracco
dff3fab47f qemu: different declarations for the same method
Recently, this warning is appearing while libvirt is being compiled:
Function 'qemuAssignDeviceDiskAlias' argument order different:
declaration 'vmdef, def' definition 'def, disk'

This commit change the default declaration for qemuAssignDeviceDiskAlias
specified at src/qemu/qemu_alias.c.

Signed-off-by: Julio Faracco <jcfaracco@gmail.com>
Reviewed-by: Andrea Bolognani <abologna@redhat.com>
2018-03-12 11:02:09 +01:00
Peter Krempa
2ccfbaa356 qemu: Add qemu functions for storage source private data handling
The qemu driver registered the helpers from util code, but it will be
necessary to format also some qemu-specific data.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
2018-03-12 10:04:56 +01:00
Andrea Bolognani
b9b9195f15 qemu: Remove old qemuDomainDeviceDefValidateControllerPCI()
We've implemented all existing checks, and more, in the new
function, so we can finally drop the old one.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Laine Stump <laine@laine.org>
2018-03-09 16:57:27 +01:00
Andrea Bolognani
07160b65db qemu: Validate PCI controllers (QEMU capabilities)
Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Laine Stump <laine@laine.org>
2018-03-09 16:57:27 +01:00
Andrea Bolognani
97727e060c qemu: Validate PCI controller options (chassis and port)
https://bugzilla.redhat.com/show_bug.cgi?id=1483816

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Laine Stump <laine@laine.org>
2018-03-09 16:57:27 +01:00
Andrea Bolognani
6fef5bf301 qemu: Validate PCI controller options (chassisNr)
https://bugzilla.redhat.com/show_bug.cgi?id=1483816

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Laine Stump <laine@laine.org>
2018-03-09 16:57:27 +01:00
Andrea Bolognani
c651cdbce6 qemu: Validate PCI controller options (numaNode)
This change catches an invalid use of the option in our
test suite.

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

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Laine Stump <laine@laine.org>
2018-03-09 16:57:27 +01:00
Andrea Bolognani
5bd8764ee0 qemu: Validate PCI controller options (busNr)
This change catches an invalid use of the option in our
test suite.

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

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Laine Stump <laine@laine.org>
2018-03-09 16:57:27 +01:00
Andrea Bolognani
932b6e1afc qemu: Validate PCI controller options (pcihole64)
https://bugzilla.redhat.com/show_bug.cgi?id=1483816

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Laine Stump <laine@laine.org>
2018-03-09 16:57:26 +01:00
Andrea Bolognani
dd8a8f1df3 qemu: Validate PCI controller options (targetIndex)
https://bugzilla.redhat.com/show_bug.cgi?id=1483816

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Laine Stump <laine@laine.org>
2018-03-09 16:57:22 +01:00
Andrea Bolognani
68b1491e89 qemu: Validate PCI controller options (index)
https://bugzilla.redhat.com/show_bug.cgi?id=1483816

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Laine Stump <laine@laine.org>
2018-03-09 16:57:22 +01:00
Andrea Bolognani
5a8b8b3f00 qemu: Validate PCI controller options (modelName)
https://bugzilla.redhat.com/show_bug.cgi?id=1483816

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Laine Stump <laine@laine.org>
2018-03-09 16:57:19 +01:00
Andrea Bolognani
e43103cbd0 qemu: Create new qemuDomainDeviceDefValidateControllerPCI()
The existing function is renamed and called from the new one, so
that even while we're in the process of implementing new checks
all the existing ones will be performed.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Laine Stump <laine@laine.org>
2018-03-09 16:57:18 +01:00
Ján Tomko
90d7262552 remote: simplify condition
In remoteConnectOpen, conn->uri cannot be NULL in the second
part of the OR expression due to short-circuit evaluation.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
2018-03-08 17:40:57 +01:00
Ján Tomko
451407c8c4 qemu: simplify condition
In qemuMigrationSrcRun, we already checked for non-NULL mig
and then dereferenced it. It's only possible for mig to be
NULL in the error section.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
2018-03-08 17:40:56 +01:00
Ján Tomko
d3b8a81ae6 openvz: pass sizeof to snprintf
The size argument accounts for the nul-byte to terminate
the string. Use sizeof and remove the pointless assignment.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
2018-03-08 16:45:54 +01:00
Ján Tomko
1efdab281f nwfilter: remove pointless assignment
Changing a parameter passed by value has no effect.

Introduced by <commit 3f74b2eb>.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
2018-03-08 16:45:54 +01:00
Ján Tomko
0a12d96c85 maint: use parentheses after if
Some instances of ARCH_IS_PPC64 did not use them.

Introduced by commits da636d8 and ef08a54

Signed-off-by: Ján Tomko <jtomko@redhat.com>
2018-03-08 16:45:54 +01:00
Daniel P. Berrangé
eefabb38c3 rpc: switch virtlockd and virtlogd to use single-threaded dispatch
Currently both virtlogd and virtlockd use a single worker thread for
dispatching RPC messages. Even this is overkill and their RPC message
handling callbacks all run in short, finite time and so blocking the
main loop is not an issue like you'd see in libvirtd with long running
QEMU commands.

By setting max_workers==0, we can turn off the worker thread and run
these daemons single threaded. This in turn fixes a serious problem in
the virtlockd daemon whereby it loses all fcntl() locks at re-exec due
to multiple threads existing. fcntl() locks only get preserved if the
process is single threaded at time of exec().

Reviewed-by: John Ferlan <jferlan@redhat.com>
Reviewed-by: Jim Fehlig <jfehlig@suse.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2018-03-08 15:40:29 +00:00
Daniel P. Berrangé
86cae503a4 rpc: avoid crashing in pre-exec if no workers are present
If max_workers is set to zero, then the worker thread pool won't be
created, so when serializing state for pre-exec we must set various
parameters to zero.

Reviewed-by: John Ferlan <jferlan@redhat.com>
Reviewed-by: Jim Fehlig <jfehlig@suse.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2018-03-08 15:40:29 +00:00
Daniel P. Berrangé
06e7ebb608 rpc: invoke the message dispatch callback with client unlocked
Currently if the virNetServer instance is created with max_workers==0 to
request a non-threaded dispatch process, we deadlock during dispatch

  #0  0x00007fb845f6f42d in __lll_lock_wait () from /lib64/libpthread.so.0
  #1  0x00007fb845f681d3 in pthread_mutex_lock () from /lib64/libpthread.so.0
  #2  0x000055a6628bb305 in virMutexLock (m=<optimized out>) at util/virthread.c:89
  #3  0x000055a6628a984b in virObjectLock (anyobj=<optimized out>) at util/virobject.c:435
  #4  0x000055a66286fcde in virNetServerClientIsAuthenticated (client=client@entry=0x55a663a7b960)
      at rpc/virnetserverclient.c:1565
  #5  0x000055a66286cc17 in virNetServerProgramDispatchCall (msg=0x55a663a7bc50, client=0x55a663a7b960,
      server=0x55a663a77550, prog=0x55a663a78020) at rpc/virnetserverprogram.c:407
  #6  virNetServerProgramDispatch (prog=prog@entry=0x55a663a78020, server=server@entry=0x55a663a77550,
      client=client@entry=0x55a663a7b960, msg=msg@entry=0x55a663a7bc50) at rpc/virnetserverprogram.c:307
  #7  0x000055a662871d56 in virNetServerProcessMsg (msg=0x55a663a7bc50, prog=0x55a663a78020, client=0x55a663a7b960,
      srv=0x55a663a77550) at rpc/virnetserver.c:148
  #8  virNetServerDispatchNewMessage (client=0x55a663a7b960, msg=0x55a663a7bc50, opaque=0x55a663a77550)
      at rpc/virnetserver.c:227
  #9  0x000055a66286e4c0 in virNetServerClientDispatchRead (client=client@entry=0x55a663a7b960)
      at rpc/virnetserverclient.c:1322
  #10 0x000055a66286e813 in virNetServerClientDispatchEvent (sock=<optimized out>, events=1, opaque=0x55a663a7b960)
      at rpc/virnetserverclient.c:1507
  #11 0x000055a662899be0 in virEventPollDispatchHandles (fds=0x55a663a7bdc0, nfds=<optimized out>)
      at util/vireventpoll.c:508
  #12 virEventPollRunOnce () at util/vireventpoll.c:657
  #13 0x000055a6628982f1 in virEventRunDefaultImpl () at util/virevent.c:327
  #14 0x000055a6628716d5 in virNetDaemonRun (dmn=0x55a663a771b0) at rpc/virnetdaemon.c:858
  #15 0x000055a662864c1d in main (argc=<optimized out>,
  #argv=0x7ffd105b4838) at logging/log_daemon.c:1235

Reviewed-by: John Ferlan <jferlan@redhat.com>
Reviewed-by: Jim Fehlig <jfehlig@suse.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2018-03-08 15:40:29 +00:00
Daniel P. Berrangé
c6f1d5190b rpc: simplify calling convention of virNetServerClientDispatchFunc
Currently virNetServerClientDispatchFunc implementations are only
responsible for free'ing the "msg" parameter upon success. Simplify the
calling convention by making it their unconditional responsibility to
free the "msg", and close the client if desired.

Reviewed-by: John Ferlan <jferlan@redhat.com>
Reviewed-by: Jim Fehlig <jfehlig@suse.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2018-03-08 15:40:29 +00:00
Daniel P. Berrangé
464889fff8 rpc: push ref acquisition into RPC dispatch function
There's no reason why the virNetServerClientDispatchRead method needs to
acquire an extra reference on the "client" object. An extra reference is
only needed if the registered dispatch callback is going to keep hold of
the "client" for work in the background. Thus we can push reference
acquisition into virNetServerDispatchNewMessage.

Reviewed-by: John Ferlan <jferlan@redhat.com>
Reviewed-by: Jim Fehlig <jfehlig@suse.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2018-03-08 15:40:29 +00:00
Andrea Bolognani
aae262c711 qemu: Remove virQEMUCapsProcessProps()
This function was introduced in commit 41f5c2ca27 as a way
to probe the same property for multiple devices at once.

Although the resulting representation is very compact, it
doesn't provide any extra features compared to the existing
virQEMUCapsProcessStringFlags() mechanism, which is already
used for pretty much all device properties.

Drop the custom function and datatypes and start using the
standard ones instead.

Note that, in theory, the end result is not identical
because we're no longer probing properties for

  virtio-serial-pci
  virtio-9p-pci
  virtio-rng-pci
  virtio-input-host-pci
  virtio-keyboard-pci
  virtio-mouse-pci
  virtio-tablet-pci

However, chances of any of those devices being compiled
into a QEMU binary where

  virtio-balloon-pci
  virtio-blk-pci
  virtio-scsi-pci
  virtio-net-pci
  virtio-gpu-pci

are compiled out are slim enough that it doesn't make any
difference in practice, as the lack of test suite churn
shows.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
2018-03-08 16:05:47 +01:00
Andrea Bolognani
f3699636ac qemu: Ignore subsequent attempts to probe device properties
In some cases, we are probing multiple devices for the same
property and setting the corresponding capability if it's
found on any of the devices: when that happens, we can quit
early after finding the first property and avoiding a bunch
of string comparisons.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
2018-03-08 16:05:47 +01:00
Andrea Bolognani
a68ba68330 qemu: Take full advantage of conditional device property probing
Commit 4ae59411fa introduced the ability to make probing for
device properties conditional on a capability being set, but
didn't extend the use of this feature to existing devices.

This commit does the last bit of work, which results in a lot
of pointless QMP chatter no longer happening and our test suite
shrinking a fair bit.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
2018-03-08 16:05:46 +01:00
John Ferlan
4b1ec66cde qemu: Fix memory leak in qemuConnectGetAllDomainStats error path
If we return -1 on VIR_ALLOC_N failure, we leaked @vms, so
goto cleanup instead.

Signed-off-by: John Ferlan <jferlan@redhat.com>
2018-03-08 08:54:02 -05:00
Peter Krempa
6a59d6c103 conf: Replace virDomainDiskSourceEncryptionParse by an XPath query
Remove the rather bulky function in favor of an XPath query.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
2018-03-08 14:29:50 +01:00
Peter Krempa
1e6e34b144 util: storage: Sanitize parsing of disk encryption XMLs
Pass in the XPath context as we do in all other places rather than
allocating a new one.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
2018-03-08 14:29:50 +01:00
Peter Krempa
15948e6266 util: storageencryption: Refactor cleanup section in virStorageEncryptionParseXML
The function used the 'cleanup' label only in error cases. This patch
makes the code pass the cleanup label in every case and removes few
unnecessary VIR_FREEs.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
2018-03-08 14:29:50 +01:00
Peter Krempa
e7c44b3f7c conf: Replace virDomainDiskSourceAuthParse by an XPath query
Remove the rather bulky function in favor of an XPath query.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
2018-03-08 14:29:49 +01:00
Peter Krempa
183f96314d util: storage: Sanitize parsing of disk auth XMLs
Pass in the XPath context as we do in all other places rather than
allocating a new one.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
2018-03-08 14:29:49 +01:00
Peter Krempa
74942ff0b6 util: storage: Simplify error handling in virStorageAuthDefParseXML
Unify the cleanup and error paths and simplify the code flow by removing
some unnecessary variables.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
2018-03-08 14:29:49 +01:00
Christian Ehrhardt
b932ed69f6
virt-aa-helper: resolve yet to be created paths
In certain cases a xml contains paths that do not yet exist, but
are valid as qemu will create them later on - for example
vhostuser mode=server sockets.

In any such cases so far the check to virFileExists failed and due to
that the paths stayed non-resolved in regard to symlinks.

But for apparmor those non-resolved rules are non functional as they
are evaluated after resolving any symlinks.

Therefore for non-existent files and partially non-existent paths
resolve as much as possible to get valid rules.

Example:
   <interface type='vhostuser'>
       <model type='virtio'/>
       <source type='unix' path='/var/run/symlinknet' mode='server'/>
   </interface>

Got rendered as:
  "/var/run/symlinknet" rw,

But correct with "/var/run" being a symlink to "/run" is:
  "/run/symlinknet" rw,

Signed-off-by: Christian Ehrhardt <christian.ehrhardt@canonical.com>
Acked-by: Michal Privoznik <mprivozn@redhat.com>
2018-03-07 18:03:36 +01:00
Erik Skultety
87c991d51e util: mdev: Treat the 'name' sysfs attribute as optional
When commit 3545cbef moved the sysfs attribute reading logic from
_udev.c module to virmdev.c, it had to replace our udev read wrappers
with the ones available from virfile.c. The problem is that the original
logic worked correctly with udev read wrappers which don't return an
error code for a missing attribute, virfile.c readers however - not so
much. Therefore add another parameter to the macro, so we can again
accept the fact that optional attributes may be missing.

Signed-off-by: Erik Skultety <eskultet@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2018-03-07 17:31:36 +01:00
Ján Tomko
1cdc9ecebd qemu: report a nicer error when USB is disabled
If the user tries to define a domain that has

  <controller type='usb' model='none'/>

and also some USB devices, we report an error:
  error: internal error: No free USB ports

Which is technically still correct for a domain with no USB ports.

Change it to:

USB is disabled for this domain, but USB devices are present in the domain XML

https://bugzilla.redhat.com/show_bug.cgi?id=1347550
Signed-off-by: Ján Tomko <jtomko@redhat.com>
2018-03-07 14:10:46 +01:00
Michal Privoznik
c17666419b qemuDomainObjBeginJob: Don't account DESTROY job to maxQueuedJobs
When trying to destroy a domain (e.g. because we've seen EOF on
the monitor) we try to acquire QEMU_JOB_DESTROY. However, if
max_queued is set in qemu.conf this may fail and since our code
doesn't count on that we will still report domain as active even
though the qemu process is long gone. More specifically, if we've
seen EOF on the monitor, qemuProcessHandleMonitorEOF() is called
which sends MONITOR_EOF job to the event worker pool and
unregisters monitor from the event loop. The worker pool calls
processMonitorEOFEvent() which tries to set job which may fail
due to the limit as described above.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2018-03-07 12:27:03 +01:00
Bjoern Walk
a07a9146bb qemu: log the crash information for S390
Since QEMU 2.12 commit id '4ada99ade' guest crash information for
S390 is available in the QEMU monitor, e.g.:

  {
    "timestamp": {
        "seconds": 1518004739,
        "microseconds": 552563
    },
    "event": "GUEST_PANICKED",
    "data": {
        "action": "pause",
        "info": {
            "core": 0,
            "psw-addr": 1102832,
            "reason": "disabled-wait",
            "psw-mask": 562956395872256,
            "type": "s390"
        }
    }
  }

Let's log this information into the domain log file, e.g.:

    2018-02-08 13:11:26.075+0000: panic s390: core='0' psw-mask='0x0002000180000000' psw-addr='0x000000000010f146' reason='disabled-wait'

Reviewed-by: Boris Fiuczynski <fiuczy@linux.vnet.ibm.com>
Signed-off-by: Bjoern Walk <bwalk@linux.vnet.ibm.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2018-03-06 08:55:12 -05:00
Erik Skultety
b4fad8ec16 qemu: Fix comparison assignment in qemuDomainUpdateDeviceLive
Fix this common typo and assign a value rather than implicitly
type-casted comparison result. Introduced by commit b6a264e855.

Signed-off-by: Erik Skultety <eskultet@redhat.com>
2018-03-06 09:20:58 +01:00
Daniel P. Berrangé
61efbbaf94 make: split vmx driver build rules into vmx/Makefile.inc.am
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2018-03-05 17:12:01 +00:00
Daniel P. Berrangé
9cd0bdd1a1 make: split util build rules into util/Makefile.inc.am
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2018-03-05 17:12:01 +00:00
Daniel P. Berrangé
d7d96a6d14 make: split RPC build rules into rpc/Makefile.inc.am
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2018-03-05 17:12:01 +00:00
Daniel P. Berrangé
7cbca93011 make: split admin driver build rules into admin/Makefile.inc.am
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2018-03-05 17:12:01 +00:00
Daniel P. Berrangé
d77f35a5ae make: split lock daemon build rules into locking/Makefile.inc.am
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2018-03-05 17:12:01 +00:00
Daniel P. Berrangé
efb021c8d8 make: split logging daemon build rules into logging/Makefile.inc.am
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2018-03-05 17:12:01 +00:00
Daniel P. Berrangé
3c1e95e6ff make: split access driver build rules into access/Makefile.inc.am
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2018-03-05 17:12:01 +00:00
Daniel P. Berrangé
95d8489ff3 make: split security driver build rules into security/Makefile.inc.am
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2018-03-05 17:12:01 +00:00
Daniel P. Berrangé
240c62ae50 make: split CPU build rules into cpu/Makefile.inc.am
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2018-03-05 17:12:01 +00:00
Daniel P. Berrangé
ed30a13c4b make: split XML conf build rules into conf/Makefile.inc.am
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2018-03-05 17:12:01 +00:00
Daniel P. Berrangé
124f06534c make: split remote driver & daemon build rules into remote/Makefile.inc.am
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2018-03-05 17:12:00 +00:00
Daniel P. Berrangé
d9da08b759 make: split storage driver build rules into storage/Makefile.inc.am
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2018-03-05 17:11:02 +00:00
Daniel P. Berrangé
d3d8b1bca8 make: split secret driver build rules into secret/Makefile.inc.am
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2018-03-05 17:09:49 +00:00
Daniel P. Berrangé
c6d59fb935 make: split nodedev driver build rules into node_device/Makefile.inc.am
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2018-03-05 17:09:48 +00:00
Daniel P. Berrangé
684388d902 make: split nwfilter driver build rules into nwfilter/Makefile.inc.am
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2018-03-05 17:09:08 +00:00
Daniel P. Berrangé
6d1d414c36 make: split network driver build rules into network/Makefile.inc.am
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2018-03-05 17:08:36 +00:00
Daniel P. Berrangé
09e771c376 make: split interface driver build rules into interface/Makefile.inc.am
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2018-03-05 17:08:35 +00:00
Jan Palus
43523d7421 make sure libvirt is linked first
so it's not affected by flags that might be passed in $(*_LIBS) like
-L/usr/lib which might result in linking against system library and
requiring incorrect version of private symbols

Signed-off-by: Jan Palus <atler@pld-linux.org>
2018-03-05 16:49:50 +00:00
Andrea Bolognani
11819aee65 conf: Assign explicit value to VIR_DOMAIN_CONTROLLER_PCI_MODEL_NAME_NONE
Pretty much any reasonable compiler would do this automatically,
but there's no harm in being explicit about it.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Laine Stump <laine@laine.org>
2018-03-05 17:29:40 +01:00
Ján Tomko
444f15adb8 conf: set postParseFailed even without ALLOW_POST_PARSE_FAIL
We allow the postParse callbacks to fail for some reasons (missing
emulator binary) when parsing the configs from /etc/libvirt.
In that case, def->postParseFailed is set to true and the post
parse callbacks are re-executed on domain startup.

However this bool was only set when virDomainDefPostParse was called
with the ALLOW_POST_PARSE_FAIL flag set. If the callback failed
again on domain startup, the bool would be reset and subsequent
startups would not attempt to reexecute the callback.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
2018-03-05 13:25:20 +01:00
Ján Tomko
dc824c6128 vboxDumpNetwork: use switch for adapterType
Also return an error when VIR_STRDUP fails.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
2018-03-05 12:57:47 +01:00
Ján Tomko
1b75e8c5fa vboxDumpNetwork: use VIR_STEAL_PTR instead of VIR_STRDUP
We can steal the strings instead of creating more copies.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
2018-03-05 12:57:47 +01:00
Ján Tomko
21f91fc5f6 vboxDumpNetwork: use a switch for attachmentType
Signed-off-by: Ján Tomko <jtomko@redhat.com>
2018-03-05 12:57:47 +01:00
Ján Tomko
0310d97ac5 vboxDumpNetwork: Use a single utf8 temp variable
Signed-off-by: Ján Tomko <jtomko@redhat.com>
2018-03-05 12:57:47 +01:00
Ján Tomko
56a3f5659a vboxDumpNetwork: Use a single utf16 variable
There is a pattern of using two temporary utf16/utf8 variables
for every value we get from VirtualBox and put in the domain
definition right away.

Reuse the same variable name to improve the chances of getting
the function on one screen.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
2018-03-05 12:57:47 +01:00
Ján Tomko
6a4b096c66 vboxDumpNetwork: use virMacAddrParseHex
Use the virMacAddrParse helper that does not require colon-separated
values instead of using extra code to format it that way.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
2018-03-05 12:57:47 +01:00
Ján Tomko
4226024bfb vboxDumpNetworks: do not allocate def->nets upfront
Use VIR_APPEND_ELEMENT instead and change the return type
to int to catch allocation errors.

This removes the need to figure out the adapter count
upfront.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
2018-03-05 12:57:47 +01:00
Ján Tomko
3b4f2924d8 vboxDumpNetworks: delete pointless comment
Signed-off-by: Ján Tomko <jtomko@redhat.com>
2018-03-05 12:57:47 +01:00
Ján Tomko
a8a2d7db67 vboxDumpNetwork: allocate the network too
Move the allocation from vboxDumpNetworks inside vboxDumpNetwork.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
2018-03-05 12:57:47 +01:00
Ján Tomko
774bedc496 vboxDumpNetworks: reduce indentation level
The 'enabled' bool is initialized to false, there is no need to nest the
conditions.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
2018-03-05 12:57:47 +01:00
Ján Tomko
d8cfda3628 vboxDumpNetwork: re-introduce this function
Split out per-adapter code from vboxDumpNetworks.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
2018-03-05 12:57:47 +01:00
Ján Tomko
8880b8723b vboxDumpNetwork: rename to vboxDumpNetworks
Free up 'vboxDumpNetwork' for dumping single network.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
2018-03-05 12:57:47 +01:00
Ján Tomko
64db711dd9 vboxDumpNetwork: add temp variable for current network
Instead of using def->nets every time, use a temporary pointer.
This will allow splitting out the per-adapter code.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
2018-03-05 12:57:47 +01:00
Ján Tomko
c94bb0427b vboxDumpSharedFolders: return a value
The allocation errors in this function are already handled by jumping
to a cleanup label.

Change the return type from void to int and return -1 on error.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
2018-03-05 12:57:47 +01:00
Ján Tomko
bfdc62e415 vboxDumpSharedFolders: remove pointless comment
Now that the functions are separate, we no longer need comment
separators.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
2018-03-05 12:57:47 +01:00
Ján Tomko
3c93a41d6b vboxDumpSharedFolders: rename non-standard label
s/sharedFoldersCleanup/cleanup/

Signed-off-by: Ján Tomko <jtomko@redhat.com>
2018-03-05 12:57:47 +01:00
Andrea Bolognani
65024c8939 src: Fix checking for clang
The check was trying to use the shell variable $CC instead of
the make variable $(CC); it also interpreted grep's return code
wrong: 1 means the provided pattern was *not* matched. As a
result, pdwtags was never run, not even when building with gcc.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
2018-03-01 17:47:54 +01:00
John Ferlan
5535856f0e conf: Fix crash in virDomainDefCompatibleDevice
Commit id 'edae027c' blindly assumed that the passed @oldDev
parameter would not be NULL when calling virDomainDeviceGetInfo;
however, commit id 'b6a264e8' passed NULL for AttachDevice
callers under the premise that there wouldn't be a device
to check/update against.

Signed-off-by: John Ferlan <jferlan@redhat.com>
2018-03-01 08:05:36 -05:00
Daniel P. Berrangé
900383f5b8 make: skip pdwtags when building with CLang
When building with CLang the structs that are emitted by pdwtags appear
in a completely different order than with GCC, which causes the
comparison against expected data to fail.

Ideally the test would not be sensitive to the ordering, because even
future GCC could cause changes, but that's not easy to fix. So for now
just skip the test when using clang.

Reviewed-by: Andrea Bolognani <abologna@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2018-02-28 17:53:23 +00:00
Nikolay Shirokovskiy
98c9c3048d vz: fix ref/unref of domain obj in vzDomainRevertToSnapshot
Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
2018-02-28 10:35:21 +01:00
Zhangzijian
f7399de11b qemu: fix memory leak of @vporttype during migration.
12 bytes in 1 blocks are definitely lost in loss record 188 of 1,145
at 0x4C2B6CD: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
by 0x5D2CD77: xmlStrndup (in /lib/x86_64-linux-gnu/libxml2.so.2.7.8)
by 0x514E137: virXMLPropString (virxml.c:506)
by 0x234F51: qemuMigrationCookieNetworkXMLParse qemu_migration.c:1001)
by 0x235FF8: qemuMigrationCookieXMLParse (qemu_migration.c:1333)
by 0x236214: qemuMigrationCookieXMLParseStr (qemu_migration.c:1372)
by 0x2365D2: qemuMigrationEatCookie (qemu_migration.c:1456)
by 0x243DBA: qemuMigrationFinish (qemu_migration.c:6381)
by 0x204032: qemuDomainMigrateFinish3 (qemu_driver.c:13228)
by 0x521CCBB: virDomainMigrateFinish3 (libvirt-domain.c:4788)
by 0x1936DE: remoteDispatchDomainMigrateFinish3 (remote.c:4580)
by 0x16DBB1: remoteDispatchDomainMigrateFinish3Helper(remote_dispatch.h:7582)

Signed-off-by: ZhangZijian <zhang.zijian@h3c.com>
2018-02-28 07:56:17 +01:00
Laine Stump
1297db7414 nwfilter: save error from DHCP snoop thread to report in main thread
A problem encountered due to a bug in libpcap was reported to the
caller as:

   An error occurred, but the cause is unknown

This was because the error had been logged in the DHCPSnoop
thread. The worker thread handling the API call to start a domain
spins up the DHCPSnoop thread which watches for dhcp packets with
libpcap, then uses virCondSignal() to notify the worker thread (which
has been waiting with virCondWait()). The worker thread knows that
there was an error (because threadStatus != THREAD_STATUS_OK), but the
error info had been stored in thread-specific storage for the other
thread, so the worker thread can only report that there was a failure,
but it doesn't know why.

The solution is to save the error that was logged (with
virErrorPreserveLast() into the object the is used to share info
between the threads, then we can set the error in the worker thread
using virErrorRestore().

In the case of the error I was looking at, this changed the "unknown"
message into:

    internal error: pcap_setfilter: can't remove kernel filter:
    Bad file descriptor

Signed-off-by: Laine Stump <laine@laine.org>
2018-02-27 12:32:46 -05:00
Daniel P. Berrangé
e1ab81b339 storage: fix sheepdog driver / test linking to avoid duplicating source
The libvirt_storage_backend_sheepdog_priv.la library depends on symbols
provided in the libvirt_driver_storage_impl.la library. As such the
latter must be listed 2nd when passed to the linker to avoid symbol
resolution problems. This mistake is being masked by the sheepdog
driver linking in a second copy of the storage driver code. Remove
this duplicate linkage of backend source and fix the test link order.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2018-02-27 14:51:12 +00:00
Daniel P. Berrangé
19d3d2633c make: fix uninstall of subdirectory data
A typo in the uninstall-data-extra rule expansion meant we just called
the install rule again, instead of the uninstall rule. While fixing
this, just inline the dependancy, since the intermediate
install-data-extra rule adds no value.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2018-02-27 14:50:57 +00:00
Nikolay Shirokovskiy
666dcb1aa2 lxc: fix rpc event leak on error path in virLXCControllerEventSend
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
2018-02-26 11:20:01 +00:00
Nikolay Shirokovskiy
8fafbf630f daemon: fix rpc event leak on error path in remoteDispatchObjectEventSend
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
2018-02-26 11:19:56 +00:00
Nikolay Shirokovskiy
68684c532a vz: build fix: handle missing switch enum cases
Ensure all enum cases are listed in switch statements, or cast away
enum type in places where we don't wish to cover all cases.

Build is broken after 67966ad51 [1].

[1] m4: enforce that all enum cases are listed in switch statements

Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
2018-02-26 11:19:52 +00:00
Nikolay Shirokovskiy
4393bc0210 vz: build fix after excluding cross driver headers
Build is broken by 5529b057 [1].

[1] cfg: forbid includes of headers in network and storage drivers again

Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
2018-02-26 11:19:48 +00:00
Michal Privoznik
9ea69808f5 qemu: Add virConnectPtr back to some migration methods
This partially reverts 82592551cb.

When migrating a domain, qemuMigrationDstPrepareAny() is called
which eventually calls qemuProcessLaunch(conn = NULL, flags =
VIR_QEMU_PROCESS_START_AUTODESTROY); But the very first thing
that qemuProcessLaunch does is check if AUTODESTROY flag is set
and @conn is not NULL. Well, it is.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
2018-02-26 11:32:27 +01:00
Michal Privoznik
61b49e387a qemuProcessLaunch: Print all arguments to debug
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
2018-02-26 11:32:14 +01:00
Michal Privoznik
ed11e9cd95 qemuMigrationSrcIsSafe: Check local storage more thoroughly
https://bugzilla.redhat.com/show_bug.cgi?id=1494454

If a domain disk is stored on local filesystem (e.g. ext4) but is
not being migrated it is very likely that domain is not able to
run on destination. Regardless of share/cache mode.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
2018-02-26 11:32:05 +01:00
Jim Fehlig
ef71caeaa8 libxl: round memory values to next 1MiB increment
libxl requires the memory sizes to be rounded to 1MiB increments.
Attempting to start a domain that violates this requirement will
fail with the marginally helpful error

2018-02-22 01:55:32.921+0000: xc: panic: xc_dom_boot.c:141: xc_dom_boot_mem_init: can't allocate low memory for domain: Out of memory
2018-02-22 01:55:32.921+0000: libxl: libxl_dom.c:671:libxl__build_dom: xc_dom_boot_mem_init failed: No such file or directory

Round the maximum and current memory values to the next 1MiB
increment when generating the libxl_domain_config object.

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
2018-02-23 15:01:27 -07:00
Daniel P. Berrangé
ddedcd0e14 make: split lxc driver build rules into lxc/Makefile.inc.am
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2018-02-23 13:14:26 +00:00
Daniel P. Berrangé
7b621870df make: split vz driver build rules into vz/Makefile.inc.am
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2018-02-23 13:14:26 +00:00
Daniel P. Berrangé
4edef9c3b3 make: split xenapi driver build rules into xenapi/Makefile.inc.am
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2018-02-23 13:14:26 +00:00
Daniel P. Berrangé
2cd876eb7f make: split xen driver build rules into xen/Makefile.inc.am
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2018-02-23 13:14:26 +00:00
Daniel P. Berrangé
ea7c61255f make: split libxl driver build rules into libxl/Makefile.inc.am
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2018-02-23 13:14:26 +00:00
Daniel P. Berrangé
cdfbb0666f make: split xenconfig driver build rules into xenconfig/Makefile.inc.am
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2018-02-23 13:14:26 +00:00
Daniel P. Berrangé
cf2c4c9e15 make: split bhyve driver build rules into bhyve/Makefile.inc.am
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2018-02-23 13:14:26 +00:00
Daniel P. Berrangé
abe060a4fa make: split qemu driver build rules into qemu/Makefile.inc.am
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2018-02-23 13:14:26 +00:00
Daniel P. Berrangé
1158bf0db1 make: split openvz driver build rules into openvz/Makefile.inc.am
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2018-02-23 13:14:26 +00:00
Daniel P. Berrangé
0ca89a95ac make: split vbox driver build rules into vbox/Makefile.inc.am
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2018-02-23 13:14:26 +00:00
Daniel P. Berrangé
af04f5c023 make: split vmware driver build rules into vmware/Makefile.inc.am
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2018-02-23 13:14:25 +00:00
Daniel P. Berrangé
253b528c3f make: split hyperv driver build rules into hyperv/Makefile.inc.am
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2018-02-23 13:14:25 +00:00
Daniel P. Berrangé
100864c042 make: split ESX driver build rules into esx/Makefile.inc.am
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2018-02-23 13:14:25 +00:00
Daniel P. Berrangé
c8da8363d2 make: split test driver build rules into test/Makefile.inc.am
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2018-02-23 13:14:25 +00:00
Daniel P. Berrangé
82ef8c49ae make: split PHyp driver build rules into phyp/Makefile.inc.am
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2018-02-23 13:14:25 +00:00
Daniel P. Berrangé
44fc16ec7f make: split UML driver build rules into uml/Makefile.inc.am
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2018-02-23 13:14:25 +00:00
Daniel P. Berrangé
1351a0f8b4 make: fix VPATH install of upstart files
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2018-02-23 11:56:25 +00:00
Jiri Denemark
edae027cfe qemu: Fix updating device with boot order
Commit v3.7.0-14-gc57f3fd2f8 prevented adding a <boot order='x'/>
element to an inactive domain with global <boot dev='...'/> element.
However, as a result of that change updating any device with boot order
would fail with 'boot order X is already used by another device', where
"another device" is in fact the device which is being updated.

To fix this we have to ignore the device which we're about to update
when checking for boot order conflicts.

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

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2018-02-23 11:52:44 +01:00
Jiri Denemark
b6a264e855 Pass oldDev to virDomainDefCompatibleDevice on device update
When calling virDomainDefCompatibleDevice to check a new device during
device update, we need to pass the original device which is going to be
updated in addition to the new device. Otherwise, the function can
report false conflicts.

The new argument is currently ignored by virDomainDefCompatibleDevice,
but this will change in the following patch.

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

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2018-02-23 11:52:44 +01:00
Jiri Denemark
e3497f3fc8 lxc: Drop useless check in live device update
Checking the new device definition makes little sense when lxc driver
does not support live device update at all.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2018-02-23 11:52:44 +01:00
Jiri Denemark
64ba7803ca qemu_hotplug: Drop dead code in net update
vm->def->nets[changeidx] can never be NULL for changeidx returned by
virDomainNetFindIdx.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2018-02-23 11:52:44 +01:00
Daniel P. Berrangé
595ecf29d2 make: fix long line in makefile that violate syntax-check rules
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2018-02-22 15:45:38 +00:00
Daniel P. Berrangé
3340f3070a make: fix another VPATH bug impacting install of sysconf files
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2018-02-22 14:54:48 +00:00
Michal Privoznik
800443f49a src: Clean *.logrotate, .aug and libvirtd.policy files on 'make clean'
Before 3f055b5997 we were doing that. However after the commit
we are leaving the files behind.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2018-02-22 14:34:16 +01:00
Daniel P. Berrangé
c2090b1189 make: fix VPATH build for libvirtd augeas check
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2018-02-22 13:33:26 +00:00
John Ferlan
c6d483cdc5 conf,qemu: Check for NULL addrs in virDomainUSBAddressEnsure
Rather than having the caller check, if the input @addrs is NULL
(e.g. priv->usbaddrs), then just return 0. This also removes the
need for ATTRIBUTE_NONNULL which only really helped if someone
passed a NULL as a parameter not if the passed parameter is NULL.

Signed-off-by: John Ferlan <jferlan@redhat.com>
2018-02-22 08:13:16 -05:00
John Ferlan
207cece6a3 conf,qemu: Check for NULL addrs in virDomainUSBAddressRelease
Rather than having the caller check, if the input @addrs is NULL
(e.g. priv->usbaddrs), then just return 0. This also removes the
need for ATTRIBUTE_NONNULL which only really helped if someone
passed a NULL as a parameter not if the passed parameter is NULL.

Signed-off-by: John Ferlan <jferlan@redhat.com>
2018-02-22 08:12:57 -05:00
Nikolay Shirokovskiy
9c61c28081 port allocator: make port range constant object
Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
2018-02-22 13:52:45 +01:00
Nikolay Shirokovskiy
5dbda5e972 port allocator: remove release functionality from set used
Let's use virPortAllocatorRelease instead of virPortAllocatorSetUsed(false).

Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
2018-02-22 13:52:45 +01:00
Nikolay Shirokovskiy
4c9c7a5ba2 port allocator: drop skip bind check flag
This flag is only used for tests. Let's instead overload bind syscall
in mocks where it is not done yet.

Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
2018-02-22 13:52:45 +01:00
Nikolay Shirokovskiy
56def261da port allocator: remove range check in release function
Range check in virPortAllocatorSetUsed is not useful anymore
when we manage ports for entire unsigned short range values.

Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
2018-02-22 13:52:45 +01:00
Nikolay Shirokovskiy
853e1542ac port allocator: remove range on manual port reserving
Range check in virPortAllocatorSetUsed is not useful anymore
when we manage ports for entire unsigned short range values.

Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
2018-02-22 13:52:45 +01:00
Nikolay Shirokovskiy
7ebc4f2a4c port allocator: make used port bitmap global
Host tcp4/tcp6 ports is a global resource thus we need to make
port accounting also global or we have issues described in [1] when
port allocator ranges of different instances are overlapped (which
is by default for qemu for example).

Let's have only one global port allocator object that take care
of the entire ports range (0 - 65535) and introduce port range object
for clients to specify desired auto allocation band.

[1] https://www.redhat.com/archives/libvir-list/2017-December/msg00600.html

Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
2018-02-22 13:52:45 +01:00
Daniel P. Berrangé
3f055b5997 daemon: move logrotate files to src/remote/
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2018-02-22 12:26:57 +00:00
Daniel P. Berrangé
21ea3828f7 daemon: move misc libvirtd policy files to src/remote/
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2018-02-22 12:26:50 +00:00
Daniel P. Berrangé
168bcca95d daemon: move configuration files to src/remote
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2018-02-22 12:26:39 +00:00
Daniel P. Berrangé
0f6260ada3 daemon: move init system files into src/remote/
Move the systemd, sysvinit, upstart and sysconfig files into the
src/remote/ directory.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2018-02-22 12:21:21 +00:00
Daniel P. Berrangé
98faaf173f daemon: move libvirtd POD manpage into src/remote/
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2018-02-22 12:21:09 +00:00
Daniel P. Berrangé
91fd3dc932 daemon: move libvirtd code into src/remote/ directory
Having a daemon/ directory makes little sense from a code structure
point of view, as 90% of the code that is built into libvirtd already
lives in the src/ directory. The virtlockd and virlogd daemons also live
entirely in src/{locking,logging} directories. This moves the source
code for libvirtd into src/remote/, alongside the client code.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2018-02-22 12:21:08 +00:00
Daniel P. Berrangé
5f998681df src: simplify sysconfig file handling in make rules
Remove lots of duplication in the sysconfig file handling, so we can
add more conf files without modifying so many places.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2018-02-22 11:30:36 +00:00
Daniel P. Berrangé
cd191ba0bb src: simplify sysv init file handling in make rules
Remove lots of duplication in the sysv init file handling, so we can
add more init files without modifying so many places.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2018-02-22 10:54:10 +00:00
Daniel P. Berrangé
3422cca648 src: simplify systemd unit file handling in make rules
Remove lots of duplication in the systemd unit file handling, so we can
add more unit files without modifying so many places.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2018-02-22 10:54:10 +00:00
Daniel P. Berrangé
ab59d3895b bhyve: add missing cases for graphics listen type
Address warning from -Wswitch-enum by adding missing cases
for graphics listen types that are not supported.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2018-02-22 09:19:51 +00:00
Jim Fehlig
c391e07eb0 libxl: add support for specifying clock offset and adjustment
libxl supports setting the domain real time clock to local time or
UTC via the localtime field of libxl_domain_build_info. Adjustment
of the clock is also supported via the rtc_timeoffset field. The
libvirt libxl driver has never supported these settings, instead
relying on libxl's default of a UTC real time clock with adjustment
set to 0.

There is at least one user that would like the ability to change
the defaults

https://www.redhat.com/archives/libvirt-users/2018-February/msg00059.html

Add support for specifying a local time clock and for specifying an
adjustment for both local time and UTC clocks. Add a test case to
verify the XML to libxl_domain_config conversion.

Local time clock and clock adjustment is already supported by the
XML <-> xl.cfg converter. What is missing is an explicit test for
the conversion. There are plenty of existing tests that all use UTC
with 0 adjustment. Hijack test-fullvirt-tsc-timer to test a local
time clock with 1 hour adjustment.

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
2018-02-21 12:28:49 -07:00
Ján Tomko
04bcc4d9ab virLogGetOutputs: remove unnecessary braces
Commit 9275def reduced the if block to one line without removing the
braces.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
2018-02-21 18:34:49 +01:00
Daniel P. Berrangé
1b6cd76ca2 xen: handle missing switch enum cases
Ensure all enum cases are listed in switch statements.

Reviewed-by: John Ferlan <jferlan@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2018-02-21 16:59:39 +00:00
Daniel P. Berrangé
46f83e5cba security: handle missing switch enum cases
Ensure all enum cases are listed in switch statements.

Reviewed-by: John Ferlan <jferlan@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2018-02-21 16:59:34 +00:00
Daniel P. Berrangé
6c84533f04 rpc: handle missing switch enum cases
Ensure all enum cases are listed in switch statements.

Reviewed-by: John Ferlan <jferlan@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2018-02-21 16:59:28 +00:00
Daniel P. Berrangé
7fef8e330d qemu: handle missing switch enum cases
Ensure all enum cases are listed in switch statements, or cast away
enum type in places where we don't wish to cover all cases.

Reviewed-by: John Ferlan <jferlan@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2018-02-21 16:59:10 +00:00
Daniel P. Berrangé
d4bf8f4150 nwfilter: handle missing switch enum cases
Ensure all enum cases are listed in switch statements, or cast away
enum type in places where we don't wish to cover all cases.

Reviewed-by: John Ferlan <jferlan@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2018-02-21 16:58:25 +00:00
Daniel P. Berrangé
017dfa27dd lxc: handle missing switch enum cases
Ensure all enum cases are listed in switch statements, or cast away
enum type in places where we don't wish to cover all cases.

Reviewed-by: John Ferlan <jferlan@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2018-02-21 16:58:17 +00:00
Daniel P. Berrangé
072579cf13 libxl: handle missing switch enum cases
Cast away enum type for libxl scheduler constants since we don't want to
cover all of them and don't want build to break when new ones are added.

Reviewed-by: John Ferlan <jferlan@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2018-02-21 16:58:03 +00:00
Daniel P. Berrangé
3b558c6b04 hyperv: handle missing switch enum cases
Ensure all enum cases are listed in switch statements. This improves
debug logging integration with openwsman.

Reviewed-by: John Ferlan <jferlan@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2018-02-21 16:57:42 +00:00
Daniel P. Berrangé
7c8f1436d0 esx: handle missing switch enum cases
Ensure all enum cases are listed in switch statements, or explicitly
cast away enum type where we don't want to list all cases.

Reviewed-by: John Ferlan <jferlan@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2018-02-21 16:57:27 +00:00
Daniel P. Berrangé
05b39a6843 conf: handle missing switch enum cases
Ensure all enum cases are listed in switch statements.

Reviewed-by: John Ferlan <jferlan@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2018-02-21 16:53:51 +00:00
Daniel P. Berrangé
9275def594 util: handle missing switch enum cases
Ensure all enum cases are listed in switch statements.

Reviewed-by: John Ferlan <jferlan@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2018-02-21 16:53:44 +00:00
Daniel P. Berrangé
3b1020ac80 util: add a virReportEnumRangeError for bad value reporting
To ensure we have standardized error messages when reporting problems
with enum values being out of a range, add virReportEnumRangeError().

   virReportEnumRangeError(virDomainState, 34);

results in a message

   "internal error: Unexpected enum value 34 for virDomainState"

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2018-02-21 16:42:34 +00:00
Daniel P. Berrangé
b7d0e27238 src: remove WITH_LIBVIRTD condition around hal/udev build
Currently building --without-libvirtd causes a failure to link the node
device driver:

node_device/.libs/libvirt_driver_nodedev_la-node_device_driver.o: In function `nodedevRegister':
/home/berrange/src/virt/libvirt/src/node_device/node_device_driver.c:649: undefined reference to `udevNodeRegister'
collect2: error: ld returned 1 exit status

because it causes us to build the core nodedev driver, but then skip the
implementations, despite udev being available.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2018-02-21 15:21:03 +00:00
Laine Stump
f565321b26 nwfilter: assure virNWFilterSnoop(Eth|Dhcp)Hdr structs don't change size
These two objects are used to access fields in actual ethernet packets
captures with libpcap, so it's essential that they don't change size
for any reason. This patch uses gnulib's verify() macro to make sure
their sizes don't change.

Signed-off-by: Laine Stump <laine@laine.org>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
2018-02-20 13:43:21 -05:00
Daniel P. Berrangé
75f4813c7d Fix build with GCC 8 new switch fallthrough warnings
GCC 8 became more fussy about detecting switch
fallthroughs. First it doesn't like it if you have
a fallthrough attribute that is not before a case
statement. e.g.

   FOO:
   BAR:
   WIZZ:
      ATTRIBUTE_FALLTHROUGH;

Is unacceptable as there's no final case statement,
so while FOO & BAR are falling through, WIZZ is
not falling through. IOW, GCC wants us to write

  FOO:
  BAR:
    ATTRIBUTE_FALLTHROUGH;
  WIZZ:

Second, it will report risk of fallthrough even if you
have a case statement for every single enum value, but
only if the switch is nested inside another switch and
the outer case statement has no final break. This is
is arguably valid because despite the fact that we have
cast from "int" to the enum typedef, nothing guarantees
that the variable we're switching on only contains values
that have corresponding switch labels. e.g.

   int domstate = 87539319;
   switch ((virDomainState)domstate) {
      ...
   }

will not match enum value, but also not raise any kind
of compiler warning. So it is right to complain about
risk of fallthrough if no default: is present.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2018-02-20 15:30:59 +00:00
Daniel P. Berrangé
a302480dcb conf: add enum constants for default controller models
The controller model is slightly unusual in that the default value is
-1, not 0. As a result the default value is not covered by any of the
existing enum cases. This in turn means that any switch() statements
that think they have covered all cases, will in fact not match the
default value at all. In the qemuDomainDeviceCalculatePCIConnectFlags()
method this has caused a serious mistake where we fallthrough from the
SCSI controller case, to the VirtioSerial controller case, and from
the USB controller case to the IDE controller case.

By adding explicit enum constant starting at -1, we can ensure switches
remember to handle the default case.

Reviewed-by: John Ferlan <jferlan@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2018-02-20 14:58:39 +00:00
Andrea Bolognani
cbd1eba8b7 qemu: Simplify modelName stringification
There's no need to perform checks before conversion, we can just
call virDomainControllerPCIModelNameTypeToString() and check the
results later on.

Since the variables involved are only used for PCI controllers,
we can declare them in the 'case' scope rather than in the
function scope to make everything a bit nicer while at it.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
2018-02-20 13:57:49 +01:00
Andrea Bolognani
35e9c02cbe qemu: Move skip for implicit PHB of pSeries guests
Performing the skip earlier will help us making the function
nicer later on. We also make the condition for the skip a bit
more precise, though that'a more for self-documenting purposes
and doesn't change anything in practice.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
2018-02-20 13:44:18 +01:00
Andrea Bolognani
3424de6288 qemu: Move 'done' label in qemuBuildControllerDevStr()
Even when we skip part of the processing, we still want error
checking on the buffer.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
2018-02-20 13:32:22 +01:00
Michal Privoznik
82e43ae164 storage_conf: Make virStorageAuthDefFormat return void
This function returns nothing but zero. Therefore it makes no
sense to have it returning an integer.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
2018-02-20 13:06:22 +01:00
Michal Privoznik
4e657f2ae2 virDomainDiskSourceFormatInternal: Avoid leaking @childBuf
If formatting of storage encryption or private data fails we must
jump to the error label instead of returning immediately
otherwise @attrBuf and @childBuf might be leaked.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
2018-02-20 13:06:22 +01:00
Laine Stump
e62cb4a9b7 conf: move 'generated' member from virMacAddr to virDomainNetDef
Commit 7e62c4cd26 (first appearing in libvirt-3.9.0 as a resolution
to rhbz #1343919) added a "generated" attribute to virMacAddr that was
set whenever a mac address was auto-generated by libvirt. This
knowledge was used in a single place - when trying to match a NetDef
from the Domain to Delete with user-provided XML. Since the XML parser
always auto-generates a MAC address for NetDefs when none is provided,
it was previously impossible to make a search where the MAC address
isn't significant, but the addition of the "generated" attribute made
it possible for the search function to ignore auto-generated MACs.

This implementation had a problem though - it was adding a field to a
"low level" struct - virMacAddr - which is used in other places with
the assumption that it contains exactly a 6 byte MAC address and
nothing else. In particular, virNWFilterSnoopEthHdr uses virMacAddr as
part of the definition of an ethernet packet header, whose layout must
of course match an actual ethernet packet. Adding the extra bools into
virNWFilterSnoopEthHdr caused the nwfilter driver's "IP discovery via
DHCP packet snooping" functionality to mysteriously stop working.

In order to fix that behavior, and prevent potential future similar
odd behavior, this patch moves the "generated" member out of
virMacAddr (so that it is again really is just a MAC address) into
virDomainNetDef, and sets it only when virDomainNetGenerateMAC() is
called from virDomainNetDefParseXML() (which is the only time we care
about it).

Resolves: https://bugzilla.redhat.com/1529338

(It should also be applied to any maintenance branch that applies
commit 7e62c4cd26 and friends to resolve
https://bugzilla.redhat.com/1343919)

Signed-off-by: Laine Stump <laine@laine.org>
2018-02-19 13:15:00 -05:00
Daniel P. Berrangé
ffb7954f88 qemu: rename migration APIs to include Src or Dst in their name
It is very difficult while reading the migration code trying to
understand whether a particular function is being called on the src side
or the dst side, or either. Putting "Src" or "Dst" in the method names will
make this much more obvious. "Any" is used in a few helpers which can be
called from both sides.

Reviewed-by: John Ferlan <jferlan@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2018-02-19 15:47:37 +00:00
Peter Krempa
8f5133f99e qemu: blockcopy: Add check for bandwidth
QEMU code does not work well with too big numbers on the JSON monitor so
our monitor code supports sending only numbers up to LLONG_MAX. Avoid a
weird error message by limiting the size of the 'bandwidth' parameter
for block copy.

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

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
2018-02-19 15:25:00 +01:00
Andrea Bolognani
f9159efec8 bhyve: Fix build
Commit 2d43f0a2dc dropped virDomainDiskTranslateSourcePool()'s
first argument but failed to update callers in the bhyve driver.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
2018-02-19 14:22:07 +01:00
Daniel P. Berrangé
fb9557ddc1 qemu: don't export migration job APIs
These APIs are not required anywhere outside the migration code so need
not be exported to the rest of the QEMU driver.

Reviewed-by: John Ferlan <jferlan@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2018-02-19 11:12:39 +00:00
Daniel P. Berrangé
82592551cb qemu: remove virConnectPtr in some migration methods
The qemuMigrationPrecreateStorage method needs a connection
to access the storage driver. Instead of passing it around,
open it at time of use.

Reviewed-by: John Ferlan <jferlan@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2018-02-19 11:12:16 +00:00
Daniel P. Berrangé
a967615c4b qemu: remove virConnectPtr from some more startup code paths
There's a few places in startup code paths which pass around a
virConnectPtr which is no longer required. Specifically, the
qemuProcessStart() method now only requires a non-NULL connection if
autodestroy is requested.

Reviewed-by: John Ferlan <jferlan@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2018-02-19 11:11:47 +00:00
Daniel P. Berrangé
6678a44777 qemu: stop passing in virConnectPtr for looking up networks
When setting up graphics, we sometimes need to resolve networks,
requiring the caller to pass in a virConnectPtr, except sometimes they
pass in NULL. Use virGetConnectNetwork() to acquire the connection to
the network driver when it is needed.

Reviewed-by: John Ferlan <jferlan@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2018-02-19 11:11:47 +00:00
Daniel P. Berrangé
6ea0ae9619 qemu: don't pass virConnectPtr around for secrets
During domain startup there are many places where we need to acquire
secrets. Currently code passes around a virConnectPtr, except in the
places where we pass in NULL. So there are a few codepaths where ability
to start guests using secrets will fail. Change to acquire a handle to
the secret driver when needed.

Reviewed-by: John Ferlan <jferlan@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2018-02-19 11:11:47 +00:00
Daniel P. Berrangé
2d43f0a2dc conf: stop passing virConnectPtr into virDomainDiskTranslateSourcePool
Rather than expecting callers to pass a virConnectPtr into the
virDomainDiskTranslateSourcePool() method, just acquire a connection
to the storage driver when needed.

Reviewed-by: John Ferlan <jferlan@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2018-02-19 11:11:47 +00:00
Daniel P. Berrangé
aed679da85 qemu: stop passing virConnectPtr into qemuMonitorStartCPUs
There is a long standing hack to pass a virConnectPtr into the
qemuMonitorStartCPUs method, so that when the text monitor prompts
for a disk password, we can lookup virSecretPtr objects. This causes
us to have to pass a virConnectPtr around through countless methods
up the call chain....except some places don't have any virConnectPtr
available so have always just passed NULL. We can finally fix this
disastrous design by using virGetConnectSecret() to open a connection
to the secret driver at time of use.

Reviewed-by: John Ferlan <jferlan@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2018-02-19 11:11:46 +00:00
Daniel P. Berrangé
0c63c117a2 conf: reimplement virDomainNetResolveActualType in terms of public API
Now that we have the ability to easily open connections to secondary
drivers, eg network:///system,  it is possible to reimplement the
virDomainNetResolveActualType method in terms of the public API. This
avoids the need to have the network driver provide a callback for it.

Reviewed-by: John Ferlan <jferlan@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2018-02-19 11:11:46 +00:00