Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Fix InodeTable issues revealed by xfstests #44

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions src/inode_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,9 @@ impl InodeTable {
lookups = entry.lookups;
if lookups == 0 {
delete = true;
self.by_path.remove(entry.path.as_ref().unwrap());
if let Some(path) = entry.path.as_ref() {
self.by_path.remove(path);
}
}
}

Expand All @@ -180,15 +182,21 @@ impl InodeTable {
/// Change an inode's path to a different one, without changing the inode number.
/// Lookup counts remain unchanged, even if this is replacing another file.
pub fn rename(&mut self, oldpath: &Path, newpath: Arc<PathBuf>) {
// replace the old path with the new one
let idx = self.by_path.remove(Pathish::new(oldpath)).unwrap();
self.table[idx].path = Some(newpath.clone());
self.by_path.insert(newpath, idx); // this can replace a path with a new inode
let prev = self.by_path.insert(newpath, idx); // this can replace a path with a new inode

// unlink the new path from the previous inode holding it
if let Some(prev) = prev {
self.table[prev].path = None;
}
}

/// Remove the path->inode mapping for a given path, but keep the inode around.
pub fn unlink(&mut self, path: &Path) {
self.by_path.remove(Pathish::new(path));
// Note that the inode->path mapping remains.
let idx = self.by_path.remove(Pathish::new(path)).unwrap();
self.table[idx].path = None;
}

/// Get a free indode table entry and its number, either by allocating a new one, or re-using
Expand Down