btrfs_cli/balance/
pause.rs1use super::open_path;
2use crate::{Format, 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 BalancePauseCommand {
12 pub path: PathBuf,
13}
14
15impl Runnable for BalancePauseCommand {
16 fn run(&self, _format: Format, _dry_run: bool) -> Result<()> {
17 let file = open_path(&self.path)?;
18
19 match balance_ctl(file.as_fd(), BalanceCtl::Pause) {
20 Ok(()) => Ok(()),
21 Err(Errno::ENOTCONN) => {
22 anyhow::bail!(
23 "balance pause on '{}' failed: Not running",
24 self.path.display()
25 )
26 }
27 Err(e) => Err(e).with_context(|| {
28 format!("balance pause on '{}' failed", self.path.display())
29 }),
30 }
31 }
32}