Commit Graph

9946 Commits

Author SHA1 Message Date
Anatol Belski
093922ff24 block: qcow: Test async read spanning cluster boundary
Add a QcowAsync unit test that writes distinct patterns into two
adjacent clusters, then issues a single read spanning the cluster
boundary. Verifies that multi mapping read resolution returns the
correct data from both clusters.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-04-14 22:11:26 +00:00
Anatol Belski
1e66c144f4 block: qcow: Test async write and read roundtrip
Add a QcowAsync unit test that writes a byte pattern through
write_vectored, reads it back through read_vectored, and verifies
the data matches. This exercises the core async write and read
paths end to end.

Also add an async_write helper for future tests.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-04-14 22:11:26 +00:00
Anatol Belski
e522d3a0aa block: qcow: Test async write zeroes
Add a QcowAsync unit test for write zeroes completion. The test
verifies that a write zeroes request reports successful completion
and that the zeroed range reads back as zeroes.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-04-14 22:11:26 +00:00
Anatol Belski
8ffbe9d6fe block: qcow: Test async punch hole
Add a QcowAsync unit test for punch hole completion. The test
verifies that a punch hole request reports successful completion
and that the deallocated range reads back as zeroes.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-04-14 22:11:26 +00:00
Anatol Belski
b1d126fdbf block: qcow: Implement batch request submission
Implement batch_requests_enabled() and submit_batch_requests() for
QcowAsync. Without batching, each read_vectored call performs its own
io_uring submit() syscall. With batching, the virtio queue handler
collects all pending requests and submits them in a single call,
pushing multiple SQEs before one submit() syscall.

Each request in the batch is classified through the metadata layer.
Requests that hit the fast path (single allocated cluster mapping)
are pushed to the io_uring submission queue. Requests that require
the slow path (compressed, backing, zero fill, or mixed mappings)
are completed synchronously and queued as synthetic completions.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-04-14 22:11:26 +00:00
Anatol Belski
3d5a40dfa6 vmm: device_manager: Wire up QcowDiskAsync with io_uring
When io_uring is available and not disabled, open QCOW2 images
with QcowDiskAsync for asynchronous reads. Falls back to
QcowDiskSync otherwise.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-04-14 22:11:26 +00:00
Anatol Belski
ffc579b913 block: qcow_async: impl AsyncDiskFile for QcowDiskAsync
try_clone shares the Arc wrapped metadata and backing file.
new_async_io creates a QcowAsync worker with its own io_uring
instance for the given ring depth.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-04-14 22:11:26 +00:00
Anatol Belski
261361c1b0 block: qcow_async: impl punch_hole and write_zeroes for QcowAsync
Deallocate clusters through QcowMetadata::deallocate_bytes, then
apply the resulting DeallocAction list (punch hole or write zeroes
at host offsets). write_zeroes delegates to punch_hole since
unallocated QCOW2 clusters inherently read as zero.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-04-14 22:11:26 +00:00
Anatol Belski
bf70c19857 block: qcow_async: impl fsync for QcowAsync
Flush dirty metadata caches and sync the underlying file via
QcowMetadata::flush, then signal synthetic completion.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-04-14 22:11:26 +00:00
Anatol Belski
a97260c5e0 block: qcow_async: impl write_vectored for QcowAsync
Synchronous per cluster write path - gather guest data from iovecs,
map each cluster through QcowMetadata, and pwrite to the allocated
host offset. Partial cluster writes with a backing file read the
backing data first so map_cluster_for_write can perform COW.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-04-14 22:11:26 +00:00
Anatol Belski
e7621abfbd block: qcow_async: impl read_vectored for QcowAsync
Single allocated cluster reads are submitted to io_uring for true
async completion. Mixed mapping reads (zero, compressed, backing,
multi cluster) fall back to synchronous pread64 with synthetic
completions.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-04-14 22:11:26 +00:00
Anatol Belski
85df0fef0d block: qcow_async: impl AsyncIo scaffold for QcowAsync
Add the AsyncIo trait impl with notifier and next_completed_request
filled in. The remaining methods are stubbed with unimplemented
and will be filled in by subsequent commits.

next_completed_request drains io_uring completions first, then
falls back to the synthetic completion list.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-04-14 22:11:26 +00:00
Anatol Belski
8d684cad98 block: qcow_async: Add QcowAsync struct and constructor
Per queue I/O worker that uses io_uring for asynchronous reads
against fully allocated clusters. The struct holds the shared
metadata, data file, optional backing reader, the io_uring
instance and a synthetic completion list.

Feature gated on io_uring in lib.rs.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-04-14 22:11:26 +00:00
Anatol Belski
8966607898 block: qcow_async: impl DiskFile for QcowDiskAsync
Marker supertrait combining all composable capability traits.
QcowDiskAsync now satisfies the full DiskFile contract.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-04-14 22:11:26 +00:00
Anatol Belski
8c3b6cb04b block: qcow_async: impl Resizable for QcowDiskAsync
Delegates to QcowMetadata::resize. Rejects resize when a backing
file is present, same as the sync backend.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-04-14 22:11:26 +00:00
Anatol Belski
52cd45874a block: qcow_async: impl SparseCapable for QcowDiskAsync
QCOW2 images support both sparse operations and the zero flag.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-04-14 22:11:26 +00:00
Anatol Belski
fa700f6493 block: qcow_async: impl Geometry for QcowDiskAsync
Uses the default geometry, same as the sync backend.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-04-14 22:11:26 +00:00
Anatol Belski
91d6356db4 block: qcow_async: impl DiskFd for QcowDiskAsync
Returns a borrowed file descriptor for the underlying data file.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-04-14 22:11:26 +00:00
Anatol Belski
403b75656c block: qcow_async: impl PhysicalSize for QcowDiskAsync
Queries the underlying raw file for on disk size.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-04-14 22:11:26 +00:00
Anatol Belski
f777113818 block: qcow_async: impl DiskSize for QcowDiskAsync
Delegates to QcowMetadata::virtual_size, identical to the sync
backend.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-04-14 22:11:26 +00:00
Anatol Belski
3422a8b258 block: qcow: Add QcowDiskAsync struct stub
Introduce the device level handle for the async QCOW2 backend.

QcowDiskAsync mirrors QcowDiskSync. It parses the image, resolves
the backing chain and wraps QcowMetadata in an Arc for sharing
across virtio queues. No trait impls yet, just the struct,
constructor, Drop and Debug.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-04-14 22:11:26 +00:00
Anatol Belski
8cd2c957ef block: qcow: Move shared_backing_from to qcow/backing
Move the backing file constructor into qcow/backing alongside the
types it creates. Both qcow_sync and qcow_async can now import
shared_backing_from directly from qcow/backing.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-04-14 22:11:26 +00:00
Anatol Belski
5ec80d45ab block: qcow: Move Qcow2MetadataBacking to qcow/backing
Move the QCOW2 metadata backed reader into qcow/backing alongside
RawBacking.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-04-14 22:11:26 +00:00
Anatol Belski
e345299f4d block: qcow: Move RawBacking to qcow/backing module
Move the raw backing file reader into the new qcow/backing module
so it can be shared between qcow_sync and the upcoming qcow_async
backend.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-04-14 22:11:26 +00:00
Anatol Belski
81f43f96c3 block: qcow: Move iovec scatter/gather helpers to qcow_common
Move scatter_to_iovecs, zero_fill_iovecs and gather_from_iovecs into
qcow_common so they can be shared with the upcoming qcow_async backend.

These helpers treat an iovec array as a flat byte stream and are used by
both read_vectored and write_vectored code paths.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-04-14 22:11:26 +00:00
Anatol Belski
7f3dfe2154 block: qcow: Extract positional I/O helpers into a common module
These position independent I/O helpers use pread64/pwrite64 to avoid
races on the shared file position when multiple queues operate on
duplicated file descriptors. Extracting them prepares for reuse by
the upcoming qcow_async backend.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-04-14 22:11:26 +00:00
Anatol Belski
73680c38c7 ci: Switch to Windows Server 2025 for AMD64
The updated image is configured in a same way as the
previously used 2022.

SAC, SSH, and RDP are configured.

All Windows updates to the curent date are installed.

Includes latest stable virtio-win 0.1.285 drivers.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-04-14 16:09:36 +00:00
Philipp Schuster
98aa9d9c12 tests: make VFIO memory hotplug more robust
After memory hotplug, it may happen that it takes a few seconds until a
VFIO device is available again (IOMMU/DMA mappings need update).

On-behalf-of: SAP philipp.schuster@sap.com
Signed-off-by: Philipp Schuster <philipp.schuster@cyberus-technology.de>
2026-04-14 15:11:42 +00:00
Philipp Schuster
e6c8b5e816 tests: run more tests in parallel
They can safely run in parallel. This further speeds up the CI by ~5.

On-behalf-of: SAP philipp.schuster@sap.com
Signed-off-by: Philipp Schuster <philipp.schuster@cyberus-technology.de>
2026-04-14 15:11:42 +00:00
Rob Bradford
cc7e56fa07 vmm: device_manager: Use more idiomatic Rust for ID assignment
Use a more idiomatic Rust approach when establishing an autogenerated ID
when none is set.

Signed-off-by: Rob Bradford <rbradford@meta.com>
2026-04-14 14:19:34 +00:00
Rob Bradford
7ac877cc26 vmm: device_manager: Reuse PciDeviceCommonConfig in MetaVirtioDevice
This struct has the same members and it can be reused to reduce
complexity now and if other common PCI related fields need to be
added in the future.

Signed-off-by: Rob Bradford <rbradford@meta.com>
2026-04-14 14:19:34 +00:00
Rob Bradford
0c837abff2 vmm: config: Put common options in an array
This can then be used with the OptionParser::add_all() API to reduce the
number of locations the same options are added to the parser. The only
quirk is that some devices do not support an IOMMU (because they are
vhost-user / vfio-user based). There are two different versions of the
array to support that.

Signed-off-by: Rob Bradford <rbradford@meta.com>
2026-04-14 14:19:34 +00:00
Rob Bradford
dde28dc38a vmm: config: Remove unused error variant
The IommuNotSupportedOnSegment variant is no longer needed as the common
PciDeviceCommonConfig::validate() handles this case with the
OnIommuSegment variant along with more use of the IommuNotSupported
error variant.

Signed-off-by: Rob Bradford <rbradford@meta.com>
2026-04-14 14:19:34 +00:00
Rob Bradford
37b1ed1b84 vmm: config: Switch VsockConfig to use PciDeviceCommonConfig
Switch VsockConfig over to using the newly extracted struct members as
used by all PCI based devices. The use of #[serde(flatten)] means that
this change has no impact on the JSON format that the data is stored as.

Signed-off-by: Rob Bradford <rbradford@meta.com>
2026-04-14 14:19:34 +00:00
Rob Bradford
ece77c3c52 vmm: config: Switch VdpaConfig to use PciDeviceCommonConfig
Switch VdpaConfig over to using the newly extracted struct members as
used by all PCI based devices. The use of #[serde(flatten)] means that
this change has no impact on the JSON format that the data is stored as.

Signed-off-by: Rob Bradford <rbradford@meta.com>
2026-04-14 14:19:34 +00:00
Rob Bradford
2c50be4753 vmm: config: Switch UserDeviceConfig to use PciDeviceCommonConfig
Switch UserDeviceConfig over to using the newly extracted struct members
as used by all PCI based devices. The use of #[serde(flatten)] means
that this change has no impact on the JSON format that the data is
stored as.

As VFIO user devices do not support being placed behind an IOMMU an
error is now raised if iommu is set. This can't happen via the CLI but
could via the JSON/API.

Signed-off-by: Rob Bradford <rbradford@meta.com>
2026-04-14 14:19:34 +00:00
Rob Bradford
47182201f9 vmm: config: Switch DeviceConfig to use PciDeviceCommonConfig
Switch DeviceConfig over to using the newly extracted struct members as
used by all PCI based devices. The use of #[serde(flatten)] means that
this change has no impact on the JSON format that the data is stored as.

Signed-off-by: Rob Bradford <rbradford@meta.com>
2026-04-14 14:19:34 +00:00
Rob Bradford
c9082570b0 vmm: config: Switch PmemConfig to use PciDeviceCommonConfig
Switch PmemConfig over to using the newly extracted struct members as
used by all PCI based devices. The use of #[serde(flatten)] means that
this change has no impact on the JSON format that the data is stored as.

Signed-off-by: Rob Bradford <rbradford@meta.com>
2026-04-14 14:19:34 +00:00
Rob Bradford
0d3080e036 vmm: config: Switch GenericVhostUserConfig to use PciDeviceCommonConfig
Switch GenericVhostUserConfig over to using the newly extracted struct
members as used by all PCI based devices. The use of #[serde(flatten)]
means that this change has no impact on the JSON format that the data is
stored as.

As generic vhost-user devices do not support being placed behind an
IOMMU an error is now raised if iommu is set. This can't happen via the
CLI but could via the JSON/API.

Signed-off-by: Rob Bradford <rbradford@meta.com>
2026-04-14 14:19:34 +00:00
Rob Bradford
40150dd72d vmm: config: Switch FsConfig to use PciDeviceCommonConfig
Switch FsConfig over to using the newly extracted struct members as used
by all PCI based devices. The use of #[serde(flatten)] means that this
change has no impact on the JSON format that the data is stored as.

As virtio-fs does not support being placed behind an IOMMU an error is
now raised if iommu is set. This option is not exposed via the CLI but
could happen with a miscontructed JSON/API call.

Signed-off-by: Rob Bradford <rbradford@meta.com>
2026-04-14 14:19:34 +00:00
Rob Bradford
92c2cf0103 vmm: config: Switch NetConfig to use PciDeviceCommonConfig
Switch NetConfig over to using the newly extracted struct members as
used by all PCI based devices. The use of #[serde(flatten)] means that
this change has no impact on the JSON format that the data is stored as.

Signed-off-by: Rob Bradford <rbradford@meta.com>
2026-04-14 14:19:34 +00:00
Rob Bradford
d2ce7667bc vmm: config: Switch DiskConfig to use PciDeviceCommonConfig
Switch DiskConfig over to using the newly extracted struct members as
used by all PCI based devices. The use of #[serde(flatten)] means that
this change has no impact on the JSON format that the data is stored as.

Signed-off-by: Rob Bradford <rbradford@meta.com>
2026-04-14 14:19:34 +00:00
Rob Bradford
a96da9d4bc vmm: Introduce PciDeviceCommonConfig::validate()
Implement some common PCI segment validation. This can be used to reduce
duplication across the different validation methods.

Signed-off-by: Rob Bradford <rbradford@meta.com>
2026-04-14 14:19:34 +00:00
Rob Bradford
c66c2b8470 vmm: config: Implement PciDeviceCommonConfig::parse
This parses a subset of the device configuration options used for
devices that are PCI based.

Signed-off-by: Rob Bradford <rbradford@meta.com>
2026-04-14 14:19:34 +00:00
Rob Bradford
4f7ff8fe48 vmm: Introduce a PciDeviceCommonConfig struct
Introduce a common struct that can encompass all the config fields
used by devices that are PCI based. The use of `skip_serializing_if`
means that the iommu field will only be included if set (otherwise
falling back to default false). This neatly handles the devices that
don't support an iommu.

Signed-off-by: Rob Bradford <rbradford@meta.com>
2026-04-14 14:19:34 +00:00
Rob Bradford
2148f2e0bc option_parser: Fix incorrect unit test
This unit test was trying to test with extra "="s in the input but was
instead testing using an unknown option. Add the option to the parser to
not hit that incorrect error.

Signed-off-by: Rob Bradford <rbradford@meta.com>
2026-04-14 14:19:34 +00:00
Rob Bradford
d93770c11d option_parser: Fill out unit testing
Add unit tests generated with Claude Opus 4.6 and reviewed by human
eyes.

Signed-off-by: Rob Bradford <rbradford@meta.com>
2026-04-14 14:19:34 +00:00
Rob Bradford
e5496a093d option_parser: Fix incorrect error message
The error message for the InvalidSyntax was copied from UnknownOption.
Correct it to "invalid syntax".

Signed-off-by: Rob Bradford <rbradford@meta.com>
2026-04-14 14:19:34 +00:00
Rob Bradford
d212255073 option_parser: Add documentation strings
Autogenerated with Claude Opus 4.6 and reviewed with human eyes.

Signed-off-by: Rob Bradford <rbradford@meta.com>
2026-04-14 14:19:34 +00:00
Rob Bradford
791889cefd option_parser: Add support for adding from a slice
Add an OptionParser::add_all method that takes a slice of option names
and use that to add to the set of parameters that the parser works on.

Signed-off-by: Rob Bradford <rbradford@meta.com>
2026-04-14 14:19:34 +00:00