move drive config to pbs_config workspace
Also moved the tape type definitions to pbs_api_types.
This commit is contained in:
@ -524,7 +524,7 @@ pub struct MtxMediaChanger {
|
||||
impl MtxMediaChanger {
|
||||
|
||||
pub fn with_drive_config(drive_config: &LtoTapeDrive) -> Result<Self, Error> {
|
||||
let (config, _digest) = crate::config::drive::config()?;
|
||||
let (config, _digest) = pbs_config::drive::config()?;
|
||||
let changer_config: ScsiTapeChanger = match drive_config.changer {
|
||||
Some(ref changer) => config.lookup("changer", changer)?,
|
||||
None => bail!("drive '{}' has no associated changer", drive_config.name),
|
||||
|
@ -125,7 +125,7 @@ pub fn mtx_status_to_online_set(status: &MtxStatus, inventory: &Inventory) -> Ha
|
||||
/// For a single 'changer', or else simply ask all changer devices.
|
||||
pub fn update_online_status(state_path: &Path, changer: Option<&str>) -> Result<OnlineStatusMap, Error> {
|
||||
|
||||
let (config, _digest) = crate::config::drive::config()?;
|
||||
let (config, _digest) = pbs_config::drive::config()?;
|
||||
|
||||
let mut inventory = Inventory::load(state_path)?;
|
||||
|
||||
|
@ -54,37 +54,34 @@ use crate::{
|
||||
},
|
||||
};
|
||||
|
||||
impl LtoTapeDrive {
|
||||
/// Open a tape device
|
||||
///
|
||||
/// This does additional checks:
|
||||
///
|
||||
/// - 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_lto_tape_drive(config: &LtoTapeDrive) -> Result<LtoTapeHandle, Error> {
|
||||
|
||||
/// Open a tape device
|
||||
///
|
||||
/// This does additional checks:
|
||||
///
|
||||
/// - 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<LtoTapeHandle, Error> {
|
||||
proxmox::try_block!({
|
||||
let file = open_lto_tape_device(&config.path)?;
|
||||
|
||||
proxmox::try_block!({
|
||||
let file = open_lto_tape_device(&self.path)?;
|
||||
let mut handle = LtoTapeHandle::new(file)?;
|
||||
|
||||
let mut handle = LtoTapeHandle::new(file)?;
|
||||
|
||||
if !handle.sg_tape.test_unit_ready().is_ok() {
|
||||
// for autoloader only, try to reload ejected tapes
|
||||
if self.changer.is_some() {
|
||||
let _ = handle.sg_tape.load(); // just try, ignore error
|
||||
}
|
||||
if !handle.sg_tape.test_unit_ready().is_ok() {
|
||||
// for autoloader only, try to reload ejected tapes
|
||||
if config.changer.is_some() {
|
||||
let _ = handle.sg_tape.load(); // just try, ignore error
|
||||
}
|
||||
}
|
||||
|
||||
handle.sg_tape.wait_until_ready()?;
|
||||
handle.sg_tape.wait_until_ready()?;
|
||||
|
||||
handle.set_default_options()?;
|
||||
handle.set_default_options()?;
|
||||
|
||||
Ok(handle)
|
||||
}).map_err(|err: Error| format_err!("open drive '{}' ({}) failed - {}", self.name, self.path, err))
|
||||
}
|
||||
Ok(handle)
|
||||
}).map_err(|err: Error| format_err!("open drive '{}' ({}) failed - {}", config.name, config.path, err))
|
||||
}
|
||||
|
||||
/// Lto Tape device handle
|
||||
|
@ -32,12 +32,9 @@ use pbs_api_types::Fingerprint;
|
||||
use pbs_datastore::key_derivation::KeyConfig;
|
||||
use pbs_datastore::task::TaskState;
|
||||
use pbs_datastore::task_log;
|
||||
use pbs_api_types::{VirtualTapeDrive, LtoTapeDrive};
|
||||
|
||||
use crate::{
|
||||
api2::types::{
|
||||
VirtualTapeDrive,
|
||||
LtoTapeDrive,
|
||||
},
|
||||
server::{
|
||||
send_load_media_email,
|
||||
WorkerTask,
|
||||
@ -47,7 +44,10 @@ use crate::{
|
||||
TapeRead,
|
||||
BlockReadError,
|
||||
MediaId,
|
||||
drive::lto::TapeAlertFlags,
|
||||
drive::{
|
||||
virtual_tape::open_virtual_tape_drive,
|
||||
lto::TapeAlertFlags,
|
||||
},
|
||||
file_formats::{
|
||||
PROXMOX_BACKUP_MEDIA_LABEL_MAGIC_1_0,
|
||||
PROXMOX_BACKUP_MEDIA_SET_LABEL_MAGIC_1_0,
|
||||
@ -305,12 +305,12 @@ pub fn open_drive(
|
||||
match section_type_name.as_ref() {
|
||||
"virtual" => {
|
||||
let tape = VirtualTapeDrive::deserialize(config)?;
|
||||
let handle = tape.open()?;
|
||||
let handle = open_virtual_tape_drive(&tape)?;
|
||||
Ok(Box::new(handle))
|
||||
}
|
||||
"lto" => {
|
||||
let tape = LtoTapeDrive::deserialize(config)?;
|
||||
let handle = tape.open()?;
|
||||
let handle = open_lto_tape_drive(&tape)?;
|
||||
Ok(Box::new(handle))
|
||||
}
|
||||
_ => bail!("unknown drive type '{}' - internal error"),
|
||||
@ -395,7 +395,7 @@ pub fn request_and_load_media(
|
||||
|
||||
tape.load_media(&label_text)?;
|
||||
|
||||
let mut handle: Box<dyn TapeDriver> = Box::new(tape.open()?);
|
||||
let mut handle: Box<dyn TapeDriver> = Box::new(open_virtual_tape_drive(&tape)?);
|
||||
|
||||
let media_id = check_label(handle.as_mut(), &label.uuid)?;
|
||||
|
||||
@ -413,7 +413,7 @@ pub fn request_and_load_media(
|
||||
let mut changer = MtxMediaChanger::with_drive_config(&drive_config)?;
|
||||
changer.load_media(&label_text)?;
|
||||
|
||||
let mut handle: Box<dyn TapeDriver> = Box::new(drive_config.open()?);
|
||||
let mut handle: Box<dyn TapeDriver> = Box::new(open_lto_tape_drive(&drive_config)?);
|
||||
|
||||
let media_id = check_label(handle.as_mut(), &label.uuid)?;
|
||||
|
||||
@ -463,7 +463,7 @@ pub fn request_and_load_media(
|
||||
);
|
||||
}
|
||||
|
||||
let mut handle = match drive_config.open() {
|
||||
let mut handle = match open_lto_tape_drive(&drive_config) {
|
||||
Ok(handle) => handle,
|
||||
Err(err) => {
|
||||
update_and_log_request_error(
|
||||
|
@ -42,26 +42,23 @@ use crate::{
|
||||
},
|
||||
};
|
||||
|
||||
impl VirtualTapeDrive {
|
||||
/// This needs to lock the drive
|
||||
pub fn open_virtual_tape_drive(config: &VirtualTapeDrive) -> Result<VirtualTapeHandle, Error> {
|
||||
proxmox::try_block!({
|
||||
let mut lock_path = std::path::PathBuf::from(&config.path);
|
||||
lock_path.push(".drive.lck");
|
||||
|
||||
/// This needs to lock the drive
|
||||
pub fn open(&self) -> Result<VirtualTapeHandle, Error> {
|
||||
proxmox::try_block!({
|
||||
let mut lock_path = std::path::PathBuf::from(&self.path);
|
||||
lock_path.push(".drive.lck");
|
||||
let options = CreateOptions::new();
|
||||
let timeout = std::time::Duration::new(10, 0);
|
||||
let lock = proxmox::tools::fs::open_file_locked(&lock_path, timeout, true, options)?;
|
||||
|
||||
let options = CreateOptions::new();
|
||||
let timeout = std::time::Duration::new(10, 0);
|
||||
let lock = proxmox::tools::fs::open_file_locked(&lock_path, timeout, true, options)?;
|
||||
|
||||
Ok(VirtualTapeHandle {
|
||||
_lock: lock,
|
||||
drive_name: self.name.clone(),
|
||||
max_size: self.max_size.unwrap_or(64*1024*1024),
|
||||
path: std::path::PathBuf::from(&self.path),
|
||||
})
|
||||
}).map_err(|err: Error| format_err!("open drive '{}' ({}) failed - {}", self.name, self.path, err))
|
||||
}
|
||||
Ok(VirtualTapeHandle {
|
||||
_lock: lock,
|
||||
drive_name: config.name.clone(),
|
||||
max_size: config.max_size.unwrap_or(64*1024*1024),
|
||||
path: std::path::PathBuf::from(&config.path),
|
||||
})
|
||||
}).map_err(|err: Error| format_err!("open drive '{}' ({}) failed - {}", config.name, config.path, err))
|
||||
}
|
||||
|
||||
#[derive(Serialize,Deserialize)]
|
||||
@ -583,42 +580,42 @@ impl MediaChange for VirtualTapeDrive {
|
||||
}
|
||||
|
||||
fn status(&mut self) -> Result<MtxStatus, Error> {
|
||||
let mut handle = self.open()?;
|
||||
let mut handle = open_virtual_tape_drive(self)?;
|
||||
handle.status()
|
||||
}
|
||||
|
||||
fn transfer_media(&mut self, from: u64, to: u64) -> Result<MtxStatus, Error> {
|
||||
let mut handle = self.open()?;
|
||||
let mut handle = open_virtual_tape_drive(self)?;
|
||||
handle.transfer_media(from, to)
|
||||
}
|
||||
|
||||
fn export_media(&mut self, label_text: &str) -> Result<Option<u64>, Error> {
|
||||
let mut handle = self.open()?;
|
||||
let mut handle = open_virtual_tape_drive(self)?;
|
||||
handle.export_media(label_text)
|
||||
}
|
||||
|
||||
fn load_media_from_slot(&mut self, slot: u64) -> Result<MtxStatus, Error> {
|
||||
let mut handle = self.open()?;
|
||||
let mut handle = open_virtual_tape_drive(self)?;
|
||||
handle.load_media_from_slot(slot)
|
||||
}
|
||||
|
||||
fn load_media(&mut self, label_text: &str) -> Result<MtxStatus, Error> {
|
||||
let mut handle = self.open()?;
|
||||
let mut handle = open_virtual_tape_drive(self)?;
|
||||
handle.load_media(label_text)
|
||||
}
|
||||
|
||||
fn unload_media(&mut self, target_slot: Option<u64>) -> Result<MtxStatus, Error> {
|
||||
let mut handle = self.open()?;
|
||||
let mut handle = open_virtual_tape_drive(self)?;
|
||||
handle.unload_media(target_slot)
|
||||
}
|
||||
|
||||
fn online_media_label_texts(&mut self) -> Result<Vec<String>, Error> {
|
||||
let handle = self.open()?;
|
||||
let handle = open_virtual_tape_drive(self)?;
|
||||
handle.online_media_label_texts()
|
||||
}
|
||||
|
||||
fn clean_drive(&mut self) -> Result<MtxStatus, Error> {
|
||||
let mut handle = self.open()?;
|
||||
let mut handle = open_virtual_tape_drive(self)?;
|
||||
handle.clean_drive()
|
||||
}
|
||||
}
|
||||
|
@ -133,7 +133,7 @@ impl PoolWriter {
|
||||
None => return Ok(()), // no media loaded
|
||||
};
|
||||
|
||||
let (drive_config, _digest) = crate::config::drive::config()?;
|
||||
let (drive_config, _digest) = pbs_config::drive::config()?;
|
||||
|
||||
if let Some((mut changer, _)) = media_changer(&drive_config, &self.drive_name)? {
|
||||
worker.log("eject media");
|
||||
@ -153,7 +153,7 @@ impl PoolWriter {
|
||||
pub fn export_media_set(&mut self, worker: &WorkerTask) -> Result<(), Error> {
|
||||
let mut status = self.status.take();
|
||||
|
||||
let (drive_config, _digest) = crate::config::drive::config()?;
|
||||
let (drive_config, _digest) = pbs_config::drive::config()?;
|
||||
|
||||
if let Some((mut changer, _)) = media_changer(&drive_config, &self.drive_name)? {
|
||||
|
||||
@ -226,7 +226,7 @@ impl PoolWriter {
|
||||
}
|
||||
}
|
||||
|
||||
let (drive_config, _digest) = crate::config::drive::config()?;
|
||||
let (drive_config, _digest) = pbs_config::drive::config()?;
|
||||
|
||||
let (mut drive, old_media_id) =
|
||||
request_and_load_media(worker, &drive_config, &self.drive_name, media.label(), &self.notify_email)?;
|
||||
|
Reference in New Issue
Block a user