Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 8: The Virtual Filesystem


If a slave — or a private or unbindable mount — has to be established, the kernel has to rearrange the
mount data structure such that thevfsmountinstance under consideration is turned into a slave mount.
This is done bydo_make_slave. The function proceeds in several steps:



  1. A master for the mount itself and any possible slave mounts needs to be found. First,
    the kernel searches among the shared-mount peers; the first one with the same root
    dentry is taken as the new master. If no such peer exists, the first element in the peer list
    is used.

  2. If a new master has been found, both the mount under consideration and all its slave mounts
    are made slaves of the new master.

  3. If the kernel could not find a new master, all slave mounts of the mount under consideration
    are freed — they do not have a master anymore.


In any case, theMNT_SHAREDflag is also removed.


Afterdo_make_slavehas performed these rearrangements,change_mnt_propagationneeds some more
steps for unbindable and private mounts.^17 In both cases, the mount is deleted from a slave list if it should
be on one, and the master is set toNULL— neither mount type has a master. For unbindable mounts, the
MNT_UNBINDABLEflag is set to identify it as such.


Shared subtrees obviously also influence the kernel behavior when new mounts are added to the sys-
tem. The crucial steps are taken inattach_recursive_mnt. Recall that the function has already been
touched on before, but the presentation was simplified. This time, I also include the effects of shared
subtrees.^18 First of all, the function needs to check into which mounts the mount event is supposed to
propagate.


fs/namespace.c
static int attach_recursive_mnt(struct vfsmount *source_mnt,
struct nameidata *nd, struct nameidata *parent_nd)
{
LIST_HEAD(tree_list);
struct vfsmount *dest_mnt = nd->mnt;
struct dentry *dest_dentry = nd->detnry;
struct vfsmount *child, *p;

if (propagate_mnt(dest_mnt, dest_dentry, source_mnt, &tree_list))
return -EINVAL;
...

propagate_mntiterates over all slave and shared mounts of the mount destination and mounts the new
filesystem into them usingmnt_set_montpoint. All mount points that are affected by this are returned
intree_list.


(^17) Since the function has already returned to the caller in the case of shared mounts, only these mount types remain and can be dif-
ferent fromMS_SLAVEin theifconditional.
(^18) Note that we also perform a slight simplification this time since we only consider add mounts, but no move mounts where an
existing mount is shifted from one place in the filesystem hierarchy to another.

Free download pdf