ubifs: ubifs to export filesystem error counters
Subsystems (2)
PATCH v2 1/1 ubifs: ubifs to export filesystem error counters
Not all ubifs filesystem errors are propagated to userspace.
Export bad magic, bad node and crc errors via sysfs. This allows userspace to notice filesystem errors:
/sys/fs/ubifs/ubiX_Y/errors_magic
/sys/fs/ubifs/ubiX_Y/errors_node
/sys/fs/ubifs/ubiX_Y/errors_crc
The counters are reset to 0 with a remount.
---
Changes in v2:
- merged sysfs.h header into ubifs.h.
- io.c: wrapped incrementing error counters into new functions
record_*_error().
- sysfs.c: removed sysfs write callback for clearing stats.
- sysfs.c: ubifs_sysfs_register(): free c->stats on error.
- sysfs.c: ubifs_attr_show(): use sysfs_emit().
fs/ubifs/Makefile | 2 +- fs/ubifs/io.c | 21 +++++++ fs/ubifs/super.c | 16 ++++- fs/ubifs/sysfs.c | 153 ++++++++++++++++++++++++++++++++++++++++++++++ fs/ubifs/ubifs.h | 35 +++++++++++ 5 files changed, 225 insertions(+), 2 deletions(-) create mode 100644 fs/ubifs/sysfs.c
fs/ubifs/Makefile +1 -1
@@ -5,7 +5,7 @@ ubifs-y += shrinker.o journal.o file.o dir.o super.o sb.o io.o ubifs-y += tnc.o master.o scan.o replay.o log.o commit.o gc.o orphan.o ubifs-y += budget.o find.o tnc_commit.o compress.o lpt.o lprops.o ubifs-y += recovery.o ioctl.o lpt_commit.o tnc_misc.o debug.o -ubifs-y += misc.o +ubifs-y += misc.o sysfs.o ubifs-$(CONFIG_FS_ENCRYPTION) += crypto.o ubifs-$(CONFIG_UBIFS_FS_XATTR) += xattr.o ubifs-$(CONFIG_UBIFS_FS_AUTHENTICATION) += auth.o
fs/ubifs/io.c +21 -0
@@ -194,6 +194,24 @@ int ubifs_is_mapped(const struct ubifs_info *c, int lnum)return err; } +static void record_magic_error (struct ubifs_stats_info *stats) +{ +if (stats) + stats->magic_errors++; +} + +static void record_node_error (struct ubifs_stats_info *stats) +{ +if (stats) + stats->node_errors++; +} + +static void record_crc_error (struct ubifs_stats_info *stats) +{ +if (stats) + stats->crc_errors++; +} +/** * ubifs_check_node - check node. * @c: UBIFS file-system description object
@@ -238,6 +256,7 @@ int ubifs_check_node(const struct ubifs_info *c, const void *buf, int len,if (!quiet)ubifs_err (c,"bad magic %#08x, expected %#08x" , magic,UBIFS_NODE_MAGIC ); +record_magic_error (c->stats); err = -EUCLEAN ; goto out; }
@@ -246,6 +265,7 @@ int ubifs_check_node(const struct ubifs_info *c, const void *buf, int len,if (type <0 || type >=UBIFS_NODE_TYPES_CNT ) {if (!quiet)ubifs_err (c,"bad node type %d" , type); +record_node_error (c->stats); goto out; }
@@ -270,6 +290,7 @@ int ubifs_check_node(const struct ubifs_info *c, const void *buf, int len,if (!quiet)ubifs_err (c,"bad CRC: calculated %#08x, read %#08x" , crc, node_crc); +record_crc_error (c->stats); err = -EUCLEAN ; goto out; }
fs/ubifs/super.c +15 -1
@@ -1264,6 +1264,10 @@ static int mount_ubifs(struct ubifs_info *c)if (err)return err; + err =ubifs_sysfs_register (c); +if (err) + goto out_debugging; + err =check_volume_empty (c);if (err) goto out_free;
@@ -1641,6 +1645,8 @@ static int mount_ubifs(struct ubifs_info *c)vfree (c->sbuf);kfree (c->bottom_up_buf);kfree (c->sup_node); +ubifs_sysfs_unregister (c); +out_debugging:ubifs_debugging_exit (c);return err; }
@@ -1684,6 +1690,7 @@ static void ubifs_umount(struct ubifs_info *c)kfree (c->bottom_up_buf);kfree (c->sup_node);ubifs_debugging_exit (c); +ubifs_sysfs_unregister (c); }/**
@@ -2436,14 +2443,20 @@ static int __init ubifs_init(void)dbg_debugfs_init (); + err =ubifs_sysfs_init (); +if (err) + goto out_dbg; + err =register_filesystem (&ubifs_fs_type);if (err) {pr_err ("UBIFS error (pid %d): cannot register file system, error %d" , current->pid, err); - goto out_dbg; + goto out_sysfs; }return 0 ; +out_sysfs: +ubifs_sysfs_exit (); out_dbg:dbg_debugfs_exit ();ubifs_compressors_exit ();
@@ -2462,6 +2475,7 @@ static void __exit ubifs_exit(void)WARN_ON (atomic_long_read (&ubifs_clean_zn_cnt) !=0 );dbg_debugfs_exit (); +ubifs_sysfs_exit ();ubifs_compressors_exit ();unregister_shrinker (&ubifs_shrinker_info);
fs/ubifs/sysfs.c new file +153 -0
153 lines not on this page · raw message
fs/ubifs/ubifs.h +35 -0
@@ -27,6 +27,8 @@#include <linux/security.h> #include <linux/xattr.h> #include <linux/random.h> +#include <linux/sysfs.h> +#include <linux/completion.h> #include <crypto/hash_info.h> #include <crypto/hash.h> #include <crypto/algapi.h>
@@ -155,6 +157,13 @@#define UBIFS_HMAC_ARR_SZ 0#endif +/* +* The UBIFS sysfs directory name pattern and maximum name length (3 for "ubi" +* + 1 for "_" and plus 2x2 for 2 UBI numbers and 1 for the trailing zero byte. +*/ +#define UBIFS_DFS_DIR_NAME "ubi%d_%d" +#define UBIFS_DFS_DIR_LEN (3 + 1 + 2*2 + 1) +/* * Lockdep classes for UBIFS inode @ui_mutex. */
@@ -990,6 +999,18 @@ struct ubifs_budg_info {int dent_budget; }; +/** +* ubifs_stats_info - per-FS statistics information. +* @magic_errors: number of bad magic numbers (will be reset with a new mount). +* @node_errors: number of bad nodes (will be reset with a new mount). +* @crc_errors: number of bad crcs (will be reset with a new mount). +*/ +struct ubifs_stats_info { +unsigned int magic_errors; +unsigned int node_errors; +unsigned int crc_errors; +}; +struct ubifs_debug_info ;/**
@@ -1251,6 +1272,10 @@ struct ubifs_debug_info;* @mount_opts: UBIFS-specific mount options * * @dbg: debugging-related information +* @stats: statistics exported over sysfs +* +* @kobj: kobject for /sys/fs/ubifs/ +* @kobj_unregister: completion to unregister sysfs kobject */ struct ubifs_info {struct super_block *vfs_sb;
@@ -1286,6 +1311,9 @@ struct ubifs_info {spinlock_t cs_lock;wait_queue_head_t cmt_wq; +struct kobject kobj; +struct completion kobj_unregister; + unsigned int big_lpt:1; unsigned int space_fixup:1; unsigned int double_hash:1;
@@ -1493,6 +1521,7 @@ struct ubifs_info {struct ubifs_mount_opts mount_opts;struct ubifs_debug_info *dbg; +struct ubifs_stats_info *stats; };extern struct list_head ubifs_infos;
@@ -2072,6 +2101,12 @@ void ubifs_compress(const struct ubifs_info *c, const void *in_buf, int in_len,int ubifs_decompress (const struct ubifs_info *c,const void *buf,int len,void *out,int *out_len,int compr_type); +/* sysfs.c */ +int ubifs_sysfs_init (void ); +void ubifs_sysfs_exit (void ); +int ubifs_sysfs_register (struct ubifs_info *c); +void ubifs_sysfs_unregister (struct ubifs_info *c); +#include "debug.h" #include "misc.h" #include "key.h"
--
2.33.0
Richard Weinberger
maintainerStefan,
----- Ursprüngliche Mail -----
Quoted 28 lines
Von: "schaecsn" <[email protected]>
An: "richard" <[email protected]>, "linux-mtd" <[email protected]>, "linux-kernel" <[email protected]>
CC: "schaecsn" <[email protected]>, "Stefan Schaeckeler" <[email protected]>
Gesendet: Sonntag, 10. Oktober 2021 06:22:39
Betreff: [PATCH v2] ubifs: ubifs to export filesystem error countersNot all ubifs filesystem errors are propagated to userspace.
Export bad magic, bad node and crc errors via sysfs. This allows userspace to notice filesystem errors:
/sys/fs/ubifs/ubiX_Y/errors_magic/sys/fs/ubifs/ubiX_Y/errors_node/sys/fs/ubifs/ubiX_Y/errors_crcThe counters are reset to 0 with a remount.
Signed-off-by Stefan Schaeckeler <[email protected]>---
Changes in v2:
- mergedsysfs.hheader intoubifs.h.
-io.c: wrapped incrementing error counters into new functions record_*_error().
-sysfs.c: removed sysfs write callback for clearing stats.
-sysfs.c:ubifs_sysfs_register(): freec->statson error.
-sysfs.c:ubifs_attr_show(): usesysfs_emit().
Quoted 7 lines
fs/ubifs/Makefile | 2 +- fs/ubifs/io.c | 21 +++++++ fs/ubifs/super.c | 16 ++++- fs/ubifs/sysfs.c | 153 ++++++++++++++++++++++++++++++++++++++++++++++ fs/ubifs/ubifs.h | 35 +++++++++++ 5 files changed, 225 insertions(+), 2 deletions(-)create mode 100644
fs/ubifs/sysfs.c
Queued for 5.16.
I just noticed forgot to request sysfs documentation in Documentation/ABI/. Can you please send a followup patch?
Thanks,
//richard
Hello Richard,
Quoted 29 lines
Quoted 21 lines
Not all ubifs filesystem errors are propagated to userspace.
Export bad magic, bad node and crc errors via sysfs. This allows userspace to notice filesystem errors:
/sys/fs/ubifs/ubiX_Y/errors_magic/sys/fs/ubifs/ubiX_Y/errors_node/sys/fs/ubifs/ubiX_Y/errors_crcThe counters are reset to 0 with a remount.
Signed-off-by Stefan Schaeckeler <[email protected]>---
Changes in v2:
- mergedsysfs.hheader intoubifs.h.
-io.c: wrapped incrementing error counters into new functions record_*_error().
-sysfs.c: removed sysfs write callback for clearing stats.
-sysfs.c:ubifs_sysfs_register(): freec->statson error.
-sysfs.c:ubifs_attr_show(): usesysfs_emit().Quoted 7 lines
fs/ubifs/Makefile | 2 +- fs/ubifs/io.c | 21 +++++++ fs/ubifs/super.c | 16 ++++- fs/ubifs/sysfs.c | 153 ++++++++++++++++++++++++++++++++++++++++++++++ fs/ubifs/ubifs.h | 35 +++++++++++ 5 files changed, 225 insertions(+), 2 deletions(-)create mode 100644
fs/ubifs/sysfs.c
Quoted 1 line
Queued for 5.16.
The merge window for 5.16 is about to close. May I point out that, as far as I can tell, you have not sent a pull request for ubifs, yet.
Stefan
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/