Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions src/dbus_api/filesystem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,9 +232,5 @@ fn get_filesystem_used(
i: &mut IterAppend,
p: &PropInfo<MTFn<TData>, TData>,
) -> Result<(), MethodErr> {
get_filesystem_property(i, p, |(_, _, fs)| {
fs.used()
.map(|v| (*v).to_string())
.map_err(|_| MethodErr::failed(&"fs used() engine call failed".to_owned()))
})
get_filesystem_property(i, p, |(_, _, fs)| Ok((*fs.used()).to_string()))
}
17 changes: 3 additions & 14 deletions src/dbus_api/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -337,20 +337,9 @@ fn get_pool_total_physical_used(
i: &mut IterAppend,
p: &PropInfo<MTFn<TData>, TData>,
) -> Result<(), MethodErr> {
fn get_used((_, uuid, pool): (Name, Uuid, &dyn Pool)) -> Result<String, MethodErr> {
let err_func = |_| {
MethodErr::failed(&format!(
"no total physical size computed for pool with uuid {}",
uuid
))
};

pool.total_physical_used()
.map(|u| Ok(format!("{}", *u)))
.map_err(err_func)?
}

get_pool_property(i, p, get_used)
get_pool_property(i, p, |(_, _, pool)| {
Ok((*pool.total_physical_used()).to_string())
})
}

fn get_pool_total_physical_size(
Expand Down
4 changes: 2 additions & 2 deletions src/engine/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pub trait Filesystem: Debug {
fn created(&self) -> DateTime<Utc>;

/// The amount of data stored on the filesystem, including overhead.
fn used(&self) -> StratisResult<Bytes>;
fn used(&self) -> Bytes;

/// Set dbus path associated with the Pool.
fn set_dbus_path(&mut self, path: MaybeDbusPath) -> ();
Expand Down Expand Up @@ -141,7 +141,7 @@ pub trait Pool: Debug {
/// The number of Sectors in this pool that are currently in use by the
/// pool for some purpose, be it to store metadata, to store user data,
/// or to reserve for some other purpose.
fn total_physical_used(&self) -> StratisResult<Sectors>;
fn total_physical_used(&self) -> Sectors;

/// Get all the filesystems belonging to this pool.
fn filesystems(&self) -> Vec<(Name, FilesystemUuid, &dyn Filesystem)>;
Expand Down
9 changes: 3 additions & 6 deletions src/engine/sim_engine/filesystem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ use std::path::PathBuf;

use devicemapper::Bytes;

use crate::{
engine::{Filesystem, MaybeDbusPath},
stratis::StratisResult,
};
use crate::engine::{Filesystem, MaybeDbusPath};

#[derive(Debug)]
pub struct SimFilesystem {
Expand Down Expand Up @@ -43,8 +40,8 @@ impl Filesystem for SimFilesystem {
self.created
}

fn used(&self) -> StratisResult<Bytes> {
Ok(Bytes(12_345_678))
fn used(&self) -> Bytes {
Bytes(12_345_678)
}

fn set_dbus_path(&mut self, path: MaybeDbusPath) {
Expand Down
4 changes: 2 additions & 2 deletions src/engine/sim_engine/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,8 @@ impl Pool for SimPool {
Sectors(IEC::Ei)
}

fn total_physical_used(&self) -> StratisResult<Sectors> {
Ok(Sectors(0))
fn total_physical_used(&self) -> Sectors {
Sectors(0)
}

fn filesystems(&self) -> Vec<(Name, FilesystemUuid, &dyn Filesystem)> {
Expand Down
6 changes: 2 additions & 4 deletions src/engine/strat_engine/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -394,10 +394,8 @@ impl Pool for StratPool {
self.backstore.datatier_size()
}

fn total_physical_used(&self) -> StratisResult<Sectors> {
self.thin_pool
.total_physical_used()
.and_then(|v| Ok(v + self.backstore.datatier_metadata_size()))
fn total_physical_used(&self) -> Sectors {
self.thin_pool.total_physical_used() + self.backstore.datatier_metadata_size()
}

fn filesystems(&self) -> Vec<(Name, FilesystemUuid, &dyn Filesystem)> {
Expand Down
59 changes: 42 additions & 17 deletions src/engine/strat_engine/thinpool/filesystem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ use std::{
};

use devicemapper::{
Bytes, DmDevice, DmName, DmUuid, Sectors, ThinDev, ThinDevId, ThinPoolDev, ThinStatus, IEC,
Bytes, DmDevice, DmName, DmUuid, Sectors, ThinDev, ThinDevId, ThinDevWorkingStatus,
ThinPoolDev, ThinStatus, IEC,
};

use libmount;
Expand Down Expand Up @@ -46,10 +47,36 @@ const TEMP_MNT_POINT_PREFIX: &str = "stratis_mp_";
/// expansion check is triggered by crossing the data low water mark for the thin pool.
pub const FILESYSTEM_LOWATER: Sectors = Sectors(4 * (DATA_LOWATER.0 * DATA_BLOCK_SIZE.0));

/// Get ThinDevWorkingStatus. If ThinDevStatus is Fail, return an error.
fn get_thindev_status(thindev: &ThinDev) -> StratisResult<ThinDevWorkingStatus> {
match thindev.status(get_dm())? {
ThinStatus::Error => {
let err_msg = format!(
"Devicemapper could not obtain the status for thin device with name {} device {} and devnode {}",
thindev.name(),
thindev.device(),
thindev.devnode().display(),
);
Err(StratisError::Error(err_msg))
}
ThinStatus::Fail => {
let err_msg = format!(
"Status of thin device with name {} device {} and devnode {} is Fail",
thindev.name(),
thindev.device(),
thindev.devnode().display(),
);
Err(StratisError::Error(err_msg))
}
ThinStatus::Working(w) => Ok(*w),
}
}

#[derive(Debug)]
pub struct StratFilesystem {
thin_dev: ThinDev,
created: DateTime<Utc>,
thin_dev_status: ThinDevWorkingStatus,
dbus_path: MaybeDbusPath,
}

Expand Down Expand Up @@ -97,11 +124,14 @@ impl StratFilesystem {
return Err(err);
}

let thin_dev_status = get_thindev_status(&thin_dev)?;

Ok((
fs_uuid,
StratFilesystem {
thin_dev,
created: Utc::now(),
thin_dev_status,
dbus_path: MaybeDbusPath(None),
},
))
Expand All @@ -122,9 +152,13 @@ impl StratFilesystem {
&thinpool_dev,
fssave.thin_id,
)?;

let thin_dev_status = get_thindev_status(&thin_dev)?;

Ok(StratFilesystem {
thin_dev,
created: Utc.timestamp(fssave.created as i64, 0),
thin_dev_status,
dbus_path: MaybeDbusPath(None),
})
}
Expand Down Expand Up @@ -180,9 +214,12 @@ impl StratFilesystem {
}

set_uuid(&thin_dev.devnode(), snapshot_fs_uuid)?;

let thin_dev_status = get_thindev_status(&thin_dev)?;
Ok(StratFilesystem {
thin_dev,
created: Utc::now(),
thin_dev_status,
dbus_path: MaybeDbusPath(None),
})
}
Expand All @@ -200,7 +237,8 @@ impl StratFilesystem {
/// TODO: deal with the thindev in a Fail state.
pub fn check(&mut self) -> StratisResult<(FilesystemStatus, bool)> {
match self.thin_dev.status(get_dm())? {
ThinStatus::Working(_) => {
ThinStatus::Working(w) => {
self.thin_dev_status = *w;
if let Some(mount_point) = self.mount_points()?.first() {
let (fs_total_bytes, fs_total_used_bytes) = fs_usage(&mount_point)?;
let free_bytes = fs_total_bytes - fs_total_used_bytes;
Expand Down Expand Up @@ -313,21 +351,8 @@ impl Filesystem for StratFilesystem {
self.created
}

fn used(&self) -> StratisResult<Bytes> {
match self.thin_dev.status(get_dm())? {
ThinStatus::Working(wk_status) => Ok(wk_status.nr_mapped_sectors.bytes()),
ThinStatus::Error => {
let error_msg = format!(
"Unable to get status for filesystem thin device {}",
self.thin_dev.device()
);
Err(StratisError::Engine(ErrorEnum::Error, error_msg))
}
ThinStatus::Fail => {
let error_msg = format!("ThinDev {} is in a failed state", self.thin_dev.device());
Err(StratisError::Engine(ErrorEnum::Error, error_msg))
}
}
fn used(&self) -> Bytes {
self.thin_dev_status.nr_mapped_sectors.bytes()
}

fn set_dbus_path(&mut self, path: MaybeDbusPath) {
Expand Down
53 changes: 36 additions & 17 deletions src/engine/strat_engine/thinpool/thinpool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use uuid::Uuid;
use devicemapper::{
device_exists, DataBlocks, Device, DmDevice, DmName, DmNameBuf, FlakeyTargetParams, LinearDev,
LinearDevTargetParams, LinearTargetParams, MetaBlocks, Sectors, TargetLine, ThinDevId,
ThinPoolDev, ThinPoolStatus, ThinPoolStatusSummary, IEC,
ThinPoolDev, ThinPoolStatus, ThinPoolStatusSummary, ThinPoolWorkingStatus, IEC,
};

use crate::{
Expand Down Expand Up @@ -178,6 +178,29 @@ struct Segments {
mdv_segments: Vec<(Sectors, Sectors)>,
}

/// Just a helper function to get the status of a thinpool device.
fn get_thinpool_status(thinpool_dev: &ThinPoolDev) -> StratisResult<ThinPoolWorkingStatus> {
match thinpool_dev.status(get_dm())? {
ThinPoolStatus::Error => {
let err_msg = format!("Devicemapper could not obtain the status for devicemapper thin pool with name {} device {} and devnode {}",
thinpool_dev.name(),
thinpool_dev.device(),
thinpool_dev.devnode().display());
Err(StratisError::Error(err_msg))
}
ThinPoolStatus::Fail => {
let err_msg = format!(
"Status of thin pool with name {} device {} and devnode {} is Fail",
thinpool_dev.name(),
thinpool_dev.device(),
thinpool_dev.devnode().display(),
);
Err(StratisError::Error(err_msg))
}
ThinPoolStatus::Working(w) => Ok(*w),
}
}

pub struct ThinPoolSizeParams {
meta_size: MetaBlocks,
data_size: DataBlocks,
Expand Down Expand Up @@ -226,6 +249,7 @@ pub struct ThinPool {
pool_state: PoolState,
pool_extend_state: PoolExtendState,
free_space_state: FreeSpaceState,
thin_pool_status: ThinPoolWorkingStatus,
dbus_path: MaybeDbusPath,
}

Expand Down Expand Up @@ -322,6 +346,8 @@ impl ThinPool {
),
)?;

let thin_pool_status = get_thinpool_status(&thinpool_dev)?;

Ok(ThinPool {
thin_pool: thinpool_dev,
segments: Segments {
Expand All @@ -337,6 +363,7 @@ impl ThinPool {
pool_state: PoolState::Initializing,
pool_extend_state: PoolExtendState::Initializing,
free_space_state,
thin_pool_status,
dbus_path: MaybeDbusPath(None),
})
}
Expand Down Expand Up @@ -434,6 +461,9 @@ impl ThinPool {
}

let thin_ids: Vec<ThinDevId> = filesystem_metadatas.iter().map(|x| x.thin_id).collect();

let thin_pool_status = get_thinpool_status(&thinpool_dev)?;

Ok(ThinPool {
thin_pool: thinpool_dev,
segments: Segments {
Expand All @@ -449,6 +479,7 @@ impl ThinPool {
pool_state: PoolState::Initializing,
pool_extend_state: PoolExtendState::Initializing,
free_space_state,
thin_pool_status,
dbus_path: MaybeDbusPath(None),
})
}
Expand Down Expand Up @@ -479,6 +510,7 @@ impl ThinPool {
let mut should_save: bool = false;
match self.thin_pool.status(get_dm())? {
ThinPoolStatus::Working(ref status) => {
self.thin_pool_status = (**status).clone();
let mut meta_extend_failed = false;
let mut data_extend_failed = false;
match status.summary {
Expand Down Expand Up @@ -806,29 +838,16 @@ impl ThinPool {
// This includes all the sectors being held as spares for the meta device,
// all the sectors allocated to the meta data device, and all the sectors
// in use on the data device.
pub fn total_physical_used(&self) -> StratisResult<Sectors> {
let data_dev_used = match self.thin_pool.status(get_dm())? {
ThinPoolStatus::Working(ref status) => datablocks_to_sectors(status.usage.used_data),
ThinPoolStatus::Error => {
let err_msg = format!(
"Devicemapper could not obtain status for devicemapper thin pool device {}",
self.thin_pool.device(),
);
return Err(StratisError::Engine(ErrorEnum::Invalid, err_msg));
}
ThinPoolStatus::Fail => {
let err_msg = "thin pool failed, could not obtain usage";
return Err(StratisError::Engine(ErrorEnum::Invalid, err_msg.into()));
}
};
pub fn total_physical_used(&self) -> Sectors {
let data_dev_used = datablocks_to_sectors(self.thin_pool_status.usage.used_data);

let spare_total = self.segments.meta_spare_segments.iter().map(|s| s.1).sum();

let meta_dev_total = self.thin_pool.meta_dev().size();

let mdv_total = self.segments.mdv_segments.iter().map(|s| s.1).sum();

Ok(data_dev_used + spare_total + meta_dev_total + mdv_total)
data_dev_used + spare_total + meta_dev_total + mdv_total
}

pub fn get_filesystem_by_uuid(&self, uuid: FilesystemUuid) -> Option<(Name, &StratFilesystem)> {
Expand Down