add patch gracefully-handle-ext4_break_layouts-failure-during-truncate
[ext4-patch-queue.git] / old-patches / delalloc-debug
blob9a3b32b7fef916acdc68f80f7443f3208b41a7f3
1 ext4: add delalloc debugging
3 This adds a file in /proc/fs/ext4/<dev> which when opened for reading,
4 will trigger debugging code that dumps a lot of information about
5 inodes subject to delayed allocation to the console.
7 Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
8 ---
9  fs/ext4/sysfs.c | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
10  1 file changed, 69 insertions(+)
12 diff --git a/fs/ext4/sysfs.c b/fs/ext4/sysfs.c
13 index 9d29723..507d33f 100644
14 --- a/fs/ext4/sysfs.c
15 +++ b/fs/ext4/sysfs.c
16 @@ -371,6 +371,74 @@ static struct kobject ext4_feat = {
17         .kset   = &ext4_kset,
18  };
20 +#ifdef CONFIG_EXT4_DEBUG
21 +static void print_inode_delalloc_info(struct inode *inode)
23 +       if (!EXT4_I(inode)->i_reserved_data_blocks ||
24 +           !EXT4_I(inode)->i_reserved_meta_blocks)
25 +               return;
27 +       printk(KERN_DEBUG "ino %lu: %u %u\n", inode->i_ino,
28 +              EXT4_I(inode)->i_reserved_data_blocks,
29 +              EXT4_I(inode)->i_reserved_meta_blocks);
32 +static int debug_delalloc_show(struct seq_file *seq, void *offset)
34 +       return 0;
37 +static int options_delalloc_debug_open_fs(struct inode *proc_inode,
38 +                                         struct file *file)
40 +       struct super_block *sb = PDE_DATA(proc_inode);
41 +       struct ext4_sb_info *sbi = EXT4_SB(sb);
42 +       struct inode *inode;
43 +       extern spinlock_t inode_sb_list_lock;
45 +       printk(KERN_DEBUG "EXT4-fs debug delalloc of %s\n", sb->s_id);
46 +       printk(KERN_DEBUG "EXT4-fs: dirty clusters %lld free clusters %lld\n",
47 +              percpu_counter_sum(&sbi->s_dirtyclusters_counter),
48 +              percpu_counter_sum(&sbi->s_freeclusters_counter));
50 +#ifndef MODULE
51 +       spin_lock(&inode_sb_list_lock);
52 +       if (!list_empty(&sb->s_bdi->wb.b_dirty)) {
53 +               printk(KERN_DEBUG "s_bdi->wb.b_dirty list:\n");
54 +               list_for_each_entry(inode, &sb->s_bdi->wb.b_dirty,
55 +                                   i_io_list) {
56 +                       print_inode_delalloc_info(inode);
57 +               }
58 +       }
59 +       if (!list_empty(&sb->s_bdi->wb.b_io)) {
60 +               printk(KERN_DEBUG "s_bdi->wb.b_io list:\n");
61 +               list_for_each_entry(inode, &sb->s_bdi->wb.b_io,
62 +                                   i_io_list) {
63 +                       print_inode_delalloc_info(inode);
64 +               }
65 +       }
66 +       if (!list_empty(&sb->s_bdi->wb.b_more_io)) {
67 +               printk(KERN_DEBUG "s_bdi->wb.b_more_io list:\n");
68 +               list_for_each_entry(inode, &sb->s_bdi->wb.b_more_io,
69 +                                   i_io_list) {
70 +                       print_inode_delalloc_info(inode);
71 +               }
72 +       }
73 +       spin_unlock(&inode_sb_list_lock);
74 +       printk(KERN_DEBUG "ext4 debug delalloc done\n");
75 +#endif
76 +       return single_open(file, debug_delalloc_show, sb);
79 +static const struct file_operations ext4_seq_delalloc_debug_fops = {
80 +       .owner = THIS_MODULE,
81 +       .open = options_delalloc_debug_open_fs,
82 +       .read = seq_read,
83 +       .llseek = seq_lseek,
84 +       .release = single_release,
85 +};
86 +#endif
88  #define PROC_FILE_SHOW_DEFN(name) \
89  static int name##_open(struct inode *inode, struct file *file) \
90  { \
91 @@ -398,6 +466,7 @@ static struct ext4_proc_files {
92         PROC_FILE_LIST(options),
93         PROC_FILE_LIST(es_shrinker_info),
94         PROC_FILE_LIST(mb_groups),
95 +       PROC_FILE_LIST(delalloc_debug),
96         { NULL, NULL },
97  };