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 v2 2/2] api2/tape/restore: use file offset to compensate for some tape drives
Date: Mon, 21 Jun 2021 10:18:22 +0200	[thread overview]
Message-ID: <20210621081822.9628-2-d.csapak@proxmox.com> (raw)
In-Reply-To: <20210621081822.9628-1-d.csapak@proxmox.com>

by calculating the offset after moving to a file and add the offset
to the drive

assuming the offset is static (e.g. always 1), we only have to do
that for the first file, all others should be correct then

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
changes from v1:
* rename to locate_offset

 src/api2/tape/restore.rs | 34 ++++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)

diff --git a/src/api2/tape/restore.rs b/src/api2/tape/restore.rs
index 14e20ee4..fcaa4428 100644
--- a/src/api2/tape/restore.rs
+++ b/src/api2/tape/restore.rs
@@ -685,6 +685,32 @@ fn get_media_set_catalog(
     Ok(catalog)
 }
 
+fn compensate_locate_offset(
+    worker: &WorkerTask,
+    target_file: u64,
+    real_file: u64,
+    drive: &mut Box<dyn TapeDriver>,
+) -> Result<(), Error> {
+    task_log!(worker, "landed on wrong file, adding offset and try again");
+    let offset: i64 =
+        i64::try_from((target_file as i128) - (real_file as i128)).map_err(|err| {
+            format_err!(
+                "offset between {} and {} invalid: {}",
+                target_file,
+                real_file,
+                err
+            )
+        })?;
+    drive.set_locate_offset(offset);
+    drive.move_to_file(target_file)?;
+    let current_file = drive.current_file_number()?;
+    if current_file != target_file {
+        bail!("Compensating locate_file with offset did not work, aborting...");
+    }
+
+    Ok(())
+}
+
 fn restore_snapshots_to_tmpdir(
     worker: Arc<WorkerTask>,
     path: &PathBuf,
@@ -727,6 +753,10 @@ fn restore_snapshots_to_tmpdir(
             drive.move_to_file(*file_num)?;
             let current_file_number = drive.current_file_number()?;
             task_log!(worker, "now at file {}", current_file_number);
+            if current_file_number != *file_num {
+                compensate_locate_offset(&worker, *file_num, current_file_number, &mut drive)?;
+                task_log!(worker, "now at file {}", current_file_number);
+            }
         }
         let mut reader = drive.read_next_file()?;
 
@@ -806,6 +836,10 @@ fn restore_file_chunk_map(
             drive.move_to_file(*nr)?;
             let current_file_number = drive.current_file_number()?;
             task_log!(worker, "now at file {}", current_file_number);
+            if current_file_number != *nr {
+                compensate_locate_offset(&worker, *nr, current_file_number, drive)?;
+                task_log!(worker, "now at file {}", current_file_number);
+            }
         }
         let mut reader = drive.read_next_file()?;
         let header: MediaContentHeader = unsafe { reader.read_le_value()? };
-- 
2.20.1





      reply	other threads:[~2021-06-21  8:18 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-21  8:18 [pbs-devel] [PATCH proxmox-backup v2 1/2] tape/drive: add 'set_locate_offset' to TapeDriver Trait Dominik Csapak
2021-06-21  8:18 ` Dominik Csapak [this message]

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=20210621081822.9628-2-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