Commit 06b0c886 authored by Zheng Liu's avatar Zheng Liu Committed by Theodore Ts'o

ext4: refine extent status tree

This commit refines the extent status tree code.

1) A prefix 'es_' is added to to the extent status tree structure
members.

2) Refactored es_remove_extent() so that __es_remove_extent() can be
used by es_insert_extent() to remove the old extent entry(-ies) before
inserting a new one.

3) Rename extent_status_end() to ext4_es_end()

4) ext4_es_can_be_merged() is define to check whether two extents can
be merged or not.

5) Update and clarified comments.
Signed-off-by: default avatarZheng Liu <wenqing.lz@taobao.com>
Signed-off-by: default avatar"Theodore Ts'o" <tytso@mit.edu>
Reviewed-by: default avatarJan Kara <jack@suse.cz>
parent 0f70b406
......@@ -3528,13 +3528,14 @@ static int ext4_find_delalloc_range(struct inode *inode,
{
struct extent_status es;
es.start = lblk_start;
ext4_es_find_extent(inode, &es);
if (es.len == 0)
es.es_lblk = lblk_start;
(void)ext4_es_find_extent(inode, &es);
if (es.es_len == 0)
return 0; /* there is no delay extent in this tree */
else if (es.start <= lblk_start && lblk_start < es.start + es.len)
else if (es.es_lblk <= lblk_start &&
lblk_start < es.es_lblk + es.es_len)
return 1;
else if (lblk_start <= es.start && es.start <= lblk_end)
else if (lblk_start <= es.es_lblk && es.es_lblk <= lblk_end)
return 1;
else
return 0;
......@@ -4569,7 +4570,7 @@ static int ext4_find_delayed_extent(struct inode *inode,
struct extent_status es;
ext4_lblk_t next_del;
es.start = newex->ec_block;
es.es_lblk = newex->ec_block;
next_del = ext4_es_find_extent(inode, &es);
if (newex->ec_start == 0) {
......@@ -4577,18 +4578,18 @@ static int ext4_find_delayed_extent(struct inode *inode,
* No extent in extent-tree contains block @newex->ec_start,
* then the block may stay in 1)a hole or 2)delayed-extent.
*/
if (es.len == 0)
if (es.es_len == 0)
/* A hole found. */
return 0;
if (es.start > newex->ec_block) {
if (es.es_lblk > newex->ec_block) {
/* A hole found. */
newex->ec_len = min(es.start - newex->ec_block,
newex->ec_len = min(es.es_lblk - newex->ec_block,
newex->ec_len);
return 0;
}
newex->ec_len = es.start + es.len - newex->ec_block;
newex->ec_len = es.es_lblk + es.es_len - newex->ec_block;
}
return next_del;
......
This diff is collapsed.
......@@ -22,8 +22,8 @@
struct extent_status {
struct rb_node rb_node;
ext4_lblk_t start; /* first block extent covers */
ext4_lblk_t len; /* length of extent in block */
ext4_lblk_t es_lblk; /* first logical block extent covers */
ext4_lblk_t es_len; /* length of extent in block */
};
struct ext4_es_tree {
......@@ -35,9 +35,9 @@ extern int __init ext4_init_es(void);
extern void ext4_exit_es(void);
extern void ext4_es_init_tree(struct ext4_es_tree *tree);
extern int ext4_es_insert_extent(struct inode *inode, ext4_lblk_t start,
extern int ext4_es_insert_extent(struct inode *inode, ext4_lblk_t lblk,
ext4_lblk_t len);
extern int ext4_es_remove_extent(struct inode *inode, ext4_lblk_t start,
extern int ext4_es_remove_extent(struct inode *inode, ext4_lblk_t lblk,
ext4_lblk_t len);
extern ext4_lblk_t ext4_es_find_extent(struct inode *inode,
struct extent_status *es);
......
......@@ -464,10 +464,9 @@ static loff_t ext4_seek_data(struct file *file, loff_t offset, loff_t maxsize)
* If there is a delay extent at this offset,
* it will be as a data.
*/
es.start = last;
es.es_lblk = last;
(void)ext4_es_find_extent(inode, &es);
if (last >= es.start &&
last < es.start + es.len) {
if (es.es_len != 0 && in_range(last, es.es_lblk, es.es_len)) {
if (last != start)
dataoff = last << blkbits;
break;
......@@ -549,11 +548,10 @@ static loff_t ext4_seek_hole(struct file *file, loff_t offset, loff_t maxsize)
* If there is a delay extent at this offset,
* we will skip this extent.
*/
es.start = last;
es.es_lblk = last;
(void)ext4_es_find_extent(inode, &es);
if (last >= es.start &&
last < es.start + es.len) {
last = es.start + es.len;
if (es.es_len != 0 && in_range(last, es.es_lblk, es.es_len)) {
last = es.es_lblk + es.es_len;
holeoff = last << blkbits;
continue;
}
......
......@@ -2093,75 +2093,75 @@ TRACE_EVENT(ext4_ext_remove_space_done,
);
TRACE_EVENT(ext4_es_insert_extent,
TP_PROTO(struct inode *inode, ext4_lblk_t start, ext4_lblk_t len),
TP_PROTO(struct inode *inode, ext4_lblk_t lblk, ext4_lblk_t len),
TP_ARGS(inode, start, len),
TP_ARGS(inode, lblk, len),
TP_STRUCT__entry(
__field( dev_t, dev )
__field( ino_t, ino )
__field( loff_t, start )
__field( loff_t, lblk )
__field( loff_t, len )
),
TP_fast_assign(
__entry->dev = inode->i_sb->s_dev;
__entry->ino = inode->i_ino;
__entry->start = start;
__entry->lblk = lblk;
__entry->len = len;
),
TP_printk("dev %d,%d ino %lu es [%lld/%lld)",
MAJOR(__entry->dev), MINOR(__entry->dev),
(unsigned long) __entry->ino,
__entry->start, __entry->len)
__entry->lblk, __entry->len)
);
TRACE_EVENT(ext4_es_remove_extent,
TP_PROTO(struct inode *inode, ext4_lblk_t start, ext4_lblk_t len),
TP_PROTO(struct inode *inode, ext4_lblk_t lblk, ext4_lblk_t len),
TP_ARGS(inode, start, len),
TP_ARGS(inode, lblk, len),
TP_STRUCT__entry(
__field( dev_t, dev )
__field( ino_t, ino )
__field( loff_t, start )
__field( loff_t, lblk )
__field( loff_t, len )
),
TP_fast_assign(
__entry->dev = inode->i_sb->s_dev;
__entry->ino = inode->i_ino;
__entry->start = start;
__entry->lblk = lblk;
__entry->len = len;
),
TP_printk("dev %d,%d ino %lu es [%lld/%lld)",
MAJOR(__entry->dev), MINOR(__entry->dev),
(unsigned long) __entry->ino,
__entry->start, __entry->len)
__entry->lblk, __entry->len)
);
TRACE_EVENT(ext4_es_find_extent_enter,
TP_PROTO(struct inode *inode, ext4_lblk_t start),
TP_PROTO(struct inode *inode, ext4_lblk_t lblk),
TP_ARGS(inode, start),
TP_ARGS(inode, lblk),
TP_STRUCT__entry(
__field( dev_t, dev )
__field( ino_t, ino )
__field( ext4_lblk_t, start )
__field( ext4_lblk_t, lblk )
),
TP_fast_assign(
__entry->dev = inode->i_sb->s_dev;
__entry->ino = inode->i_ino;
__entry->start = start;
__entry->lblk = lblk;
),
TP_printk("dev %d,%d ino %lu start %u",
TP_printk("dev %d,%d ino %lu lblk %u",
MAJOR(__entry->dev), MINOR(__entry->dev),
(unsigned long) __entry->ino, __entry->start)
(unsigned long) __entry->ino, __entry->lblk)
);
TRACE_EVENT(ext4_es_find_extent_exit,
......@@ -2173,7 +2173,7 @@ TRACE_EVENT(ext4_es_find_extent_exit,
TP_STRUCT__entry(
__field( dev_t, dev )
__field( ino_t, ino )
__field( ext4_lblk_t, start )
__field( ext4_lblk_t, lblk )
__field( ext4_lblk_t, len )
__field( ext4_lblk_t, ret )
),
......@@ -2181,15 +2181,15 @@ TRACE_EVENT(ext4_es_find_extent_exit,
TP_fast_assign(
__entry->dev = inode->i_sb->s_dev;
__entry->ino = inode->i_ino;
__entry->start = es->start;
__entry->len = es->len;
__entry->lblk = es->es_lblk;
__entry->len = es->es_len;
__entry->ret = ret;
),
TP_printk("dev %d,%d ino %lu es [%u/%u) ret %u",
MAJOR(__entry->dev), MINOR(__entry->dev),
(unsigned long) __entry->ino,
__entry->start, __entry->len, __entry->ret)
__entry->lblk, __entry->len, __entry->ret)
);
#endif /* _TRACE_EXT4_H */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment