blob: 9297f6e01e9081b46460ffb32aa5b3df1cb0bb54 [file] [log] [blame]
Dhruvaraj Subhashchandranfef66a92020-09-06 13:10:59 -05001#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
Dhruvaraj Subhashchandranfef66a92020-09-06 13:10:59 -05008#include <xyz/openbmc_project/Dump/Create/server.hpp>
9
Jayanth Othayoth0af74a52021-04-08 03:55:21 -050010#include <filesystem>
Dhruvaraj Subhashchandranfef66a92020-09-06 13:10:59 -050011namespace phosphor
12{
13namespace dump
14{
15namespace bmc
16{
17namespace internal
18{
19
20class Manager;
21
22} // namespace internal
23
Patrick Williams9b18bf22022-07-22 19:26:55 -050024using CreateIface = sdbusplus::server::object_t<
Dhruvaraj Subhashchandranfef66a92020-09-06 13:10:59 -050025 sdbusplus::xyz::openbmc_project::Dump::server::Create>;
26
27using UserMap = phosphor::dump::inotify::UserMap;
28
29using Type =
30 sdbusplus::xyz::openbmc_project::Dump::Internal::server::Create::Type;
31
Dhruvaraj Subhashchandranfef66a92020-09-06 13:10:59 -050032using Watch = phosphor::dump::inotify::Watch;
33
34// Type to dreport type string map
35static const std::map<Type, std::string> TypeMap = {
36 {Type::ApplicationCored, "core"},
37 {Type::UserRequested, "user"},
38 {Type::InternalFailure, "elog"},
George Liuff92ffe2021-02-09 15:01:53 +080039 {Type::Checkstop, "checkstop"},
40 {Type::Ramoops, "ramoops"}};
Dhruvaraj Subhashchandranfef66a92020-09-06 13:10:59 -050041
42/** @class Manager
43 * @brief OpenBMC Dump manager implementation.
44 * @details A concrete implementation for the
45 * xyz.openbmc_project.Dump.Create DBus API
46 */
Jayanth Othayoth0af74a52021-04-08 03:55:21 -050047class Manager :
48 virtual public CreateIface,
49 virtual public phosphor::dump::Manager
Dhruvaraj Subhashchandranfef66a92020-09-06 13:10:59 -050050{
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 */
Patrick Williams9b18bf22022-07-22 19:26:55 -050068 Manager(sdbusplus::bus_t& bus, const EventPtr& event, const char* path,
Dhruvaraj Subhashchandranfef66a92020-09-06 13:10:59 -050069 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)
Jayanth Othayoth0af74a52021-04-08 03:55:21 -050079 {}
Dhruvaraj Subhashchandranfef66a92020-09-06 13:10:59 -050080
81 /** @brief Implementation of dump watch call back
82 * @param [in] fileInfo - map of file info path:event
83 */
84 void watchCallback(const UserMap& fileInfo);
85
86 /** @brief Construct dump d-bus objects from their persisted
87 * representations.
88 */
89 void restore() override;
90
91 /** @brief Implementation for CreateDump
Dhruvaraj Subhashchandran6ccb50e2020-10-29 09:33:18 -050092 * Method to create a BMC dump entry when user requests for a new BMC dump
Dhruvaraj Subhashchandranfef66a92020-09-06 13:10:59 -050093 *
Dhruvaraj Subhashchandran6ccb50e2020-10-29 09:33:18 -050094 * @return object_path - The object path of the new dump entry.
Dhruvaraj Subhashchandranfef66a92020-09-06 13:10:59 -050095 */
Dhruvaraj Subhashchandran969f9a52020-10-30 01:42:39 -050096 sdbusplus::message::object_path
Dhruvaraj Subhashchandranddc33662021-07-19 09:28:42 -050097 createDump(phosphor::dump::DumpCreateParams params) override;
Dhruvaraj Subhashchandranfef66a92020-09-06 13:10:59 -050098
99 private:
100 /** @brief Create Dump entry d-bus object
101 * @param[in] fullPath - Full path of the Dump file name
102 */
Jayanth Othayoth3fc6df42021-04-08 03:45:24 -0500103 void createEntry(const std::filesystem::path& fullPath);
Dhruvaraj Subhashchandranfef66a92020-09-06 13:10:59 -0500104
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 */
Marri Devender Rao73953b82022-02-15 09:15:42 -0600121 static int callback(sd_event_source*, const siginfo_t*, void* type)
Dhruvaraj Subhashchandranfef66a92020-09-06 13:10:59 -0500122 {
Marri Devender Rao73953b82022-02-15 09:15:42 -0600123 Type* ptr = reinterpret_cast<Type*>(type);
124 if (*ptr == Type::UserRequested)
125 {
126 fUserDumpInProgress = false;
127 }
128 delete ptr;
Dhruvaraj Subhashchandranfef66a92020-09-06 13:10:59 -0500129 return 0;
130 }
131 /** @brief Remove specified watch object pointer from the
132 * watch map and associated entry from the map.
133 * @param[in] path - unique identifier of the map
134 */
Jayanth Othayoth3fc6df42021-04-08 03:45:24 -0500135 void removeWatch(const std::filesystem::path& path);
Dhruvaraj Subhashchandranfef66a92020-09-06 13:10:59 -0500136
137 /** @brief Calculate per dump allowed size based on the available
138 * size in the dump location.
139 * @returns dump size in kilobytes.
140 */
141 size_t getAllowedSize();
142
143 /** @brief sdbusplus Dump event loop */
144 EventPtr eventLoop;
145
146 /** @brief Dump main watch object */
147 Watch dumpWatch;
148
149 /** @brief Path to the dump file*/
150 std::string dumpDir;
151
Marri Devender Rao73953b82022-02-15 09:15:42 -0600152 /** @brief Flag to reject user intiated dump if a dump is in progress*/
153 // TODO: https://github.com/openbmc/phosphor-debug-collector/issues/19
154 static bool fUserDumpInProgress;
155
Dhruvaraj Subhashchandranfef66a92020-09-06 13:10:59 -0500156 /** @brief Child directory path and its associated watch object map
157 * [path:watch object]
158 */
Jayanth Othayoth3fc6df42021-04-08 03:45:24 -0500159 std::map<std::filesystem::path, std::unique_ptr<Watch>> childWatchMap;
Dhruvaraj Subhashchandranfef66a92020-09-06 13:10:59 -0500160};
161
162} // namespace bmc
163} // namespace dump
164} // namespace phosphor