diff options
Diffstat (limited to 'fs/btrfs/disk-io.c')
| -rw-r--r-- | fs/btrfs/disk-io.c | 197 |
1 files changed, 93 insertions, 104 deletions
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index 11d0ad30e203..34f7c375567e 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c | |||
| @@ -27,6 +27,7 @@ | |||
| 27 | #include <linux/kthread.h> | 27 | #include <linux/kthread.h> |
| 28 | #include <linux/freezer.h> | 28 | #include <linux/freezer.h> |
| 29 | #include <linux/crc32c.h> | 29 | #include <linux/crc32c.h> |
| 30 | #include <linux/slab.h> | ||
| 30 | #include "compat.h" | 31 | #include "compat.h" |
| 31 | #include "ctree.h" | 32 | #include "ctree.h" |
| 32 | #include "disk-io.h" | 33 | #include "disk-io.h" |
| @@ -43,8 +44,6 @@ static struct extent_io_ops btree_extent_io_ops; | |||
| 43 | static void end_workqueue_fn(struct btrfs_work *work); | 44 | static void end_workqueue_fn(struct btrfs_work *work); |
| 44 | static void free_fs_root(struct btrfs_root *root); | 45 | static void free_fs_root(struct btrfs_root *root); |
| 45 | 46 | ||
| 46 | static atomic_t btrfs_bdi_num = ATOMIC_INIT(0); | ||
| 47 | |||
| 48 | /* | 47 | /* |
| 49 | * end_io_wq structs are used to do processing in task context when an IO is | 48 | * end_io_wq structs are used to do processing in task context when an IO is |
| 50 | * complete. This is used during reads to verify checksums, and it is used | 49 | * complete. This is used during reads to verify checksums, and it is used |
| @@ -75,6 +74,11 @@ struct async_submit_bio { | |||
| 75 | int rw; | 74 | int rw; |
| 76 | int mirror_num; | 75 | int mirror_num; |
| 77 | unsigned long bio_flags; | 76 | unsigned long bio_flags; |
| 77 | /* | ||
| 78 | * bio_offset is optional, can be used if the pages in the bio | ||
| 79 | * can't tell us where in the file the bio should go | ||
| 80 | */ | ||
| 81 | u64 bio_offset; | ||
| 78 | struct btrfs_work work; | 82 | struct btrfs_work work; |
| 79 | }; | 83 | }; |
| 80 | 84 | ||
| @@ -535,7 +539,8 @@ static void run_one_async_start(struct btrfs_work *work) | |||
| 535 | async = container_of(work, struct async_submit_bio, work); | 539 | async = container_of(work, struct async_submit_bio, work); |
| 536 | fs_info = BTRFS_I(async->inode)->root->fs_info; | 540 | fs_info = BTRFS_I(async->inode)->root->fs_info; |
| 537 | async->submit_bio_start(async->inode, async->rw, async->bio, | 541 | async->submit_bio_start(async->inode, async->rw, async->bio, |
| 538 | async->mirror_num, async->bio_flags); | 542 | async->mirror_num, async->bio_flags, |
| 543 | async->bio_offset); | ||
| 539 | } | 544 | } |
| 540 | 545 | ||
| 541 | static void run_one_async_done(struct btrfs_work *work) | 546 | static void run_one_async_done(struct btrfs_work *work) |
| @@ -557,7 +562,8 @@ static void run_one_async_done(struct btrfs_work *work) | |||
| 557 | wake_up(&fs_info->async_submit_wait); | 562 | wake_up(&fs_info->async_submit_wait); |
| 558 | 563 | ||
| 559 | async->submit_bio_done(async->inode, async->rw, async->bio, | 564 | async->submit_bio_done(async->inode, async->rw, async->bio, |
| 560 | async->mirror_num, async->bio_flags); | 565 | async->mirror_num, async->bio_flags, |
| 566 | async->bio_offset); | ||
| 561 | } | 567 | } |
| 562 | 568 | ||
| 563 | static void run_one_async_free(struct btrfs_work *work) | 569 | static void run_one_async_free(struct btrfs_work *work) |
| @@ -571,6 +577,7 @@ static void run_one_async_free(struct btrfs_work *work) | |||
| 571 | int btrfs_wq_submit_bio(struct btrfs_fs_info *fs_info, struct inode *inode, | 577 | int btrfs_wq_submit_bio(struct btrfs_fs_info *fs_info, struct inode *inode, |
| 572 | int rw, struct bio *bio, int mirror_num, | 578 | int rw, struct bio *bio, int mirror_num, |
| 573 | unsigned long bio_flags, | 579 | unsigned long bio_flags, |
| 580 | u64 bio_offset, | ||
| 574 | extent_submit_bio_hook_t *submit_bio_start, | 581 | extent_submit_bio_hook_t *submit_bio_start, |
| 575 | extent_submit_bio_hook_t *submit_bio_done) | 582 | extent_submit_bio_hook_t *submit_bio_done) |
| 576 | { | 583 | { |
| @@ -593,6 +600,7 @@ int btrfs_wq_submit_bio(struct btrfs_fs_info *fs_info, struct inode *inode, | |||
| 593 | 600 | ||
| 594 | async->work.flags = 0; | 601 | async->work.flags = 0; |
| 595 | async->bio_flags = bio_flags; | 602 | async->bio_flags = bio_flags; |
| 603 | async->bio_offset = bio_offset; | ||
| 596 | 604 | ||
| 597 | atomic_inc(&fs_info->nr_async_submits); | 605 | atomic_inc(&fs_info->nr_async_submits); |
| 598 | 606 | ||
| @@ -628,7 +636,8 @@ static int btree_csum_one_bio(struct bio *bio) | |||
| 628 | 636 | ||
| 629 | static int __btree_submit_bio_start(struct inode *inode, int rw, | 637 | static int __btree_submit_bio_start(struct inode *inode, int rw, |
| 630 | struct bio *bio, int mirror_num, | 638 | struct bio *bio, int mirror_num, |
| 631 | unsigned long bio_flags) | 639 | unsigned long bio_flags, |
| 640 | u64 bio_offset) | ||
| 632 | { | 641 | { |
| 633 | /* | 642 | /* |
| 634 | * when we're called for a write, we're already in the async | 643 | * when we're called for a write, we're already in the async |
| @@ -639,7 +648,8 @@ static int __btree_submit_bio_start(struct inode *inode, int rw, | |||
| 639 | } | 648 | } |
| 640 | 649 | ||
| 641 | static int __btree_submit_bio_done(struct inode *inode, int rw, struct bio *bio, | 650 | static int __btree_submit_bio_done(struct inode *inode, int rw, struct bio *bio, |
| 642 | int mirror_num, unsigned long bio_flags) | 651 | int mirror_num, unsigned long bio_flags, |
| 652 | u64 bio_offset) | ||
| 643 | { | 653 | { |
| 644 | /* | 654 | /* |
| 645 | * when we're called for a write, we're already in the async | 655 | * when we're called for a write, we're already in the async |
| @@ -649,7 +659,8 @@ static int __btree_submit_bio_done(struct inode *inode, int rw, struct bio *bio, | |||
| 649 | } | 659 | } |
| 650 | 660 | ||
| 651 | static int btree_submit_bio_hook(struct inode *inode, int rw, struct bio *bio, | 661 | static int btree_submit_bio_hook(struct inode *inode, int rw, struct bio *bio, |
| 652 | int mirror_num, unsigned long bio_flags) | 662 | int mirror_num, unsigned long bio_flags, |
| 663 | u64 bio_offset) | ||
| 653 | { | 664 | { |
| 654 | int ret; | 665 | int ret; |
| 655 | 666 | ||
| @@ -672,6 +683,7 @@ static int btree_submit_bio_hook(struct inode *inode, int rw, struct bio *bio, | |||
| 672 | */ | 683 | */ |
| 673 | return btrfs_wq_submit_bio(BTRFS_I(inode)->root->fs_info, | 684 | return btrfs_wq_submit_bio(BTRFS_I(inode)->root->fs_info, |
| 674 | inode, rw, bio, mirror_num, 0, | 685 | inode, rw, bio, mirror_num, 0, |
| 686 | bio_offset, | ||
| 675 | __btree_submit_bio_start, | 687 | __btree_submit_bio_start, |
| 676 | __btree_submit_bio_done); | 688 | __btree_submit_bio_done); |
| 677 | } | 689 | } |
| @@ -895,7 +907,8 @@ static int __setup_root(u32 nodesize, u32 leafsize, u32 sectorsize, | |||
| 895 | root->ref_cows = 0; | 907 | root->ref_cows = 0; |
| 896 | root->track_dirty = 0; | 908 | root->track_dirty = 0; |
| 897 | root->in_radix = 0; | 909 | root->in_radix = 0; |
| 898 | root->clean_orphans = 0; | 910 | root->orphan_item_inserted = 0; |
| 911 | root->orphan_cleanup_state = 0; | ||
| 899 | 912 | ||
| 900 | root->fs_info = fs_info; | 913 | root->fs_info = fs_info; |
| 901 | root->objectid = objectid; | 914 | root->objectid = objectid; |
| @@ -904,13 +917,16 @@ static int __setup_root(u32 nodesize, u32 leafsize, u32 sectorsize, | |||
| 904 | root->name = NULL; | 917 | root->name = NULL; |
| 905 | root->in_sysfs = 0; | 918 | root->in_sysfs = 0; |
| 906 | root->inode_tree = RB_ROOT; | 919 | root->inode_tree = RB_ROOT; |
| 920 | root->block_rsv = NULL; | ||
| 921 | root->orphan_block_rsv = NULL; | ||
| 907 | 922 | ||
| 908 | INIT_LIST_HEAD(&root->dirty_list); | 923 | INIT_LIST_HEAD(&root->dirty_list); |
| 909 | INIT_LIST_HEAD(&root->orphan_list); | 924 | INIT_LIST_HEAD(&root->orphan_list); |
| 910 | INIT_LIST_HEAD(&root->root_list); | 925 | INIT_LIST_HEAD(&root->root_list); |
| 911 | spin_lock_init(&root->node_lock); | 926 | spin_lock_init(&root->node_lock); |
| 912 | spin_lock_init(&root->list_lock); | 927 | spin_lock_init(&root->orphan_lock); |
| 913 | spin_lock_init(&root->inode_lock); | 928 | spin_lock_init(&root->inode_lock); |
| 929 | spin_lock_init(&root->accounting_lock); | ||
| 914 | mutex_init(&root->objectid_mutex); | 930 | mutex_init(&root->objectid_mutex); |
| 915 | mutex_init(&root->log_mutex); | 931 | mutex_init(&root->log_mutex); |
| 916 | init_waitqueue_head(&root->log_writer_wait); | 932 | init_waitqueue_head(&root->log_writer_wait); |
| @@ -969,42 +985,6 @@ static int find_and_setup_root(struct btrfs_root *tree_root, | |||
| 969 | return 0; | 985 | return 0; |
| 970 | } | 986 | } |
| 971 | 987 | ||
| 972 | int btrfs_free_log_root_tree(struct btrfs_trans_handle *trans, | ||
| 973 | struct btrfs_fs_info *fs_info) | ||
| 974 | { | ||
| 975 | struct extent_buffer *eb; | ||
| 976 | struct btrfs_root *log_root_tree = fs_info->log_root_tree; | ||
| 977 | u64 start = 0; | ||
| 978 | u64 end = 0; | ||
| 979 | int ret; | ||
| 980 | |||
| 981 | if (!log_root_tree) | ||
| 982 | return 0; | ||
| 983 | |||
| 984 | while (1) { | ||
| 985 | ret = find_first_extent_bit(&log_root_tree->dirty_log_pages, | ||
| 986 | 0, &start, &end, EXTENT_DIRTY | EXTENT_NEW); | ||
| 987 | if (ret) | ||
| 988 | break; | ||
| 989 | |||
| 990 | clear_extent_bits(&log_root_tree->dirty_log_pages, start, end, | ||
| 991 | EXTENT_DIRTY | EXTENT_NEW, GFP_NOFS); | ||
| 992 | } | ||
| 993 | eb = fs_info->log_root_tree->node; | ||
| 994 | |||
| 995 | WARN_ON(btrfs_header_level(eb) != 0); | ||
| 996 | WARN_ON(btrfs_header_nritems(eb) != 0); | ||
| 997 | |||
| 998 | ret = btrfs_free_reserved_extent(fs_info->tree_root, | ||
| 999 | eb->start, eb->len); | ||
| 1000 | BUG_ON(ret); | ||
| 1001 | |||
| 1002 | free_extent_buffer(eb); | ||
| 1003 | kfree(fs_info->log_root_tree); | ||
| 1004 | fs_info->log_root_tree = NULL; | ||
| 1005 | return 0; | ||
| 1006 | } | ||
| 1007 | |||
| 1008 | static struct btrfs_root *alloc_log_tree(struct btrfs_trans_handle *trans, | 988 | static struct btrfs_root *alloc_log_tree(struct btrfs_trans_handle *trans, |
| 1009 | struct btrfs_fs_info *fs_info) | 989 | struct btrfs_fs_info *fs_info) |
| 1010 | { | 990 | { |
| @@ -1192,19 +1172,23 @@ again: | |||
| 1192 | if (root) | 1172 | if (root) |
| 1193 | return root; | 1173 | return root; |
| 1194 | 1174 | ||
| 1195 | ret = btrfs_find_orphan_item(fs_info->tree_root, location->objectid); | ||
| 1196 | if (ret == 0) | ||
| 1197 | ret = -ENOENT; | ||
| 1198 | if (ret < 0) | ||
| 1199 | return ERR_PTR(ret); | ||
| 1200 | |||
| 1201 | root = btrfs_read_fs_root_no_radix(fs_info->tree_root, location); | 1175 | root = btrfs_read_fs_root_no_radix(fs_info->tree_root, location); |
| 1202 | if (IS_ERR(root)) | 1176 | if (IS_ERR(root)) |
| 1203 | return root; | 1177 | return root; |
| 1204 | 1178 | ||
| 1205 | WARN_ON(btrfs_root_refs(&root->root_item) == 0); | ||
| 1206 | set_anon_super(&root->anon_super, NULL); | 1179 | set_anon_super(&root->anon_super, NULL); |
| 1207 | 1180 | ||
| 1181 | if (btrfs_root_refs(&root->root_item) == 0) { | ||
| 1182 | ret = -ENOENT; | ||
| 1183 | goto fail; | ||
| 1184 | } | ||
| 1185 | |||
| 1186 | ret = btrfs_find_orphan_item(fs_info->tree_root, location->objectid); | ||
| 1187 | if (ret < 0) | ||
| 1188 | goto fail; | ||
| 1189 | if (ret == 0) | ||
| 1190 | root->orphan_item_inserted = 1; | ||
| 1191 | |||
| 1208 | ret = radix_tree_preload(GFP_NOFS & ~__GFP_HIGHMEM); | 1192 | ret = radix_tree_preload(GFP_NOFS & ~__GFP_HIGHMEM); |
| 1209 | if (ret) | 1193 | if (ret) |
| 1210 | goto fail; | 1194 | goto fail; |
| @@ -1213,10 +1197,9 @@ again: | |||
| 1213 | ret = radix_tree_insert(&fs_info->fs_roots_radix, | 1197 | ret = radix_tree_insert(&fs_info->fs_roots_radix, |
| 1214 | (unsigned long)root->root_key.objectid, | 1198 | (unsigned long)root->root_key.objectid, |
| 1215 | root); | 1199 | root); |
| 1216 | if (ret == 0) { | 1200 | if (ret == 0) |
| 1217 | root->in_radix = 1; | 1201 | root->in_radix = 1; |
| 1218 | root->clean_orphans = 1; | 1202 | |
| 1219 | } | ||
| 1220 | spin_unlock(&fs_info->fs_roots_radix_lock); | 1203 | spin_unlock(&fs_info->fs_roots_radix_lock); |
| 1221 | radix_tree_preload_end(); | 1204 | radix_tree_preload_end(); |
| 1222 | if (ret) { | 1205 | if (ret) { |
| @@ -1374,19 +1357,11 @@ static int setup_bdi(struct btrfs_fs_info *info, struct backing_dev_info *bdi) | |||
| 1374 | { | 1357 | { |
| 1375 | int err; | 1358 | int err; |
| 1376 | 1359 | ||
| 1377 | bdi->name = "btrfs"; | ||
| 1378 | bdi->capabilities = BDI_CAP_MAP_COPY; | 1360 | bdi->capabilities = BDI_CAP_MAP_COPY; |
| 1379 | err = bdi_init(bdi); | 1361 | err = bdi_setup_and_register(bdi, "btrfs", BDI_CAP_MAP_COPY); |
| 1380 | if (err) | 1362 | if (err) |
| 1381 | return err; | 1363 | return err; |
| 1382 | 1364 | ||
| 1383 | err = bdi_register(bdi, NULL, "btrfs-%d", | ||
| 1384 | atomic_inc_return(&btrfs_bdi_num)); | ||
| 1385 | if (err) { | ||
| 1386 | bdi_destroy(bdi); | ||
| 1387 | return err; | ||
| 1388 | } | ||
| 1389 | |||
| 1390 | bdi->ra_pages = default_backing_dev_info.ra_pages; | 1365 | bdi->ra_pages = default_backing_dev_info.ra_pages; |
| 1391 | bdi->unplug_io_fn = btrfs_unplug_io_fn; | 1366 | bdi->unplug_io_fn = btrfs_unplug_io_fn; |
| 1392 | bdi->unplug_io_data = info; | 1367 | bdi->unplug_io_data = info; |
| @@ -1470,10 +1445,6 @@ static int cleaner_kthread(void *arg) | |||
| 1470 | struct btrfs_root *root = arg; | 1445 | struct btrfs_root *root = arg; |
| 1471 | 1446 | ||
| 1472 | do { | 1447 | do { |
| 1473 | smp_mb(); | ||
| 1474 | if (root->fs_info->closing) | ||
| 1475 | break; | ||
| 1476 | |||
| 1477 | vfs_check_frozen(root->fs_info->sb, SB_FREEZE_WRITE); | 1448 | vfs_check_frozen(root->fs_info->sb, SB_FREEZE_WRITE); |
| 1478 | 1449 | ||
| 1479 | if (!(root->fs_info->sb->s_flags & MS_RDONLY) && | 1450 | if (!(root->fs_info->sb->s_flags & MS_RDONLY) && |
| @@ -1486,11 +1457,9 @@ static int cleaner_kthread(void *arg) | |||
| 1486 | if (freezing(current)) { | 1457 | if (freezing(current)) { |
| 1487 | refrigerator(); | 1458 | refrigerator(); |
| 1488 | } else { | 1459 | } else { |
| 1489 | smp_mb(); | ||
| 1490 | if (root->fs_info->closing) | ||
| 1491 | break; | ||
| 1492 | set_current_state(TASK_INTERRUPTIBLE); | 1460 | set_current_state(TASK_INTERRUPTIBLE); |
| 1493 | schedule(); | 1461 | if (!kthread_should_stop()) |
| 1462 | schedule(); | ||
| 1494 | __set_current_state(TASK_RUNNING); | 1463 | __set_current_state(TASK_RUNNING); |
| 1495 | } | 1464 | } |
| 1496 | } while (!kthread_should_stop()); | 1465 | } while (!kthread_should_stop()); |
| @@ -1502,36 +1471,40 @@ static int transaction_kthread(void *arg) | |||
| 1502 | struct btrfs_root *root = arg; | 1471 | struct btrfs_root *root = arg; |
| 1503 | struct btrfs_trans_handle *trans; | 1472 | struct btrfs_trans_handle *trans; |
| 1504 | struct btrfs_transaction *cur; | 1473 | struct btrfs_transaction *cur; |
| 1474 | u64 transid; | ||
| 1505 | unsigned long now; | 1475 | unsigned long now; |
| 1506 | unsigned long delay; | 1476 | unsigned long delay; |
| 1507 | int ret; | 1477 | int ret; |
| 1508 | 1478 | ||
| 1509 | do { | 1479 | do { |
| 1510 | smp_mb(); | ||
| 1511 | if (root->fs_info->closing) | ||
| 1512 | break; | ||
| 1513 | |||
| 1514 | delay = HZ * 30; | 1480 | delay = HZ * 30; |
| 1515 | vfs_check_frozen(root->fs_info->sb, SB_FREEZE_WRITE); | 1481 | vfs_check_frozen(root->fs_info->sb, SB_FREEZE_WRITE); |
| 1516 | mutex_lock(&root->fs_info->transaction_kthread_mutex); | 1482 | mutex_lock(&root->fs_info->transaction_kthread_mutex); |
| 1517 | 1483 | ||
| 1518 | mutex_lock(&root->fs_info->trans_mutex); | 1484 | spin_lock(&root->fs_info->new_trans_lock); |
| 1519 | cur = root->fs_info->running_transaction; | 1485 | cur = root->fs_info->running_transaction; |
| 1520 | if (!cur) { | 1486 | if (!cur) { |
| 1521 | mutex_unlock(&root->fs_info->trans_mutex); | 1487 | spin_unlock(&root->fs_info->new_trans_lock); |
| 1522 | goto sleep; | 1488 | goto sleep; |
| 1523 | } | 1489 | } |
| 1524 | 1490 | ||
| 1525 | now = get_seconds(); | 1491 | now = get_seconds(); |
| 1526 | if (now < cur->start_time || now - cur->start_time < 30) { | 1492 | if (!cur->blocked && |
| 1527 | mutex_unlock(&root->fs_info->trans_mutex); | 1493 | (now < cur->start_time || now - cur->start_time < 30)) { |
| 1494 | spin_unlock(&root->fs_info->new_trans_lock); | ||
| 1528 | delay = HZ * 5; | 1495 | delay = HZ * 5; |
| 1529 | goto sleep; | 1496 | goto sleep; |
| 1530 | } | 1497 | } |
| 1531 | mutex_unlock(&root->fs_info->trans_mutex); | 1498 | transid = cur->transid; |
| 1532 | trans = btrfs_start_transaction(root, 1); | 1499 | spin_unlock(&root->fs_info->new_trans_lock); |
| 1533 | ret = btrfs_commit_transaction(trans, root); | ||
| 1534 | 1500 | ||
| 1501 | trans = btrfs_join_transaction(root, 1); | ||
| 1502 | if (transid == trans->transid) { | ||
| 1503 | ret = btrfs_commit_transaction(trans, root); | ||
| 1504 | BUG_ON(ret); | ||
| 1505 | } else { | ||
| 1506 | btrfs_end_transaction(trans, root); | ||
| 1507 | } | ||
| 1535 | sleep: | 1508 | sleep: |
| 1536 | wake_up_process(root->fs_info->cleaner_kthread); | 1509 | wake_up_process(root->fs_info->cleaner_kthread); |
| 1537 | mutex_unlock(&root->fs_info->transaction_kthread_mutex); | 1510 | mutex_unlock(&root->fs_info->transaction_kthread_mutex); |
| @@ -1539,10 +1512,10 @@ sleep: | |||
| 1539 | if (freezing(current)) { | 1512 | if (freezing(current)) { |
| 1540 | refrigerator(); | 1513 | refrigerator(); |
| 1541 | } else { | 1514 | } else { |
| 1542 | if (root->fs_info->closing) | ||
| 1543 | break; | ||
| 1544 | set_current_state(TASK_INTERRUPTIBLE); | 1515 | set_current_state(TASK_INTERRUPTIBLE); |
| 1545 | schedule_timeout(delay); | 1516 | if (!kthread_should_stop() && |
| 1517 | !btrfs_transaction_blocked(root->fs_info)) | ||
| 1518 | schedule_timeout(delay); | ||
| 1546 | __set_current_state(TASK_RUNNING); | 1519 | __set_current_state(TASK_RUNNING); |
| 1547 | } | 1520 | } |
| 1548 | } while (!kthread_should_stop()); | 1521 | } while (!kthread_should_stop()); |
| @@ -1629,12 +1602,18 @@ struct btrfs_root *open_ctree(struct super_block *sb, | |||
| 1629 | INIT_LIST_HEAD(&fs_info->dirty_cowonly_roots); | 1602 | INIT_LIST_HEAD(&fs_info->dirty_cowonly_roots); |
| 1630 | INIT_LIST_HEAD(&fs_info->space_info); | 1603 | INIT_LIST_HEAD(&fs_info->space_info); |
| 1631 | btrfs_mapping_init(&fs_info->mapping_tree); | 1604 | btrfs_mapping_init(&fs_info->mapping_tree); |
| 1605 | btrfs_init_block_rsv(&fs_info->global_block_rsv); | ||
| 1606 | btrfs_init_block_rsv(&fs_info->delalloc_block_rsv); | ||
| 1607 | btrfs_init_block_rsv(&fs_info->trans_block_rsv); | ||
| 1608 | btrfs_init_block_rsv(&fs_info->chunk_block_rsv); | ||
| 1609 | btrfs_init_block_rsv(&fs_info->empty_block_rsv); | ||
| 1610 | INIT_LIST_HEAD(&fs_info->durable_block_rsv_list); | ||
| 1611 | mutex_init(&fs_info->durable_block_rsv_mutex); | ||
| 1632 | atomic_set(&fs_info->nr_async_submits, 0); | 1612 | atomic_set(&fs_info->nr_async_submits, 0); |
| 1633 | atomic_set(&fs_info->async_delalloc_pages, 0); | 1613 | atomic_set(&fs_info->async_delalloc_pages, 0); |
| 1634 | atomic_set(&fs_info->async_submit_draining, 0); | 1614 | atomic_set(&fs_info->async_submit_draining, 0); |
| 1635 | atomic_set(&fs_info->nr_async_bios, 0); | 1615 | atomic_set(&fs_info->nr_async_bios, 0); |
| 1636 | fs_info->sb = sb; | 1616 | fs_info->sb = sb; |
| 1637 | fs_info->max_extent = (u64)-1; | ||
| 1638 | fs_info->max_inline = 8192 * 1024; | 1617 | fs_info->max_inline = 8192 * 1024; |
| 1639 | fs_info->metadata_ratio = 0; | 1618 | fs_info->metadata_ratio = 0; |
| 1640 | 1619 | ||
| @@ -1769,9 +1748,6 @@ struct btrfs_root *open_ctree(struct super_block *sb, | |||
| 1769 | min_t(u64, fs_devices->num_devices, | 1748 | min_t(u64, fs_devices->num_devices, |
| 1770 | fs_info->thread_pool_size), | 1749 | fs_info->thread_pool_size), |
| 1771 | &fs_info->generic_worker); | 1750 | &fs_info->generic_worker); |
| 1772 | btrfs_init_workers(&fs_info->enospc_workers, "enospc", | ||
| 1773 | fs_info->thread_pool_size, | ||
| 1774 | &fs_info->generic_worker); | ||
| 1775 | 1751 | ||
| 1776 | /* a higher idle thresh on the submit workers makes it much more | 1752 | /* a higher idle thresh on the submit workers makes it much more |
| 1777 | * likely that bios will be send down in a sane order to the | 1753 | * likely that bios will be send down in a sane order to the |
| @@ -1819,7 +1795,6 @@ struct btrfs_root *open_ctree(struct super_block *sb, | |||
| 1819 | btrfs_start_workers(&fs_info->endio_meta_workers, 1); | 1795 | btrfs_start_workers(&fs_info->endio_meta_workers, 1); |
| 1820 | btrfs_start_workers(&fs_info->endio_meta_write_workers, 1); | 1796 | btrfs_start_workers(&fs_info->endio_meta_write_workers, 1); |
| 1821 | btrfs_start_workers(&fs_info->endio_write_workers, 1); | 1797 | btrfs_start_workers(&fs_info->endio_write_workers, 1); |
| 1822 | btrfs_start_workers(&fs_info->enospc_workers, 1); | ||
| 1823 | 1798 | ||
| 1824 | fs_info->bdi.ra_pages *= btrfs_super_num_devices(disk_super); | 1799 | fs_info->bdi.ra_pages *= btrfs_super_num_devices(disk_super); |
| 1825 | fs_info->bdi.ra_pages = max(fs_info->bdi.ra_pages, | 1800 | fs_info->bdi.ra_pages = max(fs_info->bdi.ra_pages, |
| @@ -1922,17 +1897,22 @@ struct btrfs_root *open_ctree(struct super_block *sb, | |||
| 1922 | 1897 | ||
| 1923 | csum_root->track_dirty = 1; | 1898 | csum_root->track_dirty = 1; |
| 1924 | 1899 | ||
| 1925 | btrfs_read_block_groups(extent_root); | ||
| 1926 | |||
| 1927 | fs_info->generation = generation; | 1900 | fs_info->generation = generation; |
| 1928 | fs_info->last_trans_committed = generation; | 1901 | fs_info->last_trans_committed = generation; |
| 1929 | fs_info->data_alloc_profile = (u64)-1; | 1902 | fs_info->data_alloc_profile = (u64)-1; |
| 1930 | fs_info->metadata_alloc_profile = (u64)-1; | 1903 | fs_info->metadata_alloc_profile = (u64)-1; |
| 1931 | fs_info->system_alloc_profile = fs_info->metadata_alloc_profile; | 1904 | fs_info->system_alloc_profile = fs_info->metadata_alloc_profile; |
| 1905 | |||
| 1906 | ret = btrfs_read_block_groups(extent_root); | ||
| 1907 | if (ret) { | ||
| 1908 | printk(KERN_ERR "Failed to read block groups: %d\n", ret); | ||
| 1909 | goto fail_block_groups; | ||
| 1910 | } | ||
| 1911 | |||
| 1932 | fs_info->cleaner_kthread = kthread_run(cleaner_kthread, tree_root, | 1912 | fs_info->cleaner_kthread = kthread_run(cleaner_kthread, tree_root, |
| 1933 | "btrfs-cleaner"); | 1913 | "btrfs-cleaner"); |
| 1934 | if (IS_ERR(fs_info->cleaner_kthread)) | 1914 | if (IS_ERR(fs_info->cleaner_kthread)) |
| 1935 | goto fail_csum_root; | 1915 | goto fail_block_groups; |
| 1936 | 1916 | ||
| 1937 | fs_info->transaction_kthread = kthread_run(transaction_kthread, | 1917 | fs_info->transaction_kthread = kthread_run(transaction_kthread, |
| 1938 | tree_root, | 1918 | tree_root, |
| @@ -1961,8 +1941,11 @@ struct btrfs_root *open_ctree(struct super_block *sb, | |||
| 1961 | btrfs_level_size(tree_root, | 1941 | btrfs_level_size(tree_root, |
| 1962 | btrfs_super_log_root_level(disk_super)); | 1942 | btrfs_super_log_root_level(disk_super)); |
| 1963 | 1943 | ||
| 1964 | log_tree_root = kzalloc(sizeof(struct btrfs_root), | 1944 | log_tree_root = kzalloc(sizeof(struct btrfs_root), GFP_NOFS); |
| 1965 | GFP_NOFS); | 1945 | if (!log_tree_root) { |
| 1946 | err = -ENOMEM; | ||
| 1947 | goto fail_trans_kthread; | ||
| 1948 | } | ||
| 1966 | 1949 | ||
| 1967 | __setup_root(nodesize, leafsize, sectorsize, stripesize, | 1950 | __setup_root(nodesize, leafsize, sectorsize, stripesize, |
| 1968 | log_tree_root, fs_info, BTRFS_TREE_LOG_OBJECTID); | 1951 | log_tree_root, fs_info, BTRFS_TREE_LOG_OBJECTID); |
| @@ -1983,6 +1966,9 @@ struct btrfs_root *open_ctree(struct super_block *sb, | |||
| 1983 | BUG_ON(ret); | 1966 | BUG_ON(ret); |
| 1984 | 1967 | ||
| 1985 | if (!(sb->s_flags & MS_RDONLY)) { | 1968 | if (!(sb->s_flags & MS_RDONLY)) { |
| 1969 | ret = btrfs_cleanup_fs_roots(fs_info); | ||
| 1970 | BUG_ON(ret); | ||
| 1971 | |||
| 1986 | ret = btrfs_recover_relocation(tree_root); | 1972 | ret = btrfs_recover_relocation(tree_root); |
| 1987 | if (ret < 0) { | 1973 | if (ret < 0) { |
| 1988 | printk(KERN_WARNING | 1974 | printk(KERN_WARNING |
| @@ -1999,6 +1985,10 @@ struct btrfs_root *open_ctree(struct super_block *sb, | |||
| 1999 | fs_info->fs_root = btrfs_read_fs_root_no_name(fs_info, &location); | 1985 | fs_info->fs_root = btrfs_read_fs_root_no_name(fs_info, &location); |
| 2000 | if (!fs_info->fs_root) | 1986 | if (!fs_info->fs_root) |
| 2001 | goto fail_trans_kthread; | 1987 | goto fail_trans_kthread; |
| 1988 | if (IS_ERR(fs_info->fs_root)) { | ||
| 1989 | err = PTR_ERR(fs_info->fs_root); | ||
| 1990 | goto fail_trans_kthread; | ||
| 1991 | } | ||
| 2002 | 1992 | ||
| 2003 | if (!(sb->s_flags & MS_RDONLY)) { | 1993 | if (!(sb->s_flags & MS_RDONLY)) { |
| 2004 | down_read(&fs_info->cleanup_work_sem); | 1994 | down_read(&fs_info->cleanup_work_sem); |
| @@ -2020,7 +2010,8 @@ fail_cleaner: | |||
| 2020 | filemap_write_and_wait(fs_info->btree_inode->i_mapping); | 2010 | filemap_write_and_wait(fs_info->btree_inode->i_mapping); |
| 2021 | invalidate_inode_pages2(fs_info->btree_inode->i_mapping); | 2011 | invalidate_inode_pages2(fs_info->btree_inode->i_mapping); |
| 2022 | 2012 | ||
| 2023 | fail_csum_root: | 2013 | fail_block_groups: |
| 2014 | btrfs_free_block_groups(fs_info); | ||
| 2024 | free_extent_buffer(csum_root->node); | 2015 | free_extent_buffer(csum_root->node); |
| 2025 | free_extent_buffer(csum_root->commit_root); | 2016 | free_extent_buffer(csum_root->commit_root); |
| 2026 | fail_dev_root: | 2017 | fail_dev_root: |
| @@ -2045,7 +2036,6 @@ fail_sb_buffer: | |||
| 2045 | btrfs_stop_workers(&fs_info->endio_meta_write_workers); | 2036 | btrfs_stop_workers(&fs_info->endio_meta_write_workers); |
| 2046 | btrfs_stop_workers(&fs_info->endio_write_workers); | 2037 | btrfs_stop_workers(&fs_info->endio_write_workers); |
| 2047 | btrfs_stop_workers(&fs_info->submit_workers); | 2038 | btrfs_stop_workers(&fs_info->submit_workers); |
| 2048 | btrfs_stop_workers(&fs_info->enospc_workers); | ||
| 2049 | fail_iput: | 2039 | fail_iput: |
| 2050 | invalidate_inode_pages2(fs_info->btree_inode->i_mapping); | 2040 | invalidate_inode_pages2(fs_info->btree_inode->i_mapping); |
| 2051 | iput(fs_info->btree_inode); | 2041 | iput(fs_info->btree_inode); |
| @@ -2410,11 +2400,11 @@ int btrfs_commit_super(struct btrfs_root *root) | |||
| 2410 | down_write(&root->fs_info->cleanup_work_sem); | 2400 | down_write(&root->fs_info->cleanup_work_sem); |
| 2411 | up_write(&root->fs_info->cleanup_work_sem); | 2401 | up_write(&root->fs_info->cleanup_work_sem); |
| 2412 | 2402 | ||
| 2413 | trans = btrfs_start_transaction(root, 1); | 2403 | trans = btrfs_join_transaction(root, 1); |
| 2414 | ret = btrfs_commit_transaction(trans, root); | 2404 | ret = btrfs_commit_transaction(trans, root); |
| 2415 | BUG_ON(ret); | 2405 | BUG_ON(ret); |
| 2416 | /* run commit again to drop the original snapshot */ | 2406 | /* run commit again to drop the original snapshot */ |
| 2417 | trans = btrfs_start_transaction(root, 1); | 2407 | trans = btrfs_join_transaction(root, 1); |
| 2418 | btrfs_commit_transaction(trans, root); | 2408 | btrfs_commit_transaction(trans, root); |
| 2419 | ret = btrfs_write_and_wait_transaction(NULL, root); | 2409 | ret = btrfs_write_and_wait_transaction(NULL, root); |
| 2420 | BUG_ON(ret); | 2410 | BUG_ON(ret); |
| @@ -2431,15 +2421,15 @@ int close_ctree(struct btrfs_root *root) | |||
| 2431 | fs_info->closing = 1; | 2421 | fs_info->closing = 1; |
| 2432 | smp_mb(); | 2422 | smp_mb(); |
| 2433 | 2423 | ||
| 2434 | kthread_stop(root->fs_info->transaction_kthread); | ||
| 2435 | kthread_stop(root->fs_info->cleaner_kthread); | ||
| 2436 | |||
| 2437 | if (!(fs_info->sb->s_flags & MS_RDONLY)) { | 2424 | if (!(fs_info->sb->s_flags & MS_RDONLY)) { |
| 2438 | ret = btrfs_commit_super(root); | 2425 | ret = btrfs_commit_super(root); |
| 2439 | if (ret) | 2426 | if (ret) |
| 2440 | printk(KERN_ERR "btrfs: commit super ret %d\n", ret); | 2427 | printk(KERN_ERR "btrfs: commit super ret %d\n", ret); |
| 2441 | } | 2428 | } |
| 2442 | 2429 | ||
| 2430 | kthread_stop(root->fs_info->transaction_kthread); | ||
| 2431 | kthread_stop(root->fs_info->cleaner_kthread); | ||
| 2432 | |||
| 2443 | fs_info->closing = 2; | 2433 | fs_info->closing = 2; |
| 2444 | smp_mb(); | 2434 | smp_mb(); |
| 2445 | 2435 | ||
| @@ -2478,7 +2468,6 @@ int close_ctree(struct btrfs_root *root) | |||
| 2478 | btrfs_stop_workers(&fs_info->endio_meta_write_workers); | 2468 | btrfs_stop_workers(&fs_info->endio_meta_write_workers); |
| 2479 | btrfs_stop_workers(&fs_info->endio_write_workers); | 2469 | btrfs_stop_workers(&fs_info->endio_write_workers); |
| 2480 | btrfs_stop_workers(&fs_info->submit_workers); | 2470 | btrfs_stop_workers(&fs_info->submit_workers); |
| 2481 | btrfs_stop_workers(&fs_info->enospc_workers); | ||
| 2482 | 2471 | ||
| 2483 | btrfs_close_devices(fs_info->fs_devices); | 2472 | btrfs_close_devices(fs_info->fs_devices); |
| 2484 | btrfs_mapping_tree_free(&fs_info->mapping_tree); | 2473 | btrfs_mapping_tree_free(&fs_info->mapping_tree); |
