Skip to content

Commit

Permalink
Merge pull request #53 from RoyWFHuang/master
Browse files Browse the repository at this point in the history
Fix sb_read and umount cache not be freed
  • Loading branch information
jserv authored Aug 4, 2024
2 parents 403e1b8 + cc21eee commit 56d2ca0
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 4 deletions.
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

0 comments on commit 56d2ca0

Please sign in to comment.