Btrfs: various abort cleanups
authorJosef Bacik <jbacik@fusionio.com>
Thu, 25 Apr 2013 17:44:38 +0000 (13:44 -0400)
committerJosef Bacik <jbacik@fusionio.com>
Mon, 6 May 2013 19:55:11 +0000 (15:55 -0400)
I have a broken file system that when it aborts leaves all sorts of accounting
things wrong and gives you lots of WARN_ON()'s other than the abort.  This is
because we're not cleaning up various parts of the file system when we abort.
The first chunks are specific to mount failures, we weren't cleaning up the
block group cached inodes and we weren't cleaning up any transactions that had
been aborted, which leaves a bunch of things laying around.

The second half of this are related to the cleanup parts.  First we don't need
to release space for the dirty pages from the trans_block_rsv, that's all
handled by the trans handles so this is just plain wrong.  The other thing is we
need to pin down extents that were set ->must_insert_reserved for delayed refs.
This isn't so much for the pinning but more for the cleaning up the
cache->reserved counter since we are no longer going to use those reserved
bytes.  With this patch I no longer see a bunch of WARN_ON()'s when I try to
mount this broken file system, just the initial one from the abort.  Thanks,

Signed-off-by: Josef Bacik <jbacik@fusionio.com>
fs/btrfs/disk-io.c

index aff571cb6e04270f54a998acb8908b6eecef91f7..84c4fa503ef59009edf43e8e4f0bf5eaee328604 100644 (file)
@@ -2826,6 +2826,7 @@ fail_qgroup:
 fail_trans_kthread:
        kthread_stop(fs_info->transaction_kthread);
        del_fs_roots(fs_info);
+       btrfs_cleanup_transaction(fs_info->tree_root);
 fail_cleaner:
        kthread_stop(fs_info->cleaner_kthread);
 
@@ -2836,6 +2837,7 @@ fail_cleaner:
        filemap_write_and_wait(fs_info->btree_inode->i_mapping);
 
 fail_block_groups:
+       btrfs_put_block_group_cache(fs_info);
        btrfs_free_block_groups(fs_info);
 
 fail_tree_roots:
@@ -3681,6 +3683,9 @@ int btrfs_destroy_delayed_refs(struct btrfs_transaction *trans,
                                continue;
                        }
 
+                       if (head->must_insert_reserved)
+                               btrfs_pin_extent(root, ref->bytenr,
+                                                ref->num_bytes, 1);
                        btrfs_free_delayed_extent_op(head->extent_op);
                        delayed_refs->num_heads--;
                        if (list_empty(&head->cluster))
@@ -3876,10 +3881,6 @@ int btrfs_cleanup_transaction(struct btrfs_root *root)
 
                btrfs_destroy_delayed_refs(t, root);
 
-               btrfs_block_rsv_release(root,
-                                       &root->fs_info->trans_block_rsv,
-                                       t->dirty_pages.dirty_bytes);
-
                /* FIXME: cleanup wait for commit */
                t->in_commit = 1;
                t->blocked = 1;