Commit Graph

366 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
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
Muminul Islam
f6b4061629 block: Return BlockResult from RawFileAsyncAio::new()
Change the return type of RawFileAsyncAio::new() from
std::io::Result<Self> to BlockResult<Self>, wrapping
internal errors from EventFd::new() and IoContext::new()
in BlockError with DiskFileError::NewAsyncIo.

This simplifies the caller in AsyncDiskFile::new_async_io()
which no longer needs its own error mapping.

Signed-off-by: Muminul Islam <muislam@microsoft.com>
2026-04-02 01:18:30 +00:00
Muminul Islam
783cc8bbd9 block: Remove legacy DiskFile impl from RawFileDiskAio
Remove the old async_io::DiskFile trait implementation from
RawFileDiskAio, now that the new disk_file trait hierarchy
is fully implemented.

Clean up unused imports: DiskFile and DiskFileResult from
crate::async_io.

Signed-off-by: Muminul Islam <muislam@microsoft.com>
2026-04-02 01:18:30 +00:00
Muminul Islam
6df7cda4ad block: Implement AsyncDiskFile trait for RawFileDiskAio
Add disk_file::AsyncDiskFile trait implementation for
RawFileDiskAio with try_clone() and new_async_io() methods.

try_clone() duplicates the underlying file descriptor and
wraps it in a new RawFileDiskAio. new_async_io() creates a
RawFileAsyncAio (Linux AIO) backend, wrapping errors in
BlockError instead of DiskFileError.

Signed-off-by: Muminul Islam <muislam@microsoft.com>
2026-04-02 01:18:30 +00:00
Muminul Islam
39bbbaaa59 block: Implement DiskFile marker trait for RawFileDiskAio
Add empty disk_file::DiskFile impl for RawFileDiskAio.
This marker supertrait requires DiskSize + Geometry + Sync,
all of which are now satisfied.

Signed-off-by: Muminul Islam <muislam@microsoft.com>
2026-04-02 01:18:30 +00:00
Muminul Islam
62264cb3c7 block: Implement Resizable trait for RawFileDiskAio
Add disk_file::Resizable trait implementation for
RawFileDiskAio. Calls file.set_len(size) and wraps the
I/O error in BlockError on failure.

Signed-off-by: Muminul Islam <muislam@microsoft.com>
2026-04-02 01:18:30 +00:00
Muminul Islam
b7cf8737ac block: Implement SparseCapable trait for RawFileDiskAio
Add disk_file::SparseCapable trait implementation for
RawFileDiskAio. Delegates to probe_sparse_support() to
detect whether the underlying file supports hole-punching.

Signed-off-by: Muminul Islam <muislam@microsoft.com>
2026-04-02 01:18:30 +00:00
Muminul Islam
190380c9ba block: Implement Geometry trait for RawFileDiskAio
Add disk_file::Geometry trait implementation for
RawFileDiskAio. Probes disk topology from the file,
falling back to defaults on failure. Takes &self instead
of &mut self and uses unwrap_or_else for cleaner error
handling.

Signed-off-by: Muminul Islam <muislam@microsoft.com>
2026-04-02 01:18:30 +00:00
Muminul Islam
df890599c2 block: Implement DiskFd trait for RawFileDiskAio
Add disk_file::DiskFd trait implementation for
RawFileDiskAio. Delegates to file.as_raw_fd() via
BorrowedDiskFd, taking &self instead of &mut self.

Signed-off-by: Muminul Islam <muislam@microsoft.com>
2026-04-02 01:18:30 +00:00
Muminul Islam
78bbdbef86 block: Implement PhysicalSize trait for RawFileDiskAio
Add disk_file::PhysicalSize trait implementation for
RawFileDiskAio. Returns the physical size from
query_device_size wrapped in BlockError on failure,
consistent with the DiskSize impl.

Signed-off-by: Muminul Islam <muislam@microsoft.com>
2026-04-02 01:18:30 +00:00
Muminul Islam
fca54cb142 block: Implement DiskSize trait for RawFileDiskAio
Add disk_file::DiskSize trait implementation for
RawFileDiskAio using BlockError and BlockResult. Takes
&self instead of &mut self.

Add BlockError, BlockErrorKind, BlockResult, and disk_file
imports needed by this and subsequent trait impls.

Signed-off-by: Muminul Islam <muislam@microsoft.com>
2026-04-02 01:18:30 +00:00
Muminul Islam
98dbe6d128 block: Derive Debug on RawFileDiskAio
Add #[derive(Debug)] to RawFileDiskAio. This is required
by the new disk_file traits which have Send + Debug bounds.

Signed-off-by: Muminul Islam <muislam@microsoft.com>
2026-04-02 01:18:30 +00:00
Anatol Belski
9f980969fc block: Add UnsupportedFlags error variant for flag validation
Introduce ExecuteError::UnsupportedFlags to carry both the
request type and the rejected flags value, replacing the
generic ExecuteError::Unsupported at discard and write zeroes
flag validation sites. This provides structured context for
debugging without changing the returned VIRTIO_BLK_S_UNSUPP
status.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-03-31 23:07:26 +00:00
Anatol Belski
8ca5210603 block: Reject write zeroes with unknown flags
The virtio spec v1.2 in 5.2.6.2 requires that the device
MUST return VIRTIO_BLK_S_UNSUPP for write zeroes commands
if any unknown flag is set.

Add an early check that rejects requests with reserved flag
bits set by returning VIRTIO_BLK_S_UNSUPP via the existing
ExecuteError::Unsupported variant.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-03-31 18:54:19 +00:00
Anatol Belski
af1d69a9dd block: Reject discard requests with flags set
The virtio spec v1.2 in 5.2.6.2 requires that the device
MUST return VIRTIO_BLK_S_UNSUPP for discard commands if the
unmap flag is set or if any unknown flag is set.

The discard handler was not reading the flags field at all,
silently accepting requests with arbitrary flags. Read and
validate the flags, rejecting any non-zero value with
VIRTIO_BLK_S_UNSUPP.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-03-31 13:11:15 +00:00
Anatol Belski
5ca6ff869f block: vhd: Remove legacy async_io::DiskFile impl from FixedVhdDiskSync
No remaining consumers after switching to DiskBackend::Next.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-03-30 22:18:09 +00:00
Anatol Belski
cc2f878094 block: vhd: impl AsyncDiskFile for FixedVhdDiskSync
Delegate try_clone() to FixedVhd::clone() and new_async_io() to
FixedVhdSync, preserving DiskFileError::NewAsyncIo.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-03-30 22:18:09 +00:00
Anatol Belski
ce1592d1df block: vhd: impl DiskFile for FixedVhdDiskSync
Marker impl bundling DiskSize and Geometry supertraits.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-03-30 22:18:09 +00:00
Anatol Belski
60af47c99b block: vhd: impl Resizable for FixedVhdDiskSync
Fixed VHD does not support resize, return UnsupportedFeature.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-03-30 22:18:09 +00:00
Anatol Belski
74b0613c04 block: vhd: impl SparseCapable for FixedVhdDiskSync
Fixed VHD does not support sparse operations.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-03-30 22:18:09 +00:00
Anatol Belski
1a56cb3d0e block: vhd: impl Geometry for FixedVhdDiskSync
Use default DiskTopology with 512byte sectors.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-03-30 22:18:09 +00:00
Anatol Belski
dfa9a25fd8 block: vhd: impl DiskFd for FixedVhdDiskSync
Delegate to FixedVhd::as_raw_fd() for the backing file descriptor.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-03-30 22:18:09 +00:00
Anatol Belski
266c5fc241 block: vhd: impl PhysicalSize for FixedVhdDiskSync
Delegate to FixedVhd::physical_size() which calls file.metadata().
Preserve the crate::Error::GetFileMetadata variant as the BlockError
source for diagnostic chain traversal.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-03-30 22:18:09 +00:00
Anatol Belski
7136744549 block: vhd: impl DiskSize for FixedVhdDiskSync
Delegate to FixedVhd::logical_size() which returns the guest
visible capacity parsed from the VHD footer at construction.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-03-30 22:18:09 +00:00
Anatol Belski
24e9049280 block: vhd: Switch FixedVhdDiskSync::new to BlockResult
Classify the io::Error as BlockErrorKind::Io with ErrorOp::Open.
Update vmm CreateFixedVhdDiskSync to take BlockError.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-03-30 22:18:09 +00:00
Anatol Belski
6e36932e90 block: vhdx: Remove legacy async_io::DiskFile impl from VhdxDiskSync
All functionality now provided by composable disk_file traits.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-03-30 22:17:01 +00:00