vm-virtio: block: Add support for alignment restrictions

Doing I/O on an image opened with O_DIRECT requires to adhere to
certain restrictions, requiring the following elements to be aligned:

 - Address of the source/destination memory buffer.
 - File offset.
 - Length of the data to be read/written.

The actual alignment value depends on various elements, and according
to open(2) "(...) there is currently no filesystem-independent
interface for an application to discover these restrictions (...)".

To discover such value, we iterate through a list of alignments
(currently, 512 and 4096) calling pread() with each one and checking
if the operation succeeded.

We also extend RawFile so it can be used as a backend for QcowFile,
so the later can be easily adapted to support O_DIRECT too.

Signed-off-by: Sergio Lopez <slp@redhat.com>
This commit is contained in:
Sergio Lopez
2020-01-13 14:10:51 +01:00
committed by Rob Bradford
parent e483cde1bb
commit c5a656c9dc
3 changed files with 286 additions and 15 deletions

View File

@@ -937,7 +937,7 @@ impl DeviceManager {
.map_err(DeviceManagerError::DetectImageType)?;
match image_type {
ImageType::Raw => {
let raw_img = vm_virtio::RawFile::new(raw_img);
let raw_img = vm_virtio::RawFile::new(raw_img, false);
let dev = vm_virtio::Block::new(
raw_img,
disk_cfg.path.clone(),