Dhruvaraj Subhashchandran | fef66a9 | 2020-09-06 13:10:59 -0500 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Dhruvaraj Subhashchandran | 830a6d4 | 2021-05-05 15:47:57 -0500 | [diff] [blame] | 3 | #include "dump_manager_bmcstored.hpp" |
Dhruvaraj Subhashchandran | fef66a9 | 2020-09-06 13:10:59 -0500 | [diff] [blame] | 4 | #include "dump_utils.hpp" |
| 5 | #include "watch.hpp" |
| 6 | #include "xyz/openbmc_project/Dump/Internal/Create/server.hpp" |
| 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 | { |
| 20 | namespace internal |
| 21 | { |
| 22 | |
| 23 | class Manager; |
| 24 | |
| 25 | } // namespace internal |
| 26 | |
Dhruvaraj Subhashchandran | 830a6d4 | 2021-05-05 15:47:57 -0500 | [diff] [blame] | 27 | constexpr auto BMC_DUMP_FILENAME_REGEX = |
| 28 | "obmcdump_([0-9]+)_([0-9]+).([a-zA-Z0-9]+)"; |
| 29 | |
Patrick Williams | 9b18bf2 | 2022-07-22 19:26:55 -0500 | [diff] [blame] | 30 | using CreateIface = sdbusplus::server::object_t< |
Dhruvaraj Subhashchandran | fef66a9 | 2020-09-06 13:10:59 -0500 | [diff] [blame] | 31 | sdbusplus::xyz::openbmc_project::Dump::server::Create>; |
| 32 | |
Dhruvaraj Subhashchandran | fef66a9 | 2020-09-06 13:10:59 -0500 | [diff] [blame] | 33 | using Type = |
| 34 | sdbusplus::xyz::openbmc_project::Dump::Internal::server::Create::Type; |
Marri Devender Rao | 3ed02c3 | 2022-06-28 23:12:14 -0500 | [diff] [blame] | 35 | using ::sdeventplus::source::Child; |
Dhruvaraj Subhashchandran | 830a6d4 | 2021-05-05 15:47:57 -0500 | [diff] [blame] | 36 | |
Dhruvaraj Subhashchandran | fef66a9 | 2020-09-06 13:10:59 -0500 | [diff] [blame] | 37 | // Type to dreport type string map |
| 38 | static const std::map<Type, std::string> TypeMap = { |
| 39 | {Type::ApplicationCored, "core"}, |
| 40 | {Type::UserRequested, "user"}, |
| 41 | {Type::InternalFailure, "elog"}, |
George Liu | ff92ffe | 2021-02-09 15:01:53 +0800 | [diff] [blame] | 42 | {Type::Checkstop, "checkstop"}, |
| 43 | {Type::Ramoops, "ramoops"}}; |
Dhruvaraj Subhashchandran | fef66a9 | 2020-09-06 13:10:59 -0500 | [diff] [blame] | 44 | |
| 45 | /** @class Manager |
| 46 | * @brief OpenBMC Dump manager implementation. |
| 47 | * @details A concrete implementation for the |
| 48 | * xyz.openbmc_project.Dump.Create DBus API |
| 49 | */ |
Jayanth Othayoth | 0af74a5 | 2021-04-08 03:55:21 -0500 | [diff] [blame] | 50 | class Manager : |
| 51 | virtual public CreateIface, |
Dhruvaraj Subhashchandran | 830a6d4 | 2021-05-05 15:47:57 -0500 | [diff] [blame] | 52 | virtual public phosphor::dump::bmc_stored::Manager |
Dhruvaraj Subhashchandran | fef66a9 | 2020-09-06 13:10:59 -0500 | [diff] [blame] | 53 | { |
| 54 | friend class internal::Manager; |
| 55 | |
| 56 | public: |
| 57 | Manager() = delete; |
| 58 | Manager(const Manager&) = default; |
| 59 | Manager& operator=(const Manager&) = delete; |
| 60 | Manager(Manager&&) = delete; |
| 61 | Manager& operator=(Manager&&) = delete; |
| 62 | virtual ~Manager() = default; |
| 63 | |
| 64 | /** @brief Constructor to put object onto bus at a dbus path. |
| 65 | * @param[in] bus - Bus to attach to. |
| 66 | * @param[in] event - Dump manager sd_event loop. |
| 67 | * @param[in] path - Path to attach at. |
| 68 | * @param[in] baseEntryPath - Base path for dump entry. |
| 69 | * @param[in] filePath - Path where the dumps are stored. |
| 70 | */ |
Patrick Williams | 9b18bf2 | 2022-07-22 19:26:55 -0500 | [diff] [blame] | 71 | Manager(sdbusplus::bus_t& bus, const EventPtr& event, const char* path, |
Dhruvaraj Subhashchandran | fef66a9 | 2020-09-06 13:10:59 -0500 | [diff] [blame] | 72 | const std::string& baseEntryPath, const char* filePath) : |
| 73 | CreateIface(bus, path), |
Dhruvaraj Subhashchandran | 830a6d4 | 2021-05-05 15:47:57 -0500 | [diff] [blame] | 74 | phosphor::dump::bmc_stored::Manager( |
| 75 | bus, event, path, baseEntryPath, filePath, BMC_DUMP_FILENAME_REGEX, |
| 76 | BMC_DUMP_MAX_SIZE, BMC_DUMP_MIN_SPACE_REQD, BMC_DUMP_TOTAL_SIZE) |
Jayanth Othayoth | 0af74a5 | 2021-04-08 03:55:21 -0500 | [diff] [blame] | 77 | {} |
Dhruvaraj Subhashchandran | fef66a9 | 2020-09-06 13:10:59 -0500 | [diff] [blame] | 78 | |
Dhruvaraj Subhashchandran | fef66a9 | 2020-09-06 13:10:59 -0500 | [diff] [blame] | 79 | /** @brief Implementation for CreateDump |
Dhruvaraj Subhashchandran | 6ccb50e | 2020-10-29 09:33:18 -0500 | [diff] [blame] | 80 | * 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] | 81 | * |
Dhruvaraj Subhashchandran | 6ccb50e | 2020-10-29 09:33:18 -0500 | [diff] [blame] | 82 | * @return object_path - The object path of the new dump entry. |
Dhruvaraj Subhashchandran | fef66a9 | 2020-09-06 13:10:59 -0500 | [diff] [blame] | 83 | */ |
Dhruvaraj Subhashchandran | 969f9a5 | 2020-10-30 01:42:39 -0500 | [diff] [blame] | 84 | sdbusplus::message::object_path |
Dhruvaraj Subhashchandran | ddc3366 | 2021-07-19 09:28:42 -0500 | [diff] [blame] | 85 | createDump(phosphor::dump::DumpCreateParams params) override; |
Dhruvaraj Subhashchandran | fef66a9 | 2020-09-06 13:10:59 -0500 | [diff] [blame] | 86 | |
Dhruvaraj Subhashchandran | 830a6d4 | 2021-05-05 15:47:57 -0500 | [diff] [blame] | 87 | /** @brief Create a Dump Entry Object |
| 88 | * @param[in] id - Id of the dump |
| 89 | * @param[in] objPath - Object path to attach to |
| 90 | * @param[in] timeStamp - Dump creation timestamp |
| 91 | * since the epoch. |
| 92 | * @param[in] fileSize - Dump file size in bytes. |
| 93 | * @param[in] file - Name of dump file. |
| 94 | * @param[in] status - status of the dump. |
| 95 | * @param[in] parent - The dump entry's parent. |
Dhruvaraj Subhashchandran | fef66a9 | 2020-09-06 13:10:59 -0500 | [diff] [blame] | 96 | */ |
Dhruvaraj Subhashchandran | 830a6d4 | 2021-05-05 15:47:57 -0500 | [diff] [blame] | 97 | void createEntry(const uint32_t id, const std::string objPath, |
| 98 | const uint64_t ms, uint64_t fileSize, |
| 99 | const std::filesystem::path& file, |
| 100 | phosphor::dump::OperationStatus status, |
| 101 | std::string originatorId, |
| 102 | originatorTypes originatorType) override; |
Dhruvaraj Subhashchandran | fef66a9 | 2020-09-06 13:10:59 -0500 | [diff] [blame] | 103 | |
Dhruvaraj Subhashchandran | 830a6d4 | 2021-05-05 15:47:57 -0500 | [diff] [blame] | 104 | private: |
Dhruvaraj Subhashchandran | fef66a9 | 2020-09-06 13:10:59 -0500 | [diff] [blame] | 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 | |
Marri Devender Rao | 73953b8 | 2022-02-15 09:15:42 -0600 | [diff] [blame] | 113 | /** @brief Flag to reject user intiated dump if a dump is in progress*/ |
| 114 | // TODO: https://github.com/openbmc/phosphor-debug-collector/issues/19 |
| 115 | static bool fUserDumpInProgress; |
Dhruvaraj Subhashchandran | fef66a9 | 2020-09-06 13:10:59 -0500 | [diff] [blame] | 116 | }; |
| 117 | |
| 118 | } // namespace bmc |
| 119 | } // namespace dump |
| 120 | } // namespace phosphor |