閱讀790 返回首頁    go 阿裏雲 go 技術社區[雲棲]


網絡子係統1_socket文件係統相關的初始化

1.調用流程
start_kernel->rest_init->kernel_thread->init->do_basic_setup->do_initcalls->sock_init

//在do_basic_setup 中被調用
2.1 void __init sock_init(void)
{
	//socket SLAB初始化
	sk_init();

	//skb SLAB初始化
	skb_init();

	//socket FS初始化
	init_inodecache();
	//socket文件係統類型
	register_filesystem(&sock_fs_type);
	sock_mnt = kern_mount(&sock_fs_type);
	
}
//將此函數入口添加到extern initcall_t __initcall_start[], __initcall_end[]之間
core_initcall(sock_init);


2.2 void __init sk_init(void)
{
	//創建sock的SLAB cache
	sk_cachep = kmem_cache_create("sock", sizeof(struct sock), 0,
				      SLAB_HWCACHE_ALIGN, NULL, NULL);
	//下邊初始化一些閥值
	....
}

//socket 的file_system_type
3.1 static struct file_system_type sock_fs_type = {
	.name =		"sockfs",
	.get_sb =	sockfs_get_sb,
	.kill_sb =	kill_anon_super,
};
//填充超級塊的方法
3.2 static struct super_block *sockfs_get_sb(struct file_system_type *fs_type,
	int flags, const char *dev_name, void *data)
{
	//偽文件係統獲取sb的helper函數
	return get_sb_pseudo(fs_type, "socket:", &sockfs_ops, SOCKFS_MAGIC);
}

3.3 struct super_block *
get_sb_pseudo(struct file_system_type *fs_type, char *name,
	struct super_operations *ops, unsigned long magic)
{
	...
	//設置超級塊的函數指針
	s->s_op = ops ? ops : &default_ops;
	...
}

3.4 static struct super_operations sockfs_ops = {
	//分配,刪除inode的方法,通過在2.1中的inode cache分配
	.alloc_inode =	sock_alloc_inode,
	.destroy_inode = sock_destroy_inode,
	...
};
//至此,與socket有關的文件係統部分初始化完成

最後更新:2017-04-03 15:21:55

  上一篇:go 網絡子係統2_設備子係統相關的初始化
  下一篇:go Java麵向對象高級--抽象類的基本概念------abstract