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 B0F1C7AFE6 for ; Tue, 11 May 2021 12:50:40 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id A7A0A20C8D for ; Tue, 11 May 2021 12:50:10 +0200 (CEST) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (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 B1A5820C69 for ; Tue, 11 May 2021 12:50:08 +0200 (CEST) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 8D1F7464F1 for ; Tue, 11 May 2021 12:50:08 +0200 (CEST) From: Dominik Csapak To: pbs-devel@lists.proxmox.com Date: Tue, 11 May 2021 12:50:03 +0200 Message-Id: <20210511105007.3980-2-d.csapak@proxmox.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210511105007.3980-1-d.csapak@proxmox.com> References: <20210511105007.3980-1-d.csapak@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.019 Adjusted score from AWL reputation of From: address KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [restore.rs] Subject: [pbs-devel] [PATCH proxmox-backup v5 1/5] api2/tape/restore: refactor restore code into its own function 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: Tue, 11 May 2021 10:50:40 -0000 and create the 'email' and 'restore_owner' variable at the beginning, so that we can reuse them and do not have to pass the sources of those through too many functions Signed-off-by: Dominik Csapak --- src/api2/tape/restore.rs | 189 ++++++++++++++++++++++----------------- 1 file changed, 105 insertions(+), 84 deletions(-) diff --git a/src/api2/tape/restore.rs b/src/api2/tape/restore.rs index 9884b379..d1298434 100644 --- a/src/api2/tape/restore.rs +++ b/src/api2/tape/restore.rs @@ -281,84 +281,26 @@ pub fn restore( set_tape_device_state(&drive, &worker.upid().to_string())?; - let members = inventory.compute_media_set_members(&media_set_uuid)?; + let restore_owner = owner.as_ref().unwrap_or(&auth_id); - let media_list = members.media_list(); - - let mut media_id_list = Vec::new(); - - let mut encryption_key_fingerprint = None; + let email = notify_user + .as_ref() + .and_then(|userid| lookup_user_email(userid)) + .or_else(|| lookup_user_email(&auth_id.clone().into())); - for (seq_nr, media_uuid) in media_list.iter().enumerate() { - match media_uuid { - None => { - bail!("media set {} is incomplete (missing member {}).", media_set_uuid, seq_nr); - } - Some(media_uuid) => { - let media_id = inventory.lookup_media(media_uuid).unwrap(); - if let Some(ref set) = media_id.media_set_label { // always true here - if encryption_key_fingerprint.is_none() && set.encryption_key_fingerprint.is_some() { - encryption_key_fingerprint = set.encryption_key_fingerprint.clone(); - } - } - media_id_list.push(media_id); - } - } - } task_log!(worker, "Restore mediaset '{}'", media_set); - if let Some(fingerprint) = encryption_key_fingerprint { - task_log!(worker, "Encryption key fingerprint: {}", fingerprint); - } task_log!(worker, "Pool: {}", pool); - task_log!( - worker, - "Datastore(s): {}", - store_map - .used_datastores() - .into_iter() - .map(String::from) - .collect::>() - .join(", "), + let res = restore_worker( + worker.clone(), + inventory, + media_set_uuid, + drive_config, + &drive, + store_map, + restore_owner, + email ); - - task_log!(worker, "Drive: {}", drive); - task_log!( - worker, - "Required media list: {}", - media_id_list.iter() - .map(|media_id| media_id.label.label_text.as_str()) - .collect::>() - .join(";") - ); - - let mut datastore_locks = Vec::new(); - for store_name in store_map.used_datastores() { - // explicit create shared lock to prevent GC on newly created chunks - if let Some(store) = store_map.get_datastore(store_name) { - let shared_store_lock = store.try_shared_chunk_store_lock()?; - datastore_locks.push(shared_store_lock); - } - } - - let mut checked_chunks_map = HashMap::new(); - - for media_id in media_id_list.iter() { - request_and_restore_media( - worker.clone(), - media_id, - &drive_config, - &drive, - &store_map, - &mut checked_chunks_map, - &auth_id, - ¬ify_user, - &owner, - )?; - } - - drop(datastore_locks); - task_log!(worker, "Restore mediaset '{}' done", media_set); if let Err(err) = set_tape_device_state(&drive, "") { @@ -370,13 +312,100 @@ pub fn restore( ); } - Ok(()) + res } )?; Ok(upid_str.into()) } +fn restore_worker( + worker: Arc, + inventory: Inventory, + media_set_uuid: Uuid, + drive_config: SectionConfigData, + drive_name: &str, + store_map: DataStoreMap, + restore_owner: &Authid, + email: Option, +) -> Result<(), Error> { + let members = inventory.compute_media_set_members(&media_set_uuid)?; + + let media_list = members.media_list(); + + let mut media_id_list = Vec::new(); + + let mut encryption_key_fingerprint = None; + + for (seq_nr, media_uuid) in media_list.iter().enumerate() { + match media_uuid { + None => { + bail!("media set {} is incomplete (missing member {}).", media_set_uuid, seq_nr); + } + Some(media_uuid) => { + let media_id = inventory.lookup_media(media_uuid).unwrap(); + if let Some(ref set) = media_id.media_set_label { // always true here + if encryption_key_fingerprint.is_none() && set.encryption_key_fingerprint.is_some() { + encryption_key_fingerprint = set.encryption_key_fingerprint.clone(); + } + } + media_id_list.push(media_id); + } + } + } + + if let Some(fingerprint) = encryption_key_fingerprint { + task_log!(worker, "Encryption key fingerprint: {}", fingerprint); + } + + task_log!( + worker, + "Datastore(s): {}", + store_map + .used_datastores() + .into_iter() + .map(String::from) + .collect::>() + .join(", "), + ); + + task_log!(worker, "Drive: {}", drive_name); + task_log!( + worker, + "Required media list: {}", + media_id_list.iter() + .map(|media_id| media_id.label.label_text.as_str()) + .collect::>() + .join(";") + ); + + let mut datastore_locks = Vec::new(); + for store_name in store_map.used_datastores() { + // explicit create shared lock to prevent GC on newly created chunks + if let Some(store) = store_map.get_datastore(store_name) { + let shared_store_lock = store.try_shared_chunk_store_lock()?; + datastore_locks.push(shared_store_lock); + } + } + + let mut checked_chunks_map = HashMap::new(); + + for media_id in media_id_list.iter() { + request_and_restore_media( + worker.clone(), + media_id, + &drive_config, + drive_name, + &store_map, + &mut checked_chunks_map, + restore_owner, + &email, + )?; + } + + Ok(()) +} + /// Request and restore complete media without using existing catalog (create catalog instead) pub fn request_and_restore_media( worker: Arc, @@ -385,21 +414,15 @@ pub fn request_and_restore_media( drive_name: &str, store_map: &DataStoreMap, checked_chunks_map: &mut HashMap>, - authid: &Authid, - notify_user: &Option, - owner: &Option, + restore_owner: &Authid, + email: &Option, ) -> Result<(), Error> { let media_set_uuid = match media_id.media_set_label { None => bail!("restore_media: no media set - internal error"), Some(ref set) => &set.uuid, }; - let email = notify_user - .as_ref() - .and_then(|userid| lookup_user_email(userid)) - .or_else(|| lookup_user_email(&authid.clone().into())); - - let (mut drive, info) = request_and_load_media(&worker, &drive_config, &drive_name, &media_id.label, &email)?; + let (mut drive, info) = request_and_load_media(&worker, &drive_config, &drive_name, &media_id.label, email)?; match info.media_set_label { None => { @@ -419,8 +442,6 @@ pub fn request_and_restore_media( } } - let restore_owner = owner.as_ref().unwrap_or(authid); - restore_media( worker, &mut drive, -- 2.20.1