public inbox for pbs-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Dominik Csapak <d.csapak@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH proxmox-backup 4/5] tape/drive: improve error and email handling for requesting a tape load
Date: Wed,  3 Mar 2021 15:00:52 +0100	[thread overview]
Message-ID: <20210303140053.20936-4-d.csapak@proxmox.com> (raw)
In-Reply-To: <20210303140053.20936-1-d.csapak@proxmox.com>

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 <d.csapak@proxmox.com>
---
 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<String>,
 ) -> 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





  parent reply	other threads:[~2021-03-03 14:00 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-03 14:00 [pbs-devel] [PATCH proxmox-backup 1/5] ui: tape/DriveStatus: fix handler name for eject Dominik Csapak
2021-03-03 14:00 ` [pbs-devel] [PATCH proxmox-backup 2/5] add proxmox-tape zsh-completions Dominik Csapak
2021-03-03 14:00 ` [pbs-devel] [PATCH proxmox-backup 3/5] ui: tape: only add tapestore and nav element once Dominik Csapak
2021-03-03 14:00 ` Dominik Csapak [this message]
2021-03-03 14:00 ` [pbs-devel] [PATCH proxmox-backup 5/5] ui: tape: add missing monStoreErrors calls for the grids Dominik Csapak
2021-03-03 15:11 ` [pbs-devel] applied: [PATCH proxmox-backup 1/5] ui: tape/DriveStatus: fix handler name for eject Dietmar Maurer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210303140053.20936-4-d.csapak@proxmox.com \
    --to=d.csapak@proxmox.com \
    --cc=pbs-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal