Commit 8732d44f authored by Miao Xie's avatar Miao Xie Committed by Chris Mason

Btrfs: fix the missing error information in create_pending_snapshot()

The macro btrfs_abort_transaction() can get the line number of the code
where the problem happens, so we should invoke it in the place that the
error occurs, or we will lose the line number.
Reported-by: default avatarDavid Sterba <dave@jikos.cz>
Signed-off-by: default avatarMiao Xie <miaox@cn.fujitsu.com>
parent aa42ffd9
...@@ -1073,7 +1073,8 @@ static noinline int create_pending_snapshot(struct btrfs_trans_handle *trans, ...@@ -1073,7 +1073,8 @@ static noinline int create_pending_snapshot(struct btrfs_trans_handle *trans,
goto fail; goto fail;
} else if (IS_ERR(dir_item)) { } else if (IS_ERR(dir_item)) {
ret = PTR_ERR(dir_item); ret = PTR_ERR(dir_item);
goto abort_trans; btrfs_abort_transaction(trans, root, ret);
goto fail;
} }
btrfs_release_path(path); btrfs_release_path(path);
...@@ -1084,8 +1085,10 @@ static noinline int create_pending_snapshot(struct btrfs_trans_handle *trans, ...@@ -1084,8 +1085,10 @@ static noinline int create_pending_snapshot(struct btrfs_trans_handle *trans,
* snapshot * snapshot
*/ */
ret = btrfs_run_delayed_items(trans, root); ret = btrfs_run_delayed_items(trans, root);
if (ret) /* Transaction aborted */ if (ret) { /* Transaction aborted */
goto abort_trans; btrfs_abort_transaction(trans, root, ret);
goto fail;
}
record_root_in_trans(trans, root); record_root_in_trans(trans, root);
btrfs_set_root_last_snapshot(&root->root_item, trans->transid); btrfs_set_root_last_snapshot(&root->root_item, trans->transid);
...@@ -1118,7 +1121,8 @@ static noinline int create_pending_snapshot(struct btrfs_trans_handle *trans, ...@@ -1118,7 +1121,8 @@ static noinline int create_pending_snapshot(struct btrfs_trans_handle *trans,
if (ret) { if (ret) {
btrfs_tree_unlock(old); btrfs_tree_unlock(old);
free_extent_buffer(old); free_extent_buffer(old);
goto abort_trans; btrfs_abort_transaction(trans, root, ret);
goto fail;
} }
btrfs_set_lock_blocking(old); btrfs_set_lock_blocking(old);
...@@ -1127,8 +1131,10 @@ static noinline int create_pending_snapshot(struct btrfs_trans_handle *trans, ...@@ -1127,8 +1131,10 @@ static noinline int create_pending_snapshot(struct btrfs_trans_handle *trans,
/* clean up in any case */ /* clean up in any case */
btrfs_tree_unlock(old); btrfs_tree_unlock(old);
free_extent_buffer(old); free_extent_buffer(old);
if (ret) if (ret) {
goto abort_trans; btrfs_abort_transaction(trans, root, ret);
goto fail;
}
/* see comments in should_cow_block() */ /* see comments in should_cow_block() */
root->force_cow = 1; root->force_cow = 1;
...@@ -1140,8 +1146,10 @@ static noinline int create_pending_snapshot(struct btrfs_trans_handle *trans, ...@@ -1140,8 +1146,10 @@ static noinline int create_pending_snapshot(struct btrfs_trans_handle *trans,
ret = btrfs_insert_root(trans, tree_root, &key, new_root_item); ret = btrfs_insert_root(trans, tree_root, &key, new_root_item);
btrfs_tree_unlock(tmp); btrfs_tree_unlock(tmp);
free_extent_buffer(tmp); free_extent_buffer(tmp);
if (ret) if (ret) {
goto abort_trans; btrfs_abort_transaction(trans, root, ret);
goto fail;
}
/* /*
* insert root back/forward references * insert root back/forward references
...@@ -1150,23 +1158,30 @@ static noinline int create_pending_snapshot(struct btrfs_trans_handle *trans, ...@@ -1150,23 +1158,30 @@ static noinline int create_pending_snapshot(struct btrfs_trans_handle *trans,
parent_root->root_key.objectid, parent_root->root_key.objectid,
btrfs_ino(parent_inode), index, btrfs_ino(parent_inode), index,
dentry->d_name.name, dentry->d_name.len); dentry->d_name.name, dentry->d_name.len);
if (ret) if (ret) {
goto abort_trans; btrfs_abort_transaction(trans, root, ret);
goto fail;
}
key.offset = (u64)-1; key.offset = (u64)-1;
pending->snap = btrfs_read_fs_root_no_name(root->fs_info, &key); pending->snap = btrfs_read_fs_root_no_name(root->fs_info, &key);
if (IS_ERR(pending->snap)) { if (IS_ERR(pending->snap)) {
ret = PTR_ERR(pending->snap); ret = PTR_ERR(pending->snap);
goto abort_trans; btrfs_abort_transaction(trans, root, ret);
goto fail;
} }
ret = btrfs_reloc_post_snapshot(trans, pending); ret = btrfs_reloc_post_snapshot(trans, pending);
if (ret) if (ret) {
goto abort_trans; btrfs_abort_transaction(trans, root, ret);
goto fail;
}
ret = btrfs_run_delayed_refs(trans, root, (unsigned long)-1); ret = btrfs_run_delayed_refs(trans, root, (unsigned long)-1);
if (ret) if (ret) {
goto abort_trans; btrfs_abort_transaction(trans, root, ret);
goto fail;
}
ret = btrfs_insert_dir_item(trans, parent_root, ret = btrfs_insert_dir_item(trans, parent_root,
dentry->d_name.name, dentry->d_name.len, dentry->d_name.name, dentry->d_name.len,
...@@ -1174,15 +1189,17 @@ static noinline int create_pending_snapshot(struct btrfs_trans_handle *trans, ...@@ -1174,15 +1189,17 @@ static noinline int create_pending_snapshot(struct btrfs_trans_handle *trans,
BTRFS_FT_DIR, index); BTRFS_FT_DIR, index);
/* We have check then name at the beginning, so it is impossible. */ /* We have check then name at the beginning, so it is impossible. */
BUG_ON(ret == -EEXIST); BUG_ON(ret == -EEXIST);
if (ret) if (ret) {
goto abort_trans; btrfs_abort_transaction(trans, root, ret);
goto fail;
}
btrfs_i_size_write(parent_inode, parent_inode->i_size + btrfs_i_size_write(parent_inode, parent_inode->i_size +
dentry->d_name.len * 2); dentry->d_name.len * 2);
parent_inode->i_mtime = parent_inode->i_ctime = CURRENT_TIME; parent_inode->i_mtime = parent_inode->i_ctime = CURRENT_TIME;
ret = btrfs_update_inode(trans, parent_root, parent_inode); ret = btrfs_update_inode(trans, parent_root, parent_inode);
if (ret) if (ret)
goto abort_trans; btrfs_abort_transaction(trans, root, ret);
fail: fail:
dput(parent); dput(parent);
trans->block_rsv = rsv; trans->block_rsv = rsv;
...@@ -1193,10 +1210,6 @@ static noinline int create_pending_snapshot(struct btrfs_trans_handle *trans, ...@@ -1193,10 +1210,6 @@ static noinline int create_pending_snapshot(struct btrfs_trans_handle *trans,
path_alloc_fail: path_alloc_fail:
btrfs_block_rsv_release(root, &pending->block_rsv, (u64)-1); btrfs_block_rsv_release(root, &pending->block_rsv, (u64)-1);
return ret; return ret;
abort_trans:
btrfs_abort_transaction(trans, root, ret);
goto fail;
} }
/* /*
......
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