From: Josef Bacik Date: Wed, 20 Nov 2019 16:04:36 +0000 (-0800) Subject: btrfs: hold a ref for the root in record_one_backref X-Git-Url: http://git.hungrycats.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7db32b2236911699b298f4efc686d97ceddcd88d;p=linux btrfs: hold a ref for the root in record_one_backref We're looking up in an arbitrary root, we need to hold a ref on that root. Signed-off-by: Josef Bacik --- diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 138c21f5ed12..88f3d6eace7a 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -2523,6 +2523,8 @@ static noinline int record_one_backref(u64 inum, u64 offset, u64 root_id, inum, offset, root_id); return PTR_ERR(root); } + if (!btrfs_grab_fs_root(root)) + return 0; key.objectid = inum; key.type = BTRFS_EXTENT_DATA_KEY; @@ -2532,8 +2534,10 @@ static noinline int record_one_backref(u64 inum, u64 offset, u64 root_id, key.offset = offset; ret = btrfs_search_slot(NULL, root, &key, path, 0, 0); - if (WARN_ON(ret < 0)) + if (WARN_ON(ret < 0)) { + btrfs_put_fs_root(root); return ret; + } ret = 0; while (1) { @@ -2603,6 +2607,7 @@ static noinline int record_one_backref(u64 inum, u64 offset, u64 root_id, backref_insert(&new->root, backref); old->count++; out: + btrfs_put_fs_root(root); btrfs_release_path(path); WARN_ON(ret); return ret;