diff --git a/src/api2/tape/drive.rs b/src/api2/tape/drive.rs index 1788762e..27e54b3b 100644 --- a/src/api2/tape/drive.rs +++ b/src/api2/tape/drive.rs @@ -74,6 +74,7 @@ use crate::{ lock_tape_device, set_tape_device_state, get_tape_device_state, + tape_alert_flags_critical, }, changer::update_changer_online_status, }, @@ -759,6 +760,28 @@ pub fn clean_drive( changer.clean_drive()?; + if let Ok(drive_config) = config.lookup::("linux", &drive) { + // Note: clean_drive unloads the cleaning media, so we cannot use drive_config.open + let mut handle = LinuxTapeHandle::new(open_linux_tape_device(&drive_config.path)?); + + // test for critical tape alert flags + if let Ok(alert_flags) = handle.tape_alert_flags() { + if !alert_flags.is_empty() { + worker.log(format!("TapeAlertFlags: {:?}", alert_flags)); + if tape_alert_flags_critical(alert_flags) { + bail!("found critical tape alert flags: {:?}", alert_flags); + } + } + } + + // test wearout (max. 50 mounts) + if let Ok(volume_stats) = handle.volume_statistics() { + worker.log(format!("Volume mounts: {}", volume_stats.volume_mounts)); + let wearout = volume_stats.volume_mounts * 2; // (*100.0/50.0); + worker.log(format!("Cleaning tape wearout: {}%", wearout)); + } + } + worker.log("Drive cleaned sucessfully"); Ok(())