Skip to content

Commit 965f47a

Browse files
Stefan Roeschkdave
authored andcommitted
btrfs: make btrfs_buffered_write nowait compatible
We need to avoid unconditionally calling balance_dirty_pages_ratelimited as it could wait for some reason. Use balance_dirty_pages_ratelimited_flags with the BDP_ASYNC in case the buffered write is nowait, returning EAGAIN eventually. It also moves the function after the again label. This can cause the function to be called a bit later, but this should have no impact in the real world. Reviewed-by: Filipe Manana <[email protected]> Signed-off-by: Stefan Roesch <[email protected]> Reviewed-by: David Sterba <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent 304e45a commit 965f47a

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

fs/btrfs/file.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1653,6 +1653,7 @@ static noinline ssize_t btrfs_buffered_write(struct kiocb *iocb,
16531653
loff_t old_isize = i_size_read(inode);
16541654
unsigned int ilock_flags = 0;
16551655
const bool nowait = (iocb->ki_flags & IOCB_NOWAIT);
1656+
unsigned int bdp_flags = (nowait ? BDP_ASYNC : 0);
16561657

16571658
if (nowait)
16581659
ilock_flags |= BTRFS_ILOCK_TRY;
@@ -1755,6 +1756,10 @@ static noinline ssize_t btrfs_buffered_write(struct kiocb *iocb,
17551756

17561757
release_bytes = reserve_bytes;
17571758
again:
1759+
ret = balance_dirty_pages_ratelimited_flags(inode->i_mapping, bdp_flags);
1760+
if (ret)
1761+
break;
1762+
17581763
/*
17591764
* This is going to setup the pages array with the number of
17601765
* pages we want, so we don't really need to worry about the
@@ -1858,8 +1863,6 @@ static noinline ssize_t btrfs_buffered_write(struct kiocb *iocb,
18581863

18591864
cond_resched();
18601865

1861-
balance_dirty_pages_ratelimited(inode->i_mapping);
1862-
18631866
pos += copied;
18641867
num_written += copied;
18651868
}

0 commit comments

Comments
 (0)