diff --git a/src/cachedev.rs b/src/cachedev.rs index 6148cbc7..f5c9b456 100644 --- a/src/cachedev.rs +++ b/src/cachedev.rs @@ -30,18 +30,27 @@ pub const MAX_CACHE_BLOCK_SIZE: Sectors = Sectors(2 * IEC::Mi); // 1 GiB const CACHE_TARGET_NAME: &str = "cache"; +/// Struct representing params for a cache target #[derive(Clone, Debug, Eq, PartialEq)] pub struct CacheTargetParams { + /// Cache metadata device pub meta: Device, + /// Cache device pub cache: Device, + /// Origin device with data to be cached pub origin: Device, + /// Cache block size pub cache_block_size: Sectors, + /// Feature arguments pub feature_args: HashSet, + /// IO policy pub policy: String, + /// IO policy arguments pub policy_args: HashMap, } impl CacheTargetParams { + /// Create a new CacheTargetParams struct pub fn new( meta: Device, cache: Device, @@ -177,12 +186,15 @@ impl TargetParams for CacheTargetParams { } } +/// A target table for a cache device. #[derive(Clone, Debug, Eq, PartialEq)] pub struct CacheDevTargetTable { + /// The device's table pub table: TargetLine, } impl CacheDevTargetTable { + /// Make a new CacheDevTargetTable from the required input pub fn new(start: Sectors, length: Sectors, params: CacheTargetParams) -> CacheDevTargetTable { CacheDevTargetTable { table: TargetLine::new(start, length, params), diff --git a/src/lib.rs b/src/lib.rs index b32d6a12..294c7fbd 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -114,8 +114,8 @@ extern crate assert_matches; pub use crate::{ cachedev::{ - CacheDev, CacheDevPerformance, CacheDevStatus, CacheDevUsage, CacheDevWorkingStatus, - MAX_CACHE_BLOCK_SIZE, MIN_CACHE_BLOCK_SIZE, + CacheDev, CacheDevPerformance, CacheDevStatus, CacheDevTargetTable, CacheDevUsage, + CacheDevWorkingStatus, CacheTargetParams, MAX_CACHE_BLOCK_SIZE, MIN_CACHE_BLOCK_SIZE, }, consts::IEC, core::{ @@ -130,11 +130,11 @@ pub use crate::{ shared::{ device_exists, DmDevice, TargetLine, TargetParams, TargetTable, TargetType, TargetTypeBuf, }, - thindev::{ThinDev, ThinDevWorkingStatus, ThinStatus}, + thindev::{ThinDev, ThinDevTargetTable, ThinDevWorkingStatus, ThinStatus, ThinTargetParams}, thindevid::ThinDevId, thinpooldev::{ - ThinPoolDev, ThinPoolNoSpacePolicy, ThinPoolStatus, ThinPoolStatusSummary, ThinPoolUsage, - ThinPoolWorkingStatus, + ThinPoolDev, ThinPoolDevTargetTable, ThinPoolNoSpacePolicy, ThinPoolStatus, + ThinPoolStatusSummary, ThinPoolTargetParams, ThinPoolUsage, ThinPoolWorkingStatus, }, units::{Bytes, DataBlocks, MetaBlocks, Sectors, SECTOR_SIZE}, }; diff --git a/src/thindev.rs b/src/thindev.rs index c37f6b45..fe05435b 100644 --- a/src/thindev.rs +++ b/src/thindev.rs @@ -18,14 +18,20 @@ use crate::{ const THIN_TARGET_NAME: &str = "thin"; +/// Struct representing params for a thin target #[derive(Clone, Debug, Eq, PartialEq)] pub struct ThinTargetParams { + /// Thin pool for the given thin device pub pool: Device, + /// Thin ID pub thin_id: ThinDevId, + /// Optional block device outside of pool to be treated as a read-only snapshot + /// origin pub external_origin_dev: Option, } impl ThinTargetParams { + /// Create a new ThinTargetParams struct pub fn new( pool: Device, thin_id: ThinDevId, @@ -92,12 +98,15 @@ impl TargetParams for ThinTargetParams { } } +/// A target table for a thin device. #[derive(Clone, Debug, Eq, PartialEq)] pub struct ThinDevTargetTable { + /// The device's table pub table: TargetLine, } impl ThinDevTargetTable { + /// Make a new ThinDevTargetTable from required input pub fn new(start: Sectors, length: Sectors, params: ThinTargetParams) -> ThinDevTargetTable { ThinDevTargetTable { table: TargetLine::new(start, length, params), diff --git a/src/thinpooldev.rs b/src/thinpooldev.rs index 83e8c556..f560c21c 100644 --- a/src/thinpooldev.rs +++ b/src/thinpooldev.rs @@ -24,16 +24,23 @@ use crate::core::devnode_to_devno; const THINPOOL_TARGET_NAME: &str = "thin-pool"; +/// Struct representing params for a thin pool target #[derive(Clone, Debug, Eq, PartialEq)] pub struct ThinPoolTargetParams { + /// Thin pool metadata device pub metadata_dev: Device, + /// Thin pool data device pub data_dev: Device, + /// Block size for allocations within the thin pool pub data_block_size: Sectors, + /// Amount of free space left at which to trigger the low water mark pub low_water_mark: DataBlocks, + /// Feature arguments pub feature_args: HashSet, } impl ThinPoolTargetParams { + /// Create a new ThinPoolTargetParams struct pub fn new( metadata_dev: Device, data_dev: Device, @@ -136,12 +143,15 @@ impl TargetParams for ThinPoolTargetParams { } } +/// A target table for a thin pool device. #[derive(Clone, Debug, Eq, PartialEq)] pub struct ThinPoolDevTargetTable { + /// The device's table pub table: TargetLine, } impl ThinPoolDevTargetTable { + /// Make a new ThinPoolDevTargetTable from a suitable vec pub fn new( start: Sectors, length: Sectors,