Skip to content

Commit f6dc71f

Browse files
adam900710kdave
authored andcommitted
btrfs: remove the BUG_ON() inside extent_range_clear_dirty_for_io()
Previously we had a BUG_ON() inside extent_range_clear_dirty_for_io(), as we expected all involved folios to be still locked, thus no folio should be missing. However for extent_range_clear_dirty_for_io() itself, we can skip the missing folio and handle the remaining ones, and return an error if there is anything wrong. Remove the BUG_ON() and let the caller to handle the error. In the caller we do not have a quick way to cleanup the error, but all the compression routines would handle the missing folio as an error and properly error out, so we only need to do an ASSERT() for developers, while for non-debug build the compression routine would handle the error correctly. Signed-off-by: Qu Wenruo <wqu@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
1 parent 66372c0 commit f6dc71f

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

fs/btrfs/inode.c

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -867,19 +867,24 @@ static inline void inode_should_defrag(struct btrfs_inode *inode,
867867
btrfs_add_inode_defrag(NULL, inode, small_write);
868868
}
869869

870-
static void extent_range_clear_dirty_for_io(struct inode *inode, u64 start, u64 end)
870+
static int extent_range_clear_dirty_for_io(struct inode *inode, u64 start, u64 end)
871871
{
872-
unsigned long index = start >> PAGE_SHIFT;
873872
unsigned long end_index = end >> PAGE_SHIFT;
874873
struct page *page;
874+
int ret = 0;
875875

876-
while (index <= end_index) {
876+
for (unsigned long index = start >> PAGE_SHIFT;
877+
index <= end_index; index++) {
877878
page = find_get_page(inode->i_mapping, index);
878-
BUG_ON(!page); /* Pages should be in the extent_io_tree */
879+
if (unlikely(!page)) {
880+
if (!ret)
881+
ret = -ENOENT;
882+
continue;
883+
}
879884
clear_page_dirty_for_io(page);
880885
put_page(page);
881-
index++;
882886
}
887+
return ret;
883888
}
884889

885890
/*
@@ -923,7 +928,16 @@ static void compress_file_range(struct btrfs_work *work)
923928
* Otherwise applications with the file mmap'd can wander in and change
924929
* the page contents while we are compressing them.
925930
*/
926-
extent_range_clear_dirty_for_io(&inode->vfs_inode, start, end);
931+
ret = extent_range_clear_dirty_for_io(&inode->vfs_inode, start, end);
932+
933+
/*
934+
* All the folios should have been locked thus no failure.
935+
*
936+
* And even if some folios are missing, btrfs_compress_folios()
937+
* would handle them correctly, so here just do an ASSERT() check for
938+
* early logic errors.
939+
*/
940+
ASSERT(ret == 0);
927941

928942
/*
929943
* We need to save i_size before now because it could change in between

0 commit comments

Comments
 (0)