block: qcow: support opening backing files

This commit allows opening qcow with a backing file, which supports any
type implementing `BlockBackend`.

This commit is based on crosvm implementation:
https://chromium.googlesource.com/crosvm/crosvm/+/9ca6039b030a5c83062cfec9a5ff52f42814fa13

Signed-off-by: Yu Li <liyu.yukiteru@bytedance.com>
This commit is contained in:
Yu Li
2023-07-05 14:17:50 +08:00
committed by Rob Bradford
parent ffe78c98fd
commit 081a6ebb51
2 changed files with 167 additions and 31 deletions
+8
View File
@@ -23,6 +23,7 @@ pub struct RawFile {
file: File,
alignment: usize,
position: u64,
direct_io: bool,
}
const BLK_ALIGNMENTS: [usize; 2] = [512, 4096];
@@ -65,6 +66,7 @@ impl RawFile {
file,
alignment,
position: 0,
direct_io,
}
}
@@ -103,6 +105,7 @@ impl RawFile {
file: self.file.try_clone().expect("RawFile cloning failed"),
alignment: self.alignment,
position: self.position,
direct_io: self.direct_io,
})
}
@@ -113,6 +116,10 @@ impl RawFile {
pub fn sync_data(&self) -> std::io::Result<()> {
self.file.sync_data()
}
pub fn is_direct(&self) -> bool {
self.direct_io
}
}
impl Read for RawFile {
@@ -356,6 +363,7 @@ impl Clone for RawFile {
file: self.file.try_clone().expect("RawFile cloning failed"),
alignment: self.alignment,
position: self.position,
direct_io: self.direct_io,
}
}
}