anon_inode_getfd & anon_inode_getfile
creates a new file instance by hooking it up to an anonymous inode,
and a dentry that describe the "class" of the file
通过将 "新文件实例"(file结构体) 连接到 "匿名inode" 和 "描述文件“类”的dentry" 来 创建新文件实例
Creates a new file by hooking it on a single inode.
This is useful for files that do not need to have a full-fledged inode in order to operate correctly.
通过将新文件挂接到"单个索引节点"(anon_inode_inode)来创建新文件。
这对于不需要 "完整inode" 才能正确运行的文件非常有用。
All the files created with anon_inode_getxxx() will share a single inode,
hence saving memory and avoiding code duplication for the file/inode/dentry setup.
使用anon_inode_getxxx()创建的所有文件将共享一个inode(anon_inode_inode)
从而 "节省内存" 并 避免 代码("file/inode/dentry" 设置代码)重复。
kvm 中使用了 "匿名inode系统" 的 API
anon_inode_getfile
anon_inode_getfd // anon_inode_getfd 封装了anon_inode_getfile
fs/anon_inodes.c
anon_inode_getfile
anon_inode_getfd
anon_inode_init
anon_inode_mnt = kern_mount(&anon_inode_fs_type);
anon_inode_inode = alloc_anon_inode(anon_inode_mnt->mnt_sb); // 这个是干嘛用的?
// 整个过程中没有 register filesystem , 可见 anon 是给 内核用的
anon_inode_getfile // Returns the newly created file
ihold(anon_inode_inode);
file = alloc_file_pseudo(anon_inode_inode, anon_inode_mnt, name, flags & (O_ACCMODE | O_NONBLOCK), fops);
anon_inode_getfd // Returns new descriptor
anon_inode_getfile(name, fops, priv, flags);
ihold(anon_inode_inode);
file = alloc_file_pseudo(anon_inode_inode, anon_inode_mnt, name, flags & (O_ACCMODE | O_NONBLOCK), fops);
fd_install(fd, file);
匿名inode 中的匿名的含义
一般文件, 有inode 就会有 dentry
但是 匿名inode 不对应 dentry , 即 你在 文件系统中 用 find 找不到 该 文件
匿名 inode 对应 file 结构体
为什么 dentry 可以 缺失
一个 inode 上可以挂多个 dentry ,一个 dentry 只能属于一个 inode 。
dentry是inode的一个路径马甲
inode 信息有两种
一种存在于dentry(路径信息)
一种存在于inode(文件信息)
如果我们省略(不需要)其 路径信息, 那么就是 匿名inode
不是没有dentry , 而是 "描述文件“类”的dentry" // TODO
struct file 的 f_path 成员 // struct path
struct path 的 dentry
path.dentry = d_alloc_pseudo(mnt->mnt_sb, &this);
struct dentry *dentry = __d_alloc(sb, name);
dentry = kmem_cache_alloc(dentry_cache, GFP_KERNEL);
dentry->d_iname[DNAME_INLINE_LEN-1] = 0;
memcpy(dname, name->name, name->len);
smp_store_release(&dentry->d_name.name, dname);
匿名文件的name
root@ubuntu:~/temp# ll /proc/5398/fd
lr-x- 1 x x 64 Aug 4 9:9 8 -> anon_inode:inotify
lrwx- 1 x x 64 Aug 4 9:9 4 -> anon_inode:[eventpoll]
lrwx- 1 x x 64 Aug 4 9:9 5 -> anon_inode:[signalfd]
lrwx- 1 x x 64 Aug 4 9:9 7 -> anon_inode:[timerfd]
lrwx- 1 x x 64 Aug 4 9:9 9 -> anon_inode:[eventpoll]
lr-x-- 1 x x 64 Aug 24 09:39 10 -> /proc/5398/mountinfo
lr-x-- 1 x x 64 Aug 24 09:39 12 -> /proc/swaps
匿名文件的作用
需要在用户空间提供 文件句柄,但不需要提供 文件
匿名文件消费者
userfaultfd 系统调用
// 一些原本为内核处理的过程,出现了用户态的实现,为了提升开发灵活性
// http://blog.jcix.top/2018-10-01/userfaultfd_intro/
signalfd
https://www.modb.pro/db/103028
eventfd
https://www.modb.pro/db/88708
timerfd
https://www.modb.pro/db/100208
fanotify_user
inotify_user
eventpoll
https://www.modb.pro/db/88709
io_uring
kvm
百检网秉承“客户至上,服务为先,精诚合作,以人为本”的经营理念,始终站在用户的角度解决问题,为客户提供“一站购物式”的新奇检测体验,打开网站,像挑选商品一样简单,方便。打破行业信息壁垒,建构消费和检测机构之间高效的沟通平台