fs/ntfs3: prevent positive E_NTFS_NONRESIDENT from reaching writeback error handling
Subsystems (2)
RFC PATCH 1/1 fs/ntfs3: prevent positive E_NTFS_NONRESIDENT from reaching writeback error handling
attr_data_write_resident() returns the internal positive status code E_NTFS_NONRESIDENT when the DATA attribute becomes non-resident. ntfs_writepages() propagates this value into generic writeback error handling, which expects a standard negative errno and triggers WARN_ON_ONCE(err > 0).
Translate positive E_NTFS_* status codes to -EIO before recording the writeback error. This prevents positive internal status codes from reaching generic writeback code while preserving the existing behaviour of treating this path as a writeback error.
---
RFC:
I'd appreciate guidance on whether -EIO is the appropriate errno here.
E_NTFS_NONRESIDENT indicates that the DATA attribute became non-resident during writeback. Translating it to -EIO prevents the positive internal status code from reaching generic writeback code and preserves the existing behaviour of treating this path as a writeback error.
However, if the intended behaviour is to retry the write using the non-resident path instead of failing it, then the correct solution would be more than a simple errno translation. The proposed change assumes the current terminal-error behaviour is intentional.
fs/ntfs3/inode.c | 9 +++++++++ 1 file changed, 9 insertions(+)
fs/ntfs3/inode.c +9 -0
@@ -1019,6 +1019,15 @@ static int ntfs_writepages(struct address_space *mapping,folio_unlock (folio);if (err2) { +/* +* attr_data_write_resident() can return the +* positive internal code E_NTFS_NONRESIDENT; +* both mapping_set_error() and writeback_iter() +* need a negative errno and warn on a positive +* value. +*/ +if (err2 >0 ) + err2 = -EIO ;mapping_set_error (mapping, err2);if (!err) err = err2;
base-commit: a13c140cc289c0b7b3770bce5b3ad42ab35074aa
Signature · 1 line
2.53.0
Quoted 10 lines · Vidhu Sarwal
attr_data_write_resident()returns the internal positive status codeE_NTFS_NONRESIDENTwhen the DATA attribute becomes non-resident.ntfs_writepages()propagates this value into generic writeback error handling, which expects a standard negative errno and triggersWARN_ON_ONCE(err > 0).Translate positive E_NTFS_* status codes to
-EIObefore recording the writeback error. This prevents positive internal status codes from reaching generic writeback code while preserving the existing behaviour of treating this path as a writeback error.
Should attr_data_write_resident() be returning positive values on error? If this is correct, and this is a matter of data corruption you can use EFSCORRUPTED (EIO may also be fine if this is what NTFS uses in other places).
Thanks,
Jori.
Quoted 47 lines
Reported-by [email protected]Signed-off-by Vidhu Sarwal <[email protected]>---
RFC:I'd appreciate guidance on whether
-EIOis the appropriate errno here.
E_NTFS_NONRESIDENTindicates that the DATA attribute became non-resident during writeback. Translating it to-EIOprevents the positive internal status code from reaching generic writeback code and preserves the existing behaviour of treating this path as a writeback error.However, if the intended behaviour is to retry the write using the non-resident path instead of failing it, then the correct solution would be more than a simple errno translation. The proposed change assumes the current terminal-error behaviour is intentional.
fs/ntfs3/inode.c | 9 +++++++++ 1 file changed, 9 insertions(+)fs/ntfs3/inode.c +9
-0@@ -1019,6 +1019,15 @@ static int ntfs_writepages(struct address_space *mapping,folio_unlock (folio);if (err2) { +/* +* attr_data_write_resident() can return the +* positive internal code E_NTFS_NONRESIDENT; +* both mapping_set_error() and writeback_iter() +* need a negative errno and warn on a positive +* value. +*/ +if (err2 >0 ) + err2 = -EIO ;mapping_set_error (mapping, err2);if (!err) err = err2;base-commit:
a13c140cc289c0b7b3770bce5b3ad42ab35074aaSignature · 1 line
2.53.0
Quoted 5 lines · Jori Koolstra
Should
attr_data_write_resident()be returning positive values on error? If this is correct, and this is a matter of data corruption you can use EFSCORRUPTED (EIO may also be fine if this is what NTFS uses in other places).
Yes. attr_data_write_resident() intentionally returns the positive internal status code E_NTFS_NONRESIDENT when it detects that the DATA attribute has become non-resident. This is an ntfs3 specific used internally to signal the transition rather than a standard errno.
The issue is that ntfs_writepages() propagates this internal status into the generic writeback error handling without translating it first. The MM writeback code expects either 0 or a negative errno, so the positive value triggers the WARN_ON_ONCE(*error > 0).
I chose -EIO because this is not filesystem metadata corruption. The race is between is_resident() and attr_make_nonresident(), leaving the filesystem in a valid state but causing an internal status code to escape outside ntfs3. I think EFSCORRUPTED would imply metadata corruption, which didnt happen here.
Thanks,
Vidhu
Konstantin Komarov
maintainerQuoted 53 lines · Vidhu Sarwal
attr_data_write_resident()returns the internal positive status codeE_NTFS_NONRESIDENTwhen the DATA attribute becomes non-resident.ntfs_writepages()propagates this value into generic writeback error handling, which expects a standard negative errno and triggersWARN_ON_ONCE(err > 0).Translate positive E_NTFS_* status codes to
-EIObefore recording the writeback error. This prevents positive internal status codes from reaching generic writeback code while preserving the existing behaviour of treating this path as a writeback error.Reported-by [email protected]Signed-off-by Vidhu Sarwal <[email protected]>---
RFC:I'd appreciate guidance on whether
-EIOis the appropriate errno here.
E_NTFS_NONRESIDENTindicates that the DATA attribute became non-resident during writeback. Translating it to-EIOprevents the positive internal status code from reaching generic writeback code and preserves the existing behaviour of treating this path as a writeback error.However, if the intended behaviour is to retry the write using the non-resident path instead of failing it, then the correct solution would be more than a simple errno translation. The proposed change assumes the current terminal-error behaviour is intentional.
fs/ntfs3/inode.c | 9 +++++++++ 1 file changed, 9 insertions(+)fs/ntfs3/inode.c +9
-0@@ -1019,6 +1019,15 @@ static int ntfs_writepages(struct address_space *mapping,folio_unlock (folio);if (err2) { +/* +* attr_data_write_resident() can return the +* positive internal code E_NTFS_NONRESIDENT; +* both mapping_set_error() and writeback_iter() +* need a negative errno and warn on a positive +* value. +*/ +if (err2 >0 ) + err2 = -EIO ;mapping_set_error (mapping, err2);if (!err) err = err2;
Quoted 3 lines
base-commit:
a13c140cc289c0b7b3770bce5b3ad42ab35074aa--
2.53.0
Hello,
Sorry for the delay.
Your patch was applied, thanks.
Regards,
Konstantin