Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
diqiu50 committed Dec 18, 2024
1 parent 33dc3bd commit 4fa2ed2
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 25 deletions.
30 changes: 15 additions & 15 deletions clients/filesystem-fuse/src/filesystem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -405,17 +405,17 @@ impl<T: PathFileSystem> DefaultRawFileSystem<T> {
self.file_entry_manager
.read()
.await
.get_file_by_id(file_id)
.get_by_id(file_id)
.ok_or(Errno::from(libc::ENOENT))
}

async fn get_file_entry_by_path(&self, path: &str) -> Option<FileEntry> {
self.file_entry_manager.read().await.get_file_by_path(path)
self.file_entry_manager.read().await.get_by_path(path)
}

async fn resolve_file_id_to_filestat(&self, file_stat: &mut FileStat, parent_file_id: u64) {
let mut file_manager = self.file_entry_manager.write().await;
let file_entry = file_manager.get_file_by_path(&file_stat.path);
let file_entry = file_manager.get_by_path(&file_stat.path);
match file_entry {
None => {
// allocate new file id
Expand Down Expand Up @@ -454,7 +454,7 @@ impl<T: PathFileSystem> DefaultRawFileSystem<T> {
};
// set the exists file id
opened_file.set_file_id(file_entry.parent_file_id, file_id);
let file = self.opened_file_manager.put_file(opened_file);
let file = self.opened_file_manager.put(opened_file);
let file = file.lock().await;
Ok(file.file_handle())
}
Expand Down Expand Up @@ -482,7 +482,7 @@ impl<T: PathFileSystem> RawFileSystem for DefaultRawFileSystem<T> {
async fn valid_file_handle_id(&self, file_id: u64, fh: u64) -> Result<()> {
let fh_file_id = self
.opened_file_manager
.get_file(fh)
.get(fh)
.ok_or(Errno::from(libc::EBADF))?
.lock()
.await
Expand Down Expand Up @@ -549,7 +549,7 @@ impl<T: PathFileSystem> RawFileSystem for DefaultRawFileSystem<T> {
}

// put the file to the opened file manager
let opened_file = self.opened_file_manager.put_file(opened_file);
let opened_file = self.opened_file_manager.put(opened_file);
let opened_file = opened_file.lock().await;
Ok(opened_file.file_handle())
}
Expand Down Expand Up @@ -600,7 +600,7 @@ impl<T: PathFileSystem> RawFileSystem for DefaultRawFileSystem<T> {
async fn close_file(&self, _file_id: u64, fh: u64) -> Result<()> {
let opened_file = self
.opened_file_manager
.remove_file(fh)
.remove(fh)
.ok_or(Errno::from(libc::EBADF))?;
let mut file = opened_file.lock().await;
file.close().await
Expand All @@ -611,7 +611,7 @@ impl<T: PathFileSystem> RawFileSystem for DefaultRawFileSystem<T> {
let data = {
let opened_file = self
.opened_file_manager
.get_file(fh)
.get(fh)
.ok_or(Errno::from(libc::EBADF))?;
let mut opened_file = opened_file.lock().await;
file_stat = opened_file.file_stat.clone();
Expand All @@ -628,7 +628,7 @@ impl<T: PathFileSystem> RawFileSystem for DefaultRawFileSystem<T> {
let (len, file_stat) = {
let opened_file = self
.opened_file_manager
.get_file(fh)
.get(fh)
.ok_or(Errno::from(libc::EBADF))?;
let mut opened_file = opened_file.lock().await;
let len = opened_file.write(offset, data).await;
Expand Down Expand Up @@ -667,11 +667,11 @@ impl FileEntryManager {
}
}

fn get_file_by_id(&self, file_id: u64) -> Option<FileEntry> {
fn get_by_id(&self, file_id: u64) -> Option<FileEntry> {
self.file_id_map.get(&file_id).cloned()
}

fn get_file_by_path(&self, path: &str) -> Option<FileEntry> {
fn get_by_path(&self, path: &str) -> Option<FileEntry> {
self.file_path_map.get(path).cloned()
}

Expand Down Expand Up @@ -758,18 +758,18 @@ mod tests {
fn test_file_entry_manager() {
let mut manager = FileEntryManager::new();
manager.insert(1, 2, "a/b");
let file = manager.get_file_by_id(2).unwrap();
let file = manager.get_by_id(2).unwrap();
assert_eq!(file.file_id, 2);
assert_eq!(file.parent_file_id, 1);
assert_eq!(file.path, "a/b");

let file = manager.get_file_by_path("a/b").unwrap();
let file = manager.get_by_path("a/b").unwrap();
assert_eq!(file.file_id, 2);
assert_eq!(file.parent_file_id, 1);
assert_eq!(file.path, "a/b");

manager.remove("a/b");
assert!(manager.get_file_by_id(2).is_none());
assert!(manager.get_file_by_path("a/b").is_none());
assert!(manager.get_by_id(2).is_none());
assert!(manager.get_by_path("a/b").is_none());
}
}
20 changes: 10 additions & 10 deletions clients/filesystem-fuse/src/opened_file_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ impl OpenedFileManager {
.fetch_add(1, std::sync::atomic::Ordering::SeqCst)
}

pub(crate) fn put_file(&self, mut file: OpenedFile) -> Arc<Mutex<OpenedFile>> {
pub(crate) fn put(&self, mut file: OpenedFile) -> Arc<Mutex<OpenedFile>> {
let file_handle_id = self.next_handle_id();
file.handle_id = file_handle_id;
let file_handle = Arc::new(Mutex::new(file));
Expand All @@ -53,13 +53,13 @@ impl OpenedFileManager {
file_handle
}

pub(crate) fn get_file(&self, handle_id: u64) -> Option<Arc<Mutex<OpenedFile>>> {
pub(crate) fn get(&self, handle_id: u64) -> Option<Arc<Mutex<OpenedFile>>> {
self.file_handle_map
.get(&handle_id)
.map(|x| x.value().clone())
}

pub(crate) fn remove_file(&self, handle_id: u64) -> Option<Arc<Mutex<OpenedFile>>> {
pub(crate) fn remove(&self, handle_id: u64) -> Option<Arc<Mutex<OpenedFile>>> {
self.file_handle_map.remove(&handle_id).map(|x| x.1)
}
}
Expand All @@ -79,8 +79,8 @@ mod tests {
let file1 = OpenedFile::new(file1_stat.clone());
let file2 = OpenedFile::new(file2_stat.clone());

let handle_id1 = manager.put_file(file1).lock().await.handle_id;
let handle_id2 = manager.put_file(file2).lock().await.handle_id;
let handle_id1 = manager.put(file1).lock().await.handle_id;
let handle_id2 = manager.put(file2).lock().await.handle_id;

// Test the file handle id is assigned.
assert!(handle_id1 > 0 && handle_id2 > 0);
Expand All @@ -89,7 +89,7 @@ mod tests {
// test get file by handle id
assert_eq!(
manager
.get_file(handle_id1)
.get(handle_id1)
.unwrap()
.lock()
.await
Expand All @@ -100,7 +100,7 @@ mod tests {

assert_eq!(
manager
.get_file(handle_id2)
.get(handle_id2)
.unwrap()
.lock()
.await
Expand All @@ -112,7 +112,7 @@ mod tests {
// test remove file by handle id
assert_eq!(
manager
.remove_file(handle_id1)
.remove(handle_id1)
.unwrap()
.lock()
.await
Expand All @@ -121,7 +121,7 @@ mod tests {
);

// test get file by handle id after remove
assert!(manager.get_file(handle_id1).is_none());
assert!(manager.get_file(handle_id2).is_some());
assert!(manager.get(handle_id1).is_none());
assert!(manager.get(handle_id2).is_some());
}
}

0 comments on commit 4fa2ed2

Please sign in to comment.