1c0677e6dSZheng Liu /* 2c0677e6dSZheng Liu * fs/ext4/extents_status.h 3c0677e6dSZheng Liu * 4c0677e6dSZheng Liu * Written by Yongqiang Yang <xiaoqiangnk@gmail.com> 5c0677e6dSZheng Liu * Modified by 6c0677e6dSZheng Liu * Allison Henderson <achender@linux.vnet.ibm.com> 7c0677e6dSZheng Liu * Zheng Liu <wenqing.lz@taobao.com> 8c0677e6dSZheng Liu * 9c0677e6dSZheng Liu */ 10c0677e6dSZheng Liu 11c0677e6dSZheng Liu #ifndef _EXT4_EXTENTS_STATUS_H 12c0677e6dSZheng Liu #define _EXT4_EXTENTS_STATUS_H 13c0677e6dSZheng Liu 14654598beSZheng Liu /* 15654598beSZheng Liu * Turn on ES_DEBUG__ to get lots of info about extent status operations. 16654598beSZheng Liu */ 17654598beSZheng Liu #ifdef ES_DEBUG__ 18654598beSZheng Liu #define es_debug(fmt, ...) printk(fmt, ##__VA_ARGS__) 19654598beSZheng Liu #else 20654598beSZheng Liu #define es_debug(fmt, ...) no_printk(fmt, ##__VA_ARGS__) 21654598beSZheng Liu #endif 22654598beSZheng Liu 23fdc0212eSZheng Liu #define EXTENT_STATUS_WRITTEN 0x80000000 /* written extent */ 24fdc0212eSZheng Liu #define EXTENT_STATUS_UNWRITTEN 0x40000000 /* unwritten extent */ 25fdc0212eSZheng Liu #define EXTENT_STATUS_DELAYED 0x20000000 /* delayed extent */ 26fdc0212eSZheng Liu #define EXTENT_STATUS_HOLE 0x10000000 /* hole */ 27fdc0212eSZheng Liu 28fdc0212eSZheng Liu #define EXTENT_STATUS_FLAGS (EXTENT_STATUS_WRITTEN | \ 29fdc0212eSZheng Liu EXTENT_STATUS_UNWRITTEN | \ 30fdc0212eSZheng Liu EXTENT_STATUS_DELAYED | \ 31fdc0212eSZheng Liu EXTENT_STATUS_HOLE) 32fdc0212eSZheng Liu 33c0677e6dSZheng Liu struct extent_status { 34c0677e6dSZheng Liu struct rb_node rb_node; 3506b0c886SZheng Liu ext4_lblk_t es_lblk; /* first logical block extent covers */ 3606b0c886SZheng Liu ext4_lblk_t es_len; /* length of extent in block */ 37fdc0212eSZheng Liu ext4_fsblk_t es_pblk; /* first physical block */ 38c0677e6dSZheng Liu }; 39c0677e6dSZheng Liu 40c0677e6dSZheng Liu struct ext4_es_tree { 41c0677e6dSZheng Liu struct rb_root root; 42c0677e6dSZheng Liu struct extent_status *cache_es; /* recently accessed extent */ 43c0677e6dSZheng Liu }; 44c0677e6dSZheng Liu 45654598beSZheng Liu extern int __init ext4_init_es(void); 46654598beSZheng Liu extern void ext4_exit_es(void); 47654598beSZheng Liu extern void ext4_es_init_tree(struct ext4_es_tree *tree); 48654598beSZheng Liu 4906b0c886SZheng Liu extern int ext4_es_insert_extent(struct inode *inode, ext4_lblk_t lblk, 50fdc0212eSZheng Liu ext4_lblk_t len, ext4_fsblk_t pblk, 51fdc0212eSZheng Liu unsigned long long status); 5206b0c886SZheng Liu extern int ext4_es_remove_extent(struct inode *inode, ext4_lblk_t lblk, 53654598beSZheng Liu ext4_lblk_t len); 54be401363SZheng Liu extern void ext4_es_find_delayed_extent(struct inode *inode, ext4_lblk_t lblk, 55654598beSZheng Liu struct extent_status *es); 56d100eef2SZheng Liu extern int ext4_es_lookup_extent(struct inode *inode, ext4_lblk_t lblk, 57d100eef2SZheng Liu struct extent_status *es); 58654598beSZheng Liu 59fdc0212eSZheng Liu static inline int ext4_es_is_written(struct extent_status *es) 60fdc0212eSZheng Liu { 61fdc0212eSZheng Liu return (es->es_pblk & EXTENT_STATUS_WRITTEN); 62fdc0212eSZheng Liu } 63fdc0212eSZheng Liu 64fdc0212eSZheng Liu static inline int ext4_es_is_unwritten(struct extent_status *es) 65fdc0212eSZheng Liu { 66fdc0212eSZheng Liu return (es->es_pblk & EXTENT_STATUS_UNWRITTEN); 67fdc0212eSZheng Liu } 68fdc0212eSZheng Liu 69fdc0212eSZheng Liu static inline int ext4_es_is_delayed(struct extent_status *es) 70fdc0212eSZheng Liu { 71fdc0212eSZheng Liu return (es->es_pblk & EXTENT_STATUS_DELAYED); 72fdc0212eSZheng Liu } 73fdc0212eSZheng Liu 74fdc0212eSZheng Liu static inline int ext4_es_is_hole(struct extent_status *es) 75fdc0212eSZheng Liu { 76fdc0212eSZheng Liu return (es->es_pblk & EXTENT_STATUS_HOLE); 77fdc0212eSZheng Liu } 78fdc0212eSZheng Liu 79fdc0212eSZheng Liu static inline ext4_fsblk_t ext4_es_status(struct extent_status *es) 80fdc0212eSZheng Liu { 81fdc0212eSZheng Liu return (es->es_pblk & EXTENT_STATUS_FLAGS); 82fdc0212eSZheng Liu } 83fdc0212eSZheng Liu 84fdc0212eSZheng Liu static inline ext4_fsblk_t ext4_es_pblock(struct extent_status *es) 85fdc0212eSZheng Liu { 86fdc0212eSZheng Liu return (es->es_pblk & ~EXTENT_STATUS_FLAGS); 87fdc0212eSZheng Liu } 88fdc0212eSZheng Liu 89fdc0212eSZheng Liu static inline void ext4_es_store_pblock(struct extent_status *es, 90fdc0212eSZheng Liu ext4_fsblk_t pb) 91fdc0212eSZheng Liu { 92fdc0212eSZheng Liu ext4_fsblk_t block; 93fdc0212eSZheng Liu 94fdc0212eSZheng Liu block = (pb & ~EXTENT_STATUS_FLAGS) | 95fdc0212eSZheng Liu (es->es_pblk & EXTENT_STATUS_FLAGS); 96fdc0212eSZheng Liu es->es_pblk = block; 97fdc0212eSZheng Liu } 98fdc0212eSZheng Liu 99fdc0212eSZheng Liu static inline void ext4_es_store_status(struct extent_status *es, 100fdc0212eSZheng Liu unsigned long long status) 101fdc0212eSZheng Liu { 102fdc0212eSZheng Liu ext4_fsblk_t block; 103fdc0212eSZheng Liu 104fdc0212eSZheng Liu block = (status & EXTENT_STATUS_FLAGS) | 105fdc0212eSZheng Liu (es->es_pblk & ~EXTENT_STATUS_FLAGS); 106fdc0212eSZheng Liu es->es_pblk = block; 107fdc0212eSZheng Liu } 108fdc0212eSZheng Liu 10974cd15cdSZheng Liu extern void ext4_es_register_shrinker(struct super_block *sb); 11074cd15cdSZheng Liu extern void ext4_es_unregister_shrinker(struct super_block *sb); 11174cd15cdSZheng Liu extern void ext4_es_lru_add(struct inode *inode); 11274cd15cdSZheng Liu extern void ext4_es_lru_del(struct inode *inode); 11374cd15cdSZheng Liu 114c0677e6dSZheng Liu #endif /* _EXT4_EXTENTS_STATUS_H */ 115