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

Merge branch 'for-linus-4.11' of git://git.kernel.org/pub/scm/linux/kernel/git/mason/linux-btrfs

Pull btrfs updates from Chris Mason:
"This has a series of fixes and cleanups that Dave Sterba has been
collecting.

There is a pretty big variety here, cleaning up internal APIs and
fixing corner cases"

* 'for-linus-4.11' of git://git.kernel.org/pub/scm/linux/kernel/git/mason/linux-btrfs: (124 commits)
Btrfs: use the correct type when creating cow dio extent
Btrfs: fix deadlock between dedup on same file and starting writeback
btrfs: use btrfs_debug instead of pr_debug in transaction abort
btrfs: btrfs_truncate_free_space_cache always allocates path
btrfs: free-space-cache, clean up unnecessary root arguments
btrfs: convert btrfs_inc_block_group_ro to accept fs_info
btrfs: flush_space always takes fs_info->fs_root
btrfs: pass fs_info to (more) routines that are only called with extent_root
btrfs: qgroup: Move half of the qgroup accounting time out of commit trans
btrfs: remove unused parameter from adjust_slots_upwards
btrfs: remove unused parameters from __btrfs_write_out_cache
btrfs: remove unused parameter from cleanup_write_cache_enospc
btrfs: remove unused parameter from __add_inode_ref
btrfs: remove unused parameter from clone_copy_inline_extent
btrfs: remove unused parameters from btrfs_cmp_data
btrfs: remove unused parameter from __add_inline_refs
btrfs: remove unused parameters from scrub_setup_wr_ctx
btrfs: remove unused parameter from create_snapshot
btrfs: remove unused parameter from init_first_rw_device
btrfs: remove unused parameter from __btrfs_alloc_chunk
...

+1212 -1243
+3 -4
fs/btrfs/backref.c
··· 956 956 /* 957 957 * add all inline backrefs for bytenr to the list 958 958 */ 959 - static int __add_inline_refs(struct btrfs_fs_info *fs_info, 960 - struct btrfs_path *path, u64 bytenr, 959 + static int __add_inline_refs(struct btrfs_path *path, u64 bytenr, 961 960 int *info_level, struct list_head *prefs, 962 961 struct ref_root *ref_tree, 963 962 u64 *total_refs, u64 inum) ··· 1283 1284 */ 1284 1285 delayed_refs = &trans->transaction->delayed_refs; 1285 1286 spin_lock(&delayed_refs->lock); 1286 - head = btrfs_find_delayed_ref_head(trans, bytenr); 1287 + head = btrfs_find_delayed_ref_head(delayed_refs, bytenr); 1287 1288 if (head) { 1288 1289 if (!mutex_trylock(&head->mutex)) { 1289 1290 atomic_inc(&head->node.refs); ··· 1353 1354 if (key.objectid == bytenr && 1354 1355 (key.type == BTRFS_EXTENT_ITEM_KEY || 1355 1356 key.type == BTRFS_METADATA_ITEM_KEY)) { 1356 - ret = __add_inline_refs(fs_info, path, bytenr, 1357 + ret = __add_inline_refs(path, bytenr, 1357 1358 &info_level, &prefs, 1358 1359 ref_tree, &total_refs, 1359 1360 inum);
+30 -14
fs/btrfs/btrfs_inode.h
··· 224 224 __insert_inode_hash(inode, h); 225 225 } 226 226 227 - static inline u64 btrfs_ino(struct inode *inode) 227 + static inline u64 btrfs_ino(struct btrfs_inode *inode) 228 228 { 229 - u64 ino = BTRFS_I(inode)->location.objectid; 229 + u64 ino = inode->location.objectid; 230 230 231 231 /* 232 232 * !ino: btree_inode 233 233 * type == BTRFS_ROOT_ITEM_KEY: subvol dir 234 234 */ 235 - if (!ino || BTRFS_I(inode)->location.type == BTRFS_ROOT_ITEM_KEY) 236 - ino = inode->i_ino; 235 + if (!ino || inode->location.type == BTRFS_ROOT_ITEM_KEY) 236 + ino = inode->vfs_inode.i_ino; 237 237 return ino; 238 238 } 239 239 ··· 248 248 struct btrfs_root *root = BTRFS_I(inode)->root; 249 249 250 250 if (root == root->fs_info->tree_root && 251 - btrfs_ino(inode) != BTRFS_BTREE_INODE_OBJECTID) 251 + btrfs_ino(BTRFS_I(inode)) != BTRFS_BTREE_INODE_OBJECTID) 252 252 return true; 253 253 if (BTRFS_I(inode)->location.objectid == BTRFS_FREE_INO_OBJECTID) 254 254 return true; 255 255 return false; 256 256 } 257 257 258 - static inline int btrfs_inode_in_log(struct inode *inode, u64 generation) 258 + static inline int btrfs_inode_in_log(struct btrfs_inode *inode, u64 generation) 259 259 { 260 260 int ret = 0; 261 261 262 - spin_lock(&BTRFS_I(inode)->lock); 263 - if (BTRFS_I(inode)->logged_trans == generation && 264 - BTRFS_I(inode)->last_sub_trans <= 265 - BTRFS_I(inode)->last_log_commit && 266 - BTRFS_I(inode)->last_sub_trans <= 267 - BTRFS_I(inode)->root->last_log_commit) { 262 + spin_lock(&inode->lock); 263 + if (inode->logged_trans == generation && 264 + inode->last_sub_trans <= inode->last_log_commit && 265 + inode->last_sub_trans <= inode->root->last_log_commit) { 268 266 /* 269 267 * After a ranged fsync we might have left some extent maps 270 268 * (that fall outside the fsync's range). So return false ··· 270 272 * will be called and process those extent maps. 271 273 */ 272 274 smp_mb(); 273 - if (list_empty(&BTRFS_I(inode)->extent_tree.modified_extents)) 275 + if (list_empty(&inode->extent_tree.modified_extents)) 274 276 ret = 1; 275 277 } 276 - spin_unlock(&BTRFS_I(inode)->lock); 278 + spin_unlock(&inode->lock); 277 279 return ret; 278 280 } 279 281 ··· 322 324 smp_mb__before_atomic(); 323 325 clear_bit(BTRFS_INODE_READDIO_NEED_LOCK, 324 326 &BTRFS_I(inode)->runtime_flags); 327 + } 328 + 329 + static inline void btrfs_print_data_csum_error(struct inode *inode, 330 + u64 logical_start, u32 csum, u32 csum_expected, int mirror_num) 331 + { 332 + struct btrfs_root *root = BTRFS_I(inode)->root; 333 + 334 + /* Output minus objectid, which is more meaningful */ 335 + if (root->objectid >= BTRFS_LAST_FREE_OBJECTID) 336 + btrfs_warn_rl(root->fs_info, 337 + "csum failed root %lld ino %lld off %llu csum 0x%08x expected csum 0x%08x mirror %d", 338 + root->objectid, btrfs_ino(BTRFS_I(inode)), 339 + logical_start, csum, csum_expected, mirror_num); 340 + else 341 + btrfs_warn_rl(root->fs_info, 342 + "csum failed root %llu ino %llu off %llu csum 0x%08x expected csum 0x%08x mirror %d", 343 + root->objectid, btrfs_ino(BTRFS_I(inode)), 344 + logical_start, csum, csum_expected, mirror_num); 325 345 } 326 346 327 347 bool btrfs_page_exists_in_range(struct inode *inode, loff_t start, loff_t end);
+2 -4
fs/btrfs/compression.c
··· 124 124 kunmap_atomic(kaddr); 125 125 126 126 if (csum != *cb_sum) { 127 - btrfs_info(BTRFS_I(inode)->root->fs_info, 128 - "csum failed ino %llu extent %llu csum %u wanted %u mirror %d", 129 - btrfs_ino(inode), disk_start, csum, *cb_sum, 130 - cb->mirror_num); 127 + btrfs_print_data_csum_error(inode, disk_start, csum, 128 + *cb_sum, cb->mirror_num); 131 129 ret = -EIO; 132 130 goto fail; 133 131 }
+62 -66
fs/btrfs/ctree.c
··· 28 28 29 29 static int split_node(struct btrfs_trans_handle *trans, struct btrfs_root 30 30 *root, struct btrfs_path *path, int level); 31 - static int split_leaf(struct btrfs_trans_handle *trans, struct btrfs_root 32 - *root, struct btrfs_key *ins_key, 33 - struct btrfs_path *path, int data_size, int extend); 31 + static int split_leaf(struct btrfs_trans_handle *trans, struct btrfs_root *root, 32 + const struct btrfs_key *ins_key, struct btrfs_path *path, 33 + int data_size, int extend); 34 34 static int push_node_left(struct btrfs_trans_handle *trans, 35 35 struct btrfs_fs_info *fs_info, 36 36 struct extent_buffer *dst, ··· 426 426 tm_root = &fs_info->tree_mod_log; 427 427 for (node = rb_first(tm_root); node; node = next) { 428 428 next = rb_next(node); 429 - tm = container_of(node, struct tree_mod_elem, node); 429 + tm = rb_entry(node, struct tree_mod_elem, node); 430 430 if (tm->seq > min_seq) 431 431 continue; 432 432 rb_erase(node, tm_root); ··· 460 460 tm_root = &fs_info->tree_mod_log; 461 461 new = &tm_root->rb_node; 462 462 while (*new) { 463 - cur = container_of(*new, struct tree_mod_elem, node); 463 + cur = rb_entry(*new, struct tree_mod_elem, node); 464 464 parent = *new; 465 465 if (cur->logical < tm->logical) 466 466 new = &((*new)->rb_left); ··· 746 746 tm_root = &fs_info->tree_mod_log; 747 747 node = tm_root->rb_node; 748 748 while (node) { 749 - cur = container_of(node, struct tree_mod_elem, node); 749 + cur = rb_entry(node, struct tree_mod_elem, node); 750 750 if (cur->logical < start) { 751 751 node = node->rb_left; 752 752 } else if (cur->logical > start) { ··· 1074 1074 ret = btrfs_dec_ref(trans, root, buf, 1); 1075 1075 BUG_ON(ret); /* -ENOMEM */ 1076 1076 } 1077 - clean_tree_block(trans, fs_info, buf); 1077 + clean_tree_block(fs_info, buf); 1078 1078 *last_ref = 1; 1079 1079 } 1080 1080 return 0; ··· 1326 1326 next = rb_next(&tm->node); 1327 1327 if (!next) 1328 1328 break; 1329 - tm = container_of(next, struct tree_mod_elem, node); 1329 + tm = rb_entry(next, struct tree_mod_elem, node); 1330 1330 if (tm->logical != first_tm->logical) 1331 1331 break; 1332 1332 } ··· 1580 1580 /* 1581 1581 * compare two keys in a memcmp fashion 1582 1582 */ 1583 - static int comp_keys(struct btrfs_disk_key *disk, struct btrfs_key *k2) 1583 + static int comp_keys(const struct btrfs_disk_key *disk, 1584 + const struct btrfs_key *k2) 1584 1585 { 1585 1586 struct btrfs_key k1; 1586 1587 ··· 1593 1592 /* 1594 1593 * same as comp_keys only with two btrfs_key's 1595 1594 */ 1596 - int btrfs_comp_cpu_keys(struct btrfs_key *k1, struct btrfs_key *k2) 1595 + int btrfs_comp_cpu_keys(const struct btrfs_key *k1, const struct btrfs_key *k2) 1597 1596 { 1598 1597 if (k1->objectid > k2->objectid) 1599 1598 return 1; ··· 1733 1732 * slot may point to max if the key is bigger than all of the keys 1734 1733 */ 1735 1734 static noinline int generic_bin_search(struct extent_buffer *eb, 1736 - unsigned long p, 1737 - int item_size, struct btrfs_key *key, 1735 + unsigned long p, int item_size, 1736 + const struct btrfs_key *key, 1738 1737 int max, int *slot) 1739 1738 { 1740 1739 int low = 0; ··· 1803 1802 * simple bin_search frontend that does the right thing for 1804 1803 * leaves vs nodes 1805 1804 */ 1806 - static int bin_search(struct extent_buffer *eb, struct btrfs_key *key, 1805 + static int bin_search(struct extent_buffer *eb, const struct btrfs_key *key, 1807 1806 int level, int *slot) 1808 1807 { 1809 1808 if (level == 0) ··· 1820 1819 slot); 1821 1820 } 1822 1821 1823 - int btrfs_bin_search(struct extent_buffer *eb, struct btrfs_key *key, 1822 + int btrfs_bin_search(struct extent_buffer *eb, const struct btrfs_key *key, 1824 1823 int level, int *slot) 1825 1824 { 1826 1825 return bin_search(eb, key, level, slot); ··· 1938 1937 1939 1938 path->locks[level] = 0; 1940 1939 path->nodes[level] = NULL; 1941 - clean_tree_block(trans, fs_info, mid); 1940 + clean_tree_block(fs_info, mid); 1942 1941 btrfs_tree_unlock(mid); 1943 1942 /* once for the path */ 1944 1943 free_extent_buffer(mid); ··· 1999 1998 if (wret < 0 && wret != -ENOSPC) 2000 1999 ret = wret; 2001 2000 if (btrfs_header_nritems(right) == 0) { 2002 - clean_tree_block(trans, fs_info, right); 2001 + clean_tree_block(fs_info, right); 2003 2002 btrfs_tree_unlock(right); 2004 2003 del_ptr(root, path, level + 1, pslot + 1); 2005 2004 root_sub_used(root, right->len); ··· 2043 2042 BUG_ON(wret == 1); 2044 2043 } 2045 2044 if (btrfs_header_nritems(mid) == 0) { 2046 - clean_tree_block(trans, fs_info, mid); 2045 + clean_tree_block(fs_info, mid); 2047 2046 btrfs_tree_unlock(mid); 2048 2047 del_ptr(root, path, level + 1, pslot); 2049 2048 root_sub_used(root, mid->len); ··· 2438 2437 * reada. -EAGAIN is returned and the search must be repeated. 2439 2438 */ 2440 2439 static int 2441 - read_block_for_search(struct btrfs_trans_handle *trans, 2442 - struct btrfs_root *root, struct btrfs_path *p, 2443 - struct extent_buffer **eb_ret, int level, int slot, 2444 - struct btrfs_key *key, u64 time_seq) 2440 + read_block_for_search(struct btrfs_root *root, struct btrfs_path *p, 2441 + struct extent_buffer **eb_ret, int level, int slot, 2442 + const struct btrfs_key *key) 2445 2443 { 2446 2444 struct btrfs_fs_info *fs_info = root->fs_info; 2447 2445 u64 blocknr; ··· 2587 2587 } 2588 2588 2589 2589 static void key_search_validate(struct extent_buffer *b, 2590 - struct btrfs_key *key, 2590 + const struct btrfs_key *key, 2591 2591 int level) 2592 2592 { 2593 2593 #ifdef CONFIG_BTRFS_ASSERT ··· 2606 2606 #endif 2607 2607 } 2608 2608 2609 - static int key_search(struct extent_buffer *b, struct btrfs_key *key, 2609 + static int key_search(struct extent_buffer *b, const struct btrfs_key *key, 2610 2610 int level, int *prev_cmp, int *slot) 2611 2611 { 2612 2612 if (*prev_cmp != 0) { ··· 2668 2668 * tree. if ins_len < 0, nodes will be merged as we walk down the tree (if 2669 2669 * possible) 2670 2670 */ 2671 - int btrfs_search_slot(struct btrfs_trans_handle *trans, struct btrfs_root 2672 - *root, struct btrfs_key *key, struct btrfs_path *p, int 2673 - ins_len, int cow) 2671 + int btrfs_search_slot(struct btrfs_trans_handle *trans, struct btrfs_root *root, 2672 + const struct btrfs_key *key, struct btrfs_path *p, 2673 + int ins_len, int cow) 2674 2674 { 2675 2675 struct btrfs_fs_info *fs_info = root->fs_info; 2676 2676 struct extent_buffer *b; ··· 2870 2870 goto done; 2871 2871 } 2872 2872 2873 - err = read_block_for_search(trans, root, p, 2874 - &b, level, slot, key, 0); 2873 + err = read_block_for_search(root, p, &b, level, 2874 + slot, key); 2875 2875 if (err == -EAGAIN) 2876 2876 goto again; 2877 2877 if (err) { ··· 2953 2953 * The resulting path and return value will be set up as if we called 2954 2954 * btrfs_search_slot at that point in time with ins_len and cow both set to 0. 2955 2955 */ 2956 - int btrfs_search_old_slot(struct btrfs_root *root, struct btrfs_key *key, 2956 + int btrfs_search_old_slot(struct btrfs_root *root, const struct btrfs_key *key, 2957 2957 struct btrfs_path *p, u64 time_seq) 2958 2958 { 2959 2959 struct btrfs_fs_info *fs_info = root->fs_info; ··· 3014 3014 goto done; 3015 3015 } 3016 3016 3017 - err = read_block_for_search(NULL, root, p, &b, level, 3018 - slot, key, time_seq); 3017 + err = read_block_for_search(root, p, &b, level, 3018 + slot, key); 3019 3019 if (err == -EAGAIN) 3020 3020 goto again; 3021 3021 if (err) { ··· 3067 3067 * < 0 on error 3068 3068 */ 3069 3069 int btrfs_search_slot_for_read(struct btrfs_root *root, 3070 - struct btrfs_key *key, struct btrfs_path *p, 3071 - int find_higher, int return_any) 3070 + const struct btrfs_key *key, 3071 + struct btrfs_path *p, int find_higher, 3072 + int return_any) 3072 3073 { 3073 3074 int ret; 3074 3075 struct extent_buffer *leaf; ··· 3167 3166 */ 3168 3167 void btrfs_set_item_key_safe(struct btrfs_fs_info *fs_info, 3169 3168 struct btrfs_path *path, 3170 - struct btrfs_key *new_key) 3169 + const struct btrfs_key *new_key) 3171 3170 { 3172 3171 struct btrfs_disk_key disk_key; 3173 3172 struct extent_buffer *eb; ··· 3595 3594 * min slot controls the lowest index we're willing to push to the 3596 3595 * right. We'll push up to and including min_slot, but no lower 3597 3596 */ 3598 - static noinline int __push_leaf_right(struct btrfs_trans_handle *trans, 3599 - struct btrfs_fs_info *fs_info, 3597 + static noinline int __push_leaf_right(struct btrfs_fs_info *fs_info, 3600 3598 struct btrfs_path *path, 3601 3599 int data_size, int empty, 3602 3600 struct extent_buffer *right, ··· 3704 3704 if (left_nritems) 3705 3705 btrfs_mark_buffer_dirty(left); 3706 3706 else 3707 - clean_tree_block(trans, fs_info, left); 3707 + clean_tree_block(fs_info, left); 3708 3708 3709 3709 btrfs_mark_buffer_dirty(right); 3710 3710 ··· 3716 3716 if (path->slots[0] >= left_nritems) { 3717 3717 path->slots[0] -= left_nritems; 3718 3718 if (btrfs_header_nritems(path->nodes[0]) == 0) 3719 - clean_tree_block(trans, fs_info, path->nodes[0]); 3719 + clean_tree_block(fs_info, path->nodes[0]); 3720 3720 btrfs_tree_unlock(path->nodes[0]); 3721 3721 free_extent_buffer(path->nodes[0]); 3722 3722 path->nodes[0] = right; ··· 3809 3809 return 0; 3810 3810 } 3811 3811 3812 - return __push_leaf_right(trans, fs_info, path, min_data_size, empty, 3812 + return __push_leaf_right(fs_info, path, min_data_size, empty, 3813 3813 right, free_space, left_nritems, min_slot); 3814 3814 out_unlock: 3815 3815 btrfs_tree_unlock(right); ··· 3825 3825 * item at 'max_slot' won't be touched. Use (u32)-1 to make us do all the 3826 3826 * items 3827 3827 */ 3828 - static noinline int __push_leaf_left(struct btrfs_trans_handle *trans, 3829 - struct btrfs_fs_info *fs_info, 3828 + static noinline int __push_leaf_left(struct btrfs_fs_info *fs_info, 3830 3829 struct btrfs_path *path, int data_size, 3831 3830 int empty, struct extent_buffer *left, 3832 3831 int free_space, u32 right_nritems, ··· 3944 3945 if (right_nritems) 3945 3946 btrfs_mark_buffer_dirty(right); 3946 3947 else 3947 - clean_tree_block(trans, fs_info, right); 3948 + clean_tree_block(fs_info, right); 3948 3949 3949 3950 btrfs_item_key(right, &disk_key, 0); 3950 3951 fixup_low_keys(fs_info, path, &disk_key, 1); ··· 4034 4035 goto out; 4035 4036 } 4036 4037 4037 - return __push_leaf_left(trans, fs_info, path, min_data_size, 4038 + return __push_leaf_left(fs_info, path, min_data_size, 4038 4039 empty, left, free_space, right_nritems, 4039 4040 max_slot); 4040 4041 out: ··· 4179 4180 */ 4180 4181 static noinline int split_leaf(struct btrfs_trans_handle *trans, 4181 4182 struct btrfs_root *root, 4182 - struct btrfs_key *ins_key, 4183 + const struct btrfs_key *ins_key, 4183 4184 struct btrfs_path *path, int data_size, 4184 4185 int extend) 4185 4186 { ··· 4411 4412 return ret; 4412 4413 } 4413 4414 4414 - static noinline int split_item(struct btrfs_trans_handle *trans, 4415 - struct btrfs_fs_info *fs_info, 4415 + static noinline int split_item(struct btrfs_fs_info *fs_info, 4416 4416 struct btrfs_path *path, 4417 - struct btrfs_key *new_key, 4417 + const struct btrfs_key *new_key, 4418 4418 unsigned long split_offset) 4419 4419 { 4420 4420 struct extent_buffer *leaf; ··· 4499 4501 int btrfs_split_item(struct btrfs_trans_handle *trans, 4500 4502 struct btrfs_root *root, 4501 4503 struct btrfs_path *path, 4502 - struct btrfs_key *new_key, 4504 + const struct btrfs_key *new_key, 4503 4505 unsigned long split_offset) 4504 4506 { 4505 4507 int ret; ··· 4508 4510 if (ret) 4509 4511 return ret; 4510 4512 4511 - ret = split_item(trans, root->fs_info, path, new_key, split_offset); 4513 + ret = split_item(root->fs_info, path, new_key, split_offset); 4512 4514 return ret; 4513 4515 } 4514 4516 ··· 4523 4525 int btrfs_duplicate_item(struct btrfs_trans_handle *trans, 4524 4526 struct btrfs_root *root, 4525 4527 struct btrfs_path *path, 4526 - struct btrfs_key *new_key) 4528 + const struct btrfs_key *new_key) 4527 4529 { 4528 4530 struct extent_buffer *leaf; 4529 4531 int ret; ··· 4724 4726 * that doesn't call btrfs_search_slot 4725 4727 */ 4726 4728 void setup_items_for_insert(struct btrfs_root *root, struct btrfs_path *path, 4727 - struct btrfs_key *cpu_key, u32 *data_size, 4729 + const struct btrfs_key *cpu_key, u32 *data_size, 4728 4730 u32 total_data, u32 total_size, int nr) 4729 4731 { 4730 4732 struct btrfs_fs_info *fs_info = root->fs_info; ··· 4818 4820 int btrfs_insert_empty_items(struct btrfs_trans_handle *trans, 4819 4821 struct btrfs_root *root, 4820 4822 struct btrfs_path *path, 4821 - struct btrfs_key *cpu_key, u32 *data_size, 4823 + const struct btrfs_key *cpu_key, u32 *data_size, 4822 4824 int nr) 4823 4825 { 4824 4826 int ret = 0; ··· 4849 4851 * Given a key and some data, insert an item into the tree. 4850 4852 * This does all the path init required, making room in the tree if needed. 4851 4853 */ 4852 - int btrfs_insert_item(struct btrfs_trans_handle *trans, struct btrfs_root 4853 - *root, struct btrfs_key *cpu_key, void *data, u32 4854 - data_size) 4854 + int btrfs_insert_item(struct btrfs_trans_handle *trans, struct btrfs_root *root, 4855 + const struct btrfs_key *cpu_key, void *data, 4856 + u32 data_size) 4855 4857 { 4856 4858 int ret = 0; 4857 4859 struct btrfs_path *path; ··· 5006 5008 btrfs_set_header_level(leaf, 0); 5007 5009 } else { 5008 5010 btrfs_set_path_blocking(path); 5009 - clean_tree_block(trans, fs_info, leaf); 5011 + clean_tree_block(fs_info, leaf); 5010 5012 btrfs_del_leaf(trans, root, path, leaf); 5011 5013 } 5012 5014 } else { ··· 5241 5243 5242 5244 static int tree_move_down(struct btrfs_fs_info *fs_info, 5243 5245 struct btrfs_path *path, 5244 - int *level, int root_level) 5246 + int *level) 5245 5247 { 5246 5248 struct extent_buffer *eb; 5247 5249 ··· 5256 5258 return 0; 5257 5259 } 5258 5260 5259 - static int tree_move_next_or_upnext(struct btrfs_fs_info *fs_info, 5260 - struct btrfs_path *path, 5261 + static int tree_move_next_or_upnext(struct btrfs_path *path, 5261 5262 int *level, int root_level) 5262 5263 { 5263 5264 int ret = 0; ··· 5295 5298 int ret; 5296 5299 5297 5300 if (*level == 0 || !allow_down) { 5298 - ret = tree_move_next_or_upnext(fs_info, path, level, 5299 - root_level); 5301 + ret = tree_move_next_or_upnext(path, level, root_level); 5300 5302 } else { 5301 - ret = tree_move_down(fs_info, path, level, root_level); 5303 + ret = tree_move_down(fs_info, path, level); 5302 5304 } 5303 5305 if (ret >= 0) { 5304 5306 if (*level == 0) ··· 5780 5784 5781 5785 next = c; 5782 5786 next_rw_lock = path->locks[level]; 5783 - ret = read_block_for_search(NULL, root, path, &next, level, 5784 - slot, &key, 0); 5787 + ret = read_block_for_search(root, path, &next, level, 5788 + slot, &key); 5785 5789 if (ret == -EAGAIN) 5786 5790 goto again; 5787 5791 ··· 5830 5834 if (!level) 5831 5835 break; 5832 5836 5833 - ret = read_block_for_search(NULL, root, path, &next, level, 5834 - 0, &key, 0); 5837 + ret = read_block_for_search(root, path, &next, level, 5838 + 0, &key); 5835 5839 if (ret == -EAGAIN) 5836 5840 goto again; 5837 5841
+46 -38
fs/btrfs/ctree.h
··· 97 97 98 98 #define BTRFS_MAX_EXTENT_SIZE SZ_128M 99 99 100 + /* 101 + * Count how many BTRFS_MAX_EXTENT_SIZE cover the @size 102 + */ 103 + static inline u32 count_max_extents(u64 size) 104 + { 105 + return div_u64(size + BTRFS_MAX_EXTENT_SIZE - 1, BTRFS_MAX_EXTENT_SIZE); 106 + } 107 + 100 108 struct btrfs_mapping_tree { 101 109 struct extent_map_tree map_tree; 102 110 }; ··· 1961 1953 BTRFS_SETGET_STACK_FUNCS(disk_key_type, struct btrfs_disk_key, type, 8); 1962 1954 1963 1955 static inline void btrfs_disk_key_to_cpu(struct btrfs_key *cpu, 1964 - struct btrfs_disk_key *disk) 1956 + const struct btrfs_disk_key *disk) 1965 1957 { 1966 1958 cpu->offset = le64_to_cpu(disk->offset); 1967 1959 cpu->type = disk->type; ··· 1969 1961 } 1970 1962 1971 1963 static inline void btrfs_cpu_key_to_disk(struct btrfs_disk_key *disk, 1972 - struct btrfs_key *cpu) 1964 + const struct btrfs_key *cpu) 1973 1965 { 1974 1966 disk->offset = cpu_to_le64(cpu->offset); 1975 1967 disk->type = cpu->type; ··· 2001 1993 btrfs_disk_key_to_cpu(key, &disk_key); 2002 1994 } 2003 1995 2004 - 2005 - static inline u8 btrfs_key_type(struct btrfs_key *key) 1996 + static inline u8 btrfs_key_type(const struct btrfs_key *key) 2006 1997 { 2007 1998 return key->type; 2008 1999 } ··· 2584 2577 u64 bytenr, u64 num_bytes); 2585 2578 int btrfs_exclude_logged_extents(struct btrfs_fs_info *fs_info, 2586 2579 struct extent_buffer *eb); 2587 - int btrfs_cross_ref_exist(struct btrfs_trans_handle *trans, 2588 - struct btrfs_root *root, 2580 + int btrfs_cross_ref_exist(struct btrfs_root *root, 2589 2581 u64 objectid, u64 offset, u64 bytenr); 2590 2582 struct btrfs_block_group_cache *btrfs_lookup_block_group( 2591 2583 struct btrfs_fs_info *info, ··· 2593 2587 void btrfs_put_block_group(struct btrfs_block_group_cache *cache); 2594 2588 int get_block_group_index(struct btrfs_block_group_cache *cache); 2595 2589 struct extent_buffer *btrfs_alloc_tree_block(struct btrfs_trans_handle *trans, 2596 - struct btrfs_root *root, u64 parent, 2597 - u64 root_objectid, 2598 - struct btrfs_disk_key *key, int level, 2599 - u64 hint, u64 empty_size); 2590 + struct btrfs_root *root, 2591 + u64 parent, u64 root_objectid, 2592 + const struct btrfs_disk_key *key, 2593 + int level, u64 hint, 2594 + u64 empty_size); 2600 2595 void btrfs_free_tree_block(struct btrfs_trans_handle *trans, 2601 2596 struct btrfs_root *root, 2602 2597 struct extent_buffer *buf, ··· 2630 2623 u64 start, u64 len, int delalloc); 2631 2624 int btrfs_free_and_pin_reserved_extent(struct btrfs_fs_info *fs_info, 2632 2625 u64 start, u64 len); 2633 - void btrfs_prepare_extent_commit(struct btrfs_trans_handle *trans, 2634 - struct btrfs_fs_info *fs_info); 2626 + void btrfs_prepare_extent_commit(struct btrfs_fs_info *fs_info); 2635 2627 int btrfs_finish_extent_commit(struct btrfs_trans_handle *trans, 2636 2628 struct btrfs_fs_info *fs_info); 2637 2629 int btrfs_inc_extent_ref(struct btrfs_trans_handle *trans, ··· 2702 2696 int nitems, 2703 2697 u64 *qgroup_reserved, bool use_global_rsv); 2704 2698 void btrfs_subvolume_release_metadata(struct btrfs_fs_info *fs_info, 2705 - struct btrfs_block_rsv *rsv, 2706 - u64 qgroup_reserved); 2699 + struct btrfs_block_rsv *rsv); 2707 2700 int btrfs_delalloc_reserve_metadata(struct inode *inode, u64 num_bytes); 2708 2701 void btrfs_delalloc_release_metadata(struct inode *inode, u64 num_bytes); 2709 2702 int btrfs_delalloc_reserve_space(struct inode *inode, u64 start, u64 len); ··· 2729 2724 void btrfs_block_rsv_release(struct btrfs_fs_info *fs_info, 2730 2725 struct btrfs_block_rsv *block_rsv, 2731 2726 u64 num_bytes); 2732 - int btrfs_inc_block_group_ro(struct btrfs_root *root, 2727 + int btrfs_inc_block_group_ro(struct btrfs_fs_info *fs_info, 2733 2728 struct btrfs_block_group_cache *cache); 2734 2729 void btrfs_dec_block_group_ro(struct btrfs_block_group_cache *cache); 2735 2730 void btrfs_put_block_group_cache(struct btrfs_fs_info *info); ··· 2755 2750 struct btrfs_fs_info *info, u64 start, u64 end); 2756 2751 2757 2752 /* ctree.c */ 2758 - int btrfs_bin_search(struct extent_buffer *eb, struct btrfs_key *key, 2753 + int btrfs_bin_search(struct extent_buffer *eb, const struct btrfs_key *key, 2759 2754 int level, int *slot); 2760 - int btrfs_comp_cpu_keys(struct btrfs_key *k1, struct btrfs_key *k2); 2755 + int btrfs_comp_cpu_keys(const struct btrfs_key *k1, const struct btrfs_key *k2); 2761 2756 int btrfs_previous_item(struct btrfs_root *root, 2762 2757 struct btrfs_path *path, u64 min_objectid, 2763 2758 int type); ··· 2765 2760 struct btrfs_path *path, u64 min_objectid); 2766 2761 void btrfs_set_item_key_safe(struct btrfs_fs_info *fs_info, 2767 2762 struct btrfs_path *path, 2768 - struct btrfs_key *new_key); 2763 + const struct btrfs_key *new_key); 2769 2764 struct extent_buffer *btrfs_root_node(struct btrfs_root *root); 2770 2765 struct extent_buffer *btrfs_lock_root_node(struct btrfs_root *root); 2771 2766 int btrfs_find_next_key(struct btrfs_root *root, struct btrfs_path *path, ··· 2807 2802 int btrfs_split_item(struct btrfs_trans_handle *trans, 2808 2803 struct btrfs_root *root, 2809 2804 struct btrfs_path *path, 2810 - struct btrfs_key *new_key, 2805 + const struct btrfs_key *new_key, 2811 2806 unsigned long split_offset); 2812 2807 int btrfs_duplicate_item(struct btrfs_trans_handle *trans, 2813 2808 struct btrfs_root *root, 2814 2809 struct btrfs_path *path, 2815 - struct btrfs_key *new_key); 2810 + const struct btrfs_key *new_key); 2816 2811 int btrfs_find_item(struct btrfs_root *fs_root, struct btrfs_path *path, 2817 2812 u64 inum, u64 ioff, u8 key_type, struct btrfs_key *found_key); 2818 - int btrfs_search_slot(struct btrfs_trans_handle *trans, struct btrfs_root 2819 - *root, struct btrfs_key *key, struct btrfs_path *p, int 2820 - ins_len, int cow); 2821 - int btrfs_search_old_slot(struct btrfs_root *root, struct btrfs_key *key, 2813 + int btrfs_search_slot(struct btrfs_trans_handle *trans, struct btrfs_root *root, 2814 + const struct btrfs_key *key, struct btrfs_path *p, 2815 + int ins_len, int cow); 2816 + int btrfs_search_old_slot(struct btrfs_root *root, const struct btrfs_key *key, 2822 2817 struct btrfs_path *p, u64 time_seq); 2823 2818 int btrfs_search_slot_for_read(struct btrfs_root *root, 2824 - struct btrfs_key *key, struct btrfs_path *p, 2825 - int find_higher, int return_any); 2819 + const struct btrfs_key *key, 2820 + struct btrfs_path *p, int find_higher, 2821 + int return_any); 2826 2822 int btrfs_realloc_node(struct btrfs_trans_handle *trans, 2827 2823 struct btrfs_root *root, struct extent_buffer *parent, 2828 2824 int start_slot, u64 *last_ret, ··· 2846 2840 } 2847 2841 2848 2842 void setup_items_for_insert(struct btrfs_root *root, struct btrfs_path *path, 2849 - struct btrfs_key *cpu_key, u32 *data_size, 2843 + const struct btrfs_key *cpu_key, u32 *data_size, 2850 2844 u32 total_data, u32 total_size, int nr); 2851 - int btrfs_insert_item(struct btrfs_trans_handle *trans, struct btrfs_root 2852 - *root, struct btrfs_key *key, void *data, u32 data_size); 2845 + int btrfs_insert_item(struct btrfs_trans_handle *trans, struct btrfs_root *root, 2846 + const struct btrfs_key *key, void *data, u32 data_size); 2853 2847 int btrfs_insert_empty_items(struct btrfs_trans_handle *trans, 2854 2848 struct btrfs_root *root, 2855 2849 struct btrfs_path *path, 2856 - struct btrfs_key *cpu_key, u32 *data_size, int nr); 2850 + const struct btrfs_key *cpu_key, u32 *data_size, 2851 + int nr); 2857 2852 2858 2853 static inline int btrfs_insert_empty_item(struct btrfs_trans_handle *trans, 2859 2854 struct btrfs_root *root, 2860 2855 struct btrfs_path *path, 2861 - struct btrfs_key *key, 2856 + const struct btrfs_key *key, 2862 2857 u32 data_size) 2863 2858 { 2864 2859 return btrfs_insert_empty_items(trans, root, path, key, &data_size, 1); ··· 2948 2941 u64 root_id, u64 ref_id, u64 dirid, u64 *sequence, 2949 2942 const char *name, int name_len); 2950 2943 int btrfs_del_root(struct btrfs_trans_handle *trans, struct btrfs_root *root, 2951 - struct btrfs_key *key); 2952 - int btrfs_insert_root(struct btrfs_trans_handle *trans, struct btrfs_root 2953 - *root, struct btrfs_key *key, struct btrfs_root_item 2954 - *item); 2944 + const struct btrfs_key *key); 2945 + int btrfs_insert_root(struct btrfs_trans_handle *trans, struct btrfs_root *root, 2946 + const struct btrfs_key *key, 2947 + struct btrfs_root_item *item); 2955 2948 int __must_check btrfs_update_root(struct btrfs_trans_handle *trans, 2956 2949 struct btrfs_root *root, 2957 2950 struct btrfs_key *key, 2958 2951 struct btrfs_root_item *item); 2959 - int btrfs_find_root(struct btrfs_root *root, struct btrfs_key *search_key, 2952 + int btrfs_find_root(struct btrfs_root *root, const struct btrfs_key *search_key, 2960 2953 struct btrfs_path *path, struct btrfs_root_item *root_item, 2961 2954 struct btrfs_key *root_key); 2962 2955 int btrfs_find_orphan_roots(struct btrfs_fs_info *fs_info); ··· 3126 3119 int btrfs_set_inode_index(struct inode *dir, u64 *index); 3127 3120 int btrfs_unlink_inode(struct btrfs_trans_handle *trans, 3128 3121 struct btrfs_root *root, 3129 - struct inode *dir, struct inode *inode, 3122 + struct btrfs_inode *dir, struct btrfs_inode *inode, 3130 3123 const char *name, int name_len); 3131 3124 int btrfs_add_link(struct btrfs_trans_handle *trans, 3132 3125 struct inode *parent_inode, struct inode *inode, ··· 3454 3447 "BTRFS: Transaction aborted (error %d)\n", \ 3455 3448 (errno)); \ 3456 3449 } else { \ 3457 - pr_debug("BTRFS: Transaction aborted (error %d)\n", \ 3450 + btrfs_debug((trans)->fs_info, \ 3451 + "Transaction aborted (error %d)", \ 3458 3452 (errno)); \ 3459 3453 } \ 3460 3454 } \
+28 -29
fs/btrfs/delayed-inode.c
··· 72 72 return 0; 73 73 } 74 74 75 - static struct btrfs_delayed_node *btrfs_get_delayed_node(struct inode *inode) 75 + static struct btrfs_delayed_node *btrfs_get_delayed_node( 76 + struct btrfs_inode *btrfs_inode) 76 77 { 77 - struct btrfs_inode *btrfs_inode = BTRFS_I(inode); 78 78 struct btrfs_root *root = btrfs_inode->root; 79 - u64 ino = btrfs_ino(inode); 79 + u64 ino = btrfs_ino(btrfs_inode); 80 80 struct btrfs_delayed_node *node; 81 81 82 - node = ACCESS_ONCE(btrfs_inode->delayed_node); 82 + node = READ_ONCE(btrfs_inode->delayed_node); 83 83 if (node) { 84 84 atomic_inc(&node->refs); 85 85 return node; ··· 107 107 108 108 /* Will return either the node or PTR_ERR(-ENOMEM) */ 109 109 static struct btrfs_delayed_node *btrfs_get_or_create_delayed_node( 110 - struct inode *inode) 110 + struct btrfs_inode *btrfs_inode) 111 111 { 112 112 struct btrfs_delayed_node *node; 113 - struct btrfs_inode *btrfs_inode = BTRFS_I(inode); 114 113 struct btrfs_root *root = btrfs_inode->root; 115 - u64 ino = btrfs_ino(inode); 114 + u64 ino = btrfs_ino(btrfs_inode); 116 115 int ret; 117 116 118 117 again: 119 - node = btrfs_get_delayed_node(inode); 118 + node = btrfs_get_delayed_node(btrfs_inode); 120 119 if (node) 121 120 return node; 122 121 ··· 573 574 static int btrfs_delayed_inode_reserve_metadata( 574 575 struct btrfs_trans_handle *trans, 575 576 struct btrfs_root *root, 576 - struct inode *inode, 577 + struct btrfs_inode *inode, 577 578 struct btrfs_delayed_node *node) 578 579 { 579 580 struct btrfs_fs_info *fs_info = root->fs_info; ··· 602 603 * worth which is less likely to hurt us. 603 604 */ 604 605 if (src_rsv && src_rsv->type == BTRFS_BLOCK_RSV_DELALLOC) { 605 - spin_lock(&BTRFS_I(inode)->lock); 606 + spin_lock(&inode->lock); 606 607 if (test_and_clear_bit(BTRFS_INODE_DELALLOC_META_RESERVED, 607 - &BTRFS_I(inode)->runtime_flags)) 608 + &inode->runtime_flags)) 608 609 release = true; 609 610 else 610 611 src_rsv = NULL; 611 - spin_unlock(&BTRFS_I(inode)->lock); 612 + spin_unlock(&inode->lock); 612 613 } 613 614 614 615 /* ··· 1195 1196 } 1196 1197 1197 1198 int btrfs_commit_inode_delayed_items(struct btrfs_trans_handle *trans, 1198 - struct inode *inode) 1199 + struct btrfs_inode *inode) 1199 1200 { 1200 1201 struct btrfs_delayed_node *delayed_node = btrfs_get_delayed_node(inode); 1201 1202 struct btrfs_path *path; ··· 1232 1233 return ret; 1233 1234 } 1234 1235 1235 - int btrfs_commit_inode_delayed_inode(struct inode *inode) 1236 + int btrfs_commit_inode_delayed_inode(struct btrfs_inode *inode) 1236 1237 { 1237 - struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb); 1238 + struct btrfs_fs_info *fs_info = btrfs_sb(inode->vfs_inode.i_sb); 1238 1239 struct btrfs_trans_handle *trans; 1239 1240 struct btrfs_delayed_node *delayed_node = btrfs_get_delayed_node(inode); 1240 1241 struct btrfs_path *path; ··· 1287 1288 return ret; 1288 1289 } 1289 1290 1290 - void btrfs_remove_delayed_node(struct inode *inode) 1291 + void btrfs_remove_delayed_node(struct btrfs_inode *inode) 1291 1292 { 1292 1293 struct btrfs_delayed_node *delayed_node; 1293 1294 1294 - delayed_node = ACCESS_ONCE(BTRFS_I(inode)->delayed_node); 1295 + delayed_node = READ_ONCE(inode->delayed_node); 1295 1296 if (!delayed_node) 1296 1297 return; 1297 1298 1298 - BTRFS_I(inode)->delayed_node = NULL; 1299 + inode->delayed_node = NULL; 1299 1300 btrfs_release_delayed_node(delayed_node); 1300 1301 } 1301 1302 ··· 1433 1434 int btrfs_insert_delayed_dir_index(struct btrfs_trans_handle *trans, 1434 1435 struct btrfs_fs_info *fs_info, 1435 1436 const char *name, int name_len, 1436 - struct inode *dir, 1437 + struct btrfs_inode *dir, 1437 1438 struct btrfs_disk_key *disk_key, u8 type, 1438 1439 u64 index) 1439 1440 { ··· 1509 1510 1510 1511 int btrfs_delete_delayed_dir_index(struct btrfs_trans_handle *trans, 1511 1512 struct btrfs_fs_info *fs_info, 1512 - struct inode *dir, u64 index) 1513 + struct btrfs_inode *dir, u64 index) 1513 1514 { 1514 1515 struct btrfs_delayed_node *node; 1515 1516 struct btrfs_delayed_item *item; ··· 1557 1558 return ret; 1558 1559 } 1559 1560 1560 - int btrfs_inode_delayed_dir_index_count(struct inode *inode) 1561 + int btrfs_inode_delayed_dir_index_count(struct btrfs_inode *inode) 1561 1562 { 1562 1563 struct btrfs_delayed_node *delayed_node = btrfs_get_delayed_node(inode); 1563 1564 ··· 1574 1575 return -EINVAL; 1575 1576 } 1576 1577 1577 - BTRFS_I(inode)->index_cnt = delayed_node->index_cnt; 1578 + inode->index_cnt = delayed_node->index_cnt; 1578 1579 btrfs_release_delayed_node(delayed_node); 1579 1580 return 0; 1580 1581 } ··· 1586 1587 struct btrfs_delayed_node *delayed_node; 1587 1588 struct btrfs_delayed_item *item; 1588 1589 1589 - delayed_node = btrfs_get_delayed_node(inode); 1590 + delayed_node = btrfs_get_delayed_node(BTRFS_I(inode)); 1590 1591 if (!delayed_node) 1591 1592 return false; 1592 1593 ··· 1775 1776 struct btrfs_delayed_node *delayed_node; 1776 1777 struct btrfs_inode_item *inode_item; 1777 1778 1778 - delayed_node = btrfs_get_delayed_node(inode); 1779 + delayed_node = btrfs_get_delayed_node(BTRFS_I(inode)); 1779 1780 if (!delayed_node) 1780 1781 return -ENOENT; 1781 1782 ··· 1830 1831 struct btrfs_delayed_node *delayed_node; 1831 1832 int ret = 0; 1832 1833 1833 - delayed_node = btrfs_get_or_create_delayed_node(inode); 1834 + delayed_node = btrfs_get_or_create_delayed_node(BTRFS_I(inode)); 1834 1835 if (IS_ERR(delayed_node)) 1835 1836 return PTR_ERR(delayed_node); 1836 1837 ··· 1840 1841 goto release_node; 1841 1842 } 1842 1843 1843 - ret = btrfs_delayed_inode_reserve_metadata(trans, root, inode, 1844 + ret = btrfs_delayed_inode_reserve_metadata(trans, root, BTRFS_I(inode), 1844 1845 delayed_node); 1845 1846 if (ret) 1846 1847 goto release_node; ··· 1855 1856 return ret; 1856 1857 } 1857 1858 1858 - int btrfs_delayed_delete_inode_ref(struct inode *inode) 1859 + int btrfs_delayed_delete_inode_ref(struct btrfs_inode *inode) 1859 1860 { 1860 - struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb); 1861 + struct btrfs_fs_info *fs_info = btrfs_sb(inode->vfs_inode.i_sb); 1861 1862 struct btrfs_delayed_node *delayed_node; 1862 1863 1863 1864 /* ··· 1932 1933 mutex_unlock(&delayed_node->mutex); 1933 1934 } 1934 1935 1935 - void btrfs_kill_delayed_inode_items(struct inode *inode) 1936 + void btrfs_kill_delayed_inode_items(struct btrfs_inode *inode) 1936 1937 { 1937 1938 struct btrfs_delayed_node *delayed_node; 1938 1939
+8 -8
fs/btrfs/delayed-inode.h
··· 101 101 int btrfs_insert_delayed_dir_index(struct btrfs_trans_handle *trans, 102 102 struct btrfs_fs_info *fs_info, 103 103 const char *name, int name_len, 104 - struct inode *dir, 104 + struct btrfs_inode *dir, 105 105 struct btrfs_disk_key *disk_key, u8 type, 106 106 u64 index); 107 107 108 108 int btrfs_delete_delayed_dir_index(struct btrfs_trans_handle *trans, 109 109 struct btrfs_fs_info *fs_info, 110 - struct inode *dir, u64 index); 110 + struct btrfs_inode *dir, u64 index); 111 111 112 - int btrfs_inode_delayed_dir_index_count(struct inode *inode); 112 + int btrfs_inode_delayed_dir_index_count(struct btrfs_inode *inode); 113 113 114 114 int btrfs_run_delayed_items(struct btrfs_trans_handle *trans, 115 115 struct btrfs_fs_info *fs_info); ··· 119 119 void btrfs_balance_delayed_items(struct btrfs_fs_info *fs_info); 120 120 121 121 int btrfs_commit_inode_delayed_items(struct btrfs_trans_handle *trans, 122 - struct inode *inode); 122 + struct btrfs_inode *inode); 123 123 /* Used for evicting the inode. */ 124 - void btrfs_remove_delayed_node(struct inode *inode); 125 - void btrfs_kill_delayed_inode_items(struct inode *inode); 126 - int btrfs_commit_inode_delayed_inode(struct inode *inode); 124 + void btrfs_remove_delayed_node(struct btrfs_inode *inode); 125 + void btrfs_kill_delayed_inode_items(struct btrfs_inode *inode); 126 + int btrfs_commit_inode_delayed_inode(struct btrfs_inode *inode); 127 127 128 128 129 129 int btrfs_delayed_update_inode(struct btrfs_trans_handle *trans, 130 130 struct btrfs_root *root, struct inode *inode); 131 131 int btrfs_fill_inode(struct inode *inode, u32 *rdev); 132 - int btrfs_delayed_delete_inode_ref(struct inode *inode); 132 + int btrfs_delayed_delete_inode_ref(struct btrfs_inode *inode); 133 133 134 134 /* Used for drop dead root */ 135 135 void btrfs_kill_all_delayed_nodes(struct btrfs_root *root);
+19 -12
fs/btrfs/delayed-ref.c
··· 550 550 struct btrfs_delayed_ref_node *ref, 551 551 struct btrfs_qgroup_extent_record *qrecord, 552 552 u64 bytenr, u64 num_bytes, u64 ref_root, u64 reserved, 553 - int action, int is_data) 553 + int action, int is_data, int *qrecord_inserted_ret) 554 554 { 555 555 struct btrfs_delayed_ref_head *existing; 556 556 struct btrfs_delayed_ref_head *head_ref = NULL; 557 557 struct btrfs_delayed_ref_root *delayed_refs; 558 558 int count_mod = 1; 559 559 int must_insert_reserved = 0; 560 + int qrecord_inserted = 0; 560 561 561 562 /* If reserved is provided, it must be a data extent. */ 562 563 BUG_ON(!is_data && reserved); ··· 624 623 if(btrfs_qgroup_trace_extent_nolock(fs_info, 625 624 delayed_refs, qrecord)) 626 625 kfree(qrecord); 626 + else 627 + qrecord_inserted = 1; 627 628 } 628 629 629 630 spin_lock_init(&head_ref->lock); ··· 653 650 atomic_inc(&delayed_refs->num_entries); 654 651 trans->delayed_ref_updates++; 655 652 } 653 + if (qrecord_inserted_ret) 654 + *qrecord_inserted_ret = qrecord_inserted; 656 655 return head_ref; 657 656 } 658 657 ··· 784 779 struct btrfs_delayed_ref_head *head_ref; 785 780 struct btrfs_delayed_ref_root *delayed_refs; 786 781 struct btrfs_qgroup_extent_record *record = NULL; 782 + int qrecord_inserted; 787 783 788 784 BUG_ON(extent_op && extent_op->is_data); 789 785 ref = kmem_cache_alloc(btrfs_delayed_tree_ref_cachep, GFP_NOFS); ··· 812 806 * the spin lock 813 807 */ 814 808 head_ref = add_delayed_ref_head(fs_info, trans, &head_ref->node, record, 815 - bytenr, num_bytes, 0, 0, action, 0); 809 + bytenr, num_bytes, 0, 0, action, 0, 810 + &qrecord_inserted); 816 811 817 812 add_delayed_tree_ref(fs_info, trans, head_ref, &ref->node, bytenr, 818 813 num_bytes, parent, ref_root, level, action); 819 814 spin_unlock(&delayed_refs->lock); 820 815 816 + if (qrecord_inserted) 817 + return btrfs_qgroup_trace_extent_post(fs_info, record); 821 818 return 0; 822 819 823 820 free_head_ref: ··· 838 829 struct btrfs_trans_handle *trans, 839 830 u64 bytenr, u64 num_bytes, 840 831 u64 parent, u64 ref_root, 841 - u64 owner, u64 offset, u64 reserved, int action, 842 - struct btrfs_delayed_extent_op *extent_op) 832 + u64 owner, u64 offset, u64 reserved, int action) 843 833 { 844 834 struct btrfs_delayed_data_ref *ref; 845 835 struct btrfs_delayed_ref_head *head_ref; 846 836 struct btrfs_delayed_ref_root *delayed_refs; 847 837 struct btrfs_qgroup_extent_record *record = NULL; 838 + int qrecord_inserted; 848 839 849 - BUG_ON(extent_op && !extent_op->is_data); 850 840 ref = kmem_cache_alloc(btrfs_delayed_data_ref_cachep, GFP_NOFS); 851 841 if (!ref) 852 842 return -ENOMEM; ··· 867 859 } 868 860 } 869 861 870 - head_ref->extent_op = extent_op; 862 + head_ref->extent_op = NULL; 871 863 872 864 delayed_refs = &trans->transaction->delayed_refs; 873 865 spin_lock(&delayed_refs->lock); ··· 878 870 */ 879 871 head_ref = add_delayed_ref_head(fs_info, trans, &head_ref->node, record, 880 872 bytenr, num_bytes, ref_root, reserved, 881 - action, 1); 873 + action, 1, &qrecord_inserted); 882 874 883 875 add_delayed_data_ref(fs_info, trans, head_ref, &ref->node, bytenr, 884 876 num_bytes, parent, ref_root, owner, offset, 885 877 action); 886 878 spin_unlock(&delayed_refs->lock); 887 879 880 + if (qrecord_inserted) 881 + return btrfs_qgroup_trace_extent_post(fs_info, record); 888 882 return 0; 889 883 } 890 884 ··· 909 899 910 900 add_delayed_ref_head(fs_info, trans, &head_ref->node, NULL, bytenr, 911 901 num_bytes, 0, 0, BTRFS_UPDATE_DELAYED_HEAD, 912 - extent_op->is_data); 902 + extent_op->is_data, NULL); 913 903 914 904 spin_unlock(&delayed_refs->lock); 915 905 return 0; ··· 921 911 * the head node if any where found, or NULL if not. 922 912 */ 923 913 struct btrfs_delayed_ref_head * 924 - btrfs_find_delayed_ref_head(struct btrfs_trans_handle *trans, u64 bytenr) 914 + btrfs_find_delayed_ref_head(struct btrfs_delayed_ref_root *delayed_refs, u64 bytenr) 925 915 { 926 - struct btrfs_delayed_ref_root *delayed_refs; 927 - 928 - delayed_refs = &trans->transaction->delayed_refs; 929 916 return find_ref_head(&delayed_refs->href_root, bytenr, 0); 930 917 } 931 918
+3 -3
fs/btrfs/delayed-ref.h
··· 250 250 struct btrfs_trans_handle *trans, 251 251 u64 bytenr, u64 num_bytes, 252 252 u64 parent, u64 ref_root, 253 - u64 owner, u64 offset, u64 reserved, int action, 254 - struct btrfs_delayed_extent_op *extent_op); 253 + u64 owner, u64 offset, u64 reserved, int action); 255 254 int btrfs_add_delayed_extent_op(struct btrfs_fs_info *fs_info, 256 255 struct btrfs_trans_handle *trans, 257 256 u64 bytenr, u64 num_bytes, ··· 261 262 struct btrfs_delayed_ref_head *head); 262 263 263 264 struct btrfs_delayed_ref_head * 264 - btrfs_find_delayed_ref_head(struct btrfs_trans_handle *trans, u64 bytenr); 265 + btrfs_find_delayed_ref_head(struct btrfs_delayed_ref_root *delayed_refs, 266 + u64 bytenr); 265 267 int btrfs_delayed_ref_lock(struct btrfs_trans_handle *trans, 266 268 struct btrfs_delayed_ref_head *head); 267 269 static inline void btrfs_delayed_ref_unlock(struct btrfs_delayed_ref_head *head)
+2 -3
fs/btrfs/dir-item.c
··· 133 133 struct btrfs_disk_key disk_key; 134 134 u32 data_size; 135 135 136 - key.objectid = btrfs_ino(dir); 136 + key.objectid = btrfs_ino(BTRFS_I(dir)); 137 137 key.type = BTRFS_DIR_ITEM_KEY; 138 138 key.offset = btrfs_name_hash(name, name_len); 139 139 ··· 174 174 btrfs_release_path(path); 175 175 176 176 ret2 = btrfs_insert_delayed_dir_index(trans, root->fs_info, name, 177 - name_len, dir, &disk_key, type, 178 - index); 177 + name_len, BTRFS_I(dir), &disk_key, type, index); 179 178 out_free: 180 179 btrfs_free_path(path); 181 180 if (ret)
+10 -19
fs/btrfs/disk-io.c
··· 64 64 static const struct extent_io_ops btree_extent_io_ops; 65 65 static void end_workqueue_fn(struct btrfs_work *work); 66 66 static void free_fs_root(struct btrfs_root *root); 67 - static int btrfs_check_super_valid(struct btrfs_fs_info *fs_info, 68 - int read_only); 67 + static int btrfs_check_super_valid(struct btrfs_fs_info *fs_info); 69 68 static void btrfs_destroy_ordered_extents(struct btrfs_root *root); 70 69 static int btrfs_destroy_delayed_refs(struct btrfs_transaction *trans, 71 70 struct btrfs_fs_info *fs_info); ··· 1004 1005 return ret; 1005 1006 } 1006 1007 1007 - static int check_async_write(struct inode *inode, unsigned long bio_flags) 1008 + static int check_async_write(unsigned long bio_flags) 1008 1009 { 1009 1010 if (bio_flags & EXTENT_BIO_TREE_LOG) 1010 1011 return 0; ··· 1020 1021 u64 bio_offset) 1021 1022 { 1022 1023 struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb); 1023 - int async = check_async_write(inode, bio_flags); 1024 + int async = check_async_write(bio_flags); 1024 1025 int ret; 1025 1026 1026 1027 if (bio_op(bio) != REQ_OP_WRITE) { ··· 1247 1248 1248 1249 } 1249 1250 1250 - void clean_tree_block(struct btrfs_trans_handle *trans, 1251 - struct btrfs_fs_info *fs_info, 1251 + void clean_tree_block(struct btrfs_fs_info *fs_info, 1252 1252 struct extent_buffer *buf) 1253 1253 { 1254 1254 if (btrfs_header_generation(buf) == ··· 2800 2802 2801 2803 memcpy(fs_info->fsid, fs_info->super_copy->fsid, BTRFS_FSID_SIZE); 2802 2804 2803 - ret = btrfs_check_super_valid(fs_info, sb->s_flags & MS_RDONLY); 2805 + ret = btrfs_check_super_valid(fs_info); 2804 2806 if (ret) { 2805 2807 btrfs_err(fs_info, "superblock contains fatal errors"); 2806 2808 err = -EINVAL; ··· 3409 3411 */ 3410 3412 static int write_dev_supers(struct btrfs_device *device, 3411 3413 struct btrfs_super_block *sb, 3412 - int do_barriers, int wait, int max_mirrors) 3414 + int wait, int max_mirrors) 3413 3415 { 3414 3416 struct buffer_head *bh; 3415 3417 int i; ··· 3694 3696 return num_tolerated_disk_barrier_failures; 3695 3697 } 3696 3698 3697 - static int write_all_supers(struct btrfs_fs_info *fs_info, int max_mirrors) 3699 + int write_all_supers(struct btrfs_fs_info *fs_info, int max_mirrors) 3698 3700 { 3699 3701 struct list_head *head; 3700 3702 struct btrfs_device *dev; ··· 3751 3753 flags = btrfs_super_flags(sb); 3752 3754 btrfs_set_super_flags(sb, flags | BTRFS_HEADER_FLAG_WRITTEN); 3753 3755 3754 - ret = write_dev_supers(dev, sb, do_barriers, 0, max_mirrors); 3756 + ret = write_dev_supers(dev, sb, 0, max_mirrors); 3755 3757 if (ret) 3756 3758 total_errors++; 3757 3759 } ··· 3774 3776 if (!dev->in_fs_metadata || !dev->writeable) 3775 3777 continue; 3776 3778 3777 - ret = write_dev_supers(dev, sb, do_barriers, 1, max_mirrors); 3779 + ret = write_dev_supers(dev, sb, 1, max_mirrors); 3778 3780 if (ret) 3779 3781 total_errors++; 3780 3782 } ··· 3786 3788 return -EIO; 3787 3789 } 3788 3790 return 0; 3789 - } 3790 - 3791 - int write_ctree_super(struct btrfs_trans_handle *trans, 3792 - struct btrfs_fs_info *fs_info, int max_mirrors) 3793 - { 3794 - return write_all_supers(fs_info, max_mirrors); 3795 3791 } 3796 3792 3797 3793 /* Drop a fs root from the radix tree and free it. */ ··· 4114 4122 return btree_read_extent_buffer_pages(fs_info, buf, parent_transid); 4115 4123 } 4116 4124 4117 - static int btrfs_check_super_valid(struct btrfs_fs_info *fs_info, 4118 - int read_only) 4125 + static int btrfs_check_super_valid(struct btrfs_fs_info *fs_info) 4119 4126 { 4120 4127 struct btrfs_super_block *sb = fs_info->super_copy; 4121 4128 u64 nodesize = btrfs_super_nodesize(sb);
+2 -4
fs/btrfs/disk-io.h
··· 52 52 struct extent_buffer *btrfs_find_create_tree_block( 53 53 struct btrfs_fs_info *fs_info, 54 54 u64 bytenr); 55 - void clean_tree_block(struct btrfs_trans_handle *trans, 56 - struct btrfs_fs_info *fs_info, struct extent_buffer *buf); 55 + void clean_tree_block(struct btrfs_fs_info *fs_info, struct extent_buffer *buf); 57 56 int open_ctree(struct super_block *sb, 58 57 struct btrfs_fs_devices *fs_devices, 59 58 char *options); 60 59 void close_ctree(struct btrfs_fs_info *fs_info); 61 - int write_ctree_super(struct btrfs_trans_handle *trans, 62 - struct btrfs_fs_info *fs_info, int max_mirrors); 60 + int write_all_supers(struct btrfs_fs_info *fs_info, int max_mirrors); 63 61 struct buffer_head *btrfs_read_dev_super(struct block_device *bdev); 64 62 int btrfs_read_dev_one_super(struct block_device *bdev, int copy_num, 65 63 struct buffer_head **bh_ret);
+5 -8
fs/btrfs/export.c
··· 30 30 len = BTRFS_FID_SIZE_NON_CONNECTABLE; 31 31 type = FILEID_BTRFS_WITHOUT_PARENT; 32 32 33 - fid->objectid = btrfs_ino(inode); 33 + fid->objectid = btrfs_ino(BTRFS_I(inode)); 34 34 fid->root_objectid = BTRFS_I(inode)->root->objectid; 35 35 fid->gen = inode->i_generation; 36 36 ··· 166 166 if (!path) 167 167 return ERR_PTR(-ENOMEM); 168 168 169 - if (btrfs_ino(dir) == BTRFS_FIRST_FREE_OBJECTID) { 169 + if (btrfs_ino(BTRFS_I(dir)) == BTRFS_FIRST_FREE_OBJECTID) { 170 170 key.objectid = root->root_key.objectid; 171 171 key.type = BTRFS_ROOT_BACKREF_KEY; 172 172 key.offset = (u64)-1; 173 173 root = fs_info->tree_root; 174 174 } else { 175 - key.objectid = btrfs_ino(dir); 175 + key.objectid = btrfs_ino(BTRFS_I(dir)); 176 176 key.type = BTRFS_INODE_REF_KEY; 177 177 key.offset = (u64)-1; 178 178 } ··· 235 235 int ret; 236 236 u64 ino; 237 237 238 - if (!dir || !inode) 239 - return -EINVAL; 240 - 241 238 if (!S_ISDIR(dir->i_mode)) 242 239 return -EINVAL; 243 240 244 - ino = btrfs_ino(inode); 241 + ino = btrfs_ino(BTRFS_I(inode)); 245 242 246 243 path = btrfs_alloc_path(); 247 244 if (!path) ··· 252 255 root = fs_info->tree_root; 253 256 } else { 254 257 key.objectid = ino; 255 - key.offset = btrfs_ino(dir); 258 + key.offset = btrfs_ino(BTRFS_I(dir)); 256 259 key.type = BTRFS_INODE_REF_KEY; 257 260 } 258 261
+140 -142
fs/btrfs/extent-tree.c
··· 888 888 889 889 delayed_refs = &trans->transaction->delayed_refs; 890 890 spin_lock(&delayed_refs->lock); 891 - head = btrfs_find_delayed_ref_head(trans, bytenr); 891 + head = btrfs_find_delayed_ref_head(delayed_refs, bytenr); 892 892 if (head) { 893 893 if (!mutex_trylock(&head->mutex)) { 894 894 atomic_inc(&head->node.refs); ··· 1035 1035 1036 1036 #ifdef BTRFS_COMPAT_EXTENT_TREE_V0 1037 1037 static int convert_extent_item_v0(struct btrfs_trans_handle *trans, 1038 - struct btrfs_root *root, 1038 + struct btrfs_fs_info *fs_info, 1039 1039 struct btrfs_path *path, 1040 1040 u64 owner, u32 extra_size) 1041 1041 { 1042 + struct btrfs_root *root = fs_info->extent_root; 1042 1043 struct btrfs_extent_item *item; 1043 1044 struct btrfs_extent_item_v0 *ei0; 1044 1045 struct btrfs_extent_ref_v0 *ref0; ··· 1093 1092 return ret; 1094 1093 BUG_ON(ret); /* Corruption */ 1095 1094 1096 - btrfs_extend_item(root->fs_info, path, new_size); 1095 + btrfs_extend_item(fs_info, path, new_size); 1097 1096 1098 1097 leaf = path->nodes[0]; 1099 1098 item = btrfs_item_ptr(leaf, path->slots[0], struct btrfs_extent_item); ··· 1152 1151 } 1153 1152 1154 1153 static noinline int lookup_extent_data_ref(struct btrfs_trans_handle *trans, 1155 - struct btrfs_root *root, 1154 + struct btrfs_fs_info *fs_info, 1156 1155 struct btrfs_path *path, 1157 1156 u64 bytenr, u64 parent, 1158 1157 u64 root_objectid, 1159 1158 u64 owner, u64 offset) 1160 1159 { 1160 + struct btrfs_root *root = fs_info->extent_root; 1161 1161 struct btrfs_key key; 1162 1162 struct btrfs_extent_data_ref *ref; 1163 1163 struct extent_buffer *leaf; ··· 1240 1238 } 1241 1239 1242 1240 static noinline int insert_extent_data_ref(struct btrfs_trans_handle *trans, 1243 - struct btrfs_root *root, 1241 + struct btrfs_fs_info *fs_info, 1244 1242 struct btrfs_path *path, 1245 1243 u64 bytenr, u64 parent, 1246 1244 u64 root_objectid, u64 owner, 1247 1245 u64 offset, int refs_to_add) 1248 1246 { 1247 + struct btrfs_root *root = fs_info->extent_root; 1249 1248 struct btrfs_key key; 1250 1249 struct extent_buffer *leaf; 1251 1250 u32 size; ··· 1320 1317 } 1321 1318 1322 1319 static noinline int remove_extent_data_ref(struct btrfs_trans_handle *trans, 1323 - struct btrfs_root *root, 1320 + struct btrfs_fs_info *fs_info, 1324 1321 struct btrfs_path *path, 1325 1322 int refs_to_drop, int *last_ref) 1326 1323 { ··· 1357 1354 num_refs -= refs_to_drop; 1358 1355 1359 1356 if (num_refs == 0) { 1360 - ret = btrfs_del_item(trans, root, path); 1357 + ret = btrfs_del_item(trans, fs_info->extent_root, path); 1361 1358 *last_ref = 1; 1362 1359 } else { 1363 1360 if (key.type == BTRFS_EXTENT_DATA_REF_KEY) ··· 1419 1416 } 1420 1417 1421 1418 static noinline int lookup_tree_block_ref(struct btrfs_trans_handle *trans, 1422 - struct btrfs_root *root, 1419 + struct btrfs_fs_info *fs_info, 1423 1420 struct btrfs_path *path, 1424 1421 u64 bytenr, u64 parent, 1425 1422 u64 root_objectid) 1426 1423 { 1424 + struct btrfs_root *root = fs_info->extent_root; 1427 1425 struct btrfs_key key; 1428 1426 int ret; 1429 1427 ··· 1453 1449 } 1454 1450 1455 1451 static noinline int insert_tree_block_ref(struct btrfs_trans_handle *trans, 1456 - struct btrfs_root *root, 1452 + struct btrfs_fs_info *fs_info, 1457 1453 struct btrfs_path *path, 1458 1454 u64 bytenr, u64 parent, 1459 1455 u64 root_objectid) ··· 1470 1466 key.offset = root_objectid; 1471 1467 } 1472 1468 1473 - ret = btrfs_insert_empty_item(trans, root, path, &key, 0); 1469 + ret = btrfs_insert_empty_item(trans, fs_info->extent_root, 1470 + path, &key, 0); 1474 1471 btrfs_release_path(path); 1475 1472 return ret; 1476 1473 } ··· 1529 1524 */ 1530 1525 static noinline_for_stack 1531 1526 int lookup_inline_extent_backref(struct btrfs_trans_handle *trans, 1532 - struct btrfs_root *root, 1527 + struct btrfs_fs_info *fs_info, 1533 1528 struct btrfs_path *path, 1534 1529 struct btrfs_extent_inline_ref **ref_ret, 1535 1530 u64 bytenr, u64 num_bytes, 1536 1531 u64 parent, u64 root_objectid, 1537 1532 u64 owner, u64 offset, int insert) 1538 1533 { 1539 - struct btrfs_fs_info *fs_info = root->fs_info; 1534 + struct btrfs_root *root = fs_info->extent_root; 1540 1535 struct btrfs_key key; 1541 1536 struct extent_buffer *leaf; 1542 1537 struct btrfs_extent_item *ei; ··· 1619 1614 err = -ENOENT; 1620 1615 goto out; 1621 1616 } 1622 - ret = convert_extent_item_v0(trans, root, path, owner, 1617 + ret = convert_extent_item_v0(trans, fs_info, path, owner, 1623 1618 extra_size); 1624 1619 if (ret < 0) { 1625 1620 err = ret; ··· 1721 1716 * helper to add new inline back ref 1722 1717 */ 1723 1718 static noinline_for_stack 1724 - void setup_inline_extent_backref(struct btrfs_root *root, 1719 + void setup_inline_extent_backref(struct btrfs_fs_info *fs_info, 1725 1720 struct btrfs_path *path, 1726 1721 struct btrfs_extent_inline_ref *iref, 1727 1722 u64 parent, u64 root_objectid, ··· 1744 1739 type = extent_ref_type(parent, owner); 1745 1740 size = btrfs_extent_inline_ref_size(type); 1746 1741 1747 - btrfs_extend_item(root->fs_info, path, size); 1742 + btrfs_extend_item(fs_info, path, size); 1748 1743 1749 1744 ei = btrfs_item_ptr(leaf, path->slots[0], struct btrfs_extent_item); 1750 1745 refs = btrfs_extent_refs(leaf, ei); ··· 1782 1777 } 1783 1778 1784 1779 static int lookup_extent_backref(struct btrfs_trans_handle *trans, 1785 - struct btrfs_root *root, 1780 + struct btrfs_fs_info *fs_info, 1786 1781 struct btrfs_path *path, 1787 1782 struct btrfs_extent_inline_ref **ref_ret, 1788 1783 u64 bytenr, u64 num_bytes, u64 parent, ··· 1790 1785 { 1791 1786 int ret; 1792 1787 1793 - ret = lookup_inline_extent_backref(trans, root, path, ref_ret, 1788 + ret = lookup_inline_extent_backref(trans, fs_info, path, ref_ret, 1794 1789 bytenr, num_bytes, parent, 1795 1790 root_objectid, owner, offset, 0); 1796 1791 if (ret != -ENOENT) ··· 1800 1795 *ref_ret = NULL; 1801 1796 1802 1797 if (owner < BTRFS_FIRST_FREE_OBJECTID) { 1803 - ret = lookup_tree_block_ref(trans, root, path, bytenr, parent, 1804 - root_objectid); 1798 + ret = lookup_tree_block_ref(trans, fs_info, path, bytenr, 1799 + parent, root_objectid); 1805 1800 } else { 1806 - ret = lookup_extent_data_ref(trans, root, path, bytenr, parent, 1807 - root_objectid, owner, offset); 1801 + ret = lookup_extent_data_ref(trans, fs_info, path, bytenr, 1802 + parent, root_objectid, owner, 1803 + offset); 1808 1804 } 1809 1805 return ret; 1810 1806 } ··· 1814 1808 * helper to update/remove inline back ref 1815 1809 */ 1816 1810 static noinline_for_stack 1817 - void update_inline_extent_backref(struct btrfs_root *root, 1811 + void update_inline_extent_backref(struct btrfs_fs_info *fs_info, 1818 1812 struct btrfs_path *path, 1819 1813 struct btrfs_extent_inline_ref *iref, 1820 1814 int refs_to_mod, ··· 1872 1866 memmove_extent_buffer(leaf, ptr, ptr + size, 1873 1867 end - ptr - size); 1874 1868 item_size -= size; 1875 - btrfs_truncate_item(root->fs_info, path, item_size, 1); 1869 + btrfs_truncate_item(fs_info, path, item_size, 1); 1876 1870 } 1877 1871 btrfs_mark_buffer_dirty(leaf); 1878 1872 } 1879 1873 1880 1874 static noinline_for_stack 1881 1875 int insert_inline_extent_backref(struct btrfs_trans_handle *trans, 1882 - struct btrfs_root *root, 1876 + struct btrfs_fs_info *fs_info, 1883 1877 struct btrfs_path *path, 1884 1878 u64 bytenr, u64 num_bytes, u64 parent, 1885 1879 u64 root_objectid, u64 owner, ··· 1889 1883 struct btrfs_extent_inline_ref *iref; 1890 1884 int ret; 1891 1885 1892 - ret = lookup_inline_extent_backref(trans, root, path, &iref, 1886 + ret = lookup_inline_extent_backref(trans, fs_info, path, &iref, 1893 1887 bytenr, num_bytes, parent, 1894 1888 root_objectid, owner, offset, 1); 1895 1889 if (ret == 0) { 1896 1890 BUG_ON(owner < BTRFS_FIRST_FREE_OBJECTID); 1897 - update_inline_extent_backref(root, path, iref, 1891 + update_inline_extent_backref(fs_info, path, iref, 1898 1892 refs_to_add, extent_op, NULL); 1899 1893 } else if (ret == -ENOENT) { 1900 - setup_inline_extent_backref(root, path, iref, parent, 1894 + setup_inline_extent_backref(fs_info, path, iref, parent, 1901 1895 root_objectid, owner, offset, 1902 1896 refs_to_add, extent_op); 1903 1897 ret = 0; ··· 1906 1900 } 1907 1901 1908 1902 static int insert_extent_backref(struct btrfs_trans_handle *trans, 1909 - struct btrfs_root *root, 1903 + struct btrfs_fs_info *fs_info, 1910 1904 struct btrfs_path *path, 1911 1905 u64 bytenr, u64 parent, u64 root_objectid, 1912 1906 u64 owner, u64 offset, int refs_to_add) ··· 1914 1908 int ret; 1915 1909 if (owner < BTRFS_FIRST_FREE_OBJECTID) { 1916 1910 BUG_ON(refs_to_add != 1); 1917 - ret = insert_tree_block_ref(trans, root, path, bytenr, 1911 + ret = insert_tree_block_ref(trans, fs_info, path, bytenr, 1918 1912 parent, root_objectid); 1919 1913 } else { 1920 - ret = insert_extent_data_ref(trans, root, path, bytenr, 1914 + ret = insert_extent_data_ref(trans, fs_info, path, bytenr, 1921 1915 parent, root_objectid, 1922 1916 owner, offset, refs_to_add); 1923 1917 } ··· 1925 1919 } 1926 1920 1927 1921 static int remove_extent_backref(struct btrfs_trans_handle *trans, 1928 - struct btrfs_root *root, 1922 + struct btrfs_fs_info *fs_info, 1929 1923 struct btrfs_path *path, 1930 1924 struct btrfs_extent_inline_ref *iref, 1931 1925 int refs_to_drop, int is_data, int *last_ref) ··· 1934 1928 1935 1929 BUG_ON(!is_data && refs_to_drop != 1); 1936 1930 if (iref) { 1937 - update_inline_extent_backref(root, path, iref, 1931 + update_inline_extent_backref(fs_info, path, iref, 1938 1932 -refs_to_drop, NULL, last_ref); 1939 1933 } else if (is_data) { 1940 - ret = remove_extent_data_ref(trans, root, path, refs_to_drop, 1934 + ret = remove_extent_data_ref(trans, fs_info, path, refs_to_drop, 1941 1935 last_ref); 1942 1936 } else { 1943 1937 *last_ref = 1; 1944 - ret = btrfs_del_item(trans, root, path); 1938 + ret = btrfs_del_item(trans, fs_info->extent_root, path); 1945 1939 } 1946 1940 return ret; 1947 1941 } ··· 2095 2089 ret = btrfs_add_delayed_data_ref(fs_info, trans, bytenr, 2096 2090 num_bytes, parent, root_objectid, 2097 2091 owner, offset, 0, 2098 - BTRFS_ADD_DELAYED_REF, NULL); 2092 + BTRFS_ADD_DELAYED_REF); 2099 2093 } 2100 2094 return ret; 2101 2095 } ··· 2123 2117 path->reada = READA_FORWARD; 2124 2118 path->leave_spinning = 1; 2125 2119 /* this will setup the path even if it fails to insert the back ref */ 2126 - ret = insert_inline_extent_backref(trans, fs_info->extent_root, path, 2127 - bytenr, num_bytes, parent, 2128 - root_objectid, owner, offset, 2120 + ret = insert_inline_extent_backref(trans, fs_info, path, bytenr, 2121 + num_bytes, parent, root_objectid, 2122 + owner, offset, 2129 2123 refs_to_add, extent_op); 2130 2124 if ((ret < 0 && ret != -EAGAIN) || !ret) 2131 2125 goto out; ··· 2149 2143 path->reada = READA_FORWARD; 2150 2144 path->leave_spinning = 1; 2151 2145 /* now insert the actual backref */ 2152 - ret = insert_extent_backref(trans, fs_info->extent_root, 2153 - path, bytenr, parent, root_objectid, 2154 - owner, offset, refs_to_add); 2146 + ret = insert_extent_backref(trans, fs_info, path, bytenr, parent, 2147 + root_objectid, owner, offset, refs_to_add); 2155 2148 if (ret) 2156 2149 btrfs_abort_transaction(trans, ret); 2157 2150 out: ··· 2295 2290 item_size = btrfs_item_size_nr(leaf, path->slots[0]); 2296 2291 #ifdef BTRFS_COMPAT_EXTENT_TREE_V0 2297 2292 if (item_size < sizeof(*ei)) { 2298 - ret = convert_extent_item_v0(trans, fs_info->extent_root, 2299 - path, (u64)-1, 0); 2293 + ret = convert_extent_item_v0(trans, fs_info, path, (u64)-1, 0); 2300 2294 if (ret < 0) { 2301 2295 err = ret; 2302 2296 goto out; ··· 3032 3028 return ret; 3033 3029 } 3034 3030 3035 - static noinline int check_delayed_ref(struct btrfs_trans_handle *trans, 3036 - struct btrfs_root *root, 3031 + static noinline int check_delayed_ref(struct btrfs_root *root, 3037 3032 struct btrfs_path *path, 3038 3033 u64 objectid, u64 offset, u64 bytenr) 3039 3034 { ··· 3040 3037 struct btrfs_delayed_ref_node *ref; 3041 3038 struct btrfs_delayed_data_ref *data_ref; 3042 3039 struct btrfs_delayed_ref_root *delayed_refs; 3040 + struct btrfs_transaction *cur_trans; 3043 3041 int ret = 0; 3044 3042 3045 - delayed_refs = &trans->transaction->delayed_refs; 3043 + cur_trans = root->fs_info->running_transaction; 3044 + if (!cur_trans) 3045 + return 0; 3046 + 3047 + delayed_refs = &cur_trans->delayed_refs; 3046 3048 spin_lock(&delayed_refs->lock); 3047 - head = btrfs_find_delayed_ref_head(trans, bytenr); 3049 + head = btrfs_find_delayed_ref_head(delayed_refs, bytenr); 3048 3050 if (!head) { 3049 3051 spin_unlock(&delayed_refs->lock); 3050 3052 return 0; ··· 3098 3090 return ret; 3099 3091 } 3100 3092 3101 - static noinline int check_committed_ref(struct btrfs_trans_handle *trans, 3102 - struct btrfs_root *root, 3093 + static noinline int check_committed_ref(struct btrfs_root *root, 3103 3094 struct btrfs_path *path, 3104 3095 u64 objectid, u64 offset, u64 bytenr) 3105 3096 { ··· 3169 3162 return ret; 3170 3163 } 3171 3164 3172 - int btrfs_cross_ref_exist(struct btrfs_trans_handle *trans, 3173 - struct btrfs_root *root, 3174 - u64 objectid, u64 offset, u64 bytenr) 3165 + int btrfs_cross_ref_exist(struct btrfs_root *root, u64 objectid, u64 offset, 3166 + u64 bytenr) 3175 3167 { 3176 3168 struct btrfs_path *path; 3177 3169 int ret; ··· 3181 3175 return -ENOENT; 3182 3176 3183 3177 do { 3184 - ret = check_committed_ref(trans, root, path, objectid, 3178 + ret = check_committed_ref(root, path, objectid, 3185 3179 offset, bytenr); 3186 3180 if (ret && ret != -ENOENT) 3187 3181 goto out; 3188 3182 3189 - ret2 = check_delayed_ref(trans, root, path, objectid, 3183 + ret2 = check_delayed_ref(root, path, objectid, 3190 3184 offset, bytenr); 3191 3185 } while (ret2 == -EAGAIN); 3192 3186 ··· 3374 3368 if (trans->aborted) 3375 3369 return 0; 3376 3370 again: 3377 - inode = lookup_free_space_inode(root, block_group, path); 3371 + inode = lookup_free_space_inode(fs_info, block_group, path); 3378 3372 if (IS_ERR(inode) && PTR_ERR(inode) != -ENOENT) { 3379 3373 ret = PTR_ERR(inode); 3380 3374 btrfs_release_path(path); ··· 3388 3382 if (block_group->ro) 3389 3383 goto out_free; 3390 3384 3391 - ret = create_free_space_inode(root, trans, block_group, path); 3385 + ret = create_free_space_inode(fs_info, trans, block_group, 3386 + path); 3392 3387 if (ret) 3393 3388 goto out_free; 3394 3389 goto again; ··· 3431 3424 if (ret) 3432 3425 goto out_put; 3433 3426 3434 - ret = btrfs_truncate_free_space_cache(root, trans, NULL, inode); 3427 + ret = btrfs_truncate_free_space_cache(trans, NULL, inode); 3435 3428 if (ret) 3436 3429 goto out_put; 3437 3430 } ··· 4126 4119 return ret; 4127 4120 } 4128 4121 4122 + static u64 btrfs_space_info_used(struct btrfs_space_info *s_info, 4123 + bool may_use_included) 4124 + { 4125 + ASSERT(s_info); 4126 + return s_info->bytes_used + s_info->bytes_reserved + 4127 + s_info->bytes_pinned + s_info->bytes_readonly + 4128 + (may_use_included ? s_info->bytes_may_use : 0); 4129 + } 4130 + 4129 4131 int btrfs_alloc_data_chunk_ondemand(struct inode *inode, u64 bytes) 4130 4132 { 4131 4133 struct btrfs_space_info *data_sinfo; ··· 4160 4144 again: 4161 4145 /* make sure we have enough space to handle the data first */ 4162 4146 spin_lock(&data_sinfo->lock); 4163 - used = data_sinfo->bytes_used + data_sinfo->bytes_reserved + 4164 - data_sinfo->bytes_pinned + data_sinfo->bytes_readonly + 4165 - data_sinfo->bytes_may_use; 4147 + used = btrfs_space_info_used(data_sinfo, true); 4166 4148 4167 4149 if (used + bytes > data_sinfo->total_bytes) { 4168 4150 struct btrfs_trans_handle *trans; ··· 4435 4421 4436 4422 info = __find_space_info(fs_info, BTRFS_BLOCK_GROUP_SYSTEM); 4437 4423 spin_lock(&info->lock); 4438 - left = info->total_bytes - info->bytes_used - info->bytes_pinned - 4439 - info->bytes_reserved - info->bytes_readonly - 4440 - info->bytes_may_use; 4424 + left = info->total_bytes - btrfs_space_info_used(info, true); 4441 4425 spin_unlock(&info->lock); 4442 4426 4443 4427 num_devs = get_profile_num_devs(fs_info, type); ··· 4618 4606 return 0; 4619 4607 4620 4608 profile = btrfs_get_alloc_profile(root, 0); 4621 - used = space_info->bytes_used + space_info->bytes_reserved + 4622 - space_info->bytes_pinned + space_info->bytes_readonly; 4609 + used = btrfs_space_info_used(space_info, false); 4623 4610 4624 4611 /* 4625 4612 * We only want to allow over committing if we have lots of actual space ··· 4798 4787 * get us somewhere and then commit the transaction if it does. Otherwise it 4799 4788 * will return -ENOSPC. 4800 4789 */ 4801 - static int may_commit_transaction(struct btrfs_root *root, 4790 + static int may_commit_transaction(struct btrfs_fs_info *fs_info, 4802 4791 struct btrfs_space_info *space_info, 4803 4792 u64 bytes, int force) 4804 4793 { 4805 - struct btrfs_fs_info *fs_info = root->fs_info; 4806 4794 struct btrfs_block_rsv *delayed_rsv = &fs_info->delayed_block_rsv; 4807 4795 struct btrfs_trans_handle *trans; 4808 4796 ··· 4833 4823 spin_unlock(&delayed_rsv->lock); 4834 4824 4835 4825 commit: 4836 - trans = btrfs_join_transaction(root); 4826 + trans = btrfs_join_transaction(fs_info->fs_root); 4837 4827 if (IS_ERR(trans)) 4838 4828 return -ENOSPC; 4839 4829 ··· 4847 4837 wait_queue_head_t wait; 4848 4838 }; 4849 4839 4850 - static int flush_space(struct btrfs_root *root, 4840 + static int flush_space(struct btrfs_fs_info *fs_info, 4851 4841 struct btrfs_space_info *space_info, u64 num_bytes, 4852 4842 u64 orig_bytes, int state) 4853 4843 { 4854 - struct btrfs_fs_info *fs_info = root->fs_info; 4844 + struct btrfs_root *root = fs_info->fs_root; 4855 4845 struct btrfs_trans_handle *trans; 4856 4846 int nr; 4857 4847 int ret = 0; ··· 4891 4881 ret = 0; 4892 4882 break; 4893 4883 case COMMIT_TRANS: 4894 - ret = may_commit_transaction(root, space_info, orig_bytes, 0); 4884 + ret = may_commit_transaction(fs_info, space_info, 4885 + orig_bytes, 0); 4895 4886 break; 4896 4887 default: 4897 4888 ret = -ENOSPC; ··· 5004 4993 struct reserve_ticket *ticket; 5005 4994 int ret; 5006 4995 5007 - ret = flush_space(fs_info->fs_root, space_info, to_reclaim, 5008 - to_reclaim, flush_state); 4996 + ret = flush_space(fs_info, space_info, to_reclaim, to_reclaim, 4997 + flush_state); 5009 4998 spin_lock(&space_info->lock); 5010 4999 if (list_empty(&space_info->tickets)) { 5011 5000 space_info->flush = 0; ··· 5060 5049 spin_unlock(&space_info->lock); 5061 5050 5062 5051 do { 5063 - flush_space(fs_info->fs_root, space_info, to_reclaim, 5064 - to_reclaim, flush_state); 5052 + flush_space(fs_info, space_info, to_reclaim, to_reclaim, 5053 + flush_state); 5065 5054 flush_state++; 5066 5055 spin_lock(&space_info->lock); 5067 5056 if (ticket->bytes == 0) { ··· 5146 5135 5147 5136 spin_lock(&space_info->lock); 5148 5137 ret = -ENOSPC; 5149 - used = space_info->bytes_used + space_info->bytes_reserved + 5150 - space_info->bytes_pinned + space_info->bytes_readonly + 5151 - space_info->bytes_may_use; 5138 + used = btrfs_space_info_used(space_info, true); 5152 5139 5153 5140 /* 5154 5141 * If we have enough space then hooray, make our reservation and carry ··· 5639 5630 block_rsv->size = min_t(u64, num_bytes, SZ_512M); 5640 5631 5641 5632 if (block_rsv->reserved < block_rsv->size) { 5642 - num_bytes = sinfo->bytes_used + sinfo->bytes_pinned + 5643 - sinfo->bytes_reserved + sinfo->bytes_readonly + 5644 - sinfo->bytes_may_use; 5633 + num_bytes = btrfs_space_info_used(sinfo, true); 5645 5634 if (sinfo->total_bytes > num_bytes) { 5646 5635 num_bytes = sinfo->total_bytes - num_bytes; 5647 5636 num_bytes = min(num_bytes, ··· 5763 5756 u64 num_bytes = btrfs_calc_trans_metadata_size(fs_info, 1); 5764 5757 5765 5758 trace_btrfs_space_reservation(fs_info, "orphan", 5766 - btrfs_ino(inode), num_bytes, 1); 5759 + btrfs_ino(BTRFS_I(inode)), num_bytes, 1); 5767 5760 return btrfs_block_rsv_migrate(src_rsv, dst_rsv, num_bytes, 1); 5768 5761 } 5769 5762 ··· 5774 5767 u64 num_bytes = btrfs_calc_trans_metadata_size(fs_info, 1); 5775 5768 5776 5769 trace_btrfs_space_reservation(fs_info, "orphan", 5777 - btrfs_ino(inode), num_bytes, 0); 5770 + btrfs_ino(BTRFS_I(inode)), num_bytes, 0); 5778 5771 btrfs_block_rsv_release(fs_info, root->orphan_block_rsv, num_bytes); 5779 5772 } 5780 5773 ··· 5806 5799 if (test_bit(BTRFS_FS_QUOTA_ENABLED, &fs_info->flags)) { 5807 5800 /* One for parent inode, two for dir entries */ 5808 5801 num_bytes = 3 * fs_info->nodesize; 5809 - ret = btrfs_qgroup_reserve_meta(root, num_bytes); 5802 + ret = btrfs_qgroup_reserve_meta(root, num_bytes, true); 5810 5803 if (ret) 5811 5804 return ret; 5812 5805 } else { ··· 5831 5824 } 5832 5825 5833 5826 void btrfs_subvolume_release_metadata(struct btrfs_fs_info *fs_info, 5834 - struct btrfs_block_rsv *rsv, 5835 - u64 qgroup_reserved) 5827 + struct btrfs_block_rsv *rsv) 5836 5828 { 5837 5829 btrfs_block_rsv_release(fs_info, rsv, (u64)-1); 5838 5830 } ··· 5850 5844 { 5851 5845 unsigned drop_inode_space = 0; 5852 5846 unsigned dropped_extents = 0; 5853 - unsigned num_extents = 0; 5847 + unsigned num_extents; 5854 5848 5855 - num_extents = (unsigned)div64_u64(num_bytes + 5856 - BTRFS_MAX_EXTENT_SIZE - 1, 5857 - BTRFS_MAX_EXTENT_SIZE); 5849 + num_extents = count_max_extents(num_bytes); 5858 5850 ASSERT(num_extents); 5859 5851 ASSERT(BTRFS_I(inode)->outstanding_extents >= num_extents); 5860 5852 BTRFS_I(inode)->outstanding_extents -= num_extents; ··· 5931 5927 struct btrfs_block_rsv *block_rsv = &fs_info->delalloc_block_rsv; 5932 5928 u64 to_reserve = 0; 5933 5929 u64 csum_bytes; 5934 - unsigned nr_extents = 0; 5930 + unsigned nr_extents; 5935 5931 enum btrfs_reserve_flush_enum flush = BTRFS_RESERVE_FLUSH_ALL; 5936 5932 int ret = 0; 5937 5933 bool delalloc_lock = true; ··· 5964 5960 num_bytes = ALIGN(num_bytes, fs_info->sectorsize); 5965 5961 5966 5962 spin_lock(&BTRFS_I(inode)->lock); 5967 - nr_extents = (unsigned)div64_u64(num_bytes + 5968 - BTRFS_MAX_EXTENT_SIZE - 1, 5969 - BTRFS_MAX_EXTENT_SIZE); 5963 + nr_extents = count_max_extents(num_bytes); 5970 5964 BTRFS_I(inode)->outstanding_extents += nr_extents; 5971 5965 5972 5966 nr_extents = 0; ··· 5981 5979 5982 5980 if (test_bit(BTRFS_FS_QUOTA_ENABLED, &fs_info->flags)) { 5983 5981 ret = btrfs_qgroup_reserve_meta(root, 5984 - nr_extents * fs_info->nodesize); 5982 + nr_extents * fs_info->nodesize, true); 5985 5983 if (ret) 5986 5984 goto out_fail; 5987 5985 } ··· 6007 6005 6008 6006 if (to_reserve) 6009 6007 trace_btrfs_space_reservation(fs_info, "delalloc", 6010 - btrfs_ino(inode), to_reserve, 1); 6008 + btrfs_ino(BTRFS_I(inode)), to_reserve, 1); 6011 6009 if (release_extra) 6012 6010 btrfs_block_rsv_release(fs_info, block_rsv, 6013 6011 btrfs_calc_trans_metadata_size(fs_info, 1)); ··· 6070 6068 if (to_free) { 6071 6069 btrfs_block_rsv_release(fs_info, block_rsv, to_free); 6072 6070 trace_btrfs_space_reservation(fs_info, "delalloc", 6073 - btrfs_ino(inode), to_free, 0); 6071 + btrfs_ino(BTRFS_I(inode)), to_free, 0); 6074 6072 } 6075 6073 if (delalloc_lock) 6076 6074 mutex_unlock(&BTRFS_I(inode)->delalloc_mutex); ··· 6106 6104 return; 6107 6105 6108 6106 trace_btrfs_space_reservation(fs_info, "delalloc", 6109 - btrfs_ino(inode), to_free, 0); 6107 + btrfs_ino(BTRFS_I(inode)), to_free, 0); 6110 6108 6111 6109 btrfs_block_rsv_release(fs_info, &fs_info->delalloc_block_rsv, to_free); 6112 6110 } ··· 6563 6561 spin_unlock(&space_info->lock); 6564 6562 return ret; 6565 6563 } 6566 - void btrfs_prepare_extent_commit(struct btrfs_trans_handle *trans, 6567 - struct btrfs_fs_info *fs_info) 6564 + void btrfs_prepare_extent_commit(struct btrfs_fs_info *fs_info) 6568 6565 { 6569 6566 struct btrfs_caching_control *next; 6570 6567 struct btrfs_caching_control *caching_ctl; ··· 6846 6845 if (is_data) 6847 6846 skinny_metadata = 0; 6848 6847 6849 - ret = lookup_extent_backref(trans, extent_root, path, &iref, 6848 + ret = lookup_extent_backref(trans, info, path, &iref, 6850 6849 bytenr, num_bytes, parent, 6851 6850 root_objectid, owner_objectid, 6852 6851 owner_offset); ··· 6878 6877 #endif 6879 6878 if (!found_extent) { 6880 6879 BUG_ON(iref); 6881 - ret = remove_extent_backref(trans, extent_root, path, 6882 - NULL, refs_to_drop, 6880 + ret = remove_extent_backref(trans, info, path, NULL, 6881 + refs_to_drop, 6883 6882 is_data, &last_ref); 6884 6883 if (ret) { 6885 6884 btrfs_abort_transaction(trans, ret); ··· 6954 6953 #ifdef BTRFS_COMPAT_EXTENT_TREE_V0 6955 6954 if (item_size < sizeof(*ei)) { 6956 6955 BUG_ON(found_extent || extent_slot != path->slots[0]); 6957 - ret = convert_extent_item_v0(trans, extent_root, path, 6958 - owner_objectid, 0); 6956 + ret = convert_extent_item_v0(trans, info, path, owner_objectid, 6957 + 0); 6959 6958 if (ret < 0) { 6960 6959 btrfs_abort_transaction(trans, ret); 6961 6960 goto out; ··· 7022 7021 btrfs_mark_buffer_dirty(leaf); 7023 7022 } 7024 7023 if (found_extent) { 7025 - ret = remove_extent_backref(trans, extent_root, path, 7024 + ret = remove_extent_backref(trans, info, path, 7026 7025 iref, refs_to_drop, 7027 7026 is_data, &last_ref); 7028 7027 if (ret) { ··· 7096 7095 7097 7096 delayed_refs = &trans->transaction->delayed_refs; 7098 7097 spin_lock(&delayed_refs->lock); 7099 - head = btrfs_find_delayed_ref_head(trans, bytenr); 7098 + head = btrfs_find_delayed_ref_head(delayed_refs, bytenr); 7100 7099 if (!head) 7101 7100 goto out_delayed_unlock; 7102 7101 ··· 7245 7244 num_bytes, 7246 7245 parent, root_objectid, owner, 7247 7246 offset, 0, 7248 - BTRFS_DROP_DELAYED_REF, NULL); 7247 + BTRFS_DROP_DELAYED_REF); 7249 7248 } 7250 7249 return ret; 7251 7250 } ··· 7420 7419 * If there is no suitable free space, we will record the max size of 7421 7420 * the free space extent currently. 7422 7421 */ 7423 - static noinline int find_free_extent(struct btrfs_root *orig_root, 7422 + static noinline int find_free_extent(struct btrfs_fs_info *fs_info, 7424 7423 u64 ram_bytes, u64 num_bytes, u64 empty_size, 7425 7424 u64 hint_byte, struct btrfs_key *ins, 7426 7425 u64 flags, int delalloc) 7427 7426 { 7428 - struct btrfs_fs_info *fs_info = orig_root->fs_info; 7429 7427 int ret = 0; 7430 7428 struct btrfs_root *root = fs_info->extent_root; 7431 7429 struct btrfs_free_cluster *last_ptr = NULL; ··· 7716 7716 last_ptr->fragmented = 1; 7717 7717 spin_unlock(&last_ptr->lock); 7718 7718 } 7719 - spin_lock(&block_group->free_space_ctl->tree_lock); 7720 - if (cached && 7721 - block_group->free_space_ctl->free_space < 7722 - num_bytes + empty_cluster + empty_size) { 7723 - if (block_group->free_space_ctl->free_space > 7724 - max_extent_size) 7725 - max_extent_size = 7726 - block_group->free_space_ctl->free_space; 7727 - spin_unlock(&block_group->free_space_ctl->tree_lock); 7728 - goto loop; 7719 + if (cached) { 7720 + struct btrfs_free_space_ctl *ctl = 7721 + block_group->free_space_ctl; 7722 + 7723 + spin_lock(&ctl->tree_lock); 7724 + if (ctl->free_space < 7725 + num_bytes + empty_cluster + empty_size) { 7726 + if (ctl->free_space > max_extent_size) 7727 + max_extent_size = ctl->free_space; 7728 + spin_unlock(&ctl->tree_lock); 7729 + goto loop; 7730 + } 7731 + spin_unlock(&ctl->tree_lock); 7729 7732 } 7730 - spin_unlock(&block_group->free_space_ctl->tree_lock); 7731 7733 7732 7734 offset = btrfs_find_space_for_alloc(block_group, search_start, 7733 7735 num_bytes, empty_size, ··· 7910 7908 spin_lock(&info->lock); 7911 7909 btrfs_info(fs_info, "space_info %llu has %llu free, is %sfull", 7912 7910 info->flags, 7913 - info->total_bytes - info->bytes_used - info->bytes_pinned - 7914 - info->bytes_reserved - info->bytes_readonly - 7915 - info->bytes_may_use, (info->full) ? "" : "not "); 7911 + info->total_bytes - btrfs_space_info_used(info, true), 7912 + info->full ? "" : "not "); 7916 7913 btrfs_info(fs_info, 7917 7914 "space_info total=%llu, used=%llu, pinned=%llu, reserved=%llu, may_use=%llu, readonly=%llu", 7918 7915 info->total_bytes, info->bytes_used, info->bytes_pinned, ··· 7952 7951 flags = btrfs_get_alloc_profile(root, is_data); 7953 7952 again: 7954 7953 WARN_ON(num_bytes < fs_info->sectorsize); 7955 - ret = find_free_extent(root, ram_bytes, num_bytes, empty_size, 7954 + ret = find_free_extent(fs_info, ram_bytes, num_bytes, empty_size, 7956 7955 hint_byte, ins, flags, delalloc); 7957 7956 if (!ret && !is_data) { 7958 7957 btrfs_dec_block_group_reservations(fs_info, ins->objectid); ··· 8195 8194 ret = btrfs_add_delayed_data_ref(fs_info, trans, ins->objectid, 8196 8195 ins->offset, 0, 8197 8196 root_objectid, owner, offset, 8198 - ram_bytes, BTRFS_ADD_DELAYED_EXTENT, 8199 - NULL); 8197 + ram_bytes, BTRFS_ADD_DELAYED_EXTENT); 8200 8198 return ret; 8201 8199 } 8202 8200 ··· 8256 8256 btrfs_set_header_generation(buf, trans->transid); 8257 8257 btrfs_set_buffer_lockdep_class(root->root_key.objectid, buf, level); 8258 8258 btrfs_tree_lock(buf); 8259 - clean_tree_block(trans, fs_info, buf); 8259 + clean_tree_block(fs_info, buf); 8260 8260 clear_bit(EXTENT_BUFFER_STALE, &buf->bflags); 8261 8261 8262 8262 btrfs_set_lock_blocking(buf); ··· 8351 8351 * returns the tree buffer or an ERR_PTR on error. 8352 8352 */ 8353 8353 struct extent_buffer *btrfs_alloc_tree_block(struct btrfs_trans_handle *trans, 8354 - struct btrfs_root *root, 8355 - u64 parent, u64 root_objectid, 8356 - struct btrfs_disk_key *key, int level, 8357 - u64 hint, u64 empty_size) 8354 + struct btrfs_root *root, 8355 + u64 parent, u64 root_objectid, 8356 + const struct btrfs_disk_key *key, 8357 + int level, u64 hint, 8358 + u64 empty_size) 8358 8359 { 8359 8360 struct btrfs_fs_info *fs_info = root->fs_info; 8360 8361 struct btrfs_key ins; ··· 8877 8876 btrfs_set_lock_blocking(eb); 8878 8877 path->locks[level] = BTRFS_WRITE_LOCK_BLOCKING; 8879 8878 } 8880 - clean_tree_block(trans, fs_info, eb); 8879 + clean_tree_block(fs_info, eb); 8881 8880 } 8882 8881 8883 8882 if (eb == root->node) { ··· 9347 9346 num_bytes = cache->key.offset - cache->reserved - cache->pinned - 9348 9347 cache->bytes_super - btrfs_block_group_used(&cache->item); 9349 9348 9350 - if (sinfo->bytes_used + sinfo->bytes_reserved + sinfo->bytes_pinned + 9351 - sinfo->bytes_may_use + sinfo->bytes_readonly + num_bytes + 9349 + if (btrfs_space_info_used(sinfo, true) + num_bytes + 9352 9350 min_allocable_bytes <= sinfo->total_bytes) { 9353 9351 sinfo->bytes_readonly += num_bytes; 9354 9352 cache->ro++; ··· 9360 9360 return ret; 9361 9361 } 9362 9362 9363 - int btrfs_inc_block_group_ro(struct btrfs_root *root, 9363 + int btrfs_inc_block_group_ro(struct btrfs_fs_info *fs_info, 9364 9364 struct btrfs_block_group_cache *cache) 9365 9365 9366 9366 { 9367 - struct btrfs_fs_info *fs_info = root->fs_info; 9368 9367 struct btrfs_trans_handle *trans; 9369 9368 u64 alloc_flags; 9370 9369 int ret; 9371 9370 9372 9371 again: 9373 - trans = btrfs_join_transaction(root); 9372 + trans = btrfs_join_transaction(fs_info->extent_root); 9374 9373 if (IS_ERR(trans)) 9375 9374 return PTR_ERR(trans); 9376 9375 ··· 9556 9557 * all of the extents from this block group. If we can, we're good 9557 9558 */ 9558 9559 if ((space_info->total_bytes != block_group->key.offset) && 9559 - (space_info->bytes_used + space_info->bytes_reserved + 9560 - space_info->bytes_pinned + space_info->bytes_readonly + 9561 - min_free < space_info->total_bytes)) { 9560 + (btrfs_space_info_used(space_info, false) + min_free < 9561 + space_info->total_bytes)) { 9562 9562 spin_unlock(&space_info->lock); 9563 9563 goto out; 9564 9564 } ··· 10315 10317 * get the inode first so any iput calls done for the io_list 10316 10318 * aren't the final iput (no unlinks allowed now) 10317 10319 */ 10318 - inode = lookup_free_space_inode(tree_root, block_group, path); 10320 + inode = lookup_free_space_inode(fs_info, block_group, path); 10319 10321 10320 10322 mutex_lock(&trans->transaction->cache_write_mutex); 10321 10323 /*
+97 -116
fs/btrfs/extent_io.c
··· 98 98 if (end >= PAGE_SIZE && (end % 2) == 0 && end != isize - 1) { 99 99 btrfs_debug_rl(BTRFS_I(inode)->root->fs_info, 100 100 "%s: ino %llu isize %llu odd range [%llu,%llu]", 101 - caller, btrfs_ino(inode), isize, start, end); 101 + caller, btrfs_ino(BTRFS_I(inode)), isize, start, end); 102 102 } 103 103 } 104 104 #else ··· 144 144 if (!set && (state->state & bits) == 0) 145 145 return; 146 146 changeset->bytes_changed += state->end - state->start + 1; 147 - ret = ulist_add(changeset->range_changed, state->start, state->end, 147 + ret = ulist_add(&changeset->range_changed, state->start, state->end, 148 148 GFP_ATOMIC); 149 149 /* ENOMEM */ 150 150 BUG_ON(ret < 0); ··· 226 226 { 227 227 struct extent_state *state; 228 228 229 + /* 230 + * The given mask might be not appropriate for the slab allocator, 231 + * drop the unsupported bits 232 + */ 233 + mask &= ~(__GFP_DMA32|__GFP_HIGHMEM); 229 234 state = kmem_cache_alloc(extent_state_cache, mask); 230 235 if (!state) 231 236 return state; ··· 1554 1549 return found; 1555 1550 } 1556 1551 1552 + static int __process_pages_contig(struct address_space *mapping, 1553 + struct page *locked_page, 1554 + pgoff_t start_index, pgoff_t end_index, 1555 + unsigned long page_ops, pgoff_t *index_ret); 1556 + 1557 1557 static noinline void __unlock_for_delalloc(struct inode *inode, 1558 1558 struct page *locked_page, 1559 1559 u64 start, u64 end) 1560 1560 { 1561 - int ret; 1562 - struct page *pages[16]; 1563 1561 unsigned long index = start >> PAGE_SHIFT; 1564 1562 unsigned long end_index = end >> PAGE_SHIFT; 1565 - unsigned long nr_pages = end_index - index + 1; 1566 - int i; 1567 1563 1564 + ASSERT(locked_page); 1568 1565 if (index == locked_page->index && end_index == index) 1569 1566 return; 1570 1567 1571 - while (nr_pages > 0) { 1572 - ret = find_get_pages_contig(inode->i_mapping, index, 1573 - min_t(unsigned long, nr_pages, 1574 - ARRAY_SIZE(pages)), pages); 1575 - for (i = 0; i < ret; i++) { 1576 - if (pages[i] != locked_page) 1577 - unlock_page(pages[i]); 1578 - put_page(pages[i]); 1579 - } 1580 - nr_pages -= ret; 1581 - index += ret; 1582 - cond_resched(); 1583 - } 1568 + __process_pages_contig(inode->i_mapping, locked_page, index, end_index, 1569 + PAGE_UNLOCK, NULL); 1584 1570 } 1585 1571 1586 1572 static noinline int lock_delalloc_pages(struct inode *inode, ··· 1580 1584 u64 delalloc_end) 1581 1585 { 1582 1586 unsigned long index = delalloc_start >> PAGE_SHIFT; 1583 - unsigned long start_index = index; 1587 + unsigned long index_ret = index; 1584 1588 unsigned long end_index = delalloc_end >> PAGE_SHIFT; 1585 - unsigned long pages_locked = 0; 1586 - struct page *pages[16]; 1587 - unsigned long nrpages; 1588 1589 int ret; 1589 - int i; 1590 1590 1591 - /* the caller is responsible for locking the start index */ 1591 + ASSERT(locked_page); 1592 1592 if (index == locked_page->index && index == end_index) 1593 1593 return 0; 1594 1594 1595 - /* skip the page at the start index */ 1596 - nrpages = end_index - index + 1; 1597 - while (nrpages > 0) { 1598 - ret = find_get_pages_contig(inode->i_mapping, index, 1599 - min_t(unsigned long, 1600 - nrpages, ARRAY_SIZE(pages)), pages); 1601 - if (ret == 0) { 1602 - ret = -EAGAIN; 1603 - goto done; 1604 - } 1605 - /* now we have an array of pages, lock them all */ 1606 - for (i = 0; i < ret; i++) { 1607 - /* 1608 - * the caller is taking responsibility for 1609 - * locked_page 1610 - */ 1611 - if (pages[i] != locked_page) { 1612 - lock_page(pages[i]); 1613 - if (!PageDirty(pages[i]) || 1614 - pages[i]->mapping != inode->i_mapping) { 1615 - ret = -EAGAIN; 1616 - unlock_page(pages[i]); 1617 - put_page(pages[i]); 1618 - goto done; 1619 - } 1620 - } 1621 - put_page(pages[i]); 1622 - pages_locked++; 1623 - } 1624 - nrpages -= ret; 1625 - index += ret; 1626 - cond_resched(); 1627 - } 1628 - ret = 0; 1629 - done: 1630 - if (ret && pages_locked) { 1631 - __unlock_for_delalloc(inode, locked_page, 1632 - delalloc_start, 1633 - ((u64)(start_index + pages_locked - 1)) << 1634 - PAGE_SHIFT); 1635 - } 1595 + ret = __process_pages_contig(inode->i_mapping, locked_page, index, 1596 + end_index, PAGE_LOCK, &index_ret); 1597 + if (ret == -EAGAIN) 1598 + __unlock_for_delalloc(inode, locked_page, delalloc_start, 1599 + (u64)index_ret << PAGE_SHIFT); 1636 1600 return ret; 1637 1601 } 1638 1602 ··· 1682 1726 return found; 1683 1727 } 1684 1728 1685 - void extent_clear_unlock_delalloc(struct inode *inode, u64 start, u64 end, 1686 - u64 delalloc_end, struct page *locked_page, 1687 - unsigned clear_bits, 1688 - unsigned long page_ops) 1729 + static int __process_pages_contig(struct address_space *mapping, 1730 + struct page *locked_page, 1731 + pgoff_t start_index, pgoff_t end_index, 1732 + unsigned long page_ops, pgoff_t *index_ret) 1689 1733 { 1690 - struct extent_io_tree *tree = &BTRFS_I(inode)->io_tree; 1691 - int ret; 1734 + unsigned long nr_pages = end_index - start_index + 1; 1735 + unsigned long pages_locked = 0; 1736 + pgoff_t index = start_index; 1692 1737 struct page *pages[16]; 1693 - unsigned long index = start >> PAGE_SHIFT; 1694 - unsigned long end_index = end >> PAGE_SHIFT; 1695 - unsigned long nr_pages = end_index - index + 1; 1738 + unsigned ret; 1739 + int err = 0; 1696 1740 int i; 1697 1741 1698 - clear_extent_bit(tree, start, end, clear_bits, 1, 0, NULL, GFP_NOFS); 1699 - if (page_ops == 0) 1700 - return; 1742 + if (page_ops & PAGE_LOCK) { 1743 + ASSERT(page_ops == PAGE_LOCK); 1744 + ASSERT(index_ret && *index_ret == start_index); 1745 + } 1701 1746 1702 1747 if ((page_ops & PAGE_SET_ERROR) && nr_pages > 0) 1703 - mapping_set_error(inode->i_mapping, -EIO); 1748 + mapping_set_error(mapping, -EIO); 1704 1749 1705 1750 while (nr_pages > 0) { 1706 - ret = find_get_pages_contig(inode->i_mapping, index, 1751 + ret = find_get_pages_contig(mapping, index, 1707 1752 min_t(unsigned long, 1708 1753 nr_pages, ARRAY_SIZE(pages)), pages); 1709 - for (i = 0; i < ret; i++) { 1754 + if (ret == 0) { 1755 + /* 1756 + * Only if we're going to lock these pages, 1757 + * can we find nothing at @index. 1758 + */ 1759 + ASSERT(page_ops & PAGE_LOCK); 1760 + return ret; 1761 + } 1710 1762 1763 + for (i = 0; i < ret; i++) { 1711 1764 if (page_ops & PAGE_SET_PRIVATE2) 1712 1765 SetPagePrivate2(pages[i]); 1713 1766 1714 1767 if (pages[i] == locked_page) { 1715 1768 put_page(pages[i]); 1769 + pages_locked++; 1716 1770 continue; 1717 1771 } 1718 1772 if (page_ops & PAGE_CLEAR_DIRTY) ··· 1735 1769 end_page_writeback(pages[i]); 1736 1770 if (page_ops & PAGE_UNLOCK) 1737 1771 unlock_page(pages[i]); 1772 + if (page_ops & PAGE_LOCK) { 1773 + lock_page(pages[i]); 1774 + if (!PageDirty(pages[i]) || 1775 + pages[i]->mapping != mapping) { 1776 + unlock_page(pages[i]); 1777 + put_page(pages[i]); 1778 + err = -EAGAIN; 1779 + goto out; 1780 + } 1781 + } 1738 1782 put_page(pages[i]); 1783 + pages_locked++; 1739 1784 } 1740 1785 nr_pages -= ret; 1741 1786 index += ret; 1742 1787 cond_resched(); 1743 1788 } 1789 + out: 1790 + if (err && index_ret) 1791 + *index_ret = start_index + pages_locked - 1; 1792 + return err; 1793 + } 1794 + 1795 + void extent_clear_unlock_delalloc(struct inode *inode, u64 start, u64 end, 1796 + u64 delalloc_end, struct page *locked_page, 1797 + unsigned clear_bits, 1798 + unsigned long page_ops) 1799 + { 1800 + clear_extent_bit(&BTRFS_I(inode)->io_tree, start, end, clear_bits, 1, 0, 1801 + NULL, GFP_NOFS); 1802 + 1803 + __process_pages_contig(inode->i_mapping, locked_page, 1804 + start >> PAGE_SHIFT, end >> PAGE_SHIFT, 1805 + page_ops, NULL); 1744 1806 } 1745 1807 1746 1808 /* ··· 2054 2060 2055 2061 btrfs_info_rl_in_rcu(fs_info, 2056 2062 "read error corrected: ino %llu off %llu (dev %s sector %llu)", 2057 - btrfs_ino(inode), start, 2063 + btrfs_ino(BTRFS_I(inode)), start, 2058 2064 rcu_str_deref(dev->name), sector); 2059 2065 btrfs_bio_counter_dec(fs_info); 2060 2066 bio_put(bio); ··· 2759 2765 size_t size, unsigned long offset, 2760 2766 struct block_device *bdev, 2761 2767 struct bio **bio_ret, 2762 - unsigned long max_pages, 2763 2768 bio_end_io_t end_io_func, 2764 2769 int mirror_num, 2765 2770 unsigned long prev_bio_flags, ··· 2924 2931 } 2925 2932 } 2926 2933 while (cur <= end) { 2927 - unsigned long pnr = (last_byte >> PAGE_SHIFT) + 1; 2928 2934 bool force_bio_submit = false; 2929 2935 2930 2936 if (cur >= last_byte) { ··· 3058 3066 continue; 3059 3067 } 3060 3068 3061 - pnr -= page->index; 3062 3069 ret = submit_extent_page(REQ_OP_READ, read_flags, tree, NULL, 3063 3070 page, sector, disk_io_size, pg_offset, 3064 - bdev, bio, pnr, 3071 + bdev, bio, 3065 3072 end_bio_extent_readpage, mirror_num, 3066 3073 *bio_flags, 3067 3074 this_bio_flag, ··· 3201 3210 return ret; 3202 3211 } 3203 3212 3204 - static void update_nr_written(struct page *page, struct writeback_control *wbc, 3213 + static void update_nr_written(struct writeback_control *wbc, 3205 3214 unsigned long nr_written) 3206 3215 { 3207 3216 wbc->nr_to_write -= nr_written; ··· 3321 3330 u64 block_start; 3322 3331 u64 iosize; 3323 3332 sector_t sector; 3324 - struct extent_state *cached_state = NULL; 3325 3333 struct extent_map *em; 3326 3334 struct block_device *bdev; 3327 3335 size_t pg_offset = 0; ··· 3339 3349 else 3340 3350 redirty_page_for_writepage(wbc, page); 3341 3351 3342 - update_nr_written(page, wbc, nr_written); 3352 + update_nr_written(wbc, nr_written); 3343 3353 unlock_page(page); 3344 - ret = 1; 3345 - goto done_unlocked; 3354 + return 1; 3346 3355 } 3347 3356 } 3348 3357 ··· 3349 3360 * we don't want to touch the inode after unlocking the page, 3350 3361 * so we update the mapping writeback index now 3351 3362 */ 3352 - update_nr_written(page, wbc, nr_written + 1); 3363 + update_nr_written(wbc, nr_written + 1); 3353 3364 3354 3365 end = page_end; 3355 3366 if (i_size <= start) { ··· 3363 3374 3364 3375 while (cur <= end) { 3365 3376 u64 em_end; 3366 - unsigned long max_nr; 3367 3377 3368 3378 if (cur >= i_size) { 3369 3379 if (tree->ops && tree->ops->writepage_end_io_hook) ··· 3419 3431 continue; 3420 3432 } 3421 3433 3422 - max_nr = (i_size >> PAGE_SHIFT) + 1; 3423 - 3424 3434 set_range_writeback(tree, cur, cur + iosize - 1); 3425 3435 if (!PageWriteback(page)) { 3426 3436 btrfs_err(BTRFS_I(inode)->root->fs_info, ··· 3428 3442 3429 3443 ret = submit_extent_page(REQ_OP_WRITE, write_flags, tree, wbc, 3430 3444 page, sector, iosize, pg_offset, 3431 - bdev, &epd->bio, max_nr, 3445 + bdev, &epd->bio, 3432 3446 end_bio_extent_writepage, 3433 3447 0, 0, 0, false); 3434 - if (ret) 3448 + if (ret) { 3435 3449 SetPageError(page); 3450 + if (PageWriteback(page)) 3451 + end_page_writeback(page); 3452 + } 3436 3453 3437 3454 cur = cur + iosize; 3438 3455 pg_offset += iosize; ··· 3443 3454 } 3444 3455 done: 3445 3456 *nr_ret = nr; 3446 - 3447 - done_unlocked: 3448 - 3449 - /* drop our reference on any cached states */ 3450 - free_extent_state(cached_state); 3451 3457 return ret; 3452 3458 } 3453 3459 ··· 3745 3761 set_page_writeback(p); 3746 3762 ret = submit_extent_page(REQ_OP_WRITE, write_flags, tree, wbc, 3747 3763 p, offset >> 9, PAGE_SIZE, 0, bdev, 3748 - &epd->bio, -1, 3764 + &epd->bio, 3749 3765 end_bio_extent_buffer_writepage, 3750 3766 0, epd->bio_flags, bio_flags, false); 3751 3767 epd->bio_flags = bio_flags; 3752 3768 if (ret) { 3753 3769 set_btree_ioerr(p); 3754 - end_page_writeback(p); 3770 + if (PageWriteback(p)) 3771 + end_page_writeback(p); 3755 3772 if (atomic_sub_and_test(num_pages - i, &eb->io_pages)) 3756 3773 end_extent_buffer_writeback(eb); 3757 3774 ret = -EIO; 3758 3775 break; 3759 3776 } 3760 3777 offset += PAGE_SIZE; 3761 - update_nr_written(p, wbc, 1); 3778 + update_nr_written(wbc, 1); 3762 3779 unlock_page(p); 3763 3780 } 3764 3781 ··· 3911 3926 * WB_SYNC_ALL then we were called for data integrity and we must wait for 3912 3927 * existing IO to complete. 3913 3928 */ 3914 - static int extent_write_cache_pages(struct extent_io_tree *tree, 3915 - struct address_space *mapping, 3929 + static int extent_write_cache_pages(struct address_space *mapping, 3916 3930 struct writeback_control *wbc, 3917 3931 writepage_t writepage, void *data, 3918 3932 void (*flush_fn)(void *)) ··· 4152 4168 .bio_flags = 0, 4153 4169 }; 4154 4170 4155 - ret = extent_write_cache_pages(tree, mapping, wbc, 4156 - __extent_writepage, &epd, 4171 + ret = extent_write_cache_pages(mapping, wbc, __extent_writepage, &epd, 4157 4172 flush_write_bio); 4158 4173 flush_epd_write_bio(&epd); 4159 4174 return ret; ··· 4247 4264 EXTENT_IOBITS, 0, NULL)) 4248 4265 ret = 0; 4249 4266 else { 4250 - if ((mask & GFP_NOFS) == GFP_NOFS) 4251 - mask = GFP_NOFS; 4252 4267 /* 4253 4268 * at this point we can safely clear everything except the 4254 4269 * locked bit and the nodatasum bit ··· 4391 4410 * lookup the last file extent. We're not using i_size here 4392 4411 * because there might be preallocation past i_size 4393 4412 */ 4394 - ret = btrfs_lookup_file_extent(NULL, root, path, btrfs_ino(inode), -1, 4395 - 0); 4413 + ret = btrfs_lookup_file_extent(NULL, root, path, 4414 + btrfs_ino(BTRFS_I(inode)), -1, 0); 4396 4415 if (ret < 0) { 4397 4416 btrfs_free_path(path); 4398 4417 return ret; ··· 4407 4426 found_type = found_key.type; 4408 4427 4409 4428 /* No extents, but there might be delalloc bits */ 4410 - if (found_key.objectid != btrfs_ino(inode) || 4429 + if (found_key.objectid != btrfs_ino(BTRFS_I(inode)) || 4411 4430 found_type != BTRFS_EXTENT_DATA_KEY) { 4412 4431 /* have to trust i_size as the end */ 4413 4432 last = (u64)-1; ··· 4516 4535 * lookup stuff. 4517 4536 */ 4518 4537 ret = btrfs_check_shared(trans, root->fs_info, 4519 - root->objectid, 4520 - btrfs_ino(inode), bytenr); 4538 + root->objectid, 4539 + btrfs_ino(BTRFS_I(inode)), bytenr); 4521 4540 if (trans) 4522 4541 btrfs_end_transaction(trans); 4523 4542 if (ret < 0)
+3 -2
fs/btrfs/extent_io.h
··· 45 45 #define EXTENT_BUFFER_IN_TREE 10 46 46 #define EXTENT_BUFFER_WRITE_ERR 11 /* write IO error */ 47 47 48 - /* these are flags for extent_clear_unlock_delalloc */ 48 + /* these are flags for __process_pages_contig */ 49 49 #define PAGE_UNLOCK (1 << 0) 50 50 #define PAGE_CLEAR_DIRTY (1 << 1) 51 51 #define PAGE_SET_WRITEBACK (1 << 2) 52 52 #define PAGE_END_WRITEBACK (1 << 3) 53 53 #define PAGE_SET_PRIVATE2 (1 << 4) 54 54 #define PAGE_SET_ERROR (1 << 5) 55 + #define PAGE_LOCK (1 << 6) 55 56 56 57 /* 57 58 * page->private values. Every page that is controlled by the extent ··· 193 192 u64 bytes_changed; 194 193 195 194 /* Changed ranges */ 196 - struct ulist *range_changed; 195 + struct ulist range_changed; 197 196 }; 198 197 199 198 static inline void extent_set_compress_type(unsigned long *bio_flags,
+4 -4
fs/btrfs/file-item.c
··· 255 255 } else { 256 256 btrfs_info_rl(fs_info, 257 257 "no csum found for inode %llu start %llu", 258 - btrfs_ino(inode), offset); 258 + btrfs_ino(BTRFS_I(inode)), offset); 259 259 } 260 260 item = NULL; 261 261 btrfs_release_path(path); ··· 856 856 tmp = min(tmp, (next_offset - file_key.offset) >> 857 857 fs_info->sb->s_blocksize_bits); 858 858 859 - tmp = max((u64)1, tmp); 860 - tmp = min(tmp, (u64)MAX_CSUM_ITEMS(fs_info, csum_size)); 859 + tmp = max_t(u64, 1, tmp); 860 + tmp = min_t(u64, tmp, MAX_CSUM_ITEMS(fs_info, csum_size)); 861 861 ins_size = csum_size * tmp; 862 862 } else { 863 863 ins_size = csum_size; ··· 977 977 } else { 978 978 btrfs_err(fs_info, 979 979 "unknown file extent item type %d, inode %llu, offset %llu, root %llu", 980 - type, btrfs_ino(inode), extent_start, 980 + type, btrfs_ino(BTRFS_I(inode)), extent_start, 981 981 root->root_key.objectid); 982 982 } 983 983 }
+8 -9
fs/btrfs/file.c
··· 168 168 if (!defrag) 169 169 return -ENOMEM; 170 170 171 - defrag->ino = btrfs_ino(inode); 171 + defrag->ino = btrfs_ino(BTRFS_I(inode)); 172 172 defrag->transid = transid; 173 173 defrag->root = root->root_key.objectid; 174 174 ··· 702 702 struct btrfs_file_extent_item *fi; 703 703 struct btrfs_key key; 704 704 struct btrfs_key new_key; 705 - u64 ino = btrfs_ino(inode); 705 + u64 ino = btrfs_ino(BTRFS_I(inode)); 706 706 u64 search_start = start; 707 707 u64 disk_bytenr = 0; 708 708 u64 num_bytes = 0; ··· 1102 1102 int del_slot = 0; 1103 1103 int recow; 1104 1104 int ret; 1105 - u64 ino = btrfs_ino(inode); 1105 + u64 ino = btrfs_ino(BTRFS_I(inode)); 1106 1106 1107 1107 path = btrfs_alloc_path(); 1108 1108 if (!path) ··· 2062 2062 * commit does not start nor waits for ordered extents to complete. 2063 2063 */ 2064 2064 smp_mb(); 2065 - if (btrfs_inode_in_log(inode, fs_info->generation) || 2065 + if (btrfs_inode_in_log(BTRFS_I(inode), fs_info->generation) || 2066 2066 (full_sync && BTRFS_I(inode)->last_trans <= 2067 2067 fs_info->last_trans_committed) || 2068 2068 (!btrfs_have_ordered_extents_in_range(inode, start, len) && ··· 2203 2203 return 0; 2204 2204 2205 2205 btrfs_item_key_to_cpu(leaf, &key, slot); 2206 - if (key.objectid != btrfs_ino(inode) || 2206 + if (key.objectid != btrfs_ino(BTRFS_I(inode)) || 2207 2207 key.type != BTRFS_EXTENT_DATA_KEY) 2208 2208 return 0; 2209 2209 ··· 2237 2237 if (btrfs_fs_incompat(fs_info, NO_HOLES)) 2238 2238 goto out; 2239 2239 2240 - key.objectid = btrfs_ino(inode); 2240 + key.objectid = btrfs_ino(BTRFS_I(inode)); 2241 2241 key.type = BTRFS_EXTENT_DATA_KEY; 2242 2242 key.offset = offset; 2243 2243 ··· 2285 2285 } 2286 2286 btrfs_release_path(path); 2287 2287 2288 - ret = btrfs_insert_file_extent(trans, root, btrfs_ino(inode), offset, 2289 - 0, 0, end - offset, 0, end - offset, 2290 - 0, 0, 0); 2288 + ret = btrfs_insert_file_extent(trans, root, btrfs_ino(BTRFS_I(inode)), 2289 + offset, 0, 0, end - offset, 0, end - offset, 0, 0, 0); 2291 2290 if (ret) 2292 2291 return ret; 2293 2292
+26 -39
fs/btrfs/free-space-cache.c
··· 94 94 return inode; 95 95 } 96 96 97 - struct inode *lookup_free_space_inode(struct btrfs_root *root, 97 + struct inode *lookup_free_space_inode(struct btrfs_fs_info *fs_info, 98 98 struct btrfs_block_group_cache 99 99 *block_group, struct btrfs_path *path) 100 100 { 101 101 struct inode *inode = NULL; 102 - struct btrfs_fs_info *fs_info = root->fs_info; 103 102 u32 flags = BTRFS_INODE_NODATASUM | BTRFS_INODE_NODATACOW; 104 103 105 104 spin_lock(&block_group->lock); ··· 108 109 if (inode) 109 110 return inode; 110 111 111 - inode = __lookup_free_space_inode(root, path, 112 + inode = __lookup_free_space_inode(fs_info->tree_root, path, 112 113 block_group->key.objectid); 113 114 if (IS_ERR(inode)) 114 115 return inode; ··· 191 192 return 0; 192 193 } 193 194 194 - int create_free_space_inode(struct btrfs_root *root, 195 + int create_free_space_inode(struct btrfs_fs_info *fs_info, 195 196 struct btrfs_trans_handle *trans, 196 197 struct btrfs_block_group_cache *block_group, 197 198 struct btrfs_path *path) ··· 199 200 int ret; 200 201 u64 ino; 201 202 202 - ret = btrfs_find_free_objectid(root, &ino); 203 + ret = btrfs_find_free_objectid(fs_info->tree_root, &ino); 203 204 if (ret < 0) 204 205 return ret; 205 206 206 - return __create_free_space_inode(root, trans, path, ino, 207 + return __create_free_space_inode(fs_info->tree_root, trans, path, ino, 207 208 block_group->key.objectid); 208 209 } 209 210 ··· 226 227 return ret; 227 228 } 228 229 229 - int btrfs_truncate_free_space_cache(struct btrfs_root *root, 230 - struct btrfs_trans_handle *trans, 230 + int btrfs_truncate_free_space_cache(struct btrfs_trans_handle *trans, 231 231 struct btrfs_block_group_cache *block_group, 232 232 struct inode *inode) 233 233 { 234 + struct btrfs_root *root = BTRFS_I(inode)->root; 234 235 int ret = 0; 235 - struct btrfs_path *path = btrfs_alloc_path(); 236 236 bool locked = false; 237 237 238 - if (!path) { 239 - ret = -ENOMEM; 240 - goto fail; 241 - } 242 - 243 238 if (block_group) { 239 + struct btrfs_path *path = btrfs_alloc_path(); 240 + 241 + if (!path) { 242 + ret = -ENOMEM; 243 + goto fail; 244 + } 244 245 locked = true; 245 246 mutex_lock(&trans->transaction->cache_write_mutex); 246 247 if (!list_empty(&block_group->io_list)) { ··· 257 258 spin_lock(&block_group->lock); 258 259 block_group->disk_cache_state = BTRFS_DC_CLEAR; 259 260 spin_unlock(&block_group->lock); 261 + btrfs_free_path(path); 260 262 } 261 - btrfs_free_path(path); 262 263 263 264 btrfs_i_size_write(inode, 0); 264 265 truncate_pagecache(inode, 0); ··· 285 286 return ret; 286 287 } 287 288 288 - static int readahead_cache(struct inode *inode) 289 + static void readahead_cache(struct inode *inode) 289 290 { 290 291 struct file_ra_state *ra; 291 292 unsigned long last_index; 292 293 293 294 ra = kzalloc(sizeof(*ra), GFP_NOFS); 294 295 if (!ra) 295 - return -ENOMEM; 296 + return; 296 297 297 298 file_ra_state_init(ra, inode->i_mapping); 298 299 last_index = (i_size_read(inode) - 1) >> PAGE_SHIFT; ··· 300 301 page_cache_sync_readahead(inode->i_mapping, ra, NULL, 0, last_index); 301 302 302 303 kfree(ra); 303 - 304 - return 0; 305 304 } 306 305 307 306 static int io_ctl_init(struct btrfs_io_ctl *io_ctl, struct inode *inode, ··· 310 313 311 314 num_pages = DIV_ROUND_UP(i_size_read(inode), PAGE_SIZE); 312 315 313 - if (btrfs_ino(inode) != BTRFS_FREE_INO_OBJECTID) 316 + if (btrfs_ino(BTRFS_I(inode)) != BTRFS_FREE_INO_OBJECTID) 314 317 check_crcs = 1; 315 318 316 319 /* Make sure we can fit our crcs into the first page */ ··· 727 730 if (ret) 728 731 return ret; 729 732 730 - ret = readahead_cache(inode); 731 - if (ret) 732 - goto out; 733 + readahead_cache(inode); 733 734 734 735 ret = io_ctl_prepare_pages(&io_ctl, inode, 1); 735 736 if (ret) ··· 823 828 struct btrfs_block_group_cache *block_group) 824 829 { 825 830 struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl; 826 - struct btrfs_root *root = fs_info->tree_root; 827 831 struct inode *inode; 828 832 struct btrfs_path *path; 829 833 int ret = 0; ··· 846 852 path->search_commit_root = 1; 847 853 path->skip_locking = 1; 848 854 849 - inode = lookup_free_space_inode(root, block_group, path); 855 + inode = lookup_free_space_inode(fs_info, block_group, path); 850 856 if (IS_ERR(inode)) { 851 857 btrfs_free_path(path); 852 858 return 0; ··· 1122 1128 static void noinline_for_stack 1123 1129 cleanup_write_cache_enospc(struct inode *inode, 1124 1130 struct btrfs_io_ctl *io_ctl, 1125 - struct extent_state **cached_state, 1126 - struct list_head *bitmap_list) 1131 + struct extent_state **cached_state) 1127 1132 { 1128 1133 io_ctl_drop_pages(io_ctl); 1129 1134 unlock_extent_cached(&BTRFS_I(inode)->io_tree, 0, ··· 1218 1225 * @ctl - the free space cache we are going to write out 1219 1226 * @block_group - the block_group for this cache if it belongs to a block_group 1220 1227 * @trans - the trans handle 1221 - * @path - the path to use 1222 - * @offset - the offset for the key we'll insert 1223 1228 * 1224 1229 * This function writes out a free space cache struct to disk for quick recovery 1225 1230 * on mount. This will return 0 if it was successful in writing the cache out, ··· 1227 1236 struct btrfs_free_space_ctl *ctl, 1228 1237 struct btrfs_block_group_cache *block_group, 1229 1238 struct btrfs_io_ctl *io_ctl, 1230 - struct btrfs_trans_handle *trans, 1231 - struct btrfs_path *path, u64 offset) 1239 + struct btrfs_trans_handle *trans) 1232 1240 { 1233 1241 struct btrfs_fs_info *fs_info = root->fs_info; 1234 1242 struct extent_state *cached_state = NULL; ··· 1355 1365 mutex_unlock(&ctl->cache_writeout_mutex); 1356 1366 1357 1367 out_nospc: 1358 - cleanup_write_cache_enospc(inode, io_ctl, &cached_state, &bitmap_list); 1368 + cleanup_write_cache_enospc(inode, io_ctl, &cached_state); 1359 1369 1360 1370 if (block_group && (block_group->flags & BTRFS_BLOCK_GROUP_DATA)) 1361 1371 up_write(&block_group->data_rwsem); ··· 1368 1378 struct btrfs_block_group_cache *block_group, 1369 1379 struct btrfs_path *path) 1370 1380 { 1371 - struct btrfs_root *root = fs_info->tree_root; 1372 1381 struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl; 1373 1382 struct inode *inode; 1374 1383 int ret = 0; ··· 1379 1390 } 1380 1391 spin_unlock(&block_group->lock); 1381 1392 1382 - inode = lookup_free_space_inode(root, block_group, path); 1393 + inode = lookup_free_space_inode(fs_info, block_group, path); 1383 1394 if (IS_ERR(inode)) 1384 1395 return 0; 1385 1396 1386 - ret = __btrfs_write_out_cache(root, inode, ctl, block_group, 1387 - &block_group->io_ctl, trans, 1388 - path, block_group->key.objectid); 1397 + ret = __btrfs_write_out_cache(fs_info->tree_root, inode, ctl, 1398 + block_group, &block_group->io_ctl, trans); 1389 1399 if (ret) { 1390 1400 #ifdef DEBUG 1391 1401 btrfs_err(fs_info, ··· 3531 3543 return 0; 3532 3544 3533 3545 memset(&io_ctl, 0, sizeof(io_ctl)); 3534 - ret = __btrfs_write_out_cache(root, inode, ctl, NULL, &io_ctl, 3535 - trans, path, 0); 3546 + ret = __btrfs_write_out_cache(root, inode, ctl, NULL, &io_ctl, trans); 3536 3547 if (!ret) { 3537 3548 /* 3538 3549 * At this point writepages() didn't error out, so our metadata
+3 -4
fs/btrfs/free-space-cache.h
··· 51 51 52 52 struct btrfs_io_ctl; 53 53 54 - struct inode *lookup_free_space_inode(struct btrfs_root *root, 54 + struct inode *lookup_free_space_inode(struct btrfs_fs_info *fs_info, 55 55 struct btrfs_block_group_cache 56 56 *block_group, struct btrfs_path *path); 57 - int create_free_space_inode(struct btrfs_root *root, 57 + int create_free_space_inode(struct btrfs_fs_info *fs_info, 58 58 struct btrfs_trans_handle *trans, 59 59 struct btrfs_block_group_cache *block_group, 60 60 struct btrfs_path *path); 61 61 62 62 int btrfs_check_trunc_cache_free_space(struct btrfs_fs_info *fs_info, 63 63 struct btrfs_block_rsv *rsv); 64 - int btrfs_truncate_free_space_cache(struct btrfs_root *root, 65 - struct btrfs_trans_handle *trans, 64 + int btrfs_truncate_free_space_cache(struct btrfs_trans_handle *trans, 66 65 struct btrfs_block_group_cache *block_group, 67 66 struct inode *inode); 68 67 int load_free_space_cache(struct btrfs_fs_info *fs_info,
+1 -1
fs/btrfs/free-space-tree.c
··· 1269 1269 list_del(&free_space_root->dirty_list); 1270 1270 1271 1271 btrfs_tree_lock(free_space_root->node); 1272 - clean_tree_block(trans, fs_info, free_space_root->node); 1272 + clean_tree_block(fs_info, free_space_root->node); 1273 1273 btrfs_tree_unlock(free_space_root->node); 1274 1274 btrfs_free_tree_block(trans, free_space_root, free_space_root->node, 1275 1275 0, 1);
+1 -1
fs/btrfs/inode-map.c
··· 467 467 } 468 468 469 469 if (i_size_read(inode) > 0) { 470 - ret = btrfs_truncate_free_space_cache(root, trans, NULL, inode); 470 + ret = btrfs_truncate_free_space_cache(trans, NULL, inode); 471 471 if (ret) { 472 472 if (ret != -ENOSPC) 473 473 btrfs_abort_transaction(trans, ret);
+260 -322
fs/btrfs/inode.c
··· 71 71 u64 reserve; 72 72 u64 unsubmitted_oe_range_start; 73 73 u64 unsubmitted_oe_range_end; 74 + int overwrite; 74 75 }; 75 76 76 77 static const struct inode_operations btrfs_dir_inode_operations; ··· 109 108 u64 start, u64 end, u64 delalloc_end, 110 109 int *page_started, unsigned long *nr_written, 111 110 int unlock, struct btrfs_dedupe_hash *hash); 112 - static struct extent_map *create_pinned_em(struct inode *inode, u64 start, 113 - u64 len, u64 orig_start, 114 - u64 block_start, u64 block_len, 115 - u64 orig_block_len, u64 ram_bytes, 116 - int type); 111 + static struct extent_map *create_io_em(struct inode *inode, u64 start, u64 len, 112 + u64 orig_start, u64 block_start, 113 + u64 block_len, u64 orig_block_len, 114 + u64 ram_bytes, int compress_type, 115 + int type); 117 116 118 117 static int btrfs_dirty_inode(struct inode *inode); 119 118 ··· 167 166 struct btrfs_key key; 168 167 size_t datasize; 169 168 170 - key.objectid = btrfs_ino(inode); 169 + key.objectid = btrfs_ino(BTRFS_I(inode)); 171 170 key.offset = start; 172 171 key.type = BTRFS_EXTENT_DATA_KEY; 173 172 ··· 389 388 return 0; 390 389 } 391 390 391 + static inline void inode_should_defrag(struct inode *inode, 392 + u64 start, u64 end, u64 num_bytes, u64 small_write) 393 + { 394 + /* If this is a small write inside eof, kick off a defrag */ 395 + if (num_bytes < small_write && 396 + (start > 0 || end + 1 < BTRFS_I(inode)->disk_i_size)) 397 + btrfs_add_inode_defrag(NULL, inode); 398 + } 399 + 392 400 /* 393 401 * we create compressed extents in two phases. The first 394 402 * phase compresses a range of pages that have already been ··· 440 430 int compress_type = fs_info->compress_type; 441 431 int redirty = 0; 442 432 443 - /* if this is a small write inside eof, kick off a defrag */ 444 - if ((end - start + 1) < SZ_16K && 445 - (start > 0 || end + 1 < BTRFS_I(inode)->disk_i_size)) 446 - btrfs_add_inode_defrag(NULL, inode); 433 + inode_should_defrag(inode, start, end, end - start + 1, SZ_16K); 447 434 448 435 actual_end = min_t(u64, isize, end + 1); 449 436 again: ··· 548 541 * to make an uncompressed inline extent. 549 542 */ 550 543 ret = cow_file_range_inline(root, inode, start, end, 551 - 0, 0, NULL); 544 + 0, BTRFS_COMPRESS_NONE, NULL); 552 545 } else { 553 546 /* try making a compressed inline extent */ 554 547 ret = cow_file_range_inline(root, inode, start, end, ··· 697 690 struct btrfs_key ins; 698 691 struct extent_map *em; 699 692 struct btrfs_root *root = BTRFS_I(inode)->root; 700 - struct extent_map_tree *em_tree = &BTRFS_I(inode)->extent_tree; 701 693 struct extent_io_tree *io_tree; 702 694 int ret = 0; 703 695 ··· 784 778 * here we're doing allocation and writeback of the 785 779 * compressed pages 786 780 */ 787 - btrfs_drop_extent_cache(inode, async_extent->start, 788 - async_extent->start + 789 - async_extent->ram_size - 1, 0); 790 - 791 - em = alloc_extent_map(); 792 - if (!em) { 793 - ret = -ENOMEM; 781 + em = create_io_em(inode, async_extent->start, 782 + async_extent->ram_size, /* len */ 783 + async_extent->start, /* orig_start */ 784 + ins.objectid, /* block_start */ 785 + ins.offset, /* block_len */ 786 + ins.offset, /* orig_block_len */ 787 + async_extent->ram_size, /* ram_bytes */ 788 + async_extent->compress_type, 789 + BTRFS_ORDERED_COMPRESSED); 790 + if (IS_ERR(em)) 791 + /* ret value is not necessary due to void function */ 794 792 goto out_free_reserve; 795 - } 796 - em->start = async_extent->start; 797 - em->len = async_extent->ram_size; 798 - em->orig_start = em->start; 799 - em->mod_start = em->start; 800 - em->mod_len = em->len; 801 - 802 - em->block_start = ins.objectid; 803 - em->block_len = ins.offset; 804 - em->orig_block_len = ins.offset; 805 - em->ram_bytes = async_extent->ram_size; 806 - em->bdev = fs_info->fs_devices->latest_bdev; 807 - em->compress_type = async_extent->compress_type; 808 - set_bit(EXTENT_FLAG_PINNED, &em->flags); 809 - set_bit(EXTENT_FLAG_COMPRESSED, &em->flags); 810 - em->generation = -1; 811 - 812 - while (1) { 813 - write_lock(&em_tree->lock); 814 - ret = add_extent_mapping(em_tree, em, 1); 815 - write_unlock(&em_tree->lock); 816 - if (ret != -EEXIST) { 817 - free_extent_map(em); 818 - break; 819 - } 820 - btrfs_drop_extent_cache(inode, async_extent->start, 821 - async_extent->start + 822 - async_extent->ram_size - 1, 0); 823 - } 824 - 825 - if (ret) 826 - goto out_free_reserve; 793 + free_extent_map(em); 827 794 828 795 ret = btrfs_add_ordered_extent_compress(inode, 829 796 async_extent->start, ··· 931 952 u64 blocksize = fs_info->sectorsize; 932 953 struct btrfs_key ins; 933 954 struct extent_map *em; 934 - struct extent_map_tree *em_tree = &BTRFS_I(inode)->extent_tree; 935 955 int ret = 0; 936 956 937 957 if (btrfs_is_free_space_inode(inode)) { ··· 943 965 num_bytes = max(blocksize, num_bytes); 944 966 disk_num_bytes = num_bytes; 945 967 946 - /* if this is a small write inside eof, kick off defrag */ 947 - if (num_bytes < SZ_64K && 948 - (start > 0 || end + 1 < BTRFS_I(inode)->disk_i_size)) 949 - btrfs_add_inode_defrag(NULL, inode); 968 + inode_should_defrag(inode, start, end, num_bytes, SZ_64K); 950 969 951 970 if (start == 0) { 952 971 /* lets try to make an inline extent */ 953 - ret = cow_file_range_inline(root, inode, start, end, 0, 0, 954 - NULL); 972 + ret = cow_file_range_inline(root, inode, start, end, 0, 973 + BTRFS_COMPRESS_NONE, NULL); 955 974 if (ret == 0) { 956 975 extent_clear_unlock_delalloc(inode, start, end, 957 976 delalloc_end, NULL, ··· 983 1008 if (ret < 0) 984 1009 goto out_unlock; 985 1010 986 - em = alloc_extent_map(); 987 - if (!em) { 988 - ret = -ENOMEM; 989 - goto out_reserve; 990 - } 991 - em->start = start; 992 - em->orig_start = em->start; 993 1011 ram_size = ins.offset; 994 - em->len = ins.offset; 995 - em->mod_start = em->start; 996 - em->mod_len = em->len; 997 - 998 - em->block_start = ins.objectid; 999 - em->block_len = ins.offset; 1000 - em->orig_block_len = ins.offset; 1001 - em->ram_bytes = ram_size; 1002 - em->bdev = fs_info->fs_devices->latest_bdev; 1003 - set_bit(EXTENT_FLAG_PINNED, &em->flags); 1004 - em->generation = -1; 1005 - 1006 - while (1) { 1007 - write_lock(&em_tree->lock); 1008 - ret = add_extent_mapping(em_tree, em, 1); 1009 - write_unlock(&em_tree->lock); 1010 - if (ret != -EEXIST) { 1011 - free_extent_map(em); 1012 - break; 1013 - } 1014 - btrfs_drop_extent_cache(inode, start, 1015 - start + ram_size - 1, 0); 1016 - } 1017 - if (ret) 1012 + em = create_io_em(inode, start, ins.offset, /* len */ 1013 + start, /* orig_start */ 1014 + ins.objectid, /* block_start */ 1015 + ins.offset, /* block_len */ 1016 + ins.offset, /* orig_block_len */ 1017 + ram_size, /* ram_bytes */ 1018 + BTRFS_COMPRESS_NONE, /* compress_type */ 1019 + BTRFS_ORDERED_REGULAR /* type */); 1020 + if (IS_ERR(em)) 1018 1021 goto out_reserve; 1022 + free_extent_map(em); 1019 1023 1020 1024 cur_alloc_size = ins.offset; 1021 1025 ret = btrfs_add_ordered_extent(inode, start, ins.objectid, ··· 1118 1164 struct btrfs_root *root = BTRFS_I(inode)->root; 1119 1165 unsigned long nr_pages; 1120 1166 u64 cur_end; 1121 - int limit = 10 * SZ_1M; 1122 1167 1123 1168 clear_extent_bit(&BTRFS_I(inode)->io_tree, start, end, EXTENT_LOCKED, 1124 1169 1, 0, NULL, GFP_NOFS); ··· 1148 1195 atomic_add(nr_pages, &fs_info->async_delalloc_pages); 1149 1196 1150 1197 btrfs_queue_work(fs_info->delalloc_workers, &async_cow->work); 1151 - 1152 - if (atomic_read(&fs_info->async_delalloc_pages) > limit) { 1153 - wait_event(fs_info->async_submit_wait, 1154 - (atomic_read(&fs_info->async_delalloc_pages) < 1155 - limit)); 1156 - } 1157 1198 1158 1199 while (atomic_read(&fs_info->async_submit_draining) && 1159 1200 atomic_read(&fs_info->async_delalloc_pages)) { ··· 1197 1250 { 1198 1251 struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb); 1199 1252 struct btrfs_root *root = BTRFS_I(inode)->root; 1200 - struct btrfs_trans_handle *trans; 1201 1253 struct extent_buffer *leaf; 1202 1254 struct btrfs_path *path; 1203 1255 struct btrfs_file_extent_item *fi; 1204 1256 struct btrfs_key found_key; 1257 + struct extent_map *em; 1205 1258 u64 cow_start; 1206 1259 u64 cur_offset; 1207 1260 u64 extent_end; ··· 1216 1269 int nocow; 1217 1270 int check_prev = 1; 1218 1271 bool nolock; 1219 - u64 ino = btrfs_ino(inode); 1272 + u64 ino = btrfs_ino(BTRFS_I(inode)); 1220 1273 1221 1274 path = btrfs_alloc_path(); 1222 1275 if (!path) { ··· 1233 1286 1234 1287 nolock = btrfs_is_free_space_inode(inode); 1235 1288 1236 - if (nolock) 1237 - trans = btrfs_join_transaction_nolock(root); 1238 - else 1239 - trans = btrfs_join_transaction(root); 1240 - 1241 - if (IS_ERR(trans)) { 1242 - extent_clear_unlock_delalloc(inode, start, end, end, 1243 - locked_page, 1244 - EXTENT_LOCKED | EXTENT_DELALLOC | 1245 - EXTENT_DO_ACCOUNTING | 1246 - EXTENT_DEFRAG, PAGE_UNLOCK | 1247 - PAGE_CLEAR_DIRTY | 1248 - PAGE_SET_WRITEBACK | 1249 - PAGE_END_WRITEBACK); 1250 - btrfs_free_path(path); 1251 - return PTR_ERR(trans); 1252 - } 1253 - 1254 - trans->block_rsv = &fs_info->delalloc_block_rsv; 1255 - 1256 1289 cow_start = (u64)-1; 1257 1290 cur_offset = start; 1258 1291 while (1) { 1259 - ret = btrfs_lookup_file_extent(trans, root, path, ino, 1292 + ret = btrfs_lookup_file_extent(NULL, root, path, ino, 1260 1293 cur_offset, 0); 1261 1294 if (ret < 0) 1262 1295 goto error; ··· 1309 1382 goto out_check; 1310 1383 if (btrfs_extent_readonly(fs_info, disk_bytenr)) 1311 1384 goto out_check; 1312 - if (btrfs_cross_ref_exist(trans, root, ino, 1385 + if (btrfs_cross_ref_exist(root, ino, 1313 1386 found_key.offset - 1314 1387 extent_offset, disk_bytenr)) 1315 1388 goto out_check; ··· 1382 1455 } 1383 1456 1384 1457 if (extent_type == BTRFS_FILE_EXTENT_PREALLOC) { 1385 - struct extent_map *em; 1386 - struct extent_map_tree *em_tree; 1387 - em_tree = &BTRFS_I(inode)->extent_tree; 1388 - em = alloc_extent_map(); 1389 - BUG_ON(!em); /* -ENOMEM */ 1390 - em->start = cur_offset; 1391 - em->orig_start = found_key.offset - extent_offset; 1392 - em->len = num_bytes; 1393 - em->block_len = num_bytes; 1394 - em->block_start = disk_bytenr; 1395 - em->orig_block_len = disk_num_bytes; 1396 - em->ram_bytes = ram_bytes; 1397 - em->bdev = fs_info->fs_devices->latest_bdev; 1398 - em->mod_start = em->start; 1399 - em->mod_len = em->len; 1400 - set_bit(EXTENT_FLAG_PINNED, &em->flags); 1401 - set_bit(EXTENT_FLAG_FILLING, &em->flags); 1402 - em->generation = -1; 1403 - while (1) { 1404 - write_lock(&em_tree->lock); 1405 - ret = add_extent_mapping(em_tree, em, 1); 1406 - write_unlock(&em_tree->lock); 1407 - if (ret != -EEXIST) { 1408 - free_extent_map(em); 1409 - break; 1410 - } 1411 - btrfs_drop_extent_cache(inode, em->start, 1412 - em->start + em->len - 1, 0); 1458 + u64 orig_start = found_key.offset - extent_offset; 1459 + 1460 + em = create_io_em(inode, cur_offset, num_bytes, 1461 + orig_start, 1462 + disk_bytenr, /* block_start */ 1463 + num_bytes, /* block_len */ 1464 + disk_num_bytes, /* orig_block_len */ 1465 + ram_bytes, BTRFS_COMPRESS_NONE, 1466 + BTRFS_ORDERED_PREALLOC); 1467 + if (IS_ERR(em)) { 1468 + if (!nolock && nocow) 1469 + btrfs_end_write_no_snapshoting(root); 1470 + if (nocow) 1471 + btrfs_dec_nocow_writers(fs_info, 1472 + disk_bytenr); 1473 + ret = PTR_ERR(em); 1474 + goto error; 1413 1475 } 1476 + free_extent_map(em); 1477 + } 1478 + 1479 + if (extent_type == BTRFS_FILE_EXTENT_PREALLOC) { 1414 1480 type = BTRFS_ORDERED_PREALLOC; 1415 1481 } else { 1416 1482 type = BTRFS_ORDERED_NOCOW; ··· 1454 1534 } 1455 1535 1456 1536 error: 1457 - err = btrfs_end_transaction(trans); 1458 - if (!ret) 1459 - ret = err; 1460 - 1461 1537 if (ret && cur_offset < end) 1462 1538 extent_clear_unlock_delalloc(inode, cur_offset, end, end, 1463 1539 locked_page, EXTENT_LOCKED | ··· 1525 1609 1526 1610 size = orig->end - orig->start + 1; 1527 1611 if (size > BTRFS_MAX_EXTENT_SIZE) { 1528 - u64 num_extents; 1612 + u32 num_extents; 1529 1613 u64 new_size; 1530 1614 1531 1615 /* ··· 1533 1617 * applies here, just in reverse. 1534 1618 */ 1535 1619 new_size = orig->end - split + 1; 1536 - num_extents = div64_u64(new_size + BTRFS_MAX_EXTENT_SIZE - 1, 1537 - BTRFS_MAX_EXTENT_SIZE); 1620 + num_extents = count_max_extents(new_size); 1538 1621 new_size = split - orig->start; 1539 - num_extents += div64_u64(new_size + BTRFS_MAX_EXTENT_SIZE - 1, 1540 - BTRFS_MAX_EXTENT_SIZE); 1541 - if (div64_u64(size + BTRFS_MAX_EXTENT_SIZE - 1, 1542 - BTRFS_MAX_EXTENT_SIZE) >= num_extents) 1622 + num_extents += count_max_extents(new_size); 1623 + if (count_max_extents(size) >= num_extents) 1543 1624 return; 1544 1625 } 1545 1626 ··· 1556 1643 struct extent_state *other) 1557 1644 { 1558 1645 u64 new_size, old_size; 1559 - u64 num_extents; 1646 + u32 num_extents; 1560 1647 1561 1648 /* not delalloc, ignore it */ 1562 1649 if (!(other->state & EXTENT_DELALLOC)) ··· 1594 1681 * this case. 1595 1682 */ 1596 1683 old_size = other->end - other->start + 1; 1597 - num_extents = div64_u64(old_size + BTRFS_MAX_EXTENT_SIZE - 1, 1598 - BTRFS_MAX_EXTENT_SIZE); 1684 + num_extents = count_max_extents(old_size); 1599 1685 old_size = new->end - new->start + 1; 1600 - num_extents += div64_u64(old_size + BTRFS_MAX_EXTENT_SIZE - 1, 1601 - BTRFS_MAX_EXTENT_SIZE); 1602 - 1603 - if (div64_u64(new_size + BTRFS_MAX_EXTENT_SIZE - 1, 1604 - BTRFS_MAX_EXTENT_SIZE) >= num_extents) 1686 + num_extents += count_max_extents(old_size); 1687 + if (count_max_extents(new_size) >= num_extents) 1605 1688 return; 1606 1689 1607 1690 spin_lock(&BTRFS_I(inode)->lock); ··· 1706 1797 { 1707 1798 struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb); 1708 1799 u64 len = state->end + 1 - state->start; 1709 - u64 num_extents = div64_u64(len + BTRFS_MAX_EXTENT_SIZE -1, 1710 - BTRFS_MAX_EXTENT_SIZE); 1800 + u32 num_extents = count_max_extents(len); 1711 1801 1712 1802 spin_lock(&BTRFS_I(inode)->lock); 1713 1803 if ((state->state & EXTENT_DEFRAG) && (*bits & EXTENT_DEFRAG)) ··· 1905 1997 * at IO completion time based on sums calculated at bio submission time. 1906 1998 */ 1907 1999 static noinline int add_pending_csums(struct btrfs_trans_handle *trans, 1908 - struct inode *inode, u64 file_offset, 1909 - struct list_head *list) 2000 + struct inode *inode, struct list_head *list) 1910 2001 { 1911 2002 struct btrfs_ordered_sum *sum; 1912 2003 ··· 2068 2161 goto out; 2069 2162 2070 2163 if (!extent_inserted) { 2071 - ins.objectid = btrfs_ino(inode); 2164 + ins.objectid = btrfs_ino(BTRFS_I(inode)); 2072 2165 ins.offset = file_pos; 2073 2166 ins.type = BTRFS_EXTENT_DATA_KEY; 2074 2167 ··· 2101 2194 ins.offset = disk_num_bytes; 2102 2195 ins.type = BTRFS_EXTENT_ITEM_KEY; 2103 2196 ret = btrfs_alloc_reserved_file_extent(trans, root->root_key.objectid, 2104 - btrfs_ino(inode), file_pos, 2105 - ram_bytes, &ins); 2197 + btrfs_ino(BTRFS_I(inode)), file_pos, ram_bytes, &ins); 2106 2198 /* 2107 2199 * Release the reserved range from inode dirty range map, as it is 2108 2200 * already moved into delayed_ref_head ··· 2226 2320 u64 num_bytes; 2227 2321 2228 2322 if (BTRFS_I(inode)->root->root_key.objectid == root_id && 2229 - inum == btrfs_ino(inode)) 2323 + inum == btrfs_ino(BTRFS_I(inode))) 2230 2324 return 0; 2231 2325 2232 2326 key.objectid = root_id; ··· 2495 2589 if (ret) 2496 2590 goto out_free_path; 2497 2591 again: 2498 - key.objectid = btrfs_ino(inode); 2592 + key.objectid = btrfs_ino(BTRFS_I(inode)); 2499 2593 key.type = BTRFS_EXTENT_DATA_KEY; 2500 2594 key.offset = start; 2501 2595 ··· 2674 2768 if (!path) 2675 2769 goto out_kfree; 2676 2770 2677 - key.objectid = btrfs_ino(inode); 2771 + key.objectid = btrfs_ino(BTRFS_I(inode)); 2678 2772 key.type = BTRFS_EXTENT_DATA_KEY; 2679 2773 key.offset = new->file_pos; 2680 2774 ··· 2709 2803 2710 2804 btrfs_item_key_to_cpu(l, &key, slot); 2711 2805 2712 - if (key.objectid != btrfs_ino(inode)) 2806 + if (key.objectid != btrfs_ino(BTRFS_I(inode))) 2713 2807 break; 2714 2808 if (key.type != BTRFS_EXTENT_DATA_KEY) 2715 2809 break; ··· 2899 2993 goto out_unlock; 2900 2994 } 2901 2995 2902 - add_pending_csums(trans, inode, ordered_extent->file_offset, 2903 - &ordered_extent->list); 2996 + add_pending_csums(trans, inode, &ordered_extent->list); 2904 2997 2905 2998 btrfs_ordered_update_i_size(inode, 0, ordered_extent); 2906 2999 ret = btrfs_update_inode_fallback(trans, root, inode); ··· 3028 3123 kunmap_atomic(kaddr); 3029 3124 return 0; 3030 3125 zeroit: 3031 - btrfs_warn_rl(BTRFS_I(inode)->root->fs_info, 3032 - "csum failed ino %llu off %llu csum %u expected csum %u", 3033 - btrfs_ino(inode), start, csum, csum_expected); 3126 + btrfs_print_data_csum_error(inode, start, csum, csum_expected, 3127 + io_bio->mirror_num); 3034 3128 memset(kaddr + pgoff, 1, len); 3035 3129 flush_dcache_page(page); 3036 3130 kunmap_atomic(kaddr); ··· 3230 3326 3231 3327 /* insert an orphan item to track this unlinked/truncated file */ 3232 3328 if (insert >= 1) { 3233 - ret = btrfs_insert_orphan_item(trans, root, btrfs_ino(inode)); 3329 + ret = btrfs_insert_orphan_item(trans, root, 3330 + btrfs_ino(BTRFS_I(inode))); 3234 3331 if (ret) { 3235 3332 atomic_dec(&root->orphan_inodes); 3236 3333 if (reserve) { ··· 3287 3382 atomic_dec(&root->orphan_inodes); 3288 3383 if (trans) 3289 3384 ret = btrfs_del_orphan_item(trans, root, 3290 - btrfs_ino(inode)); 3385 + btrfs_ino(BTRFS_I(inode))); 3291 3386 } 3292 3387 3293 3388 if (release_rsv) ··· 3694 3789 goto cache_acl; 3695 3790 3696 3791 btrfs_item_key_to_cpu(leaf, &location, path->slots[0]); 3697 - if (location.objectid != btrfs_ino(inode)) 3792 + if (location.objectid != btrfs_ino(BTRFS_I(inode))) 3698 3793 goto cache_acl; 3699 3794 3700 3795 ptr = btrfs_item_ptr_offset(leaf, path->slots[0]); ··· 3716 3811 * any xattrs or acls 3717 3812 */ 3718 3813 maybe_acls = acls_after_inode_item(leaf, path->slots[0], 3719 - btrfs_ino(inode), &first_xattr_slot); 3814 + btrfs_ino(BTRFS_I(inode)), &first_xattr_slot); 3720 3815 if (first_xattr_slot != -1) { 3721 3816 path->slots[0] = first_xattr_slot; 3722 3817 ret = btrfs_load_inode_props(inode, path); 3723 3818 if (ret) 3724 3819 btrfs_err(fs_info, 3725 3820 "error loading props for ino %llu (root %llu): %d", 3726 - btrfs_ino(inode), 3821 + btrfs_ino(BTRFS_I(inode)), 3727 3822 root->root_key.objectid, ret); 3728 3823 } 3729 3824 btrfs_free_path(path); ··· 3898 3993 */ 3899 3994 static int __btrfs_unlink_inode(struct btrfs_trans_handle *trans, 3900 3995 struct btrfs_root *root, 3901 - struct inode *dir, struct inode *inode, 3996 + struct btrfs_inode *dir, 3997 + struct btrfs_inode *inode, 3902 3998 const char *name, int name_len) 3903 3999 { 3904 4000 struct btrfs_fs_info *fs_info = root->fs_info; ··· 3946 4040 * that we delay to delete it, and just do this deletion when 3947 4041 * we update the inode item. 3948 4042 */ 3949 - if (BTRFS_I(inode)->dir_index) { 4043 + if (inode->dir_index) { 3950 4044 ret = btrfs_delayed_delete_inode_ref(inode); 3951 4045 if (!ret) { 3952 - index = BTRFS_I(inode)->dir_index; 4046 + index = inode->dir_index; 3953 4047 goto skip_backref; 3954 4048 } 3955 4049 } ··· 3970 4064 goto err; 3971 4065 } 3972 4066 3973 - ret = btrfs_del_inode_ref_in_log(trans, root, name, name_len, 3974 - inode, dir_ino); 4067 + ret = btrfs_del_inode_ref_in_log(trans, root, name, name_len, inode, 4068 + dir_ino); 3975 4069 if (ret != 0 && ret != -ENOENT) { 3976 4070 btrfs_abort_transaction(trans, ret); 3977 4071 goto err; 3978 4072 } 3979 4073 3980 - ret = btrfs_del_dir_entries_in_log(trans, root, name, name_len, 3981 - dir, index); 4074 + ret = btrfs_del_dir_entries_in_log(trans, root, name, name_len, dir, 4075 + index); 3982 4076 if (ret == -ENOENT) 3983 4077 ret = 0; 3984 4078 else if (ret) ··· 3988 4082 if (ret) 3989 4083 goto out; 3990 4084 3991 - btrfs_i_size_write(dir, dir->i_size - name_len * 2); 3992 - inode_inc_iversion(inode); 3993 - inode_inc_iversion(dir); 3994 - inode->i_ctime = dir->i_mtime = 3995 - dir->i_ctime = current_time(inode); 3996 - ret = btrfs_update_inode(trans, root, dir); 4085 + btrfs_i_size_write(&dir->vfs_inode, 4086 + dir->vfs_inode.i_size - name_len * 2); 4087 + inode_inc_iversion(&inode->vfs_inode); 4088 + inode_inc_iversion(&dir->vfs_inode); 4089 + inode->vfs_inode.i_ctime = dir->vfs_inode.i_mtime = 4090 + dir->vfs_inode.i_ctime = current_time(&inode->vfs_inode); 4091 + ret = btrfs_update_inode(trans, root, &dir->vfs_inode); 3997 4092 out: 3998 4093 return ret; 3999 4094 } 4000 4095 4001 4096 int btrfs_unlink_inode(struct btrfs_trans_handle *trans, 4002 4097 struct btrfs_root *root, 4003 - struct inode *dir, struct inode *inode, 4098 + struct btrfs_inode *dir, struct btrfs_inode *inode, 4004 4099 const char *name, int name_len) 4005 4100 { 4006 4101 int ret; 4007 4102 ret = __btrfs_unlink_inode(trans, root, dir, inode, name, name_len); 4008 4103 if (!ret) { 4009 - drop_nlink(inode); 4010 - ret = btrfs_update_inode(trans, root, inode); 4104 + drop_nlink(&inode->vfs_inode); 4105 + ret = btrfs_update_inode(trans, root, &inode->vfs_inode); 4011 4106 } 4012 4107 return ret; 4013 4108 } ··· 4046 4139 if (IS_ERR(trans)) 4047 4140 return PTR_ERR(trans); 4048 4141 4049 - btrfs_record_unlink_dir(trans, dir, d_inode(dentry), 0); 4142 + btrfs_record_unlink_dir(trans, BTRFS_I(dir), BTRFS_I(d_inode(dentry)), 4143 + 0); 4050 4144 4051 - ret = btrfs_unlink_inode(trans, root, dir, d_inode(dentry), 4052 - dentry->d_name.name, dentry->d_name.len); 4145 + ret = btrfs_unlink_inode(trans, root, BTRFS_I(dir), 4146 + BTRFS_I(d_inode(dentry)), dentry->d_name.name, 4147 + dentry->d_name.len); 4053 4148 if (ret) 4054 4149 goto out; 4055 4150 ··· 4079 4170 struct btrfs_key key; 4080 4171 u64 index; 4081 4172 int ret; 4082 - u64 dir_ino = btrfs_ino(dir); 4173 + u64 dir_ino = btrfs_ino(BTRFS_I(dir)); 4083 4174 4084 4175 path = btrfs_alloc_path(); 4085 4176 if (!path) ··· 4131 4222 } 4132 4223 btrfs_release_path(path); 4133 4224 4134 - ret = btrfs_delete_delayed_dir_index(trans, fs_info, dir, index); 4225 + ret = btrfs_delete_delayed_dir_index(trans, fs_info, BTRFS_I(dir), index); 4135 4226 if (ret) { 4136 4227 btrfs_abort_transaction(trans, ret); 4137 4228 goto out; ··· 4158 4249 4159 4250 if (inode->i_size > BTRFS_EMPTY_DIR_SIZE) 4160 4251 return -ENOTEMPTY; 4161 - if (btrfs_ino(inode) == BTRFS_FIRST_FREE_OBJECTID) 4252 + if (btrfs_ino(BTRFS_I(inode)) == BTRFS_FIRST_FREE_OBJECTID) 4162 4253 return -EPERM; 4163 4254 4164 4255 trans = __unlink_start_trans(dir); 4165 4256 if (IS_ERR(trans)) 4166 4257 return PTR_ERR(trans); 4167 4258 4168 - if (unlikely(btrfs_ino(inode) == BTRFS_EMPTY_SUBVOL_DIR_OBJECTID)) { 4259 + if (unlikely(btrfs_ino(BTRFS_I(inode)) == BTRFS_EMPTY_SUBVOL_DIR_OBJECTID)) { 4169 4260 err = btrfs_unlink_subvol(trans, root, dir, 4170 4261 BTRFS_I(inode)->location.objectid, 4171 4262 dentry->d_name.name, ··· 4180 4271 last_unlink_trans = BTRFS_I(inode)->last_unlink_trans; 4181 4272 4182 4273 /* now the directory is empty */ 4183 - err = btrfs_unlink_inode(trans, root, dir, d_inode(dentry), 4184 - dentry->d_name.name, dentry->d_name.len); 4274 + err = btrfs_unlink_inode(trans, root, BTRFS_I(dir), 4275 + BTRFS_I(d_inode(dentry)), dentry->d_name.name, 4276 + dentry->d_name.len); 4185 4277 if (!err) { 4186 4278 btrfs_i_size_write(inode, 0); 4187 4279 /* ··· 4308 4398 int extent_type = -1; 4309 4399 int ret; 4310 4400 int err = 0; 4311 - u64 ino = btrfs_ino(inode); 4401 + u64 ino = btrfs_ino(BTRFS_I(inode)); 4312 4402 u64 bytes_deleted = 0; 4313 4403 bool be_nice = 0; 4314 4404 bool should_throttle = 0; ··· 4347 4437 * items. 4348 4438 */ 4349 4439 if (min_type == 0 && root == BTRFS_I(inode)->root) 4350 - btrfs_kill_delayed_inode_items(inode); 4440 + btrfs_kill_delayed_inode_items(BTRFS_I(inode)); 4351 4441 4352 4442 key.objectid = ino; 4353 4443 key.offset = (u64)-1; ··· 4612 4702 4613 4703 btrfs_free_path(path); 4614 4704 4705 + if (err == 0) { 4706 + /* only inline file may have last_size != new_size */ 4707 + if (new_size >= fs_info->sectorsize || 4708 + new_size > fs_info->max_inline) 4709 + ASSERT(last_size == new_size); 4710 + } 4711 + 4615 4712 if (be_nice && bytes_deleted > SZ_32M) { 4616 4713 unsigned long updates = trans->delayed_ref_updates; 4617 4714 if (updates) { ··· 4787 4870 return ret; 4788 4871 } 4789 4872 4790 - ret = btrfs_insert_file_extent(trans, root, btrfs_ino(inode), offset, 4791 - 0, 0, len, 0, len, 0, 0, 0); 4873 + ret = btrfs_insert_file_extent(trans, root, btrfs_ino(BTRFS_I(inode)), 4874 + offset, 0, 0, len, 0, len, 0, 0, 0); 4792 4875 if (ret) 4793 4876 btrfs_abort_transaction(trans, ret); 4794 4877 else ··· 5004 5087 if (ret && inode->i_nlink) { 5005 5088 int err; 5006 5089 5090 + /* To get a stable disk_i_size */ 5091 + err = btrfs_wait_ordered_range(inode, 0, (u64)-1); 5092 + if (err) { 5093 + btrfs_orphan_del(NULL, inode); 5094 + return err; 5095 + } 5096 + 5007 5097 /* 5008 5098 * failed to truncate, disk_i_size is only adjusted down 5009 5099 * as we remove extents, so it should represent the true ··· 5206 5282 goto no_delete; 5207 5283 } 5208 5284 5209 - ret = btrfs_commit_inode_delayed_inode(inode); 5285 + ret = btrfs_commit_inode_delayed_inode(BTRFS_I(inode)); 5210 5286 if (ret) { 5211 5287 btrfs_orphan_del(NULL, inode); 5212 5288 goto no_delete; ··· 5326 5402 trans->block_rsv = &fs_info->trans_block_rsv; 5327 5403 if (!(root == fs_info->tree_root || 5328 5404 root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)) 5329 - btrfs_return_ino(root, btrfs_ino(inode)); 5405 + btrfs_return_ino(root, btrfs_ino(BTRFS_I(inode))); 5330 5406 5331 5407 btrfs_end_transaction(trans); 5332 5408 btrfs_btree_balance_dirty(fs_info); 5333 5409 no_delete: 5334 - btrfs_remove_delayed_node(inode); 5410 + btrfs_remove_delayed_node(BTRFS_I(inode)); 5335 5411 clear_inode(inode); 5336 5412 } 5337 5413 ··· 5353 5429 if (!path) 5354 5430 return -ENOMEM; 5355 5431 5356 - di = btrfs_lookup_dir_item(NULL, root, path, btrfs_ino(dir), name, 5357 - namelen, 0); 5432 + di = btrfs_lookup_dir_item(NULL, root, path, btrfs_ino(BTRFS_I(dir)), 5433 + name, namelen, 0); 5358 5434 if (IS_ERR(di)) 5359 5435 ret = PTR_ERR(di); 5360 5436 ··· 5409 5485 5410 5486 leaf = path->nodes[0]; 5411 5487 ref = btrfs_item_ptr(leaf, path->slots[0], struct btrfs_root_ref); 5412 - if (btrfs_root_ref_dirid(leaf, ref) != btrfs_ino(dir) || 5488 + if (btrfs_root_ref_dirid(leaf, ref) != btrfs_ino(BTRFS_I(dir)) || 5413 5489 btrfs_root_ref_name_len(leaf, ref) != dentry->d_name.len) 5414 5490 goto out; 5415 5491 ··· 5444 5520 struct rb_node **p; 5445 5521 struct rb_node *parent; 5446 5522 struct rb_node *new = &BTRFS_I(inode)->rb_node; 5447 - u64 ino = btrfs_ino(inode); 5523 + u64 ino = btrfs_ino(BTRFS_I(inode)); 5448 5524 5449 5525 if (inode_unhashed(inode)) 5450 5526 return; ··· 5455 5531 parent = *p; 5456 5532 entry = rb_entry(parent, struct btrfs_inode, rb_node); 5457 5533 5458 - if (ino < btrfs_ino(&entry->vfs_inode)) 5534 + if (ino < btrfs_ino(BTRFS_I(&entry->vfs_inode))) 5459 5535 p = &parent->rb_left; 5460 - else if (ino > btrfs_ino(&entry->vfs_inode)) 5536 + else if (ino > btrfs_ino(BTRFS_I(&entry->vfs_inode))) 5461 5537 p = &parent->rb_right; 5462 5538 else { 5463 5539 WARN_ON(!(entry->vfs_inode.i_state & ··· 5517 5593 prev = node; 5518 5594 entry = rb_entry(node, struct btrfs_inode, rb_node); 5519 5595 5520 - if (objectid < btrfs_ino(&entry->vfs_inode)) 5596 + if (objectid < btrfs_ino(BTRFS_I(&entry->vfs_inode))) 5521 5597 node = node->rb_left; 5522 - else if (objectid > btrfs_ino(&entry->vfs_inode)) 5598 + else if (objectid > btrfs_ino(BTRFS_I(&entry->vfs_inode))) 5523 5599 node = node->rb_right; 5524 5600 else 5525 5601 break; ··· 5527 5603 if (!node) { 5528 5604 while (prev) { 5529 5605 entry = rb_entry(prev, struct btrfs_inode, rb_node); 5530 - if (objectid <= btrfs_ino(&entry->vfs_inode)) { 5606 + if (objectid <= btrfs_ino(BTRFS_I(&entry->vfs_inode))) { 5531 5607 node = prev; 5532 5608 break; 5533 5609 } ··· 5536 5612 } 5537 5613 while (node) { 5538 5614 entry = rb_entry(node, struct btrfs_inode, rb_node); 5539 - objectid = btrfs_ino(&entry->vfs_inode) + 1; 5615 + objectid = btrfs_ino(BTRFS_I(&entry->vfs_inode)) + 1; 5540 5616 inode = igrab(&entry->vfs_inode); 5541 5617 if (inode) { 5542 5618 spin_unlock(&root->inode_lock); ··· 5720 5796 if (btrfs_root_refs(&root->root_item) == 0) 5721 5797 return 1; 5722 5798 5723 - if (btrfs_ino(inode) == BTRFS_EMPTY_SUBVOL_DIR_OBJECTID) 5799 + if (btrfs_ino(BTRFS_I(inode)) == BTRFS_EMPTY_SUBVOL_DIR_OBJECTID) 5724 5800 return 1; 5725 5801 } 5726 5802 return 0; ··· 5789 5865 5790 5866 key.type = BTRFS_DIR_INDEX_KEY; 5791 5867 key.offset = ctx->pos; 5792 - key.objectid = btrfs_ino(inode); 5868 + key.objectid = btrfs_ino(BTRFS_I(inode)); 5793 5869 5794 5870 ret = btrfs_search_slot(NULL, root, &key, path, 0, 0); 5795 5871 if (ret < 0) ··· 5986 6062 struct extent_buffer *leaf; 5987 6063 int ret; 5988 6064 5989 - key.objectid = btrfs_ino(inode); 6065 + key.objectid = btrfs_ino(BTRFS_I(inode)); 5990 6066 key.type = BTRFS_DIR_INDEX_KEY; 5991 6067 key.offset = (u64)-1; 5992 6068 ··· 6018 6094 leaf = path->nodes[0]; 6019 6095 btrfs_item_key_to_cpu(leaf, &found_key, path->slots[0]); 6020 6096 6021 - if (found_key.objectid != btrfs_ino(inode) || 6097 + if (found_key.objectid != btrfs_ino(BTRFS_I(inode)) || 6022 6098 found_key.type != BTRFS_DIR_INDEX_KEY) { 6023 6099 BTRFS_I(inode)->index_cnt = 2; 6024 6100 goto out; ··· 6039 6115 int ret = 0; 6040 6116 6041 6117 if (BTRFS_I(dir)->index_cnt == (u64)-1) { 6042 - ret = btrfs_inode_delayed_dir_index_count(dir); 6118 + ret = btrfs_inode_delayed_dir_index_count(BTRFS_I(dir)); 6043 6119 if (ret) { 6044 6120 ret = btrfs_set_inode_index_count(dir); 6045 6121 if (ret) ··· 6218 6294 if (ret) 6219 6295 btrfs_err(fs_info, 6220 6296 "error inheriting props for ino %llu (root %llu): %d", 6221 - btrfs_ino(inode), root->root_key.objectid, ret); 6297 + btrfs_ino(BTRFS_I(inode)), root->root_key.objectid, ret); 6222 6298 6223 6299 return inode; 6224 6300 ··· 6251 6327 int ret = 0; 6252 6328 struct btrfs_key key; 6253 6329 struct btrfs_root *root = BTRFS_I(parent_inode)->root; 6254 - u64 ino = btrfs_ino(inode); 6255 - u64 parent_ino = btrfs_ino(parent_inode); 6330 + u64 ino = btrfs_ino(BTRFS_I(inode)); 6331 + u64 parent_ino = btrfs_ino(BTRFS_I(parent_inode)); 6256 6332 6257 6333 if (unlikely(ino == BTRFS_FIRST_FREE_OBJECTID)) { 6258 6334 memcpy(&key, &BTRFS_I(inode)->root->root_key, sizeof(key)); ··· 6351 6427 goto out_unlock; 6352 6428 6353 6429 inode = btrfs_new_inode(trans, root, dir, dentry->d_name.name, 6354 - dentry->d_name.len, btrfs_ino(dir), objectid, 6355 - mode, &index); 6430 + dentry->d_name.len, btrfs_ino(BTRFS_I(dir)), objectid, 6431 + mode, &index); 6356 6432 if (IS_ERR(inode)) { 6357 6433 err = PTR_ERR(inode); 6358 6434 goto out_unlock; ··· 6423 6499 goto out_unlock; 6424 6500 6425 6501 inode = btrfs_new_inode(trans, root, dir, dentry->d_name.name, 6426 - dentry->d_name.len, btrfs_ino(dir), objectid, 6427 - mode, &index); 6502 + dentry->d_name.len, btrfs_ino(BTRFS_I(dir)), objectid, 6503 + mode, &index); 6428 6504 if (IS_ERR(inode)) { 6429 6505 err = PTR_ERR(inode); 6430 6506 goto out_unlock; ··· 6533 6609 goto fail; 6534 6610 } 6535 6611 d_instantiate(dentry, inode); 6536 - btrfs_log_new_name(trans, inode, NULL, parent); 6612 + btrfs_log_new_name(trans, BTRFS_I(inode), NULL, parent); 6537 6613 } 6538 6614 6539 6615 btrfs_balance_delayed_items(fs_info); ··· 6573 6649 goto out_fail; 6574 6650 6575 6651 inode = btrfs_new_inode(trans, root, dir, dentry->d_name.name, 6576 - dentry->d_name.len, btrfs_ino(dir), objectid, 6577 - S_IFDIR | mode, &index); 6652 + dentry->d_name.len, btrfs_ino(BTRFS_I(dir)), objectid, 6653 + S_IFDIR | mode, &index); 6578 6654 if (IS_ERR(inode)) { 6579 6655 err = PTR_ERR(inode); 6580 6656 goto out_fail; ··· 6734 6810 int err = 0; 6735 6811 u64 extent_start = 0; 6736 6812 u64 extent_end = 0; 6737 - u64 objectid = btrfs_ino(inode); 6813 + u64 objectid = btrfs_ino(BTRFS_I(inode)); 6738 6814 u32 found_type; 6739 6815 struct btrfs_path *path = NULL; 6740 6816 struct btrfs_root *root = BTRFS_I(inode)->root; ··· 6992 7068 write_unlock(&em_tree->lock); 6993 7069 out: 6994 7070 6995 - trace_btrfs_get_extent(root, inode, em); 7071 + trace_btrfs_get_extent(root, BTRFS_I(inode), em); 6996 7072 6997 7073 btrfs_free_path(path); 6998 7074 if (trans) { ··· 7149 7225 int ret; 7150 7226 7151 7227 if (type != BTRFS_ORDERED_NOCOW) { 7152 - em = create_pinned_em(inode, start, len, orig_start, 7153 - block_start, block_len, orig_block_len, 7154 - ram_bytes, type); 7228 + em = create_io_em(inode, start, len, orig_start, 7229 + block_start, block_len, orig_block_len, 7230 + ram_bytes, 7231 + BTRFS_COMPRESS_NONE, /* compress_type */ 7232 + type); 7155 7233 if (IS_ERR(em)) 7156 7234 goto out; 7157 7235 } ··· 7190 7264 7191 7265 em = btrfs_create_dio_extent(inode, start, ins.offset, start, 7192 7266 ins.objectid, ins.offset, ins.offset, 7193 - ins.offset, 0); 7267 + ins.offset, BTRFS_ORDERED_REGULAR); 7194 7268 btrfs_dec_block_group_reservations(fs_info, ins.objectid); 7195 7269 if (IS_ERR(em)) 7196 7270 btrfs_free_reserved_extent(fs_info, ins.objectid, ··· 7208 7282 u64 *ram_bytes) 7209 7283 { 7210 7284 struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb); 7211 - struct btrfs_trans_handle *trans; 7212 7285 struct btrfs_path *path; 7213 7286 int ret; 7214 7287 struct extent_buffer *leaf; ··· 7227 7302 if (!path) 7228 7303 return -ENOMEM; 7229 7304 7230 - ret = btrfs_lookup_file_extent(NULL, root, path, btrfs_ino(inode), 7231 - offset, 0); 7305 + ret = btrfs_lookup_file_extent(NULL, root, path, 7306 + btrfs_ino(BTRFS_I(inode)), offset, 0); 7232 7307 if (ret < 0) 7233 7308 goto out; 7234 7309 ··· 7244 7319 ret = 0; 7245 7320 leaf = path->nodes[0]; 7246 7321 btrfs_item_key_to_cpu(leaf, &key, slot); 7247 - if (key.objectid != btrfs_ino(inode) || 7322 + if (key.objectid != btrfs_ino(BTRFS_I(inode)) || 7248 7323 key.type != BTRFS_EXTENT_DATA_KEY) { 7249 7324 /* not our file or wrong item type, must cow */ 7250 7325 goto out; ··· 7310 7385 * look for other files referencing this extent, if we 7311 7386 * find any we must cow 7312 7387 */ 7313 - trans = btrfs_join_transaction(root); 7314 - if (IS_ERR(trans)) { 7315 - ret = 0; 7316 - goto out; 7317 - } 7318 7388 7319 - ret = btrfs_cross_ref_exist(trans, root, btrfs_ino(inode), 7389 + ret = btrfs_cross_ref_exist(root, btrfs_ino(BTRFS_I(inode)), 7320 7390 key.offset - backref_offset, disk_bytenr); 7321 - btrfs_end_transaction(trans); 7322 7391 if (ret) { 7323 7392 ret = 0; 7324 7393 goto out; ··· 7489 7570 return ret; 7490 7571 } 7491 7572 7492 - static struct extent_map *create_pinned_em(struct inode *inode, u64 start, 7493 - u64 len, u64 orig_start, 7494 - u64 block_start, u64 block_len, 7495 - u64 orig_block_len, u64 ram_bytes, 7496 - int type) 7573 + /* The callers of this must take lock_extent() */ 7574 + static struct extent_map *create_io_em(struct inode *inode, u64 start, u64 len, 7575 + u64 orig_start, u64 block_start, 7576 + u64 block_len, u64 orig_block_len, 7577 + u64 ram_bytes, int compress_type, 7578 + int type) 7497 7579 { 7498 7580 struct extent_map_tree *em_tree; 7499 7581 struct extent_map *em; 7500 7582 struct btrfs_root *root = BTRFS_I(inode)->root; 7501 7583 int ret; 7584 + 7585 + ASSERT(type == BTRFS_ORDERED_PREALLOC || 7586 + type == BTRFS_ORDERED_COMPRESSED || 7587 + type == BTRFS_ORDERED_NOCOW || 7588 + type == BTRFS_ORDERED_REGULAR); 7502 7589 7503 7590 em_tree = &BTRFS_I(inode)->extent_tree; 7504 7591 em = alloc_extent_map(); ··· 7513 7588 7514 7589 em->start = start; 7515 7590 em->orig_start = orig_start; 7516 - em->mod_start = start; 7517 - em->mod_len = len; 7518 7591 em->len = len; 7519 7592 em->block_len = block_len; 7520 7593 em->block_start = block_start; ··· 7521 7598 em->ram_bytes = ram_bytes; 7522 7599 em->generation = -1; 7523 7600 set_bit(EXTENT_FLAG_PINNED, &em->flags); 7524 - if (type == BTRFS_ORDERED_PREALLOC) 7601 + if (type == BTRFS_ORDERED_PREALLOC) { 7525 7602 set_bit(EXTENT_FLAG_FILLING, &em->flags); 7603 + } else if (type == BTRFS_ORDERED_COMPRESSED) { 7604 + set_bit(EXTENT_FLAG_COMPRESSED, &em->flags); 7605 + em->compress_type = compress_type; 7606 + } 7526 7607 7527 7608 do { 7528 7609 btrfs_drop_extent_cache(inode, em->start, ··· 7534 7607 write_lock(&em_tree->lock); 7535 7608 ret = add_extent_mapping(em_tree, em, 1); 7536 7609 write_unlock(&em_tree->lock); 7610 + /* 7611 + * The caller has taken lock_extent(), who could race with us 7612 + * to add em? 7613 + */ 7537 7614 } while (ret == -EEXIST); 7538 7615 7539 7616 if (ret) { ··· 7545 7614 return ERR_PTR(ret); 7546 7615 } 7547 7616 7617 + /* em got 2 refs now, callers needs to do free_extent_map once. */ 7548 7618 return em; 7549 7619 } 7550 7620 ··· 7553 7621 struct btrfs_dio_data *dio_data, 7554 7622 const u64 len) 7555 7623 { 7556 - unsigned num_extents; 7624 + unsigned num_extents = count_max_extents(len); 7557 7625 7558 - num_extents = (unsigned) div64_u64(len + BTRFS_MAX_EXTENT_SIZE - 1, 7559 - BTRFS_MAX_EXTENT_SIZE); 7560 7626 /* 7561 7627 * If we have an outstanding_extents count still set then we're 7562 7628 * within our reservation, otherwise we need to adjust our inode ··· 7734 7804 * Need to update the i_size under the extent lock so buffered 7735 7805 * readers will get the updated i_size when we unlock. 7736 7806 */ 7737 - if (start + len > i_size_read(inode)) 7807 + if (!dio_data->overwrite && start + len > i_size_read(inode)) 7738 7808 i_size_write(inode, start + len); 7739 7809 7740 7810 adjust_dio_outstanding_extents(inode, dio_data, len); ··· 8184 8254 if (err) 8185 8255 btrfs_warn(BTRFS_I(dip->inode)->root->fs_info, 8186 8256 "direct IO failed ino %llu rw %d,%u sector %#Lx len %u err no %d", 8187 - btrfs_ino(dip->inode), bio_op(bio), bio->bi_opf, 8257 + btrfs_ino(BTRFS_I(dip->inode)), bio_op(bio), 8258 + bio->bi_opf, 8188 8259 (unsigned long long)bio->bi_iter.bi_sector, 8189 8260 bio->bi_iter.bi_size, err); 8190 8261 ··· 8610 8679 * not unlock the i_mutex at this case. 8611 8680 */ 8612 8681 if (offset + count <= inode->i_size) { 8682 + dio_data.overwrite = 1; 8613 8683 inode_unlock(inode); 8614 8684 relock = true; 8615 8685 } 8616 8686 ret = btrfs_delalloc_reserve_space(inode, offset, count); 8617 8687 if (ret) 8618 8688 goto out; 8619 - dio_data.outstanding_extents = div64_u64(count + 8620 - BTRFS_MAX_EXTENT_SIZE - 1, 8621 - BTRFS_MAX_EXTENT_SIZE); 8689 + dio_data.outstanding_extents = count_max_extents(count); 8622 8690 8623 8691 /* 8624 8692 * We need to know how many extents we reserved so that we can ··· 8761 8831 { 8762 8832 if (PageWriteback(page) || PageDirty(page)) 8763 8833 return 0; 8764 - return __btrfs_releasepage(page, gfp_flags & GFP_NOFS); 8834 + return __btrfs_releasepage(page, gfp_flags); 8765 8835 } 8766 8836 8767 8837 static void btrfs_invalidatepage(struct page *page, unsigned int offset, ··· 8962 9032 * we can't set the delalloc bits if there are pending ordered 8963 9033 * extents. Drop our locks and wait for them to finish 8964 9034 */ 8965 - ordered = btrfs_lookup_ordered_range(inode, page_start, page_end); 9035 + ordered = btrfs_lookup_ordered_range(inode, page_start, PAGE_SIZE); 8966 9036 if (ordered) { 8967 9037 unlock_extent_cached(io_tree, page_start, page_end, 8968 9038 &cached_state, GFP_NOFS); ··· 8986 9056 } 8987 9057 8988 9058 /* 8989 - * XXX - page_mkwrite gets called every time the page is dirtied, even 8990 - * if it was already dirty, so for space accounting reasons we need to 8991 - * clear any delalloc bits for the range we are fixing to save. There 8992 - * is probably a better way to do this, but for now keep consistent with 8993 - * prepare_pages in the normal write path. 9059 + * page_mkwrite gets called when the page is firstly dirtied after it's 9060 + * faulted in, but write(2) could also dirty a page and set delalloc 9061 + * bits, thus in this case for space account reason, we still need to 9062 + * clear any delalloc bits within this page range since we have to 9063 + * reserve data&meta space before lock_page() (see above comments). 8994 9064 */ 8995 9065 clear_extent_bit(&BTRFS_I(inode)->io_tree, page_start, end, 8996 9066 EXTENT_DIRTY | EXTENT_DELALLOC | ··· 9314 9384 if (test_bit(BTRFS_INODE_HAS_ORPHAN_ITEM, 9315 9385 &BTRFS_I(inode)->runtime_flags)) { 9316 9386 btrfs_info(fs_info, "inode %llu still on the orphan list", 9317 - btrfs_ino(inode)); 9387 + btrfs_ino(BTRFS_I(inode))); 9318 9388 atomic_dec(&root->orphan_inodes); 9319 9389 } 9320 9390 ··· 9443 9513 struct inode *old_inode = old_dentry->d_inode; 9444 9514 struct timespec ctime = current_time(old_inode); 9445 9515 struct dentry *parent; 9446 - u64 old_ino = btrfs_ino(old_inode); 9447 - u64 new_ino = btrfs_ino(new_inode); 9516 + u64 old_ino = btrfs_ino(BTRFS_I(old_inode)); 9517 + u64 new_ino = btrfs_ino(BTRFS_I(new_inode)); 9448 9518 u64 old_idx = 0; 9449 9519 u64 new_idx = 0; 9450 9520 u64 root_objectid; ··· 9501 9571 new_dentry->d_name.name, 9502 9572 new_dentry->d_name.len, 9503 9573 old_ino, 9504 - btrfs_ino(new_dir), old_idx); 9574 + btrfs_ino(BTRFS_I(new_dir)), 9575 + old_idx); 9505 9576 if (ret) 9506 9577 goto out_fail; 9507 9578 } ··· 9518 9587 old_dentry->d_name.name, 9519 9588 old_dentry->d_name.len, 9520 9589 new_ino, 9521 - btrfs_ino(old_dir), new_idx); 9590 + btrfs_ino(BTRFS_I(old_dir)), 9591 + new_idx); 9522 9592 if (ret) 9523 9593 goto out_fail; 9524 9594 } ··· 9535 9603 new_inode->i_ctime = ctime; 9536 9604 9537 9605 if (old_dentry->d_parent != new_dentry->d_parent) { 9538 - btrfs_record_unlink_dir(trans, old_dir, old_inode, 1); 9539 - btrfs_record_unlink_dir(trans, new_dir, new_inode, 1); 9606 + btrfs_record_unlink_dir(trans, BTRFS_I(old_dir), 9607 + BTRFS_I(old_inode), 1); 9608 + btrfs_record_unlink_dir(trans, BTRFS_I(new_dir), 9609 + BTRFS_I(new_inode), 1); 9540 9610 } 9541 9611 9542 9612 /* src is a subvolume */ ··· 9549 9615 old_dentry->d_name.name, 9550 9616 old_dentry->d_name.len); 9551 9617 } else { /* src is an inode */ 9552 - ret = __btrfs_unlink_inode(trans, root, old_dir, 9553 - old_dentry->d_inode, 9618 + ret = __btrfs_unlink_inode(trans, root, BTRFS_I(old_dir), 9619 + BTRFS_I(old_dentry->d_inode), 9554 9620 old_dentry->d_name.name, 9555 9621 old_dentry->d_name.len); 9556 9622 if (!ret) ··· 9569 9635 new_dentry->d_name.name, 9570 9636 new_dentry->d_name.len); 9571 9637 } else { /* dest is an inode */ 9572 - ret = __btrfs_unlink_inode(trans, dest, new_dir, 9573 - new_dentry->d_inode, 9638 + ret = __btrfs_unlink_inode(trans, dest, BTRFS_I(new_dir), 9639 + BTRFS_I(new_dentry->d_inode), 9574 9640 new_dentry->d_name.name, 9575 9641 new_dentry->d_name.len); 9576 9642 if (!ret) ··· 9604 9670 9605 9671 if (root_log_pinned) { 9606 9672 parent = new_dentry->d_parent; 9607 - btrfs_log_new_name(trans, old_inode, old_dir, parent); 9673 + btrfs_log_new_name(trans, BTRFS_I(old_inode), BTRFS_I(old_dir), 9674 + parent); 9608 9675 btrfs_end_log_trans(root); 9609 9676 root_log_pinned = false; 9610 9677 } 9611 9678 if (dest_log_pinned) { 9612 9679 parent = old_dentry->d_parent; 9613 - btrfs_log_new_name(trans, new_inode, new_dir, parent); 9680 + btrfs_log_new_name(trans, BTRFS_I(new_inode), BTRFS_I(new_dir), 9681 + parent); 9614 9682 btrfs_end_log_trans(dest); 9615 9683 dest_log_pinned = false; 9616 9684 } ··· 9629 9693 * allow the tasks to sync it. 9630 9694 */ 9631 9695 if (ret && (root_log_pinned || dest_log_pinned)) { 9632 - if (btrfs_inode_in_log(old_dir, fs_info->generation) || 9633 - btrfs_inode_in_log(new_dir, fs_info->generation) || 9634 - btrfs_inode_in_log(old_inode, fs_info->generation) || 9696 + if (btrfs_inode_in_log(BTRFS_I(old_dir), fs_info->generation) || 9697 + btrfs_inode_in_log(BTRFS_I(new_dir), fs_info->generation) || 9698 + btrfs_inode_in_log(BTRFS_I(old_inode), fs_info->generation) || 9635 9699 (new_inode && 9636 - btrfs_inode_in_log(new_inode, fs_info->generation))) 9700 + btrfs_inode_in_log(BTRFS_I(new_inode), fs_info->generation))) 9637 9701 btrfs_set_log_full_commit(fs_info, trans); 9638 9702 9639 9703 if (root_log_pinned) { ··· 9672 9736 inode = btrfs_new_inode(trans, root, dir, 9673 9737 dentry->d_name.name, 9674 9738 dentry->d_name.len, 9675 - btrfs_ino(dir), 9739 + btrfs_ino(BTRFS_I(dir)), 9676 9740 objectid, 9677 9741 S_IFCHR | WHITEOUT_MODE, 9678 9742 &index); ··· 9720 9784 u64 index = 0; 9721 9785 u64 root_objectid; 9722 9786 int ret; 9723 - u64 old_ino = btrfs_ino(old_inode); 9787 + u64 old_ino = btrfs_ino(BTRFS_I(old_inode)); 9724 9788 bool log_pinned = false; 9725 9789 9726 - if (btrfs_ino(new_dir) == BTRFS_EMPTY_SUBVOL_DIR_OBJECTID) 9790 + if (btrfs_ino(BTRFS_I(new_dir)) == BTRFS_EMPTY_SUBVOL_DIR_OBJECTID) 9727 9791 return -EPERM; 9728 9792 9729 9793 /* we only allow rename subvolume link between subvolumes */ ··· 9731 9795 return -EXDEV; 9732 9796 9733 9797 if (old_ino == BTRFS_EMPTY_SUBVOL_DIR_OBJECTID || 9734 - (new_inode && btrfs_ino(new_inode) == BTRFS_FIRST_FREE_OBJECTID)) 9798 + (new_inode && btrfs_ino(BTRFS_I(new_inode)) == BTRFS_FIRST_FREE_OBJECTID)) 9735 9799 return -ENOTEMPTY; 9736 9800 9737 9801 if (S_ISDIR(old_inode->i_mode) && new_inode && ··· 9806 9870 new_dentry->d_name.name, 9807 9871 new_dentry->d_name.len, 9808 9872 old_ino, 9809 - btrfs_ino(new_dir), index); 9873 + btrfs_ino(BTRFS_I(new_dir)), index); 9810 9874 if (ret) 9811 9875 goto out_fail; 9812 9876 } ··· 9819 9883 old_inode->i_ctime = current_time(old_dir); 9820 9884 9821 9885 if (old_dentry->d_parent != new_dentry->d_parent) 9822 - btrfs_record_unlink_dir(trans, old_dir, old_inode, 1); 9886 + btrfs_record_unlink_dir(trans, BTRFS_I(old_dir), 9887 + BTRFS_I(old_inode), 1); 9823 9888 9824 9889 if (unlikely(old_ino == BTRFS_FIRST_FREE_OBJECTID)) { 9825 9890 root_objectid = BTRFS_I(old_inode)->root->root_key.objectid; ··· 9828 9891 old_dentry->d_name.name, 9829 9892 old_dentry->d_name.len); 9830 9893 } else { 9831 - ret = __btrfs_unlink_inode(trans, root, old_dir, 9832 - d_inode(old_dentry), 9894 + ret = __btrfs_unlink_inode(trans, root, BTRFS_I(old_dir), 9895 + BTRFS_I(d_inode(old_dentry)), 9833 9896 old_dentry->d_name.name, 9834 9897 old_dentry->d_name.len); 9835 9898 if (!ret) ··· 9843 9906 if (new_inode) { 9844 9907 inode_inc_iversion(new_inode); 9845 9908 new_inode->i_ctime = current_time(new_inode); 9846 - if (unlikely(btrfs_ino(new_inode) == 9909 + if (unlikely(btrfs_ino(BTRFS_I(new_inode)) == 9847 9910 BTRFS_EMPTY_SUBVOL_DIR_OBJECTID)) { 9848 9911 root_objectid = BTRFS_I(new_inode)->location.objectid; 9849 9912 ret = btrfs_unlink_subvol(trans, dest, new_dir, ··· 9852 9915 new_dentry->d_name.len); 9853 9916 BUG_ON(new_inode->i_nlink == 0); 9854 9917 } else { 9855 - ret = btrfs_unlink_inode(trans, dest, new_dir, 9856 - d_inode(new_dentry), 9918 + ret = btrfs_unlink_inode(trans, dest, BTRFS_I(new_dir), 9919 + BTRFS_I(d_inode(new_dentry)), 9857 9920 new_dentry->d_name.name, 9858 9921 new_dentry->d_name.len); 9859 9922 } ··· 9879 9942 if (log_pinned) { 9880 9943 struct dentry *parent = new_dentry->d_parent; 9881 9944 9882 - btrfs_log_new_name(trans, old_inode, old_dir, parent); 9945 + btrfs_log_new_name(trans, BTRFS_I(old_inode), BTRFS_I(old_dir), 9946 + parent); 9883 9947 btrfs_end_log_trans(root); 9884 9948 log_pinned = false; 9885 9949 } ··· 9907 9969 * allow the tasks to sync it. 9908 9970 */ 9909 9971 if (ret && log_pinned) { 9910 - if (btrfs_inode_in_log(old_dir, fs_info->generation) || 9911 - btrfs_inode_in_log(new_dir, fs_info->generation) || 9912 - btrfs_inode_in_log(old_inode, fs_info->generation) || 9972 + if (btrfs_inode_in_log(BTRFS_I(old_dir), fs_info->generation) || 9973 + btrfs_inode_in_log(BTRFS_I(new_dir), fs_info->generation) || 9974 + btrfs_inode_in_log(BTRFS_I(old_inode), fs_info->generation) || 9913 9975 (new_inode && 9914 - btrfs_inode_in_log(new_inode, fs_info->generation))) 9976 + btrfs_inode_in_log(BTRFS_I(new_inode), fs_info->generation))) 9915 9977 btrfs_set_log_full_commit(fs_info, trans); 9916 9978 9917 9979 btrfs_end_log_trans(root); ··· 10175 10237 goto out_unlock; 10176 10238 10177 10239 inode = btrfs_new_inode(trans, root, dir, dentry->d_name.name, 10178 - dentry->d_name.len, btrfs_ino(dir), objectid, 10179 - S_IFLNK|S_IRWXUGO, &index); 10240 + dentry->d_name.len, btrfs_ino(BTRFS_I(dir)), 10241 + objectid, S_IFLNK|S_IRWXUGO, &index); 10180 10242 if (IS_ERR(inode)) { 10181 10243 err = PTR_ERR(inode); 10182 10244 goto out_unlock; ··· 10202 10264 err = -ENOMEM; 10203 10265 goto out_unlock_inode; 10204 10266 } 10205 - key.objectid = btrfs_ino(inode); 10267 + key.objectid = btrfs_ino(BTRFS_I(inode)); 10206 10268 key.offset = 0; 10207 10269 key.type = BTRFS_EXTENT_DATA_KEY; 10208 10270 datasize = btrfs_file_extent_calc_inline_size(name_len); ··· 10455 10517 goto out; 10456 10518 10457 10519 inode = btrfs_new_inode(trans, root, dir, NULL, 0, 10458 - btrfs_ino(dir), objectid, mode, &index); 10520 + btrfs_ino(BTRFS_I(dir)), objectid, mode, &index); 10459 10521 if (IS_ERR(inode)) { 10460 10522 ret = PTR_ERR(inode); 10461 10523 inode = NULL;
+51 -58
fs/btrfs/ioctl.c
··· 395 395 q = bdev_get_queue(device->bdev); 396 396 if (blk_queue_discard(q)) { 397 397 num_devices++; 398 - minlen = min((u64)q->limits.discard_granularity, 398 + minlen = min_t(u64, q->limits.discard_granularity, 399 399 minlen); 400 400 } 401 401 } ··· 487 487 trans = btrfs_start_transaction(root, 0); 488 488 if (IS_ERR(trans)) { 489 489 ret = PTR_ERR(trans); 490 - btrfs_subvolume_release_metadata(fs_info, &block_rsv, 491 - qgroup_reserved); 490 + btrfs_subvolume_release_metadata(fs_info, &block_rsv); 492 491 goto fail_free; 493 492 } 494 493 trans->block_rsv = &block_rsv; ··· 600 601 601 602 ret = btrfs_add_root_ref(trans, fs_info, 602 603 objectid, root->root_key.objectid, 603 - btrfs_ino(dir), index, name, namelen); 604 + btrfs_ino(BTRFS_I(dir)), index, name, namelen); 604 605 BUG_ON(ret); 605 606 606 607 ret = btrfs_uuid_tree_add(trans, fs_info, root_item->uuid, ··· 612 613 kfree(root_item); 613 614 trans->block_rsv = NULL; 614 615 trans->bytes_reserved = 0; 615 - btrfs_subvolume_release_metadata(fs_info, &block_rsv, qgroup_reserved); 616 + btrfs_subvolume_release_metadata(fs_info, &block_rsv); 616 617 617 618 if (async_transid) { 618 619 *async_transid = trans->transid; ··· 656 657 } 657 658 658 659 static int create_snapshot(struct btrfs_root *root, struct inode *dir, 659 - struct dentry *dentry, char *name, int namelen, 660 + struct dentry *dentry, 660 661 u64 *async_transid, bool readonly, 661 662 struct btrfs_qgroup_inherit *inherit) 662 663 { ··· 669 670 if (!test_bit(BTRFS_ROOT_REF_COWS, &root->state)) 670 671 return -EINVAL; 671 672 672 - pending_snapshot = kzalloc(sizeof(*pending_snapshot), GFP_NOFS); 673 + pending_snapshot = kzalloc(sizeof(*pending_snapshot), GFP_KERNEL); 673 674 if (!pending_snapshot) 674 675 return -ENOMEM; 675 676 676 677 pending_snapshot->root_item = kzalloc(sizeof(struct btrfs_root_item), 677 - GFP_NOFS); 678 + GFP_KERNEL); 678 679 pending_snapshot->path = btrfs_alloc_path(); 679 680 if (!pending_snapshot->root_item || !pending_snapshot->path) { 680 681 ret = -ENOMEM; ··· 752 753 d_instantiate(dentry, inode); 753 754 ret = 0; 754 755 fail: 755 - btrfs_subvolume_release_metadata(fs_info, 756 - &pending_snapshot->block_rsv, 757 - pending_snapshot->qgroup_reserved); 756 + btrfs_subvolume_release_metadata(fs_info, &pending_snapshot->block_rsv); 758 757 dec_and_free: 759 758 if (atomic_dec_and_test(&root->will_be_snapshoted)) 760 759 wake_up_atomic_t(&root->will_be_snapshoted); ··· 871 874 goto out_up_read; 872 875 873 876 if (snap_src) { 874 - error = create_snapshot(snap_src, dir, dentry, name, namelen, 877 + error = create_snapshot(snap_src, dir, dentry, 875 878 async_transid, readonly, inherit); 876 879 } else { 877 880 error = create_subvol(dir, dentry, name, namelen, ··· 938 941 struct btrfs_file_extent_item *extent; 939 942 int type; 940 943 int ret; 941 - u64 ino = btrfs_ino(inode); 944 + u64 ino = btrfs_ino(BTRFS_I(inode)); 942 945 943 946 path = btrfs_alloc_path(); 944 947 if (!path) ··· 1777 1780 int ret = 0; 1778 1781 u64 flags = 0; 1779 1782 1780 - if (btrfs_ino(inode) != BTRFS_FIRST_FREE_OBJECTID) 1783 + if (btrfs_ino(BTRFS_I(inode)) != BTRFS_FIRST_FREE_OBJECTID) 1781 1784 return -EINVAL; 1782 1785 1783 1786 down_read(&fs_info->subvol_sem); ··· 1809 1812 if (ret) 1810 1813 goto out; 1811 1814 1812 - if (btrfs_ino(inode) != BTRFS_FIRST_FREE_OBJECTID) { 1815 + if (btrfs_ino(BTRFS_I(inode)) != BTRFS_FIRST_FREE_OBJECTID) { 1813 1816 ret = -EINVAL; 1814 1817 goto out_drop_write; 1815 1818 } ··· 2443 2446 if (err) 2444 2447 goto out_dput; 2445 2448 2446 - if (btrfs_ino(inode) != BTRFS_FIRST_FREE_OBJECTID) { 2449 + if (btrfs_ino(BTRFS_I(inode)) != BTRFS_FIRST_FREE_OBJECTID) { 2447 2450 err = -EINVAL; 2448 2451 goto out_dput; 2449 2452 } ··· 2494 2497 trans->block_rsv = &block_rsv; 2495 2498 trans->bytes_reserved = block_rsv.size; 2496 2499 2497 - btrfs_record_snapshot_destroy(trans, dir); 2500 + btrfs_record_snapshot_destroy(trans, BTRFS_I(dir)); 2498 2501 2499 2502 ret = btrfs_unlink_subvol(trans, root, dir, 2500 2503 dest->root_key.objectid, ··· 2552 2555 err = ret; 2553 2556 inode->i_flags |= S_DEAD; 2554 2557 out_release: 2555 - btrfs_subvolume_release_metadata(fs_info, &block_rsv, qgroup_reserved); 2558 + btrfs_subvolume_release_metadata(fs_info, &block_rsv); 2556 2559 out_up_write: 2557 2560 up_write(&fs_info->subvol_sem); 2558 2561 if (err) { ··· 2610 2613 goto out; 2611 2614 } 2612 2615 ret = btrfs_defrag_root(root); 2613 - if (ret) 2614 - goto out; 2615 - ret = btrfs_defrag_root(root->fs_info->extent_root); 2616 2616 break; 2617 2617 case S_IFREG: 2618 2618 if (!(file->f_mode & FMODE_WRITE)) { ··· 3041 3047 cmp->src_pages = src_pgarr; 3042 3048 cmp->dst_pages = dst_pgarr; 3043 3049 3044 - ret = gather_extent_pages(src, cmp->src_pages, cmp->num_pages, loff); 3050 + /* 3051 + * If deduping ranges in the same inode, locking rules make it mandatory 3052 + * to always lock pages in ascending order to avoid deadlocks with 3053 + * concurrent tasks (such as starting writeback/delalloc). 3054 + */ 3055 + if (src == dst && dst_loff < loff) { 3056 + swap(src_pgarr, dst_pgarr); 3057 + swap(loff, dst_loff); 3058 + } 3059 + 3060 + ret = gather_extent_pages(src, src_pgarr, cmp->num_pages, loff); 3045 3061 if (ret) 3046 3062 goto out; 3047 3063 3048 - ret = gather_extent_pages(dst, cmp->dst_pages, cmp->num_pages, dst_loff); 3064 + ret = gather_extent_pages(dst, dst_pgarr, cmp->num_pages, dst_loff); 3049 3065 3050 3066 out: 3051 3067 if (ret) ··· 3063 3059 return 0; 3064 3060 } 3065 3061 3066 - static int btrfs_cmp_data(struct inode *src, u64 loff, struct inode *dst, 3067 - u64 dst_loff, u64 len, struct cmp_pages *cmp) 3062 + static int btrfs_cmp_data(u64 len, struct cmp_pages *cmp) 3068 3063 { 3069 3064 int ret = 0; 3070 3065 int i; ··· 3131 3128 int ret; 3132 3129 u64 len = olen; 3133 3130 struct cmp_pages cmp; 3134 - int same_inode = 0; 3131 + bool same_inode = (src == dst); 3135 3132 u64 same_lock_start = 0; 3136 3133 u64 same_lock_len = 0; 3137 - 3138 - if (src == dst) 3139 - same_inode = 1; 3140 3134 3141 3135 if (len == 0) 3142 3136 return 0; 3143 3137 3144 - if (same_inode) { 3138 + if (same_inode) 3145 3139 inode_lock(src); 3140 + else 3141 + btrfs_double_inode_lock(src, dst); 3146 3142 3147 - ret = extent_same_check_offsets(src, loff, &len, olen); 3148 - if (ret) 3149 - goto out_unlock; 3150 - ret = extent_same_check_offsets(src, dst_loff, &len, olen); 3151 - if (ret) 3152 - goto out_unlock; 3143 + ret = extent_same_check_offsets(src, loff, &len, olen); 3144 + if (ret) 3145 + goto out_unlock; 3153 3146 3147 + ret = extent_same_check_offsets(dst, dst_loff, &len, olen); 3148 + if (ret) 3149 + goto out_unlock; 3150 + 3151 + if (same_inode) { 3154 3152 /* 3155 3153 * Single inode case wants the same checks, except we 3156 3154 * don't want our length pushed out past i_size as ··· 3179 3175 3180 3176 same_lock_start = min_t(u64, loff, dst_loff); 3181 3177 same_lock_len = max_t(u64, loff, dst_loff) + len - same_lock_start; 3182 - } else { 3183 - btrfs_double_inode_lock(src, dst); 3184 - 3185 - ret = extent_same_check_offsets(src, loff, &len, olen); 3186 - if (ret) 3187 - goto out_unlock; 3188 - 3189 - ret = extent_same_check_offsets(dst, dst_loff, &len, olen); 3190 - if (ret) 3191 - goto out_unlock; 3192 3178 } 3193 3179 3194 3180 /* don't make the dst file partly checksummed */ ··· 3230 3236 } 3231 3237 3232 3238 /* pass original length for comparison so we stay within i_size */ 3233 - ret = btrfs_cmp_data(src, loff, dst, dst_loff, olen, &cmp); 3239 + ret = btrfs_cmp_data(olen, &cmp); 3234 3240 if (ret == 0) 3235 3241 ret = btrfs_clone(src, dst, loff, olen, len, dst_loff, 1); 3236 3242 ··· 3393 3399 * data into the destination inode's inline extent if the later is greater then 3394 3400 * the former. 3395 3401 */ 3396 - static int clone_copy_inline_extent(struct inode *src, 3397 - struct inode *dst, 3402 + static int clone_copy_inline_extent(struct inode *dst, 3398 3403 struct btrfs_trans_handle *trans, 3399 3404 struct btrfs_path *path, 3400 3405 struct btrfs_key *new_key, ··· 3413 3420 if (new_key->offset > 0) 3414 3421 return -EOPNOTSUPP; 3415 3422 3416 - key.objectid = btrfs_ino(dst); 3423 + key.objectid = btrfs_ino(BTRFS_I(dst)); 3417 3424 key.type = BTRFS_EXTENT_DATA_KEY; 3418 3425 key.offset = 0; 3419 3426 ret = btrfs_search_slot(NULL, root, &key, path, 0, 0); ··· 3428 3435 goto copy_inline_extent; 3429 3436 } 3430 3437 btrfs_item_key_to_cpu(path->nodes[0], &key, path->slots[0]); 3431 - if (key.objectid == btrfs_ino(dst) && 3438 + if (key.objectid == btrfs_ino(BTRFS_I(dst)) && 3432 3439 key.type == BTRFS_EXTENT_DATA_KEY) { 3433 3440 ASSERT(key.offset > 0); 3434 3441 return -EOPNOTSUPP; ··· 3462 3469 } else if (ret == 0) { 3463 3470 btrfs_item_key_to_cpu(path->nodes[0], &key, 3464 3471 path->slots[0]); 3465 - if (key.objectid == btrfs_ino(dst) && 3472 + if (key.objectid == btrfs_ino(BTRFS_I(dst)) && 3466 3473 key.type == BTRFS_EXTENT_DATA_KEY) 3467 3474 return -EOPNOTSUPP; 3468 3475 } ··· 3556 3563 3557 3564 path->reada = READA_FORWARD; 3558 3565 /* clone data */ 3559 - key.objectid = btrfs_ino(src); 3566 + key.objectid = btrfs_ino(BTRFS_I(src)); 3560 3567 key.type = BTRFS_EXTENT_DATA_KEY; 3561 3568 key.offset = off; 3562 3569 ··· 3599 3606 3600 3607 btrfs_item_key_to_cpu(leaf, &key, slot); 3601 3608 if (key.type > BTRFS_EXTENT_DATA_KEY || 3602 - key.objectid != btrfs_ino(src)) 3609 + key.objectid != btrfs_ino(BTRFS_I(src))) 3603 3610 break; 3604 3611 3605 3612 if (key.type == BTRFS_EXTENT_DATA_KEY) { ··· 3652 3659 path->leave_spinning = 0; 3653 3660 3654 3661 memcpy(&new_key, &key, sizeof(new_key)); 3655 - new_key.objectid = btrfs_ino(inode); 3662 + new_key.objectid = btrfs_ino(BTRFS_I(inode)); 3656 3663 if (off <= key.offset) 3657 3664 new_key.offset = key.offset + destoff - off; 3658 3665 else ··· 3742 3749 fs_info, 3743 3750 disko, diskl, 0, 3744 3751 root->root_key.objectid, 3745 - btrfs_ino(inode), 3752 + btrfs_ino(BTRFS_I(inode)), 3746 3753 new_key.offset - datao); 3747 3754 if (ret) { 3748 3755 btrfs_abort_transaction(trans, ··· 3772 3779 size -= skip + trim; 3773 3780 datal -= skip + trim; 3774 3781 3775 - ret = clone_copy_inline_extent(src, inode, 3782 + ret = clone_copy_inline_extent(inode, 3776 3783 trans, path, 3777 3784 &new_key, 3778 3785 drop_start, ··· 5122 5129 5123 5130 down_write(&fs_info->subvol_sem); 5124 5131 5125 - if (btrfs_ino(inode) != BTRFS_FIRST_FREE_OBJECTID) { 5132 + if (btrfs_ino(BTRFS_I(inode)) != BTRFS_FIRST_FREE_OBJECTID) { 5126 5133 ret = -EINVAL; 5127 5134 goto out; 5128 5135 }
+27 -20
fs/btrfs/ordered-data.c
··· 432 432 } 433 433 434 434 /* Needs to either be called under a log transaction or the log_mutex */ 435 - void btrfs_get_logged_extents(struct inode *inode, 435 + void btrfs_get_logged_extents(struct btrfs_inode *inode, 436 436 struct list_head *logged_list, 437 437 const loff_t start, 438 438 const loff_t end) ··· 442 442 struct rb_node *n; 443 443 struct rb_node *prev; 444 444 445 - tree = &BTRFS_I(inode)->ordered_tree; 445 + tree = &inode->ordered_tree; 446 446 spin_lock_irq(&tree->lock); 447 447 n = __tree_search(&tree->tree, end, &prev); 448 448 if (!n) ··· 984 984 } 985 985 disk_i_size = BTRFS_I(inode)->disk_i_size; 986 986 987 - /* truncate file */ 988 - if (disk_i_size > i_size) { 987 + /* 988 + * truncate file. 989 + * If ordered is not NULL, then this is called from endio and 990 + * disk_i_size will be updated by either truncate itself or any 991 + * in-flight IOs which are inside the disk_i_size. 992 + * 993 + * Because btrfs_setsize() may set i_size with disk_i_size if truncate 994 + * fails somehow, we need to make sure we have a precise disk_i_size by 995 + * updating it as usual. 996 + * 997 + */ 998 + if (!ordered && disk_i_size > i_size) { 989 999 BTRFS_I(inode)->disk_i_size = orig_offset; 990 1000 ret = 0; 991 1001 goto out; ··· 1042 1032 /* We treat this entry as if it doesn't exist */ 1043 1033 if (test_bit(BTRFS_ORDERED_UPDATED_ISIZE, &test->flags)) 1044 1034 continue; 1045 - if (test->file_offset + test->len <= disk_i_size) 1035 + 1036 + if (entry_end(test) <= disk_i_size) 1046 1037 break; 1047 1038 if (test->file_offset >= i_size) 1048 1039 break; 1049 - if (entry_end(test) > disk_i_size) { 1050 - /* 1051 - * we don't update disk_i_size now, so record this 1052 - * undealt i_size. Or we will not know the real 1053 - * i_size. 1054 - */ 1055 - if (test->outstanding_isize < offset) 1056 - test->outstanding_isize = offset; 1057 - if (ordered && 1058 - ordered->outstanding_isize > 1059 - test->outstanding_isize) 1060 - test->outstanding_isize = 1061 - ordered->outstanding_isize; 1062 - goto out; 1063 - } 1040 + 1041 + /* 1042 + * We don't update disk_i_size now, so record this undealt 1043 + * i_size. Or we will not know the real i_size. 1044 + */ 1045 + if (test->outstanding_isize < offset) 1046 + test->outstanding_isize = offset; 1047 + if (ordered && 1048 + ordered->outstanding_isize > test->outstanding_isize) 1049 + test->outstanding_isize = ordered->outstanding_isize; 1050 + goto out; 1064 1051 } 1065 1052 new_i_size = min_t(u64, offset, i_size); 1066 1053
+3 -1
fs/btrfs/ordered-data.h
··· 75 75 * in the logging code. */ 76 76 #define BTRFS_ORDERED_PENDING 11 /* We are waiting for this ordered extent to 77 77 * complete in the current transaction. */ 78 + #define BTRFS_ORDERED_REGULAR 12 /* Regular IO for COW */ 79 + 78 80 struct btrfs_ordered_extent { 79 81 /* logical offset in the file */ 80 82 u64 file_offset; ··· 203 201 const u64 range_start, const u64 range_len); 204 202 int btrfs_wait_ordered_roots(struct btrfs_fs_info *fs_info, int nr, 205 203 const u64 range_start, const u64 range_len); 206 - void btrfs_get_logged_extents(struct inode *inode, 204 + void btrfs_get_logged_extents(struct btrfs_inode *inode, 207 205 struct list_head *logged_list, 208 206 const loff_t start, 209 207 const loff_t end);
+2 -2
fs/btrfs/props.c
··· 279 279 if (unlikely(ret)) 280 280 btrfs_warn(root->fs_info, 281 281 "error applying prop %s to ino %llu (root %llu): %d", 282 - handler->xattr_name, btrfs_ino(inode), 282 + handler->xattr_name, btrfs_ino(BTRFS_I(inode)), 283 283 root->root_key.objectid, ret); 284 284 else 285 285 set_bit(BTRFS_INODE_HAS_PROPS, &BTRFS_I(inode)->runtime_flags); ··· 288 288 int btrfs_load_inode_props(struct inode *inode, struct btrfs_path *path) 289 289 { 290 290 struct btrfs_root *root = BTRFS_I(inode)->root; 291 - u64 ino = btrfs_ino(inode); 291 + u64 ino = btrfs_ino(BTRFS_I(inode)); 292 292 int ret; 293 293 294 294 ret = iterate_object_props(root, path, ino, inode_prop_iterator, inode);
+103 -60
fs/btrfs/qgroup.c
··· 319 319 if (!test_bit(BTRFS_FS_QUOTA_ENABLED, &fs_info->flags)) 320 320 return 0; 321 321 322 - fs_info->qgroup_ulist = ulist_alloc(GFP_NOFS); 322 + fs_info->qgroup_ulist = ulist_alloc(GFP_KERNEL); 323 323 if (!fs_info->qgroup_ulist) { 324 324 ret = -ENOMEM; 325 325 goto out; ··· 876 876 goto out; 877 877 } 878 878 879 - fs_info->qgroup_ulist = ulist_alloc(GFP_NOFS); 879 + fs_info->qgroup_ulist = ulist_alloc(GFP_KERNEL); 880 880 if (!fs_info->qgroup_ulist) { 881 881 ret = -ENOMEM; 882 882 goto out; ··· 1019 1019 list_del(&quota_root->dirty_list); 1020 1020 1021 1021 btrfs_tree_lock(quota_root->node); 1022 - clean_tree_block(trans, fs_info, quota_root->node); 1022 + clean_tree_block(fs_info, quota_root->node); 1023 1023 btrfs_tree_unlock(quota_root->node); 1024 1024 btrfs_free_tree_block(trans, quota_root, quota_root->node, 0, 1); 1025 1025 ··· 1038 1038 list_add(&qgroup->dirty, &fs_info->dirty_qgroups); 1039 1039 } 1040 1040 1041 + static void report_reserved_underflow(struct btrfs_fs_info *fs_info, 1042 + struct btrfs_qgroup *qgroup, 1043 + u64 num_bytes) 1044 + { 1045 + btrfs_warn(fs_info, 1046 + "qgroup %llu reserved space underflow, have: %llu, to free: %llu", 1047 + qgroup->qgroupid, qgroup->reserved, num_bytes); 1048 + qgroup->reserved = 0; 1049 + } 1041 1050 /* 1042 1051 * The easy accounting, if we are adding/removing the only ref for an extent 1043 1052 * then this qgroup and all of the parent qgroups get their reference and ··· 1074 1065 WARN_ON(sign < 0 && qgroup->excl < num_bytes); 1075 1066 qgroup->excl += sign * num_bytes; 1076 1067 qgroup->excl_cmpr += sign * num_bytes; 1077 - if (sign > 0) 1078 - qgroup->reserved -= num_bytes; 1068 + if (sign > 0) { 1069 + if (WARN_ON(qgroup->reserved < num_bytes)) 1070 + report_reserved_underflow(fs_info, qgroup, num_bytes); 1071 + else 1072 + qgroup->reserved -= num_bytes; 1073 + } 1079 1074 1080 1075 qgroup_dirty(fs_info, qgroup); 1081 1076 ··· 1099 1086 qgroup->rfer_cmpr += sign * num_bytes; 1100 1087 WARN_ON(sign < 0 && qgroup->excl < num_bytes); 1101 1088 qgroup->excl += sign * num_bytes; 1102 - if (sign > 0) 1103 - qgroup->reserved -= num_bytes; 1089 + if (sign > 0) { 1090 + if (WARN_ON(qgroup->reserved < num_bytes)) 1091 + report_reserved_underflow(fs_info, qgroup, 1092 + num_bytes); 1093 + else 1094 + qgroup->reserved -= num_bytes; 1095 + } 1104 1096 qgroup->excl_cmpr += sign * num_bytes; 1105 1097 qgroup_dirty(fs_info, qgroup); 1106 1098 ··· 1174 1156 if (btrfs_qgroup_level(src) >= btrfs_qgroup_level(dst)) 1175 1157 return -EINVAL; 1176 1158 1177 - tmp = ulist_alloc(GFP_NOFS); 1159 + tmp = ulist_alloc(GFP_KERNEL); 1178 1160 if (!tmp) 1179 1161 return -ENOMEM; 1180 1162 ··· 1223 1205 return ret; 1224 1206 } 1225 1207 1226 - int __del_qgroup_relation(struct btrfs_trans_handle *trans, 1208 + static int __del_qgroup_relation(struct btrfs_trans_handle *trans, 1227 1209 struct btrfs_fs_info *fs_info, u64 src, u64 dst) 1228 1210 { 1229 1211 struct btrfs_root *quota_root; ··· 1234 1216 int ret = 0; 1235 1217 int err; 1236 1218 1237 - tmp = ulist_alloc(GFP_NOFS); 1219 + tmp = ulist_alloc(GFP_KERNEL); 1238 1220 if (!tmp) 1239 1221 return -ENOMEM; 1240 1222 ··· 1464 1446 while (node) { 1465 1447 record = rb_entry(node, struct btrfs_qgroup_extent_record, 1466 1448 node); 1467 - ret = btrfs_find_all_roots(NULL, fs_info, record->bytenr, 0, 1468 - &record->old_roots); 1449 + if (WARN_ON(!record->old_roots)) 1450 + ret = btrfs_find_all_roots(NULL, fs_info, 1451 + record->bytenr, 0, &record->old_roots); 1469 1452 if (ret < 0) 1470 1453 break; 1471 1454 if (qgroup_to_skip) ··· 1505 1486 return 0; 1506 1487 } 1507 1488 1489 + int btrfs_qgroup_trace_extent_post(struct btrfs_fs_info *fs_info, 1490 + struct btrfs_qgroup_extent_record *qrecord) 1491 + { 1492 + struct ulist *old_root; 1493 + u64 bytenr = qrecord->bytenr; 1494 + int ret; 1495 + 1496 + ret = btrfs_find_all_roots(NULL, fs_info, bytenr, 0, &old_root); 1497 + if (ret < 0) 1498 + return ret; 1499 + 1500 + /* 1501 + * Here we don't need to get the lock of 1502 + * trans->transaction->delayed_refs, since inserted qrecord won't 1503 + * be deleted, only qrecord->node may be modified (new qrecord insert) 1504 + * 1505 + * So modifying qrecord->old_roots is safe here 1506 + */ 1507 + qrecord->old_roots = old_root; 1508 + return 0; 1509 + } 1510 + 1508 1511 int btrfs_qgroup_trace_extent(struct btrfs_trans_handle *trans, 1509 1512 struct btrfs_fs_info *fs_info, u64 bytenr, u64 num_bytes, 1510 1513 gfp_t gfp_flag) ··· 1552 1511 spin_lock(&delayed_refs->lock); 1553 1512 ret = btrfs_qgroup_trace_extent_nolock(fs_info, delayed_refs, record); 1554 1513 spin_unlock(&delayed_refs->lock); 1555 - if (ret > 0) 1514 + if (ret > 0) { 1556 1515 kfree(record); 1557 - return 0; 1516 + return 0; 1517 + } 1518 + return btrfs_qgroup_trace_extent_post(fs_info, record); 1558 1519 } 1559 1520 1560 1521 int btrfs_qgroup_trace_leaf_items(struct btrfs_trans_handle *trans, ··· 1614 1571 * If we increment the root nodes slot counter past the number of 1615 1572 * elements, 1 is returned to signal completion of the search. 1616 1573 */ 1617 - static int adjust_slots_upwards(struct btrfs_root *root, 1618 - struct btrfs_path *path, int root_level) 1574 + static int adjust_slots_upwards(struct btrfs_path *path, int root_level) 1619 1575 { 1620 1576 int level = 0; 1621 1577 int nr, slot; ··· 1755 1713 goto out; 1756 1714 1757 1715 /* Nonzero return here means we completed our search */ 1758 - ret = adjust_slots_upwards(root, path, root_level); 1716 + ret = adjust_slots_upwards(path, root_level); 1759 1717 if (ret) 1760 1718 break; 1761 1719 ··· 1969 1927 u64 nr_old_roots = 0; 1970 1928 int ret = 0; 1971 1929 1930 + if (!test_bit(BTRFS_FS_QUOTA_ENABLED, &fs_info->flags)) 1931 + return 0; 1932 + 1972 1933 if (new_roots) 1973 1934 nr_new_roots = new_roots->nnodes; 1974 1935 if (old_roots) 1975 1936 nr_old_roots = old_roots->nnodes; 1976 1937 1977 - if (!test_bit(BTRFS_FS_QUOTA_ENABLED, &fs_info->flags)) 1978 - goto out_free; 1979 1938 BUG_ON(!fs_info->quota_root); 1980 1939 1981 1940 trace_btrfs_qgroup_account_extent(fs_info, bytenr, num_bytes, ··· 2213 2170 goto out; 2214 2171 } 2215 2172 2216 - rcu_read_lock(); 2217 2173 level_size = fs_info->nodesize; 2218 - rcu_read_unlock(); 2219 2174 } 2220 2175 2221 2176 /* ··· 2347 2306 return ret; 2348 2307 } 2349 2308 2350 - static int qgroup_reserve(struct btrfs_root *root, u64 num_bytes) 2309 + static bool qgroup_check_limits(const struct btrfs_qgroup *qg, u64 num_bytes) 2310 + { 2311 + if ((qg->lim_flags & BTRFS_QGROUP_LIMIT_MAX_RFER) && 2312 + qg->reserved + (s64)qg->rfer + num_bytes > qg->max_rfer) 2313 + return false; 2314 + 2315 + if ((qg->lim_flags & BTRFS_QGROUP_LIMIT_MAX_EXCL) && 2316 + qg->reserved + (s64)qg->excl + num_bytes > qg->max_excl) 2317 + return false; 2318 + 2319 + return true; 2320 + } 2321 + 2322 + static int qgroup_reserve(struct btrfs_root *root, u64 num_bytes, bool enforce) 2351 2323 { 2352 2324 struct btrfs_root *quota_root; 2353 2325 struct btrfs_qgroup *qgroup; ··· 2401 2347 2402 2348 qg = unode_aux_to_qgroup(unode); 2403 2349 2404 - if ((qg->lim_flags & BTRFS_QGROUP_LIMIT_MAX_RFER) && 2405 - qg->reserved + (s64)qg->rfer + num_bytes > 2406 - qg->max_rfer) { 2407 - ret = -EDQUOT; 2408 - goto out; 2409 - } 2410 - 2411 - if ((qg->lim_flags & BTRFS_QGROUP_LIMIT_MAX_EXCL) && 2412 - qg->reserved + (s64)qg->excl + num_bytes > 2413 - qg->max_excl) { 2350 + if (enforce && !qgroup_check_limits(qg, num_bytes)) { 2414 2351 ret = -EDQUOT; 2415 2352 goto out; 2416 2353 } ··· 2469 2424 2470 2425 qg = unode_aux_to_qgroup(unode); 2471 2426 2472 - qg->reserved -= num_bytes; 2427 + if (WARN_ON(qg->reserved < num_bytes)) 2428 + report_reserved_underflow(fs_info, qg, num_bytes); 2429 + else 2430 + qg->reserved -= num_bytes; 2473 2431 2474 2432 list_for_each_entry(glist, &qg->groups, next_group) { 2475 2433 ret = ulist_add(fs_info->qgroup_ulist, ··· 2487 2439 spin_unlock(&fs_info->qgroup_lock); 2488 2440 } 2489 2441 2490 - static inline void qgroup_free(struct btrfs_root *root, u64 num_bytes) 2491 - { 2492 - return btrfs_qgroup_free_refroot(root->fs_info, root->objectid, 2493 - num_bytes); 2494 - } 2495 2442 void assert_qgroups_uptodate(struct btrfs_trans_handle *trans) 2496 2443 { 2497 2444 if (list_empty(&trans->qgroup_ref_list) && !trans->delayed_ref_elem.seq) ··· 2846 2803 return 0; 2847 2804 2848 2805 changeset.bytes_changed = 0; 2849 - changeset.range_changed = ulist_alloc(GFP_NOFS); 2806 + ulist_init(&changeset.range_changed); 2850 2807 ret = set_record_extent_bits(&BTRFS_I(inode)->io_tree, start, 2851 2808 start + len -1, EXTENT_QGROUP_RESERVED, &changeset); 2852 2809 trace_btrfs_qgroup_reserve_data(inode, start, len, ··· 2854 2811 QGROUP_RESERVE); 2855 2812 if (ret < 0) 2856 2813 goto cleanup; 2857 - ret = qgroup_reserve(root, changeset.bytes_changed); 2814 + ret = qgroup_reserve(root, changeset.bytes_changed, true); 2858 2815 if (ret < 0) 2859 2816 goto cleanup; 2860 2817 2861 - ulist_free(changeset.range_changed); 2818 + ulist_release(&changeset.range_changed); 2862 2819 return ret; 2863 2820 2864 2821 cleanup: 2865 2822 /* cleanup already reserved ranges */ 2866 2823 ULIST_ITER_INIT(&uiter); 2867 - while ((unode = ulist_next(changeset.range_changed, &uiter))) 2824 + while ((unode = ulist_next(&changeset.range_changed, &uiter))) 2868 2825 clear_extent_bit(&BTRFS_I(inode)->io_tree, unode->val, 2869 2826 unode->aux, EXTENT_QGROUP_RESERVED, 0, 0, NULL, 2870 2827 GFP_NOFS); 2871 - ulist_free(changeset.range_changed); 2828 + ulist_release(&changeset.range_changed); 2872 2829 return ret; 2873 2830 } 2874 2831 ··· 2880 2837 int ret; 2881 2838 2882 2839 changeset.bytes_changed = 0; 2883 - changeset.range_changed = ulist_alloc(GFP_NOFS); 2884 - if (!changeset.range_changed) 2885 - return -ENOMEM; 2886 - 2840 + ulist_init(&changeset.range_changed); 2887 2841 ret = clear_record_extent_bits(&BTRFS_I(inode)->io_tree, start, 2888 2842 start + len -1, EXTENT_QGROUP_RESERVED, &changeset); 2889 2843 if (ret < 0) 2890 2844 goto out; 2891 2845 2892 2846 if (free) { 2893 - qgroup_free(BTRFS_I(inode)->root, changeset.bytes_changed); 2847 + btrfs_qgroup_free_refroot(BTRFS_I(inode)->root->fs_info, 2848 + BTRFS_I(inode)->root->objectid, 2849 + changeset.bytes_changed); 2894 2850 trace_op = QGROUP_FREE; 2895 2851 } 2896 2852 trace_btrfs_qgroup_release_data(inode, start, len, 2897 2853 changeset.bytes_changed, trace_op); 2898 2854 out: 2899 - ulist_free(changeset.range_changed); 2855 + ulist_release(&changeset.range_changed); 2900 2856 return ret; 2901 2857 } 2902 2858 ··· 2934 2892 return __btrfs_qgroup_release_data(inode, start, len, 0); 2935 2893 } 2936 2894 2937 - int btrfs_qgroup_reserve_meta(struct btrfs_root *root, int num_bytes) 2895 + int btrfs_qgroup_reserve_meta(struct btrfs_root *root, int num_bytes, 2896 + bool enforce) 2938 2897 { 2939 2898 struct btrfs_fs_info *fs_info = root->fs_info; 2940 2899 int ret; ··· 2945 2902 return 0; 2946 2903 2947 2904 BUG_ON(num_bytes != round_down(num_bytes, fs_info->nodesize)); 2948 - ret = qgroup_reserve(root, num_bytes); 2905 + ret = qgroup_reserve(root, num_bytes, enforce); 2949 2906 if (ret < 0) 2950 2907 return ret; 2951 2908 atomic_add(num_bytes, &root->qgroup_meta_rsv); ··· 2964 2921 reserved = atomic_xchg(&root->qgroup_meta_rsv, 0); 2965 2922 if (reserved == 0) 2966 2923 return; 2967 - qgroup_free(root, reserved); 2924 + btrfs_qgroup_free_refroot(fs_info, root->objectid, reserved); 2968 2925 } 2969 2926 2970 2927 void btrfs_qgroup_free_meta(struct btrfs_root *root, int num_bytes) ··· 2978 2935 BUG_ON(num_bytes != round_down(num_bytes, fs_info->nodesize)); 2979 2936 WARN_ON(atomic_read(&root->qgroup_meta_rsv) < num_bytes); 2980 2937 atomic_sub(num_bytes, &root->qgroup_meta_rsv); 2981 - qgroup_free(root, num_bytes); 2938 + btrfs_qgroup_free_refroot(fs_info, root->objectid, num_bytes); 2982 2939 } 2983 2940 2984 2941 /* ··· 2993 2950 int ret; 2994 2951 2995 2952 changeset.bytes_changed = 0; 2996 - changeset.range_changed = ulist_alloc(GFP_NOFS); 2997 - if (WARN_ON(!changeset.range_changed)) 2998 - return; 2999 - 2953 + ulist_init(&changeset.range_changed); 3000 2954 ret = clear_record_extent_bits(&BTRFS_I(inode)->io_tree, 0, (u64)-1, 3001 2955 EXTENT_QGROUP_RESERVED, &changeset); 3002 2956 3003 2957 WARN_ON(ret < 0); 3004 2958 if (WARN_ON(changeset.bytes_changed)) { 3005 2959 ULIST_ITER_INIT(&iter); 3006 - while ((unode = ulist_next(changeset.range_changed, &iter))) { 2960 + while ((unode = ulist_next(&changeset.range_changed, &iter))) { 3007 2961 btrfs_warn(BTRFS_I(inode)->root->fs_info, 3008 2962 "leaking qgroup reserved space, ino: %lu, start: %llu, end: %llu", 3009 2963 inode->i_ino, unode->val, unode->aux); 3010 2964 } 3011 - qgroup_free(BTRFS_I(inode)->root, changeset.bytes_changed); 2965 + btrfs_qgroup_free_refroot(BTRFS_I(inode)->root->fs_info, 2966 + BTRFS_I(inode)->root->objectid, 2967 + changeset.bytes_changed); 2968 + 3012 2969 } 3013 - ulist_free(changeset.range_changed); 2970 + ulist_release(&changeset.range_changed); 3014 2971 }
+32 -4
fs/btrfs/qgroup.h
··· 94 94 struct btrfs_fs_info *fs_info); 95 95 /* 96 96 * Inform qgroup to trace one dirty extent, its info is recorded in @record. 97 - * So qgroup can account it at commit trans time. 97 + * So qgroup can account it at transaction committing time. 98 98 * 99 - * No lock version, caller must acquire delayed ref lock and allocate memory. 99 + * No lock version, caller must acquire delayed ref lock and allocated memory, 100 + * then call btrfs_qgroup_trace_extent_post() after exiting lock context. 100 101 * 101 102 * Return 0 for success insert 102 103 * Return >0 for existing record, caller can free @record safely. ··· 109 108 struct btrfs_qgroup_extent_record *record); 110 109 111 110 /* 111 + * Post handler after qgroup_trace_extent_nolock(). 112 + * 113 + * NOTE: Current qgroup does the expensive backref walk at transaction 114 + * committing time with TRANS_STATE_COMMIT_DOING, this blocks incoming 115 + * new transaction. 116 + * This is designed to allow btrfs_find_all_roots() to get correct new_roots 117 + * result. 118 + * 119 + * However for old_roots there is no need to do backref walk at that time, 120 + * since we search commit roots to walk backref and result will always be 121 + * correct. 122 + * 123 + * Due to the nature of no lock version, we can't do backref there. 124 + * So we must call btrfs_qgroup_trace_extent_post() after exiting 125 + * spinlock context. 126 + * 127 + * TODO: If we can fix and prove btrfs_find_all_roots() can get correct result 128 + * using current root, then we can move all expensive backref walk out of 129 + * transaction committing, but not now as qgroup accounting will be wrong again. 130 + */ 131 + int btrfs_qgroup_trace_extent_post(struct btrfs_fs_info *fs_info, 132 + struct btrfs_qgroup_extent_record *qrecord); 133 + 134 + /* 112 135 * Inform qgroup to trace one dirty extent, specified by @bytenr and 113 136 * @num_bytes. 114 137 * So qgroup can account it at commit trans time. 115 138 * 116 - * Better encapsulated version. 139 + * Better encapsulated version, with memory allocation and backref walk for 140 + * commit roots. 141 + * So this can sleep. 117 142 * 118 143 * Return 0 if the operation is done. 119 144 * Return <0 for error, like memory allocation failure or invalid parameter ··· 208 181 int btrfs_qgroup_release_data(struct inode *inode, u64 start, u64 len); 209 182 int btrfs_qgroup_free_data(struct inode *inode, u64 start, u64 len); 210 183 211 - int btrfs_qgroup_reserve_meta(struct btrfs_root *root, int num_bytes); 184 + int btrfs_qgroup_reserve_meta(struct btrfs_root *root, int num_bytes, 185 + bool enforce); 212 186 void btrfs_qgroup_free_meta_all(struct btrfs_root *root); 213 187 void btrfs_qgroup_free_meta(struct btrfs_root *root, int num_bytes); 214 188 void btrfs_qgroup_check_reserved_leak(struct inode *inode);
-2
fs/btrfs/raid56.c
··· 677 677 struct btrfs_raid_bio *freeit = NULL; 678 678 struct btrfs_raid_bio *cache_drop = NULL; 679 679 int ret = 0; 680 - int walk = 0; 681 680 682 681 spin_lock_irqsave(&h->lock, flags); 683 682 list_for_each_entry(cur, &h->hash_list, hash_list) { 684 - walk++; 685 683 if (cur->bbio->raid_map[0] == rbio->bbio->raid_map[0]) { 686 684 spin_lock(&cur->bio_list_lock); 687 685
+12 -13
fs/btrfs/relocation.c
··· 1548 1548 prev = node; 1549 1549 entry = rb_entry(node, struct btrfs_inode, rb_node); 1550 1550 1551 - if (objectid < btrfs_ino(&entry->vfs_inode)) 1551 + if (objectid < btrfs_ino(entry)) 1552 1552 node = node->rb_left; 1553 - else if (objectid > btrfs_ino(&entry->vfs_inode)) 1553 + else if (objectid > btrfs_ino(entry)) 1554 1554 node = node->rb_right; 1555 1555 else 1556 1556 break; ··· 1558 1558 if (!node) { 1559 1559 while (prev) { 1560 1560 entry = rb_entry(prev, struct btrfs_inode, rb_node); 1561 - if (objectid <= btrfs_ino(&entry->vfs_inode)) { 1561 + if (objectid <= btrfs_ino(entry)) { 1562 1562 node = prev; 1563 1563 break; 1564 1564 } ··· 1573 1573 return inode; 1574 1574 } 1575 1575 1576 - objectid = btrfs_ino(&entry->vfs_inode) + 1; 1576 + objectid = btrfs_ino(entry) + 1; 1577 1577 if (cond_resched_lock(&root->inode_lock)) 1578 1578 goto again; 1579 1579 ··· 1609 1609 return -ENOMEM; 1610 1610 1611 1611 bytenr -= BTRFS_I(reloc_inode)->index_cnt; 1612 - ret = btrfs_lookup_file_extent(NULL, root, path, btrfs_ino(reloc_inode), 1613 - bytenr, 0); 1612 + ret = btrfs_lookup_file_extent(NULL, root, path, 1613 + btrfs_ino(BTRFS_I(reloc_inode)), bytenr, 0); 1614 1614 if (ret < 0) 1615 1615 goto out; 1616 1616 if (ret > 0) { ··· 1698 1698 if (first) { 1699 1699 inode = find_next_inode(root, key.objectid); 1700 1700 first = 0; 1701 - } else if (inode && btrfs_ino(inode) < key.objectid) { 1701 + } else if (inode && btrfs_ino(BTRFS_I(inode)) < key.objectid) { 1702 1702 btrfs_add_delayed_iput(inode); 1703 1703 inode = find_next_inode(root, key.objectid); 1704 1704 } 1705 - if (inode && btrfs_ino(inode) == key.objectid) { 1705 + if (inode && btrfs_ino(BTRFS_I(inode)) == key.objectid) { 1706 1706 end = key.offset + 1707 1707 btrfs_file_extent_num_bytes(leaf, fi); 1708 1708 WARN_ON(!IS_ALIGNED(key.offset, ··· 2088 2088 inode = find_next_inode(root, objectid); 2089 2089 if (!inode) 2090 2090 break; 2091 - ino = btrfs_ino(inode); 2091 + ino = btrfs_ino(BTRFS_I(inode)); 2092 2092 2093 2093 if (ino > max_key->objectid) { 2094 2094 iput(inode); ··· 3543 3543 goto out; 3544 3544 } 3545 3545 3546 - ret = btrfs_truncate_free_space_cache(root, trans, block_group, inode); 3546 + ret = btrfs_truncate_free_space_cache(trans, block_group, inode); 3547 3547 3548 3548 btrfs_end_transaction(trans); 3549 3549 btrfs_btree_balance_dirty(fs_info); ··· 4334 4334 rc->block_group = btrfs_lookup_block_group(fs_info, group_start); 4335 4335 BUG_ON(!rc->block_group); 4336 4336 4337 - ret = btrfs_inc_block_group_ro(extent_root, rc->block_group); 4337 + ret = btrfs_inc_block_group_ro(fs_info, rc->block_group); 4338 4338 if (ret) { 4339 4339 err = ret; 4340 4340 goto out; ··· 4347 4347 goto out; 4348 4348 } 4349 4349 4350 - inode = lookup_free_space_inode(fs_info->tree_root, rc->block_group, 4351 - path); 4350 + inode = lookup_free_space_inode(fs_info, rc->block_group, path); 4352 4351 btrfs_free_path(path); 4353 4352 4354 4353 if (!IS_ERR(inode))
+3 -3
fs/btrfs/root-tree.c
··· 74 74 * 75 75 * If we find something return 0, otherwise > 0, < 0 on error. 76 76 */ 77 - int btrfs_find_root(struct btrfs_root *root, struct btrfs_key *search_key, 77 + int btrfs_find_root(struct btrfs_root *root, const struct btrfs_key *search_key, 78 78 struct btrfs_path *path, struct btrfs_root_item *root_item, 79 79 struct btrfs_key *root_key) 80 80 { ··· 207 207 } 208 208 209 209 int btrfs_insert_root(struct btrfs_trans_handle *trans, struct btrfs_root *root, 210 - struct btrfs_key *key, struct btrfs_root_item *item) 210 + const struct btrfs_key *key, struct btrfs_root_item *item) 211 211 { 212 212 /* 213 213 * Make sure generation v1 and v2 match. See update_root for details. ··· 337 337 338 338 /* drop the root item for 'key' from 'root' */ 339 339 int btrfs_del_root(struct btrfs_trans_handle *trans, struct btrfs_root *root, 340 - struct btrfs_key *key) 340 + const struct btrfs_key *key) 341 341 { 342 342 struct btrfs_path *path; 343 343 int ret;
+4 -8
fs/btrfs/scrub.c
··· 282 282 u64 *extent_physical, 283 283 struct btrfs_device **extent_dev, 284 284 int *extent_mirror_num); 285 - static int scrub_setup_wr_ctx(struct scrub_ctx *sctx, 286 - struct scrub_wr_ctx *wr_ctx, 287 - struct btrfs_fs_info *fs_info, 285 + static int scrub_setup_wr_ctx(struct scrub_wr_ctx *wr_ctx, 288 286 struct btrfs_device *dev, 289 287 int is_dev_replace); 290 288 static void scrub_free_wr_ctx(struct scrub_wr_ctx *wr_ctx); ··· 499 501 spin_lock_init(&sctx->stat_lock); 500 502 init_waitqueue_head(&sctx->list_wait); 501 503 502 - ret = scrub_setup_wr_ctx(sctx, &sctx->wr_ctx, fs_info, 504 + ret = scrub_setup_wr_ctx(&sctx->wr_ctx, 503 505 fs_info->dev_replace.tgtdev, is_dev_replace); 504 506 if (ret) { 505 507 scrub_free_ctx(sctx); ··· 3582 3584 * -> btrfs_scrub_pause() 3583 3585 */ 3584 3586 scrub_pause_on(fs_info); 3585 - ret = btrfs_inc_block_group_ro(root, cache); 3587 + ret = btrfs_inc_block_group_ro(fs_info, cache); 3586 3588 if (!ret && is_dev_replace) { 3587 3589 /* 3588 3590 * If we are doing a device replace wait for any tasks ··· 4082 4084 btrfs_put_bbio(bbio); 4083 4085 } 4084 4086 4085 - static int scrub_setup_wr_ctx(struct scrub_ctx *sctx, 4086 - struct scrub_wr_ctx *wr_ctx, 4087 - struct btrfs_fs_info *fs_info, 4087 + static int scrub_setup_wr_ctx(struct scrub_wr_ctx *wr_ctx, 4088 4088 struct btrfs_device *dev, 4089 4089 int is_dev_replace) 4090 4090 {
+3 -4
fs/btrfs/super.c
··· 265 265 function, line, errstr); 266 266 return; 267 267 } 268 - ACCESS_ONCE(trans->transaction->aborted) = errno; 268 + WRITE_ONCE(trans->transaction->aborted, errno); 269 269 /* Wake up anybody who may be waiting on this transaction */ 270 270 wake_up(&fs_info->transaction_wait); 271 271 wake_up(&fs_info->transaction_blocked_wait); ··· 1114 1114 1115 1115 static int btrfs_fill_super(struct super_block *sb, 1116 1116 struct btrfs_fs_devices *fs_devices, 1117 - void *data, int silent) 1117 + void *data) 1118 1118 { 1119 1119 struct inode *inode; 1120 1120 struct btrfs_fs_info *fs_info = btrfs_sb(sb); ··· 1611 1611 } else { 1612 1612 snprintf(s->s_id, sizeof(s->s_id), "%pg", bdev); 1613 1613 btrfs_sb(s)->bdev_holder = fs_type; 1614 - error = btrfs_fill_super(s, fs_devices, data, 1615 - flags & MS_SILENT ? 1 : 0); 1614 + error = btrfs_fill_super(s, fs_devices, data); 1616 1615 } 1617 1616 if (error) { 1618 1617 deactivate_locked_super(s);
+32 -26
fs/btrfs/transaction.c
··· 474 474 475 475 static struct btrfs_trans_handle * 476 476 start_transaction(struct btrfs_root *root, unsigned int num_items, 477 - unsigned int type, enum btrfs_reserve_flush_enum flush) 477 + unsigned int type, enum btrfs_reserve_flush_enum flush, 478 + bool enforce_qgroups) 478 479 { 479 480 struct btrfs_fs_info *fs_info = root->fs_info; 480 481 ··· 506 505 * Do the reservation before we join the transaction so we can do all 507 506 * the appropriate flushing if need be. 508 507 */ 509 - if (num_items > 0 && root != fs_info->chunk_root) { 508 + if (num_items && root != fs_info->chunk_root) { 510 509 qgroup_reserved = num_items * fs_info->nodesize; 511 - ret = btrfs_qgroup_reserve_meta(root, qgroup_reserved); 510 + ret = btrfs_qgroup_reserve_meta(root, qgroup_reserved, 511 + enforce_qgroups); 512 512 if (ret) 513 513 return ERR_PTR(ret); 514 514 ··· 615 613 unsigned int num_items) 616 614 { 617 615 return start_transaction(root, num_items, TRANS_START, 618 - BTRFS_RESERVE_FLUSH_ALL); 616 + BTRFS_RESERVE_FLUSH_ALL, true); 619 617 } 618 + 620 619 struct btrfs_trans_handle *btrfs_start_transaction_fallback_global_rsv( 621 620 struct btrfs_root *root, 622 621 unsigned int num_items, ··· 628 625 u64 num_bytes; 629 626 int ret; 630 627 631 - trans = btrfs_start_transaction(root, num_items); 628 + /* 629 + * We have two callers: unlink and block group removal. The 630 + * former should succeed even if we will temporarily exceed 631 + * quota and the latter operates on the extent root so 632 + * qgroup enforcement is ignored anyway. 633 + */ 634 + trans = start_transaction(root, num_items, TRANS_START, 635 + BTRFS_RESERVE_FLUSH_ALL, false); 632 636 if (!IS_ERR(trans) || PTR_ERR(trans) != -ENOSPC) 633 637 return trans; 634 638 ··· 664 654 unsigned int num_items) 665 655 { 666 656 return start_transaction(root, num_items, TRANS_START, 667 - BTRFS_RESERVE_FLUSH_LIMIT); 657 + BTRFS_RESERVE_FLUSH_LIMIT, true); 668 658 } 669 659 670 660 struct btrfs_trans_handle *btrfs_join_transaction(struct btrfs_root *root) 671 661 { 672 - return start_transaction(root, 0, TRANS_JOIN, 673 - BTRFS_RESERVE_NO_FLUSH); 662 + return start_transaction(root, 0, TRANS_JOIN, BTRFS_RESERVE_NO_FLUSH, 663 + true); 674 664 } 675 665 676 666 struct btrfs_trans_handle *btrfs_join_transaction_nolock(struct btrfs_root *root) 677 667 { 678 668 return start_transaction(root, 0, TRANS_JOIN_NOLOCK, 679 - BTRFS_RESERVE_NO_FLUSH); 669 + BTRFS_RESERVE_NO_FLUSH, true); 680 670 } 681 671 682 672 struct btrfs_trans_handle *btrfs_start_ioctl_transaction(struct btrfs_root *root) 683 673 { 684 674 return start_transaction(root, 0, TRANS_USERSPACE, 685 - BTRFS_RESERVE_NO_FLUSH); 675 + BTRFS_RESERVE_NO_FLUSH, true); 686 676 } 687 677 688 678 /* ··· 701 691 struct btrfs_trans_handle *btrfs_attach_transaction(struct btrfs_root *root) 702 692 { 703 693 return start_transaction(root, 0, TRANS_ATTACH, 704 - BTRFS_RESERVE_NO_FLUSH); 694 + BTRFS_RESERVE_NO_FLUSH, true); 705 695 } 706 696 707 697 /* ··· 717 707 struct btrfs_trans_handle *trans; 718 708 719 709 trans = start_transaction(root, 0, TRANS_ATTACH, 720 - BTRFS_RESERVE_NO_FLUSH); 710 + BTRFS_RESERVE_NO_FLUSH, true); 721 711 if (IS_ERR(trans) && PTR_ERR(trans) == -ENOENT) 722 712 btrfs_wait_for_commit(root->fs_info, 0); 723 713 ··· 876 866 877 867 if (lock && !atomic_read(&info->open_ioctl_trans) && 878 868 should_end_transaction(trans) && 879 - ACCESS_ONCE(cur_trans->state) == TRANS_STATE_RUNNING) { 869 + READ_ONCE(cur_trans->state) == TRANS_STATE_RUNNING) { 880 870 spin_lock(&info->trans_lock); 881 871 if (cur_trans->state == TRANS_STATE_RUNNING) 882 872 cur_trans->state = TRANS_STATE_BLOCKED; 883 873 spin_unlock(&info->trans_lock); 884 874 } 885 875 886 - if (lock && ACCESS_ONCE(cur_trans->state) == TRANS_STATE_BLOCKED) { 876 + if (lock && READ_ONCE(cur_trans->state) == TRANS_STATE_BLOCKED) { 887 877 if (throttle) 888 878 return btrfs_commit_transaction(trans); 889 879 else ··· 1364 1354 * enabled. If this check races with the ioctl, rescan will 1365 1355 * kick in anyway. 1366 1356 */ 1367 - mutex_lock(&fs_info->qgroup_ioctl_lock); 1368 - if (!test_bit(BTRFS_FS_QUOTA_ENABLED, &fs_info->flags)) { 1369 - mutex_unlock(&fs_info->qgroup_ioctl_lock); 1357 + if (!test_bit(BTRFS_FS_QUOTA_ENABLED, &fs_info->flags)) 1370 1358 return 0; 1371 - } 1372 - mutex_unlock(&fs_info->qgroup_ioctl_lock); 1373 1359 1374 1360 /* 1375 1361 * We are going to commit transaction, see btrfs_commit_transaction() ··· 1510 1504 1511 1505 /* check if there is a file/dir which has the same name. */ 1512 1506 dir_item = btrfs_lookup_dir_item(NULL, parent_root, path, 1513 - btrfs_ino(parent_inode), 1507 + btrfs_ino(BTRFS_I(parent_inode)), 1514 1508 dentry->d_name.name, 1515 1509 dentry->d_name.len, 0); 1516 1510 if (dir_item != NULL && !IS_ERR(dir_item)) { ··· 1604 1598 */ 1605 1599 ret = btrfs_add_root_ref(trans, fs_info, objectid, 1606 1600 parent_root->root_key.objectid, 1607 - btrfs_ino(parent_inode), index, 1601 + btrfs_ino(BTRFS_I(parent_inode)), index, 1608 1602 dentry->d_name.name, dentry->d_name.len); 1609 1603 if (ret) { 1610 1604 btrfs_abort_transaction(trans, ret); ··· 1946 1940 int ret; 1947 1941 1948 1942 /* Stop the commit early if ->aborted is set */ 1949 - if (unlikely(ACCESS_ONCE(cur_trans->aborted))) { 1943 + if (unlikely(READ_ONCE(cur_trans->aborted))) { 1950 1944 ret = cur_trans->aborted; 1951 1945 btrfs_end_transaction(trans); 1952 1946 return ret; ··· 2086 2080 atomic_read(&cur_trans->num_writers) == 1); 2087 2081 2088 2082 /* ->aborted might be set after the previous check, so check it */ 2089 - if (unlikely(ACCESS_ONCE(cur_trans->aborted))) { 2083 + if (unlikely(READ_ONCE(cur_trans->aborted))) { 2090 2084 ret = cur_trans->aborted; 2091 2085 goto scrub_continue; 2092 2086 } ··· 2200 2194 * The tasks which save the space cache and inode cache may also 2201 2195 * update ->aborted, check it. 2202 2196 */ 2203 - if (unlikely(ACCESS_ONCE(cur_trans->aborted))) { 2197 + if (unlikely(READ_ONCE(cur_trans->aborted))) { 2204 2198 ret = cur_trans->aborted; 2205 2199 mutex_unlock(&fs_info->tree_log_mutex); 2206 2200 mutex_unlock(&fs_info->reloc_mutex); 2207 2201 goto scrub_continue; 2208 2202 } 2209 2203 2210 - btrfs_prepare_extent_commit(trans, fs_info); 2204 + btrfs_prepare_extent_commit(fs_info); 2211 2205 2212 2206 cur_trans = fs_info->running_transaction; 2213 2207 ··· 2257 2251 goto scrub_continue; 2258 2252 } 2259 2253 2260 - ret = write_ctree_super(trans, fs_info, 0); 2254 + ret = write_all_supers(fs_info, 0); 2261 2255 if (ret) { 2262 2256 mutex_unlock(&fs_info->tree_log_mutex); 2263 2257 goto scrub_continue;
+148 -151
fs/btrfs/tree-log.c
··· 97 97 #define LOG_WALK_REPLAY_ALL 3 98 98 99 99 static int btrfs_log_inode(struct btrfs_trans_handle *trans, 100 - struct btrfs_root *root, struct inode *inode, 100 + struct btrfs_root *root, struct btrfs_inode *inode, 101 101 int inode_only, 102 102 const loff_t start, 103 103 const loff_t end, ··· 631 631 * file. This must be done before the btrfs_drop_extents run 632 632 * so we don't try to drop this extent. 633 633 */ 634 - ret = btrfs_lookup_file_extent(trans, root, path, btrfs_ino(inode), 635 - start, 0); 634 + ret = btrfs_lookup_file_extent(trans, root, path, 635 + btrfs_ino(BTRFS_I(inode)), start, 0); 636 636 637 637 if (ret == 0 && 638 638 (found_type == BTRFS_FILE_EXTENT_REG || ··· 843 843 static noinline int drop_one_dir_item(struct btrfs_trans_handle *trans, 844 844 struct btrfs_root *root, 845 845 struct btrfs_path *path, 846 - struct inode *dir, 846 + struct btrfs_inode *dir, 847 847 struct btrfs_dir_item *di) 848 848 { 849 849 struct btrfs_fs_info *fs_info = root->fs_info; ··· 875 875 if (ret) 876 876 goto out; 877 877 878 - ret = btrfs_unlink_inode(trans, root, dir, inode, name, name_len); 878 + ret = btrfs_unlink_inode(trans, root, dir, BTRFS_I(inode), name, 879 + name_len); 879 880 if (ret) 880 881 goto out; 881 882 else ··· 992 991 struct btrfs_root *root, 993 992 struct btrfs_path *path, 994 993 struct btrfs_root *log_root, 995 - struct inode *dir, struct inode *inode, 996 - struct extent_buffer *eb, 994 + struct btrfs_inode *dir, 995 + struct btrfs_inode *inode, 997 996 u64 inode_objectid, u64 parent_objectid, 998 997 u64 ref_index, char *name, int namelen, 999 998 int *search_done) ··· 1048 1047 parent_objectid, 1049 1048 victim_name, 1050 1049 victim_name_len)) { 1051 - inc_nlink(inode); 1050 + inc_nlink(&inode->vfs_inode); 1052 1051 btrfs_release_path(path); 1053 1052 1054 - ret = btrfs_unlink_inode(trans, root, dir, 1055 - inode, victim_name, 1056 - victim_name_len); 1053 + ret = btrfs_unlink_inode(trans, root, dir, inode, 1054 + victim_name, victim_name_len); 1057 1055 kfree(victim_name); 1058 1056 if (ret) 1059 1057 return ret; ··· 1115 1115 victim_name_len)) { 1116 1116 ret = -ENOENT; 1117 1117 victim_parent = read_one_inode(root, 1118 - parent_objectid); 1118 + parent_objectid); 1119 1119 if (victim_parent) { 1120 - inc_nlink(inode); 1120 + inc_nlink(&inode->vfs_inode); 1121 1121 btrfs_release_path(path); 1122 1122 1123 1123 ret = btrfs_unlink_inode(trans, root, 1124 - victim_parent, 1125 - inode, 1126 - victim_name, 1127 - victim_name_len); 1124 + BTRFS_I(victim_parent), 1125 + inode, 1126 + victim_name, 1127 + victim_name_len); 1128 1128 if (!ret) 1129 1129 ret = btrfs_run_delayed_items( 1130 1130 trans, ··· 1295 1295 goto out; 1296 1296 1297 1297 /* if we already have a perfect match, we're done */ 1298 - if (!inode_in_dir(root, path, btrfs_ino(dir), btrfs_ino(inode), 1299 - ref_index, name, namelen)) { 1298 + if (!inode_in_dir(root, path, btrfs_ino(BTRFS_I(dir)), 1299 + btrfs_ino(BTRFS_I(inode)), ref_index, 1300 + name, namelen)) { 1300 1301 /* 1301 1302 * look for a conflicting back reference in the 1302 1303 * metadata. if we find one we have to unlink that name ··· 1308 1307 1309 1308 if (!search_done) { 1310 1309 ret = __add_inode_ref(trans, root, path, log, 1311 - dir, inode, eb, 1310 + BTRFS_I(dir), 1311 + BTRFS_I(inode), 1312 1312 inode_objectid, 1313 1313 parent_objectid, 1314 1314 ref_index, name, namelen, ··· 1362 1360 } 1363 1361 1364 1362 static int count_inode_extrefs(struct btrfs_root *root, 1365 - struct inode *inode, struct btrfs_path *path) 1363 + struct btrfs_inode *inode, struct btrfs_path *path) 1366 1364 { 1367 1365 int ret = 0; 1368 1366 int name_len; ··· 1406 1404 } 1407 1405 1408 1406 static int count_inode_refs(struct btrfs_root *root, 1409 - struct inode *inode, struct btrfs_path *path) 1407 + struct btrfs_inode *inode, struct btrfs_path *path) 1410 1408 { 1411 1409 int ret; 1412 1410 struct btrfs_key key; ··· 1479 1477 struct btrfs_path *path; 1480 1478 int ret; 1481 1479 u64 nlink = 0; 1482 - u64 ino = btrfs_ino(inode); 1480 + u64 ino = btrfs_ino(BTRFS_I(inode)); 1483 1481 1484 1482 path = btrfs_alloc_path(); 1485 1483 if (!path) 1486 1484 return -ENOMEM; 1487 1485 1488 - ret = count_inode_refs(root, inode, path); 1486 + ret = count_inode_refs(root, BTRFS_I(inode), path); 1489 1487 if (ret < 0) 1490 1488 goto out; 1491 1489 1492 1490 nlink = ret; 1493 1491 1494 - ret = count_inode_extrefs(root, inode, path); 1492 + ret = count_inode_extrefs(root, BTRFS_I(inode), path); 1495 1493 if (ret < 0) 1496 1494 goto out; 1497 1495 ··· 1771 1769 if (!exists) 1772 1770 goto out; 1773 1771 1774 - ret = drop_one_dir_item(trans, root, path, dir, dst_di); 1772 + ret = drop_one_dir_item(trans, root, path, BTRFS_I(dir), dst_di); 1775 1773 if (ret) 1776 1774 goto out; 1777 1775 ··· 2054 2052 } 2055 2053 2056 2054 inc_nlink(inode); 2057 - ret = btrfs_unlink_inode(trans, root, dir, inode, 2058 - name, name_len); 2055 + ret = btrfs_unlink_inode(trans, root, BTRFS_I(dir), 2056 + BTRFS_I(inode), name, name_len); 2059 2057 if (!ret) 2060 2058 ret = btrfs_run_delayed_items(trans, fs_info); 2061 2059 kfree(name); ··· 2471 2469 if (trans) { 2472 2470 btrfs_tree_lock(next); 2473 2471 btrfs_set_lock_blocking(next); 2474 - clean_tree_block(trans, fs_info, next); 2472 + clean_tree_block(fs_info, next); 2475 2473 btrfs_wait_tree_block_writeback(next); 2476 2474 btrfs_tree_unlock(next); 2477 2475 } ··· 2551 2549 if (trans) { 2552 2550 btrfs_tree_lock(next); 2553 2551 btrfs_set_lock_blocking(next); 2554 - clean_tree_block(trans, fs_info, next); 2552 + clean_tree_block(fs_info, next); 2555 2553 btrfs_wait_tree_block_writeback(next); 2556 2554 btrfs_tree_unlock(next); 2557 2555 } ··· 2629 2627 if (trans) { 2630 2628 btrfs_tree_lock(next); 2631 2629 btrfs_set_lock_blocking(next); 2632 - clean_tree_block(trans, fs_info, next); 2630 + clean_tree_block(fs_info, next); 2633 2631 btrfs_wait_tree_block_writeback(next); 2634 2632 btrfs_tree_unlock(next); 2635 2633 } ··· 2960 2958 * the running transaction open, so a full commit can't hop 2961 2959 * in and cause problems either. 2962 2960 */ 2963 - ret = write_ctree_super(trans, fs_info, 1); 2961 + ret = write_all_supers(fs_info, 1); 2964 2962 if (ret) { 2965 2963 btrfs_set_log_full_commit(fs_info, trans); 2966 2964 btrfs_abort_transaction(trans, ret); ··· 3086 3084 int btrfs_del_dir_entries_in_log(struct btrfs_trans_handle *trans, 3087 3085 struct btrfs_root *root, 3088 3086 const char *name, int name_len, 3089 - struct inode *dir, u64 index) 3087 + struct btrfs_inode *dir, u64 index) 3090 3088 { 3091 3089 struct btrfs_root *log; 3092 3090 struct btrfs_dir_item *di; ··· 3096 3094 int bytes_del = 0; 3097 3095 u64 dir_ino = btrfs_ino(dir); 3098 3096 3099 - if (BTRFS_I(dir)->logged_trans < trans->transid) 3097 + if (dir->logged_trans < trans->transid) 3100 3098 return 0; 3101 3099 3102 3100 ret = join_running_log_trans(root); 3103 3101 if (ret) 3104 3102 return 0; 3105 3103 3106 - mutex_lock(&BTRFS_I(dir)->log_mutex); 3104 + mutex_lock(&dir->log_mutex); 3107 3105 3108 3106 log = root->log_root; 3109 3107 path = btrfs_alloc_path(); ··· 3178 3176 fail: 3179 3177 btrfs_free_path(path); 3180 3178 out_unlock: 3181 - mutex_unlock(&BTRFS_I(dir)->log_mutex); 3179 + mutex_unlock(&dir->log_mutex); 3182 3180 if (ret == -ENOSPC) { 3183 3181 btrfs_set_log_full_commit(root->fs_info, trans); 3184 3182 ret = 0; ··· 3194 3192 int btrfs_del_inode_ref_in_log(struct btrfs_trans_handle *trans, 3195 3193 struct btrfs_root *root, 3196 3194 const char *name, int name_len, 3197 - struct inode *inode, u64 dirid) 3195 + struct btrfs_inode *inode, u64 dirid) 3198 3196 { 3199 3197 struct btrfs_fs_info *fs_info = root->fs_info; 3200 3198 struct btrfs_root *log; 3201 3199 u64 index; 3202 3200 int ret; 3203 3201 3204 - if (BTRFS_I(inode)->logged_trans < trans->transid) 3202 + if (inode->logged_trans < trans->transid) 3205 3203 return 0; 3206 3204 3207 3205 ret = join_running_log_trans(root); 3208 3206 if (ret) 3209 3207 return 0; 3210 3208 log = root->log_root; 3211 - mutex_lock(&BTRFS_I(inode)->log_mutex); 3209 + mutex_lock(&inode->log_mutex); 3212 3210 3213 3211 ret = btrfs_del_inode_ref(trans, log, name, name_len, btrfs_ino(inode), 3214 3212 dirid, &index); 3215 - mutex_unlock(&BTRFS_I(inode)->log_mutex); 3213 + mutex_unlock(&inode->log_mutex); 3216 3214 if (ret == -ENOSPC) { 3217 3215 btrfs_set_log_full_commit(fs_info, trans); 3218 3216 ret = 0; ··· 3262 3260 * to replay anything deleted before the fsync 3263 3261 */ 3264 3262 static noinline int log_dir_items(struct btrfs_trans_handle *trans, 3265 - struct btrfs_root *root, struct inode *inode, 3263 + struct btrfs_root *root, struct btrfs_inode *inode, 3266 3264 struct btrfs_path *path, 3267 3265 struct btrfs_path *dst_path, int key_type, 3268 3266 struct btrfs_log_ctx *ctx, ··· 3452 3450 * key logged by this transaction. 3453 3451 */ 3454 3452 static noinline int log_directory_changes(struct btrfs_trans_handle *trans, 3455 - struct btrfs_root *root, struct inode *inode, 3453 + struct btrfs_root *root, struct btrfs_inode *inode, 3456 3454 struct btrfs_path *path, 3457 3455 struct btrfs_path *dst_path, 3458 3456 struct btrfs_log_ctx *ctx) ··· 3466 3464 min_key = 0; 3467 3465 max_key = 0; 3468 3466 while (1) { 3469 - ret = log_dir_items(trans, root, inode, path, 3470 - dst_path, key_type, ctx, min_key, 3471 - &max_key); 3467 + ret = log_dir_items(trans, root, inode, path, dst_path, key_type, 3468 + ctx, min_key, &max_key); 3472 3469 if (ret) 3473 3470 return ret; 3474 3471 if (max_key == (u64)-1) ··· 3596 3595 3597 3596 static int log_inode_item(struct btrfs_trans_handle *trans, 3598 3597 struct btrfs_root *log, struct btrfs_path *path, 3599 - struct inode *inode) 3598 + struct btrfs_inode *inode) 3600 3599 { 3601 3600 struct btrfs_inode_item *inode_item; 3602 3601 int ret; 3603 3602 3604 3603 ret = btrfs_insert_empty_item(trans, log, path, 3605 - &BTRFS_I(inode)->location, 3606 - sizeof(*inode_item)); 3604 + &inode->location, sizeof(*inode_item)); 3607 3605 if (ret && ret != -EEXIST) 3608 3606 return ret; 3609 3607 inode_item = btrfs_item_ptr(path->nodes[0], path->slots[0], 3610 3608 struct btrfs_inode_item); 3611 - fill_inode_item(trans, path->nodes[0], inode_item, inode, 0, 0); 3609 + fill_inode_item(trans, path->nodes[0], inode_item, &inode->vfs_inode, 3610 + 0, 0); 3612 3611 btrfs_release_path(path); 3613 3612 return 0; 3614 3613 } 3615 3614 3616 3615 static noinline int copy_items(struct btrfs_trans_handle *trans, 3617 - struct inode *inode, 3616 + struct btrfs_inode *inode, 3618 3617 struct btrfs_path *dst_path, 3619 3618 struct btrfs_path *src_path, u64 *last_extent, 3620 3619 int start_slot, int nr, int inode_only, 3621 3620 u64 logged_isize) 3622 3621 { 3623 - struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb); 3622 + struct btrfs_fs_info *fs_info = btrfs_sb(inode->vfs_inode.i_sb); 3624 3623 unsigned long src_offset; 3625 3624 unsigned long dst_offset; 3626 - struct btrfs_root *log = BTRFS_I(inode)->root->log_root; 3625 + struct btrfs_root *log = inode->root->log_root; 3627 3626 struct btrfs_file_extent_item *extent; 3628 3627 struct btrfs_inode_item *inode_item; 3629 3628 struct extent_buffer *src = src_path->nodes[0]; ··· 3634 3633 char *ins_data; 3635 3634 int i; 3636 3635 struct list_head ordered_sums; 3637 - int skip_csum = BTRFS_I(inode)->flags & BTRFS_INODE_NODATASUM; 3636 + int skip_csum = inode->flags & BTRFS_INODE_NODATASUM; 3638 3637 bool has_extents = false; 3639 3638 bool need_find_last_extent = true; 3640 3639 bool done = false; ··· 3676 3675 dst_path->slots[0], 3677 3676 struct btrfs_inode_item); 3678 3677 fill_inode_item(trans, dst_path->nodes[0], inode_item, 3679 - inode, inode_only == LOG_INODE_EXISTS, 3678 + &inode->vfs_inode, 3679 + inode_only == LOG_INODE_EXISTS, 3680 3680 logged_isize); 3681 3681 } else { 3682 3682 copy_extent_buffer(dst_path->nodes[0], src, dst_offset, ··· 3785 3783 if (need_find_last_extent) { 3786 3784 u64 len; 3787 3785 3788 - ret = btrfs_prev_leaf(BTRFS_I(inode)->root, src_path); 3786 + ret = btrfs_prev_leaf(inode->root, src_path); 3789 3787 if (ret < 0) 3790 3788 return ret; 3791 3789 if (ret) ··· 3827 3825 if (need_find_last_extent) { 3828 3826 /* btrfs_prev_leaf could return 1 without releasing the path */ 3829 3827 btrfs_release_path(src_path); 3830 - ret = btrfs_search_slot(NULL, BTRFS_I(inode)->root, &first_key, 3831 - src_path, 0, 0); 3828 + ret = btrfs_search_slot(NULL, inode->root, &first_key, 3829 + src_path, 0, 0); 3832 3830 if (ret < 0) 3833 3831 return ret; 3834 3832 ASSERT(ret == 0); ··· 3848 3846 u64 extent_end; 3849 3847 3850 3848 if (i >= btrfs_header_nritems(src_path->nodes[0])) { 3851 - ret = btrfs_next_leaf(BTRFS_I(inode)->root, src_path); 3849 + ret = btrfs_next_leaf(inode->root, src_path); 3852 3850 if (ret < 0) 3853 3851 return ret; 3854 3852 ASSERT(ret == 0); ··· 3883 3881 offset = *last_extent; 3884 3882 len = key.offset - *last_extent; 3885 3883 ret = btrfs_insert_file_extent(trans, log, btrfs_ino(inode), 3886 - offset, 0, 0, len, 0, len, 0, 3887 - 0, 0); 3884 + offset, 0, 0, len, 0, len, 0, 0, 0); 3888 3885 if (ret) 3889 3886 break; 3890 3887 *last_extent = extent_end; ··· 4056 4055 } 4057 4056 4058 4057 static int log_one_extent(struct btrfs_trans_handle *trans, 4059 - struct inode *inode, struct btrfs_root *root, 4058 + struct btrfs_inode *inode, struct btrfs_root *root, 4060 4059 const struct extent_map *em, 4061 4060 struct btrfs_path *path, 4062 4061 const struct list_head *logged_list, ··· 4073 4072 int extent_inserted = 0; 4074 4073 bool ordered_io_err = false; 4075 4074 4076 - ret = wait_ordered_extents(trans, inode, root, em, logged_list, 4077 - &ordered_io_err); 4075 + ret = wait_ordered_extents(trans, &inode->vfs_inode, root, em, 4076 + logged_list, &ordered_io_err); 4078 4077 if (ret) 4079 4078 return ret; 4080 4079 ··· 4085 4084 4086 4085 btrfs_init_map_token(&token); 4087 4086 4088 - ret = __btrfs_drop_extents(trans, log, inode, path, em->start, 4087 + ret = __btrfs_drop_extents(trans, log, &inode->vfs_inode, path, em->start, 4089 4088 em->start + em->len, NULL, 0, 1, 4090 4089 sizeof(*fi), &extent_inserted); 4091 4090 if (ret) ··· 4151 4150 4152 4151 static int btrfs_log_changed_extents(struct btrfs_trans_handle *trans, 4153 4152 struct btrfs_root *root, 4154 - struct inode *inode, 4153 + struct btrfs_inode *inode, 4155 4154 struct btrfs_path *path, 4156 4155 struct list_head *logged_list, 4157 4156 struct btrfs_log_ctx *ctx, ··· 4160 4159 { 4161 4160 struct extent_map *em, *n; 4162 4161 struct list_head extents; 4163 - struct extent_map_tree *tree = &BTRFS_I(inode)->extent_tree; 4162 + struct extent_map_tree *tree = &inode->extent_tree; 4164 4163 u64 test_gen; 4165 4164 int ret = 0; 4166 4165 int num = 0; 4167 4166 4168 4167 INIT_LIST_HEAD(&extents); 4169 4168 4170 - down_write(&BTRFS_I(inode)->dio_sem); 4169 + down_write(&inode->dio_sem); 4171 4170 write_lock(&tree->lock); 4172 4171 test_gen = root->fs_info->last_trans_committed; 4173 4172 ··· 4207 4206 * without writing to the log tree and the fsync must report the 4208 4207 * file data write error and not commit the current transaction. 4209 4208 */ 4210 - ret = filemap_check_errors(inode->i_mapping); 4209 + ret = filemap_check_errors(inode->vfs_inode.i_mapping); 4211 4210 if (ret) 4212 4211 ctx->io_err = ret; 4213 4212 process: ··· 4236 4235 } 4237 4236 WARN_ON(!list_empty(&extents)); 4238 4237 write_unlock(&tree->lock); 4239 - up_write(&BTRFS_I(inode)->dio_sem); 4238 + up_write(&inode->dio_sem); 4240 4239 4241 4240 btrfs_release_path(path); 4242 4241 return ret; 4243 4242 } 4244 4243 4245 - static int logged_inode_size(struct btrfs_root *log, struct inode *inode, 4244 + static int logged_inode_size(struct btrfs_root *log, struct btrfs_inode *inode, 4246 4245 struct btrfs_path *path, u64 *size_ret) 4247 4246 { 4248 4247 struct btrfs_key key; ··· 4280 4279 */ 4281 4280 static int btrfs_log_all_xattrs(struct btrfs_trans_handle *trans, 4282 4281 struct btrfs_root *root, 4283 - struct inode *inode, 4282 + struct btrfs_inode *inode, 4284 4283 struct btrfs_path *path, 4285 4284 struct btrfs_path *dst_path) 4286 4285 { ··· 4375 4374 */ 4376 4375 static int btrfs_log_trailing_hole(struct btrfs_trans_handle *trans, 4377 4376 struct btrfs_root *root, 4378 - struct inode *inode, 4377 + struct btrfs_inode *inode, 4379 4378 struct btrfs_path *path) 4380 4379 { 4381 4380 struct btrfs_fs_info *fs_info = root->fs_info; ··· 4386 4385 struct extent_buffer *leaf; 4387 4386 struct btrfs_root *log = root->log_root; 4388 4387 const u64 ino = btrfs_ino(inode); 4389 - const u64 i_size = i_size_read(inode); 4388 + const u64 i_size = i_size_read(&inode->vfs_inode); 4390 4389 4391 4390 if (!btrfs_fs_incompat(fs_info, NO_HOLES)) 4392 4391 return 0; ··· 4496 4495 static int btrfs_check_ref_name_override(struct extent_buffer *eb, 4497 4496 const int slot, 4498 4497 const struct btrfs_key *key, 4499 - struct inode *inode, 4498 + struct btrfs_inode *inode, 4500 4499 u64 *other_ino) 4501 4500 { 4502 4501 int ret; ··· 4552 4551 } 4553 4552 4554 4553 read_extent_buffer(eb, name, name_ptr, this_name_len); 4555 - di = btrfs_lookup_dir_item(NULL, BTRFS_I(inode)->root, 4556 - search_path, parent, 4557 - name, this_name_len, 0); 4554 + di = btrfs_lookup_dir_item(NULL, inode->root, search_path, 4555 + parent, name, this_name_len, 0); 4558 4556 if (di && !IS_ERR(di)) { 4559 4557 struct btrfs_key di_key; 4560 4558 ··· 4596 4596 * This handles both files and directories. 4597 4597 */ 4598 4598 static int btrfs_log_inode(struct btrfs_trans_handle *trans, 4599 - struct btrfs_root *root, struct inode *inode, 4599 + struct btrfs_root *root, struct btrfs_inode *inode, 4600 4600 int inode_only, 4601 4601 const loff_t start, 4602 4602 const loff_t end, ··· 4618 4618 int ins_nr; 4619 4619 bool fast_search = false; 4620 4620 u64 ino = btrfs_ino(inode); 4621 - struct extent_map_tree *em_tree = &BTRFS_I(inode)->extent_tree; 4621 + struct extent_map_tree *em_tree = &inode->extent_tree; 4622 4622 u64 logged_isize = 0; 4623 4623 bool need_log_inode_item = true; 4624 4624 ··· 4639 4639 4640 4640 4641 4641 /* today the code can only do partial logging of directories */ 4642 - if (S_ISDIR(inode->i_mode) || 4642 + if (S_ISDIR(inode->vfs_inode.i_mode) || 4643 4643 (!test_bit(BTRFS_INODE_NEEDS_FULL_SYNC, 4644 - &BTRFS_I(inode)->runtime_flags) && 4644 + &inode->runtime_flags) && 4645 4645 inode_only >= LOG_INODE_EXISTS)) 4646 4646 max_key.type = BTRFS_XATTR_ITEM_KEY; 4647 4647 else ··· 4654 4654 * order for the log replay code to mark inodes for link count 4655 4655 * fixup (create temporary BTRFS_TREE_LOG_FIXUP_OBJECTID items). 4656 4656 */ 4657 - if (S_ISDIR(inode->i_mode) || 4658 - BTRFS_I(inode)->generation > fs_info->last_trans_committed) 4657 + if (S_ISDIR(inode->vfs_inode.i_mode) || 4658 + inode->generation > fs_info->last_trans_committed) 4659 4659 ret = btrfs_commit_inode_delayed_items(trans, inode); 4660 4660 else 4661 4661 ret = btrfs_commit_inode_delayed_inode(inode); ··· 4668 4668 4669 4669 if (inode_only == LOG_OTHER_INODE) { 4670 4670 inode_only = LOG_INODE_EXISTS; 4671 - mutex_lock_nested(&BTRFS_I(inode)->log_mutex, 4672 - SINGLE_DEPTH_NESTING); 4671 + mutex_lock_nested(&inode->log_mutex, SINGLE_DEPTH_NESTING); 4673 4672 } else { 4674 - mutex_lock(&BTRFS_I(inode)->log_mutex); 4673 + mutex_lock(&inode->log_mutex); 4675 4674 } 4676 4675 4677 4676 /* 4678 4677 * a brute force approach to making sure we get the most uptodate 4679 4678 * copies of everything. 4680 4679 */ 4681 - if (S_ISDIR(inode->i_mode)) { 4680 + if (S_ISDIR(inode->vfs_inode.i_mode)) { 4682 4681 int max_key_type = BTRFS_DIR_LOG_INDEX_KEY; 4683 4682 4684 4683 if (inode_only == LOG_INODE_EXISTS) ··· 4698 4699 * (zeroes), as if an expanding truncate happened, 4699 4700 * instead of getting a file of 4Kb only. 4700 4701 */ 4701 - err = logged_inode_size(log, inode, path, 4702 - &logged_isize); 4702 + err = logged_inode_size(log, inode, path, &logged_isize); 4703 4703 if (err) 4704 4704 goto out_unlock; 4705 4705 } 4706 4706 if (test_bit(BTRFS_INODE_NEEDS_FULL_SYNC, 4707 - &BTRFS_I(inode)->runtime_flags)) { 4707 + &inode->runtime_flags)) { 4708 4708 if (inode_only == LOG_INODE_EXISTS) { 4709 4709 max_key.type = BTRFS_XATTR_ITEM_KEY; 4710 4710 ret = drop_objectid_items(trans, log, path, ino, 4711 4711 max_key.type); 4712 4712 } else { 4713 4713 clear_bit(BTRFS_INODE_NEEDS_FULL_SYNC, 4714 - &BTRFS_I(inode)->runtime_flags); 4714 + &inode->runtime_flags); 4715 4715 clear_bit(BTRFS_INODE_COPY_EVERYTHING, 4716 - &BTRFS_I(inode)->runtime_flags); 4716 + &inode->runtime_flags); 4717 4717 while(1) { 4718 4718 ret = btrfs_truncate_inode_items(trans, 4719 - log, inode, 0, 0); 4719 + log, &inode->vfs_inode, 0, 0); 4720 4720 if (ret != -EAGAIN) 4721 4721 break; 4722 4722 } 4723 4723 } 4724 4724 } else if (test_and_clear_bit(BTRFS_INODE_COPY_EVERYTHING, 4725 - &BTRFS_I(inode)->runtime_flags) || 4725 + &inode->runtime_flags) || 4726 4726 inode_only == LOG_INODE_EXISTS) { 4727 4727 if (inode_only == LOG_INODE_ALL) 4728 4728 fast_search = true; ··· 4762 4764 4763 4765 if ((min_key.type == BTRFS_INODE_REF_KEY || 4764 4766 min_key.type == BTRFS_INODE_EXTREF_KEY) && 4765 - BTRFS_I(inode)->generation == trans->transid) { 4767 + inode->generation == trans->transid) { 4766 4768 u64 other_ino = 0; 4767 4769 4768 4770 ret = btrfs_check_ref_name_override(path->nodes[0], 4769 - path->slots[0], 4770 - &min_key, inode, 4771 - &other_ino); 4771 + path->slots[0], &min_key, inode, 4772 + &other_ino); 4772 4773 if (ret < 0) { 4773 4774 err = ret; 4774 4775 goto out_unlock; 4775 4776 } else if (ret > 0 && ctx && 4776 - other_ino != btrfs_ino(ctx->inode)) { 4777 + other_ino != btrfs_ino(BTRFS_I(ctx->inode))) { 4777 4778 struct btrfs_key inode_key; 4778 4779 struct inode *other_inode; 4779 4780 ··· 4820 4823 * update the log with the new name before we 4821 4824 * unpin it. 4822 4825 */ 4823 - err = btrfs_log_inode(trans, root, other_inode, 4824 - LOG_OTHER_INODE, 4825 - 0, LLONG_MAX, ctx); 4826 + err = btrfs_log_inode(trans, root, 4827 + BTRFS_I(other_inode), 4828 + LOG_OTHER_INODE, 0, LLONG_MAX, 4829 + ctx); 4826 4830 iput(other_inode); 4827 4831 if (err) 4828 4832 goto out_unlock; ··· 4977 4979 write_unlock(&em_tree->lock); 4978 4980 } 4979 4981 4980 - if (inode_only == LOG_INODE_ALL && S_ISDIR(inode->i_mode)) { 4982 + if (inode_only == LOG_INODE_ALL && S_ISDIR(inode->vfs_inode.i_mode)) { 4981 4983 ret = log_directory_changes(trans, root, inode, path, dst_path, 4982 - ctx); 4984 + ctx); 4983 4985 if (ret) { 4984 4986 err = ret; 4985 4987 goto out_unlock; 4986 4988 } 4987 4989 } 4988 4990 4989 - spin_lock(&BTRFS_I(inode)->lock); 4990 - BTRFS_I(inode)->logged_trans = trans->transid; 4991 - BTRFS_I(inode)->last_log_commit = BTRFS_I(inode)->last_sub_trans; 4992 - spin_unlock(&BTRFS_I(inode)->lock); 4991 + spin_lock(&inode->lock); 4992 + inode->logged_trans = trans->transid; 4993 + inode->last_log_commit = inode->last_sub_trans; 4994 + spin_unlock(&inode->lock); 4993 4995 out_unlock: 4994 4996 if (unlikely(err)) 4995 4997 btrfs_put_logged_extents(&logged_list); 4996 4998 else 4997 4999 btrfs_submit_logged_extents(&logged_list, log); 4998 - mutex_unlock(&BTRFS_I(inode)->log_mutex); 5000 + mutex_unlock(&inode->log_mutex); 4999 5001 5000 5002 btrfs_free_path(path); 5001 5003 btrfs_free_path(dst_path); ··· 5019 5021 * we logged the inode or it might have also done the unlink). 5020 5022 */ 5021 5023 static bool btrfs_must_commit_transaction(struct btrfs_trans_handle *trans, 5022 - struct inode *inode) 5024 + struct btrfs_inode *inode) 5023 5025 { 5024 - struct btrfs_fs_info *fs_info = BTRFS_I(inode)->root->fs_info; 5026 + struct btrfs_fs_info *fs_info = inode->root->fs_info; 5025 5027 bool ret = false; 5026 5028 5027 - mutex_lock(&BTRFS_I(inode)->log_mutex); 5028 - if (BTRFS_I(inode)->last_unlink_trans > fs_info->last_trans_committed) { 5029 + mutex_lock(&inode->log_mutex); 5030 + if (inode->last_unlink_trans > fs_info->last_trans_committed) { 5029 5031 /* 5030 5032 * Make sure any commits to the log are forced to be full 5031 5033 * commits. ··· 5033 5035 btrfs_set_log_full_commit(fs_info, trans); 5034 5036 ret = true; 5035 5037 } 5036 - mutex_unlock(&BTRFS_I(inode)->log_mutex); 5038 + mutex_unlock(&inode->log_mutex); 5037 5039 5038 5040 return ret; 5039 5041 } ··· 5082 5084 BTRFS_I(inode)->logged_trans = trans->transid; 5083 5085 smp_mb(); 5084 5086 5085 - if (btrfs_must_commit_transaction(trans, inode)) { 5087 + if (btrfs_must_commit_transaction(trans, BTRFS_I(inode))) { 5086 5088 ret = 1; 5087 5089 break; 5088 5090 } ··· 5092 5094 5093 5095 if (IS_ROOT(parent)) { 5094 5096 inode = d_inode(parent); 5095 - if (btrfs_must_commit_transaction(trans, inode)) 5097 + if (btrfs_must_commit_transaction(trans, BTRFS_I(inode))) 5096 5098 ret = 1; 5097 5099 break; 5098 5100 } ··· 5157 5159 */ 5158 5160 static int log_new_dir_dentries(struct btrfs_trans_handle *trans, 5159 5161 struct btrfs_root *root, 5160 - struct inode *start_inode, 5162 + struct btrfs_inode *start_inode, 5161 5163 struct btrfs_log_ctx *ctx) 5162 5164 { 5163 5165 struct btrfs_fs_info *fs_info = root->fs_info; ··· 5235 5237 goto next_dir_inode; 5236 5238 } 5237 5239 5238 - if (btrfs_inode_in_log(di_inode, trans->transid)) { 5240 + if (btrfs_inode_in_log(BTRFS_I(di_inode), trans->transid)) { 5239 5241 iput(di_inode); 5240 5242 break; 5241 5243 } ··· 5243 5245 ctx->log_new_dentries = false; 5244 5246 if (type == BTRFS_FT_DIR || type == BTRFS_FT_SYMLINK) 5245 5247 log_mode = LOG_INODE_ALL; 5246 - ret = btrfs_log_inode(trans, root, di_inode, 5248 + ret = btrfs_log_inode(trans, root, BTRFS_I(di_inode), 5247 5249 log_mode, 0, LLONG_MAX, ctx); 5248 5250 if (!ret && 5249 - btrfs_must_commit_transaction(trans, di_inode)) 5251 + btrfs_must_commit_transaction(trans, BTRFS_I(di_inode))) 5250 5252 ret = 1; 5251 5253 iput(di_inode); 5252 5254 if (ret) ··· 5295 5297 struct btrfs_path *path; 5296 5298 struct btrfs_key key; 5297 5299 struct btrfs_root *root = BTRFS_I(inode)->root; 5298 - const u64 ino = btrfs_ino(inode); 5300 + const u64 ino = btrfs_ino(BTRFS_I(inode)); 5299 5301 5300 5302 path = btrfs_alloc_path(); 5301 5303 if (!path) ··· 5363 5365 5364 5366 if (ctx) 5365 5367 ctx->log_new_dentries = false; 5366 - ret = btrfs_log_inode(trans, root, dir_inode, 5368 + ret = btrfs_log_inode(trans, root, BTRFS_I(dir_inode), 5367 5369 LOG_INODE_ALL, 0, LLONG_MAX, ctx); 5368 5370 if (!ret && 5369 - btrfs_must_commit_transaction(trans, dir_inode)) 5371 + btrfs_must_commit_transaction(trans, BTRFS_I(dir_inode))) 5370 5372 ret = 1; 5371 5373 if (!ret && ctx && ctx->log_new_dentries) 5372 5374 ret = log_new_dir_dentries(trans, root, 5373 - dir_inode, ctx); 5375 + BTRFS_I(dir_inode), ctx); 5374 5376 iput(dir_inode); 5375 5377 if (ret) 5376 5378 goto out; ··· 5434 5436 if (ret) 5435 5437 goto end_no_trans; 5436 5438 5437 - if (btrfs_inode_in_log(inode, trans->transid)) { 5439 + if (btrfs_inode_in_log(BTRFS_I(inode), trans->transid)) { 5438 5440 ret = BTRFS_NO_LOG_SYNC; 5439 5441 goto end_no_trans; 5440 5442 } ··· 5443 5445 if (ret) 5444 5446 goto end_no_trans; 5445 5447 5446 - ret = btrfs_log_inode(trans, root, inode, inode_only, start, end, ctx); 5448 + ret = btrfs_log_inode(trans, root, BTRFS_I(inode), inode_only, 5449 + start, end, ctx); 5447 5450 if (ret) 5448 5451 goto end_trans; 5449 5452 ··· 5520 5521 break; 5521 5522 5522 5523 if (BTRFS_I(inode)->generation > last_committed) { 5523 - ret = btrfs_log_inode(trans, root, inode, 5524 + ret = btrfs_log_inode(trans, root, BTRFS_I(inode), 5524 5525 LOG_INODE_EXISTS, 5525 5526 0, LLONG_MAX, ctx); 5526 5527 if (ret) ··· 5534 5535 old_parent = parent; 5535 5536 } 5536 5537 if (log_dentries) 5537 - ret = log_new_dir_dentries(trans, root, orig_inode, ctx); 5538 + ret = log_new_dir_dentries(trans, root, BTRFS_I(orig_inode), ctx); 5538 5539 else 5539 5540 ret = 0; 5540 5541 end_trans: ··· 5729 5730 * inodes, etc) are done. 5730 5731 */ 5731 5732 void btrfs_record_unlink_dir(struct btrfs_trans_handle *trans, 5732 - struct inode *dir, struct inode *inode, 5733 + struct btrfs_inode *dir, struct btrfs_inode *inode, 5733 5734 int for_rename) 5734 5735 { 5735 5736 /* ··· 5742 5743 * into the file. When the file is logged we check it and 5743 5744 * don't log the parents if the file is fully on disk. 5744 5745 */ 5745 - mutex_lock(&BTRFS_I(inode)->log_mutex); 5746 - BTRFS_I(inode)->last_unlink_trans = trans->transid; 5747 - mutex_unlock(&BTRFS_I(inode)->log_mutex); 5746 + mutex_lock(&inode->log_mutex); 5747 + inode->last_unlink_trans = trans->transid; 5748 + mutex_unlock(&inode->log_mutex); 5748 5749 5749 5750 /* 5750 5751 * if this directory was already logged any new 5751 5752 * names for this file/dir will get recorded 5752 5753 */ 5753 5754 smp_mb(); 5754 - if (BTRFS_I(dir)->logged_trans == trans->transid) 5755 + if (dir->logged_trans == trans->transid) 5755 5756 return; 5756 5757 5757 5758 /* 5758 5759 * if the inode we're about to unlink was logged, 5759 5760 * the log will be properly updated for any new names 5760 5761 */ 5761 - if (BTRFS_I(inode)->logged_trans == trans->transid) 5762 + if (inode->logged_trans == trans->transid) 5762 5763 return; 5763 5764 5764 5765 /* ··· 5775 5776 return; 5776 5777 5777 5778 record: 5778 - mutex_lock(&BTRFS_I(dir)->log_mutex); 5779 - BTRFS_I(dir)->last_unlink_trans = trans->transid; 5780 - mutex_unlock(&BTRFS_I(dir)->log_mutex); 5779 + mutex_lock(&dir->log_mutex); 5780 + dir->last_unlink_trans = trans->transid; 5781 + mutex_unlock(&dir->log_mutex); 5781 5782 } 5782 5783 5783 5784 /* ··· 5793 5794 * parent root and tree of tree roots trees, etc) are done. 5794 5795 */ 5795 5796 void btrfs_record_snapshot_destroy(struct btrfs_trans_handle *trans, 5796 - struct inode *dir) 5797 + struct btrfs_inode *dir) 5797 5798 { 5798 - mutex_lock(&BTRFS_I(dir)->log_mutex); 5799 - BTRFS_I(dir)->last_unlink_trans = trans->transid; 5800 - mutex_unlock(&BTRFS_I(dir)->log_mutex); 5799 + mutex_lock(&dir->log_mutex); 5800 + dir->last_unlink_trans = trans->transid; 5801 + mutex_unlock(&dir->log_mutex); 5801 5802 } 5802 5803 5803 5804 /* ··· 5808 5809 * full transaction commit is required. 5809 5810 */ 5810 5811 int btrfs_log_new_name(struct btrfs_trans_handle *trans, 5811 - struct inode *inode, struct inode *old_dir, 5812 + struct btrfs_inode *inode, struct btrfs_inode *old_dir, 5812 5813 struct dentry *parent) 5813 5814 { 5814 - struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb); 5815 - struct btrfs_root * root = BTRFS_I(inode)->root; 5815 + struct btrfs_fs_info *fs_info = btrfs_sb(inode->vfs_inode.i_sb); 5816 + struct btrfs_root *root = inode->root; 5816 5817 5817 5818 /* 5818 5819 * this will force the logging code to walk the dentry chain 5819 5820 * up for the file 5820 5821 */ 5821 - if (S_ISREG(inode->i_mode)) 5822 - BTRFS_I(inode)->last_unlink_trans = trans->transid; 5822 + if (S_ISREG(inode->vfs_inode.i_mode)) 5823 + inode->last_unlink_trans = trans->transid; 5823 5824 5824 5825 /* 5825 5826 * if this inode hasn't been logged and directory we're renaming it 5826 5827 * from hasn't been logged, we don't need to log it 5827 5828 */ 5828 - if (BTRFS_I(inode)->logged_trans <= 5829 - fs_info->last_trans_committed && 5830 - (!old_dir || BTRFS_I(old_dir)->logged_trans <= 5831 - fs_info->last_trans_committed)) 5829 + if (inode->logged_trans <= fs_info->last_trans_committed && 5830 + (!old_dir || old_dir->logged_trans <= fs_info->last_trans_committed)) 5832 5831 return 0; 5833 5832 5834 - return btrfs_log_inode_parent(trans, root, inode, parent, 0, 5833 + return btrfs_log_inode_parent(trans, root, &inode->vfs_inode, parent, 0, 5835 5834 LLONG_MAX, 1, NULL); 5836 5835 } 5837 5836
+7 -7
fs/btrfs/tree-log.h
··· 48 48 static inline void btrfs_set_log_full_commit(struct btrfs_fs_info *fs_info, 49 49 struct btrfs_trans_handle *trans) 50 50 { 51 - ACCESS_ONCE(fs_info->last_trans_log_full_commit) = trans->transid; 51 + WRITE_ONCE(fs_info->last_trans_log_full_commit, trans->transid); 52 52 } 53 53 54 54 static inline int btrfs_need_log_full_commit(struct btrfs_fs_info *fs_info, 55 55 struct btrfs_trans_handle *trans) 56 56 { 57 - return ACCESS_ONCE(fs_info->last_trans_log_full_commit) == 57 + return READ_ONCE(fs_info->last_trans_log_full_commit) == 58 58 trans->transid; 59 59 } 60 60 ··· 72 72 int btrfs_del_dir_entries_in_log(struct btrfs_trans_handle *trans, 73 73 struct btrfs_root *root, 74 74 const char *name, int name_len, 75 - struct inode *dir, u64 index); 75 + struct btrfs_inode *dir, u64 index); 76 76 int btrfs_del_inode_ref_in_log(struct btrfs_trans_handle *trans, 77 77 struct btrfs_root *root, 78 78 const char *name, int name_len, 79 - struct inode *inode, u64 dirid); 79 + struct btrfs_inode *inode, u64 dirid); 80 80 void btrfs_end_log_trans(struct btrfs_root *root); 81 81 int btrfs_pin_log_trans(struct btrfs_root *root); 82 82 void btrfs_record_unlink_dir(struct btrfs_trans_handle *trans, 83 - struct inode *dir, struct inode *inode, 83 + struct btrfs_inode *dir, struct btrfs_inode *inode, 84 84 int for_rename); 85 85 void btrfs_record_snapshot_destroy(struct btrfs_trans_handle *trans, 86 - struct inode *dir); 86 + struct btrfs_inode *dir); 87 87 int btrfs_log_new_name(struct btrfs_trans_handle *trans, 88 - struct inode *inode, struct inode *old_dir, 88 + struct btrfs_inode *inode, struct btrfs_inode *old_dir, 89 89 struct dentry *parent); 90 90 #endif
+5 -5
fs/btrfs/ulist.c
··· 52 52 } 53 53 54 54 /** 55 - * ulist_fini - free up additionally allocated memory for the ulist 55 + * ulist_release - free up additionally allocated memory for the ulist 56 56 * @ulist: the ulist from which to free the additional memory 57 57 * 58 58 * This is useful in cases where the base 'struct ulist' has been statically 59 59 * allocated. 60 60 */ 61 - static void ulist_fini(struct ulist *ulist) 61 + void ulist_release(struct ulist *ulist) 62 62 { 63 63 struct ulist_node *node; 64 64 struct ulist_node *next; ··· 79 79 */ 80 80 void ulist_reinit(struct ulist *ulist) 81 81 { 82 - ulist_fini(ulist); 82 + ulist_release(ulist); 83 83 ulist_init(ulist); 84 84 } 85 85 ··· 105 105 * ulist_free - free dynamically allocated ulist 106 106 * @ulist: ulist to free 107 107 * 108 - * It is not necessary to call ulist_fini before. 108 + * It is not necessary to call ulist_release before. 109 109 */ 110 110 void ulist_free(struct ulist *ulist) 111 111 { 112 112 if (!ulist) 113 113 return; 114 - ulist_fini(ulist); 114 + ulist_release(ulist); 115 115 kfree(ulist); 116 116 } 117 117
+1 -7
fs/btrfs/ulist.h
··· 19 19 * 20 20 */ 21 21 struct ulist_iterator { 22 - #ifdef CONFIG_BTRFS_DEBUG 23 - int i; 24 - #endif 25 22 struct list_head *cur_list; /* hint to start search */ 26 23 }; 27 24 ··· 28 31 struct ulist_node { 29 32 u64 val; /* value to store */ 30 33 u64 aux; /* auxiliary value saved along with the val */ 31 - 32 - #ifdef CONFIG_BTRFS_DEBUG 33 - int seqnum; /* sequence number this node is added */ 34 - #endif 35 34 36 35 struct list_head list; /* used to link node */ 37 36 struct rb_node rb_node; /* used to speed up search */ ··· 44 51 }; 45 52 46 53 void ulist_init(struct ulist *ulist); 54 + void ulist_release(struct ulist *ulist); 47 55 void ulist_reinit(struct ulist *ulist); 48 56 struct ulist *ulist_alloc(gfp_t gfp_mask); 49 57 void ulist_free(struct ulist *ulist);
+7 -11
fs/btrfs/volumes.c
··· 134 134 }; 135 135 136 136 static int init_first_rw_device(struct btrfs_trans_handle *trans, 137 - struct btrfs_fs_info *fs_info, 138 - struct btrfs_device *device); 137 + struct btrfs_fs_info *fs_info); 139 138 static int btrfs_relocate_sys_chunks(struct btrfs_fs_info *fs_info); 140 139 static void __btrfs_reset_dev_stats(struct btrfs_device *dev); 141 140 static void btrfs_dev_stat_print_on_error(struct btrfs_device *dev); ··· 2439 2440 2440 2441 if (seeding_dev) { 2441 2442 mutex_lock(&fs_info->chunk_mutex); 2442 - ret = init_first_rw_device(trans, fs_info, device); 2443 + ret = init_first_rw_device(trans, fs_info); 2443 2444 mutex_unlock(&fs_info->chunk_mutex); 2444 2445 if (ret) { 2445 2446 btrfs_abort_transaction(trans, ret); ··· 4583 4584 / sizeof(struct btrfs_stripe) + 1) 4584 4585 4585 4586 static int __btrfs_alloc_chunk(struct btrfs_trans_handle *trans, 4586 - struct btrfs_fs_info *fs_info, u64 start, 4587 - u64 type) 4587 + u64 start, u64 type) 4588 4588 { 4589 4589 struct btrfs_fs_info *info = trans->fs_info; 4590 4590 struct btrfs_fs_devices *fs_devices = info->fs_devices; ··· 5007 5009 5008 5010 ASSERT(mutex_is_locked(&fs_info->chunk_mutex)); 5009 5011 chunk_offset = find_next_chunk(fs_info); 5010 - return __btrfs_alloc_chunk(trans, fs_info, chunk_offset, type); 5012 + return __btrfs_alloc_chunk(trans, chunk_offset, type); 5011 5013 } 5012 5014 5013 5015 static noinline int init_first_rw_device(struct btrfs_trans_handle *trans, 5014 - struct btrfs_fs_info *fs_info, 5015 - struct btrfs_device *device) 5016 + struct btrfs_fs_info *fs_info) 5016 5017 { 5017 5018 struct btrfs_root *extent_root = fs_info->extent_root; 5018 5019 u64 chunk_offset; ··· 5021 5024 5022 5025 chunk_offset = find_next_chunk(fs_info); 5023 5026 alloc_profile = btrfs_get_alloc_profile(extent_root, 0); 5024 - ret = __btrfs_alloc_chunk(trans, fs_info, chunk_offset, alloc_profile); 5027 + ret = __btrfs_alloc_chunk(trans, chunk_offset, alloc_profile); 5025 5028 if (ret) 5026 5029 return ret; 5027 5030 5028 5031 sys_chunk_offset = find_next_chunk(fs_info); 5029 5032 alloc_profile = btrfs_get_alloc_profile(fs_info->chunk_root, 0); 5030 - ret = __btrfs_alloc_chunk(trans, fs_info, sys_chunk_offset, 5031 - alloc_profile); 5033 + ret = __btrfs_alloc_chunk(trans, sys_chunk_offset, alloc_profile); 5032 5034 return ret; 5033 5035 } 5034 5036
+8 -8
fs/btrfs/xattr.c
··· 47 47 return -ENOMEM; 48 48 49 49 /* lookup the xattr by name */ 50 - di = btrfs_lookup_xattr(NULL, root, path, btrfs_ino(inode), name, 51 - strlen(name), 0); 50 + di = btrfs_lookup_xattr(NULL, root, path, btrfs_ino(BTRFS_I(inode)), 51 + name, strlen(name), 0); 52 52 if (!di) { 53 53 ret = -ENODATA; 54 54 goto out; ··· 108 108 path->skip_release_on_error = 1; 109 109 110 110 if (!value) { 111 - di = btrfs_lookup_xattr(trans, root, path, btrfs_ino(inode), 112 - name, name_len, -1); 111 + di = btrfs_lookup_xattr(trans, root, path, 112 + btrfs_ino(BTRFS_I(inode)), name, name_len, -1); 113 113 if (!di && (flags & XATTR_REPLACE)) 114 114 ret = -ENODATA; 115 115 else if (IS_ERR(di)) ··· 128 128 */ 129 129 if (flags & XATTR_REPLACE) { 130 130 ASSERT(inode_is_locked(inode)); 131 - di = btrfs_lookup_xattr(NULL, root, path, btrfs_ino(inode), 132 - name, name_len, 0); 131 + di = btrfs_lookup_xattr(NULL, root, path, 132 + btrfs_ino(BTRFS_I(inode)), name, name_len, 0); 133 133 if (!di) 134 134 ret = -ENODATA; 135 135 else if (IS_ERR(di)) ··· 140 140 di = NULL; 141 141 } 142 142 143 - ret = btrfs_insert_xattr_item(trans, root, path, btrfs_ino(inode), 143 + ret = btrfs_insert_xattr_item(trans, root, path, btrfs_ino(BTRFS_I(inode)), 144 144 name, name_len, value, size); 145 145 if (ret == -EOVERFLOW) { 146 146 /* ··· 278 278 * NOTE: we set key.offset = 0; because we want to start with the 279 279 * first xattr that we find and walk forward 280 280 */ 281 - key.objectid = btrfs_ino(inode); 281 + key.objectid = btrfs_ino(BTRFS_I(inode)); 282 282 key.type = BTRFS_XATTR_ITEM_KEY; 283 283 key.offset = 0; 284 284
+1 -1
include/trace/events/btrfs.h
··· 184 184 185 185 TRACE_EVENT_CONDITION(btrfs_get_extent, 186 186 187 - TP_PROTO(struct btrfs_root *root, struct inode *inode, 187 + TP_PROTO(struct btrfs_root *root, struct btrfs_inode *inode, 188 188 struct extent_map *map), 189 189 190 190 TP_ARGS(root, inode, map),