Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
gsplhtlxg
clone-Linux
提交
85e21bac
C
clone-Linux
项目概览
gsplhtlxg
/
clone-Linux
通知
2
Star
0
Fork
1
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
C
clone-Linux
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
85e21bac
编写于
1月 29, 2008
作者:
C
Chris Mason
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Btrfs: During deletes and truncate, remove many items at once from the tree
Signed-off-by:
N
Chris Mason
<
chris.mason@oracle.com
>
上级
70dec807
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
95 addition
and
70 deletion
+95
-70
fs/btrfs/ctree.c
fs/btrfs/ctree.c
+20
-18
fs/btrfs/ctree.h
fs/btrfs/ctree.h
+10
-2
fs/btrfs/extent_io.c
fs/btrfs/extent_io.c
+0
-1
fs/btrfs/inode.c
fs/btrfs/inode.c
+65
-49
未找到文件。
fs/btrfs/ctree.c
浏览文件 @
85e21bac
...
...
@@ -2514,34 +2514,36 @@ static int del_ptr(struct btrfs_trans_handle *trans, struct btrfs_root *root,
* delete the item at the leaf level in path. If that empties
* the leaf, remove it from the tree
*/
int
btrfs_del_item
(
struct
btrfs_trans_handle
*
trans
,
struct
btrfs_root
*
root
,
struct
btrfs_path
*
path
)
int
btrfs_del_item
s
(
struct
btrfs_trans_handle
*
trans
,
struct
btrfs_root
*
root
,
struct
btrfs_path
*
path
,
int
slot
,
int
nr
)
{
int
slot
;
struct
extent_buffer
*
leaf
;
struct
btrfs_item
*
item
;
int
d
off
;
int
dsize
;
int
last_
off
;
int
dsize
=
0
;
int
ret
=
0
;
int
wret
;
int
i
;
u32
nritems
;
leaf
=
path
->
nodes
[
0
];
slot
=
path
->
slots
[
0
];
doff
=
btrfs_item_offset_nr
(
leaf
,
slot
);
dsize
=
btrfs_item_size_nr
(
leaf
,
slot
);
last_off
=
btrfs_item_offset_nr
(
leaf
,
slot
+
nr
-
1
);
for
(
i
=
0
;
i
<
nr
;
i
++
)
dsize
+=
btrfs_item_size_nr
(
leaf
,
slot
+
i
);
nritems
=
btrfs_header_nritems
(
leaf
);
if
(
slot
!=
nritems
-
1
)
{
if
(
slot
+
nr
!=
nritems
)
{
int
i
;
int
data_end
=
leaf_data_end
(
root
,
leaf
);
memmove_extent_buffer
(
leaf
,
btrfs_leaf_data
(
leaf
)
+
data_end
+
dsize
,
btrfs_leaf_data
(
leaf
)
+
data_end
,
d
off
-
data_end
);
last_
off
-
data_end
);
for
(
i
=
slot
+
1
;
i
<
nritems
;
i
++
)
{
for
(
i
=
slot
+
nr
;
i
<
nritems
;
i
++
)
{
u32
ioff
;
item
=
btrfs_item_nr
(
leaf
,
i
);
...
...
@@ -2562,12 +2564,12 @@ int btrfs_del_item(struct btrfs_trans_handle *trans, struct btrfs_root *root,
}
memmove_extent_buffer
(
leaf
,
btrfs_item_nr_offset
(
slot
),
btrfs_item_nr_offset
(
slot
+
1
),
btrfs_item_nr_offset
(
slot
+
nr
),
sizeof
(
struct
btrfs_item
)
*
(
nritems
-
slot
-
1
));
(
nritems
-
slot
-
nr
));
}
btrfs_set_header_nritems
(
leaf
,
nritems
-
1
);
nritems
--
;
btrfs_set_header_nritems
(
leaf
,
nritems
-
nr
);
nritems
-=
nr
;
/* delete the leaf if we've emptied it */
if
(
nritems
==
0
)
{
...
...
@@ -2600,7 +2602,7 @@ int btrfs_del_item(struct btrfs_trans_handle *trans, struct btrfs_root *root,
}
/* delete the leaf if it is mostly empty */
if
(
used
<
BTRFS_LEAF_DATA_SIZE
(
root
)
/
3
)
{
if
(
used
<
BTRFS_LEAF_DATA_SIZE
(
root
)
/
4
)
{
/* push_leaf_left fixes the path.
* make sure the path still points to our leaf
* for possible call to del_ptr below
...
...
@@ -2608,13 +2610,13 @@ int btrfs_del_item(struct btrfs_trans_handle *trans, struct btrfs_root *root,
slot
=
path
->
slots
[
1
];
extent_buffer_get
(
leaf
);
wret
=
push_leaf_
righ
t
(
trans
,
root
,
path
,
1
,
1
);
wret
=
push_leaf_
lef
t
(
trans
,
root
,
path
,
1
,
1
);
if
(
wret
<
0
&&
wret
!=
-
ENOSPC
)
ret
=
wret
;
if
(
path
->
nodes
[
0
]
==
leaf
&&
btrfs_header_nritems
(
leaf
))
{
wret
=
push_leaf_
lef
t
(
trans
,
root
,
path
,
1
,
1
);
wret
=
push_leaf_
righ
t
(
trans
,
root
,
path
,
1
,
1
);
if
(
wret
<
0
&&
wret
!=
-
ENOSPC
)
ret
=
wret
;
}
...
...
fs/btrfs/ctree.h
浏览文件 @
85e21bac
...
...
@@ -1038,8 +1038,16 @@ void btrfs_release_path(struct btrfs_root *root, struct btrfs_path *p);
struct
btrfs_path
*
btrfs_alloc_path
(
void
);
void
btrfs_free_path
(
struct
btrfs_path
*
p
);
void
btrfs_init_path
(
struct
btrfs_path
*
p
);
int
btrfs_del_item
(
struct
btrfs_trans_handle
*
trans
,
struct
btrfs_root
*
root
,
struct
btrfs_path
*
path
);
int
btrfs_del_items
(
struct
btrfs_trans_handle
*
trans
,
struct
btrfs_root
*
root
,
struct
btrfs_path
*
path
,
int
slot
,
int
nr
);
static
inline
int
btrfs_del_item
(
struct
btrfs_trans_handle
*
trans
,
struct
btrfs_root
*
root
,
struct
btrfs_path
*
path
)
{
return
btrfs_del_items
(
trans
,
root
,
path
,
path
->
slots
[
0
],
1
);
}
int
btrfs_insert_item
(
struct
btrfs_trans_handle
*
trans
,
struct
btrfs_root
*
root
,
struct
btrfs_key
*
key
,
void
*
data
,
u32
data_size
);
int
btrfs_insert_empty_item
(
struct
btrfs_trans_handle
*
trans
,
struct
btrfs_root
...
...
fs/btrfs/extent_io.c
浏览文件 @
85e21bac
...
...
@@ -2863,7 +2863,6 @@ int read_extent_buffer_pages(struct extent_io_tree *tree,
if
(
ret
||
!
wait
)
{
return
ret
;
}
for
(
i
=
start_i
;
i
<
num_pages
;
i
++
)
{
page
=
extent_buffer_page
(
eb
,
i
);
wait_on_page_locked
(
page
);
...
...
fs/btrfs/inode.c
浏览文件 @
85e21bac
...
...
@@ -692,27 +692,6 @@ static int btrfs_rmdir(struct inode *dir, struct dentry *dentry)
return
err
;
}
static
int
btrfs_free_inode
(
struct
btrfs_trans_handle
*
trans
,
struct
btrfs_root
*
root
,
struct
inode
*
inode
)
{
struct
btrfs_path
*
path
;
int
ret
;
clear_inode
(
inode
);
path
=
btrfs_alloc_path
();
BUG_ON
(
!
path
);
ret
=
btrfs_lookup_inode
(
trans
,
root
,
path
,
&
BTRFS_I
(
inode
)
->
location
,
-
1
);
if
(
ret
>
0
)
ret
=
-
ENOENT
;
if
(
!
ret
)
ret
=
btrfs_del_item
(
trans
,
root
,
path
);
btrfs_free_path
(
path
);
return
ret
;
}
/*
* 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
...
...
@@ -723,7 +702,8 @@ static int btrfs_free_inode(struct btrfs_trans_handle *trans,
*/
static
int
btrfs_truncate_in_trans
(
struct
btrfs_trans_handle
*
trans
,
struct
btrfs_root
*
root
,
struct
inode
*
inode
)
struct
inode
*
inode
,
u32
min_type
)
{
int
ret
;
struct
btrfs_path
*
path
;
...
...
@@ -739,6 +719,8 @@ static int btrfs_truncate_in_trans(struct btrfs_trans_handle *trans,
u64
root_owner
=
0
;
int
found_extent
;
int
del_item
;
int
pending_del_nr
=
0
;
int
pending_del_slot
=
0
;
int
extent_type
=
-
1
;
btrfs_drop_extent_cache
(
inode
,
inode
->
i_size
,
(
u64
)
-
1
);
...
...
@@ -751,9 +733,8 @@ static int btrfs_truncate_in_trans(struct btrfs_trans_handle *trans,
key
.
offset
=
(
u64
)
-
1
;
key
.
type
=
(
u8
)
-
1
;
while
(
1
)
{
btrfs_init_path
(
path
);
fi
=
NULL
;
search_again:
ret
=
btrfs_search_slot
(
trans
,
root
,
&
key
,
path
,
-
1
,
1
);
if
(
ret
<
0
)
{
goto
error
;
...
...
@@ -762,6 +743,9 @@ static int btrfs_truncate_in_trans(struct btrfs_trans_handle *trans,
BUG_ON
(
path
->
slots
[
0
]
==
0
);
path
->
slots
[
0
]
--
;
}
while
(
1
)
{
fi
=
NULL
;
leaf
=
path
->
nodes
[
0
];
btrfs_item_key_to_cpu
(
leaf
,
&
found_key
,
path
->
slots
[
0
]);
found_type
=
btrfs_key_type
(
&
found_key
);
...
...
@@ -769,10 +753,7 @@ static int btrfs_truncate_in_trans(struct btrfs_trans_handle *trans,
if
(
found_key
.
objectid
!=
inode
->
i_ino
)
break
;
if
(
found_type
!=
BTRFS_CSUM_ITEM_KEY
&&
found_type
!=
BTRFS_DIR_ITEM_KEY
&&
found_type
!=
BTRFS_DIR_INDEX_KEY
&&
found_type
!=
BTRFS_EXTENT_DATA_KEY
)
if
(
found_type
<
min_type
)
break
;
item_end
=
found_key
.
offset
;
...
...
@@ -801,14 +782,17 @@ static int btrfs_truncate_in_trans(struct btrfs_trans_handle *trans,
found_type
=
BTRFS_INODE_ITEM_KEY
;
}
else
if
(
found_type
==
BTRFS_EXTENT_ITEM_KEY
)
{
found_type
=
BTRFS_CSUM_ITEM_KEY
;
}
else
if
(
found_type
==
BTRFS_EXTENT_DATA_KEY
)
{
found_type
=
BTRFS_XATTR_ITEM_KEY
;
}
else
if
(
found_type
==
BTRFS_XATTR_ITEM_KEY
)
{
found_type
=
BTRFS_INODE_REF_KEY
;
}
else
if
(
found_type
)
{
found_type
--
;
}
else
{
break
;
}
btrfs_set_key_type
(
&
key
,
found_type
);
btrfs_release_path
(
root
,
path
);
continue
;
goto
next
;
}
if
(
found_key
.
offset
>=
inode
->
i_size
)
del_item
=
1
;
...
...
@@ -860,13 +844,21 @@ static int btrfs_truncate_in_trans(struct btrfs_trans_handle *trans,
}
delete:
if
(
del_item
)
{
ret
=
btrfs_del_item
(
trans
,
root
,
path
);
if
(
ret
)
goto
error
;
if
(
!
pending_del_nr
)
{
/* no pending yet, add ourselves */
pending_del_slot
=
path
->
slots
[
0
];
pending_del_nr
=
1
;
}
else
if
(
pending_del_nr
&&
path
->
slots
[
0
]
+
1
==
pending_del_slot
)
{
/* hop on the pending chunk */
pending_del_nr
++
;
pending_del_slot
=
path
->
slots
[
0
];
}
else
{
printk
(
"bad pending slot %d pending_del_nr %d pending_del_slot %d
\n
"
,
path
->
slots
[
0
],
pending_del_nr
,
pending_del_slot
);
}
}
else
{
break
;
}
btrfs_release_path
(
root
,
path
);
if
(
found_extent
)
{
ret
=
btrfs_free_extent
(
trans
,
root
,
extent_start
,
extent_num_bytes
,
...
...
@@ -875,9 +867,36 @@ static int btrfs_truncate_in_trans(struct btrfs_trans_handle *trans,
found_key
.
offset
,
0
);
BUG_ON
(
ret
);
}
next:
if
(
path
->
slots
[
0
]
==
0
)
{
if
(
pending_del_nr
)
goto
del_pending
;
btrfs_release_path
(
root
,
path
);
goto
search_again
;
}
path
->
slots
[
0
]
--
;
if
(
pending_del_nr
&&
path
->
slots
[
0
]
+
1
!=
pending_del_slot
)
{
struct
btrfs_key
debug
;
del_pending:
btrfs_item_key_to_cpu
(
path
->
nodes
[
0
],
&
debug
,
pending_del_slot
);
ret
=
btrfs_del_items
(
trans
,
root
,
path
,
pending_del_slot
,
pending_del_nr
);
BUG_ON
(
ret
);
pending_del_nr
=
0
;
btrfs_release_path
(
root
,
path
);
goto
search_again
;
}
}
ret
=
0
;
error:
if
(
pending_del_nr
)
{
ret
=
btrfs_del_items
(
trans
,
root
,
path
,
pending_del_slot
,
pending_del_nr
);
}
btrfs_release_path
(
root
,
path
);
btrfs_free_path
(
path
);
inode
->
i_sb
->
s_dirt
=
1
;
...
...
@@ -1067,16 +1086,12 @@ void btrfs_delete_inode(struct inode *inode)
trans
=
btrfs_start_transaction
(
root
,
1
);
btrfs_set_trans_block_group
(
trans
,
inode
);
ret
=
btrfs_truncate_in_trans
(
trans
,
root
,
inode
);
if
(
ret
)
goto
no_delete_lock
;
ret
=
btrfs_delete_xattrs
(
trans
,
root
,
inode
);
if
(
ret
)
goto
no_delete_lock
;
ret
=
btrfs_free_inode
(
trans
,
root
,
inode
);
ret
=
btrfs_truncate_in_trans
(
trans
,
root
,
inode
,
0
);
if
(
ret
)
goto
no_delete_lock
;
nr
=
trans
->
blocks_used
;
clear_inode
(
inode
);
btrfs_end_transaction
(
trans
,
root
);
mutex_unlock
(
&
root
->
fs_info
->
fs_mutex
);
...
...
@@ -2190,7 +2205,8 @@ static void btrfs_truncate(struct inode *inode)
btrfs_set_trans_block_group
(
trans
,
inode
);
/* FIXME, add redo link to tree so we don't leak on crash */
ret
=
btrfs_truncate_in_trans
(
trans
,
root
,
inode
);
ret
=
btrfs_truncate_in_trans
(
trans
,
root
,
inode
,
BTRFS_EXTENT_DATA_KEY
);
btrfs_update_inode
(
trans
,
root
,
inode
);
nr
=
trans
->
blocks_used
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录