From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [45.144.208.40]) by lore.proxmox.com (Postfix) with ESMTPS id D71361FF0AA for ; Tue, 17 Nov 2026 16:28:42 +0100 (CET) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 0B2742167F; Tue, 17 Nov 2026 16:28:35 +0100 (CET) From: Christian Ebner 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 Message-ID: <20261117152814.491323-5-c.ebner@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261117152814.491323-1-c.ebner@proxmox.com> References: <20261117152814.491323-1-c.ebner@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1794929310777 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.368 Adjusted score from AWL reputation of From: address DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment (newer systems) RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Message-ID-Hash: 3EX2CCDXDHGMG7XEVDAXAP4JB2NYQGPR X-Message-ID-Hash: 3EX2CCDXDHGMG7XEVDAXAP4JB2NYQGPR X-MailFrom: c.ebner@proxmox.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox Backup Server development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: 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 --- 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 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 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 { 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 { 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; /// 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