When we failed to find a root key in btrfs_update_root(), we just panic.

That's definitely not cool, fix it by aborting current transaction and
return an error value.

Signed-off-by: Qu Wenruo <[email protected]>
---
 fs/btrfs/root-tree.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/fs/btrfs/root-tree.c b/fs/btrfs/root-tree.c
index 65bda0682928..c48a3e18866d 100644
--- a/fs/btrfs/root-tree.c
+++ b/fs/btrfs/root-tree.c
@@ -137,11 +137,15 @@ int btrfs_update_root(struct btrfs_trans_handle *trans, 
struct btrfs_root
                goto out;
        }
 
-       if (ret != 0) {
+       if (ret > 0) {
                btrfs_print_leaf(path->nodes[0]);
-               btrfs_crit(fs_info, "unable to update root key %llu %u %llu",
-                          key->objectid, key->type, key->offset);
-               BUG_ON(1);
+               btrfs_crit(fs_info,
+                       "unable to find root key (%llu %u %llu) in tree %llu",
+                          key->objectid, key->type, key->offset,
+                          root->root_key.objectid);
+               ret = -ENOENT;
+               btrfs_abort_transaction(trans, ret);
+               goto out;
        }
 
        l = path->nodes[0];
-- 
2.20.1

Reply via email to