Merge tag 'ext4_for_linue' of git://git.kernel.org/pub/scm/linux/kernel/git/tytso...
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / fs / ext4 / extents_status.h
CommitLineData
c0677e6d
ZL
1/*
2 * fs/ext4/extents_status.h
3 *
4 * Written by Yongqiang Yang <xiaoqiangnk@gmail.com>
5 * Modified by
6 * Allison Henderson <achender@linux.vnet.ibm.com>
7 * Zheng Liu <wenqing.lz@taobao.com>
8 *
9 */
10
11#ifndef _EXT4_EXTENTS_STATUS_H
12#define _EXT4_EXTENTS_STATUS_H
13
654598be
ZL
14/*
15 * Turn on ES_DEBUG__ to get lots of info about extent status operations.
16 */
17#ifdef ES_DEBUG__
18#define es_debug(fmt, ...) printk(fmt, ##__VA_ARGS__)
19#else
20#define es_debug(fmt, ...) no_printk(fmt, ##__VA_ARGS__)
21#endif
22
921f266b
DM
23/*
24 * With ES_AGGRESSIVE_TEST defined, the result of es caching will be
25 * checked with old map_block's result.
26 */
27#define ES_AGGRESSIVE_TEST__
28
8e919d13
TT
29/*
30 * These flags live in the high bits of extent_status.es_pblk
31 */
32#define EXTENT_STATUS_WRITTEN (1ULL << 63)
33#define EXTENT_STATUS_UNWRITTEN (1ULL << 62)
34#define EXTENT_STATUS_DELAYED (1ULL << 61)
35#define EXTENT_STATUS_HOLE (1ULL << 60)
fdc0212e
ZL
36
37#define EXTENT_STATUS_FLAGS (EXTENT_STATUS_WRITTEN | \
38 EXTENT_STATUS_UNWRITTEN | \
39 EXTENT_STATUS_DELAYED | \
40 EXTENT_STATUS_HOLE)
41
adb23551
ZL
42struct ext4_extent;
43
c0677e6d
ZL
44struct extent_status {
45 struct rb_node rb_node;
06b0c886
ZL
46 ext4_lblk_t es_lblk; /* first logical block extent covers */
47 ext4_lblk_t es_len; /* length of extent in block */
fdc0212e 48 ext4_fsblk_t es_pblk; /* first physical block */
c0677e6d
ZL
49};
50
51struct ext4_es_tree {
52 struct rb_root root;
53 struct extent_status *cache_es; /* recently accessed extent */
54};
55
654598be
ZL
56extern int __init ext4_init_es(void);
57extern void ext4_exit_es(void);
58extern void ext4_es_init_tree(struct ext4_es_tree *tree);
59
06b0c886 60extern int ext4_es_insert_extent(struct inode *inode, ext4_lblk_t lblk,
fdc0212e
ZL
61 ext4_lblk_t len, ext4_fsblk_t pblk,
62 unsigned long long status);
06b0c886 63extern int ext4_es_remove_extent(struct inode *inode, ext4_lblk_t lblk,
654598be 64 ext4_lblk_t len);
be401363
ZL
65extern void ext4_es_find_delayed_extent(struct inode *inode, ext4_lblk_t lblk,
66 struct extent_status *es);
d100eef2
ZL
67extern int ext4_es_lookup_extent(struct inode *inode, ext4_lblk_t lblk,
68 struct extent_status *es);
adb23551 69extern int ext4_es_zeroout(struct inode *inode, struct ext4_extent *ex);
654598be 70
fdc0212e
ZL
71static inline int ext4_es_is_written(struct extent_status *es)
72{
8e919d13 73 return (es->es_pblk & EXTENT_STATUS_WRITTEN) != 0;
fdc0212e
ZL
74}
75
76static inline int ext4_es_is_unwritten(struct extent_status *es)
77{
8e919d13 78 return (es->es_pblk & EXTENT_STATUS_UNWRITTEN) != 0;
fdc0212e
ZL
79}
80
81static inline int ext4_es_is_delayed(struct extent_status *es)
82{
8e919d13 83 return (es->es_pblk & EXTENT_STATUS_DELAYED) != 0;
fdc0212e
ZL
84}
85
86static inline int ext4_es_is_hole(struct extent_status *es)
87{
8e919d13 88 return (es->es_pblk & EXTENT_STATUS_HOLE) != 0;
fdc0212e
ZL
89}
90
91static inline ext4_fsblk_t ext4_es_status(struct extent_status *es)
92{
93 return (es->es_pblk & EXTENT_STATUS_FLAGS);
94}
95
96static inline ext4_fsblk_t ext4_es_pblock(struct extent_status *es)
97{
98 return (es->es_pblk & ~EXTENT_STATUS_FLAGS);
99}
100
101static inline void ext4_es_store_pblock(struct extent_status *es,
102 ext4_fsblk_t pb)
103{
104 ext4_fsblk_t block;
105
106 block = (pb & ~EXTENT_STATUS_FLAGS) |
107 (es->es_pblk & EXTENT_STATUS_FLAGS);
108 es->es_pblk = block;
109}
110
111static inline void ext4_es_store_status(struct extent_status *es,
112 unsigned long long status)
113{
114 ext4_fsblk_t block;
115
116 block = (status & EXTENT_STATUS_FLAGS) |
117 (es->es_pblk & ~EXTENT_STATUS_FLAGS);
118 es->es_pblk = block;
119}
120
74cd15cd
ZL
121extern void ext4_es_register_shrinker(struct super_block *sb);
122extern void ext4_es_unregister_shrinker(struct super_block *sb);
123extern void ext4_es_lru_add(struct inode *inode);
124extern void ext4_es_lru_del(struct inode *inode);
125
c0677e6d 126#endif /* _EXT4_EXTENTS_STATUS_H */