8

The udev rules I've created so far only deal with devices being added or removed, i.e.:

ACTION=="add"... or ACTION=="remove"...

I've come across an example of a rule that seems to deal with device state changes as well:

ACTION=="add|change", KERNEL=="sd[b-z]", ATTR{queue/rotational}=="1", RUN+="/usr/bin/hdparm -B 127 -S 12 /dev/%k"

I take it that the above rule applies whenever a matching device is added OR its state changes.

Question: What kind of state changes are possible (generally and specific to a USB hard drive)?

I've checked all udev documentation I can find and there's barely any mention of, or usage guidance, in respect of device state changes or specifically ACTION="change".

3 Answers 3

8

"change" corresponds, for example, to removing or inserting an sdcard in a sdcard reader, or changing the hard disc inside a usb-to-sata enclosure. The device itself is not added nor removed, but the media is no longer the same.

2

udev change event gets triggered when media changer (regards to tape - Netbackup like environment) or sd card reader is used in continuation with different media or sd card. When a same device is re-added (a san disk is re-added again or you do switchdisable/enable on the switch side or target port disable/enable from target side )

Below are the few change udev events that we see on the host side, when I did target port disable (from Vexata VX100 array) for an existing san lun

KERNEL[34942.047543] change   /devices/virtual/block/dm-0 (block)
KERNEL[34942.047596] change   /devices/virtual/block/dm-1 (block)
KERNEL[34942.047613] change   /devices/virtual/block/dm-2 (block)
KERNEL[34942.047631] change   /devices/virtual/block/dm-3 (block)
KERNEL[34942.047678] change   /devices/virtual/block/dm-4 (block)
UDEV  [34942.053448] change   /devices/virtual/block/dm-3 (block)
UDEV  [34942.053486] change   /devices/virtual/block/dm-4 (block)
UDEV  [34942.053507] change   /devices/virtual/block/dm-0 (block)
UDEV  [34942.053536] change   /devices/virtual/block/dm-2 (block)
0

It means the kernel has emitted a uevent to report that something about the device has changed, with accompanying event properties (ENV) to describe what exactly, and device properties (also ENV) to provide context. Those are different from the device attributes (ATTR, which correspond to the file structure under sysfs), and you can see what these properties are by running sudo udevadm monitor --kernel --udev -p --subsystem-match=usb.

These uevents are raised by the specific kernel modules that manage the device, so there is no complete list or guaranteed set of events. You would need to check the documentation or look at the source code of the modules in question for calls to kobject_uevent or kobject_uevent_env to know what causes events to be raised.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .