From bd8cfe40f19322bee4725411687a239cd4aaafe9 Mon Sep 17 00:00:00 2001 From: pedrocarlo Date: Wed, 20 Aug 2025 23:44:50 -0300 Subject: [PATCH] impl `remove_file` for MemoryIO + skip completion if finished --- simulator/runner/memory/io.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/simulator/runner/memory/io.rs b/simulator/runner/memory/io.rs index e2b9f038c..900237e96 100644 --- a/simulator/runner/memory/io.rs +++ b/simulator/runner/memory/io.rs @@ -53,6 +53,16 @@ impl OperationType { | OperationType::Truncate { fd, .. } => fd, } } + + fn get_completion(&self) -> &Completion { + match self { + OperationType::Read { completion, .. } + | OperationType::Write { completion, .. } + | OperationType::WriteV { completion, .. } + | OperationType::Sync { completion, .. } + | OperationType::Truncate { completion, .. } => completion, + } + } } pub struct Operation { @@ -262,6 +272,10 @@ impl IO for MemorySimIO { callbacks.append(&mut timeouts); while let Some(callback) = callbacks.pop() { + let completion = callback.op.get_completion(); + if completion.finished() { + continue; + } if callback.time.is_none() || callback.time.is_some_and(|time| time < now) { // TODO: check if we should inject fault in operation here callback.do_operation(&files); @@ -275,4 +289,9 @@ impl IO for MemorySimIO { fn generate_random_number(&self) -> i64 { self.rng.borrow_mut().next_u64() as i64 } + + fn remove_file(&self, path: &str) -> Result<()> { + self.files.borrow_mut().shift_remove(path); + Ok(()) + } }