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 D94AC69ECD for ; Wed, 3 Mar 2021 15:00:55 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id D76FB37B46 for ; Wed, 3 Mar 2021 15:00:55 +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 A64E637B35 for ; Wed, 3 Mar 2021 15:00:54 +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 7297041C3C for ; Wed, 3 Mar 2021 15:00:54 +0100 (CET) From: Dominik Csapak To: pbs-devel@lists.proxmox.com Date: Wed, 3 Mar 2021 15:00:52 +0100 Message-Id: <20210303140053.20936-4-d.csapak@proxmox.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210303140053.20936-1-d.csapak@proxmox.com> References: <20210303140053.20936-1-d.csapak@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.199 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 URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [mod.rs, email.rs] Subject: [pbs-devel] [PATCH proxmox-backup 4/5] tape/drive: improve error and email handling for requesting a tape load 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: Wed, 03 Mar 2021 14:00:55 -0000 Try once first to load the correct tape before sending an email to insert the correct one. This way, the admin does not get a mail if the correct tape is already inserted. Also include the error we got that prompted the email to insert the tape. This means that if the admin gets prompted to insert e.g. "FOO" but inserts "BAR", he'll get an email that the wrong tape is inserted. Signed-off-by: Dominik Csapak --- src/tape/changer/email.rs | 5 +++++ src/tape/drive/mod.rs | 43 ++++++++++++++++++++++++--------------- 2 files changed, 32 insertions(+), 16 deletions(-) diff --git a/src/tape/changer/email.rs b/src/tape/changer/email.rs index 9be06196..abd7ead8 100644 --- a/src/tape/changer/email.rs +++ b/src/tape/changer/email.rs @@ -7,12 +7,17 @@ pub fn send_load_media_email( drive: &str, label_text: &str, to: &str, + reason: Option, ) -> Result<(), Error> { let subject = format!("Load Media '{}' request for drive '{}'", label_text, drive); let mut text = String::new(); + if let Some(reason) = reason { + text.push_str(&format!("The drive has the wrong or no tape inserted. Error:\n{}\n\n", reason)); + } + text.push_str("Please insert the requested media into the backup drive.\n\n"); text.push_str(&format!("Drive: {}\n", drive)); diff --git a/src/tape/drive/mod.rs b/src/tape/drive/mod.rs index ba63f4d4..8bbca98c 100644 --- a/src/tape/drive/mod.rs +++ b/src/tape/drive/mod.rs @@ -375,18 +375,34 @@ pub fn request_and_load_media( return Ok((handle, media_id)); } - task_log!(worker, "Please insert media '{}' into drive '{}'", label_text, drive); let to = "root@localhost"; // fixme - send_load_media_email(drive, &label_text, to)?; - let mut last_media_uuid = None; let mut last_error = None; + let mut tried = false; + let mut failure_reason = None; + loop { worker.check_abort()?; + if tried { + if let Some(reason) = failure_reason { + task_log!(worker, "Please insert media '{}' into drive '{}'", label_text, drive); + send_load_media_email(drive, &label_text, to, Some(reason))?; + } + + failure_reason = None; + + for _ in 0..50 { // delay 5 seconds + worker.check_abort()?; + std::thread::sleep(std::time::Duration::from_millis(100)); + } + } + + tried = true; + let mut handle = match drive_config.open() { Ok(handle) => handle, Err(err) => { @@ -394,10 +410,7 @@ pub fn request_and_load_media( if Some(err.clone()) != last_error { task_log!(worker, "tape open failed - {}", err); last_error = Some(err); - } - for _ in 0..50 { // delay 5 seconds - worker.check_abort()?; - std::thread::sleep(std::time::Duration::from_millis(100)); + failure_reason = last_error.clone(); } continue; } @@ -414,19 +427,22 @@ pub fn request_and_load_media( ); return Ok((Box::new(handle), media_id)); } else if Some(media_id.label.uuid.clone()) != last_media_uuid { - task_log!( - worker, + let err = format!( "wrong media label {} ({})", media_id.label.label_text, media_id.label.uuid.to_string(), ); + task_log!(worker, "{}", err); last_media_uuid = Some(media_id.label.uuid); + failure_reason = Some(err); } } Ok((None, _)) => { if last_media_uuid.is_some() { - task_log!(worker, "found empty media without label (please label all tapes first)"); + let err = "found empty media without label (please label all tapes first)"; + task_log!(worker, "{}", err); last_media_uuid = None; + failure_reason = Some(err.to_string()); } } Err(err) => { @@ -434,15 +450,10 @@ pub fn request_and_load_media( if Some(err.clone()) != last_error { task_log!(worker, "tape open failed - {}", err); last_error = Some(err); + failure_reason = last_error.clone(); } } } - - // eprintln!("read label failed - test again in 5 secs"); - for _ in 0..50 { // delay 5 seconds - worker.check_abort()?; - std::thread::sleep(std::time::Duration::from_millis(100)); - } } } _ => bail!("drive type '{}' not implemented!"), -- 2.20.1