Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xiphi1978
linux
提交
f4b9aa8d
L
linux
项目概览
xiphi1978
/
linux
通知
2
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,发现更多精彩内容 >>
提交
f4b9aa8d
编写于
3月 27, 2007
作者:
C
Chris Mason
提交者:
David Woodhouse
3月 27, 2007
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
btrfs_truncate
Signed-off-by:
N
Chris Mason
<
chris.mason@oracle.com
>
上级
71951f35
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
114 addition
and
18 deletion
+114
-18
fs/btrfs/extent-tree.c
fs/btrfs/extent-tree.c
+13
-12
fs/btrfs/super.c
fs/btrfs/super.c
+101
-6
未找到文件。
fs/btrfs/extent-tree.c
浏览文件 @
f4b9aa8d
...
...
@@ -171,20 +171,21 @@ static int pin_down_block(struct btrfs_root *root, u64 blocknr, int pending)
struct
btrfs_header
*
header
;
struct
buffer_head
*
bh
;
bh
=
sb_find_get_block
(
root
->
fs_info
->
sb
,
blocknr
);
if
(
bh
)
{
header
=
btrfs_buffer_header
(
bh
);
if
(
btrfs_header_generation
(
header
)
==
root
->
fs_info
->
running_transaction
->
transid
)
{
if
(
!
pending
)
{
bh
=
sb_find_get_block
(
root
->
fs_info
->
sb
,
blocknr
);
if
(
bh
)
{
header
=
btrfs_buffer_header
(
bh
);
if
(
btrfs_header_generation
(
header
)
==
root
->
fs_info
->
running_transaction
->
transid
)
{
brelse
(
bh
);
return
0
;
}
brelse
(
bh
);
return
0
;
}
brelse
(
bh
);
}
if
(
pending
)
err
=
set_radix_bit
(
&
root
->
fs_info
->
pending_del_radix
,
blocknr
);
else
err
=
set_radix_bit
(
&
root
->
fs_info
->
pinned_radix
,
blocknr
);
}
else
{
err
=
set_radix_bit
(
&
root
->
fs_info
->
pending_del_radix
,
blocknr
);
}
BUG_ON
(
err
);
return
0
;
}
...
...
@@ -223,6 +224,7 @@ static int __free_extent(struct btrfs_trans_handle *trans, struct btrfs_root
BUG_ON
(
ei
->
refs
==
0
);
refs
=
btrfs_extent_refs
(
ei
)
-
1
;
btrfs_set_extent_refs
(
ei
,
refs
);
mark_buffer_dirty
(
path
.
nodes
[
0
]);
if
(
refs
==
0
)
{
u64
super_blocks_used
;
...
...
@@ -240,7 +242,6 @@ static int __free_extent(struct btrfs_trans_handle *trans, struct btrfs_root
if
(
ret
)
BUG
();
}
mark_buffer_dirty
(
path
.
nodes
[
0
]);
btrfs_release_path
(
extent_root
,
&
path
);
finish_current_insert
(
trans
,
extent_root
);
return
ret
;
...
...
fs/btrfs/super.c
浏览文件 @
f4b9aa8d
...
...
@@ -28,11 +28,15 @@ static void btrfs_read_locked_inode(struct inode *inode)
struct
btrfs_inode_item
*
inode_item
;
struct
btrfs_root
*
root
=
btrfs_sb
(
inode
->
i_sb
);
int
ret
;
btrfs_init_path
(
&
path
);
mutex_lock
(
&
root
->
fs_info
->
fs_mutex
);
ret
=
btrfs_lookup_inode
(
NULL
,
root
,
&
path
,
inode
->
i_ino
,
0
);
if
(
ret
)
{
make_bad_inode
(
inode
);
btrfs_release_path
(
root
,
&
path
);
mutex_unlock
(
&
root
->
fs_info
->
fs_mutex
);
make_bad_inode
(
inode
);
return
;
}
inode_item
=
btrfs_item_ptr
(
btrfs_buffer_leaf
(
path
.
nodes
[
0
]),
...
...
@@ -53,6 +57,7 @@ static void btrfs_read_locked_inode(struct inode *inode)
inode
->
i_blocks
=
btrfs_inode_nblocks
(
inode_item
);
inode
->
i_generation
=
btrfs_inode_generation
(
inode_item
);
btrfs_release_path
(
root
,
&
path
);
mutex_unlock
(
&
root
->
fs_info
->
fs_mutex
);
switch
(
inode
->
i_mode
&
S_IFMT
)
{
#if 0
default:
...
...
@@ -151,20 +156,85 @@ static int btrfs_free_inode(struct btrfs_trans_handle *trans,
return
ret
;
}
static
int
btrfs_truncate_in_trans
(
struct
btrfs_trans_handle
*
trans
,
struct
btrfs_root
*
root
,
struct
inode
*
inode
)
{
int
ret
;
struct
btrfs_path
path
;
struct
btrfs_key
key
;
struct
btrfs_disk_key
*
found_key
;
struct
btrfs_leaf
*
leaf
;
struct
btrfs_file_extent_item
*
fi
;
u64
extent_start
;
u64
extent_num_blocks
;
/* FIXME, add redo link to tree so we don't leak on crash */
key
.
objectid
=
inode
->
i_ino
;
key
.
offset
=
(
u64
)
-
1
;
key
.
flags
=
0
;
btrfs_set_key_type
(
&
key
,
BTRFS_EXTENT_DATA_KEY
);
while
(
1
)
{
btrfs_init_path
(
&
path
);
ret
=
btrfs_search_slot
(
trans
,
root
,
&
key
,
&
path
,
-
1
,
1
);
if
(
ret
<
0
)
{
btrfs_release_path
(
root
,
&
path
);
goto
error
;
}
if
(
ret
>
0
)
{
BUG_ON
(
path
.
slots
[
0
]
==
0
);
path
.
slots
[
0
]
--
;
}
leaf
=
btrfs_buffer_leaf
(
path
.
nodes
[
0
]);
found_key
=
&
leaf
->
items
[
path
.
slots
[
0
]].
key
;
if
(
btrfs_disk_key_objectid
(
found_key
)
!=
inode
->
i_ino
)
break
;
if
(
btrfs_disk_key_type
(
found_key
)
!=
BTRFS_EXTENT_DATA_KEY
)
break
;
if
(
btrfs_disk_key_offset
(
found_key
)
<
inode
->
i_size
)
break
;
/* FIXME: add extent truncation */
if
(
btrfs_disk_key_offset
(
found_key
)
<
inode
->
i_size
)
break
;
fi
=
btrfs_item_ptr
(
btrfs_buffer_leaf
(
path
.
nodes
[
0
]),
path
.
slots
[
0
],
struct
btrfs_file_extent_item
);
extent_start
=
btrfs_file_extent_disk_blocknr
(
fi
);
extent_num_blocks
=
btrfs_file_extent_disk_num_blocks
(
fi
);
key
.
offset
=
btrfs_disk_key_offset
(
found_key
)
-
1
;
ret
=
btrfs_del_item
(
trans
,
root
,
&
path
);
BUG_ON
(
ret
);
inode
->
i_blocks
-=
btrfs_file_extent_num_blocks
(
fi
)
>>
9
;
btrfs_release_path
(
root
,
&
path
);
ret
=
btrfs_free_extent
(
trans
,
root
,
extent_start
,
extent_num_blocks
,
0
);
BUG_ON
(
ret
);
if
(
btrfs_disk_key_offset
(
found_key
)
==
0
)
break
;
}
btrfs_release_path
(
root
,
&
path
);
ret
=
0
;
error:
return
ret
;
}
static
void
btrfs_delete_inode
(
struct
inode
*
inode
)
{
struct
btrfs_trans_handle
*
trans
;
struct
btrfs_root
*
root
=
btrfs_sb
(
inode
->
i_sb
);
int
ret
;
truncate_inode_pages
(
&
inode
->
i_data
,
0
);
if
(
is_bad_inode
(
inode
))
{
goto
no_delete
;
}
inode
->
i_size
=
0
;
if
(
inode
->
i_blocks
)
WARN_ON
(
1
);
mutex_lock
(
&
root
->
fs_info
->
fs_mutex
);
trans
=
btrfs_start_transaction
(
root
,
1
);
if
(
S_ISREG
(
inode
->
i_mode
))
{
ret
=
btrfs_truncate_in_trans
(
trans
,
root
,
inode
);
BUG_ON
(
ret
);
}
btrfs_free_inode
(
trans
,
root
,
inode
);
btrfs_end_transaction
(
trans
,
root
);
mutex_unlock
(
&
root
->
fs_info
->
fs_mutex
);
...
...
@@ -173,7 +243,6 @@ static void btrfs_delete_inode(struct inode *inode)
clear_inode
(
inode
);
}
static
int
btrfs_inode_by_name
(
struct
inode
*
dir
,
struct
dentry
*
dentry
,
ino_t
*
ino
)
{
...
...
@@ -688,6 +757,8 @@ static int btrfs_get_block(struct inode *inode, sector_t iblock,
err
=
ret
;
goto
out
;
}
inode
->
i_blocks
+=
inode
->
i_sb
->
s_blocksize
>>
9
;
set_buffer_new
(
result
);
map_bh
(
result
,
inode
->
i_sb
,
blocknr
);
out:
...
...
@@ -724,6 +795,30 @@ static int btrfs_writepage(struct page *page, struct writeback_control *wbc)
return
nobh_writepage
(
page
,
btrfs_get_block
,
wbc
);
}
static
void
btrfs_truncate
(
struct
inode
*
inode
)
{
struct
btrfs_root
*
root
=
btrfs_sb
(
inode
->
i_sb
);
int
ret
;
struct
btrfs_trans_handle
*
trans
;
if
(
!
S_ISREG
(
inode
->
i_mode
))
return
;
if
(
IS_APPEND
(
inode
)
||
IS_IMMUTABLE
(
inode
))
return
;
nobh_truncate_page
(
inode
->
i_mapping
,
inode
->
i_size
);
/* FIXME, add redo link to tree so we don't leak on crash */
mutex_lock
(
&
root
->
fs_info
->
fs_mutex
);
trans
=
btrfs_start_transaction
(
root
,
1
);
ret
=
btrfs_truncate_in_trans
(
trans
,
root
,
inode
);
BUG_ON
(
ret
);
ret
=
btrfs_end_transaction
(
trans
,
root
);
BUG_ON
(
ret
);
mutex_unlock
(
&
root
->
fs_info
->
fs_mutex
);
mark_inode_dirty
(
inode
);
}
static
int
btrfs_get_sb
(
struct
file_system_type
*
fs_type
,
int
flags
,
const
char
*
dev_name
,
void
*
data
,
struct
vfsmount
*
mnt
)
{
...
...
@@ -772,7 +867,7 @@ static struct address_space_operations btrfs_aops = {
};
static
struct
inode_operations
btrfs_file_inode_operations
=
{
.
truncate
=
NULL
,
.
truncate
=
btrfs_truncate
,
};
static
struct
file_operations
btrfs_file_operations
=
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录