Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 10: Filesystems without Persistent Storage


with the classic PID for single-threaded processes. Thesprintffunction, with which we are familiar
from the C programming of userspace applications, converts the integer number into a string.

The remaining work is then delegated to standard virtual filesystem functions that are responsible for
directing the lookup operation to the right places.

SelectionAccording to PID


Let us turn our attention to how the process-specific information is selected by PID.

Creating the Directory Inode


If a PID is passed toproc_pid_lookupinstead of"self", the course of the lookup operation is as shown
in the code flow diagram in Figure 10-4.

Because filenames are always processed in the form ofstrings but PIDs are integer numbers, the former
must be converted accordingly. The kernel provides thename_to_intauxiliary function to convert strings
consisting of digits into an integer.

The information obtained is used to find thetask_structinstance of the desired process by means
of thefind_task_by_pid_nsfunction described in Chapter 2. However, the kernel cannot make the
assumption that the desired process actually exists. After all, it is not unknown for programs to try to
process a nonexistent PID, in which case, a corresponding error (-ENOENT)isreported.

Once the desiredtask_structis found, the kernel delegates the rest of the work mostly to
proc_pid_instantiateimplemented infs/proc/base.c, which itself relies onproc_pid_make_inode.
First, a new inode is created by thenew_inodestandard function of VFS; this basically boils down to the
sameproc-specificproc_alloc_inoderoutine mentioned above that makes use of its own slab cache.

The routine not only generates a newstruct inodeinstance, but also reserves
memory needed bystruct proc_inode; the reserved memory holds a normal VFS
inode as a ‘‘subobject,‘‘ as noted in Section 10.1.2. The elements of the object
generated are then filled with standard values.

After callingproc_pid_make_inode, all the remaining code inproc_pid_instantiatehastodoisper-
form a couple of administrative tasks. Most important, theinode->i_opinode operations are set to the
proc_tgid_base_inode_operationsstatic structure whose contents are examined below.

Sequential Files


When a file (or directory) in the PID-specific/proc/piddirectory is processed, this is done using the
inode operations of the directory, as noted in Chapter 8 when discussing the virtual filesystem mech-
anisms. The kernel uses the statically definedproc_base_inode_operationsstructure as the inode
operations of PID inodes. This structure is defined as follows:

fs/proc/base.c
static const struct inode_operations proc_tgid_base_inode_operations = {
.lookup = proc_tgid_base_lookup,
.getattr = pid_getattr,
.setattr = proc_setattr,
};
Free download pdf