linux device 与driver prove 过程

本文深入解析Linux设备驱动模型中设备(Device)和驱动(Driver)的注册过程,包括枚举Bus上的Driver/Device实现绑定的机制,以及注册函数device_register()和driver_register()的具体作用。重点介绍了匹配规则、注册顺序和时序无关性的实现。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >



Linux 2.6的设备驱动模型中,所有的device都是通过Bus相连。device_register() / driver_register()执行时通过枚举BUS上的Driver/Device来实现绑定,本文详解这一过程。这是整个LINUX设备驱动的基础,PLATFORM设备,I2C上的设备等诸设备的注册最终也是调用本文讲述的注册函数来实现的。

 

Linux Device的注册最终都是通过device_register()实现,Driver的注册最终都是通过driver_register()实现。下图对照说明了Device和Driver的注册过程。


上面的图解一目了然,详细过程不再赘述。注意以下几点说明:

    • BUS的p->drivers_autoprobe;1默认是true。
    • bus_for_each_drv()是对BUS上所有的Driver都进行__device_attach()操作;同样的,bus_for_each_dev()是对BUS上所有的Device都进行__driver_attach()操作。
    • BUS上实现的.match()函数,定义了Device和Driver绑定时的规则。比如Platform实现的就是先比较id_table,然后比较name的规则。如果BUS的match()函数没实现,认为BUS上的所有的Device和Driver都是match的,具体后续过程要看probe()的实现了。
    • Probe的规则是:如果BUS上实现了probe就用BUS的probe;否则才会用driver的probe。

 

Device一般是先于Driver注册,但也不全是这样的顺序。Linux的Device和Driver的注册过程分别枚举挂在该BUS上所有的Driver和Device实现了这种时序无关性。




### Devicemapper in Linux Storage Management and Docker Usage #### Understanding Device Mapper Device Mapper serves as a kernel framework that provides dynamic online management of block devices. This includes mapping one block device onto another or applying transformations on data written to or read from these devices[^1]. In the context of Docker, `devicemapper` is used as a storage driver which manages images and containers' filesystem layers through thin provisioning technology. The data associated with this setup resides within specific files such as `/var/lib/docker/devicemapper/devicemapper/data`, indicating where Docker stores its metadata about volumes managed by the devicemapper backend. #### Configuring Docker with Devicemapper To properly configure Docker using the `devicemapper` storage driver, adjustments need to be made inside the daemon configuration file located at `/etc/docker/daemon.json`. An illustrative entry would look like: ```json { "storage-driver": "devicemapper", "storage-opts": [ "dm.thinpooldev=/dev/mapper/docker-thinpool", "dm.use_deferred_removal=true", "dm.use_deferred_deletion=true" ] } ``` This JSON snippet sets up the necessary parameters for utilizing `devicemapper` effectively while ensuring optimal performance and stability during container operations[^2]. #### Running Containers Using Devicemapper Once configured correctly, creating new containers becomes straightforward via commands similar to: ```bash docker run [OPTIONS] IMAGE [COMMAND] [ARG...] ``` For instance, launching an Ubuntu-based container could involve executing something along those lines but tailored according to project requirements[^3]. #### Updating System Packages Before Installation Before proceeding further into more complex configurations involving additional software installations related to Docker's operation under certain distributions (like Debian), it might prove beneficial first updating system packages alongside installing essential utilities required for secure communication over HTTPS connections when fetching remote resources: ```bash sudo apt-get update && \ sudo apt-get install -y ca-certificates curl gnupg lsb-release ``` Such preparatory steps ensure compatibility between installed components and future additions without encountering dependency issues down the line[^4]. --related questions-- 1. What are some best practices regarding security considerations when configuring Docker’s devicemapper? 2. Can you provide examples demonstrating how different options affect disk space allocation efficiency within devicemapper settings? 3. Is there any impact on application performance due to choosing devicemapper versus other available storage drivers offered by Docker? 4. How does setting `"dm.use_deferred_removal"` influence garbage collection processes among stopped containers?
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值