[PATCH 2/3] ntfs: wake free-cluster waiters when precalc allocation fails

From: DaeMyung Kang

Date: Wed May 20 2026 - 13:31:59 EST


get_nr_free_clusters() is run from the precalc_free_clusters() worker
queued at the end of ntfs_fill_super(). It is also the only place that
publishes the result by atomic64_set(&vol->free_clusters, ...), sets
NVolSetFreeClusterKnown(), and wakes vol->free_waitq.

The initial kzalloc(sizeof(*ra), ...) can fail before that publication
happens. Callers that need the free count wait on NVolFreeClusterKnown(),
so this failure can leave statfs, write, and allocation paths blocked
forever.

On the OOM path, publish a conservative free count of zero, initialize
the per-bitmap-page free counters to zero, set NVolFreeClusterKnown, and
wake the wait queue so callers fail with -ENOSPC rather than block
forever.

Signed-off-by: DaeMyung Kang <charsyam@xxxxxxxxx>
---
super.c | 17 ++++++++++++++++-
1 file changed, 16 insertions(+), 1 deletion(-)

diff --git a/super.c b/super.c
index 6cf09bbe017d..c90cb5673f98 100644
--- a/super.c
+++ b/super.c
@@ -1980,8 +1980,23 @@ s64 get_nr_free_clusters(struct ntfs_volume *vol)
return atomic64_read(&vol->free_clusters);

ra = kzalloc(sizeof(*ra), GFP_NOFS);
- if (!ra)
+ if (!ra) {
+ max_index = (((vol->nr_clusters + 7) >> 3) +
+ PAGE_SIZE - 1) >> PAGE_SHIFT;
+
+ /*
+ * Publish a conservative free count and wake any waiters; the
+ * NVolFreeClusterKnown flag is the sole signal the wait_event
+ * loops in statfs/allocation paths use, so failing to set it
+ * here would leave those callers blocked forever.
+ */
+ memset(vol->lcn_empty_bits_per_page, 0,
+ max_index * sizeof(*vol->lcn_empty_bits_per_page));
+ atomic64_set(&vol->free_clusters, 0);
+ NVolSetFreeClusterKnown(vol);
+ wake_up_all(&vol->free_waitq);
return 0;
+ }

file_ra_state_init(ra, mapping);

--
2.43.0