block: vhd: Enable O_DIRECT for fixed VHD images

Thread the direct flag from the disk open options through VhdDisk into
the AlignedFile the workers run on, so a fixed VHD opened with direct=on
issues O_DIRECT I/O instead of buffered I/O. Alignment is probed once on
that AlignedFile and reused by the sync and io_uring workers.

Advertise host topology from VhdDisk::topology by probing the underlying
file. On a 4096 byte sector filesystem opened with O_DIRECT this reports
logical_block_size 4096 to the guest, so the guest never issues 512 byte
I/O that the host kernel would reject as misaligned. Falls back to the
default topology with a warning when the probe fails.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
This commit is contained in:
Anatol Belski
2026-06-19 22:00:21 +02:00
committed by Rob Bradford
parent 693987b9e2
commit 6633072a28
2 changed files with 24 additions and 13 deletions

View File

@@ -127,7 +127,7 @@ fn open_fixed_vhd(
if io_uring_supported() {
info!("Opening fixed VHD disk file with io_uring backend");
return Ok(Box::new(
VhdDisk::new(file, true).map_err(|e| e.with_path(options.path))?,
VhdDisk::new(file, true, options.direct).map_err(|e| e.with_path(options.path))?,
));
}
info!("io_uring runtime probe failed for fixed VHD, using synchronous backend");
@@ -135,7 +135,7 @@ fn open_fixed_vhd(
info!("Opening fixed VHD disk file with synchronous backend");
Ok(Box::new(
VhdDisk::new(file, false).map_err(|e| e.with_path(options.path))?,
VhdDisk::new(file, false, options.direct).map_err(|e| e.with_path(options.path))?,
))
}