From 4d30ba12c8b2269e65fe31168e63ea1db065b9e8 Mon Sep 17 00:00:00 2001 From: Anatol Belski Date: Thu, 19 Feb 2026 11:27:35 +0100 Subject: [PATCH] block: qcow: Add test for BackingFilesDisabled error Verify that opening a QCOW2 image with a backing file reference through QcowDiskSync with backing_files=off produces the user-facing BackingFilesDisabled error rather than MaxNestingDepthExceeded. Signed-off-by: Anatol Belski --- block/src/qcow_sync.rs | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/block/src/qcow_sync.rs b/block/src/qcow_sync.rs index d4dfc9b78..2707f5dfb 100644 --- a/block/src/qcow_sync.rs +++ b/block/src/qcow_sync.rs @@ -229,7 +229,7 @@ mod unit_tests { use vmm_sys_util::tempfile::TempFile; use super::*; - use crate::qcow::{QcowFile, RawFile}; + use crate::qcow::{QcowFile, QcowHeader, RawFile}; #[test] fn test_qcow_async_punch_hole_completion() { @@ -482,4 +482,23 @@ mod unit_tests { "After punch_hole via new_async_io, read should return zeros" ); } + + #[test] + fn backing_files_disabled_error() { + let header = + QcowHeader::create_for_size_and_path(3, 0x10_0000, Some("/path/to/backing/file")) + .expect("Failed to create header."); + let temp_file = TempFile::new().unwrap(); + let mut raw_file = RawFile::new(temp_file.as_file().try_clone().unwrap(), false); + header + .write_to(&mut raw_file) + .expect("Failed to write header."); + + let file = temp_file.into_file(); + match QcowDiskSync::new(file, false, false, true) { + Err(QcowError::BackingFilesDisabled) => {} + Err(other) => panic!("Expected BackingFilesDisabled, got: {other:?}"), + Ok(_) => panic!("Expected BackingFilesDisabled error, but succeeded"), + } + } }