btrfs_cli/qgroup/
clear_stale.rs1use crate::{Format, Runnable};
2use anyhow::{Context, Result};
3use clap::Parser;
4use std::{fs::File, 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 = File::open(&self.path).with_context(|| {
16 format!("failed to open '{}'", self.path.display())
17 })?;
18
19 let n = btrfs_uapi::quota::qgroup_clear_stale(file.as_fd())
20 .with_context(|| {
21 format!(
22 "failed to clear stale qgroups on '{}'",
23 self.path.display()
24 )
25 })?;
26
27 if n == 0 {
28 println!("no stale qgroups found");
29 } else {
30 println!(
31 "deleted {} stale qgroup{}",
32 n,
33 if n == 1 { "" } else { "s" }
34 );
35 }
36
37 Ok(())
38 }
39}