Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 8: The Virtual Filesystem


It’s worth taking a closer look atdo_new_mountbecause it is used so frequently. Its code flow diagram is
shown in Figure 8-6.


Initialize struct vfsmnt

Prevent identical mounts

do_new_mount

do_kern_mount

get_fs_type

vfs_kern_mount

type->get_sb

do_add_mount

graft_tree

attach_recursive_mnt

Figure 8-6: Code flow diagram fordo_new_mount.

do_new_mountsplits into two parts —do_kern_mountanddo_add_mount:


❑ The initial task ofdo_kern_mountis to find the matchingfile_system_typeinstance using
get_fs_type. The helper function scans the linked list of registered filesystems mentioned above
and returns the correct entry. If no matching filesystem is found, the routine automatically tries
to load the corresponding module (see Chapter 7).
After this,vfs_kern_mountinvokes the filesystem-specificget_sbfunction to read the associated
superblock that is returned as an instance ofstruct super_block.
❑ do_add_mounthandles some necessary locking and ensures that a filesystem is not mounted
to the same place multiple times (notwithstanding that, it is certainly possible to mount the
same filesystem at multipledifferentplaces). The main work is delegated tograft_tree.
The newly mounted filesystem is added to the namespace of the parent mount by calling
attach_recursive_mount. The function is essentially defined as follows:
fs/namespace.c
static int attach_recursive_mnt(struct vfsmount *source_mnt,
struct nameidata *nd, struct nameidata *parent_nd)
{
struct vfsmount *dest_mnt = nd->mnt;
struct dentry *dest_dentry = nd->dentry;
...
mnt_set_mountpoint(dest_mnt, dest_dentry, source_mnt);
commit_tree(source_mnt);
...
}

nameidatais a structure used to group together avfsmntinstance and adentryinstance. In
this case, the structure holds thedentryinstance of the mount point and thevfsmntinstance of
Free download pdf