Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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

Pull btrfs fixes from David Sterba:

- fix swapfile activation on subvolumes with deleted snapshots

- error value mixup when removing directory entries from tree log

- fix lzo compression level reset after previous level setting

- fix space cache memory leak after transaction abort

- fix const function attribute

- more error handling improvements

* tag 'for-5.9-rc2-tag' of git://git.kernel.org/pub/scm/linux/kernel/git/kdave/linux:
btrfs: detect nocow for swap after snapshot delete
btrfs: check the right error variable in btrfs_del_dir_entries_in_log
btrfs: fix space cache memory leak after transaction abort
btrfs: use the correct const function attribute for btrfs_get_num_csums
btrfs: reset compression level for lzo on remount
btrfs: handle errors from async submission

+39 -31
+1 -1
fs/btrfs/ctree.c
··· 68 68 btrfs_csums[csum_type].name; 69 69 } 70 70 71 - size_t __const btrfs_get_num_csums(void) 71 + size_t __attribute_const__ btrfs_get_num_csums(void) 72 72 { 73 73 return ARRAY_SIZE(btrfs_csums); 74 74 }
+3 -3
fs/btrfs/ctree.h
··· 2262 2262 int btrfs_super_csum_size(const struct btrfs_super_block *s); 2263 2263 const char *btrfs_super_csum_name(u16 csum_type); 2264 2264 const char *btrfs_super_csum_driver(u16 csum_type); 2265 - size_t __const btrfs_get_num_csums(void); 2265 + size_t __attribute_const__ btrfs_get_num_csums(void); 2266 2266 2267 2267 2268 2268 /* ··· 2518 2518 u64 bytenr, u64 num_bytes); 2519 2519 int btrfs_exclude_logged_extents(struct extent_buffer *eb); 2520 2520 int btrfs_cross_ref_exist(struct btrfs_root *root, 2521 - u64 objectid, u64 offset, u64 bytenr); 2521 + u64 objectid, u64 offset, u64 bytenr, bool strict); 2522 2522 struct extent_buffer *btrfs_alloc_tree_block(struct btrfs_trans_handle *trans, 2523 2523 struct btrfs_root *root, 2524 2524 u64 parent, u64 root_objectid, ··· 2934 2934 u64 start, u64 len); 2935 2935 noinline int can_nocow_extent(struct inode *inode, u64 offset, u64 *len, 2936 2936 u64 *orig_start, u64 *orig_block_len, 2937 - u64 *ram_bytes); 2937 + u64 *ram_bytes, bool strict); 2938 2938 2939 2939 void __btrfs_del_delalloc_inode(struct btrfs_root *root, 2940 2940 struct btrfs_inode *inode);
+1
fs/btrfs/disk-io.c
··· 4551 4551 cache->io_ctl.inode = NULL; 4552 4552 iput(inode); 4553 4553 } 4554 + ASSERT(cache->io_ctl.pages == NULL); 4554 4555 btrfs_put_block_group(cache); 4555 4556 } 4556 4557
+11 -6
fs/btrfs/extent-tree.c
··· 2306 2306 2307 2307 static noinline int check_committed_ref(struct btrfs_root *root, 2308 2308 struct btrfs_path *path, 2309 - u64 objectid, u64 offset, u64 bytenr) 2309 + u64 objectid, u64 offset, u64 bytenr, 2310 + bool strict) 2310 2311 { 2311 2312 struct btrfs_fs_info *fs_info = root->fs_info; 2312 2313 struct btrfs_root *extent_root = fs_info->extent_root; ··· 2349 2348 btrfs_extent_inline_ref_size(BTRFS_EXTENT_DATA_REF_KEY)) 2350 2349 goto out; 2351 2350 2352 - /* If extent created before last snapshot => it's definitely shared */ 2353 - if (btrfs_extent_generation(leaf, ei) <= 2354 - btrfs_root_last_snapshot(&root->root_item)) 2351 + /* 2352 + * If extent created before last snapshot => it's shared unless the 2353 + * snapshot has been deleted. Use the heuristic if strict is false. 2354 + */ 2355 + if (!strict && 2356 + (btrfs_extent_generation(leaf, ei) <= 2357 + btrfs_root_last_snapshot(&root->root_item))) 2355 2358 goto out; 2356 2359 2357 2360 iref = (struct btrfs_extent_inline_ref *)(ei + 1); ··· 2380 2375 } 2381 2376 2382 2377 int btrfs_cross_ref_exist(struct btrfs_root *root, u64 objectid, u64 offset, 2383 - u64 bytenr) 2378 + u64 bytenr, bool strict) 2384 2379 { 2385 2380 struct btrfs_path *path; 2386 2381 int ret; ··· 2391 2386 2392 2387 do { 2393 2388 ret = check_committed_ref(root, path, objectid, 2394 - offset, bytenr); 2389 + offset, bytenr, strict); 2395 2390 if (ret && ret != -ENOENT) 2396 2391 goto out; 2397 2392
+1 -1
fs/btrfs/file.c
··· 1571 1571 } 1572 1572 1573 1573 ret = can_nocow_extent(&inode->vfs_inode, lockstart, &num_bytes, 1574 - NULL, NULL, NULL); 1574 + NULL, NULL, NULL, false); 1575 1575 if (ret <= 0) { 1576 1576 ret = 0; 1577 1577 if (!nowait)
+1 -1
fs/btrfs/free-space-cache.c
··· 1186 1186 ret = update_cache_item(trans, root, inode, path, offset, 1187 1187 io_ctl->entries, io_ctl->bitmaps); 1188 1188 out: 1189 - io_ctl_free(io_ctl); 1190 1189 if (ret) { 1191 1190 invalidate_inode_pages2(inode->i_mapping); 1192 1191 BTRFS_I(inode)->generation = 0; ··· 1346 1347 * them out later 1347 1348 */ 1348 1349 io_ctl_drop_pages(io_ctl); 1350 + io_ctl_free(io_ctl); 1349 1351 1350 1352 unlock_extent_cached(&BTRFS_I(inode)->io_tree, 0, 1351 1353 i_size_read(inode) - 1, &cached_state);
+14 -15
fs/btrfs/inode.c
··· 1610 1610 goto out_check; 1611 1611 ret = btrfs_cross_ref_exist(root, ino, 1612 1612 found_key.offset - 1613 - extent_offset, disk_bytenr); 1613 + extent_offset, disk_bytenr, false); 1614 1614 if (ret) { 1615 1615 /* 1616 1616 * ret could be -EIO if the above fails to read ··· 2161 2161 u64 bio_offset) 2162 2162 { 2163 2163 struct inode *inode = private_data; 2164 - blk_status_t ret = 0; 2165 2164 2166 - ret = btrfs_csum_one_bio(BTRFS_I(inode), bio, 0, 0); 2167 - BUG_ON(ret); /* -ENOMEM */ 2168 - return 0; 2165 + return btrfs_csum_one_bio(BTRFS_I(inode), bio, 0, 0); 2169 2166 } 2170 2167 2171 2168 /* ··· 6950 6953 * @orig_start: (optional) Return the original file offset of the file extent 6951 6954 * @orig_len: (optional) Return the original on-disk length of the file extent 6952 6955 * @ram_bytes: (optional) Return the ram_bytes of the file extent 6956 + * @strict: if true, omit optimizations that might force us into unnecessary 6957 + * cow. e.g., don't trust generation number. 6953 6958 * 6954 6959 * This function will flush ordered extents in the range to ensure proper 6955 6960 * nocow checks for (nowait == false) case. ··· 6966 6967 */ 6967 6968 noinline int can_nocow_extent(struct inode *inode, u64 offset, u64 *len, 6968 6969 u64 *orig_start, u64 *orig_block_len, 6969 - u64 *ram_bytes) 6970 + u64 *ram_bytes, bool strict) 6970 6971 { 6971 6972 struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb); 6972 6973 struct btrfs_path *path; ··· 7044 7045 * Do the same check as in btrfs_cross_ref_exist but without the 7045 7046 * unnecessary search. 7046 7047 */ 7047 - if (btrfs_file_extent_generation(leaf, fi) <= 7048 - btrfs_root_last_snapshot(&root->root_item)) 7048 + if (!strict && 7049 + (btrfs_file_extent_generation(leaf, fi) <= 7050 + btrfs_root_last_snapshot(&root->root_item))) 7049 7051 goto out; 7050 7052 7051 7053 backref_offset = btrfs_file_extent_offset(leaf, fi); ··· 7082 7082 */ 7083 7083 7084 7084 ret = btrfs_cross_ref_exist(root, btrfs_ino(BTRFS_I(inode)), 7085 - key.offset - backref_offset, disk_bytenr); 7085 + key.offset - backref_offset, disk_bytenr, 7086 + strict); 7086 7087 if (ret) { 7087 7088 ret = 0; 7088 7089 goto out; ··· 7304 7303 block_start = em->block_start + (start - em->start); 7305 7304 7306 7305 if (can_nocow_extent(inode, start, &len, &orig_start, 7307 - &orig_block_len, &ram_bytes) == 1 && 7306 + &orig_block_len, &ram_bytes, false) == 1 && 7308 7307 btrfs_inc_nocow_writers(fs_info, block_start)) { 7309 7308 struct extent_map *em2; 7310 7309 ··· 7620 7619 struct bio *bio, u64 offset) 7621 7620 { 7622 7621 struct inode *inode = private_data; 7623 - blk_status_t ret; 7624 - ret = btrfs_csum_one_bio(BTRFS_I(inode), bio, offset, 1); 7625 - BUG_ON(ret); /* -ENOMEM */ 7626 - return 0; 7622 + 7623 + return btrfs_csum_one_bio(BTRFS_I(inode), bio, offset, 1); 7627 7624 } 7628 7625 7629 7626 static void btrfs_end_dio_bio(struct bio *bio) ··· 10135 10136 free_extent_map(em); 10136 10137 em = NULL; 10137 10138 10138 - ret = can_nocow_extent(inode, start, &len, NULL, NULL, NULL); 10139 + ret = can_nocow_extent(inode, start, &len, NULL, NULL, NULL, true); 10139 10140 if (ret < 0) { 10140 10141 goto out; 10141 10142 } else if (ret) {
+1
fs/btrfs/super.c
··· 625 625 } else if (strncmp(args[0].from, "lzo", 3) == 0) { 626 626 compress_type = "lzo"; 627 627 info->compress_type = BTRFS_COMPRESS_LZO; 628 + info->compress_level = 0; 628 629 btrfs_set_opt(info->mount_opt, COMPRESS); 629 630 btrfs_clear_opt(info->mount_opt, NODATACOW); 630 631 btrfs_clear_opt(info->mount_opt, NODATASUM);
+6 -4
fs/btrfs/tree-log.c
··· 3449 3449 btrfs_free_path(path); 3450 3450 out_unlock: 3451 3451 mutex_unlock(&dir->log_mutex); 3452 - if (ret == -ENOSPC) { 3452 + if (err == -ENOSPC) { 3453 3453 btrfs_set_log_full_commit(trans); 3454 - ret = 0; 3455 - } else if (ret < 0) 3456 - btrfs_abort_transaction(trans, ret); 3454 + err = 0; 3455 + } else if (err < 0 && err != -ENOENT) { 3456 + /* ENOENT can be returned if the entry hasn't been fsynced yet */ 3457 + btrfs_abort_transaction(trans, err); 3458 + } 3457 3459 3458 3460 btrfs_end_log_trans(root); 3459 3461