From a484c9cf96f68f6c0899d7a8f7c85f4cf3896996 Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Tue, 12 Jan 2021 09:49:05 +0100 Subject: [PATCH] tape: automatically reload tapes inside autoloader We always automatically unload tapes to free library slots, so it should not happen that an ejected tape resides inside the drive. This is just a safe guard to handle the situation in case it happens ... You can manually produce the situation by ejecting a tape without unloading: mt -f /dev/nst0 eject Note: Our "proxmox-tape eject" does automatic unload --- src/tape/drive/linux_tape.rs | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/tape/drive/linux_tape.rs b/src/tape/drive/linux_tape.rs index 0fb7e67a..cef914bb 100644 --- a/src/tape/drive/linux_tape.rs +++ b/src/tape/drive/linux_tape.rs @@ -67,13 +67,22 @@ impl LinuxTapeDrive { /// - check if it is a non-rewinding tape device /// - check if drive is ready (tape loaded) /// - check block size + /// - for autoloader only, try to reload ejected tapes pub fn open(&self) -> Result { let file = open_linux_tape_device(&self.path)?; let mut handle = LinuxTapeHandle::new(file); - let drive_status = handle.get_drive_status()?; + let mut drive_status = handle.get_drive_status()?; + + if !drive_status.tape_is_ready() { + // for autoloader only, try to reload ejected tapes + if self.changer.is_some() { + let _ = handle.mtload(); // just try, ignore error + drive_status = handle.get_drive_status()?; + } + } if !drive_status.tape_is_ready() { bail!("tape not ready (no tape loaded)"); @@ -158,6 +167,17 @@ impl LinuxTapeHandle { Ok(()) } + fn mtload(&mut self) -> Result<(), Error> { + + let cmd = mtop { mt_op: MTCmd::MTLOAD, mt_count: 1, }; + + unsafe { + mtioctop(self.file.as_raw_fd(), &cmd) + }.map_err(|err| format_err!("MTLOAD failed - {}", err))?; + + Ok(()) + } + fn forward_space_count_files(&mut self, count: i32) -> Result<(), Error> { let cmd = mtop { mt_op: MTCmd::MTFSF, mt_count: count, };