diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2011-05-27 16:57:12 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2011-05-27 16:57:12 -0400 |
commit | a0c3061093c8b49facef95dc09a618c6e0d17cb5 (patch) | |
tree | 1d6ff7c06134b71a8bd0721395386e82e46e60c8 /fs/btrfs/disk-io.c | |
parent | 10799db60cbc4f990dd69eb49883477095c66af7 (diff) | |
parent | 174ba50915b08dcfd07c8b5fb795b46a165fa09a (diff) |
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: (58 commits)
Btrfs: use the device_list_mutex during write_dev_supers
Btrfs: setup free ino caching in a more asynchronous way
btrfs scrub: don't coalesce pages that are logically discontiguous
Btrfs: return -ENOMEM in clear_extent_bit
Btrfs: add mount -o auto_defrag
Btrfs: using rcu lock in the reader side of devices list
Btrfs: drop unnecessary device lock
Btrfs: fix the race between remove dev and alloc chunk
Btrfs: fix the race between reading and updating devices
Btrfs: fix bh leak on __btrfs_open_devices path
Btrfs: fix unsafe usage of merge_state
Btrfs: allocate extent state and check the result properly
fs/btrfs: Add missing btrfs_free_path
Btrfs: check return value of btrfs_inc_extent_ref()
Btrfs: return error to caller if read_one_inode() fails
Btrfs: BUG_ON is deleted from the caller of btrfs_truncate_item & btrfs_extend_item
Btrfs: return error code to caller when btrfs_del_item fails
Btrfs: return error code to caller when btrfs_previous_item fails
btrfs: fix typo 'testeing' -> 'testing'
btrfs: typo: 'btrfS' -> 'btrfs'
...
Diffstat (limited to 'fs/btrfs/disk-io.c')
-rw-r--r-- | fs/btrfs/disk-io.c | 210 |
1 files changed, 114 insertions, 96 deletions
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index 228cf36ece83..98b6a71decba 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c | |||
@@ -29,6 +29,7 @@ | |||
29 | #include <linux/crc32c.h> | 29 | #include <linux/crc32c.h> |
30 | #include <linux/slab.h> | 30 | #include <linux/slab.h> |
31 | #include <linux/migrate.h> | 31 | #include <linux/migrate.h> |
32 | #include <linux/ratelimit.h> | ||
32 | #include <asm/unaligned.h> | 33 | #include <asm/unaligned.h> |
33 | #include "compat.h" | 34 | #include "compat.h" |
34 | #include "ctree.h" | 35 | #include "ctree.h" |
@@ -41,6 +42,7 @@ | |||
41 | #include "locking.h" | 42 | #include "locking.h" |
42 | #include "tree-log.h" | 43 | #include "tree-log.h" |
43 | #include "free-space-cache.h" | 44 | #include "free-space-cache.h" |
45 | #include "inode-map.h" | ||
44 | 46 | ||
45 | static struct extent_io_ops btree_extent_io_ops; | 47 | static struct extent_io_ops btree_extent_io_ops; |
46 | static void end_workqueue_fn(struct btrfs_work *work); | 48 | static void end_workqueue_fn(struct btrfs_work *work); |
@@ -137,7 +139,7 @@ static const char *btrfs_eb_name[BTRFS_MAX_LEVEL + 1] = { | |||
137 | * that covers the entire device | 139 | * that covers the entire device |
138 | */ | 140 | */ |
139 | static struct extent_map *btree_get_extent(struct inode *inode, | 141 | static struct extent_map *btree_get_extent(struct inode *inode, |
140 | struct page *page, size_t page_offset, u64 start, u64 len, | 142 | struct page *page, size_t pg_offset, u64 start, u64 len, |
141 | int create) | 143 | int create) |
142 | { | 144 | { |
143 | struct extent_map_tree *em_tree = &BTRFS_I(inode)->extent_tree; | 145 | struct extent_map_tree *em_tree = &BTRFS_I(inode)->extent_tree; |
@@ -154,7 +156,7 @@ static struct extent_map *btree_get_extent(struct inode *inode, | |||
154 | } | 156 | } |
155 | read_unlock(&em_tree->lock); | 157 | read_unlock(&em_tree->lock); |
156 | 158 | ||
157 | em = alloc_extent_map(GFP_NOFS); | 159 | em = alloc_extent_map(); |
158 | if (!em) { | 160 | if (!em) { |
159 | em = ERR_PTR(-ENOMEM); | 161 | em = ERR_PTR(-ENOMEM); |
160 | goto out; | 162 | goto out; |
@@ -254,14 +256,12 @@ static int csum_tree_block(struct btrfs_root *root, struct extent_buffer *buf, | |||
254 | memcpy(&found, result, csum_size); | 256 | memcpy(&found, result, csum_size); |
255 | 257 | ||
256 | read_extent_buffer(buf, &val, 0, csum_size); | 258 | read_extent_buffer(buf, &val, 0, csum_size); |
257 | if (printk_ratelimit()) { | 259 | printk_ratelimited(KERN_INFO "btrfs: %s checksum verify " |
258 | printk(KERN_INFO "btrfs: %s checksum verify " | ||
259 | "failed on %llu wanted %X found %X " | 260 | "failed on %llu wanted %X found %X " |
260 | "level %d\n", | 261 | "level %d\n", |
261 | root->fs_info->sb->s_id, | 262 | root->fs_info->sb->s_id, |
262 | (unsigned long long)buf->start, val, found, | 263 | (unsigned long long)buf->start, val, found, |
263 | btrfs_header_level(buf)); | 264 | btrfs_header_level(buf)); |
264 | } | ||
265 | if (result != (char *)&inline_result) | 265 | if (result != (char *)&inline_result) |
266 | kfree(result); | 266 | kfree(result); |
267 | return 1; | 267 | return 1; |
@@ -296,13 +296,11 @@ static int verify_parent_transid(struct extent_io_tree *io_tree, | |||
296 | ret = 0; | 296 | ret = 0; |
297 | goto out; | 297 | goto out; |
298 | } | 298 | } |
299 | if (printk_ratelimit()) { | 299 | printk_ratelimited("parent transid verify failed on %llu wanted %llu " |
300 | printk("parent transid verify failed on %llu wanted %llu " | ||
301 | "found %llu\n", | 300 | "found %llu\n", |
302 | (unsigned long long)eb->start, | 301 | (unsigned long long)eb->start, |
303 | (unsigned long long)parent_transid, | 302 | (unsigned long long)parent_transid, |
304 | (unsigned long long)btrfs_header_generation(eb)); | 303 | (unsigned long long)btrfs_header_generation(eb)); |
305 | } | ||
306 | ret = 1; | 304 | ret = 1; |
307 | clear_extent_buffer_uptodate(io_tree, eb, &cached_state); | 305 | clear_extent_buffer_uptodate(io_tree, eb, &cached_state); |
308 | out: | 306 | out: |
@@ -380,7 +378,7 @@ static int csum_dirty_buffer(struct btrfs_root *root, struct page *page) | |||
380 | len = page->private >> 2; | 378 | len = page->private >> 2; |
381 | WARN_ON(len == 0); | 379 | WARN_ON(len == 0); |
382 | 380 | ||
383 | eb = alloc_extent_buffer(tree, start, len, page, GFP_NOFS); | 381 | eb = alloc_extent_buffer(tree, start, len, page); |
384 | if (eb == NULL) { | 382 | if (eb == NULL) { |
385 | WARN_ON(1); | 383 | WARN_ON(1); |
386 | goto out; | 384 | goto out; |
@@ -525,7 +523,7 @@ static int btree_readpage_end_io_hook(struct page *page, u64 start, u64 end, | |||
525 | len = page->private >> 2; | 523 | len = page->private >> 2; |
526 | WARN_ON(len == 0); | 524 | WARN_ON(len == 0); |
527 | 525 | ||
528 | eb = alloc_extent_buffer(tree, start, len, page, GFP_NOFS); | 526 | eb = alloc_extent_buffer(tree, start, len, page); |
529 | if (eb == NULL) { | 527 | if (eb == NULL) { |
530 | ret = -EIO; | 528 | ret = -EIO; |
531 | goto out; | 529 | goto out; |
@@ -533,12 +531,10 @@ static int btree_readpage_end_io_hook(struct page *page, u64 start, u64 end, | |||
533 | 531 | ||
534 | found_start = btrfs_header_bytenr(eb); | 532 | found_start = btrfs_header_bytenr(eb); |
535 | if (found_start != start) { | 533 | if (found_start != start) { |
536 | if (printk_ratelimit()) { | 534 | printk_ratelimited(KERN_INFO "btrfs bad tree block start " |
537 | printk(KERN_INFO "btrfs bad tree block start " | ||
538 | "%llu %llu\n", | 535 | "%llu %llu\n", |
539 | (unsigned long long)found_start, | 536 | (unsigned long long)found_start, |
540 | (unsigned long long)eb->start); | 537 | (unsigned long long)eb->start); |
541 | } | ||
542 | ret = -EIO; | 538 | ret = -EIO; |
543 | goto err; | 539 | goto err; |
544 | } | 540 | } |
@@ -550,10 +546,8 @@ static int btree_readpage_end_io_hook(struct page *page, u64 start, u64 end, | |||
550 | goto err; | 546 | goto err; |
551 | } | 547 | } |
552 | if (check_tree_block_fsid(root, eb)) { | 548 | if (check_tree_block_fsid(root, eb)) { |
553 | if (printk_ratelimit()) { | 549 | printk_ratelimited(KERN_INFO "btrfs bad fsid on block %llu\n", |
554 | printk(KERN_INFO "btrfs bad fsid on block %llu\n", | ||
555 | (unsigned long long)eb->start); | 550 | (unsigned long long)eb->start); |
556 | } | ||
557 | ret = -EIO; | 551 | ret = -EIO; |
558 | goto err; | 552 | goto err; |
559 | } | 553 | } |
@@ -650,12 +644,6 @@ unsigned long btrfs_async_submit_limit(struct btrfs_fs_info *info) | |||
650 | return 256 * limit; | 644 | return 256 * limit; |
651 | } | 645 | } |
652 | 646 | ||
653 | int btrfs_congested_async(struct btrfs_fs_info *info, int iodone) | ||
654 | { | ||
655 | return atomic_read(&info->nr_async_bios) > | ||
656 | btrfs_async_submit_limit(info); | ||
657 | } | ||
658 | |||
659 | static void run_one_async_start(struct btrfs_work *work) | 647 | static void run_one_async_start(struct btrfs_work *work) |
660 | { | 648 | { |
661 | struct async_submit_bio *async; | 649 | struct async_submit_bio *async; |
@@ -963,7 +951,7 @@ struct extent_buffer *btrfs_find_tree_block(struct btrfs_root *root, | |||
963 | struct inode *btree_inode = root->fs_info->btree_inode; | 951 | struct inode *btree_inode = root->fs_info->btree_inode; |
964 | struct extent_buffer *eb; | 952 | struct extent_buffer *eb; |
965 | eb = find_extent_buffer(&BTRFS_I(btree_inode)->io_tree, | 953 | eb = find_extent_buffer(&BTRFS_I(btree_inode)->io_tree, |
966 | bytenr, blocksize, GFP_NOFS); | 954 | bytenr, blocksize); |
967 | return eb; | 955 | return eb; |
968 | } | 956 | } |
969 | 957 | ||
@@ -974,7 +962,7 @@ struct extent_buffer *btrfs_find_create_tree_block(struct btrfs_root *root, | |||
974 | struct extent_buffer *eb; | 962 | struct extent_buffer *eb; |
975 | 963 | ||
976 | eb = alloc_extent_buffer(&BTRFS_I(btree_inode)->io_tree, | 964 | eb = alloc_extent_buffer(&BTRFS_I(btree_inode)->io_tree, |
977 | bytenr, blocksize, NULL, GFP_NOFS); | 965 | bytenr, blocksize, NULL); |
978 | return eb; | 966 | return eb; |
979 | } | 967 | } |
980 | 968 | ||
@@ -1058,13 +1046,13 @@ static int __setup_root(u32 nodesize, u32 leafsize, u32 sectorsize, | |||
1058 | root->name = NULL; | 1046 | root->name = NULL; |
1059 | root->in_sysfs = 0; | 1047 | root->in_sysfs = 0; |
1060 | root->inode_tree = RB_ROOT; | 1048 | root->inode_tree = RB_ROOT; |
1049 | INIT_RADIX_TREE(&root->delayed_nodes_tree, GFP_ATOMIC); | ||
1061 | root->block_rsv = NULL; | 1050 | root->block_rsv = NULL; |
1062 | root->orphan_block_rsv = NULL; | 1051 | root->orphan_block_rsv = NULL; |
1063 | 1052 | ||
1064 | INIT_LIST_HEAD(&root->dirty_list); | 1053 | INIT_LIST_HEAD(&root->dirty_list); |
1065 | INIT_LIST_HEAD(&root->orphan_list); | 1054 | INIT_LIST_HEAD(&root->orphan_list); |
1066 | INIT_LIST_HEAD(&root->root_list); | 1055 | INIT_LIST_HEAD(&root->root_list); |
1067 | spin_lock_init(&root->node_lock); | ||
1068 | spin_lock_init(&root->orphan_lock); | 1056 | spin_lock_init(&root->orphan_lock); |
1069 | spin_lock_init(&root->inode_lock); | 1057 | spin_lock_init(&root->inode_lock); |
1070 | spin_lock_init(&root->accounting_lock); | 1058 | spin_lock_init(&root->accounting_lock); |
@@ -1080,7 +1068,7 @@ static int __setup_root(u32 nodesize, u32 leafsize, u32 sectorsize, | |||
1080 | root->log_transid = 0; | 1068 | root->log_transid = 0; |
1081 | root->last_log_commit = 0; | 1069 | root->last_log_commit = 0; |
1082 | extent_io_tree_init(&root->dirty_log_pages, | 1070 | extent_io_tree_init(&root->dirty_log_pages, |
1083 | fs_info->btree_inode->i_mapping, GFP_NOFS); | 1071 | fs_info->btree_inode->i_mapping); |
1084 | 1072 | ||
1085 | memset(&root->root_key, 0, sizeof(root->root_key)); | 1073 | memset(&root->root_key, 0, sizeof(root->root_key)); |
1086 | memset(&root->root_item, 0, sizeof(root->root_item)); | 1074 | memset(&root->root_item, 0, sizeof(root->root_item)); |
@@ -1283,21 +1271,6 @@ out: | |||
1283 | return root; | 1271 | return root; |
1284 | } | 1272 | } |
1285 | 1273 | ||
1286 | struct btrfs_root *btrfs_lookup_fs_root(struct btrfs_fs_info *fs_info, | ||
1287 | u64 root_objectid) | ||
1288 | { | ||
1289 | struct btrfs_root *root; | ||
1290 | |||
1291 | if (root_objectid == BTRFS_ROOT_TREE_OBJECTID) | ||
1292 | return fs_info->tree_root; | ||
1293 | if (root_objectid == BTRFS_EXTENT_TREE_OBJECTID) | ||
1294 | return fs_info->extent_root; | ||
1295 | |||
1296 | root = radix_tree_lookup(&fs_info->fs_roots_radix, | ||
1297 | (unsigned long)root_objectid); | ||
1298 | return root; | ||
1299 | } | ||
1300 | |||
1301 | struct btrfs_root *btrfs_read_fs_root_no_name(struct btrfs_fs_info *fs_info, | 1274 | struct btrfs_root *btrfs_read_fs_root_no_name(struct btrfs_fs_info *fs_info, |
1302 | struct btrfs_key *location) | 1275 | struct btrfs_key *location) |
1303 | { | 1276 | { |
@@ -1326,6 +1299,19 @@ again: | |||
1326 | if (IS_ERR(root)) | 1299 | if (IS_ERR(root)) |
1327 | return root; | 1300 | return root; |
1328 | 1301 | ||
1302 | root->free_ino_ctl = kzalloc(sizeof(*root->free_ino_ctl), GFP_NOFS); | ||
1303 | if (!root->free_ino_ctl) | ||
1304 | goto fail; | ||
1305 | root->free_ino_pinned = kzalloc(sizeof(*root->free_ino_pinned), | ||
1306 | GFP_NOFS); | ||
1307 | if (!root->free_ino_pinned) | ||
1308 | goto fail; | ||
1309 | |||
1310 | btrfs_init_free_ino_ctl(root); | ||
1311 | mutex_init(&root->fs_commit_mutex); | ||
1312 | spin_lock_init(&root->cache_lock); | ||
1313 | init_waitqueue_head(&root->cache_wait); | ||
1314 | |||
1329 | set_anon_super(&root->anon_super, NULL); | 1315 | set_anon_super(&root->anon_super, NULL); |
1330 | 1316 | ||
1331 | if (btrfs_root_refs(&root->root_item) == 0) { | 1317 | if (btrfs_root_refs(&root->root_item) == 0) { |
@@ -1369,41 +1355,6 @@ fail: | |||
1369 | return ERR_PTR(ret); | 1355 | return ERR_PTR(ret); |
1370 | } | 1356 | } |
1371 | 1357 | ||
1372 | struct btrfs_root *btrfs_read_fs_root(struct btrfs_fs_info *fs_info, | ||
1373 | struct btrfs_key *location, | ||
1374 | const char *name, int namelen) | ||
1375 | { | ||
1376 | return btrfs_read_fs_root_no_name(fs_info, location); | ||
1377 | #if 0 | ||
1378 | struct btrfs_root *root; | ||
1379 | int ret; | ||
1380 | |||
1381 | root = btrfs_read_fs_root_no_name(fs_info, location); | ||
1382 | if (!root) | ||
1383 | return NULL; | ||
1384 | |||
1385 | if (root->in_sysfs) | ||
1386 | return root; | ||
1387 | |||
1388 | ret = btrfs_set_root_name(root, name, namelen); | ||
1389 | if (ret) { | ||
1390 | free_extent_buffer(root->node); | ||
1391 | kfree(root); | ||
1392 | return ERR_PTR(ret); | ||
1393 | } | ||
1394 | |||
1395 | ret = btrfs_sysfs_add_root(root); | ||
1396 | if (ret) { | ||
1397 | free_extent_buffer(root->node); | ||
1398 | kfree(root->name); | ||
1399 | kfree(root); | ||
1400 | return ERR_PTR(ret); | ||
1401 | } | ||
1402 | root->in_sysfs = 1; | ||
1403 | return root; | ||
1404 | #endif | ||
1405 | } | ||
1406 | |||
1407 | static int btrfs_congested_fn(void *congested_data, int bdi_bits) | 1358 | static int btrfs_congested_fn(void *congested_data, int bdi_bits) |
1408 | { | 1359 | { |
1409 | struct btrfs_fs_info *info = (struct btrfs_fs_info *)congested_data; | 1360 | struct btrfs_fs_info *info = (struct btrfs_fs_info *)congested_data; |
@@ -1411,7 +1362,8 @@ static int btrfs_congested_fn(void *congested_data, int bdi_bits) | |||
1411 | struct btrfs_device *device; | 1362 | struct btrfs_device *device; |
1412 | struct backing_dev_info *bdi; | 1363 | struct backing_dev_info *bdi; |
1413 | 1364 | ||
1414 | list_for_each_entry(device, &info->fs_devices->devices, dev_list) { | 1365 | rcu_read_lock(); |
1366 | list_for_each_entry_rcu(device, &info->fs_devices->devices, dev_list) { | ||
1415 | if (!device->bdev) | 1367 | if (!device->bdev) |
1416 | continue; | 1368 | continue; |
1417 | bdi = blk_get_backing_dev_info(device->bdev); | 1369 | bdi = blk_get_backing_dev_info(device->bdev); |
@@ -1420,6 +1372,7 @@ static int btrfs_congested_fn(void *congested_data, int bdi_bits) | |||
1420 | break; | 1372 | break; |
1421 | } | 1373 | } |
1422 | } | 1374 | } |
1375 | rcu_read_unlock(); | ||
1423 | return ret; | 1376 | return ret; |
1424 | } | 1377 | } |
1425 | 1378 | ||
@@ -1522,6 +1475,7 @@ static int cleaner_kthread(void *arg) | |||
1522 | btrfs_run_delayed_iputs(root); | 1475 | btrfs_run_delayed_iputs(root); |
1523 | btrfs_clean_old_snapshots(root); | 1476 | btrfs_clean_old_snapshots(root); |
1524 | mutex_unlock(&root->fs_info->cleaner_mutex); | 1477 | mutex_unlock(&root->fs_info->cleaner_mutex); |
1478 | btrfs_run_defrag_inodes(root->fs_info); | ||
1525 | } | 1479 | } |
1526 | 1480 | ||
1527 | if (freezing(current)) { | 1481 | if (freezing(current)) { |
@@ -1611,7 +1565,7 @@ struct btrfs_root *open_ctree(struct super_block *sb, | |||
1611 | struct btrfs_root *csum_root = kzalloc(sizeof(struct btrfs_root), | 1565 | struct btrfs_root *csum_root = kzalloc(sizeof(struct btrfs_root), |
1612 | GFP_NOFS); | 1566 | GFP_NOFS); |
1613 | struct btrfs_root *tree_root = btrfs_sb(sb); | 1567 | struct btrfs_root *tree_root = btrfs_sb(sb); |
1614 | struct btrfs_fs_info *fs_info = tree_root->fs_info; | 1568 | struct btrfs_fs_info *fs_info = NULL; |
1615 | struct btrfs_root *chunk_root = kzalloc(sizeof(struct btrfs_root), | 1569 | struct btrfs_root *chunk_root = kzalloc(sizeof(struct btrfs_root), |
1616 | GFP_NOFS); | 1570 | GFP_NOFS); |
1617 | struct btrfs_root *dev_root = kzalloc(sizeof(struct btrfs_root), | 1571 | struct btrfs_root *dev_root = kzalloc(sizeof(struct btrfs_root), |
@@ -1623,11 +1577,12 @@ struct btrfs_root *open_ctree(struct super_block *sb, | |||
1623 | 1577 | ||
1624 | struct btrfs_super_block *disk_super; | 1578 | struct btrfs_super_block *disk_super; |
1625 | 1579 | ||
1626 | if (!extent_root || !tree_root || !fs_info || | 1580 | if (!extent_root || !tree_root || !tree_root->fs_info || |
1627 | !chunk_root || !dev_root || !csum_root) { | 1581 | !chunk_root || !dev_root || !csum_root) { |
1628 | err = -ENOMEM; | 1582 | err = -ENOMEM; |
1629 | goto fail; | 1583 | goto fail; |
1630 | } | 1584 | } |
1585 | fs_info = tree_root->fs_info; | ||
1631 | 1586 | ||
1632 | ret = init_srcu_struct(&fs_info->subvol_srcu); | 1587 | ret = init_srcu_struct(&fs_info->subvol_srcu); |
1633 | if (ret) { | 1588 | if (ret) { |
@@ -1662,6 +1617,7 @@ struct btrfs_root *open_ctree(struct super_block *sb, | |||
1662 | spin_lock_init(&fs_info->ref_cache_lock); | 1617 | spin_lock_init(&fs_info->ref_cache_lock); |
1663 | spin_lock_init(&fs_info->fs_roots_radix_lock); | 1618 | spin_lock_init(&fs_info->fs_roots_radix_lock); |
1664 | spin_lock_init(&fs_info->delayed_iput_lock); | 1619 | spin_lock_init(&fs_info->delayed_iput_lock); |
1620 | spin_lock_init(&fs_info->defrag_inodes_lock); | ||
1665 | 1621 | ||
1666 | init_completion(&fs_info->kobj_unregister); | 1622 | init_completion(&fs_info->kobj_unregister); |
1667 | fs_info->tree_root = tree_root; | 1623 | fs_info->tree_root = tree_root; |
@@ -1684,15 +1640,35 @@ struct btrfs_root *open_ctree(struct super_block *sb, | |||
1684 | atomic_set(&fs_info->async_delalloc_pages, 0); | 1640 | atomic_set(&fs_info->async_delalloc_pages, 0); |
1685 | atomic_set(&fs_info->async_submit_draining, 0); | 1641 | atomic_set(&fs_info->async_submit_draining, 0); |
1686 | atomic_set(&fs_info->nr_async_bios, 0); | 1642 | atomic_set(&fs_info->nr_async_bios, 0); |
1643 | atomic_set(&fs_info->defrag_running, 0); | ||
1687 | fs_info->sb = sb; | 1644 | fs_info->sb = sb; |
1688 | fs_info->max_inline = 8192 * 1024; | 1645 | fs_info->max_inline = 8192 * 1024; |
1689 | fs_info->metadata_ratio = 0; | 1646 | fs_info->metadata_ratio = 0; |
1647 | fs_info->defrag_inodes = RB_ROOT; | ||
1690 | 1648 | ||
1691 | fs_info->thread_pool_size = min_t(unsigned long, | 1649 | fs_info->thread_pool_size = min_t(unsigned long, |
1692 | num_online_cpus() + 2, 8); | 1650 | num_online_cpus() + 2, 8); |
1693 | 1651 | ||
1694 | INIT_LIST_HEAD(&fs_info->ordered_extents); | 1652 | INIT_LIST_HEAD(&fs_info->ordered_extents); |
1695 | spin_lock_init(&fs_info->ordered_extent_lock); | 1653 | spin_lock_init(&fs_info->ordered_extent_lock); |
1654 | fs_info->delayed_root = kmalloc(sizeof(struct btrfs_delayed_root), | ||
1655 | GFP_NOFS); | ||
1656 | if (!fs_info->delayed_root) { | ||
1657 | err = -ENOMEM; | ||
1658 | goto fail_iput; | ||
1659 | } | ||
1660 | btrfs_init_delayed_root(fs_info->delayed_root); | ||
1661 | |||
1662 | mutex_init(&fs_info->scrub_lock); | ||
1663 | atomic_set(&fs_info->scrubs_running, 0); | ||
1664 | atomic_set(&fs_info->scrub_pause_req, 0); | ||
1665 | atomic_set(&fs_info->scrubs_paused, 0); | ||
1666 | atomic_set(&fs_info->scrub_cancel_req, 0); | ||
1667 | init_waitqueue_head(&fs_info->scrub_pause_wait); | ||
1668 | init_rwsem(&fs_info->scrub_super_lock); | ||
1669 | fs_info->scrub_workers_refcnt = 0; | ||
1670 | btrfs_init_workers(&fs_info->scrub_workers, "scrub", | ||
1671 | fs_info->thread_pool_size, &fs_info->generic_worker); | ||
1696 | 1672 | ||
1697 | sb->s_blocksize = 4096; | 1673 | sb->s_blocksize = 4096; |
1698 | sb->s_blocksize_bits = blksize_bits(4096); | 1674 | sb->s_blocksize_bits = blksize_bits(4096); |
@@ -1711,10 +1687,8 @@ struct btrfs_root *open_ctree(struct super_block *sb, | |||
1711 | 1687 | ||
1712 | RB_CLEAR_NODE(&BTRFS_I(fs_info->btree_inode)->rb_node); | 1688 | RB_CLEAR_NODE(&BTRFS_I(fs_info->btree_inode)->rb_node); |
1713 | extent_io_tree_init(&BTRFS_I(fs_info->btree_inode)->io_tree, | 1689 | extent_io_tree_init(&BTRFS_I(fs_info->btree_inode)->io_tree, |
1714 | fs_info->btree_inode->i_mapping, | 1690 | fs_info->btree_inode->i_mapping); |
1715 | GFP_NOFS); | 1691 | extent_map_tree_init(&BTRFS_I(fs_info->btree_inode)->extent_tree); |
1716 | extent_map_tree_init(&BTRFS_I(fs_info->btree_inode)->extent_tree, | ||
1717 | GFP_NOFS); | ||
1718 | 1692 | ||
1719 | BTRFS_I(fs_info->btree_inode)->io_tree.ops = &btree_extent_io_ops; | 1693 | BTRFS_I(fs_info->btree_inode)->io_tree.ops = &btree_extent_io_ops; |
1720 | 1694 | ||
@@ -1728,9 +1702,9 @@ struct btrfs_root *open_ctree(struct super_block *sb, | |||
1728 | fs_info->block_group_cache_tree = RB_ROOT; | 1702 | fs_info->block_group_cache_tree = RB_ROOT; |
1729 | 1703 | ||
1730 | extent_io_tree_init(&fs_info->freed_extents[0], | 1704 | extent_io_tree_init(&fs_info->freed_extents[0], |
1731 | fs_info->btree_inode->i_mapping, GFP_NOFS); | 1705 | fs_info->btree_inode->i_mapping); |
1732 | extent_io_tree_init(&fs_info->freed_extents[1], | 1706 | extent_io_tree_init(&fs_info->freed_extents[1], |
1733 | fs_info->btree_inode->i_mapping, GFP_NOFS); | 1707 | fs_info->btree_inode->i_mapping); |
1734 | fs_info->pinned_extents = &fs_info->freed_extents[0]; | 1708 | fs_info->pinned_extents = &fs_info->freed_extents[0]; |
1735 | fs_info->do_barriers = 1; | 1709 | fs_info->do_barriers = 1; |
1736 | 1710 | ||
@@ -1760,7 +1734,7 @@ struct btrfs_root *open_ctree(struct super_block *sb, | |||
1760 | bh = btrfs_read_dev_super(fs_devices->latest_bdev); | 1734 | bh = btrfs_read_dev_super(fs_devices->latest_bdev); |
1761 | if (!bh) { | 1735 | if (!bh) { |
1762 | err = -EINVAL; | 1736 | err = -EINVAL; |
1763 | goto fail_iput; | 1737 | goto fail_alloc; |
1764 | } | 1738 | } |
1765 | 1739 | ||
1766 | memcpy(&fs_info->super_copy, bh->b_data, sizeof(fs_info->super_copy)); | 1740 | memcpy(&fs_info->super_copy, bh->b_data, sizeof(fs_info->super_copy)); |
@@ -1772,7 +1746,7 @@ struct btrfs_root *open_ctree(struct super_block *sb, | |||
1772 | 1746 | ||
1773 | disk_super = &fs_info->super_copy; | 1747 | disk_super = &fs_info->super_copy; |
1774 | if (!btrfs_super_root(disk_super)) | 1748 | if (!btrfs_super_root(disk_super)) |
1775 | goto fail_iput; | 1749 | goto fail_alloc; |
1776 | 1750 | ||
1777 | /* check FS state, whether FS is broken. */ | 1751 | /* check FS state, whether FS is broken. */ |
1778 | fs_info->fs_state |= btrfs_super_flags(disk_super); | 1752 | fs_info->fs_state |= btrfs_super_flags(disk_super); |
@@ -1788,7 +1762,7 @@ struct btrfs_root *open_ctree(struct super_block *sb, | |||
1788 | ret = btrfs_parse_options(tree_root, options); | 1762 | ret = btrfs_parse_options(tree_root, options); |
1789 | if (ret) { | 1763 | if (ret) { |
1790 | err = ret; | 1764 | err = ret; |
1791 | goto fail_iput; | 1765 | goto fail_alloc; |
1792 | } | 1766 | } |
1793 | 1767 | ||
1794 | features = btrfs_super_incompat_flags(disk_super) & | 1768 | features = btrfs_super_incompat_flags(disk_super) & |
@@ -1798,7 +1772,7 @@ struct btrfs_root *open_ctree(struct super_block *sb, | |||
1798 | "unsupported optional features (%Lx).\n", | 1772 | "unsupported optional features (%Lx).\n", |
1799 | (unsigned long long)features); | 1773 | (unsigned long long)features); |
1800 | err = -EINVAL; | 1774 | err = -EINVAL; |
1801 | goto fail_iput; | 1775 | goto fail_alloc; |
1802 | } | 1776 | } |
1803 | 1777 | ||
1804 | features = btrfs_super_incompat_flags(disk_super); | 1778 | features = btrfs_super_incompat_flags(disk_super); |
@@ -1814,7 +1788,7 @@ struct btrfs_root *open_ctree(struct super_block *sb, | |||
1814 | "unsupported option features (%Lx).\n", | 1788 | "unsupported option features (%Lx).\n", |
1815 | (unsigned long long)features); | 1789 | (unsigned long long)features); |
1816 | err = -EINVAL; | 1790 | err = -EINVAL; |
1817 | goto fail_iput; | 1791 | goto fail_alloc; |
1818 | } | 1792 | } |
1819 | 1793 | ||
1820 | btrfs_init_workers(&fs_info->generic_worker, | 1794 | btrfs_init_workers(&fs_info->generic_worker, |
@@ -1861,6 +1835,9 @@ struct btrfs_root *open_ctree(struct super_block *sb, | |||
1861 | &fs_info->generic_worker); | 1835 | &fs_info->generic_worker); |
1862 | btrfs_init_workers(&fs_info->endio_freespace_worker, "freespace-write", | 1836 | btrfs_init_workers(&fs_info->endio_freespace_worker, "freespace-write", |
1863 | 1, &fs_info->generic_worker); | 1837 | 1, &fs_info->generic_worker); |
1838 | btrfs_init_workers(&fs_info->delayed_workers, "delayed-meta", | ||
1839 | fs_info->thread_pool_size, | ||
1840 | &fs_info->generic_worker); | ||
1864 | 1841 | ||
1865 | /* | 1842 | /* |
1866 | * endios are largely parallel and should have a very | 1843 | * endios are largely parallel and should have a very |
@@ -1882,6 +1859,7 @@ struct btrfs_root *open_ctree(struct super_block *sb, | |||
1882 | btrfs_start_workers(&fs_info->endio_meta_write_workers, 1); | 1859 | btrfs_start_workers(&fs_info->endio_meta_write_workers, 1); |
1883 | btrfs_start_workers(&fs_info->endio_write_workers, 1); | 1860 | btrfs_start_workers(&fs_info->endio_write_workers, 1); |
1884 | btrfs_start_workers(&fs_info->endio_freespace_worker, 1); | 1861 | btrfs_start_workers(&fs_info->endio_freespace_worker, 1); |
1862 | btrfs_start_workers(&fs_info->delayed_workers, 1); | ||
1885 | 1863 | ||
1886 | fs_info->bdi.ra_pages *= btrfs_super_num_devices(disk_super); | 1864 | fs_info->bdi.ra_pages *= btrfs_super_num_devices(disk_super); |
1887 | fs_info->bdi.ra_pages = max(fs_info->bdi.ra_pages, | 1865 | fs_info->bdi.ra_pages = max(fs_info->bdi.ra_pages, |
@@ -2138,6 +2116,9 @@ fail_sb_buffer: | |||
2138 | btrfs_stop_workers(&fs_info->endio_write_workers); | 2116 | btrfs_stop_workers(&fs_info->endio_write_workers); |
2139 | btrfs_stop_workers(&fs_info->endio_freespace_worker); | 2117 | btrfs_stop_workers(&fs_info->endio_freespace_worker); |
2140 | btrfs_stop_workers(&fs_info->submit_workers); | 2118 | btrfs_stop_workers(&fs_info->submit_workers); |
2119 | btrfs_stop_workers(&fs_info->delayed_workers); | ||
2120 | fail_alloc: | ||
2121 | kfree(fs_info->delayed_root); | ||
2141 | fail_iput: | 2122 | fail_iput: |
2142 | invalidate_inode_pages2(fs_info->btree_inode->i_mapping); | 2123 | invalidate_inode_pages2(fs_info->btree_inode->i_mapping); |
2143 | iput(fs_info->btree_inode); | 2124 | iput(fs_info->btree_inode); |
@@ -2165,11 +2146,9 @@ static void btrfs_end_buffer_write_sync(struct buffer_head *bh, int uptodate) | |||
2165 | if (uptodate) { | 2146 | if (uptodate) { |
2166 | set_buffer_uptodate(bh); | 2147 | set_buffer_uptodate(bh); |
2167 | } else { | 2148 | } else { |
2168 | if (printk_ratelimit()) { | 2149 | printk_ratelimited(KERN_WARNING "lost page write due to " |
2169 | printk(KERN_WARNING "lost page write due to " | ||
2170 | "I/O error on %s\n", | 2150 | "I/O error on %s\n", |
2171 | bdevname(bh->b_bdev, b)); | 2151 | bdevname(bh->b_bdev, b)); |
2172 | } | ||
2173 | /* note, we dont' set_buffer_write_io_error because we have | 2152 | /* note, we dont' set_buffer_write_io_error because we have |
2174 | * our own ways of dealing with the IO errors | 2153 | * our own ways of dealing with the IO errors |
2175 | */ | 2154 | */ |
@@ -2333,7 +2312,7 @@ int write_all_supers(struct btrfs_root *root, int max_mirrors) | |||
2333 | 2312 | ||
2334 | mutex_lock(&root->fs_info->fs_devices->device_list_mutex); | 2313 | mutex_lock(&root->fs_info->fs_devices->device_list_mutex); |
2335 | head = &root->fs_info->fs_devices->devices; | 2314 | head = &root->fs_info->fs_devices->devices; |
2336 | list_for_each_entry(dev, head, dev_list) { | 2315 | list_for_each_entry_rcu(dev, head, dev_list) { |
2337 | if (!dev->bdev) { | 2316 | if (!dev->bdev) { |
2338 | total_errors++; | 2317 | total_errors++; |
2339 | continue; | 2318 | continue; |
@@ -2366,7 +2345,7 @@ int write_all_supers(struct btrfs_root *root, int max_mirrors) | |||
2366 | } | 2345 | } |
2367 | 2346 | ||
2368 | total_errors = 0; | 2347 | total_errors = 0; |
2369 | list_for_each_entry(dev, head, dev_list) { | 2348 | list_for_each_entry_rcu(dev, head, dev_list) { |
2370 | if (!dev->bdev) | 2349 | if (!dev->bdev) |
2371 | continue; | 2350 | continue; |
2372 | if (!dev->in_fs_metadata || !dev->writeable) | 2351 | if (!dev->in_fs_metadata || !dev->writeable) |
@@ -2404,12 +2383,15 @@ int btrfs_free_fs_root(struct btrfs_fs_info *fs_info, struct btrfs_root *root) | |||
2404 | if (btrfs_root_refs(&root->root_item) == 0) | 2383 | if (btrfs_root_refs(&root->root_item) == 0) |
2405 | synchronize_srcu(&fs_info->subvol_srcu); | 2384 | synchronize_srcu(&fs_info->subvol_srcu); |
2406 | 2385 | ||
2386 | __btrfs_remove_free_space_cache(root->free_ino_pinned); | ||
2387 | __btrfs_remove_free_space_cache(root->free_ino_ctl); | ||
2407 | free_fs_root(root); | 2388 | free_fs_root(root); |
2408 | return 0; | 2389 | return 0; |
2409 | } | 2390 | } |
2410 | 2391 | ||
2411 | static void free_fs_root(struct btrfs_root *root) | 2392 | static void free_fs_root(struct btrfs_root *root) |
2412 | { | 2393 | { |
2394 | iput(root->cache_inode); | ||
2413 | WARN_ON(!RB_EMPTY_ROOT(&root->inode_tree)); | 2395 | WARN_ON(!RB_EMPTY_ROOT(&root->inode_tree)); |
2414 | if (root->anon_super.s_dev) { | 2396 | if (root->anon_super.s_dev) { |
2415 | down_write(&root->anon_super.s_umount); | 2397 | down_write(&root->anon_super.s_umount); |
@@ -2417,6 +2399,8 @@ static void free_fs_root(struct btrfs_root *root) | |||
2417 | } | 2399 | } |
2418 | free_extent_buffer(root->node); | 2400 | free_extent_buffer(root->node); |
2419 | free_extent_buffer(root->commit_root); | 2401 | free_extent_buffer(root->commit_root); |
2402 | kfree(root->free_ino_ctl); | ||
2403 | kfree(root->free_ino_pinned); | ||
2420 | kfree(root->name); | 2404 | kfree(root->name); |
2421 | kfree(root); | 2405 | kfree(root); |
2422 | } | 2406 | } |
@@ -2520,6 +2504,15 @@ int close_ctree(struct btrfs_root *root) | |||
2520 | fs_info->closing = 1; | 2504 | fs_info->closing = 1; |
2521 | smp_mb(); | 2505 | smp_mb(); |
2522 | 2506 | ||
2507 | btrfs_scrub_cancel(root); | ||
2508 | |||
2509 | /* wait for any defraggers to finish */ | ||
2510 | wait_event(fs_info->transaction_wait, | ||
2511 | (atomic_read(&fs_info->defrag_running) == 0)); | ||
2512 | |||
2513 | /* clear out the rbtree of defraggable inodes */ | ||
2514 | btrfs_run_defrag_inodes(root->fs_info); | ||
2515 | |||
2523 | btrfs_put_block_group_cache(fs_info); | 2516 | btrfs_put_block_group_cache(fs_info); |
2524 | 2517 | ||
2525 | /* | 2518 | /* |
@@ -2578,6 +2571,7 @@ int close_ctree(struct btrfs_root *root) | |||
2578 | del_fs_roots(fs_info); | 2571 | del_fs_roots(fs_info); |
2579 | 2572 | ||
2580 | iput(fs_info->btree_inode); | 2573 | iput(fs_info->btree_inode); |
2574 | kfree(fs_info->delayed_root); | ||
2581 | 2575 | ||
2582 | btrfs_stop_workers(&fs_info->generic_worker); | 2576 | btrfs_stop_workers(&fs_info->generic_worker); |
2583 | btrfs_stop_workers(&fs_info->fixup_workers); | 2577 | btrfs_stop_workers(&fs_info->fixup_workers); |
@@ -2589,6 +2583,7 @@ int close_ctree(struct btrfs_root *root) | |||
2589 | btrfs_stop_workers(&fs_info->endio_write_workers); | 2583 | btrfs_stop_workers(&fs_info->endio_write_workers); |
2590 | btrfs_stop_workers(&fs_info->endio_freespace_worker); | 2584 | btrfs_stop_workers(&fs_info->endio_freespace_worker); |
2591 | btrfs_stop_workers(&fs_info->submit_workers); | 2585 | btrfs_stop_workers(&fs_info->submit_workers); |
2586 | btrfs_stop_workers(&fs_info->delayed_workers); | ||
2592 | 2587 | ||
2593 | btrfs_close_devices(fs_info->fs_devices); | 2588 | btrfs_close_devices(fs_info->fs_devices); |
2594 | btrfs_mapping_tree_free(&fs_info->mapping_tree); | 2589 | btrfs_mapping_tree_free(&fs_info->mapping_tree); |
@@ -2665,6 +2660,29 @@ void btrfs_btree_balance_dirty(struct btrfs_root *root, unsigned long nr) | |||
2665 | if (current->flags & PF_MEMALLOC) | 2660 | if (current->flags & PF_MEMALLOC) |
2666 | return; | 2661 | return; |
2667 | 2662 | ||
2663 | btrfs_balance_delayed_items(root); | ||
2664 | |||
2665 | num_dirty = root->fs_info->dirty_metadata_bytes; | ||
2666 | |||
2667 | if (num_dirty > thresh) { | ||
2668 | balance_dirty_pages_ratelimited_nr( | ||
2669 | root->fs_info->btree_inode->i_mapping, 1); | ||
2670 | } | ||
2671 | return; | ||
2672 | } | ||
2673 | |||
2674 | void __btrfs_btree_balance_dirty(struct btrfs_root *root, unsigned long nr) | ||
2675 | { | ||
2676 | /* | ||
2677 | * looks as though older kernels can get into trouble with | ||
2678 | * this code, they end up stuck in balance_dirty_pages forever | ||
2679 | */ | ||
2680 | u64 num_dirty; | ||
2681 | unsigned long thresh = 32 * 1024 * 1024; | ||
2682 | |||
2683 | if (current->flags & PF_MEMALLOC) | ||
2684 | return; | ||
2685 | |||
2668 | num_dirty = root->fs_info->dirty_metadata_bytes; | 2686 | num_dirty = root->fs_info->dirty_metadata_bytes; |
2669 | 2687 | ||
2670 | if (num_dirty > thresh) { | 2688 | if (num_dirty > thresh) { |
@@ -2697,7 +2715,7 @@ int btree_lock_page_hook(struct page *page) | |||
2697 | goto out; | 2715 | goto out; |
2698 | 2716 | ||
2699 | len = page->private >> 2; | 2717 | len = page->private >> 2; |
2700 | eb = find_extent_buffer(io_tree, bytenr, len, GFP_NOFS); | 2718 | eb = find_extent_buffer(io_tree, bytenr, len); |
2701 | if (!eb) | 2719 | if (!eb) |
2702 | goto out; | 2720 | goto out; |
2703 | 2721 | ||