Commit Graph

21861 Commits

Author SHA1 Message Date
Pavel Hrdina
68b726b93c admin_server: fix memory leak
If caller of adminConnectListServers() pass NULL instead of servers we
need to free the list we've received from virNetDaemonGetServers().

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2016-03-24 14:03:18 +01:00
Michal Privoznik
9b48ef9c51 gendispatch: Avoid comparing signed and unsigned vars
The adminDispatchConnectListServers() function is generated by
our great perl script. However, it has a tiny flaw: if
adminConnectListServers() it calls fails, the control jumps onto
cleanup label where we try to free any list of servers built so
far. However, in the loop @i is unsigned (size_t) while @nresults
is signed (int). Currently, it does no harm because of the check
for @result being non-NULL. But if that ever changes in the
future, this bug will be hard to chase.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2016-03-24 10:49:39 +01:00
Michal Privoznik
cbe289d814 event-test: Check for virConnectRegisterCloseCallback return value
In an unlikely event of virConnectRegisterCloseCallback failing,
the error is ignored. This is an example file and we shouldn't
get a bad example.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2016-03-24 10:49:39 +01:00
Michal Privoznik
bde75a895d event-test: Use goto cleanup instead of if else jungle
Like in the rest of our code we tend to prefer 'goto' and
'cleanup' over 'if else' code structure. Do the same here.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2016-03-24 10:49:39 +01:00
Michal Privoznik
950a90d489 qemuxml2argvtest: Adapt to ethernet automatic tap creation
After 9c17d665fd the tap device for ethernet network type is
automatically precreated before spawning qemu. Problem is, the
qemuxml2argvtest wasn't updated and thus is failing. Because of
all the APIs that new code is calling, I had to mock a lot. Also,
since the tap FDs are labeled separately from the rest of the
devices/files I had to enable NOP security driver for the test
too.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2016-03-24 07:38:46 +01:00
Cole Robinson
360229e8b4 remote: Fix error message
We were printing the wrong MAX value
2016-03-23 16:52:12 -04:00
Michal Privoznik
4b527c1acf qemuxml2argv: Mock virSCSIDeviceGetSgName
When constructing SCSI hostdev command line for qemu, the
/sys/bus/scsi/devices/... dir is scanned. Unfortunately, even in
the tests. This is needed to determine the name of SCSI device to
passthrough to qemu, because in the domain XML we were given its
address instead. Anyway, we should not be touching live system
data in our test suite as it produced unpredictable results. The
test is regressing from 1e9a083742 on.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2016-03-23 12:50:19 +01:00
Vasiliy Tolstov
9c17d665fd autocreate tap device for ethernet network type
If a user specify network type ethernet, then create it via libvirt and run
script if it provided. After this commit user does not need to
run external script to create tap device or add root permissions to qemu
process.

Signed-off-by: Vasiliy Tolstov <v.tolstov@selfip.ru>
2016-03-23 11:37:59 +00:00
Andrea Bolognani
ee07c9802b tests: hostdev: Add more tests
Ensure the code behaves properly even for situations that were not
being considered before, such as simply detaching devices from the
host without attaching them to a guest and attaching devices as
managed even though they had already been manually detached from
the host.
2016-03-23 11:38:20 +01:00
Andrea Bolognani
ee4cfb5643 hostdev: Use actual device when reattaching
Instead of forcing the values for the unbind_from_stub, remove_slot
and reprobe properties, look up the actual device and use that when
calling virPCIDeviceReattach().

This ensures the device is restored to its original state after
reattach: for example, if it was not bound to any driver before
detach, it will not be bound forcefully during reattach.
2016-03-23 11:38:20 +01:00
Andrea Bolognani
c3e2f6e37d hostdev: Save netdev configuration of actual device
We would be just fine looking up the information in pcidevs most
of the time; however, some corner cases would not be handled
properly, so look up the actual device instead.
2016-03-23 11:38:20 +01:00
Andrea Bolognani
811286090f hostdev: Streamline device ownership tracking
After this patch, ownership of virPCIDevice instances is very easy
to keep track of: for each host PCI device, the only instance that
actually matters is the one inside one of the bookkeeping list.

Whenever some operation needs to be performed on a PCI device, the
actual device is looked up first; when this is not the case, a
comment explains the reason.
2016-03-23 11:38:14 +01:00
Andrea Bolognani
6da6bf2f30 hostdev: Stop early if unmanaged devices have not been detached
Unmanaged devices, as the name suggests, are not detached
automatically from the host by libvirt before being attached to a
guest: it's the user's responsability to detach them manually
beforehand. If that preliminary step has not been performed, the
attach operation can't complete successfully.

Instead of relying on the lower layers to error out with cryptic
messages such as

  error: Failed to attach device from /tmp/hostdev.xml
  error: Path '/dev/vfio/12' is not accessible: No such file or directory

prevent the situation altogether and provide the user with a more
useful error message.
2016-03-23 10:58:18 +01:00
Andrea Bolognani
df490e7c9b hostdev: Detect untracked inactive devices
Unmanaged devices are attached to guests in two steps: first,
the device is detached from the host and marked as inactive;
subsequently, it is marked as active and attached to the guest.

If the daemon is restarted between these two operations, we lose
track of the inactive device.

Steps 5 and 6 of virHostdevPreparePCIDevices() already subtly
take care of this situation, but some planned changes will make
it so that's no longer the case. Plus, explicit is always better
than implicit.
2016-03-23 10:58:11 +01:00
Pavel Hrdina
1e9a083742 qemuxml2argvtest: cleanup test
Use qemuProcessCreatePretendCmd instead duplicating required steps from
qemuProcessStart.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2016-03-22 15:15:49 +01:00
Pavel Hrdina
9dca74ee6f qemuxml2argvtest: use driver.config and priv for qemuDomainSetPrivatePaths
Update testutilsqemu to overwrite libDir and channelTargetDir and set
private paths using domain's privateData.  This changes is required for
following patch.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2016-03-22 15:15:48 +01:00
Pavel Hrdina
12de369aa6 qemu_driver: cleanup qemuConnectDomainXMLToNative
Use qemuProcessCreatePretendCmd instead duplicating required steps from
qemuProcessStart.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2016-03-22 15:15:48 +01:00
Pavel Hrdina
758cca88b2 qemu_process: introduce qemuProcessCreatePretendCmd
This will skip few steps from qemuProcessStart in order to create only
qemu CMD.  Use a VIR_QEMU_PROCESS_START_PRETEND for all the qemuProcess*
functions called by this one to not modify or check host.

This new function will be used later on for XMLToNative API and also for
qemuxml2argvtest to make sure that both API and test uses the same code
as qemuProcessStart.

We need also update qemuProcessInit to wrap few lines of code with check
that VIR_QEMU_PROCESS_START_PRETEND that makes sense only for
qemuProcessStart.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2016-03-22 15:15:48 +01:00
Pavel Hrdina
6e8266ade5 qemu_process: move qemuDomainSetPrivatePaths to qemuProcessInit
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2016-03-22 15:15:48 +01:00
Pavel Hrdina
1e38ef728c qemu_process: move checks to qemuProcessStartValidate
Move all code that checks host and domain.  Do not check host if we use
VIR_QEMU_PROCESS_START_PRETEND flag.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2016-03-22 15:15:48 +01:00
Pavel Hrdina
a431d3440f qemu: update callers of qemuProcessStartValidate to use virDomainObjPtr
This change is required by following patches.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2016-03-22 15:15:48 +01:00
Pavel Hrdina
ddc0e6bcdc qemu_process: introduce qemuProcessPrepareHost
Move all code that modifies host system to this function.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2016-03-22 15:15:48 +01:00
Pavel Hrdina
f8e712feb4 qemu_process: introduce qemuProcessPrepareDomain
Move all code that modifies only live XML to this function.  The new
VIR_QEMU_PROCESS_START_PRETEND flag will be used by qemuXMLToNative and
qemuxml2argvtest later in order to reuse the same code as
qemuProcessStart uses.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2016-03-22 15:15:48 +01:00
Pavel Hrdina
c374851960 tests: cleanup qemuxml2argvtest
This removes the testFailed magic and makes the code more readable.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2016-03-22 15:15:48 +01:00
Pavel Hrdina
15ad2ecf11 nvram: generate it's path in qemuDomainDefPostParse
The postParse callback is the correct place to generate default values
that should be present in offline XML.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2016-03-22 15:15:38 +01:00
Pavel Hrdina
5b9e77883b qemu_process: check for correct return value while starting domain
Function qemuProcessLaunch returns '-2' in case there was an error and
we need to cleanup labels.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2016-03-22 13:59:13 +01:00
Pavel Hrdina
0f4d317204 qemu-hotplug: fix eject media
QEMU changed the error message to:

        "Tray of device 'drive-sata0-0-1' is not open"

and they may change the error massage in the future.

This updates the code to not depend on the text from the error message
but only on error itself.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2016-03-22 13:26:46 +01:00
Martin Kletzander
dc56475f72 nss: Make aligning look nicer
Every aligning requires at least one cast and it's hard to read.  Let's
make a function that makes sure the pointer is moved according to the
alignment and use that to move throughout the data buffer.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2016-03-21 20:55:00 +01:00
Michal Privoznik
a8dc3ac28a tests: Produce predictable results in nsstest
Problem is that in the test any status file matching
tests/nssdata/*.status is loaded as it contains IP addresses that
are parsed. However, there's no order specified in which the
files are loaded. Therefore on different systems the order may be
different. This is then producing an unexpected results.
Instead of defining an order in which the files are loaded, make
the code that checks for missing IP addresses (or redundant ones)
cope with unordered list of addresses. The reasoning behind is
that the code doing the parsing is used in real NSS module where
we don't care for ordering.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2016-03-21 19:34:18 +01:00
Bjoern Walk
1de354ccc5 tests: nodedevxml2xml: add test for SCSI target
Let's add a test for SCSI target nodedev devices.

Signed-off-by: Bjoern Walk <bwalk@linux.vnet.ibm.com>
2016-03-21 12:06:49 -04:00
Bjoern Walk
a243316ac6 conf: node_device: fix up SCSI target
When reading in an XML definition for a SCSI target device, the name
property of struct scsi_target refers to the @target element.

Let's fix this obvious typo and also extend the XML schema to provide
validation.

Signed-off-by: Bjoern Walk <bwalk@linux.vnet.ibm.com>
2016-03-21 12:06:49 -04: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
Jim Fehlig
4c9ffc5388 xenconfig: change 'hap' setting to align with Xen behavior
hap is enabled by default in xm and xl config and usually only
specified when it is desirable to disable hap (hap = 0). Change
the xm,xl <-> xml converter to behave similarly. I.e. only
produce 'hap = 0' when <hap state='off'/> and vice versa.

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
2016-03-21 09:28:17 -06:00
Jim Fehlig
9d243e0895 conf: add 'state' attribute to <hap> feature
Most hypervisors use Hardware Assisted Paging by default and don't
require specifying the feature in domain conf. But some hypervisors
support disabling HAP on a per-domain basis. To enable HAP by default
yet provide a knob to disable it, extend the <hap> feature with a
'state=on|off' attribute, similar to <pvspinlock> and <vmport> features.

In the absence of <hap>, the hypervisor default (on) is used. <hap>
without the state attribute would be the same as <hap state='on'/> for
backwards compatibility. And of course <hap state='off'/> disables hap.

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
2016-03-21 09:28:17 -06:00
Jiri Denemark
109017d9b3 qemu: Add flags to qemuMigrationWaitForCompletion
The function already takes two bool arguments, switching to flags makes
it a lot easier to read. Especially in case we need to add another
boolean in the future.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-03-21 15:15:46 +01:00
Jiri Denemark
d64adcdb96 qemu: Refuse to abort migration in post-copy mode
In post-copy mode none of the hosts has a complete guest state and
rolling back migration is impossible. Thus aborting it would be
equivalent to destroying the domain.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-03-21 15:15:46 +01:00
Jiri Denemark
630517d860 qemu: Handle post-copy migration failures
When migration fails in the post-copy mode, it's impossible to just kill
the destination domain and resume the source since the source no longer
contains current guest state. Let's mark domains on both sides as
VIR_DOMAIN_PAUSED_POSTCOPY_FAILED to let the upper layer decide what to
do with them.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-03-21 15:15:46 +01:00
Jiri Denemark
81b2a2c749 qemu: Refactor qemuProcessRecoverMigration
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-03-21 15:15:46 +01:00
Jiri Denemark
f6ea8a9f19 qemu: Don't kill running migrated domain on daemon restart
When destination libvirtd is restarted during migration in Finish phase
just after the point we started guest CPUs, we should not kill the
domain.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-03-21 15:15:46 +01:00
Cristian Klein
4cdc4a76d3 virsh: Add --postcopy-after-precopy option to migrate
Signed-off-by: Cristian Klein <cristiklein@gmail.com>
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-03-21 15:15:46 +01:00
Jiri Denemark
257060349e virsh: Configurable migrate --timeout action
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-03-21 15:15:46 +01:00
Cristian Klein
179d97283f virsh: Add support for post-copy migration
Signed-off-by: Cristian Klein <cristiklein@gmail.com>
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-03-21 15:15:46 +01:00
Cristian Klein
51a3e4df72 qemu: Implement virDomainMigrateStartPostCopy
Signed-off-by: Cristian Klein <cristiklein@gmail.com>
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-03-21 15:15:46 +01:00
Cristian Klein
e8d2ff6ff2 qemu: Add support for VIR_MIGRATE_POSTCOPY flag
Signed-off-by: Cristian Klein <cristiklein@gmail.com>
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-03-21 15:15:46 +01:00
Cristian Klein
41d786b915 qemu: Add QMP functions for post-copy migration
Signed-off-by: Cristian Klein <cristiklein@gmail.com>
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-03-21 15:15:46 +01:00
Jiri Denemark
ee47d8e8dd qemu: Handle postcopy-active migration state
Migration enters "postcopy-active" state after QEMU switches to
post-copy and pauses guest CPUs. From libvirt's point of view this state
is similar to "completed" because we need to transfer guest execution to
the destination host.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-03-21 15:15:46 +01:00
Cristian Klein
1a1246ec7d Add public APIs for post-copy migration
To use post-copy one has to start the migration with
VIR_MIGRATE_POSTCOPY flag and, while migration is in progress, call
virDomainMigrateStartPostCopy() to switch from pre-copy to post-copy.

Signed-off-by: Cristian Klein <cristiklein@gmail.com>
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-03-21 15:15:46 +01:00
Jiri Denemark
5a9cbc6265 Add event and state details for post-copy
VIR_DOMAIN_EVENT_SUSPENDED_POSTCOPY and VIR_DOMAIN_PAUSED_POSTCOPY are
used on the source host once migration enters post-copy mode (which
means the domain gets paused on the source. After the destination host
takes over the execution of the domain, its virtual CPUs are resumed and
the domain enters VIR_DOMAIN_RUNNING_POSTCOPY state and
VIR_DOMAIN_EVENT_RESUMED_POSTCOPY event is emitted.

In case migration fails during post-copy mode and none of the hosts have
complete state of the domain, both domains will remain paused with
VIR_DOMAIN_PAUSED_POSTCOPY_FAILED reason and an upper layer may decide
what to do.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-03-21 15:15:46 +01:00
Martin Kletzander
573c41a275 util: Add virSocketAddrSetIPv[46]AddrNetOrder and use it
This allows setting the address in host and/or network order and makes
the naming consistent.  Now you don't need to call [hn]to[nh]l()
functions as that is taken care of by these functions.  Also, now
the *NetOrder take the address in network order, the other functions in
host order so the naming and usage is consistent.  Some places were
having the address in network order and calling ntohl() just so the
original function can call htonl() again.  This makes it nicer to read.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2016-03-21 11:28:33 +01:00