Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp403265pxb; Thu, 19 Aug 2021 02:14:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxeB8ALXQ4lsQPpGna7wY0FQXMmmzwLOb0KSql4zftzL9aixGsDewS3s6SwlGNqfCfIIcVS X-Received: by 2002:a17:906:89a3:: with SMTP id gg35mr14885507ejc.476.1629364499417; Thu, 19 Aug 2021 02:14:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629364499; cv=none; d=google.com; s=arc-20160816; b=XjoRTNuqdy5UrWWMrgjnzHww/c5b2W9r9aqBYqOgh2XwUEQVx/sUCJ471OVGqX2tI1 cvFHzN7xTwP0s1fbMIUVX770Ogqcdw5MjfSuRl3CzCgLseycs1DtbZzioNyb4dCN17mZ nRDwVQ+HUh/jh2KoSGJnH7Fr0GAiyqZ5Sx/w5nG/DgYJouk5pZUNzvM9gad1CP1yN0fS piXzuTz4AnyBVThvQbOporXZp6AthUN99TjD5oaKqncW+fhL+WxL5kXWdYcEU2IkkCZJ TVhOnjnZNdKCNvYUX8LtIp8RrYBuow2XHLRnUEv9ye9awHT0EnPk0QEIhvj4xYZ0lr8H QQJA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=cZxpvizMAbdA74pMtB7YmKaOF5RJeo/q5WSgBhO8vkE=; b=A/XFa46CikaLNNjDVnnN8rHhxPmynB5TofD2UKEOsGQGILmwqSdXK72yi8KF/wkvTu G878fnxtAm7FvR1CTmg8v/g57fiGxZbCc4GcoinE27EeGaX/fDYbDBFMBUpjSxtVCaB5 Ot17dVLYw2AHji4jWZ6ChQ3ED6tVpGcYKpuO1i/2asZ3+8OYF/wwUjY3yT8UsJMQXnga GkszUrIipczdRoxxU+YPeHGddrdG+hPVS8EduhptQ+gRH+qpvwsU/LI9KHfUN+Jt6wFs UKBpE+6c3r90bGrlSMgk5w8iEq6ssYWbFxO8kFXr/OlUWEqQdEU1wpPXzXp/uPYnJ0ob oc2A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z26si3708442ejc.486.2021.08.19.02.14.33; Thu, 19 Aug 2021 02:14:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230202AbhHSJOc (ORCPT + 99 others); Thu, 19 Aug 2021 05:14:32 -0400 Received: from out30-133.freemail.mail.aliyun.com ([115.124.30.133]:34164 "EHLO out30-133.freemail.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229804AbhHSJO3 (ORCPT ); Thu, 19 Aug 2021 05:14:29 -0400 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R651e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e04426;MF=jefflexu@linux.alibaba.com;NM=1;PH=DS;RN=4;SR=0;TI=SMTPD_---0Uk0e9q-_1629364431; Received: from localhost(mailfrom:jefflexu@linux.alibaba.com fp:SMTPD_---0Uk0e9q-_1629364431) by smtp.aliyun-inc.com(127.0.0.1); Thu, 19 Aug 2021 17:13:52 +0800 From: Jeffle Xu To: tytso@mit.edu, adilger.kernel@dilger.ca Cc: linux-ext4@vger.kernel.org, joseph.qi@linux.alibaba.com Subject: [PATCH] ext4: fix reserved space counter leakage Date: Thu, 19 Aug 2021 17:13:51 +0800 Message-Id: <20210819091351.19297-1-jefflexu@linux.alibaba.com> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org When ext4_es_insert_delayed_block() returns error, e.g., ENOMEM, previously reserved space is not released as the error handling, in which case @s_dirtyclusters_counter is left over. Since this delayed extent failes to be inserted into extent status tree, when inode is written back, the extra @s_dirtyclusters_counter won't be subtracted and remains there forever. This can leads to /sys/fs/ext4//delayed_allocation_blocks remains non-zero even when syncfs is executed on the filesystem. Fixes: 51865fda28e5 ("ext4: let ext4 maintain extent status tree") Cc: Reported-by: Gao Xiang Signed-off-by: Jeffle Xu --- fs/ext4/inode.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 82087657860b..7f15da370281 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -1650,6 +1650,7 @@ static int ext4_insert_delayed_block(struct inode *inode, ext4_lblk_t lblk) struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb); int ret; bool allocated = false; + bool reserved = false; /* * If the cluster containing lblk is shared with a delayed, @@ -1666,6 +1667,7 @@ static int ext4_insert_delayed_block(struct inode *inode, ext4_lblk_t lblk) ret = ext4_da_reserve_space(inode); if (ret != 0) /* ENOSPC */ goto errout; + reserved = true; } else { /* bigalloc */ if (!ext4_es_scan_clu(inode, &ext4_es_is_delonly, lblk)) { if (!ext4_es_scan_clu(inode, @@ -1678,6 +1680,7 @@ static int ext4_insert_delayed_block(struct inode *inode, ext4_lblk_t lblk) ret = ext4_da_reserve_space(inode); if (ret != 0) /* ENOSPC */ goto errout; + reserved = true; } else { allocated = true; } @@ -1688,6 +1691,8 @@ static int ext4_insert_delayed_block(struct inode *inode, ext4_lblk_t lblk) } ret = ext4_es_insert_delayed_block(inode, lblk, allocated); + if (ret && reserved) + ext4_da_release_space(inode, 1); errout: return ret; -- 2.27.0