1fef66a95SDhruvaraj Subhashchandran #pragma once 2fef66a95SDhruvaraj Subhashchandran 393f06410SDhruvaraj Subhashchandran #include "dump_entry.hpp" 4fef66a95SDhruvaraj Subhashchandran #include "dump_manager.hpp" 5fef66a95SDhruvaraj Subhashchandran #include "dump_utils.hpp" 6fef66a95SDhruvaraj Subhashchandran #include "watch.hpp" 7fef66a95SDhruvaraj Subhashchandran 83ed02c32SMarri Devender Rao #include <sdeventplus/source/child.hpp> 9fef66a95SDhruvaraj Subhashchandran #include <xyz/openbmc_project/Dump/Create/server.hpp> 10fef66a95SDhruvaraj Subhashchandran 110af74a5eSJayanth Othayoth #include <filesystem> 123ed02c32SMarri Devender Rao #include <map> 133ed02c32SMarri Devender Rao 14fef66a95SDhruvaraj Subhashchandran namespace phosphor 15fef66a95SDhruvaraj Subhashchandran { 16fef66a95SDhruvaraj Subhashchandran namespace dump 17fef66a95SDhruvaraj Subhashchandran { 18fef66a95SDhruvaraj Subhashchandran namespace bmc 19fef66a95SDhruvaraj Subhashchandran { 20fef66a95SDhruvaraj Subhashchandran 219b18bf2dSPatrick Williams using CreateIface = sdbusplus::server::object_t< 22fef66a95SDhruvaraj Subhashchandran sdbusplus::xyz::openbmc_project::Dump::server::Create>; 23fef66a95SDhruvaraj Subhashchandran 24fef66a95SDhruvaraj Subhashchandran using UserMap = phosphor::dump::inotify::UserMap; 25fef66a95SDhruvaraj Subhashchandran 26fef66a95SDhruvaraj Subhashchandran using Watch = phosphor::dump::inotify::Watch; 273ed02c32SMarri Devender Rao using ::sdeventplus::source::Child; 28fef66a95SDhruvaraj Subhashchandran 29fef66a95SDhruvaraj Subhashchandran /** @class Manager 30fef66a95SDhruvaraj Subhashchandran * @brief OpenBMC Dump manager implementation. 31fef66a95SDhruvaraj Subhashchandran * @details A concrete implementation for the 32fef66a95SDhruvaraj Subhashchandran * xyz.openbmc_project.Dump.Create DBus API 33fef66a95SDhruvaraj Subhashchandran */ 340af74a5eSJayanth Othayoth class Manager : 350af74a5eSJayanth Othayoth virtual public CreateIface, 36fef66a95SDhruvaraj Subhashchandran virtual public phosphor::dump::Manager 37fef66a95SDhruvaraj Subhashchandran { 38fef66a95SDhruvaraj Subhashchandran public: 39fef66a95SDhruvaraj Subhashchandran Manager() = delete; 40*4f68fc46SJayanth Othayoth Manager(const Manager&) = delete; 41fef66a95SDhruvaraj Subhashchandran Manager& operator=(const Manager&) = delete; 42fef66a95SDhruvaraj Subhashchandran Manager(Manager&&) = delete; 43fef66a95SDhruvaraj Subhashchandran Manager& operator=(Manager&&) = delete; 44fef66a95SDhruvaraj Subhashchandran virtual ~Manager() = default; 45fef66a95SDhruvaraj Subhashchandran 46fef66a95SDhruvaraj Subhashchandran /** @brief Constructor to put object onto bus at a dbus path. 47fef66a95SDhruvaraj Subhashchandran * @param[in] bus - Bus to attach to. 48fef66a95SDhruvaraj Subhashchandran * @param[in] event - Dump manager sd_event loop. 49fef66a95SDhruvaraj Subhashchandran * @param[in] path - Path to attach at. 50fef66a95SDhruvaraj Subhashchandran * @param[in] baseEntryPath - Base path for dump entry. 51fef66a95SDhruvaraj Subhashchandran * @param[in] filePath - Path where the dumps are stored. 52fef66a95SDhruvaraj Subhashchandran */ Manager(sdbusplus::bus_t & bus,const EventPtr & event,const char * path,const std::string & baseEntryPath,const char * filePath)539b18bf2dSPatrick Williams Manager(sdbusplus::bus_t& bus, const EventPtr& event, const char* path, 54fef66a95SDhruvaraj Subhashchandran const std::string& baseEntryPath, const char* filePath) : 55fef66a95SDhruvaraj Subhashchandran CreateIface(bus, path), 56fef66a95SDhruvaraj Subhashchandran phosphor::dump::Manager(bus, path, baseEntryPath), 57fef66a95SDhruvaraj Subhashchandran eventLoop(event.get()), 58fef66a95SDhruvaraj Subhashchandran dumpWatch( 59fef66a95SDhruvaraj Subhashchandran eventLoop, IN_NONBLOCK, IN_CLOSE_WRITE | IN_CREATE, EPOLLIN, 60fef66a95SDhruvaraj Subhashchandran filePath, 61fef66a95SDhruvaraj Subhashchandran std::bind(std::mem_fn(&phosphor::dump::bmc::Manager::watchCallback), 62fef66a95SDhruvaraj Subhashchandran this, std::placeholders::_1)), 63fef66a95SDhruvaraj Subhashchandran dumpDir(filePath) 640af74a5eSJayanth Othayoth {} 65fef66a95SDhruvaraj Subhashchandran 66fef66a95SDhruvaraj Subhashchandran /** @brief Implementation of dump watch call back 67fef66a95SDhruvaraj Subhashchandran * @param [in] fileInfo - map of file info path:event 68fef66a95SDhruvaraj Subhashchandran */ 69fef66a95SDhruvaraj Subhashchandran void watchCallback(const UserMap& fileInfo); 70fef66a95SDhruvaraj Subhashchandran 71fef66a95SDhruvaraj Subhashchandran /** @brief Construct dump d-bus objects from their persisted 72fef66a95SDhruvaraj Subhashchandran * representations. 73fef66a95SDhruvaraj Subhashchandran */ 74fef66a95SDhruvaraj Subhashchandran void restore() override; 75fef66a95SDhruvaraj Subhashchandran 76fef66a95SDhruvaraj Subhashchandran /** @brief Implementation for CreateDump 776ccb50e1SDhruvaraj Subhashchandran * Method to create a BMC dump entry when user requests for a new BMC dump 78fef66a95SDhruvaraj Subhashchandran * 796ccb50e1SDhruvaraj Subhashchandran * @return object_path - The object path of the new dump entry. 80fef66a95SDhruvaraj Subhashchandran */ 81969f9a59SDhruvaraj Subhashchandran sdbusplus::message::object_path 82ddc3366eSDhruvaraj Subhashchandran createDump(phosphor::dump::DumpCreateParams params) override; 83fef66a95SDhruvaraj Subhashchandran 84fef66a95SDhruvaraj Subhashchandran private: 85fef66a95SDhruvaraj Subhashchandran /** @brief Create Dump entry d-bus object 86fef66a95SDhruvaraj Subhashchandran * @param[in] fullPath - Full path of the Dump file name 87fef66a95SDhruvaraj Subhashchandran */ 883fc6df48SJayanth Othayoth void createEntry(const std::filesystem::path& fullPath); 89fef66a95SDhruvaraj Subhashchandran 90fef66a95SDhruvaraj Subhashchandran /** @brief Capture BMC Dump based on the Dump type. 913604710dSDhruvaraj Subhashchandran * @param[in] type - Type of the dump to pass to dreport 923604710dSDhruvaraj Subhashchandran * @param[in] path - An absolute path to the file 933604710dSDhruvaraj Subhashchandran * to be included as part of Dump package. 943604710dSDhruvaraj Subhashchandran * @return id - The Dump entry id number. 953604710dSDhruvaraj Subhashchandran */ 963604710dSDhruvaraj Subhashchandran uint32_t captureDump(DumpTypes type, const std::string& path); 973604710dSDhruvaraj Subhashchandran 98fef66a95SDhruvaraj Subhashchandran /** @brief Remove specified watch object pointer from the 99fef66a95SDhruvaraj Subhashchandran * watch map and associated entry from the map. 100fef66a95SDhruvaraj Subhashchandran * @param[in] path - unique identifier of the map 101fef66a95SDhruvaraj Subhashchandran */ 1023fc6df48SJayanth Othayoth void removeWatch(const std::filesystem::path& path); 103fef66a95SDhruvaraj Subhashchandran 104fef66a95SDhruvaraj Subhashchandran /** @brief Calculate per dump allowed size based on the available 105fef66a95SDhruvaraj Subhashchandran * size in the dump location. 106fef66a95SDhruvaraj Subhashchandran * @returns dump size in kilobytes. 107fef66a95SDhruvaraj Subhashchandran */ 108fef66a95SDhruvaraj Subhashchandran size_t getAllowedSize(); 109fef66a95SDhruvaraj Subhashchandran 110fef66a95SDhruvaraj Subhashchandran /** @brief sdbusplus Dump event loop */ 111fef66a95SDhruvaraj Subhashchandran EventPtr eventLoop; 112fef66a95SDhruvaraj Subhashchandran 113fef66a95SDhruvaraj Subhashchandran /** @brief Dump main watch object */ 114fef66a95SDhruvaraj Subhashchandran Watch dumpWatch; 115fef66a95SDhruvaraj Subhashchandran 116fef66a95SDhruvaraj Subhashchandran /** @brief Path to the dump file*/ 117fef66a95SDhruvaraj Subhashchandran std::string dumpDir; 118fef66a95SDhruvaraj Subhashchandran 11973953b8fSMarri Devender Rao /** @brief Flag to reject user intiated dump if a dump is in progress*/ 12073953b8fSMarri Devender Rao // TODO: https://github.com/openbmc/phosphor-debug-collector/issues/19 12173953b8fSMarri Devender Rao static bool fUserDumpInProgress; 12273953b8fSMarri Devender Rao 123fef66a95SDhruvaraj Subhashchandran /** @brief Child directory path and its associated watch object map 124fef66a95SDhruvaraj Subhashchandran * [path:watch object] 125fef66a95SDhruvaraj Subhashchandran */ 1263fc6df48SJayanth Othayoth std::map<std::filesystem::path, std::unique_ptr<Watch>> childWatchMap; 1273ed02c32SMarri Devender Rao 1283ed02c32SMarri Devender Rao /** @brief map of SDEventPlus child pointer added to event loop */ 1293ed02c32SMarri Devender Rao std::map<pid_t, std::unique_ptr<Child>> childPtrMap; 130fef66a95SDhruvaraj Subhashchandran }; 131fef66a95SDhruvaraj Subhashchandran 132fef66a95SDhruvaraj Subhashchandran } // namespace bmc 133fef66a95SDhruvaraj Subhashchandran } // namespace dump 134fef66a95SDhruvaraj Subhashchandran } // namespace phosphor 135