Skip to contentSkip to conversation

errseq+overlayfs: accomodate the volatile upper layer use-case

RFC PATCH Superseded Jeff Layton 7 participants 20 messages Dec 13, 2020 – Dec 17, 2020

Subsystems (4)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Jeff Layton

author maintainer
#0 lore raw

cover errseq+overlayfs: accomodate the volatile upper layer use-case

What about this as an alternate approach to the problem that Sargun has been working on? I have some minor concerns about the complexity of managing a stateful object across two different words. That can be done, but I think this may be simpler.

This set steals an extra flag bit from the errseq_t counter so that we have two flags: one indicating whether to increment the counter at set time, and another to indicate whether the error has been reported to userland.

This should give you the semantics you want in the syncfs case, no? If this does look like it's a suitable approach, then I'll plan to clean up the comments and docs.

I have a vague feeling that this might help us eventually kill the AS_EIO and AS_ENOSPC bits too, but that would require a bit more work to plumb in "since" samples at appropriate places.

Jeff Layton (2):
errseq: split the SEEN flag into two new flags
overlayfs: propagate errors from upper to overlay sb in sync_fs

 fs/overlayfs/ovl_entry.h |  1 +
 fs/overlayfs/super.c     | 14 +++++++--
 include/linux/errseq.h   |  2 ++
 lib/errseq.c             | 64 +++++++++++++++++++++++++++++++++-------
 4 files changed, 67 insertions(+), 14 deletions(-)
Signature · 1 line
2.29.2
author maintainer
#1 lore raw

RFC PATCH 1/2 errseq: split the SEEN flag into two new flags

Overlayfs's volatile mounts want to be able to sample an error for their own purposes, without preventing a later opener from potentially seeing the error.

The original reason for the SEEN flag was to make it so that we didn't need to increment the counter if nothing had observed the latest value and the error was the same. Eventually, a regression was reported in the errseq_t conversion, and we fixed that by using the SEEN flag to also mean that the error had been reported to userland at least once somewhere.

Those are two different states, however. If we instead take a second flag bit from the counter, we can track these two things separately, and accomodate the overlayfs volatile mount use-case.

Add a new MUSTINC flag that indicates that the counter must be incremented the next time an error is set, and rework the errseq functions to set and clear that flag whenever the SEEN bit is set or cleared.

Test only for the MUSTINC bit when deciding whether to increment the counter and only for the SEEN bit when deciding what to return in errseq_sample.

Add a new errseq_peek function to allow for the overlayfs use-case. This just grabs the latest counter and sets the MUSTINC bit, leaving the SEEN bit untouched.

---
 include/linux/errseq.h |  2 ++
 lib/errseq.c           | 64 ++++++++++++++++++++++++++++++++++--------
 2 files changed, 55 insertions(+), 11 deletions(-)
include/linux/errseq.h +2 -0
index fc2777770768..6d4b9bc629ac 100644
@@ -9,6 +9,8 @@ typedef u32	errseq_t;
 
 errseq_t errseq_set(errseq_t *eseq, int err);
 errseq_t errseq_sample(errseq_t *eseq);
+errseq_t errseq_peek(errseq_t *eseq);
+errseq_t errseq_sample_advance(errseq_t *eseq);
 int errseq_check(errseq_t *eseq, errseq_t since);
 int errseq_check_and_advance(errseq_t *eseq, errseq_t *since);
 #endif
lib/errseq.c +53 -11

100 lines not on this page · raw message

Signature · 1 line
2.29.2
#2 lore raw

Re: [RFC PATCH 1/2] errseq: split the SEEN flag into two new flags

Quoted 52 lines · Jeff Layton

Overlayfs's volatile mounts want to be able to sample an error for their own purposes, without preventing a later opener from potentially seeing the error.

The original reason for the SEEN flag was to make it so that we didn't need to increment the counter if nothing had observed the latest value and the error was the same. Eventually, a regression was reported in the errseq_t conversion, and we fixed that by using the SEEN flag to also mean that the error had been reported to userland at least once somewhere.

Those are two different states, however. If we instead take a second flag bit from the counter, we can track these two things separately, and accomodate the overlayfs volatile mount use-case.

Add a new MUSTINC flag that indicates that the counter must be incremented the next time an error is set, and rework the errseq functions to set and clear that flag whenever the SEEN bit is set or cleared.

Test only for the MUSTINC bit when deciding whether to increment the counter and only for the SEEN bit when deciding what to return in errseq_sample.

Add a new errseq_peek function to allow for the overlayfs use-case. This just grabs the latest counter and sets the MUSTINC bit, leaving the SEEN bit untouched.

---
 include/linux/errseq.h |  2 ++
 lib/errseq.c           | 64 ++++++++++++++++++++++++++++++++++--------
 2 files changed, 55 insertions(+), 11 deletions(-)
include/linux/errseq.h +2 -0
index fc2777770768..6d4b9bc629ac 100644
@@ -9,6 +9,8 @@ typedef u32	errseq_t;
 
 errseq_t errseq_set(errseq_t *eseq, int err);
 errseq_t errseq_sample(errseq_t *eseq);
+errseq_t errseq_peek(errseq_t *eseq);
+errseq_t errseq_sample_advance(errseq_t *eseq);
 int errseq_check(errseq_t *eseq, errseq_t since);
 int errseq_check_and_advance(errseq_t *eseq, errseq_t *since);
 #endif
lib/errseq.c +0 -0
index 81f9e33aa7e7..5cc830f0361b 100644

lib/errseq.c line 39

Quoted 2 lines
lib/errseq.c +0 -0
@@ -38,8 +38,11 @@
 /* This bit is used as a flag to indicate whether the value has been seen */
 #define ERRSEQ_SEEN		(1 << ERRSEQ_SHIFT)

Would this look nicer using the BIT() macro?

  #define ERRSEQ_SEEN		BIT(ERRSEQ_SHIFT)

lib/errseq.c line 42

Quoted 3 lines
lib/errseq.c +2 -0
+/* This bit indicates that value must be incremented even when error is same */
+#define ERRSEQ_MUSTINC		(1 << (ERRSEQ_SHIFT + 1))

#define ERRSEQ_MUSTINC BIT(ERRSEQ_SHIFT+1)

or if you don't like the BIT macro (not everyone does), then maybe

#define ERR_SEQ_MUSTINC (ERRSEQ_SEEN << 1 )

??

lib/errseq.c line 45

Quoted 4 lines
lib/errseq.c +2 -1
+
 /* The lowest bit of the counter */
-#define ERRSEQ_CTR_INC		(1 << (ERRSEQ_SHIFT + 1))
+#define ERRSEQ_CTR_INC		(1 << (ERRSEQ_SHIFT + 2))

Ditto.

lib/errseq.c errseq_t errseq_set(errseq_t *eseq, int err) · line 84

Quoted 11 lines
lib/errseq.c +2 -2
 /**
  * errseq_set - set a errseq_t for later reporting
@@ -77,11 +80,11 @@ errseq_t errseq_set(errseq_t *eseq, int err)
 	for (;;) {
 		errseq_t new;
 
-		/* Clear out error bits and set new error */
-		new = (old & ~(MAX_ERRNO|ERRSEQ_SEEN)) | -err;
+		/* Clear out flag bits and set new error */
+		new = (old & ~(MAX_ERRNO|ERRSEQ_SEEN|ERRSEQ_MUSTINC)) | -err;

This is starting to look clumsy (or maybe, this already looked clumsy, but now that is hard to ignore).

		new = (old & (ERRSEQ_CTR_INC - 1)) | -err

Also this assumes MAX_ERRNO is a mask, which it is .. today.

	BUILD_BUG_ON(MAX_ERRNO & (MAX_ERRNO + 1));

??

Quoted 15 lines
lib/errseq.c +3 -3
-		/* Only increment if someone has looked at it */
-		if (old & ERRSEQ_SEEN)
+		/* Only increment if we have to */
+		if (old & ERRSEQ_MUSTINC)
 			new += ERRSEQ_CTR_INC;
 
 		/* If there would be no change, then call it done */
@@ -122,14 +125,50 @@ EXPORT_SYMBOL(errseq_set);
 errseq_t errseq_sample(errseq_t *eseq)
 {
 	errseq_t old = READ_ONCE(*eseq);
+	errseq_t new = old;
 
-	/* If nobody has seen this error yet, then we can be the first. */

lib/errseq.c EXPORT_SYMBOL(errseq_set); · line 136

Quoted 10 lines
lib/errseq.c +7 -3
-	if (!(old & ERRSEQ_SEEN))
-		old = 0;
-	return old;
+	/*
+	 * For the common case of no errors ever having been set, we can skip
+	 * marking the SEEN|MUSTINC bits. Once an error has been set, the value
+	 * will never go back to zero.
+	 */
+	if (old != 0) {
+		new |= ERRSEQ_SEEN|ERRSEQ_MUSTINC;

You lose me here. Why is ERRSEQ_SEEN being set, where it wasn't before?

The ERRSEQ_SEEN flag not means precisely "The error has been reported to userspace".
This operations isn't used to report errors - that is errseq_check().

I'm not saying the code it wrong - I really cannot tell. I'm just saying that I cannot see why it might be right.

Thanks,
NeilBrown

Quoted 61 lines
lib/errseq.c +37 -2
+		if (old != new)
+			cmpxchg(eseq, old, new);
+		if (!(old & ERRSEQ_SEEN))
+			return 0;
+	}
+	return new;
 }
 EXPORT_SYMBOL(errseq_sample);
 
+/**
+ * errseq_peek - Grab current errseq_t value, but don't mark it SEEN
+ * @eseq: Pointer to errseq_t to be sampled.
+ *
+ * In some cases, we need to be able to sample the errseq_t, but we're not
+ * in a situation where we can report the value to userland. Use this
+ * function to do that. This ensures that later errors will be recorded,
+ * and that any current errors are reported at least once.
+ *
+ * Context: Any context.
+ * Return: The current errseq value.
+ */
+errseq_t errseq_peek(errseq_t *eseq)
+{
+	errseq_t old = READ_ONCE(*eseq);
+	errseq_t new = old;
+
+	if (old != 0) {
+		new |= ERRSEQ_MUSTINC;
+		if (old != new)
+			cmpxchg(eseq, old, new);
+	}
+	return new;
+}
+EXPORT_SYMBOL(errseq_peek);
+
 /**
  * errseq_check() - Has an error occurred since a particular sample point?
  * @eseq: Pointer to errseq_t value to be checked.
@@ -143,7 +182,10 @@ EXPORT_SYMBOL(errseq_sample);
  */
 int errseq_check(errseq_t *eseq, errseq_t since)
 {
-	errseq_t cur = READ_ONCE(*eseq);
+	errseq_t cur = READ_ONCE(*eseq) & ~(ERRSEQ_MUSTINC|ERRSEQ_SEEN);
+
+	/* Clear the flag bits for comparison */
+	since &= ~(ERRSEQ_MUSTINC|ERRSEQ_SEEN);
 
 	if (likely(cur == since))
 		return 0;
@@ -195,7 +237,7 @@ int errseq_check_and_advance(errseq_t *eseq, errseq_t *since)
 		 * can advance "since" and return an error based on what we
 		 * have.
 		 */
-		new = old | ERRSEQ_SEEN;
+		new = old | ERRSEQ_SEEN | ERRSEQ_MUSTINC;
 		if (new != old)
 			cmpxchg(eseq, old, new);
 		*since = new;
Signature · 1 line
2.29.2
#3 lore raw

Re: [RFC PATCH 1/2] errseq: split the SEEN flag into two new flags

Quoted 71 lines · NeilBrown
Quoted 52 lines · Jeff Layton

Overlayfs's volatile mounts want to be able to sample an error for their own purposes, without preventing a later opener from potentially seeing the error.

The original reason for the SEEN flag was to make it so that we didn't need to increment the counter if nothing had observed the latest value and the error was the same. Eventually, a regression was reported in the errseq_t conversion, and we fixed that by using the SEEN flag to also mean that the error had been reported to userland at least once somewhere.

Those are two different states, however. If we instead take a second flag bit from the counter, we can track these two things separately, and accomodate the overlayfs volatile mount use-case.

Add a new MUSTINC flag that indicates that the counter must be incremented the next time an error is set, and rework the errseq functions to set and clear that flag whenever the SEEN bit is set or cleared.

Test only for the MUSTINC bit when deciding whether to increment the counter and only for the SEEN bit when deciding what to return in errseq_sample.

Add a new errseq_peek function to allow for the overlayfs use-case. This just grabs the latest counter and sets the MUSTINC bit, leaving the SEEN bit untouched.

---
 include/linux/errseq.h |  2 ++
 lib/errseq.c           | 64 ++++++++++++++++++++++++++++++++++--------
 2 files changed, 55 insertions(+), 11 deletions(-)
include/linux/errseq.h +2 -0
index fc2777770768..6d4b9bc629ac 100644
@@ -9,6 +9,8 @@ typedef u32	errseq_t;
 
 errseq_t errseq_set(errseq_t *eseq, int err);
 errseq_t errseq_sample(errseq_t *eseq);
+errseq_t errseq_peek(errseq_t *eseq);
+errseq_t errseq_sample_advance(errseq_t *eseq);
 int errseq_check(errseq_t *eseq, errseq_t since);
 int errseq_check_and_advance(errseq_t *eseq, errseq_t *since);
 #endif
lib/errseq.c +0 -0
index 81f9e33aa7e7..5cc830f0361b 100644

lib/errseq.c line 39

Quoted 2 lines
lib/errseq.c +0 -0
@@ -38,8 +38,11 @@
 /* This bit is used as a flag to indicate whether the value has been seen */
 #define ERRSEQ_SEEN		(1 << ERRSEQ_SHIFT)

Would this look nicer using the BIT() macro?

  #define ERRSEQ_SEEN		BIT(ERRSEQ_SHIFT)

lib/errseq.c line 42

Quoted 3 lines
lib/errseq.c +2 -0
+/* This bit indicates that value must be incremented even when error is same */
+#define ERRSEQ_MUSTINC		(1 << (ERRSEQ_SHIFT + 1))

#define ERRSEQ_MUSTINC BIT(ERRSEQ_SHIFT+1)

or if you don't like the BIT macro (not everyone does), then maybe

#define ERR_SEQ_MUSTINC (ERRSEQ_SEEN << 1 )

Quoted 9 lines

??

lib/errseq.c line 45

Quoted 4 lines
lib/errseq.c +2 -1
+
 /* The lowest bit of the counter */
-#define ERRSEQ_CTR_INC		(1 << (ERRSEQ_SHIFT + 1))
+#define ERRSEQ_CTR_INC		(1 << (ERRSEQ_SHIFT + 2))

Ditto.

Yes, I can make that change. The BIT macro is much easier to read.

Quoted 15 lines

lib/errseq.c errseq_t errseq_set(errseq_t *eseq, int err) · line 84

Quoted 11 lines
lib/errseq.c +2 -2
 /**
  * errseq_set - set a errseq_t for later reporting
@@ -77,11 +80,11 @@ errseq_t errseq_set(errseq_t *eseq, int err)
 	for (;;) {
 		errseq_t new;
 
-		/* Clear out error bits and set new error */
-		new = (old & ~(MAX_ERRNO|ERRSEQ_SEEN)) | -err;
+		/* Clear out flag bits and set new error */
+		new = (old & ~(MAX_ERRNO|ERRSEQ_SEEN|ERRSEQ_MUSTINC)) | -err;

This is starting to look clumsy (or maybe, this already looked clumsy, but now that is hard to ignore).

Quoted 2 lines
		new = (old & (ERRSEQ_CTR_INC - 1)) | -err

I think you mean:

		new = (old & ~(ERRSEQ_CTR_INC - 1)) | -err;

Maybe I can add a new ERRSEQ_CTR_MASK value though which makes it more evident.

Quoted 5 lines

Also this assumes MAX_ERRNO is a mask, which it is .. today.

	BUILD_BUG_ON(MAX_ERRNO & (MAX_ERRNO + 1));

??

We already have this in errseq_set:

        BUILD_BUG_ON_NOT_POWER_OF_2(MAX_ERRNO + 1);
Quoted 28 lines
Quoted 15 lines
lib/errseq.c +3 -3
-		/* Only increment if someone has looked at it */
-		if (old & ERRSEQ_SEEN)
+		/* Only increment if we have to */
+		if (old & ERRSEQ_MUSTINC)
 			new += ERRSEQ_CTR_INC;
 
 		/* If there would be no change, then call it done */
@@ -122,14 +125,50 @@ EXPORT_SYMBOL(errseq_set);
 errseq_t errseq_sample(errseq_t *eseq)
 {
 	errseq_t old = READ_ONCE(*eseq);
+	errseq_t new = old;
 
-	/* If nobody has seen this error yet, then we can be the first. */

lib/errseq.c EXPORT_SYMBOL(errseq_set); · line 136

Quoted 10 lines
lib/errseq.c +7 -3
-	if (!(old & ERRSEQ_SEEN))
-		old = 0;
-	return old;
+	/*
+	 * For the common case of no errors ever having been set, we can skip
+	 * marking the SEEN|MUSTINC bits. Once an error has been set, the value
+	 * will never go back to zero.
+	 */
+	if (old != 0) {
+		new |= ERRSEQ_SEEN|ERRSEQ_MUSTINC;

You lose me here. Why is ERRSEQ_SEEN being set, where it wasn't before?

Quoted 7 lines

The ERRSEQ_SEEN flag not means precisely "The error has been reported to userspace".
This operations isn't used to report errors - that is errseq_check().

I'm not saying the code it wrong - I really cannot tell. I'm just saying that I cannot see why it might be right.

I think you're right. We should not be setting SEEN here, but we do need to set MUSTINC if it's not already set. I'll fix (and re-test).

Thanks for the review!

Quoted 64 lines
Quoted 64 lines
lib/errseq.c +37 -2
+		if (old != new)
+			cmpxchg(eseq, old, new);
+		if (!(old & ERRSEQ_SEEN))
+			return 0;
+	}
+	return new;
 }
 EXPORT_SYMBOL(errseq_sample);
 
+/**
+ * errseq_peek - Grab current errseq_t value, but don't mark it SEEN
+ * @eseq: Pointer to errseq_t to be sampled.
+ *
+ * In some cases, we need to be able to sample the errseq_t, but we're not
+ * in a situation where we can report the value to userland. Use this
+ * function to do that. This ensures that later errors will be recorded,
+ * and that any current errors are reported at least once.
+ *
+ * Context: Any context.
+ * Return: The current errseq value.
+ */
+errseq_t errseq_peek(errseq_t *eseq)
+{
+	errseq_t old = READ_ONCE(*eseq);
+	errseq_t new = old;
+
+	if (old != 0) {
+		new |= ERRSEQ_MUSTINC;
+		if (old != new)
+			cmpxchg(eseq, old, new);
+	}
+	return new;
+}
+EXPORT_SYMBOL(errseq_peek);
+
 /**
  * errseq_check() - Has an error occurred since a particular sample point?
  * @eseq: Pointer to errseq_t value to be checked.
@@ -143,7 +182,10 @@ EXPORT_SYMBOL(errseq_sample);
  */
 int errseq_check(errseq_t *eseq, errseq_t since)
 {
-	errseq_t cur = READ_ONCE(*eseq);
+	errseq_t cur = READ_ONCE(*eseq) & ~(ERRSEQ_MUSTINC|ERRSEQ_SEEN);
+
+	/* Clear the flag bits for comparison */
+	since &= ~(ERRSEQ_MUSTINC|ERRSEQ_SEEN);
 
 	if (likely(cur == since))
 		return 0;
@@ -195,7 +237,7 @@ int errseq_check_and_advance(errseq_t *eseq, errseq_t *since)
 		 * can advance "since" and return an error based on what we
 		 * have.
 		 */
-		new = old | ERRSEQ_SEEN;
+		new = old | ERRSEQ_SEEN | ERRSEQ_MUSTINC;
 		if (new != old)
 			cmpxchg(eseq, old, new);
 		*since = new;
Signature · 1 line
2.29.2
#4 lore raw

Re: [RFC PATCH 1/2] errseq: split the SEEN flag into two new flags

Quoted 102 lines · Jeffrey Layton
Quoted 71 lines · NeilBrown
Quoted 52 lines · Jeff Layton

Overlayfs's volatile mounts want to be able to sample an error for their own purposes, without preventing a later opener from potentially seeing the error.

The original reason for the SEEN flag was to make it so that we didn't need to increment the counter if nothing had observed the latest value and the error was the same. Eventually, a regression was reported in the errseq_t conversion, and we fixed that by using the SEEN flag to also mean that the error had been reported to userland at least once somewhere.

Those are two different states, however. If we instead take a second flag bit from the counter, we can track these two things separately, and accomodate the overlayfs volatile mount use-case.

Add a new MUSTINC flag that indicates that the counter must be incremented the next time an error is set, and rework the errseq functions to set and clear that flag whenever the SEEN bit is set or cleared.

Test only for the MUSTINC bit when deciding whether to increment the counter and only for the SEEN bit when deciding what to return in errseq_sample.

Add a new errseq_peek function to allow for the overlayfs use-case. This just grabs the latest counter and sets the MUSTINC bit, leaving the SEEN bit untouched.

---
 include/linux/errseq.h |  2 ++
 lib/errseq.c           | 64 ++++++++++++++++++++++++++++++++++--------
 2 files changed, 55 insertions(+), 11 deletions(-)
include/linux/errseq.h +2 -0
index fc2777770768..6d4b9bc629ac 100644
@@ -9,6 +9,8 @@ typedef u32	errseq_t;
 
 errseq_t errseq_set(errseq_t *eseq, int err);
 errseq_t errseq_sample(errseq_t *eseq);
+errseq_t errseq_peek(errseq_t *eseq);
+errseq_t errseq_sample_advance(errseq_t *eseq);
 int errseq_check(errseq_t *eseq, errseq_t since);
 int errseq_check_and_advance(errseq_t *eseq, errseq_t *since);
 #endif
lib/errseq.c +0 -0
index 81f9e33aa7e7..5cc830f0361b 100644

lib/errseq.c line 39

Quoted 2 lines
lib/errseq.c +0 -0
@@ -38,8 +38,11 @@
 /* This bit is used as a flag to indicate whether the value has been seen */
 #define ERRSEQ_SEEN		(1 << ERRSEQ_SHIFT)

Would this look nicer using the BIT() macro?

  #define ERRSEQ_SEEN		BIT(ERRSEQ_SHIFT)

lib/errseq.c line 42

Quoted 3 lines
lib/errseq.c +2 -0
+/* This bit indicates that value must be incremented even when error is same */
+#define ERRSEQ_MUSTINC		(1 << (ERRSEQ_SHIFT + 1))

#define ERRSEQ_MUSTINC BIT(ERRSEQ_SHIFT+1)

or if you don't like the BIT macro (not everyone does), then maybe

#define ERR_SEQ_MUSTINC (ERRSEQ_SEEN << 1 )

Quoted 9 lines

??

lib/errseq.c line 45

Quoted 4 lines
lib/errseq.c +2 -1
+
 /* The lowest bit of the counter */
-#define ERRSEQ_CTR_INC		(1 << (ERRSEQ_SHIFT + 1))
+#define ERRSEQ_CTR_INC		(1 << (ERRSEQ_SHIFT + 2))

Ditto.

Yes, I can make that change. The BIT macro is much easier to read.

Quoted 15 lines

lib/errseq.c errseq_t errseq_set(errseq_t *eseq, int err) · line 84

Quoted 11 lines
lib/errseq.c +2 -2
 /**
  * errseq_set - set a errseq_t for later reporting
@@ -77,11 +80,11 @@ errseq_t errseq_set(errseq_t *eseq, int err)
 	for (;;) {
 		errseq_t new;
 
-		/* Clear out error bits and set new error */
-		new = (old & ~(MAX_ERRNO|ERRSEQ_SEEN)) | -err;
+		/* Clear out flag bits and set new error */
+		new = (old & ~(MAX_ERRNO|ERRSEQ_SEEN|ERRSEQ_MUSTINC)) | -err;

This is starting to look clumsy (or maybe, this already looked clumsy, but now that is hard to ignore).

Quoted 2 lines
		new = (old & (ERRSEQ_CTR_INC - 1)) | -err
Quoted 6 lines

I think you mean:

		new = (old & ~(ERRSEQ_CTR_INC - 1)) | -err;

Maybe I can add a new ERRSEQ_CTR_MASK value though which makes it more evident.

Sounds good.

Quoted 10 lines
Quoted 6 lines

Also this assumes MAX_ERRNO is a mask, which it is .. today.

	BUILD_BUG_ON(MAX_ERRNO & (MAX_ERRNO + 1));

??

We already have this in errseq_set:

        BUILD_BUG_ON_NOT_POWER_OF_2(MAX_ERRNO + 1);

Oh good - I didn't see.

Quoted 33 lines
Quoted 33 lines
Quoted 16 lines
lib/errseq.c +3 -3
-		/* Only increment if someone has looked at it */
-		if (old & ERRSEQ_SEEN)
+		/* Only increment if we have to */
+		if (old & ERRSEQ_MUSTINC)
 			new += ERRSEQ_CTR_INC;
 
 		/* If there would be no change, then call it done */
@@ -122,14 +125,50 @@ EXPORT_SYMBOL(errseq_set);
 errseq_t errseq_sample(errseq_t *eseq)
 {
 	errseq_t old = READ_ONCE(*eseq);
+	errseq_t new = old;
 
-	/* If nobody has seen this error yet, then we can be the first. */

lib/errseq.c EXPORT_SYMBOL(errseq_set); · line 136

Quoted 10 lines
lib/errseq.c +7 -3
-	if (!(old & ERRSEQ_SEEN))
-		old = 0;
-	return old;
+	/*
+	 * For the common case of no errors ever having been set, we can skip
+	 * marking the SEEN|MUSTINC bits. Once an error has been set, the value
+	 * will never go back to zero.
+	 */
+	if (old != 0) {
+		new |= ERRSEQ_SEEN|ERRSEQ_MUSTINC;

You lose me here. Why is ERRSEQ_SEEN being set, where it wasn't before?

The ERRSEQ_SEEN flag not means precisely "The error has been reported to userspace".
This operations isn't used to report errors - that is errseq_check().

Quoted 6 lines
Quoted 3 lines

I'm not saying the code it wrong - I really cannot tell. I'm just saying that I cannot see why it might be right.

I think you're right. We should not be setting SEEN here, but we do need to set MUSTINC if it's not already set. I'll fix (and re-test).

Thanks. Though it isn't clear to me why MUSTINC needs to be set there, so if you could make that clear, it would help me.

Also, the two flags seem similar in how they are handled, only tracking different states, but their names don't reflect that.
I imagine changing "SEEN" to "MUST_REPORT" or similar, so both flags are "MUST_XXX".
Only I think we would then need to invert "SEEN" - as it currently means "MUSTN'T_REPORT" .. approximately.

Or maybe we could replace MUST_INC by DID_INC, so it says what has been done, rather than what must be done.

Or maybe not. Certainly it would be useful to have a clear picture of how the two flags are similar, and how they are different.

Thanks,
NeilBrown

Quoted 67 lines

Thanks for the review!

Quoted 64 lines
Quoted 64 lines
lib/errseq.c +37 -2
+		if (old != new)
+			cmpxchg(eseq, old, new);
+		if (!(old & ERRSEQ_SEEN))
+			return 0;
+	}
+	return new;
 }
 EXPORT_SYMBOL(errseq_sample);
 
+/**
+ * errseq_peek - Grab current errseq_t value, but don't mark it SEEN
+ * @eseq: Pointer to errseq_t to be sampled.
+ *
+ * In some cases, we need to be able to sample the errseq_t, but we're not
+ * in a situation where we can report the value to userland. Use this
+ * function to do that. This ensures that later errors will be recorded,
+ * and that any current errors are reported at least once.
+ *
+ * Context: Any context.
+ * Return: The current errseq value.
+ */
+errseq_t errseq_peek(errseq_t *eseq)
+{
+	errseq_t old = READ_ONCE(*eseq);
+	errseq_t new = old;
+
+	if (old != 0) {
+		new |= ERRSEQ_MUSTINC;
+		if (old != new)
+			cmpxchg(eseq, old, new);
+	}
+	return new;
+}
+EXPORT_SYMBOL(errseq_peek);
+
 /**
  * errseq_check() - Has an error occurred since a particular sample point?
  * @eseq: Pointer to errseq_t value to be checked.
@@ -143,7 +182,10 @@ EXPORT_SYMBOL(errseq_sample);
  */
 int errseq_check(errseq_t *eseq, errseq_t since)
 {
-	errseq_t cur = READ_ONCE(*eseq);
+	errseq_t cur = READ_ONCE(*eseq) & ~(ERRSEQ_MUSTINC|ERRSEQ_SEEN);
+
+	/* Clear the flag bits for comparison */
+	since &= ~(ERRSEQ_MUSTINC|ERRSEQ_SEEN);
 
 	if (likely(cur == since))
 		return 0;
@@ -195,7 +237,7 @@ int errseq_check_and_advance(errseq_t *eseq, errseq_t *since)
 		 * can advance "since" and return an error based on what we
 		 * have.
 		 */
-		new = old | ERRSEQ_SEEN;
+		new = old | ERRSEQ_SEEN | ERRSEQ_MUSTINC;
 		if (new != old)
 			cmpxchg(eseq, old, new);
 		*since = new;
Signature · 1 line
2.29.2
author maintainer
#5 lore raw

Re: [RFC PATCH 1/2] errseq: split the SEEN flag into two new flags

Quoted 197 lines · NeilBrown
Quoted 114 lines · Jeffrey Layton
Quoted 77 lines · NeilBrown
Quoted 55 lines · Jeff Layton

Overlayfs's volatile mounts want to be able to sample an error for their own purposes, without preventing a later opener from potentially seeing the error.

The original reason for the SEEN flag was to make it so that we didn't need to increment the counter if nothing had observed the latest value and the error was the same. Eventually, a regression was reported in the errseq_t conversion, and we fixed that by using the SEEN flag to also mean that the error had been reported to userland at least once somewhere.

Those are two different states, however. If we instead take a second flag bit from the counter, we can track these two things separately, and accomodate the overlayfs volatile mount use-case.

Add a new MUSTINC flag that indicates that the counter must be incremented the next time an error is set, and rework the errseq functions to set and clear that flag whenever the SEEN bit is set or cleared.

Test only for the MUSTINC bit when deciding whether to increment the counter and only for the SEEN bit when deciding what to return in errseq_sample.

Add a new errseq_peek function to allow for the overlayfs use-case. This just grabs the latest counter and sets the MUSTINC bit, leaving the SEEN bit untouched.

---
 include/linux/errseq.h | 2 ++
 lib/errseq.c | 64 ++++++++++++++++++++++++++++++++++--------

 2 files changed, 55 insertions(+), 11 deletions(-)
include/linux/errseq.h +0 -0
index fc2777770768..6d4b9bc629ac 100644
@@ -9,6 +9,8 @@ typedef u32	errseq_t;

 errseq_t errseq_set(errseq_t *eseq, int err);
 errseq_t errseq_sample(errseq_t *eseq);

include/linux/errseq.h +2 -0
+errseq_t errseq_peek(errseq_t *eseq);
+errseq_t errseq_sample_advance(errseq_t *eseq);

 int errseq_check(errseq_t *eseq, errseq_t since); int errseq_check_and_advance(errseq_t *eseq, errseq_t *since); #endif

lib/errseq.c +0 -0
index 81f9e33aa7e7..5cc830f0361b 100644

lib/errseq.c line 39

Quoted 2 lines
lib/errseq.c +0 -0
@@ -38,8 +38,11 @@
  /* This bit is used as a flag to indicate whether the value has been seen */
  #define ERRSEQ_SEEN		(1 << ERRSEQ_SHIFT)

Would this look nicer using the BIT() macro?

  #define ERRSEQ_SEEN BIT(ERRSEQ_SHIFT)

lib/errseq.c line 42

Quoted 6 lines

lib/errseq.c +2 -0
+/* This bit indicates that value must be incremented even when error is same */
+#define ERRSEQ_MUSTINC		(1 << (ERRSEQ_SHIFT + 1))

 #define ERRSEQ_MUSTINC BIT(ERRSEQ_SHIFT+1)

or if you don't like the BIT macro (not everyone does), then maybe

 #define ERR_SEQ_MUSTINC (ERRSEQ_SEEN << 1 )

Quoted 9 lines

??

lib/errseq.c line 45

Quoted 4 lines

+
 /* The lowest bit of the counter */

lib/errseq.c +1 -1
-#define ERRSEQ_CTR_INC		(1 << (ERRSEQ_SHIFT + 1))
+#define ERRSEQ_CTR_INC		(1 << (ERRSEQ_SHIFT + 2))

Ditto.

Yes, I can make that change. The BIT macro is much easier to read.

Quoted 21 lines
Quoted 13 lines

 /**
  * errseq_set - set a errseq_t for later reporting

lib/errseq.c +0 -0
@@ -77,11 +80,11 @@ errseq_t errseq_set(errseq_t *eseq, int err)
  	for (;;) {
  		errseq_t new;

lib/errseq.c errseq_t errseq_set(errseq_t *eseq, int err) · line 84

Quoted 4 lines
lib/errseq.c +2 -2
-		/* Clear out error bits and set new error */
-		new = (old & ~(MAX_ERRNO|ERRSEQ_SEEN)) | -err;
+		/* Clear out flag bits and set new error */
+		new = (old & ~(MAX_ERRNO|ERRSEQ_SEEN|ERRSEQ_MUSTINC)) | -err;

This is starting to look clumsy (or maybe, this already looked clumsy, but now that is hard to ignore).

Quoted 2 lines
		new = (old & (ERRSEQ_CTR_INC - 1)) | -err
Quoted 6 lines

I think you mean:

		new = (old & ~(ERRSEQ_CTR_INC - 1)) | -err;

Maybe I can add a new ERRSEQ_CTR_MASK value though which makes it more evident.

Sounds good.

Quoted 10 lines
Quoted 6 lines

Also this assumes MAX_ERRNO is a mask, which it is .. today.

	BUILD_BUG_ON(MAX_ERRNO & (MAX_ERRNO + 1));

??

We already have this in errseq_set:

        BUILD_BUG_ON_NOT_POWER_OF_2(MAX_ERRNO + 1);

Oh good - I didn't see.

Quoted 42 lines
Quoted 42 lines
Quoted 25 lines

lib/errseq.c +2 -2
-		/* Only increment if someone has looked at it */
-		if (old & ERRSEQ_SEEN)
+		/* Only increment if we have to */
+		if (old & ERRSEQ_MUSTINC)

  new += ERRSEQ_CTR_INC;

  /* If there would be no change, then call it done */

lib/errseq.c +1 -0
@@ -122,14 +125,50 @@ EXPORT_SYMBOL(errseq_set);
  errseq_t errseq_sample(errseq_t *eseq)
  {
  	errseq_t old = READ_ONCE(*eseq);
+	errseq_t new = old;

lib/errseq.c +0 -1
-	/* If nobody has seen this error yet, then we can be the first. */

lib/errseq.c EXPORT_SYMBOL(errseq_set); · line 136

Quoted 10 lines
lib/errseq.c +7 -3
-	if (!(old & ERRSEQ_SEEN))
-		old = 0;
-	return old;
+	/*
+	 * For the common case of no errors ever having been set, we can skip
+	 * marking the SEEN|MUSTINC bits. Once an error has been set, the value
+	 * will never go back to zero.
+	 */
+	if (old != 0) {
+		new |= ERRSEQ_SEEN|ERRSEQ_MUSTINC;

You lose me here. Why is ERRSEQ_SEEN being set, where it wasn't before?

The ERRSEQ_SEEN flag not means precisely "The error has been reported to userspace".
This operations isn't used to report errors - that is errseq_check().

Quoted 6 lines
Quoted 3 lines

I'm not saying the code it wrong - I really cannot tell. I'm just saying that I cannot see why it might be right.

I think you're right. We should not be setting SEEN here, but we do need to set MUSTINC if it's not already set. I'll fix (and re-test).

Thanks. Though it isn't clear to me why MUSTINC needs to be set there, so if you could make that clear, it would help me.

Also, the two flags seem similar in how they are handled, only tracking different states, but their names don't reflect that.
I imagine changing "SEEN" to "MUST_REPORT" or similar, so both flags are "MUST_XXX".
Only I think we would then need to invert "SEEN" - as it currently means "MUSTN'T_REPORT" .. approximately.

Quoted 6 lines

Or maybe we could replace MUST_INC by DID_INC, so it says what has been done, rather than what must be done.

Or maybe not. Certainly it would be useful to have a clear picture of how the two flags are similar, and how they are different.

You need to set MUSTINC in errseq_peek to ensure that the next error that occurs will be recorded, via the counter being bumped. Otherwise that increment may be skipped (if no one else observed the last error).

I sent a v2 set before I saw your mail. Hopefully it addresses some of your concerns.

You're right that the flag naming is a bit awkward. I'm open to suggestions for names, but I'd probably like to keep the "sense" of the flags so that I don't need to sort out the logic again. It also works better with 0 being a special value that way.

Quoted 85 lines

Thanks,
NeilBrown

Quoted 81 lines

Thanks for the review!

Quoted 78 lines
Quoted 78 lines
lib/errseq.c +6 -0
+		if (old != new)
+			cmpxchg(eseq, old, new);
+		if (!(old & ERRSEQ_SEEN))
+			return 0;
+	}
+	return new;

 }
 EXPORT_SYMBOL(errseq_sample);

lib/errseq.c +26 -0
+/**
+ * errseq_peek - Grab current errseq_t value, but don't mark it SEEN
+ * @eseq: Pointer to errseq_t to be sampled.
+ *
+ * In some cases, we need to be able to sample the errseq_t, but we're not
+ * in a situation where we can report the value to userland. Use this
+ * function to do that. This ensures that later errors will be recorded,
+ * and that any current errors are reported at least once.
+ *
+ * Context: Any context.
+ * Return: The current errseq value.
+ */
+errseq_t errseq_peek(errseq_t *eseq)
+{
+	errseq_t old = READ_ONCE(*eseq);
+	errseq_t new = old;
+
+	if (old != 0) {
+		new |= ERRSEQ_MUSTINC;
+		if (old != new)
+			cmpxchg(eseq, old, new);
+	}
+	return new;
+}
+EXPORT_SYMBOL(errseq_peek);
+

 /**
  * errseq_check() - Has an error occurred since a particular sample point?
  * @eseq: Pointer to errseq_t value to be checked.

lib/errseq.c +4 -1
@@ -143,7 +182,10 @@ EXPORT_SYMBOL(errseq_sample);
   */
  int errseq_check(errseq_t *eseq, errseq_t since)
  {
-	errseq_t cur = READ_ONCE(*eseq);
+	errseq_t cur = READ_ONCE(*eseq) & ~(ERRSEQ_MUSTINC|ERRSEQ_SEEN);
+
+	/* Clear the flag bits for comparison */
+	since &= ~(ERRSEQ_MUSTINC|ERRSEQ_SEEN);

  if (likely(cur == since))
  return 0;

lib/errseq.c +1 -1
@@ -195,7 +237,7 @@ int errseq_check_and_advance(errseq_t *eseq, errseq_t *since)
  		 * can advance "since" and return an error based on what we
  		 * have.
  		 */
-		new = old | ERRSEQ_SEEN;
+		new = old | ERRSEQ_SEEN | ERRSEQ_MUSTINC;
  		if (new != old)
  			cmpxchg(eseq, old, new);
  		*since = new;
Signature · 1 line
2.29.2
Signature · 1 line
Jeff Layton <[email protected]>
author maintainer
#6 lore raw

RFC PATCH 2/2 overlayfs: propagate errors from upper to overlay sb in sync_fs

In reply to Jeff Layton

Peek at the upper layer's errseq_t at mount time for volatile mounts, and record it in the per-sb info. In sync_fs, check for an error since the recorded point and set it in the overlayfs superblock if there was one.

---
 fs/overlayfs/ovl_entry.h |  1 +
 fs/overlayfs/super.c     | 14 +++++++++++---
 2 files changed, 12 insertions(+), 3 deletions(-)
fs/overlayfs/ovl_entry.h +1 -0
index 1b5a2094df8e..fcfcc3951973 100644
@@ -79,6 +79,7 @@ struct ovl_fs {
 	atomic_long_t last_ino;
 	/* Whiteout dentry cache */
 	struct dentry *whiteout;
+	errseq_t err_mark;
 };
 
 static inline struct vfsmount *ovl_upper_mnt(struct ovl_fs *ofs)
fs/overlayfs/super.c +11 -3
index 290983bcfbb3..2985d2752970 100644
@@ -264,8 +264,13 @@ static int ovl_sync_fs(struct super_block *sb, int wait)
 	if (!ovl_upper_mnt(ofs))
 		return 0;
 
-	if (!ovl_should_sync(ofs))
-		return 0;
+	if (!ovl_should_sync(ofs)) {
+		/* Propagate errors from upper to overlayfs */
+		ret = errseq_check(&upper_sb->s_wb_err, ofs->err_mark);
+		errseq_set(&sb->s_wb_err, ret);
+		return ret;
+	}
+
 	/*
 	 * Not called for sync(2) call or an emergency sync (SB_I_SKIP_SYNC).
 	 * All the super blocks will be iterated, including upper_sb.
@@ -1945,8 +1950,11 @@ static int ovl_fill_super(struct super_block *sb, void *data, int silent)
 
 		sb->s_stack_depth = ovl_upper_mnt(ofs)->mnt_sb->s_stack_depth;
 		sb->s_time_gran = ovl_upper_mnt(ofs)->mnt_sb->s_time_gran;
-
 	}
+
+	if (ofs->config.ovl_volatile)
+		ofs->err_mark = errseq_peek(&ovl_upper_mnt(ofs)->mnt_sb->s_wb_err);
+
 	oe = ovl_get_lowerstack(sb, splitlower, numlower, ofs, layers);
 	err = PTR_ERR(oe);
 	if (IS_ERR(oe))
Signature · 1 line
2.29.2
#7 lore raw

Re: [RFC PATCH 2/2] overlayfs: propagate errors from upper to overlay sb in sync_fs

[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch]

Hi Jeff,

[FYI, it's a private test report for your RFC patch.]
[auto build test WARNING on miklos-vfs/overlayfs-next]
[also build test WARNING on linus/master v5.10-rc7 next-20201211] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Jeff-Layton/errseq-overlayfs-accomodate-the-volatile-upper-layer-use-case/20201213-213109
base:   https://git.kernel.org/pub/scm/linux/kernel/git/mszeredi/vfs.git overlayfs-next
config: x86_64-randconfig-a016-20201213 (attached as .config)
compiler: clang version 12.0.0 (https://github.com/llvm/llvm-project d38205144febf4dc42c9270c6aa3d978f1ef65e1)

reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# install x86_64 cross compiling tool for clang build
# apt-get install binutils-x86-64-linux-gnu
# https://github.com/0day-ci/linux/commit/89bd90a6b2a9bc40a46e9b9de68356e99cde04e8
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Jeff-Layton/errseq-overlayfs-accomodate-the-volatile-upper-layer-use-case/20201213-213109 git checkout 89bd90a6b2a9bc40a46e9b9de68356e99cde04e8
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=x86_64

If you fix the issue, kindly add following tag as appropriate

All warnings (new ones prefixed by >>):

>> fs/overlayfs/super.c:272:23: warning: variable 'upper_sb' is uninitialized when used here [-Wuninitialized]
                   ret = errseq_check(&upper_sb->s_wb_err, ofs->err_mark);
                                       ^~~~~~~~
   fs/overlayfs/super.c:264:30: note: initialize the variable 'upper_sb' to silence this warning
           struct super_block *upper_sb;
                                       ^
                                        = NULL

1 warning generated.

vim +/upper_sb +272 fs/overlayfs/super.c

259
260 /* Sync real dirty inodes in upper filesystem (if it exists) */
261 static int ovl_sync_fs(struct super_block *sb, int wait)
262 {
263 struct ovl_fs *ofs = sb->s_fs_info;
264 struct super_block *upper_sb;
265 int ret;
266
267 if (!ovl_upper_mnt(ofs))
268 return 0;
269
270 if (!ovl_should_sync(ofs)) {
271 /* Propagate errors from upper to overlayfs */

 > 272			ret = errseq_check(&upper_sb->s_wb_err, ofs->err_mark);

273 errseq_set(&sb->s_wb_err, ret);
274 return ret;
275 }
276
277 /*
278 * Not called for sync(2) call or an emergency sync (SB_I_SKIP_SYNC).
279 * All the super blocks will be iterated, including upper_sb.
280 *
281 * If this is a syncfs(2) call, then we do need to call
282 * sync_filesystem() on upper_sb, but enough if we do it when being
283 * called with wait == 1.
284 */
285 if (!wait)
286 return 0;
287
288 upper_sb = ovl_upper_mnt(ofs)->mnt_sb;
289
290 down_read(&upper_sb->s_umount);
291 ret = sync_filesystem(upper_sb);
292 up_read(&upper_sb->s_umount);
293
294 return ret;
295 }
296

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

#8 lore raw

Re: [RFC PATCH 2/2] overlayfs: propagate errors from upper to overlay sb in sync_fs

In reply to Jeff Layton

Hi Jeff,

url:    https://github.com/0day-ci/linux/commits/Jeff-Layton/errseq-overlayfs-accomodate-the-volatile-upper-layer-use-case/20201213-213109
base:   https://git.kernel.org/pub/scm/linux/kernel/git/mszeredi/vfs.git  overlayfs-next
config: i386-randconfig-m021-20201213 (attached as .config)
compiler: gcc-9 (Debian 9.3.0-15) 9.3.0

If you fix the issue, kindly add following tag as appropriate

smatch warnings:
fs/overlayfs/super.c:272 ovl_sync_fs() error: uninitialized symbol 'upper_sb'.

vim +/upper_sb +272 fs/overlayfs/super.c

e8d4bfe3a715372 Chengguang Xu         2017-11-29  260  /* Sync real dirty inodes in upper filesystem (if it exists) */
e593b2bf513dd4d Amir Goldstein        2017-01-23  261  static int ovl_sync_fs(struct super_block *sb, int wait)
e593b2bf513dd4d Amir Goldstein        2017-01-23  262  {
ad204488d3046b3 Miklos Szeredi        2017-11-10  263  	struct ovl_fs *ofs = sb->s_fs_info;
e593b2bf513dd4d Amir Goldstein        2017-01-23  264  	struct super_block *upper_sb;
e593b2bf513dd4d Amir Goldstein        2017-01-23  265  	int ret;
e593b2bf513dd4d Amir Goldstein        2017-01-23  266  
08f4c7c86d4cf12 Miklos Szeredi        2020-06-04  267  	if (!ovl_upper_mnt(ofs))
e593b2bf513dd4d Amir Goldstein        2017-01-23  268  		return 0;
e8d4bfe3a715372 Chengguang Xu         2017-11-29  269  
89bd90a6b2a9bc4 Jeff Layton           2020-12-13  270  	if (!ovl_should_sync(ofs)) {
89bd90a6b2a9bc4 Jeff Layton           2020-12-13  271  		/* Propagate errors from upper to overlayfs */
89bd90a6b2a9bc4 Jeff Layton           2020-12-13 @272  		ret = errseq_check(&upper_sb->s_wb_err, ofs->err_mark);
                                                                                   ^^^^^^^^^^^^^^^^^^^

Uninitialized.

89bd90a6b2a9bc4 Jeff Layton           2020-12-13  273  		errseq_set(&sb->s_wb_err, ret);
89bd90a6b2a9bc4 Jeff Layton           2020-12-13  274  		return ret;
89bd90a6b2a9bc4 Jeff Layton           2020-12-13  275  	}
89bd90a6b2a9bc4 Jeff Layton           2020-12-13  276  
e8d4bfe3a715372 Chengguang Xu         2017-11-29  277  	/*
32b1924b210a70d Konstantin Khlebnikov 2020-04-09  278  	 * Not called for sync(2) call or an emergency sync (SB_I_SKIP_SYNC).
32b1924b210a70d Konstantin Khlebnikov 2020-04-09  279  	 * All the super blocks will be iterated, including upper_sb.
e8d4bfe3a715372 Chengguang Xu         2017-11-29  280  	 *
e8d4bfe3a715372 Chengguang Xu         2017-11-29  281  	 * If this is a syncfs(2) call, then we do need to call
e8d4bfe3a715372 Chengguang Xu         2017-11-29  282  	 * sync_filesystem() on upper_sb, but enough if we do it when being
e8d4bfe3a715372 Chengguang Xu         2017-11-29  283  	 * called with wait == 1.
e8d4bfe3a715372 Chengguang Xu         2017-11-29  284  	 */
e8d4bfe3a715372 Chengguang Xu         2017-11-29  285  	if (!wait)
e593b2bf513dd4d Amir Goldstein        2017-01-23  286  		return 0;
e593b2bf513dd4d Amir Goldstein        2017-01-23  287  
08f4c7c86d4cf12 Miklos Szeredi        2020-06-04  288  	upper_sb = ovl_upper_mnt(ofs)->mnt_sb;
e8d4bfe3a715372 Chengguang Xu         2017-11-29  289  
e593b2bf513dd4d Amir Goldstein        2017-01-23  290  	down_read(&upper_sb->s_umount);
e8d4bfe3a715372 Chengguang Xu         2017-11-29  291  	ret = sync_filesystem(upper_sb);
e593b2bf513dd4d Amir Goldstein        2017-01-23  292  	up_read(&upper_sb->s_umount);
e8d4bfe3a715372 Chengguang Xu         2017-11-29  293  
e593b2bf513dd4d Amir Goldstein        2017-01-23  294  	return ret;
e593b2bf513dd4d Amir Goldstein        2017-01-23  295  }

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

_______________________________________________
kbuild mailing list -- kbuild(a)lists.01.org
To unsubscribe send an email to kbuild-leave(a)lists.01.org

#9 lore raw

Re: [RFC PATCH 2/2] overlayfs: propagate errors from upper to overlay sb in sync_fs

In reply to Jeff Layton
Quoted 7 lines · Jeff Layton

Peek at the upper layer's errseq_t at mount time for volatile mounts, and record it in the per-sb info. In sync_fs, check for an error since the recorded point and set it in the overlayfs superblock if there was one.

---

While we are solving problem for non-volatile overlay mount, I also started thinking, what about non-volatile overlay syncfs() writeback errors. Looks like these will not be reported to user space at all as of now (because we never update overlay_sb->s_wb_err ever).

A patch like this might fix it. (compile tested only).

overlayfs: Report syncfs() errors to user space

Currently, syncfs(), calls filesystem ->sync_fs() method but ignores the return code. But certain writeback errors can still be reported on syncfs() by checking errors on super block.

ret2 = errseq_check_and_advance(&sb->s_wb_err, &f.file->f_sb_err);

For the case of overlayfs, we never set overlayfs super block s_wb_err. That means sync() will never report writeback errors on overlayfs uppon syncfs().

Fix this by updating overlay sb->sb_wb_err upon ->sync_fs() call. And that should mean that user space syncfs() call should see writeback errors.

ovl_fsync() does not need anything special because if there are writeback errors underlying filesystem will report it through vfs_fsync_range() return code and user space will see it.

---
 fs/overlayfs/ovl_entry.h |    1 +
 fs/overlayfs/super.c     |   14 +++++++++++---
 2 files changed, 12 insertions(+), 3 deletions(-)
fs/overlayfs/super.c +11 -3
Index: redhat-linux/fs/overlayfs/super.c
===================================================================
@@ -259,7 +259,7 @@ static int ovl_sync_fs(struct super_bloc
 {
 	struct ovl_fs *ofs = sb->s_fs_info;
 	struct super_block *upper_sb;
-	int ret;
+	int ret, ret2;
 
 	if (!ovl_upper_mnt(ofs))
 		return 0;
@@ -283,7 +283,14 @@ static int ovl_sync_fs(struct super_bloc
 	ret = sync_filesystem(upper_sb);
 	up_read(&upper_sb->s_umount);
 
-	return ret;
+	if (errseq_check(&upper_sb->s_wb_err, sb->s_wb_err)) {
+		/* Upper sb has errors since last time */
+		spin_lock(&ofs->errseq_lock);
+		ret2 = errseq_check_and_advance(&upper_sb->s_wb_err,
+						&sb->s_wb_err);
+		spin_unlock(&ofs->errseq_lock);
+	}
+	return ret ? ret : ret2;
 }
 
 /**
@@ -1873,6 +1880,7 @@ static int ovl_fill_super(struct super_b
 	if (!cred)
 		goto out_err;
 
+	spin_lock_init(&ofs->errseq_lock);
 	/* Is there a reason anyone would want not to share whiteouts? */
 	ofs->share_whiteout = true;
 
@@ -1945,7 +1953,7 @@ static int ovl_fill_super(struct super_b
 
 		sb->s_stack_depth = ovl_upper_mnt(ofs)->mnt_sb->s_stack_depth;
 		sb->s_time_gran = ovl_upper_mnt(ofs)->mnt_sb->s_time_gran;
-
+		sb->s_wb_err = errseq_sample(&ovl_upper_mnt(ofs)->mnt_sb->s_wb_err);
 	}
 	oe = ovl_get_lowerstack(sb, splitlower, numlower, ofs, layers);
 	err = PTR_ERR(oe);
fs/overlayfs/ovl_entry.h +1 -0
Index: redhat-linux/fs/overlayfs/ovl_entry.h
===================================================================
@@ -79,6 +79,7 @@ struct ovl_fs {
 	atomic_long_t last_ino;
 	/* Whiteout dentry cache */
 	struct dentry *whiteout;
+	spinlock_t errseq_lock;
 };
 
 static inline struct vfsmount *ovl_upper_mnt(struct ovl_fs *ofs)
#10 lore raw

Re: [RFC PATCH 2/2] overlayfs: propagate errors from upper to overlay sb in sync_fs

Quoted 92 lines · Vivek Goyal
Quoted 7 lines · Jeff Layton

Peek at the upper layer's errseq_t at mount time for volatile mounts, and record it in the per-sb info. In sync_fs, check for an error since the recorded point and set it in the overlayfs superblock if there was one.

---

While we are solving problem for non-volatile overlay mount, I also started thinking, what about non-volatile overlay syncfs() writeback errors. Looks like these will not be reported to user space at all as of now (because we never update overlay_sb->s_wb_err ever).

A patch like this might fix it. (compile tested only).

overlayfs: Report syncfs() errors to user space

Currently, syncfs(), calls filesystem ->sync_fs() method but ignores the return code. But certain writeback errors can still be reported on syncfs() by checking errors on super block.

ret2 = errseq_check_and_advance(&sb->s_wb_err, &f.file->f_sb_err);

For the case of overlayfs, we never set overlayfs super block s_wb_err. That means sync() will never report writeback errors on overlayfs uppon syncfs().

Fix this by updating overlay sb->sb_wb_err upon ->sync_fs() call. And that should mean that user space syncfs() call should see writeback errors.

ovl_fsync() does not need anything special because if there are writeback errors underlying filesystem will report it through vfs_fsync_range() return code and user space will see it.

---
 fs/overlayfs/ovl_entry.h |    1 +
 fs/overlayfs/super.c     |   14 +++++++++++---
 2 files changed, 12 insertions(+), 3 deletions(-)

Index: redhat-linux/fs/overlayfs/super.c
===================================================================

fs/overlayfs/super.c +11 -3
@@ -259,7 +259,7 @@ static int ovl_sync_fs(struct super_bloc
 {
 	struct ovl_fs *ofs = sb->s_fs_info;
 	struct super_block *upper_sb;
-	int ret;
+	int ret, ret2;
 
 	if (!ovl_upper_mnt(ofs))
 		return 0;
@@ -283,7 +283,14 @@ static int ovl_sync_fs(struct super_bloc
 	ret = sync_filesystem(upper_sb);
 	up_read(&upper_sb->s_umount);
 
-	return ret;
+	if (errseq_check(&upper_sb->s_wb_err, sb->s_wb_err)) {
+		/* Upper sb has errors since last time */
+		spin_lock(&ofs->errseq_lock);
+		ret2 = errseq_check_and_advance(&upper_sb->s_wb_err,
+						&sb->s_wb_err);
+		spin_unlock(&ofs->errseq_lock);
+	}
+	return ret ? ret : ret2;
 }
 
 /**
@@ -1873,6 +1880,7 @@ static int ovl_fill_super(struct super_b
 	if (!cred)
 		goto out_err;
 
+	spin_lock_init(&ofs->errseq_lock);
 	/* Is there a reason anyone would want not to share whiteouts? */
 	ofs->share_whiteout = true;
 
@@ -1945,7 +1953,7 @@ static int ovl_fill_super(struct super_b
 
 		sb->s_stack_depth = ovl_upper_mnt(ofs)->mnt_sb->s_stack_depth;
 		sb->s_time_gran = ovl_upper_mnt(ofs)->mnt_sb->s_time_gran;
-
+		sb->s_wb_err = errseq_sample(&ovl_upper_mnt(ofs)->mnt_sb->s_wb_err);
 	}
 	oe = ovl_get_lowerstack(sb, splitlower, numlower, ofs, layers);
 	err = PTR_ERR(oe);

Index: redhat-linux/fs/overlayfs/ovl_entry.h
===================================================================

fs/overlayfs/ovl_entry.h struct ovl_fs { · line 85

Quoted 7 lines
fs/overlayfs/ovl_entry.h +1 -0
@@ -79,6 +79,7 @@ struct ovl_fs {
 	atomic_long_t last_ino;
 	/* Whiteout dentry cache */
 	struct dentry *whiteout;
+	spinlock_t errseq_lock;
 };
 
 static inline struct vfsmount *ovl_upper_mnt(struct ovl_fs *ofs)

This was on my list of things to look at. I don't think we can / should use errseq_check_and_advance because it will hide errors from userspace. I think we need something like:

At startup, call errseq_peek and stash that value somewhere. This sets the MUSTINC flag.

At syncfs time: call errseq check, if it says there is an error, call errseq_peek again, and store the error in our superblock. Take the error value from the differenceb between the previous one and the new one, and copy it up to the superblock.

Either way, I think Jeff's work of making it so other kernel subsytems can interact with errseq on a superblock bears fruit elsewhere. If the first patch gets merged, I can put together the patches to do the standard error bubble up for normal syncfs, volatile syncfs, and volatile remount.

#11 lore raw

Re: [RFC PATCH 2/2] overlayfs: propagate errors from upper to overlay sb in sync_fs

Quoted 98 lines · Sargun Dhillon
Quoted 97 lines · Vivek Goyal
Quoted 7 lines · Jeff Layton

Peek at the upper layer's errseq_t at mount time for volatile mounts, and record it in the per-sb info. In sync_fs, check for an error since the recorded point and set it in the overlayfs superblock if there was one.

---

While we are solving problem for non-volatile overlay mount, I also started thinking, what about non-volatile overlay syncfs() writeback errors. Looks like these will not be reported to user space at all as of now (because we never update overlay_sb->s_wb_err ever).

A patch like this might fix it. (compile tested only).

overlayfs: Report syncfs() errors to user space

Currently, syncfs(), calls filesystem ->sync_fs() method but ignores the return code. But certain writeback errors can still be reported on syncfs() by checking errors on super block.

ret2 = errseq_check_and_advance(&sb->s_wb_err, &f.file->f_sb_err);

For the case of overlayfs, we never set overlayfs super block s_wb_err. That means sync() will never report writeback errors on overlayfs uppon syncfs().

Fix this by updating overlay sb->sb_wb_err upon ->sync_fs() call. And that should mean that user space syncfs() call should see writeback errors.

ovl_fsync() does not need anything special because if there are writeback errors underlying filesystem will report it through vfs_fsync_range() return code and user space will see it.

---
 fs/overlayfs/ovl_entry.h |    1 +
 fs/overlayfs/super.c     |   14 +++++++++++---
 2 files changed, 12 insertions(+), 3 deletions(-)

Index: redhat-linux/fs/overlayfs/super.c
===================================================================

fs/overlayfs/super.c +11 -3
@@ -259,7 +259,7 @@ static int ovl_sync_fs(struct super_bloc
 {
 	struct ovl_fs *ofs = sb->s_fs_info;
 	struct super_block *upper_sb;
-	int ret;
+	int ret, ret2;
 
 	if (!ovl_upper_mnt(ofs))
 		return 0;
@@ -283,7 +283,14 @@ static int ovl_sync_fs(struct super_bloc
 	ret = sync_filesystem(upper_sb);
 	up_read(&upper_sb->s_umount);
 
-	return ret;
+	if (errseq_check(&upper_sb->s_wb_err, sb->s_wb_err)) {
+		/* Upper sb has errors since last time */
+		spin_lock(&ofs->errseq_lock);
+		ret2 = errseq_check_and_advance(&upper_sb->s_wb_err,
+						&sb->s_wb_err);
+		spin_unlock(&ofs->errseq_lock);
+	}
+	return ret ? ret : ret2;
 }
 
 /**
@@ -1873,6 +1880,7 @@ static int ovl_fill_super(struct super_b
 	if (!cred)
 		goto out_err;
 
+	spin_lock_init(&ofs->errseq_lock);
 	/* Is there a reason anyone would want not to share whiteouts? */
 	ofs->share_whiteout = true;
 
@@ -1945,7 +1953,7 @@ static int ovl_fill_super(struct super_b
 
 		sb->s_stack_depth = ovl_upper_mnt(ofs)->mnt_sb->s_stack_depth;
 		sb->s_time_gran = ovl_upper_mnt(ofs)->mnt_sb->s_time_gran;
-
+		sb->s_wb_err = errseq_sample(&ovl_upper_mnt(ofs)->mnt_sb->s_wb_err);
 	}
 	oe = ovl_get_lowerstack(sb, splitlower, numlower, ofs, layers);
 	err = PTR_ERR(oe);

Index: redhat-linux/fs/overlayfs/ovl_entry.h
===================================================================

fs/overlayfs/ovl_entry.h +1 -0
@@ -79,6 +79,7 @@ struct ovl_fs {
 	atomic_long_t last_ino;
 	/* Whiteout dentry cache */
 	struct dentry *whiteout;
+	spinlock_t errseq_lock;
 };
 
Quoted 5 lines

fs/overlayfs/ovl_entry.h struct ovl_fs { · line 85

Quoted 2 lines
fs/overlayfs/ovl_entry.h +0 -0
 static inline struct vfsmount *ovl_upper_mnt(struct ovl_fs *ofs)

This was on my list of things to look at. I don't think we can / should use errseq_check_and_advance because it will hide errors from userspace.

Hi Sargun,

I have been struggling to figure out when to use errseq_check_and_advance() and when to use this error_check() and errorseq_set() combination.

My rational for using errseq_check_and_advance() is that say there is an unseen error on upper super block, and if overlayfs calls syncfs(), then this call should set SEEN flag on upper super block, isn't it. This is equivalent of an app directly calling syncfs() on upper.

If we use error_check() and errseq_set() combination, then we are just reading state of upper superblock but really not impacting it despite the fact overlay apps are calling syncfs().

Comapre it with fsync(). For non-volatile overlay, an fsync() overlay call will set SEEN flag on upper file. And I believe same thing should happen for ovl_syncfs() call as well. It makes more sense to me.

Wondering how will it hide errors from user space. ovl "struct file" will have its own f->f_sb_err initialized from overlay superblock. And if overlay super block gets updated with error, a later errseq_check_and_advance(&sb->s_wb_err, &f.file->f_sb_err) should still return an error.

What am I missing?

Vivek

Quoted 5 lines

I think we
need something like:

At startup, call errseq_peek and stash that value somewhere. This sets the MUSTINC flag.

So this errseq_peek() stuff is required only if we don't want to consume error while checking for error. In fact consuming error is not bad as long as we do it only ovl_syncfs() path. In fact it will match current semantics of syncfs().

But issue we have is that we want to check for error outside syncfs() path too and don't want to consume it (otherwise it breaks the semantics that it will bee seen marked in syncfs() path).

So that's why this notion of checking error without consuming it so tha we can check it in remount path.

But in syncfs() path, it should be ok to consume unseen error and we should be able to call errseq_check_and_advance(), both for volatile and non-volatile mounts, isn't it?

For ther paths, like remount, we probably can stash away on persistent storage and compare that value on remount and fail remount without actually consuming unseen error (because it is not syncfs path). This possibly can be used in other paths like read/write as well to make sure we can notice error without consuming it.

IOW, we seem to have to paths we want to check errors in. In ovl_syncfs() path we should be able consume exisiting unseen error on upper, so errseq_check_and_advance() makes sense. In rest of the paths, we should use new semantics to check for errors.

Vivek

Quoted 11 lines

At syncfs time: call errseq check, if it says there is an error, call errseq_peek again, and store the error in our superblock. Take the error value from the differenceb between the previous one and the new one, and copy it up to the superblock.

Either way, I think Jeff's work of making it so other kernel subsytems can interact with errseq on a superblock bears fruit elsewhere. If the first patch gets merged, I can put together the patches to do the standard error bubble up for normal syncfs, volatile syncfs, and volatile remount.

author maintainer
#12 lore raw

Re: [RFC PATCH 2/2] overlayfs: propagate errors from upper to overlay sb in sync_fs

In reply to Vivek Goyal
Quoted 63 lines · Vivek Goyal
Quoted 7 lines · Jeff Layton

Peek at the upper layer's errseq_t at mount time for volatile mounts, and record it in the per-sb info. In sync_fs, check for an error since the recorded point and set it in the overlayfs superblock if there was one.

---

While we are solving problem for non-volatile overlay mount, I also started thinking, what about non-volatile overlay syncfs() writeback errors. Looks like these will not be reported to user space at all as of now (because we never update overlay_sb->s_wb_err ever).

A patch like this might fix it. (compile tested only).

overlayfs: Report syncfs() errors to user space

Currently, syncfs(), calls filesystem ->sync_fs() method but ignores the return code. But certain writeback errors can still be reported on syncfs() by checking errors on super block.

ret2 = errseq_check_and_advance(&sb->s_wb_err, &f.file->f_sb_err);

For the case of overlayfs, we never set overlayfs super block s_wb_err. That means sync() will never report writeback errors on overlayfs uppon syncfs().

Fix this by updating overlay sb->sb_wb_err upon ->sync_fs() call. And that should mean that user space syncfs() call should see writeback errors.

ovl_fsync() does not need anything special because if there are writeback errors underlying filesystem will report it through vfs_fsync_range() return code and user space will see it.

---
 fs/overlayfs/ovl_entry.h | 1 +
 fs/overlayfs/super.c | 14 +++++++++++---

 2 files changed, 12 insertions(+), 3 deletions(-)

Index: redhat-linux/fs/overlayfs/super.c
===================================================================

fs/overlayfs/super.c +1 -1
@@ -259,7 +259,7 @@ static int ovl_sync_fs(struct super_bloc
  {
  	struct ovl_fs *ofs = sb->s_fs_info;
  	struct super_block *upper_sb;
-	int ret;
+	int ret, ret2;

  if (!ovl_upper_mnt(ofs))
  return 0;

fs/overlayfs/super.c +0 -0
@@ -283,7 +283,14 @@ static int ovl_sync_fs(struct super_bloc
  	ret = sync_filesystem(upper_sb);
  	up_read(&upper_sb->s_umount);

fs/overlayfs/super.c static int ovl_sync_fs(struct super_bloc · line 293

Quoted 9 lines
fs/overlayfs/super.c +8 -1
-	return ret;
+	if (errseq_check(&upper_sb->s_wb_err, sb->s_wb_err)) {
+		/* Upper sb has errors since last time */
+		spin_lock(&ofs->errseq_lock);
+		ret2 = errseq_check_and_advance(&upper_sb->s_wb_err,
+						&sb->s_wb_err);
+		spin_unlock(&ofs->errseq_lock);
+	}
+	return ret ? ret : ret2;

I think this is probably not quite right.

The problem I think is that the SEEN flag is always going to end up being set in sb->s_wb_err, and that is going to violate the desired semantics. If the writeback error occurred after all fd's were closed, then the next opener wouldn't see it and you'd lose the error.

We probably need a function to cleanly propagate the error from one errseq_t to another so that that doesn't occur. I'll have to think about it.

Quoted 48 lines

 }

 /**

fs/overlayfs/super.c +0 -0
@@ -1873,6 +1880,7 @@ static int ovl_fill_super(struct super_b
  	if (!cred)
  		goto out_err;

fs/overlayfs/super.c +1 -0
+	spin_lock_init(&ofs->errseq_lock);

  /* Is there a reason anyone would want not to share whiteouts? */ ofs->share_whiteout = true;

fs/overlayfs/super.c +0 -0
@@ -1945,7 +1953,7 @@ static int ovl_fill_super(struct super_b

  sb->s_stack_depth = ovl_upper_mnt(ofs)->mnt_sb->s_stack_depth; sb->s_time_gran = ovl_upper_mnt(ofs)->mnt_sb->s_time_gran;

fs/overlayfs/super.c +1 -1
-
+		sb->s_wb_err = errseq_sample(&ovl_upper_mnt(ofs)->mnt_sb->s_wb_err);

  }
  oe = ovl_get_lowerstack(sb, splitlower, numlower, ofs, layers); err = PTR_ERR(oe);
Index: redhat-linux/fs/overlayfs/ovl_entry.h
===================================================================

fs/overlayfs/ovl_entry.h +1 -0
@@ -79,6 +79,7 @@ struct ovl_fs {
  	atomic_long_t last_ino;
  	/* Whiteout dentry cache */
  	struct dentry *whiteout;
+	spinlock_t errseq_lock;
  };

 static inline struct vfsmount *ovl_upper_mnt(struct ovl_fs *ofs)

Signature · 1 line
Jeff Layton <[email protected]>
author maintainer
#13 lore raw

Re: [RFC PATCH 2/2] overlayfs: propagate errors from upper to overlay sb in sync_fs

Quoted 76 lines · Jeff Layton
Quoted 63 lines · Vivek Goyal
Quoted 7 lines · Jeff Layton

Peek at the upper layer's errseq_t at mount time for volatile mounts, and record it in the per-sb info. In sync_fs, check for an error since the recorded point and set it in the overlayfs superblock if there was one.

---

While we are solving problem for non-volatile overlay mount, I also started thinking, what about non-volatile overlay syncfs() writeback errors. Looks like these will not be reported to user space at all as of now (because we never update overlay_sb->s_wb_err ever).

A patch like this might fix it. (compile tested only).

overlayfs: Report syncfs() errors to user space

Currently, syncfs(), calls filesystem ->sync_fs() method but ignores the return code. But certain writeback errors can still be reported on syncfs() by checking errors on super block.

ret2 = errseq_check_and_advance(&sb->s_wb_err, &f.file->f_sb_err);

For the case of overlayfs, we never set overlayfs super block s_wb_err. That means sync() will never report writeback errors on overlayfs uppon syncfs().

Fix this by updating overlay sb->sb_wb_err upon ->sync_fs() call. And that should mean that user space syncfs() call should see writeback errors.

ovl_fsync() does not need anything special because if there are writeback errors underlying filesystem will report it through vfs_fsync_range() return code and user space will see it.

---
 fs/overlayfs/ovl_entry.h | 1 +
 fs/overlayfs/super.c | 14 +++++++++++---

 2 files changed, 12 insertions(+), 3 deletions(-)

Index: redhat-linux/fs/overlayfs/super.c
===================================================================

fs/overlayfs/super.c +1 -1
@@ -259,7 +259,7 @@ static int ovl_sync_fs(struct super_bloc
  {
  	struct ovl_fs *ofs = sb->s_fs_info;
  	struct super_block *upper_sb;
-	int ret;
+	int ret, ret2;

  if (!ovl_upper_mnt(ofs))
  return 0;

fs/overlayfs/super.c +0 -0
@@ -283,7 +283,14 @@ static int ovl_sync_fs(struct super_bloc
  	ret = sync_filesystem(upper_sb);
  	up_read(&upper_sb->s_umount);

fs/overlayfs/super.c static int ovl_sync_fs(struct super_bloc · line 293

Quoted 9 lines
fs/overlayfs/super.c +8 -1
-	return ret;
+	if (errseq_check(&upper_sb->s_wb_err, sb->s_wb_err)) {
+		/* Upper sb has errors since last time */
+		spin_lock(&ofs->errseq_lock);
+		ret2 = errseq_check_and_advance(&upper_sb->s_wb_err,
+						&sb->s_wb_err);
+		spin_unlock(&ofs->errseq_lock);
+	}
+	return ret ? ret : ret2;

I think this is probably not quite right.

Quoted 9 lines

The problem I think is that the SEEN flag is always going to end up being set in sb->s_wb_err, and that is going to violate the desired semantics. If the writeback error occurred after all fd's were closed, then the next opener wouldn't see it and you'd lose the error.

We probably need a function to cleanly propagate the error from one errseq_t to another so that that doesn't occur. I'll have to think about it.

So, the problem is that we can't guarantee that we'll have an open file when sync_fs is called. So if you do the check_and_advance in the context of a sync() syscall, you'll effectively ensure that a later opener on the upper layer won't see the error (since the upper_sb's errseq_t will be marked SEEN.

It's not clear to me what semantics you want in the following situation:

mount upper layer
mount overlayfs with non-volatile upper layer
do "stuff" on overlayfs, and close all files on overlayfs get a writeback error on upper layer
call sync() (sync_fs gets run)
open file on upper layer mount
call syncfs() on upper-layer fd

Should that last syncfs error report an error?

Also, suppose if at the end we instead opened a file on overlayfs and issued the syncfs() there -- should we see the error in that case?

Quoted 49 lines
Quoted 48 lines

 }

 /**

fs/overlayfs/super.c +0 -0
@@ -1873,6 +1880,7 @@ static int ovl_fill_super(struct super_b
  	if (!cred)
  		goto out_err;

fs/overlayfs/super.c +1 -0
+	spin_lock_init(&ofs->errseq_lock);

  /* Is there a reason anyone would want not to share whiteouts? */ ofs->share_whiteout = true;

fs/overlayfs/super.c +0 -0
@@ -1945,7 +1953,7 @@ static int ovl_fill_super(struct super_b

  sb->s_stack_depth = ovl_upper_mnt(ofs)->mnt_sb->s_stack_depth; sb->s_time_gran = ovl_upper_mnt(ofs)->mnt_sb->s_time_gran;

fs/overlayfs/super.c +1 -1
-
+		sb->s_wb_err = errseq_sample(&ovl_upper_mnt(ofs)->mnt_sb->s_wb_err);

  }
  oe = ovl_get_lowerstack(sb, splitlower, numlower, ofs, layers); err = PTR_ERR(oe);
Index: redhat-linux/fs/overlayfs/ovl_entry.h
===================================================================

fs/overlayfs/ovl_entry.h +1 -0
@@ -79,6 +79,7 @@ struct ovl_fs {
  	atomic_long_t last_ino;
  	/* Whiteout dentry cache */
  	struct dentry *whiteout;
+	spinlock_t errseq_lock;
  };

 static inline struct vfsmount *ovl_upper_mnt(struct ovl_fs *ofs)

Signature · 1 line
Jeff Layton <[email protected]>
#14 lore raw

Re: [RFC PATCH 2/2] overlayfs: propagate errors from upper to overlay sb in sync_fs

Quoted 87 lines · Jeff Layton
Quoted 76 lines · Jeff Layton
Quoted 63 lines · Vivek Goyal
Quoted 7 lines · Jeff Layton

Peek at the upper layer's errseq_t at mount time for volatile mounts, and record it in the per-sb info. In sync_fs, check for an error since the recorded point and set it in the overlayfs superblock if there was one.

---

While we are solving problem for non-volatile overlay mount, I also started thinking, what about non-volatile overlay syncfs() writeback errors. Looks like these will not be reported to user space at all as of now (because we never update overlay_sb->s_wb_err ever).

A patch like this might fix it. (compile tested only).

overlayfs: Report syncfs() errors to user space

Currently, syncfs(), calls filesystem ->sync_fs() method but ignores the return code. But certain writeback errors can still be reported on syncfs() by checking errors on super block.

ret2 = errseq_check_and_advance(&sb->s_wb_err, &f.file->f_sb_err);

For the case of overlayfs, we never set overlayfs super block s_wb_err. That means sync() will never report writeback errors on overlayfs uppon syncfs().

Fix this by updating overlay sb->sb_wb_err upon ->sync_fs() call. And that should mean that user space syncfs() call should see writeback errors.

ovl_fsync() does not need anything special because if there are writeback errors underlying filesystem will report it through vfs_fsync_range() return code and user space will see it.

---
 fs/overlayfs/ovl_entry.h | 1 +
 fs/overlayfs/super.c | 14 +++++++++++---

 2 files changed, 12 insertions(+), 3 deletions(-)

Index: redhat-linux/fs/overlayfs/super.c
===================================================================

fs/overlayfs/super.c +1 -1
@@ -259,7 +259,7 @@ static int ovl_sync_fs(struct super_bloc
  {
  	struct ovl_fs *ofs = sb->s_fs_info;
  	struct super_block *upper_sb;
-	int ret;
+	int ret, ret2;

  if (!ovl_upper_mnt(ofs))
  return 0;

fs/overlayfs/super.c +0 -0
@@ -283,7 +283,14 @@ static int ovl_sync_fs(struct super_bloc
  	ret = sync_filesystem(upper_sb);
  	up_read(&upper_sb->s_umount);

fs/overlayfs/super.c static int ovl_sync_fs(struct super_bloc · line 293

Quoted 9 lines
fs/overlayfs/super.c +8 -1
-	return ret;
+	if (errseq_check(&upper_sb->s_wb_err, sb->s_wb_err)) {
+		/* Upper sb has errors since last time */
+		spin_lock(&ofs->errseq_lock);
+		ret2 = errseq_check_and_advance(&upper_sb->s_wb_err,
+						&sb->s_wb_err);
+		spin_unlock(&ofs->errseq_lock);
+	}
+	return ret ? ret : ret2;

I think this is probably not quite right.

Quoted 9 lines

The problem I think is that the SEEN flag is always going to end up being set in sb->s_wb_err, and that is going to violate the desired semantics. If the writeback error occurred after all fd's were closed, then the next opener wouldn't see it and you'd lose the error.

We probably need a function to cleanly propagate the error from one errseq_t to another so that that doesn't occur. I'll have to think about it.

Quoted 5 lines

So, the problem is that we can't guarantee that we'll have an open file when sync_fs is called. So if you do the check_and_advance in the context of a sync() syscall, you'll effectively ensure that a later opener on the upper layer won't see the error (since the upper_sb's errseq_t will be marked SEEN.

Aha.., I assumed that when ->sync_fs() is called, we always have a valid fd open. But that's only true if ->sync_fs() is being called through syncfs(fd) syscall. For the case of plain sync() syscall, this is not true.

So it leads us back to need of passing "struct file" in ->sync_fs(). And fetching the writeback error from upper can be done only if a file is open on which syncfs() has been called.

Quoted 11 lines

It's not clear to me what semantics you want in the following situation:

mount upper layer
mount overlayfs with non-volatile upper layer
do "stuff" on overlayfs, and close all files on overlayfs get a writeback error on upper layer
call sync() (sync_fs gets run)
open file on upper layer mount
call syncfs() on upper-layer fd

Quoted 1 line

Should that last syncfs error report an error?

Actually, I was thinking of following.
- mount upper layer
- mount overlayfs (non-volatile)
- Do bunch of writes.
- A writeback error happens on upper file and gets recorded in upper fs sb.
- overlay application calls syncfs(fd) and gets the error back. IIUC, the way currently things are written, syncfs(fd) will not return writeback errors on overlayfs.

Quoted 3 lines

Also, suppose if at the end we instead opened a file on overlayfs and issued the syncfs() there -- should we see the error in that case?

I am thinking that behavior should be similar to as if two file descriptors have been opened on a regular filesystem. So if I open one fd1 on overlay and one fd2 on upper and they both were opened before writeback error happend, then syncfs(fd1) and syncfs(fd2), both should see the error.

And any of syncfs(fd1) and syncfs(fd2) should set the SEEN flag in upper_sb so that new errors can continue to be reported.

IOW, so looks like major problem with this patch is that we need to propagate error from upper_sb to overlaysb only if a valid file descriptor is open. IOW, do this in syncfs(fd) path and not sync() path. And to distinguish between two, we probably need to pass additional parameter in ->sync_fs().

Am I missing somehting. Just trying to make sure that if we are solving the problem of syncfs error propagation in overlay, lets solve it both for volatile as well as non-volatile case so that there is less confusion later.

Vivek

author maintainer
#15 lore raw

Re: [RFC PATCH 2/2] overlayfs: propagate errors from upper to overlay sb in sync_fs

Quoted 127 lines · Vivek Goyal
Quoted 87 lines · Jeff Layton
Quoted 76 lines · Jeff Layton
Quoted 63 lines · Vivek Goyal
Quoted 7 lines · Jeff Layton

Peek at the upper layer's errseq_t at mount time for volatile mounts, and record it in the per-sb info. In sync_fs, check for an error since the recorded point and set it in the overlayfs superblock if there was one.

---

While we are solving problem for non-volatile overlay mount, I also started thinking, what about non-volatile overlay syncfs() writeback errors. Looks like these will not be reported to user space at all as of now (because we never update overlay_sb->s_wb_err ever).

A patch like this might fix it. (compile tested only).

overlayfs: Report syncfs() errors to user space

Currently, syncfs(), calls filesystem ->sync_fs() method but ignores the return code. But certain writeback errors can still be reported on syncfs() by checking errors on super block.

ret2 = errseq_check_and_advance(&sb->s_wb_err, &f.file->f_sb_err);

For the case of overlayfs, we never set overlayfs super block s_wb_err. That means sync() will never report writeback errors on overlayfs uppon syncfs().

Fix this by updating overlay sb->sb_wb_err upon ->sync_fs() call. And that should mean that user space syncfs() call should see writeback errors.

ovl_fsync() does not need anything special because if there are writeback errors underlying filesystem will report it through vfs_fsync_range() return code and user space will see it.

---
 fs/overlayfs/ovl_entry.h | 1 +
 fs/overlayfs/super.c | 14 +++++++++++---

 2 files changed, 12 insertions(+), 3 deletions(-)

Index: redhat-linux/fs/overlayfs/super.c
===================================================================

fs/overlayfs/super.c +1 -1
@@ -259,7 +259,7 @@ static int ovl_sync_fs(struct super_bloc
  {
  	struct ovl_fs *ofs = sb->s_fs_info;
  	struct super_block *upper_sb;
-	int ret;
+	int ret, ret2;

  if (!ovl_upper_mnt(ofs))
  return 0;

fs/overlayfs/super.c +0 -0
@@ -283,7 +283,14 @@ static int ovl_sync_fs(struct super_bloc
  	ret = sync_filesystem(upper_sb);
  	up_read(&upper_sb->s_umount);

fs/overlayfs/super.c static int ovl_sync_fs(struct super_bloc · line 293

Quoted 9 lines
fs/overlayfs/super.c +8 -1
-	return ret;
+	if (errseq_check(&upper_sb->s_wb_err, sb->s_wb_err)) {
+		/* Upper sb has errors since last time */
+		spin_lock(&ofs->errseq_lock);
+		ret2 = errseq_check_and_advance(&upper_sb->s_wb_err,
+						&sb->s_wb_err);
+		spin_unlock(&ofs->errseq_lock);
+	}
+	return ret ? ret : ret2;

I think this is probably not quite right.

Quoted 9 lines

The problem I think is that the SEEN flag is always going to end up being set in sb->s_wb_err, and that is going to violate the desired semantics. If the writeback error occurred after all fd's were closed, then the next opener wouldn't see it and you'd lose the error.

We probably need a function to cleanly propagate the error from one errseq_t to another so that that doesn't occur. I'll have to think about it.

Quoted 5 lines

So, the problem is that we can't guarantee that we'll have an open file when sync_fs is called. So if you do the check_and_advance in the context of a sync() syscall, you'll effectively ensure that a later opener on the upper layer won't see the error (since the upper_sb's errseq_t will be marked SEEN.

Aha.., I assumed that when ->sync_fs() is called, we always have a valid fd open. But that's only true if ->sync_fs() is being called through syncfs(fd) syscall. For the case of plain sync() syscall, this is not true.

So it leads us back to need of passing "struct file" in ->sync_fs(). And fetching the writeback error from upper can be done only if a file is open on which syncfs() has been called.

Quoted 11 lines

It's not clear to me what semantics you want in the following situation:

mount upper layer
mount overlayfs with non-volatile upper layer
do "stuff" on overlayfs, and close all files on overlayfs get a writeback error on upper layer
call sync() (sync_fs gets run)
open file on upper layer mount
call syncfs() on upper-layer fd

Quoted 1 line

Should that last syncfs error report an error?

Actually, I was thinking of following.
- mount upper layer
- mount overlayfs (non-volatile)
- Do bunch of writes.
- A writeback error happens on upper file and gets recorded in upper fs sb.
- overlay application calls syncfs(fd) and gets the error back. IIUC, the way currently things are written, syncfs(fd) will not return writeback errors on overlayfs.

Quoted 1 line
Quoted 9 lines
Quoted 2 lines

Also, suppose if at the end we instead opened a file on overlayfs and issued the syncfs() there -- should we see the error in that case?

I am thinking that behavior should be similar to as if two file descriptors have been opened on a regular filesystem. So if I open one fd1 on overlay and one fd2 on upper and they both were opened before writeback error happend, then syncfs(fd1) and syncfs(fd2), both should see the error.

Yes, that will happen as a matter of course.

Quoted 3 lines

And any of syncfs(fd1) and syncfs(fd2) should set the SEEN flag in upper_sb so that new errors can continue to be reported.

The SEEN flag indicates whether a later opener should see an error that predated the open. Currently, it will iff no one else has scraped the error when the open is done.

Once we start dealing with overlayfs though, things are a bit more murky. If someone issues a sync on the upper sb and that triggers a writeback error. If I then do an open+syncfs on the overlay, should I see the error?

What about in the reverse case?

Quoted 11 lines

IOW, so looks like major problem with this patch is that we need to propagate error from upper_sb to overlaysb only if a valid file descriptor is open. IOW, do this in syncfs(fd) path and not sync() path. And to distinguish between two, we probably need to pass additional parameter in ->sync_fs().

Am I missing somehting. Just trying to make sure that if we are solving the problem of syncfs error propagation in overlay, lets solve it both for volatile as well as non-volatile case so that there is less confusion later.

It may be possible to propagate the errors in some fashion, but it's starting to sound pretty complex. I think we'd probably be better served by cleaning things up so that overlayfs can just return an error of its choosing to syncfs().

What may actually be best is to add a new ->syncfs op to struct file_operations, and turn the current syncfs syscall wrapper into a generic_syncfs or something. Then you could just define a syncfs op for overlayfs and do what you like in there.

Signature · 1 line
Jeff Layton <[email protected]>
#16 lore raw

Re: [RFC PATCH 2/2] overlayfs: propagate errors from upper to overlay sb in sync_fs

Quoted 145 lines · Jeff Layton
Quoted 127 lines · Vivek Goyal
Quoted 87 lines · Jeff Layton
Quoted 76 lines · Jeff Layton
Quoted 63 lines · Vivek Goyal
Quoted 7 lines · Jeff Layton

Peek at the upper layer's errseq_t at mount time for volatile mounts, and record it in the per-sb info. In sync_fs, check for an error since the recorded point and set it in the overlayfs superblock if there was one.

---

While we are solving problem for non-volatile overlay mount, I also started thinking, what about non-volatile overlay syncfs() writeback errors. Looks like these will not be reported to user space at all as of now (because we never update overlay_sb->s_wb_err ever).

A patch like this might fix it. (compile tested only).

overlayfs: Report syncfs() errors to user space

Currently, syncfs(), calls filesystem ->sync_fs() method but ignores the return code. But certain writeback errors can still be reported on syncfs() by checking errors on super block.

ret2 = errseq_check_and_advance(&sb->s_wb_err, &f.file->f_sb_err);

For the case of overlayfs, we never set overlayfs super block s_wb_err. That means sync() will never report writeback errors on overlayfs uppon syncfs().

Fix this by updating overlay sb->sb_wb_err upon ->sync_fs() call. And that should mean that user space syncfs() call should see writeback errors.

ovl_fsync() does not need anything special because if there are writeback errors underlying filesystem will report it through vfs_fsync_range() return code and user space will see it.

---
 fs/overlayfs/ovl_entry.h | 1 +
 fs/overlayfs/super.c | 14 +++++++++++---

 2 files changed, 12 insertions(+), 3 deletions(-)

Index: redhat-linux/fs/overlayfs/super.c
===================================================================

fs/overlayfs/super.c +1 -1
@@ -259,7 +259,7 @@ static int ovl_sync_fs(struct super_bloc
  {
  	struct ovl_fs *ofs = sb->s_fs_info;
  	struct super_block *upper_sb;
-	int ret;
+	int ret, ret2;

  if (!ovl_upper_mnt(ofs))
  return 0;

fs/overlayfs/super.c +0 -0
@@ -283,7 +283,14 @@ static int ovl_sync_fs(struct super_bloc
  	ret = sync_filesystem(upper_sb);
  	up_read(&upper_sb->s_umount);

fs/overlayfs/super.c static int ovl_sync_fs(struct super_bloc · line 293

Quoted 9 lines
fs/overlayfs/super.c +8 -1
-	return ret;
+	if (errseq_check(&upper_sb->s_wb_err, sb->s_wb_err)) {
+		/* Upper sb has errors since last time */
+		spin_lock(&ofs->errseq_lock);
+		ret2 = errseq_check_and_advance(&upper_sb->s_wb_err,
+						&sb->s_wb_err);
+		spin_unlock(&ofs->errseq_lock);
+	}
+	return ret ? ret : ret2;

I think this is probably not quite right.

Quoted 9 lines

The problem I think is that the SEEN flag is always going to end up being set in sb->s_wb_err, and that is going to violate the desired semantics. If the writeback error occurred after all fd's were closed, then the next opener wouldn't see it and you'd lose the error.

We probably need a function to cleanly propagate the error from one errseq_t to another so that that doesn't occur. I'll have to think about it.

Quoted 5 lines

So, the problem is that we can't guarantee that we'll have an open file when sync_fs is called. So if you do the check_and_advance in the context of a sync() syscall, you'll effectively ensure that a later opener on the upper layer won't see the error (since the upper_sb's errseq_t will be marked SEEN.

Aha.., I assumed that when ->sync_fs() is called, we always have a valid fd open. But that's only true if ->sync_fs() is being called through syncfs(fd) syscall. For the case of plain sync() syscall, this is not true.

So it leads us back to need of passing "struct file" in ->sync_fs(). And fetching the writeback error from upper can be done only if a file is open on which syncfs() has been called.

Quoted 11 lines

It's not clear to me what semantics you want in the following situation:

mount upper layer
mount overlayfs with non-volatile upper layer
do "stuff" on overlayfs, and close all files on overlayfs get a writeback error on upper layer
call sync() (sync_fs gets run)
open file on upper layer mount
call syncfs() on upper-layer fd

Quoted 1 line

Should that last syncfs error report an error?

Actually, I was thinking of following.
- mount upper layer
- mount overlayfs (non-volatile)
- Do bunch of writes.
- A writeback error happens on upper file and gets recorded in upper fs sb.
- overlay application calls syncfs(fd) and gets the error back. IIUC, the way currently things are written, syncfs(fd) will not return writeback errors on overlayfs.

Quoted 1 line
Quoted 9 lines
Quoted 2 lines

Also, suppose if at the end we instead opened a file on overlayfs and issued the syncfs() there -- should we see the error in that case?

I am thinking that behavior should be similar to as if two file descriptors have been opened on a regular filesystem. So if I open one fd1 on overlay and one fd2 on upper and they both were opened before writeback error happend, then syncfs(fd1) and syncfs(fd2), both should see the error.

Yes, that will happen as a matter of course.

Quoted 3 lines

And any of syncfs(fd1) and syncfs(fd2) should set the SEEN flag in upper_sb so that new errors can continue to be reported.

Quoted 8 lines

The SEEN flag indicates whether a later opener should see an error that predated the open. Currently, it will iff no one else has scraped the error when the open is done.

Once we start dealing with overlayfs though, things are a bit more murky. If someone issues a sync on the upper sb and that triggers a writeback error. If I then do an open+syncfs on the overlay, should I see the error?

I think that yes, open+syncfs on the overlay should see this UNSEEN error. IOW, this will be similar to as if somebody did an open+syncfs on upper and scrapped UNSEEN error.

Quoted 2 lines

What about in the reverse case?

Same for reverse case. If overlayfs triggered sync and resulted in in unseen error on upper sb, then a later open+syncfs on upper should see the error.

Thanks
Vivek

Quoted 26 lines
Quoted 7 lines

IOW, so looks like major problem with this patch is that we need to propagate error from upper_sb to overlaysb only if a valid file descriptor is open. IOW, do this in syncfs(fd) path and not sync() path. And to distinguish between two, we probably need to pass additional parameter in ->sync_fs().

Quoted 5 lines

Am I missing somehting. Just trying to make sure that if we are solving the problem of syncfs error propagation in overlay, lets solve it both for volatile as well as non-volatile case so that there is less confusion later.

It may be possible to propagate the errors in some fashion, but it's starting to sound pretty complex. I think we'd probably be better served by cleaning things up so that overlayfs can just return an error of its choosing to syncfs().

What may actually be best is to add a new ->syncfs op to struct file_operations, and turn the current syncfs syscall wrapper into a generic_syncfs or something. Then you could just define a syncfs op for overlayfs and do what you like in there.

Signature · 1 line
Jeff Layton <[email protected]>
#17 lore raw

Re: [RFC PATCH 2/2] overlayfs: propagate errors from upper to overlay sb in sync_fs

In reply to Jeff Layton
Quoted 76 lines · Jeff Layton
Quoted 63 lines · Vivek Goyal
Quoted 7 lines · Jeff Layton

Peek at the upper layer's errseq_t at mount time for volatile mounts, and record it in the per-sb info. In sync_fs, check for an error since the recorded point and set it in the overlayfs superblock if there was one.

---

While we are solving problem for non-volatile overlay mount, I also started thinking, what about non-volatile overlay syncfs() writeback errors. Looks like these will not be reported to user space at all as of now (because we never update overlay_sb->s_wb_err ever).

A patch like this might fix it. (compile tested only).

overlayfs: Report syncfs() errors to user space

Currently, syncfs(), calls filesystem ->sync_fs() method but ignores the return code. But certain writeback errors can still be reported on syncfs() by checking errors on super block.

ret2 = errseq_check_and_advance(&sb->s_wb_err, &f.file->f_sb_err);

For the case of overlayfs, we never set overlayfs super block s_wb_err. That means sync() will never report writeback errors on overlayfs uppon syncfs().

Fix this by updating overlay sb->sb_wb_err upon ->sync_fs() call. And that should mean that user space syncfs() call should see writeback errors.

ovl_fsync() does not need anything special because if there are writeback errors underlying filesystem will report it through vfs_fsync_range() return code and user space will see it.

---
 fs/overlayfs/ovl_entry.h | 1 +
 fs/overlayfs/super.c | 14 +++++++++++---

 2 files changed, 12 insertions(+), 3 deletions(-)

Index: redhat-linux/fs/overlayfs/super.c
===================================================================

fs/overlayfs/super.c +1 -1
@@ -259,7 +259,7 @@ static int ovl_sync_fs(struct super_bloc
  {
  	struct ovl_fs *ofs = sb->s_fs_info;
  	struct super_block *upper_sb;
-	int ret;
+	int ret, ret2;

  if (!ovl_upper_mnt(ofs))
  return 0;

fs/overlayfs/super.c +0 -0
@@ -283,7 +283,14 @@ static int ovl_sync_fs(struct super_bloc
  	ret = sync_filesystem(upper_sb);
  	up_read(&upper_sb->s_umount);

fs/overlayfs/super.c static int ovl_sync_fs(struct super_bloc · line 293

Quoted 9 lines
fs/overlayfs/super.c +8 -1
-	return ret;
+	if (errseq_check(&upper_sb->s_wb_err, sb->s_wb_err)) {
+		/* Upper sb has errors since last time */
+		spin_lock(&ofs->errseq_lock);
+		ret2 = errseq_check_and_advance(&upper_sb->s_wb_err,
+						&sb->s_wb_err);
+		spin_unlock(&ofs->errseq_lock);
+	}
+	return ret ? ret : ret2;

I think this is probably not quite right.

Quoted 4 lines

The problem I think is that the SEEN flag is always going to end up being set in sb->s_wb_err, and that is going to violate the desired semantics. If the writeback error occurred after all fd's were closed, then the next opener wouldn't see it and you'd lose the error.

So this will happen only due to sync() path and not syncfs() path, right? If we avoid calling errseq_check_and_advance() in sync() path in ovleryafs(), then we always have a valid fd and marking error SEEN on upper is perfectly valid?

Quoted 4 lines

We probably need a function to cleanly propagate the error from one errseq_t to another so that that doesn't occur. I'll have to think about it.

Thanks
Vivek

Quoted 53 lines
Quoted 49 lines

 }

 /**

fs/overlayfs/super.c +0 -0
@@ -1873,6 +1880,7 @@ static int ovl_fill_super(struct super_b
  	if (!cred)
  		goto out_err;

fs/overlayfs/super.c +1 -0
+	spin_lock_init(&ofs->errseq_lock);

  /* Is there a reason anyone would want not to share whiteouts? */ ofs->share_whiteout = true;

fs/overlayfs/super.c +0 -0
@@ -1945,7 +1953,7 @@ static int ovl_fill_super(struct super_b

  sb->s_stack_depth = ovl_upper_mnt(ofs)->mnt_sb->s_stack_depth; sb->s_time_gran = ovl_upper_mnt(ofs)->mnt_sb->s_time_gran;

fs/overlayfs/super.c +1 -1
-
+		sb->s_wb_err = errseq_sample(&ovl_upper_mnt(ofs)->mnt_sb->s_wb_err);

  }
  oe = ovl_get_lowerstack(sb, splitlower, numlower, ofs, layers); err = PTR_ERR(oe);
Index: redhat-linux/fs/overlayfs/ovl_entry.h
===================================================================

fs/overlayfs/ovl_entry.h +1 -0
@@ -79,6 +79,7 @@ struct ovl_fs {
  	atomic_long_t last_ino;
  	/* Whiteout dentry cache */
  	struct dentry *whiteout;
+	spinlock_t errseq_lock;
  };

 static inline struct vfsmount *ovl_upper_mnt(struct ovl_fs *ofs)

Signature · 1 line
Jeff Layton <[email protected]>
#18 lore raw

Re: [RFC PATCH 2/2] overlayfs: propagate errors from upper to overlay sb in sync_fs

In reply to Jeff Layton
Quoted 59 lines · Jeff Layton

Peek at the upper layer's errseq_t at mount time for volatile mounts, and record it in the per-sb info. In sync_fs, check for an error since the recorded point and set it in the overlayfs superblock if there was one.

---
 fs/overlayfs/ovl_entry.h |  1 +
 fs/overlayfs/super.c     | 14 +++++++++++---
 2 files changed, 12 insertions(+), 3 deletions(-)
fs/overlayfs/ovl_entry.h +1 -0
index 1b5a2094df8e..fcfcc3951973 100644
@@ -79,6 +79,7 @@ struct ovl_fs {
 	atomic_long_t last_ino;
 	/* Whiteout dentry cache */
 	struct dentry *whiteout;
+	errseq_t err_mark;
 };
 
 static inline struct vfsmount *ovl_upper_mnt(struct ovl_fs *ofs)
fs/overlayfs/super.c +11 -3
index 290983bcfbb3..2985d2752970 100644
@@ -264,8 +264,13 @@ static int ovl_sync_fs(struct super_block *sb, int wait)
 	if (!ovl_upper_mnt(ofs))
 		return 0;
 
-	if (!ovl_should_sync(ofs))
-		return 0;
+	if (!ovl_should_sync(ofs)) {
+		/* Propagate errors from upper to overlayfs */
+		ret = errseq_check(&upper_sb->s_wb_err, ofs->err_mark);
+		errseq_set(&sb->s_wb_err, ret);
+		return ret;
+	}
+
 	/*
 	 * Not called for sync(2) call or an emergency sync (SB_I_SKIP_SYNC).
 	 * All the super blocks will be iterated, including upper_sb.
@@ -1945,8 +1950,11 @@ static int ovl_fill_super(struct super_block *sb, void *data, int silent)
 
 		sb->s_stack_depth = ovl_upper_mnt(ofs)->mnt_sb->s_stack_depth;
 		sb->s_time_gran = ovl_upper_mnt(ofs)->mnt_sb->s_time_gran;
-
 	}
+
+	if (ofs->config.ovl_volatile)
+		ofs->err_mark = errseq_peek(&ovl_upper_mnt(ofs)->mnt_sb->s_wb_err);
+
 	oe = ovl_get_lowerstack(sb, splitlower, numlower, ofs, layers);
 	err = PTR_ERR(oe);
 	if (IS_ERR(oe))
Signature · 1 line
2.29.2

I've tested this with the following scenarios, seems to work:
Test:
1. Mount ext2 on /mnt/loop, and cause a writeback error
2. Verify syncfs on /mnt/loop shows error
3. Mount volatile filesystem
4. Create file on volatile filesystem, and verify that I can syncfs it without error
---
Fork:

5a. Create a file on overlayfs, and generate a writeback error 6a. Syncfs overlayfs.
7a. Create a new file on overlayfs, and syncfs, and verify it returns error

---
5b. Create a file on loop back, and generate a writeback error
6b. Sync said file
7b. Verify syncfs on loop returns error once, and then success on next attempts 8b. Verify all syncfs on overlayfs now fail

---
5c. Create file on overlayfs, and generate a writeback error 6c. Sync overlayfs, and verify all syncs are failures 7c. Verify syncfs on loop fails once.

#19 lore raw
In reply to Jeff Layton
Quoted 10 lines · Jeff Layton

What about this as an alternate approach to the problem that Sargun has been working on? I have some minor concerns about the complexity of managing a stateful object across two different words. That can be done, but I think this may be simpler.

This set steals an extra flag bit from the errseq_t counter so that we have two flags: one indicating whether to increment the counter at set time, and another to indicate whether the error has been reported to userland.

This approach works, and I believe you suggested it early on, but I was unsure whether it was okay to use another bit for state information.

Quoted 4 lines

This should give you the semantics you want in the syncfs case, no? If this does look like it's a suitable approach, then I'll plan to clean up the comments and docs.

From a raw semantics perspective, this looks correct, and it looks like we could stash it as well for later reference (there's no going backwards, and....well, 2**19 errors is unlikely.). We do ~10s of overlayfs mounts / sec at peak, but even then we usually see a single disk error on a machine before it fails, I'm not sure if in the field people get more churn out of the errseq than that.

Quoted 17 lines

I have a vague feeling that this might help us eventually kill the AS_EIO and AS_ENOSPC bits too, but that would require a bit more work to plumb in "since" samples at appropriate places.

Jeff Layton (2):
errseq: split the SEEN flag into two new flags
overlayfs: propagate errors from upper to overlay sb in sync_fs

 fs/overlayfs/ovl_entry.h |  1 +
 fs/overlayfs/super.c     | 14 +++++++--
 include/linux/errseq.h   |  2 ++
 lib/errseq.c             | 64 +++++++++++++++++++++++++++++++++-------
 4 files changed, 67 insertions(+), 14 deletions(-)
Signature · 1 line
2.29.2