LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Virtualization and Cloud (https://www.linuxquestions.org/questions/linux-virtualization-and-cloud-90/)
-   -   Write udev rule to change harddisk timeout (https://www.linuxquestions.org/questions/linux-virtualization-and-cloud-90/write-udev-rule-to-change-harddisk-timeout-810171/)

EricTRA 05-26-2010 04:12 AM

Write udev rule to change harddisk timeout
 
Hi all,

I want (have to) change the timeout on the harddisks of our VMWare virtual machines in Debian 5. Right now I run a small script to set the timeout manually at boot using rc.local. I would like to have it applied using a udev rule but haven't got a clue where to start. I've been reading and searching but cannot get it to work.

Our vendor provided a script for Suse and RedHat. I've tried changing the RedHat script for Debian but it doesn't work at all.

Here's the udevinfo output of the disk in question.
Code:

looking at device '/block/sda':
    KERNEL=="sda"
    SUBSYSTEM=="block"
    DRIVER==""
    ATTR{range}=="16"
    ATTR{removable}=="0"
    ATTR{size}=="16777216"
    ATTR{capability}=="12"
    ATTR{stat}=="    1206      829    37844    1664    1192    2335    28216      404        0    1724    2068"

  looking at parent device '/devices/pci0000:00/0000:00:10.0/host0/target0:0:0/0:0:0:0':
    KERNELS=="0:0:0:0"
    SUBSYSTEMS=="scsi"
    DRIVERS=="sd"
    ATTRS{device_blocked}=="0"
    ATTRS{type}=="0"
    ATTRS{scsi_level}=="3"
    ATTRS{vendor}=="VMware  "
    ATTRS{model}=="Virtual disk    "
    ATTRS{rev}=="1.0 "
    ATTRS{state}=="running"
    ATTRS{timeout}=="30"
    ATTRS{iocounterbits}=="32"
    ATTRS{iorequest_cnt}=="0x979"
    ATTRS{iodone_cnt}=="0x979"
    ATTRS{ioerr_cnt}=="0xa"
    ATTRS{modalias}=="scsi:t-0x00"
    ATTRS{evt_media_change}=="0"
    ATTRS{queue_depth}=="32"
    ATTRS{queue_type}=="simple"

  looking at parent device '/devices/pci0000:00/0000:00:10.0/host0/target0:0:0':
    KERNELS=="target0:0:0"
    SUBSYSTEMS==""
    DRIVERS==""

  looking at parent device '/devices/pci0000:00/0000:00:10.0/host0':
    KERNELS=="host0"
    SUBSYSTEMS==""
    DRIVERS==""

  looking at parent device '/devices/pci0000:00/0000:00:10.0':
    KERNELS=="0000:00:10.0"
    SUBSYSTEMS=="pci"
    DRIVERS=="mptspi"
    ATTRS{vendor}=="0x1000"
    ATTRS{device}=="0x0030"
    ATTRS{subsystem_vendor}=="0x0000"
    ATTRS{subsystem_device}=="0x0000"
    ATTRS{class}=="0x010000"
    ATTRS{irq}=="17"
    ATTRS{local_cpus}=="ff"
    ATTRS{local_cpulist}=="0-7"
ATTRS{modalias}=="pci:v00001000d00000030sv00000000sd00000000bc01sc00i00"
    ATTRS{enable}=="1"
    ATTRS{broken_parity_status}=="0"
    ATTRS{msi_bus}==""

  looking at parent device '/devices/pci0000:00':
    KERNELS=="pci0000:00"
    SUBSYSTEMS==""
    DRIVERS==""

I also don't know if I should add it to 50-udev.rules, 60-persistent-storage.rules or create a new rule file.

All help is greatly appreciated.

Kind regards,

Eric

EricTRA 05-26-2010 06:07 AM

Hi,

After some more reading and searching I put this construct in /etc/udev/rules.d/81-vmware-timeout.rules
Code:

ACTION=="add", KERNEL=="sda", SUBSYSTEM=="block", RUN+="/bin/sh -c 'echo 180 > /sys/$devpath/timeout'"
but it's not doing a thing. Can someone point me to the error or reason why it's not working?

Kind regards,

Eric

catkin 05-26-2010 06:32 AM

Three parts to this; is the match working, is the RUN command being run and if so is it doing what was intended?

You could write a shellscript and call that instead of "/bin/sh -c 'echo 180 > /sys/$devpath/timeout'". The shellscript could write its command line and the echo command to log.

EricTRA 05-26-2010 07:28 AM

Hi catkin,

Thanks for your reply. The udev rule isn't doing anything at all. The timeout value doesn't get changed. I currently do it using a script but would prefer putting it in a udev rule. Any ideas?

Kind regard,

Eric

mxwlpxwl 06-10-2010 01:16 PM

EricTra,

You are on the right path with the following

Code:

ACTION=="add", KERNEL=="sda", SUBSYSTEM=="block", RUN+="/bin/sh -c 'echo 180 > /sys/$devpath/timeout'"
testing the rule first with "/usr/bin/udevtest /block/sda" will allow you to see where you messed up. I'm no expert on debian, but you may want to try

Code:

ACTION=="add", KERNEL=="sda", SUBSYSTEM=="block", PROGRAM="/bin/sh -c 'echo 180 > /sys/$devpath/timeout'"
Bueno Suerte

EricTRA 06-11-2010 12:17 AM

Hello and Welcome to LinuxQuestions,

Thank you very much for your reply, I'll try it out and let you know. Have fun using Linux.

Kind regards,

Eric

EricTRA 06-11-2010 01:12 AM

Quote:

Originally Posted by mxwlpxwl (Post 3999294)
Code:

ACTION=="add", KERNEL=="sda", SUBSYSTEM=="block", PROGRAM="/bin/sh -c 'echo 180 > /sys/$devpath/timeout'"
Bueno Suerte

Hi,

No joy :( Tried different rule files without any result, not restarting udev nor rebooting. It just doesn't get applied. Could this have to do with the machines being virtual?

[EDIT]
Just tried it on a physical server with Debian and doesn't work either.
[/EDIT]

Kind regards,

Eric

colucix 06-11-2010 04:38 AM

Hi Eric,

pay attention to the fact that $devpath is substituted by "/block/sda", so that the path of the timeout file should be "/sys$devpath/device/timeout" (your rule lacks the device directory). As previously suggested you can test the rule with udevtest (when the disk is mounted) and if the rule's action is:
Code:

... RUN+="/bin/sh -c 'echo 180 > /sys$devpath/device/timeout'"
you should see this at some point:
Code:

$ udevtest /block/sda
<omitted>
main: run: '/bin/sh -c 'echo 180 > /sys/block/sda/device/timeout''

<omitted>[/CODE]
You may also want to refine your rule to match against that particular device, since "KERNEL=="sda", SUBSYSTEM=="block", is a bit too generic. For example you can try to add the "vendor" attribute which identifies a VMware disk and/or the "size" attribute, if fixed.

Cheers!
Alex

EricTRA 06-11-2010 05:29 AM

Hola Alex,

It's working!!! Thank you so much. The basic stuff is what gets forgotten first I think. I didn't think about to what the devpath variable was pointing, feeling pretty green right now :o

Anyway, udevtest doesn't work any more since version 0.122 and has been replaced by udevadm test <device>, so
Code:

udevadm test /block/sda
returned this:
Code:

srvtest:/etc/udev/rules.d# udevadm test /block/sda
This program is for debugging only, it does not run any program,
specified by a RUN key. It may show incorrect results, because
some values may be different, or not available at a simulation run.

add_matching_files: unable to open '/lib/udev/rules.d': No such file or directory
parse_file: reading '/etc/udev/rules.d/50-udev.rules' as rules file
parse_file: reading '/etc/udev/rules.d/60-persistent-input.rules' as rules file
parse_file: reading '/etc/udev/rules.d/60-persistent-storage-tape.rules' as rules file
parse_file: reading '/etc/udev/rules.d/60-persistent-storage.rules' as rules file
parse_file: reading '/etc/udev/rules.d/60-persistent-v4l.rules' as rules file
parse_file: reading '/dev/.udev/rules.d/61-dev-root-link.rules' as rules file
parse_file: reading '/etc/udev/rules.d/70-persistent-cd.rules' as rules file
parse_file: reading '/etc/udev/rules.d/75-cd-aliases-generator.rules' as rules file
parse_file: reading '/etc/udev/rules.d/75-persistent-net-generator.rules' as rules file
parse_file: reading '/etc/udev/rules.d/80-drivers.rules' as rules file
parse_file: reading '/etc/udev/rules.d/81-vmware-timeout.rules' as rules file
parse_file: reading '/etc/udev/rules.d/91-permissions.rules' as rules file
parse_file: reading '/etc/udev/rules.d/95-late.rules' as rules file
import_uevent_var: import into environment: 'MAJOR=8'
import_uevent_var: import into environment: 'MINOR=0'
import_uevent_var: import into environment: 'DEVTYPE=disk'
import_uevent_var: import into environment: 'PHYSDEVPATH=/devices/pci0000:00/0000:00:10.0/host0/target0:0:0/0:0:0:0'
import_uevent_var: import into environment: 'PHYSDEVBUS=scsi'
import_uevent_var: import into environment: 'PHYSDEVDRIVER=sd'
udevtest: looking at device '/block/sda' from subsystem 'block'
udev_rules_get_name: add symlink 'block/8:0'
match_rule: '/sys/block/sda/whole_disk' does not exist
udev_node_mknod: mknod(/dev/.tmp-8-0, 060600, (8,0))
udev_node_mknod: chmod(/dev/.tmp-8-0, 060600)
udev_node_mknod: chown(/dev/.tmp-8-0, 0, 0)
run_program: 'scsi_id --export --whitelisted --device=/dev/.tmp-8-0'
run_program: '/lib/udev/scsi_id' returned with status 1
run_program: 'edd_id --export /dev/.tmp-8-0'
run_program: '/lib/udev/edd_id' (stderr) 'no kernel EDD support'
run_program: '/lib/udev/edd_id' returned with status 2
run_program: 'path_id /block/sda'
run_program: '/lib/udev/path_id' (stdout) 'ID_PATH=pci-0000:00:10.0-scsi-0:0:0:0'
run_program: '/lib/udev/path_id' returned with status 0
udev_rules_get_name: add symlink 'disk/by-path/pci-0000:00:10.0-scsi-0:0:0:0'
run_program: 'vol_id --export /dev/.tmp-8-0'
run_program: '/lib/udev/vol_id' (stderr) '/dev/.tmp-8-0: unknown volume type'
run_program: '/lib/udev/vol_id' returned with status 4
udev_rules_get_name: no node name set, will use kernel name 'sda'
udev_device_event: device '/block/sda' already in database, cleanup
udev_node_add: creating device node '/dev/sda', major=8, minor=0, mode=0660, uid=0, gid=6
udev_node_update_symlinks: update symlink 'block/8:0' of '/block/sda'
udev_db_get_devices_by_name: found index directory '/dev/.udev/names/block\x2f8:0'
update_link: found 1 devices with name 'block/8:0'
update_link: found '/block/sda' for 'block/8:0'
update_link: compare (our own) priority of '/block/sda' 0 >= 0
update_link: 'block/8:0' with target 'sda' has the highest priority 0, create it
udev_node_update_symlinks: update symlink 'disk/by-path/pci-0000:00:10.0-scsi-0:0:0:0' of '/block/sda'
udev_db_get_devices_by_name: found index directory '/dev/.udev/names/disk\x2fby-path\x2fpci-0000:00:10.0-scsi-0:0:0:0'
update_link: found 1 devices with name 'disk/by-path/pci-0000:00:10.0-scsi-0:0:0:0'
update_link: found '/block/sda' for 'disk/by-path/pci-0000:00:10.0-scsi-0:0:0:0'
update_link: compare (our own) priority of '/block/sda' 0 >= 0
update_link: 'disk/by-path/pci-0000:00:10.0-scsi-0:0:0:0' with target 'sda' has the highest priority 0, create it
udevtest: run: '/bin/sh -c 'echo 180 > /sys/block/sda/device/timeout''
udevtest: run: 'socket:@/org/kernel/udev/monitor'
srvtest:/etc/udev/rules.d#

which looked pretty perfect! After a reboot of my testserver the correct value was presented. Thanks again for your help. Moltes graciès!

Kind regards,

Eric

colucix 06-11-2010 06:55 AM

Hola! You're welcome! Glad to see it works now. And thank you for the notice about udevadm... I always forget it (old habits are hard to die). :)


All times are GMT -5. The time now is 11:09 PM.