Whamcloud - gitweb
LU-17744 ldiskfs: mballoc stats fixes
[fs/lustre-release.git] / ldiskfs / kernel_patches / patches / linux-5.8 / ext4-export-mb-stream-allocator-variables.patch
1 ---
2  fs/ext4/ext4.h    |    2 +
3  fs/ext4/mballoc.c |   58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
4  fs/ext4/sysfs.c   |    4 +++
5  3 files changed, 64 insertions(+)
6
7 --- a/fs/ext4/ext4.h
8 +++ b/fs/ext4/ext4.h
9 @@ -2808,6 +2808,8 @@ extern void ext4_end_bitmap_read(struct
10  /* mballoc.c */
11  extern const struct proc_ops ext4_seq_prealloc_table_fops;
12  extern const struct seq_operations ext4_mb_seq_groups_ops;
13 +extern const struct proc_ops ext4_seq_mb_last_group_fops;
14 +extern int ext4_mb_seq_last_start_seq_show(struct seq_file *m, void *v);
15  extern long ext4_mb_stats;
16  extern long ext4_mb_max_to_scan;
17  extern int ext4_mb_init(struct super_block *);
18 --- a/fs/ext4/mballoc.c
19 +++ b/fs/ext4/mballoc.c
20 @@ -2574,6 +2574,64 @@ static struct kmem_cache *get_groupinfo_
21         return cachep;
22  }
23  
24 +#define EXT4_MB_MAX_INPUT_STRING_SIZE 32
25 +
26 +static ssize_t ext4_mb_last_group_write(struct file *file,
27 +                                       const char __user *buf,
28 +                                       size_t cnt, loff_t *pos)
29 +{
30 +       char dummy[EXT4_MB_MAX_INPUT_STRING_SIZE + 1];
31 +       struct super_block *sb = PDE_DATA(file_inode(file));
32 +       struct ext4_sb_info *sbi = EXT4_SB(sb);
33 +       unsigned long val;
34 +       char *end;
35 +
36 +       if (cnt > EXT4_MB_MAX_INPUT_STRING_SIZE)
37 +               return -EINVAL;
38 +       if (copy_from_user(dummy, buf, cnt))
39 +               return -EFAULT;
40 +       dummy[cnt] = '\0';
41 +       val = simple_strtoul(dummy, &end, 0);
42 +       if (dummy == end)
43 +               return -EINVAL;
44 +       if (val >= ext4_get_groups_count(sb))
45 +               return -ERANGE;
46 +       spin_lock(&sbi->s_md_lock);
47 +       sbi->s_mb_last_group = val;
48 +       sbi->s_mb_last_start = 0;
49 +       spin_unlock(&sbi->s_md_lock);
50 +       return cnt;
51 +}
52 +
53 +static int ext4_mb_seq_last_group_seq_show(struct seq_file *m, void *v)
54 +{
55 +       struct ext4_sb_info *sbi = EXT4_SB(m->private);
56 +
57 +       seq_printf(m , "%ld\n", sbi->s_mb_last_group);
58 +       return 0;
59 +}
60 +
61 +static int ext4_mb_seq_last_group_open(struct inode *inode, struct file *file)
62 +{
63 +       return single_open(file, ext4_mb_seq_last_group_seq_show, PDE_DATA(inode));
64 +}
65 +
66 +const struct proc_ops ext4_seq_mb_last_group_fops = {
67 +       .proc_open      = ext4_mb_seq_last_group_open,
68 +       .proc_read      = seq_read,
69 +       .proc_lseek     = seq_lseek,
70 +       .proc_release   = seq_release,
71 +       .proc_write     = ext4_mb_last_group_write,
72 +};
73 +
74 +int ext4_mb_seq_last_start_seq_show(struct seq_file *m, void *v)
75 +{
76 +       struct ext4_sb_info *sbi = EXT4_SB(m->private);
77 +
78 +       seq_printf(m , "%ld\n", sbi->s_mb_last_start);
79 +       return 0;
80 +}
81 +
82  /*
83   * Allocate the top-level s_group_info array for the specified number
84   * of groups
85 --- a/fs/ext4/sysfs.c
86 +++ b/fs/ext4/sysfs.c
87 @@ -524,6 +524,10 @@ int ext4_register_sysfs(struct super_blo
88                                 &ext4_mb_seq_groups_ops, sb);
89                 proc_create_data("prealloc_table", S_IRUGO, sbi->s_proc,
90                                 &ext4_seq_prealloc_table_fops, sb);
91 +               proc_create_data("mb_last_group", S_IRUGO, sbi->s_proc,
92 +                               &ext4_seq_mb_last_group_fops, sb);
93 +               proc_create_single_data("mb_last_start", S_IRUGO, sbi->s_proc,
94 +                               ext4_mb_seq_last_start_seq_show, sb);
95         }
96         return 0;
97  }