* [fsinfo PATCH v2 1/3] errseq: add a new errseq_scrape function
2020-06-26 15:04 [fsinfo PATCH v2 0/3] fsinfo: add error state information to fsinfo Jeff Layton
@ 2020-06-26 15:04 ` Jeff Layton
2020-06-26 15:04 ` [fsinfo PATCH v2 2/3] vfs: allow fsinfo to fetch the current state of s_wb_err Jeff Layton
2020-06-26 15:05 ` [fsinfo PATCH v2 3/3] samples: add error state information to test-fsinfo.c Jeff Layton
2 siblings, 0 replies; 4+ messages in thread
From: Jeff Layton @ 2020-06-26 15:04 UTC (permalink / raw)
To: dhowells; +Cc: linux-fsdevel, andres
From: Jeff Layton <jlayton@redhat.com>
To grab the current value of an errseq_t, mark it as seen and then
return the value with the seen bit masked off.
Signed-off-by: Jeff Layton <jlayton@redhat.com>
Reviewed-by: David Howells <dhowells@redhat.com>
Reviewed-by: Carlos Maiolino <cmaiolino@redhat.com>
---
include/linux/errseq.h | 1 +
lib/errseq.c | 33 +++++++++++++++++++++++++++++++--
2 files changed, 32 insertions(+), 2 deletions(-)
diff --git a/include/linux/errseq.h b/include/linux/errseq.h
index fc2777770768..de165623fa86 100644
--- a/include/linux/errseq.h
+++ b/include/linux/errseq.h
@@ -9,6 +9,7 @@ typedef u32 errseq_t;
errseq_t errseq_set(errseq_t *eseq, int err);
errseq_t errseq_sample(errseq_t *eseq);
+errseq_t errseq_scrape(errseq_t *eseq);
int errseq_check(errseq_t *eseq, errseq_t since);
int errseq_check_and_advance(errseq_t *eseq, errseq_t *since);
#endif
diff --git a/lib/errseq.c b/lib/errseq.c
index 81f9e33aa7e7..8ded0920eed3 100644
--- a/lib/errseq.c
+++ b/lib/errseq.c
@@ -108,7 +108,7 @@ errseq_t errseq_set(errseq_t *eseq, int err)
EXPORT_SYMBOL(errseq_set);
/**
- * errseq_sample() - Grab current errseq_t value.
+ * errseq_sample() - Grab current errseq_t value (or 0 if it hasn't been seen)
* @eseq: Pointer to errseq_t to be sampled.
*
* This function allows callers to initialise their errseq_t variable.
@@ -117,7 +117,7 @@ EXPORT_SYMBOL(errseq_set);
* see it the next time it checks for an error.
*
* Context: Any context.
- * Return: The current errseq value.
+ * Return: The current errseq value or 0 if it wasn't previously seen
*/
errseq_t errseq_sample(errseq_t *eseq)
{
@@ -130,6 +130,35 @@ errseq_t errseq_sample(errseq_t *eseq)
}
EXPORT_SYMBOL(errseq_sample);
+/**
+ * errseq_scrape() - Grab current errseq_t value
+ * @eseq: Pointer to errseq_t to be sampled.
+ *
+ * This function allows callers to scrape the current value of an errseq_t.
+ * Unlike errseq_sample, this will always return the current value with
+ * the SEEN flag unset, even when the value has not yet been seen.
+ *
+ * Context: Any context.
+ * Return: The current errseq value with ERRSEQ_SEEN masked off
+ */
+errseq_t errseq_scrape(errseq_t *eseq)
+{
+ errseq_t old = READ_ONCE(*eseq);
+
+ /*
+ * For the common case of no errors ever having been set, we can skip
+ * marking the SEEN bit. Once an error has been set, the value will
+ * never go back to zero.
+ */
+ if (old != 0) {
+ errseq_t new = old | ERRSEQ_SEEN;
+ if (old != new)
+ cmpxchg(eseq, old, new);
+ }
+ return old & ~ERRSEQ_SEEN;
+}
+EXPORT_SYMBOL(errseq_scrape);
+
/**
* errseq_check() - Has an error occurred since a particular sample point?
* @eseq: Pointer to errseq_t value to be checked.
--
2.26.2
^ permalink raw reply related [flat|nested] 4+ messages in thread* [fsinfo PATCH v2 2/3] vfs: allow fsinfo to fetch the current state of s_wb_err
2020-06-26 15:04 [fsinfo PATCH v2 0/3] fsinfo: add error state information to fsinfo Jeff Layton
2020-06-26 15:04 ` [fsinfo PATCH v2 1/3] errseq: add a new errseq_scrape function Jeff Layton
@ 2020-06-26 15:04 ` Jeff Layton
2020-06-26 15:05 ` [fsinfo PATCH v2 3/3] samples: add error state information to test-fsinfo.c Jeff Layton
2 siblings, 0 replies; 4+ messages in thread
From: Jeff Layton @ 2020-06-26 15:04 UTC (permalink / raw)
To: dhowells; +Cc: linux-fsdevel, andres
From: Jeff Layton <jlayton@redhat.com>
Add a new "error_state" struct to fsinfo, and teach the kernel to fill
that out from sb->s_wb_err. There are two fields:
wb_error_last: the most recently recorded errno for the filesystem
wb_error_cookie: this value will change vs. the previously fetched
value if a new error was recorded since it was last
checked. Callers should treat this as an opaque value
that can be compared to earlier fetched values.
Signed-off-by: Jeff Layton <jlayton@redhat.com>
---
fs/fsinfo.c | 11 +++++++++++
include/uapi/linux/fsinfo.h | 13 +++++++++++++
2 files changed, 24 insertions(+)
diff --git a/fs/fsinfo.c b/fs/fsinfo.c
index 18b533b79cea..2934e05328ed 100644
--- a/fs/fsinfo.c
+++ b/fs/fsinfo.c
@@ -274,6 +274,16 @@ static int fsinfo_generic_seq_read(struct path *path, struct fsinfo_context *ctx
return m.count + 1;
}
+static int fsinfo_generic_error_state(struct path *path,
+ struct fsinfo_context *ctx)
+{
+ struct fsinfo_error_state *es = ctx->buffer;
+
+ es->wb_error_cookie = errseq_scrape(&path->dentry->d_sb->s_wb_err);
+ es->wb_error_last = es->wb_error_cookie & MAX_ERRNO;
+ return sizeof(*es);
+}
+
static const struct fsinfo_attribute fsinfo_common_attributes[] = {
FSINFO_VSTRUCT (FSINFO_ATTR_STATFS, fsinfo_generic_statfs),
FSINFO_VSTRUCT (FSINFO_ATTR_IDS, fsinfo_generic_ids),
@@ -286,6 +296,7 @@ static const struct fsinfo_attribute fsinfo_common_attributes[] = {
FSINFO_STRING (FSINFO_ATTR_SOURCE, fsinfo_generic_mount_source),
FSINFO_STRING (FSINFO_ATTR_CONFIGURATION, fsinfo_generic_seq_read),
FSINFO_STRING (FSINFO_ATTR_FS_STATISTICS, fsinfo_generic_seq_read),
+ FSINFO_VSTRUCT (FSINFO_ATTR_ERROR_STATE, fsinfo_generic_error_state),
FSINFO_LIST (FSINFO_ATTR_FSINFO_ATTRIBUTES, (void *)123UL),
FSINFO_VSTRUCT_N(FSINFO_ATTR_FSINFO_ATTRIBUTE_INFO, (void *)123UL),
diff --git a/include/uapi/linux/fsinfo.h b/include/uapi/linux/fsinfo.h
index af681b2e0e7e..72b0e7207a8a 100644
--- a/include/uapi/linux/fsinfo.h
+++ b/include/uapi/linux/fsinfo.h
@@ -27,6 +27,7 @@
#define FSINFO_ATTR_SOURCE 0x09 /* Superblock source/device name (string) */
#define FSINFO_ATTR_CONFIGURATION 0x0a /* Superblock configuration/options (string) */
#define FSINFO_ATTR_FS_STATISTICS 0x0b /* Superblock filesystem statistics (string) */
+#define FSINFO_ATTR_ERROR_STATE 0x0c /* Superblock writeback error state */
#define FSINFO_ATTR_FSINFO_ATTRIBUTE_INFO 0x100 /* Information about attr N (for path) */
#define FSINFO_ATTR_FSINFO_ATTRIBUTES 0x101 /* List of supported attrs (for path) */
@@ -332,4 +333,16 @@ struct fsinfo_afs_server_address {
#define FSINFO_ATTR_AFS_SERVER_ADDRESSES__STRUCT struct fsinfo_afs_server_address
+/*
+ * Information struct for fsinfo(FSINFO_ATTR_ERROR_STATE).
+ *
+ * Retrieve the error state for a filesystem.
+ */
+struct fsinfo_error_state {
+ __u32 wb_error_cookie; /* writeback error cookie */
+ __u32 wb_error_last; /* latest writeback error */
+};
+
+#define FSINFO_ATTR_ERROR_STATE__STRUCT struct fsinfo_error_state
+
#endif /* _UAPI_LINUX_FSINFO_H */
--
2.26.2
^ permalink raw reply related [flat|nested] 4+ messages in thread* [fsinfo PATCH v2 3/3] samples: add error state information to test-fsinfo.c
2020-06-26 15:04 [fsinfo PATCH v2 0/3] fsinfo: add error state information to fsinfo Jeff Layton
2020-06-26 15:04 ` [fsinfo PATCH v2 1/3] errseq: add a new errseq_scrape function Jeff Layton
2020-06-26 15:04 ` [fsinfo PATCH v2 2/3] vfs: allow fsinfo to fetch the current state of s_wb_err Jeff Layton
@ 2020-06-26 15:05 ` Jeff Layton
2 siblings, 0 replies; 4+ messages in thread
From: Jeff Layton @ 2020-06-26 15:05 UTC (permalink / raw)
To: dhowells; +Cc: linux-fsdevel, andres
Signed-off-by: Jeff Layton <jlayton@kernel.org>
---
samples/vfs/test-fsinfo.c | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/samples/vfs/test-fsinfo.c b/samples/vfs/test-fsinfo.c
index 26bf23121c9a..7f43320174d2 100644
--- a/samples/vfs/test-fsinfo.c
+++ b/samples/vfs/test-fsinfo.c
@@ -411,6 +411,15 @@ static void dump_afs_fsinfo_server_address(void *reply, unsigned int size)
printf("family=%u\n", ss->ss_family);
}
+static void dump_fsinfo_generic_error_state(void *reply, unsigned int size)
+{
+ struct fsinfo_error_state *es = reply;
+
+ printf("\n");
+ printf("\tlatest error : %d (%s)\n", es->wb_error_last, strerror(es->wb_error_last));
+ printf("\tcookie : 0x%x\n", es->wb_error_cookie);
+}
+
static void dump_string(void *reply, unsigned int size)
{
char *s = reply, *p;
@@ -499,6 +508,7 @@ static const struct fsinfo_attribute fsinfo_attributes[] = {
FSINFO_STRING (FSINFO_ATTR_AFS_CELL_NAME, string),
FSINFO_STRING (FSINFO_ATTR_AFS_SERVER_NAME, string),
FSINFO_LIST_N (FSINFO_ATTR_AFS_SERVER_ADDRESSES, afs_fsinfo_server_address),
+ FSINFO_VSTRUCT (FSINFO_ATTR_ERROR_STATE, fsinfo_generic_error_state),
{}
};
--
2.26.2
^ permalink raw reply related [flat|nested] 4+ messages in thread