Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 8: The Virtual Filesystem


the filesystem in which the directory waspreviouslylocated, that is, before the new mount was
performed.
mnt_set_mountpointensures that both themnt_parentand themnt_mountpointelement of the
newvfsmntinstancechild_mountare set to point to the old elements:
fs/namespace.c
void mnt_set_mountpoint(struct vfsmount *mnt, struct dentry *dentry,
struct vfsmount *child_mnt)
{
child_mnt->mnt_parent = mntget(mnt);
child_mnt->mnt_mountpoint = dget(dentry);
dentry->d_mounted++;
}

This enables the situation prior to mounting to be reconstructed when the kernel unmounts a
filesystem. Thed_mountedvalue of theolddentryinstance is incremented so that the kernel is
able to recognize that a filesystem is mounted at this point.
In addition, the newvfsmntinstance is added to the global hash table and to the child list of the
previous entry using the list elements discussed above. This is performed bycommit_tree:
fs/namespace.c
static void commit_tree(struct vfsmount *mnt)
{
struct vfsmount *parent = mnt->mnt_parent;
...
list_add_tail(&mnt->mnt_hash, mount_hashtable +
hash(parent, mnt->mnt_mountpoint));
list_add_tail(&mnt->mnt_child, &parent->mnt_mounts);
...
}

Shared Subtrees


The mechanisms I have discussed so far covered the standard mount cases that are available on any
Unixsystem. However, Linux supports some more advanced possibilities that allow for gaining more
power from namespaces. Since they were only introduced during the development of 2.6 (2.6.16, to be
precise), their use is still somewhat limited, so I will briefly review their basic principle before I discuss
the implementation. For specific details on potential applications and a precise description of the shared
subtree semantics of themounttool, see the manual pagemount(8). Another detailed investigation of the
features provided by shared subtrees can be found onhttp://lwn.net/Articles/159077/.

The extended mount options (which I collectively callshared subtrees) implement several new attributes
for mounts:

❑ Shared Mounts— A set of mounted filesystems between which mount events are propagated.
If a new filesystem is mounted into one member of the set, the mount is replicated into all other
members of the set.
❑ Slave Mounts— Similar to shared mounts, except that the symmetry between all members of
the set is removed. One mount in the set is especially distinguished as the master mount. All
mount operations in the master mount propagate into the slave mounts, but mount operations
in the slaves do not propagate back into the master.
Free download pdf