Dhruvaraj Subhashchandran | fef66a9 | 2020-09-06 13:10:59 -0500 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include "dump_manager.hpp" |
| 4 | #include "dump_utils.hpp" |
| 5 | #include "watch.hpp" |
| 6 | #include "xyz/openbmc_project/Dump/Internal/Create/server.hpp" |
| 7 | |
Marri Devender Rao | 3ed02c3 | 2022-06-28 23:12:14 -0500 | [diff] [blame] | 8 | #include <sdeventplus/source/child.hpp> |
Dhruvaraj Subhashchandran | fef66a9 | 2020-09-06 13:10:59 -0500 | [diff] [blame] | 9 | #include <xyz/openbmc_project/Dump/Create/server.hpp> |
| 10 | |
Jayanth Othayoth | 0af74a5 | 2021-04-08 03:55:21 -0500 | [diff] [blame] | 11 | #include <filesystem> |
Marri Devender Rao | 3ed02c3 | 2022-06-28 23:12:14 -0500 | [diff] [blame] | 12 | #include <map> |
| 13 | |
Dhruvaraj Subhashchandran | fef66a9 | 2020-09-06 13:10:59 -0500 | [diff] [blame] | 14 | namespace phosphor |
| 15 | { |
| 16 | namespace dump |
| 17 | { |
| 18 | namespace bmc |
| 19 | { |
| 20 | namespace internal |
| 21 | { |
| 22 | |
| 23 | class Manager; |
| 24 | |
| 25 | } // namespace internal |
| 26 | |
Patrick Williams | 9b18bf2 | 2022-07-22 19:26:55 -0500 | [diff] [blame] | 27 | using CreateIface = sdbusplus::server::object_t< |
Dhruvaraj Subhashchandran | fef66a9 | 2020-09-06 13:10:59 -0500 | [diff] [blame] | 28 | sdbusplus::xyz::openbmc_project::Dump::server::Create>; |
| 29 | |
| 30 | using UserMap = phosphor::dump::inotify::UserMap; |
| 31 | |
| 32 | using Type = |
| 33 | sdbusplus::xyz::openbmc_project::Dump::Internal::server::Create::Type; |
| 34 | |
Dhruvaraj Subhashchandran | fef66a9 | 2020-09-06 13:10:59 -0500 | [diff] [blame] | 35 | using Watch = phosphor::dump::inotify::Watch; |
Marri Devender Rao | 3ed02c3 | 2022-06-28 23:12:14 -0500 | [diff] [blame] | 36 | using ::sdeventplus::source::Child; |
Dhruvaraj Subhashchandran | fef66a9 | 2020-09-06 13:10:59 -0500 | [diff] [blame] | 37 | // Type to dreport type string map |
| 38 | static const std::map<Type, std::string> TypeMap = { |
| 39 | {Type::ApplicationCored, "core"}, |
| 40 | {Type::UserRequested, "user"}, |
| 41 | {Type::InternalFailure, "elog"}, |
George Liu | ff92ffe | 2021-02-09 15:01:53 +0800 | [diff] [blame] | 42 | {Type::Checkstop, "checkstop"}, |
| 43 | {Type::Ramoops, "ramoops"}}; |
Dhruvaraj Subhashchandran | fef66a9 | 2020-09-06 13:10:59 -0500 | [diff] [blame] | 44 | |
| 45 | /** @class Manager |
| 46 | * @brief OpenBMC Dump manager implementation. |
| 47 | * @details A concrete implementation for the |
| 48 | * xyz.openbmc_project.Dump.Create DBus API |
| 49 | */ |
Jayanth Othayoth | 0af74a5 | 2021-04-08 03:55:21 -0500 | [diff] [blame] | 50 | class Manager : |
| 51 | virtual public CreateIface, |
| 52 | virtual public phosphor::dump::Manager |
Dhruvaraj Subhashchandran | fef66a9 | 2020-09-06 13:10:59 -0500 | [diff] [blame] | 53 | { |
| 54 | friend class internal::Manager; |
| 55 | |
| 56 | public: |
| 57 | Manager() = delete; |
| 58 | Manager(const Manager&) = default; |
| 59 | Manager& operator=(const Manager&) = delete; |
| 60 | Manager(Manager&&) = delete; |
| 61 | Manager& operator=(Manager&&) = delete; |
| 62 | virtual ~Manager() = default; |
| 63 | |
| 64 | /** @brief Constructor to put object onto bus at a dbus path. |
| 65 | * @param[in] bus - Bus to attach to. |
| 66 | * @param[in] event - Dump manager sd_event loop. |
| 67 | * @param[in] path - Path to attach at. |
| 68 | * @param[in] baseEntryPath - Base path for dump entry. |
| 69 | * @param[in] filePath - Path where the dumps are stored. |
| 70 | */ |
Patrick Williams | 9b18bf2 | 2022-07-22 19:26:55 -0500 | [diff] [blame] | 71 | Manager(sdbusplus::bus_t& bus, const EventPtr& event, const char* path, |
Dhruvaraj Subhashchandran | fef66a9 | 2020-09-06 13:10:59 -0500 | [diff] [blame] | 72 | const std::string& baseEntryPath, const char* filePath) : |
| 73 | CreateIface(bus, path), |
| 74 | phosphor::dump::Manager(bus, path, baseEntryPath), |
| 75 | eventLoop(event.get()), |
| 76 | dumpWatch( |
| 77 | eventLoop, IN_NONBLOCK, IN_CLOSE_WRITE | IN_CREATE, EPOLLIN, |
| 78 | filePath, |
| 79 | std::bind(std::mem_fn(&phosphor::dump::bmc::Manager::watchCallback), |
| 80 | this, std::placeholders::_1)), |
| 81 | dumpDir(filePath) |
Jayanth Othayoth | 0af74a5 | 2021-04-08 03:55:21 -0500 | [diff] [blame] | 82 | {} |
Dhruvaraj Subhashchandran | fef66a9 | 2020-09-06 13:10:59 -0500 | [diff] [blame] | 83 | |
| 84 | /** @brief Implementation of dump watch call back |
| 85 | * @param [in] fileInfo - map of file info path:event |
| 86 | */ |
| 87 | void watchCallback(const UserMap& fileInfo); |
| 88 | |
| 89 | /** @brief Construct dump d-bus objects from their persisted |
| 90 | * representations. |
| 91 | */ |
| 92 | void restore() override; |
| 93 | |
| 94 | /** @brief Implementation for CreateDump |
Dhruvaraj Subhashchandran | 6ccb50e | 2020-10-29 09:33:18 -0500 | [diff] [blame] | 95 | * Method to create a BMC dump entry when user requests for a new BMC dump |
Dhruvaraj Subhashchandran | fef66a9 | 2020-09-06 13:10:59 -0500 | [diff] [blame] | 96 | * |
Dhruvaraj Subhashchandran | 6ccb50e | 2020-10-29 09:33:18 -0500 | [diff] [blame] | 97 | * @return object_path - The object path of the new dump entry. |
Dhruvaraj Subhashchandran | fef66a9 | 2020-09-06 13:10:59 -0500 | [diff] [blame] | 98 | */ |
Dhruvaraj Subhashchandran | 969f9a5 | 2020-10-30 01:42:39 -0500 | [diff] [blame] | 99 | sdbusplus::message::object_path |
Dhruvaraj Subhashchandran | ddc3366 | 2021-07-19 09:28:42 -0500 | [diff] [blame] | 100 | createDump(phosphor::dump::DumpCreateParams params) override; |
Dhruvaraj Subhashchandran | fef66a9 | 2020-09-06 13:10:59 -0500 | [diff] [blame] | 101 | |
| 102 | private: |
| 103 | /** @brief Create Dump entry d-bus object |
| 104 | * @param[in] fullPath - Full path of the Dump file name |
| 105 | */ |
Jayanth Othayoth | 3fc6df4 | 2021-04-08 03:45:24 -0500 | [diff] [blame] | 106 | void createEntry(const std::filesystem::path& fullPath); |
Dhruvaraj Subhashchandran | fef66a9 | 2020-09-06 13:10:59 -0500 | [diff] [blame] | 107 | |
| 108 | /** @brief Capture BMC Dump based on the Dump type. |
| 109 | * @param[in] type - Type of the Dump. |
| 110 | * @param[in] fullPaths - List of absolute paths to the files |
| 111 | * to be included as part of Dump package. |
| 112 | * @return id - The Dump entry id number. |
| 113 | */ |
| 114 | uint32_t captureDump(Type type, const std::vector<std::string>& fullPaths); |
| 115 | |
Dhruvaraj Subhashchandran | 3604710 | 2023-06-29 03:46:25 -0500 | [diff] [blame] | 116 | /** @brief Capture BMC Dump based on the Dump type. |
| 117 | * @param[in] type - Type of the dump to pass to dreport |
| 118 | * @param[in] path - An absolute path to the file |
| 119 | * to be included as part of Dump package. |
| 120 | * @return id - The Dump entry id number. |
| 121 | */ |
| 122 | uint32_t captureDump(DumpTypes type, const std::string& path); |
| 123 | |
Dhruvaraj Subhashchandran | fef66a9 | 2020-09-06 13:10:59 -0500 | [diff] [blame] | 124 | /** @brief Remove specified watch object pointer from the |
| 125 | * watch map and associated entry from the map. |
| 126 | * @param[in] path - unique identifier of the map |
| 127 | */ |
Jayanth Othayoth | 3fc6df4 | 2021-04-08 03:45:24 -0500 | [diff] [blame] | 128 | void removeWatch(const std::filesystem::path& path); |
Dhruvaraj Subhashchandran | fef66a9 | 2020-09-06 13:10:59 -0500 | [diff] [blame] | 129 | |
| 130 | /** @brief Calculate per dump allowed size based on the available |
| 131 | * size in the dump location. |
| 132 | * @returns dump size in kilobytes. |
| 133 | */ |
| 134 | size_t getAllowedSize(); |
| 135 | |
| 136 | /** @brief sdbusplus Dump event loop */ |
| 137 | EventPtr eventLoop; |
| 138 | |
| 139 | /** @brief Dump main watch object */ |
| 140 | Watch dumpWatch; |
| 141 | |
| 142 | /** @brief Path to the dump file*/ |
| 143 | std::string dumpDir; |
| 144 | |
Marri Devender Rao | 73953b8 | 2022-02-15 09:15:42 -0600 | [diff] [blame] | 145 | /** @brief Flag to reject user intiated dump if a dump is in progress*/ |
| 146 | // TODO: https://github.com/openbmc/phosphor-debug-collector/issues/19 |
| 147 | static bool fUserDumpInProgress; |
| 148 | |
Dhruvaraj Subhashchandran | fef66a9 | 2020-09-06 13:10:59 -0500 | [diff] [blame] | 149 | /** @brief Child directory path and its associated watch object map |
| 150 | * [path:watch object] |
| 151 | */ |
Jayanth Othayoth | 3fc6df4 | 2021-04-08 03:45:24 -0500 | [diff] [blame] | 152 | std::map<std::filesystem::path, std::unique_ptr<Watch>> childWatchMap; |
Marri Devender Rao | 3ed02c3 | 2022-06-28 23:12:14 -0500 | [diff] [blame] | 153 | |
| 154 | /** @brief map of SDEventPlus child pointer added to event loop */ |
| 155 | std::map<pid_t, std::unique_ptr<Child>> childPtrMap; |
Dhruvaraj Subhashchandran | fef66a9 | 2020-09-06 13:10:59 -0500 | [diff] [blame] | 156 | }; |
| 157 | |
| 158 | } // namespace bmc |
| 159 | } // namespace dump |
| 160 | } // namespace phosphor |