From 52d901403629acfbbc495f659a63361a0cc9c78e Mon Sep 17 00:00:00 2001 From: Andrew Dunn Date: Fri, 13 Mar 2026 15:15:33 -0400 Subject: [PATCH] podstorage: fsync storage root before and after creating .bootc_labeled Sync the storage root directory after relabeling to ensure the label writes are durable before creating the stamp file, and again after creating and labeling the stamp file to persist the directory entry. This avoids a crash leaving the system in a state where the stamp exists but the relabeling writes were lost. Closes: #1210 Signed-off-by: Andrew Dunn --- crates/lib/src/podstorage.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/crates/lib/src/podstorage.rs b/crates/lib/src/podstorage.rs index 2ff34073e..7d826b2ce 100644 --- a/crates/lib/src/podstorage.rs +++ b/crates/lib/src/podstorage.rs @@ -235,6 +235,14 @@ impl CStorage { ) .context("labeling storage root")?; + // fsync so relabel writes are durable before creating the stamp file + rustix::fs::fsync( + self.storage_root + .reopen_as_ownedfd() + .context("Reopening as owned fd")?, + ) + .context("fsync")?; + self.storage_root.create(LABELED)?; // Label the stamp file itself to match the storage directory context @@ -247,6 +255,14 @@ impl CStorage { ) .context("labeling stamp file")?; + // fsync to persist the stamp file entry + rustix::fs::fsync( + self.storage_root + .reopen_as_ownedfd() + .context("Reopening as owned fd")?, + ) + .context("fsync")?; + Ok(()) }