Skip to content

Commit 4c1dd79

Browse files
committed
Merge invocation of should_extend and extend_size
Change should_extend and have it transitively invoke extend_size. Make extend_size a private method that takes self. * private because it is not called from an external function * takes self to calculate thindev size and remaining size in case it has a filesystem limit. Since strictly more threads are started than were previously, insert a post-check on the change that has occurred in order to decide whether metadata should be written or D-Bus signals sent. Signed-off-by: mulhern <amulhern@redhat.com>
1 parent 03b0003 commit 4c1dd79

2 files changed

Lines changed: 40 additions & 34 deletions

File tree

src/engine/strat_engine/thinpool/filesystem.rs

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -258,20 +258,36 @@ impl StratFilesystem {
258258
}
259259
}
260260

261-
/// Check the filesystem usage and determine whether it should extend.
261+
/// Check the filesystem usage and determine whether it should extend
262+
/// or just update. If extend, return the amount to extend.
262263
///
263264
/// Returns:
264-
/// * Some(mount_point) if the filesystem should be extended
265-
/// * None if the filesystem does not need to be extended
266-
pub fn should_extend(&self) -> Option<PathBuf> {
267-
fn should_extend_fail(fs: &StratFilesystem) -> StratisResult<Option<PathBuf>> {
265+
/// * Some(_) if the filesystem is mounted and should be visited
266+
/// * Some((_, 0)) if the filesystem does not need to be extended
267+
/// * None if the filesystem is unmounted and should not be visited
268+
pub fn visit_values(
269+
&self,
270+
no_op_remaining_size: Option<&mut Sectors>,
271+
) -> Option<(PathBuf, Sectors)> {
272+
fn visit_values_fail(
273+
fs: &StratFilesystem,
274+
no_op_remaining_size: Option<&mut Sectors>,
275+
) -> StratisResult<Option<(PathBuf, Sectors)>> {
268276
match fs.thin_dev.status(get_dm(), DmOptions::default())? {
269277
ThinStatus::Working(_) => {
270278
if let Some(mount_point) = fs.mount_points()?.first() {
271-
let (fs_total_bytes, fs_total_used_bytes) = fs_usage(mount_point)?;
272-
if 2u64 * fs_total_used_bytes > fs_total_bytes {
273-
return Ok(Some(mount_point.clone()));
274-
}
279+
return fs_usage(mount_point).map(
280+
|(fs_total_bytes, fs_total_used_bytes)| {
281+
Some((
282+
mount_point.clone(),
283+
if 2u64 * fs_total_used_bytes > fs_total_bytes {
284+
fs.extend_size(no_op_remaining_size)
285+
} else {
286+
Sectors(0)
287+
},
288+
))
289+
},
290+
);
275291
}
276292
Ok(None)
277293
}
@@ -286,11 +302,11 @@ impl StratFilesystem {
286302
}
287303
}
288304

289-
match should_extend_fail(self) {
305+
match visit_values_fail(self, no_op_remaining_size) {
290306
Ok(mt_pt) => mt_pt,
291307
Err(e) => {
292308
warn!(
293-
"Checking whether the filesystem should be extended failed: {}; ignoring",
309+
"Checking whether the filesystem should be visited failed: {}; ignoring",
294310
e
295311
);
296312
None
@@ -333,11 +349,9 @@ impl StratFilesystem {
333349

334350
/// Return an extend size for the thindev under the filesystem
335351
/// If no_op_remaining_size is None, then the pool allows overprovisioning.
336-
pub fn extend_size(
337-
current_size: Sectors,
338-
no_op_remaining_size: Option<&mut Sectors>,
339-
fs_limit_remaining_size: Option<Sectors>,
340-
) -> Sectors {
352+
fn extend_size(&self, no_op_remaining_size: Option<&mut Sectors>) -> Sectors {
353+
let current_size = self.thindev_size();
354+
let fs_limit_remaining_size = self.size_limit().map(|sl| sl - self.thindev_size());
341355
match (no_op_remaining_size, fs_limit_remaining_size) {
342356
(Some(no_op_rem_size), Some(fs_lim_rem_size)) => {
343357
let extend_size = min(min(*no_op_rem_size, current_size), fs_lim_rem_size);

src/engine/strat_engine/thinpool/thinpool.rs

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use devicemapper::{
2323

2424
use crate::{
2525
engine::{
26-
engine::{DumpState, Filesystem, StateDiff},
26+
engine::{DumpState, StateDiff},
2727
strat_engine::{
2828
backstore::Backstore,
2929
cmd::{thin_check, thin_metadata_size, thin_repair},
@@ -692,20 +692,8 @@ impl ThinPool {
692692
.filesystems
693693
.iter_mut()
694694
.filter_map(|(name, uuid, fs)| {
695-
if let Some(mt_pt) = fs.should_extend() {
696-
let extend_size = StratFilesystem::extend_size(
697-
fs.thindev_size(),
698-
remaining_space.as_mut(),
699-
fs.size_limit().map(|sl| sl - fs.thindev_size()),
700-
);
701-
if extend_size == Sectors(0) {
702-
None
703-
} else {
704-
Some((name, *uuid, fs, mt_pt, extend_size))
705-
}
706-
} else {
707-
None
708-
}
695+
fs.visit_values(remaining_space.as_mut())
696+
.map(|(mt_pt, extend_size)| (name, *uuid, fs, mt_pt, extend_size))
709697
})
710698
.map(|(name, uuid, fs, mt_pt, extend_size)| {
711699
s.spawn(move || -> StratisResult<_> {
@@ -720,15 +708,19 @@ impl ThinPool {
720708
.filter_map(|h| {
721709
h.join()
722710
.map_err(|_| {
723-
warn!("Failed to get status of filesystem extension");
711+
warn!("Failed to get status of filesystem operation");
724712
})
725713
.ok()
726714
})
727715
.fold(Vec::new(), |mut acc, res| {
728716
match res {
729717
Ok((name, uuid, fs, diff)) => {
730-
updated.insert(uuid, diff);
731-
acc.push((name, uuid, fs));
718+
if diff.size.is_changed() {
719+
acc.push((name, uuid, fs));
720+
}
721+
if diff.size.is_changed() || diff.used.is_changed() {
722+
updated.insert(uuid, diff);
723+
}
732724
}
733725
Err(e) => {
734726
warn!("Failed to extend filesystem: {}", e);

0 commit comments

Comments
 (0)