tape: use WorkerTask for erase and rewind
This commit is contained in:
parent
e92c75815b
commit
663ef85992
@ -189,17 +189,36 @@ pub fn scan_drives(_param: Value) -> Result<Vec<TapeDeviceInfo>, Error> {
|
||||
},
|
||||
},
|
||||
},
|
||||
returns: {
|
||||
schema: UPID_SCHEMA,
|
||||
},
|
||||
)]
|
||||
/// 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()?;
|
||||
|
||||
check_drive_exists(&config, &drive)?; // early check before starting worker
|
||||
|
||||
let auth_id: Authid = rpcenv.get_auth_id().unwrap().parse()?;
|
||||
|
||||
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(
|
||||
@ -210,17 +229,35 @@ pub fn erase_media(drive: String, fast: Option<bool>) -> Result<(), Error> {
|
||||
},
|
||||
},
|
||||
},
|
||||
returns: {
|
||||
schema: UPID_SCHEMA,
|
||||
},
|
||||
)]
|
||||
/// 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()?;
|
||||
|
||||
check_drive_exists(&config, &drive)?; // early check before starting worker
|
||||
|
||||
let auth_id: Authid = rpcenv.get_auth_id().unwrap().parse()?;
|
||||
|
||||
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(
|
||||
|
@ -103,7 +103,7 @@ fn lookup_drive_name(
|
||||
},
|
||||
)]
|
||||
/// Erase media
|
||||
fn erase_media(
|
||||
async fn erase_media(
|
||||
mut param: Value,
|
||||
rpcenv: &mut dyn RpcEnvironment,
|
||||
) -> Result<(), Error> {
|
||||
@ -114,11 +114,13 @@ fn 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)?,
|
||||
_ => unreachable!(),
|
||||
};
|
||||
|
||||
wait_for_local_worker(result.as_str().unwrap()).await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@ -133,7 +135,7 @@ fn erase_media(
|
||||
},
|
||||
)]
|
||||
/// Rewind tape
|
||||
fn rewind(
|
||||
async fn rewind(
|
||||
mut param: Value,
|
||||
rpcenv: &mut dyn RpcEnvironment,
|
||||
) -> Result<(), Error> {
|
||||
@ -144,11 +146,13 @@ fn rewind(
|
||||
|
||||
let info = &api2::tape::drive::API_METHOD_REWIND;
|
||||
|
||||
match info.handler {
|
||||
let result = match info.handler {
|
||||
ApiHandler::Sync(handler) => (handler)(param, info, rpcenv)?,
|
||||
_ => unreachable!(),
|
||||
};
|
||||
|
||||
wait_for_local_worker(result.as_str().unwrap()).await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
@ -277,12 +277,14 @@ Ext.define('PBS.Utils', {
|
||||
"barcode-label-media": [gettext('Drive'), gettext('Barcode label media')],
|
||||
dircreate: [gettext('Directory Storage'), gettext('Create')],
|
||||
dirremove: [gettext('Directory'), gettext('Remove')],
|
||||
"erase-media": [gettext('Drive'), gettext('Erase media')],
|
||||
garbage_collection: ['Datastore', gettext('Garbage collect')],
|
||||
"inventory-update": [gettext('Drive'), gettext('Inventory update')],
|
||||
"label-media": [gettext('Drive'), gettext('Label media')],
|
||||
logrotate: [null, gettext('Log Rotation')],
|
||||
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')),
|
||||
"rewind-media": [gettext('Drive'), gettext('Rewind media')],
|
||||
sync: ['Datastore', gettext('Remote Sync')],
|
||||
syncjob: [gettext('Sync Job'), gettext('Remote Sync')],
|
||||
verify: ['Datastore', gettext('Verification')],
|
||||
|
Loading…
Reference in New Issue
Block a user