温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

cephfs kernel client针对dir的file_operations操作代码

发布时间:2021-12-17 10:00:53 来源:亿速云 阅读:166 作者:小新 栏目:云计算

这篇文章给大家分享的是有关cephfs kernel client针对dir的file_operations操作代码的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。

cephfs kernel client针对dir的file_operations操作

const struct file_operations ceph_dir_fops = {

        .read = ceph_read_dir,

        .iterate = ceph_readdir,

        .llseek = ceph_dir_llseek,

        .open = ceph_open,

        .release = ceph_release,

        .unlocked_ioctl = ceph_ioctl,

        .fsync = ceph_fsync,

};

ceph_read_dir(struct file *file, char __user *buf, size_t size, loff_t *ppos)    只有在mount时带有参数-o dirstat时该函数才有效

|__调用ceph_test_mount_opt()函数检查mount options中是否包含DIRSTAT,若不包含则直接返回

|__若struct ceph_file_info中的dir_info为空

    |__调用kmalloc()函数为dir_info分配空间

    |__使用snprintf()函数向dir_info的内存空间进行格式化输出

|__调用copy_to_user()函数将dir_info中的内容复制到用户态空间buf中

ceph_readdir(struct file *file, struct dir_context *ctx)

|__调用dir_emit()函数向外发布”.”和”..”信息

|__若mount options中包含DCACHE则说明应该尽可能的从dcache中读取dir的信息

    |__调用__dcache_readdir()函数从dcache中读取dir

    |__返回值不等于EAGAIN

        |__直接返回

|__调用need_send_readdir()函数检查是否应该从集群中读取dir的内容

    |__得到操作码op=CEPH_MDS_OP_LSSNAP或者CEPH_MDS_OP_READDIR

    |__调用ceph_mdsc_create_request()函数创建mds请求

    |__调用ceph_alloc_readdir_reply_buffer()函数为从集群中读取到的dir内容分配内存空间

    |__调用ceph_mdsc_do_request()函数将请求同步发送给mds进程

|__遍历struct ceph_file_info->last_readdir->r_reply_info->dir_nr

    |__调用dir_emit()函数向外发布dir信息

ceph_dir_llseek(struct file *file, loff_t offset, int whence)

|__根据whence的不同值更新offset的值

|__若offset>=0

    |__调用need_reset_readdir()函数检查是否需要reset readdir

        |__调用reset_readdir()函数

    |__调整file->f_pos值为offset值

ceph_open(struct inode *inode, struct file *file)    该函数在打开文件时被调用

|__调用prepare_open_request()函数来创建ceph_mds_request请求

|__调用ceph_mdsc_do_request()函数将ceph_mds_request请求同步的发送给mds进程

|__调用ceph_init_file()函数创建ceph_file_info数据结构且将该数据结构放入到file->private_data中

ceph_release(struct inode *inode, struct file *file)    该函数在关闭文件时被调用

|__调用ceph_put_fmode()函数减少打开文件的引用次数,若引用次数为0,则从本地cache中删除该文件

ceph_ioctl(struct file *file, unsigned int cmd, unsigned long arg)

|__根据cmd的值做不同的处理

    |__cmd==CEPH_IOC_GET_LAYOUT

        |__ceph_ioctl_get_layout()

            |__ceph_do_getattr(CEPH_STAT_CAP_LAYOUT)从mds集群中读取file对应的inode的layout信息到ceph_inode_info的i_layout中

            |__将i_layout信息写入到struct ceph_ioctl_layout数据结构中且通过copy_to_user()函数将数据返回给用户态

    |__cmd==CEPH_IOC_SET_LAYOUT

        |__ceph_ioctl_set_layout()

            |__调用copy_from_user()函数将新的layout信息从用户态复制到内核态

            |__调用ceph_do_getattr()函数从mds集群中读取当前的layout信息

            |__调用__validate_layout()函数检查新设置的layout是否有效

            |__调用ceph_mdsc_create_request()函数创建request请求

            |__调用ceph_mdsc_do_request()函数同步的发送request请求到mds集群

    |__cmd==CEPH_IOC_SET_LAYOUT_POLICY

        |__ceph_ioctl_set_layout_policy()

            |__调用copy_from_user()函数将新的layout信息从用户态复制到内核态

            |__调用__validate_layout()函数检查新设置的layout是否有效

            |__调用ceph_mdsc_create_request()函数创建request请求

            |__调用ceph_mdsc_do_request()函数同步的发送request请求到mds集群

    |__cmd==CEPH_IOC_GET_DATALOC                计算data所在的ceph集群中的位置信息

        |__ceph_ioctl_get_dataloc()

            |__调用copy_from_user()函数将ceph_ioctl_dataloc信息复制到内核态

            |__调用ceph_calc_file_object_mapping()函数计算ceph_ioctl_dataloc信息中指定文件所在的oid等信息

            |__调用ceph_object_locator_to_pg()函数计算出oid所在的pg信息

            |__调用ceph_pg_to_acting_primary()函数计算出pg所在的主osd信息

            |__调用copy_to_user()函数将计算出来的信息发送回给用户态

    |__cmd==CEPH_IOC_LAZYIO                        设置LAZYIO标识

        |__ceph_ioctl_lazyio()

            |__ 判断struct ceph_file_info中的fmode是否未设置CEPH_FILE_MODE_LAZY

                |__设置struct ceph_file_info中的fmode拥有CEPH_FILE_MODE_LAZY标识

                |__更新ceph_inode_info中的i_nr_by_mode数组

                |__调用ceph_check_caps()函数更新caps

    |__cmd==CEPH_IOC_SYNCIO

        |__ceph_ioctl_syncio()

            |__设置struct ceph_file_info结构中的flags的CEPH_F_SYNC位

ceph_fsync(struct file *file, loff_t start , loff_t end, int datasync)

|__调用ceph_sync_write_wait()函数等待inode上所有未完成的osd请求执行完毕

|__调用try_flush_caps()函数将所有dirty的caps刷回到mds

|__调用unsafe_request_wait()函数等待inode上所有针对mds请求执行完毕

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

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI