Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified writeboost-cli/data/sample.cache.uninit
Binary file not shown.
14 changes: 7 additions & 7 deletions writeboost-cli/src/sub/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ enum CheckError {
"segment {seg_id} is broken. checksum: computed={computed_checksum}, expected={expected_checksum}"
)]
CacheBlockBroken {
seg_id: i32,
seg_id: u64,
computed_checksum: u32,
expected_checksum: u32,
},
}

fn do_check(devname: &str, seg_id: i32) -> Result<(), CheckError> {
fn do_check(devname: &str, seg_id: u64) -> Result<(), CheckError> {
let cache_dev = CacheDevice::new(devname.to_owned());

let mut f = File::open(&devname).expect(&format!("Device {} not found", &devname));
Expand Down Expand Up @@ -74,15 +74,15 @@ mod tests {
#[test]
fn test_check() {
let devname = "data/sample.cache.226";
let seg_id = 1;
let seg_id = 73;
let res = do_check(&devname, seg_id);
assert!(res.is_ok());
}

#[test]
fn test_uninitialized() {
let devname = "data/sample.cache.uninit";
let seg_id = 0;
let seg_id = 3;
let res = do_check(&devname, seg_id);
assert!(matches!(res, Err(CheckError::NotInitialized)));
}
Expand All @@ -94,7 +94,7 @@ pub struct CommandArgs {
#[arg(help = "Path to the cache device")]
cachedev: String,
#[arg(help = "Segment id")]
segid: i32,
segid: u64,
}

pub fn run(args: CommandArgs) {
Expand All @@ -103,10 +103,10 @@ pub fn run(args: CommandArgs) {

match do_check(&devname, id) {
Ok(()) => {}
Err(CheckError::NotInitialized) => {
Err(e @ CheckError::NotInitialized) => {
// Since segments are zero-ed out at formatting,
// if the segment is all zeros, it is considered still unused.
eprintln!("segment is not initialized");
eprintln!("{e}");
}
Err(e) => {
panic!("{e}")
Expand Down
8 changes: 4 additions & 4 deletions writeboost-cli/src/sub/dump/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,22 @@ pub struct CommandArgs {
#[arg(help = "Path to the cache device")]
cachedev: String,
#[arg(help = "Metablock index")]
mbidx: i32,
mbidx: u32,
#[arg(long, help = "MBIDX is relative to this SEGID (default is 1)")]
#[arg(default_value_t = 1)]
segid: i32,
segid: u64,
}

pub fn run(args: CommandArgs) {
let mb_idx: i32 = args.mbidx;
let mb_idx: u32 = args.mbidx;
let cache_dev = {
let devname = args.cachedev;
CacheDevice::new(devname.to_owned())
};

let mut base_id = args.segid;

base_id += mb_idx / 127;
base_id += mb_idx as u64 / 127;
let idx_inseg = mb_idx % 127;
let start_byte = (cache_dev.calc_segment_start(base_id) << 9) + ((1 + idx_inseg) << 12);

Expand Down
10 changes: 5 additions & 5 deletions writeboost-cli/src/sub/meta/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ pub struct CommandArgs {
#[arg(help = "Path to the cache device")]
cachedev: String,
#[arg(help = "Segment id. 0 means the superblock")]
segid: i32,
segid: u64,
}

pub fn run(args: CommandArgs) {
let devname: String = args.cachedev;
let id: i32 = args.segid;
let id = args.segid;

let cache_dev = CacheDevice::new(devname.to_owned());

Expand Down Expand Up @@ -56,9 +56,9 @@ pub fn run(args: CommandArgs) {
let (header, metablocks) = Segment::from_buf(&buf);

println!("[segment header]");
println!("id = {}", header.id);
println!("checksumx = {}", header.checksum);
println!("length = {}", header.length);
println!("id = {}", header.id);
println!("checksum = {}", header.checksum);
println!("length = {}", header.length);

for (i, metablock) in metablocks.iter().enumerate() {
println!(
Expand Down
14 changes: 7 additions & 7 deletions writeboost-cli/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ impl BlockDevice {
self.name.to_owned()
}

pub fn size(&self) -> i64 {
pub fn size(&self) -> u64 {
use std::str::FromStr;
let output: Vec<u8> = Command::new("blockdev")
.arg("--getsz")
Expand All @@ -34,7 +34,7 @@ impl BlockDevice {
.expect("Invalid utf8 output")
.to_string();
let output = output.trim_end();
i64::from_str(output).expect("Couldn't parse as i64")
u64::from_str(output).expect("Couldn't parse as u64")
}
}

Expand All @@ -49,13 +49,13 @@ impl CacheDevice {
}
}

fn nr_segments(&self) -> i32 {
((self.dev.size() - (1 << 11)) / (1 << 10)) as i32
fn nr_segments(&self) -> u32 {
((self.dev.size() - (1 << 11)) / (1 << 10)) as u32
}

pub fn calc_segment_start(&self, id: i32) -> i32 {
let idx = (id - 1) % self.nr_segments();
(1 << 11) + (idx * (1 << 10))
pub fn calc_segment_start(&self, id: u64) -> u32 {
let idx = (id - 1) % self.nr_segments() as u64;
(1 << 11) + (idx as u32 * (1 << 10))
}
}

Expand Down