btrfs_cli/qgroup/
destroy.rs1use crate::{
2 Format, Runnable,
3 util::{open_path, parse_qgroupid},
4};
5use anyhow::{Context, Result};
6use clap::Parser;
7use nix::errno::Errno;
8use std::{os::unix::io::AsFd, path::PathBuf};
9
10#[derive(Parser, Debug)]
12pub struct QgroupDestroyCommand {
13 pub qgroupid: String,
15
16 pub path: PathBuf,
18}
19
20impl Runnable for QgroupDestroyCommand {
21 fn run(&self, _format: Format, _dry_run: bool) -> Result<()> {
22 let qgroupid = parse_qgroupid(&self.qgroupid)?;
23
24 let file = open_path(&self.path)?;
25
26 match btrfs_uapi::quota::qgroup_destroy(file.as_fd(), qgroupid) {
27 Ok(()) => {
28 println!("qgroup {} destroyed", self.qgroupid);
29 Ok(())
30 }
31 Err(Errno::ENOTCONN) => {
32 anyhow::bail!("quota not enabled on '{}'", self.path.display())
33 }
34 Err(e) => Err(e).with_context(|| {
35 format!(
36 "failed to destroy qgroup '{}' on '{}'",
37 self.qgroupid,
38 self.path.display()
39 )
40 }),
41 }
42 }
43}