OSDN Git Service

Merge tag 'v4.4.214' into 10
[sagit-ice-cold/kernel_xiaomi_msm8998.git] / fs / btrfs / super.c
index 0f99336..df211ba 100644 (file)
@@ -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,15 @@ static int btrfs_statfs(struct dentry *dentry, struct kstatfs *buf)
         */
        thresh = 4 * 1024 * 1024;
 
-       if (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;