]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - releases/4.14.40/errseq-always-report-a-writeback-error-once.patch
Linux 4.14.95
[thirdparty/kernel/stable-queue.git] / releases / 4.14.40 / errseq-always-report-a-writeback-error-once.patch
1 From b4678df184b314a2bd47d2329feca2c2534aa12b Mon Sep 17 00:00:00 2001
2 From: Matthew Wilcox <willy@infradead.org>
3 Date: Tue, 24 Apr 2018 14:02:57 -0700
4 Subject: errseq: Always report a writeback error once
5
6 From: Matthew Wilcox <willy@infradead.org>
7
8 commit b4678df184b314a2bd47d2329feca2c2534aa12b upstream.
9
10 The errseq_t infrastructure assumes that errors which occurred before
11 the file descriptor was opened are of no interest to the application.
12 This turns out to be a regression for some applications, notably Postgres.
13
14 Before errseq_t, a writeback error would be reported exactly once (as
15 long as the inode remained in memory), so Postgres could open a file,
16 call fsync() and find out whether there had been a writeback error on
17 that file from another process.
18
19 This patch changes the errseq infrastructure to report errors to all
20 file descriptors which are opened after the error occurred, but before
21 it was reported to any file descriptor. This restores the user-visible
22 behaviour.
23
24 Cc: stable@vger.kernel.org
25 Fixes: 5660e13d2fd6 ("fs: new infrastructure for writeback error handling and reporting")
26 Signed-off-by: Matthew Wilcox <mawilcox@microsoft.com>
27 Reviewed-by: Jeff Layton <jlayton@kernel.org>
28 Signed-off-by: Jeff Layton <jlayton@redhat.com>
29 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
30
31 ---
32 lib/errseq.c | 25 +++++++++++--------------
33 1 file changed, 11 insertions(+), 14 deletions(-)
34
35 --- a/lib/errseq.c
36 +++ b/lib/errseq.c
37 @@ -111,25 +111,22 @@ EXPORT_SYMBOL(errseq_set);
38 * errseq_sample - grab current errseq_t value
39 * @eseq: pointer to errseq_t to be sampled
40 *
41 - * This function allows callers to sample an errseq_t value, marking it as
42 - * "seen" if required.
43 + * This function allows callers to initialise their errseq_t variable.
44 + * If the error has been "seen", new callers will not see an old error.
45 + * If there is an unseen error in @eseq, the caller of this function will
46 + * see it the next time it checks for an error.
47 + *
48 + * Context: Any context.
49 + * Return: The current errseq value.
50 */
51 errseq_t errseq_sample(errseq_t *eseq)
52 {
53 errseq_t old = READ_ONCE(*eseq);
54 - errseq_t new = old;
55
56 - /*
57 - * For the common case of no errors ever having been set, we can skip
58 - * marking the SEEN bit. Once an error has been set, the value will
59 - * never go back to zero.
60 - */
61 - if (old != 0) {
62 - new |= ERRSEQ_SEEN;
63 - if (old != new)
64 - cmpxchg(eseq, old, new);
65 - }
66 - return new;
67 + /* If nobody has seen this error yet, then we can be the first. */
68 + if (!(old & ERRSEQ_SEEN))
69 + old = 0;
70 + return old;
71 }
72 EXPORT_SYMBOL(errseq_sample);
73