all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: Christian Ebner <c.ebner@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [PATCH proxmox-backup 04/10] datastore: index: return dedicated type for chunk offset trait method
Date: Tue, 17 Nov 2026 16:28:08 +0100	[thread overview]
Message-ID: <20261117152814.491323-5-c.ebner@proxmox.com> (raw)
In-Reply-To: <20261117152814.491323-1-c.ebner@proxmox.com>

The trait method chunk_from_offset() as declared on IndexFile returns
the corresponding chunk position within the index file and the
relative offset within that chunk for a given absolute byte offset.

These values were however returned as tuple only, making it harder to
follow when reading the code.

Improve readability and protect against tuple value reordering by
returning a dedicated IndexedChunkOffset struct with fields chunk_pos
and relative_offset, instead of the opaque tuple positions.

No functional changes.

Signed-off-by: Christian Ebner <c.ebner@proxmox.com>
---
 pbs-datastore/src/cached_chunk_reader.rs |  9 ++++++---
 pbs-datastore/src/dynamic_index.rs       |  9 ++++++---
 pbs-datastore/src/fixed_index.rs         | 12 ++++++------
 pbs-datastore/src/index.rs               | 11 ++++++++++-
 src/bin/proxmox_backup_debug/diff.rs     |  4 ++--
 5 files changed, 30 insertions(+), 15 deletions(-)

diff --git a/pbs-datastore/src/cached_chunk_reader.rs b/pbs-datastore/src/cached_chunk_reader.rs
index 95ac23a54..e2336d874 100644
--- a/pbs-datastore/src/cached_chunk_reader.rs
+++ b/pbs-datastore/src/cached_chunk_reader.rs
@@ -76,9 +76,12 @@ impl<I: IndexFile, R: AsyncReadChunk + Send + Sync + 'static> CachedChunkReader<
         let mut read: usize = 0;
         while read < size {
             let cur_offset = offset + read as u64;
-            if let Some(chunk) = self.index.chunk_from_offset(cur_offset) {
+            if let Some(indexed_chunk_offset) = self.index.chunk_from_offset(cur_offset) {
                 // chunk indices retrieved from chunk_from_offset always resolve to Some(_)
-                let info = self.index.chunk_info(chunk.0).unwrap();
+                let info = self
+                    .index
+                    .chunk_info(indexed_chunk_offset.chunk_pos)
+                    .unwrap();
 
                 // will never be None, see AsyncChunkCacher
                 let data = self
@@ -89,7 +92,7 @@ impl<I: IndexFile, R: AsyncReadChunk + Send + Sync + 'static> CachedChunkReader<
 
                 let want_bytes = ((info.range.end - cur_offset) as usize).min(size - read);
                 let slice = &mut buf[read..(read + want_bytes)];
-                let intra_chunk = chunk.1 as usize;
+                let intra_chunk = indexed_chunk_offset.relative_offset as usize;
                 slice.copy_from_slice(&data[intra_chunk..(intra_chunk + want_bytes)]);
                 read += want_bytes;
             } else {
diff --git a/pbs-datastore/src/dynamic_index.rs b/pbs-datastore/src/dynamic_index.rs
index a0d9369a5..e4e485e0e 100644
--- a/pbs-datastore/src/dynamic_index.rs
+++ b/pbs-datastore/src/dynamic_index.rs
@@ -17,7 +17,7 @@ use pxar::accessor::{MaybeReady, ReadAt, ReadAtOperation};
 use pbs_tools::lru_cache::LruCache;
 
 use crate::file_formats;
-use crate::index::{ChunkReadInfo, IndexFile};
+use crate::index::{ChunkReadInfo, IndexFile, IndexedChunkOffset};
 use crate::read_chunk::ReadChunk;
 
 /// Header format definition for dynamic index files (`.dixd`)
@@ -247,7 +247,7 @@ impl IndexFile for DynamicIndexReader {
         self.size
     }
 
-    fn chunk_from_offset(&self, offset: u64) -> Option<(usize, u64)> {
+    fn chunk_from_offset(&self, offset: u64) -> Option<IndexedChunkOffset> {
         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);
@@ -262,7 +262,10 @@ impl IndexFile for DynamicIndexReader {
             self.chunk_end(found_idx - 1)
         };
 
-        Some((found_idx, offset - found_start))
+        Some(IndexedChunkOffset {
+            chunk_pos: found_idx,
+            relative_offset: offset - found_start,
+        })
     }
 }
 
diff --git a/pbs-datastore/src/fixed_index.rs b/pbs-datastore/src/fixed_index.rs
index ee94eae9c..df9af7c47 100644
--- a/pbs-datastore/src/fixed_index.rs
+++ b/pbs-datastore/src/fixed_index.rs
@@ -10,7 +10,7 @@ use proxmox_io::ReadExt;
 use proxmox_uuid::Uuid;
 
 use crate::file_formats;
-use crate::index::{ChunkReadInfo, IndexFile};
+use crate::index::{ChunkReadInfo, IndexFile, IndexedChunkOffset};
 
 /// Chunk size for fixed index files.
 ///
@@ -211,15 +211,15 @@ impl IndexFile for FixedIndexReader {
         (csum, chunk_end)
     }
 
-    fn chunk_from_offset(&self, offset: u64) -> Option<(usize, u64)> {
+    fn chunk_from_offset(&self, offset: u64) -> Option<IndexedChunkOffset> {
         if offset >= self.size {
             return None;
         }
 
-        Some((
-            (offset / self.chunk_size as u64) as usize,
-            offset & (self.chunk_size - 1) as u64, // fast modulo, valid for 2^x chunk_size
-        ))
+        Some(IndexedChunkOffset {
+            chunk_pos: (offset / self.chunk_size as u64) as usize,
+            relative_offset: offset & (self.chunk_size - 1) as u64, // fast modulo, valid for 2^x chunk_size
+        })
     }
 }
 
diff --git a/pbs-datastore/src/index.rs b/pbs-datastore/src/index.rs
index b5d20ad91..dd1bee970 100644
--- a/pbs-datastore/src/index.rs
+++ b/pbs-datastore/src/index.rs
@@ -14,6 +14,15 @@ impl ChunkReadInfo {
     }
 }
 
+/// Stores an absolute byte offset as the offset relative to the start of the
+/// containing chunk and the chunk position within the index file.
+pub struct IndexedChunkOffset {
+    /// Position of the chunk within the index file
+    pub chunk_pos: usize,
+    /// Byte offset relative to the start of the chunk
+    pub relative_offset: u64,
+}
+
 /// Trait to get digest list from index files
 ///
 /// To allow easy iteration over all used chunks.
@@ -26,7 +35,7 @@ pub trait IndexFile {
     fn index_size(&self) -> usize;
 
     /// Get the chunk index and the relative offset within it for a byte offset
-    fn chunk_from_offset(&self, offset: u64) -> Option<(usize, u64)>;
+    fn chunk_from_offset(&self, offset: u64) -> Option<IndexedChunkOffset>;
 
     /// Compute index checksum and size
     fn compute_csum(&self) -> ([u8; 32], u64);
diff --git a/src/bin/proxmox_backup_debug/diff.rs b/src/bin/proxmox_backup_debug/diff.rs
index 7fef82252..9cfbcddb6 100644
--- a/src/bin/proxmox_backup_debug/diff.rs
+++ b/src/bin/proxmox_backup_debug/diff.rs
@@ -354,11 +354,11 @@ fn visit_directory<'f, 'c>(
             let first_chunk = index
                 .chunk_from_offset(range.start)
                 .context("Invalid offset")?
-                .0;
+                .chunk_pos;
             let last_chunk = index
                 .chunk_from_offset(range.end)
                 .context("Invalid offset")?
-                .0;
+                .chunk_pos;
 
             if entry.is_dir() {
                 let new_dir = entry.enter_directory().await?;
-- 
2.47.3





  parent reply	other threads:[~2026-11-17 15:28 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-17 15:28 [PATCH proxmox-backup/pxar 00/10] fix #8319: support split pxar archives in proxmox-backup-debug diff Christian Ebner
2026-11-17 15:28 ` [PATCH pxar 01/10] encoder: record metadata-only goodbye size for split archive files Christian Ebner
2026-11-17 15:28 ` [PATCH pxar 02/10] accessor: limit split archive file entry ranges to payload reference Christian Ebner
2026-11-17 15:28 ` [PATCH pxar 03/10] accessor: add convenience helper to get content's byte range Christian Ebner
2026-11-17 15:28 ` Christian Ebner [this message]
2026-11-17 15:28 ` [PATCH proxmox-backup 05/10] bin: debug: fix off-by-one error in last chunk lookup Christian Ebner
2026-11-17 15:28 ` [PATCH proxmox-backup 06/10] bin: debug: refactore dynamic index reader opening logic into helper Christian Ebner
2026-11-17 15:28 ` [PATCH proxmox-backup 07/10] bin: debug: refactor and deduplicate chunk range difference check Christian Ebner
2026-11-17 15:28 ` [PATCH proxmox-backup 08/10] fix #8319: bin: debug: support split pxar archives via diff Christian Ebner
2026-11-17 15:28 ` [PATCH proxmox-backup 09/10] bin: debug: use pxar related archive name helpers for diff Christian Ebner
2026-11-17 15:28 ` [PATCH proxmox-backup 10/10] docs: debug: mention split pxar archives for diff subcommand Christian Ebner

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=20261117152814.491323-5-c.ebner@proxmox.com \
    --to=c.ebner@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal