ENV{DEVNAME} in remove rule?
Hello,
I'm learning my way around udev, and have written these rules to add a device:
KERNEL="sd*[!0-9]", ENV{ID_SERIAL}="", IMPORT{program}="/lib/udev/usb_id -x" KERNEL="sd*[!0-9]", ENV{ID_TYPE}="?*", IMPORT{program}="/lib/udev/path_id %p" KERNEL="sd*[!0-9]", ENV{ID_PATH}="*usb-0:6:1.0*", NAME="storage/raid-$env{ID_BUS}-%M-%m"
I want to run a command when it is removed, so I've written these rules:
(The first rule is a catch-all where I do "set >> /tmp/debug" to see what's available in the environment..)
SUBSYSTEM="*", RUN+="/root/udev-catch-remove" ENV{DEVNAME}="/dev/storage/raid-*", RUN+="/root/raid_management"
When the device is disconnected, "udevmonitor --env" shows me:
(DEVNAME appears just as I hoped..)
UDEV [1183481937.246643] remove /block/sdc (block)
UDEV_LOG=7
ACTION=remove
DEVPATH=/block/sdc
SUBSYSTEM=block
SEQNUM66
MINOR2
MAJOR=8 PHYSDEVPATH=/devices/pci0000:00/0000:00:0b.1/usb2/2-6/2-6:1.0/host15/target15:0:0/15:0:0:0 PHYSDEVBUS=scsi
PHYSDEVDRIVER=sd
UDEVD_EVENT=1
ID_VENDOR=Maxtor_6
ID_MODELà40L0
ID_REVISION11
ID_SERIAL=Maxtor_6_E040L0
ID_TYPE=disk
ID_BUS=usb
ID_PATH=pci-0000:00:0b.1-usb-0:6:1.0-scsi-0:0:0:0 DEVLINKS=/dev/disk/by-id/usb-Maxtor_6_E040L0 /dev/disk/by-path/pci-0000:00:0b.1-usb-0:6:1.0-scsi-0:0:0:0 DEVNAME=/dev/storage/raid-usb-8-32
But, my command /root/raid_management is never run, as if udev isn't matching ENV{DEVNAME}.
What have I misunderstood?
This is on Fedora 7 machine, using (slightly old) udev 106. ("rpm -q udev" = udev-106-4.fc7)
Thanks,
Richard
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel
Quoted 6 lines · Richard Michael
But, my command
/root/raid_managementis never run, as if udev isn't matching ENV{DEVNAME}.What have I misunderstood?
DEVNAME is set by udev before calling RUN programs. It is not available when rules are being processed.
In general I am not sure it is wise to match on DEVNAME It can be changed at any time by installing different rule(s). Better to match on device properties.
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel
Quoted 2 lines
DEVNAME is set by udev before calling RUN programs. It is not available when rules are being processed.
Where are these details documented? I've been writing lots of test rules to try and figure this out, but I'd prefer to just read something.
Quoted 3 lines
In general I am not sure it is wise to match on DEVNAME It can be changed at any time by installing different rule(s). Better to match on device properties.
I'd really prefer to match PHYSDEVPATH, because what I actually care about is identifying the USB socket which the device is attached (especially for the "add" rule.. the "remove" just uses the device name as I set it when it was added). However, PHYSDEVPATH has been deprecated.
I want to create block devices (not symlinks) for the specific ports of a USB (or firewire) controller, and take actions depending on which socket of the controller has been used.
Thanks,
Richard
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel
Quoted 4 lines · Richard Michael
Quoted 2 lines
DEVNAME is set by udev before calling RUN programs. It is not available when rules are being processed.
Where are these details documented?
source code?
Quoted 3 lines
I've been writing lots of test
rules to try and figure this out, but I'd prefer to just read something.
patches to manual pages are welcome :)
Quoted 5 lines
I want to create block devices (not symlinks) for the specific ports of a USB (or firewire) controller, and take actions depending on which socket of the controller has been used.
What's wrong with using ID_PATH? It also has advantage of being more stable than PHYSDEVPATH (which includes volatile details like running SCSI host number).
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel
Quoted 7 lines · Andrey Borzenkov
Quoted 4 lines · Richard Michael
Quoted 2 lines
DEVNAME is set by udev before calling RUN programs. It is not available when rules are being processed.
Where are these details documented?
source code?
I thought so. I think udev is great, it just needs slightly more helpful documentation to make is really user accessible. There are quite a few "things to know" (such as the default PATH, which took awhile to realize I was overlooking..).
Quoted 5 lines
Quoted 3 lines
I've been writing lots of test
rules to try and figure this out, but I'd prefer to just read something.patches to manual pages are welcome :)
I was thinking about changes to the How To Write UDev Rules document..
Quoted 3 lines
What's wrong with using
ID_PATH? It also has advantage of being more stable than PHYSDEVPATH (which includes volatile details like running SCSI host number).
Yes, I noticed the target number changes even when the hardware remains identical.
I thought I had a problem running path_id/usb_id to set those environment variables (I don't remember which one sets them..), because the sysfs entry was already gone. I think I misunderstood, maybe the variables are set from when the device was created? .. I'll look into again. I'm probably just confused, it's been a bit of mess building some understanding.. :)
Thanks,
Richard
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel
Quoted 4 lines · Richard Michael
I thought I had a problem running path_id/usb_id to set those environment variables (I don't remember which one sets them..), because the sysfs entry was already gone. I think I misunderstood, maybe the variables are set from when the device was created?
Yes. You have to import them (unless already done) on "add" event; those values are stored in udev database and added to environment *before* rules are being processed on "remove" event. At least that is the theory :)
You also can explicitly assign any environment variable on "add" and it should be available as well on "remove". This allows you to mark any specific device if you like.
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel