QQ登录

只需一步,快速开始

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 2125|回复: 0

关于sysfs的几个问题

[复制链接]
发表于 2007-12-18 17:28:57 | 显示全部楼层 |阅读模式
最近在看sysfs相关的代码,但有些地方不是很清楚,下面是发到linux-kernel的两封邮件,但一直没有回复(难道我做什么不礼貌了?),也过来这边请教一下大家。
Hi,
  I found the initialization code of the sysfs in version 2.6.22:

int __init sysfs_init(void)
{
   int err = -ENOMEM;

   sysfs_dir_cachep = kmem_cache_create("sysfs_dir_cache",
                         sizeof(struct sysfs_dirent),
                         0, 0, NULL, NULL);
   if (!sysfs_dir_cachep)
       goto out;

   err = register_filesystem(&sysfs_fs_type);
   if (!err) {
       sysfs_mount = kern_mount(&sysfs_fs_type);
........

my questions are:
1. Is some initializing script responsible for mounting the sysfs? If
so, why do we call kern_mount.
2. I looked into the kern_mount code, the routine seems to get the
super block and the inode object for the sysfs, but when setting the
root, I got:
       root = d_alloc_root(inode);
       if (!root) {
               pr_debug("%s: could not get root dentry!\n",__FUNCTION__);
               iput(inode);
               return -ENOMEM;
       }
       root->d_fsdata = &sysfs_root;
       sb->s_root = root;

and the s_root is then passed to the mnt_root and the mnt_mountpoint:

int simple_set_mnt(struct vfsmount *mnt, struct super_block *sb)
{
       mnt->mnt_sb = sb;
       mnt->mnt_root = dget(sb->s_root);
       return 0;
}

in vfs_kern_mount:
.......
       mnt->mnt_mountpoint = mnt->mnt_root;
       mnt->mnt_parent = mnt;
       up_write(&mnt->mnt_sb->s_umount);
.......

So, does this means we get the mount point from d_alloc_root(inode),
but this doesn't look like the truth. d_alloc_root seems to allocate a
dentry for the root, is that true? If so, why for the root?
Does the s_root stand for the root of the file system, so it should
always be "/", but this is different from root file system? But what
about the mnt_moountpoint, how does the kernel store the path (rooted
from the  root file system)?

Thanks

Hi all,
   Currently, I'm studying the code of the sysfs. But I got the
following questions:

1. What is the d_alloc_root used for? Actually, the question should
be: why we have to call d_alloc_root. I think the root already has its
dentry, why we have to allocate another while we mounting a file
system?

2. Why we call d_alloc_root to allocate a dentry for the mount point
while the usual mount point of sysfs is defined by the user (something
like /sysfs but not /). See below:
       root = d_alloc_root(inode);
       if (!root) {
               pr_debug("%s: could not get root dentry!\n",__FUNCTION__);
               iput(inode);
               return -ENOMEM;
       }
       root->d_fsdata = &sysfs_root;
       sb->s_root = root;

does this means settting the sysfs' mount point to "/" but not "/sysfs".

Thanks.

先谢谢大家
您需要登录后才可以回帖 登录 | 注册

本版积分规则

GMT+8, 2024-11-25 04:09 , Processed in 0.050933 second(s), 16 queries .

© 2021 Powered by Discuz! X3.5.

快速回复 返回顶部 返回列表