From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 53743B9D15 for ; Tue, 12 Dec 2023 12:33:20 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 3714E33672 for ; Tue, 12 Dec 2023 12:32:50 +0100 (CET) Received: from bookworm-dev.localdomain (unknown [94.136.29.99]) by firstgate.proxmox.com (Proxmox) with ESMTP for ; Tue, 12 Dec 2023 12:32:49 +0100 (CET) Received: by bookworm-dev.localdomain (Postfix, from userid 1000) id 3A43F615E8; Tue, 12 Dec 2023 12:32:48 +0100 (CET) From: Dominik Csapak To: pbs-devel@lists.proxmox.com Date: Tue, 12 Dec 2023 12:32:47 +0100 Message-Id: <20231212113248.159105-4-d.csapak@proxmox.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231212113248.159105-1-d.csapak@proxmox.com> References: <20231212113248.159105-1-d.csapak@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL -0.377 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment RDNS_NONE 0.793 Delivered to internal network by a host with no rDNS SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record T_SCC_BODY_TEXT_LINE -0.01 - Subject: [pbs-devel] [PATCH proxmox-backup 3/4] tape: adapt format_media for LTO9+ X-BeenThere: pbs-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Backup Server development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 12 Dec 2023 11:33:20 -0000 starting with LTO9, a FORMAT(04h) command also reinitializates the tape, which can take up to tw hours. Since we don't actually want to do that every time we format, use 'erase_media' when we want a fast erase. (On a slow erase, we let it run and wait until the drive is ready again). The users have to pre-initializate the tapes before using it for them to work properly though. Signed-off-by: Dominik Csapak --- pbs-tape/src/sg_tape.rs | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/pbs-tape/src/sg_tape.rs b/pbs-tape/src/sg_tape.rs index 16ef31f9..53fe78fa 100644 --- a/pbs-tape/src/sg_tape.rs +++ b/pbs-tape/src/sg_tape.rs @@ -26,7 +26,7 @@ pub use report_density::*; use proxmox_io::{ReadExt, WriteExt}; use proxmox_sys::error::SysResult; -use pbs_api_types::{Lp17VolumeStatistics, LtoDriveAndMediaStatus, MamAttribute}; +use pbs_api_types::{Lp17VolumeStatistics, LtoDriveAndMediaStatus, MamAttribute, TapeDensity}; use crate::{ sgutils2::{ @@ -197,16 +197,17 @@ impl SgTape { /// Format media, single partition pub fn format_media(&mut self, fast: bool) -> Result<(), Error> { // try to get info about loaded media first - let (has_format, is_worm) = match self.read_medium_configuration_page() { + let (density, is_worm) = match self.read_medium_configuration_page() { Ok((_head, block_descriptor, page)) => { // FORMAT requires LTO5 or newer - let has_format = block_descriptor.density_code >= 0x58; + let density: TapeDensity = TapeDensity::try_from(block_descriptor.density_code) + .unwrap_or(TapeDensity::Unknown); let is_worm = page.is_worm(); - (has_format, is_worm) + (density, is_worm) } Err(_) => { // LTO3 and older do not support medium configuration mode page - (false, false) + (TapeDensity::Unknown, false) } }; @@ -227,14 +228,21 @@ impl SgTape { sg_raw.set_timeout(Self::SCSI_TAPE_DEFAULT_TIMEOUT); let mut cmd = Vec::new(); - if has_format { + if density >= TapeDensity::LTO5 && density <= TapeDensity::LTO8 { cmd.extend([0x04, 0, 0, 0, 0, 0]); // FORMAT sg_raw.do_command(&cmd)?; if !fast { self.erase_media(false)?; // overwrite everything } + } else if density >= TapeDensity::LTO9 && !fast { + cmd.extend([0x04, 0x01, 0, 0, 0, 0]); // FORMAT, set IMMED + sg_raw.do_command(&cmd)?; + self.wait_until_ready(Some(60 * 60 * 2)) // 2 hours, max. initialization time + .map_err(|err| format_err!("error waiting for LTO9+ initialization: {err}"))?; + self.erase_media(false)?; // overwrite everything } else { // try rewind/erase instead + // we also do this for LTO9+ to avoid reinitialization on FORMAT(04h) self.erase_media(fast)? } -- 2.39.2