api2/tape/drive: use run_drive_blocking_task where possible
Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
This commit is contained in:
parent
54c77b3d62
commit
47a7241410
|
@ -180,16 +180,15 @@ pub fn load_media(
|
|||
///
|
||||
/// Issue a media load request to the associated changer device.
|
||||
pub async fn load_slot(drive: String, source_slot: u64) -> Result<(), Error> {
|
||||
|
||||
let (config, _digest) = config::drive::config()?;
|
||||
let lock_guard = lock_tape_device(&config, &drive)?;
|
||||
|
||||
tokio::task::spawn_blocking(move || {
|
||||
let _lock_guard = lock_guard; // keep lock guard
|
||||
|
||||
run_drive_blocking_task(
|
||||
drive.clone(),
|
||||
format!("load from slot {}", source_slot),
|
||||
move |config| {
|
||||
let (mut changer, _) = required_media_changer(&config, &drive)?;
|
||||
changer.load_media_from_slot(source_slot)
|
||||
}).await?
|
||||
},
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
#[api(
|
||||
|
@ -211,19 +210,22 @@ pub async fn load_slot(drive: String, source_slot: u64) -> Result<(), Error> {
|
|||
)]
|
||||
/// Export media with specified label
|
||||
pub async fn export_media(drive: String, label_text: String) -> Result<u64, Error> {
|
||||
|
||||
let (config, _digest) = config::drive::config()?;
|
||||
let lock_guard = lock_tape_device(&config, &drive)?;
|
||||
|
||||
tokio::task::spawn_blocking(move || {
|
||||
let _lock_guard = lock_guard; // keep lock guard
|
||||
|
||||
run_drive_blocking_task(
|
||||
drive.clone(),
|
||||
format!("export media {}", label_text),
|
||||
move |config| {
|
||||
let (mut changer, changer_name) = required_media_changer(&config, &drive)?;
|
||||
match changer.export_media(&label_text)? {
|
||||
Some(slot) => Ok(slot),
|
||||
None => bail!("media '{}' is not online (via changer '{}')", label_text, changer_name),
|
||||
None => bail!(
|
||||
"media '{}' is not online (via changer '{}')",
|
||||
label_text,
|
||||
changer_name
|
||||
),
|
||||
}
|
||||
}).await?
|
||||
}
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
#[api(
|
||||
|
@ -584,15 +586,10 @@ pub async fn restore_key(
|
|||
drive: String,
|
||||
password: String,
|
||||
) -> Result<(), Error> {
|
||||
|
||||
let (config, _digest) = config::drive::config()?;
|
||||
|
||||
// early check/lock before starting worker
|
||||
let lock_guard = lock_tape_device(&config, &drive)?;
|
||||
|
||||
tokio::task::spawn_blocking(move || {
|
||||
let _lock_guard = lock_guard; // keep lock guard
|
||||
|
||||
run_drive_blocking_task(
|
||||
drive.clone(),
|
||||
"restore key".to_string(),
|
||||
move |config| {
|
||||
let mut drive = open_drive(&config, &drive)?;
|
||||
|
||||
let (_media_id, key_config) = drive.read_label()?;
|
||||
|
@ -606,7 +603,9 @@ pub async fn restore_key(
|
|||
}
|
||||
|
||||
Ok(())
|
||||
}).await?
|
||||
}
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
#[api(
|
||||
|
@ -630,15 +629,10 @@ pub async fn read_label(
|
|||
drive: String,
|
||||
inventorize: Option<bool>,
|
||||
) -> Result<MediaIdFlat, Error> {
|
||||
|
||||
let (config, _digest) = config::drive::config()?;
|
||||
|
||||
// early check/lock before starting worker
|
||||
let lock_guard = lock_tape_device(&config, &drive)?;
|
||||
|
||||
tokio::task::spawn_blocking(move || {
|
||||
let _lock_guard = lock_guard; // keep lock guard
|
||||
|
||||
run_drive_blocking_task(
|
||||
drive.clone(),
|
||||
"reading label".to_string(),
|
||||
move |config| {
|
||||
let mut drive = open_drive(&config, &drive)?;
|
||||
|
||||
let (media_id, _key_config) = drive.read_label()?;
|
||||
|
@ -688,7 +682,9 @@ pub async fn read_label(
|
|||
};
|
||||
|
||||
Ok(media_id)
|
||||
}).await?
|
||||
}
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
#[api(
|
||||
|
@ -755,15 +751,10 @@ pub fn clean_drive(
|
|||
pub async fn inventory(
|
||||
drive: String,
|
||||
) -> Result<Vec<LabelUuidMap>, Error> {
|
||||
|
||||
let (config, _digest) = config::drive::config()?;
|
||||
|
||||
// early check/lock before starting worker
|
||||
let lock_guard = lock_tape_device(&config, &drive)?;
|
||||
|
||||
tokio::task::spawn_blocking(move || {
|
||||
let _lock_guard = lock_guard; // keep lock guard
|
||||
|
||||
run_drive_blocking_task(
|
||||
drive.clone(),
|
||||
"inventorize".to_string(),
|
||||
move |config| {
|
||||
let (mut changer, changer_name) = required_media_changer(&config, &drive)?;
|
||||
|
||||
let label_text_list = changer.online_media_label_texts()?;
|
||||
|
@ -797,7 +788,9 @@ pub async fn inventory(
|
|||
}
|
||||
|
||||
Ok(list)
|
||||
}).await?
|
||||
}
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
#[api(
|
||||
|
|
Loading…
Reference in New Issue