]>
Commit | Line | Data |
---|---|---|
c0677e6d ZL |
1 | /* |
2 | * fs/ext4/extents_status.h | |
3 | * | |
4 | * Written by Yongqiang Yang <[email protected]> | |
5 | * Modified by | |
6 | * Allison Henderson <[email protected]> | |
7 | * Zheng Liu <[email protected]> | |
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 | */ | |
3be78c73 TT |
32 | #define ES_SHIFT 60 |
33 | ||
34 | #define EXTENT_STATUS_WRITTEN (1 << 3) | |
35 | #define EXTENT_STATUS_UNWRITTEN (1 << 2) | |
36 | #define EXTENT_STATUS_DELAYED (1 << 1) | |
37 | #define EXTENT_STATUS_HOLE (1 << 0) | |
fdc0212e ZL |
38 | |
39 | #define EXTENT_STATUS_FLAGS (EXTENT_STATUS_WRITTEN | \ | |
40 | EXTENT_STATUS_UNWRITTEN | \ | |
41 | EXTENT_STATUS_DELAYED | \ | |
42 | EXTENT_STATUS_HOLE) | |
43 | ||
3be78c73 TT |
44 | #define ES_WRITTEN (1ULL << 63) |
45 | #define ES_UNWRITTEN (1ULL << 62) | |
46 | #define ES_DELAYED (1ULL << 61) | |
47 | #define ES_HOLE (1ULL << 60) | |
48 | ||
49 | #define ES_MASK (ES_WRITTEN | ES_UNWRITTEN | \ | |
50 | ES_DELAYED | ES_HOLE) | |
51 | ||
d3922a77 | 52 | struct ext4_sb_info; |
adb23551 ZL |
53 | struct ext4_extent; |
54 | ||
c0677e6d ZL |
55 | struct extent_status { |
56 | struct rb_node rb_node; | |
06b0c886 ZL |
57 | ext4_lblk_t es_lblk; /* first logical block extent covers */ |
58 | ext4_lblk_t es_len; /* length of extent in block */ | |
fdc0212e | 59 | ext4_fsblk_t es_pblk; /* first physical block */ |
c0677e6d ZL |
60 | }; |
61 | ||
62 | struct ext4_es_tree { | |
63 | struct rb_root root; | |
64 | struct extent_status *cache_es; /* recently accessed extent */ | |
65 | }; | |
66 | ||
654598be ZL |
67 | extern int __init ext4_init_es(void); |
68 | extern void ext4_exit_es(void); | |
69 | extern void ext4_es_init_tree(struct ext4_es_tree *tree); | |
70 | ||
06b0c886 | 71 | extern int ext4_es_insert_extent(struct inode *inode, ext4_lblk_t lblk, |
fdc0212e | 72 | ext4_lblk_t len, ext4_fsblk_t pblk, |
3be78c73 | 73 | unsigned int status); |
06b0c886 | 74 | extern int ext4_es_remove_extent(struct inode *inode, ext4_lblk_t lblk, |
654598be | 75 | ext4_lblk_t len); |
e30b5dca YZ |
76 | extern void ext4_es_find_delayed_extent_range(struct inode *inode, |
77 | ext4_lblk_t lblk, ext4_lblk_t end, | |
be401363 | 78 | struct extent_status *es); |
d100eef2 ZL |
79 | extern int ext4_es_lookup_extent(struct inode *inode, ext4_lblk_t lblk, |
80 | struct extent_status *es); | |
adb23551 | 81 | extern int ext4_es_zeroout(struct inode *inode, struct ext4_extent *ex); |
654598be | 82 | |
fdc0212e ZL |
83 | static inline int ext4_es_is_written(struct extent_status *es) |
84 | { | |
3be78c73 | 85 | return (es->es_pblk & ES_WRITTEN) != 0; |
fdc0212e ZL |
86 | } |
87 | ||
88 | static inline int ext4_es_is_unwritten(struct extent_status *es) | |
89 | { | |
3be78c73 | 90 | return (es->es_pblk & ES_UNWRITTEN) != 0; |
fdc0212e ZL |
91 | } |
92 | ||
93 | static inline int ext4_es_is_delayed(struct extent_status *es) | |
94 | { | |
3be78c73 | 95 | return (es->es_pblk & ES_DELAYED) != 0; |
fdc0212e ZL |
96 | } |
97 | ||
98 | static inline int ext4_es_is_hole(struct extent_status *es) | |
99 | { | |
3be78c73 | 100 | return (es->es_pblk & ES_HOLE) != 0; |
fdc0212e ZL |
101 | } |
102 | ||
3be78c73 | 103 | static inline unsigned int ext4_es_status(struct extent_status *es) |
fdc0212e | 104 | { |
3be78c73 | 105 | return es->es_pblk >> ES_SHIFT; |
fdc0212e ZL |
106 | } |
107 | ||
108 | static inline ext4_fsblk_t ext4_es_pblock(struct extent_status *es) | |
109 | { | |
3be78c73 | 110 | return es->es_pblk & ~ES_MASK; |
fdc0212e ZL |
111 | } |
112 | ||
113 | static inline void ext4_es_store_pblock(struct extent_status *es, | |
114 | ext4_fsblk_t pb) | |
115 | { | |
116 | ext4_fsblk_t block; | |
117 | ||
3be78c73 | 118 | block = (pb & ~ES_MASK) | (es->es_pblk & ES_MASK); |
fdc0212e ZL |
119 | es->es_pblk = block; |
120 | } | |
121 | ||
122 | static inline void ext4_es_store_status(struct extent_status *es, | |
3be78c73 | 123 | unsigned int status) |
fdc0212e | 124 | { |
3be78c73 TT |
125 | es->es_pblk = (((ext4_fsblk_t) |
126 | (status & EXTENT_STATUS_FLAGS) << ES_SHIFT) | | |
127 | (es->es_pblk & ~ES_MASK)); | |
fdc0212e ZL |
128 | } |
129 | ||
d3922a77 ZL |
130 | extern void ext4_es_register_shrinker(struct ext4_sb_info *sbi); |
131 | extern void ext4_es_unregister_shrinker(struct ext4_sb_info *sbi); | |
74cd15cd ZL |
132 | extern void ext4_es_lru_add(struct inode *inode); |
133 | extern void ext4_es_lru_del(struct inode *inode); | |
134 | ||
c0677e6d | 135 | #endif /* _EXT4_EXTENTS_STATUS_H */ |