Skip to content

Commit ad2626d

Browse files
committed
Checkpoint
1 parent 9cf64b9 commit ad2626d

File tree

3 files changed

+49
-22
lines changed

3 files changed

+49
-22
lines changed

Cargo.lock

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

fuc_engine/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ thiserror = "2.0.12"
1616
tracing = { version = "0.1.41", default-features = false, features = ["attributes"], optional = true }
1717

1818
[target.'cfg(target_os = "linux")'.dependencies]
19+
lockness-executor = { path = "/home/asaveau/Desktop/lockness/executor" }
1920
rustix = { version = "1.0.2", features = ["fs", "thread", "linux_latest"] }
2021

2122
[target.'cfg(not(target_os = "linux"))'.dependencies]

fuc_engine/src/ops/remove.rs

Lines changed: 43 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,12 @@ fn schedule_deletions<'a, I: Into<Cow<'a, Path>>, F: IntoIterator<Item = I>>(
114114

115115
#[cfg(target_os = "linux")]
116116
mod compat {
117+
use lockness_executor::{LocknessExecutor, LocknessMessenger};
118+
use rustix::{
119+
fs::{AtFlags, CWD, FileType, Mode, OFlags, RawDir, openat, unlinkat},
120+
io::Errno,
121+
thread::{UnshareFlags, unshare},
122+
};
117123
use std::{
118124
borrow::Cow,
119125
cell::LazyCell,
@@ -131,12 +137,6 @@ mod compat {
131137
sync::Arc,
132138
};
133139

134-
use rustix::{
135-
fs::{AtFlags, CWD, FileType, Mode, OFlags, RawDir, openat, unlinkat},
136-
io::Errno,
137-
thread::{UnshareFlags, unshare},
138-
};
139-
140140
use crate::{
141141
Error,
142142
ops::{IoErr, compat::DirectoryOp, concat_cstrs, join_cstr_paths, path_buf_to_cstring},
@@ -147,34 +147,49 @@ mod compat {
147147
}
148148

149149
impl ThreadState {
150-
#[cfg_attr(feature = "tracing", tracing::instrument(level = "trace"))]
151-
fn new(unshare_io: bool) -> Result<Self, Error> {
152-
if unshare_io {
153-
unshare(UnshareFlags::FILES | UnshareFlags::FS)
154-
.map_io_err(|| "Failed to unshare I/O.")?;
150+
#[cfg_attr(
151+
feature = "tracing",
152+
tracing::instrument(level = "trace", skip(messenger))
153+
)]
154+
fn init(messenger: &LocknessMessenger<Error>, unshare_io: bool) -> Self {
155+
let run = || -> Result<_, Error> {
156+
if unshare_io {
157+
unshare(UnshareFlags::FILES | UnshareFlags::FS)
158+
.map_io_err(|| "Failed to unshare I/O.")?;
159+
}
160+
Ok(())
161+
};
162+
if let Err(e) = run() {
163+
messenger.send(e);
155164
}
156-
Ok(Self {
165+
166+
Self {
157167
buf: [MaybeUninit::uninit(); 8192],
158-
})
168+
}
159169
}
160170
}
161171

162-
struct Impl {
163-
executor: LazyCell<LocknessExecutor<ThreadState>>,
172+
struct Impl<F, L> {
173+
executor: LazyCell<LocknessExecutor<Error, F>, L>,
164174
}
165175

166176
pub fn remove_impl<'a>() -> impl DirectoryOp<Cow<'a, Path>> {
167177
let executor = LazyCell::new(|| {
168178
let unshare_io = env::var_os("NO_UNSHARE").is_none();
169179
LocknessExecutor::builder()
170-
.thread_initializer(|| ThreadState::new(unshare_io))
180+
.message_type::<Error>()
181+
.thread_initializer(move |m| ThreadState::init(m, unshare_io))
171182
.build()
172183
});
173184

174185
Impl { executor }
175186
}
176187

177-
impl DirectoryOp<Cow<'_, Path>> for Impl {
188+
impl<
189+
F: (FnMut(&LocknessMessenger<Error>) -> ThreadState) + Send + 'static,
190+
L: FnOnce() -> LocknessExecutor<Error, F>,
191+
> DirectoryOp<Cow<'_, Path>> for Impl<F, L>
192+
{
178193
#[cfg_attr(feature = "tracing", tracing::instrument(level = "trace", skip(self)))]
179194
fn run(&self, dir: Cow<Path>) -> Result<(), Error> {
180195
let Self { ref executor } = *self;
@@ -184,7 +199,8 @@ mod compat {
184199
path: path_buf_to_cstring(dir.into_owned())?,
185200
parent: None,
186201
};
187-
executor.spawn(|executor, state| delete_dir(node, state, executor))
202+
executor.spawn(|ctx| delete_dir(node, ctx));
203+
Ok(())
188204
}
189205

190206
#[cfg_attr(feature = "tracing", tracing::instrument(level = "trace", skip(self)))]
@@ -204,7 +220,10 @@ mod compat {
204220
feature = "tracing",
205221
tracing::instrument(level = "info", skip(state, executor))
206222
)]
207-
fn delete_dir(node: TreeNode, state: &mut ThreadState, executor: &LocknessExecutor) {
223+
fn delete_dir<F: (FnMut(&LocknessMessenger<Error>) -> ThreadState) + Send + 'static>(
224+
node: TreeNode,
225+
(state, executor): (&mut ThreadState, &LocknessExecutor<Error, F>),
226+
) {
208227
let run = || -> Result<(), Error> {
209228
let dir = openat(
210229
CWD,
@@ -226,11 +245,13 @@ mod compat {
226245
feature = "tracing",
227246
tracing::instrument(level = "trace", skip(dir, buf, executor))
228247
)]
229-
fn delete_dir_contents(
248+
fn delete_dir_contents<
249+
F: (FnMut(&LocknessMessenger<Error>) -> ThreadState) + Send + 'static,
250+
>(
230251
node: TreeNode,
231252
dir: OwnedFd,
232253
ThreadState { buf }: &mut ThreadState,
233-
executor: &LocknessExecutor,
254+
executor: &LocknessExecutor<Error, F>,
234255
) -> Result<Option<TreeNode>, Error> {
235256
enum Arcable<T> {
236257
Raw(T),
@@ -303,7 +324,7 @@ mod compat {
303324
path: concat_cstrs(&node.path, file.file_name()),
304325
parent: Some(node.clone()),
305326
};
306-
executor.spawn(|executor, state| delete_dir(node, state, executor));
327+
executor.spawn(|ctx| delete_dir(node, ctx));
307328
}
308329

309330
Ok(Arcable::into_inner(node))

0 commit comments

Comments
 (0)