From: Sasha Levin Date: Sat, 20 May 2023 18:13:06 +0000 (-0400) Subject: Fixes for 5.4 X-Git-Tag: v6.3.4~40 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=de6497a5c8af4b8c599d9dfd330b6052f7ce118a;p=thirdparty%2Fkernel%2Fstable-queue.git Fixes for 5.4 Signed-off-by: Sasha Levin --- diff --git a/queue-5.4/btrfs-fix-space-cache-inconsistency-after-error-load.patch b/queue-5.4/btrfs-fix-space-cache-inconsistency-after-error-load.patch new file mode 100644 index 00000000000..2bd80778f9a --- /dev/null +++ b/queue-5.4/btrfs-fix-space-cache-inconsistency-after-error-load.patch @@ -0,0 +1,62 @@ +From b5223cbd275b426a8caf60c6216c3e137eaf99e1 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 d2d32fed8f2e9..0cb93f73acb2d 100644 +--- a/fs/btrfs/free-space-cache.c ++++ b/fs/btrfs/free-space-cache.c +@@ -784,15 +784,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-5.4/btrfs-replace-calls-to-btrfs_find_free_ino-with-btrf.patch b/queue-5.4/btrfs-replace-calls-to-btrfs_find_free_ino-with-btrf.patch new file mode 100644 index 00000000000..672dca2d633 --- /dev/null +++ b/queue-5.4/btrfs-replace-calls-to-btrfs_find_free_ino-with-btrf.patch @@ -0,0 +1,84 @@ +From 57fec172efee1a80b84a7ed94401fe953741ac9f 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 20c5db8ef8427..c89e85a7da7d4 100644 +--- a/fs/btrfs/inode.c ++++ b/fs/btrfs/inode.c +@@ -6830,7 +6830,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; + +@@ -6894,7 +6894,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; + +@@ -7039,7 +7039,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; + +@@ -9930,7 +9930,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; + +@@ -10416,7 +10416,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; + +@@ -10699,7 +10699,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-5.4/series b/queue-5.4/series index b780efc0aa7..07885bf90c8 100644 --- a/queue-5.4/series +++ b/queue-5.4/series @@ -54,3 +54,5 @@ iommu-arm-smmu-v3-acknowledge-pri-event-queue-overfl.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