Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 10: Filesystems without Persistent Storage


{
.ctl_name = CTL_DEV,
.procname = "dev",
.mode = 0555,
.child = dev_table,
},

{ .ctl_name = 0 }
};

Of course, further top-level categories can be added using the overlay mechanism described above. The
kernel also selects this option, for example, for all sysctls that are assigned to the ABI (application binary
interface) and belong to theCTL_ABIcategory.

The tables referenced in the definition ofroot_table—kern_table,net_table, and so on — are like-
wise defined as static arrays. Because they hold a wealth of sysctls, we ignore their lengthy definitions
here, particularly as they offer little of interest besides further staticctl_tableinstances. Their contents
can be viewed in the kernel sources, and their definitions are included inkernel/sysctl.c.

Registering Sysctls


In addition to statically initiated sysctls, the kernelfeatures an interface for dynamically registering and
unregistering new system control functions.register_sysctl_tableis used to register controls and its
counterpart,unregister_sysctl_table, to remove sysctl tables, typically when modules are unloaded.

Theregister_sysctl_tablefunction requires one parameter — a pointer to an array ofctl_table
entries in which the new sysctl hierarchy is defined. The function also comprises just a few steps. First,
anewctl_table_headeris instantiated and associated with the sysctl table. The resulting construct is
then added to the existing list of sysctl hierarchies.

The auxiliary functionsysct_check_tableis used to check that the new entry contains proper informa-
tion. Basically, it ensures that no nonsense combinations are specified (i.e., directories that contain data
directories that are writable) and that regular files have a valid strategy routine.

Registering a sysctl entry does not automatically createinodeinstances that connect the sysctl entries
withprocentries. Since most sysctls are never used viaproc, this wastes memory. Instead, the connection
withprocfiles is created dynamically. Only the directory/proc/sysis created when procfs is initialized:

fs/proc/proc_sysctl.c
int proc_sys_init(void)
{
proc_sys_root = proc_mkdir("sys", NULL);
proc_sys_root->proc_iops = &proc_sys_inode_operations;
proc_sys_root->proc_fops = &proc_sys_file_operations;
proc_sys_root->nlink = 0;
return 0;
}

The inode operations specified inproc_sys_inode_operationsensure that files and directories below
/proc/sysare dynamically generated when they are needed. The contents of the structure are as follows:
Free download pdf