file_operations

cephfs kernel client针对打开文件的操作

浪子不回头ぞ 提交于 2019-12-07 14:02:52
针对打开文件的操作主要体现在struct file_operations数据结构中。在cephfs kernel client中具体实现如下: const struct file_operations ceph_file_fops = { .open = ceph_open, .release = ceph_release, .llseek = ceph_llseek, .read_iter = ceph_read_iter, .write_iter = ceph_write_iter, .mmap = ceph_mmap, .fsync = ceph_fsync, .lock = ceph_lock, .flock = ceph_flock, .splice_read = generic_file_splice_read, .splice_write = iter_file_splice_write, .unlocked_ioctl = ceph_ioctl, .compat_ioctl = ceph_ioctl, .fallocate = ceph_fallocate, }; ceph_open(struct inode *inode, struct file *file) 该函数在打开文件时被调用 |__调用prepare_open_request()函数来创建ceph

cephfs kernel client针对dir的file_operations操作

╄→尐↘猪︶ㄣ 提交于 2019-12-06 23:13:23
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