kobject
linux3.4
struct kobject {
const char *name;
struct list_head entry; // directory entry, used for mount to kset list,
struct kobject *parent;
struct kset *kset;
struct kobj_type *ktype; //指向對象類型描述附指針
struct sysfs_dirent *sd; //
struct kref kref; // 引用計數
unsigned int state_initialized:1;
unsigned int state_in_sysfs:1;
unsigned int state_add_uevent_sent:1;
unsigned int state_remove_uevent_sent:1;
unsigned int uevent_suppress:1;
};
其中 sysfs_dirent,
/*
* sysfs_dirent - the building block of sysfs hierarchy. Each and
* every sysfs node is represented by single sysfs_dirent.
*
* As long as s_count reference is held, the sysfs_dirent itself is
* accessible. Dereferencing s_elem or any other outer entity
* requires s_active reference.
*/
struct sysfs_dirent {
atomic_t s_count;
atomic_t s_active;
#ifdef CONFIG_DEBUG_LOCK_ALLOC
struct lockdep_map dep_map;
#endif
struct sysfs_dirent *s_parent;
const char *s_name;
struct rb_node s_rb;
union {
struct completion *completion;
struct sysfs_dirent *removed_list;
} u;
const void *s_ns; /* namespace tag */
unsigned int s_hash; /* ns + name hash */
union {
struct sysfs_elem_dir s_dir;
struct sysfs_elem_symlink s_symlink;
struct sysfs_elem_attr s_attr;
struct sysfs_elem_bin_attr s_bin_attr;
};
unsigned short s_flags;
umode_t s_mode;
unsigned int s_ino;
struct sysfs_inode_attrs *s_iattr;
};
kset
struct kset {
struct list_head list; //double list head
spinlock_t list_lock;
struct kobject kobj; //嵌入的kobject
const struct kset_uevent_ops *uevent_ops; //事件操作集
};
其中 kset_uevent_ops
定義了kset的對所包含的kobject 可以執行的操作,包括事件過濾和導出環境變量操作。
struct kset_uevent_ops {
int (* const filter)(struct kset *kset, struct kobject *kobj); //事件過濾
const char *(* const name)(struct kset *kset, struct kobject *kobj);
int (* const uevent)(struct kset *kset, struct kobject *kobj,
struct kobj_uevent_env *env); // 環境變量導出
};
kobject 與sysfs 的關係
想要把kobject 導入sysfs,需要:
int kobject_add(struct kobject *obj,...)
kobject
kobject 與事件消息傳遞
netlink
– | – |