您的位置:首页 > 理论基础 > 计算机网络

网络子系统1_socket文件系统相关的初始化

2013-09-26 21:03 411 查看
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有关的文件系统部分初始化完成
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  内核 网络 socket kernel