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

Sibananda Sahu sibananda.sahu at avagotech.com
Mon Apr 6 09:37:58 UTC 2015


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.

In fact I need the int opt; variable of the structure:

struct reboot_args {
    char opt_l_[PADL_(int)]; int opt; char opt_r_[PADR_(int)];
};

Is there any way to know if the system is shutting down or rebooting from
a driver's perspective???

And last but not the least, I really appreciate your reply to my query.

Thanks,
Sibananda Sahu


-----Original Message-----
From: Lowell Gilbert [mailto:freebsd-questions-local at be-well.ilk.org]
Sent: Tuesday, March 31, 2015 5:29 AM
To: Sibananda Sahu
Cc: freebsd-questions at freebsd.org
Subject: Re: How to know the system state if the system is going for halt
or poweroff or reboot in FreeBSD

Sibananda Sahu <sibananda.sahu at avagotech.com> writes:

> Linux has an enum system_state the denotes about the current system
state.
>
> These values are set in the system_state global variable according to
> the current system state of either restart, booting or power off etc.
>
>
>
> See the below link for the header:
>
> http://lxr.free-electrons.com/source/include/linux/kernel.h#L450
>
>
>
> I want the similar implementation in FreeBSD.
>
> For the same I searched the source code and following are my
observations:
>
> -          For shutdown -h now, shutdown -p now, poweroff, init 0, init
6
> and reboot sys_reboot() is called.
>
> -          Sys_reboot() will call kern_reboot() which inturn endup
calling
> EVENTHANDLER_INVOKE(shutdown_final, howto);
>
> -          Based on the howto variable passed to the kern_reboot() call,
> corresponding event handlers will be invoked.
>
> -          For a reboot request shutdown_reset(), or for a halt request
> shutdown_halt() and so on.
>
>
>
> Initially I thought the "rebooting" global variable used inside
> kern_reboot() function is set only while rebooting the system but
> after some exercises I realized that the global variable "rebooting"
> is set to 1 for halt, poweroff and reboot. I mean if the system is
> powering off then also the rebooting value is set to 1, which was really
confusing for me.
>
>
>
> My requirement is to know the exact reason of shutdown, whether is it
> a power-off or a reboot call.

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.

> And I can get the information from the "howto" variable that is passed
> to the kern_reboot() function call, but this variable is local to
> kern_reboot() only.

I suspect that you're looking at this much later in the process than I
would recommend. You probably should be doing something with this
information (logging it?) when the reboot_args struct is being set up.

> SO IS THERE ANY OTHER WAY TO GET THE SYSTEM STATE IN FREEBSD???

Please don't shout.


More information about the freebsd-questions mailing list