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