errseq_t: split the ERRSEQ_SEEN flag into two
Subsystems (6)
Jeff Layton
maintainerRFC PATCH 1/1 errseq_t: split the ERRSEQ_SEEN flag into two
NFS wants to use the errseq_t mechanism to detect errors that occur during a write, but for that use-case we want to ignore anything that happened before the sample point.
This points out a problem with the current errseq_t implementation. The SEEN flag is overloaded:
- errseq_set uses it to tell when it can skip incrementing the value
- errseq_sample uses it to tell when there are unseen errors
When sampling for the NFS write usecase, we need to set the former without setting the latter.
Carve a new flag bit out of the counter as an ERRSEQ_MUST_INC flag, and have errseq_set check for that instead of ERRSEQ_SEEN. Add a new errseq_sample_new function that will set this bit, and filemap_sample_new_wb_err wrapper that NFS can call from its write codepath.
This reduces the max size of the errseq_t counter from 512k to 256k, but I believe that's an acceptable tradeoff here, as it further clarifies the meaning of the flags.
--- fs/nfs/file.c | 2 +- include/linux/errseq.h | 14 ++++++++++ include/linux/pagemap.h | 18 +++++++++++- lib/errseq.c | 62 +++++++++++++++++++++++++++++++---------- 4 files changed, 79 insertions(+), 17 deletions(-)
This patch fixes the issue where an unseen writeback error prior to the file being opened is reported on write(). It does _not_ make any material difference to Chris' testcase however, because NFS will still report the error on close(), so the second "tee" call will still fail due to the writeback error.
To _really_ fix that testcase, I think we'd need both this patch and to make NFS stop reporting writeback errors at close() (which is something problematic and not required by POSIX).
Thoughts?
fs/nfs/file.c +1 -1
@@ -643,7 +643,7 @@ ssize_t nfs_file_write(struct kiocb *iocb, struct iov_iter *from)nfs_clear_invalid_mapping (file->f_mapping); - since =filemap_sample_wb_err (file->f_mapping); + since =filemap_sample_new_wb_err (file->f_mapping);nfs_start_io_write (inode); result =generic_write_checks (iocb, from);if (result >0 ) {
include/linux/errseq.h +14 -0
@@ -7,8 +7,22 @@typedef u32 errseq_t ; +/** +* errseq_fetch - Grab the current errseq_t value +* @eseq: Pointer to errseq_t to peek +* +* Grab the current errseq_t value and return it. This value is OK +* to use as a "since" value later, as long as you don't care about +* unseen errors that happened before this point. +*/ +static inline errseq_t errseq_fetch (errseq_t *eseq) +{ +return READ_ONCE (*eseq); +} +errseq_t errseq_set (errseq_t *eseq,int err);errseq_t errseq_sample (errseq_t *eseq); +errseq_t errseq_sample_new (errseq_t *eseq);int errseq_check (errseq_t *eseq,errseq_t since);int errseq_check_and_advance (errseq_t *eseq,errseq_t *since);#endif
include/linux/pagemap.h +17 -1
@@ -102,13 +102,29 @@ static inline int filemap_check_wb_err(struct address_space *mapping,* @mapping: mapping to be sampled * * Writeback errors are always reported relative to a particular sample point -* in the past. This function provides those sample points. +* in the past. This function provides those sample points. In the event that +* there are unseen errors at the time of the sample, they will be reported +* during the next check. */ static inline errseq_t filemap_sample_wb_err (struct address_space *mapping) {return errseq_sample (&mapping->wb_err); } +/** +* filemap_peek_wb_err - peek at the current errseq_t to test for later errors +* @mapping: mapping to peek +* +* Writeback errors are always reported relative to a particular sample point +* in the past. This function provides those such sample points. If there are +* unseen errors present at the time of the sample, then they will be ignored +* in later checks. +*/ +static inline errseq_t filemap_sample_new_wb_err (struct address_space *mapping) +{ +return errseq_sample_new (&mapping->wb_err); +} +/** * file_sample_sb_err - sample the current errseq_t to test for later errors * @file: file pointer to be sampled
lib/errseq.c +47 -15
122 lines not on this page · raw message
Signature · 1 line
2.40.1