From: Stefan Reiter <s.reiter@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH v2 backup 1/5] add and implement chunk_from_offset for IndexFile
Date: Wed, 22 Jul 2020 15:56:21 +0200 [thread overview]
Message-ID: <20200722135625.23653-2-s.reiter@proxmox.com> (raw)
In-Reply-To: <20200722135625.23653-1-s.reiter@proxmox.com>
Necessary for byte-wise seeking through chunks in an index.
Signed-off-by: Stefan Reiter <s.reiter@proxmox.com>
---
src/backup/dynamic_index.rs | 18 ++++++++++++++++++
src/backup/fixed_index.rs | 11 +++++++++++
src/backup/index.rs | 3 +++
3 files changed, 32 insertions(+)
diff --git a/src/backup/dynamic_index.rs b/src/backup/dynamic_index.rs
index 4907fe1f..887b7cf3 100644
--- a/src/backup/dynamic_index.rs
+++ b/src/backup/dynamic_index.rs
@@ -216,6 +216,24 @@ impl IndexFile for DynamicIndexReader {
digest: self.index[pos].digest.clone(),
})
}
+
+ fn chunk_from_offset(&self, offset: u64) -> Option<(usize, u64)> {
+ let end_idx = self.index.len() - 1;
+ let end = self.chunk_end(end_idx);
+ let found_idx = self.binary_search(0, 0, end_idx, end, offset);
+ let found_idx = match found_idx {
+ Ok(i) => i,
+ Err(_) => return None
+ };
+
+ let found_start = if found_idx == 0 {
+ 0
+ } else {
+ self.chunk_end(found_idx - 1)
+ };
+
+ Some((found_idx, offset - found_start))
+ }
}
struct CachedChunk {
diff --git a/src/backup/fixed_index.rs b/src/backup/fixed_index.rs
index 73d0dad0..b7e785d6 100644
--- a/src/backup/fixed_index.rs
+++ b/src/backup/fixed_index.rs
@@ -219,6 +219,17 @@ impl IndexFile for FixedIndexReader {
(csum, chunk_end)
}
+
+ fn chunk_from_offset(&self, offset: u64) -> Option<(usize, u64)> {
+ if offset >= self.size {
+ return None;
+ }
+
+ Some((
+ (offset / self.chunk_size as u64) as usize,
+ offset % self.chunk_size as u64
+ ))
+ }
}
pub struct FixedIndexWriter {
diff --git a/src/backup/index.rs b/src/backup/index.rs
index efdf3b54..2eab8524 100644
--- a/src/backup/index.rs
+++ b/src/backup/index.rs
@@ -22,6 +22,9 @@ pub trait IndexFile {
fn index_bytes(&self) -> u64;
fn chunk_info(&self, pos: usize) -> Option<ChunkReadInfo>;
+ /// Get the chunk index and the relative offset within it for a byte offset
+ fn chunk_from_offset(&self, offset: u64) -> Option<(usize, u64)>;
+
/// Compute index checksum and size
fn compute_csum(&self) -> ([u8; 32], u64);
--
2.20.1
next prev parent reply other threads:[~2020-07-22 13:57 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-07-22 13:56 [pbs-devel] [PATCH v2 0/5] Fix PBS blockdriver for non-VM settings Stefan Reiter
2020-07-22 13:56 ` Stefan Reiter [this message]
2020-07-22 14:16 ` [pbs-devel] [PATCH v2 backup 1/5] add and implement chunk_from_offset for IndexFile Thomas Lamprecht
2020-07-22 14:24 ` Stefan Reiter
2020-07-22 14:41 ` Thomas Lamprecht
2020-07-22 13:56 ` [pbs-devel] [PATCH v2 backup 2/5] implement AsyncSeek for AsyncIndexReader Stefan Reiter
2020-07-22 13:56 ` [pbs-devel] [PATCH v2 backup 3/5] remove BufferedFixedReader interface Stefan Reiter
2020-07-22 13:56 ` [pbs-devel] [PATCH v2 backup-qemu 4/5] use AsyncIndexReader for read_image_at Stefan Reiter
2020-07-22 13:56 ` [pbs-devel] [PATCH v2 backup-qemu 5/5] read_image_at: iterate until buffer is filled Stefan Reiter
2020-07-23 8:31 ` [pbs-devel] applied-series: [PATCH v2 0/5] Fix PBS blockdriver for non-VM settings Thomas Lamprecht
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=20200722135625.23653-2-s.reiter@proxmox.com \
--to=s.reiter@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