xref: /openbmc/phosphor-state-manager/README.md (revision eab2ea348d0a2a1b444b6a2c3c4814f277db9870)
1d6fe3150SAndrew Geissler# Phosphor State Manager Documentation
2d6fe3150SAndrew Geissler
3d6fe3150SAndrew GeisslerThis repository contains the software responsible for tracking and controlling
42138f45cSAndrew Geisslerthe state of different objects within OpenBMC. This currently includes the BMC,
52138f45cSAndrew GeisslerChassis, Host, and Hypervisor. The most critical feature of
62138f45cSAndrew Geisslerphosphor-state-manager software is its support for requests to power on and off
72138f45cSAndrew Geisslerthe system by the user.
8d6fe3150SAndrew Geissler
9d6fe3150SAndrew GeisslerThis software also enforces any restore policy (i.e. auto power on system after
10d6fe3150SAndrew Geisslera system power event or bmc reset) and ensures its states are updated correctly
11d6fe3150SAndrew Geisslerin situations where the BMC is rebooted and the chassis or host are in
12d6fe3150SAndrew Geissleron/running states.
13d6fe3150SAndrew Geissler
14d6fe3150SAndrew GeisslerThis repository also provides a command line tool, obmcutil, which provides
15d6fe3150SAndrew Geisslerbasic command line support to query and control phosphor-state-manager
16d6fe3150SAndrew Geisslerapplications running within an OpenBMC system. This tool itself runs within an
17d6fe3150SAndrew GeisslerOpenBMC system and utilizes D-Bus APIs. These D-Bus APIs are used for
18d6fe3150SAndrew Geisslerdevelopment and debug and are not intended for end users.
19d6fe3150SAndrew Geissler
20d6fe3150SAndrew GeisslerAs with all OpenBMC applications, interfaces and properties within
21d6fe3150SAndrew Geisslerphosphor-state-manager are D-Bus interfaces. These interfaces are then used
22d6fe3150SAndrew Geisslerby external interface protocols, such as Redfish and IPMI, to report and
23d6fe3150SAndrew Geisslercontrol state to/by the end user.
24d6fe3150SAndrew Geissler
25d6fe3150SAndrew Geissler## State Tracking and Control
26d6fe3150SAndrew Geissler
27d6fe3150SAndrew Geisslerphosphor-state-manager makes extensive use of systemd. There is a writeup
28d6fe3150SAndrew Geissler[here][1] with an overview of systemd and its use by OpenBMC.
29d6fe3150SAndrew Geissler
30d6fe3150SAndrew Geisslerphosphor-state-manager follows some basics design guidelines in its
31d6fe3150SAndrew Geisslerimplementation and use of systemd:
32d6fe3150SAndrew Geissler- Keep the different objects as independent as possible (host, chassis, bmc)
33d6fe3150SAndrew Geissler- Use systemd targets for everything and keep the code within
34d6fe3150SAndrew Geissler  phosphor-state-manager minimal
35d6fe3150SAndrew Geissler- Ensure it can support required external interfaces, but don't necessarily
36d6fe3150SAndrew Geissler  create 1x1 mappings otherwise every external interface will end up with its
37d6fe3150SAndrew Geissler  own special chassis or host state request
38d6fe3150SAndrew Geissler- If something like a hard power off can be done by just turning off the
39d6fe3150SAndrew Geissler  chassis, don't provide a command in the host to do the same thing
40d6fe3150SAndrew Geissler
41d6fe3150SAndrew Geisslerphosphor-state-manager implements states and state requests as defined in
42d6fe3150SAndrew Geisslerphosphor-dbus-interfaces for each object it supports.
43d6fe3150SAndrew Geissler- [bmc][2]: The BMC has very minimal states. It is `Ready` once all services
44d6fe3150SAndrew Geissler  within the default.target have executed. The only state change request you
45d6fe3150SAndrew Geissler  can make of the BMC is for it to reboot itself.
46d6fe3150SAndrew Geissler  - CurrentBMCState: NotReady, Ready
47d6fe3150SAndrew Geissler  - RequestedBMCTransition: Reboot
48d6fe3150SAndrew Geissler- [chassis][3]: The chassis represents the physical hardware in which the system
49d6fe3150SAndrew Geissler  is contained. It usually has the power supplies, fans, and other hardware
50d6fe3150SAndrew Geissler  associated with it. It can be either `On` or `Off`.
51d6fe3150SAndrew Geissler  - CurrentPowerState: On, Off
52d6fe3150SAndrew Geissler  - RequestedPowerTransition: On, Off
53d6fe3150SAndrew Geissler- [host][4]: The host represents the software running on the system. In most
54d6fe3150SAndrew Geissler  cases this is an operating system of some sort. The host can be `Off`,
55*eab2ea34SAndrew Geissler  `Running`, `TransitioningToRunning`, `TransitioningToOff`,
56*eab2ea34SAndrew Geissler  `Quiesced`(error condition), or in `DiagnosticMode`(collecting diagnostic
57*eab2ea34SAndrew Geissler  data for a failure)
58*eab2ea34SAndrew Geissler  - CurrentHostState: Off, Running, TransitioningToRunning, TransitioningToOff,
59*eab2ea34SAndrew Geissler    Quiesced, DiagnosticMode
60c9844634SAndrew Geissler  - RequestedHostTransition: Off, On, Reboot, GracefulWarmReboot,
61c9844634SAndrew Geissler    ForceWarmReboot
622138f45cSAndrew Geissler- [hypervisor][4]: The hypervisor is an optional package systems can install
632138f45cSAndrew Geissler  which tracks the state of the hypervisor on the system. This state manager
642138f45cSAndrew Geissler  object implements a limited subset of the host D-Bus interface.
652138f45cSAndrew Geissler  - CurrentHostState: Standby, TransitionToRunning, Running, Off, Quiesced
662138f45cSAndrew Geissler  - RequestedHostTransition: On
67d6fe3150SAndrew Geissler
68d6fe3150SAndrew GeisslerAs noted above, phosphor-state-manager provides a command line tool,
69d6fe3150SAndrew Geissler[obmcutil][5], which takes a `state` parameter. This will use D-Bus commands to
70d6fe3150SAndrew Geisslerretrieve the above states and present them to the user. It also provides other
71d6fe3150SAndrew Geisslercommands which will send the appropriate D-Bus commands to the above properties
72d6fe3150SAndrew Geisslerto power on/off the chassis and host (see `obmcutil --help` within an OpenBMC
73d6fe3150SAndrew Geisslersystem).
74d6fe3150SAndrew Geissler
75d6fe3150SAndrew GeisslerThe above objects also implement other D-Bus objects like power on hours, boot
76d6fe3150SAndrew Geisslerprogress, reboot attempts, and operating system status. These D-Bus objects are
77d6fe3150SAndrew Geissleralso defined out in the phosphor-dbus-interfaces repository.
78d6fe3150SAndrew Geissler
79d6fe3150SAndrew Geissler## Restore Policy on Power Events
80d6fe3150SAndrew Geissler
81d6fe3150SAndrew GeisslerThe [RestorePolicy][6] defines the behavior the user wants when the BMC is
82d6fe3150SAndrew Geisslerreset. If the chassis or host is on/running then this service will not run.
83d6fe3150SAndrew GeisslerIf they are off then the `RestorePolicy` will be read and executed by
84d6fe3150SAndrew Geisslerphosphor-state-manager code.
85d6fe3150SAndrew Geissler
86d6fe3150SAndrew Geissler## BMC Reset with Host and/or Chassis On
87d6fe3150SAndrew Geissler
88d6fe3150SAndrew GeisslerIn situations where the BMC is reset and the chassis and host are on and
89d6fe3150SAndrew Geisslerrunning, its critical that the BMC software do two things:
90d6fe3150SAndrew Geissler- Never impact the state of the system (causing a power off of a running system
91d6fe3150SAndrew Geissleris very bad)
92d6fe3150SAndrew Geissler- Ensure the BMC, Chassis, and Host states accurately represent the state of the
93d6fe3150SAndrew Geisslersystem.
94d6fe3150SAndrew Geissler
95d6fe3150SAndrew GeisslerNote that some of this logic is provided via service files in system-specific
96d6fe3150SAndrew Geisslermeta layers. That is because the logic to determine if the chassis is on or
97d6fe3150SAndrew Geisslerif the host is running can vary from system to system. The requirement to
98d6fe3150SAndrew Geisslercreate the files defined below and ensure the common targets go active is a
99d6fe3150SAndrew Geisslermust for anyone wishing to enable this feature.
100d6fe3150SAndrew Geissler
101d6fe3150SAndrew Geisslerphosphor-state-manager discovers state vs. trying to cache and save states. This
102d6fe3150SAndrew Geisslerensure it's always getting the most accurate state information. It discovers the
103d6fe3150SAndrew Geisslerchassis state by checking the `pgood` value from the power application. If it
104d6fe3150SAndrew Geisslerdetermines that power is on then it will do the following:
105d6fe3150SAndrew Geissler- Create a file called /run/openbmc/chassis@0-on
106d6fe3150SAndrew Geissler  - The presence of this file tells the services to alter their behavior because
107d6fe3150SAndrew Geissler    the chassis is already powered on
108d6fe3150SAndrew Geissler- Start the obmc-chassis-poweron@0.target
109d6fe3150SAndrew Geissler  - The majority of services in this target will "fake start" due to the file
110d6fe3150SAndrew Geissler    being present. They will report to systemd that they started and ran
111d6fe3150SAndrew Geissler    successfully but they actually do nothing. This is what you would want in
112d6fe3150SAndrew Geissler    this case. Power is already on so you don't want to run the services to turn
113d6fe3150SAndrew Geissler    power on. You do want to get the obmc-chassis-poweron@0.target in the Active
114d6fe3150SAndrew Geissler    state though so that the chassis object within phosphor-state-manager will
115d6fe3150SAndrew Geissler    correctly report that the chassis is `On`
116d6fe3150SAndrew Geissler- Start a service to check if the host is on
117d6fe3150SAndrew Geissler
1184a4c1a69SAndrew GeisslerThe chassis@0-on file is removed once the obmc-chassis-poweron@0.target becomes
1194a4c1a69SAndrew Geissleractive (i.e. all service have been successfully started which are wanted or
1204a4c1a69SAndrew Geisslerrequired by this target).
121d6fe3150SAndrew Geissler
122d6fe3150SAndrew GeisslerThe logic to check if the host is on sends a command to the host, and if a
123d6fe3150SAndrew Geisslerresponse is received then similar logic to chassis is done:
124d6fe3150SAndrew Geissler- Create a file called /run/openbmc/host@0-on
125d6fe3150SAndrew Geissler- Start the obmc-host-start@0.target
126d6fe3150SAndrew Geissler  - Similar to above, most services will not run due to the file being created
127d6fe3150SAndrew Geissler    and their service files implementing a
128d6fe3150SAndrew Geissler    "ConditionPathExists=!/run/openbmc/host@0-request"
129d6fe3150SAndrew Geissler
1304a4c1a69SAndrew GeisslerThe host@0-on file is removed once the obmc-host-start@0.target and
1314a4c1a69SAndrew Geisslerobmc-host-startmin@0.target become active (i.e. all service have been
1324a4c1a69SAndrew Geisslersuccessfully started which are wanted or required by these targets).
133d6fe3150SAndrew Geissler
134d6fe3150SAndrew Geissler## Building the Code
135d6fe3150SAndrew Geissler```
1364640d48eSAndrew GeisslerTo build this package, do the following steps:
1374640d48eSAndrew Geissler
1384640d48eSAndrew Geissler    1. meson build
1394640d48eSAndrew Geissler    2. ninja -C build
1404640d48eSAndrew Geissler
1414640d48eSAndrew GeisslerTo clean the repository again run `rm -rf build`.
142d6fe3150SAndrew Geissler```
143d6fe3150SAndrew Geissler
144a6e7bbf0SGunnar Mills[1]: https://github.com/openbmc/docs/blob/master/architecture/openbmc-systemd.md
1451e91dc63SKonstantin Aladyshev[2]: https://github.com/openbmc/phosphor-dbus-interfaces/blob/master/yaml/xyz/openbmc_project/State/BMC.interface.yaml
1461e91dc63SKonstantin Aladyshev[3]: https://github.com/openbmc/phosphor-dbus-interfaces/blob/master/yaml/xyz/openbmc_project/State/Chassis.interface.yaml
1471e91dc63SKonstantin Aladyshev[4]: https://github.com/openbmc/phosphor-dbus-interfaces/blob/master/yaml/xyz/openbmc_project/State/Host.interface.yaml
148d6fe3150SAndrew Geissler[5]: https://github.com/openbmc/phosphor-state-manager/blob/master/obmcutil
1491e91dc63SKonstantin Aladyshev[6]: https://github.com/openbmc/phosphor-dbus-interfaces/blob/master/yaml/xyz/openbmc_project/Control/Power/RestorePolicy.interface.yaml
150