Skip to main content

btrfs_cli/quota/
enable.rs

1use crate::{RunContext, Runnable, util::open_path};
2use anyhow::{Context, Result};
3use clap::Parser;
4use std::{os::unix::io::AsFd, path::PathBuf};
5
6/// Enable subvolume quota support for a filesystem
7#[derive(Parser, Debug)]
8pub struct QuotaEnableCommand {
9    /// Path to a mounted btrfs filesystem
10    pub path: PathBuf,
11
12    /// Simple qgroups: account ownership by extent lifetime rather than backref walks
13    #[clap(short = 's', long)]
14    pub simple: bool,
15}
16
17impl Runnable for QuotaEnableCommand {
18    fn run(&self, _ctx: &RunContext) -> Result<()> {
19        let file = open_path(&self.path)?;
20
21        btrfs_uapi::quota::quota_enable(file.as_fd(), self.simple)
22            .with_context(|| {
23                format!("failed to enable quota on '{}'", self.path.display())
24            })?;
25
26        if self.simple {
27            println!(
28                "quota enabled (simple mode) on '{}'",
29                self.path.display()
30            );
31        } else {
32            println!("quota enabled on '{}'", self.path.display());
33        }
34
35        Ok(())
36    }
37}