create backup mod in backup.rs, improve docu

This commit is contained in:
Dietmar Maurer 2018-12-31 16:08:04 +01:00
parent cb4412b18e
commit cbdd8c54ae
3 changed files with 24 additions and 13 deletions

6
src/backup.rs Normal file
View File

@ -0,0 +1,6 @@
//! This mudule implements the proxmox backup chunked data storage
pub mod chunker;
pub mod chunk_store;
pub mod image_index;
pub mod datastore;

View File

@ -1,6 +1,12 @@
//! Slinding window chunker //! Slinding window chunker (Buzhash)
//! //!
//! This is a rewrite of *casync* chunker (cachunker.h) in rust //! This is a rewrite of *casync* chunker (cachunker.h) in rust.
//!
//! Hashing by cyclic polynomial (also called Buzhash) has the benefit
//! of avoiding multiplications, using barrel shifts instead. For more
//! information please take a look at the [Rolling
//! Hash](https://en.wikipedia.org/wiki/Rolling_hash) artikel from
//! wikipedia.
use std::io::Write; use std::io::Write;
@ -92,6 +98,9 @@ const BUZHASH_TABLE: [u32; 256] = [
impl Chunker { impl Chunker {
/// Create a new Chunker instance, which produces and average chunk
/// size of `chunk_size_avg`. We allow variation from
/// `chunk_size_avg/4` up to a maximum of `chunk_size_avg*4`.
pub fn new(chunk_size_avg: usize) -> Self { pub fn new(chunk_size_avg: usize) -> Self {
// The chunk cut discriminator. In order to get an average // The chunk cut discriminator. In order to get an average
// chunk size of avg, we cut whenever for a hash value "h" at // chunk size of avg, we cut whenever for a hash value "h" at
@ -118,10 +127,10 @@ impl Chunker {
} }
} }
// Scans the specified data for a chunk border. Returns 0 if none /// Scans the specified data for a chunk border. Returns 0 if none
// was found (and the function should be called with more data /// was found (and the function should be called with more data
// later on), or another value indicating the position of a /// later on), or another value indicating the position of a
// border. /// border.
pub fn scan(&mut self, data: &[u8]) -> usize { pub fn scan(&mut self, data: &[u8]) -> usize {
let window_len = self.window.len(); let window_len = self.window.len();
@ -160,6 +169,7 @@ impl Chunker {
BUZHASH_TABLE[enter as usize]; BUZHASH_TABLE[enter as usize];
self.chunk_size += 1; self.chunk_size += 1;
pos += 1; pos += 1;
if self.shall_break() { if self.shall_break() {
self.h = 0; self.h = 0;
@ -172,6 +182,7 @@ impl Chunker {
0 0
} }
#[inline(always)]
fn shall_break(&self) -> bool { fn shall_break(&self) -> bool {
if self.chunk_size >= self.chunk_size_max { return true; } if self.chunk_size >= self.chunk_size_max { return true; }

View File

@ -34,13 +34,7 @@ pub mod catar;
pub mod section_config; pub mod section_config;
pub mod backup { pub mod backup;
pub mod chunker;
pub mod chunk_store;
pub mod image_index;
pub mod datastore;
}
pub mod config { pub mod config {