]> xenbits.xensource.com Git - libvirt.git/log
libvirt.git
5 years agoRevert "configure: Colorize output"
Peter Krempa [Wed, 18 Sep 2019 06:27:41 +0000 (08:27 +0200)]
Revert "configure: Colorize output"

The colors are not based on the semantics of the message but rather
on the message itself. This means that the default human-perceived
semantics (red = bad, green = good) don't really apply and spotting a
color does not mean anythting.

This is amplified by the sheer amount of output which configure produces
and the fact that some of the messages have negative semantics or
additional output.

In case of any problem the user will have to go through everything
anyways as spotting a red or yellow line has 0 information value.

Here are a few examples:

1) some 'no' messages are not a problem:

  checking minix/config.h presence... no

2) some 'no' messages are actually positive:

  checking for special C compiler options needed for large files... no

3) in some cases a 'yes' would mean that something is broken or needs
   workaround

  checking whether stat file-mode macros are broken... no
  checking whether wint_t is too small... no
  checking whether stdint.h predates C++11... no
  checking whether the inttypes.h PRIxNN macros are broken... no
  checking whether clang gives bogus warnings for -Wdouble-promotion... no
  checking whether gettimeofday clobbers localtime buffer... no

4) due to string match based colors extra text makes messages yellow

  checking for a traditional french locale... none
  checking for working nanosleep... no (mishandles large arguments)
  checking for library containing gethostbyname... none required
  checking whether mbrtowc handles incomplete characters... (cached) guessing yes

5) in some cases the yes/no is very context dependant

  checking whether pthread_rwlock_rdlock prefers a writer to a reader... no
  checking whether this build is done by a static analysis tool... no

6) detected paths to binaries and libs are yellow despite being present

  checking for objdump... objdump
  checking for atomic ops implementation... gcc

As of the reasons above I don't think the colorization of the configure
output helps users or developers to debug the build process and
thus is not worth the extra code or output clutter.

This reverts commit c98174ce087fe23f567292132e961d4685faf337.

ACKed-by: Michal Prívozník <mprivozn@redhat.com>
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
5 years agoRevert "virt-result.m4: Colourize summary printings"
Peter Krempa [Wed, 18 Sep 2019 06:18:53 +0000 (08:18 +0200)]
Revert "virt-result.m4: Colourize summary printings"

The colorization based on the string itself makes little to no sense as
the semantic meaning of the color (red = bad, green = good) is not
extracted from the semantics of the message:

1) If there is some additional string a 'yes' is marked yellow:

configure:       driver_modules: yes (CFLAGS='' LIBS='-ldl')

2) In some cases a 'no' is actually good:

configure:                  hal: no

3) Few good/recommended configuration options are still yellow:

configure:                 QEMU: qemu:qemu

while using 'root:root' would still be yellow.

4) fields dumping config (e.g. the warning flags line) is a giant blob
  of colored text which makes little sense

configure:        Warning Flags:  -fno-common -W -Wabsolute-value
-Waddress -Waddress-of-packed-member -Waggressive-loop-optimizations
-Wall -Wattribute-warning -Wattributes -Wbad-function-cast
-Wbool-compare -Wbool-operation -Wbuiltin-declaration-mismatch
-Wbuiltin-macro-redefined -Wcannot-profile -Wcast-align
-Wcast-align=strict -Wcast-function-type -Wchar-subscripts -Wclobbered
-Wcomment -Wcomments -Wcoverage-mismatch -Wcpp -Wdangling-else
-Wdate-time -Wdeprecated-declarations -Wdesignated-init
-Wdiscarded-array-qualifiers -Wdiscarded-qualifiers -Wdiv-by-zero
-Wdouble-promotion -Wduplicated-cond -Wduplicate-decl-speci ...

In addition if the idea is to switch to a more usable build system it
does not make sense to clutter the current one with more code.

This reverts commit 4b3ab5d2135a0dccd654491ef3a4f5b71575deae.

ACKed-by: Michal Prívozník <mprivozn@redhat.com>
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
5 years agoconf: secret: Refactor cleanup in secretXMLParseNode
Peter Krempa [Mon, 16 Sep 2019 11:44:39 +0000 (13:44 +0200)]
conf: secret: Refactor cleanup in secretXMLParseNode

Use VIR_AUTO* for temporary locals and get rid of the 'cleanup' label.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
5 years agoconf: secret: Register VIR_AUTOPTR function for virSecretDef
Peter Krempa [Mon, 16 Sep 2019 11:23:51 +0000 (13:23 +0200)]
conf: secret: Register VIR_AUTOPTR function for virSecretDef

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
5 years agoconf: domain: Refactor cleanup in virDomainDefParseNode
Peter Krempa [Mon, 16 Sep 2019 11:43:44 +0000 (13:43 +0200)]
conf: domain: Refactor cleanup in virDomainDefParseNode

Use VIR_AUTOPTR for temporary locals and get rid of the cleanup label.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
5 years agoconf: domain: Register VIR_AUTOPTR function for virDomainDef
Peter Krempa [Mon, 16 Sep 2019 11:23:00 +0000 (13:23 +0200)]
conf: domain: Register VIR_AUTOPTR function for virDomainDef

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
5 years agoconf: Use VIR_AUTOPTR for xmlDoc and xmlXPath objects
Peter Krempa [Mon, 16 Sep 2019 11:16:36 +0000 (13:16 +0200)]
conf: Use VIR_AUTOPTR for xmlDoc and xmlXPath objects

Refactor functions using these two object types together with
VIR_AUTOPTR.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
5 years agoconf: Use automatic pointers for xmlXPathContext
Peter Krempa [Mon, 16 Sep 2019 10:52:57 +0000 (12:52 +0200)]
conf: Use automatic pointers for xmlXPathContext

Clean up functions which grab and free the context to use VIR_AUTOPTR.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
5 years agoconf: Refactor resource cleanup in virDomainDeviceDefParse
Peter Krempa [Mon, 16 Sep 2019 11:36:34 +0000 (13:36 +0200)]
conf: Refactor resource cleanup in virDomainDeviceDefParse

Use VIR_AUTO* helpers to get rid of the convoluted cleanup path.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
5 years agoconf: network: Use VIR_AUTOPTR in virNetworkDefUpdateSection
Peter Krempa [Mon, 16 Sep 2019 11:25:40 +0000 (13:25 +0200)]
conf: network: Use VIR_AUTOPTR in virNetworkDefUpdateSection

Add automatic cleanup for variables of xmlDoc and xmlXPathContext type
to remove the cleanup section.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
5 years agoutil: xml: Add wrapper for xmlXPathNewContext
Peter Krempa [Mon, 9 Sep 2019 06:33:58 +0000 (08:33 +0200)]
util: xml: Add wrapper for xmlXPathNewContext

The wrapper reports libvirt errors for the libxml2 function so that
the same does not have to be repeated over and over.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
5 years agovirsh: Don't open-code virJSONStringReformat in cmdQemuMonitorCommand
Peter Krempa [Mon, 9 Sep 2019 08:55:20 +0000 (10:55 +0200)]
virsh: Don't open-code virJSONStringReformat in cmdQemuMonitorCommand

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agovirsh: Use VIR_AUTO machinery in cmdQemuMonitorCommand
Peter Krempa [Mon, 9 Sep 2019 08:51:25 +0000 (10:51 +0200)]
virsh: Use VIR_AUTO machinery in cmdQemuMonitorCommand

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agovirsh: Use virshDomain type in 'inject-nmi'
Peter Krempa [Mon, 9 Sep 2019 08:41:15 +0000 (10:41 +0200)]
virsh: Use virshDomain type in 'inject-nmi'

With a nice side-effect of fixing alignment.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agovirsh: demonstrate use of VIR_AUTOPTR(virshDomain) on 'send-process-signal'
Peter Krempa [Mon, 9 Sep 2019 08:39:04 +0000 (10:39 +0200)]
virsh: demonstrate use of VIR_AUTOPTR(virshDomain) on 'send-process-signal'

Refactor the command code to use the new type.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agovirsh: Allow using VIR_AUTOPTR for releasing virDomainPtr in virsh
Peter Krempa [Mon, 9 Sep 2019 08:36:39 +0000 (10:36 +0200)]
virsh: Allow using VIR_AUTOPTR for releasing virDomainPtr in virsh

I opted to alias the 'virDomainType' to 'virshDomain' so that it's
obvious in all cases that this is a virsh-only construct. This is also
somewhat consistent with virsh's use of 'virshDomainFree' wrapper for
the freeing function which actually accepts NULL.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoutil: remove some no-op thread functions
Daniel P. Berrangé [Mon, 16 Sep 2019 16:44:23 +0000 (17:44 +0100)]
util: remove some no-op thread functions

Neither virThreadInitialize or virThreadOnExit do anything since we
dropped the Win32 threads impl, in favour of win-pthreads with:

  commit 0240d94c36c8ce0e7c35b5be430acd9ebf5adcfa
  Author: Daniel P. Berrange <berrange@redhat.com>
  Date:   Wed Jan 22 16:17:10 2014 +0000

      Remove windows thread implementation in favour of pthreads

Reviewed-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agoRevert "qemu: add socket datagram capability"
Michal Privoznik [Tue, 10 Sep 2019 09:09:13 +0000 (11:09 +0200)]
Revert "qemu: add socket datagram capability"

This reverts commit 0cebb6422a63f5a8289ae43a36f8f33eb9956a4c.

This capability is not used anywhere and also it is not contained
in any release so it's safe to just remove it.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemu: Enable slirp-helper iff dbus-vmstate present
Michal Privoznik [Tue, 10 Sep 2019 08:12:24 +0000 (10:12 +0200)]
qemu: Enable slirp-helper iff dbus-vmstate present

The fact that qemu is capable -netdev socket is not enough to
start a migratable domain. It also needs dbus-vmstate capability.
Since there are already some qemu releases which have
net-socket-dgram capability and don't have dbus-vmstate we need
to check for dbus-vmstate.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoRevert "qemu_capabilities: Temporarily disable dbus-vmstate capability"
Michal Privoznik [Thu, 19 Sep 2019 09:27:12 +0000 (11:27 +0200)]
Revert "qemu_capabilities: Temporarily disable dbus-vmstate capability"

This reverts commit 929e0bd267fe735924d445df6bb5e6d02330f3c3.

I've mistakenly pushed wrong branch.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
5 years agoRevert "Temporarily disable bla"
Michal Privoznik [Thu, 19 Sep 2019 09:26:56 +0000 (11:26 +0200)]
Revert "Temporarily disable bla"

This reverts commit 385543a543d224bcfeeafcfbb9f6a2dc53b4d078.

I've mistakenly pushed wrong branch.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
5 years agoTemporarily disable bla
Michal Privoznik [Mon, 9 Sep 2019 09:40:56 +0000 (11:40 +0200)]
Temporarily disable bla

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
5 years agoqemu_capabilities: Temporarily disable dbus-vmstate capability
Michal Privoznik [Fri, 6 Sep 2019 12:19:10 +0000 (14:19 +0200)]
qemu_capabilities: Temporarily disable dbus-vmstate capability

The qemu side is not merged in yet, so there is a chance that the
interface will change. Don't detect the capability just yet then.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
5 years agomaint: Use flake8 to check python code
Shi Lei [Wed, 18 Sep 2019 04:19:43 +0000 (12:19 +0800)]
maint: Use flake8 to check python code

Replace 'sc_prohibit_semicolon_at_eol_in_python' with generic 'sc_flake8' rule
to check python code style.

Now 'sc_flake8' just check the error E703: 'statement ends with a semicolon'.
In future, we could use '--select' to introduce more rules.

Signed-off-by: Shi Lei <shi_lei@massclouds.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemuBuildMemoryCellBackendStr: remove useless ret variable
Ján Tomko [Mon, 26 Aug 2019 20:38:51 +0000 (22:38 +0200)]
qemuBuildMemoryCellBackendStr: remove useless ret variable

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Cole Robinson <crobinso@redhat.com>
5 years agoqemuBuildMemoryBackendProps: use 'rc' instead of ret.
Ján Tomko [Mon, 26 Aug 2019 20:37:41 +0000 (22:37 +0200)]
qemuBuildMemoryBackendProps: use 'rc' instead of ret.

Do not overwrite the 'ret' value more than once.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Cole Robinson <crobinso@redhat.com>
5 years agoqemuBuildMemoryBackendProps: remove useless cleanup label
Ján Tomko [Mon, 26 Aug 2019 20:36:32 +0000 (22:36 +0200)]
qemuBuildMemoryBackendProps: remove useless cleanup label

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Cole Robinson <crobinso@redhat.com>
5 years agoqemuBuildSoundCommandLine: reduce scope of codecstr
Ján Tomko [Mon, 26 Aug 2019 20:23:50 +0000 (22:23 +0200)]
qemuBuildSoundCommandLine: reduce scope of codecstr

Copy the declaration into the smallest blocks it's used in
and mark it as VIR_AUTOFREE.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Cole Robinson <crobinso@redhat.com>
5 years agoqemuBuildHostNetStr: remove unnecessary cleanup label
Ján Tomko [Mon, 26 Aug 2019 20:28:27 +0000 (22:28 +0200)]
qemuBuildHostNetStr: remove unnecessary cleanup label

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Cole Robinson <crobinso@redhat.com>
5 years agoqemuBuildHostNetStr: remove unused 'driver' argument
Ján Tomko [Mon, 26 Aug 2019 20:21:56 +0000 (22:21 +0200)]
qemuBuildHostNetStr: remove unused 'driver' argument

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Cole Robinson <crobinso@redhat.com>
5 years agoqemuBuildHostNetStr: remove unused cfg
Ján Tomko [Mon, 26 Aug 2019 19:56:42 +0000 (21:56 +0200)]
qemuBuildHostNetStr: remove unused cfg

As of commit 2d80fbb14dffa45fe3fcd2c3f29ce54857bb766c this variable
is unused.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Cole Robinson <crobinso@redhat.com>
5 years agovz: build fix for passing qemuCaps to virDomainDefParseNode
Nikolay Shirokovskiy [Wed, 18 Sep 2019 06:59:32 +0000 (09:59 +0300)]
vz: build fix for passing qemuCaps to virDomainDefParseNode

Missing piece for [1]

[1]: 577a1f98: qemu: Pass correct qemuCaps to virDomainDefParseNode

Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
5 years agovz: build fix for passing qemuCaps to virDomainDeviceDefPostParse
Nikolay Shirokovskiy [Wed, 18 Sep 2019 06:57:08 +0000 (09:57 +0300)]
vz: build fix for passing qemuCaps to virDomainDeviceDefPostParse

Missing piece for [1].

[1] b449c2704: qemu: Pass correct qemuCaps to virDomainDeviceDefPostParse

Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
5 years agovirStrncpy: fix to successfully copy empty string
Nikolay Shirokovskiy [Mon, 16 Sep 2019 13:55:36 +0000 (16:55 +0300)]
virStrncpy: fix to successfully copy empty string

After [1] we got failure on attempt to copy empty string.
Before the patch empty string was copied successfuly.
Restore the original behaviour.

[1] 7d70a63b util: Improve virStrncpy() implementation

Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
5 years agoremote: fix registration of TLS socket
Michael Chapman [Tue, 17 Sep 2019 07:03:57 +0000 (17:03 +1000)]
remote: fix registration of TLS socket

Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Signed-off-by: Michael Chapman <mike@very.puzzling.org>
5 years agoutil: fix byte order of port in virSocketAddrResolveService
Michael Chapman [Tue, 17 Sep 2019 07:03:56 +0000 (17:03 +1000)]
util: fix byte order of port in virSocketAddrResolveService

The ports in the socket address structures returned by getaddrinfo() are
in network byte order. Convert to host byte order before returning them.

Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Signed-off-by: Michael Chapman <mike@very.puzzling.org>
5 years agoremote: pass identity across to newly opened daemons
Daniel P. Berrangé [Fri, 26 Jul 2019 15:34:15 +0000 (16:34 +0100)]
remote: pass identity across to newly opened daemons

When opening a connection to a second driver inside the daemon, we must
ensure the identity of the current user is passed across. This allows
the second daemon to perform access control checks against the real end
users, instead of against the libvirt daemon that's proxying across the
API calls.

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agoutil: allow identity to be imported/exported as typed parameters
Daniel P. Berrangé [Fri, 26 Jul 2019 15:36:29 +0000 (16:36 +0100)]
util: allow identity to be imported/exported as typed parameters

Add ability to import/export all the parameters associated with an
identity, so that they can be exposed via the public API.

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agoutil: store identity attrs as virTypedParameter internally
Daniel P. Berrangé [Fri, 26 Jul 2019 15:27:25 +0000 (16:27 +0100)]
util: store identity attrs as virTypedParameter internally

We'll shortly be exposing the identity as virTypedParameter in the
public header, so it simplifies life to use that as the internal
representation too.

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agoutil: sanitize return values for virIdentity getters
Daniel P. Berrangé [Wed, 7 Aug 2019 15:30:57 +0000 (16:30 +0100)]
util: sanitize return values for virIdentity getters

The virIdentity getters are unusual in that they return -1 to indicate
"not found" and don't report any error. Change them to return -1 for
real errors, 0 for not found, and 1 for success.

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agoutil: removed unused virIdentityIsEqual method
Daniel P. Berrangé [Tue, 6 Aug 2019 15:52:03 +0000 (16:52 +0100)]
util: removed unused virIdentityIsEqual method

It is simpler to remove this unused method than to rewrite it using
typed parameters in the next patch.

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agoutil: make generic identity accessors private
Daniel P. Berrangé [Fri, 26 Jul 2019 11:21:29 +0000 (12:21 +0100)]
util: make generic identity accessors private

Only expose the type safe getters/setters to other code in preparation
for changing the internal storage of data.

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Andrea Bolognani <abologna@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agotests: fix debug messages wrt selinux context when test fails
Daniel P. Berrangé [Tue, 6 Aug 2019 15:45:14 +0000 (16:45 +0100)]
tests: fix debug messages wrt selinux context when test fails

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Andrea Bolognani <abologna@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agoutil: change identity class attribute names
Daniel P. Berrangé [Fri, 26 Jul 2019 10:59:15 +0000 (11:59 +0100)]
util: change identity class attribute names

Remove the "UNIX" tag from the names for user name, group name,
process ID and process time, since these attributes are all usable
for non-UNIX platforms like Windows.

User ID and group ID are left with a "UNIX" tag, since there's no
equivalent on Windows. The closest equivalent concept on Windows,
SID, is a struct containing a number of integer fields, which is
commonly represented in string format instead. This would require
a separate attribute, and is left for a future exercise, since
the daemons are not currently built on Windows anyway.

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agoapi: introduce virConnectSetIdentity for passing uid, gid, selinux info
Daniel P. Berrangé [Wed, 24 Jul 2019 11:38:21 +0000 (12:38 +0100)]
api: introduce virConnectSetIdentity for passing uid, gid, selinux info

When using the fine grained access control mechanism for APIs, when a
client connects to libvirtd, the latter will fetch the uid, gid, selinux
info of the remote client on the UNIX domain socket. This is then used
as the identity when checking ACLs.

With the new split daemons things are a bit more complicated. The user
can connect to virtproxyd, which in turn connects to virtqemud. When
virtqemud requests the identity over the UNIX domain socket, it will
get the identity that virtproxyd is running as, not the identity of
the real end user/application.

virproxyd knows what the real identity is, and needs to be able to
forward this information to virtqemud. The virConnectSetIdentity API
provides a mechanism for doing this. Obviously virtqemud should not
accept such identity overrides from any client, it must only honour it
from a trusted client, aka one running as the same uid/gid as itself.

The typed parameters exposed in the API are the same as those currently
supported by the internal virIdentity class, with a few small name
changes.

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agoqemu: blockjob: Refuse to register blockjob if disk already has one
Peter Krempa [Sat, 14 Sep 2019 07:40:29 +0000 (09:40 +0200)]
qemu: blockjob: Refuse to register blockjob if disk already has one

Most code paths prevent starting a blockjob if we already have one but
the job registering function does not do this check. While this isn't a
problem for regular cases we had a bad test case where we registered two
jobs for a single disk which leaked one of the jobs. Prevent this in the
registering function until we allow having multiple jobs per disk.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
ACKed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
5 years agotests: qemustatusxml2xml: Fix disk target mess
Peter Krempa [Sat, 14 Sep 2019 07:54:07 +0000 (09:54 +0200)]
tests: qemustatusxml2xml: Fix disk target mess

There were accidentally two disks with 'vdc' target with corresponding
blockjobs which made libvirt leak some references as there are not
supposed to be two blockjobs for a single disk. Fix this mess by
renaming some of the disks.

In addition the block job names also didn't correspond to the naming
convetion which also includes the disk target. Fix it as well.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
ACKed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
5 years agoqemu: call common NetDef validation for hotplug and device update
Laine Stump [Fri, 13 Sep 2019 01:22:30 +0000 (21:22 -0400)]
qemu: call common NetDef validation for hotplug and device update

qemuDomainAttachNetDevice() (hotplug) previously had some of the
validation that is in qemuDomainValidateActualNetDef(), but it was
incomplete. qemuDomainChangeNet() had none of that validation, but it
is all appropriate in both cases.

This is the final piece of a previously partial resolution to
https://bugzilla.redhat.com/1502754

Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
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>