Skip to content

Commit 043c832

Browse files
chaseyuJaegeuk Kim
authored andcommitted
f2fs: compress: fix error path of inc_valid_block_count()
If inc_valid_block_count() can not allocate all requested blocks, it needs to release block count in .total_valid_block_count and resevation blocks in inode. Fixes: 5460749 ("f2fs: compress: fix to avoid inconsistence bewteen i_blocks and dnode") Signed-off-by: Chao Yu <[email protected]> Signed-off-by: Jaegeuk Kim <[email protected]>
1 parent a3a0bc6 commit 043c832

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

fs/f2fs/f2fs.h

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2306,7 +2306,7 @@ static inline void f2fs_i_blocks_write(struct inode *, block_t, bool, bool);
23062306
static inline int inc_valid_block_count(struct f2fs_sb_info *sbi,
23072307
struct inode *inode, blkcnt_t *count, bool partial)
23082308
{
2309-
blkcnt_t diff = 0, release = 0;
2309+
long long diff = 0, release = 0;
23102310
block_t avail_user_block_count;
23112311
int ret;
23122312

@@ -2326,26 +2326,27 @@ static inline int inc_valid_block_count(struct f2fs_sb_info *sbi,
23262326
percpu_counter_add(&sbi->alloc_valid_block_count, (*count));
23272327

23282328
spin_lock(&sbi->stat_lock);
2329-
sbi->total_valid_block_count += (block_t)(*count);
2330-
avail_user_block_count = get_available_block_count(sbi, inode, true);
23312329

2332-
if (unlikely(sbi->total_valid_block_count > avail_user_block_count)) {
2330+
avail_user_block_count = get_available_block_count(sbi, inode, true);
2331+
diff = (long long)sbi->total_valid_block_count + *count -
2332+
avail_user_block_count;
2333+
if (unlikely(diff > 0)) {
23332334
if (!partial) {
23342335
spin_unlock(&sbi->stat_lock);
2336+
release = *count;
23352337
goto enospc;
23362338
}
2337-
2338-
diff = sbi->total_valid_block_count - avail_user_block_count;
23392339
if (diff > *count)
23402340
diff = *count;
23412341
*count -= diff;
23422342
release = diff;
2343-
sbi->total_valid_block_count -= diff;
23442343
if (!*count) {
23452344
spin_unlock(&sbi->stat_lock);
23462345
goto enospc;
23472346
}
23482347
}
2348+
sbi->total_valid_block_count += (block_t)(*count);
2349+
23492350
spin_unlock(&sbi->stat_lock);
23502351

23512352
if (unlikely(release)) {

0 commit comments

Comments
 (0)