Commit Graph

10455 Commits

Author SHA1 Message Date
Daniel Henrique Barboza
5a5fde03bb qemu_domain.c: modernize qemuDomainFixupCPUs()
Use g_autoptr() to deprecate the 'cleanup' label.

Reviewed-by: Jonathon Jongsma <jjongsma@redhat.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
2020-11-13 12:11:44 -03:00
Daniel Henrique Barboza
f17de6c173 qemu_domain.c: remove unneeded cleanup labels
Remove obsolete 'cleanup' labels after the changes from the
previous patch.

Reviewed-by: Jonathon Jongsma <jjongsma@redhat.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
2020-11-13 12:11:44 -03:00
Daniel Henrique Barboza
c269d7ad2d qemu_domain.c: use g_autoptr() with virDomainDef pointers
Reviewed-by: Jonathon Jongsma <jjongsma@redhat.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
2020-11-13 12:11:44 -03:00
Daniel Henrique Barboza
0ea83f7ebb qemu_snapshot.c: remove uneeded 'cleanup' label in qemuSnapshotDelete()
Reviewed-by: Jonathon Jongsma <jjongsma@redhat.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
2020-11-13 12:11:44 -03:00
Daniel Henrique Barboza
269dffd0ce qemu_driver.c: remove unneeded 'cleanup' labels
Some labels became deprecated after the previous patches.

Reviewed-by: Jonathon Jongsma <jjongsma@redhat.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
2020-11-13 12:11:44 -03:00
Daniel Henrique Barboza
9c215628d6 qemu_driver.c: use g_autoptr() with virDomainDeviceDefPtr
Reviewed-by: Jonathon Jongsma <jjongsma@redhat.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
2020-11-13 12:11:44 -03:00
Daniel Henrique Barboza
94196ba605 qemu_driver.c: use g_autoptr() with qemuMigrationParams pointers
Reviewed-by: Jonathon Jongsma <jjongsma@redhat.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
2020-11-13 12:11:43 -03:00
Daniel Henrique Barboza
74b2834333 qemu_driver.c: use g_autoptr() with virDomainDef pointers
Reviewed-by: Jonathon Jongsma <jjongsma@redhat.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
2020-11-13 12:11:43 -03:00
Nikolay Shirokovskiy
b814d499a7 qemu: remove possible garbage left from previous rename/undefine
Due to failures to unlink on previous rename/undefine we can already have
autolink etc files for the domain to be defined. Remove them.

Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
2020-11-13 14:49:50 +03:00
Nikolay Shirokovskiy
773c7c4361 qemu: qemuDomainDefineXMLFlags: move cleanup logic to cleanup section
Let's move objlist restoring to cleanup section so that we can handle failure
of actions between virDomainObjListAdd and virDomainDefSave. We are going
to add such actions in next patch.

Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
2020-11-13 14:49:50 +03:00
Nikolay Shirokovskiy
e2738b2bd7 qemu: rename: remove snapshot/checkpoint restriction
Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
2020-11-13 14:49:50 +03:00
Nikolay Shirokovskiy
a3259e47d2 qemu: update name on reverting from snapshot
If domain name is changed since snapshot we need to update it to current in
config taken from snapshot.

Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
2020-11-13 14:49:50 +03:00
Nikolay Shirokovskiy
3b1244bffd qemu: rename: support renaming checkpoints directory
This is basically just saves checkpoints metadata on disk after name is changed
in memory as path to domain checkpoints directory depends on name. After that
old checkpoint directory is deleted with checkpoint metadata files.

Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
2020-11-13 14:49:50 +03:00
Nikolay Shirokovskiy
4770a96c66 qemu: rename: support renaming snapshots directory
This is basically just saves snapshots metadata on disk after name is changed
in memory as path to domain snapshot directory depends on name. After that
old snapshot directory is deleted with snapshot metadata files.

Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
2020-11-13 14:49:50 +03:00
Nikolay Shirokovskiy
1f209eac1d qemu: remove duplicate code for removing remnant files
This patch also changes functionality a bit.

First if unlinking of old config file is failed we rollback and return error
previously and now we return success. I don't think this makes much difference.
I guess in both cases on libvirtd restart we have to deal with both new and old
config existing on disk with different names but same uuid.

Second if unlinking of old autolink is failed we rollback previously which
was not right as at this point we already unlink old config file. So this
is fixed now.

Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
2020-11-13 14:49:50 +03:00
Nikolay Shirokovskiy
a6c3b5e6a1 qemu: rename: return instead of goto if no cleanup required
Going to cleanup label is mere return -1 thus let's just return
instead of goto to this label.

Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
2020-11-13 14:49:49 +03:00
Nikolay Shirokovskiy
9a5ac61c4e qemu: rename: send events only on success
We can simplify cleanup section by moving sending events to success path only
because only on sucess path events are not NULL.

Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
2020-11-13 14:49:49 +03:00
Nikolay Shirokovskiy
8afbd34ba9 qemu: qemuDomainRenameCallback: fix sending false undefined event
For example if saving config file with new name fails we send false undefine
event currently.

Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
2020-11-13 14:49:49 +03:00
Jiri Denemark
d8e5b45600 qemu: Do not require TSC frequency to strictly match host
Some CPUs provide a way to read exact TSC frequency, while measuring it
is required on other CPUs. However, measuring is never exact and the
result may slightly differ across reboots. For this reason both Linux
kernel and QEMU recently started allowing for guests TSC frequency to
fall into +/- 250 ppm tolerance interval around the host TSC frequency.

Let's do the same to avoid unnecessary failures (esp. during migration)
in case the host frequency does not exactly match the frequency
configured in a domain XML.

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

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
2020-11-12 17:29:16 +01:00
Michal Privoznik
e4c29e2904 virnetdevopenvswitch: Get names for dpdkvhostuserclient too
There are two types of vhostuser ports:

  dpdkvhostuser - OVS creates the socket and QEMU connects to it
  dpdkvhostuserclient - QEMU creates the socket and OVS connects to it

But of course ovs-vsctl syntax for fetching ifname is different.
So far, we've implemented the former. The lack of implementation
for the latter means that we are not detecting the interface name
and thus not reporting it in domain XML, or failing to get
interface statistics.

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

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
2020-11-12 08:24:43 +01:00
Jiri Denemark
3c7c7cd4d8 conf: Use unsigned long long for timer frequency
Although the code in qemuProcessStartValidateTSC works as if the
timer frequency was already unsigned long long (by using an appropriate
temporary variable), the virDomainTimerDef structure actually defines
frequency as unsigned long, which is not guaranteed to be 64b.

Fixes support for frequencies higher than 2^32 - 1 on 32b systems.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
2020-11-11 23:06:23 +01:00
Masayoshi Mizuma
5cde9dee8c qemu: Move qemuExtDevicesStop() before removing the pidfiles
A qemu guest which has virtiofs config fails to start if the previous
starting failed because of invalid option or something.

That's because the virtiofsd isn't killed by virPidFileForceCleanupPath()
on the former failure because the pidfile was already removed by
virFileDeleteTree(priv->libDir) in qemuProcessStop(), so
virPidFileForceCleanupPath() just returned.

Move qemuExtDevicesStop() before virFileDeleteTree(priv->libDir) so that
virPidFileForceCleanupPath() can kill virtiofsd correctly.

For example of the reproduction:

  # virsh start guest
  error: Failed to start domain guest
  error: internal error: process exited while connecting to monitor: qemu-system-x86_64: -foo: invalid option

  ... fix the option ...

  # virsh start guest
  error: Failed to start domain guest
  error: Cannot open log file: '/var/log/libvirt/qemu/guest-fs0-virtiofsd.log': Device or resource busy
  #

Signed-off-by: Masayoshi Mizuma <m.mizuma@jp.fujitsu.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2020-11-11 15:20:12 +01:00
Matt Coleman
83959e6a30 domain_conf: make virDomainLeaseInsert() void
This function always returns zero, so it might as well be void.

Signed-off-by: Matt Coleman <matt@datto.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2020-11-11 12:53:11 +01:00
Matt Coleman
56dab2f0b3 domain_conf: make virDomainLeaseInsertPreAlloc() void
This function always returns zero, so it might as well be void.

Signed-off-by: Matt Coleman <matt@datto.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2020-11-11 12:53:11 +01:00
Matt Coleman
53a1aa1759 domain_conf: make virDomainControllerInsert() void
This function always returns zero, so it might as well be void.

Signed-off-by: Matt Coleman <matt@datto.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2020-11-11 12:53:11 +01:00
Matt Coleman
736c9ea02d domain_conf: make virDomainDiskInsert() void
This function always returns zero, so it might as well be void.

Signed-off-by: Matt Coleman <matt@datto.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2020-11-11 12:53:11 +01:00
Matt Coleman
8f80014299 domain_conf: make virDomainDiskSetBlockIOTune() void
This function always returns zero, so it might as well be void.

Signed-off-by: Matt Coleman <matt@datto.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2020-11-11 12:53:11 +01:00
Matt Coleman
3245d48b86 domain_conf: make virDomainDiskSetDriver() void
The function only returns zero or aborts, so it might as well be void.
This has the added benefit of simplifying the code that calls it.

Signed-off-by: Matt Coleman <matt@datto.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2020-11-11 12:53:11 +01:00
Daniel P. Berrangé
18c73a4c70 meson: drop use of .path() for python args
When using .path() for an argument to a python script meson will not
setup dependancies on the file. This means that changes to the generator
script will not trigger a rebiuld

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2020-11-09 16:32:55 +00:00
Daniel P. Berrangé
2a917e6756 Fix name prefix of VIR_DOMAIN_CHECKPOINT_REDEFINE_VALIDATE
The enum constant names should all have a prefix that matches the enum
name. VIR_DOMAIN_CHECKPOINT_REDEFINE_VALIDATE was missing the "CREATE_"
part of the name prefix.

Reviewed-by: Peter Krempa <pkrempa@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2020-11-09 16:29:06 +00:00
Peter Krempa
5ab8cc78c4 qemu: backup: Add partial validation of incremental backup checkpoint
Verify that the checkpoint requested by an incremental backup exists.
Unfortunately validating whether the checkpoint configuration actually
matches the disk may not be reasonably feasible as the disk may have
been renamed/snapshotted/etc. We still rely on bitmap presence.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2020-11-09 12:25:50 +01:00
Peter Krempa
a4d4d2bd5d qemu: checkpoint: Implement VIR_DOMAIN_CHECKPOINT_REDEFINE_VALIDATE
Validate that the bitmaps are present when redefining a checkpoint.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2020-11-09 12:25:50 +01:00
Peter Krempa
93873c9bcc conf: checkpoint: Split virDomainCheckpointRedefinePrep into two functions
First one prepares and validates the definition, the second one actually
either updates an existing checkpoint or assigns definition for the new
one.

This will allow driver code to add extra validation between those
steps.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2020-11-09 12:25:50 +01:00
Peter Krempa
e33e89d839 qemu: backup: Use VIR_ERR_CHECKPOINT_INCONSISTENT when starting a backup
If we don't have a consistent chain of bitmaps for the backup to proceed
we'd report VIR_ERR_INVALID_ARG error code, which makes it hard to
decide whether an incremental backup makes even sense.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2020-11-09 12:25:49 +01:00
Peter Krempa
f8b0866878 qemu_migration_cookie: Make cookie parsing robust against missing domain job
In testing code we don't properly populate the job sometimes. If it
isn't populated we should not touch it though in the migration cookie
code.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2020-11-09 12:25:49 +01:00
Peter Krempa
b2d6fc67ab qemu_migration_cookie: Export qemuMigrationCookieXMLFormat for tests
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2020-11-09 12:25:49 +01:00
Peter Krempa
49c845bb4e qemu_migration_cookie: Make header standalone
Include qemu_domain.h and qemu_domainjob.h as the types from those
headers are used by this header.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2020-11-09 12:25:49 +01:00
Nikolay Shirokovskiy
7e34d9a9e0 qemu: fix qemuMigrationSrcCleanup to use qemuMigrationJobFinish
qemuMigrationSrcCleanup uses qemuDomainObjDiscardAsyncJob currently. But
discard does not reduce jobs_queued counter so it leaks. Also discard does not
notify other threads that job condition is available. Discard does reset nested
job but nested job is not possible in this conditions.

Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
2020-11-06 17:28:37 +03:00
Peter Krempa
62a01d84a3 util: hash: Retire 'virHashTable' in favor of 'GHashTable'
Don't hide our use of GHashTable behind our typedef. This will also
promote the use of glibs hash function directly.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Reviewed-by: Matt Coleman <matt@datto.com>
2020-11-06 10:40:51 +01:00
Peter Krempa
947d2db31b Use virHashForEachSorted in tested code
The simplest way to write tests is to check the output against expected
output, but we must ensure that the output is stable. We can use
virHashForEachSorted as a hash iterator to ensure stable ordering.

This patch fixes 3 instances of hash iteration which is tested in
various parts, including test output changes in appropriate places.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Reviewed-by: Matt Coleman <matt@datto.com>
2020-11-06 10:31:57 +01:00
Peter Krempa
4eb8e9ae8b util: hash: Rewrite sorting of elements in virHashGetItems
All but one of the callers either use the list in arbitrary order or
sorted by key. Rewrite the function so that it supports sorting by key
natively and make it return the element count. This in turn allows to
rewrite the only caller to sort by value internally.

This allows to remove multiple sorting functions which were sorting by
key and the function will be also later reused for some hash operations
internally.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Reviewed-by: Matt Coleman <matt@datto.com>
2020-11-06 10:31:57 +01:00
Michal Privoznik
ef164fb3f9 qemu_conf: Don't even attempt to enable rememberOwner if unsupported
The remember owner feature uses XATTRs to store original
seclabels. But that means we don't want a regular user to be able
to change what we stored and thus trick us into setting different
seclabel. Therefore, we use namespaces that are reserved to
CAP_SYS_ADMIN only. Such namespaces exist on Linux and FreeBSD.
That also means, that the whole feature is enabled only for
qemu:///system. Now, while the secdriver code is capable of
dealing with XATTRs being unsupported (it has to, not all
filesystems support them) if the feature is enabled users will
get an harmless error message in the logs and the feature
disables itself.

Since we have virSecurityXATTRNamespaceDefined() we can use it to
make a wiser decision on the default state of the feature.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Roman Bolshakov <r.bolshakov@yadro.com>
Reviewed-by: Andrea Bolognani <abologna@redhat.com>
2020-11-06 09:16:21 +01:00
Brian Turek
1d9b4a9638 qemu: add support for 'fmode' and 'dmode'
Add logic to validate and then pass through 'fmode' and 'dmode' to the
QEMU call.

Signed-off-by: Brian Turek <brian.turek@gmail.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
2020-11-04 18:25:56 +01:00
Brian Turek
b0f0e96cdd qemu: capabilities: add QEMU_CAPS_FSDEV_CREATEMODE
The QEMU 9pfs 'fmode' and 'dmode' options have existed since QEMU 2.10.
Probe QEMU's command line set to check whether these options are
available, and if yes, enable this new QEMU_CAPS_FSDEV_CREATEMODE
capability on libvirt side.

Signed-off-by: Brian Turek <brian.turek@gmail.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
2020-11-04 18:25:53 +01:00
Pavel Hrdina
09c12ba248 qemu_dbus: use emulator cgroup for dbus-daemon
All other helper processes are moved to cgroup with QEMU emulator
thread as we keep the root VM cgroup without any processes. This
assumption is validated in qemuRestoreCgroupState() which is called
when libvirtd is restarted and reconnected to all running VMs.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2020-11-03 21:26:32 +01:00
Pavel Hrdina
b43acd8e82 qemu: remove dead code that setup cgroups for helper processes
In both cases priv->cgroup will always be NULL because it is called
before the QEMU process is started and cgroups are configured.

In qemuProcessLaunch() the call order is following:

    qemuExtDevicesStart()
    ...
    virCommandRun()
    ...
    qemuSetupCgroup()

where qemuDBusStart() is called from qemuExtDevicesStart() but we
cgroups are created in qemuSetupCgroup().

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2020-11-03 21:26:32 +01:00
Pavel Hrdina
382071b8bf qemu_cgroup: remove unused @empty variable
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2020-11-03 21:26:32 +01:00
Laine Stump
85c8c29214 remove unnecessary cleanup labels and unused return variables
After converting all DIR* to g_autoptr(DIR), many cleanup: labels
ended up just having "return ret", and every place that set ret would
just immediately goto cleanup. Remove the cleanup label and its
return, and just return the set value immediately, thus eliminating
the need for the return variable itself.

Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
2020-11-02 22:01:36 -05:00
Laine Stump
c0ae4919e3 change DIR* int g_autoptr(DIR) where appropriate
All of these conversions are trivial - VIR_DIR_CLOSE() (aka
virDirClose()) is called only once on the DIR*, and it happens just
before going out of scope.

Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
2020-11-02 22:01:36 -05:00
Laine Stump
c40b673182 consistently use VIR_DIR_CLOSE() instead of virDirClose()
This will make it easier to review upcoming patches that use g_autoptr
to auto-close all DIRs.

Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
2020-11-02 22:01:36 -05:00