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

Fix sb_read and umount cache not be freed #53

Merged
merged 2 commits into from
Aug 4, 2024
Merged
Show file tree
Hide file tree
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
6 changes: 4 additions & 2 deletions dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,11 @@ static int simplefs_iterate(struct file *dir, struct dir_context *ctx)
goto release_bh;
}
dblock = (struct simplefs_dir_block *) bh2->b_data;
if (dblock->files[0].inode == 0)
if (dblock->files[0].inode == 0) {
brelse(bh2);
bh2 = NULL;
break;

}
/* Iterate every file in one block */
for (; fi < SIMPLEFS_FILES_PER_BLOCK; fi++) {
f = &dblock->files[fi];
Expand Down
4 changes: 4 additions & 0 deletions fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ static int __init simplefs_init(void)

err_inode:
simplefs_destroy_inode_cache();
/* Only after rcu_barrier() is the memory guaranteed to be freed. */
rcu_barrier();
err:
return ret;
}
Expand All @@ -69,6 +71,8 @@ static void __exit simplefs_exit(void)
pr_err("Failed to unregister file system\n");

simplefs_destroy_inode_cache();
/* Only after rcu_barrier() is the memory guaranteed to be freed. */
rcu_barrier();

pr_info("module unloaded\n");
}
Expand Down
4 changes: 2 additions & 2 deletions inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -749,8 +749,8 @@ static int simplefs_rename(struct inode *old_dir,
break;
}
}
if (new_pos < 0)
brelse(bh2);

brelse(bh2);
}
}

Expand Down
3 changes: 3 additions & 0 deletions super.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ int simplefs_init_inode_cache(void)
/* De-allocate the inode cache */
void simplefs_destroy_inode_cache(void)
{
/* wait for call_rcu() and prevent the free cache be used */
rcu_barrier();

kmem_cache_destroy(simplefs_inode_cache);
}

Expand Down