* [pbs-devel] [PATCH proxmox-backup 1/4] tape: add optional timeout to wait_until_ready
2023-12-12 11:32 [pbs-devel] [PATCH proxmox-backup 0/4] better handle lto9 format Dominik Csapak
@ 2023-12-12 11:32 ` Dominik Csapak
2023-12-12 11:32 ` [pbs-devel] [PATCH proxmox-backup 2/4] tape: derive PartialEq and PartialOrd for TapeDensity Dominik Csapak
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Dominik Csapak @ 2023-12-12 11:32 UTC (permalink / raw)
To: pbs-devel
instead of hardcodign the default timeout as only option. This will come
in handy when we need to wait for LTO9+ initialization that can take up
to two hours.
Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
pbs-tape/src/sg_tape.rs | 5 +++--
src/tape/drive/lto/mod.rs | 2 +-
2 files changed, 4 insertions(+), 3 deletions(-)
diff --git a/pbs-tape/src/sg_tape.rs b/pbs-tape/src/sg_tape.rs
index b28a5f27..16ef31f9 100644
--- a/pbs-tape/src/sg_tape.rs
+++ b/pbs-tape/src/sg_tape.rs
@@ -571,9 +571,10 @@ impl SgTape {
}
}
- pub fn wait_until_ready(&mut self) -> Result<(), Error> {
+ pub fn wait_until_ready(&mut self, timeout: Option<u64>) -> Result<(), Error> {
let start = SystemTime::now();
- let max_wait = std::time::Duration::new(Self::SCSI_TAPE_DEFAULT_TIMEOUT as u64, 0);
+ let timeout = timeout.unwrap_or(Self::SCSI_TAPE_DEFAULT_TIMEOUT as u64);
+ let max_wait = std::time::Duration::new(timeout, 0);
loop {
match self.test_unit_ready() {
diff --git a/src/tape/drive/lto/mod.rs b/src/tape/drive/lto/mod.rs
index 2c3a5a63..97dd540f 100644
--- a/src/tape/drive/lto/mod.rs
+++ b/src/tape/drive/lto/mod.rs
@@ -55,7 +55,7 @@ pub fn open_lto_tape_drive(config: &LtoTapeDrive) -> Result<LtoTapeHandle, Error
}
}
- handle.sg_tape.wait_until_ready()?;
+ handle.sg_tape.wait_until_ready(None)?;
handle.set_default_options()?;
--
2.39.2
^ permalink raw reply [flat|nested] 6+ messages in thread
* [pbs-devel] [PATCH proxmox-backup 2/4] tape: derive PartialEq and PartialOrd for TapeDensity
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 ` Dominik Csapak
2023-12-12 11:32 ` [pbs-devel] [PATCH proxmox-backup 3/4] tape: adapt format_media for LTO9+ Dominik Csapak
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Dominik Csapak @ 2023-12-12 11:32 UTC (permalink / raw)
To: pbs-devel
so that we can compare more easily
Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
pbs-api-types/src/tape/drive.rs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pbs-api-types/src/tape/drive.rs b/pbs-api-types/src/tape/drive.rs
index ea2cbbd8..0217704b 100644
--- a/pbs-api-types/src/tape/drive.rs
+++ b/pbs-api-types/src/tape/drive.rs
@@ -108,7 +108,7 @@ pub struct MamAttribute {
}
#[api()]
-#[derive(Serialize, Deserialize, Copy, Clone, Debug)]
+#[derive(Serialize, Deserialize, Copy, Clone, Debug, PartialOrd, PartialEq)]
pub enum TapeDensity {
/// Unknown (no media loaded)
Unknown,
--
2.39.2
^ permalink raw reply [flat|nested] 6+ messages in thread
* [pbs-devel] [PATCH proxmox-backup 3/4] tape: adapt format_media for LTO9+
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
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
4 siblings, 0 replies; 6+ messages in thread
From: Dominik Csapak @ 2023-12-12 11:32 UTC (permalink / raw)
To: pbs-devel
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
^ permalink raw reply [flat|nested] 6+ messages in thread
* [pbs-devel] [PATCH proxmox-backup 4/4] api: tape: add lto9 initialization message to task log
2023-12-12 11:32 [pbs-devel] [PATCH proxmox-backup 0/4] better handle lto9 format Dominik Csapak
` (2 preceding siblings ...)
2023-12-12 11:32 ` [pbs-devel] [PATCH proxmox-backup 3/4] tape: adapt format_media for LTO9+ Dominik Csapak
@ 2023-12-12 11:32 ` Dominik Csapak
2023-12-12 12:37 ` [pbs-devel] applied: [PATCH proxmox-backup 0/4] better handle lto9 format Dietmar Maurer
4 siblings, 0 replies; 6+ messages in thread
From: Dominik Csapak @ 2023-12-12 11:32 UTC (permalink / raw)
To: pbs-devel
so that it's clear that this operation can take a while
Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
src/api2/tape/drive.rs | 17 ++++++++++++++++-
1 file changed, 16 insertions(+), 1 deletion(-)
diff --git a/src/api2/tape/drive.rs b/src/api2/tape/drive.rs
index 5306e605..3a77ca6f 100644
--- a/src/api2/tape/drive.rs
+++ b/src/api2/tape/drive.rs
@@ -16,7 +16,7 @@ use proxmox_uuid::Uuid;
use pbs_api_types::{
Authid, DriveListEntry, LabelUuidMap, Lp17VolumeStatistics, LtoDriveAndMediaStatus,
- LtoTapeDrive, MamAttribute, MediaIdFlat, CHANGER_NAME_SCHEMA, DRIVE_NAME_SCHEMA,
+ LtoTapeDrive, MamAttribute, MediaIdFlat, TapeDensity, CHANGER_NAME_SCHEMA, DRIVE_NAME_SCHEMA,
MEDIA_LABEL_SCHEMA, MEDIA_POOL_NAME_SCHEMA, UPID_SCHEMA,
};
@@ -309,6 +309,21 @@ pub fn format_media(
let mut handle = open_drive(&config, &drive)?;
+ if !fast.unwrap_or(true) {
+ let drive_config: LtoTapeDrive = config.lookup("lto", &drive)?;
+ let file = open_lto_tape_device(&drive_config.path)?;
+ let mut handle = LtoTapeHandle::new(file)?;
+ if let Ok(status) = handle.get_drive_and_media_status() {
+ if status.density >= TapeDensity::LTO9 {
+ task_log!(worker, "Slow formatting LTO9+ media.");
+ task_log!(
+ worker,
+ "This can take a very long time due to media optimization."
+ );
+ }
+ }
+ }
+
match handle.read_label() {
Err(err) => {
if let Some(label) = label_text {
--
2.39.2
^ permalink raw reply [flat|nested] 6+ messages in thread
* [pbs-devel] applied: [PATCH proxmox-backup 0/4] better handle lto9 format
2023-12-12 11:32 [pbs-devel] [PATCH proxmox-backup 0/4] better handle lto9 format Dominik Csapak
` (3 preceding siblings ...)
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 ` Dietmar Maurer
4 siblings, 0 replies; 6+ messages in thread
From: Dietmar Maurer @ 2023-12-12 12:37 UTC (permalink / raw)
To: Proxmox Backup Server development discussion, Dominik Csapak
applied
^ permalink raw reply [flat|nested] 6+ messages in thread