Skip to content

Commit 6ebaa1d

Browse files
committed
Update node.c
1 parent cc6a2ad commit 6ebaa1d

File tree

1 file changed

+109
-26
lines changed

1 file changed

+109
-26
lines changed

fs/hmfs/node.c

Lines changed: 109 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
static struct kmem_cache *nat_entry_slab;
1010

1111
const struct address_space_operations hmfs_nat_aops;
12-
12+
/**
13+
* 为@inode增加@count个blocks(修改元数据,未实现分配)
14+
*/
1315
static inline bool inc_valid_node_count(struct hmfs_sb_info *sbi,
1416
struct inode *inode, int count, bool force)
1517
{
@@ -36,7 +38,9 @@ static inline bool inc_valid_node_count(struct hmfs_sb_info *sbi,
3638

3739
return true;
3840
}
39-
41+
/**
42+
* 减少@inode的@count个blocks(修改元数据)
43+
*/
4044
static inline void dec_valid_node_count(struct hmfs_sb_info *sbi,
4145
struct inode *inode, int count, bool dec_valid)
4246
{
@@ -49,7 +53,9 @@ static inline void dec_valid_node_count(struct hmfs_sb_info *sbi,
4953
cm_i->valid_block_count -= count;
5054
unlock_cm(cm_i);
5155
}
52-
56+
/**
57+
* 返回系统最大可能的NODE_ID
58+
*/
5359
static nid_t hmfs_max_nid(struct hmfs_sb_info *sbi)
5460
{
5561
nid_t nid = 1;
@@ -76,6 +82,13 @@ void set_new_dnode(struct dnode_of_data *dn, struct inode *inode,
7682
/**
7783
* The maximum depth is 4.
7884
*/
85+
/**
86+
* 寻找@block在inode中的索引路径,即从inode找到@block需经过的的NODE。
87+
* @offset 指针相对于节点起始地址的便宜
88+
* @noffset 指针在所有指针中的便宜
89+
*/
90+
91+
7992
int get_node_path(long block, int offset[4], unsigned int noffset[4])
8093
{
8194
const long direct_index = NORMAL_ADDRS_PER_INODE;
@@ -158,12 +171,16 @@ int get_node_path(long block, int offset[4], unsigned int noffset[4])
158171
got:
159172
return level;
160173
}
161-
174+
/**
175+
* 返回@n为NODE_ID的NAT_ENTRYT在内存中的地址
176+
*/
162177
static struct nat_entry *__lookup_nat_cache(struct hmfs_nm_info *nm_i, nid_t n)
163178
{
164179
return radix_tree_lookup(&nm_i->nat_root, n);
165180
}
166-
181+
/**
182+
* NODE_MANAGER销毁
183+
*/
167184
void destroy_node_manager(struct hmfs_sb_info *sbi)
168185
{
169186
struct hmfs_nm_info *nm_i = NM_I(sbi);
@@ -192,7 +209,9 @@ void destroy_node_manager(struct hmfs_sb_info *sbi)
192209
kfree(nm_i->free_nids);
193210
kfree(nm_i);
194211
}
195-
212+
/**
213+
* 初始化node_manager
214+
*/
196215
static int init_node_manager(struct hmfs_sb_info *sbi)
197216
{
198217
struct hmfs_nm_info *nm_i = NM_I(sbi);
@@ -218,7 +237,10 @@ static int init_node_manager(struct hmfs_sb_info *sbi)
218237
mutex_init(&nm_i->build_lock);
219238
return 0;
220239
}
221-
240+
/**
241+
* 空闲node分配失败恢复 分
242+
* @nid 分配失败的节点ID
243+
*/
222244
void alloc_nid_failed(struct hmfs_sb_info *sbi, nid_t nid)
223245
{
224246
struct hmfs_nm_info *nm_i = NM_I(sbi);
@@ -233,7 +255,10 @@ void alloc_nid_failed(struct hmfs_sb_info *sbi, nid_t nid)
233255
nm_i->fcnt++;
234256
unlock_free_nid(nm_i);
235257
}
236-
258+
/**
259+
* 在NAT树中加入nat_entry
260+
* @nid 加入nat_entry的节点ID
261+
*/
237262
static struct nat_entry *grab_nat_entry(struct hmfs_nm_info *nm_i, nid_t nid)
238263
{
239264
struct nat_entry *new;
@@ -251,7 +276,9 @@ static struct nat_entry *grab_nat_entry(struct hmfs_nm_info *nm_i, nid_t nid)
251276
nm_i->nat_cnt++;
252277
return new;
253278
}
254-
279+
/**
280+
* 删除dnode
281+
*/
255282
void truncate_node(struct dnode_of_data *dn)
256283
{
257284
struct hmfs_sb_info *sbi = HMFS_I_SB(dn->inode);
@@ -282,7 +309,9 @@ void truncate_node(struct dnode_of_data *dn)
282309
invalidate:
283310
dn->node_block = NULL;
284311
}
285-
312+
/**
313+
* 删除dnode及其索引的data node
314+
*/
286315
static int truncate_dnode(struct dnode_of_data *dn)
287316
{
288317
struct hmfs_sb_info *sbi = HMFS_I_SB(dn->inode);
@@ -308,6 +337,10 @@ static int truncate_dnode(struct dnode_of_data *dn)
308337
* We're about to truncate the whole nodes. Therefore, we don't need to COW
309338
* the old node. We just mark the its nid slot in parent node to be 0
310339
*/
340+
/**
341+
* 层层释放Indirect node
342+
*/
343+
311344
static int truncate_nodes(struct dnode_of_data *dn, unsigned int nofs, int ofs,
312345
int depth)
313346
{
@@ -379,6 +412,9 @@ static int truncate_nodes(struct dnode_of_data *dn, unsigned int nofs, int ofs,
379412
}
380413

381414
/* return address of node in historic checkpoint */
415+
/**
416+
* 获取特定CP版本的@nid的hmfs_node
417+
*/
382418
struct hmfs_node *__get_node(struct hmfs_sb_info *sbi,
383419
struct checkpoint_info *cp_i, nid_t nid)
384420
{
@@ -395,7 +431,9 @@ struct hmfs_node *__get_node(struct hmfs_sb_info *sbi,
395431

396432
return ADDR(sbi, node_addr);
397433
}
398-
434+
/**
435+
* 释放inode中block之后的块
436+
*/
399437
static int truncate_partial_nodes(struct dnode_of_data *dn,
400438
struct hmfs_inode *hi, int *offset, int depth)
401439
{
@@ -460,7 +498,9 @@ static int truncate_partial_nodes(struct dnode_of_data *dn,
460498
fail:
461499
return err;
462500
}
463-
501+
/**
502+
* 删除@inode中@from之后的block
503+
*/
464504
int truncate_inode_blocks(struct inode *inode, pgoff_t from)
465505
{
466506
struct hmfs_sb_info *sbi = HMFS_I_SB(inode);
@@ -538,7 +578,9 @@ int truncate_inode_blocks(struct inode *inode, pgoff_t from)
538578
fail:
539579
return err > 0 ? 0 : err;
540580
}
541-
581+
/**
582+
* 更新内存中@nid的nat_entry的块地址为@blk_addr
583+
*/
542584
void gc_update_nat_entry(struct hmfs_nm_info *nm_i, nid_t nid,
543585
block_t blk_addr)
544586
{
@@ -552,7 +594,9 @@ void gc_update_nat_entry(struct hmfs_nm_info *nm_i, nid_t nid,
552594

553595
unlock_write_nat(nm_i);
554596
}
555-
597+
/**
598+
* 更新@nid的nat_entry,检查是否为脏页
599+
*/
556600
void update_nat_entry(struct hmfs_nm_info *nm_i, nid_t nid, nid_t ino,
557601
block_t blk_addr, bool dirty)
558602
{
@@ -596,6 +640,9 @@ void update_nat_entry(struct hmfs_nm_info *nm_i, nid_t nid, nid_t ino,
596640
* return node address in NVM by nid, would not allocate
597641
* new node
598642
*/
643+
/**
644+
* 返回Node ID为@nid的节点NVM地址
645+
*/
599646
void *get_node(struct hmfs_sb_info *sbi, nid_t nid)
600647
{
601648
struct node_info ni;
@@ -619,7 +666,9 @@ void *get_node(struct hmfs_sb_info *sbi, nid_t nid)
619666

620667
return ADDR(sbi, ni.blk_addr);
621668
}
622-
669+
/**
670+
* 为新NODE设置summary_entry
671+
*/
623672
static void setup_summary_of_new_node(struct hmfs_sb_info *sbi,
624673
block_t new_node_addr, block_t src_addr, nid_t ino,
625674
unsigned int ofs_in_node, char sum_type)
@@ -631,7 +680,9 @@ static void setup_summary_of_new_node(struct hmfs_sb_info *sbi,
631680
make_summary_entry(dest_sum, ino, cm_i->new_version, ofs_in_node,
632681
sum_type);
633682
}
634-
683+
/**
684+
* 为@inode分配一个节点,Node ID为@nid ,返回节点地址 (COW)
685+
*/
635686
static struct hmfs_node *__alloc_new_node(struct hmfs_sb_info *sbi, nid_t nid,
636687
struct inode *inode, char sum_type, bool force)
637688
{
@@ -680,7 +731,9 @@ static struct hmfs_node *__alloc_new_node(struct hmfs_sb_info *sbi, nid_t nid,
680731

681732
return dest;
682733
}
683-
734+
/**
735+
* 分配一个块
736+
*/
684737
void *alloc_new_node(struct hmfs_sb_info *sbi, nid_t nid, struct inode *inode,
685738
char sum_type, bool force)
686739
{
@@ -703,7 +756,9 @@ void *alloc_new_node(struct hmfs_sb_info *sbi, nid_t nid, struct inode *inode,
703756
addr = alloc_free_node_block(sbi, true);
704757
return ADDR(sbi, addr);
705758
}
706-
759+
/**
760+
* 填充@nid的node_info @ni
761+
*/
707762
int get_node_info(struct hmfs_sb_info *sbi, nid_t nid, struct node_info *ni)
708763
{
709764
struct hmfs_nat_entry *ne_local;
@@ -729,14 +784,19 @@ int get_node_info(struct hmfs_sb_info *sbi, nid_t nid, struct node_info *ni)
729784
update_nat_entry(nm_i, nid, ni->ino, ni->blk_addr, false);
730785
return 0;
731786
}
732-
787+
/**
788+
* 将nid置为free (0,1有什么区别,可能不是空闲????)
789+
*/
733790
static void add_free_nid(struct hmfs_nm_info *nm_i, nid_t nid, u64 free,
734791
int *pos)
735792
{
736793
nm_i->free_nids[*pos].nid = make_free_nid(nid, free);
737794
}
738795

739796
/* Get free nid from journals of loaded checkpoint */
797+
/**
798+
* 用NAT_JOURNAL初始化NODE_MANAGER的free nid
799+
*/
740800
static void init_free_nids(struct hmfs_sb_info *sbi)
741801
{
742802
struct hmfs_cm_info *cm_i = CM_I(sbi);
@@ -764,6 +824,9 @@ static void init_free_nids(struct hmfs_sb_info *sbi)
764824
}
765825

766826
/* Check whether block_addr of nid in journal is NULL_ADDR */
827+
/**
828+
* 检查@NID是否可用 (???)
829+
*/
767830
static int is_valid_free_nid(struct hmfs_sb_info *sbi, nid_t nid)
768831
{
769832
struct hmfs_cm_info *cm_i = CM_I(sbi);
@@ -802,7 +865,9 @@ static int is_valid_free_nid(struct hmfs_sb_info *sbi, nid_t nid)
802865
check_value:
803866
return nid > HMFS_ROOT_INO;
804867
}
805-
868+
/**
869+
* 扫描一个nat block,将其中pos个未使用的nid放入未分配链表
870+
*/
806871
static nid_t scan_nat_block(struct hmfs_sb_info *sbi,
807872
struct hmfs_nat_block *nat_blk, nid_t start_nid, int *pos)
808873
{
@@ -831,6 +896,9 @@ static nid_t scan_nat_block(struct hmfs_sb_info *sbi,
831896
}
832897

833898
/* Scan free nid from dirty nat entries */
899+
/**
900+
* 脏NAT链表找@pos个 free nid
901+
*/
834902
static int scan_delete_nid(struct hmfs_sb_info *sbi, int *pos)
835903
{
836904
struct hmfs_nm_info *nm_i = NM_I(sbi);
@@ -864,7 +932,9 @@ static int scan_delete_nid(struct hmfs_sb_info *sbi, int *pos)
864932
unlock_write_nat(nm_i);
865933
return *pos;
866934
}
867-
935+
/**
936+
* 构造可用的fre nid链表
937+
*/
868938
static int build_free_nids(struct hmfs_sb_info *sbi)
869939
{
870940
struct hmfs_nm_info *nm_i = NM_I(sbi);
@@ -901,7 +971,9 @@ static int build_free_nids(struct hmfs_sb_info *sbi)
901971
nm_i->next_scan_nid = nid;
902972
return count;
903973
}
904-
974+
/**
975+
* 从free nid 链表分配nid
976+
*/
905977
bool alloc_nid(struct hmfs_sb_info *sbi, nid_t *nid)
906978
{
907979
struct hmfs_nm_info *nm_i = NM_I(sbi);
@@ -932,7 +1004,9 @@ bool alloc_nid(struct hmfs_sb_info *sbi, nid_t *nid)
9321004

9331005
goto retry;
9341006
}
935-
1007+
/**
1008+
* 创建node_manager的nat_entry slab缓存
1009+
*/
9361010
int create_node_manager_caches(void)
9371011
{
9381012
nat_entry_slab = hmfs_kmem_cache_create("hmfs_nat_entry",
@@ -942,13 +1016,18 @@ int create_node_manager_caches(void)
9421016

9431017
return 0;
9441018
}
945-
1019+
/**
1020+
* 销毁nat_entry slab缓存
1021+
*/
9461022
void destroy_node_manager_caches(void)
9471023
{
9481024
kmem_cache_destroy(nat_entry_slab);
9491025
}
9501026

9511027
/* get a nat/nat page from nat/nat in-NVM tree */
1028+
/**
1029+
* 返回树中第@order个节点地址
1030+
*/
9521031
static void *__get_nat_page(struct hmfs_sb_info *sbi, block_t cur_node_addr,
9531032
unsigned int order, unsigned char height)
9541033
{
@@ -970,7 +1049,9 @@ static void *__get_nat_page(struct hmfs_sb_info *sbi, block_t cur_node_addr,
9701049
return __get_nat_page(sbi, child_node_addr, order & ((1 << ofs) - 1),
9711050
height - 1);
9721051
}
973-
1052+
/**
1053+
* 返回cp版本@version中node id为@nid的NAT块地址
1054+
*/
9741055
struct hmfs_nat_block *get_nat_entry_block(struct hmfs_sb_info *sbi,
9751056
ver_t version, nid_t nid)
9761057
{
@@ -982,7 +1063,9 @@ struct hmfs_nat_block *get_nat_entry_block(struct hmfs_sb_info *sbi,
9821063
hmfs_bug_on(sbi, !cp_i);
9831064
return __get_nat_page(sbi, L_ADDR(sbi, nat_root), blk_id, nat_height);
9841065
}
985-
1066+
/**
1067+
* 返回cp版本@version中node id为@nid的hmfs_nat_entry地址
1068+
*/
9861069
struct hmfs_nat_entry *get_nat_entry(struct hmfs_sb_info *sbi,
9871070
ver_t version, nid_t nid)
9881071
{

0 commit comments

Comments
 (0)