]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/commitdiff
f2fs: Keep alloc_valid_block_count in sync
authorDaniel Rosenberg <drosen@google.com>
Tue, 10 Jul 2018 03:32:42 +0000 (20:32 -0700)
committerJuerg Haefliger <juergh@canonical.com>
Wed, 24 Jul 2019 01:48:14 +0000 (19:48 -0600)
BugLink: https://bugs.launchpad.net/bugs/1836117
[ Upstream commit 36b877af7992893b6d1ddbe96971cab5ab9e50eb ]

If we attempt to request more blocks than we have room for, we try to
instead request as much as we can, however, alloc_valid_block_count
is not decremented to match the new value, allowing it to drift higher
until the next checkpoint. This always decrements it when the requested
amount cannot be fulfilled.

Signed-off-by: Daniel Rosenberg <drosen@google.com>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
Signed-off-by: Sasha Levin <alexander.levin@microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Kamal Mostafa <kamal@canonical.com>
Signed-off-by: Kleber Sacilotto de Souza <kleber.souza@canonical.com>
fs/f2fs/f2fs.h

index 30c177de05d24ab1c09dc088a8cad0071efebdef..5846bb8878486faa900e1b7b2752f301709e8960 100644 (file)
@@ -1579,18 +1579,20 @@ static inline int inc_valid_block_count(struct f2fs_sb_info *sbi,
                sbi->total_valid_block_count = avail_user_block_count;
                if (!*count) {
                        spin_unlock(&sbi->stat_lock);
-                       percpu_counter_sub(&sbi->alloc_valid_block_count, diff);
                        goto enospc;
                }
        }
        spin_unlock(&sbi->stat_lock);
 
-       if (release)
+       if (unlikely(release)) {
+               percpu_counter_sub(&sbi->alloc_valid_block_count, release);
                dquot_release_reservation_block(inode, release);
+       }
        f2fs_i_blocks_write(inode, *count, true, true);
        return 0;
 
 enospc:
+       percpu_counter_sub(&sbi->alloc_valid_block_count, release);
        dquot_release_reservation_block(inode, release);
        return -ENOSPC;
 }