Skip to content

Commit 8cdf141

Browse files
andrewdunndevcgwalters
authored andcommitted
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 <andrew@dunn.dev>
1 parent 11ea8bc commit 8cdf141

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

crates/lib/src/podstorage.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,14 @@ impl CStorage {
235235
)
236236
.context("labeling storage root")?;
237237

238+
// fsync so relabel writes are durable before creating the stamp file
239+
rustix::fs::fsync(
240+
self.storage_root
241+
.reopen_as_ownedfd()
242+
.context("Reopening as owned fd")?,
243+
)
244+
.context("fsync")?;
245+
238246
self.storage_root.create(LABELED)?;
239247

240248
// Label the stamp file itself to match the storage directory context
@@ -247,6 +255,14 @@ impl CStorage {
247255
)
248256
.context("labeling stamp file")?;
249257

258+
// fsync to persist the stamp file entry
259+
rustix::fs::fsync(
260+
self.storage_root
261+
.reopen_as_ownedfd()
262+
.context("Reopening as owned fd")?,
263+
)
264+
.context("fsync")?;
265+
250266
Ok(())
251267
}
252268

0 commit comments

Comments
 (0)