cephfs linux kernel client针对superblock操作流程的示例分析

58次阅读
没有评论

共计 3991 个字符,预计需要花费 10 分钟才能阅读完成。

这篇文章给大家分享的是有关 cephfs linux kernel client 针对 superblock 操作流程的示例分析的内容。丸趣 TV 小编觉得挺实用的,因此分享给大家做个参考,一起跟随丸趣 TV 小编过来看看吧。

init_caches()
  初始化如下几个 cache:
    ceph_inode_cachep
    ceph_cap_cachep
    ceph_cap_flush_cachep
    ceph_dentry_cachep
    ceph_file_cachep
    cephfs cache 

ceph_mount()
|__解析 mount options
|__创建 fs client,即:struct ceph_fs_client
|__创建 mds client 且设置 fs client 和 mds client 之间的对应关系
|__得到 superblock 且使用 ceph_set_super() 函数初始化
|__调用 ceph_real_mount() 函数来执行实际的 mount 操作

ceph_real_mount()
|__若 superblock 中对应的 s_boot 为空
  |__调用__ceph_open_session() 函数创建 client 到 mds 的 session 信息
  |__调用 open_root_dentry() 函数得到 cephfs 的 root dentry 信息
  |__将 root dentry 写入到 superblock 中的 s_boot 中
|__若 mount options 中没有 server path 内容
  |__设置当前 root 为 supberblock 对应的 s_root
  |__调用 dget(root) 函数得到 root 的 dentry 信息
|__若 mount options 中有 server path 内容
  |__调用 open_root_dentry() 得到 server path 指定的 root dentry 信息
|__设置 mount state 为 CEPH_MOUNT_MOUNTED

使用 ceph_set_super()函数初始化 superblock 时通过设置如下内容来设置对 superblock 的操作:
s- s_xattr = ceph_xattr_handlers    处理扩展属性的
s- s_op = ceph_super_ops      处理针对 superblock 正常操作的
s- s_export_op = ceph_export_ops    处理针对 superblock 的 export 操作的

ceph_super_ops 的类型是 struct super_operations,其中包含了对 superblock 操作的所有回调函数集合。
ceph_alloc_inode()    该函数用于分配 inode
|__从内核 cache 中得到 ceph inode 信息,即:struct ceph_inode_info 
|__初始化 struct ceph_inode_info
  |__设置了针对 inode 的 writeback 的内核线程 ceph_writeback_work
  |__设置了针对 inode 的 invalidate 的内核线程 ceph_invalidate_work
  |__设置了针对 inode 的 vmtruncate 的内核线程 ceph_vmtruncate_work
|__返回 struct inode 信息

ceph_destroy_inode(struct inode *inode)
|__调用 ceph_fscache_unregister_inode_cookie()函数将 inode 从 fscache 中清除掉
|__调用 ceph_queue_caps_release() 函数将 ceph_inode_info 中所有 caps 删除掉
|__若 ceph_inode_info 中包含 snap realm 信息
  |__调用 ceph_put_snap_realm() 释放 snap realm 
|__释放 ceph_inode_info 中的 fragtree 信息
|__调用__ceph_destroy_xattrs() 函数释放 ceph_inode_info 中所有的 xattrs 信息
|__调用 ceph_put_string() 函数释放 ceph_inode_info 中 layout 的 pool_ns 信息

ceph_write_inode(struct inode *inode, struct writeback_control *wbc)
|__调用 try_flush_caps()函数将 ceph_inode_info 中所有 dirty caps 刷回到 mds 集群中

ceph_evict_inode(struct inode *inode)
|__调用 ceph_sync_write_wait()函数将 ceph_inode_info 中所有 i_unsafe_writes 链表上的请求同步到 ceph 集群
|__调用 truncate_inode_pages_final() 函数将 inode 所占用的 pages 都释放掉
|__调用 clear_inode() 清除 inode 信息

ceph_sync_fs(struct super_block *sb, int wait)
|__从 superblock 中得到 struct ceph_fs_client 信息
|__调用 ceph_osdc_sync() 函数将所有 osdc 连接的 osds 上的所有 struct ceph_osd_request 请求同步到 ceph 集群
|__调用 ceph_mdsc_sync() 函数将 ceph_inode_info 中所有 dirty caps 刷回到 mds 集群中

ceph_put_super(struct super_block *s)
|__调用 ceph_mdsc_close_sessions()函数来关闭所有的 mds sessions 
 
ceph_show_options(struct seq_file *m, struct dentry *root)
|__显示所有的 mount options 在 /proc/mounts 下

ceph_statfs(struct dentry *dentry, struct kstatfs *buf)
|__根据参数 dentry 得到 struct ceph_fs_client 信息,即:fsc=ceph_inode_to_client()
|__通过 struct ceph_fs_client 得到 struct ceph_monmap 信息
|__通过调用 ceph_monc_do_statfs() 从 monitor 处得到所有的 stats 信息
|__将从 monitor 处得到的 stats 信息格式化输出到 buf 中

ceph_umount_begin(struct super_block *sb)
|__通过 superblock 得到 struct ceph_fs_client 信息
|__调用 ceph_mdsc_force_umount() 函数执行强制 umount 操作
  |__查询到所有的 mds sessions 并且调用__close_session() 函数来关闭 session
  |__调用 tick_requests()函数将未发送出去的 request 发送到其他 mds 进程
|__调用__wake_requests() 函数将 mdsc- waiting_for_map 上的请求发送到其他 mds 进程上

ceph_xattr_handlers 的类型是 struct xattr_handler,其中包含了所有对 inode 的 xattr 的操作。
ceph_get_xattr_handler(struct xattr_handler *handler, struct dentry *dentry, struct inode *inode, char *name, void *value, size_t size)
|__调用 ceph_is_valid_xattr()函数检查 name 是否是有效的属性名
|__调用__ceph_getxattr() 函数得到属性名 name 对应的属性值 value 以及属性值 value 的大小 size
  |__检查 name 是否是 vxattr,若是则直接从 vxattr 处获取 name 对应的 value 值
  |__调用 ceph_do_getattr() 函数从 mds 集群中获取 inode 对应的 xattrs 值
  |__调用__build_xattrs() 函数创建 xattrs 数据结构
  |__调用__get_xattr() 函数从 xattrs 中得到 name 对应的 value
 
ceph_set_xattr_handler(struct xattr_handler *handler, struct dentry *dentry, struct inode *inode, char *name, void *value, size_t size, int flags)
|__调用 ceph_is_valid_xattr()函数检查 name 是否是有效的属性名
|__调用__ceph_setxattr() 函数设置属性名 name 和属性值 value 并同步到 mds 集群中
  |__调用__build_xattrs() 函数得到 xattrs 数据结构
  |__调用__set_xattr() 函数将属性名 name 和属性值 value 写入到 ceph_inode_info 的 xattrs 对应的红黑树里
  |__调用__ceph_mark_dirty_caps() 函数设置 caps dirty
|__调用 ceph_sync_setxattr()函数将 inode 对应的属性名 name 和属性值 value 同步到 mds 集群
 

感谢各位的阅读!关于“cephfs linux kernel client 针对 superblock 操作流程的示例分析”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,让大家可以学到更多知识,如果觉得文章不错,可以把它分享出去让更多的人看到吧!

正文完
 
丸趣
版权声明:本站原创文章,由 丸趣 2023-08-16发表,共计3991字。
转载说明:除特殊说明外本站除技术相关以外文章皆由网络搜集发布,转载请注明出处。
评论(没有评论)