Skip to content

Commit

Permalink
Btrfs: improve error handling for btrfs_insert_dir_item callers
Browse files Browse the repository at this point in the history
This allows us to gracefully continue if we aren't able to insert
directory items, both for normal files/dirs and snapshots.

Signed-off-by: Chris Mason <chris.mason@oracle.com>
  • Loading branch information
Chris Mason committed Feb 23, 2012
1 parent 692e575 commit fe66a05
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
20 changes: 19 additions & 1 deletion fs/btrfs/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -4585,14 +4585,32 @@ int btrfs_add_link(struct btrfs_trans_handle *trans,
ret = btrfs_insert_dir_item(trans, root, name, name_len,
parent_inode, &key,
btrfs_inode_type(inode), index);
BUG_ON(ret);
if (ret)
goto fail_dir_item;

btrfs_i_size_write(parent_inode, parent_inode->i_size +
name_len * 2);
parent_inode->i_mtime = parent_inode->i_ctime = CURRENT_TIME;
ret = btrfs_update_inode(trans, root, parent_inode);
}
return ret;

fail_dir_item:
if (unlikely(ino == BTRFS_FIRST_FREE_OBJECTID)) {
u64 local_index;
int err;
err = btrfs_del_root_ref(trans, root->fs_info->tree_root,
key.objectid, root->root_key.objectid,
parent_ino, &local_index, name, name_len);

} else if (add_backref) {
u64 local_index;
int err;

err = btrfs_del_inode_ref(trans, root, name, name_len,
ino, parent_ino, &local_index);
}
return ret;
}

static int btrfs_add_nondir(struct btrfs_trans_handle *trans,
Expand Down
13 changes: 7 additions & 6 deletions fs/btrfs/transaction.c
Original file line number Diff line number Diff line change
Expand Up @@ -915,7 +915,11 @@ static noinline int create_pending_snapshot(struct btrfs_trans_handle *trans,
dentry->d_name.name, dentry->d_name.len,
parent_inode, &key,
BTRFS_FT_DIR, index);
BUG_ON(ret);
if (ret) {
pending->error = -EEXIST;
dput(parent);
goto fail;
}

btrfs_i_size_write(parent_inode, parent_inode->i_size +
dentry->d_name.len * 2);
Expand Down Expand Up @@ -993,12 +997,9 @@ static noinline int create_pending_snapshots(struct btrfs_trans_handle *trans,
{
struct btrfs_pending_snapshot *pending;
struct list_head *head = &trans->transaction->pending_snapshots;
int ret;

list_for_each_entry(pending, head, list) {
ret = create_pending_snapshot(trans, fs_info, pending);
BUG_ON(ret);
}
list_for_each_entry(pending, head, list)
create_pending_snapshot(trans, fs_info, pending);
return 0;
}

Expand Down

0 comments on commit fe66a05

Please sign in to comment.