From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 93705E7C4E9 for ; Wed, 4 Oct 2023 18:21:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243890AbjJDSVU (ORCPT ); Wed, 4 Oct 2023 14:21:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52320 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233455AbjJDSVT (ORCPT ); Wed, 4 Oct 2023 14:21:19 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5034398 for ; Wed, 4 Oct 2023 11:21:16 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 939DAC433C7; Wed, 4 Oct 2023 18:21:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1696443676; bh=0m6cMkXHANolCR9IdZ+kMnL14NikIucXekfElnX4Ssc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=r6T9ELByhLk+PbBsA8Znsncx2NbHtZfDtIyFm9ELcJZTPwLbaU0pvsDDEsWyKBBq4 5hKiXH6lflK5E1BCIYOABpBUUTGbzUnkTXO8iXkNiDY1UpXq6haSK3ZR++tKsIz8TO VZFhTXQreBNRbwHqZQwL7UQ9D8UChhGWL5SBuY8g= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Josef Bacik , David Sterba Subject: [PATCH 6.1 240/259] btrfs: properly report 0 avail for very full file systems Date: Wed, 4 Oct 2023 19:56:53 +0200 Message-ID: <20231004175228.395923045@linuxfoundation.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231004175217.404851126@linuxfoundation.org> References: <20231004175217.404851126@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org 6.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Josef Bacik commit 58bfe2ccec5f9f137b41dd38f335290dcc13cd5c upstream. A user reported some issues with smaller file systems that get very full. While investigating this issue I noticed that df wasn't showing 100% full, despite having 0 chunk space and having < 1MiB of available metadata space. This turns out to be an overflow issue, we're doing: total_available_metadata_space - SZ_4M < global_block_rsv_size to determine if there's not enough space to make metadata allocations, which overflows if total_available_metadata_space is < 4M. Fix this by checking to see if our available space is greater than the 4M threshold. This makes df properly report 100% usage on the file system. CC: stable@vger.kernel.org # 4.14+ Signed-off-by: Josef Bacik Reviewed-by: David Sterba Signed-off-by: David Sterba Signed-off-by: Greg Kroah-Hartman --- fs/btrfs/super.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/fs/btrfs/super.c +++ b/fs/btrfs/super.c @@ -2418,7 +2418,7 @@ static int btrfs_statfs(struct dentry *d * calculated f_bavail. */ if (!mixed && block_rsv->space_info->full && - total_free_meta - thresh < block_rsv->size) + (total_free_meta < thresh || total_free_meta - thresh < block_rsv->size)) buf->f_bavail = 0; buf->f_type = BTRFS_SUPER_MAGIC;