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