3 #include "kerncompat.h"
4 #include "radix-tree.h"
7 #include "print-tree.h"
8 #include "transaction.h"
10 /* for testing only */
11 int next_key(int i
, int max_key
) {
12 return rand() % max_key
;
16 int main(int ac
, char **av
) {
18 struct btrfs_key last
= { (u64
)-1, 0, 0};
23 int run_size
= 100000;
24 int max_key
= 100000000;
26 struct btrfs_path path
;
27 struct btrfs_super_block super
;
28 struct btrfs_root
*root
;
29 struct btrfs_trans_handle
*trans
;
33 root
= open_ctree("dbfile", &super
);
34 trans
= btrfs_start_transaction(root
, 1);
37 btrfs_set_key_type(&ins
, BTRFS_STRING_ITEM_KEY
);
38 for (i
= 0; i
< run_size
; i
++) {
40 num
= next_key(i
, max_key
);
42 sprintf(buf
, "string-%d", num
);
44 fprintf(stderr
, "insert %d:%d\n", num
, i
);
47 ret
= btrfs_insert_item(trans
, root
, &ins
, buf
, strlen(buf
));
51 if (i
== run_size
- 5) {
52 btrfs_commit_transaction(trans
, root
, &super
);
56 close_ctree(root
, &super
);
58 root
= open_ctree("dbfile", &super
);
59 printf("starting search\n");
61 for (i
= 0; i
< run_size
; i
++) {
62 num
= next_key(i
, max_key
);
64 btrfs_init_path(&path
);
66 fprintf(stderr
, "search %d:%d\n", num
, i
);
67 ret
= btrfs_search_slot(trans
, root
, &ins
, &path
, 0, 0);
69 btrfs_print_tree(root
, root
->node
);
70 printf("unable to find %d\n", num
);
73 btrfs_release_path(root
, &path
);
75 close_ctree(root
, &super
);
76 root
= open_ctree("dbfile", &super
);
77 printf("node %p level %d total ptrs %d free spc %lu\n", root
->node
,
78 btrfs_header_level(&root
->node
->node
.header
),
79 btrfs_header_nritems(&root
->node
->node
.header
),
80 BTRFS_NODEPTRS_PER_BLOCK(root
) -
81 btrfs_header_nritems(&root
->node
->node
.header
));
82 printf("all searches good, deleting some items\n");
85 for (i
= 0 ; i
< run_size
/4; i
++) {
86 num
= next_key(i
, max_key
);
88 btrfs_init_path(&path
);
89 ret
= btrfs_search_slot(trans
, root
, &ins
, &path
, -1, 1);
92 fprintf(stderr
, "del %d:%d\n", num
, i
);
93 ret
= btrfs_del_item(trans
, root
, &path
);
98 btrfs_release_path(root
, &path
);
100 close_ctree(root
, &super
);
101 root
= open_ctree("dbfile", &super
);
103 for (i
= 0; i
< run_size
; i
++) {
105 num
= next_key(i
, max_key
);
106 sprintf(buf
, "string-%d", num
);
109 fprintf(stderr
, "insert %d:%d\n", num
, i
);
110 ret
= btrfs_insert_item(trans
, root
, &ins
, buf
, strlen(buf
));
115 close_ctree(root
, &super
);
116 root
= open_ctree("dbfile", &super
);
118 printf("starting search2\n");
119 for (i
= 0; i
< run_size
; i
++) {
120 num
= next_key(i
, max_key
);
122 btrfs_init_path(&path
);
124 fprintf(stderr
, "search %d:%d\n", num
, i
);
125 ret
= btrfs_search_slot(trans
, root
, &ins
, &path
, 0, 0);
127 btrfs_print_tree(root
, root
->node
);
128 printf("unable to find %d\n", num
);
131 btrfs_release_path(root
, &path
);
133 printf("starting big long delete run\n");
135 btrfs_header_nritems(&root
->node
->node
.header
) > 0) {
136 struct btrfs_leaf
*leaf
;
138 ins
.objectid
= (u64
)-1;
139 btrfs_init_path(&path
);
140 ret
= btrfs_search_slot(trans
, root
, &ins
, &path
, -1, 1);
144 leaf
= &path
.nodes
[0]->leaf
;
145 slot
= path
.slots
[0];
146 if (slot
!= btrfs_header_nritems(&leaf
->header
))
148 while(path
.slots
[0] > 0) {
150 slot
= path
.slots
[0];
151 leaf
= &path
.nodes
[0]->leaf
;
153 btrfs_disk_key_to_cpu(&last
, &leaf
->items
[slot
].key
);
154 if (tree_size
% 10000 == 0)
155 printf("big del %d:%d\n", tree_size
, i
);
156 ret
= btrfs_del_item(trans
, root
, &path
);
158 printf("del_item returned %d\n", ret
);
163 btrfs_release_path(root
, &path
);
166 printf("previous tree:\n");
167 btrfs_print_tree(root, root->commit_root);
168 printf("map before commit\n");
169 btrfs_print_tree(root->extent_root, root->extent_root->node);
171 btrfs_commit_transaction(trans
, root
, &super
);
172 printf("tree size is now %d\n", tree_size
);
173 printf("root %p commit root %p\n", root
->node
, root
->commit_root
);
174 printf("map tree\n");
175 btrfs_print_tree(root
->extent_root
, root
->extent_root
->node
);
176 close_ctree(root
, &super
);
This page took 0.050319 seconds and 5 git commands to generate.