]> xenbits.xensource.com Git - libvirt.git/log
libvirt.git
5 years agoqemu: move runtime netdev validation into a separate function
Laine Stump [Thu, 12 Sep 2019 22:25:21 +0000 (18:25 -0400)]
qemu: move runtime netdev validation into a separate function

The same validation should be done for both static network devices and
hotplugged devices, but they are currently inconsistent. Move all the
relevant validation from qemuBuildInterfaceCommandLine() into the new
function qemuDomainValidateActualNetDef() and call the latter from
the former.

Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agoconf: make arg to virDomainNetGetActualVirtPortProfile() a const
Laine Stump [Thu, 12 Sep 2019 18:56:41 +0000 (14:56 -0400)]
conf: make arg to virDomainNetGetActualVirtPortProfile() a const

It needs to be used by a function that only has a const pointer to
virDomainNetDef.

Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agoapparmor: avoid copying empty profile name
Jim Fehlig [Mon, 9 Sep 2019 15:50:39 +0000 (09:50 -0600)]
apparmor: avoid copying empty profile name

AppArmorGetSecurityProcessLabel copies the VM's profile name to the
label member of virSecurityLabel struct. If the profile is not loaded,
the name is set empty before calling virStrcpy to copy it. However,
virStrcpy will fail if src is empty (0 length), causing
AppArmorGetSecurityProcessLabel to needlessly fail. Simple operations
that report security driver information will subsequently fail

virsh dominfo test
Id:             248
Name:           test
...
Security model: apparmor
Security DOI:   0
error: internal error: error copying profile name

Avoid copying an empty profile name when the profile is not loaded.

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agonetwork: add debug when bandwidth settings are not applied
Daniel P. Berrangé [Fri, 13 Sep 2019 16:04:41 +0000 (17:04 +0100)]
network: add debug when bandwidth settings are not applied

To aid in troubleshooting add some debug messages wrt
bandwidth settings and networks.

Reviewed-by: Laine Stump <laine@laine.org>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agonetwork: apply bandwidth settings for forward mode=bridge
Daniel P. Berrangé [Fri, 13 Sep 2019 16:00:40 +0000 (17:00 +0100)]
network: apply bandwidth settings for forward mode=bridge

We previously allowed bandwidth settings when attaching NICs
to networks with forward mode=bridge:

  commit 42a92ee93d5432ebd9ebfd409903b5287fc7d7ff
  Author: Daniel P. Berrangé <berrange@redhat.com>
  Date:   Tue Nov 20 11:30:05 2018 +0000

    network: add missing bandwidth limits for bridge forward type

    In the case of a network with forward=bridge, which has a bridge device
    listed, we are capable of setting bandwidth limits but fail to call the
    function to register them.

Reviewed-by: Cole Robinson <crobinso@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
Unfortunately the wrong version of this patch was posted and
reviewed and thus it lacked the code to actually apply the
bandwidth settings to the bridge itself.

Reviewed-by: Laine Stump <laine@laine.org>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agonetwork: fix connection usage counts after restart
Daniel P. Berrangé [Fri, 13 Sep 2019 14:54:18 +0000 (15:54 +0100)]
network: fix connection usage counts after restart

Since the introduction of the virNetworkPort object, the network driver
has a persistent record of ports that have been created against the
networks. Thus the hypervisor drivers no longer communicate to the
network driver during libvirtd restart.

This change, however, meant that the connection usage counts were
no longer re-initialized during a libvirtd restart. To deal with this we
must iterate over all virNetworkPortDefPtr objects we have and invoke
the notify callback to record the connection usage count.

Reviewed-by: Laine Stump <laine@laine.org>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agotests: remove use of virTestOOMActive from bhyve testsuite
Daniel P. Berrangé [Fri, 13 Sep 2019 15:00:26 +0000 (16:00 +0100)]
tests: remove use of virTestOOMActive from bhyve testsuite

The virTestOOMActive method was deleted in

  commit 2c52ecd96086b4643b99b4570b5823d40ce2787b
  Author: Daniel P. Berrangé <berrange@redhat.com>
  Date:   Thu Aug 29 13:04:07 2019 +0100

    util: purge all code for testing OOM handling

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agoqemu: fix detach of hostdev based network interface
Daniel P. Berrangé [Fri, 13 Sep 2019 12:41:29 +0000 (13:41 +0100)]
qemu: fix detach of hostdev based network interface

This fixes bug in

  commit bbe2aa627f621e6749af374b22856184d1f351dc
  Author: Daniel P. Berrangé <berrange@redhat.com>
  Date:   Thu Jul 26 17:24:30 2018 +0100

    conf: simplify link from hostdev back to network device

    hostdevs have a link back to the original network device. This is fairly
    generic accepting any type of device, however, we don't intend to make
    use of this approach in future. It can thus be specialized to network
    devices.

Reviewed-by: Cole Robinson <crobinso@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
which mistakenly deleted the assignment to the 'net' variable,
which meant we never invoked the network driver release callback

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agoutil: make string functions abort on OOM
Daniel P. Berrangé [Thu, 29 Aug 2019 14:23:31 +0000 (15:23 +0100)]
util: make string functions abort on OOM

The functions are left returning an "int" to avoid an immediate
big-bang cleanup. They'll simply never return anything other
than 0.

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agoutil: remove several unused _QUIET allocation macro variants
Daniel P. Berrangé [Thu, 29 Aug 2019 14:30:33 +0000 (15:30 +0100)]
util: remove several unused _QUIET allocation macro variants

Only a few of the _QUIET allocation macros are used. Since we're no
longer reporting OOM as errors, we want to eliminate all the _QUIET
variants. This starts with the easy, unused, cases.

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agoutil: make allocation functions abort on OOM
Daniel P. Berrangé [Thu, 29 Aug 2019 14:23:31 +0000 (15:23 +0100)]
util: make allocation functions abort on OOM

The functions are left returning an "int" to avoid an immediate
big-bang cleanup. They'll simply never return anything other
than 0, except for virInsertN which can still return an error
if the requested insertion index is out of range. Interestingly
in that case, the _QUIET function would none the less report
an error.

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agoutil: purge all code for testing OOM handling
Daniel P. Berrangé [Thu, 29 Aug 2019 12:04:07 +0000 (13:04 +0100)]
util: purge all code for testing OOM handling

The OOM handling requires special build time options which we never
enable in our CI. Even once enabled the tests are incredibly slow and
typically require manual inspection of the results to weed out false
positives.

Since there was previous agreement to switch to abort on OOM in libvirt
code, there's no point continuing to keep the unused OOM testing code.

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agoconf: correctly convert 'managed' attribute from network port
Daniel P. Berrangé [Thu, 12 Sep 2019 15:04:20 +0000 (16:04 +0100)]
conf: correctly convert 'managed' attribute from network port

The virNetworkPortDef config stores the 'managed' attribute
as the virTristateBool type.

The virDomainDef config stores the 'managed' attribute as
the bool type.

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agoconf: avoid looking up network port that doesn't exist
Daniel P. Berrangé [Thu, 12 Sep 2019 13:21:21 +0000 (14:21 +0100)]
conf: avoid looking up network port that doesn't exist

If the hypervisor driver has not yet created the network port, the
portid field will be "00000000-0000-0000-0000-000000000000".

If a failure occurs during early VM startup, the hypervisor driver may
none the less try to release the network port, resulting in an
undesirable warning:

2019-09-12 13:17:42.349+0000: 16544: error :
virNetworkObjLookupPort:1679 : network port not found: Network port with
UUID 00000000-0000-0000-0000-000000000000 does not exist

By checking if the portid UUID is valid, we can avoid polluting the logs
in this way.

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agotools: fix XML validator detection of network port XML schema
Daniel P. Berrangé [Thu, 12 Sep 2019 13:12:02 +0000 (14:12 +0100)]
tools: fix XML validator detection of network port XML schema

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agotools: add virsh docs for network port commands
Daniel P. Berrangé [Thu, 12 Sep 2019 13:06:51 +0000 (14:06 +0100)]
tools: add virsh docs for network port commands

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agonode_device_conf: Don't leak @physical_function in virNodeDeviceGetPCISRIOVCaps
Jiang Kun [Thu, 12 Sep 2019 08:05:39 +0000 (16:05 +0800)]
node_device_conf: Don't leak @physical_function in virNodeDeviceGetPCISRIOVCaps

The pci_dev->physical_function is rewritten in
virPCIGetPhysicalFunction() to a newly allocated pointer.
Therefore, we must free the old one to avoid memleak.

Signed-off-by: Jiang kun <jiang.kun2@zte.com.cn>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agovirt-result.m4: Colourize summary printings
Michal Privoznik [Sat, 7 Sep 2019 11:11:59 +0000 (13:11 +0200)]
virt-result.m4: Colourize summary printings

The LIBVIRT_RESULT function takes two or three arguments. The
first one is the name of the result (aka CHECK_NAME). It is
printed before the colon character. The rest of the arguments is
printed after the character. To produce colourized output a
couple of changes needs to be made.

Firstly, we need to print the CHECK_NAME using "echo -n" so that
the new line is not appended at the end of the message. To
achieve this, AS_MESSAGE_N function is introduced. It's a
verbatim copy of AS_MESSAGE (which is just another alias to
AC_MSG_NOTICE) except it doesn't put '\n' at the EOL.

The alias is defined at /usr/share/autoconf-*/autoconf/general.m4
and the AS_MESSAGE is then defined at
/usr/share/autoconf-2.69/m4sugar/m4sh.m4.

Secondly, the rest of the arguments are printed colourized and to
achieve that and also keep printing them into the log file the
_AS_ECHO and COLORIZE_RESULT functions need to be called.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agoconfigure: Colorize output
Michal Privoznik [Sat, 7 Sep 2019 06:58:14 +0000 (08:58 +0200)]
configure: Colorize output

If we're running from a TTY we can put some colors around 'yes',
'no' and other messages.

Shamelessly copied from Ruby source code and modified a bit to
comply with syntax-check.

https://github.com/ruby/ruby/commit/e4879592873abd4cd8aeed56f4cbaa360a3d3736

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agoqemu: Use FW descriptors to report FW image paths
Michal Privoznik [Mon, 5 Aug 2019 09:29:05 +0000 (11:29 +0200)]
qemu: Use FW descriptors to report FW image paths

Now that we have qemuFirmwareGetSupported() so that it also
returns a list of FW image paths, we can use it to report them in
domain capabilities instead of the old time default list.

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

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Cole Robinson <crobinso@redhat.com>
5 years agoqemufirmwaretest: Test FW path getting through qemuFirmwareGetSupported()
Michal Privoznik [Mon, 5 Aug 2019 14:11:26 +0000 (16:11 +0200)]
qemufirmwaretest: Test FW path getting through qemuFirmwareGetSupported()

There is one hack hidden here, but since this is in a test, it's
okay. In order to get a list of expected firmwares in
virFirmwarePtr form I'm using virFirmwareParseList(). But
usually, in real life scenario, this function is used only to
parse a list of UEFI images which have NVRAM split out. In other
words, this function expects ${FW}:${NVRAM} pairs. But in this
test, we also want to allow just a single path: ${FW} because
some reported firmwares are just a BIOS image really. To avoid
writing some parser function, let's just pass "NULL" as ${NVRAM}
and fix the result later.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Cole Robinson <crobinso@redhat.com>
5 years agoqemu_firmware: Extend qemuFirmwareGetSupported to return FW paths
Michal Privoznik [Mon, 5 Aug 2019 12:56:32 +0000 (14:56 +0200)]
qemu_firmware: Extend qemuFirmwareGetSupported to return FW paths

The qemuFirmwareGetSupported() function is called from qemu
driver to generate domain capabilities XML based on FW descriptor
files. However, the function currently reports only some features
from domcapabilities XML and not actual FW image paths. The paths
reported in the domcapabilities XML are still from pre-FW
descriptor era and therefore the XML might be a bit confusing.
For instance, it may say that secure boot is supported but
secboot enabled FW is not in the listed FW image paths.

To resolve this problem, change qemuFirmwareGetSupported() so
that it also returns a list of FW images (we have the list
anyway). Luckily, we already have a structure to represent a FW
image - virFirmware.

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

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Cole Robinson <crobinso@redhat.com>
5 years agoqemu_firmware: Document qemuFirmwareGetSupported
Michal Privoznik [Mon, 5 Aug 2019 10:02:50 +0000 (12:02 +0200)]
qemu_firmware: Document qemuFirmwareGetSupported

This function is going to get some new arguments. Document the
current ones for clarity.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Cole Robinson <crobinso@redhat.com>
5 years agovirfirmware: Expose and define autoptr for virFirmwareFree
Michal Privoznik [Mon, 5 Aug 2019 09:38:06 +0000 (11:38 +0200)]
virfirmware: Expose and define autoptr for virFirmwareFree

This function frees a _virFirmware struct. So far, it doesn't
need to be called from outside of the module, but this will
change shortly. In the light of recent VIR_DEFINE_AUTOPTR_FUNC()
additions, do the same to virFirmwareFree().

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Cole Robinson <crobinso@redhat.com>
5 years agovirt-result.m4: Align string more generously
Michal Privoznik [Sat, 7 Sep 2019 11:13:35 +0000 (13:13 +0200)]
virt-result.m4: Align string more generously

The times, when we had small CRTs are long gone. Now, in the era
of wide screens we can be more generous when it comes to aligning
the output of configure. The longest string before the colon is
'wireshark_dissector' which counts 19 characters.  Therefore,
align the strings at 20.

At the same time, drop the useless result alignment. It behaves
oddly - it puts a space at the end of each "no" because of the
%-3s format we use.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Cole Robinson <crobinso@redhat.com>
5 years agoconfigure: Prefer LIBVIRT_RESULT over AC_MSG_NOTICE
Michal Privoznik [Sat, 7 Sep 2019 10:44:31 +0000 (12:44 +0200)]
configure: Prefer LIBVIRT_RESULT over AC_MSG_NOTICE

One of the advantages is that LIBVIRT_RESULT aligns the resulting
message for us.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Cole Robinson <crobinso@redhat.com>
5 years agodocs: Expand the "BIOS bootloader" documentation for domainCaps
Kashyap Chamarthy [Wed, 11 Sep 2019 14:34:54 +0000 (16:34 +0200)]
docs: Expand the "BIOS bootloader" documentation for domainCaps

Rewrite some parts for clarity, elaborate the meaning of some of the XML
attributes.  And where necessary, distinguish that we're dealing with
two different XML documents here:

  - the domainCapabilities XML, to detect the host "hypervisor"
    (QEMU/KVM) capabilities, and what libvirt knows about them.

  - the guest XML definition, i.e. what features a guest can use, based
    on the capabilities (of QEMU and libvirt and the host) reported in
    the domainCapabilities XML.

Signed-off-by: Kashyap Chamarthy <kchamart@redhat.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agolibvirt.spec.in: Add the Secure Boot-variant OVMF binaries
Kashyap Chamarthy [Tue, 30 Jul 2019 16:11:19 +0000 (18:11 +0200)]
libvirt.spec.in: Add the Secure Boot-variant OVMF binaries

Currently the RPM spec doesn't add the 'secboot'-variant OVMF binaries
(an unintentional omission, checking with Cole on #virt, OFTC) for
'x86_64' and 'ia32'.  Add them.

This way, getDomainCapabilities() will report all the OVMF binaries that
are present on the system.  E.g. on Fedora 29, if you only have the
edk2-ovmf-20190308stable-1.fc29.noarch package installed, then running
`virsh domcapabilities` will enumerate _both_ the OVMF binaries (instead
of just the OVMF_CODE.fd):

  $> virsh getdomcapabilities
    ...
    <loader supported='yes'>
      <value>/usr/share/edk2/ovmf/OVMF_CODE.fd</value>
      <value>/usr/share/edk2/ovmf/OVMF_CODE.secboot.fd</value>
    ...

(
Learnt this from a discussion with Michal Privoznik in this bug,
comment#2:

    https://bugzilla.redhat.com/show_bug.cgi?id=1733940 -- RFE: Report
    firmware (FW) paths in domainCapabilities based on FW descriptor
    files
)

Signed-off-by: Kashyap Chamarthy <kchamart@redhat.com>
Reviewed-by: Cole Robinson <crobinso@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agosnapshot: Store both config and live XML in the snapshot domain
Maxiwell S. Garcia [Thu, 29 Aug 2019 20:55:43 +0000 (17:55 -0300)]
snapshot: Store both config and live XML in the snapshot domain

The snapshot-create operation of running guests saves the live
XML and uses it to replace the active and inactive domain in
case of revert. So, the config XML is ignored by the snapshot
process. This commit changes it and adds the config XML in the
snapshot XML as the <inactiveDomain> entry.

In case of offline guest, the behavior remains the same and the
config XML is saved in the snapshot XML as <domain> entry. The
behavior of older snapshots of running guests, that don't have
the new <inactiveDomain>, remains the same too. The revert, in
this case, overrides both active and inactive domain with the
<domain> entry. So, the <inactiveDomain> in the snapshot XML is
not required to snapshot work, but it's useful to preserve the
config XML of running guests.

Signed-off-by: Maxiwell S. Garcia <maxiwell@linux.ibm.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Tested-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
5 years agoqemu: formatting XML from domain def choosing the root name
Maxiwell S. Garcia [Thu, 29 Aug 2019 20:55:42 +0000 (17:55 -0300)]
qemu: formatting XML from domain def choosing the root name

The function virDomainDefFormatInternal() has the predefined root name
"domain" to format the XML. But to save both active and inactive domain
in the snapshot XML, the new root name "inactiveDomain" was created.
So, the new function virDomainDefFormatInternalSetRootName() allows to
choose the root name of XML. The former function became a tiny wrapper
to call the new function setting the correct parameters.

Signed-off-by: Maxiwell S. Garcia <maxiwell@linux.ibm.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Tested-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
5 years agoqemu: Don't leak domain def when RevertToSnapshot fails
Jiri Denemark [Tue, 10 Sep 2019 11:44:25 +0000 (13:44 +0200)]
qemu: Don't leak domain def when RevertToSnapshot fails

Once we copy the domain definition from virDomainSnapshotDef, we either
need to assign it to the domain object or free it to avoid memory leaks.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
5 years agoqemu: Fix regression in snapshot-revert
Eric Blake [Mon, 9 Sep 2019 20:52:42 +0000 (15:52 -0500)]
qemu: Fix regression in snapshot-revert

Commit f10562799 introduced a regression: if reverting to a snapshot
fails early (such as when we refuse to revert to an external
snapshot), we lose track of the domain's current snapshot.

Before that patch, we were tracking the notion of the domain's current
snapshot via two means: vm->current_snapshot (which was left untouched
on early exit) and snap->def->current (which only controls what gets
written to XML to remember snapshots across libvirtd restarts).  That
patch was fixing a real bug: if a revert operation failed early, later
questions from the same libvirtd did not see any change to the current
snapsthot, but restarting libvirtd would now claim there is no current
snapshot.  But it fixed it in the wrong direction, in that the current
snapshot was forgotten unconditionally, rather than only when the
snapshot to revert to has a chance of being useful.

It didn't help that the code after that patch had two separate spots
clearing the old notion of the current snapshot - one after
determining the snapshot to revert to was viable, the other
unconditionally on all failure exit paths.  At any rate, the fix is
simple: drop the unconditional cleanup on error paths, and rely only
on the normal cleanup after early checks.

Sadly, it is not possible to test this bug in the existing
tests/virsh-snapshot, as the test driver does not have the same
prohibition against reverting to an external snapshot as the qemu
driver.

See: https://bugzilla.redhat.com/1738747
Signed-off-by: Eric Blake <eblake@redhat.com>
Message-Id: <20190909205242.15406-1-eblake@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
5 years agovirnetdevmacvlan: Provide stubs for macvlan related functions
Michal Privoznik [Tue, 10 Sep 2019 09:24:19 +0000 (11:24 +0200)]
virnetdevmacvlan: Provide stubs for macvlan related functions

In recent commit of 3d21ff72e0e the virNetDevMacVLanTapOpen() and
virNetDevMacVLanTapSetup() functions were exported in our private
symbols. But these functions live in an #ifdef so they need a
stub implementation.
Then in 1b46566ee the virNetDevMacVLanIsMacvtap() function was
implemented but again, only for #idef and without stub.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
5 years agoutil: activate directory override when used from library
Daniel P. Berrangé [Thu, 29 Aug 2019 10:52:08 +0000 (11:52 +0100)]
util: activate directory override when used from library

The Perl bindings for libvirt use the test driver for unit tests. This
tries to load the cpu_map/index.xml file, and when run from an
uninstalled build will fail.

The problem is that virFileActivateDirOverride is called by our various
binaries like libvirtd, virsh, but is not called when a 3rd party app
uses libvirt.so

To deal with this we allow the LIBVIRT_DIR_OVERRIDE=1 env variable to be
set and make virInitialize look for this. The 'run' script will set it,
so now build using this script to run against an uninstalled tree we
will correctly resolve files to the source tree.

Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agoconf: Avoid checking root element name in virDomainDefParseNode
Jiri Denemark [Mon, 9 Sep 2019 20:26:12 +0000 (22:26 +0200)]
conf: Avoid checking root element name in virDomainDefParseNode

The only caller for which this check makes sense is virDomainDefParse.
Thus the check should be moved there.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agoconf: Add cleanup label to virDomainDefParse
Jiri Denemark [Mon, 9 Sep 2019 20:35:10 +0000 (22:35 +0200)]
conf: Add cleanup label to virDomainDefParse

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agoRevert "dbus: correctly build reply message"
Michal Privoznik [Fri, 6 Sep 2019 15:20:40 +0000 (17:20 +0200)]
Revert "dbus: correctly build reply message"

This reverts commit 39dded7bb61444bb608fadd3f82f6fe93d08fd0e.

This commit broke virpolkittest on Ubuntu 18 which has an old
dbus (v1.12.2). Any other distro with the recent one works
(v1.12.16) which hints its a bug in dbus somewhere. Revert the
commit to stop tickling it.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
5 years agolib: Define and use autofree for virConfPtr
Michal Privoznik [Mon, 9 Sep 2019 15:56:26 +0000 (17:56 +0200)]
lib: Define and use autofree for virConfPtr

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
5 years agolxcParseConfigString: Don't return success if post parse callback fails
Michal Privoznik [Mon, 9 Sep 2019 15:45:28 +0000 (17:45 +0200)]
lxcParseConfigString: Don't return success if post parse callback fails

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
5 years agoqemu_conf: Use more of VIR_AUTOUNREF()
Michal Privoznik [Mon, 9 Sep 2019 15:14:25 +0000 (17:14 +0200)]
qemu_conf: Use more of VIR_AUTOUNREF()

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
5 years agoqemu_conf: Use more of VIR_AUTOFREE()
Michal Privoznik [Mon, 9 Sep 2019 15:07:28 +0000 (17:07 +0200)]
qemu_conf: Use more of VIR_AUTOFREE()

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
5 years agoqemu_conf: Drop a pair of needless 'cleanup' labels
Michal Privoznik [Mon, 9 Sep 2019 15:24:22 +0000 (17:24 +0200)]
qemu_conf: Drop a pair of needless 'cleanup' labels

There are two 'cleanup' labels - one in
virQEMUDriverConfigHugeTLBFSInit() and the other in
virQEMUDriverConfigSetDefaults() that do nothing more than
return and integer value. No memory freeing or anything important
is done there. Drop them in favour of returning immediately.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
5 years agoqemu_conf.c: Fix naming of *AddRemove* functions
Michal Privoznik [Mon, 9 Sep 2019 14:58:58 +0000 (16:58 +0200)]
qemu_conf.c: Fix naming of *AddRemove* functions

Our naming rules prefer qemuObjectOperation() scheme rather than
qemuOperationObject() for function names. These were not honoured
in recent commits to qemu_conf.c.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
5 years agoqemu: support unmanaged macvtap devices with <interface type='ethernet'>
Laine Stump [Mon, 26 Aug 2019 17:05:19 +0000 (13:05 -0400)]
qemu: support unmanaged macvtap devices with <interface type='ethernet'>

Traditionally, macvtap devices are supported using <interface
type='direct'>, but that type requires specifying a source device name
and macvtap mode which can't be altered after the initial device
creation (and may not even be available to the management software
that's creating the XML config to feed to libvirt).

But the attributes in the <source> are essentially describing how the
device will be connected to the network, and if libvirt is to be
supplied with the name of a macvtap device that has already been
created, that device will also already be connected to the network
(and the connection can't be changed). Thus it seems more appropriate
to use type='ethernet', which was created explicitly for this purpose
- for devices that have already been (or will be) connected to the
external network by someone/something outside of libvirt. The fact
that it is a *macv*tap rather than a contentional tap device is just a
detail.

This patch supports using an existing macvtap device with <interface
type='ethernet'> by checking the supplied target dev name to see if it
is a macvtap device and, when this is the case, calling
virNetDevMacVLanTapOpen() instead of virNetDevTapCreate(). For
consistency, this is only done when target managed='no'.

Resolves: https://bugzilla.redhat.com/1723367 (partially)

Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agoqemu: support unmanaged target tap dev for <interface type='ethernet'>
Laine Stump [Mon, 26 Aug 2019 04:24:34 +0000 (00:24 -0400)]
qemu: support unmanaged target tap dev for <interface type='ethernet'>

If managed='no', then the tap device must already exist, and setting
of MAC address and online status (IFF_UP) is skipped.

NB: we still set IFF_VNET_HDR and IFF_MULTI_QUEUE as appropriate,
because those bits must be properly set in the TUNSETIFF we use to set
the tap device name of the handle we've opened - if IFF_VNET_HDR has
not been set and we set it the request will be honored even when
running libvirtd unprivileged; if IFF_MULTI_QUEUE is requested to be
different than how it was created, that will result in an error from
the kernel. This means that you don't need to pay attention to
IFF_VNET_HDR when creating the tap devices, but you *do* need to set
IFF_MULTI_QUEUE if you're going to use multiple queues for your tap
device.

NB2: /dev/vhost-net normally has permissions 600, so it can't be
opened by an unprivileged process. This would normally cause a warning
message when using a virtio net device from an unprivileged
libvirtd. I've found that setting the permissions for /dev/vhost-net
permits unprivileged libvirtd to use vhost-net for virtio devices, but
have no idea what sort of security implications that has. I haven't
changed libvrit's code to avoid *attempting* to open /dev/vhost-net -
if you are concerned about the security of opening up permissions of
/dev/vhost-net (probably a good idea at least until we ask someone who
knows about the code) then add <driver name='qemu'/> to the interface
definition and you'll avoid the warning message.

Note that virNetDevTapCreate() is the correct function to call in the
case of an existing device, because the same ioctl() that creates a
new tap device will also open an existing tap device.

Resolves: https://bugzilla.redhat.com/1723367 (partially)

Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agoconf: new "managed" attribute for target dev of <interface type='ethernet'>
Laine Stump [Wed, 21 Aug 2019 20:42:41 +0000 (16:42 -0400)]
conf: new "managed" attribute for target dev of <interface type='ethernet'>

Although <interface type='ethernet'> has always been able to use an
existing tap device, this is just a coincidence due to the fact that
the same ioctl is used to create a new tap device or get a handle to
an existing device.

Even then, once we have the handle to the device, we still insist on
doing extra setup to it (setting the MAC address and IFF_UP).  That
*might* be okay if libvirtd is running as a privileged process, but if
libvirtd is running as an unprivileged user, those attempted
modifications to the tap device will fail (yes, even if the tap is set
to be owned by the user running libvirtd). We could avoid this if we
knew that the device already existed, but as stated above, an existing
device and new device are both accessed in the same manner, and
anyway, we need to preserve existing behavior for those who are
already using pre-existing devices with privileged libvirtd (and
allowing/expecting libvirt to configure the pre-existing device).

In order to cleanly support the idea of using a pre-existing and
pre-configured tap device, this patch introduces a new optional
attribute "managed" for the interface <target> element. This
attribute is only valid for <interface type='ethernet'> (since all
other interface types have mandatory config that doesn't apply in the
case where we expect the tap device to be setup before we
get it). The syntax would look something like this:

   <interface type='ethernet'>
      <target dev='mytap0' managed='no'/>
      ...
   </interface>

This patch just adds managed to the grammar and parser for <target>,
but has no functionality behind it.

(NB: when managed='no' (the default when not specified is 'yes'), the
target dev is always a name explicitly provided, so we don't
auto-remove it from the config just because it starts with "vnet"
(VIR_NET_GENERATED_TAP_PREFIX); this makes it possible to use the
same pattern of names that libvirt itself uses when it automatically
creates the tap devices.)

Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agoconf: use virXMLFormatElement for interface <target>
Laine Stump [Wed, 21 Aug 2019 02:53:11 +0000 (22:53 -0400)]
conf: use virXMLFormatElement for interface <target>

This will simplify addition of another attribute to the <target> element

Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agoqemu: reorganize qemuInterfaceEthernetConnect()
Laine Stump [Tue, 27 Aug 2019 16:18:35 +0000 (12:18 -0400)]
qemu: reorganize qemuInterfaceEthernetConnect()

This just moves around a few things in qemuInterfaceConnect() with no
functional difference (except that a few failures that would have
previously resulted in a "success" audit log will now properly produce
a "fail" audit). The change is so that adding support for unmanaged
tap/macvtap devices will be more easily reviewable.

Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agoutil: make a couple virNetDevMacVlan*() functions public
Laine Stump [Mon, 26 Aug 2019 05:51:40 +0000 (01:51 -0400)]
util: make a couple virNetDevMacVlan*() functions public

In virNetDevMacVLanOpen(), The "retries" arg has been removed and the
value hardcoded as 10, since previously the function was only called
from one place, so it was always 10.

Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agoutil: new function virNetDevMacVLanIsMacvtap()
Laine Stump [Mon, 26 Aug 2019 05:24:08 +0000 (01:24 -0400)]
util: new function virNetDevMacVLanIsMacvtap()

This function returns T if the given name is a macvtap device. This is
determined by 1) getting the ifindex of the device with that name (if
there is one), and 2) checking for existence of /dev/tapXX, where "XX"
is the ifindex learned in (1).

It's also possible to learn this by getting a netlink dump of the
interface and parsing through it to look for some attributes, but that
is complicated to figure out, takes longer to execute, and I'm lazy.

Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agotests: Add a baseline test for multifunction pci device use case
Shivaprasad G Bhat [Thu, 29 Aug 2019 19:19:02 +0000 (16:19 -0300)]
tests: Add a baseline test for multifunction pci device use case

There are already good number of test cases with hostdevices,
few have multifunction devices but none having more than one
than one multifunction cards.

This patch adds a case where there are two multifunction cards
and two Virtual functions part of the same XML.

0001:01:00.X & 0005:09:00.X - are Multifunction PCI cards.
0000:06:12.[5|6] - are SRIOV Virtual functions

Future commits will improve on automatically detecting the
multifunction cards and auto-assinging the addresses
appropriately.

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Shivaprasad G Bhat <sbhat@linux.vnet.ibm.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
5 years agovirpcimock.c: simplify getrealpath() usage
Daniel Henrique Barboza [Thu, 29 Aug 2019 19:19:01 +0000 (16:19 -0300)]
virpcimock.c: simplify getrealpath() usage

Previous patch had to add '/sys/kernel/' prefix in opendir() because
the path, which is being mocked, wasn't being considered due to
an 'if SYSFS_PCI_PREFIX' guarding the call to getrealpath().

In fact, all current getrealpath() callers are guarding it with a
conditional to ensure that the function will never be called with
a non-mocked path. In this case, an extra non-NULL verification is
needed for the 'newpath' string to use the variable - which is
counterintuitive, given that getrealpath() will always write the
'newpath' string in any non-error conditon.

However, simply removing the guard of all getrealpath() instances
causes an abort in init_env(). This happens because tests will
execute access() to non-mocked paths even before the
LIBVIRT_FAKE_ROOT_DIR variable is declared in the test files. We
don't need 'fakerootdir' to be created at this point though.

This patch does the following changes to simplify getrealpath()
usage:

- getrealpath() will now guard the init_env() call by checking if
both fakeroot isn't created and the required path is being mocked.
This ensures that we're not failing inside init_env() because
we're too early and LIBVIRT_FAKE_ROOT_DIR wasn't defined yet;

- remove all conditional guards to call getrealpath() from
access(), virMockStatRedirect(), open(), open_2(), opendir()
and virFileCanonicalizePath(). As a bonus, remove all ternary
conditionals with 'newpath';

- a new 'pathPrefixIsMocked()' helper to aggregate all the prefixes
we're mocking, making it easier to add/remove them. If a prefix
is added inside this function, we can be sure that all functions
are mocking them.

Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agotests: Add test case for QEMU pci-hostdev hotplug
Shivaprasad G Bhat [Thu, 29 Aug 2019 19:19:00 +0000 (16:19 -0300)]
tests: Add test case for QEMU pci-hostdev hotplug

This patch adds hostdev test cases in qemuhotplugtest.c.

Note: the small tweak inside virpcimock.c was needed because
the new tests added a code path in which virHostHasIOMMU()
(virutil.c) started being called, and the mocked '/sys/kernel/'
prefix that is mocked in virpcimock.c wasn't being considered
in the opendir() mock. An alternative to avoid these situations
in virpcimock.c is implemented in the next patch.

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Shivaprasad G Bhat <sbhat@linux.vnet.ibm.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
5 years agovirpcimock: Mock the SRIOV Virtual functions
Shivaprasad G Bhat [Thu, 29 Aug 2019 19:18:59 +0000 (16:18 -0300)]
virpcimock: Mock the SRIOV Virtual functions

The softlink to physfn is the way to know if the device is
VF or not. So, the patch softlinks 'physfn' to the parent function.
The multifunction PCI devices dont have 'physfn' softlinks.

The patch adds few Virtual functions to the mock environment and
changes the existing VFIO test xmls using the VFs to use the newly
added VFs for their use case.

Signed-off-by: Shivaprasad G Bhat <sbhat@linux.vnet.ibm.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agovirpcimock.c: mock /dev/vfio
Daniel Henrique Barboza [Thu, 29 Aug 2019 19:18:58 +0000 (16:18 -0300)]
virpcimock.c: mock /dev/vfio

This patch adds mock of the /dev/vfio path, needed for proper
implementation of the support for multifunction/multiple devices
per iommu groups.

To do that, the existing bind and unbind operations were adapted
to operate with the mocked filesystem as well.

Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agoqemu: Adjust max memlock on mdev hotplug
Eric Farman [Tue, 3 Sep 2019 20:09:48 +0000 (22:09 +0200)]
qemu: Adjust max memlock on mdev hotplug

When starting a domain, we use the presence of a vfio-pci or
mdev hostdev to determine if the memlock maximum needs to be
increased.  But if we hotplug either of these devices, only the
vfio-pci path gets that love.  This means that attaching a, say,
vfio-ccw device will appear to succeed but the device may be
unusable as the guest may see I/O errors on long CCW chains.
The host, meanwhile, would be flooded with these messages:

  vfio_pin_page_external: Task qemu-system-s39 (11584) RLIMIT_MEMLOCK (65536) exceeded

Let's adjust the maximum memlock value in the mdev hotplug path,
so that the domain has the same value as if it were started with
one or more mdev devices in its configuration.

Signed-off-by: Eric Farman <farman@linux.ibm.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
5 years agoqemu: Reset the maximum locked memory on hotplug fail
Eric Farman [Tue, 3 Sep 2019 20:09:47 +0000 (22:09 +0200)]
qemu: Reset the maximum locked memory on hotplug fail

If attaching a PCI hostdev fails, there are several things that
need to be un-done as part of the cleanup.  One thing that is
not done is re-calculating/re-setting the maximum amount of locked
memory for the domain, since we may have changed that.

Let's fix that, just to ensure everything is back the way it was.

Signed-off-by: Eric Farman <farman@linux.ibm.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
5 years agoqemu: Refactor the max memlock routine
Eric Farman [Tue, 3 Sep 2019 20:09:46 +0000 (22:09 +0200)]
qemu: Refactor the max memlock routine

Let's pull this hunk out into a function, so it can be reused
in another codepath that needs to do the same thing.

Signed-off-by: Eric Farman <farman@linux.ibm.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
5 years agovirhostdev: Don't unref @pcidevs twice
Michal Privoznik [Mon, 9 Sep 2019 14:20:07 +0000 (16:20 +0200)]
virhostdev: Don't unref @pcidevs twice

In f08e6883cb4 I've made @pcidevs in
virHostdevReAttachPCIDevices() to be automatically unrefed using
VIR_AUTOUNREF() but I forgot to remove the line that explicitly
unrefs the object at the end of the function.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
5 years agodocs: remove devhelp API docs
Daniel P. Berrangé [Thu, 5 Sep 2019 12:07:59 +0000 (13:07 +0100)]
docs: remove devhelp API docs

We currently generate two completely separate API references for the
libvirt public API. One at 'docs/html/' and one at 'docs/devhelp/'.
Both are published on the website, but we only link to content in
the 'docs/html/' pages.

Both are installed in the libvirt-docs sub-RPM, with a full copy
of the website including 'docs/html/' in /usr/share/docs/libvirt-docs,
while the 'docs/devhelp/' content goes to /usr/share/gtk-doc/. The
latter was broken for years until:

  commit ca6f602546cb28658db05f29bc840e04d22d0947
  Author: Andrea Bolognani <abologna@redhat.com>
  Date:   Fri May 10 14:54:52 2019 +0200

    docs: Introduce $(devhelphtml_generated)

    Our XSLT magic generates one Devhelp-compatible HTML file
    per documentation module, but so far we have only shipped
    and installed documentation for virterror.

    Now that we have $(modules), however, we can generate the
    list of files the same way we do for regular documentation
    and make sure we always ship and install everything.

That this bug went unnoticed for so long is a sign of how few
people are using the devhelp docs. The only commits to the devhelp
code since it was first introduced have been fixing various build
problems that hit.

The only obvious difference between the two sets of docs is the CSS
styling in use. Overall devhelp does not look compelling enough to
justify having two duplicated sets of API docs. Eliminating it will
reduce the amount of XSL code we are carrying in the tree which is
an attractive benefit.

Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Andrea Bolognani <abologna@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agoqemu_conf.c: introduce qemuAddRemoveSharedDeviceInternal
Daniel Henrique Barboza [Tue, 3 Sep 2019 23:06:07 +0000 (20:06 -0300)]
qemu_conf.c: introduce qemuAddRemoveSharedDeviceInternal

After the previous commits, qemuAddSharedDevice() and
qemuRemoveSharedDevice() are now the same code with a different
flag to call the internal functions.

This patch aggregates the common code into a new function called
qemuAddRemoveSharedDeviceInternal() to further reduce
code repetition. Both qemuAddSharedDevice() and
qemuRemoveSharedDevice() are kept since they are public
functions used elsewhere.

No functional change was made.

Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
5 years agoqemu_conf.c: introduce qemuAddRemoveSharedDiskInternal
Daniel Henrique Barboza [Tue, 3 Sep 2019 23:06:06 +0000 (20:06 -0300)]
qemu_conf.c: introduce qemuAddRemoveSharedDiskInternal

Following the same idea of avoid code repetition from the
previous patch, this commit introduces a new function that
aggregates the functions of qemuAddSharedDisk() and
qemuRemoveSharedDisk() into a single place, using a flag to
switch between add/remove operations.

Both qemuAddSharedDisk() and qemuRemoveSharedDisk() are
public, so keep them around to avoid changing other files
due to an internal qemu_conf.c refactory.

No functional change was made.

Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
5 years agoqemu_conf.c: introduce qemuAddRemoveSharedHostdevInternal
Daniel Henrique Barboza [Tue, 3 Sep 2019 23:06:05 +0000 (20:06 -0300)]
qemu_conf.c: introduce qemuAddRemoveSharedHostdevInternal

qemuAddSharedHostdev() has a code similar to
qemuRemoveSharedHostdev(), with exception of one line that
defines the operation (add or remove).

This patch introduces a new function that aggregates the common
code, using a flag to switch between the operations, avoiding
code repetition.

No functional change was made.

Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
5 years agoqemu: update threading info about domain object refs
Jonathon Jongsma [Wed, 4 Sep 2019 17:23:30 +0000 (12:23 -0500)]
qemu: update threading info about domain object refs

Since commit fd9ef3b31e, virDomainFindByUUIDRef() no longer exists and
all virDomainObjListFindBy*() functions now increment the reference
count.

Signed-off-by: Jonathon Jongsma <jjongsma@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
5 years agoremote: fix UNIX socket path being incorrectly built for libvirtd
eater [Fri, 6 Sep 2019 21:36:17 +0000 (23:36 +0200)]
remote: fix UNIX socket path being incorrectly built for libvirtd

As a result of changes in

      commit d5f0c1b6dd51f0fbab2f8a25733c55d8be6b937b
      Author: Daniel P. Berrangé <berrange@redhat.com>
      Date:   Thu Jul 18 12:30:22 2019 +0100

        remote: stop trying to print help as giant blocks of text

The socket path built would be libvirt//var/run/libvirt-sock
instead of /var/run/libvirt/libvirt-sock. Fortunately this only
affects users who have set the 'unix_sock_dir' config parameter
in /etc/libvirt/libvirtd.conf, which is pretty rare/unusual.

Signed-off-by: eater <=@eater.me>
Exception made for the psuedonym above since patch is considered
trivial & thus non-copyrightable material.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agolib: Grab write lock when modifying list of domains
Michal Privoznik [Fri, 6 Sep 2019 11:59:59 +0000 (13:59 +0200)]
lib: Grab write lock when modifying list of domains

In some places where virDomainObjListForEach() is called the
passed callback calls virDomainObjListRemoveLocked(). Well, this
is unsafe, because the former only grabs a read lock but the
latter modifies the list.
I've identified the following unsafe calls:

- qemuProcessReconnectAll()
- libxlReconnectDomains()

The rest seem to be safe.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agovirdomainobjlist: Document virDomainObjListForEach()
Michal Privoznik [Fri, 6 Sep 2019 11:50:39 +0000 (13:50 +0200)]
virdomainobjlist: Document virDomainObjListForEach()

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agovirsh: Fix help for net-port-delete
Jonathon Jongsma [Tue, 3 Sep 2019 16:47:29 +0000 (11:47 -0500)]
virsh: Fix help for net-port-delete

Apparently a copy/paste error. The net-port-delete help string was in
fact from net-port-dumpxml.

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

Signed-off-by: Jonathon Jongsma <jjongsma@redhat.com>
5 years agoqemu_slirp: Drop unused variable in qemuSlirpStart()
Michal Privoznik [Fri, 6 Sep 2019 12:14:21 +0000 (14:14 +0200)]
qemu_slirp: Drop unused variable in qemuSlirpStart()

The @cmdstr variable is not used really.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
5 years agolibxl: Fix libxlDomainPMSuspendForDuration domain active check
Marek Marczykowski-Górecki [Fri, 6 Sep 2019 14:12:55 +0000 (16:12 +0200)]
libxl: Fix libxlDomainPMSuspendForDuration domain active check

virDomainObjCheckActive() returns -1 if domain is not active, not 0.

Fixes cb50436c6f "libxl: implement virDomainPM* functions"
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Signed-off-by: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
5 years agoutil: Set backing file name for LOOP_GET_STATUS64 queries.
Julio Faracco [Mon, 2 Sep 2019 17:00:27 +0000 (14:00 -0300)]
util: Set backing file name for LOOP_GET_STATUS64 queries.

This is an issue for LXC loop devices when you are trying to get loop
devices info using `ioctl`. Modern apps uses `/sys/dev/block` to grab
information about devices, but if you use the method mention you won't
be able to retrive the associated file with that loop device. See
example below from cryptsetup sources:

    static char *_ioctl_backing_file(const char *loop)
    {
        struct loop_info64 lo64 = {0};
        int loop_fd;

        loop_fd = open(loop, O_RDONLY);
        if (loop_fd < 0)
            return NULL;

        if (ioctl(loop_fd, LOOP_GET_STATUS64, &lo64) < 0) {
            close(loop_fd);
            return NULL;
        }

        lo64.lo_file_name[LO_NAME_SIZE-2] = '*';
        lo64.lo_file_name[LO_NAME_SIZE-1] = 0;

        close(loop_fd);
        return strdup((char*)lo64.lo_file_name);
    }

It will return an empty string because lo_file_name was not set.
Function `virFileLoopDeviceOpenSearch()` is using `ioctl` to query data,
but it is not checking `lo_file_name` field.

Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Signed-off-by: Julio Faracco <jcfaracco@gmail.com>
5 years agotests: add slirp-helper qemuxml2argv test
Marc-André Lureau [Thu, 8 Aug 2019 14:55:14 +0000 (18:55 +0400)]
tests: add slirp-helper qemuxml2argv test

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agoqemu-hotplug: handle hotplugging of slirp-helper
Marc-André Lureau [Thu, 8 Aug 2019 14:55:13 +0000 (18:55 +0400)]
qemu-hotplug: handle hotplugging of slirp-helper

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agoqemu-process: prepare slirp-helper
Marc-André Lureau [Thu, 8 Aug 2019 14:55:12 +0000 (18:55 +0400)]
qemu-process: prepare slirp-helper

When the network interface is of "user" type, and QEMU has the "-net
socket,fd=" datagram support, call qemuInterfacePrepareSlirp() to
probe and associate a slirp-helper with the interface.

The usage of automated slirp-helper can be prevented with
disableSlirp (in particular when resuming a
VM that didn't start with slirp-helper before).

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agoqemu-command: use -net socket, fd= with slirp-helper
Marc-André Lureau [Thu, 8 Aug 2019 14:55:11 +0000 (18:55 +0400)]
qemu-command: use -net socket, fd= with slirp-helper

If a slirp-helper is associated with a network interface (after
probing & preparing succesfully), pass the socket fd to QEMU and use
"-net socket,fd=".

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agoqemu-extdevice: prepare, start and stop slirp-helper
Marc-André Lureau [Thu, 8 Aug 2019 14:55:10 +0000 (18:55 +0400)]
qemu-extdevice: prepare, start and stop slirp-helper

If a slirp-helper is associated with a network interface,
prepare/start/stop the process via qemu-extdevice.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agoqemu-migration: prevent migration if slirp cannot be migrated
Marc-André Lureau [Thu, 8 Aug 2019 14:55:09 +0000 (18:55 +0400)]
qemu-migration: prevent migration if slirp cannot be migrated

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agoqemu-migration: prevent migration if dbus-vmstate is required
Marc-André Lureau [Thu, 8 Aug 2019 14:55:08 +0000 (18:55 +0400)]
qemu-migration: prevent migration if dbus-vmstate is required

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agoqemu: add a flag to the cookie to prevent slirp-helper setup
Marc-André Lureau [Thu, 8 Aug 2019 14:55:07 +0000 (18:55 +0400)]
qemu: add a flag to the cookie to prevent slirp-helper setup

For VM started and migrated/saved without slirp-helpers, let's prevent
the automatic setup (as it would fail to migrate otherwise).

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agoqemu-domain: save and restore slirp state
Marc-André Lureau [Thu, 8 Aug 2019 14:55:06 +0000 (18:55 +0400)]
qemu-domain: save and restore slirp state

Save & restore the slirp helper PID associated with a network
interface & the probed features.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agoqemu: add slirp helper unit
Marc-André Lureau [Thu, 8 Aug 2019 14:55:05 +0000 (18:55 +0400)]
qemu: add slirp helper unit

The unit provides the functions associated with a slirp-helper:
- probing / checking capabilities
- opening the socketpair
- starting / stoping the helper
- registering for dbus-vmstate migration

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agoqemu-conf: add slirp state dir
Marc-André Lureau [Thu, 8 Aug 2019 14:55:04 +0000 (18:55 +0400)]
qemu-conf: add slirp state dir

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agoqemu-conf: add configurable slirp-helper location
Marc-André Lureau [Thu, 8 Aug 2019 14:55:03 +0000 (18:55 +0400)]
qemu-conf: add configurable slirp-helper location

A slirp helper is a process that provides user-mode networking through
a unix domain socket. It is expected to follow the following
specification:
https://gitlab.freedesktop.org/slirp/libslirp-rs/blob/master/src/bin/README.rst

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agoqemu: add qemuDomainNetworkPrivate
Marc-André Lureau [Thu, 8 Aug 2019 14:55:02 +0000 (18:55 +0400)]
qemu: add qemuDomainNetworkPrivate

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agodomain-conf: add network def private data
Marc-André Lureau [Thu, 8 Aug 2019 14:55:01 +0000 (18:55 +0400)]
domain-conf: add network def private data

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agoqemu: add dbus-vmstate
Marc-André Lureau [Thu, 8 Aug 2019 14:55:00 +0000 (18:55 +0400)]
qemu: add dbus-vmstate

Add dbusVMStates to keep a list of dbus-vmstate objects needed for
migration. They are populated on the command line during start or
qemuDBusVMStateAdd/Remove() will hotplug them as needed.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agoqemu-security: add qemuSecurityCommandRun()
Marc-André Lureau [Thu, 8 Aug 2019 14:54:59 +0000 (18:54 +0400)]
qemu-security: add qemuSecurityCommandRun()

Add a generic way to run a command through the security management.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agoqemu: reset VM id after external devices stop
Marc-André Lureau [Thu, 8 Aug 2019 14:54:58 +0000 (18:54 +0400)]
qemu: reset VM id after external devices stop

pid filenames (from swtpm and other helpers from this series) are
based on VM shortname, which is derived from VM id. If the id is reset
to early, the state filenames will not be found.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agoqemu: add dbus-vmstate capability
Marc-André Lureau [Thu, 8 Aug 2019 14:54:57 +0000 (18:54 +0400)]
qemu: add dbus-vmstate capability

This object is being proposed to qemu upstream "Add dbus-vmstate
object". It handles data migration of external processes.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agoqemu: add socket datagram capability
Marc-André Lureau [Thu, 8 Aug 2019 14:54:56 +0000 (18:54 +0400)]
qemu: add socket datagram capability

Datagram socket is available since qemu 4.0, commit
fdec16e3c2a614e2861f3086b05d444b5d8c3406 ("net/socket: learn to talk
with a unix dgram socket").

Required for slirp-helper communication.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agoqemu: replace logCtxt with qemuDomainLogAppendMessage()
Marc-André Lureau [Thu, 8 Aug 2019 14:54:55 +0000 (18:54 +0400)]
qemu: replace logCtxt with qemuDomainLogAppendMessage()

Once QEMU is started, the qemuDomainLogContext is owned by it, and can
no longer be used from libvirt. Instead, use
qemuDomainLogAppendMessage() which will redirect the log.

This is not strictly necessary for swtpm, but the following patches
are going to reuse qemuExtDeviceLogCommand().

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agodbus: correctly build reply message
Marc-André Lureau [Thu, 8 Aug 2019 14:54:54 +0000 (18:54 +0400)]
dbus: correctly build reply message

dbus_message_new() does not construct correct replies by itself, it is
recommended to use dbus_message_new_method_return() instead.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agotests: fix xml2xml tpm-emulator.xml test
Marc-André Lureau [Thu, 8 Aug 2019 14:54:53 +0000 (18:54 +0400)]
tests: fix xml2xml tpm-emulator.xml test

It is failing, because it ends up being parsed with version='default'
and expects '1.2' instead.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agoAdd .editorconfig
Marc-André Lureau [Thu, 8 Aug 2019 14:54:52 +0000 (18:54 +0400)]
Add .editorconfig

Consistent code style across editors.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agoqemu: qapi: Limit traversal depth for QAPI schema queries
Peter Krempa [Mon, 12 Aug 2019 16:31:44 +0000 (18:31 +0200)]
qemu: qapi: Limit traversal depth for QAPI schema queries

Implicitly the query depth is limited by the length of the QAPI schema
query, but 'alternate' and 'array' QAPI meta-types don't consume a part
of the query string thus a loop on such types would get our traversal
code stuck in an infinite loop. Prevent this from happening by limiting
the nesting depth to 1000.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agoqemu: maintain user alias for video type 'none'
Jonathon Jongsma [Thu, 5 Sep 2019 16:17:38 +0000 (11:17 -0500)]
qemu: maintain user alias for video type 'none'

After parsing a video device with a model type of
VIR_DOMAIN_VIDEO_TYPE_NONE, all device info is cleared (see
virDomainDefPostParseVideo()) in order to avoid formatting any
auto-generated values for the XML. Subsequently, however, an alias is
generated for the video device (e.g. 'video0'), which results in an
alias property being formatted in the XML output anyway. This creates
confusion if the user has explicitly provided an alias for the video
device since the alias will change.

To avoid this, don't clear the user-defined alias for video devices of
type "none".

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

Signed-off-by: Jonathon Jongsma <jjongsma@redhat.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
5 years agovircgroupv2: fix setting cpu.max period
Pavel Hrdina [Thu, 5 Sep 2019 09:22:11 +0000 (11:22 +0200)]
vircgroupv2: fix setting cpu.max period

When we set cpu.max period we need to parse the cpu.max file first as
it contains both quota and period values separated by space.  When only
a single number is written to that file it will set quota.  However,
in order to change period we need to write both values.

The code was prepared for that but mistakenly used new line to end the
string with the first value.

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

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
5 years agoqemu: migration: Switch to blockdev mode for non-shared storage migration
Peter Krempa [Wed, 4 Sep 2019 11:20:41 +0000 (13:20 +0200)]
qemu: migration: Switch to blockdev mode for non-shared storage migration

When blockdev is used we always should use the blockdev mode for
non-shared storage migration.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
5 years agoqemu: migration: Refactor cleanup in qemuMigrationSrcNBDStorageCopy
Peter Krempa [Wed, 4 Sep 2019 10:23:16 +0000 (12:23 +0200)]
qemu: migration: Refactor cleanup in qemuMigrationSrcNBDStorageCopy

Use VIR_AUTOUNREF and remove the cleanup label.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
5 years agoqemu: migration: Refactor cleanup in qemuMigrationSrcNBDStorageCopyDriveMirror
Peter Krempa [Wed, 4 Sep 2019 10:23:16 +0000 (12:23 +0200)]
qemu: migration: Refactor cleanup in qemuMigrationSrcNBDStorageCopyDriveMirror

Use VIR_AUTOFREE and remove the cleanup label.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>