add patch fix-return-value-of-ext4_do_update_inode
[ext4-patch-queue.git] / add-sysfs-bool-support
blobac694af20b4d0c510a4a0cdbc022b04dae5bc12c
1 ext4: add support for adding boolean toggles to ext4's sysfs directory
3 Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
4 ---
5  fs/ext4/super.c | 36 +++++++++++++++++++++++++++++++++---
6  1 file changed, 33 insertions(+), 3 deletions(-)
8 diff --git a/fs/ext4/super.c b/fs/ext4/super.c
9 index 85b3dd6..d31f51b 100644
10 --- a/fs/ext4/super.c
11 +++ b/fs/ext4/super.c
12 @@ -2400,6 +2400,7 @@ struct ext4_attr {
13                 int offset;
14                 int deprecated_val;
15         } u;
16 +       unsigned int mask;
17  };
19  static int parse_strtoull(const char *buf,
20 @@ -2532,7 +2533,33 @@ static ssize_t sbi_deprecated_show(struct ext4_attr *a,
21         return snprintf(buf, PAGE_SIZE, "%d\n", a->u.deprecated_val);
22  }
24 -#define EXT4_ATTR_OFFSET(_name,_mode,_show,_store,_elname) \
25 +static ssize_t sbi_bool_show(struct ext4_attr *a,
26 +                            struct ext4_sb_info *sbi, char *buf)
28 +       unsigned int *ui = (unsigned int *) (((char *) sbi) + a->u.offset);
30 +       return snprintf(buf, PAGE_SIZE, "%d\n",
31 +                       ((*ui & a->mask) == 0) ? 0 : 1);
34 +static ssize_t sbi_bool_store(struct ext4_attr *a,
35 +                             struct ext4_sb_info *sbi,
36 +                             const char *buf, size_t count)
38 +       unsigned int *ui = (unsigned int *) (((char *) sbi) + a->u.offset);
39 +       unsigned long long t;
41 +       if (parse_strtoull(buf, 0xffffffff, &t))
42 +               return -EINVAL;
43 +       if (t)
44 +               *ui |= a->mask;
45 +       else
46 +               *ui &= ~a->mask;
48 +       return count;
51 +#define EXT4_ATTR_OFFSET(_name,_mode,_show,_store,_elname,_mask)\
52  static struct ext4_attr ext4_attr_##_name = {                  \
53         .attr = {.name = __stringify(_name), .mode = _mode },   \
54         .show   = _show,                                        \
55 @@ -2540,6 +2567,7 @@ static struct ext4_attr ext4_attr_##_name = {                     \
56         .u = {                                                  \
57                 .offset = offsetof(struct ext4_sb_info, _elname),\
58         },                                                      \
59 +       .mask   = (_mask),                                              \
60  }
61  #define EXT4_ATTR(name, mode, show, store) \
62  static struct ext4_attr ext4_attr_##name = __ATTR(name, mode, show, store)
63 @@ -2548,7 +2576,9 @@ static struct ext4_attr ext4_attr_##name = __ATTR(name, mode, show, store)
64  #define EXT4_RO_ATTR(name) EXT4_ATTR(name, 0444, name##_show, NULL)
65  #define EXT4_RW_ATTR(name) EXT4_ATTR(name, 0644, name##_show, name##_store)
66  #define EXT4_RW_ATTR_SBI_UI(name, elname)      \
67 -       EXT4_ATTR_OFFSET(name, 0644, sbi_ui_show, sbi_ui_store, elname)
68 +       EXT4_ATTR_OFFSET(name, 0644, sbi_ui_show, sbi_ui_store, elname, 0)
69 +#define EXT4_RW_ATTR_SBI_BOOL(name, elname, mask)                      \
70 +EXT4_ATTR_OFFSET(name, 0644, sbi_bool_show, sbi_bool_store, elname, mask)
71  #define ATTR_LIST(name) &ext4_attr_##name.attr
72  #define EXT4_DEPRECATED_ATTR(_name, _val)      \
73  static struct ext4_attr ext4_attr_##_name = {                  \
74 @@ -2564,7 +2594,7 @@ EXT4_RO_ATTR(session_write_kbytes);
75  EXT4_RO_ATTR(lifetime_write_kbytes);
76  EXT4_RW_ATTR(reserved_clusters);
77  EXT4_ATTR_OFFSET(inode_readahead_blks, 0644, sbi_ui_show,
78 -                inode_readahead_blks_store, s_inode_readahead_blks);
79 +                inode_readahead_blks_store, s_inode_readahead_blks, 0);
80  EXT4_RW_ATTR_SBI_UI(inode_goal, s_inode_goal);
81  EXT4_RW_ATTR_SBI_UI(mb_stats, s_mb_stats);
82  EXT4_RW_ATTR_SBI_UI(mb_max_to_scan, s_mb_max_to_scan);