Hi,

I'm running NetBSD 7.0.1_PATCH (GENERIC) amd64 on a Dell laptop. Almost 
everything is working perfectly, except the fact that every time I shutdown 
using the -p switch, the hard drive makes a loud click sound as the system 
powers off. I checked the SMART status (atactl and smartctl) and after every 
poweroff the Power_Off-Retract-Count parameter increases by 1.

I did some searching on the web and came across PR #21531 where this issue was 
discussed from 2003-2008 and finally a patch was committed which resolved the 
issue by sending the STANDBY_IMMEDIATE command to the disk before powering off. 
Since then the code has been refactored, but it is present in 
src/sys/dev/ata/wd.c line 1970 (wd_shutdown) which calls line 1848 
(wd_standby). This seemed strange since the disk was definitely not being spun 
down.

I attached a remote gdb instance and stepped through the code during shutdown, 
breaking on wd_flushcache() which is always called. The code path taken is 
wdclose()->wdlastclose() (lines 1029, 1014). I can see that the cache is 
flushed but then the device is deleted in line 1023. Subsequently, power is cut 
off during shutdown, causing an emergency retract. So, it seems at least for 
newer sata disks the spindown code is not being called. I'm fairly new to 
NetBSD code so there is a chance I read this wrong, so feel free to correct me.

Ideally I'd like the disk to spin down during poweroff (-p) and halt (-h), 
perhaps settable using a sysctl, but not during a reboot (-r). I am planning to 
patch wdlastclose() as an experiment to run the spindown code to see if it 
stops the click. Is this a known issue, worthy of a PR? I can file one. I can 
also volunteer a patch once I have tested it on my laptop. Comments welcome!

Anindya

Reply via email to