blob: f190dfe969dacc59e34d15f03e2a7c5e3c5ef5e2 [file] [log] [blame]
Zheng Liuc0677e62012-11-08 15:18:54 -05001/*
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 Liu654598b2012-11-08 21:57:20 -050014/*
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'o8e919d12013-02-27 14:54:37 -050023/*
24 * These flags live in the high bits of extent_status.es_pblk
25 */
26#define EXTENT_STATUS_WRITTEN (1ULL << 63)
27#define EXTENT_STATUS_UNWRITTEN (1ULL << 62)
28#define EXTENT_STATUS_DELAYED (1ULL << 61)
29#define EXTENT_STATUS_HOLE (1ULL << 60)
Zheng Liufdc02122013-02-18 00:26:51 -050030
31#define EXTENT_STATUS_FLAGS (EXTENT_STATUS_WRITTEN | \
32 EXTENT_STATUS_UNWRITTEN | \
33 EXTENT_STATUS_DELAYED | \
34 EXTENT_STATUS_HOLE)
35
Zheng Liuc0677e62012-11-08 15:18:54 -050036struct extent_status {
37 struct rb_node rb_node;
Zheng Liu06b0c882013-02-18 00:26:51 -050038 ext4_lblk_t es_lblk; /* first logical block extent covers */
39 ext4_lblk_t es_len; /* length of extent in block */
Zheng Liufdc02122013-02-18 00:26:51 -050040 ext4_fsblk_t es_pblk; /* first physical block */
Zheng Liuc0677e62012-11-08 15:18:54 -050041};
42
43struct ext4_es_tree {
44 struct rb_root root;
45 struct extent_status *cache_es; /* recently accessed extent */
46};
47
Zheng Liu654598b2012-11-08 21:57:20 -050048extern int __init ext4_init_es(void);
49extern void ext4_exit_es(void);
50extern void ext4_es_init_tree(struct ext4_es_tree *tree);
51
Zheng Liu06b0c882013-02-18 00:26:51 -050052extern int ext4_es_insert_extent(struct inode *inode, ext4_lblk_t lblk,
Zheng Liufdc02122013-02-18 00:26:51 -050053 ext4_lblk_t len, ext4_fsblk_t pblk,
54 unsigned long long status);
Zheng Liu06b0c882013-02-18 00:26:51 -050055extern int ext4_es_remove_extent(struct inode *inode, ext4_lblk_t lblk,
Zheng Liu654598b2012-11-08 21:57:20 -050056 ext4_lblk_t len);
Zheng Liube401362013-02-18 00:27:26 -050057extern void ext4_es_find_delayed_extent(struct inode *inode, ext4_lblk_t lblk,
58 struct extent_status *es);
Zheng Liud100eef2013-02-18 00:29:59 -050059extern int ext4_es_lookup_extent(struct inode *inode, ext4_lblk_t lblk,
60 struct extent_status *es);
Zheng Liu654598b2012-11-08 21:57:20 -050061
Zheng Liufdc02122013-02-18 00:26:51 -050062static inline int ext4_es_is_written(struct extent_status *es)
63{
Theodore Ts'o8e919d12013-02-27 14:54:37 -050064 return (es->es_pblk & EXTENT_STATUS_WRITTEN) != 0;
Zheng Liufdc02122013-02-18 00:26:51 -050065}
66
67static inline int ext4_es_is_unwritten(struct extent_status *es)
68{
Theodore Ts'o8e919d12013-02-27 14:54:37 -050069 return (es->es_pblk & EXTENT_STATUS_UNWRITTEN) != 0;
Zheng Liufdc02122013-02-18 00:26:51 -050070}
71
72static inline int ext4_es_is_delayed(struct extent_status *es)
73{
Theodore Ts'o8e919d12013-02-27 14:54:37 -050074 return (es->es_pblk & EXTENT_STATUS_DELAYED) != 0;
Zheng Liufdc02122013-02-18 00:26:51 -050075}
76
77static inline int ext4_es_is_hole(struct extent_status *es)
78{
Theodore Ts'o8e919d12013-02-27 14:54:37 -050079 return (es->es_pblk & EXTENT_STATUS_HOLE) != 0;
Zheng Liufdc02122013-02-18 00:26:51 -050080}
81
82static inline ext4_fsblk_t ext4_es_status(struct extent_status *es)
83{
84 return (es->es_pblk & EXTENT_STATUS_FLAGS);
85}
86
87static inline ext4_fsblk_t ext4_es_pblock(struct extent_status *es)
88{
89 return (es->es_pblk & ~EXTENT_STATUS_FLAGS);
90}
91
92static inline void ext4_es_store_pblock(struct extent_status *es,
93 ext4_fsblk_t pb)
94{
95 ext4_fsblk_t block;
96
97 block = (pb & ~EXTENT_STATUS_FLAGS) |
98 (es->es_pblk & EXTENT_STATUS_FLAGS);
99 es->es_pblk = block;
100}
101
102static inline void ext4_es_store_status(struct extent_status *es,
103 unsigned long long status)
104{
105 ext4_fsblk_t block;
106
107 block = (status & EXTENT_STATUS_FLAGS) |
108 (es->es_pblk & ~EXTENT_STATUS_FLAGS);
109 es->es_pblk = block;
110}
111
Zheng Liu74cd15c2013-02-18 00:32:55 -0500112extern void ext4_es_register_shrinker(struct super_block *sb);
113extern void ext4_es_unregister_shrinker(struct super_block *sb);
114extern void ext4_es_lru_add(struct inode *inode);
115extern void ext4_es_lru_del(struct inode *inode);
116
Zheng Liuc0677e62012-11-08 15:18:54 -0500117#endif /* _EXT4_EXTENTS_STATUS_H */