Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 8: The Virtual Filesystem


The actual work is delegated todo_umount.

❑ If a superblock-specificumount_beginfunctionisdefined,itisinvoked.Thisallows,forinstance,
network filesystems to terminate communication with the remote partner before an unmount is
forced.
❑ umount_treeis invoked if the mounted filesystem is no longer needed (this is indicated
by the usage counter)orifMNT_DETACHwas specified to force a filesystem unmount. The
real work is delegated toumount_treeandrelease_mounts. Essentially, the first one is
responsible for decrementing the counterd_mounted, while the latter one uses the data stored
inmnt_mountpointandmnt_parentto restore the original state before the new filesystem
was mounted. The structures of the previously mounted filesystem are also removed from the
kernel lists.

Automatic Expiration


The kernel also provides some infrastructure to allow automatic expiration of mounts. When a mount is
not used by any process or the kernel itself, it will be automatically removed from the VFS mount tree if
automatic expiration is used. Currently the NFS and AFS network filesystems use this offer. Allvfsmount
instances of submounts that are supposed to expire automatically must be collected on a linked list that
usesvfsmount->mnt_expireto chain the elements together.

It then suffices to periodically applymark_mounts_for_expiryon the list. The function scans through
all entries. A mount is unused if its usage count is 1, that is, if it is only referenced by the parent mount.
When such an unused mount is found,mnt_expiry_markis set. Whenmark_mounts_for_expiryfinds
an unused entry withmnt_expiry_markset on the next list traversal, the mount is removed from the
namespace.

Note that themntputis responsible to clearmnt_expiry_mark. This ensures that a mount that has already
been on the expiration list but became used again is not immediately expired when it becomes once more
unused. The code flow is as follows:


  1. An unused mount is marked for expiry bymark_mounts_for_expiry.

  2. After this, the mount comes into use again, so itsmnt_countis increased. This prevents
    mark_mounts_for_expiryfrom removing the mount from the namespace despite the expi-
    ration mark still being set.

  3. When the usage count is decreased withmntput, the function will also ensure that the
    expiration mark is removed. Themark_mounts_for_expirycircle can thus commence as
    usual.


Pseudo-Filesystems


Filesystems do not necessarily require an underlying block medium. They can either use memory as
backing store, as is the case for ramfs and tmpfs, or can require no backing store at all, as procfs and
sysfs do — their contents are generated synthetically from information contained in the kernel’s data
structures. While filesystems of this type are already quite distinct from the traditional concepts, it is still
possible to take a further step forward. How? All filesystems, be they virtual or not, have one common
property: They are visible to userspace in the form of files and directories. However, this property is not
sacrosanct.Pseudo-filesystems are filesystems that cannot be mounted and are thus never directly visible
in userland.
Free download pdf