How to know the system state if the system is going for halt or poweroff or reboot in FreeBSD

Lowell Gilbert freebsd-questions-local at
Mon Apr 6 21:34:20 UTC 2015

Sibananda Sahu <sibananda.sahu at> writes:

> Hi Lowell Gilbert,
> As you said:
> "That's not really a requirement. It's a method you plan to use to meet
> your requirement, but we can only guess at what useful functionality you
> are making these changes to achieve."
> Yes that's true.
> I am working on mrsas(4) driver on FreeBSD.
> My requirement is to power off the drives (to save power consumption)
> attached to LSI controller if the system is shutting down.
> If the system is rebooting then we need not do anything with the drives'
> power supply.
> So to make the above things possible the mrsas(4) driver needs to know if
> the system is really shutting down or it is rebooting.

Okay, that sounds reasonable. I don't know that particular hardware, but
I can find a few things in general. 

You are powering down the drives as a way of putting them in a safe
state before control disappears. If the device were capable of shutting
itself down independently of the host computer (and had the power supply
to do so reliably), I assume you would be doing that instead of worrying
about the order in which host components shut down.

If the driver already loads an ACPI table, you may want to go through
ACPI to trigger your power down command. [I don't have any experience
writing code for ACPI either, so I may well be wrong on that point.]
Aside from that, you can register a kernel event handler. I am not sure
which event you would want to hook, but shutdown_final and
shutdown_post_sync would be good candidates.

Sibananda Sahu <sibananda.sahu at> had previously asked:
>> -          Sys_reboot() will call kern_reboot() which in turn end up calling
>> EVENTHANDLER_INVOKE(shutdown_final, howto);
>> -          Based on the howto variable passed to the kern_reboot() call,
>> corresponding event handlers will be invoked.

You probably understand this already, but in case you don't:
shutdown_final is an event for which your driver can register. 

Good luck.

More information about the freebsd-questions mailing list