The Mount System Call
The point of entry for the mount system call is the sys_mount function defined in fs/namespace.c.
Figure 8-5 shows the associated code flow diagram.
The approach described here is used only to mount a new filesystem in an existing root filesystem. A modified version of the above algorithm mounts the root filesystem itself, but is not sufficiently interesting to merit a separate description (its code can be found in mount_root in init/do_mounts.c).
After the mount options (type, device, and options) have been copied from userspace by sys_mount, the kernel transfers control to do_mount, where the information passed is analyzed, and the relevant flags are set. This is also where the dentry entry of the mount point is found using the path_lookup function discussed below.
do_mount acts as a multiplexer to delegate work that still needs to be done to various mount type-dependent functions.
□ do_remount modifies the options of a filesystem already mounted (ms_remount).
□ do_loopback is invoked to mount a filesystem via the loopback interface (the ms_bind flag is required to do this).15
□ do_move_mount (MS_MOVE) is used to move a mounted filesystem.
□ do_change_type is responsible for handling shared, slave, and unbindable mounts by changing the mount flags or building up the required data structure connections between the vfsmount instances involved.
□ do_new_mount handles normal mount operations. This is the default situation, so no special flags are required.
15 A loopback mount involves mounting a filesystem whose data reside in a file and not on a normal block device. This is useful to quickly test new filesystems or to check CD-ROM filesystems before writing them to CD.
It's worth taking a closer look at do_new_mount because it is used so frequently. Its code flow diagram is shown in Figure 8-6.
do_new_mount splits into two parts — do_kern_mount and do_add_mount:
□ The initial task of do_kern_mount is to find the matching file_system_type instance 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_mount invokes the filesystem-specific get_sb function to read the associated superblock that is returned as an instance of struct super_block.
□ do_add_mount handles 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 multiple different places). The main work is delegated to graft_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:
Continue reading here: Fsnamespacec
Was this article helpful?