tape: avoid executor blocking in drive API
By using tokio::task::spawn_blocking().
This commit is contained in:
parent
2d87f2fb73
commit
66dbe5639e
@ -70,7 +70,7 @@ use crate::{
|
||||
},
|
||||
)]
|
||||
/// Load media via changer from slot
|
||||
pub fn load_slot(
|
||||
pub async fn load_slot(
|
||||
drive: String,
|
||||
slot: u64,
|
||||
_param: Value,
|
||||
@ -85,9 +85,10 @@ pub fn load_slot(
|
||||
None => bail!("drive '{}' has no associated changer", drive),
|
||||
};
|
||||
|
||||
tokio::task::spawn_blocking(move || {
|
||||
let drivenum = drive_config.changer_drive_id.unwrap_or(0);
|
||||
|
||||
mtx_load(&changer.path, slot, drivenum)
|
||||
}).await?
|
||||
}
|
||||
|
||||
#[api(
|
||||
@ -105,15 +106,14 @@ pub fn load_slot(
|
||||
/// Load media with specified label
|
||||
///
|
||||
/// Issue a media load request to the associated changer device.
|
||||
pub fn load_media(drive: String, changer_id: String) -> Result<(), Error> {
|
||||
pub async fn load_media(drive: String, changer_id: String) -> Result<(), Error> {
|
||||
|
||||
let (config, _digest) = config::drive::config()?;
|
||||
|
||||
tokio::task::spawn_blocking(move || {
|
||||
let (mut changer, _) = media_changer(&config, &drive, false)?;
|
||||
|
||||
changer.load_media(&changer_id)?;
|
||||
|
||||
Ok(())
|
||||
changer.load_media(&changer_id)
|
||||
}).await?
|
||||
}
|
||||
|
||||
#[api(
|
||||
@ -131,7 +131,7 @@ pub fn load_media(drive: String, changer_id: String) -> Result<(), Error> {
|
||||
},
|
||||
)]
|
||||
/// Unload media via changer
|
||||
pub fn unload(
|
||||
pub async fn unload(
|
||||
drive: String,
|
||||
slot: Option<u64>,
|
||||
_param: Value,
|
||||
@ -146,13 +146,15 @@ pub fn unload(
|
||||
None => bail!("drive '{}' has no associated changer", drive),
|
||||
};
|
||||
|
||||
let drivenum: u64 = 0;
|
||||
let drivenum = drive_config.changer_drive_id.unwrap_or(0);
|
||||
|
||||
tokio::task::spawn_blocking(move || {
|
||||
if let Some(slot) = slot {
|
||||
mtx_unload(&changer.path, slot, drivenum)
|
||||
} else {
|
||||
drive_config.unload_media()
|
||||
}
|
||||
}).await?
|
||||
}
|
||||
|
||||
#[api(
|
||||
@ -270,10 +272,11 @@ pub fn rewind(
|
||||
},
|
||||
)]
|
||||
/// Eject/Unload drive media
|
||||
pub fn eject_media(drive: String) -> Result<(), Error> {
|
||||
pub async fn eject_media(drive: String) -> Result<(), Error> {
|
||||
|
||||
let (config, _digest) = config::drive::config()?;
|
||||
|
||||
tokio::task::spawn_blocking(move || {
|
||||
let (mut changer, _) = media_changer(&config, &drive, false)?;
|
||||
|
||||
if !changer.eject_on_unload() {
|
||||
@ -281,9 +284,8 @@ pub fn eject_media(drive: String) -> Result<(), Error> {
|
||||
drive.eject_media()?;
|
||||
}
|
||||
|
||||
changer.unload_media()?;
|
||||
|
||||
Ok(())
|
||||
changer.unload_media()
|
||||
}).await?
|
||||
}
|
||||
|
||||
#[api(
|
||||
@ -439,10 +441,11 @@ fn write_media_label(
|
||||
},
|
||||
)]
|
||||
/// Read media label
|
||||
pub fn read_label(drive: String) -> Result<MediaLabelInfoFlat, Error> {
|
||||
pub async fn read_label(drive: String) -> Result<MediaLabelInfoFlat, Error> {
|
||||
|
||||
let (config, _digest) = config::drive::config()?;
|
||||
|
||||
tokio::task::spawn_blocking(move || {
|
||||
let mut drive = open_drive(&config, &drive)?;
|
||||
|
||||
let info = drive.read_label()?;
|
||||
@ -472,6 +475,7 @@ pub fn read_label(drive: String) -> Result<MediaLabelInfoFlat, Error> {
|
||||
};
|
||||
|
||||
Ok(info)
|
||||
}).await?
|
||||
}
|
||||
|
||||
#[api(
|
||||
@ -497,12 +501,13 @@ pub fn read_label(drive: String) -> Result<MediaLabelInfoFlat, Error> {
|
||||
/// This method queries the changer to get a list of media labels.
|
||||
///
|
||||
/// Note: This updates the media online status.
|
||||
pub fn inventory(
|
||||
pub async fn inventory(
|
||||
drive: String,
|
||||
) -> Result<Vec<LabelUuidMap>, Error> {
|
||||
|
||||
let (config, _digest) = config::drive::config()?;
|
||||
|
||||
tokio::task::spawn_blocking(move || {
|
||||
let (changer, changer_name) = media_changer(&config, &drive, false)?;
|
||||
|
||||
let changer_id_list = changer.list_media_changer_ids()?;
|
||||
@ -512,7 +517,13 @@ pub fn inventory(
|
||||
let mut inventory = Inventory::load(state_path)?;
|
||||
let mut state_db = MediaStateDatabase::load(state_path)?;
|
||||
|
||||
update_changer_online_status(&config, &mut inventory, &mut state_db, &changer_name, &changer_id_list)?;
|
||||
update_changer_online_status(
|
||||
&config,
|
||||
&mut inventory,
|
||||
&mut state_db,
|
||||
&changer_name,
|
||||
&changer_id_list,
|
||||
)?;
|
||||
|
||||
let mut list = Vec::new();
|
||||
|
||||
@ -532,6 +543,7 @@ pub fn inventory(
|
||||
}
|
||||
|
||||
Ok(list)
|
||||
}).await?
|
||||
}
|
||||
|
||||
#[api(
|
||||
|
Loading…
Reference in New Issue
Block a user