forked from openzfs/zfs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add disks to zettacache live with
zcache add
command (openzfs#392)
Currently, disks are added to the zettacache implicitly, by specifying new devices on the command line with the `-c PATH` argument. This commit adds a way to add disks to the zettacache without restarting the agent, by running `zcache add PATH`. Additionally, a `zcache sync [--merge]` subcommand is added, to sync a checkpoint (and optionally request an immediate merge of the index).
- Loading branch information
Showing
10 changed files
with
418 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
//! `zcache add` subcommand | ||
use anyhow::anyhow; | ||
use anyhow::Result; | ||
use async_trait::async_trait; | ||
use clap::Parser; | ||
use util::message::AddDiskRequest; | ||
use util::message::TYPE_ADD_DISK; | ||
use util::writeln_stdout; | ||
|
||
use crate::remote_channel::RemoteChannel; | ||
use crate::remote_channel::RemoteError; | ||
use crate::subcommand::ZcacheSubCommand; | ||
|
||
#[derive(Parser)] | ||
#[clap(about = "Add a disk to the ZettaCache.")] | ||
pub struct Add { | ||
path: String, | ||
} | ||
|
||
#[async_trait] | ||
impl ZcacheSubCommand for Add { | ||
async fn invoke(&self) -> Result<()> { | ||
let mut remote = RemoteChannel::new(true).await?; | ||
|
||
let request = AddDiskRequest { | ||
path: self.path.clone(), | ||
}; | ||
|
||
match remote | ||
.call(TYPE_ADD_DISK, Some(nvpair::to_nvlist(&request).unwrap())) | ||
.await | ||
{ | ||
Ok(_) => { | ||
writeln_stdout!("Disk {} added", self.path); | ||
} | ||
Err(RemoteError::ResultError(_)) => return Err(anyhow!("No cache found")), | ||
Err(RemoteError::Other(e)) => return Err(e), | ||
} | ||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
//! `zcache sync` subcommand | ||
use anyhow::anyhow; | ||
use anyhow::Result; | ||
use async_trait::async_trait; | ||
use clap::Parser; | ||
use util::message::TYPE_INITIATE_MERGE; | ||
use util::message::TYPE_SYNC_CHECKPOINT; | ||
|
||
use crate::remote_channel::RemoteChannel; | ||
use crate::remote_channel::RemoteError; | ||
use crate::subcommand::ZcacheSubCommand; | ||
|
||
#[derive(Parser)] | ||
#[clap(about = "Wait for changes to be persisted to Zettacache.")] | ||
pub struct Sync { | ||
/// Request index merge. If a merge is already in progress, a new merge will be started as | ||
/// soon as this one completes. | ||
#[clap(long)] | ||
merge: bool, | ||
} | ||
|
||
#[async_trait] | ||
impl ZcacheSubCommand for Sync { | ||
async fn invoke(&self) -> Result<()> { | ||
let mut remote = RemoteChannel::new(true).await?; | ||
|
||
let result = if self.merge { | ||
remote.call(TYPE_INITIATE_MERGE, None).await | ||
} else { | ||
remote.call(TYPE_SYNC_CHECKPOINT, None).await | ||
}; | ||
match result { | ||
Ok(_) => {} | ||
Err(RemoteError::ResultError(_)) => return Err(anyhow!("No cache found")), | ||
Err(RemoteError::Other(e)) => return Err(e), | ||
} | ||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.