kobject和uevent的一点想法--待续

本文深入解析Linux内核中的kobject结构及其与uevent事件的关系。介绍了kobject的初始化、添加、释放过程,以及uevent事件的触发条件和发送机制,包括netlink广播和用户空间助手程序的调用。通过对kobject和uevent的分析,有助于理解Linux设备驱动程序的事件通知机制。
摘要由CSDN通过智能技术生成

文件路径:

include/linux/kobject.h

lib/kobject_uevent.c

lib/kobject.c

 

在我的理解中uevent事件和kobject绑定在一起的

 

几种kobject能够产生的事件属性

enumkobject_action {

KOBJ_ADD,//添加

KOBJ_REMOVE,//移除

KOBJ_CHANGE,//发生了变化

KOBJ_MOVE,//移动

KOBJ_ONLINE,//存在

KOBJ_OFFLINE,//不在

KOBJ_MAX//最大

};

 

structkobject {

constchar *name; //本目录的名字

structlist_head entry; //链表

structkobject *parent; //父目录吧。。父亲,可以使用kobj,kset或者sys root

structkset *kset;//顶层

structkobj_type *ktype; //相应的操作

structsysfs_dirent *sd;//sysfs 下的目录名,根据parent设置或者会设置位sysroot下

structkref kref;//引用计数当用kobject_put设置为0时,则调用kobject_cleanup完全释放内存

unsignedint state_initialized:1; //释放被初始化,我的理解是当申请了kobject后记得设为0阿

unsignedint state_in_sysfs:1;//是否在sys下

unsignedint state_add_uevent_sent:1;//是否为增加的action

unsignedint state_remove_uevent_sent:1;//是否为remove的acton

unsignedint uevent_suppress:1;//不发送uevent事件

};

 

structkobj_type {

void(*release)(struct kobject *kobj);

conststruct sysfs_ops *sysfs_ops;

structattribute **default_attrs;

conststruct kobj_ns_type_operations *(*child_ns_type)(struct kobject*kobj);

constvoid *(*namespace)(struct kobject *kobj);

};

 

以上是kobject的结构体,那么接下来我来分析下kobject,然后穿插着说一下这个结构体,

那么一开始当然是从kobject_init开始

 

kobject_init

*This function will properly initialize a kobject such that it canthen

*be passed to the kobject_add() call.

*

*After this function is called, the kobject MUST be cleaned up by acall

*to kobject_put(), not by a call to kfree directly to ensure that allof

*the memory is cleaned up properly.

 

根据kobject_init的解释,最后释放的时候要掉用kobject_put能够释放所有的内存,然而接下来要掉用的是kobject_add

kobject_add

/**

*kobject_add - the main kobject add function

*@kobj: the kobject to add

*@parent: pointer to the parent of the kobject.

*@fmt: format to name the kobject with.

*

*The kobject name is set and added to the kobject hierarchy in this

*function.

*

*If @parent is set,

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值