Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openeuler
raspberrypi-kernel
提交
234b63a0
R
raspberrypi-kernel
项目概览
openeuler
/
raspberrypi-kernel
通知
13
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
raspberrypi-kernel
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
234b63a0
编写于
3月 13, 2007
作者:
C
Chris Mason
提交者:
David Woodhouse
3月 13, 2007
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
rename funcs and structs to btrfs
Signed-off-by:
N
Chris Mason
<
chris.mason@oracle.com
>
上级
cf27e1ee
变更
11
展开全部
隐藏空白更改
内联
并排
Showing
11 changed file
with
454 addition
and
447 deletion
+454
-447
fs/btrfs/ctree.c
fs/btrfs/ctree.c
+159
-158
fs/btrfs/ctree.h
fs/btrfs/ctree.h
+48
-47
fs/btrfs/debug-tree.c
fs/btrfs/debug-tree.c
+4
-4
fs/btrfs/disk-io.c
fs/btrfs/disk-io.c
+54
-52
fs/btrfs/disk-io.h
fs/btrfs/disk-io.h
+15
-14
fs/btrfs/extent-tree.c
fs/btrfs/extent-tree.c
+74
-73
fs/btrfs/mkfs.c
fs/btrfs/mkfs.c
+13
-13
fs/btrfs/print-tree.c
fs/btrfs/print-tree.c
+12
-11
fs/btrfs/print-tree.h
fs/btrfs/print-tree.h
+2
-2
fs/btrfs/quick-test.c
fs/btrfs/quick-test.c
+27
-27
fs/btrfs/random-test.c
fs/btrfs/random-test.c
+46
-46
未找到文件。
fs/btrfs/ctree.c
浏览文件 @
234b63a0
此差异已折叠。
点击以展开。
fs/btrfs/ctree.h
浏览文件 @
234b63a0
#ifndef __
CTREE
__
#define __
CTREE
__
#ifndef __
BTRFS
__
#define __
BTRFS
__
#include "list.h"
#include "kerncompat.h"
#define
CTREE
_BLOCKSIZE 1024
#define
BTRFS
_BLOCKSIZE 1024
/*
* the key defines the order in the tree, and so it also defines (optimal)
...
...
@@ -46,21 +46,21 @@ struct btrfs_header {
/* generation flags to be added */
}
__attribute__
((
__packed__
));
#define MAX_LEVEL 8
#define NODEPTRS_PER_BLOCK ((
CTREE
_BLOCKSIZE - sizeof(struct btrfs_header)) / \
#define
BTRFS_
MAX_LEVEL 8
#define NODEPTRS_PER_BLOCK ((
BTRFS
_BLOCKSIZE - sizeof(struct btrfs_header)) / \
(sizeof(struct btrfs_disk_key) + sizeof(u64)))
struct
tree
_buffer
;
struct
btrfs
_buffer
;
/*
* in ram representation of the tree. extent_root is used for all allocations
* and for the extent tree extent_root root. current_insert is used
* only for the extent tree.
*/
struct
ctree
_root
{
struct
tree
_buffer
*
node
;
struct
tree
_buffer
*
commit_root
;
struct
ctree
_root
*
extent_root
;
struct
btrfs
_root
{
struct
btrfs
_buffer
*
node
;
struct
btrfs
_buffer
*
commit_root
;
struct
btrfs
_root
*
extent_root
;
struct
btrfs_key
current_insert
;
struct
btrfs_key
last_insert
;
int
fp
;
...
...
@@ -74,7 +74,7 @@ struct ctree_root {
/*
* describes a tree on disk
*/
struct
ctree
_root_info
{
struct
btrfs
_root_info
{
u64
fsid
[
2
];
/* FS specific uuid */
u64
blocknr
;
/* blocknr of this block */
u64
objectid
;
/* inode number of this root */
...
...
@@ -88,9 +88,9 @@ struct ctree_root_info {
* the super block basically lists the main trees of the FS
* it currently lacks any block count etc etc
*/
struct
ctree
_super_block
{
struct
ctree
_root_info
root_info
;
struct
ctree
_root_info
extent_info
;
struct
btrfs
_super_block
{
struct
btrfs
_root_info
root_info
;
struct
btrfs
_root_info
extent_info
;
}
__attribute__
((
__packed__
));
/*
...
...
@@ -111,13 +111,13 @@ struct btrfs_item {
* The data is separate from the items to get the keys closer together
* during searches.
*/
#define LEAF_DATA_SIZE (
CTREE
_BLOCKSIZE - sizeof(struct btrfs_header))
struct
leaf
{
#define LEAF_DATA_SIZE (
BTRFS
_BLOCKSIZE - sizeof(struct btrfs_header))
struct
btrfs_
leaf
{
struct
btrfs_header
header
;
union
{
struct
btrfs_item
items
[
LEAF_DATA_SIZE
/
sizeof
(
struct
btrfs_item
)];
u8
data
[
CTREE_BLOCKSIZE
-
sizeof
(
struct
btrfs_header
)];
u8
data
[
BTRFS_BLOCKSIZE
-
sizeof
(
struct
btrfs_header
)];
};
}
__attribute__
((
__packed__
));
...
...
@@ -125,7 +125,7 @@ struct leaf {
* all non-leaf blocks are nodes, they hold only keys and pointers to
* other blocks
*/
struct
node
{
struct
btrfs_
node
{
struct
btrfs_header
header
;
struct
btrfs_disk_key
keys
[
NODEPTRS_PER_BLOCK
];
__le64
blockptrs
[
NODEPTRS_PER_BLOCK
];
...
...
@@ -135,50 +135,51 @@ struct node {
* items in the extent btree are used to record the objectid of the
* owner of the block and the number of references
*/
struct
extent_item
{
struct
btrfs_
extent_item
{
__le32
refs
;
__le64
owner
;
}
__attribute__
((
__packed__
));
/*
*
ctree
_paths remember the path taken from the root down to the leaf.
* level 0 is always the leaf, and nodes[1...MAX_LEVEL] will point
*
btrfs
_paths remember the path taken from the root down to the leaf.
* level 0 is always the leaf, and nodes[1...
BTRFS_
MAX_LEVEL] will point
* to any other levels that are present.
*
* The slots array records the index of the item or block pointer
* used while walking the tree.
*/
struct
ctree
_path
{
struct
tree_buffer
*
nodes
[
MAX_LEVEL
];
int
slots
[
MAX_LEVEL
];
struct
btrfs
_path
{
struct
btrfs_buffer
*
nodes
[
BTRFS_
MAX_LEVEL
];
int
slots
[
BTRFS_
MAX_LEVEL
];
};
static
inline
u64
btrfs_extent_owner
(
struct
extent_item
*
ei
)
static
inline
u64
btrfs_extent_owner
(
struct
btrfs_
extent_item
*
ei
)
{
return
le64_to_cpu
(
ei
->
owner
);
}
static
inline
void
btrfs_set_extent_owner
(
struct
extent_item
*
ei
,
u64
val
)
static
inline
void
btrfs_set_extent_owner
(
struct
btrfs_
extent_item
*
ei
,
u64
val
)
{
ei
->
owner
=
cpu_to_le64
(
val
);
}
static
inline
u32
btrfs_extent_refs
(
struct
extent_item
*
ei
)
static
inline
u32
btrfs_extent_refs
(
struct
btrfs_
extent_item
*
ei
)
{
return
le32_to_cpu
(
ei
->
refs
);
}
static
inline
void
btrfs_set_extent_refs
(
struct
extent_item
*
ei
,
u32
val
)
static
inline
void
btrfs_set_extent_refs
(
struct
btrfs_
extent_item
*
ei
,
u32
val
)
{
ei
->
refs
=
cpu_to_le32
(
val
);
}
static
inline
u64
btrfs_node_blockptr
(
struct
node
*
n
,
int
nr
)
static
inline
u64
btrfs_node_blockptr
(
struct
btrfs_
node
*
n
,
int
nr
)
{
return
le64_to_cpu
(
n
->
blockptrs
[
nr
]);
}
static
inline
void
btrfs_set_node_blockptr
(
struct
node
*
n
,
int
nr
,
u64
val
)
static
inline
void
btrfs_set_node_blockptr
(
struct
btrfs_node
*
n
,
int
nr
,
u64
val
)
{
n
->
blockptrs
[
nr
]
=
cpu_to_le64
(
val
);
}
...
...
@@ -300,34 +301,34 @@ static inline void btrfs_set_header_flags(struct btrfs_header *h, u16 val)
static
inline
int
btrfs_header_level
(
struct
btrfs_header
*
h
)
{
return
btrfs_header_flags
(
h
)
&
(
MAX_LEVEL
-
1
);
return
btrfs_header_flags
(
h
)
&
(
BTRFS_
MAX_LEVEL
-
1
);
}
static
inline
void
btrfs_set_header_level
(
struct
btrfs_header
*
h
,
int
level
)
{
u16
flags
;
BUG_ON
(
level
>
MAX_LEVEL
);
flags
=
btrfs_header_flags
(
h
)
&
~
(
MAX_LEVEL
-
1
);
BUG_ON
(
level
>
BTRFS_
MAX_LEVEL
);
flags
=
btrfs_header_flags
(
h
)
&
~
(
BTRFS_
MAX_LEVEL
-
1
);
btrfs_set_header_flags
(
h
,
flags
|
level
);
}
static
inline
int
btrfs_is_leaf
(
struct
node
*
n
)
static
inline
int
btrfs_is_leaf
(
struct
btrfs_
node
*
n
)
{
return
(
btrfs_header_level
(
&
n
->
header
)
==
0
);
}
struct
tree_buffer
*
alloc_free_block
(
struct
ctree
_root
*
root
);
int
btrfs_inc_ref
(
struct
ctree_root
*
root
,
struct
tree
_buffer
*
buf
);
int
free_extent
(
struct
ctree
_root
*
root
,
u64
blocknr
,
u64
num_blocks
);
int
search_slot
(
struct
ctree
_root
*
root
,
struct
btrfs_key
*
key
,
struct
ctree
_path
*
p
,
int
ins_len
,
int
cow
);
void
release_path
(
struct
ctree_root
*
root
,
struct
ctree
_path
*
p
);
void
init_path
(
struct
ctree
_path
*
p
);
int
del_item
(
struct
ctree_root
*
root
,
struct
ctree
_path
*
path
);
int
insert_item
(
struct
ctree
_root
*
root
,
struct
btrfs_key
*
key
,
struct
btrfs_buffer
*
btrfs_alloc_free_block
(
struct
btrfs
_root
*
root
);
int
btrfs_inc_ref
(
struct
btrfs_root
*
root
,
struct
btrfs
_buffer
*
buf
);
int
btrfs_free_extent
(
struct
btrfs
_root
*
root
,
u64
blocknr
,
u64
num_blocks
);
int
btrfs_search_slot
(
struct
btrfs
_root
*
root
,
struct
btrfs_key
*
key
,
struct
btrfs
_path
*
p
,
int
ins_len
,
int
cow
);
void
btrfs_release_path
(
struct
btrfs_root
*
root
,
struct
btrfs
_path
*
p
);
void
btrfs_init_path
(
struct
btrfs
_path
*
p
);
int
btrfs_del_item
(
struct
btrfs_root
*
root
,
struct
btrfs
_path
*
path
);
int
btrfs_insert_item
(
struct
btrfs
_root
*
root
,
struct
btrfs_key
*
key
,
void
*
data
,
int
data_size
);
int
next_leaf
(
struct
ctree_root
*
root
,
struct
ctree
_path
*
path
);
int
leaf_free_space
(
struct
leaf
*
leaf
);
int
btrfs_drop_snapshot
(
struct
ctree_root
*
root
,
struct
tree
_buffer
*
snap
);
int
btrfs_finish_extent_commit
(
struct
ctree
_root
*
root
);
int
btrfs_next_leaf
(
struct
btrfs_root
*
root
,
struct
btrfs
_path
*
path
);
int
btrfs_leaf_free_space
(
struct
btrfs_
leaf
*
leaf
);
int
btrfs_drop_snapshot
(
struct
btrfs_root
*
root
,
struct
btrfs
_buffer
*
snap
);
int
btrfs_finish_extent_commit
(
struct
btrfs
_root
*
root
);
#endif
fs/btrfs/debug-tree.c
浏览文件 @
234b63a0
...
...
@@ -7,13 +7,13 @@
#include "print-tree.h"
int
main
(
int
ac
,
char
**
av
)
{
struct
ctree
_super_block
super
;
struct
ctree
_root
*
root
;
struct
btrfs
_super_block
super
;
struct
btrfs
_root
*
root
;
radix_tree_init
();
root
=
open_ctree
(
"dbfile"
,
&
super
);
printf
(
"root tree
\n
"
);
print_tree
(
root
,
root
->
node
);
btrfs_
print_tree
(
root
,
root
->
node
);
printf
(
"map tree
\n
"
);
print_tree
(
root
->
extent_root
,
root
->
extent_root
->
node
);
btrfs_
print_tree
(
root
->
extent_root
,
root
->
extent_root
->
node
);
return
0
;
}
fs/btrfs/disk-io.c
浏览文件 @
234b63a0
...
...
@@ -13,7 +13,7 @@
static
int
allocated_blocks
=
0
;
int
cache_max
=
10000
;
static
int
check_tree_block
(
struct
ctree_root
*
root
,
struct
tree
_buffer
*
buf
)
static
int
check_tree_block
(
struct
btrfs_root
*
root
,
struct
btrfs
_buffer
*
buf
)
{
if
(
buf
->
blocknr
!=
btrfs_header_blocknr
(
&
buf
->
node
.
header
))
BUG
();
...
...
@@ -23,18 +23,18 @@ static int check_tree_block(struct ctree_root *root, struct tree_buffer *buf)
return
0
;
}
static
int
free_some_buffers
(
struct
ctree
_root
*
root
)
static
int
free_some_buffers
(
struct
btrfs
_root
*
root
)
{
struct
list_head
*
node
,
*
next
;
struct
tree
_buffer
*
b
;
struct
btrfs
_buffer
*
b
;
if
(
root
->
cache_size
<
cache_max
)
return
0
;
list_for_each_safe
(
node
,
next
,
&
root
->
cache
)
{
b
=
list_entry
(
node
,
struct
tree
_buffer
,
cache
);
b
=
list_entry
(
node
,
struct
btrfs
_buffer
,
cache
);
if
(
b
->
count
==
1
)
{
BUG_ON
(
!
list_empty
(
&
b
->
dirty
));
list_del_init
(
&
b
->
cache
);
tree
_block_release
(
root
,
b
);
btrfs
_block_release
(
root
,
b
);
if
(
root
->
cache_size
<
cache_max
)
break
;
}
...
...
@@ -42,11 +42,11 @@ static int free_some_buffers(struct ctree_root *root)
return
0
;
}
struct
tree_buffer
*
alloc_tree_block
(
struct
ctree
_root
*
root
,
u64
blocknr
)
struct
btrfs_buffer
*
alloc_tree_block
(
struct
btrfs
_root
*
root
,
u64
blocknr
)
{
struct
tree
_buffer
*
buf
;
struct
btrfs
_buffer
*
buf
;
int
ret
;
buf
=
malloc
(
sizeof
(
struct
tree
_buffer
));
buf
=
malloc
(
sizeof
(
struct
btrfs
_buffer
));
if
(
!
buf
)
return
buf
;
allocated_blocks
++
;
...
...
@@ -66,9 +66,9 @@ struct tree_buffer *alloc_tree_block(struct ctree_root *root, u64 blocknr)
return
buf
;
}
struct
tree_buffer
*
find_tree_block
(
struct
ctree
_root
*
root
,
u64
blocknr
)
struct
btrfs_buffer
*
find_tree_block
(
struct
btrfs
_root
*
root
,
u64
blocknr
)
{
struct
tree
_buffer
*
buf
;
struct
btrfs
_buffer
*
buf
;
buf
=
radix_tree_lookup
(
&
root
->
cache_radix
,
blocknr
);
if
(
buf
)
{
buf
->
count
++
;
...
...
@@ -82,10 +82,10 @@ struct tree_buffer *find_tree_block(struct ctree_root *root, u64 blocknr)
return
buf
;
}
struct
tree_buffer
*
read_tree_block
(
struct
ctree
_root
*
root
,
u64
blocknr
)
struct
btrfs_buffer
*
read_tree_block
(
struct
btrfs
_root
*
root
,
u64
blocknr
)
{
loff_t
offset
=
blocknr
*
CTREE
_BLOCKSIZE
;
struct
tree
_buffer
*
buf
;
loff_t
offset
=
blocknr
*
BTRFS
_BLOCKSIZE
;
struct
btrfs
_buffer
*
buf
;
int
ret
;
buf
=
radix_tree_lookup
(
&
root
->
cache_radix
,
blocknr
);
...
...
@@ -95,8 +95,8 @@ struct tree_buffer *read_tree_block(struct ctree_root *root, u64 blocknr)
buf
=
alloc_tree_block
(
root
,
blocknr
);
if
(
!
buf
)
return
NULL
;
ret
=
pread
(
root
->
fp
,
&
buf
->
node
,
CTREE
_BLOCKSIZE
,
offset
);
if
(
ret
!=
CTREE
_BLOCKSIZE
)
{
ret
=
pread
(
root
->
fp
,
&
buf
->
node
,
BTRFS
_BLOCKSIZE
,
offset
);
if
(
ret
!=
BTRFS
_BLOCKSIZE
)
{
free
(
buf
);
return
NULL
;
}
...
...
@@ -106,7 +106,7 @@ struct tree_buffer *read_tree_block(struct ctree_root *root, u64 blocknr)
return
buf
;
}
int
dirty_tree_block
(
struct
ctree_root
*
root
,
struct
tree
_buffer
*
buf
)
int
dirty_tree_block
(
struct
btrfs_root
*
root
,
struct
btrfs
_buffer
*
buf
)
{
if
(
!
list_empty
(
&
buf
->
dirty
))
return
0
;
...
...
@@ -115,46 +115,47 @@ int dirty_tree_block(struct ctree_root *root, struct tree_buffer *buf)
return
0
;
}
int
clean_tree_block
(
struct
ctree_root
*
root
,
struct
tree
_buffer
*
buf
)
int
clean_tree_block
(
struct
btrfs_root
*
root
,
struct
btrfs
_buffer
*
buf
)
{
if
(
!
list_empty
(
&
buf
->
dirty
))
{
list_del_init
(
&
buf
->
dirty
);
tree
_block_release
(
root
,
buf
);
btrfs
_block_release
(
root
,
buf
);
}
return
0
;
}
int
write_tree_block
(
struct
ctree_root
*
root
,
struct
tree
_buffer
*
buf
)
int
write_tree_block
(
struct
btrfs_root
*
root
,
struct
btrfs
_buffer
*
buf
)
{
u64
blocknr
=
buf
->
blocknr
;
loff_t
offset
=
blocknr
*
CTREE
_BLOCKSIZE
;
loff_t
offset
=
blocknr
*
BTRFS
_BLOCKSIZE
;
int
ret
;
if
(
buf
->
blocknr
!=
btrfs_header_blocknr
(
&
buf
->
node
.
header
))
BUG
();
ret
=
pwrite
(
root
->
fp
,
&
buf
->
node
,
CTREE
_BLOCKSIZE
,
offset
);
if
(
ret
!=
CTREE
_BLOCKSIZE
)
ret
=
pwrite
(
root
->
fp
,
&
buf
->
node
,
BTRFS
_BLOCKSIZE
,
offset
);
if
(
ret
!=
BTRFS
_BLOCKSIZE
)
return
ret
;
return
0
;
}
static
int
__commit_transaction
(
struct
ctree
_root
*
root
)
static
int
__commit_transaction
(
struct
btrfs
_root
*
root
)
{
struct
tree
_buffer
*
b
;
struct
btrfs
_buffer
*
b
;
int
ret
=
0
;
int
wret
;
while
(
!
list_empty
(
&
root
->
trans
))
{
b
=
list_entry
(
root
->
trans
.
next
,
struct
tree
_buffer
,
dirty
);
b
=
list_entry
(
root
->
trans
.
next
,
struct
btrfs
_buffer
,
dirty
);
list_del_init
(
&
b
->
dirty
);
wret
=
write_tree_block
(
root
,
b
);
if
(
wret
)
ret
=
wret
;
tree
_block_release
(
root
,
b
);
btrfs
_block_release
(
root
,
b
);
}
return
ret
;
}
int
commit_transaction
(
struct
ctree_root
*
root
,
struct
ctree_super_block
*
s
)
int
btrfs_commit_transaction
(
struct
btrfs_root
*
root
,
struct
btrfs_super_block
*
s
)
{
int
ret
=
0
;
...
...
@@ -163,20 +164,20 @@ int commit_transaction(struct ctree_root *root, struct ctree_super_block *s)
ret
=
__commit_transaction
(
root
->
extent_root
);
BUG_ON
(
ret
);
if
(
root
->
commit_root
!=
root
->
node
)
{
struct
tree
_buffer
*
snap
=
root
->
commit_root
;
struct
btrfs
_buffer
*
snap
=
root
->
commit_root
;
root
->
commit_root
=
root
->
node
;
root
->
node
->
count
++
;
ret
=
btrfs_drop_snapshot
(
root
,
snap
);
BUG_ON
(
ret
);
//
tree
_block_release(root, snap);
//
btrfs
_block_release(root, snap);
}
write_ctree_super
(
root
,
s
);
btrfs_finish_extent_commit
(
root
);
return
ret
;
}
static
int
__setup_root
(
struct
ctree_root
*
root
,
struct
ctree
_root
*
extent_root
,
struct
ctree
_root_info
*
info
,
int
fp
)
static
int
__setup_root
(
struct
btrfs_root
*
root
,
struct
btrfs
_root
*
extent_root
,
struct
btrfs
_root_info
*
info
,
int
fp
)
{
INIT_LIST_HEAD
(
&
root
->
trans
);
INIT_LIST_HEAD
(
&
root
->
cache
);
...
...
@@ -191,10 +192,10 @@ static int __setup_root(struct ctree_root *root, struct ctree_root *extent_root,
return
0
;
}
struct
ctree_root
*
open_ctree
(
char
*
filename
,
struct
ctree
_super_block
*
super
)
struct
btrfs_root
*
open_ctree
(
char
*
filename
,
struct
btrfs
_super_block
*
super
)
{
struct
ctree_root
*
root
=
malloc
(
sizeof
(
struct
ctree
_root
));
struct
ctree_root
*
extent_root
=
malloc
(
sizeof
(
struct
ctree
_root
));
struct
btrfs_root
*
root
=
malloc
(
sizeof
(
struct
btrfs
_root
));
struct
btrfs_root
*
extent_root
=
malloc
(
sizeof
(
struct
btrfs
_root
));
int
fp
;
int
ret
;
...
...
@@ -207,16 +208,16 @@ struct ctree_root *open_ctree(char *filename, struct ctree_super_block *super)
INIT_RADIX_TREE
(
&
root
->
pinned_radix
,
GFP_KERNEL
);
INIT_RADIX_TREE
(
&
extent_root
->
pinned_radix
,
GFP_KERNEL
);
INIT_RADIX_TREE
(
&
extent_root
->
cache_radix
,
GFP_KERNEL
);
ret
=
pread
(
fp
,
super
,
sizeof
(
struct
ctree
_super_block
),
CTREE_SUPER_INFO_OFFSET
(
CTREE
_BLOCKSIZE
));
ret
=
pread
(
fp
,
super
,
sizeof
(
struct
btrfs
_super_block
),
BTRFS_SUPER_INFO_OFFSET
(
BTRFS
_BLOCKSIZE
));
if
(
ret
==
0
||
super
->
root_info
.
tree_root
==
0
)
{
printf
(
"making new FS!
\n
"
);
ret
=
mkfs
(
fp
);
if
(
ret
)
return
NULL
;
ret
=
pread
(
fp
,
super
,
sizeof
(
struct
ctree
_super_block
),
CTREE_SUPER_INFO_OFFSET
(
CTREE
_BLOCKSIZE
));
if
(
ret
!=
sizeof
(
struct
ctree
_super_block
))
ret
=
pread
(
fp
,
super
,
sizeof
(
struct
btrfs
_super_block
),
BTRFS_SUPER_INFO_OFFSET
(
BTRFS
_BLOCKSIZE
));
if
(
ret
!=
sizeof
(
struct
btrfs
_super_block
))
return
NULL
;
}
BUG_ON
(
ret
<
0
);
...
...
@@ -227,18 +228,19 @@ struct ctree_root *open_ctree(char *filename, struct ctree_super_block *super)
return
root
;
}
static
int
__update_root
(
struct
ctree_root
*
root
,
struct
ctree
_root_info
*
info
)
static
int
__update_root
(
struct
btrfs_root
*
root
,
struct
btrfs
_root_info
*
info
)
{
info
->
tree_root
=
root
->
node
->
blocknr
;
return
0
;
}
int
write_ctree_super
(
struct
ctree_root
*
root
,
struct
ctree
_super_block
*
s
)
int
write_ctree_super
(
struct
btrfs_root
*
root
,
struct
btrfs
_super_block
*
s
)
{
int
ret
;
__update_root
(
root
,
&
s
->
root_info
);
__update_root
(
root
->
extent_root
,
&
s
->
extent_info
);
ret
=
pwrite
(
root
->
fp
,
s
,
sizeof
(
*
s
),
CTREE_SUPER_INFO_OFFSET
(
CTREE_BLOCKSIZE
));
ret
=
pwrite
(
root
->
fp
,
s
,
sizeof
(
*
s
),
BTRFS_SUPER_INFO_OFFSET
(
BTRFS_BLOCKSIZE
));
if
(
ret
!=
sizeof
(
*
s
))
{
fprintf
(
stderr
,
"failed to write new super block err %d
\n
"
,
ret
);
return
ret
;
...
...
@@ -246,19 +248,19 @@ int write_ctree_super(struct ctree_root *root, struct ctree_super_block *s)
return
0
;
}
static
int
drop_cache
(
struct
ctree
_root
*
root
)
static
int
drop_cache
(
struct
btrfs
_root
*
root
)
{
while
(
!
list_empty
(
&
root
->
cache
))
{
struct
tree
_buffer
*
b
=
list_entry
(
root
->
cache
.
next
,
struct
tree
_buffer
,
cache
);
struct
btrfs
_buffer
*
b
=
list_entry
(
root
->
cache
.
next
,
struct
btrfs
_buffer
,
cache
);
list_del_init
(
&
b
->
cache
);
tree
_block_release
(
root
,
b
);
btrfs
_block_release
(
root
,
b
);
}
return
0
;
}
int
close_ctree
(
struct
ctree_root
*
root
,
struct
ctree
_super_block
*
s
)
int
close_ctree
(
struct
btrfs_root
*
root
,
struct
btrfs
_super_block
*
s
)
{
commit_transaction
(
root
,
s
);
btrfs_
commit_transaction
(
root
,
s
);
__commit_transaction
(
root
->
extent_root
);
write_ctree_super
(
root
,
s
);
drop_cache
(
root
->
extent_root
);
...
...
@@ -268,16 +270,16 @@ int close_ctree(struct ctree_root *root, struct ctree_super_block *s)
close
(
root
->
fp
);
if
(
root
->
node
)
tree
_block_release
(
root
,
root
->
node
);
btrfs
_block_release
(
root
,
root
->
node
);
if
(
root
->
extent_root
->
node
)
tree
_block_release
(
root
->
extent_root
,
root
->
extent_root
->
node
);
tree
_block_release
(
root
,
root
->
commit_root
);
btrfs
_block_release
(
root
->
extent_root
,
root
->
extent_root
->
node
);
btrfs
_block_release
(
root
,
root
->
commit_root
);
free
(
root
);
printf
(
"on close %d blocks are allocated
\n
"
,
allocated_blocks
);
return
0
;
}
void
tree_block_release
(
struct
ctree_root
*
root
,
struct
tree
_buffer
*
buf
)
void
btrfs_block_release
(
struct
btrfs_root
*
root
,
struct
btrfs
_buffer
*
buf
)
{
buf
->
count
--
;
if
(
buf
->
count
<
0
)
...
...
fs/btrfs/disk-io.h
浏览文件 @
234b63a0
...
...
@@ -2,29 +2,30 @@
#define __DISKIO__
#include "list.h"
struct
tree
_buffer
{
struct
btrfs
_buffer
{
u64
blocknr
;
int
count
;
union
{
struct
node
node
;
struct
leaf
leaf
;
struct
btrfs_
node
node
;
struct
btrfs_
leaf
leaf
;
};
struct
list_head
dirty
;
struct
list_head
cache
;
};
struct
tree_buffer
*
read_tree_block
(
struct
ctree_root
*
root
,
u64
blocknr
);
struct
tree_buffer
*
find_tree_block
(
struct
ctree_root
*
root
,
u64
blocknr
);
int
write_tree_block
(
struct
ctree_root
*
root
,
struct
tree_buffer
*
buf
);
int
dirty_tree_block
(
struct
ctree_root
*
root
,
struct
tree_buffer
*
buf
);
int
clean_tree_block
(
struct
ctree_root
*
root
,
struct
tree_buffer
*
buf
);
int
commit_transaction
(
struct
ctree_root
*
root
,
struct
ctree_super_block
*
s
);
struct
ctree_root
*
open_ctree
(
char
*
filename
,
struct
ctree_super_block
*
s
);
int
close_ctree
(
struct
ctree_root
*
root
,
struct
ctree_super_block
*
s
);
void
tree_block_release
(
struct
ctree_root
*
root
,
struct
tree_buffer
*
buf
);
int
write_ctree_super
(
struct
ctree_root
*
root
,
struct
ctree_super_block
*
s
);
struct
btrfs_buffer
*
read_tree_block
(
struct
btrfs_root
*
root
,
u64
blocknr
);
struct
btrfs_buffer
*
find_tree_block
(
struct
btrfs_root
*
root
,
u64
blocknr
);
int
write_tree_block
(
struct
btrfs_root
*
root
,
struct
btrfs_buffer
*
buf
);
int
dirty_tree_block
(
struct
btrfs_root
*
root
,
struct
btrfs_buffer
*
buf
);
int
clean_tree_block
(
struct
btrfs_root
*
root
,
struct
btrfs_buffer
*
buf
);
int
btrfs_commit_transaction
(
struct
btrfs_root
*
root
,
struct
btrfs_super_block
*
s
);
struct
btrfs_root
*
open_ctree
(
char
*
filename
,
struct
btrfs_super_block
*
s
);
int
close_ctree
(
struct
btrfs_root
*
root
,
struct
btrfs_super_block
*
s
);
void
btrfs_block_release
(
struct
btrfs_root
*
root
,
struct
btrfs_buffer
*
buf
);
int
write_ctree_super
(
struct
btrfs_root
*
root
,
struct
btrfs_super_block
*
s
);
int
mkfs
(
int
fd
);
#define
CTREE
_SUPER_INFO_OFFSET(bs) (16 * (bs))
#define
BTRFS
_SUPER_INFO_OFFSET(bs) (16 * (bs))
#endif
fs/btrfs/extent-tree.c
浏览文件 @
234b63a0
...
...
@@ -6,11 +6,11 @@
#include "disk-io.h"
#include "print-tree.h"
static
int
find_free_extent
(
struct
ctree
_root
*
orig_root
,
u64
num_blocks
,
static
int
find_free_extent
(
struct
btrfs
_root
*
orig_root
,
u64
num_blocks
,
u64
search_start
,
u64
search_end
,
struct
btrfs_key
*
ins
);
static
int
finish_current_insert
(
struct
ctree
_root
*
extent_root
);
static
int
run_pending
(
struct
ctree
_root
*
extent_root
);
static
int
finish_current_insert
(
struct
btrfs
_root
*
extent_root
);
static
int
run_pending
(
struct
btrfs
_root
*
extent_root
);
/*
* pending extents are blocks that we're trying to allocate in the extent
...
...
@@ -21,62 +21,63 @@ static int run_pending(struct ctree_root *extent_root);
*/
#define CTREE_EXTENT_PENDING_DEL 0
static
int
inc_block_ref
(
struct
ctree
_root
*
root
,
u64
blocknr
)
static
int
inc_block_ref
(
struct
btrfs
_root
*
root
,
u64
blocknr
)
{
struct
ctree
_path
path
;
struct
btrfs
_path
path
;
int
ret
;
struct
btrfs_key
key
;
struct
leaf
*
l
;
struct
extent_item
*
item
;
struct
btrfs_
leaf
*
l
;
struct
btrfs_
extent_item
*
item
;
struct
btrfs_key
ins
;
u32
refs
;
find_free_extent
(
root
->
extent_root
,
0
,
0
,
(
u64
)
-
1
,
&
ins
);
init_path
(
&
path
);
btrfs_
init_path
(
&
path
);
key
.
objectid
=
blocknr
;
key
.
flags
=
0
;
key
.
offset
=
1
;
ret
=
search_slot
(
root
->
extent_root
,
&
key
,
&
path
,
0
,
1
);
ret
=
btrfs_
search_slot
(
root
->
extent_root
,
&
key
,
&
path
,
0
,
1
);
if
(
ret
!=
0
)
BUG
();
BUG_ON
(
ret
!=
0
);
l
=
&
path
.
nodes
[
0
]
->
leaf
;
item
=
(
struct
extent_item
*
)(
l
->
data
+
btrfs_item_offset
(
l
->
items
+
path
.
slots
[
0
]));
item
=
(
struct
btrfs_extent_item
*
)(
l
->
data
+
btrfs_item_offset
(
l
->
items
+
path
.
slots
[
0
]));
refs
=
btrfs_extent_refs
(
item
);
btrfs_set_extent_refs
(
item
,
refs
+
1
);
BUG_ON
(
list_empty
(
&
path
.
nodes
[
0
]
->
dirty
));
release_path
(
root
->
extent_root
,
&
path
);
btrfs_
release_path
(
root
->
extent_root
,
&
path
);
finish_current_insert
(
root
->
extent_root
);
run_pending
(
root
->
extent_root
);
return
0
;
}
static
int
lookup_block_ref
(
struct
ctree
_root
*
root
,
u64
blocknr
,
u32
*
refs
)
static
int
lookup_block_ref
(
struct
btrfs
_root
*
root
,
u64
blocknr
,
u32
*
refs
)
{
struct
ctree
_path
path
;
struct
btrfs
_path
path
;
int
ret
;
struct
btrfs_key
key
;
struct
leaf
*
l
;
struct
extent_item
*
item
;
init_path
(
&
path
);
struct
btrfs_
leaf
*
l
;
struct
btrfs_
extent_item
*
item
;
btrfs_
init_path
(
&
path
);
key
.
objectid
=
blocknr
;
key
.
flags
=
0
;
key
.
offset
=
1
;
ret
=
search_slot
(
root
->
extent_root
,
&
key
,
&
path
,
0
,
0
);
ret
=
btrfs_
search_slot
(
root
->
extent_root
,
&
key
,
&
path
,
0
,
0
);
if
(
ret
!=
0
)
BUG
();
l
=
&
path
.
nodes
[
0
]
->
leaf
;
item
=
(
struct
extent_item
*
)(
l
->
data
+
item
=
(
struct
btrfs_
extent_item
*
)(
l
->
data
+
btrfs_item_offset
(
l
->
items
+
path
.
slots
[
0
]));
*
refs
=
btrfs_extent_refs
(
item
);
release_path
(
root
->
extent_root
,
&
path
);
btrfs_
release_path
(
root
->
extent_root
,
&
path
);
return
0
;
}
int
btrfs_inc_ref
(
struct
ctree_root
*
root
,
struct
tree
_buffer
*
buf
)
int
btrfs_inc_ref
(
struct
btrfs_root
*
root
,
struct
btrfs
_buffer
*
buf
)
{
u64
blocknr
;
int
i
;
...
...
@@ -93,9 +94,9 @@ int btrfs_inc_ref(struct ctree_root *root, struct tree_buffer *buf)
return
0
;
}
int
btrfs_finish_extent_commit
(
struct
ctree
_root
*
root
)
int
btrfs_finish_extent_commit
(
struct
btrfs
_root
*
root
)
{
struct
ctree
_root
*
extent_root
=
root
->
extent_root
;
struct
btrfs
_root
*
extent_root
=
root
->
extent_root
;
unsigned
long
gang
[
8
];
int
ret
;
int
i
;
...
...
@@ -115,10 +116,10 @@ int btrfs_finish_extent_commit(struct ctree_root *root)
return
0
;
}
static
int
finish_current_insert
(
struct
ctree
_root
*
extent_root
)
static
int
finish_current_insert
(
struct
btrfs
_root
*
extent_root
)
{
struct
btrfs_key
ins
;
struct
extent_item
extent_item
;
struct
btrfs_
extent_item
extent_item
;
int
i
;
int
ret
;
...
...
@@ -130,7 +131,7 @@ static int finish_current_insert(struct ctree_root *extent_root)
for
(
i
=
0
;
i
<
extent_root
->
current_insert
.
flags
;
i
++
)
{
ins
.
objectid
=
extent_root
->
current_insert
.
objectid
+
i
;
ret
=
insert_item
(
extent_root
,
&
ins
,
&
extent_item
,
ret
=
btrfs_
insert_item
(
extent_root
,
&
ins
,
&
extent_item
,
sizeof
(
extent_item
));
BUG_ON
(
ret
);
}
...
...
@@ -141,14 +142,14 @@ static int finish_current_insert(struct ctree_root *extent_root)
/*
* remove an extent from the root, returns 0 on success
*/
int
__free_extent
(
struct
ctree
_root
*
root
,
u64
blocknr
,
u64
num_blocks
)
static
int
__free_extent
(
struct
btrfs
_root
*
root
,
u64
blocknr
,
u64
num_blocks
)
{
struct
ctree
_path
path
;
struct
btrfs
_path
path
;
struct
btrfs_key
key
;
struct
ctree
_root
*
extent_root
=
root
->
extent_root
;
struct
btrfs
_root
*
extent_root
=
root
->
extent_root
;
int
ret
;
struct
btrfs_item
*
item
;
struct
extent_item
*
ei
;
struct
btrfs_
extent_item
*
ei
;
struct
btrfs_key
ins
;
u32
refs
;
...
...
@@ -157,16 +158,16 @@ int __free_extent(struct ctree_root *root, u64 blocknr, u64 num_blocks)
key
.
offset
=
num_blocks
;
find_free_extent
(
root
,
0
,
0
,
(
u64
)
-
1
,
&
ins
);
init_path
(
&
path
);
ret
=
search_slot
(
extent_root
,
&
key
,
&
path
,
-
1
,
1
);
btrfs_
init_path
(
&
path
);
ret
=
btrfs_
search_slot
(
extent_root
,
&
key
,
&
path
,
-
1
,
1
);
if
(
ret
)
{
printf
(
"failed to find %Lu
\n
"
,
key
.
objectid
);
print_tree
(
extent_root
,
extent_root
->
node
);
btrfs_
print_tree
(
extent_root
,
extent_root
->
node
);
printf
(
"failed to find %Lu
\n
"
,
key
.
objectid
);
BUG
();
}
item
=
path
.
nodes
[
0
]
->
leaf
.
items
+
path
.
slots
[
0
];
ei
=
(
struct
extent_item
*
)(
path
.
nodes
[
0
]
->
leaf
.
data
+
ei
=
(
struct
btrfs_
extent_item
*
)(
path
.
nodes
[
0
]
->
leaf
.
data
+
btrfs_item_offset
(
item
));
BUG_ON
(
ei
->
refs
==
0
);
refs
=
btrfs_extent_refs
(
ei
)
-
1
;
...
...
@@ -180,14 +181,14 @@ int __free_extent(struct ctree_root *root, u64 blocknr, u64 num_blocks)
BUG_ON
(
err
);
radix_tree_preload_end
();
}
ret
=
del_item
(
extent_root
,
&
path
);
ret
=
btrfs_
del_item
(
extent_root
,
&
path
);
if
(
root
!=
extent_root
&&
extent_root
->
last_insert
.
objectid
<
blocknr
)
extent_root
->
last_insert
.
objectid
=
blocknr
;
if
(
ret
)
BUG
();
}
release_path
(
extent_root
,
&
path
);
btrfs_
release_path
(
extent_root
,
&
path
);
finish_current_insert
(
extent_root
);
return
ret
;
}
...
...
@@ -196,10 +197,10 @@ int __free_extent(struct ctree_root *root, u64 blocknr, u64 num_blocks)
* find all the blocks marked as pending in the radix tree and remove
* them from the extent map
*/
static
int
del_pending_extents
(
struct
ctree
_root
*
extent_root
)
static
int
del_pending_extents
(
struct
btrfs
_root
*
extent_root
)
{
int
ret
;
struct
tree
_buffer
*
gang
[
4
];
struct
btrfs
_buffer
*
gang
[
4
];
int
i
;
while
(
1
)
{
...
...
@@ -214,13 +215,13 @@ static int del_pending_extents(struct ctree_root *extent_root)
radix_tree_tag_clear
(
&
extent_root
->
cache_radix
,
gang
[
i
]
->
blocknr
,
CTREE_EXTENT_PENDING_DEL
);
tree
_block_release
(
extent_root
,
gang
[
i
]);
btrfs
_block_release
(
extent_root
,
gang
[
i
]);
}
}
return
0
;
}
static
int
run_pending
(
struct
ctree
_root
*
extent_root
)
static
int
run_pending
(
struct
btrfs
_root
*
extent_root
)
{
while
(
radix_tree_tagged
(
&
extent_root
->
cache_radix
,
CTREE_EXTENT_PENDING_DEL
))
...
...
@@ -232,11 +233,11 @@ static int run_pending(struct ctree_root *extent_root)
/*
* remove an extent from the root, returns 0 on success
*/
int
free_extent
(
struct
ctree
_root
*
root
,
u64
blocknr
,
u64
num_blocks
)
int
btrfs_free_extent
(
struct
btrfs
_root
*
root
,
u64
blocknr
,
u64
num_blocks
)
{
struct
btrfs_key
key
;
struct
ctree
_root
*
extent_root
=
root
->
extent_root
;
struct
tree
_buffer
*
t
;
struct
btrfs
_root
*
extent_root
=
root
->
extent_root
;
struct
btrfs
_buffer
*
t
;
int
pending_ret
;
int
ret
;
...
...
@@ -262,11 +263,11 @@ int free_extent(struct ctree_root *root, u64 blocknr, u64 num_blocks)
* ins->offset == number of blocks
* Any available blocks before search_start are skipped.
*/
static
int
find_free_extent
(
struct
ctree
_root
*
orig_root
,
u64
num_blocks
,
static
int
find_free_extent
(
struct
btrfs
_root
*
orig_root
,
u64
num_blocks
,
u64
search_start
,
u64
search_end
,
struct
btrfs_key
*
ins
)
{
struct
ctree
_path
path
;
struct
btrfs
_path
path
;
struct
btrfs_key
key
;
int
ret
;
u64
hole_size
=
0
;
...
...
@@ -274,20 +275,20 @@ static int find_free_extent(struct ctree_root *orig_root, u64 num_blocks,
u64
last_block
;
u64
test_block
;
int
start_found
;
struct
leaf
*
l
;
struct
ctree
_root
*
root
=
orig_root
->
extent_root
;
struct
btrfs_
leaf
*
l
;
struct
btrfs
_root
*
root
=
orig_root
->
extent_root
;
int
total_needed
=
num_blocks
;
total_needed
+=
(
btrfs_header_level
(
&
root
->
node
->
node
.
header
)
+
1
)
*
3
;
if
(
root
->
last_insert
.
objectid
>
search_start
)
search_start
=
root
->
last_insert
.
objectid
;
check_failed:
init_path
(
&
path
);
btrfs_
init_path
(
&
path
);
ins
->
objectid
=
search_start
;
ins
->
offset
=
0
;
ins
->
flags
=
0
;
start_found
=
0
;
ret
=
search_slot
(
root
,
ins
,
&
path
,
0
,
0
);
ret
=
btrfs_
search_slot
(
root
,
ins
,
&
path
,
0
,
0
);
if
(
ret
<
0
)
goto
error
;
...
...
@@ -298,7 +299,7 @@ static int find_free_extent(struct ctree_root *orig_root, u64 num_blocks,
l
=
&
path
.
nodes
[
0
]
->
leaf
;
slot
=
path
.
slots
[
0
];
if
(
slot
>=
btrfs_header_nritems
(
&
l
->
header
))
{
ret
=
next_leaf
(
root
,
&
path
);
ret
=
btrfs_
next_leaf
(
root
,
&
path
);
if
(
ret
==
0
)
continue
;
if
(
ret
<
0
)
...
...
@@ -336,7 +337,7 @@ static int find_free_extent(struct ctree_root *orig_root, u64 num_blocks,
/* we have to make sure we didn't find an extent that has already
* been allocated by the map tree or the original allocation
*/
release_path
(
root
,
&
path
);
btrfs_
release_path
(
root
,
&
path
);
BUG_ON
(
ins
->
objectid
<
search_start
);
for
(
test_block
=
ins
->
objectid
;
test_block
<
ins
->
objectid
+
total_needed
;
test_block
++
)
{
...
...
@@ -353,7 +354,7 @@ static int find_free_extent(struct ctree_root *orig_root, u64 num_blocks,
ins
->
offset
=
num_blocks
;
return
0
;
error:
release_path
(
root
,
&
path
);
btrfs_
release_path
(
root
,
&
path
);
return
ret
;
}
...
...
@@ -364,13 +365,13 @@ static int find_free_extent(struct ctree_root *orig_root, u64 num_blocks,
*
* returns 0 if everything worked, non-zero otherwise.
*/
int
alloc_extent
(
struct
ctree
_root
*
root
,
u64
num_blocks
,
u64
search_start
,
int
alloc_extent
(
struct
btrfs
_root
*
root
,
u64
num_blocks
,
u64
search_start
,
u64
search_end
,
u64
owner
,
struct
btrfs_key
*
ins
)
{
int
ret
;
int
pending_ret
;
struct
ctree
_root
*
extent_root
=
root
->
extent_root
;
struct
extent_item
extent_item
;
struct
btrfs
_root
*
extent_root
=
root
->
extent_root
;
struct
btrfs_
extent_item
extent_item
;
btrfs_set_extent_refs
(
&
extent_item
,
1
);
btrfs_set_extent_owner
(
&
extent_item
,
owner
);
...
...
@@ -390,7 +391,7 @@ int alloc_extent(struct ctree_root *root, u64 num_blocks, u64 search_start,
if
(
ret
)
return
ret
;
ret
=
insert_item
(
extent_root
,
ins
,
&
extent_item
,
ret
=
btrfs_
insert_item
(
extent_root
,
ins
,
&
extent_item
,
sizeof
(
extent_item
));
finish_current_insert
(
extent_root
);
...
...
@@ -406,11 +407,11 @@ int alloc_extent(struct ctree_root *root, u64 num_blocks, u64 search_start,
* helper function to allocate a block for a given tree
* returns the tree buffer or NULL.
*/
struct
tree_buffer
*
alloc_free_block
(
struct
ctree
_root
*
root
)
struct
btrfs_buffer
*
btrfs_alloc_free_block
(
struct
btrfs
_root
*
root
)
{
struct
btrfs_key
ins
;
int
ret
;
struct
tree
_buffer
*
buf
;
struct
btrfs
_buffer
*
buf
;
ret
=
alloc_extent
(
root
,
1
,
0
,
(
unsigned
long
)
-
1
,
btrfs_header_parentid
(
&
root
->
node
->
node
.
header
),
...
...
@@ -424,10 +425,10 @@ struct tree_buffer *alloc_free_block(struct ctree_root *root)
return
buf
;
}
int
walk_down_tree
(
struct
ctree_root
*
root
,
struct
ctree
_path
*
path
,
int
*
level
)
int
walk_down_tree
(
struct
btrfs_root
*
root
,
struct
btrfs
_path
*
path
,
int
*
level
)
{
struct
tree
_buffer
*
next
;
struct
tree
_buffer
*
cur
;
struct
btrfs
_buffer
*
next
;
struct
btrfs
_buffer
*
cur
;
u64
blocknr
;
int
ret
;
u32
refs
;
...
...
@@ -445,33 +446,33 @@ int walk_down_tree(struct ctree_root *root, struct ctree_path *path, int *level)
ret
=
lookup_block_ref
(
root
,
blocknr
,
&
refs
);
if
(
refs
!=
1
||
*
level
==
1
)
{
path
->
slots
[
*
level
]
++
;
ret
=
free_extent
(
root
,
blocknr
,
1
);
ret
=
btrfs_
free_extent
(
root
,
blocknr
,
1
);
BUG_ON
(
ret
);
continue
;
}
BUG_ON
(
ret
);
next
=
read_tree_block
(
root
,
blocknr
);
if
(
path
->
nodes
[
*
level
-
1
])
tree
_block_release
(
root
,
path
->
nodes
[
*
level
-
1
]);
btrfs
_block_release
(
root
,
path
->
nodes
[
*
level
-
1
]);
path
->
nodes
[
*
level
-
1
]
=
next
;
*
level
=
btrfs_header_level
(
&
next
->
node
.
header
);
path
->
slots
[
*
level
]
=
0
;
}
out:
ret
=
free_extent
(
root
,
path
->
nodes
[
*
level
]
->
blocknr
,
1
);
tree
_block_release
(
root
,
path
->
nodes
[
*
level
]);
ret
=
btrfs_
free_extent
(
root
,
path
->
nodes
[
*
level
]
->
blocknr
,
1
);
btrfs
_block_release
(
root
,
path
->
nodes
[
*
level
]);
path
->
nodes
[
*
level
]
=
NULL
;
*
level
+=
1
;
BUG_ON
(
ret
);
return
0
;
}
int
walk_up_tree
(
struct
ctree_root
*
root
,
struct
ctree
_path
*
path
,
int
*
level
)
int
walk_up_tree
(
struct
btrfs_root
*
root
,
struct
btrfs
_path
*
path
,
int
*
level
)
{
int
i
;
int
slot
;
int
ret
;
for
(
i
=
*
level
;
i
<
MAX_LEVEL
-
1
&&
path
->
nodes
[
i
];
i
++
)
{
for
(
i
=
*
level
;
i
<
BTRFS_
MAX_LEVEL
-
1
&&
path
->
nodes
[
i
];
i
++
)
{
slot
=
path
->
slots
[
i
];
if
(
slot
<
btrfs_header_nritems
(
&
path
->
nodes
[
i
]
->
node
.
header
)
-
1
)
{
...
...
@@ -479,9 +480,9 @@ int walk_up_tree(struct ctree_root *root, struct ctree_path *path, int *level)
*
level
=
i
;
return
0
;
}
else
{
ret
=
free_extent
(
root
,
ret
=
btrfs_
free_extent
(
root
,
path
->
nodes
[
*
level
]
->
blocknr
,
1
);
tree
_block_release
(
root
,
path
->
nodes
[
*
level
]);
btrfs
_block_release
(
root
,
path
->
nodes
[
*
level
]);
path
->
nodes
[
*
level
]
=
NULL
;
*
level
=
i
+
1
;
BUG_ON
(
ret
);
...
...
@@ -490,15 +491,15 @@ int walk_up_tree(struct ctree_root *root, struct ctree_path *path, int *level)
return
1
;
}
int
btrfs_drop_snapshot
(
struct
ctree_root
*
root
,
struct
tree
_buffer
*
snap
)
int
btrfs_drop_snapshot
(
struct
btrfs_root
*
root
,
struct
btrfs
_buffer
*
snap
)
{
int
ret
;
int
level
;
struct
ctree
_path
path
;
struct
btrfs
_path
path
;
int
i
;
int
orig_level
;
init_path
(
&
path
);
btrfs_
init_path
(
&
path
);
level
=
btrfs_header_level
(
&
snap
->
node
.
header
);
orig_level
=
level
;
...
...
@@ -514,7 +515,7 @@ int btrfs_drop_snapshot(struct ctree_root *root, struct tree_buffer *snap)
}
for
(
i
=
0
;
i
<=
orig_level
;
i
++
)
{
if
(
path
.
nodes
[
i
])
{
tree
_block_release
(
root
,
path
.
nodes
[
i
]);
btrfs
_block_release
(
root
,
path
.
nodes
[
i
]);
}
}
...
...
fs/btrfs/mkfs.c
浏览文件 @
234b63a0
...
...
@@ -12,10 +12,10 @@
int
mkfs
(
int
fd
)
{
struct
ctree
_root_info
info
[
2
];
struct
leaf
empty_leaf
;
struct
btrfs
_root_info
info
[
2
];
struct
btrfs_
leaf
empty_leaf
;
struct
btrfs_item
item
;
struct
extent_item
extent_item
;
struct
btrfs_
extent_item
extent_item
;
int
ret
;
/* setup the super block area */
...
...
@@ -28,7 +28,7 @@ int mkfs(int fd)
info
[
1
].
objectid
=
2
;
info
[
1
].
tree_root
=
18
;
ret
=
pwrite
(
fd
,
info
,
sizeof
(
info
),
CTREE_SUPER_INFO_OFFSET
(
CTREE
_BLOCKSIZE
));
BTRFS_SUPER_INFO_OFFSET
(
BTRFS
_BLOCKSIZE
));
if
(
ret
!=
sizeof
(
info
))
return
-
1
;
...
...
@@ -36,7 +36,7 @@ int mkfs(int fd)
memset
(
&
empty_leaf
,
0
,
sizeof
(
empty_leaf
));
btrfs_set_header_parentid
(
&
empty_leaf
.
header
,
1
);
btrfs_set_header_blocknr
(
&
empty_leaf
.
header
,
17
);
ret
=
pwrite
(
fd
,
&
empty_leaf
,
sizeof
(
empty_leaf
),
17
*
CTREE
_BLOCKSIZE
);
ret
=
pwrite
(
fd
,
&
empty_leaf
,
sizeof
(
empty_leaf
),
17
*
BTRFS
_BLOCKSIZE
);
if
(
ret
!=
sizeof
(
empty_leaf
))
return
-
1
;
...
...
@@ -48,9 +48,9 @@ int mkfs(int fd)
btrfs_set_key_objectid
(
&
item
.
key
,
0
);
btrfs_set_key_offset
(
&
item
.
key
,
17
);
btrfs_set_key_flags
(
&
item
.
key
,
0
);
btrfs_set_item_offset
(
&
item
,
LEAF_DATA_SIZE
-
sizeof
(
struct
extent_item
));
btrfs_set_item_size
(
&
item
,
sizeof
(
struct
extent_item
));
btrfs_set_item_offset
(
&
item
,
LEAF_DATA_SIZE
-
sizeof
(
struct
btrfs_
extent_item
));
btrfs_set_item_size
(
&
item
,
sizeof
(
struct
btrfs_
extent_item
));
btrfs_set_extent_refs
(
&
extent_item
,
1
);
btrfs_set_extent_owner
(
&
extent_item
,
0
);
memcpy
(
empty_leaf
.
items
,
&
item
,
sizeof
(
item
));
...
...
@@ -60,8 +60,8 @@ int mkfs(int fd)
/* item2, give block 17 to the root */
btrfs_set_key_objectid
(
&
item
.
key
,
17
);
btrfs_set_key_offset
(
&
item
.
key
,
1
);
btrfs_set_item_offset
(
&
item
,
LEAF_DATA_SIZE
-
sizeof
(
struct
extent_item
)
*
2
);
btrfs_set_item_offset
(
&
item
,
LEAF_DATA_SIZE
-
sizeof
(
struct
btrfs_
extent_item
)
*
2
);
btrfs_set_extent_owner
(
&
extent_item
,
1
);
memcpy
(
empty_leaf
.
items
+
1
,
&
item
,
sizeof
(
item
));
memcpy
(
empty_leaf
.
data
+
btrfs_item_offset
(
&
item
),
&
extent_item
,
...
...
@@ -70,13 +70,13 @@ int mkfs(int fd)
/* item3, give block 18 for the extent root */
btrfs_set_key_objectid
(
&
item
.
key
,
18
);
btrfs_set_key_offset
(
&
item
.
key
,
1
);
btrfs_set_item_offset
(
&
item
,
LEAF_DATA_SIZE
-
sizeof
(
struct
extent_item
)
*
3
);
btrfs_set_item_offset
(
&
item
,
LEAF_DATA_SIZE
-
sizeof
(
struct
btrfs_
extent_item
)
*
3
);
btrfs_set_extent_owner
(
&
extent_item
,
2
);
memcpy
(
empty_leaf
.
items
+
2
,
&
item
,
sizeof
(
item
));
memcpy
(
empty_leaf
.
data
+
btrfs_item_offset
(
&
item
),
&
extent_item
,
btrfs_item_size
(
&
item
));
ret
=
pwrite
(
fd
,
&
empty_leaf
,
sizeof
(
empty_leaf
),
18
*
CTREE
_BLOCKSIZE
);
ret
=
pwrite
(
fd
,
&
empty_leaf
,
sizeof
(
empty_leaf
),
18
*
BTRFS
_BLOCKSIZE
);
if
(
ret
!=
sizeof
(
empty_leaf
))
return
-
1
;
return
0
;
...
...
fs/btrfs/print-tree.c
浏览文件 @
234b63a0
...
...
@@ -5,14 +5,14 @@
#include "ctree.h"
#include "disk-io.h"
void
print_leaf
(
struct
leaf
*
l
)
void
btrfs_print_leaf
(
struct
btrfs_
leaf
*
l
)
{
int
i
;
u32
nr
=
btrfs_header_nritems
(
&
l
->
header
);
struct
btrfs_item
*
item
;
struct
extent_item
*
ei
;
struct
btrfs_
extent_item
*
ei
;
printf
(
"leaf %Lu total ptrs %d free space %d
\n
"
,
btrfs_header_blocknr
(
&
l
->
header
),
nr
,
leaf_free_space
(
l
));
btrfs_header_blocknr
(
&
l
->
header
),
nr
,
btrfs_
leaf_free_space
(
l
));
fflush
(
stdout
);
for
(
i
=
0
;
i
<
nr
;
i
++
)
{
item
=
l
->
items
+
i
;
...
...
@@ -26,24 +26,25 @@ void print_leaf(struct leaf *l)
fflush
(
stdout
);
printf
(
"
\t\t
item data %.*s
\n
"
,
btrfs_item_size
(
item
),
l
->
data
+
btrfs_item_offset
(
item
));
ei
=
(
struct
extent_item
*
)(
l
->
data
+
btrfs_item_offset
(
item
));
ei
=
(
struct
btrfs_extent_item
*
)(
l
->
data
+
btrfs_item_offset
(
item
));
printf
(
"
\t\t
extent data refs %u owner %Lu
\n
"
,
ei
->
refs
,
ei
->
owner
);
fflush
(
stdout
);
}
}
void
print_tree
(
struct
ctree_root
*
root
,
struct
tree
_buffer
*
t
)
void
btrfs_print_tree
(
struct
btrfs_root
*
root
,
struct
btrfs
_buffer
*
t
)
{
int
i
;
u32
nr
;
struct
node
*
c
;
struct
btrfs_
node
*
c
;
if
(
!
t
)
return
;
c
=
&
t
->
node
;
nr
=
btrfs_header_nritems
(
&
c
->
header
);
if
(
btrfs_is_leaf
(
c
))
{
print_leaf
((
struct
leaf
*
)
c
);
btrfs_print_leaf
((
struct
btrfs_
leaf
*
)
c
);
return
;
}
printf
(
"node %Lu level %d total ptrs %d free spc %u
\n
"
,
t
->
blocknr
,
...
...
@@ -58,17 +59,17 @@ void print_tree(struct ctree_root *root, struct tree_buffer *t)
fflush
(
stdout
);
}
for
(
i
=
0
;
i
<
nr
;
i
++
)
{
struct
tree
_buffer
*
next_buf
=
read_tree_block
(
root
,
struct
btrfs
_buffer
*
next_buf
=
read_tree_block
(
root
,
btrfs_node_blockptr
(
c
,
i
));
struct
node
*
next
=
&
next_buf
->
node
;
struct
btrfs_
node
*
next
=
&
next_buf
->
node
;
if
(
btrfs_is_leaf
(
next
)
&&
btrfs_header_level
(
&
c
->
header
)
!=
1
)
BUG
();
if
(
btrfs_header_level
(
&
next
->
header
)
!=
btrfs_header_level
(
&
c
->
header
)
-
1
)
BUG
();
print_tree
(
root
,
next_buf
);
tree
_block_release
(
root
,
next_buf
);
btrfs_
print_tree
(
root
,
next_buf
);
btrfs
_block_release
(
root
,
next_buf
);
}
}
...
...
fs/btrfs/print-tree.h
浏览文件 @
234b63a0
void
print_leaf
(
struct
leaf
*
l
);
void
print_tree
(
struct
ctree_root
*
root
,
struct
tree
_buffer
*
t
);
void
btrfs_print_leaf
(
struct
btrfs_
leaf
*
l
);
void
btrfs_print_tree
(
struct
btrfs_root
*
root
,
struct
btrfs
_buffer
*
t
);
fs/btrfs/quick-test.c
浏览文件 @
234b63a0
...
...
@@ -22,9 +22,9 @@ int main(int ac, char **av) {
int
run_size
=
100000
;
int
max_key
=
100000000
;
int
tree_size
=
0
;
struct
ctree
_path
path
;
struct
ctree
_super_block
super
;
struct
ctree
_root
*
root
;
struct
btrfs
_path
path
;
struct
btrfs
_super_block
super
;
struct
btrfs
_root
*
root
;
radix_tree_init
();
...
...
@@ -40,12 +40,12 @@ int main(int ac, char **av) {
ins
.
objectid
=
num
;
ins
.
offset
=
0
;
ins
.
flags
=
0
;
ret
=
insert_item
(
root
,
&
ins
,
buf
,
strlen
(
buf
));
ret
=
btrfs_
insert_item
(
root
,
&
ins
,
buf
,
strlen
(
buf
));
if
(
!
ret
)
tree_size
++
;
free
(
buf
);
if
(
i
==
run_size
-
5
)
{
commit_transaction
(
root
,
&
super
);
btrfs_
commit_transaction
(
root
,
&
super
);
}
}
...
...
@@ -57,16 +57,16 @@ int main(int ac, char **av) {
for
(
i
=
0
;
i
<
run_size
;
i
++
)
{
num
=
next_key
(
i
,
max_key
);
ins
.
objectid
=
num
;
init_path
(
&
path
);
btrfs_
init_path
(
&
path
);
if
(
i
%
10000
==
0
)
fprintf
(
stderr
,
"search %d:%d
\n
"
,
num
,
i
);
ret
=
search_slot
(
root
,
&
ins
,
&
path
,
0
,
0
);
ret
=
btrfs_
search_slot
(
root
,
&
ins
,
&
path
,
0
,
0
);
if
(
ret
)
{
print_tree
(
root
,
root
->
node
);
btrfs_
print_tree
(
root
,
root
->
node
);
printf
(
"unable to find %d
\n
"
,
num
);
exit
(
1
);
}
release_path
(
root
,
&
path
);
btrfs_
release_path
(
root
,
&
path
);
}
close_ctree
(
root
,
&
super
);
root
=
open_ctree
(
"dbfile"
,
&
super
);
...
...
@@ -81,17 +81,17 @@ int main(int ac, char **av) {
for
(
i
=
0
;
i
<
run_size
/
4
;
i
++
)
{
num
=
next_key
(
i
,
max_key
);
ins
.
objectid
=
num
;
init_path
(
&
path
);
ret
=
search_slot
(
root
,
&
ins
,
&
path
,
-
1
,
1
);
btrfs_
init_path
(
&
path
);
ret
=
btrfs_
search_slot
(
root
,
&
ins
,
&
path
,
-
1
,
1
);
if
(
!
ret
)
{
if
(
i
%
10000
==
0
)
fprintf
(
stderr
,
"del %d:%d
\n
"
,
num
,
i
);
ret
=
del_item
(
root
,
&
path
);
ret
=
btrfs_
del_item
(
root
,
&
path
);
if
(
ret
!=
0
)
BUG
();
tree_size
--
;
}
release_path
(
root
,
&
path
);
btrfs_
release_path
(
root
,
&
path
);
}
close_ctree
(
root
,
&
super
);
root
=
open_ctree
(
"dbfile"
,
&
super
);
...
...
@@ -103,7 +103,7 @@ int main(int ac, char **av) {
ins
.
objectid
=
num
;
if
(
i
%
10000
==
0
)
fprintf
(
stderr
,
"insert %d:%d
\n
"
,
num
,
i
);
ret
=
insert_item
(
root
,
&
ins
,
buf
,
strlen
(
buf
));
ret
=
btrfs_
insert_item
(
root
,
&
ins
,
buf
,
strlen
(
buf
));
if
(
!
ret
)
tree_size
++
;
free
(
buf
);
...
...
@@ -115,25 +115,25 @@ int main(int ac, char **av) {
for
(
i
=
0
;
i
<
run_size
;
i
++
)
{
num
=
next_key
(
i
,
max_key
);
ins
.
objectid
=
num
;
init_path
(
&
path
);
btrfs_
init_path
(
&
path
);
if
(
i
%
10000
==
0
)
fprintf
(
stderr
,
"search %d:%d
\n
"
,
num
,
i
);
ret
=
search_slot
(
root
,
&
ins
,
&
path
,
0
,
0
);
ret
=
btrfs_
search_slot
(
root
,
&
ins
,
&
path
,
0
,
0
);
if
(
ret
)
{
print_tree
(
root
,
root
->
node
);
btrfs_
print_tree
(
root
,
root
->
node
);
printf
(
"unable to find %d
\n
"
,
num
);
exit
(
1
);
}
release_path
(
root
,
&
path
);
btrfs_
release_path
(
root
,
&
path
);
}
printf
(
"starting big long delete run
\n
"
);
while
(
root
->
node
&&
btrfs_header_nritems
(
&
root
->
node
->
node
.
header
)
>
0
)
{
struct
leaf
*
leaf
;
struct
btrfs_
leaf
*
leaf
;
int
slot
;
ins
.
objectid
=
(
u64
)
-
1
;
init_path
(
&
path
);
ret
=
search_slot
(
root
,
&
ins
,
&
path
,
-
1
,
1
);
btrfs_
init_path
(
&
path
);
ret
=
btrfs_
search_slot
(
root
,
&
ins
,
&
path
,
-
1
,
1
);
if
(
ret
==
0
)
BUG
();
...
...
@@ -149,26 +149,26 @@ int main(int ac, char **av) {
btrfs_disk_key_to_cpu
(
&
last
,
&
leaf
->
items
[
slot
].
key
);
if
(
tree_size
%
10000
==
0
)
printf
(
"big del %d:%d
\n
"
,
tree_size
,
i
);
ret
=
del_item
(
root
,
&
path
);
ret
=
btrfs_
del_item
(
root
,
&
path
);
if
(
ret
!=
0
)
{
printf
(
"del_item returned %d
\n
"
,
ret
);
BUG
();
}
tree_size
--
;
}
release_path
(
root
,
&
path
);
btrfs_
release_path
(
root
,
&
path
);
}
/*
printf("previous tree:\n");
print_tree(root, root->commit_root);
btrfs_
print_tree(root, root->commit_root);
printf("map before commit\n");
print_tree(root->extent_root, root->extent_root->node);
btrfs_
print_tree(root->extent_root, root->extent_root->node);
*/
commit_transaction
(
root
,
&
super
);
btrfs_
commit_transaction
(
root
,
&
super
);
printf
(
"tree size is now %d
\n
"
,
tree_size
);
printf
(
"root %p commit root %p
\n
"
,
root
->
node
,
root
->
commit_root
);
printf
(
"map tree
\n
"
);
print_tree
(
root
->
extent_root
,
root
->
extent_root
->
node
);
btrfs_
print_tree
(
root
->
extent_root
,
root
->
extent_root
->
node
);
close_ctree
(
root
,
&
super
);
return
0
;
}
fs/btrfs/random-test.c
浏览文件 @
234b63a0
...
...
@@ -8,7 +8,7 @@
#include "print-tree.h"
int
keep_running
=
1
;
struct
ctree
_super_block
super
;
struct
btrfs
_super_block
super
;
static
int
setup_key
(
struct
radix_tree_root
*
root
,
struct
btrfs_key
*
key
,
int
exists
)
...
...
@@ -36,17 +36,17 @@ static int setup_key(struct radix_tree_root *root, struct btrfs_key *key,
return
0
;
}
static
int
ins_one
(
struct
ctree
_root
*
root
,
struct
radix_tree_root
*
radix
)
static
int
ins_one
(
struct
btrfs
_root
*
root
,
struct
radix_tree_root
*
radix
)
{
struct
ctree
_path
path
;
struct
btrfs
_path
path
;
struct
btrfs_key
key
;
int
ret
;
char
buf
[
128
];
unsigned
long
oid
;
init_path
(
&
path
);
btrfs_
init_path
(
&
path
);
ret
=
setup_key
(
radix
,
&
key
,
0
);
sprintf
(
buf
,
"str-%Lu
\n
"
,
key
.
objectid
);
ret
=
insert_item
(
root
,
&
key
,
buf
,
strlen
(
buf
));
ret
=
btrfs_
insert_item
(
root
,
&
key
,
buf
,
strlen
(
buf
));
if
(
ret
)
goto
error
;
oid
=
(
unsigned
long
)
key
.
objectid
;
...
...
@@ -61,18 +61,18 @@ static int ins_one(struct ctree_root *root, struct radix_tree_root *radix)
return
-
1
;
}
static
int
insert_dup
(
struct
ctree
_root
*
root
,
struct
radix_tree_root
*
radix
)
static
int
insert_dup
(
struct
btrfs
_root
*
root
,
struct
radix_tree_root
*
radix
)
{
struct
ctree
_path
path
;
struct
btrfs
_path
path
;
struct
btrfs_key
key
;
int
ret
;
char
buf
[
128
];
init_path
(
&
path
);
btrfs_
init_path
(
&
path
);
ret
=
setup_key
(
radix
,
&
key
,
1
);
if
(
ret
<
0
)
return
0
;
sprintf
(
buf
,
"str-%Lu
\n
"
,
key
.
objectid
);
ret
=
insert_item
(
root
,
&
key
,
buf
,
strlen
(
buf
));
ret
=
btrfs_
insert_item
(
root
,
&
key
,
buf
,
strlen
(
buf
));
if
(
ret
!=
-
EEXIST
)
{
printf
(
"insert on %Lu gave us %d
\n
"
,
key
.
objectid
,
ret
);
return
1
;
...
...
@@ -80,21 +80,21 @@ static int insert_dup(struct ctree_root *root, struct radix_tree_root *radix)
return
0
;
}
static
int
del_one
(
struct
ctree
_root
*
root
,
struct
radix_tree_root
*
radix
)
static
int
del_one
(
struct
btrfs
_root
*
root
,
struct
radix_tree_root
*
radix
)
{
struct
ctree
_path
path
;
struct
btrfs
_path
path
;
struct
btrfs_key
key
;
int
ret
;
unsigned
long
*
ptr
;
init_path
(
&
path
);
btrfs_
init_path
(
&
path
);
ret
=
setup_key
(
radix
,
&
key
,
1
);
if
(
ret
<
0
)
return
0
;
ret
=
search_slot
(
root
,
&
key
,
&
path
,
-
1
,
1
);
ret
=
btrfs_
search_slot
(
root
,
&
key
,
&
path
,
-
1
,
1
);
if
(
ret
)
goto
error
;
ret
=
del_item
(
root
,
&
path
);
release_path
(
root
,
&
path
);
ret
=
btrfs_
del_item
(
root
,
&
path
);
btrfs_
release_path
(
root
,
&
path
);
if
(
ret
!=
0
)
goto
error
;
ptr
=
radix_tree_delete
(
radix
,
key
.
objectid
);
...
...
@@ -106,17 +106,17 @@ static int del_one(struct ctree_root *root, struct radix_tree_root *radix)
return
-
1
;
}
static
int
lookup_item
(
struct
ctree
_root
*
root
,
struct
radix_tree_root
*
radix
)
static
int
lookup_item
(
struct
btrfs
_root
*
root
,
struct
radix_tree_root
*
radix
)
{
struct
ctree
_path
path
;
struct
btrfs
_path
path
;
struct
btrfs_key
key
;
int
ret
;
init_path
(
&
path
);
btrfs_
init_path
(
&
path
);
ret
=
setup_key
(
radix
,
&
key
,
1
);
if
(
ret
<
0
)
return
0
;
ret
=
search_slot
(
root
,
&
key
,
&
path
,
0
,
1
);
release_path
(
root
,
&
path
);
ret
=
btrfs_
search_slot
(
root
,
&
key
,
&
path
,
0
,
1
);
btrfs_
release_path
(
root
,
&
path
);
if
(
ret
)
goto
error
;
return
0
;
...
...
@@ -125,17 +125,17 @@ static int lookup_item(struct ctree_root *root, struct radix_tree_root *radix)
return
-
1
;
}
static
int
lookup_enoent
(
struct
ctree
_root
*
root
,
struct
radix_tree_root
*
radix
)
static
int
lookup_enoent
(
struct
btrfs
_root
*
root
,
struct
radix_tree_root
*
radix
)
{
struct
ctree
_path
path
;
struct
btrfs
_path
path
;
struct
btrfs_key
key
;
int
ret
;
init_path
(
&
path
);
btrfs_
init_path
(
&
path
);
ret
=
setup_key
(
radix
,
&
key
,
0
);
if
(
ret
<
0
)
return
ret
;
ret
=
search_slot
(
root
,
&
key
,
&
path
,
0
,
0
);
release_path
(
root
,
&
path
);
ret
=
btrfs_
search_slot
(
root
,
&
key
,
&
path
,
0
,
0
);
btrfs_
release_path
(
root
,
&
path
);
if
(
ret
<=
0
)
goto
error
;
return
0
;
...
...
@@ -144,10 +144,10 @@ static int lookup_enoent(struct ctree_root *root, struct radix_tree_root *radix)
return
-
1
;
}
static
int
empty_tree
(
struct
ctree
_root
*
root
,
struct
radix_tree_root
*
radix
,
static
int
empty_tree
(
struct
btrfs
_root
*
root
,
struct
radix_tree_root
*
radix
,
int
nr
)
{
struct
ctree
_path
path
;
struct
btrfs
_path
path
;
struct
btrfs_key
key
;
unsigned
long
found
=
0
;
int
ret
;
...
...
@@ -159,22 +159,22 @@ static int empty_tree(struct ctree_root *root, struct radix_tree_root *radix,
key
.
flags
=
0
;
key
.
objectid
=
(
unsigned
long
)
-
1
;
while
(
nr
--
>=
0
)
{
init_path
(
&
path
);
ret
=
search_slot
(
root
,
&
key
,
&
path
,
-
1
,
1
);
btrfs_
init_path
(
&
path
);
ret
=
btrfs_
search_slot
(
root
,
&
key
,
&
path
,
-
1
,
1
);
if
(
ret
<
0
)
{
release_path
(
root
,
&
path
);
btrfs_
release_path
(
root
,
&
path
);
return
ret
;
}
if
(
ret
!=
0
)
{
if
(
path
.
slots
[
0
]
==
0
)
{
release_path
(
root
,
&
path
);
btrfs_
release_path
(
root
,
&
path
);
break
;
}
path
.
slots
[
0
]
-=
1
;
}
slot
=
path
.
slots
[
0
];
found
=
btrfs_key_objectid
(
&
path
.
nodes
[
0
]
->
leaf
.
items
[
slot
].
key
);
ret
=
del_item
(
root
,
&
path
);
ret
=
btrfs_
del_item
(
root
,
&
path
);
count
++
;
if
(
ret
)
{
fprintf
(
stderr
,
...
...
@@ -182,7 +182,7 @@ static int empty_tree(struct ctree_root *root, struct radix_tree_root *radix,
found
);
return
-
1
;
}
release_path
(
root
,
&
path
);
btrfs_
release_path
(
root
,
&
path
);
ptr
=
radix_tree_delete
(
radix
,
found
);
if
(
!
ptr
)
goto
error
;
...
...
@@ -195,7 +195,7 @@ static int empty_tree(struct ctree_root *root, struct radix_tree_root *radix,
return
-
1
;
}
static
int
fill_tree
(
struct
ctree
_root
*
root
,
struct
radix_tree_root
*
radix
,
static
int
fill_tree
(
struct
btrfs
_root
*
root
,
struct
radix_tree_root
*
radix
,
int
count
)
{
int
i
;
...
...
@@ -207,7 +207,7 @@ static int fill_tree(struct ctree_root *root, struct radix_tree_root *radix,
goto
out
;
}
if
(
i
%
1000
==
0
)
{
ret
=
commit_transaction
(
root
,
&
super
);
ret
=
btrfs_
commit_transaction
(
root
,
&
super
);
if
(
ret
)
{
fprintf
(
stderr
,
"fill commit failed
\n
"
);
return
ret
;
...
...
@@ -223,7 +223,7 @@ static int fill_tree(struct ctree_root *root, struct radix_tree_root *radix,
return
ret
;
}
static
int
bulk_op
(
struct
ctree
_root
*
root
,
struct
radix_tree_root
*
radix
)
static
int
bulk_op
(
struct
btrfs
_root
*
root
,
struct
radix_tree_root
*
radix
)
{
int
ret
;
int
nr
=
rand
()
%
5000
;
...
...
@@ -242,13 +242,13 @@ static int bulk_op(struct ctree_root *root, struct radix_tree_root *radix)
}
int
(
*
ops
[])(
struct
ctree
_root
*
root
,
struct
radix_tree_root
*
radix
)
=
int
(
*
ops
[])(
struct
btrfs
_root
*
root
,
struct
radix_tree_root
*
radix
)
=
{
ins_one
,
insert_dup
,
del_one
,
lookup_item
,
lookup_enoent
,
bulk_op
};
static
int
fill_radix
(
struct
ctree
_root
*
root
,
struct
radix_tree_root
*
radix
)
static
int
fill_radix
(
struct
btrfs
_root
*
root
,
struct
radix_tree_root
*
radix
)
{
struct
ctree
_path
path
;
struct
btrfs
_path
path
;
struct
btrfs_key
key
;
unsigned
long
found
;
int
ret
;
...
...
@@ -259,16 +259,16 @@ static int fill_radix(struct ctree_root *root, struct radix_tree_root *radix)
key
.
flags
=
0
;
key
.
objectid
=
(
unsigned
long
)
-
1
;
while
(
1
)
{
init_path
(
&
path
);
ret
=
search_slot
(
root
,
&
key
,
&
path
,
0
,
0
);
btrfs_
init_path
(
&
path
);
ret
=
btrfs_
search_slot
(
root
,
&
key
,
&
path
,
0
,
0
);
if
(
ret
<
0
)
{
release_path
(
root
,
&
path
);
btrfs_
release_path
(
root
,
&
path
);
return
ret
;
}
slot
=
path
.
slots
[
0
];
if
(
ret
!=
0
)
{
if
(
slot
==
0
)
{
release_path
(
root
,
&
path
);
btrfs_
release_path
(
root
,
&
path
);
break
;
}
slot
-=
1
;
...
...
@@ -287,7 +287,7 @@ static int fill_radix(struct ctree_root *root, struct radix_tree_root *radix)
radix_tree_preload_end
();
}
release_path
(
root
,
&
path
);
btrfs_
release_path
(
root
,
&
path
);
key
.
objectid
=
found
-
1
;
if
(
key
.
objectid
>
found
)
break
;
...
...
@@ -312,7 +312,7 @@ int print_usage(void)
int
main
(
int
ac
,
char
**
av
)
{
RADIX_TREE
(
radix
,
GFP_KERNEL
);
struct
ctree
_root
*
root
;
struct
btrfs
_root
*
root
;
int
i
;
int
ret
;
int
count
;
...
...
@@ -370,7 +370,7 @@ int main(int ac, char **av)
if
(
ret
)
{
fprintf
(
stderr
,
"op %d failed %d:%d
\n
"
,
op
,
i
,
iterations
);
print_tree
(
root
,
root
->
node
);
btrfs_
print_tree
(
root
,
root
->
node
);
fprintf
(
stderr
,
"op %d failed %d:%d
\n
"
,
op
,
i
,
iterations
);
err
=
ret
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录