Skip to content

Commit

Permalink
Change activation names to DmNameBuf
Browse files Browse the repository at this point in the history
  • Loading branch information
jbaublitz committed Mar 24, 2023
1 parent f49799c commit 840b621
Show file tree
Hide file tree
Showing 7 changed files with 229 additions and 222 deletions.
14 changes: 7 additions & 7 deletions src/engine/strat_engine/backstore/crypt/handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use std::{
use either::Either;
use serde_json::Value;

use devicemapper::{Device, Sectors};
use devicemapper::{Device, DmName, DmNameBuf, Sectors};
use libcryptsetup_rs::{
c_uint,
consts::{flags::CryptActivate, vals::EncryptionFormat},
Expand Down Expand Up @@ -64,7 +64,7 @@ impl CryptHandle {
physical_path: DevicePath,
identifiers: StratisIdentifiers,
encryption_info: EncryptionInfo,
activation_name: String,
activation_name: DmNameBuf,
pool_name: Option<Name>,
) -> StratisResult<CryptHandle> {
let device = get_devno_from_path(&physical_path)?;
Expand All @@ -82,8 +82,8 @@ impl CryptHandle {
metadata_handle: CryptMetadataHandle,
) -> StratisResult<CryptHandle> {
let activated_path = DevicePath::new(
&once(DEVICEMAPPER_PATH)
.chain(once(metadata_handle.activation_name()))
&once(DEVICEMAPPER_PATH.to_string())
.chain(once(metadata_handle.activation_name().to_string()))
.collect::<PathBuf>(),
)?;
Ok(CryptHandle {
Expand Down Expand Up @@ -138,7 +138,7 @@ impl CryptHandle {
}

/// Return the name of the activated devicemapper device.
pub fn activation_name(&self) -> &str {
pub fn activation_name(&self) -> &DmName {
self.metadata_handle.activation_name()
}

Expand Down Expand Up @@ -408,7 +408,7 @@ impl CryptHandle {
let name = self.activation_name().to_owned();
let active_device = log_on_failure!(
self.acquire_crypt_device()?
.runtime_handle(&name)
.runtime_handle(&name.to_string())
.get_active_device(),
"Failed to get device size for encrypted logical device"
);
Expand Down Expand Up @@ -449,7 +449,7 @@ impl CryptHandle {
)?;
crypt
.context_handle()
.resize(self.activation_name(), processed_size)
.resize(&self.activation_name().to_string(), processed_size)
.map_err(StratisError::Crypt)
}
}
15 changes: 7 additions & 8 deletions src/engine/strat_engine/backstore/crypt/initialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
use std::path::Path;

use either::Either;
use serde_json::Value;
use serde_json::{to_value, Value};

use devicemapper::{DmName, DmNameBuf};
use libcryptsetup_rs::{
consts::{
flags::CryptVolumeKey,
Expand Down Expand Up @@ -43,7 +44,7 @@ use crate::{
pub struct CryptInitializer {
physical_path: DevicePath,
identifiers: StratisIdentifiers,
activation_name: String,
activation_name: DmNameBuf,
}

impl CryptInitializer {
Expand All @@ -52,10 +53,9 @@ impl CryptInitializer {
pool_uuid: PoolUuid,
dev_uuid: DevUuid,
) -> CryptInitializer {
let dm_name = format_crypt_name(&dev_uuid).to_string();
CryptInitializer {
physical_path,
activation_name: dm_name,
activation_name: format_crypt_name(&dev_uuid),
identifiers: StratisIdentifiers::new(pool_uuid, dev_uuid),
}
}
Expand Down Expand Up @@ -237,12 +237,11 @@ impl CryptInitializer {
log_on_failure!(
device.token_handle().json_set(TokenInput::ReplaceToken(
STRATIS_TOKEN_ID,
&StratisLuks2Token {
&to_value(&StratisLuks2Token {
devname: self.activation_name.clone(),
identifiers: self.identifiers,
pool_name: Some(pool_name.clone()),
}
.into(),
})?,
)),
"Failed to create the Stratis token"
);
Expand All @@ -260,7 +259,7 @@ impl CryptInitializer {
pub fn rollback(
device: &mut CryptDevice,
physical_path: &Path,
name: &str,
name: &DmName,
) -> StratisResult<()> {
ensure_wiped(device, physical_path, name)
}
Expand Down
41 changes: 0 additions & 41 deletions src/engine/strat_engine/backstore/crypt/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,44 +15,3 @@ macro_rules! log_on_failure {
result?
}}
}

macro_rules! check_key {
($condition:expr, $key:tt, $value:tt) => {
if $condition {
return Err($crate::stratis::StratisError::Msg(format!(
"Stratis token key '{}' requires a value of '{}'",
$key, $value,
)));
}
};
}

macro_rules! check_and_get_key {
($get:expr, $key:tt) => {
if let Some(v) = $get {
v
} else {
return Err($crate::stratis::StratisError::Msg(format!(
"Stratis token is missing key '{}' or the value is of the wrong type",
$key
)));
}
};
($get:expr, $func:expr, $key:tt, $ty:ty) => {
if let Some(ref v) = $get {
$func(v).map_err(|e| {
$crate::stratis::StratisError::Msg(format!(
"Failed to convert value for key '{}' to type {}: {}",
$key,
stringify!($ty),
e
))
})?
} else {
return Err($crate::stratis::StratisError::Msg(format!(
"Stratis token is missing key '{}' or the value is of the wrong type",
$key
)));
}
};
}
8 changes: 4 additions & 4 deletions src/engine/strat_engine/backstore/crypt/metadata_handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use std::path::Path;

use devicemapper::Device;
use devicemapper::{Device, DmName, DmNameBuf};

use crate::{
engine::{
Expand All @@ -23,7 +23,7 @@ pub struct CryptMetadataHandle {
pub(super) physical_path: DevicePath,
pub(super) identifiers: StratisIdentifiers,
pub(super) encryption_info: EncryptionInfo,
pub(super) activation_name: String,
pub(super) activation_name: DmNameBuf,
pub(super) pool_name: Option<Name>,
pub(super) device: Device,
}
Expand All @@ -33,7 +33,7 @@ impl CryptMetadataHandle {
physical_path: DevicePath,
identifiers: StratisIdentifiers,
encryption_info: EncryptionInfo,
activation_name: String,
activation_name: DmNameBuf,
pool_name: Option<Name>,
device: Device,
) -> Self {
Expand Down Expand Up @@ -72,7 +72,7 @@ impl CryptMetadataHandle {
}

/// Get the name of the activated device when it is activated.
pub fn activation_name(&self) -> &str {
pub fn activation_name(&self) -> &DmName {
&self.activation_name
}

Expand Down
4 changes: 2 additions & 2 deletions src/engine/strat_engine/backstore/crypt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,11 +274,11 @@ mod tests {
libc::close(fd);
};

let device_name = handle.activation_name().to_owned();
let device_name = handle.activation_name();
loop {
match libcryptsetup_rs::status(
Some(&mut handle.acquire_crypt_device().unwrap()),
&device_name,
&device_name.to_string(),
) {
Ok(CryptStatusInfo::Busy) => (),
Ok(CryptStatusInfo::Active) => break,
Expand Down
Loading

0 comments on commit 840b621

Please sign in to comment.