Commit Graph

1342 Commits

Author SHA1 Message Date
Martin Kletzander
d3c784999d conf: Add support of zero-detection for disks
This option allows or disallows detection of zero-writes if it is set to
"on" or "off", respectively.  It can be also set to "unmap" in which
case it will try discarding that part of image based on the value of the
"discard" option.

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

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

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

Signed-off-by: Wang Yufei <james.wangyufei@huawei.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2016-06-13 13:34:37 +02:00
Michal Privoznik
559b78d96a Export virDomainRedirdevDefFree
In the 162efa1a commit the function was introduced, but the
commit forgot to update livirt_private.syms accordingly.

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

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

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

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2016-06-09 18:07:00 +01:00
Pavel Hrdina
b6465e1aa4 graphics: introduce new listen type 'socket'
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2016-06-09 14:24:00 +02:00
Jiri Denemark
9ea32aecb4 cpu_x86: Avoid unnecessary pointers to virCPUx86Data
virCPUData, virCPUx86Feature, and virCPUx86Model all contained a pointer
to virCPUx86Data, which was not very nice since the real CPUID data were
accessible by yet another pointer from virCPUx86Data. Moreover, using
virCPUx86Data directly will make static definitions of internal CPU
features a bit easier.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-06-09 09:47:56 +02:00
Ján Tomko
32e6339c19 Export virDomainGetBlkioParametersAssignFromDef
Move qemuDomainGetBlkioParametersAssignFromDef into domain_conf
and export it, to allow reuse in the LXC driver.
2016-06-08 15:23:44 +02:00
Ján Tomko
4702687cfb Introduce virXMLValidatorValidate
Split out the code for XML validation into a new function.
2016-06-08 09:58:54 +02:00
Ján Tomko
87ae612de9 Introduce virXMLValidatorInit
Split out all the code initializing the validator
to a separate function.
2016-06-08 09:58:54 +02:00
Ján Tomko
8657c7a12f Introduce virXMLValidatorFree
Split out the code cleaning up the validator.
2016-06-08 09:58:54 +02:00
Peter Krempa
78b9b85c06 log: daemon: Add remote protocol handling for the log appending API
Implement the RPC dispatcher and caller for the new API.
2016-06-07 18:10:29 +02:00
Peter Krempa
05eab1bf9a conf: Move disk info validator to the domain conf validator
Since it will not be called from outside of conf we can unexport it too
if we move it to the appropriate place.

Test suite change is necessary since the error will be reported sooner
now.
2016-06-07 13:02:20 +02:00
Peter Krempa
b394af162a conf: Add infrastructure for adding configuration validation
Until now we weren't able to add checks that would reject configuration
once accepted by the parser. This patch adds a new callback and
infrastructure to add such checks. In this patch all the places where
rejecting a now-invalid configuration wouldn't be a good idea are marked
with a new parser flag.
2016-06-07 13:02:20 +02:00
John Ferlan
1b5f1884a2 qemu: Move and rename qemuBuildObjectCommandlineFromJSON
Move the module from qemu_command.c to a new module virqemu.c and
rename the API to virQEMUBuildObjectCommandline.

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

Signed-off-by: John Ferlan <jferlan@redhat.com>
2016-06-06 13:44:51 -04:00
Michal Privoznik
89ef1589a2 Drop virPerfGetEventFd
This function is not used anywhere. Moreover, the code that would
use lives in virperf.c and therefore has access to the FD anyway.
Well, for instance virPerfReadEvent is doing just that.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2016-06-03 10:52:16 +02:00
Laine Stump
808e16ff13 conf: make virDomainControllerFindUnusedIndex() more generally usable
Make virDomainControllerFindUnusedIndex() a global function so that it
can be used outside domain_conf.c (as well as higher up in
domain_conf.c itself)/ Also make its DomainDef arg a const* so that
functions which only have a const* to the domain can use it.
2016-05-25 15:00:25 -04:00
John Ferlan
238032505f util: Introduce virCryptoGenerateRandom
Move the logic from qemuDomainGenerateRandomKey into this new
function, altering the comments, variable names, and error messages
to keep things more generic.

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

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

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

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

Adjust tests for the API's
2016-05-20 11:09:01 -04:00
Nikolay Shirokovskiy
abc85b2cab vz: add domain snapshots functionality
This solution does not keep snapshots cache because vz sdk lacks good support
for snapshot related events.

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

Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
Signed-off-by: Maxim Nestratov <mnestratov@virtuozzo.com>
2016-05-18 18:14:58 +03:00
Jiri Denemark
d8d4b9d957 Remove virDomainRNGInsert
It was just a useless wrapper around VIR_APPEND_ELEMENT*.
2016-05-18 09:36:23 +02:00
John Ferlan
1cf5af40b9 util: string: Introduce helper to determine whether a byte buffer is printable
Signed-off-by: John Ferlan <jferlan@redhat.com>
2016-05-16 12:58:48 +02:00
Peter Krempa
cb2e3e50ee util: string: Introduce virStringEncodeBase64
Add a new helper that sanitizes error semantics of base64_encode_alloc.
2016-05-16 12:58:48 +02:00
Peter Krempa
eb2116fd9a util: alloc: Introduce freeing helpers that clear the memory before freeing
For a few cases where we handle secret information it's good to clear
the buffers containing sensitive data before freeing them.

Introduce VIR_DISPOSE, VIR_DISPOSE_N and VIR_DISPOSE_STRING that allow
simple clearing fo the buffers holding sensitive information on cleanup
paths.
2016-05-16 12:58:48 +02:00
Michal Privoznik
7fccf12482 virfile: Introduce virFileRemoveLastComponent
Move some parts of virStorageFileRemoveLastPathComponent
into a separate function so they can be reused.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2016-05-13 14:17:15 +02:00
Laine Stump
b3f2c7cae8 conf: make virDomainDefAddController() public
This will be needed by the qemu driver in an upcoming patch.
2016-05-10 17:03:11 -04:00
Peter Krempa
1f880b5f22 conf: Kill now unused virDomainDiskSourceIsBlockType 2016-05-09 13:16:26 +02:00
Peter Krempa
3ec7bb354a util: Replace virDomainDiskSourceIsBlockType with a new helper
For disks sources described by a libvirt volume we don't need to do a
complicated check since virStorageTranslateDiskSourcePool already
correctly determines the actual disk type.

Replace the checks using a new accessor that does not open-code the
whole logic.
2016-05-09 12:36:52 +02:00
Nikolay Shirokovskiy
3506ad7f0a util: factor out reading file into preallocated buffer
Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
2016-05-03 08:58:30 -04:00
Cole Robinson
345d2ab488 qemu: parse: Use virControllerDefNew
Rather than reimplement it. This will be needed in upcoming patches
2016-05-03 08:58:30 -04:00
Martin Kletzander
c36b1f7b6a Change virDevicePCIAddress to virPCIDeviceAddress
We had both and the only difference was that the latter also included
information about multifunction setting.  The problem with that was that
we couldn't use functions made for only one of the structs (e.g.
parsing).  To consolidate those two structs, use the one in virpci.h,
include that in domain_conf.h and add the multifunction member in it.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2016-05-02 15:46:23 +02:00
Peter Krempa
b527e7c8e2 qemu: Error out if setting vcpu count would lead to invalid config
When the domain definition describes a machine with NUMA, setting the
maximum vCPU count via the API might lead to an invalid config.

Add a check that will forbid this until we add more advanced cpu config
capabilities.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1327499
2016-04-28 09:25:32 +02:00
Martin Kletzander
a042275a39 Unify domain name shortening
Add virDomainObjGetShortName() and use it.  For now that's used in one
place, but we should expose it so that future patches can use it.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2016-04-27 15:07:10 +02:00
John Ferlan
43d3e3c130 secret: Introduce virSecretObjGetValue and virSecretObjGetValueSize
Introduce the final accessor's to _virSecretObject data and move the
structure from virsecretobj.h to virsecretobj.c

The virSecretObjSetValue logic will handle setting both the secret
value and the value_size. Some slight adjustments to the error path
over what was in secretSetValue were made.

Additionally, a slight logic change in secretGetValue where we'll
check for the internalFlags and error out before checking for
and erroring out for a NULL secret->value. That way, it won't be
obvious to anyone that the secret value wasn't set rather they'll
just know they cannot get the secret value since it's private.
2016-04-25 15:45:29 -04:00
John Ferlan
9e1e56216f secret: Introduce virSecretObj{Get|Set}Def
Introduce fetch and set accessor to the secretObj->def field for usage
by the driver to avoid the driver needing to know the format of virSecretObj
2016-04-25 15:45:29 -04:00
John Ferlan
ac9ffd607e secret: Introduce virSecretObjSave{Config|Data}
Move and rename the secretRewriteFile, secretSaveDef, and secretSaveValue
from secret_driver to virsecretobj

Need to make some slight adjustments since the secretSave* functions
called secretEnsureDirectory, but otherwise mostly just a move of code.
2016-04-25 15:45:29 -04:00
John Ferlan
d467ac07ce secret: Introduce virSecretObjDelete{Config|Data}
Move and rename secretDeleteSaved from secret_driver into virsecretobj and
split it up into two parts since there is error path code that looks to
just delete the secret data file
2016-04-25 15:45:29 -04:00
John Ferlan
85ec94f870 secret: Move and rename secretLoadAllConfigs
Move to secret_conf.c and rename to virSecretLoadAllConfigs. Also includes
moving/renaming the supporting virSecretLoad, virSecretLoadValue, and
virSecretLoadValidateUUID.
2016-04-25 15:45:29 -04:00
John Ferlan
993f91287e secret: Use the hashed virSecretObjList
This patch replaces most of the guts of secret_driver.c with recently
added secret_conf.c APIs in order manage secret lists and objects
using the hashed virSecretObjList* lookup API's.
2016-04-25 15:45:29 -04:00
John Ferlan
615c8cce64 secret: Introduce virSecretUsageIDForDef
Move the driver specific secretUsageIDForDef into secret_conf.c. It could
be more of a general purpose API.
2016-04-25 15:45:29 -04:00
Martin Kletzander
32f3f0835e security: Rename DomainSetDirLabel to DomainSetPathLabel
It already labels abritrary paths, so it's just the naming that was
wrong.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2016-04-18 20:34:30 +02:00
Erik Skultety
93ab4da5f4 admin: Introduce virAdmServerSetThreadPoolParameters
Since threadpool increments the current number of threads according to current
load, i.e. how many jobs are waiting in the queue. The count however, is
constrained by max and min limits of workers. The logic of this new API works
like this:
    1) setting the minimum
        a) When the limit is increased, depending on the current number of
           threads, new threads are possibly spawned if the current number of
           threads is less than the new minimum limit
        b) Decreasing the minimum limit has no possible effect on the current
           number of threads
    2) setting the maximum
        a) Icreasing the maximum limit has no immediate effect on the current
           number of threads, it only allows the threadpool to spawn more
           threads when new jobs, that would otherwise end up queued, arrive.
        b) Decreasing the maximum limit may affect the current number of
           threads, if the current number of threads is less than the new
           maximum limit. Since there may be some ongoing time-consuming jobs
           that would effectively block this API from killing any threads.
           Therefore, this API is asynchronous with best-effort execution,
           i.e. the necessary number of workers will be terminated once they
           finish their previous job, unless other workers had already
           terminated, decreasing the limit to the requested value.
    3) setting priority workers
        - both increase and decrease in count of these workers have an
          immediate impact on the current number of workers, new ones will be
          spawned or some of them get terminated respectively.

Signed-off-by: Erik Skultety <eskultet@redhat.com>
2016-04-18 17:07:46 +02:00
Erik Skultety
c516e7d31a util: Add more getters to threadpool parameters
In order for the client to see all thread counts and limits, current total
and free worker count getters need to be introduced. Client might also be
interested in the job queue length, so provide a getter for that too. As with
the other getters, preparing for the admin interface, mutual exclusion is used
within all getters.

Signed-off-by: Erik Skultety <eskultet@redhat.com>
2016-04-18 17:07:18 +02:00
Richard W.M. Jones
beaa447a29 Add functions for handling exponential backoff loops.
In a few places in libvirt we busy-wait for events, for example qemu
creating a monitor socket.  This is problematic because:

 - We need to choose a sufficiently small polling period so that
   libvirt doesn't add unnecessary delays.

 - We need to choose a sufficiently large polling period so that
   the effect of busy-waiting doesn't affect the system.

The solution to this conflict is to use an exponential backoff.

This patch adds two functions to hide the details, and modifies a few
places where we currently busy-wait.

Signed-off-by: Richard W.M. Jones <rjones@redhat.com>
2016-04-15 16:54:28 +01:00
Peter Krempa
d6cb0d256a domain: Add helper to determine presence of memory baloon 2016-04-15 14:27:08 +02:00
Laine Stump
a0616ee8a8 conf: utility function to convert PCI controller model into connect type
There are two places in qemu_domain_address.c where we have a switch
statement to convert PCI controller models
(VIR_DOMAIN_CONTROLLER_MODEL_PCI*) into the connection type flag that
is matched when looking for an upstream connection for that model of
controller (VIR_PCI_CONNECT_TYPE_*). This patch makes a utility
function in conf/domain_addr.c to do that, so that when a new PCI
controller is added, we only need to add the new model-->connect-type
in a single place.
2016-04-14 14:00:34 -04:00
Cole Robinson
e7db227810 util: Add virGettextInitialize, convert the code
Take setlocale/gettext error handling pattern from tools/virsh-*
and use it for all standalone binaries via a new shared
virGettextInitialize routine. The virsh* pattern differed slightly
from other callers. All users now consistently:

* Ignore setlocale errors. virsh has done this forever, presumably for
  good reason. This has been partially responsible for some bug reports:

  https://bugzilla.redhat.com/show_bug.cgi?id=1312688
  https://bugzilla.redhat.com/show_bug.cgi?id=1026514
  https://bugzilla.redhat.com/show_bug.cgi?id=1016158

* Report the failed function name
* Report strerror
2016-04-14 13:22:40 -04:00
Maxim Nestratov
4dc5d8f2c1 fix build by correcting functions order and src/Makefile.am
commit 30c61901 added new functions to libvirt_private.syms
not alpabetically sorted and erroneously added vz sources to
STATEFUL_DRIVER_SOURCE_FILES, which triggered check-aclrules
running while vz driver isn't ready for it yet.

Pushing under build-breaker rule.

Signed-off-by: Maxim Nestratov <mnestratov@virtuozzo.com>
2016-04-14 03:09:19 +03:00
Maxim Nestratov
30c61901c8 vz: build driver as module and don't register it on client's side
Make it possible to build vz driver as a module and don't link it with
libvirt.so statically.
Remove registering it on client's side as far as we start relying on daemon

Signed-off-by: Maxim Nestratov <mnestratov@virtuozzo.com>
2016-04-13 18:48:43 +03:00
Ján Tomko
cbbd74aad5 qemuxml2argvtest: do not mock virCommand
Mock virNetDevRunEthernetScript instead.

This restores the VIR_TEST_REGENERATE_OUTPUT functionality.
2016-04-13 15:01:17 +02:00
Peter Krempa
5be120710e Add VIR_DOMAIN_EVENT_ID_DEVICE_REMOVAL_FAILED event
Since we didn't opt to use one single event for device lifecycle for a
VM we are missing one last event if the device removal failed. This
event will be emitted once we asked to eject the device but for some
reason it is not possible.
2016-04-13 13:26:29 +02:00
Pavel Hrdina
40d246d282 domain_conf: remove unused virDomainGraphicsListenGet*
Those are the last two places that uses the getter functions.  Use a
direct access instead and remove those getters.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2016-04-13 10:43:49 +02:00
Pavel Hrdina
37b1f45066 domain_conf: cleanup virDomainGraphicsGetListen
Removes the check for graphics type, it's not a public API and developer
know what he's doing and this check makes no sense.  It also removes
the ability to allocate a new array if there is none.  This was used by
the virDomainGraphicsListenAdd* functions and isn't used anymore.

This is now a simple getter with simple check for listens array presence
and whether the index in out of bounds.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2016-04-13 10:43:49 +02:00
Pavel Hrdina
d6d17226ff domain_conf: remove unused virDomainGraphicsListenSetType
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2016-04-13 10:43:49 +02:00
Pavel Hrdina
39995aa480 domain_conf: remove virDomainGraphicsListenSetNetwork
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2016-04-13 10:43:49 +02:00
Pavel Hrdina
4b75237fe6 domain_conf: introduce virDomainGraphicsListenAppendAddress
This effectively removes virDomainGraphicsListenSetAddress which was
used only to change the address of listen structure and possible change
the listen type.  The new function will auto-expand the listens array
and append a new listen.

The old function was used on pre-allocated array of listens and in most
cases it only "add" a new listen.  The two remaining uses can access the
listen structure directly.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2016-04-13 10:43:49 +02:00
Peter Krempa
dcf02a704f util: Rename and move virStrIsPrint to virStringIsPrintable 2016-04-13 08:15:24 +02:00
John Ferlan
2844de6f40 secret: Introduce virSecretGetSecretString
Commit id 'fb2bd208' essentially copied the qemuGetSecretString
creating an libxlGetSecretString.  Rather than have multiple copies
of the same code, create src/secret/secret_util.{c,h} files and
place the common function in there.

Modify the the build in order to build the module as a library
which is then pulled in by both the qemu and libxl drivers for
usage from both qemu_command.c and libxl_conf.c
2016-04-06 20:31:21 -04:00
John Ferlan
6af73f53c6 util: Introduce virRandomBytes
Using the existing virUUIDGenerateRandomBytes, move API to virrandom.c
rename it to virRandomBytes and add it to libvirt_private.syms.

This will be used as a fallback for generating a domain master key.
2016-04-06 20:27:09 -04:00
Peter Krempa
5c633e0f7b conf: Remove now unused virDomainIOThreadIDMap 2016-03-29 21:26:07 +02:00
Peter Krempa
917426c8d7 util: bitmap: Introduce self-expanding bitmap APIs
In some cases it's impractical to use the regular APIs as the bitmap
size needs to be pre-declared. These new APIs allow to use bitmaps that
self expand.

The new code adds a property to the bitmap to track the allocation of
memory so that VIR_RESIZE_N can be used.
2016-03-29 21:25:41 +02:00
Qiaowei Ren
28b446292b perf: implement a set of util functions for perf event
This patch implement a set of interfaces for perf event. Based on
these interfaces, we can implement internal driver API for perf,
and get the results of perf conuter you care about.

Signed-off-by: Qiaowei Ren <qiaowei.ren@intel.com>
Message-id: 1459171833-26416-4-git-send-email-qiaowei.ren@intel.com
2016-03-29 13:13:05 +01:00
Martin Kletzander
573c41a275 util: Add virSocketAddrSetIPv[46]AddrNetOrder and use it
This allows setting the address in host and/or network order and makes
the naming consistent.  Now you don't need to call [hn]to[nh]l()
functions as that is taken care of by these functions.  Also, now
the *NetOrder take the address in network order, the other functions in
host order so the naming and usage is consistent.  Some places were
having the address in network order and calling ntohl() just so the
original function can call htonl() again.  This makes it nicer to read.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2016-03-21 11:28:33 +01:00
Cole Robinson
9a423d1826 domain: Add virDomainDefAddImplicitDevices
It's just a combination of AddImplicitControllers, and AddConsoleCompat.
Every caller that wants ImplicitControllers also wants the ConsoleCompat
AFAICT, so lump them together. We also need it for future patches.
2016-03-20 16:11:04 -04:00
Martin Kletzander
d77ffb6876 nodedev: Expose PCI header type
If we expose this information, which is one byte in every PCI config
file, we let all mgmt apps know whether the device itself is an endpoint
or not so it's easier for them to decide whether such device can be
passed through into a VM (endpoint) or not (*-bridge).

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

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2016-03-18 17:35:06 +01:00
Michal Privoznik
1ca59d89c6 virsocketaddr: Introduce virSocketAddrSetIPv6Addr
This is a missing counterpart for virSocketAddrSetIPv4Addr()
and is going to be needed later in the tests.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2016-03-18 17:29:53 +01:00
Michal Privoznik
fd9514f8d2 Export virLease* functions for leases file handling
These functions are going to be reused very shortly. So instead
of duplicating the code, lets move them into utils module.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2016-03-18 17:29:53 +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
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
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
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
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
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
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
Andrea Bolognani
768b7ed2c8 conf: Use virGICVersion enumeration in virDomainDef
Instead of allowing any random positive number, restrict the possible
values to the ones that are part of the virGICVersion enumeration.
2016-02-16 14:58:58 +01:00
Michal Privoznik
862298a2e7 dbus: Don't unref NULL messages
Apparently we are not the only ones with dumb free functions
because dbus_message_unref() does not accept NULL either. But if
I were to vote, this one is even more evil. Instead of returning
an error just like we do it immediately dereference any pointer
passed and thus crash you app. Well done DBus!

  Program received signal SIGSEGV, Segmentation fault.
  [Switching to Thread 0x7f878ebda700 (LWP 31264)]
  0x00007f87be4016e5 in ?? () from /usr/lib64/libdbus-1.so.3
  (gdb) bt
  #0  0x00007f87be4016e5 in ?? () from /usr/lib64/libdbus-1.so.3
  #1  0x00007f87be3f004e in dbus_message_unref () from /usr/lib64/libdbus-1.so.3
  #2  0x00007f87bf6ecf95 in virSystemdGetMachineNameByPID (pid=9849) at util/virsystemd.c:228
  #3  0x00007f879761bd4d in qemuConnectCgroup (driver=0x7f87600a32a0, vm=0x7f87600c7550) at qemu/qemu_cgroup.c:909
  #4  0x00007f87976386b7 in qemuProcessReconnect (opaque=0x7f87600db840) at qemu/qemu_process.c:3386
  #5  0x00007f87bf6edfff in virThreadHelper (data=0x7f87600d5580) at util/virthread.c:206
  #6  0x00007f87bb602334 in start_thread (arg=0x7f878ebda700) at pthread_create.c:333
  #7  0x00007f87bb3481bd in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:109
  (gdb) frame 2
  #2  0x00007f87bf6ecf95 in virSystemdGetMachineNameByPID (pid=9849) at util/virsystemd.c:228
  228         dbus_message_unref(reply);
  (gdb) p reply
  $1 = (DBusMessage *) 0x0

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2016-02-11 11:35:02 +01:00
Peter Krempa
6dfb4507f5 conf: Fix how iothread scheduler info is stored
Similarly to previous commit change the way how iothread scheduler info
is stored and clean up a lot of unnecessary code.
2016-02-08 09:51:34 +01:00
Peter Krempa
cc715e9391 conf: remove unused cpu pinning helpers and data structures
Now that the pinning info is stored elsewhere we can delete all the
obsolete code.
2016-02-08 09:51:34 +01:00
Peter Krempa
e84ab7938d conf: Move and optimize disk target duplicity checking
Move the logic from virDomainDiskDefDstDuplicates into
virDomainDiskDefCheckDuplicateInfo so that we don't have to loop
multiple times through the array of disks. Since the original function
was called in qemuBuildDriveDevStr, it was actually called for every
single disk which was quite wasteful.

Additionally the target uniqueness check needed to be duplicated in
the disk hotplug case, since the disk was inserted into the domain
definition after the device string was formatted and thus
virDomainDiskDefDstDuplicates didn't do anything in that case.
2016-02-08 09:35:01 +01:00
Peter Krempa
4f1324aa48 qemu: hotplug: Check duplicate disk serial/wwn on hotplug too
We do the check on VM start, but the user could still hotplug a disk
with a conflicting serial or WWN. Reuse the checker function to fix the
issue.
2016-02-08 09:08:38 +01:00
Peter Krempa
e992aa21f7 conf: Add helper to return a bitmap of active iothread ids 2016-02-05 16:21:45 +01:00
Peter Krempa
9479642fd3 util: bitmap: Introduce bitmap subtraction
Performs binary subtraction of two bitmaps. Stores result in the first
operand.
2016-02-05 16:21:45 +01:00
Joao Martins
819d1d9438 conf: add net device prefix to capabilities
In the reverted commit d2e5538b1, the libxl driver was changed to copy
interface names autogenerated by libxl to the corresponding network def
in the domain's virDomainDef object. The copied name is freed when the
domain transitions to the shutoff state. But when migrating a domain,
the autogenerated name is included in the XML sent to the destination
host.  It is possible an interface with the same name already exists on
the destination host, causing migration to fail.

This patch defines a new capability for setting the network device
prefix that will be used in the driver. Valid prefixes are
VIR_NET_GENERATED_PREFIX or the one announced by the driver.

Signed-off-by: Joao Martins <joao.m.martins@oracle.com>
2016-02-04 11:15:51 +00:00
Erik Skultety
8cd1d546e6 util: Export remoteSerializeTypedParameters internally via util
Same as for deserializer, this method might get handy for admin one day.
The major reason for this patch is to stay consistent with idea, i.e.
when deserializer can be shared, why not serializer as well. The only
problem to be solved was that the daemon side serializer uses a code
snippet which handles sparse arrays returned by some APIs as well as
removes any string parameters that can't be returned to older clients.
This patch makes of the new virTypedParameterRemote datatype introduced
by one of the pvious patches.
2016-02-03 15:46:45 +01:00
Erik Skultety
9afc115f73 util: Export remoteFreeTypedParameters internally via util
Since the method is static to remote_driver, it can't even be used by our
daemon. Other than that, it would be useful to be able to use it with admin as
well. This patch uses the new virTypedParameterRemote datatype introduced in
one of previous patches.
2016-02-03 15:46:45 +01:00
Erik Skultety
0472cef685 util: Export remoteDeserializeTypedParameters internally via util
Currently, the deserializer is hardcoded into remote_driver which makes
it impossible for admin to use it. One way to achieve a shared implementation
(besides moving the code to another module) would be pass @ret_params_val as a
void pointer as opposed to the remote_typed_param pointer and add a new extra
argument specifying which of those two protocols is being used and typecast
the pointer at the function entry. An example from remote_protocol:

struct remote_typed_param_value {
        int type;
        union {
                int i;
                u_int ui;
                int64_t l;
                uint64_t ul;
                double d;
                int b;
                remote_nonnull_string s;
        } remote_typed_param_value_u;
};
typedef struct remote_typed_param_value remote_typed_param_value;

struct remote_typed_param {
        remote_nonnull_string field;
        remote_typed_param_value value;
};

That would leave us with a bunch of if-then-elses that needed to be used across
the method. This patch takes the other approach using the new datatype
introduced in one of earlier commits.
2016-02-03 15:46:45 +01:00
Nikolay Shirokovskiy
1e93470df0 qemu: qemuDomainRename and virDomainObjListNumOfDomains ABBA deadlock fix
A pretty nasty deadlock occurs while trying to rename a VM in parallel
with virDomainObjListNumOfDomains.
The short description of the problem is as follows:

Thread #1:

qemuDomainRename:
    ------> aquires domain lock by qemuDomObjFromDomain
       ---------> waits for domain list lock in any of the listed functions:
          - virDomainObjListFindByName
          - virDomainObjListRenameAddNew
          - virDomainObjListRenameRemove

Thread #2:

virDomainObjListNumOfDomains:
    ------> aquires domain list lock
       ---------> waits for domain lock in virDomainObjListCount

Introduce generic virDomainObjListRename function for renaming domains.
It aquires list lock in right order to avoid deadlock. Callback is used
to make driver specific domain updates.

Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2016-02-03 15:20:11 +01:00
Martin Kletzander
92757d4d2d systemd: Add virSystemdGetMachineNameByPID
Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2016-02-03 14:57:43 +01:00
Peter Krempa
9bf284daa9 conf: Add helper to retrieve bitmap of active vcpus for a definition
In some cases it may be better to have a bitmap representing state of
individual vcpus rather than iterating the definition. The new helper
creates a bitmap representing the state from the domain definition.
2016-02-03 13:10:04 +01:00
Andrea Bolognani
771eaeb2b3 pci: Phase out virPCIDeviceReattachInit()
The name is confusing, and there are just two uses: one is a test case,
and the other will be removed as part of an upcoming refactoring of
the hostdev code.
2016-01-28 11:31:28 +01:00
Laine Stump
370608b4c7 util: keep/use a bitmap of in-use macvtap devices
This patch creates two bitmaps, one for macvlan device names and one
for macvtap. The bitmap position is used to indicate that libvirt is
currently using a device with the name macvtap%d/macvlan%d, where %d
is the position in the bitmap. When requested to create a new
macvtap/macvlan device, libvirt will now look for the first clear bit
in the appropriate bitmap and derive the device name from that rather
than just starting at 0 and counting up until one works.

When libvirtd is restarted, the qemu driver code that reattaches to
active domains calls the appropriate function to "re-reserve" the
device names as it is scanning the status of running domains.

Note that it may seem strange that the retry counter now starts at
8191 instead of 5. This is because we now don't do a "pre-check" for
the existence of a device once we've reserved it in the bitmap - we
move straight to creating it; although very unlikely, it's possible
that someone has a running system where they have a large number of
network devices *created outside libvirt* named "macvtap%d" or
"macvlan%d" - such a setup would still allow creating more devices
with the old code, while a low retry max in the new code would cause a
failure. Since the objective of the retry max is just to prevent an
infinite loop, and it's highly unlikely to do more than 1 iteration
anyway, having a high max is a reasonable concession in order to
prevent lots of new failures.
2016-01-26 12:20:04 -05:00
Daniel P. Berrange
dc576025c3 lxc: don't try to hide parent cgroups inside container
On the host when we start a container, it will be
placed in a cgroup path of

   /machine.slice/machine-lxc\x2ddemo.scope

under /sys/fs/cgroup/*

Inside the containers' namespace we need to setup
/sys/fs/cgroup mounts, and currently will bind
mount /machine.slice/machine-lxc\x2ddemo.scope on
the host to appear as / in the container.

While this may sound nice, it confuses applications
dealing with cgroups, because /proc/$PID/cgroup
now does not match the directory in /sys/fs/cgroup

This particularly causes problems for systems and
will make it create repeated path components in
the cgroup for apps run in the container eg

  /machine.slice/machine-lxc\x2ddemo.scope/machine.slice/machine-lxc\x2ddemo.scope/user.slice/user-0.slice/session-61.scope

This also causes any systemd service that uses
sd-notify to fail to start, because when systemd
receives the notification it won't be able to
identify the corresponding unit it came from.
In particular this break rabbitmq-server startup

Future kernels will provide proper cgroup namespacing
which will handle this problem, but until that time
we should not try to play games with hiding parent
cgroups.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2016-01-26 16:11:32 +00:00
Roman Bogorodskiy
318ae9f3be conf: expose virDomainBootType(From|To)String
These functions are going to be used by the Bhyve driver.
2016-01-25 03:54:07 +03:00
Jiri Denemark
0b50f4a025 Introduce migration iteration event
The VIR_DOMAIN_EVENT_ID_MIGRATION_ITERATION event will be triggered
whenever VIR_DOMAIN_JOB_MEMORY_ITERATION changes its value, i.e.,
whenever a new iteration over guest memory pages is started during
migration.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-01-21 16:36:08 +01:00
Laine Stump
8ebca27bb7 qemu: define virDomainDevAddUSBController()
This new function will add a single controller of the given model,
except the case of ich9-usb-ehci1 (the master controller for a USB2
controller set) in which case a set of related controllers will be
added (EHCI1, UHCI1, UHCI2, UHCI3). These controllers will not be
given PCI addresses, but should be otherwise ready to use.

"-1" is allowed for controller model, and means "default for this
machinetype". This matches the existing practice in
qemuDomainDefPostParse(), which always adds the default controller
with model = -1, and relies on the commandline builder to set a model
(that is wrong, but will be fixed later).
2016-01-11 13:16:51 -05:00
Andrea Bolognani
6d9cdd2a57 pci: Introduce virPCIStubDriver enumeration
This replaces the virPCIKnownStubs string array that was used
internally for stub driver validation.

Advantages:

  * possible values are well-defined
  * typos in driver names will be detected at compile time
  * avoids having several copies of the same string around
  * no error checking required when setting / getting value

The names used mirror those in the
virDomainHostdevSubsysPCIBackendType enumeration.
2015-12-21 11:17:22 +01:00
Ján Tomko
22f9754f1b mark virDomainVirtioSerialAddrSetAddController as static.
This function is no longer used outside domain_addr.c
2015-12-17 16:57:25 +01:00
Ján Tomko
36d7a36158 Remove dead code from qemuDomainAttachControllerDevice
We only support hotplugging SCSI controllers.
The USB and virtio-serial related code was never reachable because
this function was only called for VIR_DOMAIN_CONTROLLER_TYPE_SCSI
controllers.

This reverts commit ee0d97a and parts of commits 16db8d2
and d6d54cd1.
2015-12-17 16:57:25 +01:00