block: aligned: Add seeking cursor and drop RawFile

RawFile wrapped AlignedFile only to add a seek position and the file
trait impls that the qcow and vhost_user_block code expects. Fold that
position and every impl onto AlignedFile so the wrapper layer goes away
and callers work with a single O_DIRECT aware file type.

AlignedFile now tracks a cursor and implements Read, Write, Seek,
WriteZeroesAt, PunchHole, FileSync, SeekHole, BlockBackend, Clone,
AsRawFd and AsFd in addition to the positional FileExt path. The
direct_io flag is dropped because alignment already encodes it, where
a zero alignment means the file was not opened with O_DIRECT.

All RawFile uses in the qcow internals and vhost_user_block move to
AlignedFile, and raw_file.rs is removed.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
This commit is contained in:
Anatol Belski
2026-06-19 20:39:33 +02:00
committed by Rob Bradford
parent 4c7e2b83c1
commit 516f4e447d
9 changed files with 292 additions and 364 deletions

View File

@@ -19,8 +19,7 @@ use std::sync::{Arc, Mutex, RwLock, RwLockWriteGuard};
use std::time::Instant;
use std::{convert, io, process, result};
use block::formats::qcow::internal::RawFile;
use block::{Request, RequestType, VirtioBlockConfig, build_serial};
use block::{AlignedFile, Request, RequestType, VirtioBlockConfig, build_serial};
use libc::EFD_NONBLOCK;
use log::{debug, error, info, warn};
use option_parser::{OptionParser, OptionParserError, Toggle};
@@ -85,7 +84,7 @@ impl convert::From<Error> for io::Error {
}
struct VhostUserBlkThread {
disk_image: Arc<Mutex<RawFile>>,
disk_image: Arc<Mutex<AlignedFile>>,
serial: Vec<u8>,
disk_nsectors: u64,
event_idx: bool,
@@ -96,7 +95,7 @@ struct VhostUserBlkThread {
impl VhostUserBlkThread {
fn new(
disk_image: Arc<Mutex<RawFile>>,
disk_image: Arc<Mutex<AlignedFile>>,
serial: Vec<u8>,
disk_nsectors: u64,
writeback: Arc<AtomicBool>,
@@ -230,7 +229,7 @@ impl VhostUserBlkBackend {
options.custom_flags(libc::O_DIRECT);
}
let image: File = options.open(image_path).unwrap();
let raw_img = RawFile::new(image, direct);
let raw_img = AlignedFile::new(image, direct);
let serial = build_serial(&PathBuf::from(&image_path));
let image = Arc::new(Mutex::new(raw_img));