From f5c92834f79dfdf8007daa019f401c5e51a7596f Mon Sep 17 00:00:00 2001 From: Chuyan Zhang Date: Sat, 2 Dec 2023 17:37:57 -0800 Subject: Fix read/write permissions --- ayafs-core/src/memory/cached_block.rs | 32 ++++++++++++++++---------------- ayafs-core/src/memory/dir_entry.rs | 24 ++++++++++++------------ 2 files changed, 28 insertions(+), 28 deletions(-) (limited to 'ayafs-core/src/memory') diff --git a/ayafs-core/src/memory/cached_block.rs b/ayafs-core/src/memory/cached_block.rs index 24f08c0..ae0f2a9 100644 --- a/ayafs-core/src/memory/cached_block.rs +++ b/ayafs-core/src/memory/cached_block.rs @@ -4,7 +4,7 @@ use crate::AyaFS; use lru::LruCache; use std::num::NonZeroUsize; use std::sync::Arc; -use log::debug; +use log::trace; #[derive(Clone)] pub struct CachedBlock { @@ -43,14 +43,14 @@ impl BlockCache { pub(crate) fn write_back(&self) { for (_, cached_block) in self.cache.iter() { if cached_block.dirty { - debug!("write_back: dirty block {}", self.global_offset + cached_block.index); + trace!("write_back: dirty block {}", self.global_offset + cached_block.index); let block_buffer = unsafe { let block_ptr = &cached_block.block as *const T as *const u8; std::slice::from_raw_parts(block_ptr, std::mem::size_of::()) }; self.device.write(self.global_offset + cached_block.index, block_buffer); } else { - debug!("write_back: clean block {}", self.global_offset + cached_block.index); + trace!("write_back: clean block {}", self.global_offset + cached_block.index); } } } @@ -68,7 +68,7 @@ impl BlockCache { if let Some((old_index, old_block)) = self.cache.push(index, cached_block) { assert_ne!(old_index, index); // 只有 block 不在 cache 里的时候才会插入 if old_block.dirty { - debug!("write_back: evicted dirty block {} while loading {}", self.global_offset + old_block.index, self.global_offset + index); + trace!("write_back: evicted dirty block {} while loading {}", self.global_offset + old_block.index, self.global_offset + index); let old_block_buffer = unsafe { let old_block_ptr = &old_block.block as *const T as *mut u8; std::slice::from_raw_parts(old_block_ptr, BLOCK_SIZE) @@ -84,18 +84,18 @@ impl BlockCache { /// 这个函数不应该返回 None pub(crate) fn get_block(&mut self, index: usize) -> Option<&CachedBlock> { if !self.cache.contains(&index) { - debug!("get_block(global_block_id: {}) loading from disk", index + self.global_offset); + trace!("get_block(global_block_id: {}) loading from disk", index + self.global_offset); self.load_block(index); } if let Some(block) = self.cache.get(&index) { - debug!("get_block(global_block_id: {}) found", index + self.global_offset); + trace!("get_block(global_block_id: {}) found", index + self.global_offset); Some(convert::(block)) } else { - debug!("get_block(global_block_id: {}) not found", index + self.global_offset); + trace!("get_block(global_block_id: {}) not found", index + self.global_offset); None } - // debug!("get_block(global_block_id: {}) found", index + self.global_offset); + // trace!("get_block(global_block_id: {}) found", index + self.global_offset); // self.cache.get(&index).map(convert::) } @@ -103,21 +103,21 @@ impl BlockCache { /// 这个函数不应该返回 None pub(crate) fn get_block_mut(&mut self, index: usize) -> Option<&mut CachedBlock> { if !self.cache.contains(&index) { - debug!("get_block_mut(global_block_id: {}) loading from disk", index + self.global_offset); + trace!("get_block_mut(global_block_id: {}) loading from disk", index + self.global_offset); self.load_block(index); } if let Some(block) = self.cache.get_mut(&index) { - debug!("get_block_mut(global_block_id: {}) found", index + self.global_offset); + trace!("get_block_mut(global_block_id: {}) found", index + self.global_offset); block.dirty = true; Some(convert_mut::(block)) } else { - debug!("get_block_mut(global_block_id: {}) not found", index + self.global_offset); + trace!("get_block_mut(global_block_id: {}) not found", index + self.global_offset); None } // self.cache.get_mut(&index).map(|block| { - // debug!("get_block_mut(global_block_id: {}) found", index + self.global_offset); + // trace!("get_block_mut(global_block_id: {}) found", index + self.global_offset); // block.dirty = true; // convert_mut::(block) // }) @@ -159,7 +159,7 @@ impl BlockCache { data_block.dirty = true; // TODO 需要把显式写回的都标记为 dirty 吗 let (entry, _value) = self.cache.push(block.index, data_block).unwrap(); assert_eq!(entry, block.index); - debug!("update_block(global_block_id: {})", block.index + self.global_offset); + trace!("update_block(global_block_id: {})", block.index + self.global_offset); true } else { false @@ -167,7 +167,7 @@ impl BlockCache { } fn pop(&mut self, entry: usize) -> Option> { - debug!("pop_block(global_block_id: {})", entry + self.global_offset); + trace!("pop_block(global_block_id: {})", entry + self.global_offset); self.cache.pop(&entry) } } @@ -179,10 +179,10 @@ impl AyaFS { pub(crate) fn get_block(&mut self, index: usize) -> Option<&CachedBlock> { if self.data_bitmap.query(index) { - debug!("get_block(block_id: {}) found", index); + trace!("get_block(block_id: {}) found", index); Some(self.cached_blocks.get_block::(index).unwrap()) } else { - debug!("get_block(block_id: {}) not exist", index); + trace!("get_block(block_id: {}) not exist", index); self.cached_blocks.pop(index); None } diff --git a/ayafs-core/src/memory/dir_entry.rs b/ayafs-core/src/memory/dir_entry.rs index 3880f61..ee363b2 100644 --- a/ayafs-core/src/memory/dir_entry.rs +++ b/ayafs-core/src/memory/dir_entry.rs @@ -4,7 +4,7 @@ use crate::AyaFS; use indexmap::map::Entry::Occupied; use indexmap::IndexMap; use libc::{c_int, ENOENT, ENOSPC}; -use log::debug; +use log::trace; use std::ffi::{OsStr, OsString}; use std::os::unix::ffi::OsStrExt; @@ -25,11 +25,11 @@ impl AyaFS { pub(crate) fn load_direntry_map(&mut self, index: usize, inode: &Inode) -> Result<(), c_int> { if self.dir_entry_map.contains(&index) { - debug!("load_direntry_map(ino: {}) already in cache", index); + trace!("load_direntry_map(ino: {}) already in cache", index); return Ok(()); } - debug!("load_direntry_map(ino: {}) loading", index); + trace!("load_direntry_map(ino: {}) loading", index); let mut dir_entry_map: IndexMap = IndexMap::new(); let mut entry_index: usize = 0; loop { @@ -38,11 +38,11 @@ impl AyaFS { match self.access_block::(inode, block_index_within_inode) { Some(directory_block) => { - debug!("bitmap for block is {:#b} {:#b}", directory_block.block.occupancy[0], directory_block.block.occupancy[1]); + trace!("bitmap for block is {:#b} {:#b}", directory_block.block.occupancy[0], directory_block.block.occupancy[1]); if directory_block.block.query(entry_index_within_block) { let dir_entry = &directory_block.block.entries[entry_index_within_block]; let name = dir_entry.name(); - debug!("loaded entry({:?}) for inode {}", name.as_os_str(), index); + trace!("loaded entry({:?}) for inode {}", name.as_os_str(), index); dir_entry_map.insert(name, dir_entry.clone()); } else { break; @@ -95,9 +95,9 @@ impl AyaFS { directory_block.block.reset(); } directory_block.dirty = true; - debug!("entry {} (block {} offset {}) for inode {}, name {:?}", entry_index, block_index_within_inode, entry_index_within_block, _parent_index, name); + trace!("entry {} (block {} offset {}) for inode {}, name {:?}", entry_index, block_index_within_inode, entry_index_within_block, _parent_index, name); directory_block.block.allocate(entry_index_within_block); - debug!("bitmap for block is {:#b} {:#b}", directory_block.block.occupancy[0], directory_block.block.occupancy[1]); + trace!("bitmap for block is {:#b} {:#b}", directory_block.block.occupancy[0], directory_block.block.occupancy[1]); directory_block.block.entries[entry_index_within_block] = dir_entry; } None => { @@ -168,7 +168,7 @@ impl AyaFS { ) -> Result<(), c_int> { self.load_direntry_map(parent_index, parent_inode)?; if let Some(dir_entry_map) = self.dir_entry_map.get_mut(&parent_index) { - debug!(" remove_direntry(ino: {}) using hashmap", parent_index); + trace!(" remove_direntry(ino: {}) using hashmap", parent_index); if dir_entry_map.shift_remove(name.as_ref()).is_some() { Ok(()) } else { @@ -191,7 +191,7 @@ impl AyaFS { if let Some(dir_entry_map) = self.dir_entry_map.get_mut(&parent_index) { let (entry_index, _) = dir_entry_map.insert_full(child_inode_name.to_os_string(), dir_entry); - debug!( + trace!( " add_direntry(ino: {}) using hashmap, entry {}", parent_index, entry_index ); @@ -227,7 +227,7 @@ impl AyaFS { let (entry_index, _) = dir_entry_map.insert_full(child_inode_name.to_os_string(), dir_entry); - debug!( + trace!( " add_direntry(ino: {}) using hashmap, entry {}", parent_index, entry_index ); @@ -246,7 +246,7 @@ impl AyaFS { ) -> Result { self.load_direntry_map(parent_index, parent_inode)?; if let Some(dir_entry_map) = self.dir_entry_map.get(&parent_index) { - debug!( + trace!( " get_direntry(ino: {}, name: {:?}) using hashmap", parent_index, name.as_ref() @@ -265,7 +265,7 @@ impl AyaFS { ) -> Result { self.load_direntry_map(parent_index, parent_inode)?; if let Some(dir_entry_map) = self.dir_entry_map.get(&parent_index) { - debug!( + trace!( " get_direntry(ino: {}, entry_index: {}) using hashmap", parent_index, entry_index ); -- cgit v1.2.3-70-g09d2