Skip to content

Commit

Permalink
Make target table structs public to support easier alternate table co…
Browse files Browse the repository at this point in the history
…nstruction
  • Loading branch information
jbaublitz committed Mar 13, 2023
1 parent c26372b commit fd707cf
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 5 deletions.
12 changes: 12 additions & 0 deletions src/cachedev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>,
/// IO policy
pub policy: String,
/// IO policy arguments
pub policy_args: HashMap<String, String>,
}

impl CacheTargetParams {
/// Create a new CacheTargetParams struct
pub fn new(
meta: Device,
cache: Device,
Expand Down Expand Up @@ -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<CacheTargetParams>,
}

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),
Expand Down
10 changes: 5 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand All @@ -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},
};
9 changes: 9 additions & 0 deletions src/thindev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Device>,
}

impl ThinTargetParams {
/// Create a new ThinTargetParams struct
pub fn new(
pool: Device,
thin_id: ThinDevId,
Expand Down Expand Up @@ -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<ThinTargetParams>,
}

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),
Expand Down
10 changes: 10 additions & 0 deletions src/thinpooldev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>,
}

impl ThinPoolTargetParams {
/// Create a new ThinPoolTargetParams struct
pub fn new(
metadata_dev: Device,
data_dev: Device,
Expand Down Expand Up @@ -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<ThinPoolTargetParams>,
}

impl ThinPoolDevTargetTable {
/// Make a new ThinPoolDevTargetTable from a suitable vec
pub fn new(
start: Sectors,
length: Sectors,
Expand Down

0 comments on commit fd707cf

Please sign in to comment.