mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
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:
committed by
Rob Bradford
parent
4c7e2b83c1
commit
516f4e447d
@@ -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));
|
||||
|
||||
Reference in New Issue
Block a user