]> xenbits.xensource.com Git - libvirt.git/log
libvirt.git
6 years agosnapshot: Drop virDomainSnapshotDef.current
Eric Blake [Tue, 19 Mar 2019 03:56:19 +0000 (22:56 -0500)]
snapshot: Drop virDomainSnapshotDef.current

The only use for the 'current' member of virDomainSnapshotDef was with
the PARSE/FORMAT_INTERNAL flag for controlling an internal-use
<active> element marking whether a particular snapshot definition was
current, and even then, only by the qemu driver on output, and by qemu
and test driver on input. But this duplicates vm->snapshot_current,
and gets in the way of potential simplifications to have qemu store a
single file for all snapshots rather than one file per snapshot.  Get
rid of the member by adding a bool* parameter during parse (ignored if
the PARSE_INTERNAL flag is not set), and by adding a new flag during
format (if FORMAT_INTERNAL is set, the value printed in <active>
depends on the new FORMAT_CURRENT).

Then update the qemu driver accordingly, which involves hoisting
assignments to vm->current_snapshot to occur prior to any point where
a snapshot XML file is written (although qemu kept
vm->current_snapshot and snapshot->def_current in sync by the end of
the function, they were not always identical in the middle of
functions, so the shuffling gets a bit interesting). Later patches
will clean up some of that confusing churn to vm->current_snapshot.

Note: even if later patches refactor qemu to no longer use
FORMAT_INTERNAL for output (by storing bulk snapshot XML instead), we
will always need PARSE_INTERNAL for input (because on upgrade, a new
libvirt still has to parse XML left from a previous libvirt).

Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
6 years agosnapshot: Minor cleanup to virDomainSnapshotAssignDef
Eric Blake [Fri, 22 Mar 2019 06:05:06 +0000 (01:05 -0500)]
snapshot: Minor cleanup to virDomainSnapshotAssignDef

When a future patch converts virDomainSnapshotDef to be a virObject,
we need to be careful that converting VIR_FREE() to virObjectUnref()
does not result in double frees. Reorder the assignment of def into
the object to the point after object is in the hash table (as
otherwise the virHashAddEntry() error path would have a shot at
freeing def prematurely).

Suggested-by: John Ferlan <ferlan@redhat.com>
Signed-off-by: Eric Blake <eblake@redhat.com>
6 years agosnapshot: Tweaks to bulk dumpxml/import internals
Eric Blake [Mon, 11 Mar 2019 11:50:23 +0000 (06:50 -0500)]
snapshot: Tweaks to bulk dumpxml/import internals

Change the return value of virDomainSnapshotObjListParse() to return
the number of snapshots imported, and allow a return of 0 (the
original proposal of adding a flag to virDomainSnapshotCreateXML
required returning an arbitrary non-NULL snapshot, but that idea was
abandoned; and by returning a count, we are no longer constrained to a
non-empty list).

Document which flags are supported (namely, just SECURE) in
virDomainSnapshotObjListFormat().

Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
6 years agovbox: Clean up some snapshot usage
Eric Blake [Thu, 21 Mar 2019 16:41:26 +0000 (11:41 -0500)]
vbox: Clean up some snapshot usage

An upcoming patch will be reworking virDomainSnapshotDef to have a
base class; minimize the churn by using a local variable to reduce the
number of dereferences required when acessing the domain definition
associated with the snapshot.

Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
6 years agotests: qemuxml2argv: move DO_TEST qemuCaps init
Cole Robinson [Thu, 14 Mar 2019 10:19:28 +0000 (06:19 -0400)]
tests: qemuxml2argv: move DO_TEST qemuCaps init

Move DO_TEST* qemuCaps init into testInfoSetArgs. This is a step
towards unifying the different test macro implementations

Reviewed-by: Andrea Bolognani <abologna@redhat.com>
Signed-off-by: Cole Robinson <crobinso@redhat.com>
6 years agotests: qemuxml2argv: add testInfoClear
Cole Robinson [Thu, 14 Mar 2019 09:54:00 +0000 (05:54 -0400)]
tests: qemuxml2argv: add testInfoClear

This is closer to the pattern of qemuxml2xml tests, and will make
things easier if we extend testInfo to contain more freeable data

Reviewed-by: Andrea Bolognani <abologna@redhat.com>
Signed-off-by: Cole Robinson <crobinso@redhat.com>
6 years agotests: qemuxml2argv: build capsfile in DO_TEST_CAPS_INTERNAL
Cole Robinson [Wed, 13 Mar 2019 23:48:06 +0000 (19:48 -0400)]
tests: qemuxml2argv: build capsfile in DO_TEST_CAPS_INTERNAL

Rather than make callers do it. The operative info is just arch
and ver which we are passing in already.

Fold in stripmachinealiases too since it is just dependent on
ver value

Reviewed-by: Andrea Bolognani <abologna@redhat.com>
Signed-off-by: Cole Robinson <crobinso@redhat.com>
6 years agotests: qemuxml2argv: centralize CAPS suffix building
Cole Robinson [Wed, 13 Mar 2019 23:32:31 +0000 (19:32 -0400)]
tests: qemuxml2argv: centralize CAPS suffix building

Reviewed-by: Andrea Bolognani <abologna@redhat.com>
Signed-off-by: Cole Robinson <crobinso@redhat.com>
6 years agotests: qemuxml2argv: remove full testInfo initialization
Cole Robinson [Wed, 13 Mar 2019 23:26:08 +0000 (19:26 -0400)]
tests: qemuxml2argv: remove full testInfo initialization

Only initialize the fields that are passed in

Reviewed-by: Andrea Bolognani <abologna@redhat.com>
Signed-off-by: Cole Robinson <crobinso@redhat.com>
6 years agotests: qemuxml2argv: use varargs for CAPS flags
Cole Robinson [Wed, 13 Mar 2019 23:15:05 +0000 (19:15 -0400)]
tests: qemuxml2argv: use varargs for CAPS flags

Reviewed-by: Andrea Bolognani <abologna@redhat.com>
Signed-off-by: Cole Robinson <crobinso@redhat.com>
6 years agotests: qemuxml2argv: remove unused CAPS migrateFrom
Cole Robinson [Wed, 13 Mar 2019 22:16:55 +0000 (18:16 -0400)]
tests: qemuxml2argv: remove unused CAPS migrateFrom

Reviewed-by: Andrea Bolognani <abologna@redhat.com>
Signed-off-by: Cole Robinson <crobinso@redhat.com>
6 years agotests: qemuxml2argv: add a comment separating DO_TEST* macros
Cole Robinson [Thu, 14 Mar 2019 13:43:23 +0000 (09:43 -0400)]
tests: qemuxml2argv: add a comment separating DO_TEST* macros

Reviewed-by: Andrea Bolognani <abologna@redhat.com>
Signed-off-by: Cole Robinson <crobinso@redhat.com>
6 years agotests: qemuxml2argv: remove unused DO_TEST_CAPS* macros
Cole Robinson [Thu, 14 Mar 2019 13:41:58 +0000 (09:41 -0400)]
tests: qemuxml2argv: remove unused DO_TEST_CAPS* macros

They are potentially useful at the moment, but we will be making
things much more flexible

Reviewed-by: Andrea Bolognani <abologna@redhat.com>
Signed-off-by: Cole Robinson <crobinso@redhat.com>
6 years agotests: qemuxml2argv: remove DO_TEST_PARSE_FLAGS_ERROR
Cole Robinson [Wed, 13 Mar 2019 21:25:23 +0000 (17:25 -0400)]
tests: qemuxml2argv: remove DO_TEST_PARSE_FLAGS_ERROR

It only has one caller. Just use DO_TEST_FULL

Reviewed-by: Andrea Bolognani <abologna@redhat.com>
Signed-off-by: Cole Robinson <crobinso@redhat.com>
6 years agotests: qemuxml2argv: handle parseFlags with varargs
Cole Robinson [Wed, 13 Mar 2019 20:17:10 +0000 (16:17 -0400)]
tests: qemuxml2argv: handle parseFlags with varargs

This allows us to drop parseFlags from DO_TEST_FULL

Reviewed-by: Andrea Bolognani <abologna@redhat.com>
Signed-off-by: Cole Robinson <crobinso@redhat.com>
6 years agotests: qemuxml2argv: handle flags with varargs
Cole Robinson [Wed, 13 Mar 2019 20:04:44 +0000 (16:04 -0400)]
tests: qemuxml2argv: handle flags with varargs

This allows us to drop flags from DO_TEST_FULL

Reviewed-by: Andrea Bolognani <abologna@redhat.com>
Signed-off-by: Cole Robinson <crobinso@redhat.com>
6 years agotests: qemuxml2argv: handle migrate* with varargs
Cole Robinson [Wed, 13 Mar 2019 19:59:42 +0000 (15:59 -0400)]
tests: qemuxml2argv: handle migrate* with varargs

This allows us to drop migrateFrom and migrateFd from DO_TEST_FULL

Reviewed-by: Andrea Bolognani <abologna@redhat.com>
Signed-off-by: Cole Robinson <crobinso@redhat.com>
6 years agotests: qemuxml2argv: handle GIC with varargs
Cole Robinson [Wed, 13 Mar 2019 19:49:18 +0000 (15:49 -0400)]
tests: qemuxml2argv: handle GIC with varargs

This allows us to drop stub GIC values from DO_TEST_FULL calls

Reviewed-by: Andrea Bolognani <abologna@redhat.com>
Signed-off-by: Cole Robinson <crobinso@redhat.com>
6 years agotests: qemuxml2argv: break apart testInitQEMUCaps
Cole Robinson [Wed, 13 Mar 2019 19:31:16 +0000 (15:31 -0400)]
tests: qemuxml2argv: break apart testInitQEMUCaps

Reviewed-by: Andrea Bolognani <abologna@redhat.com>
Signed-off-by: Cole Robinson <crobinso@redhat.com>
6 years agotests: qemuxml2argv: push ARG_QEMU_CAPS to callers
Cole Robinson [Wed, 13 Mar 2019 19:18:11 +0000 (15:18 -0400)]
tests: qemuxml2argv: push ARG_QEMU_CAPS to callers

This is necessary before we can start adding more optional parameter
implementations to DO_TEST_FULL

Reviewed-by: Andrea Bolognani <abologna@redhat.com>
Signed-off-by: Cole Robinson <crobinso@redhat.com>
6 years agotests: qemuxml2argv: add va_arg enum handling
Cole Robinson [Wed, 13 Mar 2019 22:25:21 +0000 (18:25 -0400)]
tests: qemuxml2argv: add va_arg enum handling

This establishes a pattern that will allow us to make test macros
more general purpose, by taking optional arguments. The general
format will be:

DO_TEST_FULL(...
             ARG_FOO, <value1>,
             ARG_BAR, <value2>)

ARG_X are just enum values that we look for in the va_args and know
how to interpret.

Implement this for the existing implicit qemuCaps va_args

Reviewed-by: Andrea Bolognani <abologna@redhat.com>
Signed-off-by: Cole Robinson <crobinso@redhat.com>
6 years agotests: qemuxml2argv: add testInfoSetArgs
Cole Robinson [Wed, 13 Mar 2019 22:20:57 +0000 (18:20 -0400)]
tests: qemuxml2argv: add testInfoSetArgs

For now it just fills in the qemuCaps list. We will expand it
in future patches

Reviewed-by: Andrea Bolognani <abologna@redhat.com>
Signed-off-by: Cole Robinson <crobinso@redhat.com>
6 years agoqemu: add virQEMUCapsSetVAList
Cole Robinson [Wed, 13 Mar 2019 19:03:45 +0000 (15:03 -0400)]
qemu: add virQEMUCapsSetVAList

And adjust virQEMUCapsSetList to use it. It will also be used in future
patches.

Reviewed-by: Andrea Bolognani <abologna@redhat.com>
Signed-off-by: Cole Robinson <crobinso@redhat.com>
6 years agotest: Avoid use-after-free on virDomainSnapshotDelete
Eric Blake [Sun, 17 Mar 2019 03:57:45 +0000 (22:57 -0500)]
test: Avoid use-after-free on virDomainSnapshotDelete

The following virsh command was triggering a use-after-free:

$ virsh -c test:///default '
  snapshot-create-as test s1
  snapshot-create-as test s2
  snapshot-delete --children-only test s1
  snapshot-current --name test'
Domain snapshot s1 created
Domain snapshot s2 created
Domain snapshot s1 children deleted

error: name in virGetDomainSnapshot must not be NULL

I got lucky on that run - although the error message is quite
unexpected.  On other runs, I was able to get a core dump, and
valgrind confirms there is a definitive problem.

The culprit? We were inconsistent about whether we set
vm->current_snapshot, snap->def->current, or both when updating how
the current snapshot was being tracked.  As a result, deletion did not
see that snapshot s2 was previously current, and failed to update
vm->current_snapshot, so that the next API using the current snapshot
failed because it referenced stale memory for the now-gone s2 (instead
of the intended s1).

The test driver code was copied from the qemu code (which DOES track
both pieces of state everywhere), but was purposefully simplified
because the test driver does not have to write persistent snapshot
state to the file system.  But when you realize that the only reason
snap->def->current needs to exist is when writing out one file per
snapshot for qemu, it's just as easy to state that the test driver
never has to mess with the field (rather than chasing down which
places forgot to set the field), and have vm->current_snapshot be the
sole source of truth in the test driver.

Ideally, I'd get rid of the 'current' member in virDomainSnapshotDef,
as well as the 'current_snapshot' member in virDomainDef, and instead
track the current member in virDomainSnapshotObjList, coupled with
writing ALL snapshot state for qemu in a single file (where I can use
<snapshots current='...'> as a wrapper, rather than
VIR_DOMAIN_SNAPSHOT_FORMAT_INTERNAL to output <current>1</current> XML
on a per-snapshot file basis).  But that's a bigger change, so for now
I'm just patching things to avoid the test driver segfault.

Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agorpm: fix upgrades when RBD is disabled in a new version
Daniel P. Berrangé [Tue, 19 Mar 2019 15:59:36 +0000 (15:59 +0000)]
rpm: fix upgrades when RBD is disabled in a new version

We previously had to disable RBD on 32-bit platforms since Ceph has
dropped all support for 32-bit. Unfortunately anyone with the RPM
libvirt-daemon-driver-storage-rbd installed on 32-bit now has a
broken upgrade path.

To fix this we must make libvirt-daemon-driver-storage-core
have an Obsoletes: libvirt-daemon-driver-storage-rbd < $VER-$REL

Reviewed-by: Erik Skultety <eskultet@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
6 years agovirnwfilterbindingobj: Introduce and use virNWFilterBindingObjStealDef
Michal Privoznik [Wed, 20 Mar 2019 08:59:48 +0000 (09:59 +0100)]
virnwfilterbindingobj: Introduce and use virNWFilterBindingObjStealDef

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

When trying to create a nwfilter binding via
nwfilterBindingCreateXML() we may encounter a crash. The sequence
of functions called is as follows:

1) nwfilterBindingCreateXML() parses the XML and calls
virNWFilterBindingObjListAdd() which calls
virNWFilterBindingObjListAddLocked()

2) Here, @binding is not found because binding->remove is set.

3) Therefore, controls continue with creating new @binding,
setting its def to the one from 1) and adding it to the hash
table.

4) This fails, because the binding is still in the hash table
(duplicate key is detected).

5) The control jumps to 'error' label where
virNWFilterBindingObjEndAPI() is called which frees the binding
definition passed.

6) Error is propagated to the caller, which calls
virNWFilterBindingDefFree() over the definition again.

The solution is to unset binding->def in case of failure so it's
not freed in step 5).

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoconf: Fold private data parsing into virDomainStorageSourceParse
Peter Krempa [Fri, 15 Mar 2019 15:33:38 +0000 (16:33 +0100)]
conf: Fold private data parsing into virDomainStorageSourceParse

Storage source private data can be parsed along with other components of
private data rather than a separate function which is called from
multiple places.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoconf: Simplify error paths in storage source component parsers
Peter Krempa [Fri, 8 Mar 2019 13:28:07 +0000 (14:28 +0100)]
conf: Simplify error paths in storage source component parsers

virDomainDiskSourcePrivateDataParse and virDomainDiskSourcePRParse don't
need the 'cleanup' label any more thanks to VIR_XPATH_NODE_AUTORESTORE.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoconf: Refactor control flow in virDomainDiskBackingStoreParse
Peter Krempa [Mon, 11 Mar 2019 15:10:35 +0000 (16:10 +0100)]
conf: Refactor control flow in virDomainDiskBackingStoreParse

The function does not have any code in the 'cleanup' label so we can
simplify the control flow.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agotests: Refactor control flow in testBackingXMLjsonXML
Peter Krempa [Fri, 8 Mar 2019 15:11:20 +0000 (16:11 +0100)]
tests: Refactor control flow in testBackingXMLjsonXML

Get rid of the 'cleanup' label.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agotests: Use full force of our VIR_AUTO* machinery in testBackingXMLjsonXML
Peter Krempa [Fri, 8 Mar 2019 15:10:07 +0000 (16:10 +0100)]
tests: Use full force of our VIR_AUTO* machinery in testBackingXMLjsonXML

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoutil: xml: Introduce VIR_AUTOPTR functions for xmlDoc and xmlXPathContext
Peter Krempa [Fri, 8 Mar 2019 15:02:27 +0000 (16:02 +0100)]
util: xml: Introduce VIR_AUTOPTR functions for xmlDoc and xmlXPathContext

We can use our VIR_AUTOPTR machinery also for libxml2's xmlDoc and
xmlXPathContext.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoconf: cleanup error path in virDomainStorageSourceParse
Peter Krempa [Fri, 8 Mar 2019 14:03:16 +0000 (15:03 +0100)]
conf: cleanup error path in virDomainStorageSourceParse

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoconf: Invert 'skipSeclabels' argument of virDomainDiskSourceFormatInternal
Peter Krempa [Wed, 6 Mar 2019 16:22:04 +0000 (17:22 +0100)]
conf: Invert 'skipSeclabels' argument of virDomainDiskSourceFormatInternal

Rename it to 'seclabels' and invert the value.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agovirStoragePoolDefParseSource: Don't leak @port
Michal Privoznik [Tue, 19 Mar 2019 16:35:21 +0000 (17:35 +0100)]
virStoragePoolDefParseSource: Don't leak @port

In a1c453dc088, during VIR_AUTOFREE() rewrite this wasn't done
properly. @port might be leaked because it's allocated in a for()
loop.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
6 years agovirStoragePoolDefFree: Free @def->refresh
Michal Privoznik [Tue, 19 Mar 2019 16:34:07 +0000 (17:34 +0100)]
virStoragePoolDefFree: Free @def->refresh

In 669018bc9cb I've introduced def->refresh which might be
allocated by virStoragePoolDefRefreshParse() but is never freed.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
6 years agoconf: Drop unused variable
Andrea Bolognani [Tue, 19 Mar 2019 16:29:18 +0000 (17:29 +0100)]
conf: Drop unused variable

The refresh_volume_allocation variable in
virStoragePoolDefParseXML() has been unused since its
introduction in commit 669018bc9cb1, and Clang rightfully
complains about this fact.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
6 years agorbd: optionally compute volume allocation from capacity
Jason Dillaman [Tue, 19 Mar 2019 13:42:18 +0000 (09:42 -0400)]
rbd: optionally compute volume allocation from capacity

Use the new refresh volume allocation pool override to skip
computing the actual volume usage if disabled.

Signed-off-by: Jason Dillaman <dillaman@redhat.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
6 years agostorage: optional 'refresh' elemement on pool
Jason Dillaman [Tue, 19 Mar 2019 13:42:17 +0000 (09:42 -0400)]
storage: optional 'refresh' elemement on pool

The new 'refresh' element can override the default refresh operations
for a storage pool. The only currently supported override is to set
the volume allocation size to the volume capacity. This can be specified
by adding the following snippet:

<pool>
...
  <refresh>
    <volume allocation='capacity'/>
  </refresh>
...
</pool>

This is useful for certain backends where computing the actual allocation
of a volume might be an expensive operation.

Signed-off-by: Jason Dillaman <dillaman@redhat.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
6 years agorbd: do not attempt to use fast-diff if it's marked invalid
Jason Dillaman [Tue, 19 Mar 2019 13:42:16 +0000 (09:42 -0400)]
rbd: do not attempt to use fast-diff if it's marked invalid

The librbd API will transparently revert to a slow disk usage
calculation method if the fast-diff map is marked as invalid.

Signed-off-by: Jason Dillaman <dillaman@redhat.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
6 years agonetwork: avoid trying to create global firewall rules if unprivileged
Daniel P. Berrangé [Wed, 13 Mar 2019 16:21:15 +0000 (16:21 +0000)]
network: avoid trying to create global firewall rules if unprivileged

The unprivileged libvirtd does not have permission to create firewall
rules, or bridge devices, or do anything to the host network in
general. Historically we still activate the network driver though and
let the network start API call fail.

The startup code path which reloads firewall rules on active networks
would thus effectively be a no-op when unprivileged as it is impossible
for there to be any active networks

With the change to use a global set of firewall chains, however, we now
have code that is run unconditionally.

Ideally we would not register the network driver at all when
unprivileged, but the entanglement with the virt drivers currently makes
that impractical. As a temporary hack, we just make the firewall reload
into a no-op.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
6 years agonetwork: split setup of ipv4 and ipv6 top level chains
Daniel P. Berrangé [Mon, 18 Mar 2019 16:49:32 +0000 (16:49 +0000)]
network: split setup of ipv4 and ipv6 top level chains

During startup libvirtd creates top level chains for both ipv4
and ipv6 protocols. If this fails for any reason then startup
of virtual networks is blocked.

The default virtual network, however, only requires use of ipv4
and some servers have ipv6 disabled so it is expected that ipv6
chain creation will fail. There could equally be servers with
no ipv4, only ipv6.

This patch thus makes error reporting a little more fine grained
so that it works more sensibly when either ipv4 or ipv6 is
disabled on the server. Only the protocols that are actually
used by the virtual network have errors reported.

Reviewed-by: Andrea Bolognani <abologna@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
6 years agonetwork: improve error report when firewall chain creation fails
Daniel P. Berrangé [Mon, 18 Mar 2019 17:31:21 +0000 (17:31 +0000)]
network: improve error report when firewall chain creation fails

During startup we create some top level chains in which all
virtual network firewall rules will be placed. The upfront
creation is done to avoid slowing down creation of individual
virtual networks by checking for chain existance every time.

There are some factors which can cause this upfront creation
to fail and while a message will get into the libvirtd log
this won't be seen by users who later try to start a virtual
network. Instead they'll just get a message saying that the
libvirt top level chain does not exist. This message is
accurate, but unhelpful for solving the root cause.

This patch thus saves any error during daemon startup and
reports it when trying to create a virtual network later.

Reviewed-by: Andrea Bolognani <abologna@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
6 years agotests: domaincapstest: Fix build on mingw
Cole Robinson [Mon, 18 Mar 2019 16:40:03 +0000 (12:40 -0400)]
tests: domaincapstest: Fix build on mingw

fillStringValues is only used if WITH_QEMU || WITH_BHYVE

Signed-off-by: Cole Robinson <crobinso@redhat.com>
6 years agostorage: add support for new rbd_list2 method
Daniel P. Berrangé [Mon, 18 Mar 2019 11:11:38 +0000 (11:11 +0000)]
storage: add support for new rbd_list2 method

The rbd_list method has been deprecated in Ceph >= 14.0.0
in favour of the new rbd_list2 method which populates an
array of structs.

Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
6 years agostorage: split off code for calling rbd_list
Daniel P. Berrangé [Mon, 18 Mar 2019 10:58:48 +0000 (10:58 +0000)]
storage: split off code for calling rbd_list

The rbd_list method has a quite unpleasant signature returning an
array of strings in a single buffer instead of an array. It is
being deprecated in favour of rbd_list2. To maintain clarity of
code when supporting both APIs in parallel, split the rbd_list
code out into a separate method.

In splitting this we now honour the rbd_list failures.

Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
6 years agodocs: formatdomaincaps: Describe optional XML changes
Cole Robinson [Wed, 6 Mar 2019 23:25:16 +0000 (18:25 -0500)]
docs: formatdomaincaps: Describe optional XML changes

Acked-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Cole Robinson <crobinso@redhat.com>
6 years agoconf: domcaps: Don't format XML on report=false
Cole Robinson [Wed, 6 Mar 2019 23:22:01 +0000 (18:22 -0500)]
conf: domcaps: Don't format XML on report=false

After this, newly added enums will not automatically show up in
driver output unless the driver code specifically sets report=true

Acked-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Cole Robinson <crobinso@redhat.com>
6 years agobhyve: fill in virCapsEnum 'report'
Cole Robinson [Wed, 6 Mar 2019 23:20:09 +0000 (18:20 -0500)]
bhyve: fill in virCapsEnum 'report'

Set report=true for all enums currently formatted in the XML

Acked-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Cole Robinson <crobinso@redhat.com>
6 years agolibxl: fill in virCapsEnum 'report'
Cole Robinson [Wed, 6 Mar 2019 23:20:58 +0000 (18:20 -0500)]
libxl: fill in virCapsEnum 'report'

Set report=true for all enums currently formatted in the XML

Acked-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Cole Robinson <crobinso@redhat.com>
6 years agoqemu: fill in virCapsEnum 'report'
Cole Robinson [Wed, 6 Mar 2019 23:21:45 +0000 (18:21 -0500)]
qemu: fill in virCapsEnum 'report'

Set report=true for all enums currently formatted in the XML

Acked-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Cole Robinson <crobinso@redhat.com>
6 years agoconf: domcaps: Add virCapsEnum 'report'
Cole Robinson [Wed, 6 Mar 2019 23:11:01 +0000 (18:11 -0500)]
conf: domcaps: Add virCapsEnum 'report'

virCapsEnum report is an internal bool indicating whether we
should format the enum in the XML at all. This is unused for
now but will be handled in future patches.

We use a plain bool instead of tristate because the case here
is a bit different than the explicit @supported output. We
already report the equivalent of supported=YES|NO based on
what enum values are filled in. This adds report=false to
handle the ABSENT case.

Acked-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Cole Robinson <crobinso@redhat.com>
6 years agoconf: domcaps: Don't output XML on tristate ABSENT
Cole Robinson [Tue, 19 Feb 2019 19:12:47 +0000 (14:12 -0500)]
conf: domcaps: Don't output XML on tristate ABSENT

Change domcaps to skip formatting XML if the default
TRISTATE_BOOL_ABSENT is found. Now when domcaps is extended, driver
XML output won't change until an explicit TRISTATE_BOOL value is set
in driver code.

Acked-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Cole Robinson <crobinso@redhat.com>
6 years agoschemas: domcaps: Make more elements optional
Cole Robinson [Sat, 9 Feb 2019 00:10:17 +0000 (19:10 -0500)]
schemas: domcaps: Make more elements optional

Upcoming changes will make outputting these subelements optional.

While we are here drop the useless interleave: since this is an output
only format the elements are always in the same order

Acked-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Cole Robinson <crobinso@redhat.com>
6 years agobhyve: domcaps: fill in explicit supported BOOL_NO
Cole Robinson [Tue, 19 Feb 2019 19:28:52 +0000 (14:28 -0500)]
bhyve: domcaps: fill in explicit supported BOOL_NO

<hostdev> and <features> are not supported. <loader>, <graphics>,
and <video> are supported conditionally

Acked-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Cole Robinson <crobinso@redhat.com>
6 years agolibxl: domcaps: fill in explicit supported BOOL_NO
Cole Robinson [Tue, 19 Feb 2019 19:22:23 +0000 (14:22 -0500)]
libxl: domcaps: fill in explicit supported BOOL_NO

None of the <feature> bits are supported, and the <loader> piece
is only conditionally supported

Acked-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Cole Robinson <crobinso@redhat.com>
6 years agoqemu: domcaps: fill in explicit supported BOOL_NO
Cole Robinson [Tue, 19 Feb 2019 19:15:06 +0000 (14:15 -0500)]
qemu: domcaps: fill in explicit supported BOOL_NO

Only gic->supported needs an explicit BOOL_NO setting, all other
'supported' values are handling things correctly

Acked-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Cole Robinson <crobinso@redhat.com>
6 years agoconf: domcaps: use virTristateBool for 'supported'
Cole Robinson [Fri, 8 Feb 2019 23:03:20 +0000 (18:03 -0500)]
conf: domcaps: use virTristateBool for 'supported'

Switch most 'supported' handling to use virTristateBool, so eventually
we can handle the ABSENT state.

For now the XML formatter treats ABSENT the same as FALSE, so there's
no functional output change. This will be addressed in later patches

Acked-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Cole Robinson <crobinso@redhat.com>
6 years agoconf: domcaps: Add single line formatting macro
Cole Robinson [Fri, 8 Feb 2019 23:32:48 +0000 (18:32 -0500)]
conf: domcaps: Add single line formatting macro

Similar to the macros we have for formatting enums, add a macro to
simplify formatting the pattern:

  <FOO supported='yes|no'/>

Acked-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Cole Robinson <crobinso@redhat.com>
6 years agotests: domcaps: Remove 'full' test
Cole Robinson [Tue, 19 Feb 2019 17:52:30 +0000 (12:52 -0500)]
tests: domcaps: Remove 'full' test

The 'full' test verifies the output of a virDomainCapsPtr built
by hand. It has the following problems:

The domcaps test suite nowadays has 3 hypervisor driver implementations
which should give us plenty of opportunity to get full domcaps coverage.
I don't think this test has much value. And it has the following issues:

- Requires manual intervention to test new domcaps XML, which is easy
  to miss, for example gic bits aren't covered there.
- The SET_ALL_BITS trick it uses to fill in enums will output
  values that are never reported by any driver implementation
  (strings like 'default')

Let's remove it

Acked-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Cole Robinson <crobinso@redhat.com>
6 years agotests: domcaps: Remove unused typedef
Cole Robinson [Tue, 19 Feb 2019 17:51:37 +0000 (12:51 -0500)]
tests: domcaps: Remove unused typedef

Acked-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Cole Robinson <crobinso@redhat.com>
6 years agotests: domcaps: Add a default 'empty' test
Cole Robinson [Tue, 19 Feb 2019 17:44:34 +0000 (12:44 -0500)]
tests: domcaps: Add a default 'empty' test

The 'empty' demonstrates XML generated when only bare minimum caps
data has been filled in. This will demonstrate changes that alter
the default XML output.

Acked-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Cole Robinson <crobinso@redhat.com>
6 years agotests: Document how to add new replies files
Andrea Bolognani [Wed, 13 Mar 2019 13:28:07 +0000 (14:28 +0100)]
tests: Document how to add new replies files

We already document how to generate them, so might as well
go the extra mile and document the remaining steps.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Acked-by: Michal Privoznik <mprivozn@redhat.com>
6 years agonode_device_hal.c: Follow _class -> klass rename
Michal Privoznik [Mon, 18 Mar 2019 13:32:55 +0000 (14:32 +0100)]
node_device_hal.c: Follow _class -> klass rename

In 0eca80e60 _class was renamed to klass for variety of struct
members. However, gather_usb_cap() was missed out in this rename
leaving FreeBSD build broken.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
6 years agoDrop needless virtType validation
Cole Robinson [Sun, 17 Mar 2019 19:53:40 +0000 (15:53 -0400)]
Drop needless virtType validation

This code originates from:

commit d0aa10fdd6c108ad442886e4451b2629a3dc8b86
Author: Daniel P. Berrange <berrange@redhat.com>
Date:   Tue Mar 3 12:03:44 2009 +0000

    QEMU security driver usage for sVirt support (James Morris, Dan Walsh, Daniel Berrange)

Originally in the qemudDomainGetSecurityLabel function. It doesn't
appear to have done anything useful back then either. The other two
instances look like copy+paste

Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Cole Robinson <crobinso@redhat.com>
6 years agostorageVolWipePattern: Don't take shortcut to refreshPool()
Michal Privoznik [Thu, 28 Feb 2019 16:35:14 +0000 (17:35 +0100)]
storageVolWipePattern: Don't take shortcut to refreshPool()

In d16f803d780 we've tried to solve an issue that after wiping an
image its format might have changed (e.g. from qcow2 to raw) but
libvirt wasn't probing the image format. We fixed this by calling
virStorageBackendRefreshVolTargetUpdate() which is what
refreshPool() would end up calling. But this shortcut is not good
enough because the function is called only for local types of
volumes (like dir, fs, netfs). But now that more backends support
volume wiping we have to call the function with more caution.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
6 years agostorage_backend_iscsi_direct: Simplify vol zeroing
Michal Privoznik [Fri, 1 Mar 2019 10:42:20 +0000 (11:42 +0100)]
storage_backend_iscsi_direct: Simplify vol zeroing

So far we have two branches: either we zero BLOCK_PER_PACKET
(currently 128) block at once, or if we're close to the last block
then we zero out one block at the time. This is very suboptimal.
We know how many block are there left. Might as well just write
them all at once.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
6 years agovirsh: man: Document asynchronous behaviour of detach-device-alias
Peter Krempa [Mon, 18 Mar 2019 07:08:57 +0000 (08:08 +0100)]
virsh: man: Document asynchronous behaviour of detach-device-alias

This command is fully async. Note that users can use virsh event to be
notified of the guest actually removing the device.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
6 years agovirsh: man: Document quirks of device-detach and friends
Peter Krempa [Mon, 18 Mar 2019 07:08:04 +0000 (08:08 +0100)]
virsh: man: Document quirks of device-detach and friends

Mention that successful return does not equal to device being detached
similarly as we do at the API level.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
6 years agonews: update for new class element of PCI nodedev capability
Nikolay Shirokovskiy [Tue, 12 Mar 2019 10:59:35 +0000 (13:59 +0300)]
news: update for new class element of PCI nodedev capability

Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
6 years agoxml: nodedev: add class info for pci capability
Nikolay Shirokovskiy [Tue, 19 Feb 2019 12:41:37 +0000 (15:41 +0300)]
xml: nodedev: add class info for pci capability

This info can be useful to filter devices visible
to mgmt clients so that they won't see devices that
unsafe/not meaningful to pass thru.

Provide class info the way it is provided by udev or
kernel that is as single 6-digit hexadecimal.

Class element is not optional. I guess this should not
break users that use virNodeDeviceCreateXML because
they probably specify only scsi_host capability on
input and then node device driver gets other capabilities
from udev after device appeared.

HAL driver does not get support for the new element in
this patch.

Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
6 years agoconf: don't use "class" as name
Nikolay Shirokovskiy [Tue, 12 Mar 2019 08:08:00 +0000 (11:08 +0300)]
conf: don't use "class" as name

Vim treats *.h files as cpp ones with respect to syntax highlighting.
Thus "class" in _virNodeDevCapPCIDev highlighted mistakenly.
This can be fixed by filetype detection code tunables but it
is more convinient to skip this tuning by every project member.

Let's just use "klass" as field name instead of _class or class
and add syntax rule.

Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
6 years agovz: build fix for virdomainsnapshotobjlist.h
Nikolay Shirokovskiy [Mon, 18 Mar 2019 08:03:04 +0000 (11:03 +0300)]
vz: build fix for virdomainsnapshotobjlist.h

Commit [1] moved snapshot list functions declaration into
its own file but missed a fix for vz driver.

[1] 9b75154c : snapshot: Break out virDomainSnapshotObjList into its own file

Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
6 years agovirsh-pool: Offer only active pool for pool-refresh completer
Michal Privoznik [Fri, 1 Mar 2019 09:56:42 +0000 (10:56 +0100)]
virsh-pool: Offer only active pool for pool-refresh completer

Only active pools can be refreshed. But our completer offers just
all pool, even inactive ones.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
6 years agostoragePoolRefreshFailCleanup: Clear volumes on failed refresh
Michal Privoznik [Thu, 28 Feb 2019 17:07:02 +0000 (18:07 +0100)]
storagePoolRefreshFailCleanup: Clear volumes on failed refresh

If pool refresh failed, then the internal table of volumes is
probably left in inconsistent or incomplete state anyways. Clear
it out then. This has an advantage that we can move the
virStoragePoolObjClearVols() from those very few backends that
do call it.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
6 years agostorage_driver: Introduce storagePoolRefreshImpl()
Michal Privoznik [Fri, 1 Mar 2019 09:55:23 +0000 (10:55 +0100)]
storage_driver: Introduce storagePoolRefreshImpl()

This is a wrapper over refreshPool() call as at all places we are
doing basically the same. Might as well have a single function to
call.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
6 years agovirISCSIDirectReportLuns: Drop ClearVols
Michal Privoznik [Thu, 28 Feb 2019 16:43:57 +0000 (17:43 +0100)]
virISCSIDirectReportLuns: Drop ClearVols

In bf5cf610f206d5d54 I've fixed a problem where iscsi-direct
backend was reporting only the last LUN. The fix consisted of
moving virStoragePoolObjClearVols() one level up. However, as it
turns out, storage driver already calls it before calling
refreshPool callback (which is
virStorageBackendISCSIDirectRefreshPool() in this case).

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
6 years agoiscsi_direct: Don't overwrite error in virStorageBackenISCSIDirectWipeVol()
Michal Privoznik [Wed, 6 Mar 2019 14:43:04 +0000 (15:43 +0100)]
iscsi_direct: Don't overwrite error in virStorageBackenISCSIDirectWipeVol()

If virStorageBackendISCSIDirectVolWipeZero() fails, it has
already reported an error which is probably specific enough. Do
not overwrite it with some generic one.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
6 years agoiscsi_direct: Make virStorageBackendISCSIDirectGetLun report error properly
Michal Privoznik [Wed, 6 Mar 2019 14:27:55 +0000 (15:27 +0100)]
iscsi_direct: Make virStorageBackendISCSIDirectGetLun report error properly

This function reports error for one of the two error paths. This
is unfortunate as a caller see this function failing but doesn't
know right away if an error was reported.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
6 years agonews: Add entry describing support for Xen's max grant frames
Jim Fehlig [Wed, 13 Mar 2019 22:06:11 +0000 (16:06 -0600)]
news: Add entry describing support for Xen's max grant frames

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
6 years agonews: Document dropping support for certain init scripts
Andrea Bolognani [Thu, 14 Mar 2019 10:59:42 +0000 (11:59 +0100)]
news: Document dropping support for certain init scripts

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
6 years agom4: Simplify LIBVIRT_CHECK_INIT_SCRIPT
Andrea Bolognani [Fri, 15 Mar 2019 15:57:40 +0000 (16:57 +0100)]
m4: Simplify LIBVIRT_CHECK_INIT_SCRIPT

Now that we no longer support the weird "redhat+systemd"
configuration, we can make our code slightly simpler.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
6 years agoDrop support for "Red Hat" init scripts
Andrea Bolognani [Fri, 15 Mar 2019 15:47:27 +0000 (16:47 +0100)]
Drop support for "Red Hat" init scripts

Despite the misleading name, these were supposed to be used
with a System V style init; however, none of the platforms we
target is using that kind of init anymore: almost all Linux
distributions have switched to systemd, those that haven't
(such as Gentoo and Alpine) are mostly using OpenRC with
custom init scripts, and the BSDs have been doing their own
thing all along.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
6 years agoDrop support for Upstart init scripts
Andrea Bolognani [Thu, 14 Mar 2019 10:56:13 +0000 (11:56 +0100)]
Drop support for Upstart init scripts

Not a single one of the platforms we target still uses Upstart, and
the Upstart project itself has been abandoned for several years now.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
6 years agotravis: Drop $DISTCHECK_CONFIGURE_FLAGS
Andrea Bolognani [Fri, 15 Mar 2019 15:37:09 +0000 (16:37 +0100)]
travis: Drop $DISTCHECK_CONFIGURE_FLAGS

It's no longer used.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
6 years agotravis: Stop using --with-init-script
Andrea Bolognani [Thu, 14 Mar 2019 10:57:03 +0000 (11:57 +0100)]
travis: Stop using --with-init-script

We're gonna drop support for non-systemd init scripts soon,
and we don't want Travis CI builds to break when we do.

Since we have init system auto-detection, we can just rely on
that and stop passing --with-init-script to configure entirely.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
6 years agosnapshot: Break out virDomainSnapshotObjList into its own file
Eric Blake [Fri, 15 Mar 2019 02:19:18 +0000 (21:19 -0500)]
snapshot: Break out virDomainSnapshotObjList into its own file

snapshot_conf.h was mixing three separate types: the snapshot
definition, the snapshot object, and the snapshot object list.
Separate out the snapshot object list code into its own file, and
update includes for affected clients.

This is just code motion, but done in preparation of sharing a lot of
the object list code with checkpoints.

Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agosnapshot: Export two functions prior to file split
Eric Blake [Fri, 15 Mar 2019 02:12:51 +0000 (21:12 -0500)]
snapshot: Export two functions prior to file split

The next patch will require access to the helper functions
virDomainSnapshotDefFormatInternal and
virDomainSnapshotRedefineValidate from two different files; make the
file split easier by exporting these functions.

Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agosnapshot: Break out virDomainSnapshotObj into its own file
Eric Blake [Fri, 15 Mar 2019 01:03:40 +0000 (20:03 -0500)]
snapshot: Break out virDomainSnapshotObj into its own file

snapshot_conf.h was mixing three separate types: the snapshot
definition, the snapshot object, and the snapshot object list.
Separate out the snapshot object code into its own file, which
includes moving a typedef to avoid circular inclusions.

Mostly straight code motion, although I fixed a comment along
the way, now that virDomainSnapshotForEachDescendent now
guarantees a topological visit (missed in b647d219).

Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agosnapshot: Sort virconftypes.h
Eric Blake [Fri, 15 Mar 2019 01:20:13 +0000 (20:20 -0500)]
snapshot: Sort virconftypes.h

It's easier to locate a typedef if they are stored in sorted order;
do so mechanically via:

$ sed -i '/typedef struct/ {N; N; s/\n//g}' src/conf/virconftypes.h
$ # sorting the lines
$ sed -i '/typedef struct/ s/;/;\n/g' src/conf/virconftypes.h

Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoconf: Split capabilities forward typedefs into virconftypes.h
Eric Blake [Fri, 15 Mar 2019 00:44:34 +0000 (19:44 -0500)]
conf: Split capabilities forward typedefs into virconftypes.h

As explained in the previous patch, collecting pointer typedefs into a
common header makes it easier to avoid circular inclusions.  Continue
the efforts by pulling the appropriate typedefs from capabilities.h
into the new header.

This patch is just straight code motion (all typedefs are listed in
the same order before and after the patch); a later patch will sort
things for legibility.

Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoconf: Split domain forward typedefs into virconftypes.h
Eric Blake [Fri, 15 Mar 2019 00:44:34 +0000 (19:44 -0500)]
conf: Split domain forward typedefs into virconftypes.h

Right now, snapshot_conf.h is rather large - it deals with three
separate types: virDomainSnapshotDef (the snapshot definition as it
maps to XML), virDomainSnapshotObj (an object containing a def and the
relationship to other snapshots), and virDomainSnapshotObjList (a list
of snapshot objects), where two of the three types are currently
public rather than opaque.  What's more, the types are circular: a
snapshot def includes a virDomainPtr, which contains a snapshot list,
which includes a snapshot object, which includes a snapshot def.

In order to split the three objects into separate files, while still
allowing each header to use sane typedefs to incomplete pointers, the
obvious solution is to lift the typedefs into yet another header, with
no other dependencies.  Start the split by factoring out all struct
typedefs from domain_conf.h (enum typedefs don't get used in function
signatures, and function typedefs tend not to suffer from circular
referencing, so those stay put).  The only other exception is
virDomainStateReason, which is only ever used directly rather than via
a pointer.

This patch is just straight code motion (all typedefs are listed in
the same order before and after the patch); a later patch will sort
things for legibility.

Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoobject: Add sanity check on correct parent class
Eric Blake [Fri, 15 Mar 2019 14:41:18 +0000 (09:41 -0500)]
object: Add sanity check on correct parent class

Checking that the derived class is larger than the requested parent
class saves us from some obvious mistakes, but as written, it does not
catch all the cases; in particular, it is easy to forget to update a
VIR_CLASS_NEW when changing the 'parent' member from virObject to
virObjectLockabale, but where the size checks don't catch that.  Add a
parameter for one more layer of sanity checking.

It would be cool if we could get gcc to stringize typeof(parent) into
the string name of that type, so that we could confirm that the
precise parent class is in use rather than just a struct that happens
to have the same size as the parent class.  But sizeof checks are
better than nothing.

Note that I did NOT change the fact that we require derived classes to
be larger (as the difference in size makes it easy to tell classes
apart), which means that even if a derived class has no functionality
to add (but rather exists for compiler-enforced type-safety), it must
still include a dummy member.  But I did fix the wording of the error
message to match the code.

Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
6 years agoqemu: command: Override HOME variable for system QEMU
Erik Skultety [Wed, 6 Mar 2019 12:29:01 +0000 (13:29 +0100)]
qemu: command: Override HOME variable for system QEMU

By default, qemu user's home dir points to '/' which shouldn't be used
at all. We therefore pass the HOME variable from the current variable
iff not running as SUID, which means that for systemd we never set it.
This patch makes sure, that for system QEMU this is always set to
libDir/<driver>, session mode is left untouched.

Signed-off-by: Erik Skultety <eskultet@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
6 years agoqemu: command: Enforce setting XDG variables for system QEMU
Erik Skultety [Fri, 8 Mar 2019 11:15:07 +0000 (12:15 +0100)]
qemu: command: Enforce setting XDG variables for system QEMU

For session mode, only XDG_CACHE_HOME is set, because we want to remain
integrating with services in user session, but for system mode, this
would have become reading/writing to '/' which carries the obvious issue
with permissions (also, '/' is the wrong location in 99.9% cases anyway).

Signed-off-by: Erik Skultety <eskultet@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
6 years agoutil: command: Introduce virCommandAddEnvXDG helper
Erik Skultety [Mon, 4 Mar 2019 11:47:08 +0000 (12:47 +0100)]
util: command: Introduce virCommandAddEnvXDG helper

Some modules/libraries within QEMU could make use of the XDG_ vars when
writing their data to the disk. Define the most common XDG variables
and point them to the specific driver's libDir, i.e.

XDG_CACHE_HOME -> /var/lib/libvirt/<driver>/.cache
XDG_DATA_HOME -> /var/lib/libvirt/<driver>/.local/share
XDG_CONFIG_HOME -> /var/lib/libvirt/<driver>/.config

Signed-off-by: Erik Skultety <eskultet@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
6 years agoqemu: hotplug: Merge virtio and non-virtio disk unplug code
Peter Krempa [Fri, 15 Mar 2019 14:09:14 +0000 (15:09 +0100)]
qemu: hotplug: Merge virtio and non-virtio disk unplug code

The functions do basically exactly the same thing modulo few checks.
In case of virtio disks we check that the device is not multifunction as
that can't be unplugged at once. In case of USB and SCSI disks we
checked that no active block job is running.

The check for running blockjobs should have also been done for virtio
disks. By moving the multifunction check into the common function we fix
this case and also simplify the code.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoqemu: hotplug: Use switch statement for selecting disk bus function
Peter Krempa [Fri, 15 Mar 2019 14:04:00 +0000 (15:04 +0100)]
qemu: hotplug: Use switch statement for selecting disk bus function

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoqemu: hotplug: Use typecasted enum in qemuDomainDetachDeviceDiskLive
Peter Krempa [Fri, 15 Mar 2019 13:52:58 +0000 (14:52 +0100)]
qemu: hotplug: Use typecasted enum in qemuDomainDetachDeviceDiskLive

Use the correct type in switch and populate the missing cases.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoqemu: hotplug: Remove 'ret' variable in qemuDomainDetachDeviceDiskLive
Peter Krempa [Fri, 15 Mar 2019 14:32:52 +0000 (15:32 +0100)]
qemu: hotplug: Remove 'ret' variable in qemuDomainDetachDeviceDiskLive

We don't have any cleanup section, we can return the value directly.

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