Commit Graph

9606 Commits

Author SHA1 Message Date
dependabot[bot]
7e0f8f7163 build: Bump the non-rust-vmm group across 2 directories with 10 updates
Bumps the non-rust-vmm group with 6 updates in the / directory:

| Package | From | To |
| --- | --- | --- |
| [env_logger](https://github.com/rust-cli/env_logger) | `0.11.9` | `0.11.10` |
| [arc-swap](https://github.com/vorner/arc-swap) | `1.8.2` | `1.9.0` |
| [env_filter](https://github.com/rust-cli/env_logger) | `1.0.0` | `1.0.1` |
| [terminal_size](https://github.com/eminence/terminal-size) | `0.4.3` | `0.4.4` |
| [toml_datetime](https://github.com/toml-rs/toml) | `1.0.1+spec-1.1.0` | `1.1.0+spec-1.1.0` |
| [toml_edit](https://github.com/toml-rs/toml) | `0.25.5+spec-1.1.0` | `0.25.8+spec-1.1.0` |

Bumps the non-rust-vmm group with 3 updates in the /fuzz directory: [arc-swap](https://github.com/vorner/arc-swap), [toml_datetime](https://github.com/toml-rs/toml) and [toml_edit](https://github.com/toml-rs/toml).


Updates `env_logger` from 0.11.9 to 0.11.10
- [Release notes](https://github.com/rust-cli/env_logger/releases)
- [Changelog](https://github.com/rust-cli/env_logger/blob/main/CHANGELOG.md)
- [Commits](https://github.com/rust-cli/env_logger/compare/v0.11.9...v0.11.10)

Updates `arc-swap` from 1.8.2 to 1.9.0
- [Changelog](https://github.com/vorner/arc-swap/blob/master/CHANGELOG.md)
- [Commits](https://github.com/vorner/arc-swap/compare/v1.8.2...v1.9.0)

Updates `anstream` from 0.6.21 to 1.0.0
- [Commits](https://github.com/rust-cli/anstyle/compare/anstream-v0.6.21...anstream-v1.0.0)

Updates `anstyle-parse` from 0.2.7 to 1.0.0
- [Commits](https://github.com/rust-cli/anstyle/compare/anstyle-parse-v0.2.7...anstyle-parse-v1.0.0)

Updates `env_filter` from 1.0.0 to 1.0.1
- [Release notes](https://github.com/rust-cli/env_logger/releases)
- [Changelog](https://github.com/rust-cli/env_logger/blob/main/CHANGELOG.md)
- [Commits](https://github.com/rust-cli/env_logger/compare/env_filter-v1.0.0...env_filter-v1.0.1)

Updates `terminal_size` from 0.4.3 to 0.4.4
- [Release notes](https://github.com/eminence/terminal-size/releases)
- [Commits](https://github.com/eminence/terminal-size/compare/v0.4.3...v0.4.4)

Updates `toml_datetime` from 1.0.1+spec-1.1.0 to 1.1.0+spec-1.1.0
- [Commits](https://github.com/toml-rs/toml/compare/toml_datetime-v1.0.1...toml_datetime-v1.1.0)

Updates `toml_edit` from 0.25.5+spec-1.1.0 to 0.25.8+spec-1.1.0
- [Commits](https://github.com/toml-rs/toml/compare/v0.25.5...v0.25.8)

Updates `toml_parser` from 1.0.10+spec-1.1.0 to 1.1.0+spec-1.1.0
- [Commits](https://github.com/toml-rs/toml/compare/toml_parser-v1.0.10...toml_parser-v1.1.0)

Updates `windows-sys` from 0.60.2 to 0.61.2
- [Release notes](https://github.com/microsoft/windows-rs/releases)
- [Commits](https://github.com/microsoft/windows-rs/commits)

Updates `arc-swap` from 1.8.2 to 1.9.0
- [Changelog](https://github.com/vorner/arc-swap/blob/master/CHANGELOG.md)
- [Commits](https://github.com/vorner/arc-swap/compare/v1.8.2...v1.9.0)

Updates `toml_datetime` from 1.0.1+spec-1.1.0 to 1.1.0+spec-1.1.0
- [Commits](https://github.com/toml-rs/toml/compare/toml_datetime-v1.0.1...toml_datetime-v1.1.0)

Updates `toml_edit` from 0.25.5+spec-1.1.0 to 0.25.8+spec-1.1.0
- [Commits](https://github.com/toml-rs/toml/compare/v0.25.5...v0.25.8)

Updates `toml_parser` from 1.0.10+spec-1.1.0 to 1.1.0+spec-1.1.0
- [Commits](https://github.com/toml-rs/toml/compare/toml_parser-v1.0.10...toml_parser-v1.1.0)

---
updated-dependencies:
- dependency-name: env_logger
  dependency-version: 0.11.10
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: non-rust-vmm
- dependency-name: arc-swap
  dependency-version: 1.9.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: non-rust-vmm
- dependency-name: anstream
  dependency-version: 1.0.0
  dependency-type: indirect
  update-type: version-update:semver-major
  dependency-group: non-rust-vmm
- dependency-name: anstyle-parse
  dependency-version: 1.0.0
  dependency-type: indirect
  update-type: version-update:semver-major
  dependency-group: non-rust-vmm
- dependency-name: env_filter
  dependency-version: 1.0.1
  dependency-type: indirect
  update-type: version-update:semver-patch
  dependency-group: non-rust-vmm
- dependency-name: terminal_size
  dependency-version: 0.4.4
  dependency-type: indirect
  update-type: version-update:semver-patch
  dependency-group: non-rust-vmm
- dependency-name: toml_datetime
  dependency-version: 1.1.0+spec-1.1.0
  dependency-type: indirect
  update-type: version-update:semver-minor
  dependency-group: non-rust-vmm
- dependency-name: toml_edit
  dependency-version: 0.25.8+spec-1.1.0
  dependency-type: indirect
  update-type: version-update:semver-patch
  dependency-group: non-rust-vmm
- dependency-name: toml_parser
  dependency-version: 1.1.0+spec-1.1.0
  dependency-type: indirect
  update-type: version-update:semver-minor
  dependency-group: non-rust-vmm
- dependency-name: windows-sys
  dependency-version: 0.61.2
  dependency-type: indirect
  update-type: version-update:semver-minor
  dependency-group: non-rust-vmm
- dependency-name: arc-swap
  dependency-version: 1.9.0
  dependency-type: indirect
  update-type: version-update:semver-minor
  dependency-group: non-rust-vmm
- dependency-name: toml_datetime
  dependency-version: 1.1.0+spec-1.1.0
  dependency-type: indirect
  update-type: version-update:semver-minor
  dependency-group: non-rust-vmm
- dependency-name: toml_edit
  dependency-version: 0.25.8+spec-1.1.0
  dependency-type: indirect
  update-type: version-update:semver-patch
  dependency-group: non-rust-vmm
- dependency-name: toml_parser
  dependency-version: 1.1.0+spec-1.1.0
  dependency-type: indirect
  update-type: version-update:semver-minor
  dependency-group: non-rust-vmm
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-03-24 01:06:16 +00:00
Sebastian Eydam
5aeb9f55d1 virtio-devices: fix barrier handling in virtio-blk
When configuring multiple queues for a virtio device, the guest can
activate between 1 and the configured amount of queues. The firmware,
for example, may activate only one queue, while a Linux guest would
likely activate all available queues.

The constructor of virtio-blk initializes the `paused_sync` barrier
using the configured queue count (plus one for the main thread). This
can be wrong if the guest enable a different number of queues at
activation time, which can make pause hang. Thus, we now recompute the
barrier size from the queues that are actually activated.

On-behalf-of: SAP sebastian.eydam@sap.com
Signed-off-by: Sebastian Eydam <sebastian.eydam@cyberus-technology.de>
2026-03-23 14:04:58 +00:00
Sebastian Eydam
882f82f04b virtio-devices: fix barrier handling in virtio-net
When configuring multiple queues for a virtio device, the guest can
activate between 1 and the configured amout of queues. The firmware,
for example, may activate only one queue, while a Linux guest would
likely activate all available queues.

The constructor of virtio-net initializes the `paused_sync` barrier
using the configured queue count (plus one for the main thread). This
can be wrong if the guest enables a different number of queues at
activation time, which can make pause hang. Thus, we now recompute the
barrier size from the queues that are actually activated.

On-behalf-of: SAP sebastian.eydam@sap.com
Signed-off-by: Sebastian Eydam <sebastian.eydam@cyberus-technology.de>
2026-03-23 14:04:58 +00:00
Anatol Belski
92109136f1 block: Include actual segment count in TooManySegments error
Include the number of segments found in the request payload in
the TooManySegments error variant so the logged message shows
both the actual and maximum values.

Suggested-by: Philipp Schuster <philipp.schuster@cyberus-technology.de>
Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-03-23 13:27:20 +00:00
Anatol Belski
edfbb7e180 block: Add DISCARD_WZ_MAX_PAYLOAD constant
Introduce DISCARD_WZ_MAX_PAYLOAD as the precomputed product of
DISCARD_WZ_SEG_SIZE and MAX_DISCARD_WRITE_ZEROES_SEG. Use it in the
DISCARD and WRITE_ZEROES segment count checks instead of repeating
the multiplication inline.

Suggested-by: Philipp Schuster <philipp.schuster@cyberus-technology.de>
Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-03-23 13:27:20 +00:00
Julian Schindel
27a40ed32b ci: remove net_gen from allowed titles
On-behalf-of: SAP julian.schindel@sap.com
Signed-off-by: Julian Schindel <julian.schindel@cyberus-technology.de>
2026-03-23 12:50:38 +00:00
Julian Schindel
2b28c5b15a net_gen: replace net_gen with libc
The libc crate provides all functionality provided by the net_gen crate.
Removing the net_gen crate reduces the maintenance burden.

The switch to libc required some fixes, most notably the switch from a
`Vec<u8>` to a `CString` for the `net_util::Tap.if_name` field.

On-behalf-of: SAP julian.schindel@sap.com
Signed-off-by: Julian Schindel <julian.schindel@cyberus-technology.de>
2026-03-23 12:50:38 +00:00
Rob Bradford
3a56f20ee1 vmm: seccomp: Add readlink/readlinkat to vcpu filter
Now needed for IOMMU group resolution with VFIO.

Fixes: #7876

Signed-off-by: Rob Bradford <rbradford@meta.com>
2026-03-23 10:04:07 +00:00
Rob Bradford
e05065f509 build: Bump rust-vmm dependencies
Bump to the released versions that are compatible wherever possible but
for the vhost and vfio crates they are git hashes as no releases with
compatible versions have yet been made.

Signed-off-by: Rob Bradford <rbradford@meta.com>
2026-03-23 10:04:07 +00:00
Rob Bradford
4f52e9355e virtio-devices: seccomp: Allow fcntl unconditionally
This now required after Rust-VMM crate bumps. Also reorder some syscalls
so that they are now in alphabetical order.

Signed-off-by: Rob Bradford <rbradford@meta.com>
2026-03-23 10:04:07 +00:00
Anatol Belski
c79f3acfab block: Validate sector range for DISCARD and WRITE_ZEROES requests
Add range validation for DISCARD and WRITE_ZEROES, matching the
existing check in the read/write path. Per virtio spec section
5.2.6.1, a driver must not submit a request which would cause a
read or write beyond capacity. Use checked_add to guard against
overflow, then compare against disk_nsectors.

Without this, requests beyond device capacity pass through to the
host punch_hole/write_zeroes calls, relying on backend specific
behavior rather than returning VIRTIO_BLK_S_IOERR consistently.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-03-22 19:12:52 +00:00
Anatol Belski
d3cad420a5 block: Validate segment count for DISCARD and WRITE_ZEROES requests
Split the data length check into two conditions:

- reject descriptors shorter than one
virtio_blk_discard_write_zeroes segment, and
- reject payloads exceeding MAX_DISCARD_WRITE_ZEROES_SEG segments

Previously only the minimum length was checked and extra segments
were silently dropped.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-03-22 17:55:24 +00:00
Anatol Belski
fc79d08d7d block: qcow: Remove From<qcow::Error> for BlockError
All public qcow functions now return BlockResult with explicit error
classification at every site. The temporary From impl introduced in
the first commit of this series is no longer needed and is removed.

Internal functions in header.rs and the rebuild_refcounts helpers
stay on qcow::Result. Classification happens at the call site
boundary where qcow::Result meets BlockResult.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-03-20 22:21:24 +00:00
Anatol Belski
5410d4b2d5 block: qcow: Switch detect_image_type to BlockResult
Switch detect_image_type from qcow::Result to BlockResult with
explicit error classification at every I/O site. This is the last
function migrated before the From scaffolding can be removed.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-03-20 22:21:24 +00:00
Anatol Belski
9daf1782a8 block: qcow: Switch rebuild_refcounts to BlockResult
Switch rebuild_refcounts from qcow::Result to BlockResult. The
inner helper functions remain on qcow::Result since they are purely
internal, and are wrapped with map_err at each call site where they
cross the BlockResult boundary.

InvalidRefcountTableSize errors are classified as CorruptImage since
they indicate inconsistent internal refcount structures rather than
a format violation.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-03-20 22:21:24 +00:00
Anatol Belski
f6ec817b9b block: qcow: Switch resize and grow_l1_table to BlockResult
Switch resize and grow_l1_table from qcow::Result to BlockResult.
All I/O error sites use explicit BlockError::new with the Io kind.
The write_to call in grow_l1_table rewraps WritingHeader as
ResizeIo to preserve the existing error semantics.

The two resize tests that check for ShrinkNotSupported and
ResizeWithBackingFile are updated to match on BlockErrorKind with
downcast to inspect the underlying variant.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-03-20 22:21:24 +00:00
Anatol Belski
524e620240 block: qcow: Classify errors in parse_qcow and BackingFile::new
Replace remaining automatic From conversions in parse_qcow and
BackingFile::new with explicit BlockError::new calls carrying the
appropriate BlockErrorKind at every error site.

Internal functions that still return qcow::Result (QcowHeader::new,
offset_is_cluster_boundary, clear_autoclear_features and others) are
wrapped with map_err at the boundary. These functions stay on
qcow::Result as they are internal to the qcow module and the
classification belongs at the call site rather than inside the
function itself.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-03-20 22:21:24 +00:00
Anatol Belski
be9ef116aa block: qcow: Switch parse_qcow and BackingFile::new to BlockResult
Switch parse_qcow and BackingFile::new from qcow::Result to
BlockResult. Every early return site now produces an explicit
BlockError with the appropriate kind. Remaining internal calls to
functions still on qcow::Result rely on the From scaffolding and
will be converted in subsequent commits.

Two helpers are added to BlockError. with_kind replaces the
classification on an existing error, used in QcowDiskSync::new to
avoid double wrapping when the caller needs a different kind.
into_source consumes the error and returns the boxed source, used
at the recursive BackingFile open to extract the qcow::Error for
BackingFileOpen without letting qcow::Error hold a BlockError.

The qcow_sync boundary is simplified to a single closure that
operates on the BlockError already returned by parse_qcow.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-03-20 22:21:24 +00:00
Anatol Belski
c4a5c7f843 block: qcow: Switch QcowFile constructors to BlockResult
Switch the public QcowFile constructors (new, new_from_backing,
new_from_header, from, from_backing, from_file_and_header) from
qcow::Result to BlockResult. Internal calls to header functions
that still return qcow::Result are wrapped with explicit error
classification at each call site.

Test assertions are updated to match on BlockErrorKind and use
downcast to inspect the underlying qcow::Error variant.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-03-20 22:21:24 +00:00
Anatol Belski
d77e3e7ca2 block: qcow: Add From<qcow::Error> for BlockError
Temporary From impl that classifies each qcow::Error variant into
the appropriate BlockErrorKind. This enables an incremental migration
of qcow functions from qcow::Result to BlockResult, where each
subsequent commit replaces bare ? sites with explicit BlockError::new
calls until this impl can be removed.

The mapping assigns InvalidFormat for structural header violations,
UnsupportedFeature for version and feature mismatches, CorruptImage
for internal inconsistencies, Overflow for nesting depth and Io for
everything else.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-03-20 22:21:24 +00:00
Muminul Islam
0c3249b14f tests: split integration helpers into common modules
Move shared integration test logic out of tests/integration.rs.
Add tests/common/{mod.rs,tests_wrappers.rs,utils.rs} and migrate
API, VM lifecycle, disk/net, and utility helpers.

Update integration.rs to import common modules and keep test
entrypoints thin.

Benefits:
 Reduces integration.rs size and duplication
 Groups reusable helpers by role
 Improves readability and future maintenance

Fixes: https://github.com/cloud-hypervisor/cloud-hypervisor/issues/7808

Signed-off-by: Muminul Islam <muislam@microsoft.com>
2026-03-20 22:06:11 +00:00
Wei Liu
43642d8df8 tests: Make test_virtio_mmu more flexible
We only verify devices are under some group but not which one.

With the change, the acpi variable is only needed for aarch64. Add an
underscore prefix to avoid a compilation warning on x86_64.

Signed-off-by: Wei Liu <liuwe@microsoft.com>
2026-03-19 23:11:17 +00:00
Wei Liu
6e6127bbda tests: Make test_vdpa_block more flexible
We only care that the device exists under an IOMMU group but not which
one.

Signed-off-by: Wei Liu <liuwe@microsoft.com>
2026-03-19 23:11:17 +00:00
Wei Liu
5724a0189c tests: Make the IOMMU segment test case more flexible
Linux kernel's behavior changes overtime. The grouping can be different
across different versions and different architectures.

We only cares about the exact SBDF exists somewhere. It doesn't matter
which group it is under.

Change the check so that this test case is no longer tied to the
grouping behavior of a particular kernel.

Signed-off-by: Wei Liu <liuwe@microsoft.com>
2026-03-19 23:11:17 +00:00
Anatol Belski
0d062962ac block: qcow: Remove async_io::DiskFile impl from QcowDiskSync
QcowDiskSync now exclusively uses disk_file::DiskFile and
disk_file::AsyncDiskFile. The old async_io::DiskFile impl is removed
along with its unused imports (DiskFile, DiskFileError, DiskFileResult).

Tests are updated to import the new traits.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-03-19 22:29:27 +00:00
Anatol Belski
b4dad66d35 virtio-devices: vmm: fuzz: Switch to DiskBackend
Change Block to hold DiskBackend instead of
Box<dyn async_io::DiskFile>. In device_manager, existing formats
(raw, vhd, vhdx) are wrapped in DiskBackend::Legacy while
QcowDiskSync uses DiskBackend::Next. The fuzz target is updated
accordingly.

The Error::DiskResize variant now carries BlockError instead of
DiskFileError, matching the BlockResult return type of
DiskBackend::resize().

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-03-19 22:29:27 +00:00
Anatol Belski
264013b424 block: disk_file: Add DiskBackend dispatch enum
Introduce DiskBackend with two variants:
- Legacy: wraps Box<dyn async_io::DiskFile> for existing formats
- Next: wraps Box<dyn disk_file::AsyncFullDiskFile>

Methods return BlockResult, with DiskFileError converted up to
BlockError on the Legacy path. The Next path passes through
directly with zero conversion overhead.

This is a transitional type. Once all formats implement
AsyncFullDiskFile, DiskBackend and Legacy are removed and
callers hold Box<dyn AsyncFullDiskFile> directly.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-03-19 22:29:27 +00:00
Anatol Belski
fe6e3e8fef block: qcow_sync: impl AsyncDiskFile for QcowDiskSync
Implement try_clone by sharing the metadata Arc and cloning the data
file descriptor. The new_async_io method creates a QcowSync worker
identical to the async_io::DiskFile version.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-03-19 22:29:27 +00:00
Anatol Belski
1fc8e4adb6 block: qcow_sync: impl DiskFile for QcowDiskSync
Marker impl binding the DiskSize and HasTopology supertraits.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-03-19 22:29:27 +00:00
Anatol Belski
f35bec19e8 block: qcow_sync: impl Resizable for QcowDiskSync
Add ErrorOp::Resize variant and implement the Resizable trait.
Resize is rejected when a backing file is present.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-03-19 22:29:27 +00:00
Anatol Belski
554562fef2 block: qcow_sync: impl SparseCapable for QcowDiskSync
Advertise support for sparse operations and the zero flag. QCOW2
inherently supports both through cluster deallocation.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-03-19 22:29:27 +00:00
Anatol Belski
63f5e6e97f block: qcow_sync: impl Geometry for QcowDiskSync
Uses the default DiskTopology (512B logical/physical) since
QCOW2 does not probe the underlying device geometry.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-03-19 22:29:27 +00:00
Anatol Belski
b305a7670b block: qcow_sync: impl DiskFd for QcowDiskSync
Borrows the raw file descriptor from the underlying QcowRawFile
for fcntl() operations. Uses &self for shared access.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-03-19 22:29:27 +00:00
Anatol Belski
4b731ee771 block: qcow_sync: impl PhysicalSize for QcowDiskSync
Delegate to QcowRawFile::physical_size() which returns the actual
host allocation size of the QCOW2 container file.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-03-19 22:29:27 +00:00
Anatol Belski
0a7b6b089b block: qcow_sync: impl DiskSize for QcowDiskSync
Delegate to QcowMetadata::virtual_size() which returns the guest
visible capacity stored in the QCOW2 header.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-03-19 22:29:27 +00:00
Anatol Belski
ad789024f9 block: qcow_sync: Add Debug impl for QcowDiskSync
The new composable traits require Debug. Implement it manually since
QcowMetadata contains RwLock state that cannot auto derive.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-03-19 22:29:27 +00:00
Anatol Belski
dac8707c35 block: disk_file: Add AsyncFullDiskFile trait
Marker trait combining FullDiskFile and AsyncDiskFile. Blanket impl
covers any type implementing both supertraits.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-03-19 22:29:27 +00:00
Anatol Belski
8623edb8aa block: disk_file: Add FullDiskFile trait
Marker trait bundling all optional capabilities (PhysicalSize, DiskFd,
SparseCapable, Resizable) on top of DiskFile. Blanket impl covers any
type implementing all constituent traits.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-03-19 22:29:27 +00:00
Anatol Belski
50741cca2a block: disk_file: Add AsyncDiskFile trait
Extend DiskFile with async I/O construction for virtio queue workers.

AsyncDiskFile adds try_clone() for creating independent handles to
the same backing storage, and new_async_io() for constructing an
async I/O engine at the given ring depth.

Bounds: DiskFile + Unpin. Unpin ensures trait objects can be moved
freely (all concrete disk file types are naturally Unpin since they
hold no self referential state).

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-03-19 22:29:27 +00:00
Anatol Belski
5d50d64671 block: disk_file: Add DiskFile supertrait
Bundles DiskSize and Geometry as the universal disk
capabilities every format must implement. Adds Sync so
that Arc<dyn DiskFile> can be shared across threads for
concurrent readonly access.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-03-19 22:29:27 +00:00
Anatol Belski
da1b104493 block: disk_file: Add Resizable trait
Live disk resize support. Single method resize() taking
&mut self and the new size in bytes. Implementations may
return an error if the backend does not support resizing.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-03-19 22:29:27 +00:00
Anatol Belski
a0a5718b42 block: disk_file: Add SparseCapable trait
Sparse and zero flag support for thin provisioned disk
images. Two methods with false defaults: sparse operations
(punch hole, write zeroes, discard) and zero flag
optimization in WRITE_ZEROES.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-03-19 22:29:27 +00:00
Anatol Belski
b98a5cc58d block: disk_file: Add Geometry trait
Sector and cluster geometry of a disk image. Returns
DiskTopology with a default implementation providing
512B logical and physical block sizes. Formats that
probe the underlying device override this.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-03-19 22:29:27 +00:00
Anatol Belski
2fa877e087 block: disk_file: Add DiskFd trait
Backing file descriptor access for disk images backed by
a file. Returns a BorrowedDiskFd that wraps the raw fd
with lifetime tracking. Not available for network or
memory backed disk formats.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-03-19 22:29:27 +00:00
Anatol Belski
2df731b8d3 block: disk_file: Add PhysicalSize trait
Host allocation size for file-backed disk images. Reports
actual bytes occupied on the host filesystem. Not every
format supports this, e.g. network or memory backed disks.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-03-19 22:29:27 +00:00
Anatol Belski
85e4e5027c block: disk_file: Add DiskSize trait
Reported capacity of a disk image. Every format, be it
file backed, network, memory, exposes a logical size.
Single method logical_size() returning the virtual size
in bytes.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-03-19 22:29:27 +00:00
Anatol Belski
a15bfcfee6 block: Add disk_file module skeleton
Composable disk capability traits with DiskFile as a supertrait
bundling DiskSize and Geometry. Optional capabilities are
separate traits: PhysicalSize, DiskFd, SparseCapable, Resizable.
AsyncDiskFile extends DiskFile with async I/O construction.

Empty module with doc comment, trait definitions follow.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-03-19 22:29:27 +00:00
Muminul Islam
297b683fcb tests: Add virtio block tests for confidential VMs
Add a full suite of test_virtio_block_* tests to the common_cvm
integration test module to verify virtio block functionality in
confidential guest environments.

The following tests are added, all using 4-vCPU confidential
VMs created via GuestFactory:
- test_virtio_block_io_uring (Raw image, io_uring backend)
- test_virtio_block_aio (Raw image, AIO backend)
- test_virtio_block_sync (Raw image, sync backend)
- test_virtio_block_qcow2 (QCOW2 image)
- test_virtio_block_qcow2_zlib (QCOW2 with zlib compression)
- test_virtio_block_qcow2_zstd (QCOW2 with zstd compression)
- test_virtio_block_qcow2_backing_zstd_file
- test_virtio_block_qcow2_backing_uncompressed_file
- test_virtio_block_qcow2_backing_raw_file

This extends CVM test coverage to all virtio block I/O backends
and disk image formats.

Signed-off-by: Muminul Islam <muislam@microsoft.com>
2026-03-19 16:17:28 +00:00
Muminul Islam
ec730fde21 tests: Refactor _test_virtio_block and utilities to module scope
Move _test_virtio_block to module-level scope, accepting a
Guest reference instead of an image name string. Replace
hardcoded CPU, kernel, and cmdline arguments with default_cpus
and default_kernel_cmdline.

Promote all supporting disk utilities to module-level scope:
compute_backing_checksum, disk_check_consistency, run_qemu_img,
get_image_info, get_qcow2_v3_info, check_dirty_flag,
check_corrupt_flag, set_corrupt_flag, resolve_disk_path, and
compute_file_checksum.

Update all test_virtio_block_* call sites in common_parallel
to create guests via GuestFactory::new_regular_guest_factory()
with 4 vCPUs and pass them to the helper. This enables reuse
with different guest types such as confidential VMs.

Signed-off-by: Muminul Islam <muislam@microsoft.com>
2026-03-19 16:17:28 +00:00
Muminul Islam
af4a14fa70 tests: Add direct kernel boot test for confidential VMs
Add test_direct_kernel_boot to the common_cvm integration test
module to verify that boot, CPU, memory, and MSI interrupt
functionality work correctly in confidential guest environments.

The test creates an Ubuntu Jammy-based confidential VM using
GuestFactory and delegates to the existing
_test_direct_kernel_boot helper.

Signed-off-by: Muminul Islam <muislam@microsoft.com>
2026-03-19 16:17:28 +00:00