diff options
author | Chris Mason <chris.mason@oracle.com> | 2008-06-25 16:01:31 -0400 |
---|---|---|
committer | Chris Mason <chris.mason@oracle.com> | 2008-09-25 11:04:03 -0400 |
commit | a74a4b97b61beede185b4b3ad359d7d378b0d312 (patch) | |
tree | 49ce5e7698f08e84d0ad2f65768e9f34b64d79c5 /fs/btrfs/transaction.c | |
parent | 89ce8a63d0c761fbb02089850605360f389477d8 (diff) |
Btrfs: Replace the transaction work queue with kthreads
This creates one kthread for commits and one kthread for
deleting old snapshots. All the work queues are removed.
Signed-off-by: Chris Mason <chris.mason@oracle.com>
Diffstat (limited to 'fs/btrfs/transaction.c')
-rw-r--r-- | fs/btrfs/transaction.c | 72 |
1 files changed, 2 insertions, 70 deletions
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; | |||
29 | extern struct kmem_cache *btrfs_trans_handle_cachep; | 29 | extern struct kmem_cache *btrfs_trans_handle_cachep; |
30 | extern struct kmem_cache *btrfs_transaction_cachep; | 30 | extern struct kmem_cache *btrfs_transaction_cachep; |
31 | 31 | ||
32 | static 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 | 808 | again: | |
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) | ||
821 | void btrfs_transaction_cleaner(void *p) | ||
822 | #else | ||
823 | void 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); | ||
861 | out: | ||
862 | btrfs_clean_old_snapshots(root); | ||
863 | btrfs_transaction_queue_work(root, delay); | ||
864 | } | ||
865 | |||
866 | void 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 | |||
872 | void 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 | |||
878 | void __init btrfs_init_transaction_sys(void) | ||
879 | { | ||
880 | trans_wq = create_workqueue("btrfs-transaction"); | ||
881 | } | ||
882 | |||
883 | void btrfs_exit_transaction_sys(void) | ||
884 | { | ||
885 | destroy_workqueue(trans_wq); | ||
886 | } | ||
887 | 819 | ||