From: Sasha Levin Date: Sat, 20 May 2023 18:13:07 +0000 (-0400) Subject: Fixes for 4.19 X-Git-Tag: v6.3.4~39 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=9a2d868c34ce2ba158e5fce4d793564473805fb3;p=thirdparty%2Fkernel%2Fstable-queue.git Fixes for 4.19 Signed-off-by: Sasha Levin --- diff --git a/queue-4.19/btrfs-fix-space-cache-inconsistency-after-error-load.patch b/queue-4.19/btrfs-fix-space-cache-inconsistency-after-error-load.patch new file mode 100644 index 00000000000..f78a6147bf5 --- /dev/null +++ b/queue-4.19/btrfs-fix-space-cache-inconsistency-after-error-load.patch @@ -0,0 +1,62 @@ +From 510bbc07169cbf939e6f12eabc4a929191a44fcb Mon Sep 17 00:00:00 2001 +From: Sasha Levin +Date: Thu, 4 May 2023 12:04:18 +0100 +Subject: btrfs: fix space cache inconsistency after error loading it from disk + +From: Filipe Manana + +[ Upstream commit 0004ff15ea26015a0a3a6182dca3b9d1df32e2b7 ] + +When loading a free space cache from disk, at __load_free_space_cache(), +if we fail to insert a bitmap entry, we still increment the number of +total bitmaps in the btrfs_free_space_ctl structure, which is incorrect +since we failed to add the bitmap entry. On error we then empty the +cache by calling __btrfs_remove_free_space_cache(), which will result +in getting the total bitmaps counter set to 1. + +A failure to load a free space cache is not critical, so if a failure +happens we just rebuild the cache by scanning the extent tree, which +happens at block-group.c:caching_thread(). Yet the failure will result +in having the total bitmaps of the btrfs_free_space_ctl always bigger +by 1 then the number of bitmap entries we have. So fix this by having +the total bitmaps counter be incremented only if we successfully added +the bitmap entry. + +Fixes: a67509c30079 ("Btrfs: add a io_ctl struct and helpers for dealing with the space cache") +Reviewed-by: Anand Jain +CC: stable@vger.kernel.org # 4.4+ +Signed-off-by: Filipe Manana +Reviewed-by: David Sterba +Signed-off-by: David Sterba +Signed-off-by: Sasha Levin +--- + fs/btrfs/free-space-cache.c | 7 ++++--- + 1 file changed, 4 insertions(+), 3 deletions(-) + +diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c +index 6511cb71986c9..b623e9f3b4c49 100644 +--- a/fs/btrfs/free-space-cache.c ++++ b/fs/btrfs/free-space-cache.c +@@ -783,15 +783,16 @@ static int __load_free_space_cache(struct btrfs_root *root, struct inode *inode, + } + spin_lock(&ctl->tree_lock); + ret = link_free_space(ctl, e); +- ctl->total_bitmaps++; +- ctl->op->recalc_thresholds(ctl); +- spin_unlock(&ctl->tree_lock); + if (ret) { ++ spin_unlock(&ctl->tree_lock); + btrfs_err(fs_info, + "Duplicate entries in free space cache, dumping"); + kmem_cache_free(btrfs_free_space_cachep, e); + goto free_cache; + } ++ ctl->total_bitmaps++; ++ ctl->op->recalc_thresholds(ctl); ++ spin_unlock(&ctl->tree_lock); + list_add_tail(&e->list, &bitmaps); + } + +-- +2.39.2 + diff --git a/queue-4.19/btrfs-replace-calls-to-btrfs_find_free_ino-with-btrf.patch b/queue-4.19/btrfs-replace-calls-to-btrfs_find_free_ino-with-btrf.patch new file mode 100644 index 00000000000..bd07e6d1b1e --- /dev/null +++ b/queue-4.19/btrfs-replace-calls-to-btrfs_find_free_ino-with-btrf.patch @@ -0,0 +1,84 @@ +From 296ed5f4826dda72548c73310fd1d32088390ad6 Mon Sep 17 00:00:00 2001 +From: Sasha Levin +Date: Thu, 26 Nov 2020 15:10:38 +0200 +Subject: btrfs: replace calls to btrfs_find_free_ino with + btrfs_find_free_objectid + +From: Nikolay Borisov + +[ Upstream commit abadc1fcd72e887a8f875dabe4a07aa8c28ac8af ] + +The former is going away as part of the inode map removal so switch +callers to btrfs_find_free_objectid. No functional changes since with +INODE_MAP disabled (default) find_free_objectid was called anyway. + +Signed-off-by: Nikolay Borisov +Reviewed-by: David Sterba +Signed-off-by: David Sterba +Stable-dep-of: 0004ff15ea26 ("btrfs: fix space cache inconsistency after error loading it from disk") +Signed-off-by: Sasha Levin +--- + fs/btrfs/inode.c | 12 ++++++------ + 1 file changed, 6 insertions(+), 6 deletions(-) + +diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c +index f314b2c2d1487..e4a4074ef33da 100644 +--- a/fs/btrfs/inode.c ++++ b/fs/btrfs/inode.c +@@ -6620,7 +6620,7 @@ static int btrfs_mknod(struct inode *dir, struct dentry *dentry, + if (IS_ERR(trans)) + return PTR_ERR(trans); + +- err = btrfs_find_free_ino(root, &objectid); ++ err = btrfs_find_free_objectid(root, &objectid); + if (err) + goto out_unlock; + +@@ -6684,7 +6684,7 @@ static int btrfs_create(struct inode *dir, struct dentry *dentry, + if (IS_ERR(trans)) + return PTR_ERR(trans); + +- err = btrfs_find_free_ino(root, &objectid); ++ err = btrfs_find_free_objectid(root, &objectid); + if (err) + goto out_unlock; + +@@ -6837,7 +6837,7 @@ static int btrfs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode) + if (IS_ERR(trans)) + return PTR_ERR(trans); + +- err = btrfs_find_free_ino(root, &objectid); ++ err = btrfs_find_free_objectid(root, &objectid); + if (err) + goto out_fail; + +@@ -9819,7 +9819,7 @@ static int btrfs_whiteout_for_rename(struct btrfs_trans_handle *trans, + u64 objectid; + u64 index; + +- ret = btrfs_find_free_ino(root, &objectid); ++ ret = btrfs_find_free_objectid(root, &objectid); + if (ret) + return ret; + +@@ -10316,7 +10316,7 @@ static int btrfs_symlink(struct inode *dir, struct dentry *dentry, + if (IS_ERR(trans)) + return PTR_ERR(trans); + +- err = btrfs_find_free_ino(root, &objectid); ++ err = btrfs_find_free_objectid(root, &objectid); + if (err) + goto out_unlock; + +@@ -10600,7 +10600,7 @@ static int btrfs_tmpfile(struct inode *dir, struct dentry *dentry, umode_t mode) + if (IS_ERR(trans)) + return PTR_ERR(trans); + +- ret = btrfs_find_free_ino(root, &objectid); ++ ret = btrfs_find_free_objectid(root, &objectid); + if (ret) + goto out; + +-- +2.39.2 + diff --git a/queue-4.19/series b/queue-4.19/series index 228b54574af..2f51dff63f0 100644 --- a/queue-4.19/series +++ b/queue-4.19/series @@ -44,3 +44,5 @@ clk-tegra20-fix-gcc-7-constant-overflow-warning.patch input-xpad-add-constants-for-gip-interface-numbers.patch phy-st-miphy28lp-use-_poll_timeout-functions-for-wai.patch mfd-dln2-fix-memory-leak-in-dln2_probe.patch +btrfs-replace-calls-to-btrfs_find_free_ino-with-btrf.patch +btrfs-fix-space-cache-inconsistency-after-error-load.patch