Btrfs: Fixes for 2.6.18 enterprise kernels
authorChris Mason <chris.mason@oracle.com>
Wed, 30 Apr 2008 17:59:35 +0000 (13:59 -0400)
committerChris Mason <chris.mason@oracle.com>
Thu, 25 Sep 2008 15:04:02 +0000 (11:04 -0400)
2.6.18 seems to get caught in an infinite loop when
cancel_rearming_delayed_workqueue is called more than once, so this switches
to cancel_delayed_work, which is arguably more correct.

Also, balance_dirty_pages can run into problems with 2.6.18 based kernels
because it doesn't have the per-bdi dirty limits.  This avoids calling
balance_dirty_pages on the btree inode unless there is actually something
to balance, which is a good optimization in general.

Finally there's a compile fix for ordered-data.h

Signed-off-by: Chris Mason <chris.mason@oracle.com>
fs/btrfs/disk-io.c
fs/btrfs/ordered-data.c
fs/btrfs/transaction.c

index e35e70165b5374ea8146c540b5a20b46d05e786f..fabc31b334b66aeda4307b434888c7a117855691 100644 (file)
@@ -1548,6 +1548,7 @@ int close_ctree(struct btrfs_root *root)
        btrfs_commit_transaction(trans, root);
        ret = btrfs_write_and_wait_transaction(NULL, root);
        BUG_ON(ret);
+
        write_ctree_super(NULL, root);
        mutex_unlock(&fs_info->fs_mutex);
 
@@ -1583,17 +1584,17 @@ int close_ctree(struct btrfs_root *root)
        extent_io_tree_empty_lru(&fs_info->extent_ins);
        extent_io_tree_empty_lru(&BTRFS_I(fs_info->btree_inode)->io_tree);
 
-       flush_workqueue(end_io_workqueue);
        flush_workqueue(async_submit_workqueue);
+       flush_workqueue(end_io_workqueue);
 
        truncate_inode_pages(fs_info->btree_inode->i_mapping, 0);
 
-       flush_workqueue(end_io_workqueue);
-       destroy_workqueue(end_io_workqueue);
-
        flush_workqueue(async_submit_workqueue);
        destroy_workqueue(async_submit_workqueue);
 
+       flush_workqueue(end_io_workqueue);
+       destroy_workqueue(end_io_workqueue);
+
        iput(fs_info->btree_inode);
 #if 0
        while(!list_empty(&fs_info->hashers)) {
@@ -1663,8 +1664,21 @@ void btrfs_throttle(struct btrfs_root *root)
 
 void btrfs_btree_balance_dirty(struct btrfs_root *root, unsigned long nr)
 {
-       balance_dirty_pages_ratelimited_nr(
+       struct extent_io_tree *tree;
+       u64 num_dirty;
+       u64 start = 0;
+       unsigned long thresh = 16 * 1024 * 1024;
+       tree = &BTRFS_I(root->fs_info->btree_inode)->io_tree;
+
+       if (current_is_pdflush())
+               return;
+
+       num_dirty = count_range_bits(tree, &start, (u64)-1,
+                                    thresh, EXTENT_DIRTY);
+       if (num_dirty > thresh) {
+               balance_dirty_pages_ratelimited_nr(
                                   root->fs_info->btree_inode->i_mapping, 1);
+       }
 }
 
 void btrfs_set_buffer_defrag(struct extent_buffer *buf)
index b474902c90e23550ffc4a3a51196075694f2a503..3814cb0246b47d7484871bfbb409fbe75c11f985 100644 (file)
@@ -18,6 +18,7 @@
 
 #include <linux/gfp.h>
 #include <linux/slab.h>
+#include <linux/blkdev.h>
 #include "ctree.h"
 #include "transaction.h"
 #include "btrfs_inode.h"
index c85cb48d95ee3dcd2aa1c8dbb1ad46971202563a..9826942fa18afea20a62c15be3bb5e63c6b3686c 100644 (file)
@@ -814,6 +814,9 @@ void btrfs_transaction_cleaner(struct work_struct *work)
        int ret;
 
        mutex_lock(&root->fs_info->fs_mutex);
+       if (root->fs_info->closing)
+               goto out;
+
        mutex_lock(&root->fs_info->trans_mutex);
        cur = root->fs_info->running_transaction;
        if (!cur) {
@@ -838,12 +841,13 @@ out:
 
 void btrfs_transaction_queue_work(struct btrfs_root *root, int delay)
 {
-       queue_delayed_work(trans_wq, &root->fs_info->trans_work, delay);
+       if (!root->fs_info->closing)
+               queue_delayed_work(trans_wq, &root->fs_info->trans_work, delay);
 }
 
 void btrfs_transaction_flush_work(struct btrfs_root *root)
 {
-       cancel_rearming_delayed_workqueue(trans_wq, &root->fs_info->trans_work);
+       cancel_delayed_work(&root->fs_info->trans_work);
        flush_workqueue(trans_wq);
 }