From 663ef859921c8edf26032eeeaee16a7730c32df9 Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Fri, 11 Dec 2020 11:15:58 +0100 Subject: [PATCH] tape: use WorkerTask for erase and rewind --- src/api2/tape/drive.rs | 53 ++++++++++++++++++++++++++++++++++------- src/bin/proxmox-tape.rs | 12 ++++++---- www/Utils.js | 2 ++ 3 files changed, 55 insertions(+), 12 deletions(-) diff --git a/src/api2/tape/drive.rs b/src/api2/tape/drive.rs index 294082e8..29c16143 100644 --- a/src/api2/tape/drive.rs +++ b/src/api2/tape/drive.rs @@ -189,17 +189,36 @@ pub fn scan_drives(_param: Value) -> Result, Error> { }, }, }, + returns: { + schema: UPID_SCHEMA, + }, )] /// Erase media -pub fn erase_media(drive: String, fast: Option) -> Result<(), Error> { +pub fn erase_media( + drive: String, + fast: Option, + rpcenv: &mut dyn RpcEnvironment, +) -> Result { 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( @@ -210,17 +229,35 @@ pub fn erase_media(drive: String, fast: Option) -> 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 { 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( diff --git a/src/bin/proxmox-tape.rs b/src/bin/proxmox-tape.rs index 7659978e..f5c3264e 100644 --- a/src/bin/proxmox-tape.rs +++ b/src/bin/proxmox-tape.rs @@ -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(()) } diff --git a/www/Utils.js b/www/Utils.js index 762af312..1fd20c67 100644 --- a/www/Utils.js +++ b/www/Utils.js @@ -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')],