Commit Graph

23119 Commits

Author SHA1 Message Date
Marc Hartmayer
1458746f05 virSecuritySELinuxTransactionCommit: Return -1 if no transaction is set
Return -1 and report an error message if no transaction is set and
virSecuritySELinuxTransactionCommit is called.

The function description of virSecuritySELinuxTransactionCommit says:

  "Also it is considered as error if there's no transaction set and this
   function is called."

Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Reviewed-by: Boris Fiuczynski <fiuczy@linux.ibm.com>
2018-11-13 18:36:15 +01:00
Michal Privoznik
8d8f6b4e88 virSecuritySELinuxTransactionCommit: Don't mask error
In 4674fc6afd I've implemented transactions for selinux driver.
Well, now that I am working in this area I've noticed a subtle
bug: @ret is initialized to 0 instead of -1. Facepalm.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Marc Hartmayer <mhartmay@linux.ibm.com>
2018-11-13 18:33:58 +01:00
Erik Skultety
25dde37373 conf: Move VFIO AP validation from post parse to QEMU validation code
VFIO AP has a limitation on a single device per domain, however, when
commit 11708641 added the support for vfio-ap, check for this limitation
was performed as part of the post parse code. Generally, checks like that
should be performed within the driver's validation callback to eliminate
any slight chance of failing in post parse, which could potentially
result in the domain XML config vanishing.

Signed-off-by: Erik Skultety <eskultet@redhat.com>
Reviewed-by: Boris Fiuczynski <fiuczy@linux.ibm.com>
2018-11-13 12:42:16 +01:00
Erik Skultety
208d6e6f5a qemu: Extract MDEV VFIO PCI validation code into a separate helper
Since we'll need to validate other models apart from VFIO PCI too,
having a helper for each model should keep the code base cleaner.

Signed-off-by: Erik Skultety <eskultet@redhat.com>
Reviewed-by: Boris Fiuczynski <fiuczy@linux.ibm.com>
2018-11-13 12:34:48 +01:00
Erik Skultety
f1e8d2f09a conf: Add new module node_device_util
There's a lot of stuff going on in src/conf/nodedev_conf which is
sometimes not directly related to config and we're not really consistent
with putting only parser/formatter related stuff here, e.g. like we do
for domains. So, let's start simply by adding a new module
node_device_util containing some of the helpers. Unfortunately, even
though these helpers tend to open a secondary driver connection and would
be much therefore better suited as a nodedev driver module, we can't do
that without pulling headers from the driver into conf/ and that's wrong
because we want conf/ to stay driver-agnostic.

Signed-off-by: Erik Skultety <eskultet@redhat.com>
Acked-by: Michal Privoznik <mprivozn@redhat.com>
2018-11-12 16:23:35 +01:00
Jiri Denemark
03abfd2a6e qemu: Drop priv->gotShutdown
The gotShutdown bool has been redundant since we started setting
VIR_DOMAIN_SHUTDOWN state after receiving SHUTDOWN event from QEMU.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2018-11-12 12:15:31 +01:00
Jiri Denemark
294397b63b qemu: Drop unreachable code from qemuProcessHandleStop
If gotShutdown is true, the domain state cannot be running because of
the following code in qemuProcessHandleShutdown:

    priv->gotShutdown = true;

    VIR_DEBUG("Transitioned guest %s to shutdown state",
              vm->def->name);
    virDomainObjSetState(vm,
                         VIR_DOMAIN_SHUTDOWN,
                         VIR_DOMAIN_SHUTDOWN_UNKNOWN);

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2018-11-12 12:15:31 +01:00
Wang Yechao
6b00f4f41c qemu: Fix segfault in qemuDomainPrimeVirtioDeviceAddresses
On aarch64, lauch vm with the follow configuration:

<interface type="hostdev" managed="yes">
  <mac address="fa:16:3e:14:41:00"/>
  <source>
    <address type="pci" domain="0x0000" bus="0x01" slot="0x0b" function="0x2"/>
  </source>
</interface>

libvirtd will crash when accessing net->model.

Signed-off-by: Wang Yechao <wang.yechao255@zte.com.cn>
Reviewed-by: Andrea Bolognani <abologna@redhat.com>
2018-11-09 09:56:35 +01:00
Eric Blake
68b2596f83 snapshot: Don't hose list on deletion failure
If qemuDomainSnapshotDiscard() fails for any reason (rare,
but possible with an ill-timed ENOMEM or if
qemuDomainSnapshotForEachQcow2() has problems talking to the
qemu guest monitor), then an attempt to retry the snapshot
deletion API will crash because we didn't undo the effects
of virDomainSnapshotDropParent() temporarily rearranging the
internal list structures, and the second attempt to drop
parents will dereference NULL.  Fix it by instead noting that
there are only two callers to qemuDomainSnapshotDiscard(),
and only one of the two callers wants the parent to be updated;
thus we can move the call to virDomainSnapshotDropParent()
into a code path that only gets executed on success.

Signed-off-by: Eric Blake <eblake@redhat.com>
ACKed-by: Michal Privoznik <mprivozn@redhat.com>
2018-11-08 07:19:27 -06:00
Jiri Denemark
e47949357b qemu: Don't ignore resume events
Since commit v4.7.0-302-ge6d77a75c4 processing RESUME event is mandatory
for updating domain state. But the event handler explicitly ignored this
event in some cases. Thus the state would be wrong after a fake reboot
or when a domain was rebooted after it crashed.

BTW, the code to ignore RESUME event after SHUTDOWN didn't make sense
even before making RESUME event mandatory. Most likely it was there as a
result of careless copy&paste from qemuProcessHandleStop.

The corresponding debug message was clarified since the original state
does not have to be "paused" only and while we have a "resumed" event,
the state is called "running".

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

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2018-11-08 09:08:58 +01:00
Julio Faracco
879fde3272 lxc: Clang is complaining about possible NULL pointer.
The array "mount" inside lxc_container is not being checked before for
loop. Clang syntax scan is complaining about this segmentation fault.

Signed-off-by: Julio Faracco <jcfaracco@gmail.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2018-11-07 16:22:16 -05:00
John Ferlan
8f0f8425d7 qemu: Narrow the shutdown reconnection failure reason window
The current qemuProcessReconnect logic paints a broad brush
determining that the shutdown reason must be crashed if it was
determined that the domain was started with -no-shutdown; however,
there's many other ways to get to the error label, so let's narrow
our reasoning window for using VIR_DOMAIN_SHUTOFF_CRASHED to the
period where we essentially know we've tried to create to the
monitor and before we were successful in opening the connection.

Failures that occur outside that window would thus be considered
as VIR_DOMAIN_SHUTOFF_UNKNOWN, at least for now.

Signed-off-by: John Ferlan <jferlan@redhat.com>
ACKed-by: Michal Privoznik <mprivozn@redhat.com>
2018-11-07 07:41:47 -05:00
John Ferlan
296e05b54b qemu: Restore lost shutdown reason
When qemuProcessReconnectHelper was introduced (commit d38897a5d)
reconnection failure used VIR_DOMAIN_SHUTOFF_FAILED; however, that
was changed in commit bda2f17d to either VIR_DOMAIN_SHUTOFF_CRASHED
or VIR_DOMAIN_SHUTOFF_UNKNOWN.

When QEMU_CAPS_NO_SHUTDOWN checking was removed in commit fe35b1ad6
the conditional state was just left at VIR_DOMAIN_SHUTOFF_CRASHED.

So introduce qemuDomainIsUsingNoShutdown which will manage the
condition when the domain was started with -no-shutdown so that
when/if reconnection failure occurs we can restore the decision
point used to determine whether CRASHED or UNKNOWN is provided.

Signed-off-by: John Ferlan <jferlan@redhat.com>
ACKed-by: Michal Privoznik <mprivozn@redhat.com>
2018-11-07 07:41:41 -05:00
Jim Fehlig
8496c17c53 libxl: Properly dispose libxl_domain_config object
V2 of the libxl soft reset patch, which was pushed as commit da4b0fd9,
dropped the hunk that disposed of the libxl_domain_config object. Add
the missing hunk to properly dispose the object.

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
2018-11-06 15:21:19 -07:00
Jim Fehlig
da4b0fd9d3 libxl: add support for soft reset
The pvops Linux kernel implements machine_ops.crash_shutdown as

static void xen_hvm_crash_shutdown(struct pt_regs *regs)
{
        native_machine_crash_shutdown(regs);
        xen_reboot(SHUTDOWN_soft_reset);
}

but currently the libxl driver does not handle the soft reset
shutdown event. As a result, the guest domain never proceeds
past xen_reboot(), making it impossible for HVM domains to save
a crash dump using kexec.

This patch adds support for handling the soft reset event by
calling libxl_domain_soft_reset() and re-enabling domain death
events, which is similar to the xl tool handling of soft reset
shutdown event.

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
ACKed-by: Michal Privoznik <mprivozn@redhat.com>
2018-11-06 09:10:27 -07:00
Jim Fehlig
82452a5d7f libxl: Remove some goto labels in libxlDomainShutdownThread
There are too many goto labels in libxlDomainShutdownThread. Convert the
'destroy' and 'restart' labels to helper functions, leaving only the
commonly used pattern of 'endjob' and 'cleanup' labels.

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
ACKed-by: Michal Privoznik <mprivozn@redhat.com>
2018-11-06 09:08:14 -07:00
Jim Fehlig
14d03b27bf libxl: remove redundant calls to virObjectEventStateQueue
In libxlDomainShutdownThread, virObjectEventStateQueue is needlessly
called in the destroy and restart labels. The cleanup label aready
queues whatever event was created based on libxl_shutdown_reason.
There is no need to handle destroy and restart differently.

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
ACKed-by: Michal Privoznik <mprivozn@redhat.com>
2018-11-06 09:06:45 -07:00
Ján Tomko
e08e792493 qemuBuildChrChardevStr: increase scope of qemuBuildChrChardevStr
Make it avaiable to other chardev types.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
2018-11-06 15:03:18 +01:00
Ján Tomko
4b8faeb9fe qemuBuildChrChardevStr: split attribute formatting
Remove repetition of the 'socket' device and its alias.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
2018-11-06 15:03:18 +01:00
Ján Tomko
7c94eebfe2 qemuProcessPrepareDomain: pass xmlopt when creating monConfig
Pass the driver's xmlopt to allocate the chardev source private
data correctly.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
2018-11-06 14:22:24 +01:00
Ján Tomko
912b8a5970 check-spacing: do not kill C++-style comments
Our HACKING guide forbids these.
There's no point in exempting these from the spacing check
if their existence is against our coding style.

Note that the non-usage of these comments itself is not enforced
by syntax check, probably because of the need to implement a C parser.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
2018-11-06 14:14:41 +01:00
John Ferlan
ccc72d5cbd access: Modify the VIR_ERR_ACCESS_DENIED to include driverName
https://bugzilla.redhat.com/show_bug.cgi?id=1631606

Changes made to manage and utilize a secondary connection
driver to APIs outside the scope of the primary connection
driver have resulted in some confusion processing polkit rules
since the simple "access denied" error message doesn't provide
enough of a clue when combined with the "authentication failed:
access denied by policy" as to which connection driver refused
or failed the ACL check.

In order to provide some context, let's modify the existing
"access denied" error returne from the various vir*EnsureACL
API's to provide the connection driver name that is causing
the failure. This should provide the context for writing the
polkit rules that would allow access via the driver.

Signed-off-by: John Ferlan <jferlan@redhat.com>
ACKed-by: Michal Privoznik <mprivozn@redhat.com>
2018-11-05 07:13:03 -05:00
Nikolay Shirokovskiy
67125e0d33 nwfilter: Instantiate active filter bindings during driver init
Commit 57f5621f modified nwfilterInstantiateFilter to detect when
a filter binding was already present before attempting to add the
new binding and instantiate it. Additionally, the change to
nwfilterStateInitialize to call virNWFilterBindingObjListLoadAllConfigs
(from commit c21679fa3f) to load active domain filter bindings, but
not instantiate them eventually leads to a problem for the QEMU
driver reconnection logic after a daemon restart where the filter
bindings would no longer be instantiated.

Subsequent commit f14c37ce4c replaced the nwfilterInstantiateFilter
with virDomainConfNWFilterInstantiate which uses @ignoreExists to
detect presence of the filter and still did not restore the filter
instantiation call when making the new nwfilter bindings logic active.

Thus in order to instantiate any active domain filter, we will call
virNWFilterBuildAll with 'false' to indicate the need to go through
all the active bindings calling virNWFilterInstantiateFilter to
instantiate the filter bindings.

Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2018-11-05 07:10:47 -05:00
John Ferlan
29183778af nodedev: Document the udevEventHandleThread
Commit cdbe1332 neglected to document the API. So let's add some
details about the algorithm and why it was used to help future
readers understand the issues encountered.

NB: Management of the processing udev device notification is a
delicate balance between the udev process, the scheduler, and when
exactly the data from/for the socket is received. The balance is
particularly important for environments when multiple devices are
added into the system more or less simultaneously such as is done
for mdev or SRIOV. In these cases old libudev blocking on the udev
recv() occurs more frequently. It's expected that future devices
will follow similar algorithms. Even though the algorithm does
present some challenges for older OS's (such as Centos 6), trying
to rewrite the algorithm to fit both models would be more complex
and involve pulling the monitor object out of the private data
lockable object and would need to be guarded by a separate lock.
Devising such an algorithm to work around issues with older OS's
at the expense of more modern OS algorithms in newer event processing
code may result in unexpected issues, so the choice is to encourage
use of newer OS's with newer udev event processing code.

Signed-off-by: John Ferlan <jferlan@redhat.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
2018-11-05 07:05:45 -05:00
Michal Privoznik
4de4e4bc99 qemu: Dissolve qemuBuildVhostuserCommandLine in qemuBuildInterfaceCommandLine
https://bugzilla.redhat.com/show_bug.cgi?id=1524230

The qemuBuildVhostuserCommandLine builds command line for
vhostuser type interfaces. It is duplicating some code of the
function it is called from (qemuBuildInterfaceCommandLine)
because of the way it's called. If we merge it into the caller
not only we save a few lines but we also enable checks that we
would have to duplicate otherwise (e.g. QoS availability).

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
2018-11-05 08:52:56 +01:00
Michal Privoznik
e7b7b61768 qemuBuildInterfaceCommandLine: Reorder VIR_FREE
When we have variables A, B, C then there are two ways to free
them. Either in the order they are declared or the reversed one.
Any other ordering is confusing. In this commit I'm reordering
calls to VIR_FREE in the reversed order.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
2018-11-05 08:52:56 +01:00
Daniel P. Berrangé
5a128712bc rpc: fix handling of SSH auth failure code
The result of libssh2_userauth_password is being assigned to 'ret' in
one branch and 'rc' in the other branch. Checks are all done against the
'ret' variable, so one branch never does the correct check.

Reviewed-by: Andrea Bolognani <abologna@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2018-10-30 16:31:52 +00:00
Boris Fiuczynski
1170864198 qemu: vfio-ap device support
Adjusting domain format documentation, adding device address
support and adding command line generation for vfio-ap.
Since only one mediated hostdev with model vfio-ap is supported a check
disallows to define domains with more than one such hostdev device.

Signed-off-by: Boris Fiuczynski <fiuczy@linux.ibm.com>
Reviewed-by: Bjoern Walk <bwalk@linux.ibm.com>
Reviewed-by: Chris Venteicher <cventeic@redhat.com>
2018-10-29 12:45:54 -04:00
Boris Fiuczynski
dc788d2540 qemu: add vfio-ap capability
Introduce vfio-ap capability.

Signed-off-by: Boris Fiuczynski <fiuczy@linux.ibm.com>
Reviewed-by: Bjoern Walk <bwalk@linux.ibm.com>
Reviewed-by: Thomas Huth <thuth@redhat.com>
Reviewed-by: Chris Venteicher <cventeic@redhat.com>
2018-10-29 12:45:54 -04:00
Martin Kletzander
62bac69542 util: Fix typo vcups -> vcpus
Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2018-10-22 14:37:54 +01:00
Jie Wang
58cfd0a135 qemu: Fix IOThread pids lost after qemuProcessReconnect
IOThread pids info will lost after libvirtd restart, then
if we call pinIOThread, sched_setaffinity will be called with
pid 0, not IOThread pid. So pinIOThread cannot work normally.

Signed-off-by: Jie Wang <wangjie88.huawei.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2018-10-19 14:01:58 -04:00
Eric Blake
ffac10c971 qemu: Avoid memleak on failure to format blockjobs
virXMLFormatElement() frees attrBuf on success, but not necessarily
on failure. Most other callers of this function take the time to
reset attrBuf afterwords, but qemuDomainObjPrivateXMLFormatBlockjobs()
was relying on it succeeding, and could thus result in a memory leak.

Signed-off-by: Eric Blake <eblake@redhat.com>
ACKed-by: Michal Privoznik <mprivozn@redhat.com>
2018-10-19 10:33:19 -05:00
Michal Privoznik
c0790e3a09 virfile: Take symlink into account in virFileIsSharedFixFUSE
https://bugzilla.redhat.com/show_bug.cgi?id=1640465

Weirdly enough, there can be symlinks in the path we are trying
to fix. If it is the case our clever algorithm that finds matches
against mount table won't work. Canonicalize path at the
beginning then.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
2018-10-19 13:15:54 +02:00
Michal Privoznik
f4966b8522 virFileInData: Preserve errno on error
The virFileInData() function should return to the caller if the
current position the passed file is in is a data section or a
hole (and also how long the current section is). At any rate,
upon return from this function (be it successful or not) the
original position in the file is restored. This may mess up with
errno which might have been set earlier. Save the errno into a
local variable so it can be restored for the caller's sake.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
2018-10-19 13:07:49 +02:00
Bjoern Walk
808e27a109 qemu: qemuProcessInit: Drop unused config variable
The QEMU @cfg config variable is unused in context of qemuProcessInit,
let's drop it.

Signed-off-by: Bjoern Walk <bwalk@linux.ibm.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
2018-10-18 11:37:55 +02:00
Nikolay Shirokovskiy
49825dcf31 nwfilter: Fix learning address thread shutdown
If the learning thread is configured to learn on all ethernet frames
(which is hardcoded) then chances are high that there is a packet on
every iteration of inspecting frames loop. As result we will hang on
shutdown because we don't check threadsTerminate if there is packet.

Let's just check termination conditions on every iteration. Since
we'll check each iteration, the check after pcap_next essentially
is unnecessary since on failure we'd loop back to the top and timeout
and then fail.

Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2018-10-17 17:06:04 -04:00
Wang Huaqiang
b05eeacbfd util: Fix a typo in comments of virresctrl.c
Signed-off-by: Wang Huaqiang <huaqiang.wang@intel.com>
Reviewed-by: Andrea Bolognani <abologna@redhat.com>
2018-10-17 13:52:07 +02:00
Han Han
80c8237679 conf: Fix typos in pcie controllers' name
Signed-off-by: Han Han <hhan@redhat.com>
Reviewed-by: Andrea Bolognani <abologna@redhat.com>
2018-10-17 10:47:50 +02:00
Michal Privoznik
641a95c9b6 qemu: Put format=raw onto cmd line for SCSI passthrough
https://bugzilla.redhat.com/show_bug.cgi?id=1632833

When doing a SCSI passthrough we don't put format= onto the
command line. This causes qemu to probe the format automatically
which ends up in a warning in the domain log and possible qemu
disabling writes to the first block (according to the warning
message).

Based-on-work-of: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
2018-10-17 09:16:20 +02:00
Wang Huaqiang
3a1cdb06fd conf: Fix bug in finding alloc through matching vcpus
The @alloc object returned by virDomainResctrlVcpuMatch is not
properly referenced and un-referenced in virDomainCachetuneDefParse.

This patch fixes this problem.

Signed-off-by: Wang Huaqiang <huaqiang.wang@intel.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2018-10-15 11:03:23 -04:00
Peter Krempa
6e7e965dcd util: storage: Properly parse URIs with missing trailing slash
The URI parser used by libvirt does not populate uri->path if the
trailing slash is missing. The code virStorageSourceParseBackingURI
would then not populate src->path.

As only NBD network disks are allowed to have the 'name' field in the
XML defining the disk source omitted we'd generate an invalid XML which
we'd not parse again.

Fix it by populating src->path with an empty string if the uri is
lacking slash.

As pointed out above NBD is special in this case since we actually allow
it being NULL. The URI path is used as export name. Since an empty
export does not make sense the new approach clears the src->path if the
trailing slash is present but nothing else.

Add test cases now to cover all the various cases for NBD and non-NBD
uris as there was to time only 1 test abusing the quirk witout slash for
NBD and all other URIs contained the slash or in case of NBD also the
export name.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
2018-10-12 16:41:48 +02:00
Peter Krempa
4471f7704c util: storage: Rename '@path' argument of virStorageSourceParseBackingURI
The name is misleading. Change it to 'uristr' so that 'path' can be
reused in the proper context later.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
2018-10-12 16:41:48 +02:00
Olaf Hering
297ed93ae0 rpc: reproducible genprotocol output
If the same source gets built twice ('build same source on different
hosts at different times') the resulting files may differ.
Fix this by sorting the hash keys before usage.

Signed-off-by: Olaf Hering <olaf@aepfle.de>
2018-10-12 14:44:43 +02:00
John Ferlan
86a6cb13e9 qemu: Remove unused qemuProcessAutostartAll
The function was never defined in source, just the protoype.

Signed-off-by: John Ferlan <jferlan@redhat.com>
2018-10-11 18:26:00 -04:00
Michal Privoznik
1dbf6222dd virfile: Rework virFileIsSharedFixFUSE
There are couple of things wrong with the current implementation.
The first one is that in the first loop the code tries to build a
list of fuse.glusterfs mount points. Well, since the strings are
allocated in a temporary buffer and are not duplicated this
results in wrong decision made later in the code.

The second problem is that the code does not take into account
subtree mounts. For instance, if there's a fuse.gluster mounted
at /some/path and another FS mounted at /some/path/subdir the
code would not recognize this subdir mount.

Reported-by: Han Han <hhan@redhat.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
2018-10-10 17:14:45 +02:00
Michal Privoznik
98ca1d52a2 virFileIsSharedFSType: Detect direct mount points
If the given path is already a mount point (e.g. a bind mount of
a file, or simply a direct mount point of a FS), then our code
fails to detect that because the first thing it does is cutting
off part after last slash '/'.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
2018-10-10 17:14:05 +02:00
Marc Hartmayer
2b03534eeb virfile: fix cast-align error
On s390x the struct member f_type of statsfs is hard coded to 'unsigned
int'. Change virFileIsSharedFixFUSE() to take a 'long long int' and use
a temporary to avoid pointer-casting.

This fixes the following error:
../../src/util/virfile.c:3578:38: error: cast increases required alignment of target type [-Werror=cast-align]
         virFileIsSharedFixFUSE(path, (long *) &sb.f_type);

Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Signed-off-by: Bjoern Walk <bwalk@linux.ibm.com>
2018-10-10 16:53:13 +02:00
Ján Tomko
7bff646d71 virresctrl: remove bogus virResetLastError
virFileReadValueUint does not log errors for non-existient files,
it merely returns -2.

Commit 12093f1 introduced this.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
2018-10-09 10:04:56 +02:00
Ján Tomko
f4ccf1ecdc qemu: use "id" instead of deprecated "name" for -net
-net name= will be deprecated in QEMU 3.1:
commit 101625a4d4ac7e96227a156bc5f6d21a9cc383cd
    net: Deprecate the "name" parameter of -net
git describe: v3.0.0-791-g101625a4d4

Use the id option instead, supported since QEMU 1.2:
commit 6687b79d636cd60ed9adb1177d0d946b58fa7717
    convert net_client_init() to OptsVisitor
git describe: v1.0-3564-g6687b79d63 contains: v1.2.0-rc0~142^2~8

Thankfully, libvirt only uses -net for non-PCI, non-virtio NICs
on ARM.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Laine Stump <laine@laine.org>
Reviewed-by: Thomas Huth <thuth@redhat.com>
2018-10-09 09:44:36 +02:00
Peter Krempa
0d981bcefc qemu: hotplug: Refactor qemuDomainAttachDeviceDiskLiveInternal
We now explicitly handle media change elsewhere so we can drop the
switch statement. This will also make it more intuitive once CDROM
device hotplug might be supported.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
2018-10-08 15:35:18 +02:00
Peter Krempa
a1d3fc09f8 qemu: hotplug: Split out media change code from disk hotplug
Disk hotplug has slightly different semantics from media changing. Move
the media change code out and add proper initialization of the new
source object and proper cleanups if something fails.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
2018-10-08 15:35:18 +02:00
Peter Krempa
a05bdd5533 qemu: conf: Export qemuAddSharedDisk
In cases where we know the device is a disk we can avoid using the full
device definition.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
2018-10-08 15:35:18 +02:00
Peter Krempa
aa2be13674 qemu: hotplug: Add wrapper for disk hotplug code
The disk hotplug code also overloads media change which is not ideal.
This will allow splitting out of the media change code.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
2018-10-08 15:35:18 +02:00
Peter Krempa
49272e5162 qemu: hotplug: Prepare disk source for media changing
The disk storage source needs to be prepared if we want to use -blockdev
or secrets for the new media image. It does not hurt to do the same for
the legacy hotplug code as well.

Unfortunately helpers like qemuDomainPrepareDiskSource take
virDomainDiskDef as an argument and it would be hard to fix them to take
an explicit source, so the function also temporarily replaces disk->src
for the new source in this function.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
2018-10-08 15:35:18 +02:00
Peter Krempa
f86993112a qemu: hotplug: Be explicit about old/new sources when changing media
Some functions require us to replace disk->src with the new source for
them to work properly. To avoid confusion all places which allow
explicit virStorageSource should get the appropriate definition.

The legacy code fortunately does not need anything from the old source
so that does not require modifications.

Blockdev does require the old definition so we'll pass it explicitly.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
2018-10-08 15:35:18 +02:00
Peter Krempa
50cb91dbc5 qemu: hotplug: Allow specifying explicit source for disk backend hotplug code
Since the code is also used when changing media we need to allow
specifying explicit source for which we are going to prepare. With this
change callers don't have to replace disk->src with the new source
definition for generating these.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
2018-10-08 15:35:18 +02:00
Peter Krempa
7fec0e59d3 qemu: hotplug: Remove code handling possible missing disk source format
qemu media changing code tried to assume old media's format for the new
one if that was not specified. Since the format will always be present
it does not make sense to keep the code around.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
2018-10-08 15:35:18 +02:00
Peter Krempa
6a84053789 qemu: hotplug: Don't pretend that we support secrets for media change
Old media changing code does not bother setting up the secrets for new
media or actually removing/adding of the corresponding objects.

Additionally it uses secrets setup for the old image to be removed as
the secret for the new image which is wrong.

Remove the support for secrets while changing media for the legacy
approach. The only reasonable way to fix it is when using blockdev.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
2018-10-08 12:37:07 +02:00
Peter Krempa
f479b34245 Revert "qemu: hotplug: consolidate media change code paths"
While the idea was good the implementation not so much as we need to
take into account the old disk data and the new source. The code will be
consolidated later in a different way.

This reverts commit 663b1d55de.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
2018-10-08 12:37:07 +02:00
Peter Krempa
9ac1969978 Revert "qemu: hotplug: Prepare disk source in qemuDomainAttachDeviceDiskLive"
Preparing the storage source prior to assigning the alias will not work
as the names of the certain objects depend on the alias for the legacy
hotplug case as we generate the object names for the secrets based on
the alias.

This reverts commit 192fdaa614.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
2018-10-08 12:37:07 +02:00
Pavel Hrdina
b79d858518 vircgroup: add support for hybrid configuration
This enables to use both cgroup v1 and v2 at the same time together
with libvirt.  It is supported by kernel and there is valid use-case,
not all controllers are implemented in cgroup v2 so there might be
configurations where administrator would enable these missing
controllers in cgroup v1.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2018-10-05 15:53:29 +02:00
Pavel Hrdina
a77f532691 vircgroup: register cgroup v2 backend
All mandatory callbacks are implemented for cgroup v2 backend so we
can register it now.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2018-10-05 15:53:29 +02:00
Pavel Hrdina
4d1d5c92bd vircgroup: introduce virCgroupV2GetCpuacctStat
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2018-10-05 15:53:29 +02:00
Pavel Hrdina
567fcbdca5 vircgroup: introduce virCgroupV2GetCpuacctUsage
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2018-10-05 15:53:29 +02:00
Pavel Hrdina
5a4d90ae6a vircgroup: introduce virCgroupV2SupportsCpuBW
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2018-10-05 15:53:29 +02:00
Pavel Hrdina
8e2c887ffa vircgroup: introduce virCgroupV2(Set|Get)CpuCfsQuota
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2018-10-05 15:53:29 +02:00
Pavel Hrdina
8324224572 vircgroup: introduce virCgroupV2(Set|Get)CpuCfsPeriod
In order to set CPU cfs period using cgroup v2 'cpu.max' interface
we need to load the current value of CPU cfs quota first because
format of 'cpu.max' interface is '$quota $period' and in order to
change 'period' we need to write 'quota' as well.  Writing only one
number changes only 'quota'.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2018-10-05 15:53:29 +02:00
Pavel Hrdina
b8ca5afc22 vircgroup: introduce virCgroupV2(Set|Get)CpuShares
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2018-10-05 15:53:29 +02:00
Pavel Hrdina
3f728c720b vircgroup: introduce virCgroupV2GetMemSwapUsage
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2018-10-05 15:53:29 +02:00
Pavel Hrdina
df63fd1f8f vircgroup: introduce virCgroupV2(Set|Get)MemSwapHardLimit
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2018-10-05 15:53:29 +02:00
Pavel Hrdina
94db4bf86e vircgroup: introduce virCgroupV2(Set|Get)MemorySoftLimit
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2018-10-05 15:53:29 +02:00
Pavel Hrdina
2aa5385c58 vircgroup: introduce virCgroupV2(Set|Get)MemoryHardLimit
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2018-10-05 15:53:29 +02:00
Pavel Hrdina
495f60edcb vircgroup: introduce virCgroupV2GetMemoryUsage
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2018-10-05 15:53:29 +02:00
Pavel Hrdina
d080c00166 vircgroup: introduce virCgroupV2GetMemoryStat
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2018-10-05 15:53:29 +02:00
Pavel Hrdina
63bd23a6ad vircgroup: introduce virCgroupV2SetMemory
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2018-10-05 15:53:29 +02:00
Pavel Hrdina
91756fb64a vircgroup: introduce virCgroupV2(Set|Get)BlkioDeviceWriteBps
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2018-10-05 15:53:29 +02:00
Pavel Hrdina
353ce9453e vircgroup: introduce virCgroupV2(Set|Get)BlkioDeviceReadBps
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2018-10-05 15:53:29 +02:00
Pavel Hrdina
438587033b vircgroup: introduce virCgroupV2(Set|Get)BlkioDeviceWriteIops
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2018-10-05 15:53:29 +02:00
Pavel Hrdina
862f630825 vircgroup: introduce virCgroupV2(Set|Get)BlkioDeviceReadIops
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2018-10-05 15:53:29 +02:00
Pavel Hrdina
568f746eaf vircgroup: introduce virCgroupV2(Set|Get)BlkioDeviceWeight
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2018-10-05 15:53:29 +02:00
Pavel Hrdina
93fa369df5 vircgroup: introduce virCgroupV2GetBlkioIoDeviceServiced
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2018-10-05 15:53:29 +02:00
Pavel Hrdina
709260add9 vircgroup: introduce virCgroupV2GetBlkioIoServiced
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2018-10-05 15:53:29 +02:00
Pavel Hrdina
11bb7f1561 vircgroup: introduce virCgroupV2(Set|Get)BlkioWeight
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2018-10-05 15:53:29 +02:00
Pavel Hrdina
525ac6885b vircgroup: introduce virCgroupV2SetOwner
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2018-10-05 15:53:29 +02:00
Pavel Hrdina
cda8ed0646 vircgroup: introduce virCgroupV2BindMount
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2018-10-05 15:53:29 +02:00
Pavel Hrdina
38411bb831 vircgroup: introduce virCgroupV2HasEmptyTasks
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2018-10-05 15:53:29 +02:00
Pavel Hrdina
48572f8825 vircgroup: introduce virCgroupV2AddTask
In cgroups v2 we need to handle threads and processes differently.
If you need to move a process you need to write its pid into
cgrou.procs file and it will move the process with all its threads
as well.  The whole process will be moved if you use tid of any thread.

In order to move only threads at first we need to create threaded group
and after that we can write the relevant thread tids into cgroup.threads
file.  Threads can be moved only into cgroups that are children of
cgroup of its process.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2018-10-05 15:53:29 +02:00
Pavel Hrdina
4fe4847438 vircgroup: introduce virCgroupV2Remove
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2018-10-05 15:53:29 +02:00
Pavel Hrdina
89f52abd07 vircgroup: introduce virCgroupV2MakeGroup
When creating cgroup hierarchy we need to enable controllers in the
parent cgroup in order to be usable.  That means writing "+{controller}"
into cgroup.subtree_control file.  We can enable only controllers that
are enabled for parent cgroup, that means we need to do that for the
whole cgroup tree.

Cgroups for threads needs to be handled differently in cgroup v2.  There
are two types of controllers:

    - domain controllers: these cannot be enabled for threads
    - threaded controllers: these can be enabled for threads

In addition there are multiple types of cgroups:

    - domain: normal cgroup
    - domain threaded: a domain cgroup that serves as root for threaded
                       cgroups
    - domain invalid: invalid cgroup, can be changed into threaded, this
                      is the default state if you create subgroup inside
                      domain threaded group or threaded group
    - threaded: threaded cgroup which can have domain threaded or
                threaded as parent group

In order to create threaded cgroup it's sufficient to write "threaded"
into cgroup.type file, it will automatically make parent cgroup
"domain threaded" if it was only "domain".  In case the parent cgroup
is already "domain threaded" or "threaded" it will modify only the type
of current cgroup.  After that we can enable threaded controllers.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2018-10-05 15:53:29 +02:00
Pavel Hrdina
0542640a9c vircgroup: introduce virCgroupV2PathOfController
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2018-10-05 15:53:29 +02:00
Pavel Hrdina
171c700cd8 vircgroup: introduce virCgroupV2GetAnyController
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2018-10-05 15:53:29 +02:00
Pavel Hrdina
c8f08a5346 vircgroup: introduce virCgroupV2HasController
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2018-10-05 15:53:29 +02:00
Pavel Hrdina
e1bb7fffe2 vircgroup: introduce virCgroupV2DetectControllers
Cgroup v2 has only single mount point for all controllers.  The list
of controllers is stored in cgroup.controllers file, name of controllers
are separated by space.

In cgroup v2 there is no cpuacct controller, the cpu.stat file always
exists with usage stats.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2018-10-05 15:53:29 +02:00
Pavel Hrdina
f7394dcf01 vircgroup: introduce virCgroupV2StealPlacement
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2018-10-05 15:53:29 +02:00
Pavel Hrdina
9aa8226d86 vircgroup: introduce virCgroupV2ValidatePlacement
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2018-10-05 15:53:29 +02:00
Pavel Hrdina
1efcf202e7 vircgroup: introduce virCgroupV2DetectPlacement
If the placement was copied from parent or set to absolute path
there is nothing to do, otherwise set the placement based on
process placement from /proc/self/cgroup or /proc/{pid}/cgroup.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2018-10-05 15:53:29 +02:00
Pavel Hrdina
50f61a46fc vircgroup: introduce virCgroupV2DetectMounts
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2018-10-05 15:53:29 +02:00
Pavel Hrdina
7a86201dd6 vircgroup: introduce virCgroupV2CopyPlacement
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2018-10-05 15:53:29 +02:00
Pavel Hrdina
38a3fb5647 vircgroup: introduce virCgroupV2CopyMounts
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2018-10-05 15:53:29 +02:00
Pavel Hrdina
3a365ef697 vircgroup: introduce virCgroupV2ValidateMachineGroup
When reconnecting to a domain we are validating the cgroup name.
In case of cgroup v2 we need to validate only the new format for host
without systemd '{machinename}.libvirt-{drivername}' or scope name
generated by systemd.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2018-10-05 15:53:29 +02:00
Pavel Hrdina
034ef217d7 vircgroup: introduce virCgroupV2Available
We cannot detect only mount points to figure out whether cgroup v2
is available because systemd uses cgroup v2 for process tracking and
all controllers are mounted as cgroup v1 controllers.

To make sure that this is no the situation we need to check
'cgroup.controllers' file if it's not empty to make sure that cgroup
v2 is not mounted only for process tracking.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2018-10-05 15:53:29 +02:00
Pavel Hrdina
b4ddf5ae62 util: introduce cgroup v2 files
Place cgroup v2 backend type before cgroup v1 to make it obvious
that cgroup v2 is preferred implementation.

Following patches will introduce support for hybrid configuration
which will allow us to use both at the same time, but we should
prefer cgroup v2 regardless.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2018-10-05 15:53:29 +02:00
Ján Tomko
e7730d196b qemu: fix comment in qemuSecurityChownCallback
s/chmod/chown/

Signed-off-by: Ján Tomko <jtomko@redhat.com>
2018-10-04 10:01:08 +02:00
Ján Tomko
8ba65c4d95 qemu: fix up permissions for pre-created UNIX sockets
My commit d6b8838 fixed the uid:gid for the pre-created UNIX sockets
but did not account for the different umask of libvirtd and QEMU.
Since commit 0e1a1a8c we set umask to '0002' for the QEMU process.
Manually tune-up the permissions to match what we would have gotten
if QEMU had created the socket.

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

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
2018-10-03 16:26:08 +02:00
Michal Privoznik
478da65fb4 virFileIsSharedFSType: Check for fuse.glusterfs too
https://bugzilla.redhat.com/show_bug.cgi?id=1632711

GlusterFS is typically safe when it comes to migration. It's a
network FS after all. However, it can be mounted via FUSE driver
they provide. If that is the case we fail to identify it and
think migration is not safe and require VIR_MIGRATE_UNSAFE flag.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
2018-10-03 13:50:19 +02:00
Jiri Denemark
5cae1f47c4 cpu_map: Use and install Icelake model definitions
In commit v4.7.0-168-g993d85ae5e I introduced two Icelake CPU models,
but failed to actually include them in the CPU map index.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2018-10-03 13:00:54 +02:00
Ján Tomko
d6b8838dd8 security: dac: also label listen UNIX sockets
We switched to opening mode='bind' sockets ourselves:
commit 30fb2276d8
    qemu: support passing pre-opened UNIX socket listen FD
in v4.5.0-rc1~251

Then fixed qemuBuildChrChardevStr to change libvirtd's label
while creating the socket:
commit b0c6300fc4
    qemu: ensure FDs passed to QEMU for chardevs have correct SELinux labels
v4.5.0-rc1~52

Also add labeling of these sockets to the DAC driver.
Instead of duplicating the logic which decides whether libvirt should
pre-create the socket, assume an existing path meaning that it was created
by libvirt.

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

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
2018-10-02 12:44:44 +02:00
Marc Hartmayer
9f81dc1081 qemu: Introduce qemuDomainUpdateQEMUCaps()
This function updates the used QEMU capabilities of @vm by querying
the QEMU capabilities cache.

Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Reviewed-by: Boris Fiuczynski <fiuczy@linux.ibm.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2018-10-01 18:35:47 -04:00
Marc Hartmayer
a4c12a5096 qemu: Use VIR_STEAL_PTR macro
Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Reviewed-by: Bjoern Walk <bwalk@linux.ibm.com>
Reviewed-by: Boris Fiuczynski <fiuczy@linux.ibm.com>
Reviewed-by: Stefan Zimmermann <stzi@linux.ibm.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2018-10-01 18:35:32 -04:00
John Ferlan
3a286a4e26 nwfilter: Alter virNWFilterSnoopReqLeaseDel logic
Move the fetch of @ipAddrLeft to after the goto skip_instantiate
and remove the (req->binding) guard since we know that as long
as req->binding is created, then req->threadkey is filled in.

Found by Coverity

Signed-off-by: John Ferlan <jferlan@redhat.com>
ACKed-by: Michal Privoznik <mprivozn@redhat.com>
2018-10-01 14:27:47 -04:00
John Ferlan
efdbfe57c7 util: Data overrun may lead to divide by zero
Commit 87a8a30d6 added the function based on the virsh function,
but used an unsigned long long instead of a double and thus that
limits the maximum result.

Signed-off-by: John Ferlan <jferlan@redhat.com>
ACKed-by: Michal Privoznik <mprivozn@redhat.com>
2018-10-01 14:27:31 -04:00
John Ferlan
425b9f8aa6 libxl: Fix possible object refcnt issue
When libxlDomainMigrationDstPrepare adds the @args to an
virNetSocketAddIOCallback using libxlMigrateDstReceive as
the target of the virNetSocketIOFunc @func with the knowledge
that the libxlMigrateDstReceive will virObjectUnref @args
at the end thus not needing to Unref during normal processing
for libxlDomainMigrationDstPrepare.

However, Coverity believes there's an issue with this. The
problem is there can be @nsocks virNetSocketAddIOCallback's
added, but only one virObjectUnref. That means the first
one done will Unref and the subsequent callers may not get
the @args (or @opaque) as they expected. If there's only
one socket returned from virNetSocketNewListenTCP, then sure
that works. However, if it returned more than one there's
going to be a problem.

To resolve this, since we start with 1 reference from the
virObjectNew for @args, we will add 1 reference for each
time @args is used for virNetSocketAddIOCallback. Then
since libxlDomainMigrationDstPrepare would be done with
@args, move it's virObjectUnref from the error: label to
the done: label (since error: falls through). That way
once the last IOCallback is done, then @args will be freed.

Signed-off-by: John Ferlan <jferlan@redhat.com>
ACKed-by: Michal Privoznik <mprivozn@redhat.com>
2018-10-01 14:27:18 -04:00
John Ferlan
6830c81307 lxc: Only check @nparams in lxcDomainBlockStatsFlags
Remove the "!params" check from the condition since it's possible
someone could pass a non NULL value there, but a 0 for the nparams
and thus continue on.  The external API only checks if @nparams is
non-zero, then check for NULL @params.

Found by Coverity

Signed-off-by: John Ferlan <jferlan@redhat.com>
ACKed-by: Michal Privoznik <mprivozn@redhat.com>
2018-10-01 14:27:07 -04:00
Julio Faracco
125ac4c0a8 uml: umlConnectOpen: Check the driver pointer before accessing it
The pointer related to uml_driver needs to be checked before its usage
inside the function. Some attributes of the driver are being accessed
while the pointer is NULL considering the current logic.

Signed-off-by: Julio Faracco <jcfaracco@gmail.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
2018-10-01 09:13:44 +02:00
Pavel Hrdina
199eee6aae Revert "vircgroup: cleanup controllers not managed by systemd on error"
This reverts commit 1602aa28f8.

There is no need to call virCgroupRemove() nor virCgroupFree() if
virCgroupEnableMissingControllers() fails because it will not modify
'group' at all.

The cleanup of directories is done in virCgroupMakeGroup().

Reviewed-by: John Ferlan <jferlan@redhat.com>
Reviewed-by: Fabiano Fidêncio <fidencio@redhat.com>
Reviewed-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2018-09-28 19:51:01 +02:00
Michal Privoznik
466bea0117 qemu: Temporarily disable metadata locking
Turns out, there are couple of bugs that prevent this feature
from being operational. Given how close to the release we are
disable the feature temporarily. Hopefully, it can be enabled
back after all the bugs are fixed.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
2018-09-27 16:22:44 +02:00
Pavel Hrdina
0615c8436a vircgroupv1: fix build on non-linux OSes
Cgroups are linux specific and we need to make sure that the code is
compiled only on linux.  On different OSes it fails the compilation:

../../src/util/vircgroupv1.c:65:19: error: variable has incomplete type 'struct mntent'
    struct mntent entry;
                  ^
../../src/util/vircgroupv1.c:65:12: note: forward declaration of 'struct mntent'
    struct mntent entry;
           ^
../../src/util/vircgroupv1.c:74:12: error: implicit declaration of function 'getmntent_r' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
    while (getmntent_r(mounts, &entry, buf, sizeof(buf)) != NULL) {
           ^
../../src/util/vircgroupv1.c:814:39: error: use of undeclared identifier 'MS_NOSUID'
    if (mount("tmpfs", root, "tmpfs", MS_NOSUID|MS_NODEV|MS_NOEXEC, opts) < 0) {
                                      ^
../../src/util/vircgroupv1.c:814:49: error: use of undeclared identifier 'MS_NODEV'
    if (mount("tmpfs", root, "tmpfs", MS_NOSUID|MS_NODEV|MS_NOEXEC, opts) < 0) {
                                                ^
../../src/util/vircgroupv1.c:814:58: error: use of undeclared identifier 'MS_NOEXEC'
    if (mount("tmpfs", root, "tmpfs", MS_NOSUID|MS_NODEV|MS_NOEXEC, opts) < 0) {
                                                         ^
../../src/util/vircgroupv1.c:841:65: error: use of undeclared identifier 'MS_BIND'
            if (mount(src, group->legacy[i].mountPoint, "none", MS_BIND,
                                                                ^

Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2018-09-27 13:08:40 +02:00
Pavel Hrdina
6ef37ed3b8 vircgroup: include system headers only on linux
All the system headers are used only if we are compiling on linux
and they all are present otherwise we would have seen build errors
because in our tests/vircgrouptest.c we use only __linux__ to check
whether to skip the cgroup tests or not.

Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2018-09-27 13:08:37 +02:00
Pavel Hrdina
0df6266988 vircgroup: remove VIR_CGROUP_SUPPORTED
tests/vircgrouptest.c uses #ifdef __linux__ for a long time and no
failure was reported so far so it's safe to assume that __linux__ is
good enough to guard cgroup code.

Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2018-09-27 13:08:26 +02:00
Lin Ma
79e0e62e78 qemu: Remove network type limitation for qemuARPGetInterfaces
Let's ignore the checking of interface type when we call the function
qemuARPGetInterfaces to get IP from host's arp table.

Signed-off-by: Lin Ma <lma@suse.com>
Reviewed-by: Chen Hanxiao <chenhanxiao@gmail.com>
2018-09-26 14:57:41 +02:00
Michal Privoznik
cd33eaa251 security: Don't try to lock NULL paths
It may happen that in the list of paths/disk sources to relabel
there is a disk source. If that is the case, the path is NULL. In
that case, we shouldn't try to lock the path. It's likely a
network disk anyway and therefore there is nothing to lock.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
2018-09-26 12:01:48 +02:00
Michal Privoznik
f4d7ca62a4 security: Grab a reference to virSecurityManager for transactions
This shouldn't be needed per-se. Security manager shouldn't
disappear during transactions - it's immutable. However, it
doesn't hurt to grab a reference either - transaction code uses
it after all.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2018-09-26 12:01:36 +02:00
Michal Privoznik
72a8b8ecc5 virSecuritySELinuxContextListFree: Don't leak list->items
This array is allocated in virSecuritySELinuxContextListAppend()
but never freed. This commit is essentially the same as ca25026.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2018-09-26 12:01:32 +02:00
Marc Hartmayer
9580c09163 virdbus: Use the mnemonic macros for dbus_bool_t values
Use the mnemonic macros of libdbus for 1 (TRUE) and 0 (FALSE).

Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Reviewed-by: Bjoern Walk <bwalk@linux.ibm.com>
Reviewed-by: Boris Fiuczynski <fiuczy@linux.ibm.com>
Reviewed-by: Stefan Zimmermann <stzi@linux.ibm.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2018-09-25 19:27:55 -04:00
Marc Hartmayer
07e01beb35 virdbus: Report a debug message that dbus_watch_handle() has failed
Report a debug message if dbus_watch_handle() returns FALSE.
dbus_watch_handle() returns FALSE if there wasn't enough memory for
reading or writing.

Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Reviewed-by: Bjoern Walk <bwalk@linux.ibm.com>
Reviewed-by: Boris Fiuczynski <fiuczy@linux.ibm.com>
Reviewed-by: Stefan Zimmermann <stzi@linux.ibm.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2018-09-25 19:27:47 -04:00
Marc Hartmayer
eedf83ceca virdbus: Unref the D-Bus connection when closing
As documented at
https://dbus.freedesktop.org/doc/api/html/group__DBusConnection.html#ga2522ac5075dfe0a1535471f6e045e1ee
the creator of a non-shared D-Bus connection has to release the last
reference after closing for freeing.

Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Reviewed-by: Bjoern Walk <bwalk@linux.ibm.com>
Reviewed-by: Boris Fiuczynski <fiuczy@linux.ibm.com>
Reviewed-by: Stefan Zimmermann <stzi@linux.ibm.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2018-09-25 19:27:41 -04:00
Marc Hartmayer
6707ffd11c virdbus: Grab a ref as long as the while loop is executed
Grab a ref for info->bus (a DBus connection) as long as the while loop
is running. With the grabbed reference it is ensured that info->bus
isn't freed as long as the while loop is executed. This is necessary
as it's allowed to drop the last ref for the bus connection in a
handler.

There was already a bug of this kind in libdbus itself:
https://bugs.freedesktop.org/show_bug.cgi?id=15635.

Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Reviewed-by: Boris Fiuczynski <fiuczy@linux.ibm.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2018-09-25 19:27:21 -04:00
Jiri Denemark
e6d77a75c4 qemu: Avoid duplicate resume events and state changes
The only place where VIR_DOMAIN_EVENT_RESUMED should be generated is the
RESUME event handler to make sure we don't generate duplicate events or
state changes. In the worse case the duplicity can revert or cover
changes done by other event handlers.

For example, after QEMU sent RESUME, BLOCK_IO_ERROR, and STOP events
we could happily mark the domain as running and report
VIR_DOMAIN_EVENT_RESUMED to registered clients.

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

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2018-09-25 20:42:25 +02:00
Jiri Denemark
8ae9b49f5a qemu: Map running reason to resume event detail
Thanks to the previous commit the RESUME event handler knows what reason
should be used when changing the domain state to VIR_DOMAIN_RUNNING, but
the emitted VIR_DOMAIN_EVENT_RESUMED event still uses a generic
VIR_DOMAIN_EVENT_RESUMED_UNPAUSED detail. Luckily, the event detail can
be easily deduced from the running reason, which saves us from having to
pass one more value to the handler.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2018-09-25 20:42:25 +02:00
Jiri Denemark
5dab984ed0 qemu: Pass running reason to RESUME event handler
Whenever we get the RESUME event from QEMU, we change the state of the
affected domain to VIR_DOMAIN_RUNNING with VIR_DOMAIN_RUNNING_UNPAUSED
reason. This is fine if the domain is resumed unexpectedly, but when we
sent "cont" to QEMU we usually have a better reason for the state
change. The better reason is used in qemuProcessStartCPUs which also
sets the domain state to running if qemuMonitorStartCPUs reports
success. Thus we may end up with two state updates in a row, but the
final reason is correct.

This patch is a preparation for dropping the state change done in
qemuMonitorStartCPUs for which we need to pass the actual running reason
to the RESUME event handler and use it there instead of
VIR_DOMAIN_RUNNING_UNPAUSED.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2018-09-25 20:42:25 +02:00
Jiri Denemark
54b5b0ac39 qemu: Report more appropriate running reasons
This patch replaces some rather generic VIR_DOMAIN_RUNNING_UNPAUSED
reasons when changing domain state to running with more specific ones.
All of them are done when libvirtd reconnects to an existing domain
after being restarted and sees an unfinished migration or save.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2018-09-25 20:42:25 +02:00
Jiri Denemark
55af06187c qemu: Properly report VIR_DOMAIN_EVENT_RESUMED_FROM_SNAPSHOT
VIR_DOMAIN_EVENT_RESUMED_FROM_SNAPSHOT was defined but not used anywhere
in our event generation code. This fixes qemuDomainRevertToSnapshot to
properly report why the domain was resumed.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2018-09-25 20:42:25 +02:00
Mark Asselstine
7882c6eca5 lxc_monitor: Avoid AB / BA lock race
A deadlock situation can occur when autostarting a LXC domain 'guest'
due to two threads attempting to take opposing locks while holding
opposing locks (AB BA problem). Thread A takes and holds the 'vm' lock
while attempting to take the 'client' lock, meanwhile, thread B takes
and holds the 'client' lock while attempting to take the 'vm' lock.

The potential for this can be seen as follows:

Thread A:
virLXCProcessAutostartDomain (takes vm lock)
 --> virLXCProcessStart
  --> virLXCProcessConnectMonitor
   --> virLXCMonitorNew
    --> virNetClientSetCloseCallback (wants client lock)

Thread B:
virNetClientIncomingEvent (takes client lock)
 --> virNetClientIOHandleInput
  --> virNetClientCallDispatch
   --> virNetClientCallDispatchMessage
    --> virNetClientProgramDispatch
     --> virLXCMonitorHandleEventInit
      --> virLXCProcessMonitorInitNotify (wants vm lock)

Since these threads are scheduled independently and are preemptible it
is possible for the deadlock scenario to occur where each thread locks
their first lock but both will fail to get their second lock and just
spin forever. You get something like:

virLXCProcessAutostartDomain (takes vm lock)
 --> virLXCProcessStart
  --> virLXCProcessConnectMonitor
   --> virLXCMonitorNew
<...>
virNetClientIncomingEvent (takes client lock)
 --> virNetClientIOHandleInput
  --> virNetClientCallDispatch
   --> virNetClientCallDispatchMessage
    --> virNetClientProgramDispatch
     --> virLXCMonitorHandleEventInit
      --> virLXCProcessMonitorInitNotify (wants vm lock but spins)
<...>
    --> virNetClientSetCloseCallback (wants client lock but spins)

Neither thread ever gets the lock it needs to be able to continue
while holding the lock that the other thread needs.

The actual window for preemption which can cause this deadlock is
rather small, between the calls to virNetClientProgramNew() and
execution of virNetClientSetCloseCallback(), both in
virLXCMonitorNew(). But it can be seen in real world use that this
small window is enough.

By moving the call to virNetClientSetCloseCallback() ahead of
virNetClientProgramNew() we can close any possible chance of the
deadlock taking place. There should be no other implications to the
move since the close callback (in the unlikely event was called) will
spin on the vm lock. The remaining work that takes place between the
old call location of virNetClientSetCloseCallback() and the new
location is unaffected by the move.

Signed-off-by: Mark Asselstine <mark.asselstine@windriver.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2018-09-25 17:08:08 +02:00
Pavel Hrdina
65ba48d267 vircgroup: rename controllers to legacy
With the introduction of cgroup v2 there are new names used with
cgroups based on which version is used:

    - legacy: cgroup v1
    - unified: cgroup v2
    - hybrid: cgroup v1 and cgroup v2

Let's use 'legacy' instead of 'cgroupv1' or 'controllers' in our code.

Reviewed-by: Fabiano Fidêncio <fidencio@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2018-09-25 13:40:22 +02:00
Pavel Hrdina
bebf732cfa vircgroup: rename virCgroupController into virCgroupV1Controller
Reviewed-by: Fabiano Fidêncio <fidencio@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2018-09-25 13:40:22 +02:00
Pavel Hrdina
2b09065e0f vircgroup: extract virCgroupV1(Set|Get)CpusetCpus
Reviewed-by: Fabiano Fidêncio <fidencio@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2018-09-25 13:40:22 +02:00
Pavel Hrdina
7f3aedacac vircgroup: extract virCgroupV1(Set|Get)CpusetMemoryMigrate
Reviewed-by: Fabiano Fidêncio <fidencio@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2018-09-25 13:40:22 +02:00
Pavel Hrdina
41510b1b74 vircgroup: extract virCgroupV1(Set|Get)CpusetMems
Reviewed-by: Fabiano Fidêncio <fidencio@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2018-09-25 13:40:22 +02:00
Pavel Hrdina
269a8e2718 vircgroup: extract virCgroupV1(Set|Get)FreezerState
Reviewed-by: Fabiano Fidêncio <fidencio@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2018-09-25 13:40:22 +02:00
Pavel Hrdina
e294615f9d vircgroup: extract virCgroupV1GetCpuacctStat
Reviewed-by: Fabiano Fidêncio <fidencio@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2018-09-25 13:40:22 +02:00
Pavel Hrdina
8370466323 vircgroup: extract virCgroupV1GetCpuacct*Usage
Reviewed-by: Fabiano Fidêncio <fidencio@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2018-09-25 13:40:22 +02:00
Pavel Hrdina
d182fac0bb vircgroup: extract virCgroupV1SupportsCpuBW
Reviewed-by: Fabiano Fidêncio <fidencio@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2018-09-25 13:40:22 +02:00
Pavel Hrdina
5436fd75d8 vircgroup: extract virCgroupV1(Set|Get)CpuCfsQuota
Reviewed-by: Fabiano Fidêncio <fidencio@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2018-09-25 13:40:22 +02:00
Pavel Hrdina
c840448ebb vircgroup: extract virCgroupV1(Set|Get)CpuCfsPeriod
Reviewed-by: Fabiano Fidêncio <fidencio@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2018-09-25 13:40:22 +02:00
Pavel Hrdina
857aac1f55 vircgroup: extract virCgroupV1(Set|Get)CpuShares
Reviewed-by: Fabiano Fidêncio <fidencio@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2018-09-25 13:40:22 +02:00
Pavel Hrdina
fd9a0368b9 vircgroup: extract virCgroupV1(Allow|Deny)AllDevices
Reviewed-by: Fabiano Fidêncio <fidencio@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2018-09-25 13:40:22 +02:00
Pavel Hrdina
8cbb0c76ba vircgroup: extract virCgroupV1(Allow|Deny)Device
Reviewed-by: Fabiano Fidêncio <fidencio@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2018-09-25 13:40:22 +02:00
Pavel Hrdina
87d9fc5b3b vircgroup: extract virCgroupV1GetMemSwapUsage
Reviewed-by: Fabiano Fidêncio <fidencio@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2018-09-25 13:40:22 +02:00
Pavel Hrdina
900c58b7f9 vircgroup: extract virCgroupV1(Set|Get)Memory*Limit
They all need virCgroupV1GetMemoryUnlimitedKB() so it's easier to
move them in one commit.

Reviewed-by: Fabiano Fidêncio <fidencio@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2018-09-25 13:40:22 +02:00
Pavel Hrdina
e92f8bad66 vircgroup: extract virCgroupV1GetMemoryUsage
Reviewed-by: Fabiano Fidêncio <fidencio@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2018-09-25 13:40:22 +02:00