Skip to main content

btrfs_cli/
replace.rs

1use crate::{Format, Runnable};
2use anyhow::Result;
3use clap::Parser;
4
5mod cancel;
6mod start;
7mod status;
8
9use cancel::ReplaceCancelCommand;
10use start::ReplaceStartCommand;
11use status::ReplaceStatusCommand;
12
13/// Replace a device in the filesystem.
14///
15/// Replace a device with another device or a spare. During replacement,
16/// data is read from the old device and written to the new one. The replace
17/// operation can be monitored and cancelled. Requires CAP_SYS_ADMIN.
18#[derive(Parser, Debug)]
19pub struct ReplaceCommand {
20    #[clap(subcommand)]
21    pub subcommand: ReplaceSubcommand,
22}
23
24impl Runnable for ReplaceCommand {
25    fn run(&self, format: Format, dry_run: bool) -> Result<()> {
26        match &self.subcommand {
27            ReplaceSubcommand::Start(cmd) => cmd.run(format, dry_run),
28            ReplaceSubcommand::Status(cmd) => cmd.run(format, dry_run),
29            ReplaceSubcommand::Cancel(cmd) => cmd.run(format, dry_run),
30        }
31    }
32}
33
34#[derive(Parser, Debug)]
35pub enum ReplaceSubcommand {
36    Start(ReplaceStartCommand),
37    Status(ReplaceStatusCommand),
38    Cancel(ReplaceCancelCommand),
39}