Commit Graph

621 Commits

Author SHA1 Message Date
Jim Fehlig
33a1a7c6f5 libxl: remove reference to non-existent out label
Commit e6336442 changed the 'out:' label to 'cleanup'  in
libxlDomainAttachNetDevice(), but missed a comment referencing
the 'out:' label. Remove it from the comment since it is no
longer accurate anyhow.
2016-03-28 13:05:42 -06:00
Chunyan Liu
373b9e9f00 libxl: fix hot add/remove VF from a pool
For those VF allocated from a network pool, we need to set its backend
to be VIR_DOMAIN_HOSTDEV_PCI_BACKEND_XEN so that later work can be
correct.

Signed-off-by: Chunyan Liu <cyliu@suse.com>
2016-03-28 10:18:39 -06:00
Chunyan Liu
420eff8f26 libxlDomainDetachDeviceLive: handle hostdev parent is network device
When hostdev parent is network device, should call
libxlDomainDetachNetDevice to detach the device from a higher level.

Signed-off-by: Chunyan Liu <cyliu@suse.com>
2016-03-25 16:57:34 -06:00
Chunyan Liu
b5534e5391 libxlDomainDetachNetDevice: cleanup codes
Adjust codes to make it cleaner.

Signed-off-by: Chunyan Liu <cyliu@suse.com>
2016-03-25 16:57:34 -06:00
Chunyan Liu
e633644229 libxlDomainAttachNetDevice: release actual deivce and remove hostdev when fail
When AttachNetDevice failed, should call networkReleaseActualDevice
to release actual device, and if actual device is hostdev, should
remove the hostdev from vm->def->hostdevs.

Signed-off-by: Chunyan Liu <cyliu@suse.com>
2016-03-25 16:57:33 -06:00
Jim Fehlig
6ce9b85dee libxl: support enabling and disabling <hap> feature
Until now, the libxl driver ignored any <hap> setting in domain XML
and deferred to libxl, which enables hap if not specified. While
this is a good default, it prevents disabling hap if desired.

This change allows disabling hap with <hap state='off'/>. hap is
explicitly enabled with <hap/> or <hap state='on/>. Absense of <hap>
retains current behavior of deferring default state to libxl.
2016-03-21 09:28:18 -06:00
Jim Fehlig
10c3db7308 Xen drivers: show hap enabled by default in capabilities
Hardware Assisted Paging is enabled by default in Xen. Change
the capabilities output to reflect this.

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
2016-03-21 09:28:17 -06:00
Chunyan Liu
f41e03c63f libxl_conf: reuse virDomainNetGetActualtype in libxlMakeNicList
Reuse existing helper function virDomainNetGetActualtype.

Signed-off-by: Chunyan Liu <cyliu@suse.com>
Signed-off-by: Jim Fehlig <jfehlig@suse.com>
2016-03-10 14:28:52 -07:00
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
Nikolay Shirokovskiy
390665a9b8 libxl: reuse virDomainObjUpdateModificationImpact
Original current flag expansion does not filter out non
_CONFIG and _LIVE flags explicitly but they are prohibited
earlier by virCheckFlags.

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

Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
2016-03-04 07:39:01 -05:00
Nikolay Shirokovskiy
b523302c42 libxl: Remove extraneous AFFECT_LIVE and not active check.
libxlDomainPinVcpuFlags calls virDomainLiveConfigHelperMethod which will
call virDomainObjUpdateModificationImpact make the same AFFECT_LIVE flags
and !active check, so remove this duplicated check.

Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
Signed-off-by: John Ferlan <jferlan@redhat.com>
2016-03-01 10:41:53 -05:00
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
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
Jim Fehlig
c23bbfad6e libxl: fix bogus indentation from commit fb2bd208 2016-02-23 15:28:04 -07: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
Joao Martins
5194eb9564 libxl: keepalive messages support
This patch introduces keep alive messages support for P2P migration
and it adds two new configuration entries namely 'keepalive_interval'
'keepalive_count' to control it. Behavior of these entries is the
same as qemu driver thus the description is copied from there
with just a few simplifications.

Signed-off-by: Joao Martins <joao.m.martins@oracle.com>
2016-02-09 21:14:12 -07:00
Joao Martins
a79da2457e libxl: add p2p migration
Introduce support for VIR_MIGRATE_PEER2PEER in libvirt migration.
Most of the changes occur at the source and no modifications at
the receiver.

In P2P mode there is only the Perform phase so we must handle the
connection with the destination and actually perform the
migration. libxlDomainPerformP2P implements the connection to the
destination and libxlDoMigrateP2P implements the actual migration
logic with virConnectPtr. In this function we take care of doing
all phases of migration in the destination similar to
virDomainMigrateVersion3Full. We appropriately save the last
error reported in each of the phases to provide proper reporting.
We don't yet support VIR_MIGRATE_TUNNELED and we always use V3
with extensible params, thus it also makes the implementation
simpler.

It is worth noting that the receiver didn't have any changes, and
since it's still the v3 sequence thus it is possible to migrate
from a P2P to non-P2P host.

Signed-off-by: Joao Martins <joao.m.martins@oracle.com>
2016-02-09 20:26:54 -07:00
Peter Krempa
d2a6fc79e3 conf: Store cpu pinning data in def->vcpus
Now with the new struct the data can be stored in a much saner place.
2016-02-08 09:51:34 +01:00
Peter Krempa
856f254eef conf: Don't copy def->cpumask into cpu pinning info
This step can be omitted, so that drivers can decide what to do when the
user requests to use default vcpu pinning.
2016-02-08 09:51:34 +01:00
Daniel P. Berrange
1036ddadb2 conf: add caps to virDomainObjFormat/SaveStatus
The virDomainObjFormat and virDomainSaveStatus methods
both call into virDomainDefFormat, so should be providing
a non-NULL virCapsPtr instance.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2016-02-05 10:57:08 +00:00
Joao Martins
a040ba9ed4 libxl: set net device prefix
Use the newly added virCapabilitiesSetNetPrefix to set
the network prefix for the driver. This in return will
be use by NetDefFormat() and NetDefParseXML() routines
to free any interface name that start with the registered
prefix.

Acked-by: Daniel P. Berrange <berrange@redhat.com>
Signed-off-by: Joao Martins <joao.m.martins@oracle.com>
2016-02-04 12:47:42 +00:00
Joao Martins
cd57b7c742 conf: add caps to virDomainSaveConfig
virDomainSaveConfig calls virDomainDefFormat which was setting the caps
to NULL, thus keeping the old behaviour (i.e. not looking at
netprefix). This patch adds the virCapsPtr to the function and allows
the configuration to be saved and skipping interface names that were
registered with virCapabilitiesSetNetPrefix().

Signed-off-by: Joao Martins <joao.m.martins@oracle.com>
2016-02-04 12:38:27 +00:00
Joao Martins
d239a5427f conf: add caps to virDomainDefFormat*
And use the newly added caps->host.netprefix (if it exists) for
interface names that match the autogenerated target names.

Signed-off-by: Joao Martins <joao.m.martins@oracle.com>
2016-02-04 12:38:26 +00:00
Pavel Hrdina
36785c7e77 device: cleanup input device code
The current code was a little bit odd.  At first we've removed all
possible implicit input devices from domain definition to add them later
back if there was any graphics device defined while parsing XML
description.  That's not all, while formating domain definition to XML
description we at first ignore any input devices with bus different to
USB and VIRTIO and few lines later we add implicit input devices to XML.

This seems to me as a lot of code for nothing.  This patch may look
to be more complicated than original approach, but this is a preferred
way to modify/add driver specific stuff only in those drivers and not
deal with them in common parsing/formating functions.

The update is to add those implicit input devices into config XML to
follow the real HW configuration visible by guest OS.

There was also inconsistence between our behavior and QEMU's in the way,
that in QEMU there is no way how to disable those implicit input devices
for x86 architecture and they are available always, even without graphics
device.  This applies also to XEN hypervisor.  VZ driver already does its
part by putting correct implicit devices into live XML.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2016-01-26 17:53:33 +01:00
Joao Martins
d18d6a85f9 libxl: dispose libxl_dominfo after libxl_domain_info()
As suggested in a previous thread [0] this patch adds some missing calls
to libxl_dominfo_{init,dispose} when doing some of the libxl_domain_info
operations which would otherwise lead to memory leaks.

[0]
https://www.redhat.com/archives/libvir-list/2015-September/msg00519.html

Signed-off-by: Joao Martins <joao.m.martins@oracle.com>
2016-01-21 09:49:57 -07:00
Martin Kletzander
93103da84b Provide parse flags to PostParse functions
This way both Domain and Device PostParse functions can act based on the
flags.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2016-01-11 10:54:50 +01:00
Jim Fehlig
f988ecfb34 libxl: support vif outgoing bandwidth QoS
The libxl_device_nic structure supports specifying an outgoing rate
limit based on a time interval and bytes allowed per interval. In xl
config a rate limit is specified as "<RATE>/s@<INTERVAL>". INTERVAL
is optional and defaults to 50ms.

libvirt expresses outgoing limits by average (required), peak, burst,
and floor attributes in units of KB/s. This patch supports the outgoing
bandwidth limit by converting the average KB/s to bytes per interval
based on the same default interval (50ms) used by xl.

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
2016-01-08 18:56:00 -07: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
Jim Fehlig
60ac2aa821 Xen: xenconfig: remove xendConfigVersion from public sexpr functions
Remove use of xendConfigVersion in the s-expresion config formatter/parser
in src/xenconfig/. Adjust callers in the xen and libxl drivers accordingly.

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
2015-12-17 21:28:48 -07:00
Jim Fehlig
7d7c08be1c Xen: xenconfig: remove xendConfigVersion from public functions
Remove use of xendConfigVersion in the xm and xl config formatter/parsers
in src/xenconfig/. Adjust callers in the xen and libxl drivers accordingly.

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
2015-12-17 21:22:33 -07:00
Joao Martins
b7b439196c libxl: implement virDomainGetJobStats
Introduces support for domainGetJobStats which has the same
info as domainGetJobInfo but in a slightly different format.
Another difference is that virDomainGetJobStats can also
retrieve info on the most recently completed job. Though so
far this is only used in the source node to know if the
migration has been completed. But because we don't support
completed jobs we will deliver an error.

Signed-off-by: Joao Martins <joao.m.martins@oracle.com>
2015-12-15 15:21:38 -07:00
Joao Martins
ad71665104 libxl: implement virDomainGetJobInfo
Introduce support for domainGetJobInfo to get info about the
ongoing job. If the job is active it will update the
timeElapsed which is computed with the "started" field added to
struct libxlDomainJobObj.  For now we support just the very basic
info and all jobs have VIR_DOMAIN_JOB_UNBOUNDED (i.e. no completion
time estimation) plus timeElapsed computed.

Openstack Kilo uses the Job API to monitor live-migration
progress which is currently nonexistent in libxl driver and
therefore leads to a crash in the nova compute node. Right
now, migration doesn't use jobs in the source node and will
return VIR_DOMAIN_JOB_NONE. Though nova handles this case and
will migrate it properly instead of crashing.

Signed-off-by: Joao Martins <joao.m.martins@oracle.com>
2015-12-15 15:21:37 -07:00
Peter Krempa
71c89ac9df conf: Replace read accesses to def->vcpus with accessor 2015-12-09 14:57:12 +01:00
Peter Krempa
957d597330 conf: Replace writes to def->vcpus with accessor 2015-12-09 14:57:12 +01:00
Peter Krempa
d1dda68777 conf: Replace read access to def->maxvcpus with accessor
Finalize the refactor by adding the 'virDomainDefGetVCpusMax' getter and
reusing it accross libvirt.
2015-12-09 14:57:12 +01:00
Peter Krempa
4a194c55af conf: Extract update of vcpu count if maxvcpus is decreased
The code can be unified into the new accessor rather than being
scattered accross the drivers.
2015-12-09 14:57:12 +01:00
Peter Krempa
4e187169f0 conf: Replace writes to def->maxvcpus with accessor
To support further refactors replace all write access to def->maxvcpus
with a accessor function.
2015-12-09 14:57:12 +01:00
Pavel Hrdina
6aff1e9ca5 libxl: copy persistent domain definition while starting a guest
We should make a copy of current definition to preserve a persistent
definition, because we later update the definition with live changes.
The live definition is discarded on domain shutdown and replaced by the
copy we make before starting the domain.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2015-12-09 13:00:23 +01:00
Pavel Hrdina
91a00424db xen: use virDomainDefPostParse for parsing XM/XL/SEXPR cofings
This change ensures to call driver specific post-parse code to modify
domain definition after parsing hypervisor config the same way we do
after parsing XML.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2015-12-09 12:59:21 +01:00
Jim Fehlig
e4ac5919ba Revert "libxl: implement virDomainInterfaceStats"
This reverts commit d2e5538b16.

A migration regression was introduced by this commit. When migrating
a domain, its active XML is sent to the destination libvirtd, where
it is parsed as inactive XML. d2e5538b copied the libxl generated
interface name into the active config, which was being passed to the
migration destination and being parsed into inactive config. Attempting
to start the config could result in failure if an interface with the
same generated name already exists.

The qemu driver behaves similarly, but the parser contains a hack to
skip interface names starting with 'vnet' when parsing inactive XML.
We could extend the hack to skip names starting with 'vif' too, but a
better fix would be to expose these hypervisor-specific interface name
prefixes in capabilities. See the following discussion thread for more
details

https://www.redhat.com/archives/libvir-list/2015-December/msg00262.html

For the pending 1.3.0 release, it is best to revert d2e5538b. It can
be added again post release, after moving the prefix to capabilities.
2015-12-08 08:04:40 -07:00
Joao Martins
d2e5538b16 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 adminstrator.

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>
2015-12-02 10:04:34 -07:00
Michal Privoznik
90f3c0d717 conf: Split virDomainObjList into a separate file
Our domain_conf.* files are big enough. Not only they contain XML
parsing code, but they served as a storage of all functions whose
name is virDomain prefixed. This is just wrong as it gathers not
related functions (and modules) into one big file which is then
harder to maintain. Split virDomainObjList module into a separate
file called virdomainobjlist.[ch].

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2015-11-30 13:55:10 +01:00
Pavel Hrdina
3d0c59e5bb Post-release version bump to 1.3.0
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2015-11-24 13:52:14 +01:00
Jim Fehlig
afbb8a4c8c libxl: don't unlock virDomainObj if refcnt is 0
Commit 6472e54a unlocks the virDomainObj even if libxlDomainObjEndJob
returns false, indicating that its refcnt has dropped to 0.

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
2015-11-19 08:53:44 -07:00
Jim Fehlig
97b56031a9 libxl: unref libxlDriverConfig object
Commits b6e19cf4 and 6472e54a missed unref'ing the
libxlDriverConfig object. Add missing calls to virObjectUnref.

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
2015-11-19 08:52:53 -07:00
Joao Martins
6472e54a98 libxl: implement virDomainMemorystats
Introduce support for domainMemoryStats API call, which
consequently enables the use of `virsh dommemstat` command to
query for memory statistics of a domain. We support
the following statistics: balloon info, available and currently
in use. swap-in, swap-out, major-faults, minor-faults require
cooperation of the guest and thus currently not supported.

We build on the data returned from libxl_domain_info and deliver
it in the virDomainMemoryStat format.

Signed-off-by: Joao Martins <joao.m.martins@oracle.com>
2015-11-18 13:34:04 -07:00
Joao Martins
b6e19cf4cb libxl: implement virDomainGetCPUStats
Introduce support for domainGetCPUStats API call and consequently
allow us to use `virsh cpu-stats`. The latter returns a more brief
output than the one provided by`virsh vcpuinfo`.

Signed-off-by: Joao Martins <joao.m.martins@oracle.com>
Signed-off-by: Jim Fehlig <jfehlig@suse.com>
2015-11-17 14:41:31 -07:00
Andrea Bolognani
2ab52f4af7 hostdev: Rename virHostdevUpdateDomainActiveDevices()
The new name, virHostdevUpdateActiveDomainDevices(), follows the
same naming conventions used by the rest of the module.

No functional changes.
2015-10-26 13:50:35 +01:00
John Ferlan
f84c6dd26d libxl: Resolve Coverity FORWARD_NULL
Since the strtok_r call in libxlCapsInitGuests expects a non NULL first
parameter when the third parameter is NULL, we need to check that
the returned 'capabilities' from a libxl_get_version_info call is
not NULL and error out if so since the code expects it.

Signed-off-by: John Ferlan <jferlan@redhat.com>
2015-10-07 18:34:52 -04:00
Michal Privoznik
c99b8cec82 virDomainCreateXML: Make domain definition transient
https://bugzilla.redhat.com/show_bug.cgi?id=871452

So, you want to create a domain from XML. The domain already
exists in libvirt's database of domains. It's okay, because name
and UUID matches. However, on domain startup, internal
representation of the domain is overwritten with your XML even
though we claim that the XML you've provided is a transient one.
The bug is to be found across nearly all the drivers.
Le sigh.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2015-09-24 10:52:38 +02:00
Peter Krempa
8059a99025 conf: Rename max_balloon to total_memory
The name of the variable was misleading. Rename it and it's setting
accessor before other fixes.
2015-09-22 16:09:28 +02:00
Peter Krempa
5dd61a168f libxl: vz: Use accessor instead of direct access for max_balloon
Commits 45697fe5 and f863ac80 used direct access to the variable instead
of the preferred accessor method.
2015-09-22 16:09:27 +02:00
Chunyan Liu
56945e1374 libxl: fix AttachDeviceConfig on hostdev type
After attach-device a <hostdev> with --config, new device doesn't
show up in dumpxml and in guest.

To fix that, set dev->data.hostdev = NULL after work so that the
pointer is not freed, since vmdef has the pointer and still need it.

Signed-off-by: Chunyan Liu <cyliu@suse.com>
2015-09-17 08:59:13 -06:00
Jim Fehlig
a4604eb086 libxl: fix compiler error introduced by commit ba25c214
libxl/libxl_conf.c: In function 'libxlDriverConfigNew':
libxl/libxl_conf.c:1560:30: error: 'log_level' may be used uninitialized
in this function [-Werror=maybe-uninitialized]
2015-09-15 21:10:59 -06:00
Jim Fehlig
ba25c214f7 libxl: open libxl log stream with libvirtd log_level
Instead of a hardcoded DEBUG log level, use the overall
daemon log level specified in libvirtd.conf when opening
a log stream with libxl. libxl is very verbose when DEBUG
log level is set, resulting in huge log files that can
potentially fill a disk. Control of libxl verbosity should
be placed in the administrator's hands.
2015-09-15 11:19:53 -06:00
Ian Campbell
ee7758f09b libxl: don't end job for ephemeal domain on start failure
commit 4b53d0d4ac "libxl: don't remove persistent domain on start
failure" cleans up the vm object and sets it to NULL if the vm is not
persistent, however at end job vm (now NULL) is dereferenced via the call to
libxlDomainObjEndJob. Avoid this by skipping "endjob" and going
straight to "cleanup" in this case.

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
2015-09-11 10:56:43 +02:00
Jim Fehlig
6ce939c247 libxl: don't overwrite error from virNetSocketNewConnectTCP()
Remove redundant error reporting in libxlDomainMigrationPerform().
virNetSocketNewConnectTCP() is perfectly capable of reporting
sensible errors.
2015-09-03 20:37:28 -06:00
Jonathan Toppins
5c668a78d8 qemu: add udp interface support
Adds a new interface type using UDP sockets, this seems only applicable
to QEMU but have edited tree-wide to support the new interface type.

The interface type required the addition of a "localaddr" (local
address), this then maps into the following xml and qemu call.

<interface type='udp'>
  <mac address='52:54:00:5c:67:56'/>
  <source address='127.0.0.1' port='11112'>
    <local address='127.0.0.1' port='22222'/>
  </source>
  <model type='virtio'/>
  <address type='pci' domain='0x0000' bus='0x00' slot='0x07' function='0x0'/>
</interface>

QEMU call:
	-net socket,udp=127.0.0.1:11112,localaddr=127.0.0.1:22222

Notice the xml "local" entry becomes the "localaddr" for the qemu call.

reference:
http://lists.gnu.org/archive/html/qemu-devel/2011-11/msg00629.html

Signed-off-by: Jonathan Toppins <jtoppins@cumulusnetworks.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
2015-09-02 10:17:50 +02:00
Jim Fehlig
e80b84a743 libxl: acquire a job when receiving a migrating domain
Commit f86ae403 moved acquiring a job from libxlDomainStart()
to its callers. One spot missed was in libxlDoMigrateReceive().
Acquire a job in libxlDoMigrateReceive() before calling
libxlDomainStart().

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
2015-08-27 15:51:31 -06:00
Jim Fehlig
15120b8c61 libxl: don't attempt to resume domain when suspend fails
Failure of libxl_domain_suspend() does not leave the domain in
a suspended state, so no need to call libxl_domain_resume(),
which btw will fail with "domain not suspended".

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
2015-08-27 15:51:31 -06:00
Jim Fehlig
44a54eb073 libxl: fix ref counting of libxlMigrationDstArgs
This patch fixes some flawed logic around ref counting the
libxlMigrationDstArgs object.

First, when adding sockets to the event loop with
virNetSocketAddIOCallback(), the generic virObjectFreeCallback()
was registered as a free function, with libxlMigrationDstArgs as
its parameter. A reference was also taken on
libxlMigrationDstArgs for each successful call to
virNetSocketAddIOCallback(). The rational behind this logic was
that the libxlMigrationDstArgs object had to out-live the socket
objects. But virNetSocketAddIOCallback() already takes a
reference on socket objects, ensuring their life until removed
from the event loop and unref'ed in virNetSocketEventFree(). We
only need to ensure libxlMigrationDstArgs lives until
libxlDoMigrateReceive() finishes, which can be done by simply
unref'ing libxlMigrationDstArgs at the end of
libxlDoMigrateReceive().

The second flaw was unref'ing the sockets in the failure path of
libxlMigrateReceive() and at the end of libxlDoMigrateReceive().
As mentioned above, the sockets are already unref'ed by
virNetSocketEventFree() when removed from the event loop.
Attempting to unref the socket a second time resulted in a
libvirtd crash since the socket was previously unref'ed and
disposed.

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
2015-08-27 15:51:03 -06:00
Martin Kletzander
7c8028cda9 conf: Pass private data to Parse function of XML options
This needs a reorder of XML option definitions.  It might come in handy
one day.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2015-08-13 15:06:06 +02:00
Jim Fehlig
4ffb21c89a libxl: set dom0 state to running
Commit 45697fe5 added dom0 to driver->domains, but missed
setting its state to 'running'

$ virsh list
 Id    Name                           State
----------------------------------------------------
 0     Domain-0                       shut off
2015-07-10 11:36:57 -06:00
Jim Fehlig
e9c2734441 libxl: rework setting the state of virDomainObj
Set the state of virDomainObj in the functions that
actually change the domain state, instead of the generic
libxlDomainCleanup function. This approach gives functions
calling libxlDomainCleanup more flexibility wrt when and
how they change virDomainObj state via virDomainObjSetState.

The prior approach of calling virDomainObjSetState in
libxlDomainCleanup resulted in the following incorrect
coding pattern in the various functions that change
domain state

 libxlDomain<DoStateTransition>
   call libxl function to do state transition
   emit lifecycle event
   libxlDomainCleanup
     virDomainObjSetState

Once simple manifestation of this bug is seeing a domain
running in virt-manager after selecting the shutdown button,
even after the domain has long shutdown.
2015-07-08 15:24:48 -06:00
Jim Fehlig
45697fe545 libxl: support dom0
In Xen, dom0 is really just another domain that supports ballooning,
adding/removing devices, changing vcpu configuration, etc. This patch
adds support to the libxl driver for managing dom0. Note that the
legacy xend driver has long supported managing dom0.

Operations that are not supported on dom0 are filtered in libvirt
where a sensible error is reported. Errors from libxl are not
always helpful. E.g., attempting a save on dom0 results in

2015-06-23 15:25:05 MDT libxl: debug: libxl_dom.c:1570:libxl__toolstack_save: domain=0 toolstack data size=8
2015-06-23 15:25:05 MDT libxl: debug: libxl.c:979:do_libxl_domain_suspend: ao 0x7f7e68000b70: inprogress: poller=0x7f7e68000930, flags=i
2015-06-23 15:25:05 MDT libxl-save-helper: debug: starting save: Success
2015-06-23 15:25:05 MDT xc: detail: xc_domain_save_suse: starting save of domid 0
2015-06-23 15:25:05 MDT xc: error: Couldn't map live_shinfo (3 = No such process): Internal error
2015-06-23 15:25:05 MDT xc: detail: Save exit of domid 0 with errno=3
2015-06-23 15:25:05 MDT libxl-save-helper: debug: complete r=1: No such process
2015-06-23 15:25:05 MDT libxl: error: libxl_dom.c:1876:libxl__xc_domain_save_done: saving domain: domain did not respond to suspend request: No such process
2015-06-23 15:25:05 MDT libxl: error: libxl_dom.c:2033:remus_teardown_done: Remus: failed to teardown device for guest with domid 0, rc -8

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
2015-07-08 15:04:59 -06:00
Jim Fehlig
04597f8f0d libxl: Set def->vcpus after successfully modifying live vcpu count
def->vcpus was never updated after successfully changing the live
vcpu count of a domain. Subsequent queries for vcpu info would
return incorrect results.  E.g.:

virsh vcpucount test
maximum      config         4
maximum      live           4
current      config         4
current      live           4

virsh setvcpus test 2

virsh vcpucount test
maximum      config         4
maximum      live           4
current      config         4
current      live           4

After patch, live current config is reported correctly:

virsh vcpucount test
maximum      config         4
maximum      live           4
current      config         4
current      live           2

While fixing this, noticed that the live config was not saved
to cfg->stateDir via virDomainSaveStatus. Save the live config
and change error handling of virDomainSave{Config,Status} to
log a message via VIR_WARN, instead of failing the entire
DomainSetVcpusFlags operation.

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
2015-06-30 11:02:30 -06:00
Jim Fehlig
33be48d78e libxl: honor domainGetXMLDesc() --inactive flag
The libxl driver always uses virDomainObj->def when formatting
the domain XML description.  Use virDomainObj->newDef when
--inactive flag is set.

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
2015-06-30 11:02:30 -06:00
Jim Fehlig
4b53d0d4ac libxl: don't remove persistent domain on start failure
libxlDomainCreateXML() would remove a persistent domain if
libxlDomainStart() failed.  Check if domain is persistent
before removing.

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
2015-06-30 11:02:30 -06:00
Jim Fehlig
29b154e29a libxl: don't overwrite domain state from statedir config
When restarting libvirtd and reconnecting to running domains,
libxlReconnectDomain() would unconditionally set the domain state
to VIR_DOMAIN_RUNNING, overwriting the state maintained in
$statedir/<domname>.xml.  A domain in a paused state would have
the state changed to running, even though it was actually in a
paused state.

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
2015-06-30 11:02:29 -06:00
Luyao Huang
898e76f0aa Improve some errors for openconsole/channel
Functions like virDomainOpenConsole() and virDomainOpenChannel() accept
NULL as a dev_name parameter.  Try using alias for the error message if
dev_name is not specified.

Before:
  error: internal error: character device <null> is not using a PTY

After:
  error: internal error: character device serial0 is not using a PTY

Signed-off-by: Luyao Huang <lhuang@redhat.com>
2015-06-24 10:11:56 +02:00
Ian Campbell
cc99d240f5 libxl: avoid freeing an uninitialised bitmap
If vm->def->cputune.nvcpupin is 0 in libxlDomainSetVcpuAffinities (as
seems to be the case on arm) then the VIR_FREE after cleanup: would be
operating on an uninitialised pointer in map.map.

Fix this by using libxl_bitmap_init and libxl_bitmap_dispose in the
appropriate places (like VIR_FREE, libxl_bitmap_dispose is also
idempotent, so there is no double free on exit from the loop).

libxl_bitmap_dispose is slightly preferable since it also sets
map.size back to 0, avoiding a potential source of confusion.

This fixes the crashes we've been seeing in the Xen automated tests on
ARM.

I had a glance at the handful of other users of libxl_bitmap and none
of them looked to have a similar issue.

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
2015-06-19 13:10:45 -06:00
Jiri Denemark
3a0f39bcd8 Pass domain object to private data formatter/parser
So that they can format private data (e.g., disk private data) stored
elsewhere in the domain object.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2015-06-19 15:15:10 +02:00
Anthony PERARD
bcf1349bb1 libxl: Add timestamp to the libxl driver log.
Signed-off-by: Anthony PERARD <anthony.perard@citrix.com>
2015-06-12 19:13:59 -06:00
Daniel P. Berrange
d587704cc7 rpc: allow selection of TCP address family
By default, getaddrinfo() will return addresses for both
IPv4 and IPv6 if both protocols are enabled, and so the
RPC code will listen/connect to both protocols too. There
may be cases where it is desirable to restrict this to
just one of the two protocols, so add an 'int family'
parameter to all the TCP related APIs.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2015-06-11 12:11:18 +01:00
Peter Krempa
8db0f438c4 libxl: Don't remove vcpu pin definition in libxlDomainCleanup
The vCPU pinning definition gets removed when the domain definition is
being freed later. If there is no next configuration it would remove the
configured pinning.
2015-06-04 10:52:31 +02:00
Peter Krempa
a02a161bb8 qemu: libxl: vcpupin: Don't reset pinning when pinning to all pcpus
In the pre-NUMA ages pinning a vCPU to all pCPUs was eaqual to deleting
the pinning info. Now it does not entirely work that way. Pinning a vCPU
to all pCPUs might be a desired operation. Additionally removal of the
pinning will result into using the default pinning information at the
next boot which might be different from all vcpus.

This patch removes the false assumption that we should remove the
pinning after pinning to all vCPUs and tweaks the documentation for
virsh.

A later patch will implement a new flag for the virDomainPinVcpuFlags
API that will allow to remove the pinning in a sane way.
2015-06-04 10:52:31 +02:00
Ján Tomko
12b949dfb2 maint: remove incorrect apostrophes from 'its' 2015-06-04 10:01:42 +02:00
Peter Krempa
f35b9b7898 libxl: Refactor libxlDomainGetVcpuPinInfo
Reuse the approach in qemuDomainGetVcpuPinInfo.
2015-06-03 09:42:07 +02:00
Peter Krempa
df55ed4bc0 libxl: Unbreak vcpu pinning
Libxl's vcpu pinning would work only if the vcpu array was ordered and
was not sparse. Remove the condition and iterate the pinning array
properly.
2015-06-03 09:42:07 +02:00
Peter Krempa
4f3f8ca88b libxl: Reuse virBitmapToData in libxlDomainSetVcpuAffinities 2015-06-03 09:42:07 +02:00
Roman Bogorodskiy
f57842ecfd libxl: load on FreeBSD
The libxl tries to check if it's running in dom0 by parsing
/proc/xen/capabilities and if that fails it doesn't load.

There's no procfs interface in Xen on FreeBSD, so this check always
fails.

In addition to checking procfs, check if /dev/xen/xenstored, that's enough to
check if we're running in dom0 in FreeBSD case.
2015-06-01 15:50:25 +03:00
Jim Fehlig
75d650dc5e libxl: support QXL video device
libxl recently gained support for QXL video device.  Support
it in the libxl driver too.

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
2015-05-28 12:40:43 -06:00
Jim Fehlig
6baf881441 libxl: support SPICE graphics for HVM domains
Signed-off-by: Jim Fehlig <jfehlig@suse.com>
2015-05-28 12:40:43 -06:00
Jim Fehlig
5a10fb1d2c libxl: change reservedVNCPorts to reservedGraphicsPorts
A later change will use the PortAllocator for SPICE too.

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
2015-05-28 12:40:43 -06:00
Jim Fehlig
09f2faf933 libxl: populate build_info vfb in separate function
For HVM domains, vfb info must be populated in the libxl_domain_build_info
struct.  Currently this is done in the libxlMakeVfbList function, but IMO
it would be cleaner to populate the build_info vfb in a separate
libxlMakeBuildInfoVfb function.  libxlMakeVfbList would then handle only
vfb devices, simiar to the other libxlMake<device>List functions.

A future patch will extend libxlMakeBuildInfoVfb to support SPICE.

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
2015-05-28 12:40:43 -06:00
Jiri Denemark
82cffb58a1 Use virDomainDiskByName where appropriate
Most virDomainDiskIndexByName callers do not care about the index; what
they really want is a disk def pointer.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2015-05-21 14:35:02 +02:00
Laine Stump
ffc40b63b5 conf: make virNodeDevCapData an official type
For some reason a union (_virNodeDevCapData) that had only been
declared inside the toplevel struct virNodeDevCapsDef was being used
as an argument to functions all over the place. Since it was only a
union, the "type" attribute wasn't necessarily sent with it. While
this works, it just seems wrong.

This patch creates a toplevel typedef for virNodeDevCapData and
virNodeDevCapDataPtr, making it a struct that has the type attribute
as a member, along with an anonymous union of everything that used to
be in union _virNodeDevCapData. This way we only have to change the
following:

  s/union _virNodeDevCapData */virNodeDevCapDataPtr /

and

  s/caps->type/caps->data.type/

This will make me feel less guilty when adding functions that need a
pointer to one of these.
2015-05-18 10:22:20 -04:00
Jim Fehlig
99a42f3c0f libxl: provide impl for nodeGetSecurityModel
Currently, the libxl driver does not support any security drivers.
When the qemu driver has no security driver configued,
nodeGetSecurityModel succeeds but returns an empty virSecurityModel
object.  Do the same in the libxl driver instead of reporting

this function is not supported by the connection driver:
virNodeGetSecurityModel
2015-05-15 14:07:01 -06:00
Jim Fehlig
fa33c0b8af libxl: support VNC passwd
While implementing support for SPICE, I noticed VNC passwd was
never copied to libxl_device_vfb's vnc.passwd field.

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
2015-05-12 15:32:04 -06:00
John Ferlan
11b9167954 libxl: Resolve Coverity RESOURCE_LEAK
The returned socks from virNetSocketNewListenTCP needs to be VIR_FREE'd
as well as seach of the Close/Unref on all the socks[i] that is
already done
2015-05-05 20:02:36 -04:00
Jim Fehlig
c0d3f608d6 libxl: support soundhw for hvm domains
The xend driver and the parsing/formating code in src/xenconfig
have long supported soundhw.  Add support in the libxl driver too.
2015-05-05 09:19:37 -06:00
Jim Fehlig
198cc1d339 libxl: provide integration with lock manager
Provide integration with libvirt's lock manager in the libxl driver.

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
2015-04-29 10:51:36 -06:00
Olaf Hering
bb5fc7214e libxl: remove duplicate check for pci subsystem type
Both attach and detach functions get called only if the type matches.

Signed-off-by: Olaf Hering <olaf@aepfle.de>
Cc: Jim Fehlig <jfehlig@suse.com>
2015-04-24 15:22:20 -06:00
Olaf Hering
f54391b447 libxl: use pci init and dispose functions
Rearrange code so that the local variable is always initialized and
disposed.

Signed-off-by: Olaf Hering <olaf@aepfle.de>
Cc: Jim Fehlig <jfehlig@suse.com>
2015-04-24 15:02:08 -06:00
Jim Fehlig
247b2c5388 libxl: initialize sdl.opengl defbool in libxlMakeVfb
Commit bf32462b missed initializing sdl.opengl.  Without the
initialization, libvirtd will be terminated by an assert from libxl:

Assertion `!libxl_defbool_is_default(db)' failed.

Reported-by: Olaf Hering <olaf@aepfle.de>
2015-04-24 14:11:26 -06:00
Olaf Hering
bf32462bd3 libxl: initialize vfb defbools in libxlMakeVfb
If the domU configu has sdl enabled libvirtd crashes:
libvirtd[5158]: libvirtd: libxl.c:343: libxl_defbool_val:
Assertion `!libxl_defbool_is_default(db)' failed.

Initialize the relevant defbool variables in libxl_device_vfb.

Signed-off-by: Olaf Hering <olaf@aepfle.de>
Cc: Jim Fehlig <jfehlig@suse.com>
2015-04-24 13:17:36 -06:00
Michal Privoznik
620ff93bd3 virDomainObjListFindByName: Return referenced object
Every domain that grabs a domain object to work over should
reference it to make sure it won't disappear meanwhile.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2015-04-24 13:22:45 +02:00
Jim Fehlig
d0baac09e6 libxl: Introduce configuration file for libxl driver
Introduce libxl.conf configuration file, adding the 'autoballoon'
setting as the first knob for controlling the libxl driver.

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
2015-04-21 14:23:40 -06:00
Cole Robinson
835cf84b7e domain: conf: Drop expectedVirtTypes
This needs to specified in way too many places for a simple validation
check. The ostype/arch/virttype validation checks later in
DomainDefParseXML should catch most of the cases that this was covering.
2015-04-20 16:43:43 -04:00
Cole Robinson
4fa6f9b413 caps: Convert to use VIR_DOMAIN_VIRT internally 2015-04-20 16:40:26 -04:00
Cole Robinson
5f7c599456 domain: Convert os.type to VIR_DOMAIN_OSTYPE enum 2015-04-20 16:40:09 -04:00
Cole Robinson
d0440e3269 caps: Switch AddGuest to take VIR_DOMAIN_OSTYPE value
Rather than an opencoded string. This should be a no-op
2015-04-20 16:38:09 -04:00
Jim Fehlig
6dfec1efba libxl: drop virDomainObj lock when destroying a domain
A destroy operation can take considerable time on large memory
domains due to scrubbing the domain's memory.  Unlock the
virDomainObj while libxl_domain_destroy is executing.

Implement libxlDomainDestroyInternal wrapper to handle unlocking,
calling destroy, and locking.  Change all callers of
libxl_domain_destroy to use the wrapper.

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
2015-04-16 16:43:19 -06:00
Jim Fehlig
894d2ff759 libxl: acquire a job when destroying a domain
A job should be acquired at the beginning of a domain destroy operation,
not at the end when cleaning up the domain.  Fix two occurrences of this
late job acquisition in the libxl driver.  Doing so renders
libxlDomainCleanupJob unused, so it is removed.

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
2015-04-16 16:43:18 -06:00
Jim Fehlig
f86ae40324 libxl: Move job acquisition in libxlDomainStart to callers
Let callers of libxlDomainStart decide when it is appropriate to
acquire a job on the associated virDomainObj.

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
2015-04-16 16:42:53 -06:00
Jim Fehlig
13e2c22099 libxl: support HVM direct kernel boot
Add support for HVM direct kernel boot in libxl.  Also add a
test to verify domXML <-> native conversions.

Signed-off-by: Chunyan Liu <cyliu@suse.com>
Signed-off-by: Jim Fehlig <jfehlig@suse.com>
2015-04-16 16:14:51 -06:00
Jim Fehlig
d685c0f91b libxl: fix dom0 balloon logic
Recent testing on large memory systems revealed a bug in the Xen xl
tool's freemem() function.  When autoballooning is enabled, freemem()
is used to ensure enough memory is available to start a domain,
ballooning dom0 if necessary.  When ballooning large amounts of memory
from dom0, freemem() would exceed its self-imposed wait time and
return an error.  Meanwhile, dom0 continued to balloon.  Starting the
domain later, after sufficient memory was ballooned from dom0, would
succeed.  The libvirt implementation in libxlDomainFreeMem() suffers
the same bug since it is modeled after freemem().

In the end, the best place to fix the bug on the Xen side was to
slightly change the behavior of libxl_wait_for_memory_target().
Instead of failing after caller-provided wait_sec, the function now
blocks as long as dom0 memory ballooning is progressing.  It will return
failure only when more memory is needed to reach the target and wait_sec
have expired with no progress being made.  See xen.git commit fd3aa246.
There was a dicussion on how this would affect other libxl apps like
libvirt

http://lists.xen.org/archives/html/xen-devel/2015-03/msg00739.html

If libvirt containing this patch was build against a Xen containing
the old libxl_wait_for_memory_target() behavior, libxlDomainFreeMem()
will fail after 30 sec and domain creation will be terminated.
Without this patch and with old libxl_wait_for_memory_target() behavior,
libxlDomainFreeMem() does not succeed after 30 sec, but returns success
anyway.  Domain creation continues resulting in all sorts of fun stuff
like cpu soft lockups in the guest OS.  It was decided to properly fix
libxl_wait_for_memory_target(), and if anything improve the default
behavior of apps using the freemem reference impl in xl.

xl was patched to accommodate the change in libxl_wait_for_memory_target()
with xen.git commit 883b30a0.  This patch does the same in the libxl
driver.  While at it, I changed the logic to essentially match
freemem() in $xensrc/tools/libxl/xl_cmdimpl.c.  It was a bit cleaner
IMO and will make it easier to spot future, potentially interesting
divergences.
2015-04-02 09:41:03 -06:00
Konrad Rzeszutek Wilk
95003cd511 libxl: Fix memory leak if pthread_create fails.
If we fail to create the thread we leak the shutdown_info
structure.

Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
2015-03-26 14:22:36 -06:00
Jim Fehlig
a5bf06ba34 libxl: remove per-domain libxl_ctx
Although needed in the Xen 4.1 libxl days, there is no longer any
benefit to having per-domain libxl_ctx.  On the contrary, their use
makes the code unecessarily complicated and prone to deadlocks under
load.  As suggested by the libxl maintainers, use a single libxl_ctx
as a handle to libxl instead of per-domain ctx's.

One downside to using a single libxl_ctx is there are no longer
per-domain log files for log messages emitted by libxl.  Messages
for all domains will be sent to /var/log/libvirt/libxl/libxl-driver.log.

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
2015-03-24 15:03:55 -06:00
Jim Fehlig
6728645a41 libxl: make libxlDomainFreeMem static
libxlDomainFreeMem() is only used in libxl_domain.c and thus should
be declared static.  While at it, change the signature to take a
libxl_ctx instead of libxlDomainObjPrivatePtr, since only the
libxl_ctx is needed.

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
2015-03-24 15:03:54 -06:00
Jim Fehlig
1cca1d25a0 libxl: remove unnecessary libxlDomainEventsRegister
This function now only enables domain death events.  Simply call
libxl_evenable_domain_death() instead of an unnecessary wrapper.

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
2015-03-24 15:03:54 -06:00
Jim Fehlig
0b0a3d63bb libxl: use global libxl_ctx in event handler
Change the domain event handler code to use the driver-wide
libxl_ctx instead of the domain-specific one.

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
2015-03-24 15:03:54 -06:00
Jim Fehlig
109cf8d89c libxl: move event registration to driver initialization
Register a domain event handler with the driver-wide libxl_ctx
during driver initialization.

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
2015-03-24 15:03:54 -06:00
Jim Fehlig
331a02a701 libxl: Move setup of child processing code to driver initialization
Informing libxl how to handle its child proceses should be done once
during driver initialization, not once for each domain-specific
libxl_ctx object.  The related libxl documentation in
$xen-src/tools/libxl/libxl_event.h even mentions that "it is best to
call this at initialisation".

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
2015-03-24 15:03:54 -06:00
Jim Fehlig
57db83ae3b libxl: use driver-wide ctx in fd and timer event handling
Long ago I incorrectly associated libxl fd and timer registrations
with per-domain libxl_ctx objects.  When creating a libxlDomainObjPrivate,
a libxl_ctx is allocated, and libxl_osevent_register_hooks is called
passing a pointer to the libxlDomainObjPrivate.  When an fd or timer
registration occurred, the registration callback received the
libxlDomainObjPrivate, containing the per-domain libxl_ctx.  This
libxl_ctx was then used when informing libxl about fd events or
timer expirations.

The problem with this approach is that fd and timer registrations do not
share the same lifespan as libxlDomainObjPrivate, and hence the per-domain
libxl_ctx ojects.  The result is races between per-domain libxl_ctx's being
destoryed and events firing on associated fds/timers, typically manifesting
as an assert in libxl

libxl_internal.h:2788: libxl__ctx_unlock: Assertion `!r' failed

There is no need to associate libxlDomainObjPrivate objects with libxl's
desire to use libvirt's event loop.  Instead, the driver-wide libxl_ctx can
be used for the fd and timer registrations.

This patch moves the fd and timer handling code away from the
domain-specific code in libxl_domain.c into libxl_driver.c.  While at it,
function names were changed a bit to better describe their purpose.

The unnecessary locking was also removed since the code simply provides a
wrapper over the event loop interface.  Indeed the locks may have been
causing some deadlocks when repeatedly creating/destroying muliple domains.
There have also been rumors about such deadlocks during parallel OpenStack
Tempest runs.

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
2015-03-24 15:03:54 -06:00
Peter Krempa
3e4230d270 conf: Add interface to parse and format memory device information
This patch adds code that parses and formats configuration for memory
devices.

A simple configuration would be:
<memory model='dimm'>
  <target>
    <size unit='KiB'>524287</size>
    <node>0</node>
  </target>
</memory>

A complete configuration of a memory device:
<memory model='dimm'>
  <source>
    <pagesize unit='KiB'>4096</pagesize>
    <nodemask>1-3</nodemask>
  </source>
  <target>
    <size unit='KiB'>524287</size>
    <node>1</node>
  </target>
</memory>

This patch preemptively forbids use of the <memory> device in individual
drivers so the users are warned right away that the device is not
supported.
2015-03-23 14:25:15 +01:00
Peter Krempa
bffb9163a1 conf: Add support for parsing and formatting max memory and slot count
Add a XML element that will allow to specify maximum supportable memory
and the count of memory slots to use with memory hotplug.

To avoid possible confusion and misuse of the new element this patch
also explicitly forbids the use of the maxMemory setting in individual
drivers's post parse callbacks. This limitation will be lifted when the
support is implemented.
2015-03-23 14:25:14 +01:00
Peter Krempa
19e85d8454 libxl: Refactor logic in domain post parse callback
With the current control flow the post parse callback returned success
right away for fully virtualized VMs. To allow adding additional checks
into the post parse callback tweak the conditions so that the function
doesn't return early except for error cases.

To clarify the original piece of code borrow the wording from the commit
message for the patch that introduced the code.
2015-03-23 14:25:14 +01:00
Jim Fehlig
2adba7d3ab libxl: use xenlight pkgconfig file if present
xen.git commit babeca32 added a pkgconfig file for libxenlight,
allowing libxl apps to determine the location of Xen binaries
such as firmware blobs, device emulator, etc.

This patch adds support for xenlight.pc in the libxl driver, falling
back to the previous configure logic if not found.  It introduces
LIBXL_FIRMWARE_DIR and LIBXL_EXECBIN_DIR to define the firmware and
libexec_bin locations.  If xenlight.pc does not exist, the defines
are set to the current hardcoded paths.  The capabilities'
<emulator> and <loader> elements are updated to use the paths.

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
2015-03-19 16:13:26 -06:00
Jim Fehlig
bd235cd873 libxl: Don't overwrite errors from xenconfig
When converting domXML from native, the libxl driver was overwriting
useful errors from the xenconfig parsing code with a useless, generic
error.  E.g. "internal error: parsing xm config failed" vs
"internal error: config value usbdevice was malformed".  Remove the
redundant (and useless) error reporting in the libxl driver.

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
2015-03-18 20:55:33 -06:00
Jim Fehlig
a7d6b94a00 libxl: fix regression introduced by commit 4ab8cd77
Commit 4ab8cd77 added a check requiring input devices to have
a bus type of VIR_DOMAIN_INPUT_BUS_USB, failing to start the
domain otherwise.  But virDomainDefParseXML adds implicit mouse
and keyboard if a graphics device is configured.  See calls to
virDomainDefMaybeAddInput.

The regression is fixed by removing the check requiring USB input
devices, and skipping non-USB input devices when populating USB
'usbdevice' in libxl_domain_build_info struct.
2015-03-16 11:49:58 -06:00
John Ferlan
4985dde0f5 Replace virDomainVcpuPinDel with virDomainPinDel
Since both Vcpu and IOThreads code use the same API's, alter the naming
of the API's to remove the "Vcpu" specific reference
2015-03-16 11:54:57 -04:00
John Ferlan
cacf27f212 Replace virDomainVcpuPinAdd with virDomainPinAdd
Since both Vcpu and IOThreads code use the same API's, alter the naming
of the API's to remove the "Vcpu" specific reference
2015-03-16 11:54:57 -04:00
John Ferlan
a9f528ab29 Convert virDomainPinDefPtr->vcpuid to virDomainPinDefPtr->id
Since we're not specifically a vcpu related structure anymore...
2015-03-16 11:54:57 -04:00
John Ferlan
59ba70237a Convert virDomainVcpuPinDefPtr to virDomainPinDefPtr
As pointed out by jtomko in his review of the IOThreads pinning code:

http://www.redhat.com/archives/libvir-list/2015-March/msg00495.html

there are some comments sprinkled in indicating IOThreads were using
the same structure as the VcpuPin code...

This is the first patch of a few that will change the virDomainVcpuPin*
structures and code to just virDomainPin* - starting with the data
structure naming...
2015-03-16 11:54:56 -04:00
Peter Krempa
4f9907cd11 conf: Replace access to def->mem.max_balloon with accessor functions
As there are two possible approaches to define a domain's memory size -
one used with legacy, non-NUMA VMs configured in the <memory> element
and per-node based approach on NUMA machines - the user needs to make
sure that both are specified correctly in the NUMA case.

To avoid this burden on the user I'd like to replace the NUMA case with
automatic totaling of the memory size. To achieve this I need to replace
direct access to the virDomainMemtune's 'max_balloon' field with
two separate getters depending on the desired size.

The two sizes are needed as:
1) Startup memory size doesn't include memory modules in some
hypervisors.
2) After startup these count as the usable memory size.

Note that the comments for the functions are future aware and document
state that will be present after a few later patches.
2015-03-16 14:26:51 +01:00
Marek Marczykowski-Górecki
1a01a2aa57 libxl: prevent attaching multiple netdevs with the same MAC
It will not be possible to detach such device later. Also improve
logging in such cases.

Signed-off-by: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
2015-03-13 12:00:50 -06:00
Marek Marczykowski
4ab8cd77ad libxl: add tablet/mouse input device support
Signed-off-by: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
2015-03-13 12:00:49 -06:00
Ján Tomko
22fd3ac38f Introduce virBitmapIsBitSet
A helper that never returns an error and treats bits out of bitmap range
as false.

Use it everywhere we use ignore_value on virBitmapGetBit, or loop over
the bitmap size.
2015-03-13 15:31:33 +01:00
Jim Fehlig
3b7f589571 libxl: remove unneeded cleanup_unlock label
In the old days of a global driver lock, it was necessary to unlock
the driver after a domain restore operation.  When the global lock
was removed from the driver, some remnants were left behind in
libxlDomainRestoreFlags.  Remove this unneeded (and incorrect) code.

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
2015-03-05 09:05:35 -07:00
Jim Fehlig
b1d159d889 libxl: use libxl_ctx passed to libxlConsoleCallback
Instead of using the libxl_ctx in the libxlDomainObjPrivatePtr,
use the ctx passed to the callback.

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
2015-03-05 09:05:34 -07:00
Jim Fehlig
fc3ef44ea4 libxl: remove redundant calls to libxl_evdisable_domain_death
Domain death watch is already disabled in libxlDomainCleanup.  No
need to disable it a second and third time.

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
2015-03-05 09:05:34 -07:00
Marek Marczykowski
d0106d5828 libxl: support backend domain setting for disk and net devices
This implement handling of <backenddomain name=''/>  parameter introduced
in previous patch.

Works on Xen >= 4.3, because only there libxl supports setting backend
domain by name.  Specifying backend domain by ID or UUID is currently not
supported.

Signed-off-by: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
2015-02-20 14:50:24 -07:00
John Ferlan
4438646c0d libxl: Resolve Coverity CHECKED_RETURN
Periodically my Coverity scan will return a checked_return failure
for libxlDomainShutdownThread call to libxlDomainStart. Followed the
libxlAutostartDomain example in order to check the status, emit a
message, and continue on.
2015-02-14 07:31:41 -05:00
Marek Marczykowski-Górecki
98780c6be6 libxl: disable VNC and SDL until explicitly enabled
When initializing a libxl_domain_build_info struct with
libxl_domain_build_info_init(), VNC is enabled by default.  As a
result, VMs configured with no graphics still have VNC enabled.
This behavior is a regression wrt to the legacy Xen driver.

Signed-off-by: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
2015-02-11 20:24:20 -07:00
Marek Marczykowski-Górecki
8703ee58bd libxl: pass ipaddr to libxl toolstack
Do not silently ignore its value. LibXL support only one address, so
refuse multiple IPs.

Signed-off-by: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
2015-02-11 16:46:36 -07:00
Marek Marczykowski-Górecki
490be8c724 libxl: update dom->id in libxlDomainCreateWithFlags
Otherwise domainCreateWithFlags via remote returns -1 as domid.

Signed-off-by: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
2015-02-05 13:58:47 -07:00
Daniel P. Berrange
55ea7be7d9 Removing probing of secondary drivers
For stateless, client side drivers, it is never correct to
probe for secondary drivers. It is only ever appropriate to
use the secondary driver that is associated with the
hypervisor in question. As a result the ESX & HyperV drivers
have both been forced to do hacks where they register no-op
drivers for the ones they don't implement.

For stateful, server side drivers, we always just want to
use the same built-in shared driver. The exception is
virtualbox which is really a stateless driver and so wants
to use its own server side secondary drivers. To deal with
this virtualbox has to be built as 3 separate loadable
modules to allow registration to work in the right order.

This can all be simplified by introducing a new struct
recording the precise set of secondary drivers each
hypervisor driver wants

struct _virConnectDriver {
    virHypervisorDriverPtr hypervisorDriver;
    virInterfaceDriverPtr interfaceDriver;
    virNetworkDriverPtr networkDriver;
    virNodeDeviceDriverPtr nodeDeviceDriver;
    virNWFilterDriverPtr nwfilterDriver;
    virSecretDriverPtr secretDriver;
    virStorageDriverPtr storageDriver;
};

Instead of registering the hypervisor driver, we now
just register a virConnectDriver instead. This allows
us to remove all probing of secondary drivers. Once we
have chosen the primary driver, we immediately know the
correct secondary drivers to use.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2015-01-27 12:02:04 +00:00
Anthony PERARD
368042cf4a libxl: Set path to console on domain startup.
The path to the pty of a Xen PV console is set only in
virDomainOpenConsole. But this is done too late. A call to
virDomainGetXMLDesc done before OpenConsole will not have the path to
the pty, but a call after OpenConsole will.

e.g. of the current issue.
Starting a domain with '<console type="pty"/>'
Then:
virDomainGetXMLDesc():
  <devices>
    <console type='pty'>
      <target type='xen' port='0'/>
    </console>
  </devices>
virDomainOpenConsole()
virDomainGetXMLDesc():
  <devices>
    <console type='pty' tty='/dev/pts/30'>
      <source path='/dev/pts/30'/>
      <target type='xen' port='0'/>
    </console>
  </devices>

The patch intend to have the TTY path on the first call of GetXMLDesc.
This is done by setting up the path at domain start up instead of in
OpenConsole.

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

Signed-off-by: Anthony PERARD <anthony.perard@citrix.com>
2015-01-16 15:57:10 -07:00
Daniel P. Berrange
dd69a14f90 Add support for schema validation when passing in XML
The virDomainDefineXMLFlags and virDomainCreateXML APIs both
gain new flags allowing them to be told to validate XML.
This updates all the drivers to turn on validation in the
XML parser when the flags are set
2015-01-15 16:40:27 +00:00
Kiarie Kahurani
cec71a6ba6 libxl: Add support for parsing/formating Xen XL config
Now that xenconfig supports parsing and formatting Xen's
XL config format, integrate it into the libxl driver's
connectDomainXML{From,To}Native functions.

Signed-off-by: Kiarie Kahurani <davidkiarie4@gmail.com>
Signed-off-by: Jim Fehlig <jfehlig@suse.com>
2015-01-14 08:28:51 -07:00
Daniel P. Berrange
0ecd685109 Give virDomainDef parser & formatter their own flags
The virDomainDefParse* and virDomainDefFormat* methods both
accept the VIR_DOMAIN_XML_* flags defined in the public API,
along with a set of other VIR_DOMAIN_XML_INTERNAL_* flags
defined in domain_conf.c.

This is seriously confusing & error prone for a number of
reasons:

 - VIR_DOMAIN_XML_SECURE, VIR_DOMAIN_XML_MIGRATABLE and
   VIR_DOMAIN_XML_UPDATE_CPU are only relevant for the
   formatting operation
 - Some of the VIR_DOMAIN_XML_INTERNAL_* flags only apply
   to parse or to format, but not both.

This patch cleanly separates out the flags. There are two
distint VIR_DOMAIN_DEF_PARSE_* and VIR_DOMAIN_DEF_FORMAT_*
flags that are used by the corresponding methods. The
VIR_DOMAIN_XML_* flags received via public API calls must
be converted to the VIR_DOMAIN_DEF_FORMAT_* flags where
needed.

The various calls to virDomainDefParse which hardcoded the
use of the VIR_DOMAIN_XML_INACTIVE flag change to use the
VIR_DOMAIN_DEF_PARSE_INACTIVE flag.
2015-01-13 16:26:12 +00:00
Daniel P. Berrange
4d2ebc71ce Add stub virDomainDefineXMLFlags impls
Make sure every virt driver implements virDomainDefineXMLFlags
by adding a trivial passthrough from the existing impl with
no flags set.
2015-01-13 10:38:56 +00:00
Jim Fehlig
4d77c136f8 Revert "libxl: Add support for parsing/formating Xen XL config"
This reverts commit 4f524212ce.

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
2015-01-12 10:15:04 -07:00
Kiarie Kahurani
4f524212ce libxl: Add support for parsing/formating Xen XL config
Now that xenconfig supports parsing and formatting Xen's
XL config format, integrate it into the libxl driver's
connectDomainXML{From,To}Native functions.

Signed-off-by: Kiarie Kahurani <davidkiarie4@gmail.com>
Signed-off-by: Jim Fehlig <jfehlig@suse.com>
2015-01-03 22:41:26 -07:00
John Ferlan
121c09a90b Replace virNetworkFree with virObjectUnref
Since virNetworkFree will call virObjectUnref anyway, let's just use that
directly so as to avoid the possibility that we inadvertently clear out
a pending error message when using the public API.
2014-12-02 11:03:40 -05:00
John Ferlan
5f1d3c6c87 libxl: Resolve Coverity CHECKED_RETURN
Commit id 'cb88d433' refactored the calling sequence to use a thread;
however, in doing so "lost" the check for if virNetSocketAccept returns
failure.  Since other code makes that check, Coverity complains. Although
a false positive, adding back the failure check pacifies Coverity
2014-12-01 11:21:32 -05:00