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

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

* 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mason/btrfs-unstable: (31 commits)
Btrfs: don't call writepages from within write_full_page
Btrfs: Remove unused variable 'last_index' in file.c
Btrfs: clean up for find_first_extent_bit()
Btrfs: clean up for wait_extent_bit()
Btrfs: clean up for insert_state()
Btrfs: remove unused members from struct extent_state
Btrfs: clean up code for merging extent maps
Btrfs: clean up code for extent_map lookup
Btrfs: clean up search_extent_mapping()
Btrfs: remove redundant code for dir item lookup
Btrfs: make acl functions really no-op if acl is not enabled
Btrfs: remove remaining ref-cache code
Btrfs: remove a BUG_ON() in btrfs_commit_transaction()
Btrfs: use wait_event()
Btrfs: check the nodatasum flag when writing compressed files
Btrfs: copy string correctly in INO_LOOKUP ioctl
Btrfs: don't print the leaf if we had an error
btrfs: make btrfs_set_root_node void
Btrfs: fix oops while writing data to SSD partitions
Btrfs: Protect the readonly flag of block group
...

Fix up trivial conflicts (due to acl and writeback cleanups) in
- fs/btrfs/acl.c
- fs/btrfs/ctree.h
- fs/btrfs/extent_io.c

+270 -529
+3 -1
fs/btrfs/Makefile
··· 6 6 transaction.o inode.o file.o tree-defrag.o \ 7 7 extent_map.o sysfs.o struct-funcs.o xattr.o ordered-data.o \ 8 8 extent_io.o volumes.o async-thread.o ioctl.o locking.o orphan.o \ 9 - export.o tree-log.o acl.o free-space-cache.o zlib.o lzo.o \ 9 + export.o tree-log.o free-space-cache.o zlib.o lzo.o \ 10 10 compression.o delayed-ref.o relocation.o delayed-inode.o scrub.o 11 + 12 + btrfs-$(CONFIG_BTRFS_FS_POSIX_ACL) += acl.o
-17
fs/btrfs/acl.c
··· 28 28 #include "btrfs_inode.h" 29 29 #include "xattr.h" 30 30 31 - #ifdef CONFIG_BTRFS_FS_POSIX_ACL 32 - 33 31 struct posix_acl *btrfs_get_acl(struct inode *inode, int type) 34 32 { 35 33 int size; ··· 274 276 .get = btrfs_xattr_acl_get, 275 277 .set = btrfs_xattr_acl_set, 276 278 }; 277 - 278 - #else /* CONFIG_BTRFS_FS_POSIX_ACL */ 279 - 280 - int btrfs_acl_chmod(struct inode *inode) 281 - { 282 - return 0; 283 - } 284 - 285 - int btrfs_init_acl(struct btrfs_trans_handle *trans, 286 - struct inode *inode, struct inode *dir) 287 - { 288 - return 0; 289 - } 290 - 291 - #endif /* CONFIG_BTRFS_FS_POSIX_ACL */
+10 -4
fs/btrfs/compression.c
··· 338 338 u64 first_byte = disk_start; 339 339 struct block_device *bdev; 340 340 int ret; 341 + int skip_sum = BTRFS_I(inode)->flags & BTRFS_INODE_NODATASUM; 341 342 342 343 WARN_ON(start & ((u64)PAGE_CACHE_SIZE - 1)); 343 344 cb = kmalloc(compressed_bio_size(root, compressed_len), GFP_NOFS); ··· 393 392 ret = btrfs_bio_wq_end_io(root->fs_info, bio, 0); 394 393 BUG_ON(ret); 395 394 396 - ret = btrfs_csum_one_bio(root, inode, bio, start, 1); 397 - BUG_ON(ret); 395 + if (!skip_sum) { 396 + ret = btrfs_csum_one_bio(root, inode, bio, 397 + start, 1); 398 + BUG_ON(ret); 399 + } 398 400 399 401 ret = btrfs_map_bio(root, WRITE, bio, 0, 1); 400 402 BUG_ON(ret); ··· 422 418 ret = btrfs_bio_wq_end_io(root->fs_info, bio, 0); 423 419 BUG_ON(ret); 424 420 425 - ret = btrfs_csum_one_bio(root, inode, bio, start, 1); 426 - BUG_ON(ret); 421 + if (!skip_sum) { 422 + ret = btrfs_csum_one_bio(root, inode, bio, start, 1); 423 + BUG_ON(ret); 424 + } 427 425 428 426 ret = btrfs_map_bio(root, WRITE, bio, 0, 1); 429 427 BUG_ON(ret);
+22 -8
fs/btrfs/ctree.h
··· 2406 2406 btrfs_root_item *item, struct btrfs_key *key); 2407 2407 int btrfs_find_dead_roots(struct btrfs_root *root, u64 objectid); 2408 2408 int btrfs_find_orphan_roots(struct btrfs_root *tree_root); 2409 - int btrfs_set_root_node(struct btrfs_root_item *item, 2410 - struct extent_buffer *node); 2409 + void btrfs_set_root_node(struct btrfs_root_item *item, 2410 + struct extent_buffer *node); 2411 2411 void btrfs_check_and_init_root_item(struct btrfs_root_item *item); 2412 2412 2413 2413 /* dir-item.c */ ··· 2523 2523 #define PageChecked PageFsMisc 2524 2524 #endif 2525 2525 2526 + /* This forces readahead on a given range of bytes in an inode */ 2527 + static inline void btrfs_force_ra(struct address_space *mapping, 2528 + struct file_ra_state *ra, struct file *file, 2529 + pgoff_t offset, unsigned long req_size) 2530 + { 2531 + page_cache_sync_readahead(mapping, ra, file, offset, req_size); 2532 + } 2533 + 2526 2534 struct inode *btrfs_lookup_dentry(struct inode *dir, struct dentry *dentry); 2527 2535 int btrfs_set_inode_index(struct inode *dir, u64 *index); 2528 2536 int btrfs_unlink_inode(struct btrfs_trans_handle *trans, ··· 2559 2551 int btrfs_merge_bio_hook(struct page *page, unsigned long offset, 2560 2552 size_t size, struct bio *bio, unsigned long bio_flags); 2561 2553 2562 - unsigned long btrfs_force_ra(struct address_space *mapping, 2563 - struct file_ra_state *ra, struct file *file, 2564 - pgoff_t offset, pgoff_t last_index); 2565 2554 int btrfs_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf); 2566 2555 int btrfs_readpage(struct file *file, struct page *page); 2567 2556 void btrfs_evict_inode(struct inode *inode); ··· 2653 2648 /* acl.c */ 2654 2649 #ifdef CONFIG_BTRFS_FS_POSIX_ACL 2655 2650 struct posix_acl *btrfs_get_acl(struct inode *inode, int type); 2656 - #else 2657 - #define btrfs_get_acl NULL 2658 - #endif 2659 2651 int btrfs_init_acl(struct btrfs_trans_handle *trans, 2660 2652 struct inode *inode, struct inode *dir); 2661 2653 int btrfs_acl_chmod(struct inode *inode); 2654 + #else 2655 + #define btrfs_get_acl NULL 2656 + static inline int btrfs_init_acl(struct btrfs_trans_handle *trans, 2657 + struct inode *inode, struct inode *dir) 2658 + { 2659 + return 0; 2660 + } 2661 + static inline int btrfs_acl_chmod(struct inode *inode) 2662 + { 2663 + return 0; 2664 + } 2665 + #endif 2662 2666 2663 2667 /* relocation.c */ 2664 2668 int btrfs_relocate_block_group(struct btrfs_root *root, u64 group_start);
+2 -28
fs/btrfs/dir-item.c
··· 198 198 struct btrfs_key key; 199 199 int ins_len = mod < 0 ? -1 : 0; 200 200 int cow = mod != 0; 201 - struct btrfs_key found_key; 202 - struct extent_buffer *leaf; 203 201 204 202 key.objectid = dir; 205 203 btrfs_set_key_type(&key, BTRFS_DIR_ITEM_KEY); ··· 207 209 ret = btrfs_search_slot(trans, root, &key, path, ins_len, cow); 208 210 if (ret < 0) 209 211 return ERR_PTR(ret); 210 - if (ret > 0) { 211 - if (path->slots[0] == 0) 212 - return NULL; 213 - path->slots[0]--; 214 - } 215 - 216 - leaf = path->nodes[0]; 217 - btrfs_item_key_to_cpu(leaf, &found_key, path->slots[0]); 218 - 219 - if (found_key.objectid != dir || 220 - btrfs_key_type(&found_key) != BTRFS_DIR_ITEM_KEY || 221 - found_key.offset != key.offset) 212 + if (ret > 0) 222 213 return NULL; 223 214 224 215 return btrfs_match_dir_item_name(root, path, name, name_len); ··· 302 315 struct btrfs_key key; 303 316 int ins_len = mod < 0 ? -1 : 0; 304 317 int cow = mod != 0; 305 - struct btrfs_key found_key; 306 - struct extent_buffer *leaf; 307 318 308 319 key.objectid = dir; 309 320 btrfs_set_key_type(&key, BTRFS_XATTR_ITEM_KEY); ··· 309 324 ret = btrfs_search_slot(trans, root, &key, path, ins_len, cow); 310 325 if (ret < 0) 311 326 return ERR_PTR(ret); 312 - if (ret > 0) { 313 - if (path->slots[0] == 0) 314 - return NULL; 315 - path->slots[0]--; 316 - } 317 - 318 - leaf = path->nodes[0]; 319 - btrfs_item_key_to_cpu(leaf, &found_key, path->slots[0]); 320 - 321 - if (found_key.objectid != dir || 322 - btrfs_key_type(&found_key) != BTRFS_XATTR_ITEM_KEY || 323 - found_key.offset != key.offset) 327 + if (ret > 0) 324 328 return NULL; 325 329 326 330 return btrfs_match_dir_item_name(root, path, name, name_len);
+34 -11
fs/btrfs/extent-tree.c
··· 663 663 struct btrfs_path *path; 664 664 665 665 path = btrfs_alloc_path(); 666 - BUG_ON(!path); 666 + if (!path) 667 + return -ENOMEM; 668 + 667 669 key.objectid = start; 668 670 key.offset = len; 669 671 btrfs_set_key_type(&key, BTRFS_EXTENT_ITEM_KEY); ··· 3274 3272 } 3275 3273 3276 3274 ret = btrfs_alloc_chunk(trans, extent_root, flags); 3275 + if (ret < 0 && ret != -ENOSPC) 3276 + goto out; 3277 + 3277 3278 spin_lock(&space_info->lock); 3278 3279 if (ret) 3279 3280 space_info->full = 1; ··· 3286 3281 space_info->force_alloc = CHUNK_ALLOC_NO_FORCE; 3287 3282 space_info->chunk_alloc = 0; 3288 3283 spin_unlock(&space_info->lock); 3284 + out: 3289 3285 mutex_unlock(&extent_root->fs_info->chunk_mutex); 3290 3286 return ret; 3291 3287 } ··· 4462 4456 printk(KERN_ERR "umm, got %d back from search" 4463 4457 ", was looking for %llu\n", ret, 4464 4458 (unsigned long long)bytenr); 4465 - btrfs_print_leaf(extent_root, path->nodes[0]); 4459 + if (ret > 0) 4460 + btrfs_print_leaf(extent_root, 4461 + path->nodes[0]); 4466 4462 } 4467 4463 BUG_ON(ret); 4468 4464 extent_slot = path->slots[0]; ··· 5081 5073 * group is does point to and try again 5082 5074 */ 5083 5075 if (!last_ptr_loop && last_ptr->block_group && 5084 - last_ptr->block_group != block_group) { 5076 + last_ptr->block_group != block_group && 5077 + index <= 5078 + get_block_group_index(last_ptr->block_group)) { 5085 5079 5086 5080 btrfs_put_block_group(block_group); 5087 5081 block_group = last_ptr->block_group; ··· 5511 5501 u32 size = sizeof(*extent_item) + sizeof(*block_info) + sizeof(*iref); 5512 5502 5513 5503 path = btrfs_alloc_path(); 5514 - BUG_ON(!path); 5504 + if (!path) 5505 + return -ENOMEM; 5515 5506 5516 5507 path->leave_spinning = 1; 5517 5508 ret = btrfs_insert_empty_item(trans, fs_info->extent_root, path, ··· 6283 6272 int level; 6284 6273 6285 6274 path = btrfs_alloc_path(); 6286 - BUG_ON(!path); 6275 + if (!path) 6276 + return -ENOMEM; 6287 6277 6288 6278 wc = kzalloc(sizeof(*wc), GFP_NOFS); 6289 - BUG_ON(!wc); 6279 + if (!wc) { 6280 + btrfs_free_path(path); 6281 + return -ENOMEM; 6282 + } 6290 6283 6291 6284 trans = btrfs_start_transaction(tree_root, 0); 6292 6285 BUG_ON(IS_ERR(trans)); ··· 6553 6538 u64 min_allocable_bytes; 6554 6539 int ret = -ENOSPC; 6555 6540 6556 - if (cache->ro) 6557 - return 0; 6558 6541 6559 6542 /* 6560 6543 * We need some metadata space and system metadata space for ··· 6568 6555 6569 6556 spin_lock(&sinfo->lock); 6570 6557 spin_lock(&cache->lock); 6558 + 6559 + if (cache->ro) { 6560 + ret = 0; 6561 + goto out; 6562 + } 6563 + 6571 6564 num_bytes = cache->key.offset - cache->reserved - cache->pinned - 6572 6565 cache->bytes_super - btrfs_block_group_used(&cache->item); 6573 6566 ··· 6587 6568 cache->ro = 1; 6588 6569 ret = 0; 6589 6570 } 6590 - 6571 + out: 6591 6572 spin_unlock(&cache->lock); 6592 6573 spin_unlock(&sinfo->lock); 6593 6574 return ret; ··· 7202 7183 spin_unlock(&cluster->refill_lock); 7203 7184 7204 7185 path = btrfs_alloc_path(); 7205 - BUG_ON(!path); 7186 + if (!path) { 7187 + ret = -ENOMEM; 7188 + goto out; 7189 + } 7206 7190 7207 7191 inode = lookup_free_space_inode(root, block_group, path); 7208 7192 if (!IS_ERR(inode)) { 7209 - btrfs_orphan_add(trans, inode); 7193 + ret = btrfs_orphan_add(trans, inode); 7194 + BUG_ON(ret); 7210 7195 clear_nlink(inode); 7211 7196 /* One for the block groups ref */ 7212 7197 spin_lock(&block_group->lock);
+43 -96
fs/btrfs/extent_io.c
··· 254 254 * 255 255 * This should be called with the tree lock held. 256 256 */ 257 - static int merge_state(struct extent_io_tree *tree, 258 - struct extent_state *state) 257 + static void merge_state(struct extent_io_tree *tree, 258 + struct extent_state *state) 259 259 { 260 260 struct extent_state *other; 261 261 struct rb_node *other_node; 262 262 263 263 if (state->state & (EXTENT_IOBITS | EXTENT_BOUNDARY)) 264 - return 0; 264 + return; 265 265 266 266 other_node = rb_prev(&state->rb_node); 267 267 if (other_node) { ··· 287 287 free_extent_state(other); 288 288 } 289 289 } 290 - 291 - return 0; 292 290 } 293 291 294 - static int set_state_cb(struct extent_io_tree *tree, 292 + static void set_state_cb(struct extent_io_tree *tree, 295 293 struct extent_state *state, int *bits) 296 294 { 297 - if (tree->ops && tree->ops->set_bit_hook) { 298 - return tree->ops->set_bit_hook(tree->mapping->host, 299 - state, bits); 300 - } 301 - 302 - return 0; 295 + if (tree->ops && tree->ops->set_bit_hook) 296 + tree->ops->set_bit_hook(tree->mapping->host, state, bits); 303 297 } 304 298 305 299 static void clear_state_cb(struct extent_io_tree *tree, ··· 302 308 if (tree->ops && tree->ops->clear_bit_hook) 303 309 tree->ops->clear_bit_hook(tree->mapping->host, state, bits); 304 310 } 311 + 312 + static void set_state_bits(struct extent_io_tree *tree, 313 + struct extent_state *state, int *bits); 305 314 306 315 /* 307 316 * insert an extent_state struct into the tree. 'bits' are set on the ··· 321 324 int *bits) 322 325 { 323 326 struct rb_node *node; 324 - int bits_to_set = *bits & ~EXTENT_CTLBITS; 325 - int ret; 326 327 327 328 if (end < start) { 328 329 printk(KERN_ERR "btrfs end < start %llu %llu\n", ··· 330 335 } 331 336 state->start = start; 332 337 state->end = end; 333 - ret = set_state_cb(tree, state, bits); 334 - if (ret) 335 - return ret; 336 338 337 - if (bits_to_set & EXTENT_DIRTY) 338 - tree->dirty_bytes += end - start + 1; 339 - state->state |= bits_to_set; 339 + set_state_bits(tree, state, bits); 340 + 340 341 node = tree_insert(&tree->state, end, &state->rb_node); 341 342 if (node) { 342 343 struct extent_state *found; ··· 348 357 return 0; 349 358 } 350 359 351 - static int split_cb(struct extent_io_tree *tree, struct extent_state *orig, 360 + static void split_cb(struct extent_io_tree *tree, struct extent_state *orig, 352 361 u64 split) 353 362 { 354 363 if (tree->ops && tree->ops->split_extent_hook) 355 - return tree->ops->split_extent_hook(tree->mapping->host, 356 - orig, split); 357 - return 0; 364 + tree->ops->split_extent_hook(tree->mapping->host, orig, split); 358 365 } 359 366 360 367 /* ··· 648 659 if (start > end) 649 660 break; 650 661 651 - if (need_resched()) { 652 - spin_unlock(&tree->lock); 653 - cond_resched(); 654 - spin_lock(&tree->lock); 655 - } 662 + cond_resched_lock(&tree->lock); 656 663 } 657 664 out: 658 665 spin_unlock(&tree->lock); 659 666 return 0; 660 667 } 661 668 662 - static int set_state_bits(struct extent_io_tree *tree, 669 + static void set_state_bits(struct extent_io_tree *tree, 663 670 struct extent_state *state, 664 671 int *bits) 665 672 { 666 - int ret; 667 673 int bits_to_set = *bits & ~EXTENT_CTLBITS; 668 674 669 - ret = set_state_cb(tree, state, bits); 670 - if (ret) 671 - return ret; 675 + set_state_cb(tree, state, bits); 672 676 if ((bits_to_set & EXTENT_DIRTY) && !(state->state & EXTENT_DIRTY)) { 673 677 u64 range = state->end - state->start + 1; 674 678 tree->dirty_bytes += range; 675 679 } 676 680 state->state |= bits_to_set; 677 - 678 - return 0; 679 681 } 680 682 681 683 static void cache_state(struct extent_state *state, ··· 759 779 goto out; 760 780 } 761 781 762 - err = set_state_bits(tree, state, &bits); 763 - if (err) 764 - goto out; 782 + set_state_bits(tree, state, &bits); 765 783 766 784 cache_state(state, cached_state); 767 785 merge_state(tree, state); ··· 808 830 if (err) 809 831 goto out; 810 832 if (state->end <= end) { 811 - err = set_state_bits(tree, state, &bits); 812 - if (err) 813 - goto out; 833 + set_state_bits(tree, state, &bits); 814 834 cache_state(state, cached_state); 815 835 merge_state(tree, state); 816 836 if (last_end == (u64)-1) ··· 869 893 err = split_state(tree, state, prealloc, end + 1); 870 894 BUG_ON(err == -EEXIST); 871 895 872 - err = set_state_bits(tree, prealloc, &bits); 873 - if (err) { 874 - prealloc = NULL; 875 - goto out; 876 - } 896 + set_state_bits(tree, prealloc, &bits); 877 897 cache_state(prealloc, cached_state); 878 898 merge_state(tree, prealloc); 879 899 prealloc = NULL; ··· 1031 1059 return 0; 1032 1060 } 1033 1061 1034 - /* 1035 - * find the first offset in the io tree with 'bits' set. zero is 1036 - * returned if we find something, and *start_ret and *end_ret are 1037 - * set to reflect the state struct that was found. 1038 - * 1039 - * If nothing was found, 1 is returned, < 0 on error 1040 - */ 1041 - int find_first_extent_bit(struct extent_io_tree *tree, u64 start, 1042 - u64 *start_ret, u64 *end_ret, int bits) 1043 - { 1044 - struct rb_node *node; 1045 - struct extent_state *state; 1046 - int ret = 1; 1047 - 1048 - spin_lock(&tree->lock); 1049 - /* 1050 - * this search will find all the extents that end after 1051 - * our range starts. 1052 - */ 1053 - node = tree_search(tree, start); 1054 - if (!node) 1055 - goto out; 1056 - 1057 - while (1) { 1058 - state = rb_entry(node, struct extent_state, rb_node); 1059 - if (state->end >= start && (state->state & bits)) { 1060 - *start_ret = state->start; 1061 - *end_ret = state->end; 1062 - ret = 0; 1063 - break; 1064 - } 1065 - node = rb_next(node); 1066 - if (!node) 1067 - break; 1068 - } 1069 - out: 1070 - spin_unlock(&tree->lock); 1071 - return ret; 1072 - } 1073 - 1074 1062 /* find the first state struct with 'bits' set after 'start', and 1075 1063 * return it. tree->lock must be held. NULL will returned if 1076 1064 * nothing was found after 'start' ··· 1060 1128 } 1061 1129 out: 1062 1130 return NULL; 1131 + } 1132 + 1133 + /* 1134 + * find the first offset in the io tree with 'bits' set. zero is 1135 + * returned if we find something, and *start_ret and *end_ret are 1136 + * set to reflect the state struct that was found. 1137 + * 1138 + * If nothing was found, 1 is returned, < 0 on error 1139 + */ 1140 + int find_first_extent_bit(struct extent_io_tree *tree, u64 start, 1141 + u64 *start_ret, u64 *end_ret, int bits) 1142 + { 1143 + struct extent_state *state; 1144 + int ret = 1; 1145 + 1146 + spin_lock(&tree->lock); 1147 + state = find_first_extent_bit_state(tree, start, bits); 1148 + if (state) { 1149 + *start_ret = state->start; 1150 + *end_ret = state->end; 1151 + ret = 0; 1152 + } 1153 + spin_unlock(&tree->lock); 1154 + return ret; 1063 1155 } 1064 1156 1065 1157 /* ··· 2502 2546 struct writeback_control *wbc) 2503 2547 { 2504 2548 int ret; 2505 - struct address_space *mapping = page->mapping; 2506 2549 struct extent_page_data epd = { 2507 2550 .bio = NULL, 2508 2551 .tree = tree, ··· 2509 2554 .extent_locked = 0, 2510 2555 .sync_io = wbc->sync_mode == WB_SYNC_ALL, 2511 2556 }; 2512 - struct writeback_control wbc_writepages = { 2513 - .sync_mode = wbc->sync_mode, 2514 - .nr_to_write = 64, 2515 - .range_start = page_offset(page) + PAGE_CACHE_SIZE, 2516 - .range_end = (loff_t)-1, 2517 - }; 2518 2557 2519 2558 ret = __extent_writepage(page, wbc, &epd); 2520 2559 2521 - extent_write_cache_pages(tree, mapping, &wbc_writepages, 2522 - __extent_writepage, &epd, flush_write_bio); 2523 2560 flush_epd_write_bio(&epd); 2524 2561 return ret; 2525 2562 }
+9 -11
fs/btrfs/extent_io.h
··· 76 76 struct extent_state *state); 77 77 int (*writepage_end_io_hook)(struct page *page, u64 start, u64 end, 78 78 struct extent_state *state, int uptodate); 79 - int (*set_bit_hook)(struct inode *inode, struct extent_state *state, 80 - int *bits); 81 - int (*clear_bit_hook)(struct inode *inode, struct extent_state *state, 82 - int *bits); 83 - int (*merge_extent_hook)(struct inode *inode, 84 - struct extent_state *new, 85 - struct extent_state *other); 86 - int (*split_extent_hook)(struct inode *inode, 87 - struct extent_state *orig, u64 split); 79 + void (*set_bit_hook)(struct inode *inode, struct extent_state *state, 80 + int *bits); 81 + void (*clear_bit_hook)(struct inode *inode, struct extent_state *state, 82 + int *bits); 83 + void (*merge_extent_hook)(struct inode *inode, 84 + struct extent_state *new, 85 + struct extent_state *other); 86 + void (*split_extent_hook)(struct inode *inode, 87 + struct extent_state *orig, u64 split); 88 88 int (*write_cache_pages_lock_hook)(struct page *page); 89 89 }; 90 90 ··· 108 108 wait_queue_head_t wq; 109 109 atomic_t refs; 110 110 unsigned long state; 111 - u64 split_start; 112 - u64 split_end; 113 111 114 112 /* for use by the FS */ 115 113 u64 private;
+51 -106
fs/btrfs/extent_map.c
··· 183 183 return 0; 184 184 } 185 185 186 - int unpin_extent_cache(struct extent_map_tree *tree, u64 start, u64 len) 186 + static void try_merge_map(struct extent_map_tree *tree, struct extent_map *em) 187 187 { 188 - int ret = 0; 189 188 struct extent_map *merge = NULL; 190 189 struct rb_node *rb; 191 - struct extent_map *em; 192 - 193 - write_lock(&tree->lock); 194 - em = lookup_extent_mapping(tree, start, len); 195 - 196 - WARN_ON(!em || em->start != start); 197 - 198 - if (!em) 199 - goto out; 200 - 201 - clear_bit(EXTENT_FLAG_PINNED, &em->flags); 202 190 203 191 if (em->start != 0) { 204 192 rb = rb_prev(&em->rb_node); ··· 213 225 merge->in_tree = 0; 214 226 free_extent_map(merge); 215 227 } 228 + } 229 + 230 + int unpin_extent_cache(struct extent_map_tree *tree, u64 start, u64 len) 231 + { 232 + int ret = 0; 233 + struct extent_map *em; 234 + 235 + write_lock(&tree->lock); 236 + em = lookup_extent_mapping(tree, start, len); 237 + 238 + WARN_ON(!em || em->start != start); 239 + 240 + if (!em) 241 + goto out; 242 + 243 + clear_bit(EXTENT_FLAG_PINNED, &em->flags); 244 + 245 + try_merge_map(tree, em); 216 246 217 247 free_extent_map(em); 218 248 out: ··· 253 247 struct extent_map *em) 254 248 { 255 249 int ret = 0; 256 - struct extent_map *merge = NULL; 257 250 struct rb_node *rb; 258 251 struct extent_map *exist; 259 252 ··· 268 263 goto out; 269 264 } 270 265 atomic_inc(&em->refs); 271 - if (em->start != 0) { 272 - rb = rb_prev(&em->rb_node); 273 - if (rb) 274 - merge = rb_entry(rb, struct extent_map, rb_node); 275 - if (rb && mergable_maps(merge, em)) { 276 - em->start = merge->start; 277 - em->len += merge->len; 278 - em->block_len += merge->block_len; 279 - em->block_start = merge->block_start; 280 - merge->in_tree = 0; 281 - rb_erase(&merge->rb_node, &tree->map); 282 - free_extent_map(merge); 283 - } 284 - } 285 - rb = rb_next(&em->rb_node); 286 - if (rb) 287 - merge = rb_entry(rb, struct extent_map, rb_node); 288 - if (rb && mergable_maps(em, merge)) { 289 - em->len += merge->len; 290 - em->block_len += merge->len; 291 - rb_erase(&merge->rb_node, &tree->map); 292 - merge->in_tree = 0; 293 - free_extent_map(merge); 294 - } 266 + 267 + try_merge_map(tree, em); 295 268 out: 296 269 return ret; 297 270 } ··· 280 297 if (start + len < start) 281 298 return (u64)-1; 282 299 return start + len; 300 + } 301 + 302 + struct extent_map *__lookup_extent_mapping(struct extent_map_tree *tree, 303 + u64 start, u64 len, int strict) 304 + { 305 + struct extent_map *em; 306 + struct rb_node *rb_node; 307 + struct rb_node *prev = NULL; 308 + struct rb_node *next = NULL; 309 + u64 end = range_end(start, len); 310 + 311 + rb_node = __tree_search(&tree->map, start, &prev, &next); 312 + if (!rb_node) { 313 + if (prev) 314 + rb_node = prev; 315 + else if (next) 316 + rb_node = next; 317 + else 318 + return NULL; 319 + } 320 + 321 + em = rb_entry(rb_node, struct extent_map, rb_node); 322 + 323 + if (strict && !(end > em->start && start < extent_map_end(em))) 324 + return NULL; 325 + 326 + atomic_inc(&em->refs); 327 + return em; 283 328 } 284 329 285 330 /** ··· 324 313 struct extent_map *lookup_extent_mapping(struct extent_map_tree *tree, 325 314 u64 start, u64 len) 326 315 { 327 - struct extent_map *em; 328 - struct rb_node *rb_node; 329 - struct rb_node *prev = NULL; 330 - struct rb_node *next = NULL; 331 - u64 end = range_end(start, len); 332 - 333 - rb_node = __tree_search(&tree->map, start, &prev, &next); 334 - if (!rb_node && prev) { 335 - em = rb_entry(prev, struct extent_map, rb_node); 336 - if (end > em->start && start < extent_map_end(em)) 337 - goto found; 338 - } 339 - if (!rb_node && next) { 340 - em = rb_entry(next, struct extent_map, rb_node); 341 - if (end > em->start && start < extent_map_end(em)) 342 - goto found; 343 - } 344 - if (!rb_node) { 345 - em = NULL; 346 - goto out; 347 - } 348 - if (IS_ERR(rb_node)) { 349 - em = ERR_CAST(rb_node); 350 - goto out; 351 - } 352 - em = rb_entry(rb_node, struct extent_map, rb_node); 353 - if (end > em->start && start < extent_map_end(em)) 354 - goto found; 355 - 356 - em = NULL; 357 - goto out; 358 - 359 - found: 360 - atomic_inc(&em->refs); 361 - out: 362 - return em; 316 + return __lookup_extent_mapping(tree, start, len, 1); 363 317 } 364 318 365 319 /** ··· 341 365 struct extent_map *search_extent_mapping(struct extent_map_tree *tree, 342 366 u64 start, u64 len) 343 367 { 344 - struct extent_map *em; 345 - struct rb_node *rb_node; 346 - struct rb_node *prev = NULL; 347 - struct rb_node *next = NULL; 348 - 349 - rb_node = __tree_search(&tree->map, start, &prev, &next); 350 - if (!rb_node && prev) { 351 - em = rb_entry(prev, struct extent_map, rb_node); 352 - goto found; 353 - } 354 - if (!rb_node && next) { 355 - em = rb_entry(next, struct extent_map, rb_node); 356 - goto found; 357 - } 358 - if (!rb_node) { 359 - em = NULL; 360 - goto out; 361 - } 362 - if (IS_ERR(rb_node)) { 363 - em = ERR_CAST(rb_node); 364 - goto out; 365 - } 366 - em = rb_entry(rb_node, struct extent_map, rb_node); 367 - goto found; 368 - 369 - em = NULL; 370 - goto out; 371 - 372 - found: 373 - atomic_inc(&em->refs); 374 - out: 375 - return em; 368 + return __lookup_extent_mapping(tree, start, len, 0); 376 369 } 377 370 378 371 /**
+5 -2
fs/btrfs/file-item.c
··· 291 291 u16 csum_size = btrfs_super_csum_size(&root->fs_info->super_copy); 292 292 293 293 path = btrfs_alloc_path(); 294 - BUG_ON(!path); 294 + if (!path) 295 + return -ENOMEM; 295 296 296 297 if (search_commit) { 297 298 path->skip_locking = 1; ··· 678 677 btrfs_super_csum_size(&root->fs_info->super_copy); 679 678 680 679 path = btrfs_alloc_path(); 681 - BUG_ON(!path); 680 + if (!path) 681 + return -ENOMEM; 682 + 682 683 sector_sum = sums->sums; 683 684 again: 684 685 next_offset = (u64)-1;
+9 -12
fs/btrfs/file.c
··· 74 74 * If an existing record is found the defrag item you 75 75 * pass in is freed 76 76 */ 77 - static int __btrfs_add_inode_defrag(struct inode *inode, 77 + static void __btrfs_add_inode_defrag(struct inode *inode, 78 78 struct inode_defrag *defrag) 79 79 { 80 80 struct btrfs_root *root = BTRFS_I(inode)->root; ··· 106 106 BTRFS_I(inode)->in_defrag = 1; 107 107 rb_link_node(&defrag->rb_node, parent, p); 108 108 rb_insert_color(&defrag->rb_node, &root->fs_info->defrag_inodes); 109 - return 0; 109 + return; 110 110 111 111 exists: 112 112 kfree(defrag); 113 - return 0; 113 + return; 114 114 115 115 } 116 116 ··· 123 123 { 124 124 struct btrfs_root *root = BTRFS_I(inode)->root; 125 125 struct inode_defrag *defrag; 126 - int ret = 0; 127 126 u64 transid; 128 127 129 128 if (!btrfs_test_opt(root, AUTO_DEFRAG)) ··· 149 150 150 151 spin_lock(&root->fs_info->defrag_inodes_lock); 151 152 if (!BTRFS_I(inode)->in_defrag) 152 - ret = __btrfs_add_inode_defrag(inode, defrag); 153 + __btrfs_add_inode_defrag(inode, defrag); 153 154 spin_unlock(&root->fs_info->defrag_inodes_lock); 154 - return ret; 155 + return 0; 155 156 } 156 157 157 158 /* ··· 854 855 btrfs_drop_extent_cache(inode, start, end - 1, 0); 855 856 856 857 path = btrfs_alloc_path(); 857 - BUG_ON(!path); 858 + if (!path) 859 + return -ENOMEM; 858 860 again: 859 861 recow = 0; 860 862 split = start; ··· 1059 1059 static noinline int prepare_pages(struct btrfs_root *root, struct file *file, 1060 1060 struct page **pages, size_t num_pages, 1061 1061 loff_t pos, unsigned long first_index, 1062 - unsigned long last_index, size_t write_bytes) 1062 + size_t write_bytes) 1063 1063 { 1064 1064 struct extent_state *cached_state = NULL; 1065 1065 int i; ··· 1159 1159 struct btrfs_root *root = BTRFS_I(inode)->root; 1160 1160 struct page **pages = NULL; 1161 1161 unsigned long first_index; 1162 - unsigned long last_index; 1163 1162 size_t num_written = 0; 1164 1163 int nrptrs; 1165 1164 int ret = 0; ··· 1171 1172 return -ENOMEM; 1172 1173 1173 1174 first_index = pos >> PAGE_CACHE_SHIFT; 1174 - last_index = (pos + iov_iter_count(i)) >> PAGE_CACHE_SHIFT; 1175 1175 1176 1176 while (iov_iter_count(i) > 0) { 1177 1177 size_t offset = pos & (PAGE_CACHE_SIZE - 1); ··· 1204 1206 * contents of pages from loop to loop 1205 1207 */ 1206 1208 ret = prepare_pages(root, file, pages, num_pages, 1207 - pos, first_index, last_index, 1208 - write_bytes); 1209 + pos, first_index, write_bytes); 1209 1210 if (ret) { 1210 1211 btrfs_delalloc_release_space(inode, 1211 1212 num_pages << PAGE_CACHE_SHIFT);
+53 -45
fs/btrfs/inode.c
··· 1061 1061 u64 ino = btrfs_ino(inode); 1062 1062 1063 1063 path = btrfs_alloc_path(); 1064 - BUG_ON(!path); 1064 + if (!path) 1065 + return -ENOMEM; 1065 1066 1066 1067 nolock = btrfs_is_free_space_inode(root, inode); 1067 1068 ··· 1283 1282 return ret; 1284 1283 } 1285 1284 1286 - static int btrfs_split_extent_hook(struct inode *inode, 1287 - struct extent_state *orig, u64 split) 1285 + static void btrfs_split_extent_hook(struct inode *inode, 1286 + struct extent_state *orig, u64 split) 1288 1287 { 1289 1288 /* not delalloc, ignore it */ 1290 1289 if (!(orig->state & EXTENT_DELALLOC)) 1291 - return 0; 1290 + return; 1292 1291 1293 1292 spin_lock(&BTRFS_I(inode)->lock); 1294 1293 BTRFS_I(inode)->outstanding_extents++; 1295 1294 spin_unlock(&BTRFS_I(inode)->lock); 1296 - return 0; 1297 1295 } 1298 1296 1299 1297 /* ··· 1301 1301 * extents, such as when we are doing sequential writes, so we can properly 1302 1302 * account for the metadata space we'll need. 1303 1303 */ 1304 - static int btrfs_merge_extent_hook(struct inode *inode, 1305 - struct extent_state *new, 1306 - struct extent_state *other) 1304 + static void btrfs_merge_extent_hook(struct inode *inode, 1305 + struct extent_state *new, 1306 + struct extent_state *other) 1307 1307 { 1308 1308 /* not delalloc, ignore it */ 1309 1309 if (!(other->state & EXTENT_DELALLOC)) 1310 - return 0; 1310 + return; 1311 1311 1312 1312 spin_lock(&BTRFS_I(inode)->lock); 1313 1313 BTRFS_I(inode)->outstanding_extents--; 1314 1314 spin_unlock(&BTRFS_I(inode)->lock); 1315 - return 0; 1316 1315 } 1317 1316 1318 1317 /* ··· 1319 1320 * bytes in this file, and to maintain the list of inodes that 1320 1321 * have pending delalloc work to be done. 1321 1322 */ 1322 - static int btrfs_set_bit_hook(struct inode *inode, 1323 - struct extent_state *state, int *bits) 1323 + static void btrfs_set_bit_hook(struct inode *inode, 1324 + struct extent_state *state, int *bits) 1324 1325 { 1325 1326 1326 1327 /* ··· 1350 1351 } 1351 1352 spin_unlock(&root->fs_info->delalloc_lock); 1352 1353 } 1353 - return 0; 1354 1354 } 1355 1355 1356 1356 /* 1357 1357 * extent_io.c clear_bit_hook, see set_bit_hook for why 1358 1358 */ 1359 - static int btrfs_clear_bit_hook(struct inode *inode, 1360 - struct extent_state *state, int *bits) 1359 + static void btrfs_clear_bit_hook(struct inode *inode, 1360 + struct extent_state *state, int *bits) 1361 1361 { 1362 1362 /* 1363 1363 * set_bit and clear bit hooks normally require _irqsave/restore ··· 1393 1395 } 1394 1396 spin_unlock(&root->fs_info->delalloc_lock); 1395 1397 } 1396 - return 0; 1397 1398 } 1398 1399 1399 1400 /* ··· 1642 1645 int ret; 1643 1646 1644 1647 path = btrfs_alloc_path(); 1645 - BUG_ON(!path); 1648 + if (!path) 1649 + return -ENOMEM; 1646 1650 1647 1651 path->leave_spinning = 1; 1648 1652 ··· 2213 2215 2214 2216 if (!root->orphan_block_rsv) { 2215 2217 block_rsv = btrfs_alloc_block_rsv(root); 2216 - BUG_ON(!block_rsv); 2218 + if (!block_rsv) 2219 + return -ENOMEM; 2217 2220 } 2218 2221 2219 2222 spin_lock(&root->orphan_lock); ··· 2516 2517 filled = true; 2517 2518 2518 2519 path = btrfs_alloc_path(); 2519 - BUG_ON(!path); 2520 + if (!path) 2521 + goto make_bad; 2522 + 2520 2523 path->leave_spinning = 1; 2521 2524 memcpy(&location, &BTRFS_I(inode)->location, sizeof(location)); 2522 2525 ··· 2999 2998 3000 2999 ret = btrfs_unlink_inode(trans, root, dir, dentry->d_inode, 3001 3000 dentry->d_name.name, dentry->d_name.len); 3002 - BUG_ON(ret); 3001 + if (ret) 3002 + goto out; 3003 3003 3004 3004 if (inode->i_nlink == 0) { 3005 3005 ret = btrfs_orphan_add(trans, inode); 3006 - BUG_ON(ret); 3006 + if (ret) 3007 + goto out; 3007 3008 } 3008 3009 3010 + out: 3009 3011 nr = trans->blocks_used; 3010 3012 __unlink_end_trans(trans, root); 3011 3013 btrfs_btree_balance_dirty(root, nr); ··· 3151 3147 3152 3148 BUG_ON(new_size > 0 && min_type != BTRFS_EXTENT_DATA_KEY); 3153 3149 3150 + path = btrfs_alloc_path(); 3151 + if (!path) 3152 + return -ENOMEM; 3153 + path->reada = -1; 3154 + 3154 3155 if (root->ref_cows || root == root->fs_info->tree_root) 3155 3156 btrfs_drop_extent_cache(inode, new_size & (~mask), (u64)-1, 0); 3156 3157 ··· 3167 3158 */ 3168 3159 if (min_type == 0 && root == BTRFS_I(inode)->root) 3169 3160 btrfs_kill_delayed_inode_items(inode); 3170 - 3171 - path = btrfs_alloc_path(); 3172 - BUG_ON(!path); 3173 - path->reada = -1; 3174 3161 3175 3162 key.objectid = ino; 3176 3163 key.offset = (u64)-1; ··· 3695 3690 int ret = 0; 3696 3691 3697 3692 path = btrfs_alloc_path(); 3698 - BUG_ON(!path); 3693 + if (!path) 3694 + return -ENOMEM; 3699 3695 3700 3696 di = btrfs_lookup_dir_item(NULL, root, path, btrfs_ino(dir), name, 3701 3697 namelen, 0); ··· 3952 3946 struct btrfs_root *root, int *new) 3953 3947 { 3954 3948 struct inode *inode; 3949 + int bad_inode = 0; 3955 3950 3956 3951 inode = btrfs_iget_locked(s, location->objectid, root); 3957 3952 if (!inode) ··· 3962 3955 BTRFS_I(inode)->root = root; 3963 3956 memcpy(&BTRFS_I(inode)->location, location, sizeof(*location)); 3964 3957 btrfs_read_locked_inode(inode); 3965 - inode_tree_add(inode); 3966 - unlock_new_inode(inode); 3967 - if (new) 3968 - *new = 1; 3958 + if (!is_bad_inode(inode)) { 3959 + inode_tree_add(inode); 3960 + unlock_new_inode(inode); 3961 + if (new) 3962 + *new = 1; 3963 + } else { 3964 + bad_inode = 1; 3965 + } 3966 + } 3967 + 3968 + if (bad_inode) { 3969 + iput(inode); 3970 + inode = ERR_PTR(-ESTALE); 3969 3971 } 3970 3972 3971 3973 return inode; ··· 4467 4451 int owner; 4468 4452 4469 4453 path = btrfs_alloc_path(); 4470 - BUG_ON(!path); 4454 + if (!path) 4455 + return ERR_PTR(-ENOMEM); 4471 4456 4472 4457 inode = new_inode(root->fs_info->sb); 4473 4458 if (!inode) { ··· 6728 6711 return 0; 6729 6712 } 6730 6713 6731 - /* helper function for file defrag and space balancing. This 6732 - * forces readahead on a given range of bytes in an inode 6733 - */ 6734 - unsigned long btrfs_force_ra(struct address_space *mapping, 6735 - struct file_ra_state *ra, struct file *file, 6736 - pgoff_t offset, pgoff_t last_index) 6737 - { 6738 - pgoff_t req_size = last_index - offset + 1; 6739 - 6740 - page_cache_sync_readahead(mapping, ra, file, offset, req_size); 6741 - return offset + req_size; 6742 - } 6743 - 6744 6714 struct inode *btrfs_alloc_inode(struct super_block *sb) 6745 6715 { 6746 6716 struct btrfs_inode *ei; ··· 7210 7206 goto out_unlock; 7211 7207 7212 7208 path = btrfs_alloc_path(); 7213 - BUG_ON(!path); 7209 + if (!path) { 7210 + err = -ENOMEM; 7211 + drop_inode = 1; 7212 + goto out_unlock; 7213 + } 7214 7214 key.objectid = btrfs_ino(inode); 7215 7215 key.offset = 0; 7216 7216 btrfs_set_key_type(&key, BTRFS_EXTENT_DATA_KEY);
+1 -2
fs/btrfs/ioctl.c
··· 1749 1749 key.objectid = key.offset; 1750 1750 key.offset = (u64)-1; 1751 1751 dirid = key.objectid; 1752 - 1753 1752 } 1754 1753 if (ptr < name) 1755 1754 goto out; 1756 - memcpy(name, ptr, total_len); 1755 + memmove(name, ptr, total_len); 1757 1756 name[total_len]='\0'; 1758 1757 ret = 0; 1759 1758 out:
-68
fs/btrfs/ref-cache.c
··· 1 - /* 2 - * Copyright (C) 2008 Oracle. All rights reserved. 3 - * 4 - * This program is free software; you can redistribute it and/or 5 - * modify it under the terms of the GNU General Public 6 - * License v2 as published by the Free Software Foundation. 7 - * 8 - * This program is distributed in the hope that it will be useful, 9 - * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 - * General Public License for more details. 12 - * 13 - * You should have received a copy of the GNU General Public 14 - * License along with this program; if not, write to the 15 - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 16 - * Boston, MA 021110-1307, USA. 17 - */ 18 - 19 - #include <linux/sched.h> 20 - #include <linux/slab.h> 21 - #include <linux/sort.h> 22 - #include "ctree.h" 23 - #include "ref-cache.h" 24 - #include "transaction.h" 25 - 26 - static struct rb_node *tree_insert(struct rb_root *root, u64 bytenr, 27 - struct rb_node *node) 28 - { 29 - struct rb_node **p = &root->rb_node; 30 - struct rb_node *parent = NULL; 31 - struct btrfs_leaf_ref *entry; 32 - 33 - while (*p) { 34 - parent = *p; 35 - entry = rb_entry(parent, struct btrfs_leaf_ref, rb_node); 36 - 37 - if (bytenr < entry->bytenr) 38 - p = &(*p)->rb_left; 39 - else if (bytenr > entry->bytenr) 40 - p = &(*p)->rb_right; 41 - else 42 - return parent; 43 - } 44 - 45 - entry = rb_entry(node, struct btrfs_leaf_ref, rb_node); 46 - rb_link_node(node, parent, p); 47 - rb_insert_color(node, root); 48 - return NULL; 49 - } 50 - 51 - static struct rb_node *tree_search(struct rb_root *root, u64 bytenr) 52 - { 53 - struct rb_node *n = root->rb_node; 54 - struct btrfs_leaf_ref *entry; 55 - 56 - while (n) { 57 - entry = rb_entry(n, struct btrfs_leaf_ref, rb_node); 58 - WARN_ON(!entry->in_tree); 59 - 60 - if (bytenr < entry->bytenr) 61 - n = n->rb_left; 62 - else if (bytenr > entry->bytenr) 63 - n = n->rb_right; 64 - else 65 - return n; 66 - } 67 - return NULL; 68 - }
-52
fs/btrfs/ref-cache.h
··· 1 - /* 2 - * Copyright (C) 2008 Oracle. All rights reserved. 3 - * 4 - * This program is free software; you can redistribute it and/or 5 - * modify it under the terms of the GNU General Public 6 - * License v2 as published by the Free Software Foundation. 7 - * 8 - * This program is distributed in the hope that it will be useful, 9 - * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 - * General Public License for more details. 12 - * 13 - * You should have received a copy of the GNU General Public 14 - * License along with this program; if not, write to the 15 - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 16 - * Boston, MA 021110-1307, USA. 17 - */ 18 - #ifndef __REFCACHE__ 19 - #define __REFCACHE__ 20 - 21 - struct btrfs_extent_info { 22 - /* bytenr and num_bytes find the extent in the extent allocation tree */ 23 - u64 bytenr; 24 - u64 num_bytes; 25 - 26 - /* objectid and offset find the back reference for the file */ 27 - u64 objectid; 28 - u64 offset; 29 - }; 30 - 31 - struct btrfs_leaf_ref { 32 - struct rb_node rb_node; 33 - struct btrfs_leaf_ref_tree *tree; 34 - int in_tree; 35 - atomic_t usage; 36 - 37 - u64 root_gen; 38 - u64 bytenr; 39 - u64 owner; 40 - u64 generation; 41 - int nritems; 42 - 43 - struct list_head list; 44 - struct btrfs_extent_info extents[]; 45 - }; 46 - 47 - static inline size_t btrfs_leaf_ref_size(int nr_extents) 48 - { 49 - return sizeof(struct btrfs_leaf_ref) + 50 - sizeof(struct btrfs_extent_info) * nr_extents; 51 - } 52 - #endif
+2 -3
fs/btrfs/root-tree.c
··· 71 71 return ret; 72 72 } 73 73 74 - int btrfs_set_root_node(struct btrfs_root_item *item, 75 - struct extent_buffer *node) 74 + void btrfs_set_root_node(struct btrfs_root_item *item, 75 + struct extent_buffer *node) 76 76 { 77 77 btrfs_set_root_bytenr(item, node->start); 78 78 btrfs_set_root_level(item, btrfs_header_level(node)); 79 79 btrfs_set_root_generation(item, btrfs_header_generation(node)); 80 - return 0; 81 80 } 82 81 83 82 /*
+9 -56
fs/btrfs/transaction.c
··· 216 216 spin_lock(&root->fs_info->trans_lock); 217 217 cur_trans = root->fs_info->running_transaction; 218 218 if (cur_trans && cur_trans->blocked) { 219 - DEFINE_WAIT(wait); 220 219 atomic_inc(&cur_trans->use_count); 221 220 spin_unlock(&root->fs_info->trans_lock); 222 - while (1) { 223 - prepare_to_wait(&root->fs_info->transaction_wait, &wait, 224 - TASK_UNINTERRUPTIBLE); 225 - if (!cur_trans->blocked) 226 - break; 227 - schedule(); 228 - } 229 - finish_wait(&root->fs_info->transaction_wait, &wait); 221 + 222 + wait_event(root->fs_info->transaction_wait, 223 + !cur_trans->blocked); 230 224 put_transaction(cur_trans); 231 225 } else { 232 226 spin_unlock(&root->fs_info->trans_lock); ··· 351 357 } 352 358 353 359 /* wait for a transaction commit to be fully complete */ 354 - static noinline int wait_for_commit(struct btrfs_root *root, 360 + static noinline void wait_for_commit(struct btrfs_root *root, 355 361 struct btrfs_transaction *commit) 356 362 { 357 - DEFINE_WAIT(wait); 358 - while (!commit->commit_done) { 359 - prepare_to_wait(&commit->commit_wait, &wait, 360 - TASK_UNINTERRUPTIBLE); 361 - if (commit->commit_done) 362 - break; 363 - schedule(); 364 - } 365 - finish_wait(&commit->commit_wait, &wait); 366 - return 0; 363 + wait_event(commit->commit_wait, commit->commit_done); 367 364 } 368 365 369 366 int btrfs_wait_for_commit(struct btrfs_root *root, u64 transid) ··· 1070 1085 static void wait_current_trans_commit_start(struct btrfs_root *root, 1071 1086 struct btrfs_transaction *trans) 1072 1087 { 1073 - DEFINE_WAIT(wait); 1074 - 1075 - if (trans->in_commit) 1076 - return; 1077 - 1078 - while (1) { 1079 - prepare_to_wait(&root->fs_info->transaction_blocked_wait, &wait, 1080 - TASK_UNINTERRUPTIBLE); 1081 - if (trans->in_commit) { 1082 - finish_wait(&root->fs_info->transaction_blocked_wait, 1083 - &wait); 1084 - break; 1085 - } 1086 - schedule(); 1087 - finish_wait(&root->fs_info->transaction_blocked_wait, &wait); 1088 - } 1088 + wait_event(root->fs_info->transaction_blocked_wait, trans->in_commit); 1089 1089 } 1090 1090 1091 1091 /* ··· 1080 1110 static void wait_current_trans_commit_start_and_unblock(struct btrfs_root *root, 1081 1111 struct btrfs_transaction *trans) 1082 1112 { 1083 - DEFINE_WAIT(wait); 1084 - 1085 - if (trans->commit_done || (trans->in_commit && !trans->blocked)) 1086 - return; 1087 - 1088 - while (1) { 1089 - prepare_to_wait(&root->fs_info->transaction_wait, &wait, 1090 - TASK_UNINTERRUPTIBLE); 1091 - if (trans->commit_done || 1092 - (trans->in_commit && !trans->blocked)) { 1093 - finish_wait(&root->fs_info->transaction_wait, 1094 - &wait); 1095 - break; 1096 - } 1097 - schedule(); 1098 - finish_wait(&root->fs_info->transaction_wait, 1099 - &wait); 1100 - } 1113 + wait_event(root->fs_info->transaction_wait, 1114 + trans->commit_done || (trans->in_commit && !trans->blocked)); 1101 1115 } 1102 1116 1103 1117 /* ··· 1188 1234 atomic_inc(&cur_trans->use_count); 1189 1235 btrfs_end_transaction(trans, root); 1190 1236 1191 - ret = wait_for_commit(root, cur_trans); 1192 - BUG_ON(ret); 1237 + wait_for_commit(root, cur_trans); 1193 1238 1194 1239 put_transaction(cur_trans); 1195 1240
+9 -3
fs/btrfs/tree-log.c
··· 1617 1617 return 0; 1618 1618 1619 1619 path = btrfs_alloc_path(); 1620 - BUG_ON(!path); 1620 + if (!path) 1621 + return -ENOMEM; 1621 1622 1622 1623 nritems = btrfs_header_nritems(eb); 1623 1624 for (i = 0; i < nritems; i++) { ··· 1724 1723 return -ENOMEM; 1725 1724 1726 1725 if (*level == 1) { 1727 - wc->process_func(root, next, wc, ptr_gen); 1726 + ret = wc->process_func(root, next, wc, ptr_gen); 1727 + if (ret) 1728 + return ret; 1728 1729 1729 1730 path->slots[*level]++; 1730 1731 if (wc->free) { ··· 1791 1788 parent = path->nodes[*level + 1]; 1792 1789 1793 1790 root_owner = btrfs_header_owner(parent); 1794 - wc->process_func(root, path->nodes[*level], wc, 1791 + ret = wc->process_func(root, path->nodes[*level], wc, 1795 1792 btrfs_header_generation(path->nodes[*level])); 1793 + if (ret) 1794 + return ret; 1795 + 1796 1796 if (wc->free) { 1797 1797 struct extent_buffer *next; 1798 1798
+8 -4
fs/btrfs/volumes.c
··· 1037 1037 struct btrfs_key found_key; 1038 1038 1039 1039 path = btrfs_alloc_path(); 1040 - BUG_ON(!path); 1040 + if (!path) 1041 + return -ENOMEM; 1041 1042 1042 1043 key.objectid = objectid; 1043 1044 key.offset = (u64)-1; ··· 2062 2061 2063 2062 /* step two, relocate all the chunks */ 2064 2063 path = btrfs_alloc_path(); 2065 - BUG_ON(!path); 2066 - 2064 + if (!path) { 2065 + ret = -ENOMEM; 2066 + goto error; 2067 + } 2067 2068 key.objectid = BTRFS_FIRST_CHUNK_TREE_OBJECTID; 2068 2069 key.offset = (u64)-1; 2069 2070 key.type = BTRFS_CHUNK_ITEM_KEY; ··· 2664 2661 2665 2662 ret = find_next_chunk(fs_info->chunk_root, 2666 2663 BTRFS_FIRST_CHUNK_TREE_OBJECTID, &chunk_offset); 2667 - BUG_ON(ret); 2664 + if (ret) 2665 + return ret; 2668 2666 2669 2667 alloc_profile = BTRFS_BLOCK_GROUP_METADATA | 2670 2668 (fs_info->metadata_alloc_profile &