Commit Graph

16386 Commits

Author SHA1 Message Date
Maxim Nestratov
a9555e202e vz: move prlsdkCheckDiskUnsupportedParams to vz_utils.c
As long as we have another function checking disk parameters correctness,
let's have them in one place. Here we change prefix of the moved function and
start to call it from vzCheckUnsupportedDisks rather than add disk.

Signed-off-by: Maxim Nestratov <mnestratov@virtuozzo.com>
2016-03-16 19:34:27 +03:00
Mikhail Feoktistov
adbe76fb42 vz: check supported disk format and bus
Now we check disk parameters correctness in DomainPostParse.

Signed-off-by: Maxim Nestratov <mnestratov@virtuozzo.com>
2016-03-16 19:34:27 +03:00
Mikhail Feoktistov
19d979edff vz: add vzCapabilities to connection structure
As far as Virtuozzo6 and Virtuozzo7 support different disk types for virtual
machines (ploop and qcow2 respectively) and different buses (vz6: IDE, SCSI,
SATA; vz7: IDE SCSI) we add vzCapabilities structure to help undestand which
disk formats and buses are supported in the context of a current connection.

When a new connection opens, we select proper capabilities in accordance to
current Virtuozzo version.
2016-03-16 19:34:26 +03:00
Mikhail Feoktistov
d10b02b5e5 vz: save vz version in connection structure
Move code from connectGetVersion callback to vzInitVersion function
2016-03-16 19:34:26 +03:00
Erik Skultety
0b231195cb virlog: Refactor virLogParseOutputs
The problem with the original virLogParseOutputs method was that the way it
parsed the input, walking the string char by char and using absolute jumps
depending on the virLogDestination type, was rather complicated to read.
This patch utilizes virStringSplit method twice, first time to filter out any
spaces and split the input to individual log outputs and then for each
individual output to tokenize it by to the parts according to our
PRIORITY:DESTINATION?(:DATA) format. Also, to STREQLEN for matching destination
was replaced with virDestinationTypeFromString call.
2016-03-16 14:28:24 +01:00
Erik Skultety
034337fb85 virlog: Introduce Type{To,From}String for virLogDestination
In order to refactor the ugly virLogParseOutputs method, this is a neat way of
finding out whether the destination type (in the form of a string) user
provided is a valid one. As a bonus, if it turns out it is valid, we get the
actual enum which will later be passed to any of virLogAddOutput methods right
away.
2016-03-16 14:24:15 +01:00
Martin Kletzander
c1276177f8 nodedev: Shorten match condition
Just a cleanup I stumbled upon in one of my older branches I did when
browsing through some code and forgot to send it.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2016-03-16 10:49:12 +01:00
Martin Kletzander
71fa2eb26c qemu: Don't access uninitialized memory
In qemuConnectDomainXMLToNative() we set up the monitor, but we never
memset() it to zeros.  Thanks to the introduction of the logfile
parameter of chardevs (and the logfile member of the struct), we started
checking whether that's non-NULL and that exposed this old error.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2016-03-16 10:49:12 +01:00
Cole Robinson
26f3d9c26c qemu: Don't overwrite DomainSave errors
These functions already report fine grained errors, there's no
benefit to overwriting the error here.
2016-03-15 15:43:34 -04:00
Dmitry Andreev
c5e81090ea qemuDomainRevertToSnapshot: save domain configuration
Reverting to a snapshot may change domain configuration. New
configuration should be saved if domain has persistent flag.

VIR_DOMAIN_EVENT_DEFINED_FROM_SNAPSHOT is emitted in case of
configuration update.
2016-03-15 14:57:26 -04:00
John Ferlan
5b3103e0ad qemu: Introduce qemuBuildPanicCommandLine
Add new function to manage adding the panic device options to the
command line removing that task from the mainline qemuBuildCommandLine.

Signed-off-by: John Ferlan <jferlan@redhat.com>
2016-03-15 07:10:22 -04:00
John Ferlan
928d2ffe2a qemu: Introduce qemuBuildNVRAMCommandLine
Add new function to manage adding the NVRAM device options to the
command line removing that task from the mainline qemuBuildCommandLine.

Signed-off-by: John Ferlan <jferlan@redhat.com>
2016-03-15 07:10:22 -04:00
John Ferlan
b12acd31af qemu: Introduce qemuBuildRNGCommandLine
Add new function to manage adding the RNG device options to the
command line removing that task from the mainline qemuBuildCommandLine.

Also modify the qemuBuildRNGDevStr to use const virDomainDef instead
of virDomainDefPtr.

Signed-off-by: John Ferlan <jferlan@redhat.com>
2016-03-15 07:10:22 -04:00
John Ferlan
00e47796a9 qemu: Introduce qemuBuildMemballoonCommandLine
Add new function to manage adding the memballoon device options to the
command line removing that task from the mainline qemuBuildCommandLine.

Also modify the qemuBuildMemballoonDevStr to use const virDomainDef
instead of virDomainDefPtr.

Signed-off-by: John Ferlan <jferlan@redhat.com>
2016-03-15 07:10:22 -04:00
John Ferlan
d2108df57c qemu: Introduce qemuBuildHostdevCommandLine
Add new function to manage adding the host device options to the
command line removing that task from the mainline qemuBuildCommandLine.

Also modify qemuBuildPCIHostdevDevStr, qemuBuildUSBHostdevDevStr,
and qemuBuildSCSIHostdevDevStr to use const virDomainDef instead
of virDomainDefPtr.

Make qemuBuildPCIHostdevPCIDevStr and qemuBuildUSBHostdevUSBDevStr
static to the qemu_command.c.

Signed-off-by: John Ferlan <jferlan@redhat.com>
2016-03-15 07:10:22 -04:00
John Ferlan
59e7ef3c1f qemu: Introduce qemuBuildRedirdevCommandLine
Add new function to manage adding the redirdev device options to the
command line removing that task from the mainline qemuBuildCommandLine.

Also move the qemuBuildRedirdevDevStr closer to the new function and
modify to use the const virDomainDef instead of virDomainDefPtr

Signed-off-by: John Ferlan <jferlan@redhat.com>
2016-03-15 07:10:22 -04:00
John Ferlan
4666b762b9 qemu: Introduce qemuBuildWatchdogCommandLine
Add new function to manage adding the watchdog device options to the
command line removing that task from the mainline qemuBuildCommandLine.

Also since qemuBuildWatchdogDevStr was only local here, make it static as
well as modifying the const virDomainDef.

Signed-off-by: John Ferlan <jferlan@redhat.com>
2016-03-15 07:10:22 -04:00
John Ferlan
1a91ddb496 qemu: Introduce qemuBuildSoundCommandLine
Add new function to manage adding the sound device options to the
command line removing that task from the mainline qemuBuildCommandLine.

Also since qemuBuildSoundDevStr was only local here, make it static as
well as modifying the const virDomainDef.

Signed-off-by: John Ferlan <jferlan@redhat.com>
2016-03-15 07:10:22 -04:00
Andrea Bolognani
5fc68bd4b1 hostdev: Add more comments
These comments explain the difference between a virPCIDevice
instance used for lookups and an actual device instance; some
information is also provided for specific uses.
2016-03-15 10:34:58 +01:00
Andrea Bolognani
800dd16d84 hostdev: Use consistent variable names
This is not just a cosmetic change: the name of the variable now
gives a hint about what it is supposed to be used for.
2016-03-15 10:33:18 +01:00
Andrea Bolognani
4cdbff3d52 hostdev: Remove virHostdevGetActivePCIHostDeviceList()
virHostdevGetPCIHostDeviceList() is similar but does not filter out
devices that are not in the active list; that said, we are looking
up the device in the active list just a few lines after anyway, so
we might as well just keep a single function around.

This also helps stress the fact the objects contained in pcidevs are
only for looking up the actual devices, which is something later
commits will make even more explicit.
2016-03-15 10:33:17 +01:00
Andrea Bolognani
8e3ac3ed73 hostdev: Rename usesVfio -> usesVFIO
Acronyms should be written in all caps.
2016-03-14 14:55:47 +01:00
Andrea Bolognani
95c65ae193 hostdev: Rename hostdev_mgr -> mgr
We're in the hostdev module, so mgr is not an ambiguous name, and
in fact it's already used in some cases. Switch all the code over.

Take the chance to shorten declaration of
virHostdevIsPCINodeDeviceUsedData structures.
2016-03-14 14:55:47 +01:00
Andrea Bolognani
36243a0c62 hostdev: Look up devices using IDs when possible
When we want to look up a device in a device list and we already
have the IDs from another source, we can simply use
virPCIDeviceListFindByIDs() instead of creating a temporary device
object.
2016-03-14 14:55:47 +01:00
Andrea Bolognani
e57e9413ac hostdev: Change argument order for virHostdevReattachPCIDevice()
The new order aligns better with the virHostdev prefix.
2016-03-14 14:55:47 +01:00
Andrea Bolognani
5ce91139da hostdev: virHostdevIsPCINetDevice() should return a bool
The only possible return values are true and false, so the return
type should be bool instead of int.
2016-03-14 14:55:47 +01:00
Andrea Bolognani
2ec4664b1e hostdev: Rework resetvfnetconfig loop condition
If 'last_processed_hostdev_vf != -1' is false then, since the
loop counter 'i' starts at 0, 'i <= last_processed_hostdev_vf'
can't possibly be true and the loop body will never be executed.

However, since 'i' is unsigned and 'last_processed_hostdev_vf'
is signed, we can't just get rid of the check completely; what
we can do is move it outside of the loop to avoid checking its
value on every iteration and cluttering the actual loop
condition.
2016-03-14 14:55:47 +01:00
Maxim Nestratov
8a74498721 vz: fix active domain listing
Since commit 9c14a9ab we have broken active domain listing
because reworked prlsdkLoadDomain doesn't set dom->def->id
propely. It just looses it when a new def structure is set.
Now we make prlsdkConvertDomainState function return void
and move calling it after an old dom->def is replaces with
a new one within prlsdkLoadDomain function.

Signed-off-by: Maxim Nestratov <mnestratov@virtuozzo.com>
2016-03-14 15:12:10 +03:00
Michal Privoznik
2e70af12f2 qemuBuildVideoCommandLine: Don't access def->videos without check
This function can be called over a domain definition that has no
video configured. The
tests/qemuxml2argvdata/qemuxml2argv-minimal.xml file could serve
as an example. Problem is, before the check that domain has some
or none video configured, def->videos is dereferenced causing a
segmentation fault in case there's none video configured.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2016-03-14 09:34:43 +01:00
John Ferlan
95ca4fe2f2 qemu: Introduce qemuBuildVideoCommandLine
Add new function to manage adding the video device options to the
command line removing that task from the mainline qemuBuildCommandLine.

Signed-off-by: John Ferlan <jferlan@redhat.com>
2016-03-11 19:23:46 -05:00
John Ferlan
60b1ff52f5 qemu: Introduce qemuBuildInputCommandLine
Add new function to manage adding the input device options to the
command line removing that task from the mainline qemuBuildCommandLine.

Make qemuBuildUSBInputDevStr static since only this module calls it.

Also the change to use const virDomainDef forces other changes.

Signed-off-by: John Ferlan <jferlan@redhat.com>
2016-03-11 19:23:46 -05:00
John Ferlan
9de54baf26 qemu: Modify qemuBuildTPMCommandLine
Modify the argument order and types to match other similar helpers.

Also modify called functions to use the def->emulator instead of passing
def->emulator and def.

Signed-off-by: John Ferlan <jferlan@redhat.com>
2016-03-11 19:23:46 -05:00
John Ferlan
e6944a529e qemu: Introduce qemuBuildConsoleCommandLine
Add new function to manage adding the console device options to the
command line removing that task from the mainline qemuBuildCommandLine.

Signed-off-by: John Ferlan <jferlan@redhat.com>
2016-03-11 19:23:46 -05:00
John Ferlan
3cdcc910a0 qemu: Introduce qemuBuildChannelsCommandLine
Add new function to manage adding the channel device options to the
command line removing that task from the mainline qemuBuildCommandLine.

Signed-off-by: John Ferlan <jferlan@redhat.com>
2016-03-11 19:23:46 -05:00
John Ferlan
0e1e7ade29 qemu: Introduce qemuBuildParallelsCommandLine
Add new function to manage adding the parallels device options to the
command line removing that task from the mainline qemuBuildCommandLine.
Alter logic slight to reduce indention level.

Signed-off-by: John Ferlan <jferlan@redhat.com>
2016-03-11 19:23:46 -05:00
John Ferlan
5ab86400bf qemu: Introduce qemuBuildSerialCommandLine
Add new function to manage adding the serial device options to the
command line removing that task from the mainline qemuBuildCommandLine.

Using const virDomainDef causes collateral damage in other called APIs
which need to make the similar adjustment

Signed-off-by: John Ferlan <jferlan@redhat.com>
2016-03-11 19:23:46 -05:00
John Ferlan
858bafebbf qemu: Introduce qemuBuildSmartcardCommandLine
Add new function to manage adding the smartcard device options to the
command line removing that task from the mainline qemuBuildCommandLine.

Alter the logic slightly to make !nsmartcards check first so that remainder
of the code is less indented.

Signed-off-by: John Ferlan <jferlan@redhat.com>
2016-03-11 19:23:45 -05:00
Martin Kletzander
eeb1e6fe9f gendispatch: Use proper error for limit checking
All other places use VIR_ERR_RPC except this one, let's be consistent,
shall we?

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2016-03-11 12:58:41 +01:00
Martin Kletzander
42b85f173d remote: Generate what's possible
Since gendisplatch can now generate "modern" *ListAll* functions, let
them all be generated.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2016-03-11 12:58:41 +01:00
Martin Kletzander
5b7d09804c gendispatch: Support modern listing of more types
Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2016-03-11 12:58:41 +01:00
Martin Kletzander
576c54f9b1 gendispatch: Remember the name of snapshot variable name
Until now, the script assumed that snapshot name is 'snap', but that's
going to change.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2016-03-11 12:58:41 +01:00
Martin Kletzander
1cefc14f69 gendispatch: Accept server as an argument
Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2016-03-11 12:58:41 +01:00
Martin Kletzander
d949280c72 admin: Generate ConnectListServers dispatch helpers
Since we have the opportunity now, let's save some precious code lines.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2016-03-11 12:58:41 +01:00
Martin Kletzander
6de2ef5d35 gendispatch: Be able to generate multi-return values
Let's call it modern_ret_as_list as opposed to single_ret_as_list.  The
latter was able to return list of things.  However the new, more modern,
version came and it is used since listAllDomains till nowadays in
ListServers.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2016-03-11 12:58:41 +01:00
Martin Kletzander
30c4931d28 gendispatch: Cluster, don't capture if not needed
We were using parentheses for grouping admin|remote even though we didn't
need to capture what's in it.  That caused some changes to be greater
than needed and, to be honest, some confusion as well.  Let's use it as
it should be used.  It'll also make future changes more consistent.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2016-03-11 12:58:41 +01:00
Martin Kletzander
335bc13cc1 admin: Be consistent when resetting errors
Resetting an error should be the first thing public API does.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2016-03-11 12:58:41 +01:00
Martin Kletzander
8fcb81d2de admin: Don't use priority for admin APIs
There are no priority workers as they don't make sense for now.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2016-03-11 12:58:41 +01:00
Martin Kletzander
d4218ca64f Change virNetDaemonGetServerNames to virNetDaemonGetServers
For now it does not matter which ones we return as the code is similarly
complex, however it will fit in with other constructs in the future,
mainly when we will be able to generate dispatch helpers.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2016-03-11 12:58:41 +01:00
Martin Kletzander
83942e5b6a Expose virNetServerGetName
Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2016-03-11 12:58:41 +01:00
Martin Kletzander
6541a2b4ac daemon: Properly check for clients
virHashForEach() returns 0 if everything went nice, so our session
daemon was timing out even when there was a client connected.

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

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2016-03-11 12:58:41 +01:00
Martin Kletzander
cd0a980ee1 daemon: Set error for unknown server name
Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2016-03-11 12:58:41 +01:00
Martin Kletzander
62be54861b virerror: Introduce new error type NO_SERVER
This serves the same purpose as VIR_ERR_NO_xxx where xxx is any object
that API can be called upon.  Only this particular one is used for
daemon's servers.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2016-03-11 12:58:41 +01:00
Martin Kletzander
fd4f278e1a daemon: Get server name from the server itself
Since servers know their name, there is no need to supply such
information twice.  Also defeats inconsistencies.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2016-03-11 12:58:41 +01:00
Martin Kletzander
dad3b07814 server: Store server name in server object
At first I did not want to do this, but after trying to implement some
newer feaures in the admin API I realized we need that to make our lives
easier.  On the other hand they are not saved redundantly and the
virNetServer objects are still kept in a hash table.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2016-03-11 12:58:41 +01:00
Martin Kletzander
b04e39ff86 admin: Check for flags properly
Function virAdmConnectListServers() forgot to check for flags at all,
virAdmConnectOpen() on the other hand checked them but did no dispatch
the error.  virCheckFlags() should be used only when there should be no
other thing done after erroring out and since they are used on different
places then just public API, they cannot dispatch errors.  So let's use
virCheckFlagsGoto instead.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2016-03-11 12:58:41 +01:00
Martin Kletzander
23a646f840 admin: Make virAdmServerFree() handle NULL gracefully
We don't want to end up like with virDomainFree() and other, right?

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2016-03-11 12:58:41 +01:00
John Ferlan
ef2ab8fdc5 qemu: Introduce qemuBuildNetCommandLine
Add new function to manage adding the network device options to the
command line removing that task from the mainline qemuBuildCommandLine.

Signed-off-by: John Ferlan <jferlan@redhat.com>
2016-03-11 06:32:20 -05:00
John Ferlan
3dbc2a149f qemu: Introduce qemuBuildFSDevCommandLine
Add new function to manage adding the -fsdev options to the
command line removing that task from the mainline qemuBuildCommandLine.
Alter the code slightly to perform the !caps and fsdev failure check
up front.

Since both qemuBuildFSStr and qemuBuildFSDevStr are local, make them
static and fix their prototypes to use the const virDomainDef as well.
Make some minor formatting changes for long lines.

Signed-off-by: John Ferlan <jferlan@redhat.com>
2016-03-11 06:31:05 -05:00
John Ferlan
0ea0f6c496 qemu: Introduce qemuBuildDiskDriveCommandLine
Add new function to manage adding the disk -drive options to the
command line removing that task from the mainline qemuBuildCommandLine.

Also since using const virDomainDef in new function, that means other
functions called needed to change their usage.

Signed-off-by: John Ferlan <jferlan@redhat.com>
2016-03-11 06:17:06 -05:00
John Ferlan
f87be33a6f qemu: Introduce qemuBuildHubCommandLine
Add new function to manage adding the hub -device options to the
command line removing that task from the mainline qemuBuildCommandLine.

Also make qemuBuildHubDevStr static to the module since it's only
used here.

Signed-off-by: John Ferlan <jferlan@redhat.com>
2016-03-11 06:17:06 -05:00
John Ferlan
4908772e15 qemu: Introduce qemuBuildControllerDevCommandLine
Add new function to manage adding the controller -device options to the
command line removing that task from the mainline qemuBuildCommandLine.

Also adjust to using const virDomainDef instead of virDomainDefPtr.
This causes collateral damage in order to modify called APIs to use
the const virDomainDef instead as well.

Signed-off-by: John Ferlan <jferlan@redhat.com>
2016-03-11 06:17:06 -05:00
John Ferlan
73379375c8 qemu: Introduce qemuBuildGlobalControllerCommandLine
Add new function to manage adding the -global controller options to
the command line removing that task from the mainline qemuBuildCommandLine.

Signed-off-by: John Ferlan <jferlan@redhat.com>
2016-03-11 06:17:05 -05:00
John Ferlan
44616e3304 qemu: Introduce qemuBuildBootCommandLine
Add new function to manage adding the -boot options to the command
line removing that task from the mainline qemuBuildCommandLine.

Signed-off-by: John Ferlan <jferlan@redhat.com>
2016-03-11 06:17:05 -05:00
John Ferlan
d6d31e00eb qemu: Introduce qemuBuildPMCommandLine
Add new function to manage adding the power management options to the
command line removing that task from the mainline qemuBuildCommandLine.

Signed-off-by: John Ferlan <jferlan@redhat.com>
2016-03-11 06:17:05 -05:00
John Ferlan
05e9790802 qemu: Introduce qemuBuildClockCommandLine
Add new function to manage adding the '-clock' options to the command
line removing that task from the mainline qemuBuildCommandLine.

Also includes some minor formatting cleanups.

Signed-off-by: John Ferlan <jferlan@redhat.com>
2016-03-11 06:17:05 -05:00
Marc-André Lureau
1e34a8f919 qemu: enable debug threads
When debug-threads is enabled, individual threads are given a separate
name (on Linux)

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

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-03-10 22:54:40 +01:00
Marc-André Lureau
0683ffc2ea qemu: check for debug-threads capability
QEMU (somewhere around 2.0) added a new sub-option to the -name flag
-name debug-threads=on.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-03-10 22:54:40 +01:00
Chunyan Liu
f41e03c63f libxl_conf: reuse virDomainNetGetActualtype in libxlMakeNicList
Reuse existing helper function virDomainNetGetActualtype.

Signed-off-by: Chunyan Liu <cyliu@suse.com>
Signed-off-by: Jim Fehlig <jfehlig@suse.com>
2016-03-10 14:28:52 -07:00
Daniel P. Berrange
fcd3fa385f qemu: support use of virtlogd with file based chardevs
Currently the file based character devices let QEMU write
directly to a file on disk. This allows a malicious QEMU
to inflict a denial of service by consuming all free space.

Switch QEMU to use a pipe to virtlogd, which will enforce
file rollover.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2016-03-10 15:43:19 +00:00
Daniel P. Berrange
3e12ec4a1e qemu: use virtlogd for character device log files
If use of virtlogd is enabled, then use it for backing the
character device log files too. This avoids the possibility
of a guest denial of service by writing too much data to
the log file.
2016-03-10 15:41:52 +00:00
Daniel P. Berrange
3f68f33c36 logging: support truncation of logfiles when opening
The virtlogd daemon currently opens all files for append, but
in some cases the user may wish to discard existing data. Define
a new flag to indicate that logfiles should be truncated when
opening.
2016-03-10 15:41:52 +00:00
Daniel P. Berrange
4e461228dd qemu: move functions for handling FD passing
The functions for handling FD passing when building command line
arguments need to be used by many different bits of code, so need
to be at the start of the source file

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2016-03-10 15:41:52 +00:00
Daniel P. Berrange
0192447519 qemu: don't append -chardev arg until after value is formatted
The act of formatting a chardev backend value may need to
append command line arguments for passing FDs. If we append
the -chardev arg before formatting the value, then the
resulting arguments will end up interspersed

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2016-03-10 15:40:54 +00:00
Daniel P. Berrange
06cb0cf7ce qemu: add support for logging chardev output to a file
Honour the <log file='...'/> element in chardevs to output
data to a file. This requires QEMU >= 2.6

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2016-03-10 15:33:51 +00:00
Daniel P. Berrange
00ce10c700 conf: allow use of a logfile with chardev backends
Extend the chardev source XML so that there is a new optional
<log/> element, which is applicable to all character device
backend types. For example, to log output of a TCP backed
serial port

    <serial type='tcp'>
      <source mode='connect' host='127.0.0.1' service='9999'/>
      <protocol type='raw'/>
      <log file='/var/log/libvirt/qemu/demo-serial0.log' append='on'/>
      <target port='0'/>
    </serial>

Not all hypervisors will support use of logfiles.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2016-03-10 15:33:17 +00:00
Daniel P. Berrange
f12bfc5ed5 logging: allow inode/offset params to be NULL
Not all callers of virLogManagerDomainOpenLogFile will
care about getting the current inode/offset, so we should
allow those parameters to be NULL

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2016-03-10 15:33:16 +00:00
Peter Krempa
ab3f1428a6 qemu: cpu: Don't remove pinning of cold-unplugged cpu
After adding support for offline vcpu pinning the code that removes the
pinning for cpu cold-unplug was forgotten. This fixes up commit 02ae21d

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1316371
2016-03-10 15:56:55 +01:00
Peter Krempa
a0143d5242 qemu: Fix memory leak in qemuGetSchedInfo
Memory returned from virStringSplit shall be freed with
virStringFreeList rather than VIR_FREE. Introduced in commit 511e7c5b.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1316433
2016-03-10 13:58:44 +01:00
Peter Krempa
8c7b7c4b0b conf: Fix off-by-one in virDomainDefGetVcpu
Cpus are indexed starting from '0' so the check was invalid.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1316384
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1316420
2016-03-10 13:58:44 +01:00
Peter Krempa
4a39149b69 qemu: Refactor bitmap handling in qemuDomainPinVcpuFlags
Now that the function was extracted we can get rid of some temp
variables. Additionally formatting of the bitmap string for the event
code should be checked.
2016-03-10 13:23:15 +01:00
Peter Krempa
475c530cd3 qemu: vcpupin: Extract live vcpupin setting into a separate function
The function was now beyond maintainability.
2016-03-10 13:23:15 +01:00
Cole Robinson
adefc561cc util: virfile: Only setuid for virFileRemove if on NFS
NFS with root-squash is the only reason we need to do setuid/setgid
crazyness in virFileRemove, so limit that behavior to the NFS case.
2016-03-09 16:07:18 -05:00
Cole Robinson
7cf5343709 util: virfile: Clarify setuid usage for virFileRemove
Break these checks out into their own function, and clearly document
each one. This shouldn't change behavior
2016-03-09 16:06:56 -05:00
Peter Krempa
02ae21deb3 qemu: add support for offline vcpupin
Allow pinning for inactive vcpus. The pinning mask will be automatically
applied as we would apply the default mask in case of a cpu hotplug.

Setting the scheduler settings for a vcpu has the same semantics.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1306556
2016-03-09 10:09:16 +01:00
Peter Krempa
acf521e121 conf: extract ignoring of inactive vcpu pinning information
Introduce VIR_DOMAIN_DEF_FEATURE_OFFLINE_VCPUPIN domain feature flag
whcih will allow to skip ignoring of the pinning information for
hypervisor drivers which will want to implement forward-pinning of
vcpus.
2016-03-09 10:09:16 +01:00
Peter Krempa
185d13b1b0 conf: refactor checking for unsupported memory devices
Introduce a helper to check supported device and domain config and move
the memory hotplug checks to it.

The advantage of this approach is that by default all new features are
considered unsupported by all hypervisors unless specifically changed
rather than the previous approach where every hypervisor would need to
declare that a given feature is unsupported.
2016-03-09 10:09:16 +01:00
Peter Krempa
23eb382128 conf: introduce parser feature flags
To avoid having to forbid new features added to domain XML in post parse
callbacks for individual hypervisor drivers the feature flag mechanism
will allow to add a central check that will be disabled for the drivers
that will add support.

As a first example flag, the 'hasWideSCSIBus' is converted to the new
bitmap.
2016-03-09 10:09:16 +01:00
Peter Krempa
0fe41f1a8a qemu: Report pinning for all vCPUs in qemuDomainGetVcpuPinInfo
The API documentation states that the function is returning pinning for
all vCPUs, so we can actually do so if the user passes a large enough
array.
2016-03-09 10:09:16 +01:00
Peter Krempa
e498e90469 conf: Extract code filling data for virDomainGetVcpuPinInfo
The implementation of the inner guts of the function is similar for all
drivers, so we can add a helper and not have to reimplement it three
times.
2016-03-09 10:09:16 +01:00
Jiri Denemark
cf091094a4 qemu: Add support for job completed event
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-03-08 16:26:01 +01:00
Jiri Denemark
f289300181 Introduce job completed event
The VIR_DOMAIN_EVENT_ID_JOB_COMPLETED event will be triggered once a job
(such as migration) finishes and it will contain statistics for the job
as one would get by calling virDomainGetJobStats. Thanks to this event
it is now possible to get statistics of a completed migration of a
transient domain on the source host.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-03-08 16:26:00 +01:00
Jiri Denemark
a2374edf08 qemu: Do not report completed stats until the job finishes
We would happily report and free statistics of a completed migration
even before it actually completed (on the source host while migration is
in the Finish phase).

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-03-08 16:26:00 +01:00
Jiri Denemark
cb483a68fd qemu: Fix a race when computing migration downtime
Computing a total downtime during a migration requires us to store a
time stamp when guest CPUs get stopped. The value (and all other
statistics) is then transferred to the destination to compute the
downtime. Because the stopped time stamp is stored by a STOP event
handler while the statistics which will be sent over to the destination
are copied synchronously within qemuMigrationWaitForCompletion.

Depending on the timing of STOP and MIGRATION events, we may end up
copying (and transferring) statistics without the stopped time stamp
set. Let's make sure we always use the correct time stamp.

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

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-03-08 16:26:00 +01:00
Jiri Denemark
315808e99e qemu: Don't explicitly stop CPUs after migration
With a very old QEMU which doesn't support events we need to explicitly
call qemuMigrationSetOffline at the end of migration to update our
internal state. On the other hand, if we talk to QEMU using QMP, we
should just wait for the STOP event and let the event handler update the
state and trigger a libvirt event.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-03-08 16:25:59 +01:00
Jiri Denemark
5d01e8666b qemu: Properly update completed migration stats
We should not overwrite all migration statistics on the source with the
numbers sent by the destination since the source may have an updated
view in some cases (such as post-copy migration). It's safer to update
just the timing info we need to get from the destination and be prepared
for the future. And we should only do all this after a successful
migration.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-03-08 16:25:59 +01:00
Jiri Denemark
e031560e87 qemu: Store completed stats at the very end of migration
Statistics for a completed migration only make sense if the migration
was successful. Let's not store them in priv->job.completed until we
are sure it was a success.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-03-08 16:25:47 +01:00
Andrea Bolognani
12a1631440 hostdev: Remove explicit NULL checks
NULL checks are performed implicitly in the rest of the module,
including other allocations in the very same function.
2016-03-08 10:44:01 +01:00
Andrea Bolognani
a54de18a54 hostdev: Fix indentation 2016-03-08 10:44:01 +01:00
Andrea Bolognani
a67b14a975 hostdev: Remove inaccurate comment
The comment claimed that virPCIDeviceReattach() does not reattach
a device to the host driver; except it actually does, so the
comment is just confusing and we're better off removing it.
2016-03-08 10:42:26 +01:00
Andrea Bolognani
be70acb788 hostdev: Make comments easier to change later
Replace the term "loop" with the more generic "step". This allows us
to be more flexible and eg. have a step that consists in a single
function call.

Don't include the number of steps in the first comment of the
function, so that we can add or remove steps without having to worry
about keeping that comment in sync.

For the same reason, remove the summary contained in that comment.

Clean up some weird vertical spacing while we're at it.
2016-03-08 10:42:25 +01:00
Michal Privoznik
18f231e6ff _virtualboxCreateMachine: Avoid unbounded stack
If the stars are in the right position and you're building with
VBox >= 4.2.0 it will happen that compiler thinks an array
allocated on the stack may be unbounded:

In file included from vbox/vbox_V4_2.c:13:0:
vbox/vbox_tmpl.c: In function '_virtualboxCreateMachine':
vbox/vbox_tmpl.c:2811:1: error: stack usage might be unbounded [-Werror=stack-usage=]
 _virtualboxCreateMachine(vboxGlobalData *data, virDomainDefPtr def, IMachine **machine, char *uuidstr ATTRIBUTE_UNUSED)
 ^

Well, given how the variable is declared, I had some hard time
seeing it is actually bounded. Surprisingly compiler does not
complain because of -Wframe-larger-than. This is because
variable length arrays do not count into that warning.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2016-03-08 09:53:24 +01:00
John Ferlan
eff43d9aba Add secretObjFromSecret
Signed-off-by: John Ferlan <jferlan@redhat.com>
2016-03-07 15:52:21 -05:00
John Ferlan
0e3e00a183 locking: Use bit shift for flag values not constant values.
So far it hasn't bitten us, but if the next value wasn't 4, then
the logic used to check flag bits would have issues.
2016-03-07 15:48:19 -05:00
Yuri Chornoivan
47b70b8793 Fix minor typos 2016-03-07 18:37:25 +01:00
Shanzhi Yu
347035f959 qemu: improve the error when try to undefine transient network
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1315059

Signed-off-by: Shanzhi Yu <shyu@redhat.com>
2016-03-07 10:15:53 +01:00
Peter Krempa
47fdf9bc3a qemu: rename: Forbid renaming domains with managed save image
The code does not handle renaming of the save state file. In addition to
that the resuming code would need to be tweaked to handle the name
change since the XML is extracted from the save image. The easies option
is to make the rename API even less useful by forbiding this.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1314594
2016-03-07 10:15:37 +01:00
Michal Privoznik
f3c47aafa4 virLXCProcessMonitorInitNotify: Initialize @inode
This is an error message I've just seen. Fix it by initializing
@inode.

  CC       lxc/libvirt_driver_lxc_impl_la-lxc_process.lo
lxc/lxc_process.c: In function 'virLXCProcessMonitorInitNotify':
lxc/lxc_process.c:767:23: error: 'inode' may be used uninitialized in this function [-Werror=maybe-uninitialized]
     virDomainAuditInit(vm, initpid, inode);
                       ^

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2016-03-04 15:23:16 +01:00
Nikolay Shirokovskiy
390665a9b8 libxl: reuse virDomainObjUpdateModificationImpact
Original current flag expansion does not filter out non
_CONFIG and _LIVE flags explicitly but they are prohibited
earlier by virCheckFlags.

Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
2016-03-04 07:39:01 -05:00
Nikolay Shirokovskiy
7d3230d36d lxc: reuse virDomainObjUpdateModificationImpact
Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
2016-03-04 07:39:01 -05:00
Nikolay Shirokovskiy
4cf22bdcfd libxl: Use virDomainLiveConfigHelperMethod for libxlDomainSetMemoryFlags
Flag expansion is the same as in virDomainObjUpdateModificationImpact
which virDomainLiveConfigHelperMethod calls internally. The difference
is merely in implementation. Note that VIR_DOMAIN_MEM_CONFIG is the
same as VIR_DOMAIN_AFFECT_CONFIG.  Additionally, the called functions
will properly use flag OR and thus handle the VIR_DOMAIN_MEM_MAXIMUM case.

Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
2016-03-04 07:39:01 -05:00
Michal Privoznik
bde6e002b5 Initialize couple of variables.
While trying to build with -Os couple of compile errors showed
up.

conf/domain_conf.c: In function 'virDomainChrRemove':
conf/domain_conf.c:13666:24: error: 'ret' may be used uninitialized in this function [-Werror=maybe-uninitialized]
     virDomainChrDefPtr ret, **arrPtr = NULL;
                        ^
Compiler fails to see that @ret is used only if set in the loop,
but whatever, there's no harm in initializing the variable.

In vboxAttachDrivesNew and _vboxAttachDrivesOld compiler thinks
that @rc may be used uninitialized. Well, not directly, but maybe
after some optimization. Yet again, no harm in initializing a
variable.

In file included from ./util/virthread.h:26:0,
                 from ./datatypes.h:28,
                 from vbox/vbox_tmpl.c:43,
                 from vbox/vbox_V3_1.c:37:
vbox/vbox_tmpl.c: In function '_vboxAttachDrivesOld':
./util/virerror.h:181:5: error: 'rc' may be used uninitialized in this function [-Werror=maybe-uninitialized]
     virReportErrorHelper(VIR_FROM_THIS, code, __FILE__,              \
     ^
In file included from vbox/vbox_V3_1.c:37:0:
vbox/vbox_tmpl.c:1041:14: note: 'rc' was declared here
     nsresult rc;
              ^
Yet again, one uninitialized variable:

qemu/qemu_driver.c: In function 'qemuDomainBlockCommit':
qemu/qemu_driver.c:17194:9: error: 'baseSource' may be used uninitialized in this function [-Werror=maybe-uninitialized]
         qemuDomainPrepareDiskChainElement(driver, vm, baseSource,
         ^

And another one:

storage/storage_backend_logical.c: In function 'virStorageBackendLogicalMatchPoolSource.isra.2':
storage/storage_backend_logical.c:618:33: error: 'thisSource' may be used uninitialized in this function [-Werror=maybe-uninitialized]
                       thisSource->devices[j].path))
                                 ^

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2016-03-03 14:39:57 +01:00
Michal Privoznik
be8b536af1 Drop inline keyword from some functions.
While trying to build with -Os I've encountered some build
failures.

util/vircommand.c: In function 'virCommandAddEnvFormat':
util/vircommand.c:1257:1: error: inlining failed in call to 'virCommandAddEnv': call is unlikely and code size would grow [-Werror=inline]
 virCommandAddEnv(virCommandPtr cmd, char *env)
 ^
util/vircommand.c:1308:5: error: called from here [-Werror=inline]
     virCommandAddEnv(cmd, env);
     ^
This function is big enough for the compiler to be not inlined.
This is the error message I'm seeing:

Then virDomainNumatuneNodeSpecified is exported and called from
other places. It shouldn't be inlined then.

In file included from network/bridge_driver_platform.h:30:0,
                 from network/bridge_driver_platform.c:26:
network/bridge_driver_linux.c: In function 'networkRemoveRoutingFirewallRules':
./conf/network_conf.h:350:1: error: inlining failed in call to 'virNetworkDefForwardIf.constprop': call is unlikely and code size would grow [-Werror=inline]
 virNetworkDefForwardIf(const virNetworkDef *def, size_t n)
 ^

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2016-03-03 14:39:57 +01:00
Jiri Denemark
e53f2dc875 qemu: Check if domain is active in GetControlInfo
Reporting status of a control connection makes no sense for an inactive
domain.

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

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-03-03 13:26:51 +01:00
Jiri Denemark
1a0f076dd6 Use correct LDFLAGS for leaseshelper
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-03-03 13:23:46 +01:00
John Ferlan
0b36b0e9ce util: Cleanup error path for virPolkitAgentCreate
More fallout from changing to using virPolkitAgent and handling error
paths.  Needed to clear the 'cmd' once stored and of course add the
virCommandFree(cmd) in the error: label.
2016-03-02 13:59:37 -05:00
Michal Privoznik
f5f1ccbc23 datatypes.c: Replace 'close' with 'closeData'
Older compilers fail to see that 'close' is not used a function
rather than a variable and produce the following error:

cc1: warnings being treated as errors
../../src/datatypes.c: In function 'virConnectCloseCallbackDataReset':
../../src/datatypes.c:149: error: declaration of 'close' shadows a global declaration [-Wshadow]

Replace all the 'close' occurrences with 'closeData' to resolve
this.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2016-03-02 09:33:28 +01:00
John Ferlan
95aa101795 util: Fix missing initializer for agent
In virPolkitAgentCreate neglected to initialize agent to NULL. If
there was an error in the pipe, then we jump to error and would have
an issue. Found by coverity.
2016-03-01 19:36:37 -05:00
Nikolay Shirokovskiy
b523302c42 libxl: Remove extraneous AFFECT_LIVE and not active check.
libxlDomainPinVcpuFlags calls virDomainLiveConfigHelperMethod which will
call virDomainObjUpdateModificationImpact make the same AFFECT_LIVE flags
and !active check, so remove this duplicated check.

Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
Signed-off-by: John Ferlan <jferlan@redhat.com>
2016-03-01 10:41:53 -05:00
Nikolay Shirokovskiy
9dc19806f6 conf: Combine if condition in virDomainObjUpdateModificationImpact
Prior to commit id '3d021381' virDomainObjUpdateModificationImpact was
part of virDomainLiveConfigHelperMethod and the *flags if condition
VIR_DOMAIN_AFFECT_CONFIG checked the ->persistent boolean and made the
virDomainObjGetPersistentDef call.

Since the functions were split the ->persistent check is all that remained
and thus could be combined into one if statement.

Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
Signed-off-by: John Ferlan <jferlan@redhat.com>
2016-03-01 10:41:53 -05:00
Shanzhi Yu
751033a2e4 qemu: enalbe hotplugging of macvtap device with multiqueue
in commit 81a110, multiqueue for macvtap is enabled but forget
to support hotplugging enabled

Signed-off-by: Shanzhi Yu <shyu@redhat.com>
2016-03-01 16:16:58 +01:00
Jiri Denemark
bd7c8a693d qemu: Don't always wait for SPICE to finish migration
When SPICE graphics is configured for a domain but we did not ask the
client to switch to the destination, we should not wait for
SPICE_MIGRATE_COMPLETED event (which will never come).

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

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-03-01 15:59:00 +01:00
Jiri Denemark
3ecd73c4d8 qemu: Don't try to fetch migration stats on destination
Migration statistics are not available on the destination host and
starting a query job during incoming migration is not allowed. Trying to
do that would result in

    Timed out during operation: cannot acquire state change lock (held
    by remoteDispatchDomainMigratePrepare3Params)

error. We should not even try to start the job.

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

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-03-01 15:59:00 +01:00
Jiri Denemark
65e44a44b2 Fix formatting in remote_protocol-structs
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-03-01 15:57:20 +01:00
Jiri Denemark
254b028943 util: Fix build without polkit
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-03-01 15:51:37 +01:00
Alexander Burluka
4e17ff796f Implement handling of per-domain bandwidth settings
Signed-off-by: Alexander Burluka <aburluka@virtuozzo.com>
2016-03-01 14:30:11 +00:00
Alexander Burluka
ef1fa55e46 Implement qemuSetupGlobalCpuCgroup
This functions setups per-domain cpu bandwidth parameters

Signed-off-by: Alexander Burluka <aburluka@virtuozzo.com>
2016-03-01 14:30:11 +00:00
Alexander Burluka
fbcbd1b252 Add error checking on global quota and period
Signed-off-by: Alexander Burluka <aburluka@virtuozzo.com>
2016-03-01 14:29:06 +00:00
Alexander Burluka
55ecdae0fb Add global quota parameter necessary definitions
This parameter controls the maximum bandwidth to be used
within a period for whole domain.

Signed-off-by: Alexander Burluka <aburluka@virtuozzo.com>
2016-03-01 14:29:06 +00:00
Alexander Burluka
4d92d58f2c Add global period definitions
This parameter represents top level period cgroup
that limits whole domain enforcement period for a quota

Signed-off-by: Alexander Burluka <aburluka@virtuozzo.com>
2016-03-01 14:29:06 +00:00
Nikolay Shirokovskiy
4b4fbfe406 vz: implement connection close notification
Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
2016-03-01 14:18:16 +00:00
Nikolay Shirokovskiy
f484310add daemon: add connection close rpc
Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
2016-03-01 14:18:16 +00:00
Nikolay Shirokovskiy
ec4ef72c13 remote: factor out feature checks on connection open
Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
2016-03-01 14:18:16 +00:00
Nikolay Shirokovskiy
88f09b75eb close callback: move it to driver
Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
2016-03-01 14:17:38 +00:00
Nikolay Shirokovskiy
bb5827950e virConnectCloseCallbackDataDispose: remove unnecessary locks
We don't need locks in dispose functions as they can only
be run in one thread for given object.
2016-03-01 14:16:56 +00:00
Nikolay Shirokovskiy
fa8c164501 close callback API: remove unnecessary locks
closeCallback pointer is immutable (set on connection object creation)
and self-locking.
2016-03-01 14:16:56 +00:00
Nikolay Shirokovskiy
baf47a1f5a virConnectCloseCallbackData: factor out callback disarming 2016-03-01 14:16:56 +00:00
Nikolay Shirokovskiy
42b0f7510d close callback: make unregister clean after connect close event
If connect close is fired then following unregister will fail
as we set callback to NULL and thus callback equality checking
will fail.

Callback is set to NULL to make it fired only one time probabaly.
Instead lets use connection equality to NULL to check if callback
is already fired.

Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
2016-03-01 14:16:56 +00:00
Nikolay Shirokovskiy
a16cd9a6eb virConnectCloseCallbackData: fix connection object refcount
We have reference to connection object in virConnectCloseCallbackData
object thus we have to refcount it. Obviously we have problems
in dispose and call functions. Let's fix it.

Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
2016-03-01 14:16:56 +00:00
Nikolay Shirokovskiy
24dbb69f21 factor out virConnectCloseCallbackDataPtr methods
Make register and unregister functions return void because
we can check the state of callback object beforehand via
virConnectCloseCallbackDataGetCallback. This can be done
without race conditions if we use higher level locks for registering
and unregistering. The fact they return void simplifies
task of consistent registering/unregistering.

Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
2016-03-01 14:16:56 +00:00
Henning Schild
ff16bde100 qemu_cgroup: use virCgroupAddTask instead of virCgroupMoveTask
qemuProcessSetupEmulator runs at a point in time where there is only
the qemu main thread. Use virCgroupAddTask to put just that one task
into the emulator cgroup. That patch makes virCgroupMoveTask and
virCgroupAddTaskStrController obsolete.

Signed-off-by: Henning Schild <henning.schild@siemens.com>
2016-03-01 14:07:27 +00:00
Henning Schild
8e21e8d110 qemu_cgroup: put qemu right into emulator sub-cgroup
Move qemuProcessSetupEmulator up under qemuSetupCgroup. That way
we move the one main thread right into the emulator cgroup, instead
of moving multiple threads later on. And we do not actually want any
threads running in the parent cgroups (cpu cpuacct cpuset).

Signed-off-by: Henning Schild <henning.schild@siemens.com>
2016-03-01 14:07:27 +00:00
Peter Krempa
a06ef20782 qemu: process: Move emulator thread setting code into one function
Similarly to the refactors to iothreads and vcpus, move the code that
initializes the emulator thread settings into single function.
2016-03-01 14:07:27 +00:00
Pavel Hrdina
b4a5fd95f7 qemu: introduce vram64 attribute for QXL video device
This attribute is used to extend secondary PCI bar and expose it to the
guest as 64bit memory.  It works like this: attribute vram is there to
set size of secondary PCI bar and guest sees it as 32bit memory,
attribute vram64 can extend this secondary PCI bar.  If both attributes
are used, guest sees two memory bars, both address the same memory, with
the difference that the 32bit bar can address only the first part of the
whole memory.

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

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2016-03-01 14:17:09 +01:00
Pavel Hrdina
37b746336e qemu_capabilities: introduce QEMU_CAPS_QXL(_VGA)_VRAM64
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2016-03-01 14:17:09 +01:00
Pavel Hrdina
119cd06ef7 domain_conf: always set primary video device as primary
We always place primary video device at first place, to make it easier
to create a qemu command or format an xml, but we should also set the
primary boolean for primary video device to 'true'.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2016-03-01 14:17:09 +01:00
John Ferlan
6fb96a7f8b util: Introduce API's for Polkit text authentication
Introduce virPolkitAgentCreate and virPolkitAgentDestroy

virPolkitAgentCreate will run the polkit pkttyagent image as an asynchronous
command in order to handle the local agent authentication via stdin/stdout.
The code makes use of the pkttyagent --notify-fd mechanism to let it know
when the agent is successfully registered.

virPolkitAgentDestroy will close the command effectively reaping our
child process
2016-03-01 06:50:16 -05:00
John Ferlan
1d35f6ffe1 polkit: Adjust message when authentication agent isn't found
When there isn't a ssh -X type session running and a user has not
been added to the libvirt group, attempts to run 'virsh -c qemu:///system'
commands from an otherwise unprivileged user will fail with rather
generic or opaque error message:

    "error: authentication failed: no agent is available to authenticate"

This patch will adjust the error code and message to help reflect the
situation that the problem is the requested mechanism is UNAVAILABLE and
a slightly more descriptive error. The result on a failure then becomes:

    "error: authentication unavailable: no polkit agent available to
            authenticate action 'org.libvirt.unix.manage'"

A bit more history on this - at one time a failure generated the
following type message when running the 'pkcheck' as a subprocess:

"error: authentication failed: polkit\56retains_authorization_after_challenge=1
Authorization requires authentication but no agent is available."

but, a patch was generated to adjust the error message to help provide
more details about what failed. This was pushed as commit id '96a108c99'.
That patch prepended a "polkit: " to the output. It really didn't solve
the problem, but gave a hint.

After some time it was deemed using DBus API calls directly was a
better way to go (since pkcheck calls them anyway). So, commit id
'1b854c76' (more or less) copied the code from remoteDispatchAuthPolkit
and adjusted it. Then commit id 'c7542573' adjusted the remote.c
code to call the new API (virPolkitCheckAuth). Finally, commit id
'308c0c5a' altered the code to call DBus APIs directly. In doing
so, it reverted the failing error message to the generic message
that would have been received from DBus anyway.
2016-03-01 06:50:16 -05:00
John Ferlan
35b20c1f7c secret: Rename loadSecrets
Rename to secretLoadAllConfigs and add the 'driver->configDir' as
a parameter.

Signed-off-by: John Ferlan <jferlan@redhat.com>
2016-03-01 06:44:37 -05:00
John Ferlan
fa9ca7fd3c secret: Introduce secretAssignDef
This new API will allocate the secret, assign the def pointer, and
insert the secret onto the passed list. Whether that's the temporary
list in loadSecrets which gets loaded into the driver list or driver
list during secretDefineXML.

Signed-off-by: John Ferlan <jferlan@redhat.com>
2016-03-01 06:44:34 -05:00
John Ferlan
27950465b1 secret: Introduce listUnlinkSecret
Add a temporary helper to search for a specific secret by address
on the list and remove it if it's found. The following patch will
introduce a common allocation and listInsert helper. That means
error paths of the routines calling would need a way to remove the
secret off the list.

Signed-off-by: John Ferlan <jferlan@redhat.com>
2016-03-01 06:44:28 -05:00
John Ferlan
0250f34af1 secret: Create a 'base64File' in virSecretObj
This patch removes need for secretBase64Path and secretComputePath. Similar
to the configFile, create an entry for base64File, which will be generated
as the driver->configDir, the UUID value, plus the ".base" suffix. Rather
than generating on the fly, store this in the virSecretObj.

The buildup of the pathname done in loadSecrets where the failure to build
is ignored which is no different than the failure to generate the name
in secretLoadValue which would have been ignored in the failure path
after secretLoad.

This also removes the need for secretComputPath and secretBase64Path.

Signed-off-by: John Ferlan <jferlan@redhat.com>
2016-03-01 06:44:24 -05:00
John Ferlan
aefe02f52e secret: Create a 'configFile' in virSecretObj
This patch removes the need for secretXMLPath. Instead save 'path' during
loadSecret as 'configFile'. The secretXMLPath is nothing more than an
open coded virFileBuildPath.  All that code did was concantenate the
driver->configDir, the UUID of the secret, and the ".xml" suffix to form
the configFile name which we now will generate and save instead.

Signed-off-by: John Ferlan <jferlan@redhat.com>
2016-03-01 06:43:53 -05:00
John Ferlan
232b7417a6 secret: Adjust logic to build file path in secretLoad
The 'secretLoad' was essentially open coding virFileBuildPath.

Adjust the logic to have the caller build the path and pass it. The net
sum of ignoring the virFileBuildPath failure is the same as before where
the failure to virAsprintf the path would have been ignored anyway in
the secretLoad error path.

Signed-off-by: John Ferlan <jferlan@redhat.com>
2016-03-01 06:43:53 -05:00
John Ferlan
0e458e66a8 secret: Rename directory to configDir
This follows other drivers usage model.

Signed-off-by: John Ferlan <jferlan@redhat.com>
2016-03-01 06:43:53 -05:00
John Ferlan
72a0121896 secret: Use 'secret' instead of 's' for variable name
Remove one letter variable.

Signed-off-by: John Ferlan <jferlan@redhat.com>
2016-03-01 06:43:53 -05:00
John Ferlan
ca1eb18113 secret: Rename virSecretObjPtr 'entry' to 'secret'
Just renaming the variable in secretConnectListAllSecrets.

Signed-off-by: John Ferlan <jferlan@redhat.com>
2016-03-01 06:43:53 -05:00
John Ferlan
bfd25584b4 secret: Remove local virSecretPtr 'secret'
Remove the need for the local 'secret' in secretConnectListAllSecrets.
A subsequent patch will rename the ObjPtr entry to secret.

Signed-off-by: John Ferlan <jferlan@redhat.com>
2016-03-01 06:43:53 -05:00
John Ferlan
ea86edba9f secret: Rename virSecretEntry
Rename to virSecretObj - preparation for future patch, but also follows
similar code in other drivers.

Signed-off-by: John Ferlan <jferlan@redhat.com>
2016-03-01 06:43:53 -05:00
John Ferlan
558a61a3d0 secret: Use virFileRewrite instead of replaceFile
Use the common API instead of essentially open coding same functionality.

Signed-off-by: John Ferlan <jferlan@redhat.com>
2016-03-01 06:43:53 -05:00
John Ferlan
d44f561824 secret: Various formatting cleanups
Rather than having it interspersed with other changes, do it once.

Remove a couple ^L, 1 argument per line for functions, less than 80 chars
per line, use of spacing between logical groups of code, use of one line
if statements when doing fetch followed by comparison, use direct return
when no cleanup to be done.

Signed-off-by: John Ferlan <jferlan@redhat.com>
2016-03-01 06:43:53 -05:00
Henning Schild
85d7480654 vircgroup: one central point for adding tasks to cgroups
Use virCgroupAddTaskController in virCgroupAddTask so we have one
single point where we add tasks to cgroups.

Signed-off-by: Henning Schild <henning.schild@siemens.com>
2016-03-01 11:20:56 +00:00
Peter Krempa
d1277de226 qemu: Allow setting pinning of emulator/iohtread with automatic placement
We honour the placement bitmaps when starting up, so there's no point in
having this check. Additionally the check was buggy since it checked
vm->def all the time even if the user requested to modify the persistent
definition which had different configuration.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1308317
2016-03-01 10:45:52 +01:00
Marc-André Lureau
937ebba00e qemu: add spice opengl support
Add Spice graphics gl attribute. qemu 2.6 should have -spice gl=on argument to
enable opengl rendering context (patches on the ML). This is necessary to
actually enable virgl rendering.

Add a qemuxml2argv test for virtio-gpu + spice with virgl.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2016-03-01 09:45:47 +01:00
Martin Kletzander
a89f05ba8d qemu: Shorten per-domain directory names
Per-domain directories were introduced in order to be able to
completely separate security labels for each domain (commit
f1f68ca334).  However when the domain
name is long (let's say a ridiculous 110 characters), we cannot
connect to the monitor socket because on length of UNIX socket address
is limited.  In order to get around this, let's shorten it in similar
fashion and in order to avoid conflicts, throw in an ID there as well.
Also save that into the status XML and load the old status XMLs
properly (to clean up after older domains).  That way we can change it
in the future.

The shortening can be seen in qemuxml2argv tests, for example in the
hugepages-pages2 case.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2016-03-01 07:15:29 +01:00
John Ferlan
ee67069c73 storage: Fix error path in storagePoolDefineXML
Found by inspection - after calling virStoragePoolObjAssignDef the
pool is part of the driver->pools.objs list and the failure path
for the virStoragePoolObjSaveDef will use virStoragePoolObjRemove
to remove the pool from the objs list which will unlock and free
the pool pointer (as pools->objs[i] during the loop). Since the call
doesn't clear the pool address from the callee, we need to set it
to NULL; otherwise, the virStoragePoolObjUnlock in the cleanup: code
will fail miserably.
2016-02-26 07:23:05 -05:00
John Ferlan
c53e4ae0c8 storage: Fix error path in virStoragePoolObjLoad
While reviewing how storage driver used ObjListPtr's for reference
in some recent secret driver patches to use the same mechanism, I came
across an instance where the wrong API was called for error paths after
successfully allocating the storage pool pointer and inserting into
the driver pool list.

The path is after virStoragePoolObjAssignDef succeeds - the 'def' passed
in is assigned to pool->def (or newDef) so it shouldn't be the only thing
deleted. The pool is now part of driver->pools.objs, so it would need to
be removed (as happens in the storagePoolCreateXML error paths).

Rather than calling virStoragePoolDefFree to free the def which is now
assigned to the pool, call virStoragePoolObjRemove to ensure the pool
element is removed from the driver list and that anything stored in pool
is properly handled by virStoragePoolObjFree including the call to
virStoragePoolDefFree for the pool->{def|newDef} element.
2016-02-26 07:23:05 -05:00
Ján Tomko
21b316f4d3 qemu: error out on missing machine type in configs
Commit f1a89a8 allowed parsing configs from /etc/libvirt
without validating the emulator capabilities.

Check for the presence of a machine type in the qemu driver's
post parse function instead of crashing.

https://bugzilla.redhat.com/show_bug.cgi?id=1267256
2016-02-26 10:32:31 +01:00
Ján Tomko
5f265fa0db Revert "Error out on missing machine type in machine configs"
Revert commit 55e6d8cd9e.

This fix for https://bugzilla.redhat.com/show_bug.cgi?id=1267256
unconditionally required a machine type for all machine types
even though qemu is the only emulator using them.

Revert it to fix persistent configs for drivers with no machine type:
https://www.redhat.com/archives/libvir-list/2016-February/msg01228.html
2016-02-26 09:47:45 +01:00
Jim Fehlig
e4f1be7eb6 libxl: unref objects in error paths
libxlMakeNic opens a virConnect object and takes a reference on a
virNetwork object, but doesn't drop the references on all error
paths. Rework the function to follow the standard libvirt pattern
of using a local 'ret' variable to hold the function return value,
performing all cleanup and returning 'ret' at a 'cleanup' label.
2016-02-25 11:46:20 -07:00
John Ferlan
5430ee3aa6 storage: No need to check ret after VIR_APPEND_ELEMENT
Generates a false positive for Coverity, but it turns out there's no need
to check ret == -1 since if VIR_APPEND_ELEMENT is successful, the local
vol pointer is cleared anyway.

Signed-off-by: John Ferlan <jferlan@redhat.com>
2016-02-25 11:52:49 -05:00
John Ferlan
4e87164306 zfs: Resolve RESOURCE_LEAK
Found by my Coverity checker - virCheckFlags call could return -1, but
not virCommandFree(destroy_cmd).

Signed-off-by: John Ferlan <jferlan@redhat.com>
2016-02-25 11:52:49 -05:00
John Ferlan
fe0063685a openvz: Use virStringSplitCount instead of strtok_r
When parsing the barrier:limit values, use virStringSplitCount in order
to split the pair and make the approriate checks to get the data.

Signed-off-by: John Ferlan <jferlan@redhat.com>
2016-02-25 11:52:45 -05:00
Andrea Bolognani
b2ce5b027c hostdev: Remove temporary variable when checking for VF
The virHostdevIsVirtualFunction() was called exactly twice, and in
both cases the return value was saved to a temporary variable before
being checked. This would be okay if it improved readability, but in
this case is pretty pointless.

Get rid of the temporary variable and check the return value
directly; while at it, change the check from '<= 0' to '!= 1' to
align it with the way other similar *IsVirtualFunction() functions
are used thorough the code.
2016-02-25 17:09:53 +01:00
Andrea Bolognani
dec3a4a135 netdev: Use virNetDevIsVirtualFunction() properly
virNetDevIsVirtualFunction() returns 1 if the interface is a
virtual function, 0 if it isn't and -1 on error. This means that,
despite the name suggesting otherwise, using it as a predicate is
not correct.

Fix two callers that were doing so adding an explicit check on
the return value.
2016-02-25 17:09:52 +01:00
Jiri Denemark
04e10925a1 util: Avoid calling closedir(NULL)
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-02-25 12:50:12 +01:00
Osier Yang
c92547c34a Fix bug of attaching redirdev device
RHBZ: https://bugzilla.redhat.com/show_bug.cgi?id=1298070

The corresponding chardev must be attached first, otherwise the
the qemu command line won't be complete (missing the host part),
2016-02-25 09:17:41 +01:00
Joao Martins
77fdd82e51 libxl: implement virDomainInterfaceStats
Introduce support for domainInterfaceStats API call for querying
network interface statistics. Consequently it also enables the use of
`virsh domifstat <dom> <interface name>` command plus seeing the
interfaces names instead of "-" when doing `virsh domiflist <dom>`.

After successful guest creation we fill the network interfaces names
based on domain, device id and append suffix if it's emulated in the
following form: vif<domid>.<devid>[-emu].  We extract the network
interfaces info from the libxl_domain_config object in
libxlDomainCreateIfaceNames() to generate ifname. On domain cleanup we
also clear ifname, in case it was set by libvirt (i.e. being prefixed
with "vif"). We also skip these two steps in case the name of the
interface was manually inserted by the administrator. Since the
introduction of netprefix (commit a040ba9), ifnames with a registered
prefix will be freed on virDomain{Obj,Def}Format*, thus eliminating
the migration issues observed with the reverted commit d2e5538 whereas
source and destination would have the same ifname.

For getting the interface statistics we resort to virNetInterfaceStats
and let libvirt handle the platform specific nits. Note that the
latter is not yet supported in FreeBSD.

Signed-off-by: Joao Martins <joao.m.martins@oracle.com>
2016-02-24 14:28:57 -07:00
Chunyan Liu
5c79c445c2 libxl: small fix in parsing network
Signed-off-by: Chunyan Liu <cyliu@suse.com>
2016-02-23 21:22:17 -07:00
Eric Blake
5a5c2837c8 rbd: fix 32-bit build
%zu is not always synonymous with uint64_t; on 32-bit machines,
size_t is only 32 bits.  Prefer "%lld"/'unsigned long long' when
the variable is under our control, and "%"PRIu64 when we are
stuck with 'uint64_t' from RBD.

Fixes errors such as:

../../src/storage/storage_backend_rbd.c: In function 'virStorageBackendRBDVolWipe':
../../src/storage/storage_backend_rbd.c:1281:15: error: format '%zu' expects argument of type 'size_t', but argument 8 has type 'uint64_t {aka long long unsigned int}' [-Werror=format=]
     VIR_DEBUG("Need to wipe %zu bytes from RBD image %s/%s",
               ^
../../src/util/virlog.h:90:73: note: in definition of macro 'VIR_DEBUG_INT'
     virLogMessage(src, VIR_LOG_DEBUG, filename, linenr, funcname, NULL, __VA_ARGS__)
                                                                         ^
../../src/storage/storage_backend_rbd.c:1281:5: note: in expansion of macro 'VIR_DEBUG'
     VIR_DEBUG("Need to wipe %zu bytes from RBD image %s/%s",
     ^

Signed-off-by: Eric Blake <eblake@redhat.com>
2016-02-23 16:54:35 -07:00
Jim Fehlig
c23bbfad6e libxl: fix bogus indentation from commit fb2bd208 2016-02-23 15:28:04 -07:00
Michal Privoznik
01c3185298 qemuBuildCommandLine: Change the condition for -nographics
There's this check when building command line that whenever
domain has no graphics card configured we put -nographics onto
qemu command line. The check is 'if (!def->graphics)'. This
makes coverity think that def->graphics can be NULL, which is
true. But later in the code every access to def->graphics is
guarded by check for def->ngraphics, so no crash occurs. But this
is something that coverity fails to deduct.
In order to shut coverity up lets change the condition to
'if (!def->ngraphics)'.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2016-02-23 15:48:37 +01:00
Michal Privoznik
e0392f5a74 xen: Check return value of virStringReplace
After 6604a3dd9f in which new helper function has been
introduced, the code calls virStringReplace and dereference the
result immediately. The string function can, however, return NULL
so this would SIGSEGV right away. Check for the return value of
the string function.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2016-02-23 15:46:19 +01:00
Michal Privoznik
a0e5faaf66 vbox: Avoid signed and unsigned comparison
After 457ff97fa there are two defects in our code. In both of
them we use a signed variable to hold up a number of snapshots
that domain has. We use a helper function to count the number.
However, the helper function may fail in which case it returns
a negative one and control jumps to cleanup label where an
unsigned variable is used to iterate over array of snapshots. The
loop condition thus compare signed and unsigned variables which
in this specific case ends up badly for us.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2016-02-23 15:38:20 +01:00
Jim Fehlig
fb2bd208e5 libxl: add support for rbd qdisk
xl/libxl already supports qemu's network-based block backends
such as nbd and rbd. libvirt has supported configuring such
<disk>s for long time too. This patch adds support for rbd
disks in the libxl driver by generating a rbd device URL from
the virDomainDiskDef object. The URL is passed to libxl via the
pdev_path field of libxl_device_disk struct. libxl then passes
the URL to qemu for cosumption by the rbd backend.

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
2016-02-22 11:46:50 -07:00
Jim Fehlig
6604a3dd9f xenconfig: support xl<->xml conversion of rbd disk devices
The target= setting in xl disk configuration can be used to encode
meta info that is meaningful to a backend. Leverage this fact to
support qdisk network disk types such as rbd. E.g. <disk> config
such as

   <disk type='network' device='disk'>
     <driver name='qemu' type='raw'/>
     <source protocol='rbd' name='pool/image'>
       <host name='mon1.example.org' port='6321'/>
       <host name='mon2.example.org' port='6322'/>
       <host name='mon3.example.org' port='6322'/>
     </source>
     <target dev='hdb' bus='ide'/>
     <address type='drive' controller='0' bus='0' target='0' unit='1'/>
   </disk>

can be converted to the following xl config (and vice versa)

  disk = [ "format=raw,vdev=hdb,access=rw,backendtype=qdisk,
            target=rbd:pool/image:auth_supported=none:mon_host=mon1.example.org\\:6321\\;mon2.example.org\\:6322\\;mon3.example.org\\:6322"
         ]

Note that in xl disk config, a literal backslash in target= must
be escaped with a backslash. Conversion of <auth> config is not
handled in this patch, but can be done in a follow-up patch.

Also add a test for the conversions.

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
2016-02-22 11:46:50 -07:00
Jim Fehlig
a44f1f85f9 xenconfig: produce key=value disk config syntax in xl formatter
The most formal form of xl disk configuration uses key=value
syntax to define each configuration item, e.g.

format=raw, vdev=xvda, access=rw, backendtype=phy, target=disksrc

Change the xl disk formatter to produce this syntax, which allows
target= to contain meta info needed to setup a network-based
disksrc (e.g. rbd, nbd, iscsi). For details on xl disk config
format, see  $xen-src/docs/misc/xl-disk-configuration.txt

Update the disk config in the tests to use the formal syntax.
But add tests to ensure disks specified with the positional
parameter syntax are correctly converted to <disk> XML.

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
2016-02-22 11:46:50 -07:00
Andrea Bolognani
dad0ae1c1f hostdev: Minor style adjustments
Mostly labels names and whitespace.

No functional changes.
2016-02-22 17:32:48 +01:00
Marc-André Lureau
ef766337ff util: TristateBool and TristateSwitch are interchangeable
It may be useful in some cases to call TristateSwitch helper with TristateBool.
Document that enum values equivalency in the code.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2016-02-22 15:13:56 +01:00
Pavel Hrdina
85a687c6b2 qemu_process: mark auto-generated spice ports as reserved
In case you will specify graphics like this:

<graphics type='spice' port='-1'/>

or

<graphics type='spice' port='-1' tlsPort='6000'/>

libvirt will automatically add autoport='no'.  This leads to an issue
that in qemuProcessStop() we don't release that port because we are
releasing both port if autoport=yes or only port marked as reserved.

If autoport=no but we request to generate port via '-1' we need to mark
that port as reserved in order to release it.

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

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2016-02-22 14:34:45 +01:00
Martin Kletzander
457ff97fa2 Miscellaneous for-loop syntax clean-ups
Checking whether x > 0 before looping over [0..x] items doesn't make
sense and multi-line body must have curly brackets around it.

Best viewed with '-w'.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2016-02-22 11:29:59 +01:00
Paolo Bonzini
fc922eb208 qemu: add support for LSI SAS1068 (aka MPT Fusion) SCSI controller
This does nothing more than adding the new device and capability.
The device is present since QEMU 2.6.0.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2016-02-22 10:10:52 +00:00
Michal Privoznik
eeed7f6e75 virDomainDefFormatInternal: Drop useless check
There's a check if a domain definition has any graphics card and
if so, we iterate over each one of them. This makes no sense,
because even if it has none we can still iterate over.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2016-02-22 07:59:25 +01:00
Andrea Bolognani
d8fc7e05f8 gic: Introduce VIR_GIC_VERSION_DEFAULT alias
GIC v2 is the default, but checking against that specific version when
we want to know whether the default has been selected is potentially
error prone; using an alias instead makes it safer.
2016-02-19 18:24:58 +01:00
Laurent Bigonville
0b6e5ddd89 security_selinux: Fix typo in error message 2016-02-19 17:15:31 +00:00
Peter Krempa
29eeb81437 qemu: iothreadpin: Always set affinity when pinning iothread
Similarly to VM startup always set the legacy affinity. Additionally we
don't need to report an explicit error since virProcessSetAffinity
reports them themselves.
2016-02-19 16:47:09 +01:00
Peter Krempa
2242503efb qemu: emulatorpin: Always set affinity when pinning emulator thread
Similarly to VM startup always set the legacy affinity. Additionally we
don't need to report an explicit error since virProcessSetAffinity
reports them themselves.
2016-02-19 16:47:09 +01:00
Cole Robinson
e6ad2b69ae qemu: parse: drop redundant AddImplicitControllers
PostParse handles it for us now.

This causes some test suite churn; qemu's custom PostParse could is
now invoked before the generic AddImplicitControllers, so PCI
controllers end up sequentially in the XML before the generically
added IDE controllers. So it's just some XML reordering
2016-02-19 09:45:23 -05:00
Cole Robinson
378a9dc6b7 qemu: parse: rename qemuCaps->caps
Everywhere else in qemu driver code 'qemuCaps' is a virQEMUCapsPtr,
and virCapsPtr is generally named just 'caps'. Rename the offenders
2016-02-19 09:45:23 -05:00
Cole Robinson
4066c73428 domain: add implicit controllers from post parse
Seems like the natural fit, since we are already adding other XML bits
in the PostParse routine.

Previously AddImplicitControllers was only called at the end of XML
parsing, meaning code that builds a DomainDef by hand had to manually
call it. Now those PostParse callers get it for free.

There's some test churn here; xen xm and sexpr test suite bits weren't
calling this before, but now they are, so you'll see new IDE controllers.
I don't think this will cause problems in practice, since the code already
needs to handle these implicit controllers like in the case when a user
defines their own XML.
2016-02-19 09:45:23 -05:00
Jiri Denemark
5591ca502d Check for active domain in virDomainObjWait
virDomainObjWait is designed to be called in a loop. Make sure we break
the loop in case the domain dies to avoid waiting for an event which
will never happen.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-02-19 15:41:57 +01:00
Jiri Denemark
81f50cb92d qemu: Avoid calling qemuProcessStop without a job
Calling qemuProcessStop without a job opens a way to race conditions
with qemuDomainObjExitMonitor called in another thread. A real world
example of such a race condition:

  - migration thread (A) calls qemuMigrationWaitForSpice
  - another thread (B) starts processing qemuDomainAbortJob API
  - thread B signals thread A via qemuDomainObjAbortAsyncJob
  - thread B enters monitor (qemuDomainObjEnterMonitor)
  - thread B calls qemuMonitorSend
  - thread A awakens and calls qemuProcessStop
  - thread A calls qemuMonitorClose and sets priv->mon to NULL
  - thread B calls qemuDomainObjExitMonitor with priv->mon == NULL
  => monitor stays ref'ed and locked

Depending on how lucky we are, the race may result in a memory leak or
it can even deadlock libvirtd's event loop if it tries to lock the
monitor to process an event received before qemuMonitorClose was called.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-02-19 15:41:57 +01:00
Jiri Denemark
6f08cbb82b qemu: Simplify error handling in qemuProcessReconnect
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-02-19 15:41:57 +01:00
Jiri Denemark
8c9ff9960b qemu: Process monitor EOF in a job
Stopping a domain without a job risks a race condition with another
thread which started a job a which does not expect anyone else to be
messing around with the same domain object.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-02-19 15:41:57 +01:00
Jiri Denemark
1894112bb7 qemu: Start an async job for processGuestPanicEvent
Only a small portion of processGuestPanicEvent was enclosed within a
job, let's make sure we use the job for all operations to avoid race
conditions.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-02-19 15:41:57 +01:00
Jiri Denemark
26edd68c35 qemu: Start job in qemuDomainDestroyFlags early
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-02-19 15:41:57 +01:00
Jiri Denemark
4d0c535a36 qemu: Introduce qemuProcessBeginStopJob
When destroying a domain we need to make sure we will be able to start a
job no matter what other operations are running or even stuck in a job.
This is done by killing the domain before starting the destroy job.

Let's introduce qemuProcessBeginStopJob which combines killing a domain
and starting a job in a single API which can be called everywhere we
need a job to stop a domain.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-02-19 15:41:57 +01:00
Jiri Denemark
b7a948be01 qemu: Pass async job to qemuProcessInit
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-02-19 15:41:57 +01:00
Jiri Denemark
bf657dffb8 qemu: End nested jobs properly
Ending a nested job is no different from ending any other (non-async)
job, after all the code in qemuDomainBeginJobInternal does not handle
them differently either. Thus we should call qemuDomainObjEndJob to stop
nested jobs.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-02-19 15:41:57 +01:00
Jiri Denemark
17c4312c63 qemu: Export qemuDomainObjBeginNestedJob
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-02-19 15:41:57 +01:00
Peter Krempa
783584b52b qemu: qemuDomainGetStatsVcpu: Fix output for possible sparse vCPU settings
qemuDomainHelperGetVcpus would correctly return an array of
virVcpuInfoPtr structs for online vcpus even for sparse topologies, but
the loop that fills the returned typed parameters would number the vcpus
incorrectly. Fortunately sparse topologies aren't supported yet.
2016-02-19 15:23:54 +01:00
Peter Krempa
9958422d10 qemu: vcpupin: Always set affinity even when cgroups are supported
VM startup and CPU hotplug always set the affinity regardless of cgroups
support. Use the same approach for the pinning API.
2016-02-19 15:23:54 +01:00
Peter Krempa
471741309d qemu: vcpupin: Don't overwrite errors from functions setting pinning
Both errors from the cgroups code and from the affinity code would be
overwritten by the API. Report the more specific error.
2016-02-19 15:23:54 +01:00
Peter Krempa
9268b9ad48 util: Use virBitmapIsBitSet in freebsd impl of virProcessSetAffinity
Use the helper that does not return errors to fix spuriously looking
dead return of -1.
2016-02-19 15:23:54 +01:00
Erik Skultety
e9e8565593 admin: Fix memory leak in remoteAdminConnectClose
When virt-admin is run with valgrind, this kind of output can be obtained:

HEAP SUMMARY:
  in use at exit: 134,589 bytes in 1,031 blocks
  total heap usage: 2,667 allocs, 1,636 frees, 496,755 bytes allocated

88 bytes in 1 blocks are definitely lost in loss record 82 of 128
 at 0x4C2A9C7: calloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
 by 0x52F6D1F: virAllocVar (viralloc.c:560)
 by 0x5350268: virObjectNew (virobject.c:193)
 by 0x53503E0: virObjectLockableNew (virobject.c:219)
 by 0x4E3BBCB: virAdmConnectNew (datatypes.c:832)
 by 0x4E38495: virAdmConnectOpen (libvirt-admin.c:209)
 by 0x10C541: vshAdmConnect (virt-admin.c:107)
 by 0x10C7B2: vshAdmReconnect (virt-admin.c:163)
 by 0x10CC7C: cmdConnect (virt-admin.c:298)
 by 0x110838: vshCommandRun (vsh.c:1224)
 by 0x10DFD8: main (virt-admin.c:862)

 LEAK SUMMARY:
    definitely lost: 88 bytes in 1 blocks
    indirectly lost: 0 bytes in 0 blocks
    possibly lost: 0 bytes in 0 blocks
    still reachable: 134,501 bytes in 1,030 blocks
    suppressed: 0 bytes in 0 blocks

This is because virNetClientSetCloseCallback was being reinitialized
incorrectly. By resetting the callbacks in a proper way, the leak is fixed.
2016-02-19 08:21:18 +01:00
Matthias Bolte
647ac97ab6 esx: Avoid using vSphere SessionIsActive function
A login session with the vSphere API might expire after some idle time.
The esxVI_EnsureSession function uses the SessionIsActive function to
check if the current session has expired and a relogin needs to be done.

But the SessionIsActive function needs the Sessions.ValidateSession
privilege that is considered as an admin level privilege.

Only vCenter actually provides the SessionIsActive function. This results
in requiring an admin level privilege even for read-only operations on
a vCenter server.

ESX and VMware Server don't provide the SessionIsActive function and
the code already works around that. Use the same workaround for vCenter
again.

This basically reverts commit 5699034b65.
2016-02-18 19:28:35 +01:00
Ján Tomko
55e6d8cd9e Error out on missing machine type in machine configs
Commit f1a89a8 allowed parsing configs from /etc/libvirt
without validating the emulator capabilities.

Check for the presence of os->type.machine even if the
VIR_DOMAIN_DEF_PARSE_SKIP_OSTYPE_CHECKS flag is set,
otherwise the daemon can crash on carelessly crafted input
in the config directory.

https://bugzilla.redhat.com/show_bug.cgi?id=1267256
2016-02-18 16:19:39 +01:00
John Ferlan
c7f0069e8b qemu: Introduce qemuBuildMonitorCommandLine
Add new function to manage adding the '-mon' or '-monitor' options to
the command line removing that task from the mainline qemuBuildCommandLine.

Also adjusted qemuBuildChrChardevStr and qemuBuildChrArgStr to use
const virDomainChrSourceDef *def rather than virDomainChrSourceDefPtr def.

Signed-off-by: John Ferlan <jferlan@redhat.com>
2016-02-18 07:03:30 -05:00
John Ferlan
8204234040 qemu: Introduce qemuBuildSgaCommandLine
Add new function to manage adding the '-device sga' to the command
line removing that task from the mainline qemuBuildCommandLine

Signed-off-by: John Ferlan <jferlan@redhat.com>
2016-02-18 07:03:30 -05:00
John Ferlan
6c56a71c9f qemu: Introduce qemuBuildSmbiosCommandLine
Add new function to manage adding the '-smbios' options to the command
line removing that task from the mainline qemuBuildCommandLine

Also while I was looking at it, move the uuid processing closer to usage.

Signed-off-by: John Ferlan <jferlan@redhat.com>
2016-02-18 07:03:30 -05:00
John Ferlan
b827eddae0 qemu: Introduce qemuBuildNumaCommandLine
Add new function to manage adding the '-numa' options to the command
line removing that task from the mainline qemuBuildCommandLine

Signed-off-by: John Ferlan <jferlan@redhat.com>
2016-02-18 07:03:30 -05:00
John Ferlan
70681e3502 qemu: Introduce qemuBuildIOThreadCommandLine
Add new function to manage adding the IOThread '-object' to the command
line removing that task from the mainline qemuBuildCommandLine

Signed-off-by: John Ferlan <jferlan@redhat.com>
2016-02-18 07:03:30 -05:00
John Ferlan
e0dd78c9b2 qemu: Rename qemuBuildSmpArgStr to qemuBuildSmpCommandLine
Rename function and move code in from qemuBuildCommandLine to
keep smp related code together. Also make a few style changes
for long lines, return value change, and 2 spaces between functions.

Signed-off-by: John Ferlan <jferlan@redhat.com>
2016-02-18 07:03:30 -05:00
John Ferlan
aa076fe8e4 qemu: Introduce qemuBuildMemCommandLine
Add new function to manage adding the '-m' memory options to the command
line removing that task from the mainline qemuBuildCommandLine

Signed-off-by: John Ferlan <jferlan@redhat.com>
2016-02-18 07:03:30 -05:00
John Ferlan
d238b51f00 qemu: Rename qemuBuildCpuArgStr to qemuBuildCpuCommandLine
Rename function and move code from mainline qemuBuildCommandLine to
keep alike code together.

Signed-off-by: John Ferlan <jferlan@redhat.com>
2016-02-18 07:03:30 -05:00
John Ferlan
e3b964bc81 qemu: Rename qemuBuildMachineArgStr
Rename to qemuBuildMachineCommandLine to fit current (and future)
helper naming conventions.

Signed-off-by: John Ferlan <jferlan@redhat.com>
2016-02-18 07:03:30 -05:00
John Ferlan
470129a43f qemu: Make basic upfront checks before create command
Create qemuBuildCommandLineValidate to make some checks before trying
to build the command. This will move some logic from much later to much
earlier - we shouldn't be adjusting any data so that shouldn't matter.

Signed-off-by: John Ferlan <jferlan@redhat.com>
2016-02-18 07:03:30 -05:00
Bjoern Walk
65c4c7d850 qemu: cgroup: fix cgroup permission logic
Fix logic error introduced in commit d6c91b3c which essentially broke
starting any domain.

Signed-off-by: Bjoern Walk <bwalk@linux.vnet.ibm.com>
2016-02-18 10:32:46 +01:00
John Ferlan
71eb431c63 qemu: Remove local emulator
Remove the local variable 'emulator' and just use def->emulator

Signed-off-by: John Ferlan <jferlan@redhat.com>
2016-02-17 20:22:02 -05:00
Peter Krempa
d46eb9e5ea qemu: Kill VIR_WRAPPER_SHELL_PREFIX
The migration code now doesn't need it, so remove the macros and the
configure code that is detecting it.
2016-02-17 17:27:02 +01:00
Cole Robinson
4b9fa11450 qemu: Move PORT definitions to qemu_conf.c
Which is the only user. That was the only reason for including
qemu_command.h, though we need to explicitly include qemu_domain.h
afterwards.
2016-02-17 11:07:21 -05:00
Peter Krempa
6b9b21db70 qemu: Remove unnecessary calculations in qemuDomainSaveMemory
Now that the file migration doesn't require us to use 'dd' and other
legacy stuff for too old qemus we don't even have to calcuate the
offsets and other stuff.
2016-02-17 15:54:44 +01:00
Peter Krempa
4e615aabe2 qemu: monitor: Remove unused qemuMonitorMigrateToFile
With the currently supported qemus we always migrate to file
descriptors so the old function is not required any more.

Additionally QEMU_MONITOR_MIGRATE_TO_FILE_TRANSFER_SIZE macro is now
unused.
2016-02-17 15:54:44 +01:00
Michal Privoznik
6bfb03ae15 vircgroup: Update virCgroupDenyDevicePath stub
In cf113e8d we changed the declaration of
virCgroupAllowDevicePath() and virCgroupDenyDevicePath().
However, while updating the stub for non-cgroup platforms for the
former we forgot to update the latter too causing a build
failure.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2016-02-17 14:25:35 +01:00
Ján Tomko
cdb757c970 Revert "storageVolCreateXMLFrom: Check if backend knows how to createVol"
This reverts commit 611a278fa4.

According to the original commit message, this is dead code:

  It is highly unlikely that a backend will know how to create a
  volume from a different volume (buildVolFrom) and not know how to
  create an empty volume (createVol).
2016-02-17 13:29:41 +01:00
Erik Skultety
67121f0834 syms: add forgotten virAdmConnectClass symbol
Although it currently doesn't cause any linking issues, the symbol should be
exported correctly according to our conventions.
2016-02-17 12:59:31 +01:00
Erik Skultety
1a07c2efb3 admin: Introduce adminDaemonConnectListServers API
This API is merely a convenience API, i.e. when managing clients connected to
daemon's servers, we should know (convenience) which server the specific client
is connected to. This implies a client-side representation of a server along
with a basic API to let the administrating client know what servers are actually
available on the daemon.

Signed-off-by: Erik Skultety <eskultet@redhat.com>
Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2016-02-17 12:46:34 +01:00
Erik Skultety
c50a834b80 admin: Introduce virAdmServer structure
This is the key structure of all management operations performed on the
daemon/clients. An admin client needs to be able to identify
another client (either admin or non-privileged client) to perform an
action on it. This identification includes a server the client is
connected to, thus a client-side representation of a server is needed.

Signed-off-by: Erik Skultety <eskultet@redhat.com>
2016-02-17 12:46:34 +01:00
Erik Skultety
252610f7dd virnetdaemon: Store servers in a hash table
Since the daemon can manage and add (at fresh start) multiple servers,
we also should be able to add them from a JSON state file in case of a
daemon restart, so post exec restart support for multiple servers is also
provided. Patch also updates virnetdaemontest accordingly.

Signed-off-by: Erik Skultety <eskultet@redhat.com>
Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2016-02-17 12:46:34 +01:00
Erik Skultety
353de572a6 util: Refactor virHashForEach so it returns as soon as an iterator fails
The method will now return 0 on success and -1 on error, rather than number of
items which it iterated over before it returned back to the caller. Since the
only place where we actually check the number of elements iterated is in
virhashtest, return value of 0 and -1 can be a pretty accurate hint that it
iterated over all the items. However, if we really want to know the number of
items iterated over (like virhashtest does), a counter has to be provided
through opaque data to each iterator call. This patch adjusts return value of
virHashForEach, refactors the body, so it returns as soon as one of the
iterators fail and adjusts virhashtest to reflect these changes.

Signed-off-by: Erik Skultety <eskultet@redhat.com>
2016-02-17 12:46:34 +01:00
Erik Skultety
cc48d3a122 util: Add a return value to void hash iterators
Our existing virHashForEach method iterates through all items disregarding the
fact, that some of the iterators might have actually failed. Errors are usually
dispatched through an error element in opaque data which then causes the
original caller of virHashForEach to return -1. In that case, virHashForEach
could return as soon as one of the iterators fail. This patch changes the
iterator return type and adjusts all of its instances accordingly, so the
actual refactor of virHashForEach method can be dealt with later.

Signed-off-by: Erik Skultety <eskultet@redhat.com>
2016-02-17 12:46:34 +01:00
Peter Krempa
d1242ba24a qemu: cgroup: Setup cgroups for bios/firmware images
oVirt wants to use OVMF images on top of lvm for their 'logical'
storage thus we should set up device ACLs for them so it will actually
work.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1305922
2016-02-17 12:29:00 +01:00
Peter Krempa
d6c91b3c03 qemu: cgroup: Extract guts of qemuSetupImageCgroupInternal
They will later be reused for setting cgroup for other image backed
devices.
2016-02-17 10:54:05 +01:00
Peter Krempa
2b15f2a196 qemu: cgroup: Split up qemuSetImageCgroupInternal
Separate the Teardown and Setup code paths into separate helpers.
2016-02-17 10:54:05 +01:00
Peter Krempa
5dd610d01d qemu: cgroup: Switch to qemu(Setup|Teardown)ImageCgroup
For other objects we use the two functions rather than one with a bool.
Convert qemuSetImageCgroup to the same approach.
2016-02-17 10:54:05 +01:00
Peter Krempa
4e22355ee1 qemu: cgroup: Avoid reporting errors from inaccessible NFS volumes
Rather than reporting it and then reseting the error, don't report it in
the first place.
2016-02-17 10:54:05 +01:00
Peter Krempa
cf113e8d54 util: cgroup: Allow ignoring EACCES in virCgroup(Allow|Deny)DevicePath
When adding disk images to ACL we may call those functions on NFS
shares. In that case we might get an EACCES, which isn't really relevant
since NFS would not hold a block device. This patch adds a flag that
allows to stop reporting an error on EACCES to avoid spaming logs.

Currently there's no functional change.
2016-02-17 10:54:05 +01:00
Peter Krempa
9cd5da710e util: cgroup: Drop virCgroup(Allow|Deny)DeviceMajor
Since commit 47e5b5ae virCgroupAllowDevice allows to pass -1 as either
the minor or major device number and it automatically uses '*' in place
of that. Reuse the new approach through the code and drop the duplicated
functions.
2016-02-17 10:54:05 +01:00
Peter Krempa
f42b5c327f util: cgroup: Instrument virCgroupDenyDevice to handle -1 device number as *
Similarly to commit 47e5b5ae virCgroupDenyDevice will handle -1 as *.
2016-02-17 10:54:05 +01:00
Peter Krempa
23087cfdbd qemu: migration: Refactor code now that we assume support for fd migration
After removing capability check for fd migration the code that was left
behind didn't make quite sense. The old exec migration would be used in
case when pipe() failed. Remove the old code and make failure of pipe()
a hard error.

This additionally removes usage of virCgroupAllowDevicePath outside of
qemu_cgroup.c.
2016-02-17 10:52:38 +01:00
Peter Krempa
21212fca13 qemu: cgroup: Remove abandoned function qemuAddToCgroup
This function doesn't do anything useful since 2049ef9942.
2016-02-17 10:28:34 +01:00