Skip to content

Commit

Permalink
Remove set_device and tests related to method
Browse files Browse the repository at this point in the history
The previous commit changes initializing the cache so that the device
stays the same and doesn't need to be set as only the table changes.

This commit should be reverted once switching from an unencrypted pool
to an encrypted pool is supported.
  • Loading branch information
jbaublitz committed Apr 5, 2023
1 parent a177bf2 commit 9d53a35
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 215 deletions.
16 changes: 5 additions & 11 deletions src/engine/strat_engine/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -606,17 +606,11 @@ impl Pool for StratPool {
}

self.thin_pool.suspend()?;
let devices_result = self
.backstore
.init_cache(Name::new(pool_name.to_string()), pool_uuid, unowned_devices)
.and_then(|bdi| {
self.thin_pool
.set_device(self.backstore.device().expect(
"Since thin pool exists, space must have been allocated \
from the backstore, so backstore must have a cap device",
))
.and(Ok(bdi))
});
let devices_result = self.backstore.init_cache(
Name::new(pool_name.to_string()),
pool_uuid,
unowned_devices,
);
self.thin_pool.resume()?;
let devices = devices_result?;
self.write_metadata(pool_name)?;
Expand Down
14 changes: 2 additions & 12 deletions src/engine/strat_engine/thinpool/mdv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ use nix::{
};
use retry::{delay::Fixed, retry_with_index};

use devicemapper::{
DevId, DmDevice, DmOptions, LinearDev, LinearDevTargetParams, Sectors, TargetLine,
};
use devicemapper::{DevId, DmDevice, DmOptions, LinearDev, Sectors};

use crate::{
engine::{
Expand Down Expand Up @@ -227,19 +225,11 @@ impl MetadataVol {
}

/// Get a reference to the backing device
#[cfg(test)]
pub fn device(&self) -> &LinearDev {
&self.dev
}

/// Set the table of the backing device
pub fn set_table(
&mut self,
table: Vec<TargetLine<LinearDevTargetParams>>,
) -> StratisResult<()> {
self.dev.set_table(get_dm(), table)?;
Ok(())
}

/// The maximum number of filesystems that can be recorded in the MDV.
pub fn max_fs_limit(&self) -> StratisResult<u64> {
let (total_size, _) = fs_usage(&self.mount_pt)?;
Expand Down
195 changes: 3 additions & 192 deletions src/engine/strat_engine/thinpool/thinpool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ use retry::{delay::Fixed, retry_with_index};
use serde_json::{Map, Value};

use devicemapper::{
device_exists, Bytes, DataBlocks, Device, DmDevice, DmName, DmNameBuf, DmOptions,
FlakeyTargetParams, LinearDev, LinearDevTargetParams, LinearTargetParams, MetaBlocks, Sectors,
TargetLine, ThinDevId, ThinPoolDev, ThinPoolStatus, ThinPoolStatusSummary, ThinPoolUsage, IEC,
device_exists, Bytes, DataBlocks, Device, DmDevice, DmName, DmNameBuf, DmOptions, LinearDev,
LinearDevTargetParams, LinearTargetParams, MetaBlocks, Sectors, TargetLine, ThinDevId,
ThinPoolDev, ThinPoolStatus, ThinPoolStatusSummary, ThinPoolUsage, IEC,
};

use crate::{
Expand Down Expand Up @@ -1397,72 +1397,6 @@ impl ThinPool {
Ok(())
}

/// Set the device on all DM devices
pub fn set_device(&mut self, backstore_device: Device) -> StratisResult<bool> {
if backstore_device == self.backstore_device {
return Ok(false);
}

let xform_target_line =
|line: &TargetLine<LinearDevTargetParams>| -> TargetLine<LinearDevTargetParams> {
let new_params = match line.params {
LinearDevTargetParams::Linear(ref params) => LinearDevTargetParams::Linear(
LinearTargetParams::new(backstore_device, params.start_offset),
),
LinearDevTargetParams::Flakey(ref params) => {
let feature_args = params.feature_args.iter().cloned().collect::<Vec<_>>();
LinearDevTargetParams::Flakey(FlakeyTargetParams::new(
backstore_device,
params.start_offset,
params.up_interval,
params.down_interval,
feature_args,
))
}
};

TargetLine::new(line.start, line.length, new_params)
};

let meta_table = self
.thin_pool
.meta_dev()
.table()
.table
.clone()
.iter()
.map(&xform_target_line)
.collect::<Vec<_>>();

let data_table = self
.thin_pool
.data_dev()
.table()
.table
.clone()
.iter()
.map(&xform_target_line)
.collect::<Vec<_>>();

let mdv_table = self
.mdv
.device()
.table()
.table
.clone()
.iter()
.map(&xform_target_line)
.collect::<Vec<_>>();

self.thin_pool.set_meta_table(get_dm(), meta_table)?;
self.thin_pool.set_data_table(get_dm(), data_table)?;
self.mdv.set_table(mdv_table)?;

self.backstore_device = backstore_device;

Ok(true)
}

pub fn fs_limit(&self) -> u64 {
self.fs_limit
}
Expand Down Expand Up @@ -2369,127 +2303,4 @@ mod tests {
test_suspend_resume,
);
}

/// Set up thinpool and backstore. Set up filesystem and write to it.
/// Add cachedev to backstore, causing cache to be built.
/// Update device on self. Read written bits from filesystem
/// presented on cache device.
fn test_set_device(paths: &[&Path]) {
assert!(paths.len() > 1);

let (paths1, paths2) = paths.split_at(paths.len() / 2);

let pool_name = "pool";
let pool_uuid = PoolUuid::new_v4();

let devices1 = get_devices(paths1).unwrap();
let devices = get_devices(paths2).unwrap();

let mut backstore = Backstore::initialize(
Name::new(pool_name.to_string()),
pool_uuid,
devices,
MDADataSize::default(),
None,
)
.unwrap();
let mut pool = ThinPool::new(
pool_uuid,
&ThinPoolSizeParams::new(backstore.available_in_backstore()).unwrap(),
DATA_BLOCK_SIZE,
&mut backstore,
)
.unwrap();

let fs_uuid = pool
.create_filesystem(
pool_name,
pool_uuid,
"stratis_test_filesystem",
DEFAULT_THIN_DEV_SIZE,
)
.unwrap();

let tmp_dir = tempfile::Builder::new()
.prefix("stratis_testing")
.tempdir()
.unwrap();
let new_file = tmp_dir.path().join("stratis_test.txt");
let bytestring = b"some bytes";
{
let (_, fs) = pool.get_filesystem_by_uuid(fs_uuid).unwrap();
mount(
Some(&fs.devnode()),
tmp_dir.path(),
Some("xfs"),
MsFlags::empty(),
None as Option<&str>,
)
.unwrap();
OpenOptions::new()
.create(true)
.write(true)
.open(&new_file)
.unwrap()
.write_all(bytestring)
.unwrap();
}
let filesystem_saves = pool.mdv.filesystems().unwrap();
assert_eq!(filesystem_saves.len(), 1);
assert_eq!(
filesystem_saves
.first()
.expect("filesystem_saves().len == 1")
.uuid,
fs_uuid
);

pool.suspend().unwrap();
let old_device = backstore
.device()
.expect("Space already allocated from backstore, backstore must have device");
backstore
.init_cache(Name::new(pool_name.to_string()), pool_uuid, devices1)
.unwrap();
let new_device = backstore
.device()
.expect("Space already allocated from backstore, backstore must have device");
assert_ne!(old_device, new_device);
pool.set_device(new_device).unwrap();
pool.resume().unwrap();

let mut buf = [0u8; 10];
{
OpenOptions::new()
.read(true)
.open(&new_file)
.unwrap()
.read_exact(&mut buf)
.unwrap();
}
assert_eq!(&buf, bytestring);

let filesystem_saves = pool.mdv.filesystems().unwrap();
assert_eq!(filesystem_saves.len(), 1);
assert_eq!(
filesystem_saves
.first()
.expect("filesystem_saves().len == 1")
.uuid,
fs_uuid
);
}

#[test]
fn loop_test_set_device() {
loopbacked::test_with_spec(
&loopbacked::DeviceLimits::Range(3, 4, None),
test_set_device,
);
}

#[test]
fn real_test_set_device() {
real::test_with_spec(&real::DeviceLimits::AtLeast(2, None, None), test_set_device);
}
}

0 comments on commit 9d53a35

Please sign in to comment.