From d4607cdd96e22b0822618cdac23784364daf04e6 Mon Sep 17 00:00:00 2001 From: Sasha Levin Date: Mon, 3 Feb 2020 17:42:40 -0500 Subject: [PATCH] fixes for 4.4 Signed-off-by: Sasha Levin --- ...o-f_bavail-if-we-have-available-spac.patch | 65 +++++++++++++++++++ ...mixed-block-count-of-available-space.patch | 64 ++++++++++++++++++ queue-4.4/series | 2 + 3 files changed, 131 insertions(+) create mode 100644 queue-4.4/btrfs-do-not-zero-f_bavail-if-we-have-available-spac.patch create mode 100644 queue-4.4/btrfs-fix-mixed-block-count-of-available-space.patch diff --git a/queue-4.4/btrfs-do-not-zero-f_bavail-if-we-have-available-spac.patch b/queue-4.4/btrfs-do-not-zero-f_bavail-if-we-have-available-spac.patch new file mode 100644 index 00000000000..ad209bff8e6 --- /dev/null +++ b/queue-4.4/btrfs-do-not-zero-f_bavail-if-we-have-available-spac.patch @@ -0,0 +1,65 @@ +From 4311e198e8c8ee86d37e42046500a8b8d9b6bd1f Mon Sep 17 00:00:00 2001 +From: Sasha Levin +Date: Fri, 31 Jan 2020 09:31:05 -0500 +Subject: btrfs: do not zero f_bavail if we have available space + +From: Josef Bacik + +[ Upstream commit d55966c4279bfc6a0cf0b32bf13f5df228a1eeb6 ] + +There was some logic added a while ago to clear out f_bavail in statfs() +if we did not have enough free metadata space to satisfy our global +reserve. This was incorrect at the time, however didn't really pose a +problem for normal file systems because we would often allocate chunks +if we got this low on free metadata space, and thus wouldn't really hit +this case unless we were actually full. + +Fast forward to today and now we are much better about not allocating +metadata chunks all of the time. Couple this with d792b0f19711 ("btrfs: +always reserve our entire size for the global reserve") which now means +we'll easily have a larger global reserve than our free space, we are +now more likely to trip over this while still having plenty of space. + +Fix this by skipping this logic if the global rsv's space_info is not +full. space_info->full is 0 unless we've attempted to allocate a chunk +for that space_info and that has failed. If this happens then the space +for the global reserve is definitely sacred and we need to report +b_avail == 0, but before then we can just use our calculated b_avail. + +Reported-by: Martin Steigerwald +Fixes: ca8a51b3a979 ("btrfs: statfs: report zero available if metadata are exhausted") +CC: stable@vger.kernel.org # 4.5+ +Reviewed-by: Qu Wenruo +Tested-By: Martin Steigerwald +Signed-off-by: Josef Bacik +Reviewed-by: David Sterba +Signed-off-by: David Sterba +Signed-off-by: Sasha Levin +--- + fs/btrfs/super.c | 10 +++++++++- + 1 file changed, 9 insertions(+), 1 deletion(-) + +diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c +index fd98802bee90c..df211bad255c7 100644 +--- a/fs/btrfs/super.c ++++ b/fs/btrfs/super.c +@@ -2052,7 +2052,15 @@ static int btrfs_statfs(struct dentry *dentry, struct kstatfs *buf) + */ + thresh = 4 * 1024 * 1024; + +- if (!mixed && total_free_meta - thresh < block_rsv->size) ++ /* ++ * We only want to claim there's no available space if we can no longer ++ * allocate chunks for our metadata profile and our global reserve will ++ * not fit in the free metadata space. If we aren't ->full then we ++ * still can allocate chunks and thus are fine using the currently ++ * calculated f_bavail. ++ */ ++ if (!mixed && block_rsv->space_info->full && ++ total_free_meta - thresh < block_rsv->size) + buf->f_bavail = 0; + + buf->f_type = BTRFS_SUPER_MAGIC; +-- +2.20.1 + diff --git a/queue-4.4/btrfs-fix-mixed-block-count-of-available-space.patch b/queue-4.4/btrfs-fix-mixed-block-count-of-available-space.patch new file mode 100644 index 00000000000..7743ca6822a --- /dev/null +++ b/queue-4.4/btrfs-fix-mixed-block-count-of-available-space.patch @@ -0,0 +1,64 @@ +From ce7b786533bdcea27a4e46f03ffd7df377de2682 Mon Sep 17 00:00:00 2001 +From: Sasha Levin +Date: Wed, 30 Mar 2016 21:53:38 +0100 +Subject: btrfs: fix mixed block count of available space + +From: Luis de Bethencourt + +[ Upstream commit ae02d1bd070767e109f4a6f1bb1f466e9698a355 ] + +Metadata for mixed block is already accounted in total data and should not +be counted as part of the free metadata space. + +Signed-off-by: Luis de Bethencourt +Link: https://bugzilla.kernel.org/show_bug.cgi?id=114281 +Signed-off-by: David Sterba +Signed-off-by: Sasha Levin +--- + fs/btrfs/super.c | 16 +++++++++++++--- + 1 file changed, 13 insertions(+), 3 deletions(-) + +diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c +index 0f99336c37eb4..fd98802bee90c 100644 +--- a/fs/btrfs/super.c ++++ b/fs/btrfs/super.c +@@ -1978,6 +1978,7 @@ static int btrfs_statfs(struct dentry *dentry, struct kstatfs *buf) + struct btrfs_block_rsv *block_rsv = &fs_info->global_block_rsv; + int ret; + u64 thresh = 0; ++ int mixed = 0; + + /* + * holding chunk_muext to avoid allocating new chunks, holding +@@ -2003,8 +2004,17 @@ static int btrfs_statfs(struct dentry *dentry, struct kstatfs *buf) + } + } + } +- if (found->flags & BTRFS_BLOCK_GROUP_METADATA) +- total_free_meta += found->disk_total - found->disk_used; ++ ++ /* ++ * Metadata in mixed block goup profiles are accounted in data ++ */ ++ if (!mixed && found->flags & BTRFS_BLOCK_GROUP_METADATA) { ++ if (found->flags & BTRFS_BLOCK_GROUP_DATA) ++ mixed = 1; ++ else ++ total_free_meta += found->disk_total - ++ found->disk_used; ++ } + + total_used += found->disk_used; + } +@@ -2042,7 +2052,7 @@ static int btrfs_statfs(struct dentry *dentry, struct kstatfs *buf) + */ + thresh = 4 * 1024 * 1024; + +- if (total_free_meta - thresh < block_rsv->size) ++ if (!mixed && total_free_meta - thresh < block_rsv->size) + buf->f_bavail = 0; + + buf->f_type = BTRFS_SUPER_MAGIC; +-- +2.20.1 + diff --git a/queue-4.4/series b/queue-4.4/series index bceee284020..064909b091a 100644 --- a/queue-4.4/series +++ b/queue-4.4/series @@ -51,3 +51,5 @@ net-sonic-quiesce-sonic-before-re-initializing-descr.patch seq_tab_next-should-increase-position-index.patch l2t_seq_next-should-increase-position-index.patch net-fix-skb-csum-update-in-inet_proto_csum_replace16.patch +btrfs-fix-mixed-block-count-of-available-space.patch +btrfs-do-not-zero-f_bavail-if-we-have-available-spac.patch -- 2.47.3