Commit Graph

47442 Commits

Author SHA1 Message Date
Erik Skultety
3ebfeaa206 ci: Refresh and add Fedora 37 target
Signed-off-by: Erik Skultety <eskultet@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
2023-01-09 14:53:34 +01:00
Peter Krempa
d9193ff92b qemu: Fix variable sizing issues with 'bandwidth' argument of qemuBlockCommit
The patch moving the code didn't faithfully represent the typecasting
of the 'bandwidth' variable needed to properly convert from the legacy
'unsigned long' argument which resulted in a build failure on 32 bit
systems:

../src/qemu/qemu_block.c: In function ‘qemuBlockCommit’:
../src/qemu/qemu_block.c:3249:23: error: comparison is always false due to limited range of data type [-Werror=type-limits]
 3249 |         if (bandwidth > LLONG_MAX >> 20) {
      |                       ^

Fix it by returning the check into qemuDomainBlockCommit as it's needed
only because of the legacy argument type in the old API and use
'unsigned long long' for qemuBlockCommit.

Fixes: f5a77198bf
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
2023-01-09 14:40:39 +01:00
Peter Krempa
64366c0056 qemu: snapshot: Restructure control flow to detect errors sooner and work around compiler
Some compilers aren't happy when an automatically freed variable is used
just to free something (thus it's only assigned in the code):

When compiling qemuSnapshotDelete after recent commits they complain:

../src/qemu/qemu_snapshot.c:3153:61: error: variable 'delData' set but not used [-Werror,-Wunused-but-set-variable]
                g_autoslist(qemuSnapshotDeleteExternalData) delData = NULL;
                                                            ^

To work around the issue we can restructure the code which also has the
following semantic implications:
 - since qemuSnapshotDeleteExternalPrepare does validation we error out
   sooner than attempting to start the VM

 - we read the temporary variable at least in one code path

Fixes: 4a4d89a925
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
2023-01-09 14:13:25 +01:00
Peter Krempa
bb80344fd0 virNWFilterSnoopLeaseFileLoad: Don't typecast 'ipl.timeout'
Use a temporary variable to avoid memory alignment issues on ARM:

../src/nwfilter/nwfilter_dhcpsnoop.c: In function ‘virNWFilterSnoopLeaseFileLoad’:
../src/nwfilter/nwfilter_dhcpsnoop.c:1745:20: error: cast increases required alignment of target type [-Werror=cast-align]
 1745 |                    (unsigned long long *) &ipl.timeout,
      |

Fixes: 0d278aa089
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
2023-01-09 13:54:56 +01:00
Pavel Hrdina
8858a3cc35 NEWS: document support for external snapshot deletion
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
2023-01-09 13:33:20 +01:00
Pavel Hrdina
8702898569 api: document support for external snapshot deletion
Now that deletion of external snapshot is implemented document the
current virDomainSnapshotDelete supported state.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
2023-01-09 13:33:19 +01:00
Pavel Hrdina
85931fce74 qemu_snapshot: enable deletion of external snapshots
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
2023-01-09 13:33:18 +01:00
Pavel Hrdina
cadbf40d05 qemu_process: abort snapshot delete when daemon starts
If the daemon crashes or is restarted while the snapshot delete is in
progress we have to handle it gracefully to not leave any block jobs
active.

For now we will simply abort the snapshot delete operation so user can
start it again. We need to refuse deleting external snapshots if there
is already another active job as we would have to figure out which jobs
we can abort.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
2023-01-09 13:33:16 +01:00
Pavel Hrdina
f474e80ac3 qemu_domain: store snapshotDelete in qemuDomainJobPrivate
When daemon is restarted and libvirt tries to recover domain jobs we
need to know if the snapshot job was a snapshot delete in order to
safely abort running QEMU block jobs.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
2023-01-09 13:33:12 +01:00
Pavel Hrdina
565bcb5d79 qemu_snapshot: when deleting snapshot invalidate parent snapshot
When deleting external snapshots the operation may fail at any point
which could lead to situation that some disks finished the block commit
operation but for some disks it failed and the libvirt job ends.

In order to make sure that the qcow2 images are in consistent state
introduce new element "<snapshotDeleteInProgress/>" that will mark the
disk in snapshot metadata as invalid until the snapshot delete is
completed successfully.

This will prevent deleting snapshot with the invalid disk and in future
reverting to snapshot with the invalid disk.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
2023-01-09 13:33:07 +01:00
Pavel Hrdina
7190582fbc qemu_snapshot: update metadata when deleting snapshots
With external snapshots we need to modify the metadata bit more then
what is required for internal snapshots. Mainly the storage source
location changes with every external snapshot.

This means that if we delete non-leaf snapshot we need to update all
children snapshots and modify the disk sources for all affected disks.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
2023-01-09 13:33:06 +01:00
Pavel Hrdina
e27f081967 qemu_snapshot: implement deletion of external snapshot
When deleting snapshot we are starting block-commit job over all disks
that are part of the snapshot.

This operation may fail as it writes data changes to the backing qcow2
image so we need to wait for all the disks to finish the operation and
wait for correct signal from QEMU. If deleting active snapshot we will
get `ready` signal and for inactive snapshots we need to disable
autofinalize in order to get `pending` signal.

At this point if commit for any disk fails for some reason and we abort
the VM is still in consistent state and user can fix the reason why the
deletion failed.

After that we do `pivot` or `finalize` if it's active snapshot or not to
finish the block job. It still may fail but there is nothing else we can
do about it.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
2023-01-09 13:33:05 +01:00
Pavel Hrdina
4a4d89a925 qemu_snapshot: prepare data for external snapshot deletion
In order to save some CPU cycles we will collect all the necessary data
to delete external snapshot before we even start. They will be later
used by code that deletes the snapshots and updates metadata when
needed.

With external snapshots we need data that libvirt gets from running QEMU
process so if the VM is not running we need to start paused QEMU process
for the snapshot deletion and kill at afterwards.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
2023-01-09 13:33:04 +01:00
Pavel Hrdina
2038c1cd3a qemu_snapshot: convert snapshot delete to async domain job
Deleting external snapshots will require to run it as async domain job,
the same way as we do for snapshot creation.

For internal snapshots modify the job mask in order to forbid any other
job to be started.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
2023-01-09 13:33:02 +01:00
Pavel Hrdina
f5def5cd11 qemu_snapshot: error out when deleting internal snapshot on non-active disk
Deleting internal snapshot when the currently active disk image is
different than where the internal snapshot was taken doesn't work
correctly.

This applies to a running VM only as we are using QMP command and
talking to the QEMU process that is using different disk.

This works correctly when the VM is shut of as in this case we spawn
qemu-img process to delete the snapshot.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
2023-01-09 13:33:01 +01:00
Pavel Hrdina
4475c69787 qemu_snapshot: refactor validation of snapshot delete
Prepare the validation function for external snapshot delete support.

There is one exception when deleting `children-only` snapshots. If the
snapshot tree is like this example:

    snap1 (external)
     |
     +- snap2 (internal)
         |
         +- snap3 (internal)
             |
             +- snap4 (internal)

and user calls `snapshot-delete snap1 --children-only` the current
snapshot is external but all the children snapshots are internal only
and we are able to delete it.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
2023-01-09 13:32:59 +01:00
Pavel Hrdina
86883588c7 qemu_snapshot: introduce qemuSnapshotDeleteValidate function
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
2023-01-09 13:32:58 +01:00
Pavel Hrdina
691fd8f3e3 qemu_snapshot: introduce qemuSnapshotDiscardMetadata
Extract the code deleting external snapshot metadata to separate
function.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
2023-01-09 13:32:57 +01:00
Pavel Hrdina
deb35939ee qemu_snapshot: move snapshot metadata reparent code
Previously the reparent happened before the actual snapshot deletion.
This change moves the code closer to the rest of the code handling
snapshot metadata when deletion happens. This makes the metadate
deletion happen after the data files are deleted.

Following patch will extract it into separate function

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
2023-01-09 13:32:56 +01:00
Pavel Hrdina
9dd19a7a43 qemu_snapshot: move snapshot discard out of qemu_domain.c
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
2023-01-09 13:32:55 +01:00
Pavel Hrdina
f5bde47d6c qemu_snapshot: rework snapshot children deletion
This simplifies the code a bit by reusing existing parts that deletes
a single snapshot.

The drawback of this change is that we will now call the re-parent bits
to keep the metadata in sync for every child even though it will get
deleted as well.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
2023-01-09 13:32:53 +01:00
Pavel Hrdina
a3c8c7e37a qemu_snapshot: introduce qemuSnapshotDeleteChildren
Extract code that deletes children of specific snapshot to separate
function.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
2023-01-09 13:32:52 +01:00
Pavel Hrdina
7a6e5c5013 qemu_snapshot: introduce qemuSnapshotDeleteSingle
Extract code that deletes single snapshot to separate function.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
2023-01-09 13:32:51 +01:00
Pavel Hrdina
06c2382ab9 qemu_snapshot: refactor qemuSnapshotDelete
Move code around to make it clear what is called when deleting single
snapshot or children snapshots.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
2023-01-09 13:32:50 +01:00
Pavel Hrdina
a784d4076a storage_source: introduce virStorageSourceChainLookupBySource
Looks up disk storage source within storage source chain using storage
source object instead of path to make it work with all disk types.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
2023-01-09 13:32:49 +01:00
Pavel Hrdina
90d9bc9d74 qemu_blockjob: process QEMU_MONITOR_JOB_STATUS_PENDING signal
QEMU emits this signal when the job finished its work and is about to be
finalized. If the job is started with autofinalize disabled the job
waits for user input to finalize the job.

This will be used by snapshot delete code.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
2023-01-09 13:32:48 +01:00
Pavel Hrdina
2686738b6c qemu_block: change qemuBlockCommit to return job pointer
The created job will be needed by external snapshot delete code so
rework qemuBlockCommit to return that pointer.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
2023-01-09 13:32:47 +01:00
Pavel Hrdina
47cc6470f2 qemu_block: introduce qemuBlockFinalize
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
2023-01-09 13:32:46 +01:00
Pavel Hrdina
11e30faf75 qemu_block: allow configuring autofinalize for block commit
External snapshots will use this to synchronize qemu block jobs.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
2023-01-09 13:32:45 +01:00
Pavel Hrdina
b308dc4b77 qemu_monitor_json: allow configuring autofinalize for block commit
Deleting external snapshots will require configuring autofinalize to
synchronize the block jobs for disks withing single snapshot in order to
be able safely abort of one of the jobs fails.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
2023-01-09 13:32:44 +01:00
Pavel Hrdina
07b54c3d5a qemu_monitor: introduce qemuMonitorJobFinalize
Upcoming snapshot deletion code will require that multiple commit jobs
are finished in sync. To allow aborting then if one fails we will need
to use manual finalization of the jobs.

This commit implements the monitor code for `job-finalize`.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
2023-01-09 13:32:43 +01:00
Pavel Hrdina
9a0ce66503 qemu_block: add async domain job support to qemuBlockPivot
This will allow to use it while having async domain job active which we
will use when deleting external snapshots.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
2023-01-09 13:32:42 +01:00
Pavel Hrdina
ef1c609a16 qemu_block: add async domain job support to qemuBlockCommit
This will allow to use it while having async domain job active which we
will use when deleting external snapshots. At the same time we will need
to have the block job started as synchronous.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
2023-01-09 13:32:41 +01:00
Pavel Hrdina
f4751c3cae qemu_block: move qemuDomainBlockPivot out of qemu_driver
Move the code for finishing a job in the ready state to qemu_block.c.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
2023-01-09 13:32:39 +01:00
Pavel Hrdina
f5a77198bf qemu_block: extract block commit code to separate function
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
2023-01-09 13:32:38 +01:00
Pavel Hrdina
a1cbaee5c8 libvirt: introduce VIR_DOMAIN_JOB_OPERATION_SNAPSHOT_DELETE
This will be used by snapshot delete async domain job.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
2023-01-09 13:32:35 +01:00
Andrea Bolognani
e152f0718f qemu: Always check nodeset provided to numatune
Up until commit 629282d884, using mode=restrictive caused
virNumaSetupMemoryPolicy() to be called from qemuProcessHook(),
and that in turn resulted in virNumaNodesetIsAvailable() being
called and the nodeset being validated.

After that change, the only validation for the nodeset is the one
happening in qemuBuildMemoryBackendProps(), which is skipped when
using mode=restrictive.

Make sure virNumaNodesetIsAvailable() is called whenever a
nodeset has been provided by the user, regardless of the mode.

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

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2023-01-09 11:09:31 +01:00
Andrea Bolognani
6fabd21546 tests: Add cases for numatune with unavailable nodes
The one for mode=strict fails, as expected, while the one for
mode=restrictive currently doesn't even though it should. The
next commit will address the issue.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2023-01-09 11:09:21 +01:00
Jiang Jiacheng
ffd286ac6f vz: use g_autofree and remove unnecessary label
Signed-off-by: Jiang Jiacheng <jiangjiacheng@huawei.com>
Reviewed-by: Jonathon Jongsma <jjongsma@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
2023-01-09 04:38:52 +01:00
Jiang Jiacheng
e26c5d1212 vmware: use g_autofree and remove unnecessary label
Signed-off-by: Jiang Jiacheng <jiangjiacheng@huawei.com>
Reviewed-by: Jonathon Jongsma <jjongsma@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
2023-01-09 04:38:52 +01:00
Jiang Jiacheng
c49a7e359c util: use g_autofree and remove unnecessary label
Signed-off-by: Jiang Jiacheng <jiangjiacheng@huawei.com>
Reviewed-by: Jonathon Jongsma <jjongsma@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
2023-01-09 04:38:52 +01:00
Jiang Jiacheng
c68cbb4335 security: use g_autofree and remove unnecessary label
Signed-off-by: Jiang Jiacheng <jiangjiacheng@huawei.com>
Reviewed-by: Jonathon Jongsma <jjongsma@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
2023-01-09 04:38:52 +01:00
Jiang Jiacheng
2040011301 rpc: use g_autofree and remove unnecessary label
Signed-off-by: Jiang Jiacheng <jiangjiacheng@huawei.com>
Reviewed-by: Jonathon Jongsma <jjongsma@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
2023-01-09 04:38:52 +01:00
Jiang Jiacheng
ef36cc5058 remote: use g_autofree and remove unnecessary label
Signed-off-by: Jiang Jiacheng <jiangjiacheng@huawei.com>
Reviewed-by: Jonathon Jongsma <jjongsma@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
2023-01-09 04:38:52 +01:00
Jiang Jiacheng
075cfd842e locking: use g_autofree and remove unnecessary label
Signed-off-by: Jiang Jiacheng <jiangjiacheng@huawei.com>
Reviewed-by: Jonathon Jongsma <jjongsma@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
2023-01-09 04:38:52 +01:00
Jiang Jiacheng
a71744c7e5 interface: use g_autofree and remove unnecessary label
Signed-off-by: Jiang Jiacheng <jiangjiacheng@huawei.com>
Reviewed-by: Jonathon Jongsma <jjongsma@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
2023-01-09 04:38:52 +01:00
Jiang Jiacheng
a9027d447b conf: use g_autofree and remove unnecessary label
Signed-off-by: Jiang Jiacheng <jiangjiacheng@huawei.com>
Reviewed-by: Jonathon Jongsma <jjongsma@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
2023-01-09 04:38:52 +01:00
Jiri Denemark
7050dad5f9 qemu: Remember failed post-copy migration in job
When post-copy migration fails, the domain stays running on the
destination with a VIR_DOMAIN_RUNNING_POSTCOPY_FAILED reason. Both the
state and the reason can later be rewritten in case the domain gets
paused for other reasons (such as an I/O error). Thus we need a separate
place to remember the post-copy migration failed to be able to resume
the migration.

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

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2023-01-06 16:17:38 +01:00
Jiri Denemark
49a5754063 conf: Add job parameter to virDomainObjIsFailedPostcopy
Unused for now, but this will change soon.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2023-01-06 16:17:38 +01:00
Jiri Denemark
b92cba67c6 conf: Drop virDomainJobOperation parameter from virDomainObjIsPostcopy
The parameter was only used to select which states correspond to an
active or failed post-copy migration. But these states are either
applicable to both operations or the check would just paper over a code
bug in case of an impossible combination of state and operation. By
dropping the check we can make the code simpler and also reuse existing
virDomainObjIsFailedPostcopy function and only check for active
post-copy states.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2023-01-06 16:17:38 +01:00