]> xenbits.xensource.com Git - libvirt.git/log
libvirt.git
4 years agoqemu: Convert 'priv->dbusVMStateIds' to a GSList
Peter Krempa [Fri, 5 Feb 2021 09:48:51 +0000 (10:48 +0100)]
qemu: Convert 'priv->dbusVMStateIds' to a GSList

The conversion removes the use of virStringListAdd/virStringListRemove
which try to add dynamic properties to a string list which is really
inefficient.

Storing the dbus VMState ids in a GSList is pretty straightforward and
the slightly increased complexity of the code will be paid back by
removing the string list helpers later.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agovirResctrlMonitorGetStats: Don't use 'virStringListAdd'
Peter Krempa [Fri, 5 Feb 2021 14:30:02 +0000 (15:30 +0100)]
virResctrlMonitorGetStats: Don't use 'virStringListAdd'

The iner loop copies the 'resources' array multiple times using
'virStringListAdd' which has O(n^2) complexity.

Pre-calculate the length so we can allocate the array upfront and just
copy the strings in the loop.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agovirResctrlInfoGetMonitorPrefix: Don't use 'virStringListAdd' to construct list
Peter Krempa [Fri, 5 Feb 2021 14:28:46 +0000 (15:28 +0100)]
virResctrlInfoGetMonitorPrefix: Don't use 'virStringListAdd' to construct list

Pre-allocate a buffer for the upper limit and shrink it afterwards to
avoid use of 'virStringListAdd' in a loop.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agox86ModelParseFeatures: Don't construct list using 'virStringListAdd'
Peter Krempa [Fri, 5 Feb 2021 14:20:44 +0000 (15:20 +0100)]
x86ModelParseFeatures: Don't construct list using 'virStringListAdd'

Pre-allocate the list to the upper bound and fill it gradually. Since
the data is kept long-term and the list won't be populated much shrink
it to the actual size after parsing.

While using 'virStringListAdd' here wouldn't be as expensive as this
function is used just once, the removal will allow to remove
'virStringListAdd' altogether to discourage the antipattern it promotes.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agovirCPUDefCheckFeatures: Don't use 'virStringListAdd' to construct list
Peter Krempa [Fri, 5 Feb 2021 14:13:28 +0000 (15:13 +0100)]
virCPUDefCheckFeatures: Don't use 'virStringListAdd' to construct list

We already know the upper bound of items we might need so we can
allocate the array upfront and avoid the quadratic complexity of
'virStringListAdd'.

In this instance the returned data is kept only temporarily so a
potential unused space due to filtered-out entries doesn't impose a
long-term burden on memory.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agoqemuInteropFetchConfigs: Don't use 'virStringListAdd' to construct list
Peter Krempa [Fri, 5 Feb 2021 14:09:12 +0000 (15:09 +0100)]
qemuInteropFetchConfigs: Don't use 'virStringListAdd' to construct list

'virHashGetItems' already returns the number of entries which will be
considered for addition to the list so we can allocate it to the upper
bound upfront rather than growing it in a loop. This avoids the
quadratic complexity of 'virStringListAdd'.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agovirHookCall: Don't use 'virStringListAdd' to construct list in loop
Peter Krempa [Thu, 4 Feb 2021 19:27:05 +0000 (20:27 +0100)]
virHookCall: Don't use 'virStringListAdd' to construct list in loop

'virStringListAdd' calculates the string list length on every invocation
so constructing a string list using it results in O(n^2) complexity.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agoqemu: namespace: Don't use 'virStringListAdd' inside loops
Peter Krempa [Thu, 4 Feb 2021 13:10:42 +0000 (14:10 +0100)]
qemu: namespace: Don't use 'virStringListAdd' inside loops

'virStringListAdd' calculates the string list length on every invocation
so constructing a string list using it results in O(n^2) complexity.

Use a GSList which has cheap insertion and iteration and doesn't need
failure handling.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agoutil: Add helpers for auto-freeing GSList filled with strings
Peter Krempa [Thu, 4 Feb 2021 16:58:23 +0000 (17:58 +0100)]
util: Add helpers for auto-freeing GSList filled with strings

glib's 'g_autoslist()' doesn't support lists of 'char *' strings. Add a
type alias 'virGSListString' so that we can register an 'autoptr'
function for it for simple usage of GSList with strings.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agoqemuNamespaceUnlinkPaths: Fix inconsistent cleanup handling
Peter Krempa [Thu, 4 Feb 2021 14:12:57 +0000 (15:12 +0100)]
qemuNamespaceUnlinkPaths: Fix inconsistent cleanup handling

Some code paths return -1 directly while others jump to 'cleanup' which
cleans the list of mounts. Since qemuDomainGetPreservedMounts now
returns a NULL-terminated list, convert devMountsPath to g_auto(GStrv)
and remove the cleanup altoghether.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agoqemuNamespaceUnlinkPaths: Fix wrong use of iterator variable
Peter Krempa [Thu, 4 Feb 2021 13:27:19 +0000 (14:27 +0100)]
qemuNamespaceUnlinkPaths: Fix wrong use of iterator variable

'i' is used in both outer and inner loop. Since 'devMountsPath' is now a
NULL-terminated list, we can use a GStrv to iterate it;

Additionally rewrite the conditional of adding to the 'unlinkPaths'
array so that it's more clear what's happening.

Fixes: 5c86fbb72d6e90025481db7
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agoqemuDomainGetPreservedMounts: Refactor to return NULL-terminated string lists
Peter Krempa [Thu, 4 Feb 2021 14:09:57 +0000 (15:09 +0100)]
qemuDomainGetPreservedMounts: Refactor to return NULL-terminated string lists

Refactor the handling of internals so that NULL-terminated lists are
always returned.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agoutil: macmap: Remove unused cleanup labels and 'ret' variables
Peter Krempa [Fri, 5 Feb 2021 10:14:43 +0000 (11:14 +0100)]
util: macmap: Remove unused cleanup labels and 'ret' variables

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agoutil: virmacmap: Use g_autofree for virJSONValue
Peter Krempa [Fri, 5 Feb 2021 10:14:09 +0000 (11:14 +0100)]
util: virmacmap: Use g_autofree for virJSONValue

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agoTranslated using Weblate (Finnish)
Jan Kuparinen [Thu, 11 Feb 2021 07:45:28 +0000 (08:45 +0100)]
Translated using Weblate (Finnish)

Currently translated at 14.0% (1468 of 10451 strings)

Translation: libvirt/libvirt
Translate-URL: https://translate.fedoraproject.org/projects/libvirt/libvirt/fi/

Translated using Weblate (Finnish)

Currently translated at 13.8% (1447 of 10451 strings)

Translation: libvirt/libvirt
Translate-URL: https://translate.fedoraproject.org/projects/libvirt/libvirt/fi/

Co-authored-by: Jan Kuparinen <copper_fin@hotmail.com>
Signed-off-by: Jan Kuparinen <copper_fin@hotmail.com>
4 years agoqemu: Do not Use canonical path for system memory
Michal Privoznik [Fri, 8 Jan 2021 15:35:26 +0000 (16:35 +0100)]
qemu: Do not Use canonical path for system memory

In commit 88957116c9d3cb4705380c3702c9d4315fb500bb I've adapted
libvirt to QEMU's deprecation of -mem-path and -mem-prealloc and
switched to memory-backend-* even for system memory. My claim was
that that's what QEMU does under the hood anyway. And indeed it
was: see QEMU commit 900c0ba373aada4c13d47d95330aa72ec4067ba5 and
look at function create_default_memdev().

However, then commit d96c4d5f193e0e45beec80a6277728b32875bddb was
merged into QEMU. While it was fixing a bug, it also changed the
create_default_memdev() function in which it started turning off
use of canonical path (by setting
"x-use-canonical-path-for-ramblock-id" attribute to false). This
wasn't documented until QEMU commit
8db0b20415c129cf5e577a593a4a0372d90b7cc9. The path affects
migration - the same path has to be used on the source and on the
destination. Therefore, if there is old guest started with '-m X'
it has "pc.ram" block which doesn't use canonical path and thus
when migrating to newer QEMU which uses memory-backend-* we have
to turn off the canonical path explicitly. Otherwise,
"/objects/pc.ram" path would be expected by QEMU which doesn't
match the source.

Ideally, we would need to set it only for some machine types
(4.0 and older) because newer machine types already do what we
are doing. However, we treat machine types as opaque strings and
therefore we don't want to parse nor inspect their versions. But
then again, newer machine types already do what we are doing in
this commit, so when old machine types are deprecated and removed
we can remove our hack and forget it ever happened.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1912201
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
4 years agoqemu_capabilities: Introduce QEMU_CAPS_X_USE_CANONICAL_PATH_FOR_RAMBLOCK_ID
Michal Privoznik [Mon, 11 Jan 2021 17:15:57 +0000 (18:15 +0100)]
qemu_capabilities: Introduce QEMU_CAPS_X_USE_CANONICAL_PATH_FOR_RAMBLOCK_ID

This capability tracks whether memory-backend-file has
"x-use-canonical-path-for-ramblock-id" attribute. Introduced into
QEMU by commit fa0cb34d2210cc749b9a70db99bb41c56ad20831. As of
QEMU commit 8db0b20415c129cf5e577a593a4a0372d90b7cc9 the property
is considered stable by qemu despite the 'x-' prefix to preserve
compatibility with released qemu versions.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
4 years agobuild: Remove unused 'conflicts' key from virt_daemon_unit
Jim Fehlig [Tue, 9 Feb 2021 18:21:04 +0000 (11:21 -0700)]
build: Remove unused 'conflicts' key from virt_daemon_unit

The 'conflict' key in a virt_daemon_unit dictionary is not used when
generating systemd service and socket files. The comment associated
with the key claims the default is 'true', and a few build files
needlessly set it to 'true' when defining their virt_daemon_unit.
Remove the 'conflict' key and its use in the affect build files.

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agoschemas: Add support for maximum CPU mode
Jiri Denemark [Wed, 10 Feb 2021 13:08:49 +0000 (14:08 +0100)]
schemas: Add support for maximum CPU mode

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
4 years agotests: add cgroup nested tests
Pavel Hrdina [Thu, 5 Nov 2020 17:39:10 +0000 (18:39 +0100)]
tests: add cgroup nested tests

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agovircgroup: introduce nested cgroup to properly work with systemd
Pavel Hrdina [Tue, 9 Feb 2021 11:33:53 +0000 (12:33 +0100)]
vircgroup: introduce nested cgroup to properly work with systemd

When running on host with systemd we register VMs with machined.
In this case systemd creates the root VM cgroup for us. This has some
implications where one of them is that systemd owns all files inside
the root VM cgroup and we should not touch them.

We already use DBus calls for some of the APIs but for the remaining
ones we will continue accessing the files directly. Systemd doesn't
support threaded cgroups so we need to do this.

The reason why we don't use DBus for most of the APIs is that we already
have a code that works with files and we would have to check if systemd
supports each API.

This change introduces new topology on systemd hosts:

$ROOT
  |
  +- machine.slice
     |
     +- machine-qemu\x2d1\x2dvm1.scope
        |
        +- libvirt
           |
           +- emulator
           +- vcpu0
           +- vcpu0

compared to the previous topology:

$ROOT
  |
  +- machine.slice
     |
     +- machine-qemu\x2d1\x2dvm1.scope
        |
        +- emulator
        +- vcpu0
        +- vcpu0

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agovircgroup: introduce virCgroupV1Exists and virCgroupV2Exists
Pavel Hrdina [Tue, 9 Feb 2021 11:31:13 +0000 (12:31 +0100)]
vircgroup: introduce virCgroupV1Exists and virCgroupV2Exists

This will check if the cgroup actually exists on the system.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agovircgroupv2: move task into cgroup before enabling controllers
Pavel Hrdina [Wed, 4 Nov 2020 18:55:44 +0000 (19:55 +0100)]
vircgroupv2: move task into cgroup before enabling controllers

When we create a new child cgroup and the parent cgroup has any process
attached to it enabling controllers for the child cgroup fails with
error. We need to move the process into the child cgroup first before
enabling any controllers.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agovircgroupv1: refactor virCgroupV1DetectPlacement
Pavel Hrdina [Wed, 4 Nov 2020 18:46:24 +0000 (19:46 +0100)]
vircgroupv1: refactor virCgroupV1DetectPlacement

Remove one level of indentation by splitting the condition.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agovircgroup: use DBus call to systemd for some APIs
Pavel Hrdina [Fri, 5 Feb 2021 15:17:35 +0000 (16:17 +0100)]
vircgroup: use DBus call to systemd for some APIs

When running on host with systemd we register VMs with machined.
In this case systemd creates the root VM cgroup for us. This has some
implications where one of them is that systemd owns all files inside
the root VM cgroup and we should not touch them.

If we change any value in file that systemd knows about it will be
changed to what systemd thinks it should be when executing
`systemctl daemon-reload`.

These are the APIs that we need to call using systemd because they set
limits that are proportional to sibling cgroups.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agovirsystemd: introduce virSystemdGetMachineUnitByPID
Pavel Hrdina [Tue, 27 Oct 2020 13:15:03 +0000 (14:15 +0100)]
virsystemd: introduce virSystemdGetMachineUnitByPID

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agovirsystemd: introduce virSystemdGetMachineByPID
Pavel Hrdina [Fri, 30 Oct 2020 11:06:56 +0000 (12:06 +0100)]
virsystemd: introduce virSystemdGetMachineByPID

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agovirsystemd: export virSystemdHasMachined
Pavel Hrdina [Tue, 27 Oct 2020 13:14:08 +0000 (14:14 +0100)]
virsystemd: export virSystemdHasMachined

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agoqemu: wire up support for maximum CPU model
Daniel P. Berrangé [Fri, 5 Feb 2021 18:35:10 +0000 (18:35 +0000)]
qemu: wire up support for maximum CPU model

The "max" model can be treated the same way as "host" model in general.

Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
4 years agoqemu: probe for "-cpu max" support
Daniel P. Berrangé [Fri, 5 Feb 2021 18:21:14 +0000 (18:21 +0000)]
qemu: probe for "-cpu max" support

This is a special CPU model similar to "-cpu host", so won't use our
normal CPU model detection logic.

Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
4 years agocpu: wire up support for maximum CPU mode
Daniel P. Berrangé [Fri, 5 Feb 2021 16:19:33 +0000 (16:19 +0000)]
cpu: wire up support for maximum CPU mode

The logic applied in the ppc64 case isn't quite correct, as the
interpretation of maximum mode depends on whether hardware virt
is used or not. This is information the CPU driver doesn't have.

Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
4 years agoconf: add reporting of "maximum" CPU mode in domain caps
Daniel P. Berrangé [Fri, 5 Feb 2021 15:59:35 +0000 (15:59 +0000)]
conf: add reporting of "maximum" CPU mode in domain caps

The data reported is the same as for "host-passthrough"

Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
4 years agoconf: define a new "maximum" CPU mode
Daniel P. Berrangé [Fri, 5 Feb 2021 15:51:09 +0000 (15:51 +0000)]
conf: define a new "maximum" CPU mode

For hardware virtualization this is functionally identical to the
existing host-passthrough mode so the same caveats apply.

For emulated guest this exposes the maximum featureset supported by
the emulator. Note that despite being emulated this is not guaranteed
to be migration safe, especially if different emulator software versions
are used on each host.

Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
4 years agovirStorageSourceClear: Unref @vhostuser
Michal Privoznik [Tue, 9 Feb 2021 19:16:03 +0000 (20:16 +0100)]
virStorageSourceClear: Unref @vhostuser

The @vhostuser member of virStorageSource structure is allocated
during parsing in virDomainDiskSourceVHostUserParse() but never
freed leading to a memleak. Since the member is an object it has
to be unrefed instead of g_free()-d.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
4 years agovsh: Drop unused @text arg from readline generators
Michal Privoznik [Thu, 4 Feb 2021 12:46:12 +0000 (13:46 +0100)]
vsh: Drop unused @text arg from readline generators

After previous patches neither vshReadlineCommandGenerator() nor
vshReadlineOptionsGenerator() use prefix that user wants to
complete. The argument is marked as unused in both functions.
Drop it then.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Jonathon Jongsma <jjongsma@redhat.com>
4 years agovsh: Rework vshReadlineCommandGenerator()
Michal Privoznik [Tue, 26 Jan 2021 16:22:00 +0000 (17:22 +0100)]
vsh: Rework vshReadlineCommandGenerator()

Firstly, move variable declarations into the inner most block
they are used. Secondly, use for() loop instead of while so that
we don't have to advance loop counter explicitly on 'continue'.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Jonathon Jongsma <jjongsma@redhat.com>
4 years agovsh: Simplify condition for calling completer callback
Michal Privoznik [Tue, 2 Feb 2021 10:52:27 +0000 (11:52 +0100)]
vsh: Simplify condition for calling completer callback

The way we currently call completer callbacks is that if we've
found --option that user wants to complete value for and it has
callback set then the callback is called.

And just before that, if no --option to have the value completed
is found or is found and is of boolean type then a list of
--option is generated (for given command).

But these two conditions can never be true at the same time
because boolean type of --options do not accept values. Therefore
the calling of completer callback can be promoted onto the same
level as the --option list generation.

This means that merging of two lists can be dropped to and
completer callback can store its retval directly into @list (but
as shown earlier one of the string lists to merge is always
empty).

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Jonathon Jongsma <jjongsma@redhat.com>
4 years agovsh: Deduplicate filtering in vshReadlineCommandGenerator()
Michal Privoznik [Wed, 3 Feb 2021 06:08:19 +0000 (07:08 +0100)]
vsh: Deduplicate filtering in vshReadlineCommandGenerator()

Completer callbacks generate all possible outputs ignoring any partial
input (e.g. prefix of a domain name) and then use vshCompleterFilter() to
filter out those strings which don't fit the partial input (prefix).

In contrast, vshReadlineCommandGenerator() does some internal filtering and
only generates completions that match a given prefix. Rather than treating
these scenarios differently, simply generate all possible options and
filter them all at the end.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Jonathon Jongsma <jjongsma@redhat.com>
4 years agovsh: Deduplicate filtering in vshReadlineOptionsGenerator()
Michal Privoznik [Tue, 2 Feb 2021 10:38:17 +0000 (11:38 +0100)]
vsh: Deduplicate filtering in vshReadlineOptionsGenerator()

Completer callbacks generate all possible outputs ignoring any partial
input (e.g. prefix of a domain name) and then use vshCompleterFilter() to
filter out those strings which don't fit the partial input (prefix).

In contrast, vshReadlineOptionsGenerator() does some internal filtering and
only generates completions that match a given prefix. Rather than treating
these scenarios differently, simply generate all possible options and
filter them all at the end.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Jonathon Jongsma <jjongsma@redhat.com>
4 years agovsh: Rewrite opt->type check in vshReadlineParse()
Michal Privoznik [Tue, 2 Feb 2021 10:32:22 +0000 (11:32 +0100)]
vsh: Rewrite opt->type check in vshReadlineParse()

The vshReadlineParse() function is called whenever user hits
<TAB><TAB>. If there is no command (or a partially written one),
then a list of possible commands is printed to the user. But, if
there is a command then its --options are generated. But
obviously, we can not generate --options if there already is an
--option that's expecting a value. For instance, consider:

  virsh # start --domain <TAB><TAB>

In this case we want to call completer for --domain option, but
that's a different story.

Anyway, the way that we currently check whether --options list
should be generated is checking the type of the last --option. If
it isn't DATA, STRING, INT, or ARGV (all these expect a value),
then we can generate --option list. Well, writing the condition
this way is needlessly verbose and also prone to errors (see
d9a320bf97 for example).

We know that boolean type does not require a value. This leaves
us with the only type that was not mentioned yet - VSH_OT_ALIAS.
This is a special type for backwards compatibility and it refers
to another --option which can be just any type.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Jonathon Jongsma <jjongsma@redhat.com>
4 years agovsh: Use g_auto() for string lists returned in readline command/options generators
Michal Privoznik [Tue, 2 Feb 2021 10:09:01 +0000 (11:09 +0100)]
vsh: Use g_auto() for string lists returned in readline command/options generators

There are two functions that are used to generate completion
lists: vshReadlineCommandGenerator() for command names and
vshReadlineOptionsGenerator() for --options for given command.
Both return a string list, but may also fail while constructing
it. For that case, they call g_strfreev() explicitly, which is
needless since we have g_auto(GStrv).

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Jonathon Jongsma <jjongsma@redhat.com>
4 years agovsh: Prefer g_strdup_printf() over g_snprintf() in vshReadlineOptionsGenerator()
Michal Privoznik [Tue, 2 Feb 2021 10:05:47 +0000 (11:05 +0100)]
vsh: Prefer g_strdup_printf() over g_snprintf() in vshReadlineOptionsGenerator()

The vshReadlineOptionsGenerator() function returns a string list
of all --options for given command. But the way that individual
items on the list are allocated can be written better.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Jonathon Jongsma <jjongsma@redhat.com>
4 years agovsh: Accept NULL @list in vshCompleterFilter()
Michal Privoznik [Tue, 2 Feb 2021 09:39:19 +0000 (10:39 +0100)]
vsh: Accept NULL @list in vshCompleterFilter()

The aim of vshCompleterFilter() is to take a string list and a
prefix and remove all strings from the list that don't have the
desired prefix. The function is used to filter out those strings
returned by a completer callback that don't correspond with
user's (partial) input. For instance, domain name completer
virshDomainNameCompleter() returns all domain names and then
vshCompleterFilter() refines the list so that only domains with
correct prefix of their name are offered to user. This was a
design choice - it allows us to have shorter completers as they
do not have to copy the list filtering over and over.

Having said all of that, it may happen that a completer does not
return anything (e.g. there is no domain in requested state,
virsh is not connected and thus completer exited early, etc.). In
that case, the string list is NULL and vshCompleterFilter() can
simply return early.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Jonathon Jongsma <jjongsma@redhat.com>
4 years agovsh: Use g_auto(GStrv) to free string list returned by completer callback
Michal Privoznik [Tue, 26 Jan 2021 16:12:50 +0000 (17:12 +0100)]
vsh: Use g_auto(GStrv) to free string list returned by completer callback

This saves us explicit call of g_strfreev() in error path.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Jonathon Jongsma <jjongsma@redhat.com>
4 years agovsh: Don't put VSH_OT_ALIAS onto list of completions
Michal Privoznik [Tue, 2 Feb 2021 13:55:28 +0000 (14:55 +0100)]
vsh: Don't put VSH_OT_ALIAS onto list of completions

We've invented VSH_OT_ALIAS type for --option so that we can
rewrite some --options (e.g. fix spelling). For instance
blkdeviotune command uses this feature heavily:
--options-with-dash are preferred over old
--options_with_underscore. Both versions are supported but only
the new ones (not aliased) are documented and reported in --help.

Except for options completer, which happily put also aliased
versions in front of user's eyes.

Note, there is a second (gross) way we use aliases: to rewrite
options from --oldoption to --newoption=value (for instance
--shareable option of attach-disk is an alias of
--mode=shareable). And just like with the previous group - don't
generate them into the list of possible options.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Jonathon Jongsma <jjongsma@redhat.com>
4 years agolib: Substitute some STREQLEN with STRPREFIX
Michal Privoznik [Tue, 26 Jan 2021 16:06:50 +0000 (17:06 +0100)]
lib: Substitute some STREQLEN with STRPREFIX

There are few cases where STREQLEN() is called like this:

  STREQLEN(var, string, strlen(string))

which is the same as STRPREFIX(var, string). Use STRPREFIX()
because it is more obvious what the check is doing.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Jonathon Jongsma <jjongsma@redhat.com>
4 years agotests: Only mock $INODE64 symbols on x86_64 macOS
Andrea Bolognani [Thu, 4 Feb 2021 14:48:18 +0000 (15:48 +0100)]
tests: Only mock $INODE64 symbols on x86_64 macOS

The version of macOS running on Apple Silicon doesn't need to
concern itself with backwards compatibility with 32-bit
applications, and so it could jettison all the symbol aliasing
shenanigans involved.

https://gitlab.com/libvirt/libvirt/-/issues/121

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Roman Bolshakov <r.bolshakov@yadro.com>
Tested-by: Roman Bolshakov <r.bolshakov@yadro.com>
4 years agoqemu_capabilities: Parse "deprecated" in virQEMUCapsLoadMachines() properly
Michal Privoznik [Tue, 9 Feb 2021 15:36:17 +0000 (16:36 +0100)]
qemu_capabilities: Parse "deprecated" in virQEMUCapsLoadMachines() properly

A <machine/> element can have "deprecated" attribute that
corresponds to 'deprecated' member of _virQEMUCapsMachineType
struct. But the member is of boolean type. Therefore, the string
returned by virXMLPropString() must be freed.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
4 years agoqemu_capabilities: Don't leak @str in virQEMUCapsLoadMachines()
Michal Privoznik [Tue, 9 Feb 2021 15:29:39 +0000 (16:29 +0100)]
qemu_capabilities: Don't leak @str in virQEMUCapsLoadMachines()

If parsing "maxCpus" attribute of <machine/> element fails an
error is printed but the corresponding string is not freed. While
it is very unlikely to happen (parsed XML is not user provided
and we are the ones generating it), it is possible. Instead of
freeing the variable in the error path explicitly, let's declare
it as g_autofree. And while I'm at it, let's bring it into the
loop where it's used.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
4 years agobuild: Fix generation of virtproxyd socket files
Jim Fehlig [Tue, 9 Feb 2021 15:55:41 +0000 (08:55 -0700)]
build: Fix generation of virtproxyd socket files

The various virtproxyd socket files are generated with invalid syntax,
e.g. from virtproxyd.socket

[Unit]
Description=Libvirt proxy local socket
Before=virtproxyd.service
libvirtd.socket libvirtd-ro.socket libvirtd-admin.socket libvirtd-tcp.socket libvirtd-tls.socket

Note the missing 'Conflicts=' in the last line. Fix it by prepending
'Conflicts=' to libvirtd_socket_conflicts when adding virtproxyd
to virt_daemon_units.

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
4 years agoqemucapabilitiesdata: Update 6.0.0 x86_64 capability test data
Peter Krempa [Sat, 6 Feb 2021 11:06:53 +0000 (12:06 +0100)]
qemucapabilitiesdata: Update 6.0.0 x86_64 capability test data

Update to qemu commit v5.2.0-1684-gd0dddab40e which includes the removal
of pc-1.0/pc-1.1/pc-1.2 machine types, adds the new QMP commands for
internal snapshots as well as includes the background-snapshot
capability.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
4 years agoqemuxml2argvdata: luks-disks-source-qcow2: Remove specific machine type
Peter Krempa [Sat, 6 Feb 2021 12:05:04 +0000 (13:05 +0100)]
qemuxml2argvdata: luks-disks-source-qcow2: Remove specific machine type

The test doesn't depend on any specific machine type.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
4 years agoqemuxml2argvdata: disk-cache: Remove specific machine type
Peter Krempa [Sat, 6 Feb 2021 12:02:51 +0000 (13:02 +0100)]
qemuxml2argvdata: disk-cache: Remove specific machine type

The test doesn't depend on any specific machine type.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
4 years agoqemuxml2argvdata: disk-cdrom-network: Remove specific machine type
Peter Krempa [Sat, 6 Feb 2021 11:12:08 +0000 (12:12 +0100)]
qemuxml2argvdata: disk-cdrom-network: Remove specific machine type

The test doesn't depend on a specific machine type.

The test uses a machine type which is becoming deprecated so it would
break the _LATEST version of the test once we update the qemu data.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
4 years agogitlab: Fix build container dependencies for build jobs
Andrea Bolognani [Tue, 9 Feb 2021 09:26:55 +0000 (10:26 +0100)]
gitlab: Fix build container dependencies for build jobs

A couple of these were wrong, resulting in the build job not
waiting for the correct container to be built before starting.

Fixes: 77296c807b18d22286be4b0ba5595d13103910a1
Signed-off-by: Andrea Bolognani <abologna@redhat.com>
4 years agocpu: Fix build on some aarch64 platforms
Andrea Bolognani [Fri, 5 Feb 2021 13:07:27 +0000 (14:07 +0100)]
cpu: Fix build on some aarch64 platforms

On platforms that lack both getauxval() and elf_aux_info(),
such as OpenBSD and macOS, host CPU detection can't work.

https://gitlab.com/libvirt/libvirt/-/issues/121

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
4 years agocpu: Only retrieve AT_HWCAP once
Andrea Bolognani [Fri, 5 Feb 2021 14:01:46 +0000 (15:01 +0100)]
cpu: Only retrieve AT_HWCAP once

No need to fetch the same information twice.

As a side effect, this solves a bug where, on platforms where
elf_aux_info() is used instead of getauxval(), we would not
make sure the CPUID feature is available before attempting to
use it.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
4 years agocpu: Only include <sys/auxv.h> if available
Andrea Bolognani [Fri, 5 Feb 2021 14:03:32 +0000 (15:03 +0100)]
cpu: Only include <sys/auxv.h> if available

This header is not present on several non-Linux targets that
nonetheless support aarch64.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
4 years agoqemu: Release <memory/> device address on failed hotplug
Michal Privoznik [Mon, 8 Feb 2021 14:21:16 +0000 (15:21 +0100)]
qemu: Release <memory/> device address on failed hotplug

A few commits back I've introduced new 'virtio-pmem' <memory/>
device. Since it's virtio it goes onto PCI bus. Therefore, on
hotplug new PCI address is generated (or provided one is
reserved). However, if hotplug fails (for whatever reason) the
address needs to be released. This is different to 'dimm' type of
address because for that type we don't keep a map of used slots
rather generate one on each address assign request. The map is
then thrown away. But for PCI addresses we keep internal state
and thus has to keep it updated. Therefore, this new
qemuDomainReleaseMemoryDeviceSlot() function is NOP for those
models which use 'dimm' address type ('dimm' and 'nvdimm').

While I'm at it, let's release the address in case of hot unplug.
Not that is supported (any such attempt fails with the following
error:

  "virtio based memory devices cannot be unplugged"

But if QEMU ever implements hot unplug then we don't have to
remember to fix our code.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
4 years agobhyve: auto allocate nmdm console paths
Roman Bogorodskiy [Sun, 7 Feb 2021 03:57:07 +0000 (07:57 +0400)]
bhyve: auto allocate nmdm console paths

Currently, nmdm console device requires user to specify master and slave
path attributes (such as /dev/nmdm0A and /dev/nmdm0B respectively).
However, making user find a non-occupied device name might be not
convenient, especially for the remote connections.

Update the logic to make these attributes optional. In case if not
specified, use /dev/nmdm$UUID[AB], where $UUID is a domain's UUID.
With this schema it's unlikely nmdm device will clash with other domains
or even other non-bhyve nmdm devices.

Signed-off-by: Roman Bogorodskiy <bogorodskiy@gmail.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
4 years agoTranslated using Weblate (Finnish)
Jan Kuparinen [Sat, 6 Feb 2021 19:40:11 +0000 (20:40 +0100)]
Translated using Weblate (Finnish)

Currently translated at 13.5% (1415 of 10451 strings)

Translation: libvirt/libvirt
Translate-URL: https://translate.fedoraproject.org/projects/libvirt/libvirt/fi/

Co-authored-by: Jan Kuparinen <copper_fin@hotmail.com>
Signed-off-by: Jan Kuparinen <copper_fin@hotmail.com>
4 years agoconf: allow virtio driver attributes for vhostuser disk
Pavel Hrdina [Fri, 5 Feb 2021 12:05:54 +0000 (13:05 +0100)]
conf: allow virtio driver attributes for vhostuser disk

All of these options are actually supported by vhostuser disk so
we should allow them to be usable.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
4 years agobhyve: drop emulator binary value check
Roman Bogorodskiy [Thu, 4 Feb 2021 15:29:44 +0000 (19:29 +0400)]
bhyve: drop emulator binary value check

Currently, requesting domain capabilities fails when the specified
emulator binary does not equal to "/usr/sbin/bhyve". As we're
not using user-specified emulator anyway, drop this check to avoid
showing errors for values like "bhyve" (without absolute path).

Signed-off-by: Roman Bogorodskiy <bogorodskiy@gmail.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agodocs: Remove broken link to Xen channel doc
Jim Fehlig [Thu, 4 Feb 2021 23:32:50 +0000 (16:32 -0700)]
docs: Remove broken link to Xen channel doc

Many of Xen's text documents have been converted to man pages over
the years, the channel doc being one of them. Replace the broken
channel.txt link with the name of the man page providing the same
information.

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agodocs: Add 'known_hosts_verify' parameter for libssh(2) connection uris
Jakob Meng [Fri, 29 Jan 2021 12:55:06 +0000 (13:55 +0100)]
docs: Add 'known_hosts_verify' parameter for libssh(2) connection uris

Parameter 'known_hosts_verify' is supported for some time now,
but it is not yet documented.

Signed-off-by: Jakob Meng <jakobmeng@web.de>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agoqemuDomainAttachRedirdevDevice: Remove need_release variable
Yi Li [Wed, 3 Feb 2021 06:18:34 +0000 (14:18 +0800)]
qemuDomainAttachRedirdevDevice: Remove need_release variable

Get rid of the 'need_release' variable. The code can be rewritten
so that it is not needed.

Signed-off-by: Yi Li <yili@winhong.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agoRevert "tests: Avoid gnulib replacements in mocks"
Andrea Bolognani [Thu, 4 Feb 2021 10:05:48 +0000 (11:05 +0100)]
Revert "tests: Avoid gnulib replacements in mocks"

Now that we're no longer using gnulib, we can treat macOS the
same as all other targets.

This reverts commit 0ae6f5cea54d95c0d1dedf04a0a2accfe2529fb2

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Roman Bolshakov <r.bolshakov@yadro.com>
Tested-by: Roman Bolshakov <r.bolshakov@yadro.com>
4 years agoutil: Remove '\n' from vhostuser ifname
Yalei Li [Fri, 5 Feb 2021 03:10:51 +0000 (11:10 +0800)]
util: Remove '\n' from vhostuser ifname

When deleting the vhostuserclient interface, OVS prompts that the interface does not exist,
Through the XML file, I found that the "target dev" has a '\n', results in an XML parsing error.

XML file:

<target dev='vm-20ac9c030a47
'/>

That is because 'ovs-vsctl' returns a newline result, always come with a '\n',
and the vircommandrun function puts it in ifname.

So virNetDevOpenvswitchGetVhostuserIfname should remove '\n' from ifname.

Signed-off-by: Yalei Li <liyl43@chinatelecom.cn>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agodatatypes: replace VIR_FREE with g_free in all *Dispose() functions
Laine Stump [Wed, 3 Feb 2021 20:16:43 +0000 (15:16 -0500)]
datatypes: replace VIR_FREE with g_free in all *Dispose() functions

Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
4 years agotests: replace VIR_FREE with g_free in all *Dispose() functions
Laine Stump [Wed, 3 Feb 2021 20:15:50 +0000 (15:15 -0500)]
tests: replace VIR_FREE with g_free in all *Dispose() functions

Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
4 years agoconf: replace VIR_FREE with g_free in all *Dispose() functions
Laine Stump [Wed, 3 Feb 2021 20:15:35 +0000 (15:15 -0500)]
conf: replace VIR_FREE with g_free in all *Dispose() functions

Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
4 years agoutil: replace VIR_FREE with g_free in all *Dispose() functions
Laine Stump [Wed, 3 Feb 2021 20:15:23 +0000 (15:15 -0500)]
util: replace VIR_FREE with g_free in all *Dispose() functions

Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
4 years agosecurity: replace VIR_FREE with g_free in all *Dispose() functions
Laine Stump [Wed, 3 Feb 2021 20:15:18 +0000 (15:15 -0500)]
security: replace VIR_FREE with g_free in all *Dispose() functions

Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
4 years agorpc: replace VIR_FREE with g_free in all *Dispose() functions
Laine Stump [Wed, 3 Feb 2021 20:14:57 +0000 (15:14 -0500)]
rpc: replace VIR_FREE with g_free in all *Dispose() functions

Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
4 years agologging: replace VIR_FREE with g_free in all *Dispose() functions
Laine Stump [Wed, 3 Feb 2021 20:14:51 +0000 (15:14 -0500)]
logging: replace VIR_FREE with g_free in all *Dispose() functions

Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
4 years agohypervisor: replace VIR_FREE with g_free in all *Dispose() functions
Laine Stump [Wed, 3 Feb 2021 20:14:27 +0000 (15:14 -0500)]
hypervisor: replace VIR_FREE with g_free in all *Dispose() functions

Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
4 years agoaccess: replace VIR_FREE with g_free in all *Dispose() functions
Laine Stump [Wed, 3 Feb 2021 20:14:21 +0000 (15:14 -0500)]
access: replace VIR_FREE with g_free in all *Dispose() functions

Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
4 years agointerface: replace VIR_FREE with g_free in all *Dispose() functions
Laine Stump [Wed, 3 Feb 2021 19:55:20 +0000 (14:55 -0500)]
interface: replace VIR_FREE with g_free in all *Dispose() functions

Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
4 years agoqemu: replace VIR_FREE with g_free in all *Dispose() functions
Laine Stump [Wed, 3 Feb 2021 20:13:53 +0000 (15:13 -0500)]
qemu: replace VIR_FREE with g_free in all *Dispose() functions

Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
4 years agolibxl: replace VIR_FREE with g_free in all *Dispose() functions
Laine Stump [Wed, 3 Feb 2021 20:13:46 +0000 (15:13 -0500)]
libxl: replace VIR_FREE with g_free in all *Dispose() functions

Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
4 years agobhyve: replace VIR_FREE with g_free in all *Dispose() functions
Laine Stump [Wed, 3 Feb 2021 20:13:23 +0000 (15:13 -0500)]
bhyve: replace VIR_FREE with g_free in all *Dispose() functions

Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
4 years agorpc: eliminate static function virNetLibsshSessionAuthMethodsFree()
Laine Stump [Thu, 4 Feb 2021 02:12:21 +0000 (21:12 -0500)]
rpc: eliminate static function virNetLibsshSessionAuthMethodsFree()

This function is only called from one place, and has, well... not a
*misleading* name, but it doesn't fit the standard frame of functions
that end in "Free" (it doesn't actually free the object pointed to by
its argument, but frees *some parts* of the content of the object).

Rather than try to think up an appropriate name, let's just move the
meat of this function into its one and only caller,
virNetLibsshSessionDispose(), which will allow us to convert its
VIR_FREEs into g_free in a future patch.

Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
4 years agoconf: simplify virDomainCapsDispose()
Laine Stump [Tue, 2 Feb 2021 06:11:30 +0000 (01:11 -0500)]
conf: simplify virDomainCapsDispose()

virDomainCapsDispose() was the only caller of
virDomainCapsStringValuesFree(), which 1) didn't actually free the
object it was called with, but only cleared it, making it less
mechanical to convert from VIR_FREE to g_free (since it's not
immediately obvious from looking at virDomainCapsStringValuesFree()
that the pointers being cleared will never again be used).

We could have renamed the function to virDomainCapsStringValuesClear()
to side-step the confusion of what the function actually does, but
that would just make the upcoming switch from VIR_FREE to g_free
require more thought. But since there is only a single caller to the
function, and it is a vir*Dispose() function (indicating that the
object containing the virDomainCapsStringValues is going to be freed
immediately after the function finishes), and thus VIR_FREE() *could*
be safely replaced by g_free()), we instead just move the contents of
virDomainCapsStringValuesFree() into virDomainCapsDispose() (and
*that* function will be trivially converted in an upcoming
"mechanical" patch).

Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
4 years agorpc: rename virNetSessionAuthMethodsFree to virNetSessionAuthMethodsClear
Laine Stump [Thu, 4 Feb 2021 02:51:04 +0000 (21:51 -0500)]
rpc: rename virNetSessionAuthMethodsFree to virNetSessionAuthMethodsClear

This is another *Free() function that doesn't free the object it is
passed. Instead it frees and clears some parts of the object.

In this case, the function is actually called from two places, and one
of them (virNetSSHSessionAuthReset) appears to be assuming that the
pointers actually *will* be cleared. So the proper thing to do here
(?) is to rename the function to virNetSSHSesionAuthMethodsClear().

(NB: virNetSSHSessionAuthReset is seemingly never called from
anywhere. Is this one of those functions that actually *is* called by
some strange MACRO invocation? Or it is truly one of those
"written-but-never-used" functions that can be deleted? (if the latter
is the case, then I would rather move the contents of
virNetSessionAuthMethodsFree() into its only other caller,
virNetSSHSessionDispose(), so that the VIR_FREEs could be replaced
with g_free.)

Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
4 years agoqemu: replace VIR_FREE with g_free in qemuFirmware*FreeContent()
Laine Stump [Thu, 4 Feb 2021 02:07:20 +0000 (21:07 -0500)]
qemu: replace VIR_FREE with g_free in qemuFirmware*FreeContent()

These functions are all only called as a part of qemuFirmwareFree(),
which frees the qemuFirmware object before return, so we can be sure
none of the pointers is referenced after freeing (and thus there is no
need to clear any of them).

Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
4 years agoqemu: pass pointers instead of copying objects for qemuFirmware*FreeContent()
Laine Stump [Wed, 3 Feb 2021 21:57:57 +0000 (16:57 -0500)]
qemu: pass pointers instead of copying objects for qemuFirmware*FreeContent()

These functions all cooperate to free memory pointed to by a single
object that contains (doesn't *point to*, but actually contains)
several sub-objects. They were written to send copies of these
sub-objects to subordinate functions, rather than just sending
pointers to the sub-objects.

Let's change these functions to just send pointers to the objects
they're cleaning out rather than all the wasteful and pointless
copying.

Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
4 years agoqemu: rename virFirmware*Free() functions to have more accurate names
Laine Stump [Wed, 3 Feb 2021 21:07:59 +0000 (16:07 -0500)]
qemu: rename virFirmware*Free() functions to have more accurate names

Several functions had the names virFirmware[something]Free(), but they
aren't taking a pointer to some object and freeing it. Instead, they
are making a copy of the content of an entire object, then Freeing the
objects pointed to by that content.

As a first step in a too-complicated cleanup just to eliminate a few
occurrences of VIR_FREE(), this patch renames those functions to more
accurately reflect what they do - they Free the *Content* of their
arguments.

Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
4 years agoutil: rename two *Free() functions while changing VIR_FREE to g_free
Laine Stump [Thu, 4 Feb 2021 02:38:59 +0000 (21:38 -0500)]
util: rename two *Free() functions while changing VIR_FREE to g_free

dhcpHostFree() and addnHostFree() don't follow the normal pattern of
*Free functions in the rest of libvirt code - they are actually more
similar to the *Dispose() functions, in that they free all subordinate
objects, but not the object pointed to by the argument
itself. However, the arguments aren't virObjects, so it wouldn't be
proper to name them *Dispose() either.

They *currently* behave similar to a *Clear() function, in that they
free all the subordinate objects and nullify the pointers of those
objects. HOWEVER, we don't actually need or want that behavior - the
two functions in question are only called as part of a higher level
*Free() function, and the pointers are not referenced in any way
between the time they are freed and when the parent object is freed.

So, since the current name isn't correct, nor is *Dispose(), and we
want to change the behavior in such a way that *Clear() also wouldn't
be correct, lets name the functions *FreeContent(), which is an
accurate description of what the functions do, and what we *want* them
to do.

And since it's such a small patch, we can go ahead and change that
behavior - replacing the VIR_FREEs with g_free.

Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
4 years agolibvirtd: replace straggler VIR_FREE with g_free in all vir*Free() functions
Laine Stump [Wed, 3 Feb 2021 19:58:38 +0000 (14:58 -0500)]
libvirtd: replace straggler VIR_FREE with g_free in all vir*Free() functions

Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
4 years agostorage: replace VIR_FREE with g_free in all vir*Free() functions
Laine Stump [Wed, 3 Feb 2021 19:35:44 +0000 (14:35 -0500)]
storage: replace VIR_FREE with g_free in all vir*Free() functions

Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
4 years agotests: replace VIR_FREE with g_free in all vir*Free() functions
Laine Stump [Wed, 3 Feb 2021 19:35:02 +0000 (14:35 -0500)]
tests: replace VIR_FREE with g_free in all vir*Free() functions

Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
4 years agotools: replace VIR_FREE with g_free in all vir*Free() functions
Laine Stump [Wed, 3 Feb 2021 19:32:55 +0000 (14:32 -0500)]
tools: replace VIR_FREE with g_free in all vir*Free() functions

Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
4 years agosecurity: replace VIR_FREE with g_free in all vir*Free() functions
Laine Stump [Wed, 3 Feb 2021 19:40:30 +0000 (14:40 -0500)]
security: replace VIR_FREE with g_free in all vir*Free() functions

Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
4 years agorpc: replace VIR_FREE with g_free in all vir*Free() functions
Laine Stump [Wed, 3 Feb 2021 19:40:09 +0000 (14:40 -0500)]
rpc: replace VIR_FREE with g_free in all vir*Free() functions

Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
4 years agoremote: replace VIR_FREE with g_free in all vir*Free() functions
Laine Stump [Wed, 3 Feb 2021 19:54:59 +0000 (14:54 -0500)]
remote: replace VIR_FREE with g_free in all vir*Free() functions

Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
4 years agologging: replace VIR_FREE with g_free in all vir*Free() functions
Laine Stump [Wed, 3 Feb 2021 19:37:07 +0000 (14:37 -0500)]
logging: replace VIR_FREE with g_free in all vir*Free() functions

Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
4 years agolocking: replace VIR_FREE with g_free in all vir*Free() functions
Laine Stump [Wed, 3 Feb 2021 19:37:59 +0000 (14:37 -0500)]
locking: replace VIR_FREE with g_free in all vir*Free() functions

Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
4 years agoadmin: replace VIR_FREE with g_free in all vir*Free() functions
Laine Stump [Wed, 3 Feb 2021 19:57:46 +0000 (14:57 -0500)]
admin: replace VIR_FREE with g_free in all vir*Free() functions

Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
4 years agovz: replace VIR_FREE with g_free in all vir*Free() functions
Laine Stump [Wed, 3 Feb 2021 19:35:19 +0000 (14:35 -0500)]
vz: replace VIR_FREE with g_free in all vir*Free() functions

Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
4 years agovmx: replace VIR_FREE with g_free in all vir*Free() functions
Laine Stump [Wed, 3 Feb 2021 19:56:20 +0000 (14:56 -0500)]
vmx: replace VIR_FREE with g_free in all vir*Free() functions

Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>