From owner-freebsd-questions@FreeBSD.ORG Fri Apr 10 10:16:11 2015 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 677CA7A2 for ; Fri, 10 Apr 2015 10:16:11 +0000 (UTC) Received: from mail-wi0-f171.google.com (mail-wi0-f171.google.com [209.85.212.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 0314BD09 for ; Fri, 10 Apr 2015 10:16:10 +0000 (UTC) Received: by widdi4 with SMTP id di4so122639807wid.0 for ; Fri, 10 Apr 2015 03:16:03 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:references:in-reply-to:mime-version :thread-index:date:message-id:subject:to:content-type; bh=kAMm8vZLR+7S2ALF5ofKf5ayoszGPs5XF5nSloaFSio=; b=Mfjf7vFe6GQo7jbvSpO85gWCUW+QTeQtoE95Nh7DxoxpSpohMzrX89QHkduGqRqe1E 50O83wsuuIlh7gHaoiNwovfHvHvQJc0HyTyS+9H8U6AQsjg8Pcj115TZCe10l1MivdQv FykSu5M+t+IPbjyBV8X2tO1CPyPY7Wj81rz3VGPvmpxUqI75y4LVTEz75TJJRDMdl4Qz ddY3Tyf5X1CSbwJ3wcTiGK92646QtpxYc6eyqIlJtpkF/GL71Z0gq+zyYR7Rgkp/x/ig bped34RonJzZRoqE7GtrA4p6o76aPFtyFHTZP36sIkDGfjEbBgaO3NzSSm3QMQqds6pD UHvg== X-Gm-Message-State: ALoCoQk8KXeXd3abHadhd1e8XIa34uErtxaCL8btGyQ+t2AQI4EmjzwjmF6YQ4lP21HUxM8236K5 X-Received: by 10.194.235.71 with SMTP id uk7mr1670170wjc.13.1428660963405; Fri, 10 Apr 2015 03:16:03 -0700 (PDT) From: Sibananda Sahu References: <0a2b68c0f411b50a276ce00a8d8b15ee@mail.gmail.com> <444mp2avfy.fsf@lowell-desk.lan> <78386e1c45b998c5ae63a63301d1ac23@mail.gmail.com> <44wq1posa6.fsf@lowell-desk.lan> In-Reply-To: <44wq1posa6.fsf@lowell-desk.lan> MIME-Version: 1.0 X-Mailer: Microsoft Outlook 14.0 Thread-Index: AQIBBheFu/GSn/ikPV4vQevJE0vKPQKjEDVRAgPoozsAyWfE7Zy5XwhA Date: Fri, 10 Apr 2015 15:46:02 +0530 Message-ID: <58e98b85960a28cbedc9c3108ecc3673@mail.gmail.com> Subject: RE: How to know the system state if the system is going for halt or poweroff or reboot in FreeBSD To: freebsd-questions@freebsd.org Content-Type: text/plain; charset=UTF-8 X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 10 Apr 2015 10:16:11 -0000 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 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 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.