blob: 5d927360ad8b87540df839141c4626558720804b [file] [log] [blame]
Dhruvaraj Subhashchandranfef66a92020-09-06 13:10:59 -05001#pragma once
2
Dhruvaraj Subhashchandran830a6d42021-05-05 15:47:57 -05003#include "dump_manager_bmcstored.hpp"
Dhruvaraj Subhashchandranfef66a92020-09-06 13:10:59 -05004#include "dump_utils.hpp"
5#include "watch.hpp"
6#include "xyz/openbmc_project/Dump/Internal/Create/server.hpp"
7
Marri Devender Rao3ed02c32022-06-28 23:12:14 -05008#include <sdeventplus/source/child.hpp>
Dhruvaraj Subhashchandranfef66a92020-09-06 13:10:59 -05009#include <xyz/openbmc_project/Dump/Create/server.hpp>
10
Jayanth Othayoth0af74a52021-04-08 03:55:21 -050011#include <filesystem>
Marri Devender Rao3ed02c32022-06-28 23:12:14 -050012#include <map>
13
Dhruvaraj Subhashchandranfef66a92020-09-06 13:10:59 -050014namespace phosphor
15{
16namespace dump
17{
18namespace bmc
19{
20namespace internal
21{
22
23class Manager;
24
25} // namespace internal
26
Dhruvaraj Subhashchandran830a6d42021-05-05 15:47:57 -050027constexpr auto BMC_DUMP_FILENAME_REGEX =
28 "obmcdump_([0-9]+)_([0-9]+).([a-zA-Z0-9]+)";
29
Patrick Williams9b18bf22022-07-22 19:26:55 -050030using CreateIface = sdbusplus::server::object_t<
Dhruvaraj Subhashchandranfef66a92020-09-06 13:10:59 -050031 sdbusplus::xyz::openbmc_project::Dump::server::Create>;
32
Dhruvaraj Subhashchandranfef66a92020-09-06 13:10:59 -050033using Type =
34 sdbusplus::xyz::openbmc_project::Dump::Internal::server::Create::Type;
Marri Devender Rao3ed02c32022-06-28 23:12:14 -050035using ::sdeventplus::source::Child;
Dhruvaraj Subhashchandran830a6d42021-05-05 15:47:57 -050036
Dhruvaraj Subhashchandranfef66a92020-09-06 13:10:59 -050037// Type to dreport type string map
38static const std::map<Type, std::string> TypeMap = {
39 {Type::ApplicationCored, "core"},
40 {Type::UserRequested, "user"},
41 {Type::InternalFailure, "elog"},
George Liuff92ffe2021-02-09 15:01:53 +080042 {Type::Checkstop, "checkstop"},
43 {Type::Ramoops, "ramoops"}};
Dhruvaraj Subhashchandranfef66a92020-09-06 13:10:59 -050044
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 Othayoth0af74a52021-04-08 03:55:21 -050050class Manager :
51 virtual public CreateIface,
Dhruvaraj Subhashchandran830a6d42021-05-05 15:47:57 -050052 virtual public phosphor::dump::bmc_stored::Manager
Dhruvaraj Subhashchandranfef66a92020-09-06 13:10:59 -050053{
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 Williams9b18bf22022-07-22 19:26:55 -050071 Manager(sdbusplus::bus_t& bus, const EventPtr& event, const char* path,
Dhruvaraj Subhashchandranfef66a92020-09-06 13:10:59 -050072 const std::string& baseEntryPath, const char* filePath) :
73 CreateIface(bus, path),
Dhruvaraj Subhashchandran830a6d42021-05-05 15:47:57 -050074 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 Othayoth0af74a52021-04-08 03:55:21 -050077 {}
Dhruvaraj Subhashchandranfef66a92020-09-06 13:10:59 -050078
Dhruvaraj Subhashchandranfef66a92020-09-06 13:10:59 -050079 /** @brief Implementation for CreateDump
Dhruvaraj Subhashchandran6ccb50e2020-10-29 09:33:18 -050080 * Method to create a BMC dump entry when user requests for a new BMC dump
Dhruvaraj Subhashchandranfef66a92020-09-06 13:10:59 -050081 *
Dhruvaraj Subhashchandran6ccb50e2020-10-29 09:33:18 -050082 * @return object_path - The object path of the new dump entry.
Dhruvaraj Subhashchandranfef66a92020-09-06 13:10:59 -050083 */
Dhruvaraj Subhashchandran969f9a52020-10-30 01:42:39 -050084 sdbusplus::message::object_path
Dhruvaraj Subhashchandranddc33662021-07-19 09:28:42 -050085 createDump(phosphor::dump::DumpCreateParams params) override;
Dhruvaraj Subhashchandranfef66a92020-09-06 13:10:59 -050086
Dhruvaraj Subhashchandran830a6d42021-05-05 15:47:57 -050087 /** @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 Subhashchandranfef66a92020-09-06 13:10:59 -050096 */
Dhruvaraj Subhashchandran830a6d42021-05-05 15:47:57 -050097 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 Subhashchandranfef66a92020-09-06 13:10:59 -0500103
Dhruvaraj Subhashchandran830a6d42021-05-05 15:47:57 -0500104 private:
Dhruvaraj Subhashchandranfef66a92020-09-06 13:10:59 -0500105 /** @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 Rao73953b82022-02-15 09:15:42 -0600113 /** @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 Subhashchandranfef66a92020-09-06 13:10:59 -0500116};
117
118} // namespace bmc
119} // namespace dump
120} // namespace phosphor