[PATCH v6 06/37] ntfs: preserve compressed I/O preparation errors

From: Xuewen Wang

Date: Wed Nov 18 2026 - 04:08:29 EST


From: Xuewen Wang <wangxuewen@xxxxxxxxxx>

Compressed reads discard compression-buffer allocation and runlist mapping
errors at cleanup, returning EIO instead. Compressed writes also replace
mapping-pairs update errors with EIO.

Save allocation and mapping results before cleanup and return the original
errno. Keep EIO for an invalid runlist result with no more specific error,
and preserve the result of updating mapping pairs after compressed writes.

Reviewed-by: Baolin Liu <liubaolin@xxxxxxxxxx>
Signed-off-by: Xuewen Wang <wangxuewen@xxxxxxxxxx>
---
Changes in v6:
Extract compressed I/O errno propagation from v5 patch 10.

Validation:
- Compiled and linked the NTFS module object with W=1 at this stage.
- No undefined references to ntfs_report_* or fserror_report_*.

fs/ntfs/compress.c | 14 ++++++++------
1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/fs/ntfs/compress.c b/fs/ntfs/compress.c
index 82c7c7d29073..6a393e7fc1dd 100644
--- a/fs/ntfs/compress.c
+++ b/fs/ntfs/compress.c
@@ -585,11 +585,13 @@ int ntfs_read_compressed_block(struct folio *folio)
nr_cbs--;

mutex_lock(&ntfs_cb_lock);
- if (!ntfs_compression_buffer)
- if (allocate_compression_buffers()) {
+ if (!ntfs_compression_buffer) {
+ err = allocate_compression_buffers();
+ if (err) {
mutex_unlock(&ntfs_cb_lock);
goto err_out;
}
+ }


cb = ntfs_compression_buffer;
@@ -633,7 +635,8 @@ int ntfs_read_compressed_block(struct folio *folio)
* duration.
*/
up_read(&ni->runlist.lock);
- if (!ntfs_map_runlist(ni, vcn))
+ err = ntfs_map_runlist(ni, vcn);
+ if (!err)
goto lock_retry_remap;
mutex_unlock(&ntfs_cb_lock);
goto map_rl_err;
@@ -839,6 +842,7 @@ int ntfs_read_compressed_block(struct folio *folio)
goto err_out;

rl_err:
+ err = -EIO;
up_read(&ni->runlist.lock);
ntfs_error(vol->sb, "ntfs_rl_vcn_to_lcn() failed. Cannot read compression block.");
goto err_out;
@@ -859,7 +863,7 @@ int ntfs_read_compressed_block(struct folio *folio)
}
kfree(pages);
kfree(completed_pages);
- return -EIO;
+ return err;
}

/*
@@ -1452,8 +1456,6 @@ static int ntfs_write_cb(struct ntfs_inode *ni, loff_t pos, struct page **pages,

err = ntfs_attr_update_mapping_pairs_locked(ni, 0, ni);
up_write(&ni->runlist.lock);
- if (err)
- err = -EIO;
goto out;

free_rlc:
--
2.51.0