From a898517686554918be944418c5f2fac1d96b14d9 Mon Sep 17 00:00:00 2001 From: Sean Klein Date: Thu, 6 Mar 2025 17:19:05 -0800 Subject: [PATCH 1/2] [zone bundle] Fix boolean logic to find snapshots --- sled-agent/src/zone_bundle.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/sled-agent/src/zone_bundle.rs b/sled-agent/src/zone_bundle.rs index 2b6bafa8085..868707a6acc 100644 --- a/sled-agent/src/zone_bundle.rs +++ b/sled-agent/src/zone_bundle.rs @@ -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; } From f5526efc6179e8c0432bd5f59334613857389061 Mon Sep 17 00:00:00 2001 From: Sean Klein Date: Fri, 7 Mar 2025 13:32:04 -0800 Subject: [PATCH 2/2] Fix logging too --- sled-agent/src/zone_bundle.rs | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/sled-agent/src/zone_bundle.rs b/sled-agent/src/zone_bundle.rs index 0b6a70845d6..df9101455e2 100644 --- a/sled-agent/src/zone_bundle.rs +++ b/sled-agent/src/zone_bundle.rs @@ -86,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!(