diff --git a/src/engine/strat_engine/pool.rs b/src/engine/strat_engine/pool.rs index 862560da099..baff33871db 100644 --- a/src/engine/strat_engine/pool.rs +++ b/src/engine/strat_engine/pool.rs @@ -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)?; diff --git a/src/engine/strat_engine/thinpool/mdv.rs b/src/engine/strat_engine/thinpool/mdv.rs index 444b763eda4..5e3c46beceb 100644 --- a/src/engine/strat_engine/thinpool/mdv.rs +++ b/src/engine/strat_engine/thinpool/mdv.rs @@ -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::{ @@ -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>, - ) -> 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 { let (total_size, _) = fs_usage(&self.mount_pt)?; diff --git a/src/engine/strat_engine/thinpool/thinpool.rs b/src/engine/strat_engine/thinpool/thinpool.rs index 97427d969f4..00506f5ff9d 100644 --- a/src/engine/strat_engine/thinpool/thinpool.rs +++ b/src/engine/strat_engine/thinpool/thinpool.rs @@ -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::{ @@ -1397,72 +1397,6 @@ impl ThinPool { Ok(()) } - /// Set the device on all DM devices - pub fn set_device(&mut self, backstore_device: Device) -> StratisResult { - if backstore_device == self.backstore_device { - return Ok(false); - } - - let xform_target_line = - |line: &TargetLine| -> TargetLine { - 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::>(); - 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::>(); - - let data_table = self - .thin_pool - .data_dev() - .table() - .table - .clone() - .iter() - .map(&xform_target_line) - .collect::>(); - - let mdv_table = self - .mdv - .device() - .table() - .table - .clone() - .iter() - .map(&xform_target_line) - .collect::>(); - - 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 } @@ -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); - } }