Skip to content

Commit

Permalink
fix(casperf/lvs): purge lvs by wiping the first 8MiB
Browse files Browse the repository at this point in the history
Signed-off-by: Tiago Castro <[email protected]>
  • Loading branch information
tiagolobocastro committed Oct 3, 2023
1 parent d7015e4 commit 9c92b58
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 31 deletions.
76 changes: 47 additions & 29 deletions io-engine/src/bdev/lvs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,42 +232,60 @@ impl Lvs {
LvsMode::CreateOrImport => {
crate::lvs::Lvs::create_or_import(args).await
}
LvsMode::Purge => match self.destroy().await {
Ok(_)
| Err(BdevError::BdevNotFound {
..
}) => match crate::lvs::Lvs::create_or_import(args.clone())
.await
{
Ok(lvs) => Ok(lvs),
Err(crate::lvs::Error::Import {
reason:
crate::lvs::ImportErrorReason::NameMismatch {
name,
},
..
}) => {
let mut eargs = args.clone();
eargs.name = name;
match crate::lvs::Lvs::create_or_import(eargs).await {
Ok(lvs) => {
lvs.destroy().await.ok();
crate::lvs::Lvs::create_or_import(args).await
}
Err(error) => Err(error),
}
}
Err(error) => Err(error),
},
Err(error) => return Err(error),
},
LvsMode::Purge => {
Self::wipe_super(args.clone()).await?;
crate::lvs::Lvs::create_or_import(args).await
}
}
.map_err(|error| BdevError::CreateBdevFailedStr {
error: error.to_string(),
name: self.name.to_owned(),
})
}

async fn wipe_super(args: PoolArgs) -> Result<(), BdevError> {
let disk =
crate::lvs::Lvs::parse_disk(args.disks.clone()).map_err(|_| {
BdevError::InvalidUri {
uri: String::new(),
message: String::new(),
}
})?;

let parsed = super::uri::parse(&disk)?;
let bdev_str = parsed.create().await?;
{
let bdev =
crate::core::Bdev::get_by_name(&bdev_str).map_err(|_| {
BdevError::BdevNotFound {
name: bdev_str,
}
})?;

let hdl = crate::core::Bdev::open(&bdev, true)
.and_then(|desc| desc.into_handle())
.map_err(|_| BdevError::BdevNotFound {
name: bdev.name().into(),
})?;

let wiper = crate::core::wiper::Wiper::new(
hdl,
crate::core::wiper::WipeMethod::WriteZeroes,
)
.map_err(|_| BdevError::WipeFailed {})?;
wiper
.wipe(0, 8 * 1024 * 1024)
.await
.map_err(|_| BdevError::WipeFailed {})?;
}
// We can't destroy the device here as this causes issues with the next
// section. Seems the deletion of nvme device is not sync as
// bdev_nvme_delete implies..
// todo: ensure nvme delete does what it says..
// parsed.destroy().await.unwrap();
Ok(())
}

async fn destroy(&self) -> Result<(), BdevError> {
debug!("{self:?}: deleting");
let Some(lvs) = crate::lvs::Lvs::lookup(&self.name) else {
Expand Down
2 changes: 2 additions & 0 deletions io-engine/src/bdev_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ pub enum BdevError {
// Command canceled.
#[snafu(display("Command canceled for a BDEV '{}'", name))]
BdevCommandCanceled { source: Canceled, name: String },
#[snafu(display("Failed to wipe the BDEV"))]
WipeFailed {},
}

/// Parse URI and create bdev described in the URI.
Expand Down
2 changes: 1 addition & 1 deletion io-engine/src/core/wiper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ impl Wiper {
})
}
/// Wipe the bdev at the given byte offset and byte size.
async fn wipe(&self, offset: u64, size: u64) -> Result<(), Error> {
pub async fn wipe(&self, offset: u64, size: u64) -> Result<(), Error> {
match self.wipe_method {
WipeMethod::None => Ok(()),
WipeMethod::WriteZeroes => {
Expand Down
2 changes: 1 addition & 1 deletion io-engine/src/lvs/lvs_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ impl Lvs {
}

// checks for the disks length and parses to correct format
fn parse_disk(disks: Vec<String>) -> Result<String, Error> {
pub fn parse_disk(disks: Vec<String>) -> Result<String, Error> {
let disk = match disks.first() {
Some(disk) if disks.len() == 1 => {
if Url::parse(disk).is_err() {
Expand Down

0 comments on commit 9c92b58

Please sign in to comment.