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 8 #include <experimental/filesystem> 9 #include <xyz/openbmc_project/Dump/Create/server.hpp> 10 11 namespace phosphor 12 { 13 namespace dump 14 { 15 namespace bmc 16 { 17 namespace internal 18 { 19 20 class Manager; 21 22 } // namespace internal 23 24 using CreateIface = sdbusplus::server::object::object< 25 sdbusplus::xyz::openbmc_project::Dump::server::Create>; 26 27 using UserMap = phosphor::dump::inotify::UserMap; 28 29 using Type = 30 sdbusplus::xyz::openbmc_project::Dump::Internal::server::Create::Type; 31 32 namespace fs = std::experimental::filesystem; 33 34 using Watch = phosphor::dump::inotify::Watch; 35 36 // Type to dreport type string map 37 static const std::map<Type, std::string> TypeMap = { 38 {Type::ApplicationCored, "core"}, 39 {Type::UserRequested, "user"}, 40 {Type::InternalFailure, "elog"}, 41 {Type::Checkstop, "checkstop"}}; 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 */ 48 class Manager : virtual public CreateIface, 49 virtual public phosphor::dump::Manager 50 { 51 friend class internal::Manager; 52 53 public: 54 Manager() = delete; 55 Manager(const Manager&) = default; 56 Manager& operator=(const Manager&) = delete; 57 Manager(Manager&&) = delete; 58 Manager& operator=(Manager&&) = delete; 59 virtual ~Manager() = default; 60 61 /** @brief Constructor to put object onto bus at a dbus path. 62 * @param[in] bus - Bus to attach to. 63 * @param[in] event - Dump manager sd_event loop. 64 * @param[in] path - Path to attach at. 65 * @param[in] baseEntryPath - Base path for dump entry. 66 * @param[in] filePath - Path where the dumps are stored. 67 */ 68 Manager(sdbusplus::bus::bus& bus, const EventPtr& event, const char* path, 69 const std::string& baseEntryPath, const char* filePath) : 70 CreateIface(bus, path), 71 phosphor::dump::Manager(bus, path, baseEntryPath), 72 eventLoop(event.get()), 73 dumpWatch( 74 eventLoop, IN_NONBLOCK, IN_CLOSE_WRITE | IN_CREATE, EPOLLIN, 75 filePath, 76 std::bind(std::mem_fn(&phosphor::dump::bmc::Manager::watchCallback), 77 this, std::placeholders::_1)), 78 dumpDir(filePath) 79 { 80 } 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 93 * Method to create a BMC dump entry when user requests for a new BMC dump 94 * 95 * @return object_path - The object path of the new dump entry. 96 */ 97 sdbusplus::message::object_path createDump() override; 98 99 private: 100 /** @brief Create Dump entry d-bus object 101 * @param[in] fullPath - Full path of the Dump file name 102 */ 103 void createEntry(const fs::path& fullPath); 104 105 /** @brief Capture BMC Dump based on the Dump type. 106 * @param[in] type - Type of the Dump. 107 * @param[in] fullPaths - List of absolute paths to the files 108 * to be included as part of Dump package. 109 * @return id - The Dump entry id number. 110 */ 111 uint32_t captureDump(Type type, const std::vector<std::string>& fullPaths); 112 113 /** @brief sd_event_add_child callback 114 * 115 * @param[in] s - event source 116 * @param[in] si - signal info 117 * @param[in] userdata - pointer to Watch object 118 * 119 * @returns 0 on success, -1 on fail 120 */ 121 static int callback(sd_event_source*, const siginfo_t*, void*) 122 { 123 // No specific action required in 124 // the sd_event_add_child callback. 125 return 0; 126 } 127 /** @brief Remove specified watch object pointer from the 128 * watch map and associated entry from the map. 129 * @param[in] path - unique identifier of the map 130 */ 131 void removeWatch(const fs::path& path); 132 133 /** @brief Calculate per dump allowed size based on the available 134 * size in the dump location. 135 * @returns dump size in kilobytes. 136 */ 137 size_t getAllowedSize(); 138 139 /** @brief sdbusplus Dump event loop */ 140 EventPtr eventLoop; 141 142 /** @brief Dump main watch object */ 143 Watch dumpWatch; 144 145 /** @brief Path to the dump file*/ 146 std::string dumpDir; 147 148 /** @brief Child directory path and its associated watch object map 149 * [path:watch object] 150 */ 151 std::map<fs::path, std::unique_ptr<Watch>> childWatchMap; 152 }; 153 154 } // namespace bmc 155 } // namespace dump 156 } // namespace phosphor 157