mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Xuewen Wang <wangxuewen_ky@163.com>
To: linkinjeon@kernel.org, hyc.lee@gmail.com
Cc: wangxuewen_ky@163.com, ntfs@lists.linux.dev,
	linux-kernel@vger.kernel.org, Baolin Liu <liubaolin@kylinos.cn>
Subject: [PATCH v5 02/31] ntfs: preserve cluster-free counts in attribute cleanup
Date: Mon,  2 Nov 2026 15:35:03 +0800	[thread overview]
Message-ID: <20261102073532.98873-3-wangxuewen_ky@163.com> (raw)
In-Reply-To: <20261102073532.98873-1-wangxuewen_ky@163.com>

From: Baolin Liu <liubaolin@kylinos.cn>

ntfs_cluster_free() returns a signed 64-bit cluster count on success,
not an integer status. Several attribute cleanup paths truncate that
count or treat a positive count as an error. ntfs_attr_rm() can even
return the count to callers that expect zero on success.

Store the result in s64 variables, test negative results for failure,
and compare the full count when validating an allocation rollback.
Return zero from ntfs_attr_rm() after successful removal. This keeps
successful deallocation from being misclassified by later reporting.

Fixes: 495e90fa3348 ("ntfs: update attrib operations")
Signed-off-by: Baolin Liu <liubaolin@kylinos.cn>
---
 fs/ntfs/attrib.c | 27 +++++++++++++++------------
 1 file changed, 15 insertions(+), 12 deletions(-)

diff --git a/fs/ntfs/attrib.c b/fs/ntfs/attrib.c
index fce7144d7bef..0be410973176 100644
--- a/fs/ntfs/attrib.c
+++ b/fs/ntfs/attrib.c
@@ -4164,7 +4164,7 @@ static int ntfs_attr_make_resident(struct ntfs_inode *ni, struct ntfs_attr_searc
 	struct super_block *sb = vol->sb;
 	struct attr_record *a = ctx->attr;
 	int name_ofs, val_ofs, err;
-	s64 arec_size;
+	s64 arec_size, freed;
 
 	ntfs_debug("Entering for inode 0x%llx, attr 0x%x.\n",
 			(unsigned long long)ni->mft_no, ni->type);
@@ -4252,8 +4252,8 @@ static int ntfs_attr_make_resident(struct ntfs_inode *ni, struct ntfs_attr_searc
 	 * the whole run list and thus it doesn't matter that the attribute
 	 * record is in a transiently corrupted state at this moment in time.
 	 */
-	err = ntfs_cluster_free(ni, 0, -1, ctx);
-	if (err) {
+	freed = ntfs_cluster_free(ni, 0, -1, ctx);
+	if (freed < 0) {
 		ntfs_error(sb, "Eeek! Failed to release allocated clusters");
 		ntfs_debug("Ignoring error and leaving behind wasted clusters.\n");
 	}
@@ -4496,6 +4496,7 @@ static int ntfs_non_resident_attr_expand(struct ntfs_inode *ni, const s64 newsiz
 	struct ntfs_attr_search_ctx *ctx = NULL;
 	struct runlist_element *rl, *rln;
 	s64 org_alloc_size, org_compressed_size;
+	s64 freed;
 	int err, err2;
 	struct ntfs_inode *base_ni;
 	struct super_block *sb = ni->vol->sb;
@@ -4760,9 +4761,9 @@ static int ntfs_non_resident_attr_expand(struct ntfs_inode *ni, const s64 newsiz
 		down_write(&ni->runlist.lock);
 rollback_locked:
 	/* Free allocated clusters. */
-	err2 = ntfs_cluster_free(ni, ntfs_bytes_to_cluster(vol, org_alloc_size),
-				-1, ctx);
-	if (err2)
+	freed = ntfs_cluster_free(ni, ntfs_bytes_to_cluster(vol, org_alloc_size),
+				  -1, ctx);
+	if (freed < 0)
 		ntfs_debug("Leaking clusters");
 
 	/*
@@ -5229,6 +5230,7 @@ int ntfs_attr_map_cluster(struct ntfs_inode *ni, s64 vcn_start, s64 *lcn_start,
 	struct runlist_element *rl, *rlc;
 	struct runlist_element *old_rl = NULL;
 	s64 vcn = vcn_start, lcn, clu_count;
+	s64 freed;
 	s64 lcn_seek_from = -1;
 	int err = 0;
 	size_t new_rl_count, old_rl_count;
@@ -5359,10 +5361,8 @@ int ntfs_attr_map_cluster(struct ntfs_inode *ni, s64 vcn_start, s64 *lcn_start,
 		ntfs_attr_reinit_search_ctx(ctx);
 		err = ntfs_attr_update_mapping_pairs_locked(ni, 0, ni);
 		if (err) {
-			int err2;
-
-			err2 = ntfs_cluster_free(ni, vcn, clu_count, ctx);
-			if (err2 < 0 || err2 != clu_count) {
+			freed = ntfs_cluster_free(ni, vcn, clu_count, ctx);
+			if (freed < 0 || freed != clu_count) {
 				ntfs_error(vol->sb,
 					   "Failed to free cluster allocation. Leaving inconsistent metadata.\n");
 				NVolSetErrors(vol);
@@ -5410,6 +5410,7 @@ int ntfs_attr_rm(struct ntfs_inode *ni)
 {
 	struct ntfs_attr_search_ctx *ctx;
 	int err = 0, ret = 0;
+	s64 freed = 0;
 	struct ntfs_inode *base_ni;
 	struct super_block *sb = ni->vol->sb;
 
@@ -5431,10 +5432,12 @@ int ntfs_attr_rm(struct ntfs_inode *ni)
 			return -ENOMEM;
 		}
 
-		ret = ntfs_cluster_free(ni, 0, -1, ctx);
-		if (ret < 0)
+		freed = ntfs_cluster_free(ni, 0, -1, ctx);
+		if (freed < 0) {
+			ret = freed;
 			ntfs_error(sb,
 				"Failed to free cluster allocation. Leaving inconstant metadata.\n");
+		}
 		ntfs_attr_put_search_ctx(ctx);
 	}
 


  parent reply	other threads:[~2026-11-02  7:35 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-02  7:35 [PATCH v5 00/31] ntfs: report metadata errors and shutdown through FAN_FS_ERROR Xuewen Wang
2026-11-02  7:35 ` [PATCH v5 01/31] ntfs: propagate mapping-pairs update errors from inode writeback Xuewen Wang
2026-11-02  7:35 ` Xuewen Wang [this message]
2026-11-02  7:35 ` [PATCH v5 03/31] ntfs: add filesystem metadata error reporting helpers Xuewen Wang
2026-11-02  7:35 ` [PATCH v5 04/31] ntfs: preserve attribute search context initialization errors Xuewen Wang
2026-11-02  7:35 ` [PATCH v5 05/31] ntfs: report boot geometry and MFT bootstrap errors Xuewen Wang
2026-11-02  7:35 ` [PATCH v5 06/31] ntfs: report required system file and volume metadata errors Xuewen Wang
2026-11-02  7:35 ` [PATCH v5 07/31] ntfs: report logfile metadata and emptying errors Xuewen Wang
2026-11-02  7:35 ` [PATCH v5 08/31] ntfs: report runlist and cluster allocation metadata errors Xuewen Wang
2026-11-02  7:35 ` [PATCH v5 09/31] ntfs: report iomap corruption and preserve buffered read errors Xuewen Wang
2026-11-02  7:35 ` [PATCH v5 10/31] ntfs: report LZNT1 and WOF compressed stream errors Xuewen Wang
2026-11-02  7:35 ` [PATCH v5 11/31] ntfs: handle source record removal failure during attribute moves Xuewen Wang
2026-11-09  2:31   ` Hyunchul Lee
2026-11-10  3:13     ` Xuewen Wang
2026-11-10  4:11       ` Namjae Jeon
2026-11-10  6:16         ` Xuewen Wang
2026-11-02  7:35 ` [PATCH v5 12/31] ntfs: report attribute lookup and validation errors Xuewen Wang
2026-11-02  7:35 ` [PATCH v5 13/31] ntfs: report attribute record update and cleanup failures Xuewen Wang
2026-11-02  7:35 ` [PATCH v5 14/31] ntfs: report attribute list update and recovery failures Xuewen Wang
2026-11-02  7:35 ` [PATCH v5 15/31] ntfs: report attribute conversion and mapping update failures Xuewen Wang
2026-11-02  7:35 ` [PATCH v5 16/31] ntfs: report attribute resize and relocation recovery failures Xuewen Wang
2026-11-02  7:35 ` [PATCH v5 17/31] ntfs: report incomplete attribute range updates Xuewen Wang
2026-11-02  7:35 ` [PATCH v5 18/31] ntfs: report inode metadata and eviction cleanup errors Xuewen Wang
2026-11-02  7:35 ` [PATCH v5 19/31] ntfs: report index validation and block I/O errors Xuewen Wang
2026-11-02  7:35 ` [PATCH v5 20/31] ntfs: preserve index traversal errors and directory retries Xuewen Wang
2026-11-02  7:35 ` [PATCH v5 21/31] ntfs: report directory lookup and metadata corruption Xuewen Wang
2026-11-02  7:35 ` [PATCH v5 22/31] ntfs: report index update and recovery failures Xuewen Wang
2026-11-02  7:35 ` [PATCH v5 23/31] ntfs: report namespace and file recovery errors Xuewen Wang
2026-11-02  7:35 ` [PATCH v5 24/31] ntfs: serialize and report export parent reconstruction errors Xuewen Wang
2026-11-02  7:35 ` [PATCH v5 25/31] ntfs: report MFT record validation and lifecycle errors Xuewen Wang
2026-11-02  7:35 ` [PATCH v5 26/31] ntfs: report MFT bitmap and data growth recovery failures Xuewen Wang
2026-11-02  7:35 ` [PATCH v5 27/31] ntfs: report MFT writeback errors to fsnotify Xuewen Wang
2026-11-02  7:35 ` [PATCH v5 28/31] ntfs: report EA metadata and restoration errors Xuewen Wang
2026-11-02  7:35 ` [PATCH v5 29/31] ntfs: report named stream metadata and recovery errors Xuewen Wang
2026-11-02  7:35 ` [PATCH v5 30/31] ntfs: report reparse and object ID metadata errors Xuewen Wang
2026-11-02  7:35 ` [PATCH v5 31/31] ntfs: report each shutdown transition once Xuewen Wang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261102073532.98873-3-wangxuewen_ky@163.com \
    --to=wangxuewen_ky@163.com \
    --cc=hyc.lee@gmail.com \
    --cc=linkinjeon@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=liubaolin@kylinos.cn \
    --cc=ntfs@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®