tape: improve media status in list_media

This commit is contained in:
Dietmar Maurer 2021-03-04 08:52:58 +01:00
parent b74a1daae9
commit ab77d660cc
2 changed files with 34 additions and 8 deletions

View File

@ -121,11 +121,16 @@ pub async fn list_media(
let config: MediaPoolConfig = config.lookup("pool", pool_name)?; let config: MediaPoolConfig = config.lookup("pool", pool_name)?;
let changer_name = None; // does not matter here let changer_name = None; // assume standalone drive
let pool = MediaPool::with_config(status_path, &config, changer_name)?; let mut pool = MediaPool::with_config(status_path, &config, changer_name)?;
let current_time = proxmox::tools::time::epoch_i64(); let current_time = proxmox::tools::time::epoch_i64();
// Call start_write_session, so that we show the same status a
// backup job would see.
pool.force_media_availability();
pool.start_write_session(current_time)?;
for media in pool.list_media() { for media in pool.list_media() {
let expired = pool.media_is_expired(&media, current_time); let expired = pool.media_is_expired(&media, current_time);

View File

@ -46,6 +46,7 @@ pub struct MediaPool {
retention: RetentionPolicy, retention: RetentionPolicy,
changer_name: Option<String>, changer_name: Option<String>,
force_media_availability: bool,
encrypt_fingerprint: Option<Fingerprint>, encrypt_fingerprint: Option<Fingerprint>,
@ -87,9 +88,17 @@ impl MediaPool {
inventory, inventory,
current_media_set, current_media_set,
encrypt_fingerprint, encrypt_fingerprint,
force_media_availability: false,
}) })
} }
/// Pretend all Online(x) and Offline media is available
///
/// Only media in Vault(y) is considered unavailable.
pub fn force_media_availability(&mut self) {
self.force_media_availability = true;
}
/// Creates a new instance using the media pool configuration /// Creates a new instance using the media pool configuration
pub fn with_config( pub fn with_config(
state_path: &Path, state_path: &Path,
@ -218,6 +227,9 @@ impl MediaPool {
/// ///
/// If not, starts a new media set. Also creates a new /// If not, starts a new media set. Also creates a new
/// set if media_set_policy implies it. /// set if media_set_policy implies it.
///
/// Note: We also call this in list_media to compute correct media
/// status, so this must not change persistent/saved state.
pub fn start_write_session(&mut self, current_time: i64) -> Result<(), Error> { pub fn start_write_session(&mut self, current_time: i64) -> Result<(), Error> {
let mut create_new_set = match self.current_set_usable() { let mut create_new_set = match self.current_set_usable() {
@ -284,16 +296,24 @@ impl MediaPool {
pub fn location_is_available(&self, location: &MediaLocation) -> bool { pub fn location_is_available(&self, location: &MediaLocation) -> bool {
match location { match location {
MediaLocation::Online(name) => { MediaLocation::Online(name) => {
if let Some(ref changer_name) = self.changer_name { if self.force_media_availability {
name == changer_name true
} else { } else {
// a standalone drive cannot use media currently inside a library if let Some(ref changer_name) = self.changer_name {
false name == changer_name
} else {
// a standalone drive cannot use media currently inside a library
false
}
} }
} }
MediaLocation::Offline => { MediaLocation::Offline => {
// consider available for standalone drives if self.force_media_availability {
self.changer_name.is_none() true
} else {
// consider available for standalone drives
self.changer_name.is_none()
}
} }
MediaLocation::Vault(_) => false, MediaLocation::Vault(_) => false,
} }
@ -500,6 +520,7 @@ impl MediaPool {
_ => bail!("unable to use media set - wrong media status {:?}", media.status()), _ => bail!("unable to use media set - wrong media status {:?}", media.status()),
} }
} }
Ok(last_is_writable) Ok(last_is_writable)
} }