Date: Fri, 10 Apr 2015 15:46:02 +0530 From: Sibananda Sahu <sibananda.sahu@avagotech.com> To: freebsd-questions@freebsd.org Subject: RE: How to know the system state if the system is going for halt or poweroff or reboot in FreeBSD Message-ID: <58e98b85960a28cbedc9c3108ecc3673@mail.gmail.com> In-Reply-To: <44wq1posa6.fsf@lowell-desk.lan> References: <0a2b68c0f411b50a276ce00a8d8b15ee@mail.gmail.com> <444mp2avfy.fsf@lowell-desk.lan> <78386e1c45b998c5ae63a63301d1ac23@mail.gmail.com> <44wq1posa6.fsf@lowell-desk.lan>
next in thread | previous in thread | raw e-mail | index | archive | help
Thanks Lowell Gilbert and John Baldwin for your help. I have registered an event handler and my job is done easily. Thanks for your time. - Sibananda Sahu -----Original Message----- From: Lowell Gilbert [mailto:freebsd-questions-local@be-well.ilk.org] Sent: Tuesday, April 07, 2015 3:04 AM To: Sibananda Sahu Cc: freebsd-questions@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@avagotech.com> 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@avagotech.com> 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.
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?58e98b85960a28cbedc9c3108ecc3673>