lazytime -v7 patches
[ext4-patch-queue.git] / cleanup-flag-definitions-for-extent-status-tree
blobacbadf94c00d7aae5590a8e7f44c7e57c13538fc
1 ext4: cleanup flag definitions for extent status tree
3 From: Jan Kara <jack@suse.cz>
5 Currently flags for extent status tree are defined twice, once shifted
6 and once without a being shifted. Consolidate these definitions into one
7 place and make some computations automatic to make adding flags less
8 error prone. Compiler should be clever enough to figure out these are
9 constants and generate the same code.
11 Signed-off-by: Jan Kara <jack@suse.cz>
12 Signed-off-by: Theodore Ts'o <tytso@mit.edu>
13 ---
14  fs/ext4/extents_status.c |  2 ++
15  fs/ext4/extents_status.h | 58 ++++++++++++++++++++++--------------------------
16  2 files changed, 28 insertions(+), 32 deletions(-)
18 diff --git a/fs/ext4/extents_status.c b/fs/ext4/extents_status.c
19 index 8f2aac4006d2..30596498ed0b 100644
20 --- a/fs/ext4/extents_status.c
21 +++ b/fs/ext4/extents_status.c
22 @@ -1174,6 +1174,8 @@ int ext4_es_register_shrinker(struct ext4_sb_info *sbi)
23  {
24         int err;
26 +       /* Make sure we have enough bits for physical block number */
27 +       BUILD_BUG_ON(ES_SHIFT < 48);
28         INIT_LIST_HEAD(&sbi->s_es_list);
29         sbi->s_es_nr_inode = 0;
30         spin_lock_init(&sbi->s_es_lock);
31 diff --git a/fs/ext4/extents_status.h b/fs/ext4/extents_status.h
32 index b0b78b95f481..e86b1f34cfec 100644
33 --- a/fs/ext4/extents_status.h
34 +++ b/fs/ext4/extents_status.h
35 @@ -29,25 +29,21 @@
36  /*
37   * These flags live in the high bits of extent_status.es_pblk
38   */
39 -#define ES_SHIFT       60
41 -#define EXTENT_STATUS_WRITTEN  (1 << 3)
42 -#define EXTENT_STATUS_UNWRITTEN (1 << 2)
43 -#define EXTENT_STATUS_DELAYED  (1 << 1)
44 -#define EXTENT_STATUS_HOLE     (1 << 0)
46 -#define EXTENT_STATUS_FLAGS    (EXTENT_STATUS_WRITTEN | \
47 -                                EXTENT_STATUS_UNWRITTEN | \
48 -                                EXTENT_STATUS_DELAYED | \
49 -                                EXTENT_STATUS_HOLE)
50 +enum {
51 +       ES_WRITTEN_B,
52 +       ES_UNWRITTEN_B,
53 +       ES_DELAYED_B,
54 +       ES_HOLE_B,
55 +       ES_FLAGS
56 +};
58 -#define ES_WRITTEN             (1ULL << 63)
59 -#define ES_UNWRITTEN           (1ULL << 62)
60 -#define ES_DELAYED             (1ULL << 61)
61 -#define ES_HOLE                        (1ULL << 60)
62 +#define ES_SHIFT (sizeof(ext4_fsblk_t)*8 - ES_FLAGS)
63 +#define ES_MASK (~((ext4_fsblk_t)0) << ES_SHIFT)
65 -#define ES_MASK                        (ES_WRITTEN | ES_UNWRITTEN | \
66 -                                ES_DELAYED | ES_HOLE)
67 +#define EXTENT_STATUS_WRITTEN  (1 << ES_WRITTEN_B)
68 +#define EXTENT_STATUS_UNWRITTEN (1 << ES_UNWRITTEN_B)
69 +#define EXTENT_STATUS_DELAYED  (1 << ES_DELAYED_B)
70 +#define EXTENT_STATUS_HOLE     (1 << ES_HOLE_B)
72  struct ext4_sb_info;
73  struct ext4_extent;
74 @@ -92,29 +88,29 @@ extern void ext4_es_find_delayed_extent_range(struct inode *inode,
75  extern int ext4_es_lookup_extent(struct inode *inode, ext4_lblk_t lblk,
76                                  struct extent_status *es);
78 +static inline unsigned int ext4_es_status(struct extent_status *es)
80 +       return es->es_pblk >> ES_SHIFT;
83  static inline int ext4_es_is_written(struct extent_status *es)
84  {
85 -       return (es->es_pblk & ES_WRITTEN) != 0;
86 +       return (ext4_es_status(es) & EXTENT_STATUS_WRITTEN) != 0;
87  }
89  static inline int ext4_es_is_unwritten(struct extent_status *es)
90  {
91 -       return (es->es_pblk & ES_UNWRITTEN) != 0;
92 +       return (ext4_es_status(es) & EXTENT_STATUS_UNWRITTEN) != 0;
93  }
95  static inline int ext4_es_is_delayed(struct extent_status *es)
96  {
97 -       return (es->es_pblk & ES_DELAYED) != 0;
98 +       return (ext4_es_status(es) & EXTENT_STATUS_DELAYED) != 0;
99  }
101  static inline int ext4_es_is_hole(struct extent_status *es)
103 -       return (es->es_pblk & ES_HOLE) != 0;
106 -static inline unsigned int ext4_es_status(struct extent_status *es)
108 -       return es->es_pblk >> ES_SHIFT;
109 +       return (ext4_es_status(es) & EXTENT_STATUS_HOLE) != 0;
112  static inline ext4_fsblk_t ext4_es_pblock(struct extent_status *es)
113 @@ -134,18 +130,16 @@ static inline void ext4_es_store_pblock(struct extent_status *es,
114  static inline void ext4_es_store_status(struct extent_status *es,
115                                         unsigned int status)
117 -       es->es_pblk = (((ext4_fsblk_t)
118 -                       (status & EXTENT_STATUS_FLAGS) << ES_SHIFT) |
119 -                      (es->es_pblk & ~ES_MASK));
120 +       es->es_pblk = (((ext4_fsblk_t)status << ES_SHIFT) & ES_MASK) |
121 +                     (es->es_pblk & ~ES_MASK);
124  static inline void ext4_es_store_pblock_status(struct extent_status *es,
125                                                ext4_fsblk_t pb,
126                                                unsigned int status)
128 -       es->es_pblk = (((ext4_fsblk_t)
129 -                       (status & EXTENT_STATUS_FLAGS) << ES_SHIFT) |
130 -                      (pb & ~ES_MASK));
131 +       es->es_pblk = (((ext4_fsblk_t)status << ES_SHIFT) & ES_MASK) |
132 +                     (pb & ~ES_MASK);
135  extern int ext4_es_register_shrinker(struct ext4_sb_info *sbi);
136 -- 
137 1.8.1.4
140 To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
141 the body of a message to majordomo@vger.kernel.org
142 More majordomo info at  http://vger.kernel.org/majordomo-info.html