Matthew Barth | c95c527 | 2020-06-15 19:51:13 -0500 | [diff] [blame] | 1 | /** |
| 2 | * Copyright © 2020 IBM Corporation |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | #pragma once |
| 17 | |
| 18 | #include "fan.hpp" |
Matt Spinler | e892e39 | 2020-10-14 13:21:31 -0500 | [diff] [blame] | 19 | #include "power_off_rule.hpp" |
| 20 | #include "power_state.hpp" |
Matthew Barth | c95c527 | 2020-06-15 19:51:13 -0500 | [diff] [blame] | 21 | #include "tach_sensor.hpp" |
| 22 | #include "trust_manager.hpp" |
| 23 | #include "types.hpp" |
| 24 | |
| 25 | #include <nlohmann/json.hpp> |
| 26 | #include <sdbusplus/bus.hpp> |
| 27 | #include <sdeventplus/event.hpp> |
Matthew Barth | d06905c | 2020-06-12 08:13:06 -0500 | [diff] [blame] | 28 | #include <sdeventplus/source/signal.hpp> |
Matthew Barth | c95c527 | 2020-06-15 19:51:13 -0500 | [diff] [blame] | 29 | |
| 30 | #include <memory> |
| 31 | #include <optional> |
| 32 | #include <vector> |
| 33 | |
| 34 | namespace phosphor::fan::monitor |
| 35 | { |
| 36 | |
| 37 | using json = nlohmann::json; |
| 38 | |
| 39 | class System |
| 40 | { |
| 41 | public: |
| 42 | System() = delete; |
| 43 | System(const System&) = delete; |
| 44 | System(System&&) = delete; |
| 45 | System& operator=(const System&) = delete; |
| 46 | System& operator=(System&&) = delete; |
| 47 | ~System() = default; |
| 48 | |
| 49 | /** |
| 50 | * Constructor |
| 51 | * Parses and populates the fan monitor trust groups and list of fans |
| 52 | * |
| 53 | * @param[in] mode - mode of fan monitor |
| 54 | * @param[in] bus - sdbusplus bus object |
| 55 | * @param[in] event - event loop reference |
| 56 | */ |
| 57 | System(Mode mode, sdbusplus::bus::bus& bus, |
| 58 | const sdeventplus::Event& event); |
| 59 | |
Matthew Barth | d06905c | 2020-06-12 08:13:06 -0500 | [diff] [blame] | 60 | /** |
| 61 | * @brief Callback function to handle receiving a HUP signal to reload the |
| 62 | * JSON configuration. |
| 63 | */ |
| 64 | void sighupHandler(sdeventplus::source::Signal&, |
| 65 | const struct signalfd_siginfo*); |
| 66 | |
Matt Spinler | b63aa09 | 2020-10-14 09:45:11 -0500 | [diff] [blame] | 67 | /** |
| 68 | * @brief Called from the fan when it changes either |
| 69 | * present or functional status to update the |
| 70 | * fan health map. |
| 71 | * |
| 72 | * @param[in] fan - The fan that changed |
| 73 | */ |
| 74 | void fanStatusChange(const Fan& fan); |
| 75 | |
Matt Spinler | f13b42e | 2020-10-26 15:29:49 -0500 | [diff] [blame^] | 76 | /** |
| 77 | * @brief Called when a fan sensor's error timer expires, which |
| 78 | * happens when the sensor has been nonfunctional for a |
| 79 | * certain amount of time. An event log will be created. |
| 80 | * |
| 81 | * @param[in] fan - The parent fan of the sensor |
| 82 | * @param[in] sensor - The faulted sensor |
| 83 | */ |
| 84 | void sensorErrorTimerExpired(const Fan& fan, const TachSensor& sensor); |
| 85 | |
Matthew Barth | c95c527 | 2020-06-15 19:51:13 -0500 | [diff] [blame] | 86 | private: |
| 87 | /* The mode of fan monitor */ |
| 88 | Mode _mode; |
| 89 | |
| 90 | /* The sdbusplus bus object */ |
| 91 | sdbusplus::bus::bus& _bus; |
| 92 | |
| 93 | /* The event loop reference */ |
| 94 | const sdeventplus::Event& _event; |
| 95 | |
| 96 | /* Trust manager of trust groups */ |
| 97 | std::unique_ptr<phosphor::fan::trust::Manager> _trust; |
| 98 | |
| 99 | /* List of fan objects to monitor */ |
| 100 | std::vector<std::unique_ptr<Fan>> _fans; |
| 101 | |
| 102 | /** |
Matt Spinler | b63aa09 | 2020-10-14 09:45:11 -0500 | [diff] [blame] | 103 | * @brief The latest health of all the fans |
| 104 | */ |
| 105 | FanHealth _fanHealth; |
| 106 | |
| 107 | /** |
Matt Spinler | e892e39 | 2020-10-14 13:21:31 -0500 | [diff] [blame] | 108 | * @brief The object to watch the power state |
| 109 | */ |
| 110 | std::unique_ptr<PowerState> _powerState; |
| 111 | |
| 112 | /** |
| 113 | * @brief The power off rules, for shutting down the system |
| 114 | * due to fan failures. |
| 115 | */ |
| 116 | std::vector<std::unique_ptr<PowerOffRule>> _powerOffRules; |
| 117 | |
| 118 | /** |
Matt Spinler | f13b42e | 2020-10-26 15:29:49 -0500 | [diff] [blame^] | 119 | * @brief The number of concurrently nonfunctional fan sensors |
| 120 | * there must be for an event log created due to a |
| 121 | * nonfunctional fan sensor to have an Error severity as |
| 122 | * opposed to an Informational one. |
| 123 | */ |
| 124 | std::optional<size_t> _numNonfuncSensorsBeforeError; |
| 125 | |
| 126 | /** |
| 127 | * @brief Captures tach sensor data as JSON for use in |
| 128 | * fan fault and fan missing event logs. |
| 129 | * |
| 130 | * @return json - The JSON data |
| 131 | */ |
| 132 | json captureSensorData(); |
| 133 | |
| 134 | /** |
Matthew Barth | c95c527 | 2020-06-15 19:51:13 -0500 | [diff] [blame] | 135 | * @brief Retrieve the configured trust groups |
| 136 | * |
| 137 | * @param[in] jsonObj - JSON object to parse from |
| 138 | * |
| 139 | * @return List of functions applied on trust groups |
| 140 | */ |
| 141 | const std::vector<CreateGroupFunction> getTrustGroups(const json& jsonObj); |
| 142 | |
| 143 | /** |
Matthew Barth | d06905c | 2020-06-12 08:13:06 -0500 | [diff] [blame] | 144 | * @brief Set the trust manager's list of trust group functions |
| 145 | * |
| 146 | * @param[in] groupFuncs - list of trust group functions |
| 147 | */ |
| 148 | void setTrustMgr(const std::vector<CreateGroupFunction>& groupFuncs); |
| 149 | |
| 150 | /** |
Matthew Barth | c95c527 | 2020-06-15 19:51:13 -0500 | [diff] [blame] | 151 | * @brief Retrieve the configured fan definitions |
| 152 | * |
| 153 | * @param[in] jsonObj - JSON object to parse from |
| 154 | * |
| 155 | * @return List of fan definition data on the fans configured |
| 156 | */ |
| 157 | const std::vector<FanDefinition> getFanDefinitions(const json& jsonObj); |
Matthew Barth | d06905c | 2020-06-12 08:13:06 -0500 | [diff] [blame] | 158 | |
| 159 | /** |
| 160 | * @brief Set the list of fans to be monitored |
| 161 | * |
| 162 | * @param[in] fanDefs - list of fan definitions to create fans monitored |
| 163 | */ |
| 164 | void setFans(const std::vector<FanDefinition>& fanDefs); |
Matt Spinler | b63aa09 | 2020-10-14 09:45:11 -0500 | [diff] [blame] | 165 | |
| 166 | /** |
| 167 | * @brief Updates the fan health map entry for the fan passed in |
| 168 | * |
| 169 | * @param[in] fan - The fan to update the health map with |
| 170 | */ |
| 171 | void updateFanHealth(const Fan& fan); |
Matt Spinler | e892e39 | 2020-10-14 13:21:31 -0500 | [diff] [blame] | 172 | |
| 173 | /** |
| 174 | * @brief The function that runs when the power state changes |
| 175 | * |
| 176 | * @param[in] powerStateOn - If power is now on or not |
| 177 | */ |
| 178 | void powerStateChanged(bool powerStateOn); |
| 179 | |
| 180 | /** |
| 181 | * @brief Reads the fault configuration from the JSON config |
| 182 | * file, such as the power off rule configuration. |
| 183 | * |
| 184 | * @param[in] jsonObj - JSON object to parse from |
| 185 | */ |
| 186 | void setFaultConfig(const json& jsonObj); |
Matthew Barth | c95c527 | 2020-06-15 19:51:13 -0500 | [diff] [blame] | 187 | }; |
| 188 | |
| 189 | } // namespace phosphor::fan::monitor |