tape: use WorkerTask for erase and rewind

This commit is contained in:
Dietmar Maurer 2020-12-11 11:15:58 +01:00
parent e92c75815b
commit 663ef85992
3 changed files with 55 additions and 12 deletions

View File

@ -189,17 +189,36 @@ pub fn scan_drives(_param: Value) -> Result<Vec<TapeDeviceInfo>, Error> {
}, },
}, },
}, },
returns: {
schema: UPID_SCHEMA,
},
)] )]
/// Erase media /// Erase media
pub fn erase_media(drive: String, fast: Option<bool>) -> Result<(), Error> { pub fn erase_media(
drive: String,
fast: Option<bool>,
rpcenv: &mut dyn RpcEnvironment,
) -> Result<Value, Error> {
let (config, _digest) = config::drive::config()?; let (config, _digest) = config::drive::config()?;
let mut drive = open_drive(&config, &drive)?; check_drive_exists(&config, &drive)?; // early check before starting worker
drive.erase_media(fast.unwrap_or(true))?; let auth_id: Authid = rpcenv.get_auth_id().unwrap().parse()?;
Ok(()) let upid_str = WorkerTask::new_thread(
"erase-media",
Some(drive.clone()),
auth_id,
true,
move |_worker| {
let mut drive = open_drive(&config, &drive)?;
drive.erase_media(fast.unwrap_or(true))?;
Ok(())
}
)?;
Ok(upid_str.into())
} }
#[api( #[api(
@ -210,17 +229,35 @@ pub fn erase_media(drive: String, fast: Option<bool>) -> Result<(), Error> {
}, },
}, },
}, },
returns: {
schema: UPID_SCHEMA,
},
)] )]
/// Rewind tape /// Rewind tape
pub fn rewind(drive: String) -> Result<(), Error> { pub fn rewind(
drive: String,
rpcenv: &mut dyn RpcEnvironment,
) -> Result<Value, Error> {
let (config, _digest) = config::drive::config()?; let (config, _digest) = config::drive::config()?;
let mut drive = open_drive(&config, &drive)?; check_drive_exists(&config, &drive)?; // early check before starting worker
drive.rewind()?; let auth_id: Authid = rpcenv.get_auth_id().unwrap().parse()?;
Ok(()) let upid_str = WorkerTask::new_thread(
"rewind-media",
Some(drive.clone()),
auth_id,
true,
move |_worker| {
let mut drive = open_drive(&config, &drive)?;
drive.rewind()?;
Ok(())
}
)?;
Ok(upid_str.into())
} }
#[api( #[api(

View File

@ -103,7 +103,7 @@ fn lookup_drive_name(
}, },
)] )]
/// Erase media /// Erase media
fn erase_media( async fn erase_media(
mut param: Value, mut param: Value,
rpcenv: &mut dyn RpcEnvironment, rpcenv: &mut dyn RpcEnvironment,
) -> Result<(), Error> { ) -> Result<(), Error> {
@ -114,11 +114,13 @@ fn erase_media(
let info = &api2::tape::drive::API_METHOD_ERASE_MEDIA; let info = &api2::tape::drive::API_METHOD_ERASE_MEDIA;
match info.handler { let result = match info.handler {
ApiHandler::Sync(handler) => (handler)(param, info, rpcenv)?, ApiHandler::Sync(handler) => (handler)(param, info, rpcenv)?,
_ => unreachable!(), _ => unreachable!(),
}; };
wait_for_local_worker(result.as_str().unwrap()).await?;
Ok(()) Ok(())
} }
@ -133,7 +135,7 @@ fn erase_media(
}, },
)] )]
/// Rewind tape /// Rewind tape
fn rewind( async fn rewind(
mut param: Value, mut param: Value,
rpcenv: &mut dyn RpcEnvironment, rpcenv: &mut dyn RpcEnvironment,
) -> Result<(), Error> { ) -> Result<(), Error> {
@ -144,11 +146,13 @@ fn rewind(
let info = &api2::tape::drive::API_METHOD_REWIND; let info = &api2::tape::drive::API_METHOD_REWIND;
match info.handler { let result = match info.handler {
ApiHandler::Sync(handler) => (handler)(param, info, rpcenv)?, ApiHandler::Sync(handler) => (handler)(param, info, rpcenv)?,
_ => unreachable!(), _ => unreachable!(),
}; };
wait_for_local_worker(result.as_str().unwrap()).await?;
Ok(()) Ok(())
} }

View File

@ -277,12 +277,14 @@ Ext.define('PBS.Utils', {
"barcode-label-media": [gettext('Drive'), gettext('Barcode label media')], "barcode-label-media": [gettext('Drive'), gettext('Barcode label media')],
dircreate: [gettext('Directory Storage'), gettext('Create')], dircreate: [gettext('Directory Storage'), gettext('Create')],
dirremove: [gettext('Directory'), gettext('Remove')], dirremove: [gettext('Directory'), gettext('Remove')],
"erase-media": [gettext('Drive'), gettext('Erase media')],
garbage_collection: ['Datastore', gettext('Garbage collect')], garbage_collection: ['Datastore', gettext('Garbage collect')],
"inventory-update": [gettext('Drive'), gettext('Inventory update')], "inventory-update": [gettext('Drive'), gettext('Inventory update')],
"label-media": [gettext('Drive'), gettext('Label media')], "label-media": [gettext('Drive'), gettext('Label media')],
logrotate: [null, gettext('Log Rotation')], logrotate: [null, gettext('Log Rotation')],
prune: (type, id) => PBS.Utils.render_datastore_worker_id(id, gettext('Prune')), prune: (type, id) => PBS.Utils.render_datastore_worker_id(id, gettext('Prune')),
reader: (type, id) => PBS.Utils.render_datastore_worker_id(id, gettext('Read objects')), reader: (type, id) => PBS.Utils.render_datastore_worker_id(id, gettext('Read objects')),
"rewind-media": [gettext('Drive'), gettext('Rewind media')],
sync: ['Datastore', gettext('Remote Sync')], sync: ['Datastore', gettext('Remote Sync')],
syncjob: [gettext('Sync Job'), gettext('Remote Sync')], syncjob: [gettext('Sync Job'), gettext('Remote Sync')],
verify: ['Datastore', gettext('Verification')], verify: ['Datastore', gettext('Verification')],