]> git.baikalelectronics.ru Git - kernel.git/commitdiff
btrfs: fix inode reserve space leak due to nowait buffered write
authorFilipe Manana <fdmanana@suse.com>
Wed, 2 Nov 2022 12:46:36 +0000 (12:46 +0000)
committerDavid Sterba <dsterba@suse.com>
Wed, 2 Nov 2022 16:44:45 +0000 (17:44 +0100)
During a nowait buffered write, if we fail to balance dirty pages we exit
btrfs_buffered_write() without releasing the delalloc space reserved for
an extent, resulting in leaking space from the inode's block reserve.

So fix that by releasing the delalloc space for the extent when balancing
dirty pages fails.

Reported-by: kernel test robot <yujie.liu@intel.com>
Link: https://lore.kernel.org/all/202210111304.d369bc32-yujie.liu@intel.com
Fixes: df3bfbe171cf ("btrfs: make btrfs_buffered_write nowait compatible")
Reviewed-by: Josef Bacik <josef@toxicpanda.com>
Signed-off-by: Filipe Manana <fdmanana@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/file.c

index 5ce2ae9d4f72348ebf9691f9a9db90fcd1263af8..d01631d478067e788264a6bc3dcc8a3e94302748 100644 (file)
@@ -1607,8 +1607,10 @@ static noinline ssize_t btrfs_buffered_write(struct kiocb *iocb,
                release_bytes = reserve_bytes;
 again:
                ret = balance_dirty_pages_ratelimited_flags(inode->i_mapping, bdp_flags);
-               if (ret)
+               if (ret) {
+                       btrfs_delalloc_release_extents(BTRFS_I(inode), reserve_bytes);
                        break;
+               }
 
                /*
                 * This is going to setup the pages array with the number of