]> git.ipfire.org Git - thirdparty/libvirt.git/log
thirdparty/libvirt.git
4 months agoqemu: Add support for mapped-ram on restore
Jim Fehlig [Mon, 22 Jul 2024 22:09:39 +0000 (16:09 -0600)] 
qemu: Add support for mapped-ram on restore

Add support for the mapped-ram migration capability on restore.

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
4 months agoqemu: Apply migration parameters in qemuMigrationDstRun
Jim Fehlig [Tue, 21 Jan 2025 23:39:20 +0000 (16:39 -0700)] 
qemu: Apply migration parameters in qemuMigrationDstRun

Similar to qemuMigrationSrcRun, apply migration parameters in
qemuMigrationDstRun. This allows callers to create customized
migration parameters, but delegates their application to the
function performing the migration.

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
4 months agoqemu: Move creation of qemuProcessIncomingDef struct
Jim Fehlig [Mon, 22 Jul 2024 23:12:21 +0000 (17:12 -0600)] 
qemu: Move creation of qemuProcessIncomingDef struct

qemuProcessStartWithMemoryState() is the only caller of qemuProcessStart()
that uses the qemuProcessIncomingDef struct. Move creation of the struct
to qemuProcessStartWithMemoryState().

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
4 months agoqemu: Add support for mapped-ram on save
Jim Fehlig [Tue, 14 Jan 2025 23:13:20 +0000 (16:13 -0700)] 
qemu: Add support for mapped-ram on save

Introduce support for QEMU's new mapped-ram stream format [1].
mapped-ram can be enabled by setting the 'save_image_format'
setting in qemu.conf to 'sparse'.

To use mapped-ram with QEMU:
- The 'mapped-ram' migration capability must be set to true
- The 'multifd' migration capability must be set to true and
  the 'multifd-channels' migration parameter must set to 1
- QEMU must be provided an fdset containing the migration fd
- The 'migrate' qmp command is invoked with a URI referencing the
  fdset and an offset where to start reading or writing the data
  stream, e.g.

  {"execute":"migrate",
   "arguments":{"detach":true,"resume":false,
                "uri":"file:/dev/fdset/0,offset=0x11921"}}

The mapped-ram stream, in conjunction with direct IO and multifd
support provided by subsequent patches, can significantly improve
the time required to save VM memory state. The following tables
compare mapped-ram with the existing, sequential save stream. In
all cases, the save and restore operations are to/from a block
device comprised of two NVMe disks in RAID0 configuration with
xfs (~8600MiB/s). The values in the 'save time' and 'restore time'
columns were scraped from the 'real' time reported by time(1). The
'Size' and 'Blocks' columns were provided by the corresponding
outputs of stat(1).

VM: 32G RAM, 1 vcpu, idle (shortly after boot)

                       | save    | restore |
       | time    | time    | Size         | Blocks
-----------------------+---------+---------+--------------+--------
legacy                 | 6.193s  | 4.399s  | 985744812    | 1925288
-----------------------+---------+---------+--------------+--------
mapped-ram             | 5.109s  | 1.176s  | 34368554354  | 1774472
-----------------------+---------+---------+--------------+--------
legacy + direct IO     | 5.725s  | 4.512s  | 985765251    | 1925328
-----------------------+---------+---------+--------------+--------
mapped-ram + direct IO | 4.627s  | 1.490s  | 34368554354  | 1774304
-----------------------+---------+---------+--------------+--------
mapped-ram + direct IO |         |         |              |
 + multifd-channels=8  | 4.421s  | 0.845s  | 34368554318  | 1774312
-------------------------------------------------------------------

VM: 32G RAM, 30G dirty, 1 vcpu in tight loop dirtying memory

                       | save    | restore |
       | time    | time    | Size         | Blocks
-----------------------+---------+---------+--------------+---------
legacy                 | 25.800s | 14.332s | 33154309983  | 64754512
-----------------------+---------+---------+--------------+---------
mapped-ram             | 18.742s | 15.027s | 34368559228  | 64617160
-----------------------+---------+---------+--------------+---------
legacy + direct IO     | 13.115s | 18.050s | 33154310496  | 64754520
-----------------------+---------+---------+--------------+---------
mapped-ram + direct IO | 13.623s | 15.959s | 34368557392  | 64662040
-----------------------+-------- +---------+--------------+---------
mapped-ram + direct IO |         |         |              |
 + multifd-channels=8  | 6.994s  | 6.470s  | 34368554980  | 64665776
--------------------------------------------------------------------

As can be seen from the tables, one caveat of mapped-ram is the logical
file size of a saved image is basically equivalent to the VM memory size.
Note however that mapped-ram typically uses fewer blocks on disk, hence
the name 'sparse' for 'save_image_format'.

Also note the mapped-ram stream is incompatible with the existing stream
format, hence mapped-ram cannot be used to restore an image saved with
the existing format and vice versa.

[1] https://gitlab.com/qemu-project/qemu/-/blob/master/docs/devel/migration/mapped-ram.rst?ref_type=heads

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
4 months agoqemu: Add helper function for creating save image fd
Jim Fehlig [Wed, 17 Jul 2024 23:04:43 +0000 (17:04 -0600)] 
qemu: Add helper function for creating save image fd

Move the code in qemuSaveImageCreate that opens, labels, and wraps the
save image fd to a helper function, providing more flexibility for
upcoming mapped-ram support.

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
4 months agoqemu_saveimage: add "sparse" to supported save image formats
Jim Fehlig [Mon, 13 Jan 2025 22:57:50 +0000 (15:57 -0700)] 
qemu_saveimage: add "sparse" to supported save image formats

Extend the list of formats to include "sparse", which uses QEMU's mapped-ram
stream format [1] to write guest memory blocks at fixed offsets in the save
image file.

[1] https://gitlab.com/qemu-project/qemu/-/blob/master/docs/devel/migration/mapped-ram.rst?ref_type=heads

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
4 months agoqemu: Add function to get migration params for save
Jim Fehlig [Wed, 29 May 2024 22:31:05 +0000 (16:31 -0600)] 
qemu: Add function to get migration params for save

Introduce qemuMigrationParamsForSave() to create a
qemuMigrationParams object initialized with appropriate migration
capabilities and parameters for a save operation.

Note that mapped-ram capability also requires the multifd capability.
For now, the number of multifd channels is set to 1. Future work
to support parallel save/restore can set the number of channels to
a user-specified value.

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
4 months agoqemu: Add mapped-ram migration capability
Jim Fehlig [Thu, 4 Apr 2024 22:55:10 +0000 (16:55 -0600)] 
qemu: Add mapped-ram migration capability

Add the mapped-ram migration capability introduced in QEMU 9.0.

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
4 months agoqemu: Add function to get bool value from migration params
Jim Fehlig [Fri, 26 Jul 2024 17:19:31 +0000 (11:19 -0600)] 
qemu: Add function to get bool value from migration params

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
4 months agoqemu: Add function to check capability in migration params
Jim Fehlig [Fri, 19 Jul 2024 22:31:19 +0000 (16:31 -0600)] 
qemu: Add function to check capability in migration params

Add new function qemuMigrationParamsCapEnabled() to check if a
capability is set in the caller-provided migration parameters.

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
4 months agoqemu: Add function to get FDPass object from monitor
Jim Fehlig [Thu, 6 Feb 2025 22:20:27 +0000 (15:20 -0700)] 
qemu: Add function to get FDPass object from monitor

Add new function qemuFDPassNewFromMonitor to get an fdset previously
passed to qemu, based on the 'prefix' provided when the qemuFDPass
object was initially created.

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
4 months agovirsh: Add option "throttle-groups" to "attach_disk"
Chun Feng Wu [Wed, 19 Feb 2025 16:57:22 +0000 (22:27 +0530)] 
virsh: Add option "throttle-groups" to "attach_disk"

Update "attach_disk" to support new option: throttle-groups to
form filter chain in QEMU for specific disk

Signed-off-by: Chun Feng Wu <danielwuwy@163.com>
* apply suggested coding style changes.

Signed-off-by: Harikumar Rajkumar <harirajkumar230@gmail.com>
* Fixed alignment of child elements in the XML
* Fixed placement of the throttlegroups element
* Removed completer wrapper

Reviewed-by: Peter Krempa <pkrempa@redhat.com>
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
4 months agovirsh: Add support for throttle group operations
Chun Feng Wu [Wed, 19 Feb 2025 16:57:21 +0000 (22:27 +0530)] 
virsh: Add support for throttle group operations

Implement new throttle cmds

* Add new virsh cmds: domthrottlegroupset, domthrottlegrouplist,
  domthrottlegroupinfo, domthrottlegroupdel
* Add doc for new cmds at docs/manpages/virsh.rst
* Add cmd helper "virshDomainThrottleGroupCompleter", which is used by
  domthrottlegroupset, domthrottlegroupinfo, domthrottlegroupdel

Signed-off-by: Chun Feng Wu <danielwuwy@163.com>
* Update of code documentation comments.
* Reimplement Get throttle group from XML.

Signed-off-by: Harikumar Rajkumar <harirajkumar230@gmail.com>a
* Fixed memleaks
* Rewrote getter to avoid extra copies
* Simplified name extractor

Reviewed-by: Peter Krempa <pkrempa@redhat.com>
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
4 months agovirsh: Refactor iotune options for re-use
Chun Feng Wu [Wed, 19 Feb 2025 16:57:20 +0000 (22:27 +0530)] 
virsh: Refactor iotune options for re-use

Define macro for iotune options, this macro is used by opts_blkdeviotune and
later throttle group opts

Signed-off-by: Chun Feng Wu <danielwuwy@163.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
4 months agoqemustatusxml2xmldata: Add 'throttlefilter' tests
Harikumar Rajkumar [Wed, 19 Feb 2025 16:57:18 +0000 (22:27 +0530)] 
qemustatusxml2xmldata: Add 'throttlefilter' tests

* Add tests for throttlefilter nodename parse and format for statusxml
(disk/privateData/nodenames/nodename with type='throttle-filter')
* Add iotune limited disk tests to make sure iotune refactory works

Signed-off-by: Chun Feng Wu <danielwuwy@163.com>
* Isolate status xml test

Signed-off-by: Harikumar Rajkumar <harirajkumar230@gmail.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
4 months agoqemuxmlconftest: Add 'throttlefilter' tests
Chun Feng Wu [Wed, 19 Feb 2025 16:57:17 +0000 (22:27 +0530)] 
qemuxmlconftest: Add 'throttlefilter' tests

* Add tests for throttlegroup domain xml processing, including
groups referenced and not referenced by filters
* Add tests for throttlefilter domain xml processing, including
throttle group referenced by different disks
* Add negative test case to report error when iotune is configured
together with throttle filters

Signed-off-by: Chun Feng Wu <danielwuwy@163.com>
* Isolate domain xml test

Signed-off-by: Harikumar Rajkumar <harirajkumar230@gmail.com>
* Added test case with copy on read

Reviewed-by-by: Peter Krempa <pkrempa@redhat.com>
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
4 months agoconfig: validate: Verify iotune, throttle group and filter
Chun Feng Wu [Wed, 19 Feb 2025 16:57:16 +0000 (22:27 +0530)] 
config: validate: Verify iotune, throttle group and filter

Refactor iotune verification, and verify some rules

* Disk iotune validation can be reused for throttle group validation,
  refactor it into common method "virDomainDiskIoTuneValidate"
* Add "virDomainDefValidateThrottleGroups" to validate throttle groups,
  which in turn calls "virDomainDiskIoTuneValidate"
* Make sure referenced throttle group exists
* Use "iotune" and "throttlefilters" exclusively for specific disk
* Throttle filters cannot be used together with CDROM

Signed-off-by: Chun Feng Wu <danielwuwy@163.com>
* Update of code documentation comments.

Signed-off-by: Harikumar Rajkumar <harirajkumar230@gmail.com>
* Moved validation code from parser to validator
* Removed dead checks after validation

Reviewed-by: Peter Krempa <pkrempa@redhat.com>
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
4 months agoqemu: block: Support block disk along with throttle filters
Chun Feng Wu [Wed, 19 Feb 2025 16:57:15 +0000 (22:27 +0530)] 
qemu: block: Support block disk along with throttle filters

For hot attaching/detaching
* Leverage qemuBlockThrottleFiltersData to prepare attaching/detaching
  throttle filter data for qemuMonitorBlockdevAdd and qemuMonitorBlockdevDel
* For hot attaching, within qemuDomainAttachDiskGeneric,prepare throttle
  filters json data, and create corresponding blockdev for QMP request
  ("blockdev-add" with "driver":"throttle")
* Each filter has a nodename, and those filters are chained up,
  create them in sequence, and delete them reversely
* Delete filters by "qemuBlockThrottleFiltersDetach"("blockdev-del")
  when detaching device

For throttle group commandline
* Add qemuBuildThrottleGroupCommandLine in qemuBuildCommandLine to add
  "object" of throttle-group
* Verify throttle group definition when lauching vm
* Check QEMU_CAPS_OBJECT_JSON before "qemuBuildObjectCommandlineFromJSON",
  which is to build "-object" option

For throttle filter commandline
* Add qemuBuildDiskThrottleFiltersCommandLine in qemuBuildDiskCommandLine
  to add "blockdev"

Signed-off-by: Chun Feng Wu <danielwuwy@163.com>
* Apply suggested coding style changes.
* Update of code documentation comments.

Signed-off-by: Harikumar Rajkumar <harirajkumar230@gmail.com>
* Removed QEMU_CAPS_OBJECT_JSON_CHECK

Reviewed-by: Peter Krempa <pkrempa@redhat.com>
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
4 months agoqemu: helper: throttle filter nodename and preparation processing
Chun Feng Wu [Wed, 19 Feb 2025 16:57:14 +0000 (22:27 +0530)] 
qemu: helper: throttle filter nodename and preparation processing

It contains throttle filter nodename processing(new nodename,
topnodename, parse and format nodename), throttle filter
attaching/detaching preparation and implementation.

* Updated "qemuDomainDiskGetTopNodename", so if throttlefilter is used
  together with copyOnRead, top node is throttle filter node, e.g.
  device -> throttle -> copyOnRead Layer-> image chain
* In qemuBuildThrottleFiltersAttachPrepareBlockdev, if copy_on_read
  is on, build throttle nodename chain on top of copy_on_read nodename
* In status xml, throttle filter nodename(virDomainDiskDef.nodename) is
  saved at disk/privateData/nodenames/nodename(type='throttle-filter'),
  corresponding parse/format sits in qemuDomainDiskPrivateParse and
  qemuDomainDiskPrivateFormat
* If filter nodename hasn't been set by qemuDomainDiskPrivateParse,
  in qemuDomainPrepareThrottleFilterBlockdev, filter nodename index
  can be generated by reusing qemuDomainStorageIDNew and current
  global sequence number is persistented in virDomainObj-
  >privateData(qemuDomainObjPrivate)->nodenameindex.
  qemuDomainPrepareThrottleFilterBlockdev is called by
  qemuDomainPrepareDiskSourceBlockdev, which in turn used by both
  hotplug and qemuProcessStart to prepare throttle filter node name
* Define method qemuBlockThrottleFilterGetProps, which is used by
  both hotplug and command to build throttle object for QEMU
* Define methods for throttle filter attach/detach/rollback

Signed-off-by: Chun Feng Wu <danielwuwy@163.com>
* Apply suggested coding style changes.
* Update of code documentation comments.

Signed-off-by: Harikumar Rajkumar <harirajkumar230@gmail.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
4 months agoqemu: Implement qemu driver for throttle API
Chun Feng Wu [Wed, 19 Feb 2025 16:57:13 +0000 (22:27 +0530)] 
qemu: Implement qemu driver for throttle API

ThrottleGroup lifecycle implementation, note, in QOM, throttlegroup name is prefixed with
"throttle-" to clearly separate throttle group objects into their own namespace.
* "qemuDomainSetThrottleGroup", this method is to add("object-add") or update("qom-set")
  throttlegroup in QOM and update corresponding objects in DOM
* "qemuDomainGetThrottleGroup", this method queries throttlegroup info by groupname
* "qemuDomainDelThrottleGroup", this method checks if group is referenced by any throttle
  in disks and delete it if it's not used anymore
* Check flag "QEMU_CAPS_OBJECT_JSON" during qemuDomainSetThrottleGroup when vm is active,
  throttle group feature requries such flag
* "objectAddNoWrap"("props") check is done by reusing qemuMonitorAddObject in
  qemuDomainSetThrottleGroup

Signed-off-by: Chun Feng Wu <danielwuwy@163.com>
* Apply suggested coding style changes.
* cleanup qemu Get ThrottleGroup.
* Update the version to 11.1.0.

Signed-off-by: Harikumar Rajkumar <harirajkumar230@gmail.com>
* Removed QEMU_CAPS_OBJECT_JSON check as the flag no longer exists.
* Update the version to 11.2.0.

Reviewed-by: Peter Krempa <pkrempa@redhat.com>
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
4 months agoqemu: Refactor qemuDomainSetBlockIoTune to extract common methods
Chun Feng Wu [Wed, 19 Feb 2025 16:57:12 +0000 (22:27 +0530)] 
qemu: Refactor qemuDomainSetBlockIoTune to extract common methods

extract common methods from "qemuDomainSetBlockIoTune" to be reused
by throttle handling later, common methods include:
* "qemuDomainValidateBlockIoTune", which is to validate that PARAMS
  contains only recognized parameter names with correct types
* "qemuDomainSetBlockIoTuneFields", which is to load parameters into
  internal object virDomainBlockIoTuneInfo
* "qemuDomainCheckBlockIoTuneMutualExclusion", which is to check rules
  like "total and read/write of bytes_sec cannot be set at the same time"
* "qemuDomainCheckBlockIoTuneMax", which is to check "max" rules within iotune

Signed-off-by: Chun Feng Wu <danielwuwy@163.com>
* Apply suggested coding style changes.

Signed-off-by: Harikumar Rajkumar <harirajkumar230@gmail.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
4 months agoremote: New APIs for ThrottleGroup lifecycle management
Chun Feng Wu [Wed, 19 Feb 2025 16:57:11 +0000 (22:27 +0530)] 
remote: New APIs for ThrottleGroup lifecycle management

Defined new public APIs:
* virDomainSetThrottleGroup to add or update throttlegroup within specific domain,
  it will be referenced by throttlefilter later in disk to do limits
* virDomainGetThrottleGroup to get throttlegroup info, old-style is discarded
  (APIs to query first for the number of parameters and then give it a
  reasonably-sized pointer), instead, the new approach is adopted that
  API returns allocated array of fields and number of fileds that are in it.
* virDomainDelThrottleGroup to delete throttlegroup, it fails if this throttlegroup
  is still referenced by some throttlefilter

Signed-off-by: Chun Feng Wu <danielwuwy@163.com>
* Reimplement getter API to fetch data from XML.
* Apply suggested coding style changes.
* Update of code documentation comments.
* Update the version to 11.2.0.

Signed-off-by: Harikumar Rajkumar <harirajkumar230@gmail.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
4 months agotests: Test qemuMonitorJSONGetThrottleGroup and qemuMonitorJSONUpdateThrottleGroup
Chun Feng Wu [Wed, 19 Feb 2025 16:57:10 +0000 (22:27 +0530)] 
tests: Test qemuMonitorJSONGetThrottleGroup and qemuMonitorJSONUpdateThrottleGroup

Within "testQemuMonitorJSONqemuMonitorJSONUpdateThrottleGroup"
* Test qemuMonitorJSONGetThrottleGroup
* Test qemuMonitorJSONUpdateThrottleGroup, which updates limits through "qom-set"

Signed-off-by: Chun Feng Wu <danielwuwy@163.com>
* fix test

Signed-off-by: Harikumar Rajkumar <harirajkumar230@gmail.com>
* Deleted getter-related code.

Reviewed-by: Peter Krempa <pkrempa@redhat.com>
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
4 months agoqemu: monitor: Add support for ThrottleGroup operations
Chun Feng Wu [Wed, 19 Feb 2025 16:57:09 +0000 (22:27 +0530)] 
qemu: monitor: Add support for ThrottleGroup operations

This change contains QMP requests for ThrottleGroup

* ThrottleGroup is updated through "qemuMonitorJSONUpdateThrottleGroup"
* ThrottleGroup is retrieved through "qemuMonitorJSONGetThrottleGroup"
* ThrottleGroup is deleted by reusing "qemuMonitorDelObject"
* ThrottleGroup is added by reusing "qemuMonitorAddObject"
* "qemuMonitorMakeThrottleGroupLimits" will be used by building qemu cmd as well

Signed-off-by: Chun Feng Wu <danielwuwy@163.com>
* change throttle group config conversions P to U allow zero.
* Apply suggested coding style changes.

Signed-off-by: Harikumar Rajkumar <harirajkumar230@gmail.com>
* Deleted all getter code.

Reviewed-by: Peter Krempa <pkrempa@redhat.com>
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
4 months agoconfig: Introduce ThrottleFilter and corresponding XML parsing
Chun Feng Wu [Wed, 19 Feb 2025 16:57:08 +0000 (22:27 +0530)] 
config: Introduce ThrottleFilter and corresponding XML parsing

Introduce throttle filter along with corresponding operations.

* Define new struct 'virDomainThrottleFilterDef' and corresponding destructor
* Update _virDomainDiskDef to include virDomainThrottleFilterDef
* Support throttle filter "Parse" and "Format" for operations between DOM XML
  and structs. Note, this commit just contains parse/format of group name for
  throttle filter in domain_conf.c, there is other commit to handle throttle
  filter nodename parse/format between throttlefilter and diskPrivateData for
  statusxml in qemu_domain.c when processing qemuDomainDiskPrivate and
  qemuDomainDiskPrivate

Signed-off-by: Chun Feng Wu <danielwuwy@163.com>
* Error handling for null throttle group.
* Update of code documentation comments.
* Apply suggested coding style changes.

Signed-off-by: Harikumar Rajkumar <harirajkumar230@gmail.com>
* Fixed naming of virDomainThrottleFilterDefClear to ...Free
* Fixed memleak of the throttle filter definitions

Reviewed-by: Peter Krempa <pkrempa@redhat.com>
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
4 months agoconfig: Introduce ThrottleGroup and corresponding XML parsing
Chun Feng Wu [Wed, 19 Feb 2025 16:57:07 +0000 (22:27 +0530)] 
config: Introduce ThrottleGroup and corresponding XML parsing

Introduce throttlegroup into domain and provide corresponding methods

* Define new struct 'virDomainThrottleGroupDef' and corresponding destructor
* Add operations(Add, Update, Del, ByName, Copy, Free) for 'virDomainThrottleGroupDef'
* Update _virDomainDef to include virDomainThrottleGroupDef
* Support new resource "Parse" and "Format" for operations between struct and DOM XML
* Make sure "group_name" is defined in xml

Signed-off-by: Chun Feng Wu <danielwuwy@163.com>
* Validation check for zero throttle groups.
* Update of code documentation comments.

Signed-off-by: Harikumar Rajkumar <harirajkumar230@gmail.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
4 months agoschema: Add new domain elements to support multiple throttle filters
Chun Feng Wu [Wed, 19 Feb 2025 16:57:06 +0000 (22:27 +0530)] 
schema: Add new domain elements to support multiple throttle filters

Introduce schema for defining '<throttlefilters>' element which
references throttling groups to form filter chain in qemu for specific
disk

* Add new elements '<throttlefilters>'
* <ThrottleFilters> can include multiple throttlegroup references to
  form filter chain in qemu
* Chained throttle filters feature in qemu is described at
  https://gitlab.com/qemu-project/qemu/blob/master/docs/throttle.txt

Signed-off-by: Chun Feng Wu <danielwuwy@163.com>
Signed-off-by: Harikumar Rajkumar <harirajkumar230@gmail.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
4 months agoschema: Add new domain elements to support multiple throttle groups
Chun Feng Wu [Wed, 19 Feb 2025 16:57:05 +0000 (22:27 +0530)] 
schema: Add new domain elements to support multiple throttle groups

Introduce schema for defining '<throttlegroups>' element which
configures throttling groups which can be configured for multiple
disks.

* Refactor "diskIoTune" to extract common schema "iotune"
* Add new elements '<throttlegroups>'
* <ThrottleGroups> contains <ThrottleGroup> defintion, which references
  "iotune"

Signed-off-by: Chun Feng Wu <danielwuwy@163.com>
Signed-off-by: Harikumar Rajkumar <harirajkumar230@gmail.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
4 months agovirsh: Introduce new hypervisor-cpu-models command
David Judkovics [Thu, 20 Mar 2025 05:28:24 +0000 (01:28 -0400)] 
virsh: Introduce new hypervisor-cpu-models command

Add new virsh command 'hypervisor-cpu-models'.  Command pulls from the
existing domcapabilities XML and uses xpath to parse CPU model strings.
By default, only models reported as usable by the hypervisor on the
host system are printed.  User may specify "--all" to also print
models which are not supported on the host.

Signed-off-by: David Judkovics <djudkovi@linux.ibm.com>
Signed-off-by: Boris Fiuczynski <fiuczy@linux.ibm.com>
Signed-off-by: Collin Walling <walling@linux.ibm.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
4 months agohypervisor: emit systemd status & log messages while saving
Daniel P. Berrangé [Tue, 7 Jan 2025 15:25:33 +0000 (15:25 +0000)] 
hypervisor: emit systemd status & log messages while saving

Since processing running VMs on OS shutdown can take a while, it is
beneficial to send systemd status messages about the progress.

The systemd status is a point-in-time message, with no ability to
look at the history of received messages. So in the systemd status
we include the progress information. For the same reason there is
no benefit in sending failure messages, as they'll disappear as soon
as a status is sent for the subsequent VM to be processed.

The libvirt log statements can be viewed as a complete log record
so don't need progress info, but do include warnings about failures
(present from earlier commits).

Reviewed-by: Peter Krempa <pkrempa@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
4 months agorpc: don't let systemd shutdown daemon while saving VMs
Daniel P. Berrangé [Tue, 7 Jan 2025 15:22:14 +0000 (15:22 +0000)] 
rpc: don't let systemd shutdown daemon while saving VMs

The service unit "TimeoutStopSec" setting controls how long systemd
waits for a service to stop before aggressively killing it, defaulting
to 30 seconds if not set.

When we're processing shutdown of VMs in response to OS shutdown, we
very likely need more than 30 seconds to complete this job, and can
not stop the daemon during this time.

To avoid being prematurely killed, setup a timer that repeatedly
extends the "TimeoutStopSec" value while stop of running VMs is
arranged.

This does mean if libvirt hangs while stoppping VMs, systemd won't
get to kill the libvirt daemon, but this is considered less harmful
that forcefully killing running VMs.

Reviewed-by: Peter Krempa <pkrempa@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
4 months agoadmin: add 'daemon-shutdown' command
Daniel P. Berrangé [Tue, 7 Jan 2025 13:25:49 +0000 (13:25 +0000)] 
admin: add 'daemon-shutdown' command

The daemons are wired up to shutdown in responsible to UNIX process
signals, as well as in response to login1 dbus signals, or loss of
desktop session. The latter two options can optionally preserve state
(ie running VMs).

In non-systemd environments, as well as for testing, it would be useful
to have a way to trigger shutdown with state preservation more directly.

Thus a new admin protocol API is introduced

  virAdmConnectDaemonShutdown

which will trigger a daemon shutdown, and preserve running VMs if the
VIR_DAEMON_SHUTDOWN_PRESERVE flag is set.

It has a corresponding 'virt-admin daemon-shutdown [--preserve]' command
binding.

Reviewed-by: Peter Krempa <pkrempa@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
4 months agorpc: fix shutdown sequence when preserving state
Daniel P. Berrangé [Tue, 7 Jan 2025 11:05:51 +0000 (11:05 +0000)] 
rpc: fix shutdown sequence when preserving state

The preserving of state (ie running VMs) requires a fully functional
daemon and hypervisor driver. If any part has started shutting down
then saving state may fail, or worse, hang.

The current shutdown sequence does not guarantee safe ordering, as
we synchronize with the state saving thread only after the hypervisor
driver has had its 'shutdownPrepare' callback invoked. In the case of
QEMU this means that worker threads processing monitor events may well
have been stopped.

This implements a full state machine that has a well defined ordering
that an earlier commit documented as the desired semantics.

With this change, nothing will start shutting down if the state saving
thread is still running.

Reviewed-by: Peter Krempa <pkrempa@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
4 months agorpc: don't unconditionally quit after preserving state
Daniel P. Berrangé [Tue, 7 Jan 2025 10:27:21 +0000 (10:27 +0000)] 
rpc: don't unconditionally quit after preserving state

The call to preserve state (ie running VMs) is triggered in response to
the desktop session dbus terminating (session daemon), or logind sending
a "PrepareForShutdown" signal. In the case of the latter, daemons
should only save their state, not actually exit yet. Other things on the
system may still expect the daemon to be running at this stage.

Reviewed-by: Peter Krempa <pkrempa@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
4 months agorpc: move state stop into virNetDaemon class
Daniel P. Berrangé [Tue, 7 Jan 2025 10:27:01 +0000 (10:27 +0000)] 
rpc: move state stop into virNetDaemon class

Currently the remote daemon code is responsible for calling virStateStop
in a background thread. The virNetDaemon code wants to synchronize with
this during shutdown, however, so the virThreadPtr must be passed over.

Even the limited synchronization done currently, however, is flawed and
to fix this requires the virNetDaemon code to be responsible for calling
virStateStop in a thread more directly.

Thus the logic is moved over into virStateStop via a further callback
to be registered by the remote daemon.

Reviewed-by: Peter Krempa <pkrempa@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
4 months agorpc: rename virNetDaemonSetShutdownCallbacks
Daniel P. Berrangé [Tue, 11 Mar 2025 17:44:44 +0000 (17:44 +0000)] 
rpc: rename virNetDaemonSetShutdownCallbacks

The next patch will be introducing a new callback, so rename the method
to virNetDaemonSetLifecycleCallbacks to reflect the more general usage.

Reviewed-by: Peter Krempa <pkrempa@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
4 months agosrc: clarify semantics of the various virStateNNN methods
Daniel P. Berrangé [Tue, 11 Mar 2025 17:24:34 +0000 (17:24 +0000)] 
src: clarify semantics of the various virStateNNN methods

It is not documented what the various virStateNNN methods are each
responsible for doing and the names give little guidance either.
Provide some useful documentation comments to explain the intended
usage of each.

Reviewed-by: Peter Krempa <pkrempa@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
4 months agoqemu: add config to control if auto-shutdown VMs are restored
Daniel P. Berrangé [Fri, 20 Dec 2024 12:55:49 +0000 (12:55 +0000)] 
qemu: add config to control if auto-shutdown VMs are restored

If shutting down running VMs at host shutdown, it can be useful to
automatically start them again on next boot. This adds a config
parameter 'auto_shutdown_restore', which defaults to enabled, which
leverages the autostart once feature.

Reviewed-by: Peter Krempa <pkrempa@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
4 months agoqemu: wire up support for once only autostart
Daniel P. Berrangé [Fri, 20 Dec 2024 12:43:28 +0000 (12:43 +0000)] 
qemu: wire up support for once only autostart

Reviewed-by: Peter Krempa <pkrempa@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
4 months agohypervisor: wire up support for auto restore of running domains
Daniel P. Berrangé [Fri, 20 Dec 2024 11:38:01 +0000 (11:38 +0000)] 
hypervisor: wire up support for auto restore of running domains

When performing auto-shutdown of running domains, there is now the
option to mark them as "autostart once",  so that their state is
restored on next boot. This applies on top of the traditional
autostart flag.

Reviewed-by: Peter Krempa <pkrempa@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
4 months agoconf: implement support for autostart once feature
Daniel P. Berrangé [Fri, 20 Dec 2024 11:26:55 +0000 (11:26 +0000)] 
conf: implement support for autostart once feature

This is maintained in the same way as the autostart flag, using a
symlink. The difference is that instead of '.xml', the symlink
suffix is '.xml.once'.

Reviewed-by: Peter Krempa <pkrempa@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
4 months agosrc: add new APIs for marking a domain to autostart once
Daniel P. Berrangé [Fri, 20 Dec 2024 10:55:30 +0000 (10:55 +0000)] 
src: add new APIs for marking a domain to autostart once

When a domain is marked for autostart, it will be started on every
subsequent host OS boot. There may be times when it is desirable to
mark a domain to be autostarted, on the next boot only.

Thus we add virDomainSetAutostartOnce / virDomainGetAutostartOnce.

An alternative would have been to overload the existing
virDomainSetAutostart method, to accept values '1' or '2' for
the autostart flag. This was not done because it is expected
that language bindings will have mapped the current autostart
flag to a boolean, and thus turning it into an enum would create
a compatibility problem.

A further alternative would have been to create a new method
virDomainSetAutostartFlags, with a VIR_DOMAIN_AUTOSTART_ONCE
flag defined. This was not done because it is felt desirable
to clearly separate the two flags. Setting the "once" flag
should not interfere with existing autostart setting, whether
it is enabled or disabled currently.

The 'virsh autostart' command, however, is still overloaded
by just adding a --once flag, while current state is added
to 'virsh dominfo'.

No ability to filter by 'autostart once' status is added to
the domain list APIs. The most common use of autostart once
will be to automatically set it on host shutdown, and it be
cleared on host startup. Thus there would rarely be scenarios
in which a running app will need to filter on this new flag.

Reviewed-by: Peter Krempa <pkrempa@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
4 months agoqemu: add config parameter to control auto-save bypass cache
Daniel P. Berrangé [Thu, 19 Dec 2024 19:21:31 +0000 (19:21 +0000)] 
qemu: add config parameter to control auto-save bypass cache

When doing managed save of VMs, triggered by OS shutdown, it may
be desirable to control cache usage.

Reviewed-by: Peter Krempa <pkrempa@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
4 months agohypervisor: support bypassing cache for managed save
Daniel P. Berrangé [Thu, 19 Dec 2024 19:18:04 +0000 (19:18 +0000)] 
hypervisor: support bypassing cache for managed save

Bypassing cache can make save performance more predictable and avoids
trashing the OS cache with data that will not be read again.

Reviewed-by: Peter Krempa <pkrempa@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
4 months agoqemu: configurable delay for shutdown before poweroff
Daniel P. Berrangé [Thu, 19 Dec 2024 19:13:04 +0000 (19:13 +0000)] 
qemu: configurable delay for shutdown before poweroff

Allow users to control how many seconds libvirt waits for QEMU
shutdown before force powering off a guest.

Reviewed-by: Peter Krempa <pkrempa@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
4 months agoqemu: improve shutdown defaults for session daemon
Daniel P. Berrangé [Fri, 20 Dec 2024 17:32:49 +0000 (17:32 +0000)] 
qemu: improve shutdown defaults for session daemon

Currently the session daemon will try a managed save on all VMs,
leaving them running if that fails.

This limits the managed save just to persistent VMs, as there will
usually not be any way to restore transient VMs later.

It also enables graceful shutdown and then forced poweroff, should
save fail for some reason.

These new defaults can be overridden in the config file if needed.

Reviewed-by: Peter Krempa <pkrempa@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
4 months agoqemu: support automatic VM managed save in system daemon
Daniel P. Berrangé [Tue, 17 Dec 2024 17:45:05 +0000 (17:45 +0000)] 
qemu: support automatic VM managed save in system daemon

Currently automatic VM managed save is only performed in session
daemons, on desktop session close, or host OS shutdown request.

With this change it is possible to control shutdown behaviour for
all daemons. A recommended setup might be:

  auto_shutdown_try_save = "persistent"
  auto_shutdown_try_shutdown = "all"
  auto_shutdown_poweroff = "all"

Each setting accepts 'none', 'persistent', 'transient', and 'all'
to control what types of guest it applies to.

For historical compatibility, for the system daemon, the settings
currently default to:

  auto_shutdown_try_save = "none"
  auto_shutdown_try_shutdown = "none"
  auto_shutdown_poweroff = "none"

while for the session daemon they currently default to

  auto_shutdown_try_save = "persistent"
  auto_shutdown_try_shutdown = "none"
  auto_shutdown_poweroff = "none"

The system daemon settings should NOT be enabled if the traditional
libvirt-guests.service is already enabled.

Reviewed-by: Peter Krempa <pkrempa@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
4 months agohypervisor: custom shutdown actions for transient vs persistent VMs
Daniel P. Berrangé [Fri, 20 Dec 2024 13:56:19 +0000 (13:56 +0000)] 
hypervisor: custom shutdown actions for transient vs persistent VMs

It may be desirable to treat transient VMs differently from persistent
VMs. For example, while performing managed save on persistent VMs makes
sense, the same not usually true of transient VMs, since by their
nature they will have no config to restore from.

This also lets us fix a long standing problem with incorrectly
attempting to perform managed save on transient VMs.

Reviewed-by: Peter Krempa <pkrempa@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
4 months agohypervisor: expand available shutdown actions
Daniel P. Berrangé [Thu, 19 Dec 2024 18:57:47 +0000 (18:57 +0000)] 
hypervisor: expand available shutdown actions

The auto shutdown code can currently only perform managed save,
which may fail in some cases, for example when PCI devices are
assigned. On failure, shutdown inhibitors remain in place which
may be undesirable.

This expands the logic to try a sequence of operations

 * Managed save
 * Graceful shutdown
 * Forced poweroff

Each of these operations can be enabled or disabled, but they
are always applied in this order.

With the shutdown option, a configurable time is allowed for
shutdown to complete, defaulting to 30 seconds, before moving
onto the forced poweroff phase.

Reviewed-by: Peter Krempa <pkrempa@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
4 months agoremote: always invoke virStateStop for all daemons
Daniel P. Berrangé [Tue, 17 Dec 2024 17:06:18 +0000 (17:06 +0000)] 
remote: always invoke virStateStop for all daemons

Currently the virStateStop method is only wired up to run save for
the unprivileged daemons, so there is no functional change.

IOW, session exit, or host OS shutdown will trigger VM managed saved
for QEMU session daemon, but not the system daemon.

This changes the daemon code to always run virStateStop for all
daemons. Instead the QEMU driver is responsible for skipping its
own logic when running privileged...for now.

This means that virStateStop will now be triggered by logind's
PrepareForShutdown signal.

Reviewed-by: Peter Krempa <pkrempa@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
4 months agohypervisor: move support for auto-shutdown out of QEMU driver
Daniel P. Berrangé [Tue, 17 Dec 2024 10:04:35 +0000 (10:04 +0000)] 
hypervisor: move support for auto-shutdown out of QEMU driver

This is a move of the code that currently exists in the QEMU
driver, into the common layer that can be used by multiple
drivers.

The code currently supports performing managed save of all
running guests, ignoring any failures.

Reviewed-by: Peter Krempa <pkrempa@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
4 months agoqemuHotplugRemoveManagedPR: Integrate check whether removal is needed
Peter Krempa [Mon, 17 Mar 2025 17:18:37 +0000 (18:18 +0100)] 
qemuHotplugRemoveManagedPR: Integrate check whether removal is needed

Calls to 'qemuHotplugRemoveManagedPR' needed to be guarded by a check if
the removed elements actually caused us to add the manager in the first
place.

The two new calls added in commit 1697323bfe6000c2f5a2519c06f0ba81 were
not guarded by such check and thus would spam the debug log with:

  [{"id": "libvirt-59", "error": {"class": "GenericError", "desc": "object 'pr-helper0' not found"}}]

Luckily 'qemuHotplugRemoveManagedPR' didn't request the error to be
reported as a proper error.

Don't attempt the removal unless needed.

Fixes: 1697323bfe6000c2f5a2519c06f0ba81f7b792eb
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
4 months agoqemuDomainChangeEjectableMedia: Separate rollback and success code paths
Peter Krempa [Mon, 17 Mar 2025 17:09:03 +0000 (18:09 +0100)] 
qemuDomainChangeEjectableMedia: Separate rollback and success code paths

Do not use the rollback code path on success just to avoid extra call to
qemuHotplugRemoveManagedPR.

Rename the label and use it only when rolling back.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
4 months agoqemu: Remove return value from 'qemuHotplugRemoveManagedPR'
Peter Krempa [Mon, 17 Mar 2025 16:50:42 +0000 (17:50 +0100)] 
qemu: Remove return value from 'qemuHotplugRemoveManagedPR'

The only place which actually checked the return value would skip code
e.g. to delete unused files or stop no longer used services. The rest of
the callers ignored the value.

As this is expected to be used on cleanup code paths which have no
possibility to report errors we should remove the return value
completely.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
4 months agoqemu: Do not replace filter nodes with virDomainBlockCopy
Peter Krempa [Mon, 17 Mar 2025 16:35:12 +0000 (17:35 +0100)] 
qemu: Do not replace filter nodes with virDomainBlockCopy

The block copy operation is supposed to just move the disk to a new
destination. While in certain scenarios it'd make sense to drop the
copy-on-read layer, the definition would not correspond to it.

This was caused by a fix to the behaviour of the block job after
conversion to -blockdev as 'blockdev-mirror' requires the top node of
the disk to be selected. This also causes that the 'copy-on-read' filter
is ejected but libvirt doesn't unplug it.

Instead we need to use the 'replaces' argument of 'blockdev-mirror'
which allows to keep filters in place. This will preserve the
configuration (which can be optimized later) and also fixes a spurious
error logged when trying to unplug the first real file node after
copy-on-read which still looks used to qemu.

This is also needed for the upcoming feature which adds 'throttle'
filter layers as we need to keep those in place too to facilitate the
throttling.

Resolves: https://issues.redhat.com/browse/RHEL-40077
Fixes: e3137539a9c4af25ab085506d5467ec0847b0ecc
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
4 months agoqemu: monitor: Wire up 'replaces' attribute for 'blockdev-mirror'
Peter Krempa [Mon, 17 Mar 2025 16:15:22 +0000 (17:15 +0100)] 
qemu: monitor: Wire up 'replaces' attribute for 'blockdev-mirror'

The 'replaces' field controls which node will be replaced by the job.
This can be used to e.g. keep filter nodes in place after the copy
finishes.

This will be used to keep the 'copy-on-read' and 'throttle' layers in
place after a copy.

This patch wires up the monitor and test, but the real callers pass NULL
for now.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
4 months agoNEWS: Mention multiple iothread support for 'virtio-scsi' controller
Peter Krempa [Mon, 3 Mar 2025 15:16:41 +0000 (16:16 +0100)] 
NEWS: Mention multiple iothread support for 'virtio-scsi' controller

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
4 months agoqemuxmlconftest: Add 'iothreads-virtio-scsi-mapping' case
Peter Krempa [Fri, 14 Feb 2025 14:58:54 +0000 (15:58 +0100)] 
qemuxmlconftest: Add 'iothreads-virtio-scsi-mapping' case

Test the XML and commandline for iothread<->virtqueue mapping for
'virtio-scsi' controllers.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
4 months agoqemu: Implement support for iothread <-> virtqueue mapping for 'virtio-scsi' controllers
Peter Krempa [Fri, 14 Feb 2025 14:13:36 +0000 (15:13 +0100)] 
qemu: Implement support for iothread <-> virtqueue mapping for 'virtio-scsi' controllers

Similarly to 'virtio-blk' users can map multiple iothreads and pin them
appropriately for 'virtio-scsi' controllers to ensure the best
performance.

Implement the validation and command line generation based on the
helpers we have for 'virtio-blk'.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
4 months agoconf: Add support for iothread to queue mapping config for 'virtio-scsi'
Peter Krempa [Fri, 14 Feb 2025 14:13:36 +0000 (15:13 +0100)] 
conf: Add support for iothread to queue mapping config for 'virtio-scsi'

Upcoming qemu release will support configuring mapping iothreads to
virtio queues for 'virtio-scsi' controllers in order to improve
performance.

Reuse the infrastructure we have from the same configuration for
'virti-blk' to implement the conf support for this feature.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
4 months agoqemu: capabilities: Introduce QEMU_CAPS_VIRTIO_SCSI_IOTHREAD_MAPPING
Peter Krempa [Tue, 11 Feb 2025 16:53:51 +0000 (17:53 +0100)] 
qemu: capabilities: Introduce QEMU_CAPS_VIRTIO_SCSI_IOTHREAD_MAPPING

The 'virtio-scsi' controller now supports iothread<->virtqueue mapping
configuration.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
4 months agoqemucapabilitiestest: Update 'caps_10.0.0_x86_64' to v9.2.0-2799-g0462a32b4f
Peter Krempa [Tue, 11 Feb 2025 16:50:36 +0000 (17:50 +0100)] 
qemucapabilitiestest: Update 'caps_10.0.0_x86_64' to v9.2.0-2799-g0462a32b4f

Notable changes:
 - 'virtio-scsi' supports 'iothread-vq-mapping'
 - 'vfio-pci' device gained two unstable options 'x-igd-legacy-mode'
   and 'x-igd-lpc'

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
4 months agoconf: also free auth for rdp in virDomainGraphicsDefFree
Ján Tomko [Tue, 18 Mar 2025 17:55:25 +0000 (18:55 +0100)] 
conf: also free auth for rdp in virDomainGraphicsDefFree

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Fixes: bfa7d5aaa8834c6801cacbfc6c6ea83a8ecaca9c
4 months agoqemu: remove unreachable breaks in qemuDomainAssignMemoryDeviceSlot
Ján Tomko [Tue, 18 Mar 2025 17:01:33 +0000 (18:01 +0100)] 
qemu: remove unreachable breaks in qemuDomainAssignMemoryDeviceSlot

Signed-off-by: Ján Tomko <jtomko@redhat.com>
4 months agoqemu_domain_address: fix CCW virtio-mem hotplug
Boris Fiuczynski [Tue, 18 Mar 2025 13:48:50 +0000 (14:48 +0100)] 
qemu_domain_address: fix CCW virtio-mem hotplug

Since commit f23f8ff91a virtio-mem supports also CCW. When hotplugging a
virtio-mem device with a CCW address results in a PCI device getting
attached. The method qemuDomainAssignMemoryDeviceSlot is only
considering PCI as address type and overwriting the CCW address. Adding
support for address type CCW.

Signed-off-by: Boris Fiuczynski <fiuczy@linux.ibm.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
4 months agotests: add qemu <graphics type='rdp'/> test
Marc-André Lureau [Sun, 16 Mar 2025 08:18:41 +0000 (12:18 +0400)] 
tests: add qemu <graphics type='rdp'/> test

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
4 months agoqemu: add RDP support
Marc-André Lureau [Sun, 16 Mar 2025 08:18:40 +0000 (12:18 +0400)] 
qemu: add RDP support

Wire the external server RDP support with QEMU.

Check the configuration, allocate a port, start the process
and set the credentials.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
4 months agoqemu: add 'rdp' capability if qemu-rdp is available
Marc-André Lureau [Sun, 16 Mar 2025 08:18:39 +0000 (12:18 +0400)] 
qemu: add 'rdp' capability if qemu-rdp is available

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
4 months agoqemu: pass virQEMUDriverConfig to capabilities
Marc-André Lureau [Sun, 16 Mar 2025 08:18:38 +0000 (12:18 +0400)] 
qemu: pass virQEMUDriverConfig to capabilities

This will help with the following patch, which also requires config access.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
4 months agoqemu: add qemu-rdp helper unit
Marc-André Lureau [Sun, 16 Mar 2025 08:18:37 +0000 (12:18 +0400)] 
qemu: add qemu-rdp helper unit

Helpers to start the qemu-rdp server and set it up.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
4 months agoqemu: validate RDP configuration
Marc-André Lureau [Sun, 16 Mar 2025 08:18:36 +0000 (12:18 +0400)] 
qemu: validate RDP configuration

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
4 months agoqemu/dbus: log daemon stdout/err, use domainLogContext
Marc-André Lureau [Sun, 16 Mar 2025 08:18:35 +0000 (12:18 +0400)] 
qemu/dbus: log daemon stdout/err, use domainLogContext

Currently, if dbus-daemon writes on errfd, it will SIGPIPE.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
4 months agoqemu/dbus: keep a connection to the VM D-Bus
Marc-André Lureau [Sun, 16 Mar 2025 08:18:34 +0000 (12:18 +0400)] 
qemu/dbus: keep a connection to the VM D-Bus

The following changes are going to communicate with the qemu-rdp server
through the VM D-Bus bus, keep a connection for that and further usage.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
4 months agoqemu/virtiofs: use domainLogContext
Marc-André Lureau [Sun, 16 Mar 2025 08:18:33 +0000 (12:18 +0400)] 
qemu/virtiofs: use domainLogContext

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
4 months agoqemu: limit to one <graphics type='rdp'>
Marc-André Lureau [Sun, 16 Mar 2025 08:18:32 +0000 (12:18 +0400)] 
qemu: limit to one <graphics type='rdp'>

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
4 months agoqemu: add RDP ports range allocator
Marc-André Lureau [Sun, 16 Mar 2025 08:18:31 +0000 (12:18 +0400)] 
qemu: add RDP ports range allocator

RDP server uses port 3389 by default.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
4 months agoqemu: use virDomainDefHasGraphics
Marc-André Lureau [Sun, 16 Mar 2025 08:18:30 +0000 (12:18 +0400)] 
qemu: use virDomainDefHasGraphics

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
4 months agoconf: generalize virDomainDefHasSpiceGraphics
Marc-André Lureau [Sun, 16 Mar 2025 08:18:29 +0000 (12:18 +0400)] 
conf: generalize virDomainDefHasSpiceGraphics

Generalize the function, broaden its potential usage.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
4 months agoconf: parse optional RDP username & password
Marc-André Lureau [Sun, 16 Mar 2025 08:18:28 +0000 (12:18 +0400)] 
conf: parse optional RDP username & password

Like VNC, allow to set credentials for RDP.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
4 months agoqemu: add qemu RDP configuration
Marc-André Lureau [Sun, 16 Mar 2025 08:18:27 +0000 (12:18 +0400)] 
qemu: add qemu RDP configuration

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
4 months agoqemu: add rdp state directory
Marc-André Lureau [Sun, 16 Mar 2025 08:18:26 +0000 (12:18 +0400)] 
qemu: add rdp state directory

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
4 months agoutil: annotate non-null arguments for virGDBusCallMethod()
Marc-André Lureau [Sun, 16 Mar 2025 08:18:25 +0000 (12:18 +0400)] 
util: annotate non-null arguments for virGDBusCallMethod()

Helps avoid/debug a potential SEGV if conn is NULL, since gio will not
set the "gerror" in that case and we will crash later at:
  virReportError(VIR_ERR_DBUS_SERVICE, "%s", gerror->message);

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
4 months agoqemu-slirp: drop unneeded check for OOM
Marc-André Lureau [Sun, 16 Mar 2025 08:18:24 +0000 (12:18 +0400)] 
qemu-slirp: drop unneeded check for OOM

glib anti-pattern, since it aborts on OOM.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
4 months agobuild: fix -Werror=maybe-uninitialized
Marc-André Lureau [Sun, 16 Mar 2025 08:18:23 +0000 (12:18 +0400)] 
build: fix -Werror=maybe-uninitialized

When compiled with -Doptimization=g

../tools/nss/libvirt_nss_macs.c:155:8: error: ‘jerr’ may be used uninitialized [-Werror=maybe-uninitialized]
  155 |     if (jerr == json_tokener_continue) {
      |        ^

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
4 months agobuild-sys: drop -Winline when optimization=g
Marc-André Lureau [Sun, 16 Mar 2025 08:18:22 +0000 (12:18 +0400)] 
build-sys: drop -Winline when optimization=g

The warning is triggered when compiling with various build options, such
as -Doptimization=g.

From gcc(1) man page about -Winline:
seemingly insignificant changes in the source program can cause the warnings produced by -Winline to appear or disappear.

Such flaky behaviour is best left to the user discretion.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
4 months agonews: Add item for guest load averages
Martin Kletzander [Mon, 3 Mar 2025 13:31:48 +0000 (14:31 +0100)] 
news: Add item for guest load averages

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
4 months agosrc: add new target for regenerating protocol structs files
Daniel P. Berrangé [Thu, 13 Mar 2025 15:53:07 +0000 (15:53 +0000)] 
src: add new target for regenerating protocol structs files

Introduce a new ninja target

   ninja -C build regen-{PROTO}

eg

   ninja -C build regen-admin_protocol

that will re-create the reference output file based on what the
current pdwtags command emits. A small change is made to squash
whitespace on enum declarations so that introducing a new longer
enum name doesn't trigger re-indent of all existing enum names.

Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
4 months agosrc: normalize whitespace in protocol structs files
Daniel P. Berrangé [Thu, 13 Mar 2025 15:53:01 +0000 (15:53 +0000)] 
src: normalize whitespace in protocol structs files

This makes the output match what current pdwtags will emit,
modulo some whitespace changes made by the check script
before comparison.

Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
4 months agoch: Fix refcounting in virCHEventHandlerLoop() and virCHStartEventHandler()
Kirill Shchetiniuk [Fri, 14 Mar 2025 11:51:19 +0000 (12:51 +0100)] 
ch: Fix refcounting in virCHEventHandlerLoop() and virCHStartEventHandler()

When event handler thread is created inside of
virCHStartEventHandler() the monitor object is refed because the thread
(virCHEventHandlerLoop()) that's created in the very next step
uses it. But right after that, the monitor object is unrefed,
which is wrong because it takes away the reference which was
handed over to the thread. The monitor must be unrefed inside the
thread, when no longer needed.

And while at it, move the unref call of the domain object after
the debug print which obviously accesses the domain definition.

Signed-off-by: Kirill Shchetiniuk <kshcheti@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 months agoch: preserve last error in virCHProcessStop()
Kirill Shchetiniuk [Fri, 14 Mar 2025 11:51:18 +0000 (12:51 +0100)] 
ch: preserve last error in virCHProcessStop()

If starting a CH domain fails an error is reported and
virCHProcessStart() calls virCHProcessStop() to clean up any
residues. Problem is, inside of virCHProcessStop() some public
APIs might be called (e.g. virNetworkLookupByName(),
virNetworkPortLookupByUUID() and/or virNetworkPortDelete()). Per
our design, public APIs reset last error which means the useful
error reported earlier is lost.

Fix this by calling virErrorPreserveLast() + virErrorRestore()
combo inside of virCHProcessStop().

Signed-off-by: Kirill Shchetiniuk <kshcheti@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 months agodocs: Fix some typos
Thomas Huth [Mon, 17 Mar 2025 10:41:20 +0000 (11:41 +0100)] 
docs: Fix some typos

Found with the codespell utility.

Signed-off-by: Thomas Huth <thuth@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
4 months agodocs: remove references to removed APIs
Daniel P. Berrangé [Mon, 17 Mar 2025 10:02:24 +0000 (10:02 +0000)] 
docs: remove references to removed APIs

The glib adoption docs was suggesting avoidance of certain APIs that
were obsoleted by glib, during the transition period. Now that the
referenced APIs no longer exist in libvirt code, they can also be
removed from the docs.

NB, the virStringListRemoveDuplicates method remains since there is
no glib equivalent.

Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
4 months agoscripts: add execute permission to several files
Daniel P. Berrangé [Mon, 17 Mar 2025 10:11:01 +0000 (10:11 +0000)] 
scripts: add execute permission to several files

Most, but not all, files in scripts have execute permission. While we
don't need this in order to launch them via meson/ninja build rules,
it is nice to direct execution if they have execution permission. This
makes the practice consistent across all scripts.

Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
4 months agodocs: document workaround for DMARC countermeasures
Daniel P. Berrangé [Mon, 17 Mar 2025 11:18:17 +0000 (11:18 +0000)] 
docs: document workaround for DMARC countermeasures

If a contributor's email domain has a DMARC policy of 'p=quarantine'
or 'p=reject', mailman will apply DMARC countermeasures on all mails
sent to lists.libvirt.org rewriting the "From" header to remove the
sender's email address. e.g.

  From: Your Name via <lists.libvirt.org>

If these countermeasures were not applied, affected mail would either
have gone directly to SPAM, or have been entirely rejected. Mailman3
is unable to be configured to guarantee no mangling of the mail body
so these countermeasures are unavoidable for lists.libvirt.org.

Amongst the various downsides, the From address rewriting has the
bad effect of mangling git commit author attribution.

To avoid this it is required to add two additional git config
settings:

  $ git config --global format.from "Your Name <your@email.com>"
  $ git config --global format.forceInBodyFrom true

Note, *both* are required, even if your ``format.from`` matches
your existing git identity, because the latter only takes effect
once the former is set.

Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
4 months agoconf: parse interface/source/@dev for all interface types (with backend type='passt')
Laine Stump [Fri, 7 Mar 2025 00:19:12 +0000 (19:19 -0500)] 
conf: parse interface/source/@dev for all interface types (with backend type='passt')

The original implementation of the passt backend for vhost-user
interfaces erroneously forgot to parse:

  <source dev='blah'/>

for interface type='vhostuser', so it wasn't being added to the passt
commandline, and also wasn't being saved to the domain config. Now we
parse it whenever the <backend> type='passt', no matter what the
interface type, and then throw an error during validation if
source/@dev was specified for interface type = 'user|vhostuser' and
backend type != 'passt'.

Fixes: 1e9054b9c79d721a55f413c2983c5370044f8f60
Resolves: https://issues.redhat.com/browse/RHEL-82539
Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
4 months agoRemove unreachable breaks right after return
Ján Tomko [Thu, 13 Mar 2025 15:27:27 +0000 (16:27 +0100)] 
Remove unreachable breaks right after return

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
4 months agoqemu: remove unused vm from qemuBuildPVCommandLine
Ján Tomko [Thu, 13 Mar 2025 15:03:23 +0000 (16:03 +0100)] 
qemu: remove unused vm from qemuBuildPVCommandLine

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
4 months agoqemu: remove unused vm from qemuBuildSEVSNPCommandLine
Ján Tomko [Thu, 13 Mar 2025 15:01:03 +0000 (16:01 +0100)] 
qemu: remove unused vm from qemuBuildSEVSNPCommandLine

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
4 months agoqemu: remove qemuCaps from qemuBuildIOThreadCommandLine
Ján Tomko [Thu, 13 Mar 2025 14:56:29 +0000 (15:56 +0100)] 
qemu: remove qemuCaps from qemuBuildIOThreadCommandLine

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
4 months agoqemu: remove qemuCaps from qemuBuildObjectCommandline
Ján Tomko [Thu, 13 Mar 2025 14:55:53 +0000 (15:55 +0100)] 
qemu: remove qemuCaps from qemuBuildObjectCommandline

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