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