Skip to content

Commit 2052ecc

Browse files
committed
Add integration test for fully disabling udev synchronization
Add sudo_test_no_udev_device_lifecycle that simulates the dm-verity device creation flow with all DM_UDEV_DISABLE_* flags set: device_create -> table_load -> device_suspend(resume) -> device_info -> device_remove. It validates the end-to-end integration of the UdevSync::begin() reordering and do_ioctl() event_nr clearing changes, ensuring DM operations work correctly in no-udev environments. Signed-off-by: Alex Lyn <alex.lyn@antgroup.com>
1 parent 7efd063 commit 2052ecc

1 file changed

Lines changed: 62 additions & 0 deletions

File tree

‎src/core/dm.rs‎

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1153,4 +1153,66 @@ mod tests {
11531153
dm.device_remove(&DevId::Name(&name), DmOptions::default())
11541154
.unwrap();
11551155
}
1156+
1157+
use crate::core::dm_flags::DmUdevFlags;
1158+
1159+
/// Build DmOptions that fully disable udev synchronization.
1160+
/// Setting all DM_UDEV_DISABLE_* flags together with DM_UDEV_DISABLE_LIBRARY_FALLBACK
1161+
/// tells the kernel and the UdevSync layer to skip udev cookie handling entirely.
1162+
fn no_udev_dm_options() -> DmOptions {
1163+
DmOptions::default().set_udev_flags(
1164+
DmUdevFlags::DM_UDEV_DISABLE_LIBRARY_FALLBACK
1165+
| DmUdevFlags::DM_UDEV_DISABLE_SUBSYSTEM_RULES_FLAG
1166+
| DmUdevFlags::DM_UDEV_DISABLE_DISK_RULES_FLAG
1167+
| DmUdevFlags::DM_UDEV_DISABLE_OTHER_RULES_FLAG
1168+
| DmUdevFlags::DM_UDEV_DISABLE_DM_RULES_FLAG,
1169+
)
1170+
}
1171+
1172+
/// The test verifies that DM operations work correctly when udev
1173+
/// synchronization is fully disabled, simulating the dm-verity device
1174+
/// creation flow in a no-udev guest VM environment.
1175+
///
1176+
/// It simulates the dm-verity device lifecycle:
1177+
/// device_create -> table_load -> device_suspend(resume) -> device_info -> device_remove
1178+
///
1179+
/// All operations use no-udev DmOptions. Uses a read-only error target
1180+
/// (no real block device needed).
1181+
#[test]
1182+
fn sudo_test_no_udev_device_lifecycle() {
1183+
let dm = DM::new().unwrap();
1184+
let name = test_name("no-udev-lifecycle").expect("is valid DM name");
1185+
let id = DevId::Name(&name);
1186+
1187+
let ro_opts = no_udev_dm_options().set_flags(DmFlags::DM_READONLY);
1188+
let opts = no_udev_dm_options();
1189+
1190+
// Step 1: Create device (read-only, no-udev)
1191+
let create_info = dm.device_create(&name, None, ro_opts).unwrap();
1192+
assert_eq!(create_info.name(), Some(&*name));
1193+
1194+
// Step 2: Load a trivial error target table
1195+
let table = vec![(
1196+
0u64,
1197+
1024u64, // 512KB in 512-byte sectors
1198+
"error".into(),
1199+
"".into(),
1200+
)];
1201+
dm.table_load(&id, &table, ro_opts).unwrap();
1202+
1203+
// Step 3: Resume device (activate the table)
1204+
// device_suspend without DM_SUSPEND flag = resume
1205+
dm.device_suspend(&id, opts).unwrap();
1206+
1207+
// Step 4: Verify device is active via device_info
1208+
// device_info uses DmOptions::default(), but DM_DEV_STATUS_CMD
1209+
// does not require udev sync, so it works in no-udev environments
1210+
let info = dm.device_info(&id).unwrap();
1211+
assert_eq!(info.name(), Some(&*name));
1212+
// Device should not be suspended after resume
1213+
assert!(!info.flags().contains(DmFlags::DM_SUSPEND));
1214+
1215+
// Step 5: Remove device with no-udev options
1216+
dm.device_remove(&id, no_udev_dm_options()).unwrap();
1217+
}
11561218
}

0 commit comments

Comments
 (0)