Skip to main content

btrfs_cli/
qgroup.rs

1use crate::{CommandGroup, Runnable};
2use clap::Parser;
3
4mod assign;
5mod clear_stale;
6mod create;
7mod destroy;
8mod limit;
9mod remove;
10mod show;
11
12pub use self::{
13    assign::*, clear_stale::*, create::*, destroy::*, limit::*, remove::*,
14    show::*,
15};
16
17/// Manage quota groups.
18///
19/// Quota groups (qgroups) track and limit disk usage at the subvolume
20/// level. Each subvolume automatically gets a level-0 qgroup (e.g.
21/// 0/256 for subvolume 256) that tracks how much data it references
22/// and how much is exclusive to it. Qgroups cannot be applied to
23/// individual files or directories within a subvolume, only to whole
24/// subvolumes. This is why per-directory quotas on btrfs require
25/// creating separate subvolumes.
26///
27/// Higher-level qgroups (1/0, 2/0, ...) are user-created containers
28/// that aggregate the usage of their member subvolumes and can enforce
29/// a shared limit across all of them. For example, assigning several
30/// user home subvolumes to a single level-1 qgroup lets you cap their
31/// combined usage.
32///
33/// Quotas must be enabled first with "btrfs quota enable". Most
34/// operations require CAP_SYS_ADMIN.
35#[derive(Parser, Debug)]
36#[allow(clippy::doc_markdown)]
37#[clap(arg_required_else_help = true)]
38pub struct QgroupCommand {
39    #[clap(subcommand)]
40    pub subcommand: QgroupSubcommand,
41}
42
43impl CommandGroup for QgroupCommand {
44    fn leaf(&self) -> &dyn Runnable {
45        match &self.subcommand {
46            QgroupSubcommand::Assign(cmd) => cmd,
47            QgroupSubcommand::Remove(cmd) => cmd,
48            QgroupSubcommand::Create(cmd) => cmd,
49            QgroupSubcommand::Destroy(cmd) => cmd,
50            QgroupSubcommand::Show(cmd) => cmd,
51            QgroupSubcommand::Limit(cmd) => cmd,
52            QgroupSubcommand::ClearStale(cmd) => cmd,
53        }
54    }
55}
56
57#[derive(Parser, Debug)]
58pub enum QgroupSubcommand {
59    Assign(QgroupAssignCommand),
60    Remove(QgroupRemoveCommand),
61    Create(QgroupCreateCommand),
62    Destroy(QgroupDestroyCommand),
63    Show(QgroupShowCommand),
64    Limit(QgroupLimitCommand),
65    #[command(name = "clear-stale")]
66    ClearStale(QgroupClearStaleCommand),
67}