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
38 changes: 25 additions & 13 deletions writeboost-cli/src/sub/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,23 +93,35 @@ mod tests {
pub struct CommandArgs {
#[arg(help = "Path to the cache device")]
cachedev: String,
#[arg(help = "Segment id")]
segid: u64,
#[arg(long, help = "Segment id to check")]
segid: Option<u64>,
#[arg(short, long, help = "Check all segments")]
all: bool,
}

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

match do_check(&devname, id) {
Ok(()) => {}
Err(e @ CheckError::NotInitialized) => {
// Since segments are zero-ed out at formatting,
// if the segment is all zeros, it is considered still unused.
eprintln!("{e}");
}
Err(e) => {
panic!("{e}")

let range = if let Some(seg_id) = args.segid {
seg_id..=seg_id
} else if args.all {
let cache_dev = CacheDevice::new(devname.to_owned());
let nr_segs = cache_dev.nr_segments();
1..=nr_segs as u64
} else {
panic!("either --segid or --all must be specified");
};

for seg_id in range {
match do_check(&devname, seg_id) {
Ok(()) => {}
Err(CheckError::NotInitialized) => {
// Since segments are zero-ed out at formatting,
// if the segment is all zeros, it is considered still unused.
}
Err(e) => {
panic!("{e}")
}
}
}
}
2 changes: 1 addition & 1 deletion writeboost-cli/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ impl CacheDevice {
}
}

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

Expand Down