Skip to content

Commit 464aa70

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 9802242 commit 464aa70

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

0 commit comments

Comments
 (0)