From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id BEBDC6B3A2 for ; Thu, 18 Feb 2021 15:40:36 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 71B86F701 for ; Thu, 18 Feb 2021 15:40:36 +0100 (CET) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [212.186.127.180]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id 1B321F655 for ; Thu, 18 Feb 2021 15:40:32 +0100 (CET) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id D880846274 for ; Thu, 18 Feb 2021 15:40:31 +0100 (CET) From: Dominik Csapak To: pbs-devel@lists.proxmox.com Date: Thu, 18 Feb 2021 15:40:23 +0100 Message-Id: <20210218144030.16778-4-d.csapak@proxmox.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210218144030.16778-1-d.csapak@proxmox.com> References: <20210218144030.16778-1-d.csapak@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.214 Adjusted score from AWL reputation of From: address KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: [pbs-devel] [PATCH proxmox-backup 04/11] api2/tape/drive: use 'run_drive_worker' where possible X-BeenThere: pbs-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Backup Server development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 18 Feb 2021 14:40:36 -0000 Signed-off-by: Dominik Csapak --- src/api2/tape/drive.rs | 223 ++++++++++------------------------------- 1 file changed, 52 insertions(+), 171 deletions(-) diff --git a/src/api2/tape/drive.rs b/src/api2/tape/drive.rs index f4977612..7a6461b0 100644 --- a/src/api2/tape/drive.rs +++ b/src/api2/tape/drive.rs @@ -124,32 +124,20 @@ pub fn load_media( label_text: String, rpcenv: &mut dyn RpcEnvironment, ) -> Result { - - let (config, _digest) = config::drive::config()?; - - // early check/lock before starting worker - let lock_guard = lock_tape_device(&config, &drive)?; - - let auth_id: Authid = rpcenv.get_auth_id().unwrap().parse()?; - - let to_stdout = rpcenv.env_type() == RpcEnvironmentType::CLI; - let job_id = format!("{}:{}", drive, label_text); - let upid_str = WorkerTask::new_thread( + let upid_str = run_drive_worker( + rpcenv, + drive.clone(), "load-media", Some(job_id), - auth_id, - to_stdout, - move |worker| { - let _lock_guard = lock_guard; // keep lock guard - + move |worker, config| { task_log!(worker, "loading media '{}' into drive '{}'", label_text, drive); let (mut changer, _) = required_media_changer(&config, &drive)?; changer.load_media(&label_text)?; Ok(()) - } + }, )?; Ok(upid_str.into()) @@ -241,29 +229,18 @@ pub fn unload( target_slot: Option, rpcenv: &mut dyn RpcEnvironment, ) -> Result { - - let (config, _digest) = config::drive::config()?; - // early check/lock before starting worker - let lock_guard = lock_tape_device(&config, &drive)?; - - let auth_id: Authid = rpcenv.get_auth_id().unwrap().parse()?; - - let to_stdout = rpcenv.env_type() == RpcEnvironmentType::CLI; - - let upid_str = WorkerTask::new_thread( + let upid_str = run_drive_worker( + rpcenv, + drive.clone(), "unload-media", Some(drive.clone()), - auth_id, - to_stdout, - move |worker| { - let _lock_guard = lock_guard; // keep lock guard - + move |worker, config| { task_log!(worker, "unloading media from drive '{}'", drive); let (mut changer, _) = required_media_changer(&config, &drive)?; changer.unload_media(target_slot)?; Ok(()) - } + }, )?; Ok(upid_str.into()) @@ -298,23 +275,12 @@ pub fn erase_media( label_text: Option, rpcenv: &mut dyn RpcEnvironment, ) -> Result { - let (config, _digest) = config::drive::config()?; - - // early check/lock before starting worker - let lock_guard = lock_tape_device(&config, &drive)?; - - let auth_id: Authid = rpcenv.get_auth_id().unwrap().parse()?; - - let to_stdout = rpcenv.env_type() == RpcEnvironmentType::CLI; - - let upid_str = WorkerTask::new_thread( + let upid_str = run_drive_worker( + rpcenv, + drive.clone(), "erase-media", Some(drive.clone()), - auth_id, - to_stdout, - move |worker| { - let _lock_guard = lock_guard; // keep lock guard - + move |worker, config| { if let Some(ref label) = label_text { task_log!(worker, "try to load media '{}'", label); if let Some((mut changer, _)) = media_changer(&config, &drive)? { @@ -368,7 +334,7 @@ pub fn erase_media( } Ok(()) - } + }, )?; Ok(upid_str.into()) @@ -391,27 +357,16 @@ pub fn rewind( drive: String, rpcenv: &mut dyn RpcEnvironment, ) -> Result { - - let (config, _digest) = config::drive::config()?; - - // early check/lock before starting worker - let lock_guard = lock_tape_device(&config, &drive)?; - - let auth_id: Authid = rpcenv.get_auth_id().unwrap().parse()?; - - let to_stdout = rpcenv.env_type() == RpcEnvironmentType::CLI; - - let upid_str = WorkerTask::new_thread( + let upid_str = run_drive_worker( + rpcenv, + drive.clone(), "rewind-media", Some(drive.clone()), - auth_id, - to_stdout, - move |_worker| { - let _lock_guard = lock_guard; // keep lock guard + move |_worker, config| { let mut drive = open_drive(&config, &drive)?; drive.rewind()?; Ok(()) - } + }, )?; Ok(upid_str.into()) @@ -434,32 +389,21 @@ pub fn eject_media( drive: String, rpcenv: &mut dyn RpcEnvironment, ) -> Result { - - let (config, _digest) = config::drive::config()?; - - // early check/lock before starting worker - let lock_guard = lock_tape_device(&config, &drive)?; - - let auth_id: Authid = rpcenv.get_auth_id().unwrap().parse()?; - - let to_stdout = rpcenv.env_type() == RpcEnvironmentType::CLI; - - let upid_str = WorkerTask::new_thread( + let upid_str = run_drive_worker( + rpcenv, + drive.clone(), "eject-media", Some(drive.clone()), - auth_id, - to_stdout, - move |_worker| { - let _lock_guard = lock_guard; // keep lock guard - - if let Some((mut changer, _)) = media_changer(&config, &drive)? { + move |_worker, config| { + if let Some((mut changer, _)) = media_changer(&config, &drive)? { changer.unload_media(None)?; } else { let mut drive = open_drive(&config, &drive)?; drive.eject_media()?; } Ok(()) - })?; + }, + )?; Ok(upid_str.into()) } @@ -495,9 +439,6 @@ pub fn label_media( label_text: String, rpcenv: &mut dyn RpcEnvironment, ) -> Result { - - let auth_id: Authid = rpcenv.get_auth_id().unwrap().parse()?; - if let Some(ref pool) = pool { let (pool_config, _digest) = config::media_pool::config()?; @@ -505,22 +446,12 @@ pub fn label_media( bail!("no such pool ('{}')", pool); } } - - let (config, _digest) = config::drive::config()?; - - // early check/lock before starting worker - let lock_guard = lock_tape_device(&config, &drive)?; - - let to_stdout = rpcenv.env_type() == RpcEnvironmentType::CLI; - - let upid_str = WorkerTask::new_thread( + let upid_str = run_drive_worker( + rpcenv, + drive.clone(), "label-media", Some(drive.clone()), - auth_id, - to_stdout, - move |worker| { - let _lock_guard = lock_guard; // keep lock guard - + move |worker, config| { let mut drive = open_drive(&config, &drive)?; drive.rewind()?; @@ -545,7 +476,7 @@ pub fn label_media( }; write_media_label(worker, &mut drive, label, pool) - } + }, )?; Ok(upid_str.into()) @@ -757,24 +688,12 @@ pub fn clean_drive( drive: String, rpcenv: &mut dyn RpcEnvironment, ) -> Result { - - let (config, _digest) = config::drive::config()?; - - // early check/lock before starting worker - let lock_guard = lock_tape_device(&config, &drive)?; - - let auth_id: Authid = rpcenv.get_auth_id().unwrap().parse()?; - - let to_stdout = rpcenv.env_type() == RpcEnvironmentType::CLI; - - let upid_str = WorkerTask::new_thread( + let upid_str = run_drive_worker( + rpcenv, + drive.clone(), "clean-drive", Some(drive.clone()), - auth_id, - to_stdout, - move |worker| { - let _lock_guard = lock_guard; // keep lock guard - + move |worker, config| { let (mut changer, _changer_name) = required_media_changer(&config, &drive)?; worker.log("Starting drive clean"); @@ -784,7 +703,8 @@ pub fn clean_drive( worker.log("Drive cleaned sucessfully"); Ok(()) - })?; + }, + )?; Ok(upid_str.into()) } @@ -891,24 +811,12 @@ pub fn update_inventory( read_all_labels: Option, rpcenv: &mut dyn RpcEnvironment, ) -> Result { - - let (config, _digest) = config::drive::config()?; - - // early check/lock before starting worker - let lock_guard = lock_tape_device(&config, &drive)?; - - let auth_id: Authid = rpcenv.get_auth_id().unwrap().parse()?; - - let to_stdout = rpcenv.env_type() == RpcEnvironmentType::CLI; - - let upid_str = WorkerTask::new_thread( + let upid_str = run_drive_worker( + rpcenv, + drive.clone(), "inventory-update", Some(drive.clone()), - auth_id, - to_stdout, - move |worker| { - let _lock_guard = lock_guard; // keep lock guard - + move |worker, config| { let (mut changer, changer_name) = required_media_changer(&config, &drive)?; let label_text_list = changer.online_media_label_texts()?; @@ -960,7 +868,7 @@ pub fn update_inventory( changer.unload_media(None)?; } Ok(()) - } + }, )?; Ok(upid_str.into()) @@ -989,7 +897,6 @@ pub fn barcode_label_media( pool: Option, rpcenv: &mut dyn RpcEnvironment, ) -> Result { - if let Some(ref pool) = pool { let (pool_config, _digest) = config::media_pool::config()?; @@ -998,24 +905,12 @@ pub fn barcode_label_media( } } - let (drive_config, _digest) = config::drive::config()?; - - // early check/lock before starting worker - let lock_guard = lock_tape_device(&drive_config, &drive)?; - - let auth_id: Authid = rpcenv.get_auth_id().unwrap().parse()?; - - let to_stdout = rpcenv.env_type() == RpcEnvironmentType::CLI; - - let upid_str = WorkerTask::new_thread( + let upid_str = run_drive_worker( + rpcenv, + drive.clone(), "barcode-label-media", Some(drive.clone()), - auth_id, - to_stdout, - move |worker| { - let _lock_guard = lock_guard; // keep lock guard - barcode_label_media_worker(worker, drive, &drive_config, pool) - } + move |worker, config| barcode_label_media_worker(worker, drive, &config, pool), )?; Ok(upid_str.into()) @@ -1027,7 +922,6 @@ fn barcode_label_media_worker( drive_config: &SectionConfigData, pool: Option, ) -> Result<(), Error> { - let (mut changer, changer_name) = required_media_changer(drive_config, &drive)?; let label_text_list = changer.online_media_label_texts()?; @@ -1202,27 +1096,15 @@ pub fn catalog_media( verbose: Option, rpcenv: &mut dyn RpcEnvironment, ) -> Result { - let verbose = verbose.unwrap_or(false); let force = force.unwrap_or(false); - let (config, _digest) = config::drive::config()?; - - // early check/lock before starting worker - let lock_guard = lock_tape_device(&config, &drive)?; - - let auth_id: Authid = rpcenv.get_auth_id().unwrap().parse()?; - - let to_stdout = rpcenv.env_type() == RpcEnvironmentType::CLI; - - let upid_str = WorkerTask::new_thread( + let upid_str = run_drive_worker( + rpcenv, + drive.clone(), "catalog-media", Some(drive.clone()), - auth_id, - to_stdout, - move |worker| { - let _lock_guard = lock_guard; // keep lock guard - + move |worker, config| { let mut drive = open_drive(&config, &drive)?; drive.rewind()?; @@ -1279,8 +1161,7 @@ pub fn catalog_media( restore_media(&worker, &mut drive, &media_id, None, verbose)?; Ok(()) - - } + }, )?; Ok(upid_str.into()) -- 2.20.1