hello. I think this is already handled in wd.c in wd_shutdown() we
see:
wd_flushcache(wd, AT_POLL);
if ((how & RB_POWERDOWN) == RB_POWERDOWN)
wd_standby(wd, AT_POLL);
return true;
So, wd_standby only gets called if RB_POWERDOWN is sent in the howto
argument. It seems like the howto argument isn't geting set to
RB_POWERDOWN in this case and the question is why isn't it set?
-thanks
-Brian
On Jun 17, 11:59am, David Young wrote:
} Subject: Re: Spinning down sata disk before poweroff
} On Fri, Jun 17, 2016 at 01:23:36PM +0200, Manuel Bouyer wrote:
} > On Fri, Jun 17, 2016 at 01:49:43AM +0000, Anindya Mukherjee wrote:
} > > 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!
} >
} >
} > So the disk is not powered off because it's detached before the pmf
framework
} > has a chance to power it off (see amd64/amd64/machdep.c:cpu_reboot()).
} > that's bad.
} > Doing the poweroff in wdlastclose() is bad because then you'll have a
} > poweroff/powerup cycle for a reboot, or even on unmount/mount events if this
} > is not your root device. This can be harmfull for some disks (this has
already
} > been discussed).
} >
} > The (untested) attached patch should fix this by calling pmf before detach;
} > can you give it a try ?
}
} Careful! The alternation of detaching devices and unmounting
} filesystems is purposeful. You can have devices such as vnd(4) backed
} by filesystems backed by further devices.
}
} It's possible that unmounting a filesystem will counteract the PMF
} shutdown.
}
} A less intrusive change that's likely to work pretty well, I think, is
} to introduce a new flag, DETACH_REBOOT or DETACH_STAY_POWERED, that's
} passed to config_detach_all() by cpu_reboot() when the RB_* flags
} indicate a reboot is happening. Then, in the wd(4) detach routine, put
} the device into standby mode if the flag is not set.
}
} Dave
}
} --
} David Young //\ Trestle Technology Consulting
} (217) 721-9981 Urbana, IL http://trestle.tech/
>-- End of excerpt from David Young