tape: lock artificial "__UNASSIGNED__" pool to avoid races
This commit is contained in:
parent
af76234112
commit
1057b1f5a5
@ -7,7 +7,7 @@
|
|||||||
//!
|
//!
|
||||||
//!
|
//!
|
||||||
|
|
||||||
use std::path::Path;
|
use std::path::{PathBuf, Path};
|
||||||
use anyhow::{bail, Error};
|
use anyhow::{bail, Error};
|
||||||
use ::serde::{Deserialize, Serialize};
|
use ::serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
@ -41,6 +41,7 @@ pub struct MediaPoolLockGuard(std::fs::File);
|
|||||||
pub struct MediaPool {
|
pub struct MediaPool {
|
||||||
|
|
||||||
name: String,
|
name: String,
|
||||||
|
state_path: PathBuf,
|
||||||
|
|
||||||
media_set_policy: MediaSetPolicy,
|
media_set_policy: MediaSetPolicy,
|
||||||
retention: RetentionPolicy,
|
retention: RetentionPolicy,
|
||||||
@ -82,6 +83,7 @@ impl MediaPool {
|
|||||||
|
|
||||||
Ok(MediaPool {
|
Ok(MediaPool {
|
||||||
name: String::from(name),
|
name: String::from(name),
|
||||||
|
state_path: state_path.to_owned(),
|
||||||
media_set_policy,
|
media_set_policy,
|
||||||
retention,
|
retention,
|
||||||
changer_name,
|
changer_name,
|
||||||
@ -439,7 +441,12 @@ impl MediaPool {
|
|||||||
println!("no expired media in pool, try to find unassigned/free media");
|
println!("no expired media in pool, try to find unassigned/free media");
|
||||||
|
|
||||||
// try unassigned media
|
// try unassigned media
|
||||||
// fixme: lock free media pool to avoid races
|
|
||||||
|
// lock artificial "__UNASSIGNED__" pool to avoid races
|
||||||
|
let _lock = MediaPool::lock(&self.state_path, "__UNASSIGNED__")?;
|
||||||
|
|
||||||
|
self.inventory.reload()?;
|
||||||
|
|
||||||
let mut free_media = Vec::new();
|
let mut free_media = Vec::new();
|
||||||
|
|
||||||
for media_id in self.inventory.list_unassigned_media() {
|
for media_id in self.inventory.list_unassigned_media() {
|
||||||
|
Loading…
Reference in New Issue
Block a user