Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[zone bundle] Fix boolean logic to find snapshots #7753

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
37 changes: 22 additions & 15 deletions sled-agent/src/zone_bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,12 @@ fn initialize_zfs_resources(log: &Logger) -> Result<(), BundleError> {
let zb_snapshots =
Zfs::list_snapshots().unwrap().into_iter().filter(|snap| {
// Check for snapshots named how we expect to create them.
if snap.snap_name != ZONE_ROOT_SNAPSHOT_NAME
|| !snap.snap_name.starts_with(ARCHIVE_SNAPSHOT_PREFIX)
{
let is_root_snapshot = snap.snap_name == ZONE_ROOT_SNAPSHOT_NAME;
let is_archive_snapshot =
snap.snap_name.starts_with(ARCHIVE_SNAPSHOT_PREFIX);
let is_zone_bundle_snapshot =
is_root_snapshot || is_archive_snapshot;
if !is_zone_bundle_snapshot {
return false;
}

Expand All @@ -83,21 +86,25 @@ fn initialize_zfs_resources(log: &Logger) -> Result<(), BundleError> {
// have such a property (or has in invalid property), we'll log it
// but avoid deleting the snapshot.
let name = snap.to_string();
let Ok([value]) = Zfs::get_values(
let value = match Zfs::get_values(
&name,
&[ZONE_BUNDLE_ZFS_PROPERTY_NAME],
Some(illumos_utils::zfs::PropertySource::Local),
) else {
warn!(
log,
"Found a ZFS snapshot with a name reserved for zone \
bundling, but which does not have the zone-bundle-specific \
property. Bailing out, rather than risking deletion of \
user data.";
"snap_name" => &name,
"property" => ZONE_BUNDLE_ZFS_PROPERTY_NAME
);
return false;
) {
Ok([value]) => value,
Err(err) => {
warn!(
log,
"Found a ZFS snapshot with a name reserved for zone \
bundling, but which does not have the zone-bundle-specific \
property. Bailing out, rather than risking deletion of \
user data.";
"snap_name" => &name,
"property" => ZONE_BUNDLE_ZFS_PROPERTY_NAME,
"error" => slog_error_chain::InlineErrorChain::new(&err),
);
return false;
}
};
if value != ZONE_BUNDLE_ZFS_PROPERTY_VALUE {
warn!(
Expand Down
Loading