btrfs_cli/qgroup/
clear_stale.rs1use crate::{Format, Runnable, util::open_path};
2use anyhow::{Context, Result};
3use clap::Parser;
4use std::{os::unix::io::AsFd, path::PathBuf};
5
6#[derive(Parser, Debug)]
8pub struct QgroupClearStaleCommand {
9 pub path: PathBuf,
11}
12
13impl Runnable for QgroupClearStaleCommand {
14 fn run(&self, _format: Format, _dry_run: bool) -> Result<()> {
15 let file = open_path(&self.path)?;
16
17 let n = btrfs_uapi::quota::qgroup_clear_stale(file.as_fd())
18 .with_context(|| {
19 format!(
20 "failed to clear stale qgroups on '{}'",
21 self.path.display()
22 )
23 })?;
24
25 if n == 0 {
26 println!("no stale qgroups found");
27 } else {
28 println!(
29 "deleted {} stale qgroup{}",
30 n,
31 if n == 1 { "" } else { "s" }
32 );
33 }
34
35 Ok(())
36 }
37}