]> xenbits.xensource.com Git - libvirt.git/log
libvirt.git
6 years agoutil: Rename resctrl to alloc if it is virResctrlAllocPtr
Martin Kletzander [Thu, 1 Feb 2018 13:57:40 +0000 (14:57 +0100)]
util: Rename resctrl to alloc if it is virResctrlAllocPtr

Just to stay consistent.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agodocs: Add TSEG support info into news.xml
Martin Kletzander [Thu, 7 Jun 2018 13:57:05 +0000 (15:57 +0200)]
docs: Add TSEG support info into news.xml

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoqemu: Add support for setting the TSEG size
Martin Kletzander [Thu, 10 May 2018 21:37:18 +0000 (23:37 +0200)]
qemu: Add support for setting the TSEG size

The default is stable per machine type so there should be no need to keep that.

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

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoqemu: Add capability flag for setting the extended tseg size
Martin Kletzander [Thu, 10 May 2018 21:27:57 +0000 (23:27 +0200)]
qemu: Add capability flag for setting the extended tseg size

For getting the reply I queried the newest and oldest QEMU using
test/qemucapsprobe.  From the differences I only extracted the reply to the new
QMP command and discarded the rest.  For all the versions below the one which
added support for the new option I used the output from the oldest QEMU release
and for those that support it I used the output from the newest one.

In order to make doubly sure the reply is where it is supposed to be (the
replies files are very forgiving) I added the property to all the replies files,
reran the tests again and fixed the order in replies files so that all the
versions are reporting the new capability.  Then removed that one property.

After that I used test/qemucapsfixreplies to fix the reply IDs.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoconf, schema, docs: Add support for TSEG size setting
Martin Kletzander [Thu, 10 May 2018 19:32:26 +0000 (21:32 +0200)]
conf, schema, docs: Add support for TSEG size setting

TSEG (Top of Memory Segment) is one of many regions that SMM (System Management
Mode) can occupy.  This one, however is special, because a) most of the SMM code
lives in TSEG nowadays and b) QEMU just (well, some time ago) added support for
so called 'extended' TSEG.  The difference to the TSEG implemented in real q35's
MCH (Memory Controller Hub) is that it can offer one extra size to the guest OS
apart from the standard TSEG's 1, 2, and 8 MiB and that size can be selected in
1 MiB increments.  Maximum may vary based on QEMU and is way too big, so we
don't need to check for the maximum here.  Similarly to the memory size we'll
leave it to the hypervisor to try satisfying that and giving us an error message
in case it is not possible.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
Acked-by: Laszlo Ersek <lersek@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoqemu: Relax check for SMM feature
Martin Kletzander [Thu, 7 Jun 2018 21:24:45 +0000 (23:24 +0200)]
qemu: Relax check for SMM feature

One of the things that this is improving is the fact that instead of error
message (that was wrong) you get when starting a domain with SMM and i440fx we
allow the setting to go through.  SMM option exists and makes sense on i440fx as
well (basically whenever that _SMM_OPT capability is set).

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoqemu: Move checks for SMM from command-line creation into validation phase
Martin Kletzander [Thu, 10 May 2018 21:28:24 +0000 (23:28 +0200)]
qemu: Move checks for SMM from command-line creation into validation phase

We are still hoping all of such checks will be moved there and this is one small
step in that direction.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agotests: qemuxml2argv: Make tests based on DO_TEST_CAPS_LATEST stable
Peter Krempa [Mon, 4 Jun 2018 13:30:49 +0000 (15:30 +0200)]
tests: qemuxml2argv: Make tests based on DO_TEST_CAPS_LATEST stable

To avoid problems with test cases specifying an alias machine type which
would change once capabilities for a newer version are added strip all
alias machine types for the DO_TEST_CAPS_LATEST based tests.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
6 years agoutil: storage: remove 'allow_probe' from virStorageFileGetMetadata
Peter Krempa [Mon, 4 Jun 2018 08:25:17 +0000 (10:25 +0200)]
util: storage: remove 'allow_probe' from virStorageFileGetMetadata

All callers pass 'false' now so it's no longer needed.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agotests: storage: Drop duplicate tests with TEST_CHAIN
Peter Krempa [Mon, 4 Jun 2018 08:16:03 +0000 (10:16 +0200)]
tests: storage: Drop duplicate tests with TEST_CHAIN

Now that all test cases with TEST_CHAIN were testing the same thing
twice drop one of them. Note that some of the cases were duplicate even
before dropping the image format probing tests.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agotests: storage: Drop format probing from tests
Peter Krempa [Mon, 4 Jun 2018 07:39:28 +0000 (09:39 +0200)]
tests: storage: Drop format probing from tests

Storage drivers now don't allow it so there's no need to test it.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agotests: storage: Absorb ALLOW_PROBE flag into the TEST_CHAIN macro
Peter Krempa [Mon, 4 Jun 2018 07:50:13 +0000 (09:50 +0200)]
tests: storage: Absorb ALLOW_PROBE flag into the TEST_CHAIN macro

The second set of arguments for TEST_CHAIN always specifies the
'ALLOW_PROBE' flag. Make it part of the macro.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agotests: virstoragetest: Add complementary test case for QED format
Peter Krempa [Mon, 4 Jun 2018 07:36:24 +0000 (09:36 +0200)]
tests: virstoragetest: Add complementary test case for QED format

We have a test case for QED disk image with autodetection but not with
the format explicitly specified.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agosecurity: aa-helper: Remove the -p parameter
Peter Krempa [Mon, 4 Jun 2018 07:00:47 +0000 (09:00 +0200)]
security: aa-helper: Remove the -p parameter

As the aa-helper binary is supposed to be used only with libvirt, we can
fully remove it.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agosecurity: Remove VIR_SECURITY_MANAGER_ALLOW_DISK_PROBE
Peter Krempa [Mon, 4 Jun 2018 07:00:41 +0000 (09:00 +0200)]
security: Remove VIR_SECURITY_MANAGER_ALLOW_DISK_PROBE

Nothing is setting that flag now so it can be removed. Note that
removing 'mgr' from 'load_profile' in the apparmor driver would create a
lot of churn.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoqemu: driver: Remove impossible code path in qemuDomainSnapshotCreateInactiveExternal
Peter Krempa [Mon, 4 Jun 2018 07:00:37 +0000 (09:00 +0200)]
qemu: driver: Remove impossible code path in  qemuDomainSnapshotCreateInactiveExternal

Previous patch naively removed all code relevant to disk format
checking. The semantics now dictate that the format check when creating
external snapshots is now impossible as we always fill in the format for
disks in domain definition in the post-parse callback.

Remove the impossible code path.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoqemu: conf: Remove 'allow_disk_format_probing' config option
Peter Krempa [Mon, 4 Jun 2018 07:00:27 +0000 (09:00 +0200)]
qemu: conf: Remove 'allow_disk_format_probing' config option

The option is insecure and it has been long enough for users to migrate
their disk files to use explicit format. Drop the option and related
code.

The config parser still parses it and rejects statup if it's still
present in the config in enabled state.

The augeas lens is also kept so that users can disable it.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agotests: Drop tests enabling allowDiskFormatProbing
Peter Krempa [Mon, 4 Jun 2018 06:59:57 +0000 (08:59 +0200)]
tests: Drop tests enabling allowDiskFormatProbing

Format probing will be dropped so remove the tests which will become
obsolete.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoAdd Virtlyst web application to apps.html
Daniel Nicoletti [Mon, 4 Jun 2018 18:44:23 +0000 (15:44 -0300)]
Add Virtlyst web application to apps.html

Signed-off-by: Daniel Nicoletti <dantti12@gmail.com>
6 years agonwfilter: fix build error when pcap-config is not present
Brijesh Singh [Thu, 7 Jun 2018 20:46:27 +0000 (15:46 -0500)]
nwfilter: fix build error when pcap-config is not present

The compilation fails with the following error when pcap-config
is not present on the host:

nwfilter/nwfilter_learnipaddr.c:824:1: error: conflicting types for 'virNWFilterLearnIPAddress'
 virNWFilterLearnIPAddress(virNWFilterTechDriverPtr techdriver ATTRIBUTE_UNUSED,

 In file included from nwfilter/nwfilter_learnipaddr.c:57:0:
 nwfilter/nwfilter_learnipaddr.h:38:5: note: previous declaration of 'virNWFilterLearnIPAddress' was here
  int virNWFilterLearnIPAddress(virNWFilterTechDriverPtr techdriver,

Signed-off-by: Brijesh Singh <brijesh.singh@amd.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
6 years agonwfilter: directly use poll to wait for packets instead of pcap_next
Daniel P. Berrangé [Mon, 21 May 2018 11:46:00 +0000 (12:46 +0100)]
nwfilter: directly use poll to wait for packets instead of pcap_next

When a QEMU VM shuts down its TAP device gets deleted while nwfilter
IP address learning thread is still capturing packets. It is seen that
with TPACKET_V3 support in libcap, the pcap_next() call will not always
exit its poll() when the NIC is removed. This prevents the learning
thread from exiting which blocks the rest of libvirtd waiting on mutex
acquisition. By switching to do poll() in libvirt code, we can ensure
that we always exit the poll() at a time that is right for libvirt.

Reviewed-by: John Ferlan <jferlan@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
6 years agonwfilter: fix IP address learning
Daniel P. Berrangé [Fri, 18 May 2018 11:54:52 +0000 (12:54 +0100)]
nwfilter: fix IP address learning

In a previous commit:

  commit d4bf8f415074759baf051644559e04fe78888f8b
  Author: Daniel P. Berrangé <berrange@redhat.com>
  Date:   Wed Feb 14 09:43:59 2018 +0000

    nwfilter: handle missing switch enum cases

    Ensure all enum cases are listed in switch statements, or cast away
    enum type in places where we don't wish to cover all cases.

Reviewed-by: John Ferlan <jferlan@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
we changed a switch in the nwfilter learning thread so that it had
explict cases for all enum entries. Unfortunately the parameters in the
method had been declared with incorrect type. The "howDetect" parameter
does *not* accept "enum howDetect" values, rather it accepts a bitmask
of "enum howDetect" values, so it should have been an "int" type.

The caller always passes DETECT_STATIC|DETECT_DHCP, so essentially the
IP addressing learning was completely broken by the above change, as it
never matched any switch case, hitting the default leading to EINVAL.

Stop using a typedef for the parameter name this this is a bitmask,
not a plain enum value. Also stop using switch() since that's misleading
with bitmasks too.

Reviewed-by: John Ferlan <jferlan@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
6 years agodocs: remove git snapshot download links
Daniel P. Berrangé [Thu, 7 Jun 2018 14:05:07 +0000 (15:05 +0100)]
docs: remove git snapshot download links

The process used to build the snapshots no longer works because the box
it runs on is outdated. Analysing the web logs shows the majority of
traffic to these links is from search engine bots. With those removed,
there is about 1 hit per day from (probable) humans.

Most users needing a tarball are better served by using official
releases. Those needing latest code are better served by using git
checkout. The tarball snapshots are not compelling enough to invest time
in fixing the script that produces them.

Reviewed-by: Andrea Bolognani <abologna@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
6 years agonews: Document bhyve guest CPU topology feature
Roman Bogorodskiy [Mon, 28 May 2018 14:41:09 +0000 (18:41 +0400)]
news: Document bhyve guest CPU topology feature

Signed-off-by: Roman Bogorodskiy <bogorodskiy@gmail.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
6 years agobhyve: Add CPU topology support
Roman Bogorodskiy [Mon, 21 May 2018 14:53:36 +0000 (18:53 +0400)]
bhyve: Add CPU topology support

Recently, bhyve started supporting specifying guest CPU topology.
It looks this way:

  bhyve -c cpus=C,sockets=S,cores=C,threads=T ...

The old behaviour was bhyve -c C, where C is a number of vCPUs, is
still supported.

So if we have CPU topology in the domain XML, use the new syntax,
otherwise keep the old behaviour.

Also, document this feature in the bhyve driver page.

Signed-off-by: Roman Bogorodskiy <bogorodskiy@gmail.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
6 years agobhyve: Properly name bhyve help parsing function
Roman Bogorodskiy [Thu, 7 Jun 2018 13:20:53 +0000 (17:20 +0400)]
bhyve: Properly name bhyve help parsing function

Currently there's a function called bhyveProbeCapsRTC_UTC() that
parses bhyve capabilities from the bhyve help output (bhyve -h).
Right now it only checks the '-u' flag, but as there will be more
features detectable through this help output, give it more general
name: bhyveProbeCapsFromHelp().

Signed-off-by: Roman Bogorodskiy <bogorodskiy@gmail.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
6 years agoschema: remove reference to brctl
Ján Tomko [Thu, 7 Jun 2018 07:08:41 +0000 (09:08 +0200)]
schema: remove reference to brctl

ip(8) is the contemporary way of configuring bridges.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
6 years agotravis: Whitespace fixes
Andrea Bolognani [Thu, 7 Jun 2018 13:41:40 +0000 (15:41 +0200)]
travis: Whitespace fixes

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
6 years agotravis: switch to using Ubuntu 16.04 and 18.04
Daniel P. Berrangé [Tue, 5 Jun 2018 14:20:04 +0000 (15:20 +0100)]
travis: switch to using Ubuntu 16.04 and 18.04

The container images provided by Travis only support Ubuntu 14.04,
however, Travis has ability to run docker, which allows the build
script to use arbitrary OS images. This takes advantage of that to
convert the build over to Ubuntu 16.04 and 18.04

This is using the official Ubuntu provided images and installing
extra build deps required, as we previously did with Travis container
images.

Reviewed-by: Andrea Bolognani <abologna@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
6 years agodocs: Tiny fix for the SMM description
Martin Kletzander [Thu, 10 May 2018 19:43:18 +0000 (21:43 +0200)]
docs: Tiny fix for the SMM description

The default is actually `on` when `<smm/>` is specified.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
6 years agodocs: document mandatory signoffs in governance.html
Ján Tomko [Tue, 5 Jun 2018 18:57:43 +0000 (20:57 +0200)]
docs: document mandatory signoffs in governance.html

Amend the paragraphs about no CLAs and implicit license
agreements to mention mandatory Signed-off-by tags.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
6 years agovirsh: fix help for detach-disk --print-xml
Ján Tomko [Thu, 7 Jun 2018 07:21:14 +0000 (09:21 +0200)]
virsh: fix help for detach-disk --print-xml

The help message was copied from attach-interface.
Introduced by commit <431e736>.

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

Signed-off-by: Ján Tomko <jtomko@redhat.com>
6 years agoqemu_tpm: Drop needles include of cap-ng.h
Michal Privoznik [Thu, 7 Jun 2018 06:32:11 +0000 (08:32 +0200)]
qemu_tpm: Drop needles include of cap-ng.h

qemu_tpm.c is not calling any capng_* functions. Let's drop this
include then. This also fixes a build failure without capng.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
6 years agofdstream: Report error from the I/O thread
John Ferlan [Wed, 6 Jun 2018 12:38:30 +0000 (08:38 -0400)]
fdstream: Report error from the I/O thread

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

Commit id 0fe4aa14 added the thread specific error message
reporting (or save) to virFDStreamEvent; however, as processing
goes via virStream{Send|SendHole|Recv} via calls from
daemonStreamHandle{WriteData|Hole|Read} the last error
gets reset in the main libvirt API's thus, whatever error
may have been set as last error will be cleared prior to
the error paths using it resulting in the generic error
on the client side.

For each of the paths that check threadQuit or threadErr,
check if threadErr was set and set it agian if there isn't
a last error (e.g. some other failure) set so that the
message can be provided back to the client.

Signed-off-by: John Ferlan <jferlan@redhat.com>
ACKed-by: Michal Privoznik <mprivozn@redhat.com>
6 years agoutil: Implement and use virFileIsRegular() rather than d_type
Stefan Berger [Wed, 6 Jun 2018 16:24:12 +0000 (12:24 -0400)]
util: Implement and use virFileIsRegular() rather than d_type

The dirent's d_type field is not portable to all platforms. So we have
to use stat() to determine the type of file for the functions that need
to be cross-platform. Fix virFileChownFiles() by calling the new
virFileIsRegular() function.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
6 years agoDon't use enums in TPM struct fields
Daniel P. Berrangé [Wed, 6 Jun 2018 16:37:49 +0000 (17:37 +0100)]
Don't use enums in TPM struct fields

When using an enum in a struct field, the compiler is free to decide to
make it an unsigned type if it desires. This in turn leads to bugs when
code does

    if ((def->foo = virDomainFooTypeFromString(str)) < 0)
       ...

because 'def->foo' can't technically have an unsigned value from the
compiler's POV. While it is possible to add (int) casts in the code
example above, this is not desirable because it is easy to miss out
such casts. eg the code fixed here caused an error with clang builds

../../src/conf/domain_conf.c:12838:73: error: comparison of unsigned enum expression < 0 is always false [-Werror,-Wtautological-compare]
        if ((def->version = virDomainTPMVersionTypeFromString(version)) < 0) {
            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^ ~

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
6 years agostorage: fix crash in luks encrypted volume creation
Katerina Koukiou [Wed, 6 Jun 2018 14:15:19 +0000 (16:15 +0200)]
storage: fix crash in luks encrypted volume creation

Fix the case when creating a luks encrypted volume
via an xml file without 'secret' element.
libvirtd was receiving SIGSEGV, now proper error is reported for
the missing element.

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

Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com>
6 years agoconf: Use virDomainChrSourceDefClear() rather than VIR_FREE()
Stefan Berger [Thu, 24 May 2018 14:56:09 +0000 (10:56 -0400)]
conf: Use virDomainChrSourceDefClear() rather than VIR_FREE()

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoconf: Use resrc=tpm in case of TPM passthrough following docs
Stefan Berger [Thu, 24 May 2018 14:53:05 +0000 (10:53 -0400)]
conf: Use resrc=tpm in case of TPM passthrough following docs

Fix the resrc field for the TPM passthrough case to show tpm.
This fixes the code to follow the documentation.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoconf: Audit TPM emulator device at domain startup
Stefan Berger [Thu, 24 May 2018 14:51:26 +0000 (10:51 -0400)]
conf: Audit TPM emulator device at domain startup

Extend the existing auditing with auditing for the TPM emulator.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoqemu: Run swtpm_setup in unprivileged mode for a TPM 2.0
Stefan Berger [Wed, 23 May 2018 20:53:09 +0000 (16:53 -0400)]
qemu: Run swtpm_setup in unprivileged mode for a TPM 2.0

swtpm_setup can be run for a TPM 2 in unprivileged mode assuming
XDG_CONFIG_HOME has been set and the necessary configuration files
have been put into that directory.

For current reference also see this link:

https://github.com/stefanberger/swtpm/pull/63

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agonews: Update news with new TPM emulator feature
Stefan Berger [Tue, 22 May 2018 14:55:32 +0000 (10:55 -0400)]
news: Update news with new TPM emulator feature

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoqemu: Add swtpm to emulator cgroup
Stefan Berger [Thu, 5 Apr 2018 19:06:55 +0000 (15:06 -0400)]
qemu: Add swtpm to emulator cgroup

Add the external swtpm to the emulator cgroup so that upper limits of CPU
usage can be enforced on the emulated TPM.

To enable this we need to have the swtpm write its process id (pid) into a
file. We then read it from the file to configure the emulator cgroup.

The PID file is created in /var/run/libvirt/qemu/swtpm:

[root@localhost swtpm]# ls -lZ /var/run/libvirt/qemu/swtpm/
total 4
-rw-r--r--. 1 tss  tss  system_u:object_r:qemu_var_run_t:s0          5 Apr 10 12:26 1-testvm-swtpm.pid
srw-rw----. 1 qemu qemu system_u:object_r:svirt_image_t:s0:c597,c632 0 Apr 10 12:26 1-testvm-swtpm.sock

The swtpm command line now looks as follows:

root@localhost testvm]# ps auxZ | grep swtpm | grep socket | grep -v grep
system_u:system_r:virtd_t:s0:c597,c632 tss 18697 0.0  0.0 28172 3892 ?       Ss   16:46   0:00 /usr/bin/swtpm socket --daemon --ctrl type=unixio,path=/var/run/libvirt/qemu/swtpm/1-testvm-swtpm.sock,mode=0600 --tpmstate dir=/var/lib/libvirt/swtpm/485d0004-a48f-436a-8457-8a3b73e28568/tpm1.2/ --log file=/var/log/swtpm/libvirt/qemu/testvm-swtpm.log --pid file=/var/run/libvirt/qemu/swtpm/1-testvm-swtpm.pid

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoconf: Add support for choosing emulation of a TPM 2.0
Stefan Berger [Wed, 4 Apr 2018 18:40:17 +0000 (14:40 -0400)]
conf: Add support for choosing emulation of a TPM 2.0

This patch extends the TPM's device XML with TPM 2.0 support. This only works
for the emulator type backend and looks as follows:

    <tpm model='tpm-tis'>
      <backend type='emulator' version='2.0'/>
    </tpm>

The swtpm process now has --tpm2 as an additional parameter:

system_u:system_r:svirt_t:s0:c597,c632 tss 18477 11.8  0.0 28364  3868 ?        Rs   11:13  13:50 /usr/bin/swtpm socket --daemon --ctrl type=unixio,path=/var/run/libvirt/qemu/swtpm/testvm-swtpm.sock,mode=0660 --tpmstate dir=/var/lib/libvirt/swtpm/testvm/tpm2,mode=0640 --log file=/var/log/swtpm/libvirt/qemu/testvm-swtpm.log --tpm2 --pid file=/var/run/libvirt/qemu/swtpm/testvm-swtpm.pid

The version of the TPM can be changed and the state of the TPM is preserved.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agosecurity: Label the external swtpm with SELinux labels
Stefan Berger [Wed, 4 Apr 2018 16:40:32 +0000 (12:40 -0400)]
security: Label the external swtpm with SELinux labels

In this patch we label the swtpm process with SELinux labels. We give it the
same label as the QEMU process has. We label its state directory and files
as well. We restore the old security labels once the swtpm has terminated.

The file and process labels now look as follows:

Directory: /var/lib/libvirt/swtpm

[root@localhost swtpm]# ls -lZ
total 4
rwx------. 2 tss  tss  system_u:object_r:svirt_image_t:s0:c254,c932 4096 Apr  5 16:46 testvm

[root@localhost testvm]# ls -lZ
total 8
-rw-r--r--. 1 tss tss system_u:object_r:svirt_image_t:s0:c254,c932 3648 Apr  5 16:46 tpm-00.permall

The log in /var/log/swtpm/libvirt/qemu is labeled as follows:

-rw-r--r--. 1 tss tss system_u:object_r:svirt_image_t:s0:c254,c932 2237 Apr  5 16:46 vtpm.log

[root@localhost 485d0004-a48f-436a-8457-8a3b73e28567]# ps auxZ | grep swtpm | grep ctrl | grep -v grep
system_u:system_r:svirt_t:s0:c254,c932 tss 25664 0.0  0.0 28172  3892 ?        Ss   16:57   0:00 /usr/bin/swtpm socket --daemon --ctrl type=unixio,path=/var/run/libvirt/qemu/swtpm/testvm-swtpm.sock,mode=0660 --tpmstate dir=/var/lib/libvirt/swtpm/testvm/tpm1.2 --log file=/var/log/swtpm/libvirt/qemu/testvm-swtpm.log

[root@localhost 485d0004-a48f-436a-8457-8a3b73e28567]# ps auxZ | grep qemu | grep tpm | grep -v grep
system_u:system_r:svirt_t:s0:c254,c932 qemu 25669 99.0  0.0 3096704 48500 ?    Sl   16:57   3:28 /bin/qemu-system-x86_64 [..]

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agotests: Add test cases for external swtpm TPM emulator
Stefan Berger [Tue, 4 Apr 2017 16:22:31 +0000 (12:22 -0400)]
tests: Add test cases for external swtpm TPM emulator

This patch adds extensions to existing test cases and specific test cases
for the tpm-emulator.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoqemu: Add support for external swtpm TPM emulator
Stefan Berger [Tue, 4 Apr 2017 16:22:31 +0000 (12:22 -0400)]
qemu: Add support for external swtpm TPM emulator

This patch adds support for an external swtpm TPM emulator. The XML for
this type of TPM looks as follows:

 <tpm model='tpm-tis'>
   <backend type='emulator'/>
 </tpm>

The XML will currently only start a TPM 1.2.

Upon first start, libvirt will run `swtpm_setup`, which will simulate the
manufacturing of a TPM and create certificates for it and write them into
NVRAM locations of the emulated TPM.

After that libvirt starts the swtpm TPM emulator using the `swtpm` executable.

Once the VM terminates, libvirt uses the swtpm_ioctl executable to gracefully
shut down the `swtpm` in case it is still running (QEMU did not send shutdown)
or clean up the socket file.

The above mentioned executables must be found in the PATH.

The executables can either be run as root or started as root and switch to
the tss user. The requirement for the tss user comes through 'tcsd', which
is used for the simulation of the manufacturing. Which user is used can be
configured through qemu.conf. By default 'tss' is used.

The swtpm writes out state into files. The state is kept in /var/lib/libvirt/swtpm:

[root@localhost libvirt]# ls -lZ | grep swtpm

drwx--x--x. 7 root root unconfined_u:object_r:virt_var_lib_t:s0 4096 Apr  5 16:22 swtpm

The directory /var/lib/libvirt/swtpm maintains per-TPM state directories.
(Using the uuid of the VM for that since the name can change per VM renaming but
 we need a stable directory name.)

[root@localhost swtpm]# ls -lZ
total 4
drwx------. 2 tss  tss  system_u:object_r:virt_var_lib_t:s0          4096 Apr  5 16:46 485d0004-a48f-436a-8457-8a3b73e28568

[root@localhost 485d0004-a48f-436a-8457-8a3b73e28568]# ls -lZ
total 4
drwx------. 2 tss tss system_u:object_r:virt_var_lib_t:s0 4096 Apr 10 21:34 tpm1.2

[root@localhost tpm1.2]# ls -lZ
total 8
-rw-r--r--. 1 tss tss system_u:object_r:virt_var_lib_t:s0 3648 Apr  5 16:46 tpm-00.permall

The directory /var/run/libvirt/qemu/swtpm/ hosts the swtpm.sock that
QEMU uses to communicate with the swtpm:

root@localhost domain-1-testvm]# ls -lZ
total 0
srw-------. 1 qemu qemu system_u:object_r:svirt_image_t:s0:c597,c632  0 Apr  6 10:24 1-testvm-swtpm.sock

The logfile for the swtpm is in /var/log/swtpm/libvirt/qemu:

[root@localhost-3 qemu]# ls -lZ
total 4
-rw-------. 1 tss tss unconfined_u:object_r:var_log_t:s0 2199 Apr  6 14:01 testvm-swtpm.log

The processes are labeled as follows:

[root@localhost 485d0004-a48f-436a-8457-8a3b73e28567]# ps auxZ | grep swtpm | grep socket | grep -v grep
system_u:system_r:virtd_t:s0-s0:c0.c1023 tss 18697 0.0  0.0 28172 3892 ?       Ss   16:46   0:00 /usr/bin/swtpm socket --daemon --ctrl type=unixio,path=/var/run/libvirt/qemu/swtpm/1-testvm-swtpm.sock,mode=0600 --tpmstate dir=/var/lib/libvirt/swtpm/485d0004-a48f-436a-8457-8a3b73e28568/tpm1.2 --log file=/var/log/swtpm/libvirt/qemu/testvm-swtpm.log

[root@localhost 485d0004-a48f-436a-8457-8a3b73e28567]# ps auxZ | grep qemu | grep tpm | grep -v grep
system_u:system_r:svirt_t:s0:c413,c430 qemu 18702 2.5  0.0 3036052 48676 ?     Sl   16:46   0:08 /bin/qemu-system-x86_64 [...]

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoqemu: Extend QEMU with external TPM support
Stefan Berger [Tue, 4 Apr 2017 16:22:31 +0000 (12:22 -0400)]
qemu: Extend QEMU with external TPM support

Implement functions for managing the storage of the external swtpm as well
as starting and stopping it. Also implement functions to use swtpm_setup,
which simulates the manufacturing of a TPM, which includes creation of
certificates for the device.

Further, the external TPM needs storage on the host that we need to set
up before it can be run. We can clean up the host once the domain is
undefined.

This patch also implements a small layer for external device support that
calls into the TPM device layer if a domain has an attached TPM. This is
the layer we will wire up later on.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoqemu: Extend qemu_conf with tpm-emulator support
Stefan Berger [Tue, 4 Apr 2017 16:22:31 +0000 (12:22 -0400)]
qemu: Extend qemu_conf with tpm-emulator support

Extend qemu_conf with user and group for running the tpm-emulator
and add directories to the configuration for the locations of the
log, state, and socket of the tpm-emulator.

Also add these new directories to the QEMU Makefile.inc.am and
the RPM spec file libvirt.spec.in.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agosecurity: Add DAC and SELinux security for tpm-emulator
Stefan Berger [Tue, 4 Apr 2017 16:22:31 +0000 (12:22 -0400)]
security: Add DAC and SELinux security for tpm-emulator

Extend the DAC and SELinux modules with support for the tpm-emulator.
We label the Unix socket that QEMU connects to after starting swtmp
with DAC and SELinux labels. We do not have to restore the labels in
this case since the tpm-emulator will remove the Unix socket when it
terminates.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoutil: Implement virFileChownFiles()
Stefan Berger [Tue, 4 Apr 2017 16:22:31 +0000 (12:22 -0400)]
util: Implement virFileChownFiles()

Implement virFileChownFiles() which changes file ownership of all
files in a given directory.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoqemu: Extend QEMU capabilities with 'tpm-emulator'
Stefan Berger [Tue, 4 Apr 2017 16:22:31 +0000 (12:22 -0400)]
qemu: Extend QEMU capabilities with 'tpm-emulator'

Extend the QEMU capabilities with tpm-emulator support.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoconf: Add support for external swtpm TPM emulator to domain XML
Stefan Berger [Tue, 4 Apr 2017 16:22:31 +0000 (12:22 -0400)]
conf: Add support for external swtpm TPM emulator to domain XML

This patch adds support for an external swtpm TPM emulator. The XML for
this type of TPM looks as follows:

 <tpm model='tpm-tis'>
   <backend type='emulator'/>
 </tpm>

The XML will currently only define a TPM 1.2.

Extend the documentation.

Add a test case testing the XML parser and formatter.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoqemu: Fix double free in qemuDomainSecretAESClear
John Ferlan [Tue, 5 Jun 2018 20:20:59 +0000 (16:20 -0400)]
qemu: Fix double free in qemuDomainSecretAESClear

Commit id 02b031a4 added a secondary path from which the
incoming @secinfo would not be free'd until the private
data was freed in qemuDomainStorageSourcePrivateDispose.

However, by doing this the original intention to free
@*secinfo afterwards is lost and thus the pass by value
of the secinfo->s.aes (or secinfo->s.plain for its method)
results in not keeping the NULL setting in the various
secret.{username|iv|ciphertext} fields upon return to
qemuDomainSecretInfoClear and eventually will result in
a double free at domain destroy:

    raise ()
    abort ()
    __libc_message ()
    malloc_printerr ()
    _int_free ()
    virFree
    qemuDomainSecretAESClear
    qemuDomainSecretInfoClear
    qemuDomainSecretInfoFree
    qemuDomainStorageSourcePrivateDispose
    virObjectUnref
    virStorageSourceClear
    virStorageSourceFree
    virDomainDiskDefFree
    virDomainDefFree
    virDomainObjRemoveTransientDef
    qemuProcessStop
    qemuDomainDestroyFlags
    virDomainDestroy

Signed-off-by: John Ferlan <jferlan@redhat.com>
ACKed-by: Peter Krempa <pkrempa@redhat.com>
6 years agoqemuBuildNumaArgStr: Simplify @nodeBackends
Michal Privoznik [Wed, 6 Jun 2018 11:00:17 +0000 (13:00 +0200)]
qemuBuildNumaArgStr: Simplify @nodeBackends

Instead of array of pointers to individual buffers it can be
array of buffers directly. This also fixes the following memleak:

==22516== 96 bytes in 4 blocks are definitely lost in loss record 166 of 195
==22516==    at 0x4C2EF26: calloc (vg_replace_malloc.c:711)
==22516==    by 0x5D2C7D5: virAlloc (viralloc.c:144)
==22516==    by 0x56FAABD: qemuBuildNumaArgStr (qemu_command.c:7543)
==22516==    by 0x5701835: qemuBuildCommandLine (qemu_command.c:10112)
==22516==    by 0x575D794: qemuProcessCreatePretendCmd (qemu_process.c:6568)
==22516==    by 0x113338: testCompareXMLToArgv (qemuxml2argvtest.c:549)
==22516==    by 0x138CA3: virTestRun (testutils.c:180)
==22516==    by 0x136CD1: mymain (qemuxml2argvtest.c:2825)
==22516==    by 0x13AD58: virTestMain (testutils.c:1118)
==22516==    by 0x137351: main (qemuxml2argvtest.c:2874)

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
6 years agovirQEMUCapsFreeHostCPUModel: Don't always free host cpuData
Michal Privoznik [Fri, 1 Jun 2018 06:08:10 +0000 (08:08 +0200)]
virQEMUCapsFreeHostCPUModel: Don't always free host cpuData

This function exists because of 5276ec712a44b36. But it is
missing initial check just like virQEMUCapsInitHostCPUModel()
has.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agotests: use a fixed NBD TLS certificate path
Daniel P. Berrangé [Tue, 5 Jun 2018 17:27:32 +0000 (18:27 +0100)]
tests: use a fixed NBD TLS certificate path

The default NBD TLS certificate path varies based on prefix given to
configure, causing tests to fail depending on build options.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
6 years agoall: Replace virGetLastError with virGetLastErrorCode where we can
ramyelkest [Sat, 5 May 2018 12:04:21 +0000 (13:04 +0100)]
all: Replace virGetLastError with virGetLastErrorCode where we can

Replace instances where we previously called virGetLastError just to
either get the code or to check if an error exists with
virGetLastErrorCode to avoid a validity pre-check.

Signed-off-by: Ramy Elkest <ramyelkest@gmail.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
6 years agoutil: virerror: Introduce virGetLastError{Code,Domain} public APIs
ramyelkest [Sat, 5 May 2018 12:04:20 +0000 (13:04 +0100)]
util: virerror: Introduce virGetLastError{Code,Domain} public APIs

Many places in the code call virGetLastError() just to check the
raised error code, or domain. However virGetLastError() can return
NULL, so the code has to check for that first. This patch therefore
introduces virGetLasError{Code,Domain} functions which always return a
valid error code or domain respectively, thus dropping the need to
perform any checks on the error object.

Signed-off-by: Ramy Elkest <ramyelkest@gmail.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
6 years agoutil: Prefer virGetLastErrorMessage over direct err->message usage
ramyelkest [Sat, 5 May 2018 12:04:19 +0000 (13:04 +0100)]
util: Prefer virGetLastErrorMessage over direct err->message usage

Signed-off-by: Ramy Elkest <ramyelkest@gmail.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
6 years agopo: don't install gmo files when --disable-nls is given
Daniel P. Berrangé [Wed, 25 Apr 2018 08:53:09 +0000 (09:53 +0100)]
po: don't install gmo files when --disable-nls is given

With --disable-nls is given we turn off use of gettext in the source
code, but mistakenly still installed the gmo files.

Reported-by: Olaf Hering <olaf@aepfle.de>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
6 years agoqemu: remove pointless connect retry logic in agent
Daniel P. Berrangé [Mon, 16 Apr 2018 14:44:16 +0000 (15:44 +0100)]
qemu: remove pointless connect retry logic in agent

When the agent code was first introduced back in

  commit c160ce3316852a797d7b06b4ee101233866e69a9
  Author: Daniel P. Berrange <berrange@redhat.com>
  Date:   Wed Oct 5 18:31:54 2011 +0100

    QEMU guest agent support

there was code that would loop and retry the connection when opening
the agent socket. At this time, the only thing done in between the
opening of the monitor socket & opening of the agent socket was a
call to set the monitor capabilities. This was a no-op on non-QMP
versions, so in theory there could be a race which let us connect
to the monitor while the agent socket was still not created by QEMU.

In the modern world, however, we long ago mandated the use of QMP
for managing QEMU, so we're guaranteed to have a set capabilities
QMP call. Once we've seen a reply to this, we're guaranteed that
QEMU has fully initialized all backends and is in its event loop.

We can thus be sure the QEMU agent socket is present and don't need
to retry connections to it, even without having the chardev FD passing
feature.

Reviewed-by: John Ferlan <jferlan@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
6 years agoqemu: don't retry connect() if doing FD passing
Daniel P. Berrangé [Wed, 14 Mar 2018 17:27:49 +0000 (17:27 +0000)]
qemu: don't retry connect() if doing FD passing

Since libvirt called bind() and listen() on the UNIX socket, it is
guaranteed that connect() will immediately succeed, if QEMU is running
normally. It will only fail if QEMU has closed the monitor socket by
mistake or if QEMU has exited, letting the kernel close it.

With this in mind we can remove the retry loop and timeout when
connecting to the QEMU monitor if we are doing FD passing. Libvirt can
go straight to sending the QMP greeting and will simply block waiting
for a reply until QEMU is ready.

Reviewed-by: John Ferlan <jferlan@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
6 years agoqemu: support passing pre-opened UNIX socket listen FD
Daniel P. Berrangé [Wed, 14 Mar 2018 12:16:11 +0000 (12:16 +0000)]
qemu: support passing pre-opened UNIX socket listen FD

There is a race condition when spawning QEMU where libvirt has spawned
QEMU but the monitor socket is not yet open. Libvirt has to repeatedly
try to connect() to QEMU's monitor until eventually it succeeds, or
times out. We use kill() to check if QEMU is still alive so we avoid
waiting a long time if QEMU exited, but having a timeout at all is still
unpleasant.

With QEMU 2.12 we can pass in a pre-opened FD for UNIX domain or TCP
sockets. If libvirt has called bind() and listen() on this FD, then we
have a guarantee that libvirt can immediately call connect() and
succeed without any race.

Although we only really care about this for the monitor socket and agent
socket, this patch does FD passing for all UNIX socket based character
devices since there appears to be no downside to it.

We don't do FD passing for TCP sockets, however, because it is only
possible to pass a single FD, while some hostnames may require listening
on multiple FDs to cover IPv4 and IPv6 concurrently.

Reviewed-by: John Ferlan <jferlan@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
6 years agoqemu: probe for -chardev 'fd' parameter for FD passing
Daniel P. Berrangé [Wed, 14 Mar 2018 10:34:37 +0000 (10:34 +0000)]
qemu: probe for -chardev 'fd' parameter for FD passing

QEMU >= 2.12 will support passing of pre-opened file descriptors for
socket based character devices.

Reviewed-by: John Ferlan <jferlan@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
6 years agoqemu: Fix detaching from persistent def in qemuDomainDetachDeviceAliasLiveAndConfig
Peter Krempa [Tue, 5 Jun 2018 07:35:12 +0000 (09:35 +0200)]
qemu: Fix detaching from persistent def in qemuDomainDetachDeviceAliasLiveAndConfig

The code that detaches the device from persistent definition copies the
persistent definition first so that it can easily be rolled back. The
actual detaching is then made in the copy which is assigned back on
success (if the live operation succeeded as well).

This is not the case in qemuDomainDetachDeviceAliasLiveAndConfig where
the definition was copied and put back, but the detaching happened from
the other object which was overwritten.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
6 years agosrc: Drop most of #ifdef WITH_GNUTLS
Michal Privoznik [Mon, 4 Jun 2018 09:12:29 +0000 (11:12 +0200)]
src: Drop most of #ifdef WITH_GNUTLS

Now that GnuTLS is a requirement, we can drop a lot of
conditionally built code. However, not all ifdef-s can go because
we still want libvirt_setuid to build without gnutls.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
6 years agotests: Always build TLS related tests
Michal Privoznik [Tue, 5 Jun 2018 11:39:28 +0000 (13:39 +0200)]
tests: Always build TLS related tests

Since GnuTLS is required there is no way to go with !WITH_GNUTLS
branch and just distribute these files.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
6 years agosrc: Dissolve libvirt_gnutls.syms in libvirt_remote.syms
Michal Privoznik [Mon, 4 Jun 2018 05:11:00 +0000 (07:11 +0200)]
src: Dissolve libvirt_gnutls.syms in libvirt_remote.syms

Now that GnuTLS is required these symbols are going to be present
all the time.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
6 years agosrc: Always build virnettlscontext into libvirt-net-rpc.la
Michal Privoznik [Tue, 5 Jun 2018 11:35:56 +0000 (13:35 +0200)]
src: Always build virnettlscontext into libvirt-net-rpc.la

Since GnuTLS is required there is no way to go with !WITH_GNUTLS
branch and just distribute these files.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
6 years agoconfigure: Require GnuTLS
Michal Privoznik [Mon, 4 Jun 2018 04:51:50 +0000 (06:51 +0200)]
configure: Require GnuTLS

We are building with GnuTLS everywhere because GnuTLS is widely
available. Also, it is desirable to prefer cryptographically
strong PRNG over "/dev/urandom" which is just a fallback.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
6 years agostorage: Add specific check for LUKS encryption support
John Ferlan [Tue, 29 May 2018 15:01:15 +0000 (11:01 -0400)]
storage: Add specific check for LUKS encryption support

Modify virStorageBackendLogicalLVCreate to ensure if encryption
is requested that only type LUKS is supported; otherwise, error.

Signed-off-by: John Ferlan <jferlan@redhat.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
6 years agovircrypto: Drop virCryptoGenerateRandom
Michal Privoznik [Tue, 29 May 2018 08:01:38 +0000 (10:01 +0200)]
vircrypto: Drop virCryptoGenerateRandom

Now that virCryptoGenerateRandom() is plain wrapper over
virRandomBytes() we can drop it in favour of the latter.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
6 years agovirUUIDGenerate don't fall back to virRandomBits
Michal Privoznik [Tue, 29 May 2018 06:35:13 +0000 (08:35 +0200)]
virUUIDGenerate don't fall back to virRandomBits

If virRandomBytes() fails there is no point calling
virRandomBits() because it uses virRandomBytes() internally
again.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
6 years agovirrandom: Make virRandomBits better
Michal Privoznik [Tue, 29 May 2018 06:26:18 +0000 (08:26 +0200)]
virrandom: Make virRandomBits better

Now that we have strong PRNG generator implemented in
virRandomBytes() let's use that instead of gnulib's random_r.

Problem with the latter is in way we seed it: current UNIX time
and libvirtd's PID are not that random as one might think.
Imagine two hosts booting at the same time. There's a fair chance
that those hosts spawn libvirtds at the same time and with the
same PID. This will result in both daemons generating the same
sequence of say MAC addresses [1].

1: https://www.redhat.com/archives/libvirt-users/2018-May/msg00097.html

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
6 years agovirRandomBytes: Use gnutls_rnd whenever possible
Michal Privoznik [Tue, 29 May 2018 07:43:26 +0000 (09:43 +0200)]
virRandomBytes: Use gnutls_rnd whenever possible

While /dev/urandom is not terrible source of random data
gnutls_rnd is better. Prefer that one.

Also, since nearly every platform we build on already has gnutls
(if not all of them) this is going to be used by default.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
6 years agovirRandomBytes: Report error
Michal Privoznik [Tue, 29 May 2018 06:58:46 +0000 (08:58 +0200)]
virRandomBytes: Report error

Instead of having each caller report error move it into the
function. This way we can produce more accurate error messages
too.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
6 years agovirRandomBytes: Prefer saferead over plain read
Michal Privoznik [Tue, 29 May 2018 06:55:28 +0000 (08:55 +0200)]
virRandomBytes: Prefer saferead over plain read

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
6 years agovirCryptoGenerateRandom: Don't allocate return buffer
Michal Privoznik [Tue, 29 May 2018 05:46:32 +0000 (07:46 +0200)]
virCryptoGenerateRandom: Don't allocate return buffer

To unify our vir*Random() functions we need to make
virCryptoGenerateRandom NOT allocate return buffer. It should
just fill given buffer with random data.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
6 years agovirCryptoGenerateRandom: Explain gnults error
Michal Privoznik [Tue, 29 May 2018 05:50:29 +0000 (07:50 +0200)]
virCryptoGenerateRandom: Explain gnults error

When generating random stream using gnults fails an error is
reported. However, the error is not helpful as it contains only
an integer error code (a negative number). Use gnutls_strerror()
to turn the error code into a string explaining what went wrong.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
6 years agovirCryptoGenerateRandom: rename ret
Michal Privoznik [Tue, 29 May 2018 05:48:02 +0000 (07:48 +0200)]
virCryptoGenerateRandom: rename ret

This function allocates a buffer, fills it in with random bytes
and then returns it. However, the buffer is held in @buf
variable, therefore having @ret variable which does not hold
return value of the function is misleading.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
6 years agovirRandomBytes: Fix return value
Michal Privoznik [Tue, 29 May 2018 07:02:57 +0000 (09:02 +0200)]
virRandomBytes: Fix return value

In libvirt when a function wants to return an error code it
should be a negative value. Returning a positive value (or zero)
means success. But virRandomBytes() does not follow this rule.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
6 years agotravis: Install and use ccache on macOS
Andrea Bolognani [Wed, 30 May 2018 12:27:10 +0000 (14:27 +0200)]
travis: Install and use ccache on macOS

As documented in [1], ccache needs to be installed and
configured explicitly on macOS.

[1] https://docs.travis-ci.com/user/caching/#ccache-cache

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
6 years agotravis: Move PATH to macOS-specific environment
Andrea Bolognani [Wed, 30 May 2018 12:24:41 +0000 (14:24 +0200)]
travis: Move PATH to macOS-specific environment

Now that we have separate sections for each build
configuration, there's no reason to set PATH in the global
environment.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
6 years agobuild: Don't install sysconfig files as scripts
Jiri Denemark [Mon, 4 Jun 2018 21:07:16 +0000 (23:07 +0200)]
build: Don't install sysconfig files as scripts

The files are not scripts and should not be executable.

Broken by v4.0.0-294-g5f998681df.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
6 years agoqemu: Fix domain resume after failed migration
Jiri Denemark [Tue, 17 Apr 2018 12:46:29 +0000 (14:46 +0200)]
qemu: Fix domain resume after failed migration

Libvirt relies on being able to kill the destination domain and resume
the source one during migration until we called "cont" on the
destination. Unfortunately, QEMU automatically activates block devices
at the end of migration even when it's called with -S. This wasn't a big
issue in the past since the guest is not running and thus no data are
written to the block devices. However, when QEMU introduced its internal
block device locks, we can no longer resume the source domain once the
destination domain already activated the block devices (and thus
acquired all locks) unless the destination domain is killed first.

Since it's impossible to synchronize the destination and the source
libvirt daemons after a failed migration, QEMU introduced a new
migration capability called "late-block-activate" which ensures QEMU
won't activate block devices until it gets "cont". The only thing we
need to do is to enable this capability whenever QEMU supports it.

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

QEMU commit implementing the capability: v2.12.0-952-g0f073f44df

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agovirDomainDefCopy: Skip ostype checks
Michal Privoznik [Sat, 2 Jun 2018 09:15:55 +0000 (11:15 +0200)]
virDomainDefCopy: Skip ostype checks

When parsing domain XML the virCapsDomainData lookup is performed
in order to fill in missing def->os.arch and def->os.machine
strings. Well, when doing copy of already existing virDomainDef
we don't want any automagic fill in of defaults (and those two
strings are going to be provided at this point anyway by first
parse of the domain XML).

What is even worse is that we do not look up capabilities for
parsed emulator path rather some generic capabilities for parsed
arch. Therefore, if emulator points to qemu under non-default
path (say $HOME/qemu-system-arm) but there's no such qemu under
the default path (say /usr/bin/qemu-system-arm) the capabilities
lookup fails and creating the copy is denied.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agovirFileAccessibleAs: Remove redundant forkRet
Radostin Stoyanov [Tue, 5 Jun 2018 07:11:33 +0000 (08:11 +0100)]
virFileAccessibleAs: Remove redundant forkRet

The variable forkRet is not used after commit 25f8781

Signed-off-by: Radostin Stoyanov <rstoyanov1@gmail.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
6 years agodocs: news: Explain iommu_support improvement
Filip Alac [Fri, 1 Jun 2018 08:16:00 +0000 (10:16 +0200)]
docs: news: Explain iommu_support improvement

Signed-off-by: Filip Alac <filipalac@gmail.com>
6 years agocapabilities: Extend capabilities with iommu_support
Filip Alac [Fri, 1 Jun 2018 08:15:59 +0000 (10:15 +0200)]
capabilities: Extend capabilities with iommu_support

Signed-off-by: Filip Alac <filipalac@gmail.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
6 years agoqemu: hostdev: Move parts of qemuHostdevHostSupportsPassthroughVFIO() into separate...
Filip Alac [Fri, 1 Jun 2018 08:15:58 +0000 (10:15 +0200)]
qemu: hostdev: Move parts of qemuHostdevHostSupportsPassthroughVFIO() into separate function

Signed-off-by: Filip Alac <filipalac@gmail.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
6 years agoqemu: command: Refactor disk commandline formatting
Peter Krempa [Fri, 1 Jun 2018 14:57:44 +0000 (16:57 +0200)]
qemu: command: Refactor disk commandline formatting

Now that we have one place that sets up all disk-related objects to
qemuBlockStorageSourceAttachDataPtr we can easily reuse the data in the
command-line formatter by implementing a worker which will convert the
data.

A huge advantage is that it will be way easier to integrate this with
-blockdev later on.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoqemu: command: Extract setup of one disk's command line
Peter Krempa [Fri, 1 Jun 2018 14:25:18 +0000 (16:25 +0200)]
qemu: command: Extract setup of one disk's command line

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoqemu: command: Rename qemuBuildDiskDriveCommandLine
Peter Krempa [Fri, 1 Jun 2018 14:14:19 +0000 (16:14 +0200)]
qemu: command: Rename qemuBuildDiskDriveCommandLine

It prepares all disk so use the plural form.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoqemu: hotplug: Extract hotplug of TLS into qemuBlockStorageSourceAttachApply
Peter Krempa [Fri, 1 Jun 2018 10:11:06 +0000 (12:11 +0200)]
qemu: hotplug: Extract hotplug of TLS into qemuBlockStorageSourceAttachApply

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoqemu: hotplug: Extract hotplug of secrets into qemuBlockStorageSourceAttachApply
Peter Krempa [Thu, 17 May 2018 08:32:32 +0000 (10:32 +0200)]
qemu: hotplug: Extract hotplug of secrets into qemuBlockStorageSourceAttachApply

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoqemu: hotplug: Extract hotplug of PR into qemuBlockStorageSourceAttachApply
Peter Krempa [Fri, 1 Jun 2018 13:56:47 +0000 (15:56 +0200)]
qemu: hotplug: Extract hotplug of PR into qemuBlockStorageSourceAttachApply

Introduce a new setup function for all the related configuration and
move the setup and attachment of the PR code.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoqemu: Reuse qemuBlockStorageSourceAttachApply in disk hotplug
Peter Krempa [Wed, 16 May 2018 11:39:22 +0000 (13:39 +0200)]
qemu: Reuse qemuBlockStorageSourceAttachApply in disk hotplug

Create a new "Prepare" function and move the drive add code into the new
helpers. This will eventually allow to simplify and unify the attaching
code for use with blockdev at the same time as providing compatibility
with older qemus.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoqemu: alias: Rename qemuAliasFromDisk to qemuAliasDiskDriveFromDisk
Peter Krempa [Thu, 31 May 2018 09:55:24 +0000 (11:55 +0200)]
qemu: alias: Rename qemuAliasFromDisk to qemuAliasDiskDriveFromDisk

Emphasize that it's for the 'drive' part of the disk.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoqemu: hotplug: Remove qemuDomainDelDiskSrcTLSObject
Peter Krempa [Mon, 14 May 2018 10:12:41 +0000 (12:12 +0200)]
qemu: hotplug: Remove qemuDomainDelDiskSrcTLSObject

Replace access via wrapper by direct call to monitor API.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>