Zheng Liu | c0677e6 | 2012-11-08 15:18:54 -0500 | [diff] [blame] | 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 | |
Zheng Liu | 654598b | 2012-11-08 21:57:20 -0500 | [diff] [blame] | 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 | |
Theodore Ts'o | 8e919d1 | 2013-02-27 14:54:37 -0500 | [diff] [blame] | 23 | /* |
Dmitry Monakhov | 921f266 | 2013-03-10 21:01:03 -0400 | [diff] [blame] | 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 | |
| 29 | /* |
Theodore Ts'o | 8e919d1 | 2013-02-27 14:54:37 -0500 | [diff] [blame] | 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) |
Zheng Liu | fdc0212 | 2013-02-18 00:26:51 -0500 | [diff] [blame] | 36 | |
| 37 | #define EXTENT_STATUS_FLAGS (EXTENT_STATUS_WRITTEN | \ |
| 38 | EXTENT_STATUS_UNWRITTEN | \ |
| 39 | EXTENT_STATUS_DELAYED | \ |
| 40 | EXTENT_STATUS_HOLE) |
| 41 | |
Zheng Liu | c0677e6 | 2012-11-08 15:18:54 -0500 | [diff] [blame] | 42 | struct extent_status { |
| 43 | struct rb_node rb_node; |
Zheng Liu | 06b0c88 | 2013-02-18 00:26:51 -0500 | [diff] [blame] | 44 | ext4_lblk_t es_lblk; /* first logical block extent covers */ |
| 45 | ext4_lblk_t es_len; /* length of extent in block */ |
Zheng Liu | fdc0212 | 2013-02-18 00:26:51 -0500 | [diff] [blame] | 46 | ext4_fsblk_t es_pblk; /* first physical block */ |
Zheng Liu | c0677e6 | 2012-11-08 15:18:54 -0500 | [diff] [blame] | 47 | }; |
| 48 | |
| 49 | struct ext4_es_tree { |
| 50 | struct rb_root root; |
| 51 | struct extent_status *cache_es; /* recently accessed extent */ |
| 52 | }; |
| 53 | |
Zheng Liu | 654598b | 2012-11-08 21:57:20 -0500 | [diff] [blame] | 54 | extern int __init ext4_init_es(void); |
| 55 | extern void ext4_exit_es(void); |
| 56 | extern void ext4_es_init_tree(struct ext4_es_tree *tree); |
| 57 | |
Zheng Liu | 06b0c88 | 2013-02-18 00:26:51 -0500 | [diff] [blame] | 58 | extern int ext4_es_insert_extent(struct inode *inode, ext4_lblk_t lblk, |
Zheng Liu | fdc0212 | 2013-02-18 00:26:51 -0500 | [diff] [blame] | 59 | ext4_lblk_t len, ext4_fsblk_t pblk, |
| 60 | unsigned long long status); |
Zheng Liu | 06b0c88 | 2013-02-18 00:26:51 -0500 | [diff] [blame] | 61 | extern int ext4_es_remove_extent(struct inode *inode, ext4_lblk_t lblk, |
Zheng Liu | 654598b | 2012-11-08 21:57:20 -0500 | [diff] [blame] | 62 | ext4_lblk_t len); |
Zheng Liu | be40136 | 2013-02-18 00:27:26 -0500 | [diff] [blame] | 63 | extern void ext4_es_find_delayed_extent(struct inode *inode, ext4_lblk_t lblk, |
| 64 | struct extent_status *es); |
Zheng Liu | d100eef | 2013-02-18 00:29:59 -0500 | [diff] [blame] | 65 | extern int ext4_es_lookup_extent(struct inode *inode, ext4_lblk_t lblk, |
| 66 | struct extent_status *es); |
Zheng Liu | 654598b | 2012-11-08 21:57:20 -0500 | [diff] [blame] | 67 | |
Zheng Liu | fdc0212 | 2013-02-18 00:26:51 -0500 | [diff] [blame] | 68 | static inline int ext4_es_is_written(struct extent_status *es) |
| 69 | { |
Theodore Ts'o | 8e919d1 | 2013-02-27 14:54:37 -0500 | [diff] [blame] | 70 | return (es->es_pblk & EXTENT_STATUS_WRITTEN) != 0; |
Zheng Liu | fdc0212 | 2013-02-18 00:26:51 -0500 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | static inline int ext4_es_is_unwritten(struct extent_status *es) |
| 74 | { |
Theodore Ts'o | 8e919d1 | 2013-02-27 14:54:37 -0500 | [diff] [blame] | 75 | return (es->es_pblk & EXTENT_STATUS_UNWRITTEN) != 0; |
Zheng Liu | fdc0212 | 2013-02-18 00:26:51 -0500 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | static inline int ext4_es_is_delayed(struct extent_status *es) |
| 79 | { |
Theodore Ts'o | 8e919d1 | 2013-02-27 14:54:37 -0500 | [diff] [blame] | 80 | return (es->es_pblk & EXTENT_STATUS_DELAYED) != 0; |
Zheng Liu | fdc0212 | 2013-02-18 00:26:51 -0500 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | static inline int ext4_es_is_hole(struct extent_status *es) |
| 84 | { |
Theodore Ts'o | 8e919d1 | 2013-02-27 14:54:37 -0500 | [diff] [blame] | 85 | return (es->es_pblk & EXTENT_STATUS_HOLE) != 0; |
Zheng Liu | fdc0212 | 2013-02-18 00:26:51 -0500 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | static inline ext4_fsblk_t ext4_es_status(struct extent_status *es) |
| 89 | { |
| 90 | return (es->es_pblk & EXTENT_STATUS_FLAGS); |
| 91 | } |
| 92 | |
| 93 | static inline ext4_fsblk_t ext4_es_pblock(struct extent_status *es) |
| 94 | { |
| 95 | return (es->es_pblk & ~EXTENT_STATUS_FLAGS); |
| 96 | } |
| 97 | |
| 98 | static inline void ext4_es_store_pblock(struct extent_status *es, |
| 99 | ext4_fsblk_t pb) |
| 100 | { |
| 101 | ext4_fsblk_t block; |
| 102 | |
| 103 | block = (pb & ~EXTENT_STATUS_FLAGS) | |
| 104 | (es->es_pblk & EXTENT_STATUS_FLAGS); |
| 105 | es->es_pblk = block; |
| 106 | } |
| 107 | |
| 108 | static inline void ext4_es_store_status(struct extent_status *es, |
| 109 | unsigned long long status) |
| 110 | { |
| 111 | ext4_fsblk_t block; |
| 112 | |
| 113 | block = (status & EXTENT_STATUS_FLAGS) | |
| 114 | (es->es_pblk & ~EXTENT_STATUS_FLAGS); |
| 115 | es->es_pblk = block; |
| 116 | } |
| 117 | |
Zheng Liu | 74cd15c | 2013-02-18 00:32:55 -0500 | [diff] [blame] | 118 | extern void ext4_es_register_shrinker(struct super_block *sb); |
| 119 | extern void ext4_es_unregister_shrinker(struct super_block *sb); |
| 120 | extern void ext4_es_lru_add(struct inode *inode); |
| 121 | extern void ext4_es_lru_del(struct inode *inode); |
| 122 | |
Zheng Liu | c0677e6 | 2012-11-08 15:18:54 -0500 | [diff] [blame] | 123 | #endif /* _EXT4_EXTENTS_STATUS_H */ |