Skip to main content

btrfs_cli/scrub/
cancel.rs

1use crate::{RunContext, Runnable, util::open_path};
2use anyhow::{Context, Result};
3use btrfs_uapi::scrub::scrub_cancel;
4use clap::Parser;
5use std::{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, _ctx: &RunContext) -> Result<()> {
16        let file = open_path(&self.path)?;
17
18        scrub_cancel(file.as_fd()).with_context(|| {
19            format!("failed to cancel scrub on '{}'", self.path.display())
20        })?;
21
22        println!("scrub cancelled on '{}'", self.path.display());
23        Ok(())
24    }
25}