Skip to content

Commit 304e45a

Browse files
Stefan Roeschkdave
authored andcommitted
btrfs: plumb NOWAIT through the write path
We have everywhere setup for nowait, plumb NOWAIT through the write path. Reviewed-by: Filipe Manana <[email protected]> Signed-off-by: Josef Bacik <[email protected]> Signed-off-by: Stefan Roesch <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent 2fcab92 commit 304e45a

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

fs/btrfs/file.c

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1652,8 +1652,9 @@ static noinline ssize_t btrfs_buffered_write(struct kiocb *iocb,
16521652
bool force_page_uptodate = false;
16531653
loff_t old_isize = i_size_read(inode);
16541654
unsigned int ilock_flags = 0;
1655+
const bool nowait = (iocb->ki_flags & IOCB_NOWAIT);
16551656

1656-
if (iocb->ki_flags & IOCB_NOWAIT)
1657+
if (nowait)
16571658
ilock_flags |= BTRFS_ILOCK_TRY;
16581659

16591660
ret = btrfs_inode_lock(inode, ilock_flags);
@@ -1709,17 +1710,22 @@ static noinline ssize_t btrfs_buffered_write(struct kiocb *iocb,
17091710
extent_changeset_release(data_reserved);
17101711
ret = btrfs_check_data_free_space(BTRFS_I(inode),
17111712
&data_reserved, pos,
1712-
write_bytes, false);
1713+
write_bytes, nowait);
17131714
if (ret < 0) {
17141715
int can_nocow;
17151716

1717+
if (nowait && (ret == -ENOSPC || ret == -EAGAIN)) {
1718+
ret = -EAGAIN;
1719+
break;
1720+
}
1721+
17161722
/*
17171723
* If we don't have to COW at the offset, reserve
17181724
* metadata only. write_bytes may get smaller than
17191725
* requested here.
17201726
*/
17211727
can_nocow = btrfs_check_nocow_lock(BTRFS_I(inode), pos,
1722-
&write_bytes, false);
1728+
&write_bytes, nowait);
17231729
if (can_nocow < 0)
17241730
ret = can_nocow;
17251731
if (can_nocow > 0)
@@ -1736,7 +1742,7 @@ static noinline ssize_t btrfs_buffered_write(struct kiocb *iocb,
17361742
WARN_ON(reserve_bytes == 0);
17371743
ret = btrfs_delalloc_reserve_metadata(BTRFS_I(inode),
17381744
reserve_bytes,
1739-
reserve_bytes, false);
1745+
reserve_bytes, nowait);
17401746
if (ret) {
17411747
if (!only_release_metadata)
17421748
btrfs_free_reserved_data_space(BTRFS_I(inode),
@@ -1765,10 +1771,11 @@ static noinline ssize_t btrfs_buffered_write(struct kiocb *iocb,
17651771
extents_locked = lock_and_cleanup_extent_if_need(
17661772
BTRFS_I(inode), pages,
17671773
num_pages, pos, write_bytes, &lockstart,
1768-
&lockend, false, &cached_state);
1774+
&lockend, nowait, &cached_state);
17691775
if (extents_locked < 0) {
1770-
if (extents_locked == -EAGAIN)
1776+
if (!nowait && extents_locked == -EAGAIN)
17711777
goto again;
1778+
17721779
btrfs_delalloc_release_extents(BTRFS_I(inode),
17731780
reserve_bytes);
17741781
ret = extents_locked;

0 commit comments

Comments
 (0)