In a later patch, nfsd is going to need to to fetch the current errseq_t value for its write verifiers. Ordinarily, we'd use errseq_sample, but in the event that the value hasn't been SEEN, we don't want to return a 0. Resurrect the old errseq_sample routine (before Willy fixed it) and rechristen it as errseq_fetch. Cc: Matthew Wilcox <willy@xxxxxxxxxxxxx> Signed-off-by: Jeff Layton <jlayton@xxxxxxxxxx> --- include/linux/errseq.h | 1 + lib/errseq.c | 33 ++++++++++++++++++++++++++++++++- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/include/linux/errseq.h b/include/linux/errseq.h index fc2777770768..13a731236c9b 100644 --- a/include/linux/errseq.h +++ b/include/linux/errseq.h @@ -9,6 +9,7 @@ typedef u32 errseq_t; errseq_t errseq_set(errseq_t *eseq, int err); errseq_t errseq_sample(errseq_t *eseq); +errseq_t errseq_fetch(errseq_t *eseq); int errseq_check(errseq_t *eseq, errseq_t since); int errseq_check_and_advance(errseq_t *eseq, errseq_t *since); #endif diff --git a/lib/errseq.c b/lib/errseq.c index 93e9b94358dc..f243b7dc36f5 100644 --- a/lib/errseq.c +++ b/lib/errseq.c @@ -109,7 +109,7 @@ errseq_t errseq_set(errseq_t *eseq, int err) EXPORT_SYMBOL(errseq_set); /** - * errseq_sample() - Grab current errseq_t value. + * errseq_sample() - Grab current errseq_t value (or 0 if it's unseen) * @eseq: Pointer to errseq_t to be sampled. * * This function allows callers to initialise their errseq_t variable. @@ -131,6 +131,37 @@ errseq_t errseq_sample(errseq_t *eseq) } EXPORT_SYMBOL(errseq_sample); +/** + * errseq_fetch() - Grab current errseq_t value + * @eseq: Pointer to errseq_t to be sampled. + * + * This function grabs the current errseq_t value, and returns it, + * and marks the value as SEEN. This differs from a "sample" in that we + * grab the actual value even if it has not been seen before (instead of + * returning 0 in that case). + * + * Context: Any context. + * Return: The current errseq value. + */ +errseq_t errseq_fetch(errseq_t *eseq) +{ + errseq_t old = READ_ONCE(*eseq); + errseq_t new = old; + + /* + * For the common case of no errors ever having been set, we can skip + * marking the SEEN bit. Once an error has been set, the value will + * never go back to zero. + */ + if (old != 0) { + new |= ERRSEQ_SEEN; + if (old != new) + cmpxchg(eseq, old, new); + } + return new; +} +EXPORT_SYMBOL(errseq_fetch); + /** * errseq_check() - Has an error occurred since a particular sample point? * @eseq: Pointer to errseq_t value to be checked. -- 2.39.1