Skip to content

Commit aaa04b4

Browse files
OGAWAHirofumitorvalds
authored andcommitted
fatfs: ratelimit corruption report
Signed-off-by: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent f40c396 commit aaa04b4

4 files changed

Lines changed: 31 additions & 18 deletions

File tree

‎fs/fat/cache.c‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -242,9 +242,10 @@ int fat_get_cluster(struct inode *inode, int cluster, int *fclus, int *dclus)
242242
while (*fclus < cluster) {
243243
/* prevent the infinite loop of cluster chain */
244244
if (*fclus > limit) {
245-
fat_fs_error(sb, "%s: detected the cluster chain loop"
246-
" (i_pos %lld)", __func__,
247-
MSDOS_I(inode)->i_pos);
245+
fat_fs_error_ratelimit(sb,
246+
"%s: detected the cluster chain loop"
247+
" (i_pos %lld)", __func__,
248+
MSDOS_I(inode)->i_pos);
248249
nr = -EIO;
249250
goto out;
250251
}
@@ -253,9 +254,9 @@ int fat_get_cluster(struct inode *inode, int cluster, int *fclus, int *dclus)
253254
if (nr < 0)
254255
goto out;
255256
else if (nr == FAT_ENT_FREE) {
256-
fat_fs_error(sb, "%s: invalid cluster chain"
257-
" (i_pos %lld)", __func__,
258-
MSDOS_I(inode)->i_pos);
257+
fat_fs_error_ratelimit(sb, "%s: invalid cluster chain"
258+
" (i_pos %lld)", __func__,
259+
MSDOS_I(inode)->i_pos);
259260
nr = -EIO;
260261
goto out;
261262
} else if (nr == FAT_ENT_EOF) {

‎fs/fat/fat.h‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <linux/nls.h>
77
#include <linux/fs.h>
88
#include <linux/mutex.h>
9+
#include <linux/ratelimit.h>
910
#include <linux/msdos_fs.h>
1011

1112
/*
@@ -82,6 +83,8 @@ struct msdos_sb_info {
8283
struct fatent_operations *fatent_ops;
8384
struct inode *fat_inode;
8485

86+
struct ratelimit_state ratelimit;
87+
8588
spinlock_t inode_hash_lock;
8689
struct hlist_head inode_hashtable[FAT_HASH_SIZE];
8790
};
@@ -322,8 +325,13 @@ extern int fat_fill_super(struct super_block *sb, void *data, int silent,
322325
extern int fat_flush_inodes(struct super_block *sb, struct inode *i1,
323326
struct inode *i2);
324327
/* fat/misc.c */
325-
extern void fat_fs_error(struct super_block *s, const char *fmt, ...)
326-
__attribute__ ((format (printf, 2, 3))) __cold;
328+
extern void
329+
__fat_fs_error(struct super_block *s, int report, const char *fmt, ...)
330+
__attribute__ ((format (printf, 3, 4))) __cold;
331+
#define fat_fs_error(s, fmt, args...) \
332+
__fat_fs_error(s, 1, fmt , ## args)
333+
#define fat_fs_error_ratelimit(s, fmt, args...) \
334+
__fat_fs_error(s, __ratelimit(&MSDOS_SB(s)->ratelimit), fmt , ## args)
327335
extern int fat_clusters_flush(struct super_block *sb);
328336
extern int fat_chain_add(struct inode *inode, int new_dclus, int nr_cluster);
329337
extern void fat_time_fat2unix(struct msdos_sb_info *sbi, struct timespec *ts,

‎fs/fat/inode.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1250,6 +1250,8 @@ int fat_fill_super(struct super_block *sb, void *data, int silent,
12501250
sb->s_op = &fat_sops;
12511251
sb->s_export_op = &fat_export_ops;
12521252
sbi->dir_ops = fs_dir_inode_ops;
1253+
ratelimit_state_init(&sbi->ratelimit, DEFAULT_RATELIMIT_INTERVAL,
1254+
DEFAULT_RATELIMIT_BURST);
12531255

12541256
error = parse_options(data, isvfat, silent, &debug, &sbi->options);
12551257
if (error)

‎fs/fat/misc.c‎

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,27 +20,29 @@
2020
* In case the file system is remounted read-only, it can be made writable
2121
* again by remounting it.
2222
*/
23-
void fat_fs_error(struct super_block *s, const char *fmt, ...)
23+
void __fat_fs_error(struct super_block *s, int report, const char *fmt, ...)
2424
{
2525
struct fat_mount_options *opts = &MSDOS_SB(s)->options;
2626
va_list args;
2727

28-
printk(KERN_ERR "FAT: Filesystem error (dev %s)\n", s->s_id);
28+
if (report) {
29+
printk(KERN_ERR "FAT: Filesystem error (dev %s)\n", s->s_id);
2930

30-
printk(KERN_ERR " ");
31-
va_start(args, fmt);
32-
vprintk(fmt, args);
33-
va_end(args);
34-
printk("\n");
31+
printk(KERN_ERR " ");
32+
va_start(args, fmt);
33+
vprintk(fmt, args);
34+
va_end(args);
35+
printk("\n");
36+
}
3537

3638
if (opts->errors == FAT_ERRORS_PANIC)
37-
panic(" FAT fs panic from previous error\n");
39+
panic("FAT: fs panic from previous error\n");
3840
else if (opts->errors == FAT_ERRORS_RO && !(s->s_flags & MS_RDONLY)) {
3941
s->s_flags |= MS_RDONLY;
40-
printk(KERN_ERR " File system has been set read-only\n");
42+
printk(KERN_ERR "FAT: Filesystem has been set read-only\n");
4143
}
4244
}
43-
EXPORT_SYMBOL_GPL(fat_fs_error);
45+
EXPORT_SYMBOL_GPL(__fat_fs_error);
4446

4547
/* Flushes the number of free clusters on FAT32 */
4648
/* XXX: Need to write one per FSINFO block. Currently only writes 1 */

0 commit comments

Comments
 (0)