Skip to content

Commit 705d84a

Browse files
committed
Merge tag 'for-5.17-rc4-tag' of git://git.kernel.org/pub/scm/linux/kernel/git/kdave/linux
Pull btrfs fixes from David Sterba: - yield CPU more often when defragmenting a large file - skip defragmenting extents already under writeback - improve error message when send fails to write file data - get rid of warning when mounted with 'flushoncommit' * tag 'for-5.17-rc4-tag' of git://git.kernel.org/pub/scm/linux/kernel/git/kdave/linux: btrfs: send: in case of IO error log it btrfs: get rid of warning on transaction commit when using flushoncommit btrfs: defrag: don't try to defrag extents which are under writeback btrfs: don't hold CPU for too long when defragging a file
2 parents 2572da4 + 2e7be9d commit 705d84a

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

fs/btrfs/ioctl.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1210,6 +1210,10 @@ static int defrag_collect_targets(struct btrfs_inode *inode,
12101210
if (em->generation < newer_than)
12111211
goto next;
12121212

1213+
/* This em is under writeback, no need to defrag */
1214+
if (em->generation == (u64)-1)
1215+
goto next;
1216+
12131217
/*
12141218
* Our start offset might be in the middle of an existing extent
12151219
* map, so take that into account.
@@ -1629,6 +1633,7 @@ int btrfs_defrag_file(struct inode *inode, struct file_ra_state *ra,
16291633
ret = 0;
16301634
break;
16311635
}
1636+
cond_resched();
16321637
}
16331638

16341639
if (ra_allocated)

fs/btrfs/send.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4999,6 +4999,10 @@ static int put_file_data(struct send_ctx *sctx, u64 offset, u32 len)
49994999
lock_page(page);
50005000
if (!PageUptodate(page)) {
50015001
unlock_page(page);
5002+
btrfs_err(fs_info,
5003+
"send: IO error at offset %llu for inode %llu root %llu",
5004+
page_offset(page), sctx->cur_ino,
5005+
sctx->send_root->root_key.objectid);
50025006
put_page(page);
50035007
ret = -EIO;
50045008
break;

fs/btrfs/transaction.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1981,16 +1981,24 @@ static void btrfs_cleanup_pending_block_groups(struct btrfs_trans_handle *trans)
19811981
static inline int btrfs_start_delalloc_flush(struct btrfs_fs_info *fs_info)
19821982
{
19831983
/*
1984-
* We use writeback_inodes_sb here because if we used
1984+
* We use try_to_writeback_inodes_sb() here because if we used
19851985
* btrfs_start_delalloc_roots we would deadlock with fs freeze.
19861986
* Currently are holding the fs freeze lock, if we do an async flush
19871987
* we'll do btrfs_join_transaction() and deadlock because we need to
19881988
* wait for the fs freeze lock. Using the direct flushing we benefit
19891989
* from already being in a transaction and our join_transaction doesn't
19901990
* have to re-take the fs freeze lock.
1991+
*
1992+
* Note that try_to_writeback_inodes_sb() will only trigger writeback
1993+
* if it can read lock sb->s_umount. It will always be able to lock it,
1994+
* except when the filesystem is being unmounted or being frozen, but in
1995+
* those cases sync_filesystem() is called, which results in calling
1996+
* writeback_inodes_sb() while holding a write lock on sb->s_umount.
1997+
* Note that we don't call writeback_inodes_sb() directly, because it
1998+
* will emit a warning if sb->s_umount is not locked.
19911999
*/
19922000
if (btrfs_test_opt(fs_info, FLUSHONCOMMIT))
1993-
writeback_inodes_sb(fs_info->sb, WB_REASON_SYNC);
2001+
try_to_writeback_inodes_sb(fs_info->sb, WB_REASON_SYNC);
19942002
return 0;
19952003
}
19962004

0 commit comments

Comments
 (0)