Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 8: The Virtual Filesystem


A usage counter is implemented withmnt_count. Whenever avfsmountinstance is not required
anymore, the counter must be decreased withmntput.mntgetis the counterpart that needs to be called
when the instance is taken in use.

The remaining fields are used to implement several novel mount types that were mostly introduced
during the development of kernel 2.6.mnt_slave,mnt_slave_list,andmnt_masterserve to realize
slave mounts. The master mount keeps all slave mounts on a linked list for whichmnt_slave_listis
used as the list head, whilemnt_slave_listserves as the list element. All slave mounts point back to
their master viamnt_master.

Shared mounts are easier to represent. All the kernel needs to do is to keep all shared peer mounts on a
circular list.mnt_shareserves as the list element for this.

Mount expiration is handled withmnt_expiry_mark. The element is used to indicate if the mount is
unused.mnt_expireallows for placing all mounts that are subjected to auto-expiration on a linked list.
Section 8.4.1 discusses the implementation of expiring mounts.

Finally,mnt_nspoints at the namespace to which the mount belongs.

Superblock Management


The mount structures themselves are not the only objects generated in memory when new filesystems are
mounted. The mount operation starts by reading a structure called asuperblock. I mentioned this structure
several times above without bothering to define it properly. I do this now.

Theread_superfunction pointer stored in thefile_system_typeobjects returns an object of type
super_blockthat represents a superblock in memory. It is generated with the help of the low-level
implementation.

The structure definition is very long. I therefore reproduce a simplified version below (which itself is
anything but lean).

<fs.h>
struct super_block {
struct list_head s_list; /* Keep this first */
dev_t s_dev; /* search index; _not_ kdev_t */
unsigned long s_blocksize;
unsigned char s_blocksize_bits;
unsigned char s_dirt;
unsigned long long s_maxbytes; /* Max file size */
struct file_system_type *s_type;
struct super_operations *s_op;
unsigned long s_flags;
unsigned long s_magic;
struct dentry *s_root;
struct xattr_handler **s_xattr;

struct list_head s_inodes; /* all inodes */
struct list_head s_dirty; /* dirty inodes */
struct list_head s_io; /* parked for writeback */
struct list_head s_more_io; /* parked for more writeback */
struct list_head s_files;
Free download pdf