Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 10: Filesystems without Persistent Storage


sysfs_open_file

sysfs_get_active_two

sysfs_put_active_two

sysfs_get_open_dirent

Set sysfs_ops

Allocate sysfs_buffer

Check read and write support

Figure 10-13: Code flow diagram for
sysfs_open_file.

The first task is to find thesysfs_opsoperations that belong to the opened file. Recall thatstruct
kobj_typeprovides a pointer to an instance ofsysf_ops:

<kobject.h>
struct kobj_type {
...
struct sysfs_ops * sysfs_ops;
...
};

However, the kernel needs to obtain an active reference on thekobjectinstance that is associated with
the sysfs file before the proper instance ofsysfs_opscan be found. The functionsysfs_get_active_two
grabs the active reference as discussed above. If thekobjectis a member of a set, then the pointer is read
from theksetinstance. Otherwise, thekobjectitself is used as source. If neither provides a pointer to
an instance ofsysfs_ops, a generic set of operations given bysysfs_sysfs_opsis used. However, this
is only necessary for direct kernel attributes found in/sys/kernel:

fs/sysfs/file.c
static int sysfs_open_file(struct inode *inode, struct file *file)
{
struct sysfs_dirent *attr_sd = file->f_path.dentry->d_fsdata;
struct kobject *kobj = attr_sd->s_parent->s_dir.kobj;
struct sysfs_buffer * buffer;
struct sysfs_ops * ops = NULL;
...

/* need attr_sd for attr and ops, its parent for kobj */
if (!sysfs_get_active_two(attr_sd))
return -ENODEV;

/* if the kobject has no ktype, then we assume that it is a subsystem
* itself, and use ops for it.
*/
if (kobj->kset && kobj->kset->ktype)
Free download pdf