Skip to content

Commit

Permalink
Disable copy-on-write for qcow2 images. quickemu-project/quickemu#1228
Browse files Browse the repository at this point in the history
Also, disable unsupported lazy_refcounts for non-qcow2 images
  • Loading branch information
lj3954 committed May 21, 2024
1 parent 4a2b71e commit 4aec7cf
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
14 changes: 9 additions & 5 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -317,12 +317,16 @@ pub enum PreAlloc {
Full,
}
impl PreAlloc {
pub fn qemu_arg(&self) -> &'static str {
pub fn qemu_arg(&self, is_qcow2: bool) -> &'static str {
match self {
Self::Off => "lazy_refcounts=on,preallocation=off",
Self::Metadata => "lazy_refcounts=on,preallocation=metadata",
Self::Falloc => "lazy_refcounts=on,preallocation=falloc",
Self::Full => "lazy_refcounts=on,preallocation=full",
Self::Off if is_qcow2 => "lazy_refcounts=on,preallocation=off,nocow=on",
Self::Off => "preallocation=off",
Self::Metadata if is_qcow2 => "lazy_refcounts=on,preallocation=metadata,nocow=on",
Self::Metadata => "preallocation=metadata",
Self::Falloc if is_qcow2 => "lazy_refcounts=on,preallocation=falloc,nocow=on",
Self::Falloc => "preallocation=falloc",
Self::Full if is_qcow2 => "lazy_refcounts=on,preallocation=full,nocow=on",
Self::Full => "preallocation=full"
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/qemu_args/images.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub fn image_args(vm_dir: &Path, images: Option<Vec<Image>>, disks: Vec<DiskImag
let disk_format = disk_format(&disk.path.to_string_lossy(), &disk.preallocation)?;
let size = disk.size.unwrap_or(guest_os.disk_size());
let creation = Command::new(&qemu_img)
.args(["create", "-q", "-f", disk_format, "-o", disk.preallocation.qemu_arg()])
.args(["create", "-q", "-f", disk_format, "-o", disk.preallocation.qemu_arg(disk_format == "qcow2")])
.arg(&disk.path)
.arg(size.to_string())
.output().map_err(|e| anyhow!("Could not launch qemu-img to create disk image {}: {}", &disk.path.display(), e))?;
Expand Down

0 comments on commit 4aec7cf

Please sign in to comment.