btrfs_cli/balance/
cancel.rs1use super::open_path;
2use crate::{RunContext, Runnable};
3use anyhow::{Context, Result};
4use btrfs_uapi::balance::{BalanceCtl, balance_ctl};
5use clap::Parser;
6use nix::errno::Errno;
7use std::{os::unix::io::AsFd, path::PathBuf};
8
9#[derive(Parser, Debug)]
11pub struct BalanceCancelCommand {
12 pub path: PathBuf,
13}
14
15impl Runnable for BalanceCancelCommand {
16 fn run(&self, _ctx: &RunContext) -> Result<()> {
17 let file = open_path(&self.path)?;
18
19 match balance_ctl(file.as_fd(), BalanceCtl::Cancel) {
20 Ok(()) => Ok(()),
21 Err(Errno::ENOTCONN) => {
22 anyhow::bail!(
23 "balance cancel on '{}' failed: Not in progress",
24 self.path.display()
25 )
26 }
27 Err(e) => Err(e).with_context(|| {
28 format!("balance cancel on '{}' failed", self.path.display())
29 }),
30 }
31 }
32}