Commit Graph

1294 Commits

Author SHA1 Message Date
Peter Krempa
a877a1635b conf: Remove pre-calculation of initial memory size
While we need to know the difference between the total memory stored in
<memory> and the actual size not included in the possible memory modules
we can't pre-calculate it reliably. This is due to the fact that
libvirt's XML is copied via formatting and parsing the XML and the
initial memory size can be reliably calculated only when certain
conditions are met due to backwards compatibility.

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

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

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1344892
2016-06-17 10:36:41 +02:00
Jovanka Gulicoska
dc7b849a0c conf: add storage_event handling
Add storage event handling infrastructure to storage_event.[ch], following
the network_event.[ch] pattern.
2016-06-16 12:22:11 -04:00
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