aboutsummaryrefslogtreecommitdiffstats
path: root/fs
diff options
context:
space:
mode:
Diffstat (limited to 'fs')
-rw-r--r--fs/btrfs/ctree.c5
-rw-r--r--fs/btrfs/ctree.h13
-rw-r--r--fs/btrfs/disk-io.c116
-rw-r--r--fs/btrfs/extent-tree.c10
-rw-r--r--fs/btrfs/super.c16
-rw-r--r--fs/btrfs/transaction.c72
-rw-r--r--fs/btrfs/transaction.h10
-rw-r--r--fs/btrfs/volumes.c12
8 files changed, 136 insertions, 118 deletions
diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
index 5edbcc09b3cc..40f0e0cb804b 100644
--- a/fs/btrfs/ctree.c
+++ b/fs/btrfs/ctree.c
@@ -1352,6 +1352,8 @@ again:
1352 free_extent_buffer(tmp); 1352 free_extent_buffer(tmp);
1353 goto again; 1353 goto again;
1354 } else { 1354 } else {
1355 if (tmp)
1356 free_extent_buffer(tmp);
1355 b = read_node_slot(root, b, slot); 1357 b = read_node_slot(root, b, slot);
1356 } 1358 }
1357 } 1359 }
@@ -3048,7 +3050,8 @@ int btrfs_next_leaf(struct btrfs_root *root, struct btrfs_path *path)
3048 free_extent_buffer(c); 3050 free_extent_buffer(c);
3049 path->nodes[level] = next; 3051 path->nodes[level] = next;
3050 path->slots[level] = 0; 3052 path->slots[level] = 0;
3051 path->locks[level] = 1; 3053 if (!path->skip_locking)
3054 path->locks[level] = 1;
3052 if (!level) 3055 if (!level)
3053 break; 3056 break;
3054 if (level == 1 && path->locks[1] && path->reada) 3057 if (level == 1 && path->locks[1] && path->reada)
diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
index e9bbb53eda63..244fe86bcc55 100644
--- a/fs/btrfs/ctree.h
+++ b/fs/btrfs/ctree.h
@@ -23,7 +23,6 @@
23#include <linux/mm.h> 23#include <linux/mm.h>
24#include <linux/highmem.h> 24#include <linux/highmem.h>
25#include <linux/fs.h> 25#include <linux/fs.h>
26#include <linux/workqueue.h>
27#include <linux/completion.h> 26#include <linux/completion.h>
28#include <linux/backing-dev.h> 27#include <linux/backing-dev.h>
29#include <asm/kmap_types.h> 28#include <asm/kmap_types.h>
@@ -519,15 +518,14 @@ struct btrfs_fs_info {
519 struct backing_dev_info bdi; 518 struct backing_dev_info bdi;
520 spinlock_t hash_lock; 519 spinlock_t hash_lock;
521 struct mutex trans_mutex; 520 struct mutex trans_mutex;
521 struct mutex transaction_kthread_mutex;
522 struct mutex cleaner_mutex;
522 struct mutex alloc_mutex; 523 struct mutex alloc_mutex;
523 struct mutex chunk_mutex; 524 struct mutex chunk_mutex;
524 struct mutex drop_mutex; 525 struct mutex drop_mutex;
525 struct list_head trans_list; 526 struct list_head trans_list;
526 struct list_head hashers; 527 struct list_head hashers;
527 struct list_head dead_roots; 528 struct list_head dead_roots;
528 struct list_head end_io_work_list;
529 struct work_struct end_io_work;
530 spinlock_t end_io_work_lock;
531 atomic_t nr_async_submits; 529 atomic_t nr_async_submits;
532 530
533 /* 531 /*
@@ -543,13 +541,10 @@ struct btrfs_fs_info {
543 struct btrfs_workers workers; 541 struct btrfs_workers workers;
544 struct btrfs_workers endio_workers; 542 struct btrfs_workers endio_workers;
545 struct btrfs_workers submit_workers; 543 struct btrfs_workers submit_workers;
544 struct task_struct *transaction_kthread;
545 struct task_struct *cleaner_kthread;
546 int thread_pool_size; 546 int thread_pool_size;
547 547
548#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,18)
549 struct work_struct trans_work;
550#else
551 struct delayed_work trans_work;
552#endif
553 struct kobject super_kobj; 548 struct kobject super_kobj;
554 struct completion kobj_unregister; 549 struct completion kobj_unregister;
555 int do_barriers; 550 int do_barriers;
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index 52569b57692d..31ca9f89388d 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -16,6 +16,7 @@
16 * Boston, MA 021110-1307, USA. 16 * Boston, MA 021110-1307, USA.
17 */ 17 */
18 18
19#include <linux/version.h>
19#include <linux/fs.h> 20#include <linux/fs.h>
20#include <linux/blkdev.h> 21#include <linux/blkdev.h>
21#include <linux/scatterlist.h> 22#include <linux/scatterlist.h>
@@ -24,6 +25,12 @@
24#include <linux/writeback.h> 25#include <linux/writeback.h>
25#include <linux/buffer_head.h> // for block_sync_page 26#include <linux/buffer_head.h> // for block_sync_page
26#include <linux/workqueue.h> 27#include <linux/workqueue.h>
28#include <linux/kthread.h>
29#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
30# include <linux/freezer.h>
31#else
32# include <linux/sched.h>
33#endif
27#include "crc32c.h" 34#include "crc32c.h"
28#include "ctree.h" 35#include "ctree.h"
29#include "disk-io.h" 36#include "disk-io.h"
@@ -1100,6 +1107,87 @@ static void end_workqueue_fn(struct btrfs_work *work)
1100#endif 1107#endif
1101} 1108}
1102 1109
1110static int cleaner_kthread(void *arg)
1111{
1112 struct btrfs_root *root = arg;
1113
1114 do {
1115 smp_mb();
1116 if (root->fs_info->closing)
1117 break;
1118
1119 vfs_check_frozen(root->fs_info->sb, SB_FREEZE_WRITE);
1120 mutex_lock(&root->fs_info->cleaner_mutex);
1121printk("cleaner awake\n");
1122 btrfs_clean_old_snapshots(root);
1123printk("cleaner done\n");
1124 mutex_unlock(&root->fs_info->cleaner_mutex);
1125
1126 if (freezing(current)) {
1127 refrigerator();
1128 } else {
1129 smp_mb();
1130 if (root->fs_info->closing)
1131 break;
1132 set_current_state(TASK_INTERRUPTIBLE);
1133 schedule();
1134 __set_current_state(TASK_RUNNING);
1135 }
1136 } while (!kthread_should_stop());
1137 return 0;
1138}
1139
1140static int transaction_kthread(void *arg)
1141{
1142 struct btrfs_root *root = arg;
1143 struct btrfs_trans_handle *trans;
1144 struct btrfs_transaction *cur;
1145 unsigned long now;
1146 unsigned long delay;
1147 int ret;
1148
1149 do {
1150 smp_mb();
1151 if (root->fs_info->closing)
1152 break;
1153
1154 delay = HZ * 30;
1155 vfs_check_frozen(root->fs_info->sb, SB_FREEZE_WRITE);
1156 mutex_lock(&root->fs_info->transaction_kthread_mutex);
1157
1158 mutex_lock(&root->fs_info->trans_mutex);
1159 cur = root->fs_info->running_transaction;
1160 if (!cur) {
1161 mutex_unlock(&root->fs_info->trans_mutex);
1162 goto sleep;
1163 }
1164 now = get_seconds();
1165 if (now < cur->start_time || now - cur->start_time < 30) {
1166 mutex_unlock(&root->fs_info->trans_mutex);
1167 delay = HZ * 5;
1168 goto sleep;
1169 }
1170 mutex_unlock(&root->fs_info->trans_mutex);
1171 btrfs_defrag_dirty_roots(root->fs_info);
1172 trans = btrfs_start_transaction(root, 1);
1173 ret = btrfs_commit_transaction(trans, root);
1174sleep:
1175 wake_up_process(root->fs_info->cleaner_kthread);
1176 mutex_unlock(&root->fs_info->transaction_kthread_mutex);
1177
1178 if (freezing(current)) {
1179 refrigerator();
1180 } else {
1181 if (root->fs_info->closing)
1182 break;
1183 set_current_state(TASK_INTERRUPTIBLE);
1184 schedule_timeout(delay);
1185 __set_current_state(TASK_RUNNING);
1186 }
1187 } while (!kthread_should_stop());
1188 return 0;
1189}
1190
1103struct btrfs_root *open_ctree(struct super_block *sb, 1191struct btrfs_root *open_ctree(struct super_block *sb,
1104 struct btrfs_fs_devices *fs_devices, 1192 struct btrfs_fs_devices *fs_devices,
1105 char *options) 1193 char *options)
@@ -1189,11 +1277,6 @@ struct btrfs_root *open_ctree(struct super_block *sb,
1189 fs_info->btree_inode->i_mapping, GFP_NOFS); 1277 fs_info->btree_inode->i_mapping, GFP_NOFS);
1190 fs_info->do_barriers = 1; 1278 fs_info->do_barriers = 1;
1191 1279
1192#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,18)
1193 INIT_WORK(&fs_info->trans_work, btrfs_transaction_cleaner, fs_info);
1194#else
1195 INIT_DELAYED_WORK(&fs_info->trans_work, btrfs_transaction_cleaner);
1196#endif
1197 BTRFS_I(fs_info->btree_inode)->root = tree_root; 1280 BTRFS_I(fs_info->btree_inode)->root = tree_root;
1198 memset(&BTRFS_I(fs_info->btree_inode)->location, 0, 1281 memset(&BTRFS_I(fs_info->btree_inode)->location, 0,
1199 sizeof(struct btrfs_key)); 1282 sizeof(struct btrfs_key));
@@ -1204,6 +1287,8 @@ struct btrfs_root *open_ctree(struct super_block *sb,
1204 mutex_init(&fs_info->drop_mutex); 1287 mutex_init(&fs_info->drop_mutex);
1205 mutex_init(&fs_info->alloc_mutex); 1288 mutex_init(&fs_info->alloc_mutex);
1206 mutex_init(&fs_info->chunk_mutex); 1289 mutex_init(&fs_info->chunk_mutex);
1290 mutex_init(&fs_info->transaction_kthread_mutex);
1291 mutex_init(&fs_info->cleaner_mutex);
1207 1292
1208#if 0 1293#if 0
1209 ret = add_hasher(fs_info, "crc32c"); 1294 ret = add_hasher(fs_info, "crc32c");
@@ -1247,7 +1332,6 @@ struct btrfs_root *open_ctree(struct super_block *sb,
1247 btrfs_start_workers(&fs_info->submit_workers, 1); 1332 btrfs_start_workers(&fs_info->submit_workers, 1);
1248 btrfs_start_workers(&fs_info->endio_workers, fs_info->thread_pool_size); 1333 btrfs_start_workers(&fs_info->endio_workers, fs_info->thread_pool_size);
1249 1334
1250
1251 err = -EINVAL; 1335 err = -EINVAL;
1252 if (btrfs_super_num_devices(disk_super) > fs_devices->open_devices) { 1336 if (btrfs_super_num_devices(disk_super) > fs_devices->open_devices) {
1253 printk("Btrfs: wanted %llu devices, but found %llu\n", 1337 printk("Btrfs: wanted %llu devices, but found %llu\n",
@@ -1341,9 +1425,22 @@ struct btrfs_root *open_ctree(struct super_block *sb,
1341 fs_info->data_alloc_profile = (u64)-1; 1425 fs_info->data_alloc_profile = (u64)-1;
1342 fs_info->metadata_alloc_profile = (u64)-1; 1426 fs_info->metadata_alloc_profile = (u64)-1;
1343 fs_info->system_alloc_profile = fs_info->metadata_alloc_profile; 1427 fs_info->system_alloc_profile = fs_info->metadata_alloc_profile;
1428 fs_info->cleaner_kthread = kthread_run(cleaner_kthread, tree_root,
1429 "btrfs-cleaner");
1430 if (!fs_info->cleaner_kthread)
1431 goto fail_extent_root;
1432
1433 fs_info->transaction_kthread = kthread_run(transaction_kthread,
1434 tree_root,
1435 "btrfs-transaction");
1436 if (!fs_info->transaction_kthread)
1437 goto fail_trans_kthread;
1438
1344 1439
1345 return tree_root; 1440 return tree_root;
1346 1441
1442fail_trans_kthread:
1443 kthread_stop(fs_info->cleaner_kthread);
1347fail_extent_root: 1444fail_extent_root:
1348 free_extent_buffer(extent_root->node); 1445 free_extent_buffer(extent_root->node);
1349fail_tree_root: 1446fail_tree_root:
@@ -1562,8 +1659,11 @@ int close_ctree(struct btrfs_root *root)
1562 fs_info->closing = 1; 1659 fs_info->closing = 1;
1563 smp_mb(); 1660 smp_mb();
1564 1661
1565 btrfs_transaction_flush_work(root); 1662 kthread_stop(root->fs_info->transaction_kthread);
1663 kthread_stop(root->fs_info->cleaner_kthread);
1664
1566 btrfs_defrag_dirty_roots(root->fs_info); 1665 btrfs_defrag_dirty_roots(root->fs_info);
1666 btrfs_clean_old_snapshots(root);
1567 trans = btrfs_start_transaction(root, 1); 1667 trans = btrfs_start_transaction(root, 1);
1568 ret = btrfs_commit_transaction(trans, root); 1668 ret = btrfs_commit_transaction(trans, root);
1569 /* run commit again to drop the original snapshot */ 1669 /* run commit again to drop the original snapshot */
@@ -1574,8 +1674,6 @@ int close_ctree(struct btrfs_root *root)
1574 1674
1575 write_ctree_super(NULL, root); 1675 write_ctree_super(NULL, root);
1576 1676
1577 btrfs_transaction_flush_work(root);
1578
1579 if (fs_info->delalloc_bytes) { 1677 if (fs_info->delalloc_bytes) {
1580 printk("btrfs: at unmount delalloc count %Lu\n", 1678 printk("btrfs: at unmount delalloc count %Lu\n",
1581 fs_info->delalloc_bytes); 1679 fs_info->delalloc_bytes);
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index 6274f30031db..89cc4f611869 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -1216,15 +1216,16 @@ static int do_chunk_alloc(struct btrfs_trans_handle *trans,
1216 if (ret == -ENOSPC) { 1216 if (ret == -ENOSPC) {
1217printk("space info full %Lu\n", flags); 1217printk("space info full %Lu\n", flags);
1218 space_info->full = 1; 1218 space_info->full = 1;
1219 goto out; 1219 goto out_unlock;
1220 } 1220 }
1221 BUG_ON(ret); 1221 BUG_ON(ret);
1222 1222
1223 ret = btrfs_make_block_group(trans, extent_root, 0, flags, 1223 ret = btrfs_make_block_group(trans, extent_root, 0, flags,
1224 BTRFS_FIRST_CHUNK_TREE_OBJECTID, start, num_bytes); 1224 BTRFS_FIRST_CHUNK_TREE_OBJECTID, start, num_bytes);
1225 BUG_ON(ret); 1225 BUG_ON(ret);
1226out: 1226out_unlock:
1227 mutex_unlock(&extent_root->fs_info->chunk_mutex); 1227 mutex_unlock(&extent_root->fs_info->chunk_mutex);
1228out:
1228 return 0; 1229 return 0;
1229} 1230}
1230 1231
@@ -2274,7 +2275,8 @@ static int noinline walk_down_tree(struct btrfs_trans_handle *trans,
2274 free_extent_buffer(next); 2275 free_extent_buffer(next);
2275 mutex_unlock(&root->fs_info->alloc_mutex); 2276 mutex_unlock(&root->fs_info->alloc_mutex);
2276 2277
2277 reada_walk_down(root, cur, path->slots[*level]); 2278 if (path->slots[*level] == 0)
2279 reada_walk_down(root, cur, path->slots[*level]);
2278 2280
2279 next = read_tree_block(root, bytenr, blocksize, 2281 next = read_tree_block(root, bytenr, blocksize,
2280 ptr_gen); 2282 ptr_gen);
@@ -2446,8 +2448,6 @@ int btrfs_drop_snapshot(struct btrfs_trans_handle *trans, struct btrfs_root
2446 break; 2448 break;
2447 if (wret < 0) 2449 if (wret < 0)
2448 ret = wret; 2450 ret = wret;
2449 ret = -EAGAIN;
2450 break;
2451 } 2451 }
2452 for (i = 0; i <= orig_level; i++) { 2452 for (i = 0; i <= orig_level; i++) {
2453 if (path->nodes[i]) { 2453 if (path->nodes[i]) {
diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
index b61ded7a20c9..726d6871fa13 100644
--- a/fs/btrfs/super.c
+++ b/fs/btrfs/super.c
@@ -340,7 +340,6 @@ static int btrfs_fill_super(struct super_block * sb,
340 goto fail_close; 340 goto fail_close;
341 341
342 sb->s_root = root_dentry; 342 sb->s_root = root_dentry;
343 btrfs_transaction_queue_work(tree_root, HZ * 30);
344 343
345#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,25) 344#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,25)
346 save_mount_options(sb, data); 345 save_mount_options(sb, data);
@@ -416,9 +415,7 @@ static int btrfs_get_sb(struct file_system_type *fs_type, int flags,
416 goto error_free_subvol_name; 415 goto error_free_subvol_name;
417 416
418 bdev = fs_devices->latest_bdev; 417 bdev = fs_devices->latest_bdev;
419 btrfs_lock_volumes();
420 s = sget(fs_type, btrfs_test_super, set_anon_super, fs_devices); 418 s = sget(fs_type, btrfs_test_super, set_anon_super, fs_devices);
421 btrfs_unlock_volumes();
422 if (IS_ERR(s)) 419 if (IS_ERR(s))
423 goto error_s; 420 goto error_s;
424 421
@@ -530,13 +527,15 @@ out:
530static void btrfs_write_super_lockfs(struct super_block *sb) 527static void btrfs_write_super_lockfs(struct super_block *sb)
531{ 528{
532 struct btrfs_root *root = btrfs_sb(sb); 529 struct btrfs_root *root = btrfs_sb(sb);
533 btrfs_transaction_flush_work(root); 530 mutex_lock(&root->fs_info->transaction_kthread_mutex);
531 mutex_lock(&root->fs_info->cleaner_mutex);
534} 532}
535 533
536static void btrfs_unlockfs(struct super_block *sb) 534static void btrfs_unlockfs(struct super_block *sb)
537{ 535{
538 struct btrfs_root *root = btrfs_sb(sb); 536 struct btrfs_root *root = btrfs_sb(sb);
539 btrfs_transaction_queue_work(root, HZ * 30); 537 mutex_unlock(&root->fs_info->cleaner_mutex);
538 mutex_unlock(&root->fs_info->transaction_kthread_mutex);
540} 539}
541 540
542static struct super_operations btrfs_super_ops = { 541static struct super_operations btrfs_super_ops = {
@@ -589,10 +588,9 @@ static int __init init_btrfs_fs(void)
589 if (err) 588 if (err)
590 return err; 589 return err;
591 590
592 btrfs_init_transaction_sys();
593 err = btrfs_init_cachep(); 591 err = btrfs_init_cachep();
594 if (err) 592 if (err)
595 goto free_transaction_sys; 593 goto free_sysfs;
596 594
597 err = extent_io_init(); 595 err = extent_io_init();
598 if (err) 596 if (err)
@@ -618,15 +616,13 @@ free_extent_io:
618 extent_io_exit(); 616 extent_io_exit();
619free_cachep: 617free_cachep:
620 btrfs_destroy_cachep(); 618 btrfs_destroy_cachep();
621free_transaction_sys: 619free_sysfs:
622 btrfs_exit_transaction_sys();
623 btrfs_exit_sysfs(); 620 btrfs_exit_sysfs();
624 return err; 621 return err;
625} 622}
626 623
627static void __exit exit_btrfs_fs(void) 624static void __exit exit_btrfs_fs(void)
628{ 625{
629 btrfs_exit_transaction_sys();
630 btrfs_destroy_cachep(); 626 btrfs_destroy_cachep();
631 extent_map_exit(); 627 extent_map_exit();
632 extent_io_exit(); 628 extent_io_exit();
diff --git a/fs/btrfs/transaction.c b/fs/btrfs/transaction.c
index 69ed5f85a387..0c53ff775b92 100644
--- a/fs/btrfs/transaction.c
+++ b/fs/btrfs/transaction.c
@@ -29,8 +29,6 @@ static int total_trans = 0;
29extern struct kmem_cache *btrfs_trans_handle_cachep; 29extern struct kmem_cache *btrfs_trans_handle_cachep;
30extern struct kmem_cache *btrfs_transaction_cachep; 30extern struct kmem_cache *btrfs_transaction_cachep;
31 31
32static struct workqueue_struct *trans_wq;
33
34#define BTRFS_ROOT_TRANS_TAG 0 32#define BTRFS_ROOT_TRANS_TAG 0
35#define BTRFS_ROOT_DEFRAG_TAG 1 33#define BTRFS_ROOT_DEFRAG_TAG 1
36 34
@@ -807,81 +805,15 @@ int btrfs_clean_old_snapshots(struct btrfs_root *root)
807{ 805{
808 struct list_head dirty_roots; 806 struct list_head dirty_roots;
809 INIT_LIST_HEAD(&dirty_roots); 807 INIT_LIST_HEAD(&dirty_roots);
810 808again:
811 mutex_lock(&root->fs_info->trans_mutex); 809 mutex_lock(&root->fs_info->trans_mutex);
812 list_splice_init(&root->fs_info->dead_roots, &dirty_roots); 810 list_splice_init(&root->fs_info->dead_roots, &dirty_roots);
813 mutex_unlock(&root->fs_info->trans_mutex); 811 mutex_unlock(&root->fs_info->trans_mutex);
814 812
815 if (!list_empty(&dirty_roots)) { 813 if (!list_empty(&dirty_roots)) {
816 drop_dirty_roots(root, &dirty_roots); 814 drop_dirty_roots(root, &dirty_roots);
815 goto again;
817 } 816 }
818 return 0; 817 return 0;
819} 818}
820#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,18)
821void btrfs_transaction_cleaner(void *p)
822#else
823void btrfs_transaction_cleaner(struct work_struct *work)
824#endif
825{
826#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,18)
827 struct btrfs_fs_info *fs_info = p;
828#else
829 struct btrfs_fs_info *fs_info = container_of(work,
830 struct btrfs_fs_info,
831 trans_work.work);
832
833#endif
834 struct btrfs_root *root = fs_info->tree_root;
835 struct btrfs_transaction *cur;
836 struct btrfs_trans_handle *trans;
837 unsigned long now;
838 unsigned long delay = HZ * 30;
839 int ret;
840
841 smp_mb();
842 if (root->fs_info->closing)
843 goto out;
844
845 mutex_lock(&root->fs_info->trans_mutex);
846 cur = root->fs_info->running_transaction;
847 if (!cur) {
848 mutex_unlock(&root->fs_info->trans_mutex);
849 goto out;
850 }
851 now = get_seconds();
852 if (now < cur->start_time || now - cur->start_time < 30) {
853 mutex_unlock(&root->fs_info->trans_mutex);
854 delay = HZ * 5;
855 goto out;
856 }
857 mutex_unlock(&root->fs_info->trans_mutex);
858 btrfs_defrag_dirty_roots(root->fs_info);
859 trans = btrfs_start_transaction(root, 1);
860 ret = btrfs_commit_transaction(trans, root);
861out:
862 btrfs_clean_old_snapshots(root);
863 btrfs_transaction_queue_work(root, delay);
864}
865
866void btrfs_transaction_queue_work(struct btrfs_root *root, int delay)
867{
868 if (!root->fs_info->closing)
869 queue_delayed_work(trans_wq, &root->fs_info->trans_work, delay);
870}
871
872void btrfs_transaction_flush_work(struct btrfs_root *root)
873{
874 cancel_delayed_work(&root->fs_info->trans_work);
875 flush_workqueue(trans_wq);
876}
877
878void __init btrfs_init_transaction_sys(void)
879{
880 trans_wq = create_workqueue("btrfs-transaction");
881}
882
883void btrfs_exit_transaction_sys(void)
884{
885 destroy_workqueue(trans_wq);
886}
887 819
diff --git a/fs/btrfs/transaction.h b/fs/btrfs/transaction.h
index 52559b51b181..e1e5a06b65f4 100644
--- a/fs/btrfs/transaction.h
+++ b/fs/btrfs/transaction.h
@@ -82,16 +82,6 @@ int btrfs_write_and_wait_transaction(struct btrfs_trans_handle *trans,
82int btrfs_commit_tree_roots(struct btrfs_trans_handle *trans, 82int btrfs_commit_tree_roots(struct btrfs_trans_handle *trans,
83 struct btrfs_root *root); 83 struct btrfs_root *root);
84 84
85#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,18)
86void btrfs_transaction_cleaner(void *p);
87#else
88void btrfs_transaction_cleaner(struct work_struct *work);
89#endif
90
91void btrfs_transaction_flush_work(struct btrfs_root *root);
92void btrfs_transaction_queue_work(struct btrfs_root *root, int delay);
93void btrfs_init_transaction_sys(void);
94void btrfs_exit_transaction_sys(void);
95int btrfs_add_dead_root(struct btrfs_root *root, struct btrfs_root *latest, 85int btrfs_add_dead_root(struct btrfs_root *root, struct btrfs_root *latest,
96 struct list_head *dead_list); 86 struct list_head *dead_list);
97int btrfs_defrag_dirty_roots(struct btrfs_fs_info *info); 87int btrfs_defrag_dirty_roots(struct btrfs_fs_info *info);
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index 869864ddcc29..4e7cee27aab5 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -271,13 +271,17 @@ again:
271 list_for_each(cur, head) { 271 list_for_each(cur, head) {
272 device = list_entry(cur, struct btrfs_device, dev_list); 272 device = list_entry(cur, struct btrfs_device, dev_list);
273 if (!device->in_fs_metadata) { 273 if (!device->in_fs_metadata) {
274 if (device->bdev) { 274 struct block_device *bdev;
275 close_bdev_excl(device->bdev);
276 fs_devices->open_devices--;
277 }
278 list_del(&device->dev_list); 275 list_del(&device->dev_list);
279 list_del(&device->dev_alloc_list); 276 list_del(&device->dev_alloc_list);
280 fs_devices->num_devices--; 277 fs_devices->num_devices--;
278 if (device->bdev) {
279 bdev = device->bdev;
280 fs_devices->open_devices--;
281 mutex_unlock(&uuid_mutex);
282 close_bdev_excl(bdev);
283 mutex_lock(&uuid_mutex);
284 }
281 kfree(device->name); 285 kfree(device->name);
282 kfree(device); 286 kfree(device);
283 goto again; 287 goto again;