Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 8: The Virtual Filesystem


Two list heads group together inodes and files associated with the superblock.

❑ s_dirtyis a list head for the list of ‘‘dirty‘‘ inodes(discussed in Section 8.3.2) used to achieve
major speed gains when synchronizing memory contents with the data on the underlying stor-
age medium. Notallinodes need be scanned to write back changes — only those that have been
modified and therefore appear in this list. This field must not be confused withs_dirt,which
is not a list head, but a simple integer variable. It is set to 1 if the superblock was altered in any
way and needs to be written back to disk. Otherwise, it is 0.
❑ s_filesis a series offilestructures listing all opened files of the filesystem represented by
the superblock. The kernel references this list when unmounting filesystems. If it still contains
files opened for writing, the filesystem is still in use, and the unmount operation fails with an
appropriate error message.

The first element of the structure is also a list element calleds_listthat is used to group together all
superblock elements in the system. The list is headed by the global variablesuper_blocksdefined in
fs/super.c.

Finally, the individual superblocks are linked in a further list that combines all instances representing
filesystemsof the same type, regardless of the underlying block devices but with the condition that
the filesystem type is the same for all elements. The list head is thefs_superselement of the
file_system_typestructure discussed in Section 8.4.1.s_instanceslinks the individual elements.

s_oppoints to a structure with function pointers that, in the familiar VFS manner, provide a generic
interface with operations for working with superblocks. The implementation of the operations must be
provided by the underlying low-level code of the filesystems.

The structure is defined as follows:

<fs.h>
struct super_operations {
struct inode *(*alloc_inode)(struct super_block *sb);
void (*destroy_inode)(struct inode *);

void (*read_inode) (struct inode *);

void (*dirty_inode) (struct inode *);
int (*write_inode) (struct inode *, int);
void (*put_inode) (struct inode *);
void (*drop_inode) (struct inode *);
void (*delete_inode) (struct inode *);
void (*put_super) (struct super_block *);
void (*write_super) (struct super_block *);
int (*sync_fs)(struct super_block *sb, int wait);
void (*write_super_lockfs) (struct super_block *);
void (*unlockfs) (struct super_block *);
int (*statfs) (struct super_block *, struct kstatfs *);
int (*remount_fs) (struct super_block *, int *, char *);
void (*clear_inode) (struct inode *);
void (*umount_begin) (struct super_block *);

int (*show_options)(struct seq_file *, struct vfsmount *);
int (*show_stats)(struct seq_file *, struct vfsmount *);
};
Free download pdf