Skip to content

Commit

Permalink
Locks mount point
Browse files Browse the repository at this point in the history
  • Loading branch information
ultimaweapon committed Nov 9, 2024
1 parent bbf86b5 commit 60af209
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions dumper/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use core::ffi::c_int;
use core::mem::zeroed;
use core::panic::PanicInfo;
use okf::fd::{openat, write_all, OpenFlags, AT_FDCWD};
use okf::lock::MtxLock;
use okf::mount::Mount;
use okf::pcpu::Pcpu;
use okf::uio::UioSeg;
Expand Down Expand Up @@ -85,17 +84,30 @@ fn run<K: Kernel>(k: K) {
}
};

// Get target mounts.
// Lock mount list.
let mtx = k.var(K::MOUNTLIST_MTX);
let lock = unsafe { MtxLock::new(k, mtx.ptr()) };

unsafe { k.mtx_lock_flags(mtx.ptr(), 0, c"".as_ptr(), 0) };

// Dump all read-only mounts.
let list = k.var(K::MOUNTLIST);
let mut mp = unsafe { (*list.ptr()).first };

while !mp.is_null() {
// vfs_busy always success without MBF_NOWAIT.
unsafe { k.vfs_busy(mp, K::MBF_MNTLSTLOCK) };

// vfs_busy with MBF_MNTLSTLOCK will unlock before return so we need to re-acquire the lock.
unsafe { k.mtx_lock_flags(mtx.ptr(), 0, c"".as_ptr(), 0) };

// This need to be done inside mountlist_mtx otherwise our current mp may be freed when we
// try to access the next mount point.
unsafe { k.vfs_unbusy(mp) };

mp = unsafe { (*mp).entry().next };
}

drop(lock);
unsafe { k.mtx_unlock_flags(mtx.ptr(), 0, c"".as_ptr(), 0) };
drop(fd);

// Notify the user.
Expand Down

0 comments on commit 60af209

Please sign in to comment.