Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 10: Filesystems without Persistent Storage


proc_root_initfirst creates a slab cache forproc_inodeobjects usingproc_init_inodecache;these
objects are the backbone of theprocfilesystem and often need to be generated and destroyed as quickly
as possible. Then the filesystem is officially registered with the kernel using theregister_filesystem
routine described in Chapter 8. And finally,mountis invoked to mount the filesystem.

kern_mount_datais a wrapper function fordo_kern_mount, also discussed in Chapter 8. It returns a
pointer to avfsmountinstance. The pointer is saved in the global variableproc_mntfor later use by the
kernel.

proc_misc_initgenerates various file entries in theprocmain directory; these are linked using special
procedures to read information from the kernel datastructures. Examples of these procedures are:

❑ loadavg (loadavg_read_proc)
❑ meminfo (meminfo_read_proc)
❑ filesystems (filesystems_read_proc)
❑ version (version_read_proc)

create_proc_read_entryis invoked for each name on this list (and for a few more, as the kernel
sources show). The function creates a new instance of the familiarproc_dir_entrydata structure whose
read_procentry is set to the procedure associated with each name. The implementation of most of these
procedures is extremely simple, as exemplified by theversion_read_procprocedure used to get the
kernel version:

init/version.c
const char linux_proc_banner[] =
"%s version %s"
" (" LINUX_COMPILE_BY "@" LINUX_COMPILE_HOST ")"
" (" LINUX_COMPILER ") %s\n";

fs/proc/proc_misc.c
static int version_read_proc(char *page, char **start, off_t off,
int count, int *eof, void *data)
{
int len;

len = snprintf(page, PAGE_SIZE, linux_proc_banner,
utsname()->sysname,
utsname()->release,
utsname()->version);
return proc_calc_metrics(page, start, off, count, eof, len);
}

The kernel stringlinux_proc_banneris written into a userspace page usingsprintf. When this is done,
theproc_calc_metricsauxiliary function determines the length of the data returned.

Onceproc_misc_inithas completed, the kernel usesproc_net_initto install a large number of net-
working related files in/proc/net. Since the mechanism is similar to the previous case, it is not discussed
here.

Finally, the kernel invokesproc_mkdirto create a number of/procsubdirectories; these are required
later but do not contain files at the moment. As forproc_mkdir, all we need to know is that the function
Free download pdf