Jayanth Othayoth | a320c7c | 2017-06-14 07:17:21 -0500 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Jayanth Othayoth | cb65ffc | 2018-10-16 08:29:32 -0500 | [diff] [blame] | 3 | #include "config.h" |
Jayanth Othayoth | 671fc7f | 2017-06-14 08:01:41 -0500 | [diff] [blame] | 4 | |
Jayanth Othayoth | a320c7c | 2017-06-14 07:17:21 -0500 | [diff] [blame] | 5 | #include "dump_entry.hpp" |
Jayanth Othayoth | 671fc7f | 2017-06-14 08:01:41 -0500 | [diff] [blame] | 6 | #include "dump_utils.hpp" |
Jayanth Othayoth | bcb174b | 2017-07-02 06:29:24 -0500 | [diff] [blame] | 7 | #include "watch.hpp" |
Jayanth Othayoth | cb65ffc | 2018-10-16 08:29:32 -0500 | [diff] [blame] | 8 | #include "xyz/openbmc_project/Collection/DeleteAll/server.hpp" |
| 9 | #include "xyz/openbmc_project/Dump/Internal/Create/server.hpp" |
Dhruvaraj Subhashchandran | 33df507 | 2020-01-30 01:48:02 -0600 | [diff] [blame] | 10 | #include "xyz/openbmc_project/Dump/NewDump/server.hpp" |
Jayanth Othayoth | cb65ffc | 2018-10-16 08:29:32 -0500 | [diff] [blame] | 11 | |
| 12 | #include <experimental/filesystem> |
| 13 | #include <sdbusplus/bus.hpp> |
| 14 | #include <sdbusplus/server/object.hpp> |
| 15 | #include <xyz/openbmc_project/Dump/Create/server.hpp> |
Jayanth Othayoth | a320c7c | 2017-06-14 07:17:21 -0500 | [diff] [blame] | 16 | |
| 17 | namespace phosphor |
| 18 | { |
| 19 | namespace dump |
| 20 | { |
| 21 | namespace internal |
| 22 | { |
| 23 | |
| 24 | class Manager; |
| 25 | |
| 26 | } // namespace internal |
| 27 | |
Jayanth Othayoth | bcb174b | 2017-07-02 06:29:24 -0500 | [diff] [blame] | 28 | using UserMap = phosphor::dump::inotify::UserMap; |
| 29 | |
Jayanth Othayoth | a320c7c | 2017-06-14 07:17:21 -0500 | [diff] [blame] | 30 | using Type = |
| 31 | sdbusplus::xyz::openbmc_project::Dump::Internal::server::Create::Type; |
| 32 | |
Jayanth Othayoth | cb65ffc | 2018-10-16 08:29:32 -0500 | [diff] [blame] | 33 | using CreateIface = sdbusplus::server::object::object< |
| 34 | sdbusplus::xyz::openbmc_project::Collection::server::DeleteAll, |
Dhruvaraj Subhashchandran | 33df507 | 2020-01-30 01:48:02 -0600 | [diff] [blame] | 35 | sdbusplus::xyz::openbmc_project::Dump::server::Create, |
| 36 | sdbusplus::xyz::openbmc_project::Dump::server::NewDump>; |
Jayanth Othayoth | a320c7c | 2017-06-14 07:17:21 -0500 | [diff] [blame] | 37 | |
Jayanth Othayoth | 671fc7f | 2017-06-14 08:01:41 -0500 | [diff] [blame] | 38 | namespace fs = std::experimental::filesystem; |
Jayanth Othayoth | a320c7c | 2017-06-14 07:17:21 -0500 | [diff] [blame] | 39 | |
Jayanth Othayoth | 764d1b2 | 2017-07-12 19:14:02 -0500 | [diff] [blame] | 40 | using Watch = phosphor::dump::inotify::Watch; |
| 41 | |
Marri Devender Rao | 0deb287 | 2018-11-12 07:45:54 -0600 | [diff] [blame] | 42 | // Type to dreport type string map |
| 43 | static const std::map<Type, std::string> TypeMap = { |
| 44 | {Type::ApplicationCored, "core"}, |
| 45 | {Type::UserRequested, "user"}, |
| 46 | {Type::InternalFailure, "elog"}, |
| 47 | {Type::Checkstop, "checkstop"}}; |
| 48 | |
Jayanth Othayoth | a320c7c | 2017-06-14 07:17:21 -0500 | [diff] [blame] | 49 | /** @class Manager |
| 50 | * @brief OpenBMC Dump manager implementation. |
| 51 | * @details A concrete implementation for the |
Nagaraju Goruganti | 3c899a4 | 2017-09-12 06:14:46 -0500 | [diff] [blame] | 52 | * xyz.openbmc_project.Dump.Create DBus API and |
| 53 | * xyz::openbmc_project::Collection::server::DeleteAll. |
Jayanth Othayoth | a320c7c | 2017-06-14 07:17:21 -0500 | [diff] [blame] | 54 | */ |
| 55 | class Manager : public CreateIface |
| 56 | { |
Jayanth Othayoth | cb65ffc | 2018-10-16 08:29:32 -0500 | [diff] [blame] | 57 | friend class internal::Manager; |
| 58 | friend class Entry; |
Jayanth Othayoth | a320c7c | 2017-06-14 07:17:21 -0500 | [diff] [blame] | 59 | |
Jayanth Othayoth | cb65ffc | 2018-10-16 08:29:32 -0500 | [diff] [blame] | 60 | public: |
| 61 | Manager() = delete; |
| 62 | Manager(const Manager&) = default; |
| 63 | Manager& operator=(const Manager&) = delete; |
| 64 | Manager(Manager&&) = delete; |
| 65 | Manager& operator=(Manager&&) = delete; |
| 66 | virtual ~Manager() = default; |
Jayanth Othayoth | a320c7c | 2017-06-14 07:17:21 -0500 | [diff] [blame] | 67 | |
Jayanth Othayoth | cb65ffc | 2018-10-16 08:29:32 -0500 | [diff] [blame] | 68 | /** @brief Constructor to put object onto bus at a dbus path. |
| 69 | * @param[in] bus - Bus to attach to. |
| 70 | * @param[in] event - Dump manager sd_event loop. |
| 71 | * @param[in] path - Path to attach at. |
| 72 | */ |
| 73 | Manager(sdbusplus::bus::bus& bus, const EventPtr& event, const char* path) : |
| 74 | CreateIface(bus, path), bus(bus), eventLoop(event.get()), |
| 75 | lastEntryId(0), |
| 76 | dumpWatch( |
| 77 | eventLoop, IN_NONBLOCK, IN_CLOSE_WRITE | IN_CREATE, EPOLLIN, |
| 78 | BMC_DUMP_PATH, |
| 79 | std::bind(std::mem_fn(&phosphor::dump::Manager::watchCallback), |
| 80 | this, std::placeholders::_1)) |
| 81 | { |
| 82 | } |
Jayanth Othayoth | a320c7c | 2017-06-14 07:17:21 -0500 | [diff] [blame] | 83 | |
Jayanth Othayoth | cb65ffc | 2018-10-16 08:29:32 -0500 | [diff] [blame] | 84 | /** @brief Implementation for CreateDump |
| 85 | * Method to create Dump. |
| 86 | * |
| 87 | * @return id - The Dump entry id number. |
| 88 | */ |
| 89 | uint32_t createDump() override; |
Jayanth Othayoth | a320c7c | 2017-06-14 07:17:21 -0500 | [diff] [blame] | 90 | |
Jayanth Othayoth | cb65ffc | 2018-10-16 08:29:32 -0500 | [diff] [blame] | 91 | /** @brief Implementation of dump watch call back |
| 92 | * @param [in] fileInfo - map of file info path:event |
| 93 | */ |
| 94 | void watchCallback(const UserMap& fileInfo); |
Jayanth Othayoth | bcb174b | 2017-07-02 06:29:24 -0500 | [diff] [blame] | 95 | |
Jayanth Othayoth | cb65ffc | 2018-10-16 08:29:32 -0500 | [diff] [blame] | 96 | /** @brief Construct dump d-bus objects from their persisted |
| 97 | * representations. |
| 98 | */ |
| 99 | void restore(); |
Jayanth Othayoth | 4309659 | 2017-07-20 02:17:37 -0500 | [diff] [blame] | 100 | |
Dhruvaraj Subhashchandran | 33df507 | 2020-01-30 01:48:02 -0600 | [diff] [blame] | 101 | /** @brief Notify the dump manager about creation of a new dump. |
| 102 | * @param[in] dumpType - Type of the Dump. |
| 103 | * @param[in] dumpId - Id from the source of the dump. |
| 104 | * @param[in] size - Size of the dump. |
| 105 | */ |
| 106 | void notify(NewDump::DumpType dumpType, uint32_t dumpId, uint64_t size); |
| 107 | |
Jayanth Othayoth | cb65ffc | 2018-10-16 08:29:32 -0500 | [diff] [blame] | 108 | private: |
| 109 | /** @brief Create Dump entry d-bus object |
| 110 | * @param[in] fullPath - Full path of the Dump file name |
| 111 | */ |
| 112 | void createEntry(const fs::path& fullPath); |
Jayanth Othayoth | a320c7c | 2017-06-14 07:17:21 -0500 | [diff] [blame] | 113 | |
Jayanth Othayoth | cb65ffc | 2018-10-16 08:29:32 -0500 | [diff] [blame] | 114 | /** @brief Capture BMC Dump based on the Dump type. |
| 115 | * @param[in] type - Type of the Dump. |
| 116 | * @param[in] fullPaths - List of absolute paths to the files |
| 117 | * to be included as part of Dump package. |
| 118 | * @return id - The Dump entry id number. |
| 119 | */ |
| 120 | uint32_t captureDump(Type type, const std::vector<std::string>& fullPaths); |
Jayanth Othayoth | a320c7c | 2017-06-14 07:17:21 -0500 | [diff] [blame] | 121 | |
Jayanth Othayoth | cb65ffc | 2018-10-16 08:29:32 -0500 | [diff] [blame] | 122 | /** @brief Erase specified entry d-bus object |
| 123 | * |
| 124 | * @param[in] entryId - unique identifier of the entry |
| 125 | */ |
| 126 | void erase(uint32_t entryId); |
Jayanth Othayoth | a320c7c | 2017-06-14 07:17:21 -0500 | [diff] [blame] | 127 | |
Jayanth Othayoth | cb65ffc | 2018-10-16 08:29:32 -0500 | [diff] [blame] | 128 | /** @brief Erase all BMC dump entries and Delete all Dump files |
| 129 | * from Permanent location |
| 130 | * |
| 131 | */ |
| 132 | void deleteAll() override; |
Nagaraju Goruganti | 3c899a4 | 2017-09-12 06:14:46 -0500 | [diff] [blame] | 133 | |
Jayanth Othayoth | cb65ffc | 2018-10-16 08:29:32 -0500 | [diff] [blame] | 134 | /** @brief sd_event_add_child callback |
| 135 | * |
| 136 | * @param[in] s - event source |
| 137 | * @param[in] si - signal info |
| 138 | * @param[in] userdata - pointer to Watch object |
| 139 | * |
| 140 | * @returns 0 on success, -1 on fail |
| 141 | */ |
Ramesh Iyyar | bb410df | 2020-08-03 03:13:04 -0500 | [diff] [blame] | 142 | static int callback(sd_event_source*, const siginfo_t*, void*) |
Jayanth Othayoth | cb65ffc | 2018-10-16 08:29:32 -0500 | [diff] [blame] | 143 | { |
| 144 | // No specific action required in |
| 145 | // the sd_event_add_child callback. |
| 146 | return 0; |
| 147 | } |
| 148 | /** @brief Remove specified watch object pointer from the |
| 149 | * watch map and associated entry from the map. |
| 150 | * @param[in] path - unique identifier of the map |
| 151 | */ |
| 152 | void removeWatch(const fs::path& path); |
Jayanth Othayoth | a320c7c | 2017-06-14 07:17:21 -0500 | [diff] [blame] | 153 | |
Jayanth Othayoth | cb65ffc | 2018-10-16 08:29:32 -0500 | [diff] [blame] | 154 | /** @brief Calculate per dump allowed size based on the available |
| 155 | * size in the dump location. |
| 156 | * @returns dump size in kilobytes. |
| 157 | */ |
| 158 | size_t getAllowedSize(); |
Jayanth Othayoth | ab7f920 | 2017-08-02 06:24:58 -0500 | [diff] [blame] | 159 | |
Jayanth Othayoth | cb65ffc | 2018-10-16 08:29:32 -0500 | [diff] [blame] | 160 | /** @brief sdbusplus DBus bus connection. */ |
| 161 | sdbusplus::bus::bus& bus; |
Jayanth Othayoth | a320c7c | 2017-06-14 07:17:21 -0500 | [diff] [blame] | 162 | |
Jayanth Othayoth | cb65ffc | 2018-10-16 08:29:32 -0500 | [diff] [blame] | 163 | /** @brief sdbusplus Dump event loop */ |
| 164 | EventPtr eventLoop; |
Jayanth Othayoth | a320c7c | 2017-06-14 07:17:21 -0500 | [diff] [blame] | 165 | |
Jayanth Othayoth | cb65ffc | 2018-10-16 08:29:32 -0500 | [diff] [blame] | 166 | /** @brief Dump Entry dbus objects map based on entry id */ |
| 167 | std::map<uint32_t, std::unique_ptr<Entry>> entries; |
Jayanth Othayoth | a320c7c | 2017-06-14 07:17:21 -0500 | [diff] [blame] | 168 | |
Jayanth Othayoth | cb65ffc | 2018-10-16 08:29:32 -0500 | [diff] [blame] | 169 | /** @brief Id of the last Dump entry */ |
| 170 | uint32_t lastEntryId; |
Jayanth Othayoth | bcb174b | 2017-07-02 06:29:24 -0500 | [diff] [blame] | 171 | |
Jayanth Othayoth | cb65ffc | 2018-10-16 08:29:32 -0500 | [diff] [blame] | 172 | /** @brief Dump main watch object */ |
| 173 | Watch dumpWatch; |
Jayanth Othayoth | 764d1b2 | 2017-07-12 19:14:02 -0500 | [diff] [blame] | 174 | |
Jayanth Othayoth | cb65ffc | 2018-10-16 08:29:32 -0500 | [diff] [blame] | 175 | /** @brief Child directory path and its associated watch object map |
| 176 | * [path:watch object] |
| 177 | */ |
| 178 | std::map<fs::path, std::unique_ptr<Watch>> childWatchMap; |
Jayanth Othayoth | a320c7c | 2017-06-14 07:17:21 -0500 | [diff] [blame] | 179 | }; |
| 180 | |
| 181 | } // namespace dump |
| 182 | } // namespace phosphor |