Usage of uvent, bind and unbind interface in/sys

Source: Internet
Author: User

In/sys, there are using kobject which have the attribute of uevent. mainly Thay are used as the interface for communication between kenel and udev. to udev and the Netlink protocol, they doesn't have to access uevent file. but via the interface of the uevent
File, udevmonitor can send message from kernel to udevd, and it also can be used to check the environment variable of Netlink messages which are support by this device. this attribute can be used by developer to debug udev script, and udevtrigger is also implemented
Based on this interface.

These uevent file usually are writable, in/sys/device, there are failed of them. In the latest version kernel, these files are also readable.

# Find/sys-type F-name uevent-ls

11 0-RW-r-1 Root 4096 Jan 12 21:10/sys/devices/platform/uevent

1471 0-RW-r-1 Root 4096 Jan 12/sys/devices/platform/pcspkr/uevent

3075 0-RW-r-1 Root 4096 Jan 12/sys/devices/platform/vesafb.0/uevent

3915 0-RW-r-1 Root 4096 Jan 12/sys/devices/platform/serial8250/uevent

3941 0-RW-r-1 Root 4096 Jan 12/sys/devices/platform/serial8250/tty/ttys2/uevent

3950 0-RW-r-1 Root 4096 Jan 12/sys/devices/platform/serial8250/tty/ttys3/uevent 5204 0-RW-r-1 root 4096 Jan 12 21:10/sys/devices/platform/i8042/uevent [...]

912 0-RW-r-1 Root 4096 Jan 12/sys/devices/pci0000: 00/0000: 00: 02.5/uevent

All these uevent file are writable and readable. the last item is uevent file of SCSI controller. the parameter which can be written are "Add", "remove", "change", "move", "online" and "offline ". by writing "Add", it can sent a Netlink message to udevd and
Let udevd refresh the udev script file. This is very helpfult for developer to debug the udev script file.

# Echo add>/sys/devices/pci0000: 00/0000: 00: 02.5/uevent

In the/sys, there are using bind, unbind and new_id file for PCI device. every device driver specified in the program which hardware this driver for, for example in the source code of driver, the module_device_table specifies the PCI hardware
PCI device ID. if the hardware which is designed in future still can work in the mode of backward comptiable, then it still can use current driver. but before the interface of bind and unbind were implemented, we have to modify the device_table of the source
code and recompile it. besides this, there is no other solution. after the bind and unbind were added to kernel 2.6, We can bind the device driver and the hardware manually without the recompilation of the Code.

In addition, to some hardware, there are several device drivers available, but at any certain time, there is only one driver running. we can use bind and unbind to decide which driver is running or not (for the choose of multiple drivers, the better way is
Use modprobe. conf. it needs to be effective after reboot, but bind/unbind provide a temporary method witheout reboot ). via the interface of bind and unbind we can forcefully decide a device use certain driver or not.

# Find/sys/-type F (-name bind-or-name unbind-or-name new_id)-ls

69 0-RW-r-1 Root 4096 Jan 12 22: 12

/Sys/devices/virtual/vtconsole/vtcon0/Bind

3072 0-W --- 1 Root 4096 Jan 12

/Sys/bus/platform/Drivers/vesafb/unbind

[...]

6489 0-W --- 1 Root 4096 Jan 12 22: 09

/Sys/bus/PCI/Drivers/8139too/unbind

6490 0-W --- 1 Root 4096 Jan 12 22: 09

/Sys/bus/PCI/Drivers/8139too/Bind

6491 0-W --- 1 Root 4096 Jan 12

/Sys/bus/PCI/Drivers/8139too/new_id

# Find/sys/bus/PCI/Drivers/8139too/-ls

6435 0 drwxr-XR-x 2 root Root 0 Jan 12

/Sys/bus/PCI/Drivers/8139too/

6436 0 lrwxrwxrwx 1 Root 0 Jan 12

/Sys/bus/PCI/Drivers/8139too/0000: 00: 0e. 0-> .. /.. /.. /.. /devices/pci0000: 00/0000: 00: 0e. 0

6485 0 lrwxrwxrwx 1 Root 0 Jan 12

/Sys/bus/PCI/Drivers/8139too/Module->.../module/8139too

6488 0-W --- 1 Root 4096 Jan 12

/Sys/bus/PCI/Drivers/8139too/uevent

6489 0-W --- 1 Root 4096 Jan 12

/Sys/bus/PCI/Drivers/8139too/unbind

6490 0-W --- 1 Root 4096 Jan 12

/Sys/bus/PCI/Drivers/8139too/Bind

6491 0-W --- 1 Root 4096 Jan 12

/Sys/bus/PCI/Drivers/8139too/new_id

# IP ADDR

1: Lo: <loopback, up, lower_up> MTU 16436 qdisc noqueue state unknown

Link/loopback 00: 00: 00: 00: 00: 00 BRD 00: 00: 00: 00: 00: 00

Inet 127.0.0.1/8 Scope host Lo

2: eth0: <broadcast, multicast, up, lower_up> MTU 1500 qdisc

Pfifo_fast state

Unknown qlen 1000

Link/ether 00: 14: 2a: D1: 16: 72 brd ff: FF

Inet 192.168.1.102/24 BRD 192.168.1.255 scope global eth0

3: bond0: <broadcast, multicast, Master> MTU 1500 qdisc Noop state down

Link/ether 00: 00: 00: 00: 00 brd ff: FF

# Echo-N 0000: 00: 0e. 0>/sys/bus/PCI/Drivers/8139too/unbind

# IP ADDR

1: Lo: <loopback, up, lower_up> MTU 16436 qdisc noqueue state unknown

Link/loopback 00: 00: 00: 00: 00: 00 BRD 00: 00: 00: 00: 00: 00

Inet 127.0.0.1/8 Scope host Lo

3: bond0: <broadcast, multicast, Master> MTU 1500 qdisc Noop state down

Link/ether 00: 00: 00: 00: 00 brd ff: FF

# Echo-N 0000: 00: 0e. 0>/sys/bus/PCI/Drivers/8139too/Bind

# IP ADDR

1: Lo: <loopback, up, lower_up> MTU 16436 qdisc noqueue state unknown

Link/loopback 00: 00: 00: 00: 00: 00 BRD 00: 00: 00: 00: 00: 00

Inet 127.0.0.1/8 Scope host Lo

3: bond0: <broadcast, multicast, Master> MTU 1500 qdisc Noop state down

Link/ether 00: 00: 00: 00: 00 brd ff: FF

4: eth0: <broadcast, multicast> MTU 1500 qdisc Noop state

Down qlen 1000

Link/ether 00: 14: 2a: D1: 16: 72 brd ff: FF

This example shows how to bind and unbind the driver 8139too to device "0000: 00: 0e. 0" forcefully.

Write bus_id to unbind to Cancal binding.

Write bus_id to bind to implement binding

Notes: Bus ID is used for writing, for PCI device, it meets following rules and it can be retrieved from the kobject node. to device of other kinds bus, it meets the rules of this kind of bus.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.