1# Phosphor State Manager Documentation 2 3This repository contains the software responsible for tracking and controlling 4the state of different objects within OpenBMC. This currently includes the 5BMC, Chassis, and Host. The most critical feature of phosphor-state-manager 6software is its support for requests to power on and off the system by the user. 7 8This software also enforces any restore policy (i.e. auto power on system after 9a system power event or bmc reset) and ensures its states are updated correctly 10in situations where the BMC is rebooted and the chassis or host are in 11on/running states. 12 13This repository also provides a command line tool, obmcutil, which provides 14basic command line support to query and control phosphor-state-manager 15applications running within an OpenBMC system. This tool itself runs within an 16OpenBMC system and utilizes D-Bus APIs. These D-Bus APIs are used for 17development and debug and are not intended for end users. 18 19As with all OpenBMC applications, interfaces and properties within 20phosphor-state-manager are D-Bus interfaces. These interfaces are then used 21by external interface protocols, such as Redfish and IPMI, to report and 22control state to/by the end user. 23 24## State Tracking and Control 25 26phosphor-state-manager makes extensive use of systemd. There is a writeup 27[here][1] with an overview of systemd and its use by OpenBMC. 28 29phosphor-state-manager follows some basics design guidelines in its 30implementation and use of systemd: 31- Keep the different objects as independent as possible (host, chassis, bmc) 32- Use systemd targets for everything and keep the code within 33 phosphor-state-manager minimal 34- Ensure it can support required external interfaces, but don't necessarily 35 create 1x1 mappings otherwise every external interface will end up with its 36 own special chassis or host state request 37- If something like a hard power off can be done by just turning off the 38 chassis, don't provide a command in the host to do the same thing 39 40phosphor-state-manager implements states and state requests as defined in 41phosphor-dbus-interfaces for each object it supports. 42- [bmc][2]: The BMC has very minimal states. It is `Ready` once all services 43 within the default.target have executed. The only state change request you 44 can make of the BMC is for it to reboot itself. 45 - CurrentBMCState: NotReady, Ready 46 - RequestedBMCTransition: Reboot 47- [chassis][3]: The chassis represents the physical hardware in which the system 48 is contained. It usually has the power supplies, fans, and other hardware 49 associated with it. It can be either `On` or `Off`. 50 - CurrentPowerState: On, Off 51 - RequestedPowerTransition: On, Off 52- [host][4]: The host represents the software running on the system. In most 53 cases this is an operating system of some sort. The host can be `Off`, 54 `Running`, `Quiesced`(error condition), or in `DiagnosticMode`(collecting 55 diagnostic data for a failure) 56 - CurrentHostState: Off, Running, Quiesced, DiagnosticMode 57 - RequestedHostTransition: Off, On, Reboot, GracefulWarmReboot, 58 ForceWarmReboot 59 60As noted above, phosphor-state-manager provides a command line tool, 61[obmcutil][5], which takes a `state` parameter. This will use D-Bus commands to 62retrieve the above states and present them to the user. It also provides other 63commands which will send the appropriate D-Bus commands to the above properties 64to power on/off the chassis and host (see `obmcutil --help` within an OpenBMC 65system). 66 67The above objects also implement other D-Bus objects like power on hours, boot 68progress, reboot attempts, and operating system status. These D-Bus objects are 69also defined out in the phosphor-dbus-interfaces repository. 70 71## Restore Policy on Power Events 72 73The [RestorePolicy][6] defines the behavior the user wants when the BMC is 74reset. If the chassis or host is on/running then this service will not run. 75If they are off then the `RestorePolicy` will be read and executed by 76phosphor-state-manager code. 77 78## BMC Reset with Host and/or Chassis On 79 80In situations where the BMC is reset and the chassis and host are on and 81running, its critical that the BMC software do two things: 82- Never impact the state of the system (causing a power off of a running system 83is very bad) 84- Ensure the BMC, Chassis, and Host states accurately represent the state of the 85system. 86 87Note that some of this logic is provided via service files in system-specific 88meta layers. That is because the logic to determine if the chassis is on or 89if the host is running can vary from system to system. The requirement to 90create the files defined below and ensure the common targets go active is a 91must for anyone wishing to enable this feature. 92 93phosphor-state-manager discovers state vs. trying to cache and save states. This 94ensure it's always getting the most accurate state information. It discovers the 95chassis state by checking the `pgood` value from the power application. If it 96determines that power is on then it will do the following: 97- Create a file called /run/openbmc/chassis@0-on 98 - The presence of this file tells the services to alter their behavior because 99 the chassis is already powered on 100- Start the obmc-chassis-poweron@0.target 101 - The majority of services in this target will "fake start" due to the file 102 being present. They will report to systemd that they started and ran 103 successfully but they actually do nothing. This is what you would want in 104 this case. Power is already on so you don't want to run the services to turn 105 power on. You do want to get the obmc-chassis-poweron@0.target in the Active 106 state though so that the chassis object within phosphor-state-manager will 107 correctly report that the chassis is `On` 108- Start a service to check if the host is on 109 110The chassis@0-on file is removed once the obmc-chassis-poweron@0.target becomes 111active (i.e. all service have been successfully started which are wanted or 112required by this target). 113 114The logic to check if the host is on sends a command to the host, and if a 115response is received then similar logic to chassis is done: 116- Create a file called /run/openbmc/host@0-on 117- Start the obmc-host-start@0.target 118 - Similar to above, most services will not run due to the file being created 119 and their service files implementing a 120 "ConditionPathExists=!/run/openbmc/host@0-request" 121 122The host@0-on file is removed once the obmc-host-start@0.target and 123obmc-host-startmin@0.target become active (i.e. all service have been 124successfully started which are wanted or required by these targets). 125 126## Building the Code 127``` 128To build this package, do the following steps: 129 130 1. meson build 131 2. ninja -C build 132 133To clean the repository again run `rm -rf build`. 134``` 135 136[1]: https://github.com/openbmc/docs/blob/master/architecture/openbmc-systemd.md 137[2]: https://github.com/openbmc/phosphor-dbus-interfaces/blob/master/xyz/openbmc_project/State/BMC.interface.yaml 138[3]: https://github.com/openbmc/phosphor-dbus-interfaces/blob/master/xyz/openbmc_project/State/Chassis.interface.yaml 139[4]: https://github.com/openbmc/phosphor-dbus-interfaces/blob/master/xyz/openbmc_project/State/Host.interface.yaml 140[5]: https://github.com/openbmc/phosphor-state-manager/blob/master/obmcutil 141[6]: https://github.com/openbmc/phosphor-dbus-interfaces/blob/master/xyz/openbmc_project/Control/Power/RestorePolicy.interface.yaml 142