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

Pull btrfs fixes from Chris Mason:
"The big ones here are a memory leak we introduced in rc1, and a
scheduling while atomic if the transid on disk doesn't match the
transid we expected. This happens for corrupt blocks, or out of date
disks.

It also fixes up the ioctl definition for our ioctl to resolve logical
inode numbers. The __u32 was a merging error and doesn't match what
we ship in the progs."

* 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mason/linux-btrfs:
Btrfs: avoid sleeping in verify_parent_transid while atomic
Btrfs: fix crash in scrub repair code when device is missing
btrfs: Fix mismatching struct members in ioctl.h
Btrfs: fix page leak when allocing extent buffers
Btrfs: Add properly locking around add_root_to_dirty_list

+19 -9
fs/btrfs/ctree.c
··· 220 220 */ 221 221 static void add_root_to_dirty_list(struct btrfs_root *root) 222 222 { 223 + spin_lock(&root->fs_info->trans_lock); 223 224 if (root->track_dirty && list_empty(&root->dirty_list)) { 224 225 list_add(&root->dirty_list, 225 226 &root->fs_info->dirty_cowonly_roots); 226 227 } 228 + spin_unlock(&root->fs_info->trans_lock); 227 229 } 228 230 229 231 /* ··· 725 723 726 724 cur = btrfs_find_tree_block(root, blocknr, blocksize); 727 725 if (cur) 728 - uptodate = btrfs_buffer_uptodate(cur, gen); 726 + uptodate = btrfs_buffer_uptodate(cur, gen, 0); 729 727 else 730 728 uptodate = 0; 731 729 if (!cur || !uptodate) { ··· 1360 1358 block1 = btrfs_node_blockptr(parent, slot - 1); 1361 1359 gen = btrfs_node_ptr_generation(parent, slot - 1); 1362 1360 eb = btrfs_find_tree_block(root, block1, blocksize); 1363 - if (eb && btrfs_buffer_uptodate(eb, gen)) 1361 + /* 1362 + * if we get -eagain from btrfs_buffer_uptodate, we 1363 + * don't want to return eagain here. That will loop 1364 + * forever 1365 + */ 1366 + if (eb && btrfs_buffer_uptodate(eb, gen, 1) != 0) 1364 1367 block1 = 0; 1365 1368 free_extent_buffer(eb); 1366 1369 } ··· 1373 1366 block2 = btrfs_node_blockptr(parent, slot + 1); 1374 1367 gen = btrfs_node_ptr_generation(parent, slot + 1); 1375 1368 eb = btrfs_find_tree_block(root, block2, blocksize); 1376 - if (eb && btrfs_buffer_uptodate(eb, gen)) 1369 + if (eb && btrfs_buffer_uptodate(eb, gen, 1) != 0) 1377 1370 block2 = 0; 1378 1371 free_extent_buffer(eb); 1379 1372 } ··· 1511 1504 1512 1505 tmp = btrfs_find_tree_block(root, blocknr, blocksize); 1513 1506 if (tmp) { 1514 - if (btrfs_buffer_uptodate(tmp, 0)) { 1515 - if (btrfs_buffer_uptodate(tmp, gen)) { 1507 + /* first we do an atomic uptodate check */ 1508 + if (btrfs_buffer_uptodate(tmp, 0, 1) > 0) { 1509 + if (btrfs_buffer_uptodate(tmp, gen, 1) > 0) { 1516 1510 /* 1517 1511 * we found an up to date block without 1518 1512 * sleeping, return ··· 1531 1523 free_extent_buffer(tmp); 1532 1524 btrfs_set_path_blocking(p); 1533 1525 1526 + /* now we're allowed to do a blocking uptodate check */ 1534 1527 tmp = read_tree_block(root, blocknr, blocksize, gen); 1535 - if (tmp && btrfs_buffer_uptodate(tmp, gen)) { 1528 + if (tmp && btrfs_buffer_uptodate(tmp, gen, 0) > 0) { 1536 1529 *eb_ret = tmp; 1537 1530 return 0; 1538 1531 } ··· 1568 1559 * and give up so that our caller doesn't loop forever 1569 1560 * on our EAGAINs. 1570 1561 */ 1571 - if (!btrfs_buffer_uptodate(tmp, 0)) 1562 + if (!btrfs_buffer_uptodate(tmp, 0, 0)) 1572 1563 ret = -EIO; 1573 1564 free_extent_buffer(tmp); 1574 1565 } ··· 4052 4043 tmp = btrfs_find_tree_block(root, blockptr, 4053 4044 btrfs_level_size(root, level - 1)); 4054 4045 4055 - if (tmp && btrfs_buffer_uptodate(tmp, gen)) { 4046 + if (tmp && btrfs_buffer_uptodate(tmp, gen, 1) > 0) { 4056 4047 free_extent_buffer(tmp); 4057 4048 break; 4058 4049 } ··· 4175 4166 struct extent_buffer *cur; 4176 4167 cur = btrfs_find_tree_block(root, blockptr, 4177 4168 btrfs_level_size(root, level - 1)); 4178 - if (!cur || !btrfs_buffer_uptodate(cur, gen)) { 4169 + if (!cur || 4170 + btrfs_buffer_uptodate(cur, gen, 1) <= 0) { 4179 4171 slot++; 4180 4172 if (cur) 4181 4173 free_extent_buffer(cur);
+13 -5
fs/btrfs/disk-io.c
··· 323 323 * in the wrong place. 324 324 */ 325 325 static int verify_parent_transid(struct extent_io_tree *io_tree, 326 - struct extent_buffer *eb, u64 parent_transid) 326 + struct extent_buffer *eb, u64 parent_transid, 327 + int atomic) 327 328 { 328 329 struct extent_state *cached_state = NULL; 329 330 int ret; 330 331 331 332 if (!parent_transid || btrfs_header_generation(eb) == parent_transid) 332 333 return 0; 334 + 335 + if (atomic) 336 + return -EAGAIN; 333 337 334 338 lock_extent_bits(io_tree, eb->start, eb->start + eb->len - 1, 335 339 0, &cached_state); ··· 376 372 ret = read_extent_buffer_pages(io_tree, eb, start, 377 373 WAIT_COMPLETE, 378 374 btree_get_extent, mirror_num); 379 - if (!ret && !verify_parent_transid(io_tree, eb, parent_transid)) 375 + if (!ret && !verify_parent_transid(io_tree, eb, 376 + parent_transid, 0)) 380 377 break; 381 378 382 379 /* ··· 1207 1202 root->commit_root = NULL; 1208 1203 root->node = read_tree_block(root, btrfs_root_bytenr(&root->root_item), 1209 1204 blocksize, generation); 1210 - if (!root->node || !btrfs_buffer_uptodate(root->node, generation)) { 1205 + if (!root->node || !btrfs_buffer_uptodate(root->node, generation, 0)) { 1211 1206 free_extent_buffer(root->node); 1212 1207 root->node = NULL; 1213 1208 return -EIO; ··· 3148 3143 return 0; 3149 3144 } 3150 3145 3151 - int btrfs_buffer_uptodate(struct extent_buffer *buf, u64 parent_transid) 3146 + int btrfs_buffer_uptodate(struct extent_buffer *buf, u64 parent_transid, 3147 + int atomic) 3152 3148 { 3153 3149 int ret; 3154 3150 struct inode *btree_inode = buf->pages[0]->mapping->host; ··· 3159 3153 return ret; 3160 3154 3161 3155 ret = verify_parent_transid(&BTRFS_I(btree_inode)->io_tree, buf, 3162 - parent_transid); 3156 + parent_transid, atomic); 3157 + if (ret == -EAGAIN) 3158 + return ret; 3163 3159 return !ret; 3164 3160 } 3165 3161
+2 -1
fs/btrfs/disk-io.h
··· 66 66 void __btrfs_btree_balance_dirty(struct btrfs_root *root, unsigned long nr); 67 67 void btrfs_free_fs_root(struct btrfs_fs_info *fs_info, struct btrfs_root *root); 68 68 void btrfs_mark_buffer_dirty(struct extent_buffer *buf); 69 - int btrfs_buffer_uptodate(struct extent_buffer *buf, u64 parent_transid); 69 + int btrfs_buffer_uptodate(struct extent_buffer *buf, u64 parent_transid, 70 + int atomic); 70 71 int btrfs_set_buffer_uptodate(struct extent_buffer *buf); 71 72 int btrfs_read_buffer(struct extent_buffer *buf, u64 parent_transid); 72 73 u32 btrfs_csum_data(struct btrfs_root *root, char *data, u32 seed, size_t len);
+1 -1
fs/btrfs/extent-tree.c
··· 6568 6568 goto skip; 6569 6569 } 6570 6570 6571 - if (!btrfs_buffer_uptodate(next, generation)) { 6571 + if (!btrfs_buffer_uptodate(next, generation, 0)) { 6572 6572 btrfs_tree_unlock(next); 6573 6573 free_extent_buffer(next); 6574 6574 next = NULL;
+2 -2
fs/btrfs/extent_io.c
··· 4120 4120 if (atomic_inc_not_zero(&exists->refs)) { 4121 4121 spin_unlock(&mapping->private_lock); 4122 4122 unlock_page(p); 4123 + page_cache_release(p); 4123 4124 mark_extent_buffer_accessed(exists); 4124 4125 goto free_eb; 4125 4126 } ··· 4200 4199 unlock_page(eb->pages[i]); 4201 4200 } 4202 4201 4203 - if (!atomic_dec_and_test(&eb->refs)) 4204 - return exists; 4202 + WARN_ON(!atomic_dec_and_test(&eb->refs)); 4205 4203 btrfs_release_extent_buffer(eb); 4206 4204 return exists; 4207 4205 }
+2 -2
fs/btrfs/ioctl.h
··· 252 252 253 253 struct btrfs_ioctl_ino_path_args { 254 254 __u64 inum; /* in */ 255 - __u32 size; /* in */ 255 + __u64 size; /* in */ 256 256 __u64 reserved[4]; 257 257 /* struct btrfs_data_container *fspath; out */ 258 258 __u64 fspath; /* out */ ··· 260 260 261 261 struct btrfs_ioctl_logical_ino_args { 262 262 __u64 logical; /* in */ 263 - __u32 size; /* in */ 263 + __u64 size; /* in */ 264 264 __u64 reserved[4]; 265 265 /* struct btrfs_data_container *inodes; out */ 266 266 __u64 inodes;
+7
fs/btrfs/scrub.c
··· 998 998 page = sblock->pagev + page_index; 999 999 page->logical = logical; 1000 1000 page->physical = bbio->stripes[mirror_index].physical; 1001 + /* for missing devices, bdev is NULL */ 1001 1002 page->bdev = bbio->stripes[mirror_index].dev->bdev; 1002 1003 page->mirror_num = mirror_index + 1; 1003 1004 page->page = alloc_page(GFP_NOFS); ··· 1042 1041 int ret; 1043 1042 struct scrub_page *page = sblock->pagev + page_num; 1044 1043 DECLARE_COMPLETION_ONSTACK(complete); 1044 + 1045 + if (page->bdev == NULL) { 1046 + page->io_error = 1; 1047 + sblock->no_io_error_seen = 0; 1048 + continue; 1049 + } 1045 1050 1046 1051 BUG_ON(!page->page); 1047 1052 bio = bio_alloc(GFP_NOFS, 1);
+1 -1
fs/btrfs/tree-log.c
··· 279 279 log->fs_info->extent_root, 280 280 eb->start, eb->len); 281 281 282 - if (btrfs_buffer_uptodate(eb, gen)) { 282 + if (btrfs_buffer_uptodate(eb, gen, 0)) { 283 283 if (wc->write) 284 284 btrfs_write_tree_block(eb); 285 285 if (wc->wait)