mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-22 00:43:24 +00:00
Revise MountNode
's lock usage
This commit is contained in:
committed by
Tate, Hongliang Tian
parent
0415225c19
commit
271e893889
@ -16,13 +16,13 @@ pub struct MountNode {
|
|||||||
root_dentry: Arc<Dentry_>,
|
root_dentry: Arc<Dentry_>,
|
||||||
/// Mountpoint dentry. A mount node can be mounted on one dentry of another mount node,
|
/// Mountpoint dentry. A mount node can be mounted on one dentry of another mount node,
|
||||||
/// which makes the mount being the child of the mount node.
|
/// which makes the mount being the child of the mount node.
|
||||||
mountpoint_dentry: RwMutex<Option<Arc<Dentry_>>>,
|
mountpoint_dentry: RwLock<Option<Arc<Dentry_>>>,
|
||||||
/// The associated FS.
|
/// The associated FS.
|
||||||
fs: Arc<dyn FileSystem>,
|
fs: Arc<dyn FileSystem>,
|
||||||
/// The parent mount node.
|
/// The parent mount node.
|
||||||
parent: RwMutex<Option<Weak<MountNode>>>,
|
parent: RwLock<Option<Weak<MountNode>>>,
|
||||||
/// Child mount nodes which are mounted on one dentry of self.
|
/// Child mount nodes which are mounted on one dentry of self.
|
||||||
children: RwMutex<HashMap<DentryKey, Arc<Self>>>,
|
children: RwLock<HashMap<DentryKey, Arc<Self>>>,
|
||||||
/// Reference to self.
|
/// Reference to self.
|
||||||
this: Weak<Self>,
|
this: Weak<Self>,
|
||||||
}
|
}
|
||||||
@ -50,9 +50,9 @@ impl MountNode {
|
|||||||
fn new(fs: Arc<dyn FileSystem>, parent_mount: Option<Weak<MountNode>>) -> Arc<Self> {
|
fn new(fs: Arc<dyn FileSystem>, parent_mount: Option<Weak<MountNode>>) -> Arc<Self> {
|
||||||
Arc::new_cyclic(|weak_self| Self {
|
Arc::new_cyclic(|weak_self| Self {
|
||||||
root_dentry: Dentry_::new_root(fs.root_inode()),
|
root_dentry: Dentry_::new_root(fs.root_inode()),
|
||||||
mountpoint_dentry: RwMutex::new(None),
|
mountpoint_dentry: RwLock::new(None),
|
||||||
parent: RwMutex::new(parent_mount),
|
parent: RwLock::new(parent_mount),
|
||||||
children: RwMutex::new(HashMap::new()),
|
children: RwLock::new(HashMap::new()),
|
||||||
fs,
|
fs,
|
||||||
this: weak_self.clone(),
|
this: weak_self.clone(),
|
||||||
})
|
})
|
||||||
@ -106,9 +106,9 @@ impl MountNode {
|
|||||||
fn clone_mount_node(&self, root_dentry: &Arc<Dentry_>) -> Arc<Self> {
|
fn clone_mount_node(&self, root_dentry: &Arc<Dentry_>) -> Arc<Self> {
|
||||||
Arc::new_cyclic(|weak_self| Self {
|
Arc::new_cyclic(|weak_self| Self {
|
||||||
root_dentry: root_dentry.clone(),
|
root_dentry: root_dentry.clone(),
|
||||||
mountpoint_dentry: RwMutex::new(None),
|
mountpoint_dentry: RwLock::new(None),
|
||||||
parent: RwMutex::new(None),
|
parent: RwLock::new(None),
|
||||||
children: RwMutex::new(HashMap::new()),
|
children: RwLock::new(HashMap::new()),
|
||||||
fs: self.fs.clone(),
|
fs: self.fs.clone(),
|
||||||
this: weak_self.clone(),
|
this: weak_self.clone(),
|
||||||
})
|
})
|
||||||
@ -221,11 +221,13 @@ impl MountNode {
|
|||||||
|
|
||||||
/// Flushes all pending filesystem metadata and cached file data to the device.
|
/// Flushes all pending filesystem metadata and cached file data to the device.
|
||||||
pub fn sync(&self) -> Result<()> {
|
pub fn sync(&self) -> Result<()> {
|
||||||
let children = self.children.read();
|
let children: Vec<Arc<MountNode>> = {
|
||||||
for child in children.values() {
|
let children = self.children.read();
|
||||||
|
children.values().cloned().collect()
|
||||||
|
};
|
||||||
|
for child in children {
|
||||||
child.sync()?;
|
child.sync()?;
|
||||||
}
|
}
|
||||||
drop(children);
|
|
||||||
|
|
||||||
self.fs.sync()?;
|
self.fs.sync()?;
|
||||||
Ok(())
|
Ok(())
|
||||||
|
Reference in New Issue
Block a user