all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: Dominik Csapak <d.csapak@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH proxmox-backup 3/4] tape: adapt format_media for LTO9+
Date: Tue, 12 Dec 2023 12:32:47 +0100	[thread overview]
Message-ID: <20231212113248.159105-4-d.csapak@proxmox.com> (raw)
In-Reply-To: <20231212113248.159105-1-d.csapak@proxmox.com>

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 <d.csapak@proxmox.com>
---
 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




  parent reply	other threads:[~2023-12-12 11:33 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-12 11:32 [pbs-devel] [PATCH proxmox-backup 0/4] better handle lto9 format Dominik Csapak
2023-12-12 11:32 ` [pbs-devel] [PATCH proxmox-backup 1/4] tape: add optional timeout to wait_until_ready Dominik Csapak
2023-12-12 11:32 ` [pbs-devel] [PATCH proxmox-backup 2/4] tape: derive PartialEq and PartialOrd for TapeDensity Dominik Csapak
2023-12-12 11:32 ` Dominik Csapak [this message]
2023-12-12 11:32 ` [pbs-devel] [PATCH proxmox-backup 4/4] api: tape: add lto9 initialization message to task log Dominik Csapak
2023-12-12 12:37 ` [pbs-devel] applied: [PATCH proxmox-backup 0/4] better handle lto9 format Dietmar Maurer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20231212113248.159105-4-d.csapak@proxmox.com \
    --to=d.csapak@proxmox.com \
    --cc=pbs-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal