Commit Graph

16111 Commits

Author SHA1 Message Date
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