[PATCH 06/21] btrfs: wait ordered range before locking during truncate

Goldwyn Rodrigues
2023-03-02T22:25:21Z

Check if truncate needs to wait for ordered range before calling
btrfs_truncate(). Instead of performing it in btrfs_truncate(), perform
the wait before the call.

Remove the no longer needed variable to perform writeback in
btrfs_truncate().

Signed-off-by: Goldwyn Rodrigues <rgoldwyn@suse.com>
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Reviewed-by: Josef Bacik <josef@toxicpanda.com>
---
fs/btrfs/inode.c | 18 +++++-------------
1 file changed, 5 insertions(+), 13 deletions(-)

diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index 2c96c39975e0..02307789b0a8 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -109,7 +109,7 @@ static const struct file_operations btrfs_dir_file_operations;
static struct kmem_cache *btrfs_inode_cachep;

static int btrfs_setsize(struct inode *inode, struct iattr *attr);
-static int btrfs_truncate(struct btrfs_inode *inode, bool skip_writeback);
+static int btrfs_truncate(struct btrfs_inode *inode);
static noinline int cow_file_range(struct btrfs_inode *inode,
struct page *locked_page,
u64 start, u64 end, int *page_started,
@@ -5084,7 +5084,7 @@ static int btrfs_setsize(struct inode *inode, struct iattr *attr)
} else {
struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb);

- if (btrfs_is_zoned(fs_info)) {
+ if (btrfs_is_zoned(fs_info) || (newsize < oldsize)) {
ret = btrfs_wait_ordered_range(inode,
ALIGN(newsize, fs_info->sectorsize),
(u64)-1);
@@ -5105,7 +5105,8 @@ static int btrfs_setsize(struct inode *inode, struct iattr *attr)

inode_dio_wait(inode);

- ret = btrfs_truncate(BTRFS_I(inode), newsize == oldsize);
+ ret = btrfs_truncate(BTRFS_I(inode));
+
if (ret && inode->i_nlink) {
int err;

@@ -8241,7 +8242,7 @@ vm_fault_t btrfs_page_mkwrite(struct vm_fault *vmf)
return ret;
}

-static int btrfs_truncate(struct btrfs_inode *inode, bool skip_writeback)
+static int btrfs_truncate(struct btrfs_inode *inode)
{
struct btrfs_truncate_control control = {
.inode = inode,
@@ -8254,17 +8255,8 @@ static int btrfs_truncate(struct btrfs_inode *inode, bool skip_writeback)
struct btrfs_block_rsv *rsv;
int ret;
struct btrfs_trans_handle *trans;
- u64 mask = fs_info->sectorsize - 1;
u64 min_size = btrfs_calc_metadata_size(fs_info, 1);

- if (!skip_writeback) {
- ret = btrfs_wait_ordered_range(&inode->vfs_inode,
- inode->vfs_inode.i_size & (~mask),
- (u64)-1);
- if (ret)
- return ret;
- }
-
/*
* Yes ladies and gentlemen, this is indeed ugly. We have a couple of
* things going on here:
--
2.39.2