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 | |
Zheng Liu | fdc0212 | 2013-02-18 00:26:51 -0500 | [diff] [blame] | 23 | #define EXTENT_STATUS_WRITTEN 0x80000000 /* written extent */ |
| 24 | #define EXTENT_STATUS_UNWRITTEN 0x40000000 /* unwritten extent */ |
| 25 | #define EXTENT_STATUS_DELAYED 0x20000000 /* delayed extent */ |
| 26 | #define EXTENT_STATUS_HOLE 0x10000000 /* hole */ |
| 27 | |
| 28 | #define EXTENT_STATUS_FLAGS (EXTENT_STATUS_WRITTEN | \ |
| 29 | EXTENT_STATUS_UNWRITTEN | \ |
| 30 | EXTENT_STATUS_DELAYED | \ |
| 31 | EXTENT_STATUS_HOLE) |
| 32 | |
Zheng Liu | c0677e6 | 2012-11-08 15:18:54 -0500 | [diff] [blame] | 33 | struct extent_status { |
| 34 | struct rb_node rb_node; |
Zheng Liu | 06b0c88 | 2013-02-18 00:26:51 -0500 | [diff] [blame] | 35 | ext4_lblk_t es_lblk; /* first logical block extent covers */ |
| 36 | ext4_lblk_t es_len; /* length of extent in block */ |
Zheng Liu | fdc0212 | 2013-02-18 00:26:51 -0500 | [diff] [blame] | 37 | ext4_fsblk_t es_pblk; /* first physical block */ |
Zheng Liu | c0677e6 | 2012-11-08 15:18:54 -0500 | [diff] [blame] | 38 | }; |
| 39 | |
| 40 | struct ext4_es_tree { |
| 41 | struct rb_root root; |
| 42 | struct extent_status *cache_es; /* recently accessed extent */ |
| 43 | }; |
| 44 | |
Zheng Liu | 654598b | 2012-11-08 21:57:20 -0500 | [diff] [blame] | 45 | extern int __init ext4_init_es(void); |
| 46 | extern void ext4_exit_es(void); |
| 47 | extern void ext4_es_init_tree(struct ext4_es_tree *tree); |
| 48 | |
Zheng Liu | 06b0c88 | 2013-02-18 00:26:51 -0500 | [diff] [blame] | 49 | 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] | 50 | ext4_lblk_t len, ext4_fsblk_t pblk, |
| 51 | unsigned long long status); |
Zheng Liu | 06b0c88 | 2013-02-18 00:26:51 -0500 | [diff] [blame] | 52 | 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] | 53 | ext4_lblk_t len); |
Zheng Liu | be40136 | 2013-02-18 00:27:26 -0500 | [diff] [blame] | 54 | extern void ext4_es_find_delayed_extent(struct inode *inode, ext4_lblk_t lblk, |
| 55 | struct extent_status *es); |
Zheng Liu | 654598b | 2012-11-08 21:57:20 -0500 | [diff] [blame] | 56 | |
Zheng Liu | fdc0212 | 2013-02-18 00:26:51 -0500 | [diff] [blame] | 57 | static inline int ext4_es_is_written(struct extent_status *es) |
| 58 | { |
| 59 | return (es->es_pblk & EXTENT_STATUS_WRITTEN); |
| 60 | } |
| 61 | |
| 62 | static inline int ext4_es_is_unwritten(struct extent_status *es) |
| 63 | { |
| 64 | return (es->es_pblk & EXTENT_STATUS_UNWRITTEN); |
| 65 | } |
| 66 | |
| 67 | static inline int ext4_es_is_delayed(struct extent_status *es) |
| 68 | { |
| 69 | return (es->es_pblk & EXTENT_STATUS_DELAYED); |
| 70 | } |
| 71 | |
| 72 | static inline int ext4_es_is_hole(struct extent_status *es) |
| 73 | { |
| 74 | return (es->es_pblk & EXTENT_STATUS_HOLE); |
| 75 | } |
| 76 | |
| 77 | static inline ext4_fsblk_t ext4_es_status(struct extent_status *es) |
| 78 | { |
| 79 | return (es->es_pblk & EXTENT_STATUS_FLAGS); |
| 80 | } |
| 81 | |
| 82 | static inline ext4_fsblk_t ext4_es_pblock(struct extent_status *es) |
| 83 | { |
| 84 | return (es->es_pblk & ~EXTENT_STATUS_FLAGS); |
| 85 | } |
| 86 | |
| 87 | static inline void ext4_es_store_pblock(struct extent_status *es, |
| 88 | ext4_fsblk_t pb) |
| 89 | { |
| 90 | ext4_fsblk_t block; |
| 91 | |
| 92 | block = (pb & ~EXTENT_STATUS_FLAGS) | |
| 93 | (es->es_pblk & EXTENT_STATUS_FLAGS); |
| 94 | es->es_pblk = block; |
| 95 | } |
| 96 | |
| 97 | static inline void ext4_es_store_status(struct extent_status *es, |
| 98 | unsigned long long status) |
| 99 | { |
| 100 | ext4_fsblk_t block; |
| 101 | |
| 102 | block = (status & EXTENT_STATUS_FLAGS) | |
| 103 | (es->es_pblk & ~EXTENT_STATUS_FLAGS); |
| 104 | es->es_pblk = block; |
| 105 | } |
| 106 | |
Zheng Liu | c0677e6 | 2012-11-08 15:18:54 -0500 | [diff] [blame] | 107 | #endif /* _EXT4_EXTENTS_STATUS_H */ |