Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Linux-御风守护者
linux
提交
3c69faec
L
linux
项目概览
Linux-御风守护者
/
linux
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
L
linux
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
3c69faec
编写于
8月 07, 2007
作者:
C
Chris Mason
提交者:
David Woodhouse
8月 07, 2007
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Btrfs: Fold some btree readahead routines into something more generic.
Signed-off-by:
N
Chris Mason
<
chris.mason@oracle.com
>
上级
9f3a7427
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
81 addition
and
96 deletion
+81
-96
fs/btrfs/ctree.c
fs/btrfs/ctree.c
+77
-0
fs/btrfs/ctree.h
fs/btrfs/ctree.h
+1
-0
fs/btrfs/extent-tree.c
fs/btrfs/extent-tree.c
+1
-29
fs/btrfs/inode.c
fs/btrfs/inode.c
+2
-67
未找到文件。
fs/btrfs/ctree.c
浏览文件 @
3c69faec
...
...
@@ -639,6 +639,73 @@ static int push_nodes_for_insert(struct btrfs_trans_handle *trans,
return
1
;
}
/*
* readahead one full node of leaves
*/
static
void
reada_for_search
(
struct
btrfs_root
*
root
,
struct
btrfs_path
*
path
,
int
slot
)
{
struct
btrfs_node
*
node
;
int
i
;
u32
nritems
;
u64
item_objectid
;
u64
blocknr
;
u64
search
;
u64
cluster_start
;
int
ret
;
int
nread
=
0
;
int
direction
=
path
->
reada
;
struct
radix_tree_root
found
;
unsigned
long
gang
[
8
];
struct
buffer_head
*
bh
;
if
(
!
path
->
nodes
[
1
])
return
;
node
=
btrfs_buffer_node
(
path
->
nodes
[
1
]);
search
=
btrfs_node_blockptr
(
node
,
slot
);
bh
=
btrfs_find_tree_block
(
root
,
search
);
if
(
bh
)
{
brelse
(
bh
);
return
;
}
init_bit_radix
(
&
found
);
nritems
=
btrfs_header_nritems
(
&
node
->
header
);
for
(
i
=
slot
;
i
<
nritems
;
i
++
)
{
item_objectid
=
btrfs_disk_key_objectid
(
&
node
->
ptrs
[
i
].
key
);
blocknr
=
btrfs_node_blockptr
(
node
,
i
);
set_radix_bit
(
&
found
,
blocknr
);
}
if
(
direction
>
0
)
{
cluster_start
=
search
-
4
;
if
(
cluster_start
>
search
)
cluster_start
=
0
;
}
else
cluster_start
=
search
+
4
;
while
(
1
)
{
ret
=
find_first_radix_bit
(
&
found
,
gang
,
0
,
ARRAY_SIZE
(
gang
));
if
(
!
ret
)
break
;
for
(
i
=
0
;
i
<
ret
;
i
++
)
{
blocknr
=
gang
[
i
];
clear_radix_bit
(
&
found
,
blocknr
);
if
(
nread
>
64
)
continue
;
if
(
direction
>
0
&&
cluster_start
<=
blocknr
&&
cluster_start
+
8
>
blocknr
)
{
cluster_start
=
blocknr
;
readahead_tree_block
(
root
,
blocknr
);
nread
++
;
}
else
if
(
direction
<
0
&&
cluster_start
>=
blocknr
&&
blocknr
+
8
>
cluster_start
)
{
cluster_start
=
blocknr
;
readahead_tree_block
(
root
,
blocknr
);
nread
++
;
}
}
}
}
/*
* look for key in the tree. path is filled in with nodes along the way
* if key is found, we return zero and you can find the item in the leaf
...
...
@@ -660,9 +727,11 @@ int btrfs_search_slot(struct btrfs_trans_handle *trans, struct btrfs_root
struct
buffer_head
*
cow_buf
;
struct
btrfs_node
*
c
;
struct
btrfs_root_item
*
root_item
=
&
root
->
root_item
;
u64
blocknr
;
int
slot
;
int
ret
;
int
level
;
int
should_reada
=
p
->
reada
;
u8
lowest_level
=
0
;
if
(
btrfs_root_refs
(
root_item
)
==
0
&&
root
->
ref_cows
)
{
...
...
@@ -728,7 +797,11 @@ int btrfs_search_slot(struct btrfs_trans_handle *trans, struct btrfs_root
/* this is only true while dropping a snapshot */
if
(
level
==
lowest_level
)
break
;
blocknr
=
btrfs_node_blockptr
(
c
,
slot
);
if
(
level
==
1
&&
should_reada
)
reada_for_search
(
root
,
p
,
slot
);
b
=
read_tree_block
(
root
,
btrfs_node_blockptr
(
c
,
slot
));
}
else
{
struct
btrfs_leaf
*
l
=
(
struct
btrfs_leaf
*
)
c
;
p
->
slots
[
level
]
=
slot
;
...
...
@@ -1915,6 +1988,8 @@ int btrfs_next_leaf(struct btrfs_root *root, struct btrfs_path *path)
blocknr
=
btrfs_node_blockptr
(
c_node
,
slot
);
if
(
next
)
btrfs_block_release
(
root
,
next
);
if
(
level
==
1
&&
path
->
reada
)
reada_for_search
(
root
,
path
,
slot
);
next
=
read_tree_block
(
root
,
blocknr
);
break
;
}
...
...
@@ -1927,6 +2002,8 @@ int btrfs_next_leaf(struct btrfs_root *root, struct btrfs_path *path)
path
->
slots
[
level
]
=
0
;
if
(
!
level
)
break
;
if
(
level
==
1
&&
path
->
reada
)
reada_for_search
(
root
,
path
,
slot
);
next
=
read_tree_block
(
root
,
btrfs_node_blockptr
(
btrfs_buffer_node
(
next
),
0
));
}
...
...
fs/btrfs/ctree.h
浏览文件 @
3c69faec
...
...
@@ -177,6 +177,7 @@ struct btrfs_node {
struct
btrfs_path
{
struct
buffer_head
*
nodes
[
BTRFS_MAX_LEVEL
];
int
slots
[
BTRFS_MAX_LEVEL
];
int
reada
;
};
/*
...
...
fs/btrfs/extent-tree.c
浏览文件 @
3c69faec
...
...
@@ -32,33 +32,6 @@ static int finish_current_insert(struct btrfs_trans_handle *trans, struct
static
int
del_pending_extents
(
struct
btrfs_trans_handle
*
trans
,
struct
btrfs_root
*
extent_root
);
static
void
reada_extent_leaves
(
struct
btrfs_root
*
root
,
struct
btrfs_path
*
path
,
u64
limit
)
{
struct
btrfs_node
*
node
;
int
i
;
int
nritems
;
u64
item_objectid
;
u64
blocknr
;
int
slot
;
int
ret
;
if
(
!
path
->
nodes
[
1
])
return
;
node
=
btrfs_buffer_node
(
path
->
nodes
[
1
]);
slot
=
path
->
slots
[
1
]
+
1
;
nritems
=
btrfs_header_nritems
(
&
node
->
header
);
for
(
i
=
slot
;
i
<
nritems
&&
i
<
slot
+
8
;
i
++
)
{
item_objectid
=
btrfs_disk_key_objectid
(
&
node
->
ptrs
[
i
].
key
);
if
(
item_objectid
>
limit
)
break
;
blocknr
=
btrfs_node_blockptr
(
node
,
i
);
ret
=
readahead_tree_block
(
root
,
blocknr
);
if
(
ret
)
break
;
}
}
static
int
cache_block_group
(
struct
btrfs_root
*
root
,
struct
btrfs_block_group_cache
*
block_group
)
{
...
...
@@ -84,6 +57,7 @@ static int cache_block_group(struct btrfs_root *root,
path
=
btrfs_alloc_path
();
if
(
!
path
)
return
-
ENOMEM
;
path
->
reada
=
1
;
key
.
objectid
=
block_group
->
key
.
objectid
;
key
.
flags
=
0
;
key
.
offset
=
0
;
...
...
@@ -94,12 +68,10 @@ static int cache_block_group(struct btrfs_root *root,
if
(
ret
&&
path
->
slots
[
0
]
>
0
)
path
->
slots
[
0
]
--
;
limit
=
block_group
->
key
.
objectid
+
block_group
->
key
.
offset
;
reada_extent_leaves
(
root
,
path
,
limit
);
while
(
1
)
{
leaf
=
btrfs_buffer_leaf
(
path
->
nodes
[
0
]);
slot
=
path
->
slots
[
0
];
if
(
slot
>=
btrfs_header_nritems
(
&
leaf
->
header
))
{
reada_extent_leaves
(
root
,
path
,
limit
);
ret
=
btrfs_next_leaf
(
root
,
path
);
if
(
ret
<
0
)
goto
err
;
...
...
fs/btrfs/inode.c
浏览文件 @
3c69faec
...
...
@@ -374,40 +374,6 @@ static int btrfs_free_inode(struct btrfs_trans_handle *trans,
return
ret
;
}
/*
* truncates go from a high offset to a low offset. So, walk
* from hi to lo in the node and issue readas. Stop when you find
* keys from a different objectid
*/
static
void
reada_truncate
(
struct
btrfs_root
*
root
,
struct
btrfs_path
*
path
,
u64
objectid
)
{
struct
btrfs_node
*
node
;
int
i
;
int
nritems
;
u64
item_objectid
;
u64
blocknr
;
int
slot
;
int
ret
;
if
(
!
path
->
nodes
[
1
])
return
;
node
=
btrfs_buffer_node
(
path
->
nodes
[
1
]);
slot
=
path
->
slots
[
1
];
if
(
slot
==
0
)
return
;
nritems
=
btrfs_header_nritems
(
&
node
->
header
);
for
(
i
=
slot
-
1
;
i
>=
0
;
i
--
)
{
item_objectid
=
btrfs_disk_key_objectid
(
&
node
->
ptrs
[
i
].
key
);
if
(
item_objectid
!=
objectid
)
break
;
blocknr
=
btrfs_node_blockptr
(
node
,
i
);
ret
=
readahead_tree_block
(
root
,
blocknr
);
if
(
ret
)
break
;
}
}
/*
* this can truncate away extent items, csum items and directory items.
* It starts at a high offset and removes keys until it can't find
...
...
@@ -434,6 +400,7 @@ static int btrfs_truncate_in_trans(struct btrfs_trans_handle *trans,
int
del_item
;
path
=
btrfs_alloc_path
();
path
->
reada
=
-
1
;
BUG_ON
(
!
path
);
/* FIXME, add redo link to tree so we don't leak on crash */
key
.
objectid
=
inode
->
i_ino
;
...
...
@@ -450,7 +417,6 @@ static int btrfs_truncate_in_trans(struct btrfs_trans_handle *trans,
BUG_ON
(
path
->
slots
[
0
]
==
0
);
path
->
slots
[
0
]
--
;
}
reada_truncate
(
root
,
path
,
inode
->
i_ino
);
leaf
=
btrfs_buffer_leaf
(
path
->
nodes
[
0
]);
found_key
=
&
leaf
->
items
[
path
->
slots
[
0
]].
key
;
found_type
=
btrfs_disk_key_type
(
found_key
);
...
...
@@ -827,36 +793,6 @@ static struct dentry *btrfs_lookup(struct inode *dir, struct dentry *dentry,
return
d_splice_alias
(
inode
,
dentry
);
}
/*
* readahead one full node of leaves as long as their keys include
* the objectid supplied
*/
static
void
reada_leaves
(
struct
btrfs_root
*
root
,
struct
btrfs_path
*
path
,
u64
objectid
)
{
struct
btrfs_node
*
node
;
int
i
;
u32
nritems
;
u64
item_objectid
;
u64
blocknr
;
int
slot
;
int
ret
;
if
(
!
path
->
nodes
[
1
])
return
;
node
=
btrfs_buffer_node
(
path
->
nodes
[
1
]);
slot
=
path
->
slots
[
1
];
nritems
=
btrfs_header_nritems
(
&
node
->
header
);
for
(
i
=
slot
+
1
;
i
<
nritems
;
i
++
)
{
item_objectid
=
btrfs_disk_key_objectid
(
&
node
->
ptrs
[
i
].
key
);
if
(
item_objectid
!=
objectid
)
break
;
blocknr
=
btrfs_node_blockptr
(
node
,
i
);
ret
=
readahead_tree_block
(
root
,
blocknr
);
if
(
ret
)
break
;
}
}
static
unsigned
char
btrfs_filetype_table
[]
=
{
DT_UNKNOWN
,
DT_REG
,
DT_DIR
,
DT_CHR
,
DT_BLK
,
DT_FIFO
,
DT_SOCK
,
DT_LNK
};
...
...
@@ -890,18 +826,17 @@ static int btrfs_readdir(struct file *filp, void *dirent, filldir_t filldir)
btrfs_set_key_type
(
&
key
,
key_type
);
key
.
offset
=
filp
->
f_pos
;
path
=
btrfs_alloc_path
();
path
->
reada
=
1
;
ret
=
btrfs_search_slot
(
NULL
,
root
,
&
key
,
path
,
0
,
0
);
if
(
ret
<
0
)
goto
err
;
advance
=
0
;
reada_leaves
(
root
,
path
,
inode
->
i_ino
);
while
(
1
)
{
leaf
=
btrfs_buffer_leaf
(
path
->
nodes
[
0
]);
nritems
=
btrfs_header_nritems
(
&
leaf
->
header
);
slot
=
path
->
slots
[
0
];
if
(
advance
||
slot
>=
nritems
)
{
if
(
slot
>=
nritems
-
1
)
{
reada_leaves
(
root
,
path
,
inode
->
i_ino
);
ret
=
btrfs_next_leaf
(
root
,
path
);
if
(
ret
)
break
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录