mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* About mounting the sysfs
@ 2007-12-18  7:10 wit
  2007-12-18 12:39 ` Jan Engelhardt
  0 siblings, 1 reply; 4+ messages in thread
From: wit @ 2007-12-18  7:10 UTC (permalink / raw)
  To: linux-kernel

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.

--Zhanhua

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: About mounting the sysfs
  2007-12-18  7:10 About mounting the sysfs wit
@ 2007-12-18 12:39 ` Jan Engelhardt
  2007-12-18 15:05   ` Zhanhua
  0 siblings, 1 reply; 4+ messages in thread
From: Jan Engelhardt @ 2007-12-18 12:39 UTC (permalink / raw)
  To: wit; +Cc: linux-kernel


On Dec 18 2007 15:10, wit wrote:
>
>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,

It does not.

>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 /).

/sys is a dentry that belongs to the / vfsmount, but we need a
/ that belongs to the <whatever you are going to mount> vfsmount.

> 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".

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: About mounting the sysfs
  2007-12-18 12:39 ` Jan Engelhardt
@ 2007-12-18 15:05   ` Zhanhua
  0 siblings, 0 replies; 4+ messages in thread
From: Zhanhua @ 2007-12-18 15:05 UTC (permalink / raw)
  To: Jan Engelhardt; +Cc: linux-kernel

2007/12/18, Jan Engelhardt <jengelh@computergmbh.de>:
>
> On Dec 18 2007 15:10, wit wrote:
> >
> >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,
>
> It does not.
There's no dentry for the "/"? I mean the rootfs.

>
> >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 /).
>
> /sys is a dentry that belongs to the / vfsmount, but we need a
> / that belongs to the <whatever you are going to mount> vfsmount.

Why we need such a vfsmount (for the "/", not the rootfs)? And where
we store the mount point info (path) when mount_root, s_root and the
mnt_mountpoint are all points to the "/" which is allocated by
d_alloc_root? Or do we have to store such info? Why?

>
> > 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".
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* about mounting the sysfs
@ 2007-12-05 15:02 wit
  0 siblings, 0 replies; 4+ messages in thread
From: wit @ 2007-12-05 15:02 UTC (permalink / raw)
  To: 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

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2007-12-18 15:05 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-12-18  7:10 About mounting the sysfs wit
2007-12-18 12:39 ` Jan Engelhardt
2007-12-18 15:05   ` Zhanhua
  -- strict thread matches above, loose matches on Subject: below --
2007-12-05 15:02 about " wit

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®