Commit Graph

17539 Commits

Author SHA1 Message Date
John Ferlan
ecd45ced0e util: Move and rename virStorageAuthDefParseSecret
Move to virsecret.c and rename to virSecretLookupParseSecret. Also convert
to usage xmlNodePtr and virXMLPropString rather than virXPathString.

Signed-off-by: John Ferlan <jferlan@redhat.com>
2016-06-23 12:30:28 -04:00
John Ferlan
1eca5f6581 secret: Move virStorageSecretType and rename
Move the enum into a new src/util/virsecret.h, rename it to be
virSecretLookupType. Add a src/util/virsecret.h in order to perform
a couple of simple operations on the secret XML and virSecretLookupTypeDef
for clearing and copying.

This includes quite a bit of collateral damage, but the goal is to remove
the "virStorage*" and replace with the virSecretLookupType so that it's
easier to to add new lookups that aren't necessarily storage pool related.

Signed-off-by: John Ferlan <jferlan@redhat.com>
2016-06-23 12:30:27 -04:00
Cole Robinson
e808d3f227 storage: Remove redundant refreshPool check
Every driver provides a refreshPool impl, and many other critical
places in the code unconditionally call it without checking if
it exists, so this check is pointless
2016-06-23 09:29:54 -04:00
Cole Robinson
7490fdec92 qemu: command: Error on accel2d
qemu doesn't have any accel2d support wired up. Explicitly error
if a user tries it out, or typos the accel3d option
2016-06-23 09:29:18 -04:00
Cole Robinson
9a4703a3f0 qemu: command: Error on accel3d with non-virtio
We should be raising an error if accel3d is present for any
non-virtio video as well, incase someone tries it for say 'qxl'
2016-06-23 09:29:18 -04:00
Nikolay Shirokovskiy
6606ea96a1 qemu: make monitor command API available during async jobs
One can not issue monitor commands manually during async calls thru
designated API while this could be useful for testing/debugging purposes.
qemuDomainQemuMonitorCommand uses job of type QEMU_JOB_MODIFY and any async
call disable parallel execution of this type of job. The only state that is
changed is taint variable. AFAIU the only place we can mess is resetting
taint flag in qemuProcessStop routine under some async job. But this can not
happen thanx to both virDomainObjIsActive check in qemuDomainQemuMonitorCommand
and resetting active status in qemuProcessStop before taint flag.

  Change job type to QEMU_JOB_QUERY and thus make the API call available for
most of async jobs.

Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
2016-06-23 15:18:31 +02:00
Peter Krempa
dfeb19ff60 Allow virDomain(SG)etGuestVcpus on read-write connection only
Guest agent interaction is considered privileged.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1349272
2016-06-23 09:41:52 +02:00
Ján Tomko
8b04ce598d Add newDomain parameter to qemuDomainAssignAddresses
Pass 'true' if we are not dealing with a migration.
2016-06-23 07:45:31 +02:00
Cole Robinson
03ce132808 conf: Remove dead console compat formatting
This code was attempting to handle some implicit <console> XML
formatting for manually assembled DomainDef, since previously the
console<->serial compat copying was only done at XML parse time.

Nowadays it's done via virDomainDefPostParse ->
virDomainDefAddConsoleCompat, which all manual DomainDef builders
already call, so we can drop this workaround.
2016-06-22 20:14:31 -04:00
Jim Fehlig
76d5871648 libxl: use serial device for console when targetType is serial
When domXML contains only <console type='pty'> and no corresponding
<serial>, the console is "stolen" [1] and used as the first <serial>
device. When this "stolen" console is accessed from the libxl driver
(in libxlConsoleCallback and libxlDomainOpenConsole), check if the
targetType is VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_SERIAL, and use the
"stolen" device in def->serials[0] instead. Prior to this change,
creating a domain with input XML containing only a <console> device
and subsequently attempting to access its console with
'virsh console' would fail

error: internal error: character device <null> is not using a PTY

[1] See comments associated with virDomainDefAddConsoleCompat() in
    $LIBVIRT-SRC/src/conf/domain_conf.c:
2016-06-22 15:06:27 -06:00
Ján Tomko
a921699ad9 Use for instead of code duplication when parsing USB port
We are done if the string ends and move to another nesting
level if we find a dot.
2016-06-22 21:33:57 +02:00
Ján Tomko
0956d9b2a3 Split out USB port parsing
Make rewriting it easier.
2016-06-22 21:33:57 +02:00
Jiri Denemark
d85c3a5451 Report auto convergence throttle rate in migration stats
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-06-22 15:54:21 +02:00
Jiri Denemark
445853e1ba qemu: Implement auto convergence migration parameters
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-06-22 15:54:21 +02:00
Jiri Denemark
abaa11006f qemu: Add support for cpu throttling parameters
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-06-22 15:54:21 +02:00
Jiri Denemark
8d58952bed qemu: Introduce qemuMigrationSetParams
Several places in the code update qemuMonitorMigrationParams structure
and qemuMigrationSetParams is then used to set them all at once.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-06-22 15:54:21 +02:00
Jiri Denemark
bd3da51697 qemu: Rework qemuMonitorJSONSetMigrationParams
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-06-22 15:54:21 +02:00
Jiri Denemark
eb3e018414 qemu: Rework qemuMonitorJSONGetMigrationParams
We should not require any parameters to be present. After all we have
the *_set bools to express that some parameters were not set.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-06-22 15:54:21 +02:00
Jiri Denemark
b1473708d8 qemu: Rename qemuMonitorMigrationCompression
qemuMonitorMigrationParams is a better name for a structure which
contains various migration parameters. While doing that, we should use
full names for individual parameters.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-06-22 15:54:21 +02:00
Jiri Denemark
dbcbc86648 qemu: Decouple migration parameters from compression settings
Compression parameters are not the only migration parameters.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-06-22 15:54:21 +02:00
Jiri Denemark
5a235947c2 qemu: Make qemuMonitorSetMigrationCompression saner
Checking whether the function has anything to do is better done in the
function rather then requiring callers to do that.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-06-22 15:54:21 +02:00
Jiri Denemark
0966f0d7e0 conf: Simplify conditions in CPU parser/formatter
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-06-22 12:16:19 +02:00
Jiri Denemark
70a576899a conf: Remove redundant free in virCPUDefFree
vendor_id is (and always was) already freed in virCPUDefFreeModel.

This effectively reverts commit fb49ffc3.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-06-22 10:38:52 +02:00
Jiri Denemark
0b224cce8b qemu: Fix reference leak in qemuDomainDefPostParse
The function gets a reference on virQEMUDriverConfig which needs to be
released before returning.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-06-22 10:29:15 +02:00
Jiri Denemark
cf32a69ae1 qemu: Hide virQEMUCapsNewForBinary
Since virQEMUCapsNewForBinaryInternal was introduced,
virQEMUCapsNewForBinary is no longer used outside qemu_capabilities.c.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-06-22 10:25:53 +02:00
Peter Krempa
66acbe603b qemu: Implement virDomainSetGuestVcpus
Allow modification of specific vCPU states via the guest agent.
2016-06-22 09:26:08 +02:00
Peter Krempa
a24edc48c3 qemu: Implement virDomainGetGuestVcpus
Allow gathering available vcpu ids, their state and offlinability via
the qemu guest agent. The maximum id was chosen arbitrarily and ought
to be enough for everybody.
2016-06-22 09:26:08 +02:00
Peter Krempa
b1aa91e140 qemu: agent: Make setting of vcpus more robust
Documentation for the "guest-set-vcpus" command describes a proper
algorithm how to set vcpus. This patch makes the following changes:

- state of cpus that has not changed is not updated
- if the command was partially successful the command is re-tried with
  the rest of the arguments to get a proper error message
- code is more robust against malicious guest agent
- fix testsuite to the new semantics
2016-06-22 09:26:08 +02:00
Peter Krempa
3ebf7ca07e lib: Add API to set individual vcpu usage in the guest via guest agent
To allow finer-grained control of vcpu state using guest agent this API
can be used to individually set the state of the vCPU.

This will allow to better control NUMA enabled guests and/or test
various vCPU configurations.
2016-06-22 09:25:47 +02:00
Peter Krempa
800244faf3 lib: Add API to query guest vcpu info using guest agent
Add a rather universal API implemented via typed params that will allow
to query the guest agent for the state and possibly other aspects of
guest vcpus.
2016-06-22 08:16:31 +02:00
Peter Krempa
830f9b624d rpcgen: Add support for generating funcs returning alloc'd typed params
Since it's rather tedious to write the dispatchers for functions that
return an array of typed parameters (which are rather common) let's add
some rpcgen code to generate them.
2016-06-22 08:15:45 +02:00
John Ferlan
35f6abef6b storage: Use virSecretGetSecretString
Rather than inline code secret lookup for rbd/iscsi, use the common function.

Signed-off-by: John Ferlan <jferlan@redhat.com>
2016-06-21 14:31:19 -04:00
John Ferlan
7df631b66a storage: Create helper to set options for CreateQemuImg code
Create a helper virStorageBackendCreateQemuImgSetOptions to set either
the qemu-img -o options or the previous mechanism using -F

Signed-off-by: John Ferlan <jferlan@redhat.com>
2016-06-21 14:31:19 -04:00
John Ferlan
d12a64f310 storage: Create helper to set backing for CreateQemuImg code
Create a helper virStorageBackendCreateQemuImgSetBacking to perform the
backing store set

Signed-off-by: John Ferlan <jferlan@redhat.com>
2016-06-21 14:31:19 -04:00
John Ferlan
f6a92f8e20 storage: Adjust qemu-img switches check
Since we support QEMU 0.12 and later, checking for support of specific flags
added prior to that isn't necessary.

Thus start with the base of having the "-o options" available for the
qemu-img create option and then determine whether we have the compat
option for qcow2 files (which would be necessary up through qemu 2.0
where the default changes to compat 0.11).

Adjust test to no long check for NONE and FLAG options as well was removing
results of tests that would use that option.

Signed-off-by: John Ferlan <jferlan@redhat.com>
2016-06-21 14:31:19 -04:00
Ján Tomko
8b3f0b767e Do not call postParse with ABI_UPDATE when parsing cmdline
So far this is only useful for recalculating NUMA memory size,
which this function cannot parse.

This will let us generate USB addresses based on this flag.
2016-06-21 18:23:56 +02:00
Ján Tomko
d0e5dd376f vbox: remove duplicate macros
There is a definiton of VIR_FROM_THIS just two lines above.

The rest is defined in vbox_common.h.
2016-06-21 18:07:25 +02:00
Ján Tomko
8ddf58f5a1 Remove unused SOL_NETLINK macro
Introduced by commit d575679, unused at the time.
2016-06-21 18:07:11 +02:00
Laine Stump
df2fb9bfff conf: limit chassisNr, and busNr to a minimum value of 1, not 0
In the case of chassisNr (used to set chassis_nr of a pci-bridge
controller), 0 is reserved for / used by the pci[e]-root bus. In the
base of busNr, a value of 0 would mean that the root bus had no places
available to plug in new buses, including the pxb itself (the
documentation I wrote for pxb even noted the limit of busNr as 1.254).

NB: oddly, the "chassis" attribute, which is used for pcie-root-port
and pcie-switch-downstream-port *can* be set to 0, since it's the
combination of {chassis, slot} that needs to be unique, not chassis by
itself (and slot 0 of pcie-root is reserved, while pcie-*-port can use
*only* slot 0).

This resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1342962
2016-06-21 11:54:46 -04:00
Andrea Bolognani
f83ab972bc qemu: Fix typo pci-extender-bus -> pci-expander-bus 2016-06-21 12:48:02 +02:00
Peter Krempa
832f160247 util: Make failure to get supplementary group list for a uid non-fatal
Since introduction of the DAC security driver we've documented that
seclabels with a leading + can be used with numerical uid. This would
not work though with the rest of libvirt if the uid was not actually
used in the system as we'd fail when trying to get a list of
supplementary groups for the given uid. Since a uid without entry in
/etc/passwd (or other user database) will not have any supplementary
groups we can treat the failure to obtain them as such.

This patch modifies virGetGroupList to not report the error for missing
users and makes it return an empty list or just the group specified in
@gid.

All callers will grant less permissions to a user in case of failure of
this function and thus this change is safe.
2016-06-20 17:35:55 +02:00
Peter Krempa
c674dcccf1 util: Add option not to report errors in virGetUserEnt
In some cases it will be necessary to ignore errors reported from this
function. This allows suppressing them to avoid spamming logs.
2016-06-20 16:51:10 +02:00
Peter Krempa
0a07bf3dc5 conf: Fix label name in virDomainGraphicsListensParseXML
Use 'cleanup' since it's also used on success.
2016-06-20 16:34:43 +02:00
Peter Krempa
9982758cc5 conf: Fix memory leak in graphics XML parser
When loading status XMLs with following graphics definition:

  <graphics type='spice' port='5900' autoport='yes' listen='127.0.0.1'>
    <listen type='address' address='127.0.0.1' fromConfig='1'/>
    <image compression='off'/>
  </graphics>

libvirtd would leak a few bytes:

10 bytes in 1 blocks are definitely lost in loss record 71 of 1,127
   at 0x4C2C000: malloc (vg_replace_malloc.c:299)
   by 0x6789298: xmlStrndup (in /usr/lib64/libxml2.so.2.9.4)
   by 0x552AB0A: virXMLPropString (virxml.c:479)
   by 0x5539536: virDomainGraphicsListensParseXML (domain_conf.c:11171)
   by 0x553DD5E: virDomainGraphicsDefParseXMLSpice (domain_conf.c:11414)
   by 0x553DD5E: virDomainGraphicsDefParseXML (domain_conf.c:11749)
   by 0x5566061: virDomainDefParseXML (domain_conf.c:16939)
   by 0x556953F: virDomainObjParseXML (domain_conf.c:17348)
   by 0x556953F: virDomainObjParseNode (domain_conf.c:17513)
   by 0x5569902: virDomainObjParseFile (domain_conf.c:17532)
   by 0x5571E02: virDomainObjListLoadStatus (virdomainobjlist.c:514)
   by 0x5571E02: virDomainObjListLoadAllConfigs (virdomainobjlist.c:596)
   by 0x26E0BDC8: qemuStateInitialize (qemu_driver.c:911)
   by 0x55B1FDB: virStateInitialize (libvirt.c:770)
   by 0x122039: daemonRunStateInit (libvirtd.c:960)
2016-06-20 16:34:43 +02:00
Chen Hanxiao
a7822ba3f6 util: fix a typo
s/succcess/success

Signed-off-by: Chen Hanxiao <chenhanxiao@gmail.com>
2016-06-20 15:20:09 +02:00
Ján Tomko
dc56b3a7ce Introduce virBitmapParseUnlimited
For parsing a bitmap of an unknown size.
2016-06-20 12:09:52 +02:00
Ján Tomko
ff52e9d43a Remove separator argument from virBitmapParse
Most the callers pass 0 in one form or another, including
vircapstest which used VIR_ARCH_NONE.
2016-06-20 12:09:52 +02:00
Ján Tomko
d728689d9b Introduce virBitmapParseSeparator
This will be used for the caller that needs to specify a separator.
Currently identical to virBitmapParse.

Also change one test case to use the new function.
2016-06-20 12:09:39 +02:00
Ján Tomko
ba7c026dab Do not return number of set bits in virBitmapParse
This is only used by one caller.
2016-06-20 12:07:16 +02:00
Andrea Bolognani
dc5821d743 qemu: Don't use legacy USB for aarch64 mach-virt guests
The '-usb' option doesn't have any effect for aarch64 mach-virt
guests, so the fact that it's currently enabled by default is not
really causing any issue.

However, that might change in the future (although unlikely), and
having it as part of the QEMU command line can cause confusion to
someone looking through the process list.

Avoid it completely, like it's already happening for q35.
2016-06-20 09:58:48 +02:00
Tomasz Flendrich
ec3f07f0a7 qemu_hotplug: Use a helper variable consistently 2016-06-19 15:55:37 +02:00
Jim Fehlig
8bab1e7c05 libxl: add USB to hostdev domcapabilities
Commit 2a58ed0b added support for creating guests with USB
hostdevs. Commit fc21d10 later added support for hotplut of
USB hostdevs. Advertise support for USB hostdevs in the
domcapabilities.

In addition add the appropriate caps for USB support on
domaincapstest when libvirt is built on a Xen with
LIBXL_HAVE_PVUSB. Otherwise domaincapstest would fail i.e.
testing the wrong domain capabilities.

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
Signed-off-by: Joao Martins <joao.m.martins@oracle.com>
2016-06-17 14:25:02 -06:00
Ján Tomko
22d262c9b0 qemu: restore non-pci hostdev labels after detach
Commit 409de00 changed the logic to only match PCI devices
while moving this before Remove*HostDevice calls.

https://bugzilla.redhat.com/show_bug.cgi?id=1342874
2016-06-17 19:43:22 +02:00
Andrea Bolognani
86a68bdb0c qemu: Permit PCI-free aarch64 mach-virt guests
There has been some progress lately in enabling virtio-pci on
aarch64 guests; however, guest OS support is still spotty at best,
so most guests are going to be using virtio-mmio instead.

Currently, mach-virt guests are closely modeled after q35 guests,
and that includes always adding a dmi-to-pci-bridge that's just
impossible to get rid of. While that's acceptable (if suboptimal)
for q35, where you will always need some kind of PCI device anyway,
mach-virt guests should be allowed to avoid it.
2016-06-17 18:30:04 +02:00
Michal Privoznik
9e155e1d8a qemuDomainDetachDeviceConfig: Allow cold unplug of redirdevs
This is fairly simple. We lookup the device in the array of
devices and remove it. No magic.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2016-06-17 18:12:43 +02:00
Michal Privoznik
3441274016 qemuDomainAttachDeviceConfig: Allow redirdev coldplug
This is really simple, we just need to append the device into the
domain def and that's it.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2016-06-17 18:12:43 +02:00
Michal Privoznik
87bbb6eb2f virDomainDeviceInfoIterateInternal: Iterate through redirdevs too
This is going to be important later when we received
DEVICE_DELETED event on the qemu monitor. If we do,
virDomainDefFindDevice() is called to find the device for given
device alias in the virDomainDef tree. When we enable removal for
redirdevs we need to include them in the lookup process too.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2016-06-17 18:12:43 +02:00
Michal Privoznik
e30dbb9f98 virDomainRedirdevDef: Introduce find & remove routines
Basically, there are just two functions introduced here:
virDomainRedirdevDefFind which looks up given redirdev in domain
definition, and virDomainRedirdevDefRemove which removes the
device at given index in the array of devices.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2016-06-17 18:12:43 +02:00
Michal Privoznik
9f20b3b45e domain_conf: Validate redirdev after parsing
There's currently just one limitation: redirdevs that want to go
on USB bus require a USB controller, surprisingly.
At the same time, since I'm using virDomainDefHasUSB() in this
new validator function, it has to be moved a few lines up and
also its header needed to be changed a bit: it is now taking a
const pointer to domain def since it's not changing anything in
there.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2016-06-17 18:12:43 +02:00
Andrea Bolognani
b31b3eee85 qemu: Fix alignment in virDomainDefAddController() call 2016-06-17 13:06:52 +02:00
Jiri Denemark
5a9221b9af cpu_x86: Use signature in CPU detection code
Our current detection code uses just the number of CPU features which
need to be added/removed from the CPU model to fully describe the CPUID
data. The smallest number wins. But this may sometimes generate wrong
results as one can see from the fixed test cases. This patch modifies
the algorithm to prefer the CPU model with matching signature even if
this model results in a longer list of additional features.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-06-17 11:46:31 +02:00
Jiri Denemark
2f3ccdf01b cpu: Add Skylake-Client x86 CPU model
The CPU model was implemented in QEMU by commit f6f949e929.

The change to i7-5600U is wrong since it's a 5th generation CPU, i.e.,
Broadwell rather than Skylake, but that's just the result of our CPU
detection code (which is fixed by the following commit).

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-06-17 11:40:58 +02:00
Peter Krempa
f8d565bf86 conf: Rename virDomainDefGetMemoryActual to virDomainDefGetMemoryTotal 2016-06-17 10:39:40 +02:00
Peter Krempa
a877a1635b conf: Remove pre-calculation of initial memory size
While we need to know the difference between the total memory stored in
<memory> and the actual size not included in the possible memory modules
we can't pre-calculate it reliably. This is due to the fact that
libvirt's XML is copied via formatting and parsing the XML and the
initial memory size can be reliably calculated only when certain
conditions are met due to backwards compatibility.

This patch removes the storage of 'initial_memory' and fixes the helpers
to recalculate the initial memory size all the time from the total
memory size. This conversion is possible when we also make sure that
memory hotplug accounts properly for the update of the total memory size
and thus the helpers for inserting and removing memory devices need to
be tweaked too.

This fixes a bug where a cold-plug and cold-remove of a memory device
would increase the size reported in <memory> in the XML by the size of
the memory device. This would happen as the persistent definition is
copied before attaching the device and this would lead to the loss of
data in 'initial_memory'.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1344892
2016-06-17 10:36:41 +02:00
Peter Krempa
23690e1d74 conf: Fix perf event parser
The parser was totaly broken. Fix it by rewriting it. Add tests so that
it doesn't happen.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1346723
2016-06-17 09:35:14 +02:00
Peter Krempa
da8285c44a qemu: perf: Don't set state of first event for every other event
A bug in the code used the value of the first perf event as state for
all the mentioned one rather than extracting individual ones.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1346730
2016-06-17 09:35:14 +02:00
Jim Fehlig
e33cd67a9b xenconfig: fix conversion of <driver> to backendtype
When converting domXML to xen xl.cfg, backendtype should
not be emitted if <driver> is not specified. Moreover,
<driver name='file'/> should be converted to backendtype
qdisk, similar to handling of <driver> in libxlMakeDisk()
in libxl_conf.c.

Prior to this change, connectDomainXMLToNative would
produce incorrect xl.cfg when the input domXML contained
<driver name='file'/>

domXML:

  <disk type="file" device="disk">
    <driver name="file"/>
    <source file="/image/file/path"/>
    <target dev="xvda" bus="xen"/>
  </disk>

virsh domxml-to-native xen-xl domXML

disk = [ "format=raw,vdev=xvda,access=rw,backendtype=target=/image/file/path" ]

xl create xl.cfg
config parsing error in disk specification: unknown value
for backendtype: near `target=/image/file/path' in
`format=raw,vdev=xvda,access=rw,backendtype=target=/image/file/path'
2016-06-16 12:31:04 -06:00
Laine Stump
bf913385ae util: fix missing broadcast address in bridge and tap device IP addresses
Commit b3d069872c added peer address setting to the low level
virNetDevSetIPAddress() function, but ended up causing a segfault in
cases where the caller passed NULL for peer address.

Commit a3510e33d3 fixed the segfault, but managed to cause us to
skip setting the broadcast address when setting an interface's IP
address. The result is that the broadcast address is 0.0.0.0 for all
libvirt-created bridges (and interfaces in lxc containers with IP
addresses set by libvirt).

This was reported on the mailing list:

  https://www.redhat.com/archives/libvir-list/2016-June/msg00027.html

but I was too busy to investigate at the time. I found it by accident
today while refactoring virNetDevSetIPAddress(). Since this regression
is present in the 1.3.5 release, I'm sending the bugfix as a separate
patch from my larger refactoring patchset.
2016-06-16 14:27:40 -04:00
Laine Stump
d5fb8f4564 qemu: don't add pci-bridge to Q35/arm domains unless it's needed
Until now, a Q35 domain (or arm/virt, or any other domain that has a
pcie-root bus) would always have a pci-bridge added, so that there
would be a hotpluggable standard PCI slot available to plug in any PCI
devices that might be added. This patch removes the explicit add,
instead relying on the pci-bridge being auto-added during PCI address
assignment (it will add a pci-bridge if there are no free slots).

This doesn't eliminate the dmi-to-pci-bridge controller that is
explicitly added whether or not a standard PCI slot is required (and
that is almost never used as anything other than a converter between
pcie.0's PCIe slots and standard PCI). That will be done separately.
2016-06-16 13:48:25 -04:00
Laine Stump
97b215a450 qemu: don't be as insistent about adding dmi-to-pci-bridge or pci-bridge
Previously there was no way to have a Q35 domain that didn't have
these two controllers. This patch skips their creation as long as
there are some other kinds of pci controllers at index 1 and 2
(e.g. some pcie-root-port controllers).

I'm hoping that soon we won't add them at all, plugging all devices
into auto-added pcie-*-port ports instead, but in the meantime this
makes it easier to experiment with alternative bus hierarchies.
2016-06-16 13:32:11 -04:00
Chen Hanxiao
e9df53052e util: remove redundant comments
Signed-off-by: Chen Hanxiao <chenhanxiao@gmail.com>
2016-06-16 13:09:19 -04:00
Jovanka Gulicoska
41b2f108d5 storage: implement storage lifecycle event APIs
Implement storage pool event callbacks for START, STOP, DEFINE, UNDEFINED
and REFRESHED in functions when a storage pool is created/started/stopped
etc. accordingly
2016-06-16 12:22:11 -04:00
Jovanka Gulicoska
22fb4374da remote: implement storage lifecycle event APIs 2016-06-16 12:22:11 -04:00
Jovanka Gulicoska
edc1a27a5a test: implement storage lifecycle event APIs
Also includes unittests for storage pool lifecycle events API
2016-06-16 12:22:11 -04:00
Jovanka Gulicoska
dc7b849a0c conf: add storage_event handling
Add storage event handling infrastructure to storage_event.[ch], following
the network_event.[ch] pattern.
2016-06-16 12:22:11 -04:00
Jovanka Gulicoska
1328f98224 Introduce storage lifecycle event APIs
Storage pool lifecycle event API entry points for registering and deregistering
storage pool events, as well as types of events associated with storage pools.
These entry points will be used for implementing asynchronous lifecycle events.

Storage pool API:
virConnectStoragePoolEventRegisterAny
virConnectStoragePoolEventDeregisterAny
virStoragePoolEventLifecycleType which has events STARTED, STOPPED, DEFINED,
UNDEFINED, and REFRESHED
2016-06-16 12:22:11 -04:00
Martin Kletzander
bce3d20d04 qemu: Remove useless block in processWatchdogEvent
Best viewed with -w since this is mostly just an indentation patch.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2016-06-16 18:07:43 +02:00
Martin Kletzander
0aaeff96d6 qemu: Follow coding style convention
Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2016-06-16 18:07:43 +02:00
Martin Kletzander
5e1257820f qemu: Unify automatic coredump filenames
Just create a helper for it and use it.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2016-06-16 18:07:43 +02:00
John Ferlan
f0fe184fb9 qemu: Add cfg pointer to various command line helpers
Soon at least one of them will need to grab something out of the
qemu config structure

Signed-off-by: John Ferlan <jferlan@redhat.com>
2016-06-16 11:57:45 -04:00
John Ferlan
7d49f2c199 qemu: Make qemuBuildShmemBackendStr private
It's not used externally anywhere else

Signed-off-by: John Ferlan <jferlan@redhat.com>
2016-06-16 11:57:45 -04:00
Martin Kletzander
ab74f60a36 qemu: Shorten domain name for watchdog coredump
Similarly to commit d294f6b0df, if the name is long enough, the
filename can be longer than filesystem's limit.

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

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2016-06-16 16:01:14 +02:00
Cole Robinson
e6001cc557 qemu: migration: use consistent error message
The other two DomainHasBlockJob usage error messages don't contain
'an', so unify things to save translators some effort. Dropping
the 'an' is closer to the sentence structure in the errors from
qemuDomainDiskBlockJobIsActive as well
2016-06-16 09:52:51 -04:00
Cole Robinson
b732704f49 qemu: More usage of qemuDomainDiskBlockJobIsActive
qemuDomainDiskBlockJobIsActive already checks if a disk has a
blockjob, and if so, raises an error
2016-06-16 09:52:51 -04:00
John Ferlan
55be2920c3 util: Fix broken syntax-check
Commit id '743db933' broke at least one syntax check rule regard open/close
braces and perhaps more with spacing.  Just remove the braces
2016-06-16 06:17:58 -04:00
yuelongguang
743db933ed add default mapping of credentials to machine
In the auth config file, it is currently required to have
an entry for each hostname to connect to, eg

  [auth-libvirt-prod1.example.com]
  credentials=prod

This is inconvenient when there are large numbers of machines
all with the same credentials. Add support for a default
entry:

  [auth-default]
  credentials=prod
2016-06-16 10:36:46 +01:00
Nikolay Shirokovskiy
475835e38b vz: get rid of unused home state variable in private domain obj
Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
2016-06-15 16:24:28 +02:00
Ján Tomko
b9df355592 maint: remove whitespace from closing parentheses
To allow tightening syntax check.
2016-06-15 15:07:47 +02:00
Ján Tomko
ca773b2fe2 vbox: reformat multi-line error reports
Put the comma on the first line.
2016-06-15 15:07:47 +02:00
Michal Privoznik
8ce58b0081 virHostCPUGetInfo: Fix build on non-Unix like systems
This function is plenty of ifdefs providing implementations for
Linux, *BSD and OS-X. However, if we are being build for any
other architecture, all that's left behind by preprocessor is
just a error reporting call and return of -1. In that case,
passed arguments are unused:

../../src/util/virhostcpu.c: In function 'virHostCPUGetInfo':
../../src/util/virhostcpu.c:966:33: error: unused parameter 'cpus' [-Werror=unused-parameter]
                   unsigned int *cpus,
                                 ^~~~

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2016-06-15 09:44:46 +02:00
Chunyan Liu
44c99f2500 Add conversion of domxml USB config to/from xl.cfg
xl.cfg:
usbdev = [ "hostbus=1,hostaddr=3" ]

usb.xml:
  <hostdev mode='subsystem' type='usb' managed='no'>
    <source>
      <address bus='1' device='3'/>
    </source>
  </hostdev>

Signed-off-by: Chunyan Liu <cyliu@suse.com>
Signed-off-by: Jim Fehlig <jfehlig@suse.com>
2016-06-14 14:33:15 -06:00
Chunyan Liu
fc21d1065b libxl: support hotplug USB host device
Support hot attach/detach a USB host device to guest.
Currently libxl only supports xen PV guest, and only
supports specifying USB host device by 'bus number'
and 'device number', for example:

 usb.xml:
    <hostdev mode='subsystem' type='usb' managed='no'>
      <source>
        <address bus='1' device='3'/>
      </source>
    </hostdev>
 #xl attach-device dom usb.xml
 #xl detach-device dom usb.xml

Signed-off-by: Chunyan Liu <cyliu@suse.com>
Signed-off-by: Jim Fehlig <jfehlig@suse.com>
2016-06-14 14:26:09 -06:00
Chunyan Liu
2a58ed0bce libxl: support creating guest with USB hostdev
Support creating guest with USB host device in config file.
Currently libxl only supports xen PV guest, and only supports
specifying USB host device by 'bus number' and 'device number',
for example:

    <hostdev mode='subsystem' type='usb' managed='no'>
      <source>
        <address bus='1' device='3'/>
      </source>
    </hostdev>

Signed-off-by: Chunyan Liu <cyliu@suse.com>
Signed-off-by: Jim Fehlig <jfehlig@suse.com>
2016-06-14 14:25:47 -06:00
John Ferlan
55931292c9 qemu: Refactor qemuDomainAttachChrDevice error paths
Refactor the error paths for attaching char device (it's about to be
more complicated).

Signed-off-by: John Ferlan <jferlan@redhat.com>
2016-06-14 08:41:45 -04:00
John Ferlan
d2e14efb05 caps: Add capability for tls-x509-creds
Add the capability flag and checks for the qemu object 'tls-creds-x509'

Signed-off-by: John Ferlan <jferlan@redhat.com>
2016-06-14 08:41:45 -04:00
Martin Kletzander
e8dc0e3a43 Change 1.3.6 occurrences to 2.0.0 to follow version bump
Version was bumped but documentation (and comments) didn't follow the
numbering.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2016-06-14 11:15:18 +02:00
Martin Kletzander
b842741ba4 qemu: Allow ACPI shutdown only for running domains
If the domain is not running, but for example the CPUs are stopped, the
ACPI event gets queued and resume of the domain will just shut it off.

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

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2016-06-14 11:13:03 +02:00
Martin Kletzander
a781eae8c1 qemu: Obtain job before checking if domain is live
Since obtaining a job can wait for another job to finish, the state
might change in the meantime.  And checking it more than once is
pointless.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2016-06-14 11:10:49 +02:00
Daniel P. Berrange
8264c70e0b Bump release to 2.0.0 and document release schedule & versioning
This bumps the release number of 2.0.0, to reflect the switch to
a new time based release versioning scheme. The downloads page
is updated to describe our policies for release schedules and
release version numbering

The stable release docs are changed to reflect the fact that
the stable version numbers are now just 3 digits long instead
of 4.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2016-06-14 10:59:07 +02:00
Martin Kletzander
6445ad488f qemu: Add support for zero-detection writes
Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2016-06-14 08:25:25 +02:00
Martin Kletzander
d3c784999d conf: Add support of zero-detection for disks
This option allows or disallows detection of zero-writes if it is set to
"on" or "off", respectively.  It can be also set to "unmap" in which
case it will try discarding that part of image based on the value of the
"discard" option.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2016-06-14 08:25:25 +02:00
Jim Fehlig
00bcb45d8d libxl: Add support for ovmf firmware
Populate libxl_domain_build_info struct with bios and firmware
info from virDomainLoaderDef.

Note: Currently libxl only allows specifying the type of BIOS.
For type LIBXL_BIOS_TYPE_OVMF, the firmware path is configured
when building Xen using '--with-system-ovmf='. If not specified,
LIBXL_FIRMWARE_DIR/ovmf.bin is used. In the future, Xen will
support a user-specified firmware path. See

http://lists.xenproject.org/archives/html/xen-devel/2016-03/msg01628.html

Once that work is merged into xen.git, the libvirt libxl driver
will be able to honor a user-specified path. In the meantime use
the implicit path, which is tolerable since it is advertised in
domcapabilities.

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
2016-06-13 14:13:17 -06:00
Jim Fehlig
53d98ccea7 xenconfig: support bios=ovmf xl.cfg
Add support to xenconfig for conversion of xl.cfg(5) bios config
to/from libvirt domXml <loader> config. SeaBIOS is the default
for HVM guests using upstream QEMU. ROMBIOS is the default when
using the old qemu-dm. This patch allows specifying OVMF as an
alternate firmware.

Example xl.cfg:
  bios = "ovmf"

Example domXML:
  <os>
    ...
    <loader readonly='yes' type='pflash'>/usr/lib/xen/boot/ovmf.bin</loader>
  </os>

Note that currently Xen does not support a separate nvram for
non-volatile variables.

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
2016-06-13 14:13:17 -06:00
Jim Fehlig
11567cf66f libxl: implement connectGetDomainCapabilities
Add domain capabilities for PV and HVM domains.

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
2016-06-13 14:13:17 -06:00
Jim Fehlig
cb110a67e3 libxl: introduce libxl_capabilities.{ch}
Move capabilities code out of libxl_conf.{ch} and into new
libxl_capabilities.{ch} files.

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
2016-06-13 14:13:16 -06:00
Jim Fehlig
cb5d3e9b02 libxl: add default firmwares to driver config object
Prefer firmwares specified via --with-loader-nvram configure
option. If none are specified, use the Xen-provided default
firmwares found in LIBXL_FIRMWARE_DIR.

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
2016-06-13 14:13:16 -06:00
Jim Fehlig
fda5a98e9e driver config: Introduce virFirmware object
The virQEMUDriverConfig object contains lists of
loader:nvram pairs to advertise firmwares supported by
by the driver, and qemu_conf.c contains code to populate
the lists, all of which is useful for other drivers too.

To avoid code duplication, introduce a virFirmware object
to encapsulate firmware details and switch the qemu driver
to use it.

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
2016-06-13 14:13:16 -06:00
Wang Yufei
9ac9450780 libxl: fix vm lock overwritten bug
In libxl driver we do virObjectRef in libxlDomainObjBeginJob,
If virCondWaitUntil failed, it goes to error, do virObjectUnref,
There's a chance that someone undefine the vm at the same time,
and refs unref to zero, vm is freed in libxlDomainObjBeginJob.
But the vm outside function is not Null, we do virObjectUnlock(vm).
That's how we overwrite the vm memory after it's freed. I fix it.

Signed-off-by: Wang Yufei <james.wangyufei@huawei.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2016-06-13 13:34:37 +02:00
Roman Bogorodskiy
f2f6eb2ac5 bhyve: add missing virhost(cpu|mem).h headers 2016-06-12 10:56:11 +03:00
Roman Bogorodskiy
2af0541572 hostcpu: fix build on FreeBSD
* Fix misspelt function name:
    s/virHostCPUGetStatsFreebsd/virHostCPUGetStatsFreeBSD/
 * Mark the first argument to virHostCPUGetInfo with ATTRIBUTE_UNUSED
   as it's not actually used on non-Linux
2016-06-12 10:53:23 +03:00
Roman Bogorodskiy
992f93f18a nodeinfo: fix build on non-Linux
SYSFS_SYSTEM_PATH is only defined for Linux, however it's used outside
of #ifdef __linux__ code, e.g. as the first argument to
nodeCapsInitNUMAFake().

But as this argument's value is used on Linux only, it's safe to define
SYSFS_SYSTEM_PATH to "fake" to get things built on FreeBSD.
2016-06-12 10:33:17 +03:00
Maxim Nestratov
85d54f133c vz: fix crash when parsing unexpected disk configuration
As it turned out PrlVmDev_GetStackIndex can return negative values
without reporting an error, which is incorrect but nevertheless.
After that we feed this negative index to virIndexToDiskName,
which in turn returns NULL and we set it to virDomainDiskDef.dst.
Using virDiskNameToBusDeviceIndex with a virDomainDiskDef structure
which has NULL dst field crashes.
Fix this by returning an error in prlsdkGetDiskId in such cases.

Signed-off-by: Maxim Nestratov <mnestratov@virtuozzo.com>
2016-06-11 18:21:15 +03:00
Mikhail Feoktistov
ceb5461f7b vz: implementation of domainSetUserPassword callback 2016-06-11 18:20:56 +03:00
Maxim Nestratov
f166d6449c vz: return correct result for unimplemented ChangeState actions
Map PRL_ERR_UNIMPLEMENTED to VIR_ERR_OPERATION_INVALID

Signed-off-by: Maxim Nestratov <mnestratov@virtuozzo.com>
2016-06-11 18:20:41 +03:00
Maxim Nestratov
ab753f7b50 vz: remove unused macro logPrlEventError
Signed-off-by: Maxim Nestratov <mnestratov@virtuozzo.com>
2016-06-11 18:20:24 +03:00
Nikolay Shirokovskiy
4f17e4d0a1 vz: keep subscription to performance events thru domain lifetime
The approach of subscribing on first stat API call and then waiting
for receiving of performance event from sdk to process the call originates
in times when every vz libvirt connections spawns its own sdk connection.
Thus without this waiting virsh stat call would return empty stats. Now
with single sdk connection this scheme is unnecessary complicated.

This patch subscribes to performance events on first domain appearence
and unsubscribe on its removing.

Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
Signed-off-by: Maxim Nestratov <mnestratov@virtuozzo.com>
2016-06-11 13:27:55 +03:00
Nikolay Shirokovskiy
4385b86817 vz: use consistent naming for different domain object in vz_driver.c
Naming scheme is next:

virDomainPtr domain;
virDomainObjPtr dom;

Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
2016-06-11 13:27:55 +03:00
Pavel Hrdina
13da6ff078 domain_conf: silence gcc warnings
../../src/conf/domain_conf.c:10949: error: declaration of 'socket'
shadows a global declaration [-Wshadow]

../../src/conf/domain_conf.c:24373: error: declaration of 'listen'
shadows a global declaration [-Wshadow]

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2016-06-10 19:42:54 +02:00
Maxim Nestratov
ecdff2fd89 vz: fixed build by including necessary headers
After eaf18f4c2 some functions changed their homes
Pushed under build breaking rule
2016-06-10 20:21:18 +03:00
Michal Privoznik
3668526fa6 qemuMonitorJSONAttachCharDev: Teach spicevmc
https://bugzilla.redhat.com/show_bug.cgi?id=1298070

We have the code for attaching redirdevs for ages now.
Unfortunately, our monitor code that handles talking to the qemu
process was missing a little piece of code that actually enabled
the feature.

BTW: it really is called "type" on the monitor, even though it's
called "name" on the cmd line. Don't ask.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2016-06-10 15:22:07 +02:00
Michal Privoznik
559b78d96a Export virDomainRedirdevDefFree
In the 162efa1a commit the function was introduced, but the
commit forgot to update livirt_private.syms accordingly.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2016-06-10 15:16:56 +02:00
Daniel P. Berrange
57e62ee00a libvirt-lxc: add virDomainLxcEnterCGroup API
Add the virDomainLxcEnterCGroup API to the libvirt-lxc.so
file. This method moves the calling process into the cgroups
associated with the container.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2016-06-10 11:02:53 +01:00
Daniel P. Berrange
235620463c util: add function for looking up the user shell
Add a virGetUserShell wrapper around virGetUserEnt, that
returns the shell field.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2016-06-09 18:44:52 +01:00
Daniel P. Berrange
86dd9fac0f nodeinfo: move host memory APIs out into virhostmem file
Move all APIs with a virHostMEM name prefix out into new
util/virhostmem.h & util/virhostmem.c files

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2016-06-09 18:43:18 +01:00
Daniel P. Berrange
eaf18f4c2b nodeinfo: move host CPU APIs out into virhostcpu.c file
Move all APIs with a virHostCPU name prefix out into new
util/virhostcpu.h & util/virhostcpu.c files

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2016-06-09 18:31:11 +01:00
Daniel P. Berrange
4053350bfe nodeinfo: rename all CPU APIs to have a virHostCPU prefix
In preparation for moving all the CPU related APIs out of
the nodeinfo file, give them a virHostCPU name prefix.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2016-06-09 18:08:15 +01:00
Daniel P. Berrange
dcfe37e682 nodeinfo: rename all memory APIs to have a virHostMem prefix
In preparation for moving all the memory related APIs out of
the nodeinfo file, give them a virHostMem name prefix.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2016-06-09 18:07:00 +01:00
Daniel P. Berrange
bfb412a32e nodeinfo: split CPU info retrieval out of nodeGetInfo
Instead of having platform specific code in nodeGetInfo to
fetch CPU topology, split it all out into a new method
nodeGetCPUInfo.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2016-06-09 18:05:53 +01:00
Daniel P. Berrange
3050a3f5a6 nodeinfo: remove FreeBSD specific code for getting memory
The GNULIB physmem module already provides support for
the FreeBSD platform, so there's no reason to re-implement
FreeBSD portability code in libvirt. If there are bugs in
the GNULIB code, we should fix GNULIB rather than workaround
it in libvirt.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2016-06-09 18:04:44 +01:00
Daniel P. Berrange
912813de27 nodeinfo: make nodeGetInfo() call nodeGetMemory for memory size
The nodeGetInfo() method currently has its own code for getting
memory size in KB, that basically just re-invents what nodeGetMemory
already does. Remove it and just call nodeGetMemory, converting its
result from bytes to KB, allowing removal of more platform specific
conditional code.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2016-06-09 18:03:37 +01:00
Daniel P. Berrange
08ea852c25 nodeinfo: remove sysfs_prefix from all methods
Nearly all the methods in the nodeinfo file are given a
'const char *sysfs_prefix' parameter to override the
default sysfs path (/sys/devices/system). Every single
caller passes in NULL for this, except one use in the
unit tests. Furthermore this parameter is totally
Linux-specific, when the APIs are intended to be cross
platform portable.

This removes the sysfs_prefix parameter and instead gives
a new method linuxNodeInfoSetSysFSSystemPath for use by
the test suite.

For two of the methods this hardcodes use of the constant
SYSFS_SYSTEM_PATH, since the test suite does not need to
override the path for thos methods.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2016-06-09 18:00:18 +01:00
Martin Kletzander
5f4c50d528 qemu: Yet another check for blkdeviotune values
If you want to set block device I/O tuning values that end with '_max'
and there is nothing else set, libvirt emits an error.  In particular:

  error: internal error: Unexpected error

That's an unknown error.  That is because *_max values depend on their
respective non-_max values.  QEMU even says that in the error message
sent as a response to the monitor command:

  "error": {"class": "GenericError", "desc": "bps_max/iops_max require
  corresponding bps/iops values"}

the problem was that we didn't know that and there was no check for it.
Adding such check makes sure that there will be less confused users.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2016-06-09 17:16:38 +02:00
Pavel Hrdina
93a2fb230a vnc: add support for listen type none
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2016-06-09 14:46:45 +02:00
Pavel Hrdina
c34ada0996 spice: introduce listen type none
This new listen type is currently supported only by spice graphics.
It's introduced to make it easier and clearer specify to not listen
anywhere in order to start a guest with OpenGL support.

The old way to do this was set spice graphics autoport='no' and don't
specify any ports.  The new way is to use <listen type='none'/>.  In
order to be able to migrate to old libvirt the migratable XML will be
generated without the listen element and with autoport='no'.  Also the
old configuration will be automatically converted to the this listen
type.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2016-06-09 14:44:08 +02:00
Pavel Hrdina
ffac505639 spice: introduce spice_auto_unix_socket config option
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2016-06-09 14:43:39 +02:00
Pavel Hrdina
e0c309b2dc spice: add support for listen type socket
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1335832

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2016-06-09 14:43:15 +02:00
Pavel Hrdina
61a63abfe8 qemu_capabilites: add QEMU_CAPS_SPICE_UNIX
Add a new capability to detect support of unix sockets for spice
graphics.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2016-06-09 14:43:09 +02:00
Pavel Hrdina
acc83afe33 vnc: add support for listen type 'socket'
VNC graphics already supports sockets but only via 'socket' attribute.
This patch coverts that attribute into listen type 'socket'.

For backward compatibility we need to handle listen type 'socket' and 'socket'
attribute properly to support old XMLs and new XMLs.  If both are provided they
have to match, if only one of them is provided we need to be able to parse that
configuration too.

To not break migration back to old libvirt if the socket is provided by user we
need to generate migratable XML without the listen element and use only 'socket'
attribute.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2016-06-09 14:42:48 +02:00
Pavel Hrdina
b6465e1aa4 graphics: introduce new listen type 'socket'
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2016-06-09 14:24:00 +02:00
Pavel Hrdina
c5caecab7b vnc: move generation of socket path to qemuProcessGraphicsSetupListen
This moves the socket generation if "vnc_auto_unix_socket" is set.

It also fixes a bug with this config option that we should auto-generate
socket path only if listen type is address and there is no address
specified.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2016-06-09 14:22:34 +02:00
Pavel Hrdina
17271d04e7 vnc: rename socketAutogenerated to socketFromConfig
Even though it's auto-generated it's based on qemu.conf option and listen type
address already uses "fromConfig" to carry this information.  Following commits
will convert the socket to listen element so this rename is required because
there will be also an option to get socket auto-generated independently on the
qemu.conf option.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2016-06-09 14:22:30 +02:00
Pavel Hrdina
fdff47c587 qemu_command: move websocket code into else part for address listen
There is no need to check again for vnc socket.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2016-06-09 14:22:27 +02:00
Martin Kletzander
326e5941cd qemu: Generate channel target paths on hotplug as well
Since commit 7140807917, qemu agent
channel cannot be plugged in because we won't generate its path
automatically.  Let's not only fix that, but also add tests for it so
next time it's checked for.

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

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2016-06-09 13:27:54 +02:00
Martin Kletzander
f670008b58 qemu: Move channel path generation out of command creation
Put it into separate function called qemuDomainPrepareChannel() and call
it from the new qemuProcessPrepareDomain().

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2016-06-09 13:23:15 +02:00
Jiri Denemark
877c46d8a7 cpu: Add ARAT x86 CPU feature
Implemented in QEMU by commit 28b8e4d0bf93ba176b4b7be819d537383c5a9060.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-06-09 10:16:44 +02:00
Jiri Denemark
6dd5910da7 cpu: Add x86 feature flags for CPUID leaf 0xd, sub leaf 1
This was implemented in QEMU by commit 0bb0b2d2fe7f645dda.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-06-09 10:16:44 +02:00
Jiri Denemark
4c39a448e8 cpu: Sort CPU map features on eax_in
As a side effect this changes the order of CPU features in XMLs
generated by libvirt, but that's not a big deal since the order there is
insignificant.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-06-09 10:16:44 +02:00
Jiri Denemark
177bbc672f cpu: Shorten eax_in values in CPU map
For two reasons:
- 0x00000001 is very similar to 0x80000001, but 0x01 is visually
  different
- 0x01 format is consistent with CPUID manual

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-06-09 10:16:44 +02:00
Jiri Denemark
76561efedd cpu_x86: Add full support for ecx_in CPUID parameter
This patch makes our CPUID handling code up-to-date with the current
specification found in

Intel® 64 and IA-32 Architectures Developer's Manual: Vol. 2A
http://www.intel.com/content/www/us/en/processors/architectures-software-developer-manuals.html

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-06-09 10:16:41 +02:00
Jiri Denemark
f0fd7ae122 cpu_x86: Prepare for ecx_in CPUID parameter
CPUID instruction normally takes its parameter from EAX, but sometimes
ECX is used as an additional parameter. This patch prepares the x86 CPU
driver code for the new 'ecx_in' CPUID parameter.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-06-09 10:03:38 +02:00
Jiri Denemark
a54234c37b cpu_x86: Refactor internal KVM features
The internal features are only used in explicit checks with
cpuHasFeature. Loading them into the CPU map is dangerous since the
features may accidentally be reported to users when decoding CPUID data.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-06-09 09:47:56 +02:00
Jiri Denemark
74b23a00eb cpu_ppc64: Avoid unnecessary pointer to virCPUppc64Data
virCPUData and struct ppc64_model structures contained a pointer to
virCPUppc64Data, which was not very nice since the real data were
accessible by yet another level of pointers from virCPUppc64Data.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-06-09 09:47:56 +02:00
Jiri Denemark
9ea32aecb4 cpu_x86: Avoid unnecessary pointers to virCPUx86Data
virCPUData, virCPUx86Feature, and virCPUx86Model all contained a pointer
to virCPUx86Data, which was not very nice since the real CPUID data were
accessible by yet another pointer from virCPUx86Data. Moreover, using
virCPUx86Data directly will make static definitions of internal CPU
features a bit easier.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-06-09 09:47:56 +02:00
Jiri Denemark
2a8d40f4ec qemu: Refactor qemuMonitorJSONGetCPUx86Data
This patch splits qemuMonitorJSONGetCPUx86Data in three functions:

- qemuMonitorJSONCheckCPUx86 checks if QEMU supports reporting CPUID
  features for a guest CPU

- qemuMonitorJSONParseCPUx86Features parses CPUID features from a JSON
  array

- qemuMonitorJSONGetCPUx86Data gets the requested guest CPU property
  from QOM and uses qemuMonitorJSONParseCPUx86Features to parse it

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-06-09 09:47:56 +02:00
Jiri Denemark
90f4bc34b5 cpu_x86: Rename CPUID function to eax_in
CPUID instruction normally takes its parameter from EAX, but sometimes
ECX is used as an additional parameter. Let's rename 'function' to
'eax_in' in preparation for adding 'ecx_in'.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-06-09 09:47:56 +02:00
Jiri Denemark
7ab88767a7 cpu: Detect arch when parsing CPU data
A CPU data XML file already contains the architecture, let the parser
use it to detect which CPU driver should be used to parse the rest of
the file.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-06-09 09:47:56 +02:00
Jiri Denemark
a68ab347d5 cpu_x86: Fix CPU data parser
The formatter uses /cpudata/cpuid elements and the parser should really
do the same.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-06-09 09:47:56 +02:00
Jiri Denemark
fc4ee3e674 cpu_x86: Propagate vendor to guest's virCPUData
When computing CPU data for a given guest CPU we should set CPUID vendor
bits appropriately so that we don't lose the vendor when transforming
CPU data back to XML description.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-06-09 09:47:56 +02:00
Ján Tomko
378ef3df57 Fix typo in virNetDevGetEthtoolGFeatures stub
s/ATTRIBUGE/ATTRIBUTE/

Reported-by: Olaf Hering <olaf@aepfle.de>
2016-06-09 08:45:14 +02:00
Jovanka Gulicoska
609ba3a751 node_device: Replace VIR_ERROR with standard vir*Error in state driver init 2016-06-08 10:19:32 -04:00
Ján Tomko
e4fd42d87b lxc: simplify lxcDomainGetBlkioParameters
Replace all the repetitive code by using
virDomainGetBlkioParametersAssignFromDef, similar to what commit 9f50f6e
did in the qemu driver.
2016-06-08 15:25:35 +02:00
Ján Tomko
32e6339c19 Export virDomainGetBlkioParametersAssignFromDef
Move qemuDomainGetBlkioParametersAssignFromDef into domain_conf
and export it, to allow reuse in the LXC driver.
2016-06-08 15:23:44 +02:00
Ján Tomko
e74bbe5caf Use virDomainObjGetDefs in lxcDomainGetBlkioParameters 2016-06-08 15:23:44 +02:00
Ján Tomko
f62e4f2091 Use virDomainObjGetDefs in lxcDomainSetBlkioParameters
Remove yet another usage of virDomainLiveConfigHelperMethod
along with an sa_assert that helped clang understand the code flow.
2016-06-08 15:23:44 +02:00
Ján Tomko
a4b1371803 Use virDomainObjGetDefs in lxcDomainGetMemoryParameters
Instead of virDomainLiveConfigHelperMethod.
2016-06-08 15:23:40 +02:00
Ján Tomko
c643910486 Use virDomainObjGetDefs in lxcDomainGetSchedulerParametersFlags
On LXC domain startup we have already called virDomainObjSetDefTransient
to fill vm->newDef.

There is no need to call virDomainLiveConfigHelperMethod which has the
ability to fill newDef if it's NULL.
2016-06-08 15:22:36 +02:00
Ján Tomko
1ca45c8fb5 Use virDomainObjGetDefs in lxcDomainSetSchedulerParametersFlags
On LXC domain startup we have already called virDomainObjSetDefTransient
to fill vm->newDef.

There is no need to call virDomainLiveConfigHelperMethod which has the
ability to fill newDef if it's NULL.
2016-06-08 15:22:00 +02:00
Ján Tomko
15654cc594 Use virDomainObjGetDefs in lxcDomainSetMemoryFlags
On LXC domain startup we have already called virDomainObjSetDefTransient
to fill vm->newDef.

There is no need to call virDomainLiveConfigHelperMethod which has the
ability to fill newDef if it's NULL.
2016-06-08 15:21:57 +02:00
Ján Tomko
c646cd742a lxc: rename vmdef to persistentDef
A few functions using virDomainLiveConfigHelperMethod use the generic
name 'vmdef' to point to the persistent definition.

Use persistentDef and/or persistentDefCopy to make its purpose obvious.
2016-06-08 15:20:35 +02:00
Daniel P. Berrange
6d310c9cff remote: allow TLS priority to be customized
Support reading the TLS priority from the client configuration
file via the "tls_priority" config option, eg

 $ cat $HOME/.config/libvirt/libvirt.conf
 tls_priority="NORMAL:-VERS-SSL3.0"

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2016-06-08 13:48:45 +01:00
Daniel P. Berrange
5f1837eaca Pass config file object through to driver open methods
The virConnectOpenInternal method opens the libvirt client
config file and uses it to resolve things like URI aliases.

There may be driver specific things that are useful to
store in the config file too, so rather than have them
re-parse the same file, pass the virConfPtr down to the
drivers.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2016-06-08 13:48:45 +01:00
Daniel P. Berrange
416358d99d remote: allow TLS protocol/cipher priority override in URI
Add support for a "tls_priority" URI parameter in remote
driver URIs. eg

 qemu+tls://localhost/session?tls_priority=NORMAL:-VERS-SSL3.0

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2016-06-08 13:48:45 +01:00
Daniel P. Berrange
214489f550 rpc: allow priority string to be passed to TLS context
Extend the virNetTLSContextNew* constructors to allow
the TLS priority string to be passed in, overriding the
compile time default.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2016-06-08 13:48:45 +01:00
Daniel P. Berrange
cbb2e91ecc configure: allow setting default TLS priority string
Currently libvirt calls gnutls_set_default_priority()
which on old systems resolves to "NORMAL" while new
systems it resolves to "@SYSTEM". Either way, this
is a global default that is identical across all apps.

We want to allow distros to flexibility to define a
custom default string for libvirt priority, so add
a --tls-priority=STRING  flag to configure to enable
this to be set.

It is expected that distros would use this when creating
RPM/Deb/etc packages, according to their preferred crypto
handling policies.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2016-06-08 13:48:45 +01:00
Daniel P. Berrange
20c5ded9d0 rpc: set gnutls log function at global init time
Currently we set the gnutls log function when creating a
TLS context, however, the setting is in fact global, not
per context. So we should be setting it when we first call
gnutls_global_init() instead.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2016-06-08 13:48:45 +01:00
Daniel P. Berrange
d8a8af3492 tls: remove support for gnutls 1.x.x, require 2.2.0
We need to use the gnutls_priority_set_direct method which
was not introduced until 2.1.7, so bump version to 2.2.0
which is the first stable release with it included. This
release dates from Dec 2007 so it is reasonable to ditch
support for the 1.x.x series for gnutls releases entirely.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2016-06-08 13:48:45 +01:00
Pavel Hrdina
407c6909bc qemu_process: don't print empty line if qemu exits without any error
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1335617

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2016-06-08 13:51:00 +02:00
Pavel Hrdina
c1b8d87bab qemu_monitor: rephrase error message if qemu closes monitor
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2016-06-08 13:50:31 +02:00
Ján Tomko
4702687cfb Introduce virXMLValidatorValidate
Split out the code for XML validation into a new function.
2016-06-08 09:58:54 +02:00
Ján Tomko
87ae612de9 Introduce virXMLValidatorInit
Split out all the code initializing the validator
to a separate function.
2016-06-08 09:58:54 +02:00
Ján Tomko
8657c7a12f Introduce virXMLValidatorFree
Split out the code cleaning up the validator.
2016-06-08 09:58:54 +02:00
Ján Tomko
71c68b40df Introduce virXMLValidator structure
Store all the data related to RNG validation in one structure to
allow splitting virXMLValidateAgainstSchema.
2016-06-08 09:58:54 +02:00
Peter Krempa
9cda91d6f6 qemu: process: Call disk startup policy check after cloning domain def
In commit 1e38ef72 the disk startup policy check was moved prior to the
call to virDomainObjSetDefTransient which dropped the disk from the
config rather than the def to be started which is a bug.

Additionally we'd not report the disk change event for this since the
disk aliases were not set at that point.

Finally 'volume' based disks would not work with startup policy too.

Fix it by moving it back after the definition is copied, aliases are
assigned and disk sources are translated.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1341415
2016-06-08 08:15:11 +02:00
Peter Krempa
1e467f6622 qemu: domain: Sanitize return value handling in disk presence checker
One of the functions is returning always 0 and the second one uses
unnecessary labels.
2016-06-08 08:15:11 +02:00
Peter Krempa
f392654b5e qemu: driver: Unset log file watcher after restoring a VM save file
qemuProcessStart does not unset the infrastructure that retrieves errors
from the qemu log file in case of migration. As this wasn't handled
properly in qemuDomainSaveImageStartVM we kept the logging context/fd
open for the lifetime of the VM rather than closing it after it's not
needed.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1325080
2016-06-08 08:10:54 +02:00
Philipp Hahn
fafcc64a07 xen: Also add sub-type for driver=tap2 in xen-xm
tap2 only handles 'aio', but not 'raw', which must be explicitly given:

| $ virsh domxml-to-native yyy.xml > yyy.xm
| $ xm new yyy.xm
| Error: tap:/srv/xen/xxx.img not a valid disk type
| $ sed -i -e 's/tap2:/&aio:/' yyy.xm
| $ xm new yyy.xm

Fix reading and writing "xen-xm" format for "tap2" by handling it the
same as "tap".
2016-06-07 13:59:58 -06:00
Jovanka Gulicoska
62aff792ac qemu: Replace VIR_ERROR with standard vir*Error in state driver init 2016-06-07 13:47:13 -04:00
Jovanka Gulicoska
9c9afba4c0 xen: Replace VIR_ERROR with standard vir*Error in state driver init 2016-06-07 13:47:13 -04:00
Jovanka Gulicoska
de48ee1d6c uml: Replace VIR_ERROR with standard vir*Error in state driver init 2016-06-07 13:46:34 -04:00
Peter Krempa
ecb714de53 qemu: migration: Add VM log entry on start of migration
Note the start of migration of a qemu process to the VM log file for
possible debug purposes.
2016-06-07 18:10:29 +02:00
Peter Krempa
cf3ea0769c qemu: process: Append the "shutting down" message using the new APIs
Use qemuDomainLogAppendMessage rather than attempting to open a new
logging context with file descriptors. The new approach allows to log
the message even if qemu is still running at that point which appens
during migration finish phase where qemuProcessStop is killing qemu.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1312188
2016-06-07 18:10:29 +02:00
Peter Krempa
91a6eacc8f qemu: domain: Implement helper for one-shot log entries to the VM log file
Along with the virtlogd addition of the log file appending API implement
a helper for logging one-shot entries to the log file including the
fallback approach of using direct file access.

This will be used for noting the shutdown of the qemu proces and
possibly other actions such as VM migration and other critical VM
lifecycle events.
2016-06-07 18:10:29 +02:00
Peter Krempa
78b9b85c06 log: daemon: Add remote protocol handling for the log appending API
Implement the RPC dispatcher and caller for the new API.
2016-06-07 18:10:29 +02:00
Peter Krempa
5e6143fbcc log: handler: Add new API to append to logging files
For logging one-shot entries to the VM log file it's quite a waste to
hold open the file descriptor for logging that is provided by the
current API.

This new API will be ideal for logging one-shot entries to the file
e.g. at the point when we shut the VM down rather than having to add the
whole file-descriptor infrastructure.

Additionally this will allow to add the messages even after restart of
libvirtd since virtlogd doesn't allow to obtain a regular context with
filedescriptors while the VM is still active.
2016-06-07 18:10:29 +02:00
John Ferlan
456ccc14d5 util: Perform proper virRandomBytes return value checking
Document the return value of virRandomBytes as 0 or some errno value and
then make sure all callers make the proper checks.
2016-06-07 10:18:36 -04:00
Ján Tomko
cf922bf837 Reindent virNetDevSendEthtoolIoctl 2016-06-07 14:13:11 +02:00
Ján Tomko
0a9bbe748a Reuse the socket in virNetDevGetFeatures
This speeds up node_device_udev driver startup 11x.
2016-06-07 14:13:11 +02:00
Ján Tomko
d59ca0b05f Return bool in virNetDevFeatureAvailable
Simplify the logic
2016-06-07 14:13:11 +02:00
Ján Tomko
3a7440bdc7 Split out virNetDevGetEthtoolGFeatures
Move out the code depending on HAVE_DECL_ETHTOOL_GFEATURES.
2016-06-07 14:13:11 +02:00
Ján Tomko
970af4a69f Split out virNetDevGetEthtoolFeatures
Split out the features that we probe via various ethtool commands
and ETHTOOL_GFLAGS.
2016-06-07 14:13:11 +02:00
Ján Tomko
0a7da7882d Move struct elem out of virNetDevGetFeatures
Rename struct elem to virNetDevEthtoolFeatureCmd and move it
out of the function to allow reusing it.
2016-06-07 14:13:11 +02:00
Ján Tomko
7d097b223d Reindent comment of virNetDevFeatureAvailable 2016-06-07 14:13:11 +02:00
Peter Krempa
577fb98fbd qemu: process: Allow VIR_QEMU_PROCESS_START_NEW in qemuProcessLaunch
The new flag was not added to virCheckFlags in commit '0d1c17aa' causing
a regression where VMs were not able to start.
2016-06-07 13:56:36 +02:00
John Ferlan
896c4862d5 util: Alter virCryptoEncryptData for non GNUTLS builds
Rather than intermixing the ATTRIBUTE_UNUSED - use HAVE_GNUTLS_CIPHER_ENCRYPT
for the whole function instead.
2016-06-07 07:38:25 -04:00
Ján Tomko
1fd8fc8fc1 Add nomatch filters when enumerating udev devices
Filter out some subsystems we are not interested in.
2016-06-07 13:23:22 +02:00
Ján Tomko
207a50f7cd node_device_udev: rename labels to cleanup
Instead of the custom out and out_unlock.
2016-06-07 13:23:22 +02:00
Ján Tomko
074b4888ee node_device_udev: remove unnecessary ret variables
Remove ret variables and labels from functions where there is no cleanup
to be done.
2016-06-07 13:23:22 +02:00
Peter Krempa
5972f185e1 qemu: Move check that validates 'min_guarantee' to qemuDomainDefValidate
Introduce a validation callback for qemu and move checking of
min_guarantee to the new callback.
2016-06-07 13:02:20 +02:00
Peter Krempa
18f1dda390 conf: Move validation of disk LUN device to the appropriate place
Now with the proper domain config validation infrastructure the check
can be moved to a place that doesn't make domains vanish.
2016-06-07 13:02:20 +02:00
Peter Krempa
05eab1bf9a conf: Move disk info validator to the domain conf validator
Since it will not be called from outside of conf we can unexport it too
if we move it to the appropriate place.

Test suite change is necessary since the error will be reported sooner
now.
2016-06-07 13:02:20 +02:00
Peter Krempa
d071d292ca qemu: process: Call the domain config validator when starting a new VM
To avoid duplicating all the checks when starting a fresh VM from a
possibly unchecked config, call the domain def validator.
2016-06-07 13:02:20 +02:00
Peter Krempa
0d1c17aa68 qemu: process: Convert multiple boolean args to a single flag
Validation of qemu process startup requires to know whether the process
is used for a fresh VM or whether it's reloaded from a
snapshot/migration. Pass this information in via a flag rather than
calculating it from a bunch of bools.
2016-06-07 13:02:20 +02:00
Peter Krempa
43e21b1f10 qemu: process: Unexport qemuProcessStartValidate 2016-06-07 13:02:20 +02:00
Peter Krempa
9890a7a183 conf: Add device def validation callback
Similarly to the domain definition validator add a device validator. The
change to the prototype of the domain validator is necessary as
virDomainDeviceInfoIterateInternal requires a non-const pointer.
2016-06-07 13:02:20 +02:00
Peter Krempa
0fc1fde20b conf: drop 'def' from struct virDomainDefPostParseDeviceIteratorData
It's passed to all places along with the structure.
2016-06-07 13:02:20 +02:00
Peter Krempa
b394af162a conf: Add infrastructure for adding configuration validation
Until now we weren't able to add checks that would reject configuration
once accepted by the parser. This patch adds a new callback and
infrastructure to add such checks. In this patch all the places where
rejecting a now-invalid configuration wouldn't be a good idea are marked
with a new parser flag.
2016-06-07 13:02:20 +02:00
Peter Krempa
998c9e34e6 conf: Rename VIR_DOMAIN_DEF_PARSE_VALIDATE to VIR_DOMAIN_DEF_PARSE_VALIDATE_SCHEMA
Make it obvious that the flag is controlling RNG schema validation.
2016-06-07 13:02:20 +02:00
Ján Tomko
0c8fe3d457 node_device_udev: remove yoda condition 2016-06-07 12:53:37 +02:00
Ján Tomko
29c2a9cc21 udevSetupSystemDev: return if allocation fails
There is no cleanup to be done.
2016-06-07 12:53:37 +02:00
Ján Tomko
d1d4719814 Reformat udevProcessRemoveableMedia
Remove unnecessary ret variable and return early if we have no media
to save on indentation.
2016-06-07 12:53:37 +02:00
Ján Tomko
e2859b9dcd udevProcessStorage: trim all whitespace from model and vendor
Use virTrimSpaces instead of a custom implementation.
2016-06-07 12:53:37 +02:00
Ján Tomko
cc1d0e2a0e node_device_udev: switch to using virReportError
Also use the more common "Unable to initialize mutex" string
and virReportSystemError instead of virStrerror.
2016-06-07 12:53:37 +02:00
Ján Tomko
c40ed871cc Remove PROPERTY_* constants
They are no longer used.
2016-06-07 12:53:37 +02:00
Ján Tomko
4ab526ef71 Only return two values in udevGetUintSysfsAttr
Open code the call to udev_device_get_sysattr_value
in the one place where it's needed.
2016-06-07 12:53:37 +02:00
Ján Tomko
3554492a08 Only return two values in udevGetIntSysfsAttr
Callers only check for an error or a specific integer value.
2016-06-07 12:53:37 +02:00
Ján Tomko
e545806db9 Only return two values in udevGetStringSysfsAttr
The callers only care for an error, and a missing attribute
is simply NULL.
2016-06-07 12:53:37 +02:00
Ján Tomko
470498de18 Remove extra allocation in udevGetDeviceSysfsAttr
Most of the code paths free it right after converting it to
an integer.
2016-06-07 12:53:37 +02:00
Ján Tomko
10427db779 Only return two values in udevGetUintProperty
We only care about the failure, not a missing property.
2016-06-07 12:53:37 +02:00
Ján Tomko
71402ef6f5 Only return two values in udevGetStringProperty
There is no need to differentiate between PROPERTY_FOUND
and PROPERTY_MISSING - we can just look if the string is non-NULL.
2016-06-07 12:53:37 +02:00
Martin Kletzander
3484c05ce0 qemu: Add support to QXL's max_outputs parameter
Historically, we added heads=1 to videos, but for example for qxl, we
did not reflect that on the command line.

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

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2016-06-07 12:42:54 +02:00
Martin Kletzander
6e81a1f9ef qemu: Check for qxl's max_outputs parameter
Add capabilities for both qxl and qxl-vga devices.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2016-06-07 12:40:01 +02:00
Ján Tomko
71cddab042 Rewrite disk type checking in udevProcessStorage
Error out on parsing errors and use a local const char pointer
instead of chained ifs to check whether we found a match.
2016-06-07 12:14:24 +02:00
Ján Tomko
4ccf6886c8 Fix the return value in udevKludgeStorageType
Since the switch to VIR_STRDUP this function returns 1 on success,
but the caller treats any non-zero value as failure.
2016-06-07 12:13:59 +02:00
Ján Tomko
df7291c31c udevProcessFloppy; remove unnecessary allocation
Use udevHasDeviceProperty instead of udevGetStringProperty.
We do not need to copy the string since we do not need it.

Also add braces around the if body, since the change made
syntax check complain.
2016-06-07 12:13:38 +02:00
Ján Tomko
61cafffb2f Move udevHasDeviceProperty earlier 2016-06-07 12:13:33 +02:00
Ján Tomko
0d372687eb Do not VIR_STRDUP the string in udevGetDeviceProperty
Two out of three callers free it right after converting it to a number.

Also change the comment at the beginning of the function, because
the comment inside the function told me to.
2016-06-07 12:00:36 +02:00
Ján Tomko
fde3a38e03 Remove udevStrToLong_i
Open code the error message.
2016-06-07 12:00:36 +02:00
Ján Tomko
07202bf4cf Remove udevStrToLong_ui
Remove the debug message, open code the error in the two udevGetUint
callers and use a more specific error in SCSI and PCI processing.
2016-06-07 12:00:36 +02:00
Ján Tomko
1a97fb16ae Remove udevStrToLong_ull
The wrapper adds an error message or a debug log.

Since we already log the properties we get from udev as strings,
there is no much use for the debug logs.

Open code the error message and delete the function.
2016-06-07 12:00:36 +02:00
Ján Tomko
876a5da03e Rewrite usage of StrToLong_ui in udevProcess{PCI,SCSI}
Use virStrToLong_ui instead of udevStrToLong_ui, reformat the code
and report a more specific error message.
2016-06-07 12:00:36 +02:00
Ján Tomko
3775a2e174 udevProcessSCSIHost: use STRSKIP
Instead of separating it into STRPEFIX and str + strlen.
2016-06-07 10:51:36 +02:00
Ján Tomko
170c68c4a8 udevGetDMIData: remove unused variable
A variable without use is pointless.

Remove it, since we have no use for it.
2016-06-07 10:51:36 +02:00
Ján Tomko
fa89f6c4a3 Assign node device driver private data earlier 2016-06-07 10:51:36 +02:00
Ján Tomko
c8afb4e1ec Do not call nodeStateCleanup on early initialization error
If we have not allocated driver yet, there is nothing to cleanup.
2016-06-07 10:51:36 +02:00
Ján Tomko
d85e29dd82 Reformat nodeStateCleanup
Remove the ret variable and return early if there is no driver.
2016-06-07 10:51:36 +02:00
Ján Tomko
5c88b34afa node_device_udev: initialize libpciaccess after the driver lock
This will simplify cleanup.
2016-06-07 10:51:36 +02:00
Ján Tomko
feb876660e Split out pciaccess (de)initialization
Move pci_system_init and pci_system_cleanup into separate functions,
to make the conditional compilation easier to read.
2016-06-07 10:51:36 +02:00
Ján Tomko
b2a55dfd1f Initialize ret to -1 in nodeStateInitialize
Most of the code paths had to reset it to -1 and returning 0 was
only possible if we made it to the end of the function.

Initialize it to -1 and only set it to 0 if we reach the end, as we do
in most of libvirt code.
2016-06-07 10:51:36 +02:00
Daniel P. Berrange
c0bc172383 systemd: directly notify systemd instead of using sd_notify
The sd_notify method is used to tell systemd when libvirtd
has finished starting up. All it does is send a datagram
containing the string parameter to systemd on a UNIX socket
named in the NOTIFY_SOCKET environment variable. Rather than
pulling in the systemd libraries for this, just code the
notification directly in libvirt as this is a stable ABI
from systemd's POV which explicitly allows independant
implementations:

See "Reimplementable Independently" column in the
"$NOTIFY_SOCKET Daemon Notifications" row:

https://www.freedesktop.org/wiki/Software/systemd/InterfacePortabilityAndStabilityChart/

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

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2016-06-07 09:37:57 +01:00
John Ferlan
1b5f1884a2 qemu: Move and rename qemuBuildObjectCommandlineFromJSON
Move the module from qemu_command.c to a new module virqemu.c and
rename the API to virQEMUBuildObjectCommandline.

This API will then be shareable with qemu-img and the need to build
a security object for luks support.

Signed-off-by: John Ferlan <jferlan@redhat.com>
2016-06-06 13:44:51 -04:00
John Ferlan
77ad76b615 storage: Create helper to set input for CreateQemuImg code
Create helper virStorageBackendCreateQemuImgSetInput to set the input

Signed-off-by: John Ferlan <jferlan@redhat.com>
2016-06-06 12:15:43 -04:00
John Ferlan
4c6038a35e storage: Split out a helper for encryption checks
Split out a helper from virStorageBackendCreateQemuImgCmdFromVol
to check the encryption - soon a new encryption sheriff will be
patroling and that'll mean all sorts of new checks.

Signed-off-by: John Ferlan <jferlan@redhat.com>
2016-06-06 11:41:45 -04:00
John Ferlan
a2a7f7ede8 storage: Split out setting default secret for encryption
Split the qcow setting of encryption secrets into a helper

Signed-off-by: John Ferlan <jferlan@redhat.com>
2016-06-06 11:41:45 -04:00
John Ferlan
1933b87855 util: Clean up code formatting in virstorageencryption
Bring style more in line with more recent code.

Signed-off-by: John Ferlan <jferlan@redhat.com>
2016-06-06 11:41:45 -04:00
Ján Tomko
8c40ede4a4 Do not check for domain liveness in virDomainObjSetDefTransient
Remove the live attribute and mark the definition as transient
whether the domain is runing or not.

There were only two callers left calling with live=false:
* testDomainStartState, where the domain already is active
  because we assigned vm->def->id just a few lines above the call
* virDomainObjGetPersistentDef, which now only calls
  virDomainObjSetDefTransient for an active domain
2016-06-06 08:34:22 +02:00
Ján Tomko
1dcb1dc0f9 Check if the domain is active in virDomainObjGetPersistentDef
Calling virDomainObjSetDefTransient with live=false is a no-op
on an inactive domain.

Only call it on an active domain, since this is the only place using
the live bool.
2016-06-06 08:34:22 +02:00
Ján Tomko
9b111048ad Clean up redundant usage of virDomainObjSetDefTransient
Commit 45ec297d from November 2010:
    Make state driver device hotplug/update actually transient
added virDomainObjSetDefTransient calls to the domain startup
function in several drivers.

In November 2011, commit 8866eed:
    Set aliases for LXC/UML console devices
added a call earlier in the startup function, without removing the
existing ones.

Also, in the UML driver it seems the function never did anything
useful - vm->def->id is set asynchronnously in umlNotifyEvent.
At the time of calling virDomainObjSetDefTransient with live=false,
vm->def->id was likely still -1, making the call a no-op.
2016-06-06 08:34:22 +02:00
Martin Kletzander
3470cd860d Fix building with -Og
When building using -Og, gcc sees that some variables can be used
uninitialized  It can be debatable whether it is possible with our
codeflow, but functions should be self-contained and initializations are
always good.  The return instead of goto is due to actualType being used
in the cleanup.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2016-06-03 13:26:30 +02:00
Michal Privoznik
5a72397ee1 virPerfEventIsEnabled: Don't crash on shut off domains
So imagine the following. You connect read only to a daemon and
try to fetch stats for a shut off domain, e.g.:

  virsh -r domstats $dom

but all of a sudden, virsh instead of printing the stats throws
the following error at you:

  error: Disconnected from qemu:///system due to I/O error
  error: End of file while reading data: Input/output error

The daemon crashed. This is its backtrace:

#0  0x00007fa43e3751a8 in virPerfEventIsEnabled (perf=0x0, type=VIR_PERF_EVENT_MBMT) at util/virperf.c:241
#1  0x00007fa424a9f042 in qemuDomainGetStatsPerf (driver=0x7fa3f4022a30, dom=0x7fa3f40e24c0, record=0x7fa41c000e20, maxparams=0x7fa4360b38d0, privflags=1) at qemu/qemu_driver.c:19110
#2  0x00007fa424a9f2e7 in qemuDomainGetStats (conn=0x7fa41c001b20, dom=0x7fa3f40e24c0, stats=127, record=0x7fa4360b3970, flags=1) at qemu/qemu_driver.c:19213
#3  0x00007fa424a9f672 in qemuConnectGetAllDomainStats (conn=0x7fa41c001b20, doms=0x7fa41c0017f0, ndoms=1, stats=127, retStats=0x7fa4360b3a50, flags=0) at qemu/qemu_driver.c:19303
#4  0x00007fa43e4e15f6 in virDomainListGetStats (doms=0x7fa41c0017f0, stats=0, retStats=0x7fa4360b3a50, flags=0) at libvirt-domain.c:11615

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7f28d1a38700 (LWP 16154)]
0x00007f28da4fa1a8 in virPerfEventIsEnabled (perf=0x0, type=VIR_PERF_EVENT_MBMT) at util/virperf.c:241
241         return event->enabled;

Problem is, shut off domains don't have priv->perf allocated.
Therefore if in frame #1 qemuDomainGetStatsPerf() tries to check
if perf events are enabled, NULL is passed to
virPerfEventIsEnabled() which due to some incredible
implementation dereference it. Fix this by checking whether
passed object is not NULL.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2016-06-03 10:52:16 +02:00
Michal Privoznik
89ef1589a2 Drop virPerfGetEventFd
This function is not used anywhere. Moreover, the code that would
use lives in virperf.c and therefore has access to the FD anyway.
Well, for instance virPerfReadEvent is doing just that.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2016-06-03 10:52:16 +02:00
Michal Privoznik
43395f190b virDomainChrGetDomainPtrsInternal: Return an integer
There's this problem on the recent gcc-6.1:

In file included from conf/domain_conf.c:37:0:
conf/domain_conf.c: In function 'virDomainChrPreAlloc':
conf/domain_conf.c:14109:35: error: potential null pointer dereference [-Werror=null-dereference]
     return VIR_REALLOC_N(*arrPtr, *cntPtr + 1);
                                   ^~
./util/viralloc.h:158:73: note: in definition of macro 'VIR_REALLOC_N'
 # define VIR_REALLOC_N(ptr, count) virReallocN(&(ptr), sizeof(*(ptr)), (count), \
                                                                         ^~~~~
conf/domain_conf.c: In function 'virDomainChrRemove':
conf/domain_conf.c:14133:21: error: potential null pointer dereference [-Werror=null-dereference]
     for (i = 0; i < *cntPtr; i++) {
                     ^~~~~~~

GCC basically fails to see, that the
virDomainChrGetDomainPtrsInternal will never actually return NULL
because it's never called over a domain char device with _LAST
type. But to make it shut up, lets turn this function into
returning an integer and check in the callers if a zero value
value was returned.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2016-06-03 09:15:49 +02:00
Michal Privoznik
f916194c7e virDomainFormatSchedDef: Avoid false positive NULL dereference
Okay, I admit that our code here is complex. It's not easy to
spot that NULL deref can't really happen here. So it's no wonder
that a dumb compiler fails to see all the connections and
produces the following errors:

  CC       conf/libvirt_conf_la-domain_conf.lo
conf/domain_conf.c: In function 'virDomainDefFormatInternal':
conf/domain_conf.c:22162:22: error: potential null pointer dereference [-Werror=null-dereference]
             if (sched->policy == i)
                 ~~~~~^~~~~~~~
<snip/>
cc1: all warnings being treated as errors

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2016-06-02 13:59:44 +02:00
Michal Privoznik
09258c3c82 ppc64Compute: Avoid possible NULL dereference
cpu/cpu_ppc64.c: In function 'ppc64Compute':
cpu/cpu_ppc64.c:620:27: error: potential null pointer dereference [-Werror=null-dereference]
     if (STRNEQ(guest_model->name, host_model->name)) {
                ~~~~~~~~~~~^~~
cpu/cpu_ppc64.c:620:9: note: in expansion of macro 'STRNEQ'
     if (STRNEQ(guest_model->name, host_model->name)) {
         ^~~~~~
cc1: all warnings being treated as errors

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2016-06-02 11:56:50 +02:00
Michal Privoznik
263a88806c virNetDevBridgeGet: Don't require users to virNetDevSetupControl
So far, this function has just three callers. Two of them call
virNetDevSetupControl to create a socket that we can then
optionally use for ioctl() to fetch data. However, querying sysfs
is preferred. Therefore it doesn't make much sense to require
users to set up the socket if they don't even know it will be
used in favour of sysfs. We can set up the socket iff we need to.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2016-06-02 11:35:29 +02:00
Laine Stump
93b59fcff6 network: restart dnsmasq after adding/removing txt and srv records
Although dns host records are stored in a separate configuration file
that is reread by dnsmasq when it receives a SIGHUP, the txt and srv
records are directly in the dnsmasq .conf file which can't be reread
after initial dnsmasq startup. This means that if an srv or txt record
is modified in a network config, libvirt needs to restart the dnsmasq
process rather than just sending a SIGHUP.

This was pointed out in a question in
https://bugzilla.redhat.com/show_bug.cgi?id=988718 , but no separate
BZ was filed.
2016-06-01 11:45:25 -04:00
Pavel Hrdina
de0b091ae0 QXL: fix reloading of vram64 attribute
Commit b4a5fd95 introduced vram64 attribute for QXL video device but
there were two issues.  Only function
qemuMonitorJSONUpdateVideoVram64Size should update the vram64 attribute
and also the value is in MiB, not in B.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2016-06-01 14:33:08 +02:00
Michal Privoznik
99809fd482 esxStorageVolGetXMLDesc: Lookup SCSI lun properly
So the idea is as follows: firstly we obtain a list of all the
luns, then iterate over it trying to find the one we want to work
with and after all the iterations we detect whether we have found
something. Now, the last check is broken, because it compares a
value form previous iteration, not the one we've just been
through.

Then, when computing md5 sum of lun's UUID, we use wrong variable
again. Well, @hostScsiDisk which is type of esxVI_HostScsiDisk
extends esxVI_ScsiLun type so they both have the uuid member, but
it just doesn't feel right to access the data via two different
variables in one function call.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2016-05-31 13:36:25 +02:00
Michal Privoznik
c94720f86a qemuMonitorTextGetAllBlockStatsInfo: Fix line validation
There's a bug in the function. We expect the following format for
the data we are parsing here:

  key: value

So we use strchr() to find ':' and then see if it is followed by
space. But the check that does just that is slightly incorrect.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2016-05-31 13:06:55 +02:00
Michal Privoznik
2bd61c8448 virSocketAddrIsPrivate: Work on 32bits platforms
Yet another one of those where signed int (or long int) is not
enough. And useless to as we're aiming at unsigned anyway.

../../src/util/virsocketaddr.c: In function 'virSocketAddrIsPrivate':
../../src/util/virsocketaddr.c:289:45: error: result of '192l << 24' requires 33 bits to represent, but 'long int' only has 32 bits [-Werror=shift-overflow=]
        return ((val & 0xFFFF0000) == ((192L << 24) + (168 << 16)) ||
                                             ^~
../../src/util/virsocketaddr.c:290:45: error: result of '172l << 24' requires 33 bits to represent, but 'long int' only has 32 bits [-Werror=shift-overflow=]
                (val & 0xFFF00000) == ((172L << 24) + (16  << 16)) ||
                                             ^~
cc1: all warnings being treated as errors

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2016-05-30 15:45:19 +02:00
Michal Privoznik
0628f3498c Turn 1<<31 into 1U<<31
Apparently, 1 << 31 is signed which in turn does not fit into
a signed integer variable:

../../include/libvirt/libvirt-domain.h:1881:57: error: result of '1 << 31' requires 33 bits to represent, but 'int' only has 32 bits [-Werror=shift-overflow=]
     VIR_CONNECT_GET_ALL_DOMAINS_STATS_ENFORCE_STATS = 1 << 31, /* enforce requested stats */
                                                         ^~
cc1: all warnings being treated as errors

The solution is to make it an unsigned value. I've found only two
such occurrences in our code base.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2016-05-28 13:49:14 +02:00
Katerina Koukiou
9b9d0f13d3 lxc: Fix virLXCDomainObjBeginJob position in lxcDomainSetMemoryParameters
Adjust the code to perform the virLXCDomainObjBeginJob first
and then the call virDomainLiveConfigHelperMethod.
As Ján Tomko pointed out, in virDomainLiveConfigHelperMethod,
there is a check to see if the domain is active when AFFECT_LIVE is set.
Since virLXCDomainObjBeginJob unlocks the virDomainObjPtr lock,
the domain could possibly be destroyed while we wait for the job
and the check results would no longer be valid.

Signed-off-by: Katerina Koukiou <k.koukiou@gmail.com>
2016-05-27 15:15:44 +02:00
Dawid Zamirski
3ef5e218b1 esx: do not store escaped password in esxVI_Context.
This patch fixes an issue where screenshot API call was failing when
the esx/vcenter password contains special characters such as
apostrophee. The reason for failures was that passwords were escaped
for XML and stored in esxVI_Context which was then passed to raw CURL
API calls where the password must be passed in original form to
authenticate successfully. So this patch addresses this by storing
original passwords in the esxVI_Context struct and escape only for
esxVI_Login call.
2016-05-26 18:27:55 +02:00
Andrea Bolognani
c7289cf3b5 qemu: Fix error message when PCI bridge has index <= bus
Commit ff2126225d changed the error message to be more
detailed about the failure at hand; however, while the new
error message claims that "bus must be <= index", the error
message is displayed if "idx <= addr->bus", ie. when bus
is larger than or *equal to* index.

Change the error message to report the correct constraint,
and format it in a way that mirrors the check exactly to
make it clearer to people reading the code. The new error
message reads "index must be larger than bus".

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1339900
2016-05-26 16:24:04 +02:00
Nikolay Shirokovskiy
3ba93c754b daemon: cleanup state drivers in order reverse to init order
This patch aims to fix observed crash on daemon shutdown. Main thread is in
the process of state drivers cleanup, network driver is cleaned up and
qemu driver is not yet. Meanwhile eof event from qemu process triggers
qemuProcessStop -> networkReleaseActualDevice and crash happens as
network driver is already cleaned up.

Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
2016-05-26 08:25:40 -04:00
Dawid Zamirski
f8f7440870 esx: use newer virtualHW version for 5.1+ hosts
This is because there's a known issue where ESX will refuse to attach
drives bigger than 4TB when virtualHW < 9. Therefore, to avoid that
use the higher virtualHW for hosts that support it.

https://kb.vmware.com/selfservice/microsites/search.do?language=en_US&cmd=displayKC&externalId=2054952
2016-05-26 11:47:38 +02:00
Dawid Zamirski
5b36410f37 esx: Add VMCI device for virtualHW >= 7
This patch fixes an issue where vMotion fails when VMCI device is not
present in the vmx file.
2016-05-26 11:17:06 +02:00
Dawid Zamirski
2b89f1d8f5 esx: add pciBridge devices when SCSI is used
When a SCSI controller is present, ESX adds several pciBridge devices
to vmx file. This fixes an error message where it refuses to create VM
due to not enough PCI devices available. This applies only to virtualHW
version >= 7.
2016-05-26 10:55:09 +02:00
Laine Stump
4d100c7a41 conf: permit auto-assignment of controller indexes
Hand-entering indexes for 20 PCI controllers is not as tedious as
manually determining and entering their PCI addresses, but it's still
annoying, and the algorithm for determining the proper index is
incredibly simple (in all cases except one) - just pick the lowest
unused index.

The one exception is USB2 controllers because multiple controllers in
the same group have the same index. For these we look to see if 1) the
most recently added USB controller is also a USB2 controller, and 2)
the group *that* controller belongs to doesn't yet have a controller
of the exact model we're just now adding - if both are true, the new
controller gets the same index, but in all other cases we just assign
the lowest unused index.

With this patch in place and combined with the automatic PCI address
assignment, we can define a PCIe switch with several ports like this:

  <controller type='pci' model='pcie-root-port'/>
  <controller type='pci' model='pcie-switch-upstream-port'/>
  <controller type='pci' model='pcie-switch-downstream-port'/>
  <controller type='pci' model='pcie-switch-downstream-port'/>
  <controller type='pci' model='pcie-switch-downstream-port'/>
  <controller type='pci' model='pcie-switch-downstream-port'/>
  <controller type='pci' model='pcie-switch-downstream-port'/>
  ...

These will each get a unique index, and PCI addresses that connect
them together appropriately with no pesky numbers required.
2016-05-25 15:00:25 -04:00
Laine Stump
808e16ff13 conf: make virDomainControllerFindUnusedIndex() more generally usable
Make virDomainControllerFindUnusedIndex() a global function so that it
can be used outside domain_conf.c (as well as higher up in
domain_conf.c itself)/ Also make its DomainDef arg a const* so that
functions which only have a const* to the domain can use it.
2016-05-25 15:00:25 -04:00
Laine Stump
1140b31f25 conf/qemu: make IS_USB2_CONTROLLER globally available
IS_USB2_CONTROLLER() is useful in more places aside from just when
assigning PCI addresses in QEMU, and is checking for enum values that
are all defined in conf/domain_conf.h anyway, so define it there
instead.
2016-05-25 15:00:25 -04:00
Chunyan Liu
ba56642885 libxl: add .domainInterfaceAddresses
Add .domainInterfaceAddresses so that user can have a way to
get domain interface address by 'virsh domifaddr'. Currently
it only supports '--source lease'.

Signed-off: Chunyan Liu <cyliu@suse.com>
2016-05-25 09:41:03 -06:00
Ján Tomko
5da23bbedf security: label the slic_table
Add support for the slic_table to the security drivers.
2016-05-25 17:15:21 +02:00
Ján Tomko
ea04d1a659 qemu: format SLIC ACPI table command line
<os>
  <acpi>
    <table type="slic">/path/to/acpi/table/file</table>
  </acpi>
</os>

will result in:

-acpitable sig=SLIC,file=/path/to/acpi/table/file

This option was introduced by QEMU commit 8a92ea2 in 2009.

https://bugzilla.redhat.com/show_bug.cgi?id=1327537
2016-05-25 17:15:21 +02:00
Ján Tomko
72f652da63 conf: add <acpi><table> to <os>
Add a new element to <domain> XML:
<os>
  <acpi>
    <table type="slic">/path/to/acpi/table/file</table>
  </acpi>
</os>

To supply a path to a SLIC (Software Licensing) ACPI
table blob.

https://bugzilla.redhat.com/show_bug.cgi?id=1327537
2016-05-25 17:15:21 +02:00
Peter Krempa
a5c70e58f2 qemu: Remove virDomainLiveConfigHelperMethod from qemuDomainSetSchedulerParametersFlags
This refactor also makes a distinction between the pointer to the
original definition and copied one to prevent mixups.
2016-05-25 16:59:58 +02:00
Peter Krempa
48dc930aab qemu: Remove virDomainLiveConfigHelperMethod from qemuDomainSetBlockIoTune 2016-05-25 16:59:58 +02:00
Peter Krempa
d314410fb8 qemu: Refactor qemuDomainGetSchedulerParametersFlags
Use virDomainCputune struct to store the data rather than exploding the
fields and use macros to fill the typed params.
2016-05-25 16:59:58 +02:00
Peter Krempa
e6e144689d conf: Change virDomainCputune member 'shares' to unsigned long long
cgroup functions set and get the longer type so use it everywhere
2016-05-25 16:59:58 +02:00
Peter Krempa
8bf8838fb4 qemu: Remove virDomainLiveConfigHelperMethod from qemuDomainGetSchedulerParametersFlags 2016-05-25 16:59:58 +02:00
Peter Krempa
9f50f6e288 qemu: Refactor qemuDomainGetBlkioParameters
Get rid of lots of duplicated code.
2016-05-25 16:59:58 +02:00
Peter Krempa
31b4d75877 qemu: Remove virDomainLiveConfigHelperMethod from qemuDomainGetBlkioParameters 2016-05-25 16:59:58 +02:00
Peter Krempa
b30387732a qemu: Remove virDomainLiveConfigHelperMethod from qemuDomainSetMemoryParameters 2016-05-25 16:59:58 +02:00
Peter Krempa
62a73bf631 qemu: Refactor typed params assignment in qemuDomainGetBlockIoTune
Introduce a macro to assign the parameters to avoid the for loop and
shuffle around various checks for a simpler and saner function.
2016-05-25 16:59:58 +02:00
Peter Krempa
6448356f27 qemu: Replace virDomainLiveConfigHelperMethod in qemuDomainGetBlockIoTune
Use virDomainObjGetDefs since the API guarantees that both live and
config are never set together.
2016-05-25 16:59:58 +02:00
Peter Krempa
2fde4e724e qemu: monitor: Remove 'supportMaxOptions' argument from qemuMonitorGetBlockIoThrottle
The caller is already aware that the params are missing and the
extractor is ignoring the missing ones so the parameter isn't necessary.
2016-05-25 16:59:58 +02:00
Dawid Zamirski
77298458d0 esx: use lsilogic adapter type in vol create.
ESX will refuse to attach VMDKS that have buslogic adatper type to 64bit
VMs whereas lsilogic works fine both 32bit and 64bit VMs.
2016-05-25 16:49:49 +02:00
Jim Fehlig
a1c9a81a31 libxl: default to qemu driver for network disks
Xen only supports network-based disks with the qemu (aka qdisk) driver.
Set the driverName to 'qemu' in libxlDomainDeviceDefPostParse() if
not already set. When starting a domain with network-based disks,
ensure the driverName is 'qemu'.

Resolves: https://bugzilla.opensuse.org/show_bug.cgi?id=981094
2016-05-25 08:28:22 -06:00
Peter Krempa
a09d9f5b7a qemu: driver: Allow disk update of startupPolicy/snapshot for all disks
The libvirt internal bits can be changed for disks that don't otherwise
support changing media. Remove the switch statement and allow changes of
non-source data for all disks.
2016-05-25 13:28:34 +02:00
Peter Krempa
e78794c95f qemu: driver: Move around code to avoid need to rollback
qemuDomainChangeDiskLive rolled back few changes to the disk definition
if changing of the media failed. This can be avoided by moving some code
around.
2016-05-25 13:22:36 +02:00
Shivaprasad G Bhat
cab28101ee Call qemuDomainObjEndJob when qemuCaps is null during hotplug
Signed-off-by: Shivaprasad G Bhat <sbhat@linux.vnet.ibm.com>
2016-05-25 13:15:21 +02:00
Shivaprasad G Bhat
a24cdf6cf7 Unref the cfg in qemuDomainAttachHostPCIDevice()
Signed-off-by: Shivaprasad G Bhat <sbhat@linux.vnet.ibm.com>
2016-05-25 12:24:28 +02:00
John Ferlan
cb0159df9f lxc: Fix lxcDomainDestroyFlags endjob processing
Commit id '15ccb0dbf' added job functions for the lxc driver; however,
for shutdown and nonpersistent path, the vm was removed from the domain
object list and the vm pointer cleared before the endjob.

Adjust the code to perform the endjob first and then perform the
ObjListRemove as long as the vm wasn't NULL. This follows more closely
models from qemu and libxl

Found by Coverity (FORWARD_NULL)
2016-05-25 06:02:42 -04:00
John Ferlan
fb06350021 qemu: Remove unused persistentAddrs
Based on some digital archaeology performed by jtomko, it's been determined
that the persistentAddrs variable is no longer necessary...

The variable was added by:
commit 141dea6bc7
CommitDate: 2010-02-12 17:25:52 +0000
    Add persistence of PCI addresses to QEMU

Where it was set to 0 on domain startup if qemu did not support the
QEMUD_CMD_FLAG_DEVICE capability, to clear the addresses at shutdown,
because QEMU might make up different ones next time.

As of commit f5dd58a608
CommitDate: 2012-07-11 11:19:05 +0200
    qemu: Extended qemuDomainAssignAddresses to be callable from
    everywhere.

this was broken, when the persistentAddrs = 0 assignment was moved
inside qemuDomainAssignPCIAddresses and while it pretends to check
for !QEMU_CAPS_DEVICE, its parent qemuDomainAssignAddresses is only
called if QEMU_CAPS_DEVICE is present.
2016-05-25 06:02:42 -04:00
John Ferlan
f30672d5ee qemu: Remove dead code
Since commit id '20a0fa8e' removed the QEMU_CAPS_DEVICE, Coverity notes
that it's no longer possible to have 'addrs' be NULL when checking for
a live domain since qemuDomainPCIAddressSetCreate would have jumped to
cleanup if addrs was NULL.
2016-05-25 06:02:42 -04:00
Andrea Bolognani
54f325e925 conf: nodedev: Set PCI_PHYSICAL_FUNCTION flag more carefully
Instead of setting the flag before parsing the PCI address, set
it afterwards. This ensure we can never end up in a situation
where the flag has been set but pci_dev.physical_function has
not been filled in.
2016-05-25 10:38:01 +02:00
Andrea Bolognani
fc9ba9d574 pci: Fix virPCIGetPhysicalFunction()'s callers
Commit c8b1a83605 changed the function, making it
impossible for callers to be able to tell whether a
non-negative return value means "physical function
address found and parsed correctly" or "couldn't find
corresponding physical function".

The important difference between the two being that,
in the latter case, the returned pointer is NULL and
should never, ever be dereferenced.

In order to cope with these changes, the callers
have to be updated.
2016-05-25 10:38:01 +02:00
Andrea Bolognani
063da39376 pci: Document virPCIGetPhysicalFunction() 2016-05-25 10:38:01 +02:00
Andrea Bolognani
12b28f1bf8 pci: Initialize return location in virPCIGetPhysicalFunction()
Just an extra precaution in case the function returns early
due to an OOM error.
2016-05-25 10:38:01 +02:00
Peter Krempa
72a7ff6b50 qemu: hotplug: wait for the tray to eject only for drives with a tray
Use the detected tray presence flag to trigger the tray waiting code
only if the given storage device in qemu reports to have a tray.

This is necessary as the floppy device lost it's tray as of qemu commit:

commit abb3e55b5b718d6392441f56ba0729a62105ac56
Author: Max Reitz <mreitz@redhat.com>
Date:   Fri Jan 29 20:49:12 2016 +0100

    Revert "hw/block/fdc: Implement tray status"
2016-05-25 10:15:54 +02:00
Peter Krempa
2e75da42e4 qemu: hotplug: Fix error reported when cdrom tray is locked
Commit 1fad65d49a used a really big hammer
and overwrote the error message that might be reported by qemu if the
tray is locked. Fix it by reporting the error only if no error is
currently set.

Error after commit mentioned above:
error: internal error: timed out waiting for disk tray status update

New error:
error: internal error: unable to execute QEMU command 'eject': Tray of
device 'drive-ide0-0-0' is not open
2016-05-25 10:15:54 +02:00
Peter Krempa
0aa19f35e0 qemu: hotplug: Extract code for waiting for tray eject
The code grew rather convoluted. Extract it to a separate function.
2016-05-25 10:15:54 +02:00
Peter Krempa
894dc85fd1 qemu: process: Fix and improve disk data extraction
Extract information for all disks and update tray state and source only
for removable drives. Additionally store whether a drive is removable
and whether it has a tray.
2016-05-25 10:15:54 +02:00
Peter Krempa
d9bee413ad qemu: Move and rename qemuDomainCheckEjectableMedia to qemuProcessRefreshDisks
Move it to a more sane place since it's refreshing data about disks.
2016-05-25 10:15:54 +02:00
Peter Krempa
f1690dc3d7 qemu: Extract more information about qemu drives
Extract whether a given drive has a tray and whether there is no image
inserted.

Negative logic for the image insertion is chosen so that the flag is set
only if we are certain of the fact.
2016-05-25 10:15:54 +02:00
Peter Krempa
5f963d89b1 qemu: Move struct qemuDomainDiskInfo to qemu_domain.h 2016-05-25 10:15:54 +02:00
Joao Martins
293668cd70 xenconfig: xm: check for driver on disk format
When reviewing libxl vif typename series[0] I found a bug
on xen-xm formatter where "virsh domxml-to-native xen-xm file.xml"
can lead to a NULL dereference if the disk driver isn't specified.
Fix this by checking for driver before writing/testing it down.

[0] https://www.redhat.com/archives/libvir-list/2016-April/msg01434.html

Signed-off-by: Joao Martins <joao.m.martins@oracle.com>
2016-05-24 19:19:50 -06:00
Laine Stump
002b7704ff lxc: support <interface type='ethernet'>
This is identical to type='bridge', but without the "connect to a
bridge" part, so it can be handled by using the same functions (and
often even the same cases in switch statements), after renaming
virLXCProcessSetupInterfaceBridged() to virLXCProcessInterfaceTap()
and enhancing it to skip bridge-related items when brname == NULL.

To be truly useful, we need to support setting the ip address on the
host side veth as well as guest side veth (already supported for
type='bridge'), as well as setting the peer address for both.

The <script> element (supported by type='ethernet' in qemu) isn't
supported in this patch. An error is logged at domain start time if it
is encountered. This may be changed in a later patch.
2016-05-24 15:21:05 -04:00
Katerina Koukiou
306b3a8504 lxc: completely rework reference counting
This patch follows the pattern used in qemu driver regarding
reference counting.
It changes lxcDomObjFromDomain() to ref the domain (using
virDomainObjListFindByUUIDRef()) and adds virDomainObjEndAPI() which
should be the only function in which the return value of
virObjectUnref() is checked.  This makes all reference counting
deterministic and makes the code a bit clearer.

Signed-off-by: Katerina Koukiou <k.koukiou@gmail.com>
2016-05-24 16:54:01 +02:00
Katerina Koukiou
6ce89dcae0 lxc: use job functions in lxcDomainLxcOpenNamespace & lxcDomainSendProcessSignal
Use the recently added job functions in lxcDomainLxcOpenNamespace,
lxcDomainSendProcessSignal.

Signed-off-by: Katerina Koukiou <k.koukiou@gmail.com>
2016-05-24 16:35:02 +02:00
Maxim Nestratov
2f5e24ba00 nwfilter: fix lock order deadlock
Below is backtraces of two deadlocked threads:

thread #1:
 virDomainConfVMNWFilterTeardown
   virNWFilterTeardownFilter
       lock updateMutex <------------
       _virNWFilterTeardownFilter
            try to lock interface <----------

thread #2:
 learnIPAddressThread
    lock interface <-------
    virNWFilterInstantiateFilterLate
        try to lock updateMutex <----------

The problem is fixed by unlocking interface before calling
virNWFilterInstantiateFilterLate to avoid updateMutex and interface ordering
deadlocks. Otherwise we are going to instantiate the filter while holding
interface lock, which will try to lock updateMutex, and if some other thread
instantiating a filter in parallel is holding updateMutex and is trying to
lock interface, both will deadlock.
Also it is safe to unlock interface before virNWFilterInstantiateFilterLate
because learnIPAddressThread stopped capturing packets and applied necessary
rules on the interface, while instantiating a new filter doesn't require a
locked interface.

Signed-off-by: Maxim Nestratov <mnestratov@virtuozzo.com>
2016-05-24 15:24:37 +03:00
Pavel Hrdina
9db7308502 makefile: fix build on systems where gnutls is not in /usr/include
We need to append GNUTLS_CFLAGS while building utils because virtcrypto
is using it.  This fixes build on freebsd where gnutuls is in
/usr/local/include.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2016-05-24 13:30:01 +02:00
Jovanka Gulicoska
580dbf06a4 storage: Replace VIR_ERROR with standard vir*Error in state driver init
Replace VIR_ERROR with virReportError and virReportSystemError
2016-05-23 15:42:46 -04:00
Jovanka Gulicoska
1433c803c9 nwfilter: Replace VIR_ERROR with standard vir*Error in state driver init
Replace VIR_ERROR with virReportError
2016-05-23 15:42:46 -04:00
Jovanka Gulicoska
1223f7b23e libxl: Replace VIR_ERROR with standard vir*Error in state driver init
Replace VIR_ERROR with virReportError
2016-05-23 15:42:46 -04:00
Jovanka Gulicoska
86d1ae0479 bhyve: Replace VIR_ERROR with standard vir*Error in state driver init
Replace VIR_ERROR with virReportError
2016-05-23 15:42:46 -04:00
Laine Stump
9cdac8afc9 qemu: simplify addition of USB controller in qemuParseCommandLine
virDomainDefAddUSBController() does everything that the multiple lines
of code were doing.
2016-05-23 15:26:57 -04:00
Mikhail Feoktistov
4aeb1d5158 vz: add error code for case if vm is already stopped
If try to stop VM or container which is already stopped than
Virtuozzo 7 returns code PRL_ERR_INVALID_ACTION_REQUESTED.
Error code PRL_ERR_DISP_VM_IS_NOT_STARTED is used in Virtuozzo 6
2016-05-23 20:06:17 +03:00
Ján Tomko
d033d4762f Revert "qemu_cgroup: allow access to /dev/dri for virtio-vga"
This reverts commit 3943bdd60c.
2016-05-23 10:48:27 +02:00
Ján Tomko
21fdb4fe70 storage: do not clear vols before volume upload
Commit 5e54361c added virStoragePoolObjClearVols before refreshPool
to prevent duplicate volume entries.

However it is not needed here because we're not refreshing the pool yet,
just checking for the existence of the refresh callback.

The actual refresh is done via virStorageVolFDStreamCloseCb
in virStorageVolPoolRefreshThread, which already calls
virStoragePoolObjClearVols.
2016-05-23 10:47:32 +02:00
Ján Tomko
71cfa668eb Deprecate QEMU_CAPS_PCIDEVICE
Before removal of QEMU_CAPS_DEVICE, its only usage was
or'd with QEMU_CAPS_DEVICE.

Now it's unused.
2016-05-23 10:40:22 +02:00
Ján Tomko
5572cd7f0e Deprecate QEMU_CAPS_DEVICE
We support qemu version 0.12.0+, which has it.
2016-05-23 10:38:45 +02:00
Ján Tomko
e9488fcd20 Deprecate QEMU_CAPS_DRIVE_READONLY
We have been assuming its support if qemu supports -device,
which all the supported versions do.
2016-05-23 10:37:09 +02:00
Ján Tomko
00c9877e77 qemu: always assume QEMU_CAPS_DRIVE_READONLY
We have been always setting the capability on if qemu has
QEMU_CAPS_DEVICE.
2016-05-23 10:35:44 +02:00
Ján Tomko
5c4b6e8f5f qemu: assume QEMU_CAPS_DEVICE almost everywhere
Remove more checks that are no longer necessary.
2016-05-23 09:39:40 +02:00
Ján Tomko
34ab070c0d qemu_command: assume QEMU_CAPS_DEVICE
Drop some checks that are no longer necessary as well as
-usbdevice -pcidevice and -soundhw support.
2016-05-23 09:39:40 +02:00
Mikhail Feoktistov
33705aeec0 util: fix build without GNUTLS 2016-05-22 08:53:58 +03:00
Laine Stump
c026f8f1c2 qemu: auto-assign addresses when <address type='pci'/> is specified
Rather than only assigning a PCI address when no address is given at
all, also do it when the config says that the address type is 'pci',
but it gives no address (virDeviceInfoPCIAddressWanted()).

There are also several places after parsing but prior to address
assignment where code previously expected that any info with address
type='pci' would have a *valid* PCI address, which isn't always the
case - now we check not only for type='pci', but also for a valid
address (virDeviceInfoPCIAddressPresent()).

The test case added in this patch was directly copied from Cole's patch titled:

    qemu: Wire up address type=pci auto_allocate
2016-05-20 13:54:26 -04:00
Laine Stump
d05da3fc72 bhyve: auto-assign addresses when <address type='pci'/> is specified
Rather than only assigning a PCI address when no address is given at
all, also do it when the config says that the address type is 'pci',
but it gives no address.
2016-05-20 13:54:26 -04:00
Laine Stump
8f578716c7 conf: allow type='pci' addresses with no address attributes specified
Prior to this, <address type='pci'/> wasn't allowed when parsing
(domain+bus+slot+function needed to be a "valid" PCI address, meaning
that at least one of domain/bus/slot had to be non-0), the RNG
required bus to be specified, and if type was set to PCI when
formatting, domain+bus+slot+function would always be output.

This makes all the address attributes optional during parse and RNG
validation, and suppresses domain+bus+slot+function if domain+bus+slot
are all 0 (NB: if d+b+s are all 0, any value for function is
nonsensical as that will never happen in the real world, and after
the next patch we will always assign a real working address to any
empty PCI address before it is ever output to anywhere).

Note that explicitly setting all attributes to 0 is equivalent to
setting none of them, which is okay, since 0000:00:00 is reserved in
any PCI bus setup, and can't be used anyway.
2016-05-20 13:54:25 -04:00
Laine Stump
9a81a36353 conf: new functions to check if PCI address is wanted/present
In order to allow <address type='pci'/> with no other attributes to
mean "I want a PCI address, but any PCI address will do" (just as
having no <address> at all usually indicates), we will need to change
several places in the code from a simple "info->type == (or !=)
VIR_DOMAIN_DEVICE_ADDRESS_TYPE_(PCI|NONE)" into something slightly
more complex, this patch adds to new functions that take a
virDomainDeviceInfoPtr and return true/false depending on 1) whether
the current state of the info indicates that we "want" a PCI address
for this device (virDeviceInfoPCIAddressWanted()) and 2) whether this
device already has a valid PCI address
(virDeviceInfoPCIAddressPresent()).

Both of these functions required the simpler check for whether a pci
address is "empty" (i.e. all of its attributes are 0, which can never
happen in a real PCI address, since slot 0 of bus 0 of domain 0 is
always reserved), so that function is also added.
2016-05-20 13:54:25 -04:00
Laine Stump
ff89e9b932 conf: move virDomainDeviceInfo definition from domain_conf.h to device_conf.h
Also moves all the subordinate structs. This is necessary due to a new
inline function that will be defined in device_conf.h, and also makes
sense, because it is the *device* info that's in the struct. (Actually
a lot more stuff from domain_conf.h could move to this newer file, but
I didn't want to disturb any more than necessary).
2016-05-20 13:54:25 -04:00
John Ferlan
a1344f70a1 qemu: Utilize qemu secret objects for RBD auth/secret
https://bugzilla.redhat.com/show_bug.cgi?id=1182074

If they're available and we need to pass secrets to qemu, then use the
qemu domain secret object in order to pass the secrets for RBD volumes
instead of passing the base64 encoded secret on the command line.

The goal is to make AES secrets the default and have no user interaction
required in order to allow using the AES mechanism. If the mechanism
is not available, then fall back to the current plain mechanism using
a base64 encoded secret.

New APIs:

qemu_domain.c:
  qemuDomainGetSecretAESAlias:
    Generate/return the secret object alias for an AES Secret Info type.
    This will be called from qemuDomainSecretAESSetup.

  qemuDomainSecretAESSetup: (private)
    This API handles the details of the generation of the AES secret
    and saves the pieces that need to be passed to qemu in order for
    the secret to be decrypted. The encrypted secret based upon the
    domain master key, an initialization vector (16 byte random value),
    and the stored secret. Finally, the requirement from qemu is the IV
    and encrypted secret are to be base64 encoded.

qemu_command.c:
  qemuBuildSecretInfoProps: (private)
    Generate/return a JSON properties object for the AES secret to
    be used by both the command building and eventually the hotplug
    code in order to add the secret object. Code was designed so that
    in the future perhaps hotplug could use it if it made sense.

  qemuBuildObjectSecretCommandLine (private)
    Generate and add to the command line the -object secret for the
    secret. This will be required for the subsequent RBD reference
    to the object.

  qemuBuildDiskSecinfoCommandLine (private)
    Handle adding the AES secret object.

Adjustments:

qemu_domain.c:
  The qemuDomainSecretSetup was altered to call either the AES or Plain
  Setup functions based upon whether AES secrets are possible (we have
  the encryption API) or not, we have secrets, and of course if the
  protocol source is RBD.

qemu_command.c:
  Adjust the qemuBuildRBDSecinfoURI API's in order to generate the
  specific command options for an AES secret, such as:

    -object secret,id=$alias,keyid=$masterKey,data=$base64encodedencrypted,
            format=base64
    -drive file=rbd:pool/image:id=myname:auth_supported=cephx\;none:\
           mon_host=mon1.example.org\:6321,password-secret=$alias,...

  where the 'id=' value is the secret object alias generated by
  concatenating the disk alias and "-aesKey0". The 'keyid= $masterKey'
  is the master key shared with qemu, and the -drive syntax will
  reference that alias as the 'password-secret'. For the -drive
  syntax, the 'id=myname' is kept to define the username, while the
  'key=$base64 encoded secret' is removed.

  While according to the syntax described for qemu commit '60390a21'
  or as seen in the email archive:

    https://lists.gnu.org/archive/html/qemu-devel/2016-01/msg04083.html

  it is possible to pass a plaintext password via a file, the qemu
  commit 'ac1d8878' describes the more feature rich 'keyid=' option
  based upon the shared masterKey.

Add tests for checking/comparing output.

NB: For hotplug, since the hotplug code doesn't add command line
    arguments, passing the encoded secret directly to the monitor
    will suffice.
2016-05-20 11:09:05 -04:00
John Ferlan
97868a2b85 qemu: Introduce qemuDomainSecretSetup
Currently just a shim to call qemuDomainSecretPlainSetup, but soon to be more
2016-05-20 11:09:05 -04:00
John Ferlan
238032505f util: Introduce virCryptoGenerateRandom
Move the logic from qemuDomainGenerateRandomKey into this new
function, altering the comments, variable names, and error messages
to keep things more generic.

NB: Although perhaps more reasonable to add soemthing to virrandom.c.
    The virrandom.c was included in the setuid_rpc_client, so I chose
    placement in vircrypto.
2016-05-20 11:09:05 -04:00
John Ferlan
1ce9c08ab3 util: Introduce encryption APIs
Introduce virCryptoHaveCipher and virCryptoEncryptData to handle
performing encryption.

 virCryptoHaveCipher:
   Boolean function to determine whether the requested cipher algorithm
   is available. It's expected this API will be called prior to
   virCryptoEncryptdata. It will return true/false.

 virCryptoEncryptData:
   Based on the requested cipher type, call the specific encryption
   API to encrypt the data.

Currently the only algorithm support is the AES 256 CBC encryption.

Adjust tests for the API's
2016-05-20 11:09:01 -04:00
Nishith Shah
701b0f1867 qemu: parse: Handle suffixes for -m memory
According to QEMU docs, the '-m' option for specifying RAM is by default
in MiB, and a suffix of "M" or "G" may be passed for values in MiB and
GiB respectively. This commit adds support and a test for the same.

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

Signed-off-by: Nishith Shah <nishithshah.2211@gmail.com>
2016-05-20 08:46:39 -04:00
Nishith Shah
30677a78ab qemu: parse: Use qemuParseCommandLineMem for -m memory
Move the parsing of -m memory to a new function, qemuParseCommandLineMem

Signed-off-by: Nishith Shah <nishithshah.2211@gmail.com>
2016-05-20 08:46:39 -04:00
Pavel Hrdina
2c8e75554b qemu_command: refactor spice channel code
This prepares the code for other listen types.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2016-05-20 10:18:18 +02:00
Pavel Hrdina
0f6db3a44d qemu_process: separate graphics socket and address generation
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2016-05-20 10:16:49 +02:00
Pavel Hrdina
78a09aa033 graphics: resolve address for listen type network in qemu_process
Both VNC and SPICE requires the same code to resolve address for listen
type network.  Remove code duplication and create a new function that
will be used in qemuProcessSetupGraphics().

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2016-05-20 10:16:45 +02:00
Pavel Hrdina
858d7b6cf0 qemu_command: move sasl parameter after port and addr definition
This is required for following patches where new listen types will be
introduced.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2016-05-20 10:14:36 +02:00
Pavel Hrdina
54820cc600 domain_conf: introduce virDomainGraphicsListenDefFormatAddr
Move code that decide whether we print the 'listen' attribute or not
into virDomainGraphicsListenDefFormatAddr() function.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2016-05-20 10:08:03 +02:00
Pavel Hrdina
6bd0cd3b73 graphics: rename gListen to glisten
We have both in the code.  Let's use only one format.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2016-05-20 10:05:56 +02:00
Pavel Hrdina
ed7683f4d6 qemu_domain: add a empty listen type address if we remove socket for VNC
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2016-05-20 10:05:55 +02:00
Jiri Denemark
5f29c53150 cpu: Fix documentation of cpuGetModels
All callers of cpuGetModels expect @models to be NULL-terminated. Once
both x86GetModels and ppc64GetModels were fixed to meet this
expectation, we can explicitly document it.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-05-20 09:18:56 +02:00
Jiri Denemark
4b7c45ef61 cpu: Rework CPU map loading
The architecture specific loaders are now called with a list of all
elements of a given type (rather than a single element at a time). This
avoids the need to reallocate the arrays in CPU maps for each element.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-05-20 09:18:56 +02:00
Jiri Denemark
82aca17199 cpu_ppc64: Use array of models in CPU map
There's no reason for keeping the models in a linked list. Especially
when we know upfront the total number of models we are loading.

As a nice side effect, this fixes ppc64GetModels to always return a
NULL-terminated list of models.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-05-20 09:18:56 +02:00
Jiri Denemark
1bf79d9041 cpu_ppc64: Use array of vendors in CPU map
There's no reason for keeping the vendors in a linked list. Especially
when we know upfront the total number of models we are loading.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-05-20 09:18:56 +02:00
Jiri Denemark
3a7cd180a5 cpu_x86: Use array of features in CPU map
There's no reason for keeping the features in a linked list. Especially
when we know upfront the total number of features we are loading.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-05-20 09:18:56 +02:00
Jiri Denemark
22137d3952 cpu_x86: Use array of vendors in CPU map
There's no reason for keeping the vendors in a linked list. Especially
when we know upfront the total number of models we are loading.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-05-20 09:18:56 +02:00
Jiri Denemark
6f46bf7fcb cpu_x86: Use array of models in CPU map
There's no reason for keeping the models in a linked list. Especially
when we know upfront the total number of models we are loading.

As a nice side effect, this fixes x86GetModels to always return a
NULL-terminated list of models.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-05-20 09:18:56 +02:00
Ján Tomko
a84fce355e Do not mask QEMU_CAPS_DEVICE in qemuBuildDriveStr
For some disk types (SD), we want to emit the syntax
we used for disks before -device was available even
if QEMU supports -device.

Use the qemuDiskBusNeedsDeviceArg helper to figure out
whether to use the old or new syntax.
2016-05-20 09:07:51 +02:00
Ján Tomko
2e33ef4822 Introduce qemuDiskBusNeedsDeviceArg
Replace the two uses of the withDeviceArg bool in
qemuBuildDiskDriveCommandLine and allow this function to be reused in
qemuBuildDriveStr.
2016-05-20 09:03:42 +02:00
Ján Tomko
cd3b06b7f6 Assume QEMU_CAPS_DEVICE in qemuBuildDiskDriveCommandLine
We no longer need to handle -usbdevice and the withDeviceArg
logic becomes clearer.
2016-05-20 09:02:58 +02:00
Ján Tomko
936b86528d Remove DISK_BUS_XEN support from qemuBuildDiskDriveCommandLine
We have stopped supporting Xenner some time ago.
2016-05-20 09:02:08 +02:00
Ján Tomko
0586cf9800 qemu: always add -nodefaults
Since we always asumme support of QEMU_CAPS_DEVICE.
2016-05-20 09:02:08 +02:00
Cole Robinson
4bc8543401 qemu: process: Drop !QEMU_CAPS_DEVICE code
Nowadays we only support qemu 0.12.0+ which provides QEMU_CAPS_DEVICE,
so this is all dead code.
2016-05-20 09:01:48 +02:00
Ján Tomko
02c2097571 Remove qemuProcessInitPCIAddresses with dependencies
It was only called for QEMUs without QEMU_CAPS_DEVICE,
which we no longer support.
2016-05-20 07:43:39 +02:00
Peter Krempa
68c8cb04b1 qemu: driver: Fix function header alignment of some functions 2016-05-20 06:51:11 +02:00
Peter Krempa
827ce46e59 conf: disk: Rename virDomainDiskDefValidate to virDomainDiskDefParseValidate
Name the validation function distinctively since it's called in the
parser. Later patches will add function that will validate disk
definitions that are invalid but need to be parsed to avoid losing
domains.
2016-05-20 06:51:11 +02:00
John Ferlan
4a718d6a0e util: Remove need for STATIC_ANALYSIS check
Seems recent versions of Coverity have (mostly) resolved the issue using
ternary operations in VIR_FREE (and now VIR_DISPOSE*) macros.  So let's
just remove it and if necessary handle one off issues as the arise.
2016-05-19 16:30:04 -04:00
John Ferlan
c1faf3093c util: Adjust return for virPCIGetDeviceAddressFromSysfsLink
Rather than return 0/-1 and/or a pointer to some memory, adjust the
helper to just return the allocated structure or NULL on failure.

Adjust the callers in order to handle that

Signed-off-by: John Ferlan <jferlan@redhat.com>
2016-05-19 16:30:04 -04:00
John Ferlan
c8b1a83605 util: Remove need for ret in virPCIGetPhysicalFunction
Since the callers only ever expect 0 or -1, let's just return that directly

Signed-off-by: John Ferlan <jferlan@redhat.com>
2016-05-19 16:30:04 -04:00
John Ferlan
1f1273c2d1 util: Fix error path for virPCIGetVirtualFunctions
If we get to the error: label and clear out the *virtual_functions[]
pointers and then return w/ error to the caller - the caller has it's
own cleanup of the same array in the out: label which is keyed off the
value of num_virt_fns, which wasn't reset to 0 in the called function
leading to a possible problem.

Just clear the value (found by Coverity)

Signed-off-by: John Ferlan <jferlan@redhat.com>
2016-05-19 16:30:04 -04:00
Jovanka Gulicoska
b29e08dbe3 More usage of virGetLastErrorMessage
Convert to virGetLastErrorMessage() in the rest of the code
2016-05-19 15:17:03 -04:00
Katerina Koukiou
15ccb0dbf3 lxc: use job functions in lxcDomain* functions that perform modify actions.
Use the recently added job functions and unlock the virDomainObj while
performing the respective modify operation.
This commit affects lxcDomain{DestroyFlags, Reboot, SetBlkioParameters,
SetMemoryParameters, SetMetadata, SetSchedulerParameterFlags, ShutdownFlags}

Signed-off-by: Katerina Koukiou <k.koukiou@gmail.com>
2016-05-19 18:42:08 +02:00
Katerina Koukiou
95cee48056 lxc: use job functions in lxcDomain* functions that do query operations.
This commit affects lxcDomain{InterfaceStats, MemoryStats, BlockStats,
BlockStatsFlags}

Signed-off-by: Katerina Koukiou <k.koukiou@gmail.com>
2016-05-19 18:42:08 +02:00
Katerina Koukiou
30129edd5f lxc: add job functions in lxcDomainSetAutostart
This operation isn't necessarily time consuming, but need to
wait in the queue of modify jobs.

Signed-off-by: Katerina Koukiou <k.koukiou@gmail.com>
2016-05-19 18:42:08 +02:00
Katerina Koukiou
0fc0f715be lxc: use job functions in lxcDomain{AttachDeviceFlags, DetachDeviceFlags, UpdateDeviceFlags}
These operations aren't necessarily time consuming, but need to
wait in the queue of modify jobs.

Signed-off-by: Katerina Koukiou <k.koukiou@gmail.com>
2016-05-19 18:42:08 +02:00
Katerina Koukiou
91f433e45c lxc: use job functions in lxcDomain{Suspend, Resume}
These operations aren't necessarily time consuming, but need to
wait in the queue of modify jobs.

Signed-off-by: Katerina Koukiou <k.koukiou@gmail.com>
2016-05-19 18:42:08 +02:00
Katerina Koukiou
f5df98aae4 lxc: use job functions in lxcDomainSetMemoryFlags
Large balloon operation can be time consuming.  Use the recently
added job functions and unlock the virDomainObj while ballooning.

Signed-off-by: Katerina Koukiou <k.koukiou@gmail.com>
2016-05-19 18:42:08 +02:00
Katerina Koukiou
c066f9eed3 lxc: use job functions in lxcDomain{CreateXMLWithFiles, CreateWithFiles}
Creating a large domain could potentially be time consuming.  Use the
recently added job functions and unlock the virDomainObj while
the create operation is in progress.

Signed-off-by: Katerina Koukiou <k.koukiou@gmail.com>
2016-05-19 18:42:08 +02:00
Katerina Koukiou
03e9077bd1 lxc: Add job support to lxc driver
Follows the pattern used in the libxl driver for managing multiple,
simultaneous jobs within the driver.

Signed-off-by: Katerina Koukiou <k.koukiou@gmail.com>
2016-05-19 18:42:08 +02:00
Peter Krempa
71d2c172ed qemu: bulk stats: Don't access possibly blocked storage
If the stats for a block device can't be acquired from qemu we've
fallen back to loading them from the file on the disk in libvirt.

If qemu is not cooperating due to being stuck on an inaccessible NFS
share we would then attempt to read the files and get stuck too with
the VM object locked. All other APIs would eventually get stuck waiting
on the VM lock.

Avoid this problem by skipping the block stats if the VM is online but
the monitor did not provide any stats.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1337073
2016-05-19 16:27:42 +02:00
Peter Krempa
3aa5d51a95 qemu: driver: Separate bulk stats worker for block devices
Extract the fallback path that reloads the stats from disk into a
separate function.
2016-05-19 16:19:22 +02:00
Peter Krempa
5d2b0e6f12 qemu: driver: Remove unnecessary flag in qemuDomainGetStatsBlock
'abbreviated' was true if 'stats' were NULL
2016-05-19 16:19:22 +02:00
Qiaowei Ren
90b9995d1d perf: add support to perf event for MBM
Some Intel processor families (e.g. the Intel Xeon processor E5 v3
family) introduced some RDT (Resource Director Technology) features
to monitor or control shared resource. Among these features, MBM
(Memory Bandwidth Monitoring), which is build on the CMT (Cache
Monitoring Technology) infrastructure, provides OS/VMM a way to
monitor bandwidth from one level of cache to another.

With current perf framework, this patch adds support to perf event
for MBM.

Signed-off-by: Qiaowei Ren <qiaowei.ren@intel.com>
2016-05-19 15:57:57 +02:00
Ján Tomko
e4cbfa717a Separate virDomainDefParseBootOptions
Split out parsing of most of the <os> subelements into a separate
function.
2016-05-19 14:13:03 +02:00
Nikolay Shirokovskiy
2d3940907d vz: cleanup: define vz format of uuids
vz puts uuids into curly braces. Simply introduce new contstant to reflect this
and get rid of magic +2 in code.

Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
2016-05-19 14:57:13 +03:00
Nikolay Shirokovskiy
0ec30a24b8 vz: implement p2p migration
Peer to peer migration is implemented just as in managed case. Basically
it is copy paste from managed case but with all the branches that are not
applied to vz removed.

Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
2016-05-19 14:57:13 +03:00
Nikolay Shirokovskiy
0eced74f34 vz: implement managed migration
The newest version of migration protocol - version 3 with parameters is implemented.
Supported flags is VIR_MIGRATE_PAUSED only. Supported parameters are
VIR_MIGRATE_PARAM_URI and VIR_MIGRATE_PARAM_DEST_NAME. VIR_MIGRATE_PARAM_DEST_XML
is in VZ_MIGRATION_PARAMETERS for technical onyl reasons.

Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
Signed-off-by: Maxim Nestratov <mnestratov@virtuozzo.com>
2016-05-19 14:57:02 +03:00
Nikolay Shirokovskiy
17c37031e5 vz: fix const correctness case
Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
2016-05-19 14:56:00 +03:00
Nikolay Shirokovskiy
34075acf21 vz: save session uuid on login
This session uuid acts as authN token for different multihost vz operations one
of which is migration. Unfortunately we can't get it from server at any time
thus we need to save it at login.

Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
2016-05-19 14:56:00 +03:00
Erik Skultety
8b1f04693d admin: Introduce virAdmServerSetClientLimits
Opposite operation to virAdmServerGetClientLimits. Understandably though,
setting values for current number of clients connected or still waiting
for authentication does not make sense, since changes to these values are event
dependent, i.e. a client connects - counter is increased. Thus only the limits
to maximum clients connected and waiting for authentication can be set. Should
a request for other controls to be set arrive (provided such a setting will
be first introduced to the config), the set of configuration controls can be
later expanded (thanks to typed params). This patch also introduces a
constraint that the maximum number of clients waiting for authentication has to
be less than the overall maximum number of clients connected and any attempt to
violate this constraint will be denied.

Signed-off-by: Erik Skultety <eskultet@redhat.com>
2016-05-19 12:31:53 +02:00
Erik Skultety
509bd5d8b3 admin: Introduce virAdmServerGetClientLimits
Enable retrieval of the number of maximum clients connected to all sockets
combined, as well as the number of maximum clients waiting for authentication,
in order to be successfully connected. These are the attributes configurable
through libvirtd.conf, however, it could be handy to not only know values for
these limits, but also the values for the current number of clients
connected and number of clients currently waiting for authentication which are
changing dynamically. This API does both, retrieves the limits as well as the
current dynamic values.

Signed-off-by: Erik Skultety <eskultet@redhat.com>
2016-05-19 12:31:53 +02:00
Erik Skultety
abf29786f2 virnetserver: Introduce server's client-related limits getters
Add some trivial getters for client related attributes to virnetserver before
any admin method can be introduced.

Signed-off-by: Erik Skultety <eskultet@redhat.com>
2016-05-19 11:11:13 +02:00
Ján Tomko
3943bdd60c qemu_cgroup: allow access to /dev/dri for virtio-vga
QEMU needs access to the /dev/dri/render* device for
virgl to work.

Allow access to all /dev/dri/* devices for domains with
<video>
  <model type='virtio' heads='1' primary='yes'>
    <acceleration accel3d='yes'/>
  </model>
</video>

https://bugzilla.redhat.com/show_bug.cgi?id=1337290
2016-05-19 10:52:50 +02:00
Cole Robinson
20a0fa8eb2 qemu: address: Remove QEMU_CAPS_DEVICE usage
All qemu versions we support have QEMU_CAPS_DEVICE, so checking
for it is redundant. Remove the usage.

The code diff isn't clear, but all that code is just inindented
with no other change.

Test cases that hit qemuDomainAssignAddresses but don't have
infrastructure for specifying qemuCaps values see lots of
churn, since now PCI addresses are in the XML output.
2016-05-18 14:33:58 -04:00
Cole Robinson
383833e230 qemu: Call virDomainDefPostParse via CONFIG hotplug
hotplug APIs with the AFFECT_CONFIG flag are essentially replicating
'insert <device> into XML document, and redefine XML'. Thinking of
it this way, it's natural that we call virDomainDefPostParse after
manually editing the XML here.

Not only does doing so allow us to drop a bunch of open coded calls
to qemuDomainAssignAddresses, but it also means we are going through
the standard channels for XML validation and potentially catching
errors in user submitted XML.
2016-05-18 14:33:58 -04:00
Cole Robinson
5d7314bbcf qemu: Assign device addresses in PostParse
This wires up qemuDomainAssignAddresses into the new
virDomainDefAssignAddressesCallback, so it's always triggered
via virDomainDefPostParse. We are essentially doing this already
with open coded calls sprinkled about.

qemu argv parse output changes slightly since previously it wasn't
hitting qemuDomainAssignAddresses.
2016-05-18 14:33:58 -04:00