Skip to content

Commit

Permalink
Define a merge operation for FilesystemSave
Browse files Browse the repository at this point in the history
To avoid a mutable snap and miscellaneous setting and unsetting in the
setup method.

Signed-off-by: mulhern <amulhern@redhat.com>
  • Loading branch information
mulkieran committed Sep 25, 2024
1 parent f90aed7 commit a9b8724
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 32 deletions.
17 changes: 16 additions & 1 deletion src/engine/strat_engine/shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use std::collections::HashMap;

use crate::engine::{
strat_engine::{backstore::StratBlockDev, metadata::BDA},
strat_engine::{backstore::StratBlockDev, metadata::BDA, serde_structs::FilesystemSave},
types::DevUuid,
};

Expand All @@ -29,3 +29,18 @@ pub fn tiers_to_bdas(
.chain(bda.map(|bda| (bda.dev_uuid(), bda)))
.collect::<HashMap<_, _>>()
}

/// Define how an origin and its snapshot are merged when a filesystem is
/// reverted.
pub fn merge(origin: &FilesystemSave, snap: &FilesystemSave) -> FilesystemSave {
FilesystemSave {
name: origin.name.to_owned(),
uuid: origin.uuid,
thin_id: snap.thin_id,
size: snap.size,
created: origin.created,
fs_size_limit: snap.fs_size_limit,
origin: origin.origin,
merge: origin.merge,
}
}
45 changes: 14 additions & 31 deletions src/engine/strat_engine/thinpool/thinpool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ use crate::{
ThinRole,
},
serde_structs::{FlexDevsSave, Recordable, ThinPoolDevSave},
shared::merge,
thinpool::{filesystem::StratFilesystem, mdv::MetadataVol, thinids::ThinDevIdPool},
writing::wipe_sectors,
},
Expand Down Expand Up @@ -600,49 +601,36 @@ m metadata",
}

let mut fs_table = Table::default();
for (origin, mut snap) in ready_to_merge {
let snap_uuid = snap.uuid;
snap.uuid = origin.uuid;

let snap_origin = snap.origin;
snap.origin = origin.origin;

for (origin, snap) in ready_to_merge {
assert!(!origin.merge.unwrap_or(false));
let snap_merge = snap.merge;
snap.merge = origin.merge;

let snap_name = snap.name;
snap.name = origin.name.to_owned();

let created = snap.created;
snap.created = origin.created;
let merged = merge(&origin, &snap);

match StratFilesystem::setup(pool_uuid, &thinpool_dev, &snap) {
match StratFilesystem::setup(pool_uuid, &thinpool_dev, &merged) {
Ok(fs) => {
if let Err(e) = set_uuid(&fs.devnode(), snap.uuid) {
if let Err(e) = set_uuid(&fs.devnode(), merged.uuid) {
error!(
"Could not set the UUID of the XFS filesystem on th
e Stratis filesystem with UUID {} after revert, reason: {:?}",
snap.uuid, e
merged.uuid, e
);
};
fs.udev_fs_change(pool_name, snap.uuid, &snap.name);
fs.udev_fs_change(pool_name, merged.uuid, &merged.name);

let name = Name::new(snap.name.to_owned());
if let Err(e) = mdv.save_fs(&name, snap.uuid, &fs) {
let name = Name::new(merged.name.to_owned());
if let Err(e) = mdv.save_fs(&name, merged.uuid, &fs) {
error!(
"Could not save MDV for fs with UUID {} and name {} belonging to pool with UUID {} after revert, reason: {:?}",
snap.uuid, snap.name, pool_uuid, e
merged.uuid, merged.name, pool_uuid, e
);
}
if let Err(e) = mdv.rm_fs(snap_uuid) {
if let Err(e) = mdv.rm_fs(snap.uuid) {
error!(
"Could not remove old MDV for fs with UUID {} belonging to pool with UUID {} after revert, reason: {:?}",
snap_uuid, pool_uuid, e
snap.uuid, pool_uuid, e
);
};
assert!(
fs_table.insert(name, snap.uuid, fs).is_none(),
fs_table.insert(name, merged.uuid, fs).is_none(),
"Duplicates already removed when building filesystem_metadata_map"
);
if let Err(e) = message(
Expand All @@ -656,17 +644,12 @@ e Stratis filesystem with UUID {} after revert, reason: {:?}",
);
}
for fs in filesystem_metadata_map.values_mut() {
if fs.origin.map(|o| o == snap_uuid).unwrap_or(false) {
if fs.origin.map(|o| o == snap.uuid).unwrap_or(false) {
fs.origin = Some(origin.uuid);
}
}
}
Err(err) => {
snap.uuid = snap_uuid;
snap.origin = snap_origin;
snap.merge = snap_merge;
snap.name = snap_name;
snap.created = created;
warn!(
"Snapshot {:?} could not be reverted into origin {:?}, reason: {:?}",
snap, origin, err
Expand Down

0 comments on commit a9b8724

Please sign in to comment.