Skip to content

Commit 4edbc36

Browse files
committed
filetree: use fsfreeze_thaw_cycle(), cleanup
We had our own syncfs() implementation used just in this file, use the one provided by openat-ext.
1 parent c343a1d commit 4edbc36

File tree

1 file changed

+3
-19
lines changed

1 file changed

+3
-19
lines changed

src/filetree.rs

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66

7+
use crate::freezethaw::fsfreeze_thaw_cycle;
78
#[cfg(any(
89
target_arch = "x86_64",
910
target_arch = "aarch64",
@@ -330,23 +331,6 @@ pub(crate) struct ApplyUpdateOptions {
330331
pub(crate) skip_sync: bool,
331332
}
332333

333-
// syncfs() is a Linux-specific system call, which doesn't seem
334-
// to be bound in nix today. I found https://github.com/XuShaohua/nc
335-
// but that's a nontrivial dependency with not a lot of code review.
336-
// Let's just fork off a helper process for now.
337-
#[cfg(any(
338-
target_arch = "x86_64",
339-
target_arch = "aarch64",
340-
target_arch = "riscv64"
341-
))]
342-
pub(crate) fn syncfs(d: &openat::Dir) -> Result<()> {
343-
use rustix::fs::{Mode, OFlags};
344-
let d = unsafe { BorrowedFd::borrow_raw(d.as_raw_fd()) };
345-
let oflags = OFlags::RDONLY | OFlags::CLOEXEC | OFlags::DIRECTORY;
346-
let d = rustix::fs::openat(d, ".", oflags, Mode::empty())?;
347-
rustix::fs::syncfs(d).map_err(Into::into)
348-
}
349-
350334
/// Copy from src to dst at root dir
351335
#[cfg(any(
352336
target_arch = "x86_64",
@@ -475,7 +459,7 @@ pub(crate) fn apply_diff(
475459
}
476460
// Ensure all of the updates & changes are written persistently to disk
477461
if !opts.skip_sync {
478-
syncfs(destdir)?;
462+
destdir.syncfs()?;
479463
}
480464

481465
// finally remove the temp dir
@@ -486,7 +470,7 @@ pub(crate) fn apply_diff(
486470
// A second full filesystem sync to narrow any races rather than
487471
// waiting for writeback to kick in.
488472
if !opts.skip_sync {
489-
syncfs(destdir)?;
473+
fsfreeze_thaw_cycle(destdir.open_file(".")?)?;
490474
}
491475
Ok(())
492476
}

0 commit comments

Comments
 (0)