Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
cloud-kernel
提交
87cbda5c
cloud-kernel
项目概览
openanolis
/
cloud-kernel
1 年多 前同步成功
通知
161
Star
36
Fork
7
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
10
列表
看板
标记
里程碑
合并请求
2
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
cloud-kernel
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
10
Issue
10
列表
看板
标记
里程碑
合并请求
2
合并请求
2
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
87cbda5c
编写于
3月 28, 2007
作者:
C
Chris Mason
提交者:
David Woodhouse
3月 28, 2007
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Btrfs: sha256 csums on metadata
Signed-off-by:
N
Chris Mason
<
chris.mason@oracle.com
>
上级
d98237b3
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
67 addition
and
7 deletion
+67
-7
fs/btrfs/ctree.h
fs/btrfs/ctree.h
+6
-2
fs/btrfs/disk-io.c
fs/btrfs/disk-io.c
+59
-3
fs/btrfs/super.c
fs/btrfs/super.c
+2
-2
未找到文件。
fs/btrfs/ctree.h
浏览文件 @
87cbda5c
...
...
@@ -51,11 +51,11 @@ struct btrfs_key {
* every tree block (leaf or node) starts with this header.
*/
struct
btrfs_header
{
__le32
csum
[
8
];
u8
fsid
[
16
];
/* FS specific uuid */
__le64
blocknr
;
/* which block this node is supposed to live in */
__le64
generation
;
__le64
parentid
;
/* objectid of the tree root */
__le32
csum
;
__le32
ham
;
__le16
nritems
;
__le16
flags
;
...
...
@@ -75,9 +75,10 @@ struct buffer_head;
* it currently lacks any block count etc etc
*/
struct
btrfs_super_block
{
__le32
csum
[
8
];
/* the first 3 fields must match struct btrfs_header */
u8
fsid
[
16
];
/* FS specific uuid */
__le64
blocknr
;
/* this block number */
__le32
csum
;
__le64
magic
;
__le32
blocksize
;
__le64
generation
;
...
...
@@ -217,6 +218,7 @@ struct btrfs_inode_map_item {
struct
btrfs_disk_key
key
;
}
__attribute__
((
__packed__
));
struct
crypto_hash
;
struct
btrfs_fs_info
{
struct
btrfs_root
*
fs_root
;
struct
btrfs_root
*
extent_root
;
...
...
@@ -236,6 +238,8 @@ struct btrfs_fs_info {
struct
inode
*
btree_inode
;
struct
mutex
trans_mutex
;
struct
mutex
fs_mutex
;
struct
crypto_hash
*
hash_tfm
;
spinlock_t
hash_lock
;
};
/*
...
...
fs/btrfs/disk-io.c
浏览文件 @
87cbda5c
#include <linux/module.h>
#include <linux/fs.h>
#include <linux/blkdev.h>
#include <linux/crypto.h>
#include <linux/scatterlist.h>
#include "ctree.h"
#include "disk-io.h"
#include "transaction.h"
...
...
@@ -126,8 +128,51 @@ static int btree_get_block(struct inode *inode, sector_t iblock,
return
0
;
}
static
int
csum_tree_block
(
struct
btrfs_root
*
root
,
struct
buffer_head
*
bh
,
int
verify
)
{
struct
btrfs_node
*
node
=
btrfs_buffer_node
(
bh
);
struct
scatterlist
sg
;
struct
crypto_hash
*
tfm
=
root
->
fs_info
->
hash_tfm
;
struct
hash_desc
desc
;
int
ret
;
char
result
[
32
];
desc
.
tfm
=
tfm
;
desc
.
flags
=
0
;
sg_init_one
(
&
sg
,
bh
->
b_data
+
32
,
bh
->
b_size
-
32
);
spin_lock
(
&
root
->
fs_info
->
hash_lock
);
ret
=
crypto_hash_digest
(
&
desc
,
&
sg
,
bh
->
b_size
-
32
,
result
);
spin_unlock
(
&
root
->
fs_info
->
hash_lock
);
if
(
ret
)
{
printk
(
"sha256 digest failed
\n
"
);
}
if
(
verify
)
{
if
(
memcmp
(
node
->
header
.
csum
,
result
,
sizeof
(
result
)))
printk
(
"csum verify failed on %Lu
\n
"
,
bh
->
b_blocknr
);
return
-
EINVAL
;
}
else
memcpy
(
node
->
header
.
csum
,
result
,
sizeof
(
node
->
header
.
csum
));
return
0
;
}
static
int
btree_writepage
(
struct
page
*
page
,
struct
writeback_control
*
wbc
)
{
struct
buffer_head
*
bh
;
struct
btrfs_root
*
root
=
btrfs_sb
(
page
->
mapping
->
host
->
i_sb
);
struct
buffer_head
*
head
;
if
(
!
page_has_buffers
(
page
))
{
create_empty_buffers
(
page
,
root
->
fs_info
->
sb
->
s_blocksize
,
(
1
<<
BH_Dirty
)
|
(
1
<<
BH_Uptodate
));
}
head
=
page_buffers
(
page
);
bh
=
head
;
do
{
if
(
buffer_dirty
(
bh
))
csum_tree_block
(
root
,
bh
,
0
);
bh
=
bh
->
b_this_page
;
}
while
(
bh
!=
head
);
return
block_write_full_page
(
page
,
btree_get_block
,
wbc
);
}
...
...
@@ -157,6 +202,7 @@ struct buffer_head *read_tree_block(struct btrfs_root *root, u64 blocknr)
wait_on_buffer
(
bh
);
if
(
!
buffer_uptodate
(
bh
))
goto
fail
;
csum_tree_block
(
root
,
bh
,
1
);
}
else
{
unlock_buffer
(
bh
);
}
...
...
@@ -233,8 +279,9 @@ struct btrfs_root *open_ctree(struct super_block *sb,
GFP_NOFS
);
int
ret
;
if
(
!
btrfs_super_root
(
disk_super
))
if
(
!
btrfs_super_root
(
disk_super
))
{
return
NULL
;
}
init_bit_radix
(
&
fs_info
->
pinned_radix
);
init_bit_radix
(
&
fs_info
->
pending_del_radix
);
sb_set_blocksize
(
sb
,
sb_buffer
->
b_size
);
...
...
@@ -252,6 +299,12 @@ struct btrfs_root *open_ctree(struct super_block *sb,
fs_info
->
btree_inode
->
i_size
=
sb
->
s_bdev
->
bd_inode
->
i_size
;
fs_info
->
btree_inode
->
i_mapping
->
a_ops
=
&
btree_aops
;
mapping_set_gfp_mask
(
fs_info
->
btree_inode
->
i_mapping
,
GFP_NOFS
);
fs_info
->
hash_tfm
=
crypto_alloc_hash
(
"sha256"
,
0
,
CRYPTO_ALG_ASYNC
);
if
(
!
fs_info
->
hash_tfm
)
{
printk
(
"failed to allocate sha256 hash
\n
"
);
return
NULL
;
}
spin_lock_init
(
&
fs_info
->
hash_lock
);
mutex_init
(
&
fs_info
->
trans_mutex
);
mutex_init
(
&
fs_info
->
fs_mutex
);
...
...
@@ -262,9 +315,10 @@ struct btrfs_root *open_ctree(struct super_block *sb,
fs_info
->
sb_buffer
=
read_tree_block
(
tree_root
,
sb_buffer
->
b_blocknr
);
if
(
!
fs_info
->
sb_buffer
)
if
(
!
fs_info
->
sb_buffer
)
{
printk
(
"failed2
\n
"
);
return
NULL
;
}
brelse
(
sb_buffer
);
sb_buffer
=
NULL
;
disk_super
=
(
struct
btrfs_super_block
*
)
fs_info
->
sb_buffer
->
b_data
;
...
...
@@ -300,6 +354,7 @@ int write_ctree_super(struct btrfs_trans_handle *trans, struct btrfs_root
root
->
fs_info
->
tree_root
->
node
->
b_blocknr
);
lock_buffer
(
bh
);
clear_buffer_dirty
(
bh
);
csum_tree_block
(
root
,
bh
,
0
);
bh
->
b_end_io
=
end_buffer_write_sync
;
get_bh
(
bh
);
submit_bh
(
WRITE
,
bh
);
...
...
@@ -338,6 +393,7 @@ int close_ctree(struct btrfs_root *root)
root
->
fs_info
->
tree_root
->
node
);
btrfs_block_release
(
root
,
root
->
commit_root
);
btrfs_block_release
(
root
,
root
->
fs_info
->
sb_buffer
);
crypto_free_hash
(
root
->
fs_info
->
hash_tfm
);
iput
(
root
->
fs_info
->
btree_inode
);
kfree
(
root
->
fs_info
->
extent_root
);
kfree
(
root
->
fs_info
->
inode_root
);
...
...
fs/btrfs/super.c
浏览文件 @
87cbda5c
...
...
@@ -473,13 +473,13 @@ static int btrfs_fill_super(struct super_block * sb, void * data, int silent)
}
disk_super
=
(
struct
btrfs_super_block
*
)
bh
->
b_data
;
root
=
open_ctree
(
sb
,
bh
,
disk_super
);
sb
->
s_fs_info
=
root
;
disk_super
=
root
->
fs_info
->
disk_super
;
if
(
!
root
)
{
printk
(
"btrfs: open_ctree failed
\n
"
);
return
-
EIO
;
}
sb
->
s_fs_info
=
root
;
disk_super
=
root
->
fs_info
->
disk_super
;
printk
(
"read in super total blocks %Lu root %Lu
\n
"
,
btrfs_super_total_blocks
(
disk_super
),
btrfs_super_root_dir
(
disk_super
));
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录