Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 10: Filesystems without Persistent Storage


#ifdef CONFIG_AUDITSYSCALL
REG("loginuid", S_IWUSR|S_IRUGO, loginuid),
#endif
#ifdef CONFIG_FAULT_INJECTION
REG("make-it-fail", S_IRUGO|S_IWUSR, fault_inject),
#endif
#if defined(USE_ELF_CORE_DUMP) && defined(CONFIG_ELF_CORE)
REG("coredump_filter", S_IRUGO|S_IWUSR, coredump_filter),
#endif
#ifdef CONFIG_TASK_IO_ACCOUNTING
INF("io", S_IRUGO, pid_io_accounting),
#endif
};

The structure describes each entry by type, name, and access rights. The latter are defined using the usual
VFS constants with which we are familiar from Chapter 8.

To summarize, various types of entry can be distinguished:

❑ INF-style files use a separateread_procfunction to obtain the desired data. The
proc_info_file_operationsstandard instance is used as thefile_operationsstruc-
ture. The methods it defines represent the VFS interface that passes the data returned upward
usingread_proc.
❑ SYMgenerates symbolic links that point to another VFS file. A type-specific function in
proc_get_linkspecifies the link target, andproc_pid_link_inode_operationsforwards the
data to the virtual filesystem in suitable form.
❑ REGcreates regular files that use specialized inode operations responsible for gathering data and
forwarding them to the VFS layer. This is necessary if the data source does not fit into the frame-
work provided byproc_info_inode_operations.

Let us return toproc_pident_lookup. To check whether the desired nameispresent,allthekerneldoes
is iterate over the array elements and compare the names stored there with the required name until
it strikes lucky — or perhaps not. After it has ensured that the name exists intgid_base_stuff,the
function generates a new inode usingproc_pident_instantiate, which, in turn, uses the already known
proc_pid_make_inodefunction.

10.1.8 System Control Mechanism


Kernel behavior can be modified at run time by means ofsystem controls. Parameters can be transferred
from userspace into the kernel without having to reboot. The classic method of manipulating the ker-
nel is thesysctlsystem call. However, for a variety of reasons, this is not always the most elegant
option — one reason being that it is necessary to write a program to read arguments and pass them to
the kernel usingsysctl. Unfortunately, this method does not allow users to obtain a quick overview of
which kernel control options are available; unlike with system calls, there is no POSIX or, indeed, any
other standard that defines a standard set of sysctls to be implemented by all compatible systems. Con-
sequently, thesysctlimplementation is now regarded as outmoded and will, in the short or the long
term, sink into oblivion.

To resolve this situation, Linux resorts to theprocfilesystem. It exports to/proc/sysa directory structure
that arranges all sysctls hierarchically and also allows parameters to be read and manipulated using
simple userspace tools;catandechoare sufficient to modify kernel run-time behavior.
Free download pdf