Skip to main content

btrfs_cli/scrub/
cancel.rs

1use crate::{Format, Runnable};
2use anyhow::{Context, Result};
3use btrfs_uapi::scrub::scrub_cancel;
4use clap::Parser;
5use std::{fs::File, os::unix::io::AsFd, path::PathBuf};
6
7/// Cancel a running scrub
8#[derive(Parser, Debug)]
9pub struct ScrubCancelCommand {
10    /// Path to a mounted btrfs filesystem or a device
11    pub path: PathBuf,
12}
13
14impl Runnable for ScrubCancelCommand {
15    fn run(&self, _format: Format, _dry_run: bool) -> Result<()> {
16        let file = File::open(&self.path).with_context(|| {
17            format!("failed to open '{}'", self.path.display())
18        })?;
19
20        scrub_cancel(file.as_fd()).with_context(|| {
21            format!("failed to cancel scrub on '{}'", self.path.display())
22        })?;
23
24        println!("scrub cancelled on '{}'", self.path.display());
25        Ok(())
26    }
27}