diff options
Diffstat (limited to 'fs/btrfs/disk-io.c')
-rw-r--r-- | fs/btrfs/disk-io.c | 27 |
1 files changed, 18 insertions, 9 deletions
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index 02b6afbd7450..009e3bd18f23 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c | |||
@@ -892,6 +892,8 @@ static int __setup_root(u32 nodesize, u32 leafsize, u32 sectorsize, | |||
892 | root->stripesize = stripesize; | 892 | root->stripesize = stripesize; |
893 | root->ref_cows = 0; | 893 | root->ref_cows = 0; |
894 | root->track_dirty = 0; | 894 | root->track_dirty = 0; |
895 | root->in_radix = 0; | ||
896 | root->clean_orphans = 0; | ||
895 | 897 | ||
896 | root->fs_info = fs_info; | 898 | root->fs_info = fs_info; |
897 | root->objectid = objectid; | 899 | root->objectid = objectid; |
@@ -928,7 +930,6 @@ static int __setup_root(u32 nodesize, u32 leafsize, u32 sectorsize, | |||
928 | root->defrag_trans_start = fs_info->generation; | 930 | root->defrag_trans_start = fs_info->generation; |
929 | init_completion(&root->kobj_unregister); | 931 | init_completion(&root->kobj_unregister); |
930 | root->defrag_running = 0; | 932 | root->defrag_running = 0; |
931 | root->defrag_level = 0; | ||
932 | root->root_key.objectid = objectid; | 933 | root->root_key.objectid = objectid; |
933 | root->anon_super.s_root = NULL; | 934 | root->anon_super.s_root = NULL; |
934 | root->anon_super.s_dev = 0; | 935 | root->anon_super.s_dev = 0; |
@@ -980,12 +981,12 @@ int btrfs_free_log_root_tree(struct btrfs_trans_handle *trans, | |||
980 | 981 | ||
981 | while (1) { | 982 | while (1) { |
982 | ret = find_first_extent_bit(&log_root_tree->dirty_log_pages, | 983 | ret = find_first_extent_bit(&log_root_tree->dirty_log_pages, |
983 | 0, &start, &end, EXTENT_DIRTY); | 984 | 0, &start, &end, EXTENT_DIRTY | EXTENT_NEW); |
984 | if (ret) | 985 | if (ret) |
985 | break; | 986 | break; |
986 | 987 | ||
987 | clear_extent_dirty(&log_root_tree->dirty_log_pages, | 988 | clear_extent_bits(&log_root_tree->dirty_log_pages, start, end, |
988 | start, end, GFP_NOFS); | 989 | EXTENT_DIRTY | EXTENT_NEW, GFP_NOFS); |
989 | } | 990 | } |
990 | eb = fs_info->log_root_tree->node; | 991 | eb = fs_info->log_root_tree->node; |
991 | 992 | ||
@@ -1210,8 +1211,10 @@ again: | |||
1210 | ret = radix_tree_insert(&fs_info->fs_roots_radix, | 1211 | ret = radix_tree_insert(&fs_info->fs_roots_radix, |
1211 | (unsigned long)root->root_key.objectid, | 1212 | (unsigned long)root->root_key.objectid, |
1212 | root); | 1213 | root); |
1213 | if (ret == 0) | 1214 | if (ret == 0) { |
1214 | root->in_radix = 1; | 1215 | root->in_radix = 1; |
1216 | root->clean_orphans = 1; | ||
1217 | } | ||
1215 | spin_unlock(&fs_info->fs_roots_radix_lock); | 1218 | spin_unlock(&fs_info->fs_roots_radix_lock); |
1216 | radix_tree_preload_end(); | 1219 | radix_tree_preload_end(); |
1217 | if (ret) { | 1220 | if (ret) { |
@@ -1225,10 +1228,6 @@ again: | |||
1225 | ret = btrfs_find_dead_roots(fs_info->tree_root, | 1228 | ret = btrfs_find_dead_roots(fs_info->tree_root, |
1226 | root->root_key.objectid); | 1229 | root->root_key.objectid); |
1227 | WARN_ON(ret); | 1230 | WARN_ON(ret); |
1228 | |||
1229 | if (!(fs_info->sb->s_flags & MS_RDONLY)) | ||
1230 | btrfs_orphan_cleanup(root); | ||
1231 | |||
1232 | return root; | 1231 | return root; |
1233 | fail: | 1232 | fail: |
1234 | free_fs_root(root); | 1233 | free_fs_root(root); |
@@ -1477,6 +1476,7 @@ static int cleaner_kthread(void *arg) | |||
1477 | 1476 | ||
1478 | if (!(root->fs_info->sb->s_flags & MS_RDONLY) && | 1477 | if (!(root->fs_info->sb->s_flags & MS_RDONLY) && |
1479 | mutex_trylock(&root->fs_info->cleaner_mutex)) { | 1478 | mutex_trylock(&root->fs_info->cleaner_mutex)) { |
1479 | btrfs_run_delayed_iputs(root); | ||
1480 | btrfs_clean_old_snapshots(root); | 1480 | btrfs_clean_old_snapshots(root); |
1481 | mutex_unlock(&root->fs_info->cleaner_mutex); | 1481 | mutex_unlock(&root->fs_info->cleaner_mutex); |
1482 | } | 1482 | } |
@@ -1606,6 +1606,7 @@ struct btrfs_root *open_ctree(struct super_block *sb, | |||
1606 | INIT_RADIX_TREE(&fs_info->fs_roots_radix, GFP_ATOMIC); | 1606 | INIT_RADIX_TREE(&fs_info->fs_roots_radix, GFP_ATOMIC); |
1607 | INIT_LIST_HEAD(&fs_info->trans_list); | 1607 | INIT_LIST_HEAD(&fs_info->trans_list); |
1608 | INIT_LIST_HEAD(&fs_info->dead_roots); | 1608 | INIT_LIST_HEAD(&fs_info->dead_roots); |
1609 | INIT_LIST_HEAD(&fs_info->delayed_iputs); | ||
1609 | INIT_LIST_HEAD(&fs_info->hashers); | 1610 | INIT_LIST_HEAD(&fs_info->hashers); |
1610 | INIT_LIST_HEAD(&fs_info->delalloc_inodes); | 1611 | INIT_LIST_HEAD(&fs_info->delalloc_inodes); |
1611 | INIT_LIST_HEAD(&fs_info->ordered_operations); | 1612 | INIT_LIST_HEAD(&fs_info->ordered_operations); |
@@ -1614,6 +1615,7 @@ struct btrfs_root *open_ctree(struct super_block *sb, | |||
1614 | spin_lock_init(&fs_info->new_trans_lock); | 1615 | spin_lock_init(&fs_info->new_trans_lock); |
1615 | spin_lock_init(&fs_info->ref_cache_lock); | 1616 | spin_lock_init(&fs_info->ref_cache_lock); |
1616 | spin_lock_init(&fs_info->fs_roots_radix_lock); | 1617 | spin_lock_init(&fs_info->fs_roots_radix_lock); |
1618 | spin_lock_init(&fs_info->delayed_iput_lock); | ||
1617 | 1619 | ||
1618 | init_completion(&fs_info->kobj_unregister); | 1620 | init_completion(&fs_info->kobj_unregister); |
1619 | fs_info->tree_root = tree_root; | 1621 | fs_info->tree_root = tree_root; |
@@ -1689,6 +1691,7 @@ struct btrfs_root *open_ctree(struct super_block *sb, | |||
1689 | mutex_init(&fs_info->cleaner_mutex); | 1691 | mutex_init(&fs_info->cleaner_mutex); |
1690 | mutex_init(&fs_info->volume_mutex); | 1692 | mutex_init(&fs_info->volume_mutex); |
1691 | init_rwsem(&fs_info->extent_commit_sem); | 1693 | init_rwsem(&fs_info->extent_commit_sem); |
1694 | init_rwsem(&fs_info->cleanup_work_sem); | ||
1692 | init_rwsem(&fs_info->subvol_sem); | 1695 | init_rwsem(&fs_info->subvol_sem); |
1693 | 1696 | ||
1694 | btrfs_init_free_cluster(&fs_info->meta_alloc_cluster); | 1697 | btrfs_init_free_cluster(&fs_info->meta_alloc_cluster); |
@@ -2386,8 +2389,14 @@ int btrfs_commit_super(struct btrfs_root *root) | |||
2386 | int ret; | 2389 | int ret; |
2387 | 2390 | ||
2388 | mutex_lock(&root->fs_info->cleaner_mutex); | 2391 | mutex_lock(&root->fs_info->cleaner_mutex); |
2392 | btrfs_run_delayed_iputs(root); | ||
2389 | btrfs_clean_old_snapshots(root); | 2393 | btrfs_clean_old_snapshots(root); |
2390 | mutex_unlock(&root->fs_info->cleaner_mutex); | 2394 | mutex_unlock(&root->fs_info->cleaner_mutex); |
2395 | |||
2396 | /* wait until ongoing cleanup work done */ | ||
2397 | down_write(&root->fs_info->cleanup_work_sem); | ||
2398 | up_write(&root->fs_info->cleanup_work_sem); | ||
2399 | |||
2391 | trans = btrfs_start_transaction(root, 1); | 2400 | trans = btrfs_start_transaction(root, 1); |
2392 | ret = btrfs_commit_transaction(trans, root); | 2401 | ret = btrfs_commit_transaction(trans, root); |
2393 | BUG_ON(ret); | 2402 | BUG_ON(ret); |