History

Merge tag 'for-7.1-rc3-tag' of git://git.kernel.org/pub/scm/linux/kernel/git/kdave/linux

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

Linus Torvalds committed 6 months ago

Commit a8b0b722 parents 663ea69 c562ba66 files · +56 −35Browse files

Unified · Split

6 files
  1. fs/btrfs/block-group.c +8 −15
  2. fs/btrfs/compression.c +14 −12
  3. fs/btrfs/disk-io.c +1 −0
  4. fs/btrfs/inode.c +28 −0
  5. fs/btrfs/transaction.c +4 −5
  6. include/trace/events/btrfs.h +1 −3
fs/btrfs/block-group.c+8−15
@@ -2412,29 +2412,25 @@ static struct btrfs_block_group *btrfs_create_block_group( · 2411 unmodified lines
24122412 */
24132413 static int check_chunk_block_group_mappings(struct btrfs_fs_info *fs_info)
24142414 {
2415− u64 start = 0;
2415+ struct rb_node *node;
24162416 int ret = 0;
24172417
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)) {
24192424 struct btrfs_chunk_map *map;
24202425 struct btrfs_block_group *bg;
24212426
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);
24312428 bg = btrfs_lookup_block_group(fs_info, map->start);
24322429 if (unlikely(!bg)) {
24332430 btrfs_err(fs_info,
24342431 "chunk start=%llu len=%llu doesn't have corresponding block group",
24352432 map->start, map->chunk_len);
24362433 ret = -EUCLEAN;
2437− btrfs_free_chunk_map(map);
24382434 break;
24392435 }
24402436 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
24472443 bg->start, bg->length,
24482444 bg->flags & BTRFS_BLOCK_GROUP_TYPE_MASK);
24492445 ret = -EUCLEAN;
2450− btrfs_free_chunk_map(map);
24512446 btrfs_put_block_group(bg);
24522447 break;
24532448 }
2454− start = map->start + map->chunk_len;
2455− btrfs_free_chunk_map(map);
24562449 btrfs_put_block_group(bg);
24572450 }
24582451 return ret;
fs/btrfs/compression.c+14−12
@@ -407,22 +407,18 @@ static noinline int add_ra_bio_pages(struct inode *inode, · 406 unmodified lines
407407
408408 end_index = (i_size_read(inode) - 1) >> PAGE_SHIFT;
409409
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;
415413 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;
421416 }
422417
423418 while (cur < compressed_end) {
424419 pgoff_t page_end;
425420 pgoff_t pg_index = cur >> PAGE_SHIFT;
421+ gfp_t masked_constraint_gfp;
426422 u32 add_size;
427423
428424 if (pg_index > end_index)
@@ -449,8 +445,14 @@ static noinline int add_ra_bio_pages(struct inode *inode, · 20 unmodified lines
449445 continue;
450446 }
451447
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);
454456 if (!folio)
455457 break;
456458
fs/btrfs/disk-io.c+1−0
@@ -4686,6 +4686,7 @@ static void btrfs_destroy_marked_extents(struct btrfs_fs_info *fs_info, · 4685 unmodified lines
46864686 free_extent_buffer_stale(eb);
46874687 }
46884688 }
4689+ btrfs_extent_io_tree_release(dirty_pages);
46894690 }
46904691
46914692 static void btrfs_destroy_pinned_extent(struct btrfs_fs_info *fs_info,
fs/btrfs/inode.c+28−0
@@ -9299,10 +9299,38 @@ next: · 9298 unmodified lines
92999299 if (!(mode & FALLOC_FL_KEEP_SIZE) &&
93009300 (actual_len > inode->i_size) &&
93019301 (cur_offset > inode->i_size)) {
9302+ u64 range_start;
9303+ u64 range_end;
9304+
93029305 if (cur_offset > actual_len)
93039306 i_size = actual_len;
93049307 else
93059308 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+
93069334 i_size_write(inode, i_size);
93079335 btrfs_inode_safe_disk_i_size_write(BTRFS_I(inode), 0);
93089336 }
fs/btrfs/transaction.c+4−5
@@ -1293,14 +1293,13 @@ static int btrfs_write_and_wait_transaction(struct btrfs_trans_handle *trans) · 1292 unmodified lines
12931293 blk_finish_plug(&plug);
12941294 ret2 = btrfs_wait_extents(fs_info, dirty_pages);
12951295
1296− btrfs_extent_io_tree_release(&trans->transaction->dirty_pages);
1297−
12981296 if (ret)
12991297 return ret;
1300− else if (ret2)
1298+ if (ret2)
13011299 return ret2;
1302− else
1303− return 0;
1300+
1301+ btrfs_extent_io_tree_release(&trans->transaction->dirty_pages);
1302+ return 0;
13041303 }
13051304
13061305 /*
include/trace/events/btrfs.h+1−3
@@ -771,10 +771,8 @@ TRACE_EVENT(btrfs_sync_file, · 770 unmodified lines
771771 TP_fast_assign(
772772 struct dentry *dentry = file_dentry(file);
773773 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);
776775
777− dput(parent);
778776 TP_fast_assign_fsid(btrfs_sb(inode->i_sb));
779777 __entry->ino = btrfs_ino(BTRFS_I(inode));
780778 __entry->parent = btrfs_ino(BTRFS_I(parent_inode));