全部博文(48)
分类: LINUX
2013-01-06 12:17:41
-->mkfs.c:main()
-->open_ctree()
-->open_ctree_fs_info()
__open_ctree_fd(): make up struct btrfs_fs_info
-->btrfs_scan_one_device()://make_btrfs自造super_block,device信息
-->btrfs_read_dev_super()
-->read super_block from hard disk or "dd file"
-->device_list_add():????????????????return 0 success。
-->find_fsid():return fs_devices linked all devices
-->__find_device():find btrfs_devices.
-->if btrfs_device no in fs_devices,自造一个加入链表中。
-->btrfs_open_devices():open all the deices and record fd.
-->btrfs_read_dev_super():read sb from disk to fs_info->super_copyt
-->btrfs_read_sys_array():read btrfs_chunk from sys_chunk
-->fell confuse? details in make_btrfs()
-->read_one_chunk():
--> insert map_lookup to fs_info->mapping_tree-->cache_tree
--> map_lookup is outline of *every* btrfs_chunk
-->read_tree_block():
-->btrfs_find_create_tree_block()
-->alloc_extent_buffer()
-->find_cache_extent(): in fs_info->extent_cache
-->__tree_search():
-->__alloc_extent_buffer():
-->insert_existing_cache_extent():
-->insert into fs_info->extent_cache
-->tree_insert():
-->btrfs_map_block()
-->__btrfs_map_block():
-->find_first_cache_extent()
-->read_extent_from_disk()
-->find_and_setup_root():find target objid in tree_root-> node, then setup.
-->btrfs_find_last_root():last reflect in key.offset = (u64)-1;
-->btrfs_search_slot ():
-->bin_search():
-->generic_bin_search()
-->read_tree_block():
-->btrfs_root->btrfs_root_item 从tree_root得到extent_root
--> 的基本信息bytenr block[2]???,这是在make_btrfs 设定的。
-->读取block[2]到extent_root->node.这就算设置完了。
-->make_root_dir()
-->btrfs_start_transaction():set transaction handler
-->btrfs_make_block_group():
-->update_space_info():
-->__find_space_info(): cache->flags has BTRFS_BLOCK_GROUP_SYSTEM
-->set_extent_bits()
-->find_first_cache_extent():in fs_info->block_group_cache->state
-->insert_state():if not found insert into fs_info->block_group_cache
-->merge_state():try to merge state, maybe modify state's info
-->set_state_private():set fs_info->blcok_group_cache with btrfs_b_g_c
-->btrfs_insert_item(): insert btrfs_block_group_cache->item into extent -tree
-->btrfs_alloc_chunk():
--> I think parameter calc_size is the chunk size for dup raid1
--> For raid10 is calc_size * (num_stripes / sub_stripes)
--> For raid0 is calc_size * num_stripes.
--> calc_size 是一个disk上的一个chunk大小, 而chunk size就是存不重复数据的大小
-->对于RAID0 来说要有多个calc_size.
-->chunk_bytes_by_type():this is the real chunk size, both of raid1, dup, raid10
--> are store duplicated data, the real capacity of chunk is calc size for raid1, dup
--> for raid10 is calc size / sub_stripes.
--> we should konw that raid10 is consisted of tow raid1 in raido mode.
-->btrfs_alloc_dev_extent():para chunk_tree = BTRFS_CHUNK_TREE_OBJECTID
--> insert a btrfs_dev_extent into dev_root that records the relation
--> between device's extent and chunk, details in his members.
-->find_free_dev_extent():
-->btrfs_update_device(): Just update bytes_used.
-->btrfs_insert_item():insert the new btrfs_chunk alloced above into chunk_root.
-->btrfs_add_system_chunk():
--> if set BTRFS_BLOCK_GROUP_SYSTEM then write the new btrfs_chunk to
-->fs_info->super_copy->sys_chunk_array.
-->kfree(): temp chunk alloced above.
-->btrfs_make_block_group()
--> insert btrfs_block_group_cache->btrfs_block_gropu item into extent_root
--> and records the start address in key->objectid and size in key->offset
--> space_info records used total flags and so on difference to key.
--> set the private of fs_info->block_group_cache with btrfs_block_group_cache
-->finish_current_insert(): TO BE CONTINUE...
-->del_pending_extents(): TO BE CONTINUE...
-->btrfs_make_root_dir():
-->firstly create a btrfs_inode_item then insert tree_root with parameter
-->objectid = BTRFS_ROOT_TREE_DIR_OBJECTID
--> btrfs_insert_inode()
-->create a key for inserting below
--> btrfs_insert_item()
--> btrfs_insert_inode_ref()
--> btrfs_insert_dir_item()
-->parameter location:(BTRFS_FS_TREE_OBJECTID, ROOT_ITEM, -1)
--> dir #define BTRFS_ROOT_TREE_DIR_OBJECTID 6ULL, but not sure
--> insert_with_overflow()
-->parameters: tree_root,
-->key(ROOT_TREE_DIR_OBJECTID,DIR_ITEM_KEY, name-hash)
-->data_size:btrfs_dir_item + name_len
-->btrfs_insert_empty_item()
-->btrfs_match_dir_item_name()
-->btrfs_extend_item()
-->btrfs_insert_inode_ref()
-->btrfs_commit_transaction():Parameter :fs_root
-->commit_tree_roots():
-->btrfs_cow_block():
-->should_cow_block():
-->__btrfs_cow_block():Paramemter tree_root, tree_root->node.
-->btrfs_alloc_free_block()
-->Parameters: root = tree_root
-->buf->len = blocksize = num bytes
-->BTRFS_ROOT_TREE_OBJECTID = root_objectid
-->key = root key ,search_start = hint_byte
-->flags = 0, search_end = (u64) -1, data =0, return ins
-->alloc_tree_block()
-->btrfs_reserve_extent()
-->
-->__commit_transaction():
-->find_first_extent_bit()
-->write_ctree_super()
-->write_all_supers()
-->btrfs_finish_extent_commit()
-->create_raid_group()
-->create_one_raid_group()
-->btrfs_alloc_chunk()
-->btrfs_make_block_group()
-->create_data_reloc_tree()
Parameters:
fd: file descriptor of hard disk device, may be just a file created by shell dd
path: character pointer of hard disk device's file '/dev/ or something else'
total_devs: total number of device attached to filesystem,used by return ing
btrfs_fs_devices: pointer devices attached to filesystem, used by returning
super_offset: addreses of super block in disk, in this case, is BTRFS_SUPER_INFO_OFFSET.
Function:从硬盘上获取device的信息。这些信息是我们自造的在make_btrfs。
int btrfs_scan_one_device(int fd, const char *path, struct btrfs_fs_devices **fs_devices_ret,
u64 *total_devs, u64 super_offset)
Parameters:
fd: file descriptor of disk device
sb_bytenr:BTRFS_SUPER_INFO_OFFSET
sb: dest address to store super block
Function: read super block from disk
int btrfs_read_dev_super(int fd, struct btrfs_super_block *sb, u64 sb_bytenr)
Parameters:
root:in this case is chunk_root in RAM
bytenr: in this case is btrfs_super_chunk_root(disk_super), that is block[3] in disk.
blocksize:leaf size of node size
parent_transid:btrfs_super_block->chunk_root_generiation set in make_btrfs is 1.
Funtcion:
Read a tree block into extent buffer and return it ,
in this case, read block[3] into chunk_root->node
struct extent_buffer *read_tree_block(struct btrfs_root *root, u64 bytenr,
u32 blocksize, u64 parent_transid)
Parameters:
tree: in this case is fs_info->extent_cache
bytenr:block[3] in disk
blocksize: leaf size or node size depend on which level this block stand on.
struct extent_buffer *alloc_extent_buffer(struct extent_io_tree *tree,
u64 bytenr, u32 blocksize)
Parameters:
map_tree:fs_infor->mapping_tree which maps chunk_root. Details in read one block.
rw:READ
logical: in this case eb->start = btrfs_super_chunk_root(disk_super) = block[3]
type:NULL
multi_ret: for returning.
Function:
Search map_lookup form fs_info->mapping_tree then map it into multi bio stripes
int __btrfs_map_block(struct btrfs_mapping_tree *map_tree, int rw, u64 logical, u64 *length,
u64 *type, struct btrfs_multi_bio **multi_ret, int mirror_num)
ret = btrfs_insert_dir_item(trans, ,
, ,
,
&location, , 0);
Parameters:
root:root->fs_info->tree_root
name:"default"
name_len:7
dir:btrfs_super_root_dir(&root->fs_info->super_copy)
That is root_dir_objectid = #define BTRFS_ROOT_TREE_DIR_OBJECTID 6ULL.
location:root->fs_info->fs_root->root_key
type:BTRFS_FT_DIR
index:0
Function:
int btrfs_insert_dir_item(struct btrfs_trans_handle *trans, struct btrfs_root *root,
const char *name, int name_len, u64 dir, struct btrfs_key *location, u8 type, u64 index)
Parameters:
__btrfs_cow_block(trans, root, buf, parent, parent_slot, cow_ret, search_start, 0);
int __btrfs_cow_block(struct btrfs_trans_handle *trans, struct btrfs_root *root,
struct extent_buffer *buf, struct extent_buffer *parent, int parent_slot,
struct extent_buffer **cow_ret, u64 search_start, u64 empty_size)