作者 | 时间 | QQ技术交流群 |
---|---|---|
perrynzhou@gmail.com | 2022/08/20 | 672152841 |
vfs
层文件创建链路
vfs
层是在客户端执行创建创建,首先是经过内核的syscall
的open
调用,最后调用的是具体文件系统实现的
的dir->i_op->atomic_open
函数,这个函数是具体文件系统定义的。如下是vfs层
的简要函数的定制和执行路径。
// 定义了系统调用open
SYSCALL_DEFINE3(open, const char __user *, filename, int, flags, umode_t, mode)
{
return do_sys_open(AT_FDCWD, filename, flags, mode);
}
// open函数的具体执行syscall函数
long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
{
do_sys_openat2(dfd, filename, &how);
}
static long do_sys_openat2(int dfd, const char __user *filename,
struct open_how *how)
{
struct file *f = do_filp_open(dfd, tmp, &op);
}
// 返回内核返回的struct file,这个是每个进程的fd所指向的结构
struct file *do_filp_open(int dfd, struct filename *pathname,
const struct open_flags *op)
{
filp = path_openat(&nd, op, flags | LOOKUP_RCU);
}
// 文件查找
static struct file *path_openat(struct nameidata *nd,
const struct open_flags *op, unsigned flags)
{
const char *s = path_init(nd, flags);
while (!(error = link_path_walk(s, nd)) &&
(s = open_last_lookups(nd, file, op)) != NULL)
;
}
// 快速查找
static const char *open_last_lookups(struct nameidata *nd,
struct file *file, const struct open_flags *op)
{
lookup_open(nd, file, op, got_write);
}
// dentry的快速打开
static struct dentry *lookup_open(struct nameidata *nd, struct file *file,
const struct open_flags *op,
bool got_write)
{
dentry = atomic_open(nd, dentry, file, open_flag, mode);
}
// 在这里即使执行具体文件系统定义的atomic_open函数
static struct dentry *atomic_open(struct nameidata *nd, struct dentry *dentry,
struct file *file,
int open_flag, umode_t mode)
{
// ll_atomic_open
error = dir->i_op->atomic_open(dir, dentry, file,
open_to_namei_flags(open_flag), mode);
}
lustre
客户端
ll_atomic_open
入口函数
文件创建的过程的本质是在父目录的
inode
的数据块添加一个dentry
.在lustre中文件创建首先执行的是atomic_open
函数,lustre
文件系统和内核的vfs
衔接是通过inode_operations ll_dir_inode_operations
结构,这个是元数据的操作的函数结构体表其定义如下
文章转载自存储内核技术交流,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。