From ab77d660cc20466c1958c5e83dd1d99eaea81224 Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Thu, 4 Mar 2021 08:52:58 +0100 Subject: [PATCH] tape: improve media status in list_media --- src/api2/tape/media.rs | 9 +++++++-- src/tape/media_pool.rs | 33 +++++++++++++++++++++++++++------ 2 files changed, 34 insertions(+), 8 deletions(-) diff --git a/src/api2/tape/media.rs b/src/api2/tape/media.rs index 82ab306a..ecfe41bf 100644 --- a/src/api2/tape/media.rs +++ b/src/api2/tape/media.rs @@ -121,11 +121,16 @@ pub async fn list_media( let config: MediaPoolConfig = config.lookup("pool", pool_name)?; - let changer_name = None; // does not matter here - let pool = MediaPool::with_config(status_path, &config, changer_name)?; + let changer_name = None; // assume standalone drive + let mut pool = MediaPool::with_config(status_path, &config, changer_name)?; 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() { let expired = pool.media_is_expired(&media, current_time); diff --git a/src/tape/media_pool.rs b/src/tape/media_pool.rs index be1db8be..a3172f31 100644 --- a/src/tape/media_pool.rs +++ b/src/tape/media_pool.rs @@ -46,6 +46,7 @@ pub struct MediaPool { retention: RetentionPolicy, changer_name: Option, + force_media_availability: bool, encrypt_fingerprint: Option, @@ -87,9 +88,17 @@ impl MediaPool { inventory, current_media_set, 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 pub fn with_config( state_path: &Path, @@ -218,6 +227,9 @@ impl MediaPool { /// /// If not, starts a new media set. Also creates a new /// 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> { 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 { match location { MediaLocation::Online(name) => { - if let Some(ref changer_name) = self.changer_name { - name == changer_name + if self.force_media_availability { + true } else { - // a standalone drive cannot use media currently inside a library - false + if let Some(ref changer_name) = self.changer_name { + name == changer_name + } else { + // a standalone drive cannot use media currently inside a library + false + } } } MediaLocation::Offline => { - // consider available for standalone drives - self.changer_name.is_none() + if self.force_media_availability { + true + } else { + // consider available for standalone drives + self.changer_name.is_none() + } } MediaLocation::Vault(_) => false, } @@ -500,6 +520,7 @@ impl MediaPool { _ => bail!("unable to use media set - wrong media status {:?}", media.status()), } } + Ok(last_is_writable) }