Commit 2cc65e3e authored by Chris Mason's avatar Chris Mason

Merge branch 'master' of...

Merge branch 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/josef/btrfs-next into for-linus-3.9
parents 154ea289 9b53157a
...@@ -62,7 +62,7 @@ static void btrfs_destroy_ordered_operations(struct btrfs_transaction *t, ...@@ -62,7 +62,7 @@ static void btrfs_destroy_ordered_operations(struct btrfs_transaction *t,
static void btrfs_destroy_ordered_extents(struct btrfs_root *root); static void btrfs_destroy_ordered_extents(struct btrfs_root *root);
static int btrfs_destroy_delayed_refs(struct btrfs_transaction *trans, static int btrfs_destroy_delayed_refs(struct btrfs_transaction *trans,
struct btrfs_root *root); struct btrfs_root *root);
static void btrfs_destroy_pending_snapshots(struct btrfs_transaction *t); static void btrfs_evict_pending_snapshots(struct btrfs_transaction *t);
static void btrfs_destroy_delalloc_inodes(struct btrfs_root *root); static void btrfs_destroy_delalloc_inodes(struct btrfs_root *root);
static int btrfs_destroy_marked_extents(struct btrfs_root *root, static int btrfs_destroy_marked_extents(struct btrfs_root *root,
struct extent_io_tree *dirty_pages, struct extent_io_tree *dirty_pages,
...@@ -3687,7 +3687,7 @@ int btrfs_destroy_delayed_refs(struct btrfs_transaction *trans, ...@@ -3687,7 +3687,7 @@ int btrfs_destroy_delayed_refs(struct btrfs_transaction *trans,
return ret; return ret;
} }
static void btrfs_destroy_pending_snapshots(struct btrfs_transaction *t) static void btrfs_evict_pending_snapshots(struct btrfs_transaction *t)
{ {
struct btrfs_pending_snapshot *snapshot; struct btrfs_pending_snapshot *snapshot;
struct list_head splice; struct list_head splice;
...@@ -3700,10 +3700,8 @@ static void btrfs_destroy_pending_snapshots(struct btrfs_transaction *t) ...@@ -3700,10 +3700,8 @@ static void btrfs_destroy_pending_snapshots(struct btrfs_transaction *t)
snapshot = list_entry(splice.next, snapshot = list_entry(splice.next,
struct btrfs_pending_snapshot, struct btrfs_pending_snapshot,
list); list);
snapshot->error = -ECANCELED;
list_del_init(&snapshot->list); list_del_init(&snapshot->list);
kfree(snapshot);
} }
} }
...@@ -3840,6 +3838,8 @@ void btrfs_cleanup_one_transaction(struct btrfs_transaction *cur_trans, ...@@ -3840,6 +3838,8 @@ void btrfs_cleanup_one_transaction(struct btrfs_transaction *cur_trans,
cur_trans->blocked = 1; cur_trans->blocked = 1;
wake_up(&root->fs_info->transaction_blocked_wait); wake_up(&root->fs_info->transaction_blocked_wait);
btrfs_evict_pending_snapshots(cur_trans);
cur_trans->blocked = 0; cur_trans->blocked = 0;
wake_up(&root->fs_info->transaction_wait); wake_up(&root->fs_info->transaction_wait);
...@@ -3849,8 +3849,6 @@ void btrfs_cleanup_one_transaction(struct btrfs_transaction *cur_trans, ...@@ -3849,8 +3849,6 @@ void btrfs_cleanup_one_transaction(struct btrfs_transaction *cur_trans,
btrfs_destroy_delayed_inodes(root); btrfs_destroy_delayed_inodes(root);
btrfs_assert_delayed_root_empty(root); btrfs_assert_delayed_root_empty(root);
btrfs_destroy_pending_snapshots(cur_trans);
btrfs_destroy_marked_extents(root, &cur_trans->dirty_pages, btrfs_destroy_marked_extents(root, &cur_trans->dirty_pages,
EXTENT_DIRTY); EXTENT_DIRTY);
btrfs_destroy_pinned_extent(root, btrfs_destroy_pinned_extent(root,
...@@ -3894,6 +3892,8 @@ int btrfs_cleanup_transaction(struct btrfs_root *root) ...@@ -3894,6 +3892,8 @@ int btrfs_cleanup_transaction(struct btrfs_root *root)
if (waitqueue_active(&root->fs_info->transaction_blocked_wait)) if (waitqueue_active(&root->fs_info->transaction_blocked_wait))
wake_up(&root->fs_info->transaction_blocked_wait); wake_up(&root->fs_info->transaction_blocked_wait);
btrfs_evict_pending_snapshots(t);
t->blocked = 0; t->blocked = 0;
smp_mb(); smp_mb();
if (waitqueue_active(&root->fs_info->transaction_wait)) if (waitqueue_active(&root->fs_info->transaction_wait))
...@@ -3907,8 +3907,6 @@ int btrfs_cleanup_transaction(struct btrfs_root *root) ...@@ -3907,8 +3907,6 @@ int btrfs_cleanup_transaction(struct btrfs_root *root)
btrfs_destroy_delayed_inodes(root); btrfs_destroy_delayed_inodes(root);
btrfs_assert_delayed_root_empty(root); btrfs_assert_delayed_root_empty(root);
btrfs_destroy_pending_snapshots(t);
btrfs_destroy_delalloc_inodes(root); btrfs_destroy_delalloc_inodes(root);
spin_lock(&root->fs_info->trans_lock); spin_lock(&root->fs_info->trans_lock);
......
...@@ -527,6 +527,8 @@ static noinline int create_subvol(struct inode *dir, ...@@ -527,6 +527,8 @@ static noinline int create_subvol(struct inode *dir,
if (async_transid) { if (async_transid) {
*async_transid = trans->transid; *async_transid = trans->transid;
err = btrfs_commit_transaction_async(trans, root, 1); err = btrfs_commit_transaction_async(trans, root, 1);
if (err)
err = btrfs_commit_transaction(trans, root);
} else { } else {
err = btrfs_commit_transaction(trans, root); err = btrfs_commit_transaction(trans, root);
} }
...@@ -592,16 +594,14 @@ static int create_snapshot(struct btrfs_root *root, struct inode *dir, ...@@ -592,16 +594,14 @@ static int create_snapshot(struct btrfs_root *root, struct inode *dir,
*async_transid = trans->transid; *async_transid = trans->transid;
ret = btrfs_commit_transaction_async(trans, ret = btrfs_commit_transaction_async(trans,
root->fs_info->extent_root, 1); root->fs_info->extent_root, 1);
if (ret)
ret = btrfs_commit_transaction(trans, root);
} else { } else {
ret = btrfs_commit_transaction(trans, ret = btrfs_commit_transaction(trans,
root->fs_info->extent_root); root->fs_info->extent_root);
} }
if (ret) { if (ret)
/* cleanup_transaction has freed this for us */
if (trans->aborted)
pending_snapshot = NULL;
goto fail; goto fail;
}
ret = pending_snapshot->error; ret = pending_snapshot->error;
if (ret) if (ret)
...@@ -2245,13 +2245,6 @@ static int btrfs_ioctl_defrag(struct file *file, void __user *argp) ...@@ -2245,13 +2245,6 @@ static int btrfs_ioctl_defrag(struct file *file, void __user *argp)
if (ret) if (ret)
return ret; return ret;
if (atomic_xchg(&root->fs_info->mutually_exclusive_operation_running,
1)) {
pr_info("btrfs: dev add/delete/balance/replace/resize operation in progress\n");
mnt_drop_write_file(file);
return -EINVAL;
}
if (btrfs_root_readonly(root)) { if (btrfs_root_readonly(root)) {
ret = -EROFS; ret = -EROFS;
goto out; goto out;
...@@ -2306,7 +2299,6 @@ static int btrfs_ioctl_defrag(struct file *file, void __user *argp) ...@@ -2306,7 +2299,6 @@ static int btrfs_ioctl_defrag(struct file *file, void __user *argp)
ret = -EINVAL; ret = -EINVAL;
} }
out: out:
atomic_set(&root->fs_info->mutually_exclusive_operation_running, 0);
mnt_drop_write_file(file); mnt_drop_write_file(file);
return ret; return ret;
} }
......
...@@ -1269,6 +1269,8 @@ static int __update_reloc_root(struct btrfs_root *root, int del) ...@@ -1269,6 +1269,8 @@ static int __update_reloc_root(struct btrfs_root *root, int del)
} }
spin_unlock(&rc->reloc_root_tree.lock); spin_unlock(&rc->reloc_root_tree.lock);
if (!node)
return 0;
BUG_ON((struct btrfs_root *)node->data != root); BUG_ON((struct btrfs_root *)node->data != root);
if (!del) { if (!del) {
...@@ -2237,6 +2239,21 @@ int prepare_to_merge(struct reloc_control *rc, int err) ...@@ -2237,6 +2239,21 @@ int prepare_to_merge(struct reloc_control *rc, int err)
return err; return err;
} }
static noinline_for_stack
void free_reloc_roots(struct list_head *list)
{
struct btrfs_root *reloc_root;
while (!list_empty(list)) {
reloc_root = list_entry(list->next, struct btrfs_root,
root_list);
__update_reloc_root(reloc_root, 1);
free_extent_buffer(reloc_root->node);
free_extent_buffer(reloc_root->commit_root);
kfree(reloc_root);
}
}
static noinline_for_stack static noinline_for_stack
int merge_reloc_roots(struct reloc_control *rc) int merge_reloc_roots(struct reloc_control *rc)
{ {
...@@ -2244,7 +2261,7 @@ int merge_reloc_roots(struct reloc_control *rc) ...@@ -2244,7 +2261,7 @@ int merge_reloc_roots(struct reloc_control *rc)
struct btrfs_root *reloc_root; struct btrfs_root *reloc_root;
LIST_HEAD(reloc_roots); LIST_HEAD(reloc_roots);
int found = 0; int found = 0;
int ret; int ret = 0;
again: again:
root = rc->extent_root; root = rc->extent_root;
...@@ -2270,20 +2287,33 @@ int merge_reloc_roots(struct reloc_control *rc) ...@@ -2270,20 +2287,33 @@ int merge_reloc_roots(struct reloc_control *rc)
BUG_ON(root->reloc_root != reloc_root); BUG_ON(root->reloc_root != reloc_root);
ret = merge_reloc_root(rc, root); ret = merge_reloc_root(rc, root);
BUG_ON(ret); if (ret)
goto out;
} else { } else {
list_del_init(&reloc_root->root_list); list_del_init(&reloc_root->root_list);
} }
ret = btrfs_drop_snapshot(reloc_root, rc->block_rsv, 0, 1); ret = btrfs_drop_snapshot(reloc_root, rc->block_rsv, 0, 1);
BUG_ON(ret < 0); if (ret < 0) {
if (list_empty(&reloc_root->root_list))
list_add_tail(&reloc_root->root_list,
&reloc_roots);
goto out;
}
} }
if (found) { if (found) {
found = 0; found = 0;
goto again; goto again;
} }
out:
if (ret) {
btrfs_std_error(root->fs_info, ret);
if (!list_empty(&reloc_roots))
free_reloc_roots(&reloc_roots);
}
BUG_ON(!RB_EMPTY_ROOT(&rc->reloc_root_tree.rb_root)); BUG_ON(!RB_EMPTY_ROOT(&rc->reloc_root_tree.rb_root));
return 0; return ret;
} }
static void free_block_list(struct rb_root *blocks) static void free_block_list(struct rb_root *blocks)
...@@ -2818,8 +2848,10 @@ int relocate_tree_blocks(struct btrfs_trans_handle *trans, ...@@ -2818,8 +2848,10 @@ int relocate_tree_blocks(struct btrfs_trans_handle *trans,
int err = 0; int err = 0;
path = btrfs_alloc_path(); path = btrfs_alloc_path();
if (!path) if (!path) {
return -ENOMEM; err = -ENOMEM;
goto out_path;
}
rb_node = rb_first(blocks); rb_node = rb_first(blocks);
while (rb_node) { while (rb_node) {
...@@ -2858,10 +2890,11 @@ int relocate_tree_blocks(struct btrfs_trans_handle *trans, ...@@ -2858,10 +2890,11 @@ int relocate_tree_blocks(struct btrfs_trans_handle *trans,
rb_node = rb_next(rb_node); rb_node = rb_next(rb_node);
} }
out: out:
free_block_list(blocks);
err = finish_pending_nodes(trans, rc, path, err); err = finish_pending_nodes(trans, rc, path, err);
btrfs_free_path(path); btrfs_free_path(path);
out_path:
free_block_list(blocks);
return err; return err;
} }
...@@ -3698,7 +3731,15 @@ int prepare_to_relocate(struct reloc_control *rc) ...@@ -3698,7 +3731,15 @@ int prepare_to_relocate(struct reloc_control *rc)
set_reloc_control(rc); set_reloc_control(rc);
trans = btrfs_join_transaction(rc->extent_root); trans = btrfs_join_transaction(rc->extent_root);
BUG_ON(IS_ERR(trans)); if (IS_ERR(trans)) {
unset_reloc_control(rc);
/*
* extent tree is not a ref_cow tree and has no reloc_root to
* cleanup. And callers are responsible to free the above
* block rsv.
*/
return PTR_ERR(trans);
}
btrfs_commit_transaction(trans, rc->extent_root); btrfs_commit_transaction(trans, rc->extent_root);
return 0; return 0;
} }
...@@ -3730,7 +3771,11 @@ static noinline_for_stack int relocate_block_group(struct reloc_control *rc) ...@@ -3730,7 +3771,11 @@ static noinline_for_stack int relocate_block_group(struct reloc_control *rc)
while (1) { while (1) {
progress++; progress++;
trans = btrfs_start_transaction(rc->extent_root, 0); trans = btrfs_start_transaction(rc->extent_root, 0);
BUG_ON(IS_ERR(trans)); if (IS_ERR(trans)) {
err = PTR_ERR(trans);
trans = NULL;
break;
}
restart: restart:
if (update_backref_cache(trans, &rc->backref_cache)) { if (update_backref_cache(trans, &rc->backref_cache)) {
btrfs_end_transaction(trans, rc->extent_root); btrfs_end_transaction(trans, rc->extent_root);
...@@ -4264,14 +4309,9 @@ int btrfs_recover_relocation(struct btrfs_root *root) ...@@ -4264,14 +4309,9 @@ int btrfs_recover_relocation(struct btrfs_root *root)
out_free: out_free:
kfree(rc); kfree(rc);
out: out:
while (!list_empty(&reloc_roots)) { if (!list_empty(&reloc_roots))
reloc_root = list_entry(reloc_roots.next, free_reloc_roots(&reloc_roots);
struct btrfs_root, root_list);
list_del(&reloc_root->root_list);
free_extent_buffer(reloc_root->node);
free_extent_buffer(reloc_root->commit_root);
kfree(reloc_root);
}
btrfs_free_path(path); btrfs_free_path(path);
if (err == 0) { if (err == 0) {
......
...@@ -1053,7 +1053,12 @@ int btrfs_defrag_root(struct btrfs_root *root) ...@@ -1053,7 +1053,12 @@ int btrfs_defrag_root(struct btrfs_root *root)
/* /*
* new snapshots need to be created at a very specific time in the * new snapshots need to be created at a very specific time in the
* transaction commit. This does the actual creation * transaction commit. This does the actual creation.
*
* Note:
* If the error which may affect the commitment of the current transaction
* happens, we should return the error number. If the error which just affect
* the creation of the pending snapshots, just return 0.
*/ */
static noinline int create_pending_snapshot(struct btrfs_trans_handle *trans, static noinline int create_pending_snapshot(struct btrfs_trans_handle *trans,
struct btrfs_fs_info *fs_info, struct btrfs_fs_info *fs_info,
...@@ -1072,7 +1077,7 @@ static noinline int create_pending_snapshot(struct btrfs_trans_handle *trans, ...@@ -1072,7 +1077,7 @@ static noinline int create_pending_snapshot(struct btrfs_trans_handle *trans,
struct extent_buffer *tmp; struct extent_buffer *tmp;
struct extent_buffer *old; struct extent_buffer *old;
struct timespec cur_time = CURRENT_TIME; struct timespec cur_time = CURRENT_TIME;
int ret; int ret = 0;
u64 to_reserve = 0; u64 to_reserve = 0;
u64 index = 0; u64 index = 0;
u64 objectid; u64 objectid;
...@@ -1081,40 +1086,36 @@ static noinline int create_pending_snapshot(struct btrfs_trans_handle *trans, ...@@ -1081,40 +1086,36 @@ static noinline int create_pending_snapshot(struct btrfs_trans_handle *trans,
path = btrfs_alloc_path(); path = btrfs_alloc_path();
if (!path) { if (!path) {
ret = pending->error = -ENOMEM; pending->error = -ENOMEM;
return ret; return 0;
} }
new_root_item = kmalloc(sizeof(*new_root_item), GFP_NOFS); new_root_item = kmalloc(sizeof(*new_root_item), GFP_NOFS);
if (!new_root_item) { if (!new_root_item) {
ret = pending->error = -ENOMEM; pending->error = -ENOMEM;
goto root_item_alloc_fail; goto root_item_alloc_fail;
} }
ret = btrfs_find_free_objectid(tree_root, &objectid); pending->error = btrfs_find_free_objectid(tree_root, &objectid);
if (ret) { if (pending->error)
pending->error = ret;
goto no_free_objectid; goto no_free_objectid;
}
btrfs_reloc_pre_snapshot(trans, pending, &to_reserve); btrfs_reloc_pre_snapshot(trans, pending, &to_reserve);
if (to_reserve > 0) { if (to_reserve > 0) {
ret = btrfs_block_rsv_add(root, &pending->block_rsv, pending->error = btrfs_block_rsv_add(root,
&pending->block_rsv,
to_reserve, to_reserve,
BTRFS_RESERVE_NO_FLUSH); BTRFS_RESERVE_NO_FLUSH);
if (ret) { if (pending->error)
pending->error = ret;
goto no_free_objectid; goto no_free_objectid;
} }
}
ret = btrfs_qgroup_inherit(trans, fs_info, root->root_key.objectid, pending->error = btrfs_qgroup_inherit(trans, fs_info,
root->root_key.objectid,
objectid, pending->inherit); objectid, pending->inherit);
if (ret) { if (pending->error)
pending->error = ret;
goto no_free_objectid; goto no_free_objectid;
}
key.objectid = objectid; key.objectid = objectid;
key.offset = (u64)-1; key.offset = (u64)-1;
...@@ -1142,7 +1143,7 @@ static noinline int create_pending_snapshot(struct btrfs_trans_handle *trans, ...@@ -1142,7 +1143,7 @@ static noinline int create_pending_snapshot(struct btrfs_trans_handle *trans,
dentry->d_name.len, 0); dentry->d_name.len, 0);
if (dir_item != NULL && !IS_ERR(dir_item)) { if (dir_item != NULL && !IS_ERR(dir_item)) {
pending->error = -EEXIST; pending->error = -EEXIST;
goto fail; goto dir_item_existed;
} else if (IS_ERR(dir_item)) { } else if (IS_ERR(dir_item)) {
ret = PTR_ERR(dir_item); ret = PTR_ERR(dir_item);
btrfs_abort_transaction(trans, root, ret); btrfs_abort_transaction(trans, root, ret);
...@@ -1273,6 +1274,8 @@ static noinline int create_pending_snapshot(struct btrfs_trans_handle *trans, ...@@ -1273,6 +1274,8 @@ static noinline int create_pending_snapshot(struct btrfs_trans_handle *trans,
if (ret) if (ret)
btrfs_abort_transaction(trans, root, ret); btrfs_abort_transaction(trans, root, ret);
fail: fail:
pending->error = ret;
dir_item_existed:
trans->block_rsv = rsv; trans->block_rsv = rsv;
trans->bytes_reserved = 0; trans->bytes_reserved = 0;
no_free_objectid: no_free_objectid:
...@@ -1288,12 +1291,17 @@ static noinline int create_pending_snapshot(struct btrfs_trans_handle *trans, ...@@ -1288,12 +1291,17 @@ static noinline int create_pending_snapshot(struct btrfs_trans_handle *trans,
static noinline int create_pending_snapshots(struct btrfs_trans_handle *trans, static noinline int create_pending_snapshots(struct btrfs_trans_handle *trans,
struct btrfs_fs_info *fs_info) struct btrfs_fs_info *fs_info)
{ {
struct btrfs_pending_snapshot *pending; struct btrfs_pending_snapshot *pending, *next;
struct list_head *head = &trans->transaction->pending_snapshots; struct list_head *head = &trans->transaction->pending_snapshots;
int ret = 0;
list_for_each_entry(pending, head, list) list_for_each_entry_safe(pending, next, head, list) {
create_pending_snapshot(trans, fs_info, pending); list_del(&pending->list);
return 0; ret = create_pending_snapshot(trans, fs_info, pending);
if (ret)
break;
}
return ret;
} }
static void update_super_roots(struct btrfs_root *root) static void update_super_roots(struct btrfs_root *root)
...@@ -1449,6 +1457,13 @@ static void cleanup_transaction(struct btrfs_trans_handle *trans, ...@@ -1449,6 +1457,13 @@ static void cleanup_transaction(struct btrfs_trans_handle *trans,
btrfs_abort_transaction(trans, root, err); btrfs_abort_transaction(trans, root, err);
spin_lock(&root->fs_info->trans_lock); spin_lock(&root->fs_info->trans_lock);
if (list_empty(&cur_trans->list)) {
spin_unlock(&root->fs_info->trans_lock);
btrfs_end_transaction(trans, root);
return;
}
list_del_init(&cur_trans->list); list_del_init(&cur_trans->list);
if (cur_trans == root->fs_info->running_transaction) { if (cur_trans == root->fs_info->running_transaction) {
root->fs_info->trans_no_join = 1; root->fs_info->trans_no_join = 1;
......
...@@ -1382,6 +1382,9 @@ static noinline int link_to_fixup_dir(struct btrfs_trans_handle *trans, ...@@ -1382,6 +1382,9 @@ static noinline int link_to_fixup_dir(struct btrfs_trans_handle *trans,
btrfs_release_path(path); btrfs_release_path(path);
if (ret == 0) { if (ret == 0) {
if (!inode->i_nlink)
set_nlink(inode, 1);
else
btrfs_inc_nlink(inode); btrfs_inc_nlink(inode);
ret = btrfs_update_inode(trans, root, inode); ret = btrfs_update_inode(trans, root, inode);
} else if (ret == -EEXIST) { } else if (ret == -EEXIST) {
......
...@@ -2379,7 +2379,11 @@ static int btrfs_relocate_chunk(struct btrfs_root *root, ...@@ -2379,7 +2379,11 @@ static int btrfs_relocate_chunk(struct btrfs_root *root,
return ret; return ret;
trans = btrfs_start_transaction(root, 0); trans = btrfs_start_transaction(root, 0);
BUG_ON(IS_ERR(trans)); if (IS_ERR(trans)) {
ret = PTR_ERR(trans);
btrfs_std_error(root->fs_info, ret);
return ret;
}
lock_chunks(root); lock_chunks(root);
...@@ -3050,7 +3054,8 @@ static void __cancel_balance(struct btrfs_fs_info *fs_info) ...@@ -3050,7 +3054,8 @@ static void __cancel_balance(struct btrfs_fs_info *fs_info)
unset_balance_control(fs_info); unset_balance_control(fs_info);
ret = del_balance_item(fs_info->tree_root); ret = del_balance_item(fs_info->tree_root);
BUG_ON(ret); if (ret)
btrfs_std_error(fs_info, ret);
atomic_set(&fs_info->mutually_exclusive_operation_running, 0); atomic_set(&fs_info->mutually_exclusive_operation_running, 0);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment