Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
L
linux
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
linux
Commits
02217ed2
Commit
02217ed2
authored
Mar 02, 2007
by
Chris Mason
Committed by
David Woodhouse
Mar 02, 2007
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Btrfs: early reference counting
Signed-off-by:
Chris Mason
<
chris.mason@oracle.com
>
parent
77ce6846
Changes
6
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
145 additions
and
80 deletions
+145
-80
fs/btrfs/ctree.c
fs/btrfs/ctree.c
+88
-65
fs/btrfs/ctree.h
fs/btrfs/ctree.h
+2
-1
fs/btrfs/disk-io.c
fs/btrfs/disk-io.c
+2
-0
fs/btrfs/extent-tree.c
fs/btrfs/extent-tree.c
+42
-3
fs/btrfs/quick-test.c
fs/btrfs/quick-test.c
+5
-5
fs/btrfs/random-test.c
fs/btrfs/random-test.c
+6
-6
No files found.
fs/btrfs/ctree.c
View file @
02217ed2
This diff is collapsed.
Click to expand it.
fs/btrfs/ctree.h
View file @
02217ed2
...
...
@@ -142,8 +142,9 @@ struct ctree_path {
};
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
key
*
key
,
struct
ctree_path
*
p
,
int
ins_len
);
int
search_slot
(
struct
ctree_root
*
root
,
struct
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
);
...
...
fs/btrfs/disk-io.c
View file @
02217ed2
...
...
@@ -260,6 +260,8 @@ void tree_block_release(struct ctree_root *root, struct tree_buffer *buf)
if
(
buf
->
count
<
0
)
BUG
();
if
(
buf
->
count
==
0
)
{
BUG_ON
(
!
list_empty
(
&
buf
->
cache
));
BUG_ON
(
!
list_empty
(
&
buf
->
dirty
));
if
(
!
radix_tree_lookup
(
&
root
->
cache_radix
,
buf
->
blocknr
))
BUG
();
radix_tree_delete
(
&
root
->
cache_radix
,
buf
->
blocknr
);
...
...
fs/btrfs/extent-tree.c
View file @
02217ed2
...
...
@@ -15,6 +15,39 @@
*/
#define CTREE_EXTENT_PENDING 0
static
int
inc_block_ref
(
struct
ctree_root
*
root
,
u64
blocknr
)
{
struct
ctree_path
path
;
int
ret
;
struct
key
key
;
struct
leaf
*
l
;
struct
extent_item
*
item
;
init_path
(
&
path
);
key
.
objectid
=
blocknr
;
key
.
flags
=
0
;
key
.
offset
=
1
;
ret
=
search_slot
(
root
->
extent_root
,
&
key
,
&
path
,
0
,
1
);
BUG_ON
(
ret
!=
0
);
l
=
&
path
.
nodes
[
0
]
->
leaf
;
item
=
(
struct
extent_item
*
)(
l
->
data
+
l
->
items
[
path
.
slots
[
0
]].
offset
);
item
->
refs
++
;
BUG_ON
(
list_empty
(
&
path
.
nodes
[
0
]
->
dirty
));
release_path
(
root
->
extent_root
,
&
path
);
return
0
;
}
int
btrfs_inc_ref
(
struct
ctree_root
*
root
,
struct
tree_buffer
*
buf
)
{
u64
blocknr
;
int
i
;
for
(
i
=
0
;
i
<
buf
->
node
.
header
.
nritems
;
i
++
)
{
blocknr
=
buf
->
node
.
blockptrs
[
i
];
inc_block_ref
(
root
,
blocknr
);
}
return
0
;
}
/*
* find all the blocks marked as pending in the radix tree and remove
* them from the extent map
...
...
@@ -39,7 +72,7 @@ static int del_pending_extents(struct ctree_root *extent_root)
key
.
flags
=
0
;
key
.
offset
=
1
;
init_path
(
&
path
);
ret
=
search_slot
(
extent_root
,
&
key
,
&
path
,
-
1
);
ret
=
search_slot
(
extent_root
,
&
key
,
&
path
,
-
1
,
1
);
if
(
ret
)
{
print_tree
(
extent_root
,
extent_root
->
node
);
printf
(
"unable to find %Lu
\n
"
,
key
.
objectid
);
...
...
@@ -83,7 +116,7 @@ int free_extent(struct ctree_root *root, u64 blocknr, u64 num_blocks)
return
0
;
}
init_path
(
&
path
);
ret
=
search_slot
(
extent_root
,
&
key
,
&
path
,
-
1
);
ret
=
search_slot
(
extent_root
,
&
key
,
&
path
,
-
1
,
1
);
if
(
ret
)
{
print_tree
(
extent_root
,
extent_root
->
node
);
printf
(
"failed to find %Lu
\n
"
,
key
.
objectid
);
...
...
@@ -124,7 +157,7 @@ static int find_free_extent(struct ctree_root *orig_root, u64 num_blocks,
ins
->
offset
=
0
;
ins
->
flags
=
0
;
start_found
=
0
;
ret
=
search_slot
(
root
,
ins
,
&
path
,
0
);
ret
=
search_slot
(
root
,
ins
,
&
path
,
0
,
0
);
if
(
ret
<
0
)
goto
error
;
...
...
@@ -221,6 +254,8 @@ static int insert_pending_extents(struct ctree_root *extent_root)
ret
=
insert_item
(
extent_root
,
&
key
,
&
item
,
sizeof
(
item
));
if
(
ret
)
{
printf
(
"%Lu already in tree
\n
"
,
key
.
objectid
);
print_tree
(
extent_root
,
extent_root
->
node
);
BUG
();
// FIXME undo it and return sane
return
ret
;
...
...
@@ -228,6 +263,7 @@ static int insert_pending_extents(struct ctree_root *extent_root)
radix_tree_tag_clear
(
&
extent_root
->
cache_radix
,
gang
[
i
]
->
blocknr
,
CTREE_EXTENT_PENDING
);
printf
(
"%Lu is not pending
\n
"
,
gang
[
i
]
->
blocknr
);
tree_block_release
(
extent_root
,
gang
[
i
]);
}
}
...
...
@@ -266,15 +302,18 @@ int alloc_extent(struct ctree_root *root, u64 num_blocks, u64 search_start,
if
(
pending_ret
)
return
pending_ret
;
*
buf
=
find_tree_block
(
root
,
ins
->
objectid
);
dirty_tree_block
(
root
,
*
buf
);
return
0
;
}
/* we're allocating an extent for the extent tree, don't recurse */
BUG_ON
(
ins
->
offset
!=
1
);
*
buf
=
find_tree_block
(
root
,
ins
->
objectid
);
BUG_ON
(
!*
buf
);
printf
(
"%Lu is pending
\n
"
,
ins
->
objectid
);
radix_tree_tag_set
(
&
root
->
cache_radix
,
ins
->
objectid
,
CTREE_EXTENT_PENDING
);
(
*
buf
)
->
count
++
;
dirty_tree_block
(
root
,
*
buf
);
return
0
;
}
...
...
fs/btrfs/quick-test.c
View file @
02217ed2
...
...
@@ -19,7 +19,7 @@ int main(int ac, char **av) {
int
i
;
int
num
;
int
ret
;
int
run_size
=
10
0000
;
int
run_size
=
10
24
;
int
max_key
=
100000000
;
int
tree_size
=
0
;
struct
ctree_path
path
;
...
...
@@ -57,7 +57,7 @@ int main(int ac, char **av) {
init_path
(
&
path
);
if
(
i
%
10000
==
0
)
fprintf
(
stderr
,
"search %d:%d
\n
"
,
num
,
i
);
ret
=
search_slot
(
root
,
&
ins
,
&
path
,
0
);
ret
=
search_slot
(
root
,
&
ins
,
&
path
,
0
,
0
);
if
(
ret
)
{
print_tree
(
root
,
root
->
node
);
printf
(
"unable to find %d
\n
"
,
num
);
...
...
@@ -79,7 +79,7 @@ int main(int ac, char **av) {
num
=
next_key
(
i
,
max_key
);
ins
.
objectid
=
num
;
init_path
(
&
path
);
ret
=
search_slot
(
root
,
&
ins
,
&
path
,
-
1
);
ret
=
search_slot
(
root
,
&
ins
,
&
path
,
-
1
,
1
);
if
(
!
ret
)
{
if
(
i
%
10000
==
0
)
fprintf
(
stderr
,
"del %d:%d
\n
"
,
num
,
i
);
...
...
@@ -117,7 +117,7 @@ int main(int ac, char **av) {
init_path
(
&
path
);
if
(
i
%
10000
==
0
)
fprintf
(
stderr
,
"search %d:%d
\n
"
,
num
,
i
);
ret
=
search_slot
(
root
,
&
ins
,
&
path
,
0
);
ret
=
search_slot
(
root
,
&
ins
,
&
path
,
0
,
0
);
if
(
ret
)
{
print_tree
(
root
,
root
->
node
);
printf
(
"unable to find %d
\n
"
,
num
);
...
...
@@ -131,7 +131,7 @@ int main(int ac, char **av) {
int
slot
;
ins
.
objectid
=
(
u64
)
-
1
;
init_path
(
&
path
);
ret
=
search_slot
(
root
,
&
ins
,
&
path
,
-
1
);
ret
=
search_slot
(
root
,
&
ins
,
&
path
,
-
1
,
1
);
if
(
ret
==
0
)
BUG
();
...
...
fs/btrfs/random-test.c
View file @
02217ed2
...
...
@@ -93,7 +93,7 @@ static int del_one(struct ctree_root *root, struct radix_tree_root *radix)
ret
=
setup_key
(
radix
,
&
key
,
1
);
if
(
ret
<
0
)
return
0
;
ret
=
search_slot
(
root
,
&
key
,
&
path
,
-
1
);
ret
=
search_slot
(
root
,
&
key
,
&
path
,
-
1
,
1
);
if
(
ret
)
goto
error
;
ret
=
del_item
(
root
,
&
path
);
...
...
@@ -118,7 +118,7 @@ static int lookup_item(struct ctree_root *root, struct radix_tree_root *radix)
ret
=
setup_key
(
radix
,
&
key
,
1
);
if
(
ret
<
0
)
return
0
;
ret
=
search_slot
(
root
,
&
key
,
&
path
,
0
);
ret
=
search_slot
(
root
,
&
key
,
&
path
,
0
,
1
);
release_path
(
root
,
&
path
);
if
(
ret
)
goto
error
;
...
...
@@ -137,7 +137,7 @@ static int lookup_enoent(struct ctree_root *root, struct radix_tree_root *radix)
ret
=
setup_key
(
radix
,
&
key
,
0
);
if
(
ret
<
0
)
return
ret
;
ret
=
search_slot
(
root
,
&
key
,
&
path
,
0
);
ret
=
search_slot
(
root
,
&
key
,
&
path
,
0
,
0
);
release_path
(
root
,
&
path
);
if
(
ret
<=
0
)
goto
error
;
...
...
@@ -163,7 +163,7 @@ static int empty_tree(struct ctree_root *root, struct radix_tree_root *radix,
key
.
objectid
=
(
unsigned
long
)
-
1
;
while
(
nr
--
>=
0
)
{
init_path
(
&
path
);
ret
=
search_slot
(
root
,
&
key
,
&
path
,
-
1
);
ret
=
search_slot
(
root
,
&
key
,
&
path
,
-
1
,
1
);
if
(
ret
<
0
)
{
release_path
(
root
,
&
path
);
return
ret
;
...
...
@@ -216,7 +216,7 @@ static int fill_tree(struct ctree_root *root, struct radix_tree_root *radix,
return
ret
;
}
}
if
(
i
%
10000
==
0
)
{
if
(
i
&&
i
%
10000
==
0
)
{
printf
(
"bigfill %d
\n
"
,
i
);
}
if
(
!
keep_running
)
...
...
@@ -263,7 +263,7 @@ static int fill_radix(struct ctree_root *root, struct radix_tree_root *radix)
key
.
objectid
=
(
unsigned
long
)
-
1
;
while
(
1
)
{
init_path
(
&
path
);
ret
=
search_slot
(
root
,
&
key
,
&
path
,
0
);
ret
=
search_slot
(
root
,
&
key
,
&
path
,
0
,
0
);
if
(
ret
<
0
)
{
release_path
(
root
,
&
path
);
return
ret
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment