Skip to contentSkip to conversation

About mounting the sysfs

DISCUSSION wit 2 participants 3 messages Dec 18, 2007

lore
Share & tools
lore

wit

author
#0 lore raw

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

#1 lore raw
Quoted 5 lines · wit

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.

Quoted 6 lines

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.

Quoted 11 lines

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

author
#2 lore raw

2007/12/18, Jan Engelhardt <[email protected]>:

Quoted 9 lines · wit
Quoted 5 lines

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.

Quoted 10 lines
Quoted 7 lines

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?

Quoted 13 lines
Quoted 12 lines

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