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] tape/drive: improve tape device locking behaviour
Date: Wed,  2 Jun 2021 10:19:36 +0200	[thread overview]
Message-ID: <20210602081936.20907-1-d.csapak@proxmox.com> (raw)

by passing through errors if they are of the 'Interrupted' kind,
since that happens mostly when the lock is interrupted by the
timeout timer signal.

In the api, check in the worker loop for exactly this error and continue only
then. All other errors lead to a aborted task.

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
an alternative solution would be to change the function signature to
return an Option<Guard> instead and check that, but this would
be a 'weird' interface for a locking function...

 src/api2/tape/backup.rs | 20 +++++++++++++++-----
 src/tape/drive/mod.rs   | 10 ++++++++--
 2 files changed, 23 insertions(+), 7 deletions(-)

diff --git a/src/api2/tape/backup.rs b/src/api2/tape/backup.rs
index 77b11bb0..7e1de88e 100644
--- a/src/api2/tape/backup.rs
+++ b/src/api2/tape/backup.rs
@@ -203,12 +203,22 @@ pub fn do_tape_backup_job(
                     // for scheduled tape backup jobs, we wait indefinitely for the lock
                     task_log!(worker, "waiting for drive lock...");
                     loop {
-                        if let Ok(lock) = lock_tape_device(&drive_config, &setup.drive) {
-                            drive_lock = Some(lock);
-                            break;
-                        } // ignore errors
-
                         worker.check_abort()?;
+                        match lock_tape_device(&drive_config, &setup.drive) {
+                            Ok(lock) => {
+                                drive_lock = Some(lock);
+                                break;
+                            }
+                            Err(err) => {
+                                if let Some(err) = err.downcast_ref::<std::io::Error>() {
+                                    if err.kind() == std::io::ErrorKind::Interrupted {
+                                        // locking was probably interrupted due to a timeout
+                                        continue;
+                                    }
+                                }
+                                return Err(err);
+                            }
+                        }
                     }
                 }
                 set_tape_device_state(&setup.drive, &worker.upid().to_string())?;
diff --git a/src/tape/drive/mod.rs b/src/tape/drive/mod.rs
index f72e0b51..5cc81924 100644
--- a/src/tape/drive/mod.rs
+++ b/src/tape/drive/mod.rs
@@ -485,8 +485,14 @@ pub fn lock_tape_device(
     drive: &str,
 ) -> Result<DeviceLockGuard, Error> {
     let path = tape_device_path(config, drive)?;
-    lock_device_path(&path)
-        .map_err(|err| format_err!("unable to lock drive '{}' - {}", drive, err))
+    match lock_device_path(&path) {
+        Ok(lock) => Ok(lock),
+        // we do not change interrrupted errors, so that the caller can catch that
+        Err(err) => match err.downcast_ref::<std::io::Error>() {
+            Some(e) if e.kind() == std::io::ErrorKind::Interrupted => Err(err),
+            _ => bail!("unable to lock drive '{}' - {}", drive, err),
+        }
+    }
 }
 
 /// Writes the given state for the specified drive
-- 
2.20.1





                 reply	other threads:[~2021-06-02  8:20 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20210602081936.20907-1-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