* [pbs-devel] [PATCH proxmox-backup 1/2] tape: changer: save whole LtoTapeDrive config in MtxMediaChanger
@ 2023-12-07 12:51 Dominik Csapak
2023-12-07 12:51 ` [pbs-devel] [PATCH proxmox-backup 2/2] fix #4904: tape changer: add option to eject before unload Dominik Csapak
2023-12-12 13:38 ` [pbs-devel] applied: [PATCH proxmox-backup 1/2] tape: changer: save whole LtoTapeDrive config in MtxMediaChanger Dietmar Maurer
0 siblings, 2 replies; 4+ messages in thread
From: Dominik Csapak @ 2023-12-07 12:51 UTC (permalink / raw)
To: pbs-devel
we'll need more info from there in the future, so derive clone for it
and save the whole config instead of adding an additional field.
Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
pbs-api-types/src/tape/drive.rs | 2 +-
src/tape/changer/mod.rs | 14 ++++++--------
2 files changed, 7 insertions(+), 9 deletions(-)
diff --git a/pbs-api-types/src/tape/drive.rs b/pbs-api-types/src/tape/drive.rs
index ea2cbbd8..ec7c8395 100644
--- a/pbs-api-types/src/tape/drive.rs
+++ b/pbs-api-types/src/tape/drive.rs
@@ -59,7 +59,7 @@ pub struct VirtualTapeDrive {
},
}
)]
-#[derive(Serialize, Deserialize, Updater)]
+#[derive(Serialize, Deserialize, Updater, Clone)]
#[serde(rename_all = "kebab-case")]
/// Lto SCSI tape driver
pub struct LtoTapeDrive {
diff --git a/src/tape/changer/mod.rs b/src/tape/changer/mod.rs
index 0cb42486..bf0a15f4 100644
--- a/src/tape/changer/mod.rs
+++ b/src/tape/changer/mod.rs
@@ -384,8 +384,7 @@ fn load_changer_state_cache(changer: &str) -> Result<Option<MtxStatus>, Error> {
/// Implements MediaChange using 'mtx' linux cli tool
pub struct MtxMediaChanger {
- drive_name: String, // used for error messages
- drive_number: u64,
+ drive: LtoTapeDrive,
config: ScsiTapeChanger,
}
@@ -398,8 +397,7 @@ impl MtxMediaChanger {
};
Ok(Self {
- drive_name: drive_config.name.clone(),
- drive_number: drive_config.changer_drivenum.unwrap_or(0),
+ drive: drive_config.clone(),
config: changer_config,
})
}
@@ -407,11 +405,11 @@ impl MtxMediaChanger {
impl MediaChange for MtxMediaChanger {
fn drive_number(&self) -> u64 {
- self.drive_number
+ self.drive.changer_drivenum.unwrap_or(0)
}
fn drive_name(&self) -> &str {
- &self.drive_name
+ &self.drive.name
}
fn status(&mut self) -> Result<MtxStatus, Error> {
@@ -423,12 +421,12 @@ impl MediaChange for MtxMediaChanger {
}
fn load_media_from_slot(&mut self, slot: u64) -> Result<MtxStatus, Error> {
- self.config.load_slot(slot, self.drive_number)
+ self.config.load_slot(slot, self.drive_number())
}
fn unload_media(&mut self, target_slot: Option<u64>) -> Result<MtxStatus, Error> {
if let Some(target_slot) = target_slot {
- self.config.unload(target_slot, self.drive_number)
+ self.config.unload(target_slot, self.drive_number())
} else {
let status = self.status()?;
self.unload_to_free_slot(status)
--
2.39.2
^ permalink raw reply [flat|nested] 4+ messages in thread
* [pbs-devel] [PATCH proxmox-backup 2/2] fix #4904: tape changer: add option to eject before unload
2023-12-07 12:51 [pbs-devel] [PATCH proxmox-backup 1/2] tape: changer: save whole LtoTapeDrive config in MtxMediaChanger Dominik Csapak
@ 2023-12-07 12:51 ` Dominik Csapak
2023-12-12 13:38 ` [pbs-devel] applied: " Dietmar Maurer
2023-12-12 13:38 ` [pbs-devel] applied: [PATCH proxmox-backup 1/2] tape: changer: save whole LtoTapeDrive config in MtxMediaChanger Dietmar Maurer
1 sibling, 1 reply; 4+ messages in thread
From: Dominik Csapak @ 2023-12-07 12:51 UTC (permalink / raw)
To: pbs-devel
some tape libraries need the tape being ejected from the drive before
doing an unload. Since we cannot easily detect if that's the case,
introduce an 'eject_before_unload' option.
Instead of just adding a bool flag to the config, add a new 'options'
property string where we can put such niche options similar to how we
handle the datastore tuning options.
Extend the LtoTapeHandle with 'medium_present' which just uses a
TEST UNIT READY command to check for present medium, so we don't
try to eject an already ejected tape.
Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
pbs-api-types/src/tape/changer.rs | 28 +++++++++++++++++++++++++++-
src/api2/config/changer.rs | 9 +++++++++
src/bin/proxmox_tape/changer.rs | 1 +
src/tape/changer/mod.rs | 21 +++++++++++++++++++--
src/tape/drive/lto/mod.rs | 5 +++++
5 files changed, 61 insertions(+), 3 deletions(-)
diff --git a/pbs-api-types/src/tape/changer.rs b/pbs-api-types/src/tape/changer.rs
index c9c7fcaa..e3cf27c1 100644
--- a/pbs-api-types/src/tape/changer.rs
+++ b/pbs-api-types/src/tape/changer.rs
@@ -3,7 +3,7 @@
use serde::{Deserialize, Serialize};
use proxmox_schema::{
- api, ApiStringFormat, ArraySchema, IntegerSchema, Schema, StringSchema, Updater,
+ api, ApiStringFormat, ApiType, ArraySchema, IntegerSchema, Schema, StringSchema, Updater,
};
use crate::{OptionalDeviceIdentification, PROXMOX_SAFE_ID_FORMAT};
@@ -39,6 +39,26 @@ Import/Export, i.e. any media in those slots are considered to be
.format(&ApiStringFormat::PropertyString(&SLOT_ARRAY_SCHEMA))
.schema();
+fn is_false(b: &bool) -> bool {
+ !b
+}
+
+#[api]
+#[derive(Serialize, Deserialize)]
+#[serde(rename_all = "kebab-case")]
+/// Options for Changers
+pub struct ChangerOptions {
+ #[serde(default, skip_serializing_if = "is_false")]
+ /// if set to true, tapes are ejected manually before unloading
+ pub eject_before_unload: bool,
+}
+
+pub const CHANGER_OPTIONS_STRING_SCHEMA: Schema = StringSchema::new("Changer options")
+ .format(&ApiStringFormat::PropertyString(
+ &ChangerOptions::API_SCHEMA,
+ ))
+ .schema();
+
#[api(
properties: {
name: {
@@ -51,6 +71,10 @@ Import/Export, i.e. any media in those slots are considered to be
schema: EXPORT_SLOT_LIST_SCHEMA,
optional: true,
},
+ options: {
+ optional: true,
+ schema: CHANGER_OPTIONS_STRING_SCHEMA,
+ },
},
)]
#[derive(Serialize, Deserialize, Updater)]
@@ -62,6 +86,8 @@ pub struct ScsiTapeChanger {
pub path: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub export_slots: Option<String>,
+ #[serde(skip_serializing_if = "Option::is_none")]
+ pub options: Option<String>,
}
#[api(
diff --git a/src/api2/config/changer.rs b/src/api2/config/changer.rs
index 01908e3b..bff9ed9e 100644
--- a/src/api2/config/changer.rs
+++ b/src/api2/config/changer.rs
@@ -138,6 +138,8 @@ pub fn list_changers(
pub enum DeletableProperty {
/// Delete export-slots.
ExportSlots,
+ /// Delete options.
+ Options,
}
#[api(
@@ -194,6 +196,9 @@ pub fn update_changer(
DeletableProperty::ExportSlots => {
data.export_slots = None;
}
+ DeletableProperty::Options => {
+ data.options = None;
+ }
}
}
}
@@ -222,6 +227,10 @@ pub fn update_changer(
}
}
+ if let Some(options) = update.options {
+ data.options = Some(options);
+ }
+
config.set_data(&name, "changer", &data)?;
pbs_config::drive::save_config(&config)?;
diff --git a/src/bin/proxmox_tape/changer.rs b/src/bin/proxmox_tape/changer.rs
index d1ddb5e0..a8bff173 100644
--- a/src/bin/proxmox_tape/changer.rs
+++ b/src/bin/proxmox_tape/changer.rs
@@ -161,6 +161,7 @@ fn get_config(param: Value, rpcenv: &mut dyn RpcEnvironment) -> Result<(), Error
let options = default_table_format_options()
.column(ColumnConfig::new("name"))
.column(ColumnConfig::new("path"))
+ .column(ColumnConfig::new("options"))
.column(ColumnConfig::new("export-slots"));
format_and_print_result_full(&mut data, &info.returns, &output_format, &options);
diff --git a/src/tape/changer/mod.rs b/src/tape/changer/mod.rs
index bf0a15f4..df63f6f8 100644
--- a/src/tape/changer/mod.rs
+++ b/src/tape/changer/mod.rs
@@ -4,6 +4,7 @@ pub mod mtx;
mod online_status_map;
pub use online_status_map::*;
+use proxmox_schema::ApiType;
use std::path::PathBuf;
@@ -11,9 +12,11 @@ use anyhow::{bail, Error};
use proxmox_sys::fs::{file_read_optional_string, replace_file, CreateOptions};
-use pbs_api_types::{LtoTapeDrive, ScsiTapeChanger};
+use pbs_api_types::{ChangerOptions, LtoTapeDrive, ScsiTapeChanger};
-use pbs_tape::{sg_pt_changer, ElementStatus, MtxStatus};
+use pbs_tape::{linux_list_drives::open_lto_tape_device, sg_pt_changer, ElementStatus, MtxStatus};
+
+use crate::tape::drive::{LtoTapeHandle, TapeDriver};
/// Interface to SCSI changer devices
pub trait ScsiMediaChange {
@@ -425,6 +428,20 @@ impl MediaChange for MtxMediaChanger {
}
fn unload_media(&mut self, target_slot: Option<u64>) -> Result<MtxStatus, Error> {
+ let options: ChangerOptions = serde_json::from_value(
+ ChangerOptions::API_SCHEMA
+ .parse_property_string(self.config.options.as_deref().unwrap_or_default())?,
+ )?;
+
+ if options.eject_before_unload {
+ let file = open_lto_tape_device(&self.drive.path)?;
+ let mut handle = LtoTapeHandle::new(file)?;
+
+ if handle.medium_present() {
+ handle.eject_media()?;
+ }
+ }
+
if let Some(target_slot) = target_slot {
self.config.unload(target_slot, self.drive_number())
} else {
diff --git a/src/tape/drive/lto/mod.rs b/src/tape/drive/lto/mod.rs
index 2c3a5a63..955dbdf7 100644
--- a/src/tape/drive/lto/mod.rs
+++ b/src/tape/drive/lto/mod.rs
@@ -162,6 +162,11 @@ impl LtoTapeHandle {
.set_medium_removal(true)
.map_err(|err| format_err!("unlock door failed - {}", err))
}
+
+ /// Returns if a medium is present
+ pub fn medium_present(&mut self) -> bool {
+ self.sg_tape.test_unit_ready().is_ok()
+ }
}
impl TapeDriver for LtoTapeHandle {
--
2.39.2
^ permalink raw reply [flat|nested] 4+ messages in thread
* [pbs-devel] applied: [PATCH proxmox-backup 1/2] tape: changer: save whole LtoTapeDrive config in MtxMediaChanger
2023-12-07 12:51 [pbs-devel] [PATCH proxmox-backup 1/2] tape: changer: save whole LtoTapeDrive config in MtxMediaChanger Dominik Csapak
2023-12-07 12:51 ` [pbs-devel] [PATCH proxmox-backup 2/2] fix #4904: tape changer: add option to eject before unload Dominik Csapak
@ 2023-12-12 13:38 ` Dietmar Maurer
1 sibling, 0 replies; 4+ messages in thread
From: Dietmar Maurer @ 2023-12-12 13:38 UTC (permalink / raw)
To: Proxmox Backup Server development discussion, Dominik Csapak
applied
^ permalink raw reply [flat|nested] 4+ messages in thread
* [pbs-devel] applied: [PATCH proxmox-backup 2/2] fix #4904: tape changer: add option to eject before unload
2023-12-07 12:51 ` [pbs-devel] [PATCH proxmox-backup 2/2] fix #4904: tape changer: add option to eject before unload Dominik Csapak
@ 2023-12-12 13:38 ` Dietmar Maurer
0 siblings, 0 replies; 4+ messages in thread
From: Dietmar Maurer @ 2023-12-12 13:38 UTC (permalink / raw)
To: Proxmox Backup Server development discussion, Dominik Csapak
applied
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-12-12 13:38 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-12-07 12:51 [pbs-devel] [PATCH proxmox-backup 1/2] tape: changer: save whole LtoTapeDrive config in MtxMediaChanger Dominik Csapak
2023-12-07 12:51 ` [pbs-devel] [PATCH proxmox-backup 2/2] fix #4904: tape changer: add option to eject before unload Dominik Csapak
2023-12-12 13:38 ` [pbs-devel] applied: " Dietmar Maurer
2023-12-12 13:38 ` [pbs-devel] applied: [PATCH proxmox-backup 1/2] tape: changer: save whole LtoTapeDrive config in MtxMediaChanger Dietmar Maurer
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