From owner-freebsd-questions@FreeBSD.ORG Mon Apr 6 08:57:54 2015 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 64F963E8 for ; Mon, 6 Apr 2015 08:57:54 +0000 (UTC) Received: from m132-178.yeah.net (m132-178.yeah.net [123.58.178.132]) by mx1.freebsd.org (Postfix) with ESMTP id 65A709FD for ; Mon, 6 Apr 2015 08:57:53 +0000 (UTC) Received: from info7$hengyiev.com ( [183.31.201.245] ) by ajax-webmail-wmsvr2 (Coremail) ; Mon, 6 Apr 2015 16:49:22 +0800 (CST) X-Originating-IP: [183.31.201.245] Date: Mon, 6 Apr 2015 16:49:22 +0800 (CST) From: info To: freebsd-questions@FreeBSD.ORG Subject: Inquery X-Priority: 3 X-Mailer: Coremail Webmail Server Version SP_ntes V3.5 build 20140422(26738.6344) Copyright (c) 2002-2015 www.mailtech.cn 163-hosting MIME-Version: 1.0 Message-ID: <680e4e91.23ea.14c8deb7ac3.Coremail.info7@hengyiev.com> X-CM-TRANSID: ymR4CkB5VkKSSCJVhwcKAA--.4931W X-CM-SenderInfo: 5lqi0lw6kh0wh1lh4hhfrp/1tbiBR7T9VSYSYXS8AAKsV X-Coremail-Antispam: 1U5529EdanIXcx71UUUUU7vcSsGvfC2KfnxnUU== Content-Type: text/plain; charset=GBK Content-Transfer-Encoding: base64 X-Content-Filtered-By: Mailman/MimeDel 2.1.18-1 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: Mon, 06 Apr 2015 08:57:54 -0000 RGVhciBNYW5hZ2VyLAoKCiBHb29kIGRheSEKCiAgT3VyIGNvbXBhbnkgbmVlZHMgdG8gcHVyY2hh c2UgSGlnaC1wb2xlIGxhbXAuICBJZiB5b3UgYXJlIHRoZSBIaWdoLXBvbGUgbGFtcCBwcm9kdWNl ciBwbGVhc2UgY29udGFjdCB1cyAuIFBscyBvZmZlciB1cyB0aGUgcHJvZHVjdCBtYW51ZmFjdHVy ZSBtYXRlcmlhbCxmdW5jdGlvbixwaWN0dXJlIGFuZCBwcmljZS4KCnBseiBxdW90ZSBwcmljZSBp biBVU0QvRVVSIGFzIHNvb24gYXMgcG9zc2libGUgLgoKV2UgU2luY2VyZWx5IGhvcGUgdG8gZXN0 YWJsaXNoIGEgbG9uZy10ZXJtIHJlbGF0aW9uc2hpcCB3aXRoIHlvdXIgZXN0ZWVtZWQgY29tcGFu eS4KCiAKClRoYW5rcyAKCkJydWNlCgpURUw6MDA4Ni0xMzUyNzI0MTAzNAoKIAoKRS1tYWlsOmhr LmluZm9AaGF6ZmlsLmNvbQ== From owner-freebsd-questions@FreeBSD.ORG Mon Apr 6 09:37:58 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 34DD8C1D for ; Mon, 6 Apr 2015 09:37:58 +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 E5501DD3 for ; Mon, 6 Apr 2015 09:37:57 +0000 (UTC) Received: by wiun10 with SMTP id n10so29326391wiu.1 for ; Mon, 06 Apr 2015 02:37:50 -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:cc:content-type; bh=XOaOqqHQsYZr2MT2fnFTVRjyDmVPuQdWufCrOyz6n5s=; b=OoEjM8XGfpnzxiWXvoQiod76fnrRzK4bxQxEKRWERYe1yPCvK2oBrx6mMWX6VN7YXz VvAxJNFjKSRClmSiL9r0r148TKTuD18ClZ4nCpPHEyhEGsW00JnfLSlpVLe5owziks1j rSSv/ZoWaBTZHnj7O18GZaVcmVQTAhtTqcNBWmxqly28yTtYfuN69znNBi+A2r+vn0n/ 8PrEynyOoOnqLkKBMLKTVWnq5ui6RNkXPvX0Qg8VjKUbr0j+SXtMe9RQ4u8s6CWJf5cj DnMMxChSvSRTRGG5l86piwm+9K8SFIAYJQNr4XCcX/42mJWt3LOtRvZinniooC6Hul/Y YAGg== X-Gm-Message-State: ALoCoQlZuoHeK7F/GyO3OnJ84J5q4dkpykdxDGTSipgdgwOKcj9d0OZ3bEowQQgyWfCr/QKL/IYc X-Received: by 10.194.11.9 with SMTP id m9mr28727704wjb.82.1428313070387; Mon, 06 Apr 2015 02:37:50 -0700 (PDT) From: Sibananda Sahu References: <0a2b68c0f411b50a276ce00a8d8b15ee@mail.gmail.com> <444mp2avfy.fsf@lowell-desk.lan> In-Reply-To: <444mp2avfy.fsf@lowell-desk.lan> MIME-Version: 1.0 X-Mailer: Microsoft Outlook 14.0 Thread-Index: AQIBBheFu/GSn/ikPV4vQevJE0vKPQKjEDVRnMlyKgA= Date: Mon, 6 Apr 2015 15:07:48 +0530 Message-ID: <78386e1c45b998c5ae63a63301d1ac23@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 Cc: freebsd-questions-local@be-well.ilk.org 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: Mon, 06 Apr 2015 09:37:58 -0000 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@be-well.ilk.org] Sent: Tuesday, March 31, 2015 5:29 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: > 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.