Commit Graph

17234 Commits

Author SHA1 Message Date
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
Cole Robinson
f891390fa7 domain: Add virDomainDefAssignAddressesCallback
This will be called at the end of virDomainDefPostParse to
allow hypervisor drivers to fill in device addresses.
2016-05-18 14:33:58 -04:00
Pavel Hrdina
919d0b368e Revert "qemu_hotplug: fix checking graphics ports"
This reverts commit 1ccc7fbff3.

We cannot check ports if autoport is set because we set ports to 0 while
parsing device XML.

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

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2016-05-18 17:16:56 +02:00
Nikolay Shirokovskiy
d6734879c0 vz: drop prlsdkDomainHasSnapshots
Let's use introduced domain snapshots infrastructure instead.

Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
2016-05-18 18:15:11 +03:00
Nikolay Shirokovskiy
abc85b2cab vz: add domain snapshots functionality
This solution does not keep snapshots cache because vz sdk lacks good support
for snapshot related events.

Libvirt and vz sdk has different approach to snapshot ids. vz sdk always
auto generate them while libvirt has ability to specify id by user.
Thus I have no other choice rather than simply ignore ids set by user
or generated by libvirt.

Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
Signed-off-by: Maxim Nestratov <mnestratov@virtuozzo.com>
2016-05-18 18:14:58 +03:00
John Ferlan
027986f5bf iscsi: Remove initiatoriqn from virISCSIScanTargets
No longer necessary to have it, so remove it.
2016-05-18 08:29:24 -04:00
Fritz Elfert
56057900dc util: Remove disabling of autologin for iscsi-targets
https://bugzilla.redhat.com/show_bug.cgi?id=1331552

Instead of disabling auto-login of all scsi targets (even those
that do not "belong" to libvirt), use iscsiadm's "--op nonpersistent"
during discovery of iSCSI targets (e.g. "iscsiadm --mode discovery
--type sendtargets") in order to avoid the node database being altered
which led to the need for the "large hammer" approach taken by
commit id '3c12b654'.

This commit removes the virISCSITargetAutologin adjustment (eg. the setting
of node.startup to "manual"). The iscsiadm command has supported this mode
of operation as of commit id 'ad873767' to open-iscsi.
2016-05-18 08:29:24 -04:00
John Ferlan
8f54e0d632 iscsi: Add exit status checking for virISCSIGetSession
Utilize the exit status parameter for virCommandRunRegex in order to
check the return error from the 'iscsiadm --mode session' command.
Without this enabled, if there are no sessions running then virCommandRun
would have displayed an error such as:

    2016-05-13 15:17:15.165+0000: 10920: error : virCommandWait:2553 :
               internal error: Child process (iscsiadm --mode session)
               unexpected exit status 21: iscsiadm: No active sessions.

It is possible that for certain paths (when probe is true) we only care
whether it's running or not to make certain decisions.  Spitting out
the error for those paths is unnecessary.

If we do have a situation where probe = false and there's an error,
then display the error from iscsiadm if it's there.
2016-05-18 08:29:24 -04:00
John Ferlan
8b10494733 util: Add exitstatus parameter to virCommandRunRegex
Rather than have virCommandRun just spit out the error, allow callers
to decide to pass the exitstatus so the caller can make intelligent
decisions based on the error.
2016-05-18 08:29:24 -04:00
Andrea Bolognani
8b74919d69 qemu: Add virQEMUCapsSetGICCapabilities()
For use in the test suite.
2016-05-18 11:27:56 +02:00
Andrea Bolognani
1a012c9a51 qemu: Automatically choose usable GIC version
When the <gic/> element in not present in the domain XML, use the
domain capabilities to figure out what GIC version is usable and
choose that one automatically.

This allows guests to be created on hardware that only supports
GIC v3 without having to update virt-manager and similar tools.

Keep using the default GIC version if the <gic/> element has been
added to the domain XML but no version has been specified, as not
to break existing guests.
2016-05-18 11:27:50 +02:00
Andrea Bolognani
58f0152f3b qemu: Add virQEMUCapsSupportsGICVersion()
This utility function extracts some of the logic from
virQEMUCapsFillDomainFeatureGICCaps() so that it can be used
in a different context.
2016-05-18 10:39:00 +02:00
Jiri Denemark
f2b4609723 Change return value of VIR_APPEND*INPLACE* to void
The INPLACE variants of the VIR_APPEND macros cannot fail and they are
inherently quiet.
2016-05-18 09:36:23 +02:00
Jiri Denemark
d8d4b9d957 Remove virDomainRNGInsert
It was just a useless wrapper around VIR_APPEND_ELEMENT*.
2016-05-18 09:36:23 +02:00
Chunyan Liu
03f8bba26e xenFormatNet: correct `type=netfront' to 'type=vif' to match libxl
According to current xl.cfg docs and xl codes, it uses type=vif
instead of type=netfront.

Currently after domxml-to-native, libvirt xml model=netfront will be
converted to xl type=netfront. This has no problem before, xen codes
for a long time just check type=ioemu, if not, set type to _VIF.

Since libxl uses parse_nic_config to avoid duplicate codes, it
compares 'type=vif' and 'type=ioemu' for valid parameters, others
are considered as invalid, thus we have problem with type=netfront
in xl config file.
 #xl create sles12gm-hvm.orig
 Parsing config from sles12gm-hvm.orig
 Invalid parameter `type'.

Correct the conversion in libvirt, so that it matchs libxl codes
and also xl.cfg.

Signed-off-by: Chunyan Liu <cyliu@suse.com>
2016-05-17 14:09:11 -06:00
Chunyan Liu
f1066d0d46 extract XEN_CONFIG_FORMAT_XM/XL to xen_common.h
Unify XEN_CONFIG_FORMAT_x and LIBXL_CONFIG_FORMAT_x to
XEN_CONFIG_FORMAT_x, and move to xen_common.h.

Signed-off-by: Chunyan Liu <cyliu@suse.com>
2016-05-17 14:09:11 -06:00
Fabian Freyer
ef45eb9bc7 bhyve: implement virConnectIsSecure
Trivially return 1, since bhyve is considered a local connection that
should not be vulnerable to eavesdropping.
2016-05-17 20:18:04 +03:00
Fabian Freyer
32aa9ed3ba bhyve: Implement virConnectIsEncrypted
Being a local connection, bhyve does not support encryption. Therefore
trivially return 0.
2016-05-17 20:18:01 +03:00
Maxim Nestratov
9ef05d597e Revert "vz: handle sourceless cdroms"
This reverts commit 071fe092.
It was committed by a mistake and correct patch was committed
earlier as baad90fb.
2016-05-17 15:11:35 +03:00
Cole Robinson
1fad65d49a qemu: hotplug: Report error if we hit tray status timeout
If we exceed the timeout waiting for the tray status to change,
we don't report an error. Fix it
2016-05-17 08:09:04 -04:00
Nikolay Shirokovskiy
e10a4c67c3 vz: make error path code idiomatic
Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
Signed-off-by: Maxim Nestratov <mnestratov@virtuozzo.com>
2016-05-17 13:35:29 +03:00
Mikhail Feoktistov
4aef1a5e3e vz: fix template ct creation
First we don't need to add disk in this case. Second flag should
be skipped.

Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
2016-05-17 13:35:29 +03:00
Nikolay Shirokovskiy
07761f5d39 vz: fix error message for readonly fs
Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
2016-05-17 13:35:29 +03:00
Mikhail Feoktistov
071fe09260 vz: handle sourceless cdroms
SDK handles empty cdroms all right. We just need to
pass "" instead of NULL (not setting is good too).

However we can get problems here. Disk detaching treats source
as ids. Fortunately disk detaching is not supported for cdroms
yet and for hard disks we can not get empty source - this is prohibitited
by xml parsing code.

Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
Signed-off-by: Maxim Nestratov <mnestratov@virtuozzo.com>
2016-05-17 13:35:28 +03:00
Nikolay Shirokovskiy
caff6b8043 vz: fix vzCheckUnsupportedDisks format checks for cdroms
Current version of the function does not check format of cdroms at all.
At the same time prlsdkGetDiskInfo give hints that cdroms always
have format VIR_STORAGE_FILE_RAW. So fix vzCheckUnsupportedDisks.

About structure of checks. As we don't have means to store format
in SDK we always have only one format in every situation. So instead
of setting boolean let's get allowed format instead and finally compare
it to the requested. This structure of checks seems stable to me
because we have only one format in every situation.

Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
2016-05-17 13:35:28 +03:00
Nikolay Shirokovskiy
38e1e06845 vz: remove check for auto file format for disks
VIR_STORAGE_FILE_AUTO can not be set from xml description.
At the same time we don't set disks format to this value
as for example qemu does. Thus this we can never get this
value in format.

Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
2016-05-17 13:35:28 +03:00
Pavel Hrdina
f161e40152 domain_conf: cleanup virDomainGraphicsListenDefParseXML
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2016-05-17 10:41:45 +02:00
Pavel Hrdina
b33c14b342 graphics: make address attribute for listen type='address' optional
We support omitting listen attribute of graphics element so we should
also support omitting address attribute of listen element.  This patch
also updates libvirt to always add a listen element into domain XML
except for VNC graphics if socket attribute is specified.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2016-05-17 10:41:45 +02:00
Pavel Hrdina
38c9973f36 domain_conf: parse listen attribute while parsing listen elements
Move the compatibility code out of virDomainGraphicsListensParseXML()
into virDomainGraphicsListenDefParseXML().  This also fixes a small
inconsistency between the code and error message itself.

Before this patch we would search first listen element that is
type='address' to validate listen and address attributes. After this
patch we always take the first listen element regardless of the type.

This shouldn't break anything since all drivers supports only one
listen.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2016-05-17 10:41:45 +02:00
Pavel Hrdina
360cbf6f83 graphics: don't parse listens if socket attribute is present
If socket attribute is present we start VNC that listens only on that
unix socket.  This makes the parser behave the same way as we actually
use the socket attribute.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2016-05-17 10:41:45 +02:00
Peter Krempa
72475ac3b3 conf: Allow all volume modes for disk type='lun' sources
Commit 82ba41108a made possible to use direct mapped iSCSI
volumes in qemu as disk sources but didn't remove the define time check.

Rework the check by simplifying the condition and allow any volumes to
be used with disk type='lun'.
2016-05-17 07:09:56 +02:00
Andrea Bolognani
0e8a72a5ef qemu: Drop QEMU_CAPS_VIRTIO_BLK_SG_IO
The only QEMU versions that don't have such capability are <0.11,
which we no longer support anyway
2016-05-17 00:01:45 +02:00
Andrea Bolognani
859743c27c qemu: Drop QEMU_CAPS_CPU_HOST
The only QEMU versions that don't have such capability are <0.11,
which we no longer support anyway
2016-05-17 00:01:45 +02:00
Andrea Bolognani
8531b85ba6 qemu: Drop QEMU_CAPS_PCI_ROMBAR
The only QEMU versions that don't have such capability are <0.12,
which we no longer support anyway.

Additionally, this solves the issue of some QEMU binaries being
reported as not having such capability just because they lacked
the {kvm-}pci-assign QMP object.
2016-05-17 00:01:45 +02:00
John Ferlan
1222a3032b libxl: Free migration cookie
Commit id 'f9edcfa4' added cookie manipulation for libxl; however, some
cookie crumb cleanup was missed. Found by Coverity.

In libxlDomainMigrationBegin, the cookie is allocated and baked; however,
the mig ingredients weren't cleaned up.

In libxlDomainMigrationPrepare, when the 'mig' cookie is added to the
args, set the 'mig = NULL'; otherwise, other failure paths between when
the code ate the cookie data and when it was added to args would fail
to clean up the crumbs.

Signed-off-by: John Ferlan <jferlan@redhat.com>
2016-05-16 13:41:17 -04:00
John Ferlan
52760707bc qemu: More qemu_monitor_json cleanups
Recent adjustments to the code produced a litany of coverity false
positives, but only because the "standard" procedure of setting a
variable to NULL after it was assigned to something else and keeping
the *Free/*FREE call in the cleanup path wasn't kept. So this patch
makes those adjustments (assign variable to NULL and remove the if
'ret < 0' condition to clean it up).

Signed-off-by: John Ferlan <jferlan@redhat.com>
2016-05-16 13:41:10 -04:00
Fabian Freyer
a1efc9428b bhyve: implement virConnectIsAlive
bhyve connections are local, and a "connection will be classed as alive
if it is [...] local".
2016-05-16 19:19:49 +03:00
Cole Robinson
e3a6859019 qemu: command: Use -name guest= if available
-name guest= is the explicit parameter for passing a VM name. Using
it is required to allow a VM with an '=' in the name

https://bugzilla.redhat.com/show_bug.cgi?id=1276485
2016-05-16 10:30:38 -04:00
Cole Robinson
7dbbc0ca07 qemu: command: escape commas in chardev socket path
After this, a default virt-manager VM will startup with a comma
in the VM name:

https://bugzilla.redhat.com/show_bug.cgi?id=639926
2016-05-16 10:30:38 -04:00
Cole Robinson
077ba95677 qemu: command: escape commas in VNC socket path
This path can be dependent on the VM libdir, which contains its name
2016-05-16 10:30:38 -04:00
Cole Robinson
3153ac08c9 qemu: command: escape commas in secret master path
Need to convert the local function to virBuffer usage, so we
can use qemuBufferEscapeComma
2016-05-16 10:30:38 -04:00
Cole Robinson
0f377eb1b0 qemu: command: escape commas in VM name
This isn't sufficient on its own, since the VM name is used for things
like monitor paths, which we don't escape yet
2016-05-16 10:30:38 -04:00
Cole Robinson
53d976b63a qemu: command: Add qemuBufferEscapeComma
Centralize the magic invocation for escaping commas on the qemu
command line, and document it a bit
2016-05-16 10:30:38 -04:00
Cole Robinson
ef2c82170f qemu: alias: Remove QEMU_CAPS_DEVICE
QEMU_CAPS_DEVICE is always set nowadays, so drop code that depends
on not-DEVICE
2016-05-16 10:29:39 -04:00
Jiri Denemark
5b62a95176 cpu: Properly report errors when parsing CPU map XML
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-05-16 15:46:30 +02:00
Jiri Denemark
17924643ec cpu_x86: Check vendor early
When searching for the best CPU model for CPUID data we can easily
ignore models with non-matching vendor before spending time on CPUID
data to virCPUDef conversion.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-05-16 15:46:30 +02:00
Jiri Denemark
1cc9a1d07c cpu_x86: Don't ignore parsing errors in x86ModelLoad
CPU map XML is our internal data file, it makes no sense to tolerate any
errors in it.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-05-16 15:46:29 +02:00
Jiri Denemark
49da4cf168 cpu_x86: Don't ignore parsing errors in x86FeatureLoad
CPU map XML is our internal data file, it makes no sense to tolerate any
errors in it.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-05-16 15:46:29 +02:00
Jiri Denemark
db8a1873fb cpu_x86: Don't ignore parsing errors in x86VendorLoad
CPU map XML is our internal data file, it makes no sense to tolerate any
errors in it.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-05-16 15:46:29 +02:00
Jiri Denemark
945776dbc6 cpu_x86: Simplify insertions into a linked list
The next pointer is initialized to NULL, overwriting to with another
NULL doesn't hurt.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-05-16 15:46:28 +02:00
Jiri Denemark
26bfa2a63b cpu_x86: Remove comparisons to NULL
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-05-16 15:46:28 +02:00
Jiri Denemark
aa9e0ef0ef cpu_x86: Use for loop in x86Decode
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-05-16 15:46:28 +02:00
Jiri Denemark
2085f9a514 cpu_x86: Rename cleanup labels
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-05-16 15:46:27 +02:00
Jiri Denemark
ea51e6a045 cpu_x86: Compare CPU candidates in a separate function
Splitting the comparison into a separate function makes the code cleaner
and easier to update in the future.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-05-16 15:46:27 +02:00
Jiri Denemark
5b991c44ed cpu_x86: Rename struct virCPUx86DataIterator
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-05-16 15:46:27 +02:00
Jiri Denemark
5778daf7db cpu_x86: Rename enum compare_result
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-05-16 15:46:26 +02:00
Jiri Denemark
bc01151a03 cpu_x86: Rename struct x86_map
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-05-16 15:46:26 +02:00
Jiri Denemark
449e2d43cc cpu_x86: Rename struct x86_model
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-05-16 15:46:26 +02:00
Jiri Denemark
44f9cf6c04 cpu_x86: Rename struct x86_kvm_feature
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-05-16 15:46:25 +02:00
Jiri Denemark
3925e073f1 cpu_x86: Rename struct x86_feature
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-05-16 15:46:25 +02:00
Jiri Denemark
49ecf3da24 cpu_x86: Rename struct x86_vendor
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-05-16 15:46:25 +02:00
Cole Robinson
c7d6c13989 qemu: command: Ignore QEMU_CAPS_DEVICE when building drive alias
QEMU_CAPS_DEVICE is always set nowadays, so we can drop the
non-DEVICE code paths
2016-05-16 08:59:35 -04:00
Jiri Denemark
afdb3fc901 cpuGetModels: Fix memory leak on error
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-05-16 13:21:43 +02:00
Alexander Burluka
2b140f0cae cpu: Add support for clflushopt and tsc_adjust Intel features
Corresponding QEMU commits:
    clflushopt f7fda280948a5e74aeb076ef346b991ecb173c56
    tsc_adjust 7b458bfd12a71b3da6b531daedc417492c9334e0

Signed-off-by: Alexander Burluka <aburluka@virtuozzo.com>
2016-05-16 13:19:12 +02:00
John Ferlan
abd2272c02 secret: Alter virSecretGetSecretString
Rather than returning a "char *" indicating perhaps some sized set of
characters that is NUL terminated, alter the function to return 0 or -1
for success/failure and add two parameters to handle returning the
buffer and it's size.

The function no longer encodes the returned secret, rather it returns
the unencoded secret forcing callers to make the necessary adjustments.

Alter the callers to handle the adjusted model.

Signed-off-by: John Ferlan <jferlan@redhat.com>
2016-05-16 12:58:48 +02:00
Peter Krempa
fb1dddfb00 qemu: domain: Fix names for functions that clear security info
They don't free the structure itself so they should be called *Clear
rather than *Free.
2016-05-16 12:58:48 +02:00
John Ferlan
1cf5af40b9 util: string: Introduce helper to determine whether a byte buffer is printable
Signed-off-by: John Ferlan <jferlan@redhat.com>
2016-05-16 12:58:48 +02:00
Peter Krempa
cb2e3e50ee util: string: Introduce virStringEncodeBase64
Add a new helper that sanitizes error semantics of base64_encode_alloc.
2016-05-16 12:58:48 +02:00
Peter Krempa
1d632c3924 secret: util: Refactor virSecretGetSecretString
Call the internal driver callbacks rather than the public APIs to avoid
calling unnecessarily the error dispatching code and don't overwrite
the error messages provided by the APIs. They are good enough to
describe which secret is missing either by UUID or the usage (basically
name).
2016-05-16 12:58:48 +02:00
Peter Krempa
eb2116fd9a util: alloc: Introduce freeing helpers that clear the memory before freeing
For a few cases where we handle secret information it's good to clear
the buffers containing sensitive data before freeing them.

Introduce VIR_DISPOSE, VIR_DISPOSE_N and VIR_DISPOSE_STRING that allow
simple clearing fo the buffers holding sensitive information on cleanup
paths.
2016-05-16 12:58:48 +02:00
Jiri Denemark
ced1e846a0 capabilities: Advertise cpuselection if -cpu host is usable
When -cpu host is supported by a QEMU binary, a user can use
<cpu mode='host-passthrough'/> in domain XML even when libvirtd failed
to find a matching model for the host CPU. Let's make it obvious by
advertising <cpuselection/> guest capability whenever -cpu host is
supported.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-05-16 10:42:28 +02:00
Fabian Freyer
9055faebd4 qemu: remove ATTRIBUTE_UNUSED in connectGetType
This is not needed here, since the conn parameter is used in the ACL
checking calls, which were introduced in abf75aea2.
2016-05-13 15:52:11 -04:00
Fabian Freyer
126e630e85 bhyve: implement virConnectGetType
This implements virConnectGetType for the bhyve driver.
2016-05-13 21:10:58 +03:00
Jim Fehlig
400e716d7d libxl: don't attempt to probe a non-existent emulator
When probing the <emulator> with '-help' to determine if
it is the old qemu, errors are reported if the emulator
doesn't exist

libvirt:  error : internal error: Child process
(/usr/lib/xen/bin/qemu-dm -help) unexpected exit status 127:
libvirt:  error : cannot execute binary /usr/lib/xen/bin/qemu-dm:
No such file or directory

Avoid the probe if the specified emulator doesn't exist,
squelching the error. There is no behavior change since
libxlDomainGetEmulatorType() would return
LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN if the probe failed
via virCommandRun().

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
2016-05-13 10:08:34 -06:00
Pavel Hrdina
3902f634bf virt-aa-helper: remove replace_string and use virStringReplace instead
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2016-05-13 17:42:57 +02:00
Laine Stump
9575cb8554 network: log error when <bandwidth> is requested for hostdev interfaces
This would previously be silently ignored.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1319044
2016-05-13 10:02:20 -04:00
Michal Privoznik
7fccf12482 virfile: Introduce virFileRemoveLastComponent
Move some parts of virStorageFileRemoveLastPathComponent
into a separate function so they can be reused.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2016-05-13 14:17:15 +02:00
Shivaprasad G Bhat
be1a7e6d31 leave out the default USB controller only on i440fx during migration
Further followup discussions in list on commit 192a53e concluded
that we should be leaving out the USB controller only for
i440fx machines as default USB can be used by someone on q35
at random slots.

Signed-off-by: Shivaprasad G Bhat <sbhat@linux.vnet.ibm.com>
2016-05-13 10:11:00 +02:00
Peter Krempa
2a1a9808b1 qemu: domain: Fix name of macro defining AES IV length
The initialization vector is a technical term by itself different from
the key.
2016-05-12 17:13:09 +02:00
John Ferlan
677b94f487 qemu: Change from SecretIV or _IV to SecretAES or _AES
The preferred name will be AES not IV, change current references

Signed-off-by: John Ferlan <jferlan@redhat.com>
2016-05-12 09:30:08 -04:00
Ján Tomko
538012c8a3 Fill out default vram in DeviceDefPostParse
Move filling out the default video (v)ram to DeviceDefPostParse.

This means it can be removed from virDomainVideoDefParseXML
and qemuParseCommandLine. Also, we no longer need to special case
VIR_DOMAIN_VIRT_XEN, since the per-driver callback gets called
before the generic one.
2016-05-12 08:22:08 +02:00
Ján Tomko
3e42867032 Call per-device post-parse callback even on implicit video
Commit 6879be48 moved adding of an implicit video device after XML
parsing. As a result, libxlDomainDeviceDefPostParse() is no longer
called to set the default vram when adding an implicit device.
Commit 6879be48 assumes virDomainVideoDefaultRAM() will set the
default vram, but it returns 0 if the domain virtType is
VIR_DOMAIN_VIRT_XEN. Attempting to start an HVM domain with vram=0
results in

error: unsupported configuration: videoram must be at least 4MB for CIRRUS

The default vram setting for Xen HVM domains depends on the device
model used (qemu-xen vs qemu-traditional), hence setting the
default is deferred to libxlDomainDeviceDefPostParse().

Call the device post-parse callback even for implicit video,
to fill out the default vram even for VIR_DOMAIN_VIRT_XEN.

https://bugzilla.redhat.com/show_bug.cgi?id=1334557
Most-of-commit-message-by: Jim Fehlig <jfehlig@suse.com>
2016-05-12 08:22:08 +02:00
Ján Tomko
e4d131b8cb Move virDomainDefPostParseInternal after virDomainDeviceDefPostParse
Future commit will call DeviceDefPostParse on a device auto-added
in DomainDefPostParse.
2016-05-12 08:22:08 +02:00
Erik Skultety
e711a3918f util: Fix virGetLastErrorMessage to return proper error when 'err' is NULL
Both virGetLastError and virGetLastErrorMessage call virLastErrorObject method
that returns a thread-local error object. However, if a direct call to malloc
or pthread_setspecific (probably also due to malloc, since it sets ENOMEM)
fail, virLastErrorObject returns NULL which, although incorrectly interpreted
by virGetLastError as no error, still requires the caller to check for NULL
pointer. This isn't the case with virGetLastErrorMessage that also treated it
incorrectly as no error, but returned the literal "no error".
This patch tweaks the checks in the virGetLastErrorMessage function, so that
if virLastErrorObject failed, it returned "unknown error" which is equivalent
to the current approach with virGetLastError and if it returned NULL,
"unknown error" was set.

Signed-off-by: Erik Skultety <eskultet@redhat.com>
2016-05-11 20:10:35 +02:00
John Ferlan
8cdff0b93f storage: Fix virStorageBackendDiskDeleteVol for device mapper
Commit id 'df1011ca8' modified virStorageBackendDiskDeleteVol to use
"dmsetup remove --force" to remove the volume, but left things in an
inconsistent state since the partition still existed on the disk and
only the device mapper device (/dev/dm-#) was removed.

Prior to commit '1895b421' (or '1ffd82bb' and '471e1c4e'), this could
go unnoticed since virStorageBackendDiskRefreshPool wasn't called.
However, the pool would be unusable since the /dev/dm-# device would
be removed even though the partition was not removed unless a multipathd
restart reset the link. That would of course make the volume appear again
in the pool after a refresh or pool start after libvirt reload.

This patch removes the 'dmsetup' logic and re-implements the partition
deletion logic for device mapper devices. The removal of the partition
via 'parted rm --script #' will cause udev device change logic to allow
multipathd to handle removing the dm-* device associated with the partition.
2016-05-11 09:23:31 -04:00
John Ferlan
e7bde8d319 storage: Fix algorithm generating path names for devmapper
https://bugzilla.redhat.com/show_bug.cgi?id=1265694

Commit id '020135dc' didn't quite get the algorithm correct when a
device mapper source ended with a non numeric value (e.g. ends with
an alphabet value).

This patch modifies the 'part_separator' logic to add the "p" separator
to the attempted target path name only when specified as part_separator='yes'.

For a source name that already ends with a number, the logic doesn't change
as the part separator would need to be there.

For a source name that ends with something other than a number, this allows
the possibility that a "p" separator can be added. The default for one of
these source devices is to not add the separator.

The key for device mapper and the need for a partition separator "p" is
the presence of a number in the last character of the device name link
in /dev/mapper.  A name such as "/dev/mapper/mpatha1" would generate
a "/dev/mapper/mpatha1p1" partition, while "/dev/mapper/mpatha" would
generate partition "/dev/mapper/mpatha1". Similarly for a device
mapper entry not using friendly names or an alias, a device such as
"/dev/mapper/3600a0b80005b10ca00005ad656fd8d93" would generate a
paritition "/dev/mapper/3600a0b80005b10ca00005ad656fd8d93p1", while
a device such as "/dev/mapper/3600a0b80005b10ca00005e115729093f" would
generate a partition "/dev/mapper/3600a0b80005b10ca00005e115729093f1".
The long number is the WWID of the device. It's also possible to assign
an alias for a device mapper entry, that alias follows the same rules
with respect to ending with a number or not when adding a "p" to create
the target device path.
2016-05-11 09:23:31 -04:00
John Ferlan
5e54361c9d storage: Need to clear pool prior to calling the refreshPool
Prior to calling the 'refreshPool' during CreatePool or UploadPool
operations, we need to clear the pool; otherwise, the pool will
have duplicated entries.
2016-05-11 09:23:31 -04:00
John Ferlan
2c52ec43aa storage: Fix regression cloning volume into a logical pool
https://bugzilla.redhat.com/show_bug.cgi?id=1318993

Commit id 'dd519a294' caused a regression cloning a volume into a
logical pool by removing just the 'allocation' adjustment during
storageVolCreateXMLFrom. Combined with the change to not require the
new volume input XML to have a capacity listed (commit id 'e3f1d2a8')
left the possibility that a zero allocation value (e.g., not provided)
would create a thin/sparse logical volume. When a thin lv becomes fully
populated, then LVM sets the partition 'inactive' and the subsequent
fdatasync() fails.

Add a new 'has_allocation' flag to be set at XML parse time to indicate
that allocation was provided. This is done so that if it's not provided
the create-from code uses the capacity value since we document that if
omitted, the volume will be fully allocated at time of creation.

For a logical backend, that creation time is 'createVol', while for a
file backend, creation doesn't set the size, but the 'createRaw' called
during buildVolFrom will decide whether the file is sparse or not based
on the provided capacity and allocation value.

For volume clones that provide different allocation and capacity values
to allow for sparse files, there is no change.
2016-05-11 09:06:26 -04:00
Erik Skultety
898c0bbea7 headers: Remove unnecessary keyword extern from function declaration
Usage of this keyword in front of function declaration that is exported via a
header file is unnecessary, since internally, this has been the default for most
compilers for quite some time.

Signed-off-by: Erik Skultety <eskultet@redhat.com>
2016-05-11 09:06:32 +02:00
Laine Stump
e5aecc2f80 conf: log error when incorrect PCI root controller is added to domain
libvirt may automatically add a pci-root or pcie-root controller to a
domain, depending on the arch/machinetype, and it hopefully always
makes the right decision about which to add (since in all cases these
controllers are an implicit part of the virtual machine).

But it's always possible that someone will create a config that
explicitly supplies the wrong type of PCI controller for the selected
machinetype. In the past that would lead to an error later when
libvirt was trying to assign addresses to other devices, for example:

  XML error: PCI bus is not compatible with the device at
  0000:00:02.0. Device requires a PCI Express slot, which is not
  provided by bus 0000:00

(that's the error message that appears if you replace the pcie-root
controller in a Q35 domain with a pci-root controller).

This patch adds a check at the same place that the implicit
controllers are added (to ensure that the same logic is used to check
which type of pci root is correct). If a pci controller with index='0'
is already present, we verify that it is of the model that we would
have otherwise added automatically; if not, an error is logged:

  The PCI controller with index='0' must be " model='pcie-root' for
  this machine type, " but model='pci-root' was found instead.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1004602
2016-05-10 17:03:24 -04:00
Laine Stump
b3f2c7cae8 conf: make virDomainDefAddController() public
This will be needed by the qemu driver in an upcoming patch.
2016-05-10 17:03:11 -04:00
Jim Fehlig
f9edcfa473 libxl: support migration stream V2 in migration
Similar to "support Xen migration stream V2 in save/restore",
add support for indicating the migration stream version in
the migration code. To accomplish this, add a minimal migration
cookie in the libxl driver that is passed between source and
destination hosts. Initially, the cookie is only used in
the Begin and Prepare phases of migration to communicate the
version of the migration stream produced by the source.

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
2016-05-10 14:23:37 -06:00
Jim Fehlig
5325123d23 libxl: support Xen migration stream V2 in save/restore
Xen 4.6 introduced a new migration stream commonly referred to as
"migration V2". Xen 4.6 and newer always produce this new stream,
whereas Xen 4.5 and older always produce the legacy stream.
Support for migration stream V2 can be detected at build time with
LIBXL_HAVE_SRM_V2 from libxl.h. The legacy and V2 streams are not
compatible, but a V2 host can accept and convert a legacy stream.

Commit e7440656 changed the libxl driver to use the lowest libxl
API version possible (version 0x040200) to ensure the driver
builds against older Xen releases. The old 4.2 restore API does
not support specifying a stream version and assumes a legacy
stream, even if the incoming stream is migration V2. Thinking it
has been given a legacy stream, libxl will fail to convert an
incoming stream that is already V2, which causes the entire
restore operation to fail. Xen's libvirt-related OSSTest has been
failing since commit e7440656 landed in libvirt.git master. One
of the more recent failures can be seen here

http://lists.xenproject.org/archives/html/xen-devel/2016-05/msg00071.html

This patch changes the call to libxl_domain_create_restore() to
include the stream version if LIBXL_HAVE_SRM_V2 is defined. The
version field of the libxlSavefileHeader struct is also updated
to '2' when LIBXL_HAVE_SRM_V2 is defined, ensuring the stream
version in the header matches the actual stream version produced
by Xen. Along with bumping the libxl API requirement to 0x040400,
this patch fixes save/restore on a migration V2 Xen host.

Oddly, migration has never used the libxlSavefileHeader. It
handles passing configuration in the Begin and Prepare phases,
and then calls libxl directly to transfer domain state/memory
in the Perform phase. A subsequent patch will add stream
version handling in the Begin and Prepare phase handshaking,
which will fix the migration related OSSTest failures.

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
2016-05-10 14:23:37 -06:00
Jim Fehlig
fccf27253c libxl: switch to using libxl_domain_create_restore from v4.4 API
In LIBXL_API_VERSION 0x040400, the libxl_domain_create_restore API
gained a parameter for specifying restore parameters. Switch to
using version 0x040400, which will be useful in a subsequent commit
to specify the Xen migration stream version when restoring.

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
2016-05-10 14:23:37 -06:00
John Ferlan
fc5c1e7fe9 qemu: Add extra checks for secret destroy API's
Remove the possibility that a NULL hostdev->privateData or a
disk->privateData could crash libvirtd by checking for NULL
before dereferencing for the secinfo structure in the
qemuDomainSecret{Disk|Hostdev}Destroy functions. The hostdevPriv
could be NULL if qemuProcessNetworkPrepareDevices adds a new
hostdev during virDomainNetGetActualHostdev that then gets
inserted via virDomainHostdevInsert. The hostdevPriv was added
by commit id '27726d8' and is currently only used by scsi hostdev.
2016-05-10 15:48:08 -04:00
Laine Stump
75db9997a0 util: set vlan tag for macvtap passthrough mode on SRIOV VFs
SRIOV VFs used in macvtap passthrough mode can take advantage of the
SRIOV card's transparent vlan tagging. All the code was there to set
the vlan tag, and it has been used for SRIOV VFs used for hostdev
interfaces for several years, but for some reason, the vlan tag for
macvtap passthrough devices was stubbed out with a -1.

This patch moves a bit of common validation down to a lower level
(virNetDevReplaceNetConfig()) so it is shared by hostdev and macvtap
modes, and updates the macvtap caller to actually send the vlan config
instead of -1.
2016-05-10 14:04:19 -04:00
Erik Skultety
c22ac618b5 admin: Introduce virAdmClientClose API
Once we're able to list and identify all clients connected to a specific
server, we can then support force-closing a connection. This patch introduces
a simple API calling virNetServerClientClose on a specific client, which
can be later extended easily, e.g. by sending an event once the client is
disconnected successfully.

Signed-off-by: Erik Skultety <eskultet@redhat.com>
2016-05-10 16:05:17 +02:00
Erik Skultety
37675f6b66 admin: Remove flags checking from virAdmConnectOpen public API
Unlike the previous commit, we do actually support one client-side only flag
VIR_CONNECT_NO_ALIASES, so besides removing the check for flags this flag
has to be masked out before sending a message to the daemon, otherwise it
would trigger an error when checking flags on the daemon side.

Signed-off-by: Erik Skultety <eskultet@redhat.com>
2016-05-10 15:54:20 +02:00
Erik Skultety
c53595785d admin: Remove flags checking from public API entry points
Due to compatibility reasons these should be checked on the server side.

Signed-off-by: Erik Skultety <eskultet@redhat.com>
2016-05-10 15:50:26 +02:00
Pavel Hrdina
1ccc7fbff3 qemu_hotplug: fix checking graphics ports
We cannot change ports for running domain and we should error out if
autoport is enabled.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2016-05-10 10:44:46 +02:00
Pavel Hrdina
9d88cbea87 qemu_process: merge graphics code into qemuProcessSetupGraphics
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2016-05-10 10:44:45 +02:00
Pavel Hrdina
9f51c1c7c7 graphics: generate fake ports also for tests
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2016-05-10 10:44:45 +02:00
Pavel Hrdina
446aebbcf6 qemu_process: separate graphics port reservation
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2016-05-10 10:44:45 +02:00
Roman Bogorodskiy
9dec97dd00 conf: don't redefine virDomainCapsDeviceHostdev
Commit 5ed235c6 added unnecessary redifinition of
virDomainCapsDeviceHostdev in conf/domain_capabilities.h. This breaks
build with clang 3.4:

In file included from conf/domain_capabilities.c:25:
conf/domain_capabilities.h:88:44: error: redefinition of typedef
'virDomainCapsDeviceHostdev' is a C11 feature
[-Werror,-Wtypedef-redefinition]
typedef struct _virDomainCapsDeviceHostdev virDomainCapsDeviceHostdev;
                                           ^
conf/domain_capabilities.h:86:44: note: previous definition is here
typedef struct _virDomainCapsDeviceHostdev virDomainCapsDeviceHostdev;

So drop one of those.
2016-05-10 07:12:10 +03:00
John Ferlan
9d418b20ae conf: Fix error path in virNodeDevPCICapabilityParseXML
If the call to virXPathNodeSet to set naddresses fails, Coverity notes
that the subsequent VIR_ALLOC_N cannot have a negative value (well it
probably wouldn't be negative per se).

Signed-off-by: John Ferlan <jferlan@redhat.com>
2016-05-09 19:33:57 -04:00
John Ferlan
4fac5a9fd3 Use virGetLastErrorMessage to avoid Coverity message
Both instances use VIR_WARN() to print the error from a failed
virDBusGetSystemBus() call.  Rather than use the virGetLastError
and need to check for valid return err pointer, just use the
virGetLastErrorMessage.

Signed-off-by: John Ferlan <jferlan@redhat.com>
2016-05-09 19:33:56 -04:00
Cole Robinson
f0187c1f27 qemu: command: unconditionally allow accel3d='no'
This matches how we handle spice gl='no' even if spice GL isn't
supported. Not too interesting in practice but I figure we should
be consistent
2016-05-09 16:06:32 -04:00
Cole Robinson
5ed235c68f domaincaps: Report video modelType
Requires adding the plumbing for <device><video>
The value is <enum name='modelType'> to match the associated domain
XML of <video><model type='XXX'/>

Wire it up for qemu too
2016-05-09 16:05:31 -04:00
Cole Robinson
6da27ad1b5 domaincaps: Report graphics type enum
Requires adding the plumbing for <device><graphics>
Wire it up for qemu too
2016-05-09 16:05:31 -04:00
Peter Krempa
4e8b81e5c4 util: polkit: Fix polkit agent startup
Commit 0b36b0e9 broke polkit agent startup when attempting to fix a
coverity warning. Refactor it properly so that we don't need the 'cmd'
intermediate variable.
2016-05-09 13:54:52 +02:00
Peter Krempa
a391a9c5b1 qemu: domain: Don't treat unknown storage type as not having backing chain
qemuDomainCheckDiskPresence has short-circuit code to skip the
determination of the disk backing chain for storage formats that can't
have backing volumes. The code treats VIR_STORAGE_FILE_NONE as not
having backing chain and skips the call to qemuDomainDetermineDiskChain.

This is wrong as qemuDomainDetermineDiskChain is responsible for storage
format detection and has logic to determine the default type if format
detection is disabled.

This allows to storage passed via <disk type="volume"> to circumvent the
enforcement to have correct storage format or that we shall default to
format='raw', since we don't set the default type via the post parse
callback for "volume" backed disks as the translation code could come up
with a better guess.

This resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1328003
2016-05-09 13:40:17 +02:00
Peter Krempa
bd9d707894 qemu: Reject invalid block copy targets for <disk device='lun'>
Extract the relevant parts of the existing checker and reuse them for
blockcopy since copying to a non-block device creates an invalid
configuration.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1209802
2016-05-09 13:16:26 +02:00
Peter Krempa
b66664ffcc qemu: command: Remove unnecessary label in qemuCheckDiskConfig 2016-05-09 13:16:26 +02:00
Peter Krempa
1f880b5f22 conf: Kill now unused virDomainDiskSourceIsBlockType 2016-05-09 13:16:26 +02:00
Peter Krempa
c240335b88 qemu: command: Use more appropriate checking function for block devices
In qemuCheckDiskConfig would now use virDomainDiskSourceIsBlockType just
as a glorified version of virStorageSourceIsBlockLocal that reports
error messages. Replace it with the latter including the message for
clarity.
2016-05-09 13:16:26 +02:00
Peter Krempa
82ba41108a qemu: Support <disk device='lun'> for iSCSI direct mapped volumes
Commit c820fbff9f added support for iSCSI
disk as backing for <disk device='lun'>. We would not use it for a disk
type="volume" with direct access mode which basically maps to direct
iSCSI usage. Fix it by adding the storage source type accessor that
resolves the volume type.
2016-05-09 13:16:26 +02:00
Peter Krempa
5e9d56f83f lxc: Fix wrong error message on disk hotplug
Commit 36025c552 tried to improve error reporting for <disk type="lun">
but reused the code in LXC which doesn't care about the actual disk
type. The error messages would then contain a bogous hint that the
config for the 'lun' device is invalid which might not be the case.

Re-do the relevant portion of the commit with the original message.
2016-05-09 12:44:52 +02:00
Peter Krempa
3ec7bb354a util: Replace virDomainDiskSourceIsBlockType with a new helper
For disks sources described by a libvirt volume we don't need to do a
complicated check since virStorageTranslateDiskSourcePool already
correctly determines the actual disk type.

Replace the checks using a new accessor that does not open-code the
whole logic.
2016-05-09 12:36:52 +02:00
Michal Privoznik
e85d3e1bbe qemu_monitor_json: Follow refactor
In 7884d089d2 I've started to refactor qemu_monitor_json.c.
Thing is, it's current structure is nothing like the rest of our
code. The @ret variable is rewritten all the time, if()-s are
nested instead of using goto and so on.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2016-05-09 09:55:18 +02:00
Pavel Hrdina
3d3d1dfa31 domain_conf: fix migration/managedsave with usb keyboard
Commin 36785c7e refactored the code for input devices but introduced a
bug where we removed all keyboard from migratable XML.  We have to
remove only implicit keyboards like PS2 or XEN.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2016-05-06 15:42:38 +02:00
Pavel Hrdina
351ee40643 qemu_hotplug: cleanup error messages in qemuDomainChangeGraphics
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2016-05-06 15:24:35 +02:00
Pavel Hrdina
39f78671ce qemu_process: handle port allocation for VNC the same way as for Spice
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2016-05-06 14:54:13 +02:00
Pavel Hrdina
df73f1db82 qemu_process: move listen code out of qemuProcessSetupGraphics
Move adding the config listen type=address if there is none in
qemuProcessPrepareDomain and move check for multiple listens to
qemuProcessStartValidate.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2016-05-06 14:52:40 +02:00
Pavel Hrdina
76ee92562e graphics: use enums instead of int
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2016-05-06 14:33:48 +02:00
Michal Privoznik
fb377701f2 virCgroupValidateMachineGroup: Reflect change in CGroup struct naming
Fron c3bd0019c0 on instead of creating the following path for
cgroups:

  /sys/fs/cgroupX/$name.libvirt-$driver

we generate rather more verbose one:

  /sys/fs/cgroupX/$driver-$id-$name.libvirt-$driver

where $name is optional and included iff contains allowed chars.
See original commit for more reasoning. Now, problem with the
original commit is that we are unable to start any LXC domain
after it. Because when starting LXC container, the CGroup layout
is created by our lxc_controller process and then detected and
validated by libvirtd. The validation is done by trying to match
detected layout against all the possible patterns for cgroup
paths that we've ever had. And the commit in question forgot to
update this part of the code.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2016-05-06 12:51:06 +02:00
Jiri Denemark
3af432199d qemu: Export caps cache APIs for tests
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-05-06 10:27:32 +02:00
Jiri Denemark
dccb2629c3 qemu: Separate formatting from saving into caps cache
We will need to use the formatter directly for testing QEMU capabilities
code.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-05-06 10:27:28 +02:00
John Ferlan
bead05ea4d qemu: Introduce qemuDomainSecretIV
Add the data structure and infrastructure to support an initialization
vector (IV) secrets. The IV secret generation will need to have access
to the domain private master key, so let's make sure the prepare disk
and hostdev functions can accept that now.

Anywhere that needs to make a decision over which secret type to use
in order to fill in or use the IV secret has a switch added.

Signed-off-by: John Ferlan <jferlan@redhat.com>
2016-05-05 14:47:51 -04:00
John Ferlan
2ba52ce095 qemu: Separate network URI command building code
Create helper API's in order to build the network URI as shortly we will
be adding a new SecretInfo type

Signed-off-by: John Ferlan <jferlan@redhat.com>
2016-05-05 14:47:51 -04:00
John Ferlan
8ac3b74ad2 qemu: Move qemuDomainSecretDestroy to qemuProcessLaunch
Rather than need to call qemuDomainSecretDestroy after any call to
qemuProcessLaunch, let's do the destroy in qemuProcessLaunch since
that's where command line is eventually generated and processed. Once
it's generated, we can clear out the secrets.

Signed-off-by: John Ferlan <jferlan@redhat.com>
2016-05-05 14:47:51 -04:00
John Ferlan
3619be4971 qemu: Move qemuDomainSecretPrepare to qemuProcessPrepareDomain
Commit id '40d8e2ba3' added the function to qemuProcessStart because
in order to set up some secrets in the future we will need the master
key. However, since the previous patch split the master key creation
into two parts (create just the key and create the file), we can now
call qemuDomainSecretPrepare from qemuProcessPrepareDomain since the
file is not necessary.

Signed-off-by: John Ferlan <jferlan@redhat.com>
2016-05-05 14:47:50 -04:00
John Ferlan
608dfc6af0 qemu: Split out the master key create and write
A recent review of related changes noted that we should split the creation
(or generation) of the master key into the qemuProcessPrepareDomain and leave
the writing of the master key for qemuProcessPrepareHost.

Made the adjustment and modified some comments to functions that have
changed calling parameters, but didn't change the intro doc.

Signed-off-by: John Ferlan <jferlan@redhat.com>
2016-05-05 14:47:50 -04:00
John Ferlan
70ae856e34 qemu: Adjust names of qemuDomainSecretInfoType enums
From a review after push, add the "_TYPE" into the name.

Also use qemuDomainSecretInfoType in the struct rather than int
with the comment field containing the struct name

Signed-off-by: John Ferlan <jferlan@redhat.com>
2016-05-05 14:47:50 -04:00
Cole Robinson
b6238738ea rpc: use virNetMessageClearPayload in client
This removes the opencoded payload freeing in the client, to use
the shared virNetMessageClearPayload call. Two changes:

- ClearPayload sets nfds=0, which fixes a potential crash if
  an error path called virNetMessageFree/Clear on the message
  after fds was free'd
- We drop the inner loop VIR_FORCE_CLOSE... this may mean fds are
  kept open a little bit longer if the call is blocking but in
  practice I don't think it will have any effect
2016-05-05 14:28:19 -04:00
Cole Robinson
64bd680d42 rpc: Clear more in virNetMessageClearPayload
Set all counters to 0. This doesn't impact current users, but
future users will want this
2016-05-05 14:28:19 -04:00
Cole Robinson
220c4e85b3 rpc: Add virNetMessageClearPayload
Handles freeing the buffer and fds, but not the message details.
Use it to drop some duplicate code.
2016-05-05 14:28:19 -04:00
Michal Privoznik
b17e610e1f virNetServerClientNewPostExecRestart: Avoid align problems
I've noticed this while trying to compile libvirt on my arm box.

  CC       rpc/libvirt_net_rpc_server_la-virnetserverclient.lo
rpc/virnetserverclient.c: In function 'virNetServerClientNewPostExecRestart':
rpc/virnetserverclient.c:516:45: error: cast increases required alignment of target type [-Werror=cast-align]
                                             (long long *) &timestamp) < 0) {
                                             ^
cc1: all warnings being treated as errors

Problem is, @timestap is defined as time_t which is 32 bits long,
and we are typecasting it to long long which is 64bits long.
Solution is to make @timestamp type of long long. At the same
time, we can make @conn_time in _virNetServerClient struct long
long too. There is no need for it to be type of time_t.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2016-05-05 13:48:56 +02:00
Michal Privoznik
2a3a2c2f5b virNetServerClientNewPostExecRestart: Drop useless typecasts
In this function, @id is defined as unsigned long long. When
passing this variable to virJSONValueObjectGetNumberUlong(),
well address of this variable, it's typecasted to ull*. There
is no need for that. It's a same story with @nrequests_max.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2016-05-05 13:48:53 +02:00
Jiri Denemark
7197e5fd3f virjson: Make pretty format more compact
json_reformat uses two spaces for when indenting nested objects, let's
do the same. The result of virJSONValueToString will be exactly the same
as json_reformat would produce.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-05-05 10:01:55 +02:00
Jiri Denemark
666d780531 qemu: Make qemuMonitorJSONIOProcessLine available for tests
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-05-05 10:01:55 +02:00
Jiri Denemark
b0b8517eeb qemu: Make virQEMUCapsNewForBinary usable from tests
virQEMUCapsNewForBinary unconditionally loads data from cache and probes
using both QMP and -help parsing, which is suboptimal when we want to
use it in tests.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-05-05 10:01:55 +02:00
Roman Bogorodskiy
9e0bb1c8b6 bhyve: implement domainShutdown
Bhyve supports ACPI shutdown by issuing SIGTERM signal to a bhyve
process.

Add the bhyveDomainShutdown() function and virBhyveProcessShutdown()
helper function that just sends SIGTERM to VM's bhyve process. If
a guest supports ACPI shutdown then process will be terminated and
this event will be noticed by the bhyve monitor code that will handle
setting proper status and clean up VM's resources by calling
virBhyveProcessStop().
2016-05-05 08:04:01 +03:00
Roman Bogorodskiy
c35c2fe78e bhyve: drop virProcessKillPainfully() from destroy
Current implementation of domainDestroy for bhyve calls
virProcessKillPainfully() for the bhyve process and then
executes "bhyvectl --destroy".

This is wrong for two reasons:

 * bhyvectl --destroy alone is sufficient because it terminates
   the process
 * virProcessKillPainfully() first sends SIGTERM and after few
   attempts sends SIGKILL. As SIGTERM triggers ACPI shutdown that
   we're not interested in, it creates an unwanted side effect in
   domainDestroy.

Also, destroy monitor only after "bhyvectl --destroy" command succeeded
to avoid a case when the command fails and domain remains running, but
not being monitored anymore.
2016-05-05 08:01:19 +03:00
Erik Skultety
ca0d45148d admin: Add a check to reject negative argument for number of typed params
Since nparams can be technically negative, it is a good practice throughout
our code to check if nparams actually has a non-negative value. The same effect
would be achieved by converting our internal typed params serializer argument
to 'unsigned' type, but it definitely would not be the path of least resistance.

Signed-off-by: Erik Skultety <eskultet@redhat.com>
2016-05-04 16:36:22 +02:00
John Ferlan
d0b5845952 qemu: Add 'iothread' to command line for supported controller
https://bugzilla.redhat.com/show_bug.cgi?id=1286709

Now that we have all the pieces in place, we can add the 'iothread=#' to
the command line for the (two) controllers that support it (virtio-scsi-pci
and virtio-scsi-ccw). Add the tests as well...
2016-05-04 09:59:14 -04:00
John Ferlan
ade5dae282 qemu: Use switch for qemuCheckIOThreads
Rather than an if statement, use a switch.

The switch will also catch the illegal usage of 'iothread' with some other
kind of unsupported bus configuration.
2016-05-04 09:59:14 -04:00
John Ferlan
e0d0e53086 conf: Add support for virtio-scsi iothreads
Add the ability to add an 'iothread' to the controller which will be how
virtio-scsi-pci and virtio-scsi-ccw iothreads have been implemented in qemu.

Describe the new functionality and add tests to parse/validate that the
new attribute can be added.
2016-05-04 09:59:14 -04:00
John Ferlan
a3aa2005f8 conf: Move virDomainControllerModelTypeToString
Move virDomainControllerModelTypeToString closer to it's counterpart
virDomainControllerModelTypeFromString.

Signed-off-by: John Ferlan <jferlan@redhat.com>
2016-05-03 14:08:05 -04:00
John Ferlan
e2faa97672 qemu: Add capability for virtio-scsi iothreads
An iothread for virtio-scsi is a property of the controller. Add a lookup
of the 'virtio-scsi-pci' and 'virtio-scsi-ccw' device properties and parse
the output.  For both, support for the iothread was added in qemu 2.4
while support for virtio-scsi in general was added in qemu 1.4.

Modify the various mock capabilities replies (by hand) to reflect the
when virtio-scsi was supported and then specifically when the iothread
property was added. For versions prior to 1.4, use the no device error
return for virtio-scsi. For versions 1.4 to before 2.4, add some data
for virtio-scsi-pci even though it isn't complete we're not looking for
anything specific there anyway. For 2.4 to 2.6, add a more complete reply.

Signed-off-by: John Ferlan <jferlan@redhat.com>
2016-05-03 14:08:05 -04:00
Erik Skultety
4a0e910825 admin: Introduce virAdmClientGetInfo API
Expose a public API to retrieve some identity and connection information about
a client connected to the specified server on daemon. The identity info
retrieved is mostly connection transport dependent, i.e. there won't be any
socket address returned for a local (UNIX socket) connection, while on the
other hand, when connected through TLS or unencrypted TCP, obviously no UNIX
process identification will be present in the returned data. All supported
values that can be returned in typed params are exposed and documented in
include/libvirt/libvirt-admin.h

Signed-off-by: Erik Skultety <eskultet@redhat.com>
2016-05-03 15:52:50 +02:00
Erik Skultety
8420a53edf virnetserverclient: Add an internal method to retrieve client's identity
This method just aggregates various client object attributes, like socket
address, connection type (RO/RW), and some TCP/TLS/UNIX identity in an atomic
manner.

Signed-off-by: Erik Skultety <eskultet@redhat.com>
2016-05-03 15:52:50 +02:00
Erik Skultety
bde2cb6136 virneserverclient: Introduce virNetServerClientHasSASLSession
We do have a similar method, serving the same purpose, for TLS, but we lack
one for SASL. So introduce one, in order for other modules to be able to find
out, if a SASL session is active, or better said, that a SASL session exists
at all.

Signed-off-by: Erik Skultety <eskultet@redhat.com>
2016-05-03 15:52:50 +02:00
Erik Skultety
9b45c9f049 virnetsocket: Provide socket address format in a more standard form
Our socket address format is in a rather non-standard format and that is
because sasl library requires the IP address and service to be delimited by a
semicolon. The string form is a completely internal matter, however once the
admin interfaces to retrieve client identity information are merged, we should
return the socket address string in a common format, e.g. format defined by
URI rfc-3986, i.e. the IP address and service are delimited by a colon and
in case of an IPv6 address, square brackets are added:

Examples:
    127.0.0.1:1234
    [::1]:1234

This patch changes our default format to the one described above, while adding
separate methods to request the non-standard SASL format using semicolon as a
delimiter.

Signed-off-by: Erik Skultety <eskultet@redhat.com>
2016-05-03 15:52:50 +02:00
Erik Skultety
52a2eef948 admin: Introduce virAdmServerLookupClient
Just like with server-related APIs, before any of client-based APIs can be
called, a reference to a client-side client object needs to be obtained. For
this purpose, a lookup method should exist. Apart from the client retrieval
logic, a new error code for non-existent client had to be added as well.

Signed-off-by: Erik Skultety <eskultet@redhat.com>
2016-05-03 15:52:50 +02:00
Michal Privoznik
7884d089d2 qemu_monitor_json: Follow our coding style
In majority of our functions we have this variable @ret that is
overwritten a lot. In other areas of the code we use 'goto
cleanup;' just so that this wouldn't happen. But here.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2016-05-03 15:45:44 +02:00
Nikolay Shirokovskiy
3506ad7f0a util: factor out reading file into preallocated buffer
Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
2016-05-03 08:58:30 -04:00
Cole Robinson
600977e293 qemu: support configuring usb3 controller port count
This adds a ports= attribute to usb controller XML, like

  <controller type='usb' model='nec-xhci' ports='8'/>

This maps to:

  qemu -device nec-usb-xhci,p2=8,p3=8

Meaning, 8 ports that support both usb2 and usb3 devices. Gerd
suggested to just expose them as one knob.

https://bugzilla.redhat.com/show_bug.cgi?id=1271408
2016-05-03 08:58:30 -04:00
Cole Robinson
48e12de51e qemu: caps: introduce QEMU_CAPS_NEC_USB_XHCI_PORTS
Reports whether we support -device nec-usb-xhci,p3=XXX value,
which has been available since qemu 1.3.0
2016-05-03 08:58:30 -04:00
Cole Robinson
345d2ab488 qemu: parse: Use virControllerDefNew
Rather than reimplement it. This will be needed in upcoming patches
2016-05-03 08:58:30 -04:00
Michal Privoznik
e2ac519cd2 qemu_monitor_json: Drop redundant checks
In these functions I'm fixing here, we do call
qemuMonitorJSONCheckError() followed by another check if qemu
reply contains 'return' object. If it wouldn't, the former
CheckError() function would error out and the flow would not even
get to the latter.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2016-05-03 14:18:02 +02:00
Michal Privoznik
3af8186898 qemuMonitorJSONQueryRxFilter: Validate qemu reply prior parsing it
Usually, the flow in this area of the code is as follows:

qemuMonitorJSONMakeCommand()
qemuMonitorJSONCommand()
qemuMonitorJSONCheckError()
parseReply()

But in this function, for some reasons, the last two steps were
swapped. This makes no sense.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2016-05-03 14:18:02 +02:00
Ján Tomko
f2b157945f Remove useless os.machine NULL check
In qemuDomainDefAddDefaultDevices we check for a non-NULL
def->os.machine for x86 archs, but not the others.

Moreover, the only caller - qemuDomainDefPostParse
already checks for it and even then it can happen only
if /etc/libvirt contains an XML without a machine type.
2016-05-03 12:29:26 +02:00
Ján Tomko
53a868f152 Introduce qemuDomainMachineIsVirt
Use it everywhere except for virQEMUCapsFillDomainFeatureGICCaps.
2016-05-03 12:08:44 +02:00
Ján Tomko
204b459c1a Rewrite the condition in qemuDomainAssignARMVirtioMMIOAddresses
It was not indented correctly.
2016-05-03 12:08:09 +02:00
Ján Tomko
2d61934a21 Remove useless variable in qemuDomainAssignAddresses
We do not need to propagate the exact return values
and the only possible ones are 0 and -1 anyway.

Remove the temporary variable and use the usual pattern:

if (f() < 0)
    return -1;
2016-05-03 12:07:46 +02:00
Ján Tomko
7c6733a234 Return void in qemuDomainAssignARMVirtioMMIOAddresses
This function does not fail and it does not need to return anything.
2016-05-03 12:07:46 +02:00
Ján Tomko
ef0f90d1b8 Invert condition in qemuDomainDefAddDefaultDevices
For all the other machine types, we use a positive condition.

Be more positive and use it for i440fx too.
2016-05-03 12:07:46 +02:00
Ján Tomko
90f27f07ed Use qemuDomainMachineIs helpers when adding default devices
Do not duplicate the string comparisons by writing them twice.
2016-05-03 12:07:45 +02:00
Michal Privoznik
6ee78d334a qemu: Refresh RTC adjustment on qemuProcessReconnect
https://bugzilla.redhat.com/show_bug.cgi?id=1139766

Thing is, for some reasons you can have your domain's RTC to be
in something different than UTC. More weirdly, it's not only time
zone what you can shift it of, but an arbitrary value. So, if
domain is configured that way, libvirt will correctly put it onto
qemu cmd line and moreover track it as this offset changes during
domain's life time (e.g. because guest OS decides the best thing
to do is set new time to RTC). Anyway, they way in which this
tracking is implemented is events. But we've got a problem if
change in guest's RTC occurs and the daemon is not running. The
event is lost and we end up reporting invalid value in domain
XML. Therefore, when the daemon is starting up again and it is
reconnecting to all running domains, re-fetch their RTC so the
correct offset value can be computed.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2016-05-03 11:44:13 +02:00
Michal Privoznik
b1e2f2d84d qemu: Introduce qemuMonitorGetRTCTime
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2016-05-03 11:44:13 +02:00
Erik Skultety
ed978fa2bc admin: Introduce listing clients
Finally add public method to retrieve the list of currently connected clients
to a given server.

Signed-off-by: Erik Skultety <eskultet@redhat.com>
2016-05-03 10:04:54 +02:00
Erik Skultety
42b06aa65d rpc: virnetserverclient: Implement client connection transport retrieval
Although we document 6 types of transport that we support, internally we can
only differentiate between TCP, TLS, and UNIX transports only, since both SSH
and libssh2 transports, due to using netcat, behave in the exactly the same
way as a UNIX socket.

Signed-off-by: Erik Skultety <eskultet@redhat.com>
2016-05-03 10:04:49 +02:00
Erik Skultety
04bab54d05 rpc: virnetserver: Support retrieval of a list of clients
For now, the list copy is done simply by locking the whole server, walking the
original and increasing the refcount on each object. We may want to change
the list to a lockable object (like list of domains) later in the future if
we discover some performance issues related to locking the whole server in
order to walk the whole list of clients, possibly issuing some 'ForEach'
callback.

Signed-off-by: Erik Skultety <eskultet@redhat.com>
2016-05-02 22:26:23 +02:00
Erik Skultety
4bd430748c rpc: gendispatch: Tune it to support client structure
Now that libvirt-admin supports another client-side object and provided that
we want to generate as many both client-side and server-side RPC dispatchers,
support for this needs to be added to gendispatch.

Signed-off-by: Erik Skultety <eskultet@redhat.com>
2016-05-02 22:26:23 +02:00
Erik Skultety
324945d99b admin: Introduce virAdmClient client-side object
Besides ID, the object also stores static data like connection transport and
connection timestamp, since once obtained a list of all clients connected to a
server, from user's perspective, it would be nice to know whether a given
client is remote or local only and when did it connect to the daemon.
Along with the object introduction, all necessary client-side methods necessary
to work with the object are added as well.

Signed-off-by: Erik Skultety <eskultet@redhat.com>
2016-05-02 22:26:17 +02:00
Erik Skultety
a32135b3b1 rpc: virnetserverclient: Introduce new attribute conn_time to client
Besides ID, libvirt should provide several parameters to help the user
distinguish two clients from each other. One of them is the connection
timestamp. This patch also adds a testcase for proper JSON formatting of the
new attribute too (proper formatting of older clients that did not support
this attribute yet is included in the existing tests) - in order to
testGenerateJSON to work, a mock of time_t time(time_t *timer) needed to be
created.

Signed-off-by: Erik Skultety <eskultet@redhat.com>
2016-05-02 22:25:52 +02:00
Erik Skultety
5841d64d25 rpc: virnetserverclient: Identify clients by an integer ID
Admin API needs a way of addressing specific clients. Unlike servers, which we
are happy to address by names both because its name reflects its purpose (to
some extent) and we only have two of them (so far), naming clients doesn't make
any sense, since a) each client is an anonymous, i.e. not recognized after a
disconnect followed by a reconnect, b) we can't predict what kind of requests
it's going to send to daemon, and c) the are loads of them comming and going,
so the only viable option is to use an ID which is of a reasonably wide data
type.

Signed-off-by: Erik Skultety <eskultet@redhat.com>
2016-05-02 22:25:51 +02:00
Boris Fiuczynski
73e4e10e62 qemu: add default panic device to S390 guests
This patch adds by default a panic device with model s390 to S390 guests.

Signed-off-by: Boris Fiuczynski <fiuczy@linux.vnet.ibm.com>
2016-05-02 17:01:40 +02:00
Boris Fiuczynski
d855465452 qemu: add panic device support for S390
If a panic device is being defined without a model in a domain
the default value is always overwritten with model ISA. An ISA
bus does not exist on S390 and therefore specifying a panic device
results in an unsupported configuration.
Since the S390 architecture inherently provides a crash detection
capability the panic device should be defined in the domain xml.

This patch adds an s390 panic device model and prevents setting a
device address on it.

Signed-off-by: Boris Fiuczynski <fiuczy@linux.vnet.ibm.com>
Reviewed-by: Cornelia Huck <cornelia.huck@de.ibm.com>
2016-05-02 17:01:40 +02:00
Boris Fiuczynski
b43ab240c2 qemu: merge S390 and S390X default device creation
Signed-off-by: Boris Fiuczynski <fiuczy@linux.vnet.ibm.com>
2016-05-02 17:01:40 +02:00
Boris Fiuczynski
a1574e5c98 qemu: fix error message for default panic device
Adding the default bus type ISA to the message.

Signed-off-by: Boris Fiuczynski <fiuczy@linux.vnet.ibm.com>
2016-05-02 17:01:40 +02:00
Cole Robinson
a5481546d6 fdstream: don't raise error on SIGPIPE if abort requested
The iohelper dies on SIGPIPE if the stream is closed before all data
is processed. IMO this should be an error condition for virStreamFinish
according to docs like:

  * This method is a synchronization point for all asynchronous
  * errors, so if this returns a success code the application can
  * be sure that all data has been successfully processed.

However for virStreamAbort, not so much:

  * Request that the in progress data transfer be cancelled
  * abnormally before the end of the stream has been reached.
  * For output streams this can be used to inform the driver
  * that the stream is being terminated early. For input
  * streams this can be used to inform the driver that it
  * should stop sending data.

Without this, virStreamAbort will realistically always error for
active streams like domain console. So, treat the SIGPIPE case
as non-fatal if abort is requested.

Note, this will only affect an explicit user requested abort. An
abnormal abort, like from a server error, always raises an error
in the daemon.
2016-05-02 10:13:05 -04:00
Cole Robinson
8958dde506 rpc: protocol: Clarify VIR_NET_ERROR usage with streams
The described protocol semantics really only apply to server initiated
stream messages. Document the semantics for client messages.
2016-05-02 10:13:04 -04:00
Cole Robinson
c48db92fbd fdstream: Raise explicit error when iohelper gets SIGPIPE
This happens when virStreamFinish/Abort are called, but iohelper
still has data to process.
2016-05-02 10:13:04 -04:00
Cole Robinson
6b173cf562 fdstream: Report error with virProcessTranslateStatus
Rather than poorly duplicate it
2016-05-02 10:13:04 -04:00
Cole Robinson
c0e870376c fdstream: separate out virCommandPtr cleanup
Let's us de-nest some of the logic, and will simplify upcoming
patches
2016-05-02 10:12:58 -04:00
Cole Robinson
441e881e9a nwfilter: Save config to disk if we generated a UUID
libvirt-daemon-config-nwfilter will put a bunch of xml configs
into /etc/libvirt/nwfilter. These configs don't hardcode a UUID
and depends on libvirt to generate one. However the generated UUID
is never saved to disk, unless the user manually calls Define.

This makes daemon reload quite noisy with many errors like:

error : virNWFilterObjAssignDef:3101 : operation failed: filter 'allow-incoming-ipv4' already exists with uuid 50def3b5-48d6-46a3-b005-cc22df4e5c5c

Because a new UUID is generated every time the config is read from
disk, so libvirt constantly thinks it's finding a new nwfilter.

Detect if we generated a UUID when the config file is loaded; if so,
resave the new contents to disk to ensure the UUID is persisteny.

This is similar to what was done in commit a47ae7c0 with virtual
networks and generated MAC addresses
2016-05-02 10:06:04 -04:00
Cole Robinson
0feb1c6c24 nwfilter: Push configFile building into LoadConfig
This matches the pattern used for network object APIs, and we want
configDir in LoadConfig for upcoming patches
2016-05-02 10:06:04 -04:00
Cole Robinson
ab05abdbc3 nwfilter: Fix potential locking problems on ObjLoad failure
In virNWFilterObjLoad we can still fail after virNWFilterObjAssignDef,
but we don't unlock and free the created virNWFilterObjPtr in the
cleanup path.

The bit we are trying to do after AssignDef is just STRDUP in the
configFile path. However caching the configFile in the NWFilterObj
is largely redundant and doesn't follow the same pattern we use
for domain and network objects.

So just remove all the configFile caching which fixes the latent
bug as a side effect.
2016-05-02 10:06:04 -04:00
Cole Robinson
26af7e4e93 network: Fix segfault on daemon reload
We will segfault of a daemon reload picks up a new network config
that needs to be autostarted. We shouldn't be passing NULL for
network_driver here. This seems like it was missed in the larger
rework in commit 1009a61e
2016-05-02 10:06:04 -04:00
Shivaprasad G Bhat
192a53e07c send default USB controller in xml to destination during migration
The default USB controller is not sent to destination as the older versions
of libvirt(0.9.4 or earlier as I see in commit log of 409b5f54) didn't
support them. For some archs where the support started much later can
safely send the USB controllers without this worry. So, send the controller
to destination for all archs except x86. Moreover this is not very applicable
to x86 as the USB controller has model ich9_ehci1 on q35 and for pc-i440fx,
there cant be any slots before USB as it is fixed on slot 1.

The patch fixes a bug that, if the USB controller happens to occupy
a slot after disks/interfaces and one of them is hot-unplugged, then
the default USB controller added on destination takes the smallest slot
number and that would lead to savestate mismatch and migration
failure. Seen and verified on PPC64.

Signed-off-by: Shivaprasad G Bhat <sbhat@linux.vnet.ibm.com>
2016-05-02 10:06:04 -04:00
Cole Robinson
601531d6ea conf: format runtime DAC seclabel, unless MIGRATABLE
We historically format runtime seclabel selinux/apparmor values,
however we skip formatting runtime DAC values. This was added in

commit 990e46c454
Author: Marcelo Cerri <mhcerri@linux.vnet.ibm.com>
Date:   Fri Aug 31 13:40:41 2012 +0200

    conf: Avoid formatting auto-generated DAC labels

to maintain migration compatibility with libvirt < 0.10.0.

However the formatting was skipped unconditionally. Instead only
skip formatting in the VIR_DOMAIN_DEF_FORMAT_MIGRATABLE case.

https://bugzilla.redhat.com/show_bug.cgi?id=1215833
2016-05-02 10:06:04 -04:00
Cole Robinson
20b52668dd conf: storage: pool: reject name containing '/'
Trying to define a pool name containing an embedded '/'
will immediately fail when trying to write the XML to disk.
This patch explicitly rejects names containing a '/'

Besides our stateful driver, there are two other storage impls:
esx and phyp. esx doesn't support pool creation, so this should
doesn't apply.

phyp does support pool creation, and the name is passed to the
'mksp' tool, which google doesn't reveal whether it accepts '/'
or not. IMO the likeliness of this impacting any users is near zero
2016-05-02 10:06:04 -04:00
Cole Robinson
454f739f24 conf: network: reject name containing '/'
Trying to define a network name containing an embedded '/'
will immediately fail when trying to write the XML to disk.
This patch explicitly rejects names containing a '/'

Besides the network bridge driver, the only other network
implementation is a very thin one for virtualbox, which seems to
use the network name as a host interface name, which won't
accept '/' anyways, so I think this is fine to do unconitionally.

https://bugzilla.redhat.com/show_bug.cgi?id=787604
2016-05-02 10:06:04 -04:00
Cole Robinson
b1fc6a7b73 conf: domain: reject name containing '/'
Trying to define a domain name containing an embedded '/'
will immediately fail when trying to write the XML to disk for
our stateful drivers. This patch explicitly rejects names
containing a '/', and provides an xmlopt feature for drivers
to avoid this validation check, which is enabled in every
non-stateful driver that already has xmlopt handling wired up.

(Technically this could reject a previously accepted vmname like
 '/foo', however at least for the qemu driver that falls over
 later when starting qemu)

https://bugzilla.redhat.com/show_bug.cgi?id=639923
2016-05-02 10:06:04 -04:00
Martin Kletzander
541f21afa6 conf: Parse more of our nodedev XML
We were lacking tests that are checking for the completeness of our
nodedev XMLs and also whether we output properly formatted ones.  This
patch adds parsing for the capability elements inside the <capability
type='pci'> element.  Also bunch of tests are added to show everything
works properly.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2016-05-02 15:46:23 +02:00
Martin Kletzander
88c8be67d4 Move capability formatting together
All sub-PCI capabilities should be next to each other for clarity.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2016-05-02 15:46:23 +02:00
Martin Kletzander
c36b1f7b6a Change virDevicePCIAddress to virPCIDeviceAddress
We had both and the only difference was that the latter also included
information about multifunction setting.  The problem with that was that
we couldn't use functions made for only one of the structs (e.g.
parsing).  To consolidate those two structs, use the one in virpci.h,
include that in domain_conf.h and add the multifunction member in it.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2016-05-02 15:46:23 +02:00
John Ferlan
573cfd188c qemu: hotplug: Fix possible memory leak of props
If we failed to build the aliases or attach the chardev, then the props
would be leaked - fix that.

Signed-off-by: John Ferlan <jferlan@redhat.com>
2016-05-02 06:29:21 -04:00
John Ferlan
3e81b98ceb qemu: hotplug: Adjust error path for attach hostdev scsi disk
Adjust error path logic to make it clearer how to undo the failed add.

Signed-off-by: John Ferlan <jferlan@redhat.com>
2016-05-02 06:29:21 -04:00
John Ferlan
843ae77896 qemu: hotplug: Adjust error path for attach virtio disk
Adjust error path logic to make it clearer how to undo the failed add.

Signed-off-by: John Ferlan <jferlan@redhat.com>
2016-05-02 06:29:21 -04:00
John Ferlan
b0e002fcfd qemu: hotplug: Adjust error path for attach scsi disk
Adjust error path logic to make it clearer how to undo the failed add.

Signed-off-by: John Ferlan <jferlan@redhat.com>
2016-05-02 06:22:56 -04:00
John Ferlan
db5b47fd4a qemu: Use qemuDomainSecretInfoPtr in qemuBuildNetworkDriveURI
Rather than take username and password as parameters, now take
a qemuDomainSecretInfoPtr and decode within the function.

NB: Having secinfo implies having the username for a plain type
    from a successful virSecretGetSecretString

Signed-off-by: John Ferlan <jferlan@redhat.com>
2016-05-02 06:10:19 -04:00
John Ferlan
d081665045 qemu: Introduce qemuDomainSecretHostdevPrepare and Destroy
Similar to the qemuDomainSecretDiskPrepare, generate the secret
for the Hostdev's prior to call qemuProcessLaunch which calls
qemuBuildCommandLine. Additionally, since the secret is not longer
added as part of building the command, the hotplug code will need
to make the call to add the secret in the hostdevPriv.

Since this then is the last requirement to pass a virConnectPtr
to qemuBuildCommandLine, we now can remove that as part of these
changes. That removal has cascading effects through various callers.

Signed-off-by: John Ferlan <jferlan@redhat.com>
2016-05-02 06:10:19 -04:00
John Ferlan
27726d8c21 qemu: Introduce qemuDomainHostdevPrivatePtr
Modeled after the qemuDomainDiskPrivatePtr logic, create a privateData
pointer in the _virDomainHostdevDef to allow storage of private data
for a hypervisor in order to at least temporarily store auth/secrets
data for usage during qemuBuildCommandLine.

NB: Since the qemu_parse_command (qemuParseCommandLine) code is not
expecting to restore the auth/secret data, there's no need to add
code to handle this new structure there.

Updated copyrights for modules touched. Some didn't have updates in a
couple years even though changes have been made.

Signed-off-by: John Ferlan <jferlan@redhat.com>
2016-05-02 06:10:19 -04:00
John Ferlan
40d8e2ba37 qemu: Introduce qemuDomainSecretPrepare and Destroy
Rather than needing to pass the conn parameter to various command
line building API's, add qemuDomainSecretPrepare just prior to the
qemuProcessLaunch which calls qemuBuilCommandLine. The function
must be called after qemuProcessPrepareHost since it's expected
to eventually need the domain masterKey generated during the prepare
host call. Additionally, future patches may require device aliases
(assigned during the prepare domain call) in order to associate
the secret objects.

The qemuDomainSecretDestroy is called after the qemuProcessLaunch
finishes in order to clear and free memory used by the secrets
that were recently prepared, so they are not kept around in memory
too long.

Placing the setup here is beneficial for future patches which will
need the domain masterKey in order to generate an encrypted secret
along with an initialization vector to be saved and passed (since
the masterKey shouldn't be passed around).

Finally, since the secret is not added during command line build,
the hotplug code will need to get the secret into the private disk data.

Signed-off-by: John Ferlan <jferlan@redhat.com>
2016-05-02 06:10:19 -04:00