Check autoclear setup using block sysfs
Instead of checking the loop device size, to avoid flakiness when the
loop device doesn't self-distruct by that time.
Bug: 291169704
Test: atest libdm_rust.test
Change-Id: I122bc5b82d858ef35ba7f3123cf925532ac1b2c3
diff --git a/libs/devicemapper/src/loopdevice.rs b/libs/devicemapper/src/loopdevice.rs
index b830eda..30ab6f6 100644
--- a/libs/devicemapper/src/loopdevice.rs
+++ b/libs/devicemapper/src/loopdevice.rs
@@ -199,6 +199,12 @@
"0" == fs::read_to_string(ro).unwrap().trim()
}
+ fn is_autoclear(dev: &Path) -> bool {
+ let autoclear =
+ Path::new("/sys/block").join(dev.file_name().unwrap()).join("loop/autoclear");
+ "1" == fs::read_to_string(autoclear).unwrap().trim()
+ }
+
#[rdroidtest]
fn attach_loop_device_with_dio() {
let a_dir = tempfile::TempDir::new().unwrap();
@@ -258,10 +264,7 @@
let dev =
attach(a_file, 0, a_size, &LoopConfigOptions { autoclear: true, ..Default::default() })
.unwrap();
- drop(dev.file);
- let dev_size_path =
- Path::new("/sys/block").join(dev.path.file_name().unwrap()).join("size");
- assert_eq!("0", fs::read_to_string(dev_size_path).unwrap().trim());
+ assert!(is_autoclear(&dev.path));
}
}