mirror of
https://github.com/hardkernel/linux.git
synced 2026-06-05 10:31:46 +09:00
BACKPORT: f2fs: introduce get_available_block_count() for cleanup
There are very similar codes in inc_valid_block_count() and inc_valid_node_count() which is used for available user block count calculation. This patch introduces a new helper get_available_block_count() to include those common codes, and used it to clean up codes. Change-Id: Ie2ce55bdac091bc4880478eeba2a76e1608726e3 Signed-off-by: Chao Yu <chao@kernel.org> Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org> (cherry picked from commit 0f1c6ede6da9f7c5dd7380b74a64850298279168) [Added line for F2FS_IO_ALIGNED, which was removed in later kernels] Signed-off-by: Daniel Rosenberg <drosen@google.com>
This commit is contained in:
committed by
Daniel Rosenberg
parent
997d1e6f69
commit
38149d5303
@@ -2235,6 +2235,31 @@ static inline bool __allow_reserved_blocks(struct f2fs_sb_info *sbi,
|
||||
return false;
|
||||
}
|
||||
|
||||
static inline unsigned int get_available_block_count(struct f2fs_sb_info *sbi,
|
||||
struct inode *inode, bool cap)
|
||||
{
|
||||
block_t avail_user_block_count;
|
||||
|
||||
avail_user_block_count = sbi->user_block_count -
|
||||
sbi->current_reserved_blocks;
|
||||
|
||||
if (!__allow_reserved_blocks(sbi, inode, cap))
|
||||
avail_user_block_count -= F2FS_OPTION(sbi).root_reserved_blocks;
|
||||
|
||||
if (F2FS_IO_ALIGNED(sbi))
|
||||
avail_user_block_count -= sbi->blocks_per_seg *
|
||||
SM_I(sbi)->additional_reserved_segments;
|
||||
|
||||
if (unlikely(is_sbi_flag_set(sbi, SBI_CP_DISABLED))) {
|
||||
if (avail_user_block_count > sbi->unusable_block_count)
|
||||
avail_user_block_count -= sbi->unusable_block_count;
|
||||
else
|
||||
avail_user_block_count = 0;
|
||||
}
|
||||
|
||||
return avail_user_block_count;
|
||||
}
|
||||
|
||||
static inline void f2fs_i_blocks_write(struct inode *, block_t, bool, bool);
|
||||
static inline int inc_valid_block_count(struct f2fs_sb_info *sbi,
|
||||
struct inode *inode, blkcnt_t *count, bool partial)
|
||||
@@ -2260,22 +2285,8 @@ static inline int inc_valid_block_count(struct f2fs_sb_info *sbi,
|
||||
|
||||
spin_lock(&sbi->stat_lock);
|
||||
sbi->total_valid_block_count += (block_t)(*count);
|
||||
avail_user_block_count = sbi->user_block_count -
|
||||
sbi->current_reserved_blocks;
|
||||
avail_user_block_count = get_available_block_count(sbi, inode, true);
|
||||
|
||||
if (!__allow_reserved_blocks(sbi, inode, true))
|
||||
avail_user_block_count -= F2FS_OPTION(sbi).root_reserved_blocks;
|
||||
|
||||
if (F2FS_IO_ALIGNED(sbi))
|
||||
avail_user_block_count -= sbi->blocks_per_seg *
|
||||
SM_I(sbi)->additional_reserved_segments;
|
||||
|
||||
if (unlikely(is_sbi_flag_set(sbi, SBI_CP_DISABLED))) {
|
||||
if (avail_user_block_count > sbi->unusable_block_count)
|
||||
avail_user_block_count -= sbi->unusable_block_count;
|
||||
else
|
||||
avail_user_block_count = 0;
|
||||
}
|
||||
if (unlikely(sbi->total_valid_block_count > avail_user_block_count)) {
|
||||
if (!partial) {
|
||||
spin_unlock(&sbi->stat_lock);
|
||||
@@ -2595,7 +2606,8 @@ static inline int inc_valid_node_count(struct f2fs_sb_info *sbi,
|
||||
struct inode *inode, bool is_inode)
|
||||
{
|
||||
block_t valid_block_count;
|
||||
unsigned int valid_node_count, user_block_count;
|
||||
unsigned int valid_node_count;
|
||||
unsigned int avail_user_block_count;
|
||||
int err;
|
||||
|
||||
if (is_inode) {
|
||||
@@ -2615,21 +2627,10 @@ static inline int inc_valid_node_count(struct f2fs_sb_info *sbi,
|
||||
|
||||
spin_lock(&sbi->stat_lock);
|
||||
|
||||
valid_block_count = sbi->total_valid_block_count +
|
||||
sbi->current_reserved_blocks + 1;
|
||||
valid_block_count = sbi->total_valid_block_count + 1;
|
||||
avail_user_block_count = get_available_block_count(sbi, inode, false);
|
||||
|
||||
if (!__allow_reserved_blocks(sbi, inode, false))
|
||||
valid_block_count += F2FS_OPTION(sbi).root_reserved_blocks;
|
||||
|
||||
if (F2FS_IO_ALIGNED(sbi))
|
||||
valid_block_count += sbi->blocks_per_seg *
|
||||
SM_I(sbi)->additional_reserved_segments;
|
||||
|
||||
user_block_count = sbi->user_block_count;
|
||||
if (unlikely(is_sbi_flag_set(sbi, SBI_CP_DISABLED)))
|
||||
user_block_count -= sbi->unusable_block_count;
|
||||
|
||||
if (unlikely(valid_block_count > user_block_count)) {
|
||||
if (unlikely(valid_block_count > avail_user_block_count)) {
|
||||
spin_unlock(&sbi->stat_lock);
|
||||
goto enospc;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user