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