Btrfs: handle errors in btrfs_orphan_cleanup
PATCH 1/1 Btrfs: handle errors in btrfs_orphan_cleanup
If we cannot truncate an inode for some reason we will never delete the orphan item associated with that inode, which means that we will loop forever in btrfs_orphan_cleanup. Instead of doing this just return error so we fail to mount. It sucks, but hey it's better than hanging. Thanks,
--- fs/btrfs/ctree.h | 2 +- fs/btrfs/disk-io.c | 14 +++++++++++--- fs/btrfs/extent-tree.c | 3 ++- fs/btrfs/inode.c | 44 ++++++++++++++++++++++++++++++-------------- fs/btrfs/ioctl.c | 4 +++- fs/btrfs/relocation.c | 2 +- 6 files changed, 48 insertions(+), 21 deletions(-)
fs/btrfs/ctree.h +1 -1
@@ -2517,7 +2517,7 @@ int btrfs_update_inode(struct btrfs_trans_handle *trans, struct inode *inode);int btrfs_orphan_add (struct btrfs_trans_handle *trans,struct inode *inode);int btrfs_orphan_del (struct btrfs_trans_handle *trans,struct inode *inode); -void btrfs_orphan_cleanup (struct btrfs_root *root); +int btrfs_orphan_cleanup (struct btrfs_root *root);void btrfs_orphan_pre_snapshot (struct btrfs_trans_handle *trans,struct btrfs_pending_snapshot *pending,u64 *bytes_to_reserve);
fs/btrfs/disk-io.c +11 -3
@@ -2053,8 +2053,12 @@ struct btrfs_root *open_ctree(struct super_block *sb,if (!(sb->s_flags &MS_RDONLY )) {down_read (&fs_info->cleanup_work_sem); -btrfs_orphan_cleanup (fs_info->fs_root); -btrfs_orphan_cleanup (fs_info->tree_root); + err =btrfs_orphan_cleanup (fs_info->fs_root); +if (err) + goto fail_trans_kthread; + err =btrfs_orphan_cleanup (fs_info->tree_root); +if (err) + goto fail_trans_kthread;up_read (&fs_info->cleanup_work_sem); }
@@ -2430,8 +2434,12 @@ int btrfs_cleanup_fs_roots(struct btrfs_fs_info *fs_info) root_objectid = gang[ret -1 ]->root_key.objectid +1 ;for (i =0 ; i < ret; i++) { +int err; + root_objectid = gang[i]->root_key.objectid; -btrfs_orphan_cleanup (gang[i]); + err =btrfs_orphan_cleanup (gang[i]); +if (err) +return err; } root_objectid++; }
fs/btrfs/extent-tree.c +2 -1
@@ -7604,7 +7604,8 @@ int btrfs_cleanup_reloc_trees(struct btrfs_root *root) reloc_root =btrfs_read_fs_root_no_name (root->fs_info, &location);BUG_ON (!reloc_root); -btrfs_orphan_cleanup (reloc_root); + ret =btrfs_orphan_cleanup (reloc_root); +BUG_ON (ret);return 0 ; }
fs/btrfs/inode.c +30 -14
108 lines not on this page · raw message
fs/btrfs/ioctl.c +3 -1
@@ -409,7 +409,9 @@ static int create_snapshot(struct btrfs_root *root, struct dentry *dentry,if (ret) goto fail; -btrfs_orphan_cleanup (pending_snapshot->snap); + ret =btrfs_orphan_cleanup (pending_snapshot->snap); +if (ret) + goto fail; parent =dget_parent (dentry); inode =btrfs_lookup_dentry (parent->d_inode, dentry);
fs/btrfs/relocation.c +1 -1
@@ -4174,7 +4174,7 @@ out:if (IS_ERR (fs_root)) err =PTR_ERR (fs_root);else -btrfs_orphan_cleanup (fs_root); + err =btrfs_orphan_cleanup (fs_root); }return err; }
Signature · 1 line
1.7.2.3
PATCH 1/1 Btrfs: handle errors in btrfs_orphan_cleanup V2
If we cannot truncate an inode for some reason we will never delete the orphan item associated with that inode, which means that we will loop forever in btrfs_orphan_cleanup. Instead of doing this just return error so we fail to mount. It sucks, but hey it's better than hanging. Thanks,
---V1->V2:
-turns out there was a problem with how we cleanup if btrfs_orphan_cleanup failed. Since we're so far into the open_ctree function anyway, just call close_ctree instead which cleans everything up properly.
fs/btrfs/ctree.h | 2 +- fs/btrfs/disk-io.c | 15 ++++++++++++--- fs/btrfs/extent-tree.c | 3 ++- fs/btrfs/inode.c | 45 +++++++++++++++++++++++++++++++-------------- fs/btrfs/ioctl.c | 4 +++- fs/btrfs/relocation.c | 2 +- 6 files changed, 50 insertions(+), 21 deletions(-)
fs/btrfs/ctree.h +1 -1
@@ -2517,7 +2517,7 @@ int btrfs_update_inode(struct btrfs_trans_handle *trans, struct inode *inode);int btrfs_orphan_add (struct btrfs_trans_handle *trans,struct inode *inode);int btrfs_orphan_del (struct btrfs_trans_handle *trans,struct inode *inode); -void btrfs_orphan_cleanup (struct btrfs_root *root); +int btrfs_orphan_cleanup (struct btrfs_root *root);void btrfs_orphan_pre_snapshot (struct btrfs_trans_handle *trans,struct btrfs_pending_snapshot *pending,u64 *bytes_to_reserve);
fs/btrfs/disk-io.c +12 -3
@@ -2053,9 +2053,14 @@ struct btrfs_root *open_ctree(struct super_block *sb,if (!(sb->s_flags &MS_RDONLY )) {down_read (&fs_info->cleanup_work_sem); -btrfs_orphan_cleanup (fs_info->fs_root); -btrfs_orphan_cleanup (fs_info->tree_root); + err =btrfs_orphan_cleanup (fs_info->fs_root); +if (!err) + err =btrfs_orphan_cleanup (fs_info->tree_root);up_read (&fs_info->cleanup_work_sem); +if (err) { +close_ctree (tree_root); +return ERR_PTR (err); + } }return tree_root;
@@ -2430,8 +2435,12 @@ int btrfs_cleanup_fs_roots(struct btrfs_fs_info *fs_info) root_objectid = gang[ret -1 ]->root_key.objectid +1 ;for (i =0 ; i < ret; i++) { +int err; + root_objectid = gang[i]->root_key.objectid; -btrfs_orphan_cleanup (gang[i]); + err =btrfs_orphan_cleanup (gang[i]); +if (err) +return err; } root_objectid++; }
fs/btrfs/extent-tree.c +2 -1
@@ -7604,7 +7604,8 @@ int btrfs_cleanup_reloc_trees(struct btrfs_root *root) reloc_root =btrfs_read_fs_root_no_name (root->fs_info, &location);BUG_ON (!reloc_root); -btrfs_orphan_cleanup (reloc_root); + ret =btrfs_orphan_cleanup (reloc_root); +BUG_ON (ret);return 0 ; }
fs/btrfs/inode.c +31 -14
115 lines not on this page · raw message
fs/btrfs/ioctl.c +3 -1
@@ -409,7 +409,9 @@ static int create_snapshot(struct btrfs_root *root, struct dentry *dentry,if (ret) goto fail; -btrfs_orphan_cleanup (pending_snapshot->snap); + ret =btrfs_orphan_cleanup (pending_snapshot->snap); +if (ret) + goto fail; parent =dget_parent (dentry); inode =btrfs_lookup_dentry (parent->d_inode, dentry);
fs/btrfs/relocation.c +1 -1
@@ -4174,7 +4174,7 @@ out:if (IS_ERR (fs_root)) err =PTR_ERR (fs_root);else -btrfs_orphan_cleanup (fs_root); + err =btrfs_orphan_cleanup (fs_root); }return err; }
Signature · 1 line
1.7.2.3