Commit Graph

43900 Commits

Author SHA1 Message Date
Ján Tomko
096412f1ba ch: fix logic in virCHMonitorBuildPtyJson
There is a leftover 'ptys' variable, which we only assign
to and one assignment to 'content', where we add an empty
'pty' object.

Remove 'ptys'.

Fixes: 93accefd9e
Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Kristína Hanicová <khanicov@redhat.com>
2021-11-23 16:59:36 +01:00
Ján Tomko
f5dd918978 vbox: fix vboxCapsInit
There is a stray mis-indented 'return NULL' left after a recent
refactor.

Fixes: c18d9e23fa
Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Kristína Hanicová <khanicov@redhat.com>
2021-11-23 16:59:36 +01:00
Ján Tomko
097d3a4f56 tools: virt-host-validate: fix memory leak
virHostValidateGetCPUFlags returns an allocated virBitmap and
it needs to be freed.

Fixes: a0ec7165e3
Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Kristína Hanicová <khanicov@redhat.com>
2021-11-23 16:59:36 +01:00
Martin Kletzander
edd1fd8ca9 Use virProcessGetStat
This eliminates one incorrect parsing implementation which relied on the
command field not having a closing bracket.  This possibility is already
tested against in the virProcessGetStat() tests.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2021-11-23 16:43:08 +01:00
Martin Kletzander
e370d4056b util: Add virProcessGetStat
This reads and separates all fields from /proc/<pid>/stat or
/proc/<pid>/task/<tid>/stat as there are easy mistakes to be done in the
implementation.  Some tests are added to show it works correctly.  No number
parsing is done as it would be unused for most of the fields most, if not all,
of the time.  No struct is used for the result as the length can vary (new
fields can be added in the future).

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2021-11-23 16:43:08 +01:00
Pavel Hrdina
2fe7622d19 virsh: man: update snapshot-revert description
We've changed the behavior of this API that from now on it will always
restart the VM process and we are no longer able to revert to snapshots
created by libvirt older then 0.9.5.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2021-11-23 16:03:19 +01:00
Pavel Hrdina
4b3c0d1aba qemu_monitor: remove unused load snapshot code
Recent cleanup of snapshot revert code made these function unused.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2021-11-23 16:03:07 +01:00
Koichi Murase
097296c30b bash-completion: fix variable leaks of "IFS" and "word"
Signed-off-by: Koichi Murase <myoga.murase@gmail.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2021-11-23 13:35:36 +01:00
Martin Kletzander
00c0ba5de3 util: Check for pkttyagent availability properly
It does not need a tty to work, it opens its controlling terminal for user
interaction and with this patch even crazy things like this work:

  echo 'list --name' | virsh -q >/dev/null

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2021-11-23 12:51:09 +01:00
Martin Kletzander
32eae6fd31 util: Report errors in all code paths in virPolkitAgentCreate
Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2021-11-23 12:51:09 +01:00
Martin Kletzander
0ac13b189f virsh: Do not try connecting first time without polkit agent
Trying to connect once without a polkit agent will generate an error on the
server side which seems too rough given it only serves the purpose of the client
(virsh in this case) to figure out that an agent is needed.  Thankfully we can
just try running the agent.  It does not break anything as we are running it
with `--fallback`, which makes sure it does not replace an existing agent in
case there is one already registered.

The second piece of code trying to start the polkit text agent is kept in order
to _really_ try out starting the agent (and error out when failing to do so)
just in case the agent was not available the first time it was ran.  Even though
it should not happen it avoids a very rare race condition and really does not
add much complexity.

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

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2021-11-23 12:51:09 +01:00
Martin Kletzander
32d100ca5c util: Add virPolkitAgentAvailable
With this function we can decide whether to try running the polkit text agent
only if it is available, removing a potential needless error saying that the
agent binary does not exist, which is useful especially when running the agent
before knowing whether it is going to be needed.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2021-11-23 12:51:09 +01:00
Martin Kletzander
e4ebe391d7 util: Tiny reword fix in comment
Automatic "Ptr " -> " *" also wreaked havoc in comments.  Fix it and while at it
reword the sentence so it is clear that the object is newly allocated.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2021-11-23 12:51:09 +01:00
Martin Kletzander
e20ad73780 virsh: Remove needless variable
It only redundantly reflects whether pkagent != NULL.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2021-11-23 12:51:09 +01:00
Roman Bogorodskiy
c07cf0a686 meson: improve CPU affinity routines check
Recently, FreeBSD has got sched_get/setaffinity(3) implementations and
the sched.h header as well [1]. To make these routines visible,
users have to define _WITH_CPU_SET_T.

This breaks current detection. Specifically, meson sees the
sched_getaffinity() symbol and defines WITH_SCHED_GETAFFINITY. This
define unlocks Linux implementation of virProcessSetAffinity() and other
functions, which fails to build on FreeBSD because cpu_set_t is not
visible as _WITH_CPU_SET_T is not defined.

For now, change detection to the following:

 - Instead of checking sched_getaffinity(), check if 'cpu_set_t' is
   available through sched.h
 - Explicitly check the sched.h header instead of assuming its presence
   if WITH_SCHED_SETSCHEDULER is defined

1:
https://cgit.freebsd.org/src/commit/?id=43736b71dd051212d5c55be9fa21c45993017fbb
https://cgit.freebsd.org/src/commit/?id=160b4b922b6021848b6b48afc894d16b879b7af2
https://cgit.freebsd.org/src/commit/?id=90fa9705d5cd29cf11c5dc7319299788dec2546a

Signed-off-by: Roman Bogorodskiy <bogorodskiy@gmail.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
2021-11-23 15:11:00 +04:00
Pavel Hrdina
9b0a6d959b domain_snapshot: update virDomainRevertToSnapshot description
We've changed the behavior of this API that from now on it will always
restart the VM process and we are no longer able to revert to snapshots
created by libvirt older then 0.9.5.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
2021-11-23 11:42:07 +01:00
Pavel Hrdina
5956eddf9f test: snapshot revert: drop error the VM must be restarted
This will always happen so there is no need to error out and require
usage of FORCE flag.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
2021-11-23 11:42:05 +01:00
Pavel Hrdina
a4942cfa3a test: snapshot revert: fix emitting events
Now that we always emulate restarting the VM process events are emitted
differently so we need to update the code and the comment as well.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
2021-11-23 11:42:03 +01:00
Pavel Hrdina
74ea062be6 test: snapshot revert: drop unused code
Now that we always emulate VM process stop we can drop the unused code
and simply the logic.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
2021-11-23 11:42:00 +01:00
Pavel Hrdina
5bed5db990 test: snapshot revert: always emulate VM process stop
Reflect the same change in test driver as in QEMU driver because the
compatibility check code isn't perfect.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
2021-11-23 11:41:57 +01:00
Pavel Hrdina
2ef6b1cecf test: snapshot revert: properly emulate starting CPUs
When active snapshot is reverted we stop CPUs in order to load the
snapshot but we never start the CPUs again.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
2021-11-23 11:41:55 +01:00
Pavel Hrdina
ca04290be3 test: snapshot revert: always error out if VM XML is missing
We should have this check even if FORCE flag is used because later we
unconditionally copy the `snap->def->dom` and error out if there is no
copy created. The test driver will always save the VM XML when creating
new snapshot.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
2021-11-23 11:41:52 +01:00
Pavel Hrdina
6c86b92f14 qemu_snapshot: revert: drop error that QEMU process must be restarted
This will always happen so there is no need to error out and require
usage of FORCE flag.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
2021-11-23 11:41:50 +01:00
Pavel Hrdina
d8a4acab96 qemu_snapshot: revert: fix emitting events
Now that we always restart the QEMU process events are emitted
differently so we need to update the code and the comment as well.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
2021-11-23 11:41:48 +01:00
Pavel Hrdina
f33ce12e9c qemu_snapshot: revert: drop unused loadvm code
Now that we always restart QEMU process the loadvm code is unused and
can be dropped.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
2021-11-23 11:41:45 +01:00
Pavel Hrdina
3bec4ce049 qemu_snapshot: revert: always restart QEMU process for running VM
Our compatibility check code isn't complete and there are cases where it
fails to detect incompatible configuration and the revert fails. In
addition future support for external snapshot will always require
restarting the QEMU process.

To unify the behavior drop the compatibility check code and always
restart the QEMU process.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
2021-11-23 11:41:43 +01:00
Pavel Hrdina
649bd34c28 qemu_snapshot: revert: always error out if VM XML is missing
The support to revert snapshots was introduced in libvirt 0.8.0 but
saving the whole VM XML was implemented later in libvirt 0.9.5.

That is more then 10 years ago so we can safely assume that nobody will
try reverting to snapshot created by that old libvirt. In the unlikely
scenario where someone would actually did it we would simply error out.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
2021-11-23 11:41:38 +01:00
Pavel Hrdina
23b99623ee util: fix various ATTRIBUTE_NONNULL calls
Git bisect took me to commit where incorrect usage of ATTRIBUTE_NONNULL
was introduced and caused coverity scan to fail. This patch fixes the
issue where the index starts from 1 and not 0 and two other different
cases.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2021-11-23 09:59:00 +01:00
Michal Privoznik
d20ebdda28 qemu: Switch to -accel
We currently use -machine accel=XXX which is just a syntax sugar
for -accel XXX. The former doesn't allow specifying arguments for
accelerator, because all arguments passed to -machine are
treated as arguments of machine itself.

The -accel argument was introduced in QEMU commit
v2.9.0-rc0~70^2~19 and since our minimum required version is
newer (2.11.0) we can safely assume its existence and use it
without any capability.

Resolves: https://gitlab.com/libvirt/libvirt/-/issues/233
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Tested-by: Kashyap Chamarthy <kchamart@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
2021-11-22 13:06:54 +01:00
Michal Privoznik
69f2f63299 qemu_command: Don't validate accelerator when building cmd line
The domain accelerator was validated in qemuValidateDomainDef()
which calls virQEMUCapsIsVirtTypeSupported() which reports proper
error if QEMU is not capable of KVM/TCG. There is no point in
doing the validation again when building command line.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Tested-by: Kashyap Chamarthy <kchamart@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
2021-11-22 13:06:54 +01:00
Peter Krempa
d5643e73da qemuMonitorJSONAttachCharDevGetProps: Modernize construction of JSON objects
Use 'virJSONValueObjectAdd' instead of the step-by-step manual JSON
object building.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2021-11-22 12:51:18 +01:00
Peter Krempa
03cab99ca5 qemuMonitorJSONBuildChrChardevReconnect: Unify with qemuBuildChrChardevReconnectStr
When formatting the commandline we explicitly set the reconnect timeout
to 0 when it's disabled even when that's the default. Do the same in
the monitor/hotplug code.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2021-11-22 12:51:18 +01:00
Peter Krempa
dd138ea402 qemuMonitorJSONAttachCharDevGetProps: Rename 'backend_type' and 'data'
Rename 'data' to 'backendData' so that it's more clear what the object
represents and 'backend_type' to 'backendType' to go with the common
camel case notation.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2021-11-22 12:51:18 +01:00
Michal Privoznik
784e9e2b62 lib: Drop needless one line labels
In some cases we have a label that contains nothing but a return
statement. The amount of such labels rises as we use automagic
cleanup. Anyway, such labels are pointless and can be dropped.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
2021-11-22 12:39:59 +01:00
Michal Privoznik
3010a69226 qemu_command: Generate -mem-prealloc in one corner case more
When guest has NUMA nodes and QEMU is new enough to report
default RAM ID then ideally we would use -numa memdev= combined
with memory-backend-* combo becasue -mem-path/-mem-prealloc/-numa
mem are deprecated. Well, there is one problem - the .memdev=
attribute is machine type dependent (just look at arguments of
virQEMUCapsGetMachineNumaMemSupported()) and to ensure backwards
compatibility we prefer -numa mem= over -numa memdev=.

But there was one corner case when -mem-prealloc was requested
but not generated on the cmd line. It all starts with
qemuBuildMemCommandLine() which generates just '-m XXX' and
because it sees defaultRAMid and guest NUMA nodes greater than
zero it does nothing more.

Then, qemuBuildNumaCommandLine() sees that -numa mem= is still
supported for given machine type and nothing else set
@needBackend thus qemuBuildMemPathStr() is called which output
-mem-prealloc only in a few cases assuming it was outputted
earlier.

Reported-by: Jing Qi <jinqi@redhat.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2021-11-22 12:27:29 +01:00
Michal Privoznik
3f390db2e2 qemuxml2argvtest: Introduce another numa-topology test
This test shows a bug we have: even though the XML says:

  <allocation mode='immediate'/>

there is no -mem-prealloc nor .prealloc=yes anywhere on the cmd
line. This will be fixed in the next commit.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2021-11-22 12:27:19 +01:00
Daniel Henrique Barboza
c7820f1509 qemu_capabilities.c: del 'cleanup' label in virQEMUCapsLoadHostCPUModelInfo()
Create extra g_autofree strings and use them in an adequate scope to
eliminate the need for VIR_FREE() calls and the 'cleanup' label.

Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
2021-11-19 13:32:59 -03:00
Daniel Henrique Barboza
0e2b546166 cpu_ppc64.c: remove 'guest' param from ppc64Compute()
ppc64Compute() is used only once, by virCPUppc64Compare(), which
doesn't use the 'guest' parameter. It was last used by an API
called 'cpuGuestData' that was dropped by commit 03fa904c0c.

Removing the 'guest' parameter will not only remove unused code from
ppc64Compute() but also remove the ppc64MakeCPUData() entirely.

Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
2021-11-19 13:32:59 -03:00
Daniel Henrique Barboza
294e92145e qemu_capabilities.c: remove cleanup label from virQEMUCapsLoadCache()
'str' is no longer being used and the 'cleanup' label can be removed
together with the 'ret' variable.

Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
2021-11-19 13:32:58 -03:00
Daniel Henrique Barboza
484c6e2ca4 qemu_capabilities.c: add virQEMUCapsValidateArch()
Create a new helper to remove the arch validation logic from the
body of virQEMUCapsLoadCache().

Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
2021-11-19 13:32:58 -03:00
Daniel Henrique Barboza
8ccf9444b9 qemu_capabilities.c: add virQEMUCapsValidateEmulator()
Create a new helper to remove the emulator validation logic from the
body of virQEMUCapsLoadCache().

Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
2021-11-19 13:32:58 -03:00
Daniel Henrique Barboza
89120dddbe qemu_capabilities.c: del 'nodes' var from virQEMUCapsLoadCache()
The 'nodes' var is not being used.

Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
2021-11-19 13:32:58 -03:00
Daniel Henrique Barboza
a0eafbf250 qemu_capabilities.c: add virQEMUCapsParseGIC()
Create a new helper to remove the GIC parse logic from the body of
virQEMUCapsLoadCache().

Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
2021-11-19 13:32:58 -03:00
Daniel Henrique Barboza
9041fa5d53 qemu_capabilities.c: add virQEMUCapsParseFlags()
Create a new helper to remove the parse capabilities flag logic from the
body of virQEMUCapsLoadCache().

Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
2021-11-19 13:32:58 -03:00
Vasiliy Ulyanov
4f3120d70c qemu: Fix the check of AMD secure guest support
The content of /sys/module/kvm_amd/parameters/sev may vary depending on
the kernel version. Check also for 'Y' and 'y' in addition to '1' to
cover several possible variants. The fix is similar to the one
introduced in commit 3f9c1a4bb8

Signed-off-by: Vasiliy Ulyanov <vulyanov@suse.de>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2021-11-19 14:59:00 +01:00
Ján Tomko
28bb7266a0 conf: match by network alias only if aliases are assigned
Commit 114e3b4232 added matching by
aliases for interfaces with same MAC address.
( https://bugzilla.redhat.com/show_bug.cgi?id=1926190 )

However, unless the domain is using user aliases (prefixed ua-),
there are no aliases in the persistent definition.

Only match by MAC/PCI/other addresses in that case, to fix update-device
with --persistent flag (AFFECT_LIVE | AFFECT_CONFIG).

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

Fixes: 114e3b4232
Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
2021-11-19 14:06:17 +01:00
Peter Krempa
1e085019ca qemuDomainPrepareStorageSourceBlockdev: Set default encryption engine also when preparing virStorageSource
Originally the default encryption engine is populated in the disk
post-parse callback code. This works for disks but for any additional
images introduced either via the block copy API or via the backup API we
don't populate the default.

In case when the backup or block copy is requested on an encrypted image
this would then lead to an error:

 error: internal error: Unexpected enum value 0 for virStorageEncryptionEngine

This patch adds another point where we populate the default which is
when setting up a virStorageSource for actual usage.

We keep the original setting in the post-parse callback as that's the
only point that is recorded in the XML file after definition.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=2023674
Fixes: ab1d46d612
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2021-11-19 12:41:36 +01:00
Peter Krempa
84d1347dbe qemuxml2argvtest: Add device with 'ramfb=off' to 'hostdev-mdev-display-ramfb'
Add a test case where 'ramfb' is explicitly disabled for a mediated
device to prevent regressing again.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2021-11-19 12:40:41 +01:00
Peter Krempa
c3bf7f5e62 qemuBuildHostdevMediatedDevProps: Format 'ramfb' only when enabled
Before commit 73c352ab8c which converted the hostdev commandline
formatter to JSON the 'ramfb' property was formatted only if it was
enabled.

The main reason for that is that enabling 'ramfb' switches the device
model to 'vfio-pci-nohotplug' which actually has the property, while
'vfio-pci' (used when 'ramfb' is disabled or absent) doesn't have it.

Restore the logic to format 'ramfb' only when it's enabled and add a
comment that it's deliberate.

Fixes: 73c352ab8c
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=2024435
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2021-11-19 12:40:41 +01:00
Peter Krempa
2cb53c61cf qemuxml2argvtest: Fix type for faked chardev backing a TPM
The test filled the chardev type to VIR_DOMAIN_CHR_TYPE_FILE and thus
set the 'data.emulator.source->data.file.path' pointer, but the
commandline formatter is unconditionally expecting VIR_DOMAIN_CHR_TYPE_UNIX
and thus reading 'data.emulator.source->data.nix.path'. Since it's an
union it happened to land in the correct place. Fix the faked data.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2021-11-19 12:38:35 +01:00