Pull btrfs fixes from David Sterba: - fixup warning when allocating memory for readahead, __GFP_NOWARN was accidentally dropped when setting mapping constraints - in tracepoint of file sync, fix sleeping in atomic context when handling dentries - harden initial loading of block group on crafted/fuzzed images, iterate all chunk mapping entries unconditionally - fix freeing pages of submitted io after checking for errors - fix incorrect inode size after remount when using fallocate KEEP_SIZE mode (also requires disabled 'no-holes' feature) * tag 'for-7.1-rc3-tag' of git://git.kernel.org/pub/scm/linux/kernel/git/kdave/linux: btrfs: fix incorrect i_size after remount caused by KEEP_SIZE prealloc gap btrfs: only release the dirty pages io tree after successful writes btrfs: tracepoints: fix sleep while in atomic context in btrfs_sync_file() btrfs: always pass __GFP_NOWARN from add_ra_bio_pages() btrfs: fix check_chunk_block_group_mappings() to iterate all chunk maps
Unified · Split
| @@ -2412,29 +2412,25 @@ static struct btrfs_block_group *btrfs_create_block_group( · 2411 unmodified lines | ||
| 2412 | 2412 | */ |
| 2413 | 2413 | static int check_chunk_block_group_mappings(struct btrfs_fs_info *fs_info) |
| 2414 | 2414 | { |
| 2415 | − u64 start = 0; | |
| 2415 | + struct rb_node *node; | |
| 2416 | 2416 | int ret = 0; |
| 2417 | 2417 | |
| 2418 | − while (1) { | |
| 2418 | + /* | |
| 2419 | + * This is called during mount from btrfs_read_block_groups(), before | |
| 2420 | + * any background threads are started, so no concurrent writers can | |
| 2421 | + * modify the mapping_tree. No lock is needed here. | |
| 2422 | + */ | |
| 2423 | + for (node = rb_first_cached(&fs_info->mapping_tree); node; node = rb_next(node)) { | |
| 2419 | 2424 | struct btrfs_chunk_map *map; |
| 2420 | 2425 | struct btrfs_block_group *bg; |
| 2421 | 2426 | |
| 2422 | − /* | |
| 2423 | − * btrfs_find_chunk_map() will return the first chunk map | |
| 2424 | − * intersecting the range, so setting @length to 1 is enough to | |
| 2425 | − * get the first chunk. | |
| 2426 | − */ | |
| 2427 | − map = btrfs_find_chunk_map(fs_info, start, 1); | |
| 2428 | − if (!map) | |
| 2429 | − break; | |
| 2430 | − | |
| 2427 | + map = rb_entry(node, struct btrfs_chunk_map, rb_node); | |
| 2431 | 2428 | bg = btrfs_lookup_block_group(fs_info, map->start); |
| 2432 | 2429 | if (unlikely(!bg)) { |
| 2433 | 2430 | btrfs_err(fs_info, |
| 2434 | 2431 | "chunk start=%llu len=%llu doesn't have corresponding block group", |
| 2435 | 2432 | map->start, map->chunk_len); |
| 2436 | 2433 | ret = -EUCLEAN; |
| 2437 | − btrfs_free_chunk_map(map); | |
| 2438 | 2434 | break; |
| 2439 | 2435 | } |
| 2440 | 2436 | if (unlikely(bg->start != map->start || bg->length != map->chunk_len || |
| @@ -2447,12 +2443,9 @@ static int check_chunk_block_group_mappings(struct btrfs_fs_info *fs_info) · 6 unmodified lines | ||
| 2447 | 2443 | bg->start, bg->length, |
| 2448 | 2444 | bg->flags & BTRFS_BLOCK_GROUP_TYPE_MASK); |
| 2449 | 2445 | ret = -EUCLEAN; |
| 2450 | − btrfs_free_chunk_map(map); | |
| 2451 | 2446 | btrfs_put_block_group(bg); |
| 2452 | 2447 | break; |
| 2453 | 2448 | } |
| 2454 | − start = map->start + map->chunk_len; | |
| 2455 | − btrfs_free_chunk_map(map); | |
| 2456 | 2449 | btrfs_put_block_group(bg); |
| 2457 | 2450 | } |
| 2458 | 2451 | return ret; |
| @@ -407,22 +407,18 @@ static noinline int add_ra_bio_pages(struct inode *inode, · 406 unmodified lines | ||
| 407 | 407 | |
| 408 | 408 | end_index = (i_size_read(inode) - 1) >> PAGE_SHIFT; |
| 409 | 409 | |
| 410 | − /* | |
| 411 | − * Avoid direct reclaim when the caller does not allow it. Since | |
| 412 | − * add_ra_bio_pages() is always speculative, suppress allocation warnings | |
| 413 | − * in either case. | |
| 414 | − */ | |
| 410 | + /* Avoid direct reclaim when the caller does not allow it. */ | |
| 411 | + constraint_gfp = ~__GFP_FS; | |
| 412 | + cache_gfp = GFP_NOFS | __GFP_NOWARN; | |
| 415 | 413 | if (!direct_reclaim) { |
| 416 | − constraint_gfp = ~(__GFP_FS | __GFP_DIRECT_RECLAIM) | __GFP_NOWARN; | |
| 417 | − cache_gfp = (GFP_NOFS & ~__GFP_DIRECT_RECLAIM) | __GFP_NOWARN; | |
| 418 | − } else { | |
| 419 | − constraint_gfp = (~__GFP_FS) | __GFP_NOWARN; | |
| 420 | − cache_gfp = GFP_NOFS | __GFP_NOWARN; | |
| 414 | + constraint_gfp &= ~__GFP_DIRECT_RECLAIM; | |
| 415 | + cache_gfp &= ~__GFP_DIRECT_RECLAIM; | |
| 421 | 416 | } |
| 422 | 417 | |
| 423 | 418 | while (cur < compressed_end) { |
| 424 | 419 | pgoff_t page_end; |
| 425 | 420 | pgoff_t pg_index = cur >> PAGE_SHIFT; |
| 421 | + gfp_t masked_constraint_gfp; | |
| 426 | 422 | u32 add_size; |
| 427 | 423 | |
| 428 | 424 | if (pg_index > end_index) |
| @@ -449,8 +445,14 @@ static noinline int add_ra_bio_pages(struct inode *inode, · 20 unmodified lines | ||
| 449 | 445 | continue; |
| 450 | 446 | } |
| 451 | 447 | |
| 452 | − folio = filemap_alloc_folio(mapping_gfp_constraint(mapping, constraint_gfp), | |
| 453 | − 0, NULL); | |
| 448 | + /* | |
| 449 | + * Since add_ra_bio_pages() is always speculative, suppress | |
| 450 | + * allocation warnings. | |
| 451 | + */ | |
| 452 | + masked_constraint_gfp = mapping_gfp_constraint(mapping, constraint_gfp); | |
| 453 | + masked_constraint_gfp |= __GFP_NOWARN; | |
| 454 | + | |
| 455 | + folio = filemap_alloc_folio(masked_constraint_gfp, 0, NULL); | |
| 454 | 456 | if (!folio) |
| 455 | 457 | break; |
| 456 | 458 | |
| @@ -4686,6 +4686,7 @@ static void btrfs_destroy_marked_extents(struct btrfs_fs_info *fs_info, · 4685 unmodified lines | ||
| 4686 | 4686 | free_extent_buffer_stale(eb); |
| 4687 | 4687 | } |
| 4688 | 4688 | } |
| 4689 | + btrfs_extent_io_tree_release(dirty_pages); | |
| 4689 | 4690 | } |
| 4690 | 4691 | |
| 4691 | 4692 | static void btrfs_destroy_pinned_extent(struct btrfs_fs_info *fs_info, |
| @@ -9299,10 +9299,38 @@ next: · 9298 unmodified lines | ||
| 9299 | 9299 | if (!(mode & FALLOC_FL_KEEP_SIZE) && |
| 9300 | 9300 | (actual_len > inode->i_size) && |
| 9301 | 9301 | (cur_offset > inode->i_size)) { |
| 9302 | + u64 range_start; | |
| 9303 | + u64 range_end; | |
| 9304 | + | |
| 9302 | 9305 | if (cur_offset > actual_len) |
| 9303 | 9306 | i_size = actual_len; |
| 9304 | 9307 | else |
| 9305 | 9308 | i_size = cur_offset; |
| 9309 | + | |
| 9310 | + /* | |
| 9311 | + * Make sure the file_extent_tree covers the entire | |
| 9312 | + * range [old_i_size, new_i_size) before we update | |
| 9313 | + * disk_i_size. Without this, a previous KEEP_SIZE | |
| 9314 | + * prealloc that extended past i_size (and was lost | |
| 9315 | + * across umount/mount because file_extent_tree is | |
| 9316 | + * only populated up to round_up(i_size) on inode | |
| 9317 | + * load) can leave a gap inside this range. That gap | |
| 9318 | + * would cause btrfs_inode_safe_disk_i_size_write() | |
| 9319 | + * (via find_contiguous_extent_bit() starting at 0) | |
| 9320 | + * to truncate disk_i_size to the start of the gap, | |
| 9321 | + * making the persisted size smaller than i_size. | |
| 9322 | + */ | |
| 9323 | + range_start = round_down(inode->i_size, fs_info->sectorsize); | |
| 9324 | + range_end = round_up(i_size, fs_info->sectorsize); | |
| 9325 | + ret = btrfs_inode_set_file_extent_range(BTRFS_I(inode), | |
| 9326 | + range_start, range_end - range_start); | |
| 9327 | + if (ret) { | |
| 9328 | + btrfs_abort_transaction(trans, ret); | |
| 9329 | + if (own_trans) | |
| 9330 | + btrfs_end_transaction(trans); | |
| 9331 | + break; | |
| 9332 | + } | |
| 9333 | + | |
| 9306 | 9334 | i_size_write(inode, i_size); |
| 9307 | 9335 | btrfs_inode_safe_disk_i_size_write(BTRFS_I(inode), 0); |
| 9308 | 9336 | } |
| @@ -1293,14 +1293,13 @@ static int btrfs_write_and_wait_transaction(struct btrfs_trans_handle *trans) · 1292 unmodified lines | ||
| 1293 | 1293 | blk_finish_plug(&plug); |
| 1294 | 1294 | ret2 = btrfs_wait_extents(fs_info, dirty_pages); |
| 1295 | 1295 | |
| 1296 | − btrfs_extent_io_tree_release(&trans->transaction->dirty_pages); | |
| 1297 | − | |
| 1298 | 1296 | if (ret) |
| 1299 | 1297 | return ret; |
| 1300 | − else if (ret2) | |
| 1298 | + if (ret2) | |
| 1301 | 1299 | return ret2; |
| 1302 | − else | |
| 1303 | − return 0; | |
| 1300 | + | |
| 1301 | + btrfs_extent_io_tree_release(&trans->transaction->dirty_pages); | |
| 1302 | + return 0; | |
| 1304 | 1303 | } |
| 1305 | 1304 | |
| 1306 | 1305 | /* |
| @@ -771,10 +771,8 @@ TRACE_EVENT(btrfs_sync_file, · 770 unmodified lines | ||
| 771 | 771 | TP_fast_assign( |
| 772 | 772 | struct dentry *dentry = file_dentry(file); |
| 773 | 773 | struct inode *inode = file_inode(file); |
| 774 | − struct dentry *parent = dget_parent(dentry); | |
| 775 | − struct inode *parent_inode = d_inode(parent); | |
| 774 | + struct inode *parent_inode = d_inode(dentry->d_parent); | |
| 776 | 775 | |
| 777 | − dput(parent); | |
| 778 | 776 | TP_fast_assign_fsid(btrfs_sb(inode->i_sb)); |
| 779 | 777 | __entry->ino = btrfs_ino(BTRFS_I(inode)); |
| 780 | 778 | __entry->parent = btrfs_ino(BTRFS_I(parent_inode)); |