c - 为什么挂载结构有两个挂载点字段?

标签 c linux linux-kernel filesystems

我试图了解 Linux 文件系统的工作原理。 struct mountmnt_mountpoint 字段,它指向挂载点目录并用于路径查找。

struct mount {
    /*...*/
    struct dentry *mnt_mountpoint;
    /*...*/
    struct mountpoint *mnt_mp;
    /*...*/
} 

此时我不明白第二个挂载点字段的用途是什么?它指向 mountpoint 结构,而该结构又指向另一个 mountpoint 目录 m_dentry

struct mountpoint {
    struct hlist_node m_hash;
    struct dentry *m_dentry;
    struct hlist_head m_list;
    int m_count;
};

最佳答案

We also have struct mountpoint in the picture. Once upon a time it used to be a part of struct dentry - the list of all mounts on given mountpoint. Since it doesn't make sense to bloat every dentry for the sake of a very small fraction that will ever be anyone's mountpoints, that thing got separated.

What we have is

  • mark in dentry flags (DCACHE_MOUNTED) set for dentries that are currently mountpoints
  • for each of those we have a struct mountpoint instance (exactly one for each of those dentries).

https://lwn.net/Articles/793073/

不是 struct dentry 有一个列表指针,所有的挂载点都存储在一个哈希表中。 m_dentry字段用于区分落入同一哈希桶的不同挂载点。

我想 struct mount 持有对 struct mountpoint 的引用,主要用于清理。 IE。当 struct mount 被销毁时,我们调用 put_mountpoint(mnt_mp)m_count 递减,如果它达到零,挂载点将被销毁。

关于c - 为什么挂载结构有两个挂载点字段?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57361052/

相关文章:

c - 用链表实现的任意索引处的序列插入

c - Objcopy --writable-text 没有使 elf 二进制文本部分可写?

c - 内核模块中缺少键盘中断

c - "Variable"C 中的变量名

c++ - 在隐式障碍处等待 OpenMP 任务完成?

linux - 使用 Sudo 命令时,单行中的多个命令不起作用

linux - httpd : Could not reliably determine the server's fully qualified domain name, 使用 127.0.0.1 作为 ServerName

linux - 如何为 RHEL 6 找到 libstdc++.so.6 : that contain GLIBCXX_3. 4.19?

windows - 故意使内核崩溃

linux-kernel - 旧内核模块在重启后仍然存在