Skip to content

Commit

Permalink
btrfs: fix return value check of btrfs_start_transaction()
Browse files Browse the repository at this point in the history
The error check of btrfs_start_transaction() is added, and the mistake
of the error check on several places is corrected.

Signed-off-by: Tsutomu Itoh <t-itoh@jp.fujitsu.com>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
  • Loading branch information
Tsutomu Itoh authored and Chris Mason committed Feb 1, 2011
1 parent 5df6708 commit 98d5dc1
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 6 deletions.
7 changes: 5 additions & 2 deletions fs/btrfs/extent-tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -6271,6 +6271,8 @@ int btrfs_drop_snapshot(struct btrfs_root *root,
BUG_ON(!wc);

trans = btrfs_start_transaction(tree_root, 0);
BUG_ON(IS_ERR(trans));

if (block_rsv)
trans->block_rsv = block_rsv;

Expand Down Expand Up @@ -6368,6 +6370,7 @@ int btrfs_drop_snapshot(struct btrfs_root *root,

btrfs_end_transaction_throttle(trans, tree_root);
trans = btrfs_start_transaction(tree_root, 0);
BUG_ON(IS_ERR(trans));
if (block_rsv)
trans->block_rsv = block_rsv;
}
Expand Down Expand Up @@ -7587,7 +7590,7 @@ int btrfs_cleanup_reloc_trees(struct btrfs_root *root)

if (found) {
trans = btrfs_start_transaction(root, 1);
BUG_ON(!trans);
BUG_ON(IS_ERR(trans));
ret = btrfs_commit_transaction(trans, root);
BUG_ON(ret);
}
Expand Down Expand Up @@ -7831,7 +7834,7 @@ static noinline int relocate_one_extent(struct btrfs_root *extent_root,


trans = btrfs_start_transaction(extent_root, 1);
BUG_ON(!trans);
BUG_ON(IS_ERR(trans));

if (extent_key->objectid == 0) {
ret = del_extent_zero(trans, extent_root, path, extent_key);
Expand Down
1 change: 1 addition & 0 deletions fs/btrfs/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -2357,6 +2357,7 @@ void btrfs_orphan_cleanup(struct btrfs_root *root)
*/
if (is_bad_inode(inode)) {
trans = btrfs_start_transaction(root, 0);
BUG_ON(IS_ERR(trans));
btrfs_orphan_del(trans, inode);
btrfs_end_transaction(trans, root);
iput(inode);
Expand Down
10 changes: 8 additions & 2 deletions fs/btrfs/ioctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -907,6 +907,10 @@ static noinline int btrfs_ioctl_resize(struct btrfs_root *root,

if (new_size > old_size) {
trans = btrfs_start_transaction(root, 0);
if (IS_ERR(trans)) {
ret = PTR_ERR(trans);
goto out_unlock;
}
ret = btrfs_grow_device(trans, device, new_size);
btrfs_commit_transaction(trans, root);
} else {
Expand Down Expand Up @@ -2141,9 +2145,9 @@ static long btrfs_ioctl_default_subvol(struct file *file, void __user *argp)
path->leave_spinning = 1;

trans = btrfs_start_transaction(root, 1);
if (!trans) {
if (IS_ERR(trans)) {
btrfs_free_path(path);
return -ENOMEM;
return PTR_ERR(trans);
}

dir_id = btrfs_super_root_dir(&root->fs_info->super_copy);
Expand Down Expand Up @@ -2337,6 +2341,8 @@ static noinline long btrfs_ioctl_start_sync(struct file *file, void __user *argp
u64 transid;

trans = btrfs_start_transaction(root, 0);
if (IS_ERR(trans))
return PTR_ERR(trans);
transid = trans->transid;
btrfs_commit_transaction_async(trans, root, 0);

Expand Down
3 changes: 3 additions & 0 deletions fs/btrfs/relocation.c
Original file line number Diff line number Diff line change
Expand Up @@ -2028,6 +2028,7 @@ static noinline_for_stack int merge_reloc_root(struct reloc_control *rc,

while (1) {
trans = btrfs_start_transaction(root, 0);
BUG_ON(IS_ERR(trans));
trans->block_rsv = rc->block_rsv;

ret = btrfs_block_rsv_check(trans, root, rc->block_rsv,
Expand Down Expand Up @@ -3665,6 +3666,7 @@ static noinline_for_stack int relocate_block_group(struct reloc_control *rc)

while (1) {
trans = btrfs_start_transaction(rc->extent_root, 0);
BUG_ON(IS_ERR(trans));

if (update_backref_cache(trans, &rc->backref_cache)) {
btrfs_end_transaction(trans, rc->extent_root);
Expand Down Expand Up @@ -4033,6 +4035,7 @@ static noinline_for_stack int mark_garbage_root(struct btrfs_root *root)
int ret;

trans = btrfs_start_transaction(root->fs_info->tree_root, 0);
BUG_ON(IS_ERR(trans));

memset(&root->root_item.drop_progress, 0,
sizeof(root->root_item.drop_progress));
Expand Down
2 changes: 2 additions & 0 deletions fs/btrfs/super.c
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,8 @@ int btrfs_sync_fs(struct super_block *sb, int wait)
btrfs_wait_ordered_extents(root, 0, 0);

trans = btrfs_start_transaction(root, 0);
if (IS_ERR(trans))
return PTR_ERR(trans);
ret = btrfs_commit_transaction(trans, root);
return ret;
}
Expand Down
1 change: 1 addition & 0 deletions fs/btrfs/tree-log.c
Original file line number Diff line number Diff line change
Expand Up @@ -3112,6 +3112,7 @@ int btrfs_recover_log_trees(struct btrfs_root *log_root_tree)
BUG_ON(!path);

trans = btrfs_start_transaction(fs_info->tree_root, 0);
BUG_ON(IS_ERR(trans));

wc.trans = trans;
wc.pin = 1;
Expand Down
19 changes: 17 additions & 2 deletions fs/btrfs/volumes.c
Original file line number Diff line number Diff line change
Expand Up @@ -1212,6 +1212,10 @@ static int btrfs_rm_dev_item(struct btrfs_root *root,
return -ENOMEM;

trans = btrfs_start_transaction(root, 0);
if (IS_ERR(trans)) {
btrfs_free_path(path);
return PTR_ERR(trans);
}
key.objectid = BTRFS_DEV_ITEMS_OBJECTID;
key.type = BTRFS_DEV_ITEM_KEY;
key.offset = device->devid;
Expand Down Expand Up @@ -1604,6 +1608,12 @@ int btrfs_init_new_device(struct btrfs_root *root, char *device_path)
}

trans = btrfs_start_transaction(root, 0);
if (IS_ERR(trans)) {
kfree(device);
ret = PTR_ERR(trans);
goto error;
}

lock_chunks(root);

device->barriers = 1;
Expand Down Expand Up @@ -1872,7 +1882,7 @@ static int btrfs_relocate_chunk(struct btrfs_root *root,
return ret;

trans = btrfs_start_transaction(root, 0);
BUG_ON(!trans);
BUG_ON(IS_ERR(trans));

lock_chunks(root);

Expand Down Expand Up @@ -2046,7 +2056,7 @@ int btrfs_balance(struct btrfs_root *dev_root)
BUG_ON(ret);

trans = btrfs_start_transaction(dev_root, 0);
BUG_ON(!trans);
BUG_ON(IS_ERR(trans));

ret = btrfs_grow_device(trans, device, old_size);
BUG_ON(ret);
Expand Down Expand Up @@ -2212,6 +2222,11 @@ int btrfs_shrink_device(struct btrfs_device *device, u64 new_size)

/* Shrinking succeeded, else we would be at "done". */
trans = btrfs_start_transaction(root, 0);
if (IS_ERR(trans)) {
ret = PTR_ERR(trans);
goto done;
}

lock_chunks(root);

device->disk_total_bytes = new_size;
Expand Down

0 comments on commit 98d5dc1

Please sign in to comment.