Skip to content

Commit

Permalink
Update origin links on removal
Browse files Browse the repository at this point in the history
Signed-off-by: mulhern <[email protected]>
  • Loading branch information
mulkieran committed Dec 21, 2023
1 parent 7b6bed0 commit 3973bfe
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/engine/sim_engine/filesystem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ impl SimFilesystem {
}
}
}

pub fn unset_origin(&mut self) -> bool {
let changed = self.origin.is_some();
self.origin = None;
changed
}
}

impl Filesystem for SimFilesystem {
Expand Down
19 changes: 19 additions & 0 deletions src/engine/sim_engine/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,25 @@ impl Pool for SimPool {
removed.push(uuid);
}
}

let snapshots: Vec<FilesystemUuid> = self
.filesystems()
.iter()
.filter_map(|(_, u, fs)| {
fs.origin()
.and_then(|x| if removed.contains(&x) { Some(*u) } else { None })
})
.collect();

let mut updated_origins = vec![];
for sn_uuid in snapshots {
if let Some((_, fs)) = self.filesystems.get_mut_by_uuid(sn_uuid) {
if fs.unset_origin() {
updated_origins.push(sn_uuid);
}
}
}

Ok(SetDeleteAction::new(removed))
}

Expand Down
22 changes: 22 additions & 0 deletions src/engine/strat_engine/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1011,6 +1011,28 @@ impl Pool for StratPool {
}
}

let snapshots: Vec<FilesystemUuid> = self
.thin_pool
.filesystems()
.iter()
.filter_map(|(_, u, fs)| {
fs.origin()
.and_then(|x| if removed.contains(&x) { Some(*u) } else { None })
})
.collect();

let mut updated_origins = vec![];
for sn_uuid in snapshots {
if let Err(err) = self.thin_pool.unset_fs_origin(sn_uuid) {
warn!(
"Failed to write null origin to metadata for filesystem with UUID {}: {}",
sn_uuid, err
);
} else {
updated_origins.push(sn_uuid);
}
}

Ok(SetDeleteAction::new(removed))
}

Expand Down
6 changes: 6 additions & 0 deletions src/engine/strat_engine/thinpool/filesystem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,12 @@ impl StratFilesystem {
pub fn thindev_size(&self) -> Sectors {
self.thin_dev.size()
}

pub fn unset_origin(&mut self) -> bool {
let changed = self.origin.is_some();
self.origin = None;
changed
}
}

impl Filesystem for StratFilesystem {
Expand Down
16 changes: 16 additions & 0 deletions src/engine/strat_engine/thinpool/thinpool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1577,6 +1577,22 @@ impl ThinPool {
}
Ok(changed)
}

pub fn unset_fs_origin(&mut self, fs_uuid: FilesystemUuid) -> StratisResult<bool> {
let changed = {
let (_, fs) = self.get_mut_filesystem_by_uuid(fs_uuid).ok_or_else(|| {
StratisError::Msg(format!("No filesystem with UUID {fs_uuid} found"))
})?;
fs.unset_origin()
};
let (name, fs) = self
.get_filesystem_by_uuid(fs_uuid)
.expect("Looked up above.");
if changed {
self.mdv.save_fs(&name, fs_uuid, fs)?;
}
Ok(changed)
}
}

impl<'a> Into<Value> for &'a ThinPool {
Expand Down

0 comments on commit 3973bfe

Please sign in to comment.