INIT_RADIX_TREE(&fs_info->block_group_radix, GFP_KERNEL);
INIT_RADIX_TREE(&fs_info->block_group_data_radix, GFP_KERNEL);
INIT_LIST_HEAD(&fs_info->trans_list);
+ INIT_LIST_HEAD(&fs_info->dead_roots);
sb_set_blocksize(sb, 4096);
fs_info->running_transaction = NULL;
fs_info->tree_root = tree_root;
fs_info->do_barriers = 1;
fs_info->extent_tree_insert_nr = 0;
fs_info->extent_tree_prealloc_nr = 0;
+ fs_info->closing = 0;
+
INIT_DELAYED_WORK(&fs_info->trans_work, btrfs_transaction_cleaner);
BTRFS_I(fs_info->btree_inode)->root = tree_root;
memset(&BTRFS_I(fs_info->btree_inode)->location, 0,
struct btrfs_trans_handle *trans;
struct btrfs_fs_info *fs_info = root->fs_info;
+ fs_info->closing = 1;
btrfs_transaction_flush_work(root);
mutex_lock(&fs_info->fs_mutex);
trans = btrfs_start_transaction(root, 1);
#define BTRFS_ROOT_TRANS_TAG 0
-#define TRANS_MAGIC 0xE1E10E
static void put_transaction(struct btrfs_transaction *transaction)
{
WARN_ON(transaction->use_count == 0);
transaction->use_count--;
- WARN_ON(transaction->magic != TRANS_MAGIC);
if (transaction->use_count == 0) {
WARN_ON(total_trans == 0);
total_trans--;
cur_trans->transid = root->fs_info->generation;
init_waitqueue_head(&cur_trans->writer_wait);
init_waitqueue_head(&cur_trans->commit_wait);
- cur_trans->magic = TRANS_MAGIC;
cur_trans->in_commit = 0;
cur_trans->use_count = 1;
cur_trans->commit_done = 0;
h->block_group = NULL;
root->fs_info->running_transaction->use_count++;
mutex_unlock(&root->fs_info->trans_mutex);
- h->magic = h->magic2 = TRANS_MAGIC;
return h;
}
{
struct btrfs_transaction *cur_trans;
- WARN_ON(trans->magic != TRANS_MAGIC);
- WARN_ON(trans->magic2 != TRANS_MAGIC);
mutex_lock(&root->fs_info->trans_mutex);
cur_trans = root->fs_info->running_transaction;
WARN_ON(cur_trans->num_writers < 1);
struct dirty_root *dirty;
struct btrfs_trans_handle *trans;
int ret;
-
while(!list_empty(list)) {
+ mutex_lock(&tree_root->fs_info->fs_mutex);
dirty = list_entry(list->next, struct dirty_root, list);
list_del_init(&dirty->list);
trans = btrfs_start_transaction(tree_root, 1);
ret = btrfs_end_transaction(trans, tree_root);
BUG_ON(ret);
kfree(dirty);
+ mutex_unlock(&tree_root->fs_info->fs_mutex);
}
return 0;
}
wake_up(&cur_trans->commit_wait);
put_transaction(cur_trans);
put_transaction(cur_trans);
+ if (root->fs_info->closing)
+ list_splice_init(&root->fs_info->dead_roots, &dirty_fs_roots);
+ else
+ list_splice_init(&dirty_fs_roots, &root->fs_info->dead_roots);
mutex_unlock(&root->fs_info->trans_mutex);
kmem_cache_free(btrfs_trans_handle_cachep, trans);
- drop_dirty_roots(root->fs_info->tree_root, &dirty_fs_roots);
+ if (root->fs_info->closing) {
+ mutex_unlock(&root->fs_info->fs_mutex);
+ drop_dirty_roots(root->fs_info->tree_root, &dirty_fs_roots);
+ mutex_lock(&root->fs_info->fs_mutex);
+ }
return ret;
}
struct btrfs_root *root = fs_info->tree_root;
struct btrfs_transaction *cur;
struct btrfs_trans_handle *trans;
+ struct list_head dirty_roots;
unsigned long now;
unsigned long delay = HZ * 30;
int ret;
-printk("btrfs transaction cleaner\n");
+ INIT_LIST_HEAD(&dirty_roots);
+ mutex_lock(&root->fs_info->trans_mutex);
+ list_splice_init(&root->fs_info->dead_roots, &dirty_roots);
+ mutex_unlock(&root->fs_info->trans_mutex);
+
+ if (!list_empty(&dirty_roots)) {
+ drop_dirty_roots(root, &dirty_roots);
+ }
mutex_lock(&root->fs_info->fs_mutex);
mutex_lock(&root->fs_info->trans_mutex);
cur = root->fs_info->running_transaction;
goto out;
}
mutex_unlock(&root->fs_info->trans_mutex);
-printk("forcing commit\n");
trans = btrfs_start_transaction(root, 1);
ret = btrfs_commit_transaction(trans, root);
out: