Commit Graph

4136 Commits

Author SHA1 Message Date
Peter Krempa
2f37362e44 qemu: Fix balloon size handling with memory hot(un)plug
Since libvirt doesn't call to update the new balloon size in qemu add
code that will handle tweaking of the size of the current balloon
statistic until qemu reports the new size using the event.
2015-05-11 08:50:36 +02:00
Peter Krempa
85d8ede9eb qemu: Convert qemuConnectGetAllDomainStats to use new helpers
Use the new domain list collection helpers to avoid going through
virDomainPtrs.

This additionally implements filter capability when called through the
api that accepts domain list filters.
2015-05-11 08:47:42 +02:00
Peter Krempa
a5e89ae16e util: Make the virDomainListFree helper more universal
Extend it to a universal helper used for clearing lists of any objects.
Note that the argument type is specifically void * to allow implicit
typecasting.

Additionally add a helper that works on non-NULL terminated arrays once
we know the length.
2015-05-11 08:28:53 +02:00
Michal Privoznik
2af51483cc processSerialChangedEvent: Close agent monitor early
https://bugzilla.redhat.com/show_bug.cgi?id=890648

So, imagine you've issued an API that involves guest agent. For
instance, you want to query guest's IP addresses. So the API acquires
QUERY_JOB, locks the guest agent and issues the agent command.
However, for some reason, guest agent replies to initial ping
correctly, but then crashes tragically while executing real command
(in this case guest-network-get-interfaces). Since initial ping went
well, libvirt thinks guest agent is accessible and awaits reply to the
real command. But it will never come. What will is a monitor event.
Our handler (processSerialChangedEvent) will try to acquire
MODIFY_JOB, which will fail obviously because the other thread that's
executing the API already holds a job. So the event handler exits
early, and the QUERY_JOB is never released nor ended.

The way how to solve this is to put flag somewhere in the monitor
internals. The flag is called @running and agent commands are issued
iff the flag is set. The flag itself is set when we connect to the
agent socket. And unset whenever we see DISCONNECT event from the
agent. Moreover, we must wake up all the threads waiting for the
agent. This is done by signalizing the condition they're waiting on.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2015-05-07 11:31:17 +02:00
Michal Privoznik
21e8fc36c6 qemuDomainShutdownFlags: check for domain activeness prior to guest presence
Running shutdown with mode agent on a shutoff domain gives cryptic
error message:

    virsh # shutdown --mode agent gentoo
    error: Failed to shutdown domain gentoo
    error: Guest agent is not responding: QEMU guest agent is not connected

After this patch, the error is more clear:

    virsh # shutdown --mode agent gentoo
    error: Failed to shutdown domain gentoo
    error: Requested operation is not valid: domain is not running

Reported-by: Martin Kletzander <mkletzan@redhat.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2015-05-06 18:03:04 +02:00
Boris Fiuczynski
808e771e83 qemu: multiqueue for ccw devices
Allow ccw devices to be used with multiqueues. ccw provides a one to
one relation of fds to queues and does not support the vectors option.

Signed-off-by: Boris Fiuczynski <fiuczy@linux.vnet.ibm.com>
Reviewed-by: Matthew Rosato <mjrosato@linux.vnet.ibm.com>
Reviewed-by: Daniel Hansel <daniel.hansel@linux.vnet.ibm.com>
Reviewed-by: Cornelia Huck <cornelia.huck@de.ibm.com>
2015-05-06 11:42:42 -04:00
John Ferlan
b8e60f00d8 qemu: Resolve Coverity FORWARD_NULL
Coverity points out that qemuMonitorGetAllBlockStatsInfo could return a
-1 and thus not fill in 'stats' (leaving it NULL). Then the call to
qemuMonitorBlockStatsUpdateCapacity will dereference it.
2015-05-05 20:02:37 -04:00
John Ferlan
3e4ce35926 qemu: Resolve Coverity FORWARD_NULL
Coverity complains over the [n]values pairing in virQEMUCapsFreeStringList
and rather than make a bunch if "if values" checks prior to calling, by
just adding the values check inside the free function we avoid the chance
that somehow nvalues is > 0, while values == NULL
2015-05-05 20:02:37 -04:00
John Ferlan
e7664eedaa qemu: Resolve Coverity FORWARD_NULL
Coverity points out it was possible to have a zero return from
qemuBuildRNGBackendProps thus not filling in 'props' and then
causing a NULL dereference on the next call.
2015-05-05 20:02:37 -04:00
John Ferlan
75dfbb85c7 qemu: Resolve Coverity FORWARD_NULL
Coverity notes that ->ifname is used after the VIR_FREE done in the
code path after the call to virNetDevMacVLanDeleteWithVPortProfile
by a call to virNetDevOpenvswitchRemovePort.

Since the ->ifname will be VIR_FREE()'d eventually in virDomainNetDefFree
just remove the extraneous VIR_FREE here.

When originally added, the Openvswitch code wasn't present and checks
were made for non NULL prior to use.
2015-05-05 20:02:36 -04:00
John Ferlan
9ad32e5052 qemu: Resolve Coverity IDENTICAL_BRANCHES
Coverity complains that in the error paths both the < 0 condition and
the success path after the qemuDomainObjExitMonitor failure will end
up going to cleanup.  So just use ignore_value in this error path to
resolve the complaint.
2015-05-05 20:02:36 -04:00
Michal Privoznik
608c95c76c qemu: Implement GIC
The only version that's supported in QEMU is version 2, currently.
Fortunately, it is enabled by aarch64 automatically, so there's
nothing for us that needs to be put onto command line.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2015-05-05 09:45:52 +02:00
Jiri Denemark
fc3601a308 qemu: Properly rename persistent def after migration
When migrating a domain while changing its name and using
VIR_MIGRATE_PERSIST_DEST flag, libvirt would fail to properly change the
name in the persistent definition. The inconsistency results in weird
behavior when dumping domain XML, destroying the domain, restarting
libvirtd and likely in several other situations.

Since the new name is already stored in vm->def->name, we just need to
make sure the persistent definition uses this new name too.

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

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2015-05-04 22:59:51 +02:00
Jiri Denemark
b45ec56f58 qemu: Forbid unsupported parameters for tunnelled migration
Neither migrate URI nor lister address make any sense for tunnelled
migration.

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

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2015-05-04 15:06:33 +02:00
Marc-André Lureau
7d3dc7a084 qemu: add machine vmport argument
Fill qemu command line vmport argument as required.
2015-05-04 13:19:38 +02:00
Marc-André Lureau
f5a5f2b7d4 qemu: add virQEMUCapsSupportsVmport
The vmport machine argument works with pc machine kind, not with xen for
example.
2015-05-04 13:19:38 +02:00
Marc-André Lureau
46ae6b7fc7 qemu: move qemuDomainMachineIs{I440FX,Q35}
Move common functions being used by the following
virQEMUCapsSupportsVmport commit.
2015-05-04 13:19:38 +02:00
Marc-André Lureau
384a06f5f2 qemu: add QEMU_CAPS_MACHINE_VMPORT_OPT
Set the capability based on qmp query, or qemu version.  The qmp query
includes vmport with 2.2, but no longer with 2.3. It lists only
non-machine specific capabilities, so check the qemu version too until a
machine-specific query is supported.
2015-05-04 13:19:38 +02:00
Luyao Huang
3f7cad7a8f qemu: fix the vm deadlock when deleting a nonexistent iothread
https://bugzilla.redhat.com/show_bug.cgi?id=1218145

Jump to endjob instead of cleanup to fix this deadlock.

Signed-off-by: Luyao Huang <lhuang@redhat.com>
2015-05-04 12:18:55 +02:00
Pavel Hrdina
28ca8520bb qemu: use new macros for setvcpus to check flags and cleanup the code
Now that we have macros for exclusive flags and flag requirements we can
use them to cleanup the code for setvcpus and error out for all wrong
flag combination.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2015-05-04 09:20:01 +02:00
Pavel Hrdina
6e3f9cbc9c use new macro helpers to check flag requirements
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2015-05-04 09:20:01 +02:00
John Ferlan
63a368012d qemu: Fix bus and lun checks when scsi-disk.channel not present
Found by Laine and discussed a bit on internal IRC.

Commit id c56fe7f1d6 added support for creating a command line to support
scsi-disk.channel.

Series was here:
http://www.redhat.com/archives/libvir-list/2012-February/msg01052.html

Which pointed to a design proposal here:
http://permalink.gmane.org/gmane.comp.emulators.libvirt/50428

Which states (in part):

Libvirt should check for the QEMU "scsi-disk.channel" property.  If it
is unavailable, QEMU will only support channel=lun=0 and 0<=target<=7.

However, the check added was ensuring that bus != lun *and* bus != 0. So
if bus == lun and both were non zero, we'd never make the second check.
Changing this to an *or* check fixes the check, but still is less readable
than the just checking each for 0
2015-04-30 16:21:38 -04:00
Peter Krempa
f06d7daaa9 qemu: blockjob: Call qemuDomainSupportsBlockJobs only on online VMs
Since the qemu capabilities are not initialized for offline VMs the
caller might get suboptimal error message:

$ virsh blockjob VM PATH --bandwidth 1
error: unsupported configuration: block jobs not supported with this QEMU binary

Move the checks after we make sure that the VM is alive.
2015-04-30 16:46:42 +02:00
Jiri Denemark
6280294574 qemu: Check address type for USB disks
Only USB addresses are allowed for USB disks. Report an error if another
address is configured.

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

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2015-04-30 15:34:57 +02:00
Michael Chapman
99725f946c qemu: migration: use sync block job helpers
In qemuMigrationDriveMirror we can start all disk mirrors in parallel.
We wait until they are all ready, or one of them aborts.

In qemuMigrationCancelDriveMirror, we wait until all mirrors are
properly stopped. This is necessary to ensure that destination VM is
fully in sync with the (paused) source VM.

If a drive mirror can not be cancelled, then the destination is not in a
consistent state. In this case it is not safe to continue with the
migration.

Signed-off-by: Michael Chapman <mike@very.puzzling.org>
2015-04-29 13:11:42 +02:00
Michael Chapman
1e106fee57 qemuDomainBlockJobAbort: use sync block job helpers
The !modern code path needs to call qemuBlockJobEventProcess directly.
the modern code path will call it via qemuBlockJobSyncWait.

Signed-off-by: Michael Chapman <mike@very.puzzling.org>
2015-04-29 13:11:42 +02:00
Michael Chapman
1ec03c8772 qemuProcessStop: wake up pending sync block jobs
Other threads may be blocked in qemuBlockJobSyncWait. Ensure that
they're woken up when the domain is stopped.

Signed-off-by: Michael Chapman <mike@very.puzzling.org>
2015-04-29 13:11:42 +02:00
Michael Chapman
89a5e25d05 qemuBlockJobSync*: introduce sync block job helpers
qemuBlockJobSyncBegin and qemuBlockJobSyncEnd delimit a region of code
where block job events are processed "synchronously".
qemuBlockJobSyncWait and qemuBlockJobSyncWaitWithTimeout wait for an
event generated by a block job.

The Wait* functions may be called multiple times while the synchronous
block job is active. Any pending block job event will be processed by
only when Wait* or End is called.  disk->blockJobStatus is reset by
these functions, so if it is needed a pointer to a
virConnectDomainEventBlockJobStatus variable should be passed as the
last argument. It is safe to pass NULL if you do not care about the
block job status.

All functions assume the VM object is locked. The Wait* functions will
unlock the object for as long as they are waiting. They will return -1
and report an error if the domain exits before an event is received.

Typical use is as follows:

  virQEMUDriverPtr driver;
  virDomainObjPtr vm; /* locked */
  virDomainDiskDefPtr disk;
  virConnectDomainEventBlockJobStatus status;

  qemuBlockJobSyncBegin(disk);

  ... start block job ...

  if (qemuBlockJobSyncWait(driver, vm, disk, &status) < 0) {
      /* domain died while waiting for event */
      ret = -1;
      goto error;
  }

  ... possibly start other block jobs
      or wait for further events ...

  qemuBlockJobSyncEnd(driver, vm, disk, NULL);

To perform other tasks periodically while waiting for an event:

  virQEMUDriverPtr driver;
  virDomainObjPtr vm; /* locked */
  virDomainDiskDefPtr disk;
  virConnectDomainEventBlockJobStatus status;
  unsigned long long timeout = 500 * 1000ull; /* milliseconds */

  qemuBlockJobSyncBegin(disk);

  ... start block job ...

  do {
      ... do other task ...

      if (qemuBlockJobSyncWaitWithTimeout(driver, vm, disk,
                                          timeout, &status) < 0) {
          /* domain died while waiting for event */
          ret = -1;
          goto error;
      }
  } while (status == -1);

  qemuBlockJobSyncEnd(driver, vm, disk, NULL);

Signed-off-by: Michael Chapman <mike@very.puzzling.org>
2015-04-29 13:11:42 +02:00
Michael Chapman
206dbf3f0a qemuBlockJobEventProcess: move to new source file
We will want to use synchronous block jobs from qemu_migration as well,
so split this function out into a new source file.

Signed-off-by: Michael Chapman <mike@very.puzzling.org>
2015-04-29 13:11:42 +02:00
Peter Krempa
a83b2e253f qemu: Validate available slot count for memory devices
While qemu would reject the configuration we can check whether it makes
sense to plug the device upfront.
2015-04-29 09:40:16 +02:00
Peter Krempa
6705d828fc qemu: command: Validate that memory devices slot ID is in range
slot id, if specified, has to be less than the slots count.
2015-04-29 09:40:16 +02:00
Peter Krempa
ebe0bd5590 qemu: blockCopy: Allow reuse of raw image for shallow block copy
The documentation states that for shallow block copy the image has to
have the same guest visible content as backing file of the current
image if the file is being reused. This condition can be achieved also
with a raw file (or a qcow without a backing file) so remove the
condition that would disallow it.

(This patch additionally fixes crash described in
 https://bugzilla.redhat.com/show_bug.cgi?id=1215569 )
2015-04-29 09:32:53 +02:00
Zhang Bo
6f5d29f40d qemu: make qemuMonitorChardevInfoFree non-static
It would be used in qemumonitorjsontest, thus we make it non-static.

Signed-off-by: Zhang Bo <oscar.zhangbo@huawei.com>
Signed-off-by: Zhou Yimin <zhouyimin@huawei.com>
2015-04-28 16:50:11 +02:00
John Ferlan
b515339fe7 qemu: Remove need for qemuMonitorIOThreadInfoFree
Replace with just VIR_FREE.
2015-04-28 06:33:49 -04:00
John Ferlan
69b16513a5 qemu: qemuProcessDetectIOThreadPIDs invert checks
If we received zero iothreads from the monitor, but were perhaps
expecting to receive something, then the code was skipping the check
to ensure what's in the monitor matches our expectations.  So invert
the checks to check that what we get back matches expectations and
then check there are zero iothreads returned.
2015-04-28 06:33:35 -04:00
John Ferlan
4c2ca5664a qemu: Remove need for qemuDomainParseIOThreadAlias
Rather than have a separate routine to parse the alias of an iothread
returned from qemu in order to get the iothread_id value, parse the alias
when returning and just return the iothread_id in qemuMonitorIOThreadInfoPtr

This set of patches removes the function, changes the "char *name" to
"unsigned int" and handles all the fallout.
2015-04-28 06:33:30 -04:00
John Ferlan
d8082d2d44 qemu: Resolve Coverity DEADCODE
Coverity notes that the switch() used to check 'connected' values has
two DEADCODE paths (_DEFAULT & _LAST).  Since 'connected' is a boolean
it can only be one or the other (CONNECTED or DISCONNECTED), so it just
seems pointless to use a switch to get "all" values.  Convert to if-else
2015-04-27 14:55:35 -04:00
John Ferlan
a27ed6e78c qemu: Add support to Add/Delete IOThreads
Add qemuDomainAddIOThread and qemuDomainDelIOThread in order to add or
remove an IOThread to/from the host either for live or config optoins

The implementation for the 'live' option will use the iothreadpids list
in order to make decision, while the 'config' option will use the
iothreadids list.  Additionally, for deletion each may have to adjust
the iothreadpin list.

IOThreads are implemented by qmp objects, the code makes use of the existing
qemuMonitorAddObject or qemuMonitorDelObject APIs.

Signed-off-by: John Ferlan <jferlan@redhat.com>
2015-04-27 12:36:36 -04:00
John Ferlan
b266486fb9 Move iothreadspin information into iothreadids
Remove the iothreadspin array from cputune and replace with a cpumask
to be stored in the iothreadids list.

Adjust the test output because our printing goes in order of the iothreadids
list now.
2015-04-27 12:36:35 -04:00
John Ferlan
8d4614a512 qemu: Use domain iothreadids to IOThread's 'thread_id'
Add 'thread_id' to the virDomainIOThreadIDDef as a means to store the
'thread_id' as returned from the live qemu monitor data.

Remove the iothreadpids list from _qemuDomainObjPrivate and replace with
the new iothreadids 'thread_id' element.

Rather than use the default numbering scheme of 1..number of iothreads
defined for the domain, use the iothreadid's list for the iothread_id

Since iothreadids list keeps track of the iothread_id's, these are
now used in place of the many places where a for loop would "know"
that the ID was "+ 1" from the array element.

The new tests ensure usage of the <iothreadid> values for an exact number
of iothreads and the usage of a smaller number of <iothreadid> values than
iothreads that exist (and usage of the default numbering scheme).
2015-04-27 12:36:35 -04:00
Martin Kletzander
6957a606a5 Fix check for return value of qemuDomainAgentAvailable()
Commit dcbb243bbc used the return value of
the function as int even though it returns bool.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2015-04-27 10:11:35 +02:00
Zhang Bo
0a8bd97afa qemu: fix memleaks in qemuBuildCommandLine
free boot_opts_str and boot_order_str both in normal and error paths.

Signed-off-by: Zhang Bo <oscar.zhangbo@huawei.com>
2015-04-27 10:04:38 +02:00
Jiri Denemark
659dbba37e qemu: Fix comment for timeDelta
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2015-04-27 09:43:27 +02:00
zhang bo
21b64552fe Fix typo in comment about memory binding
rather then -> rather than

Signed-off-by: YueWenyuan <yuewenyuan@huawei.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
2015-04-27 09:05:29 +02:00
Peter Krempa
a03e2d3a99 qemu: Connect to guest agent after channel hotplug
If a user hot-attaches the guest agent channel libvirt would ignore it
until the restart of libvirtd or shutdown/destroy and start of the VM
itself.

This patch adds code that opens or closes the guest agent connection
according to the state of the guest agent channel according to
connect/disconnect events.

To allow opening the channel from the event handler qemuConnectAgent
needed to be exported.
2015-04-26 17:19:22 +02:00
Peter Krempa
e1c04108d7 qemu: agent: Differentiate errors when the agent channel was hotplugged
When the guest agent channel gets hotplugged to a VM, libvirt would
still report that "QEMU guest agent is not configured" rather than
stating that the connection was not established yet.

Currently the code won't be able to connect to the agent after hotplug
but that will change in a later patch.

As the qemuFindAgentConfig() helper is quite helpful in this case move
it to a more usable place and export it.
2015-04-26 17:19:22 +02:00
Peter Krempa
dcbb243bbc qemu: Reuse qemuDomainAgentAvailable in qemuDomainInterfaceAddresses 2015-04-26 17:19:22 +02:00
Peter Krempa
c6351cc689 qemu: Fix domain object leak in qemuDomainInterfaceAddresses
The API didn't use virDomainObjEndAPI to release the domain object thus
it leaked a reference to it.
2015-04-26 17:19:22 +02:00
Peter Krempa
249992876b qemu: agent: Reuse virJSONValueObjectCreateVArgs in qemuAgentMakeCommand
Since the code is now separated into the common helper, we can reuse it
instead of maintaining two copies.
2015-04-26 17:19:22 +02:00
Cole Robinson
19425d110b qemu: Build nvram directory at driver startup
Similar to what was done for the channel socket in the previous commit.
2015-04-24 10:30:42 -04:00