blob: 6dbb7ad5140a378fa8ff9797bf4d08c185517bd3 [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
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
Patrick Williams9b18bf22022-07-22 19:26:55 -050027using CreateIface = sdbusplus::server::object_t<
Dhruvaraj Subhashchandranfef66a92020-09-06 13:10:59 -050028 sdbusplus::xyz::openbmc_project::Dump::server::Create>;
29
30using UserMap = phosphor::dump::inotify::UserMap;
31
32using Type =
33 sdbusplus::xyz::openbmc_project::Dump::Internal::server::Create::Type;
34
Dhruvaraj Subhashchandranfef66a92020-09-06 13:10:59 -050035using Watch = phosphor::dump::inotify::Watch;
Marri Devender Rao3ed02c32022-06-28 23:12:14 -050036using ::sdeventplus::source::Child;
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,
52 virtual public phosphor::dump::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),
74 phosphor::dump::Manager(bus, path, baseEntryPath),
75 eventLoop(event.get()),
76 dumpWatch(
77 eventLoop, IN_NONBLOCK, IN_CLOSE_WRITE | IN_CREATE, EPOLLIN,
78 filePath,
79 std::bind(std::mem_fn(&phosphor::dump::bmc::Manager::watchCallback),
80 this, std::placeholders::_1)),
81 dumpDir(filePath)
Jayanth Othayoth0af74a52021-04-08 03:55:21 -050082 {}
Dhruvaraj Subhashchandranfef66a92020-09-06 13:10:59 -050083
84 /** @brief Implementation of dump watch call back
85 * @param [in] fileInfo - map of file info path:event
86 */
87 void watchCallback(const UserMap& fileInfo);
88
89 /** @brief Construct dump d-bus objects from their persisted
90 * representations.
91 */
92 void restore() override;
93
94 /** @brief Implementation for CreateDump
Dhruvaraj Subhashchandran6ccb50e2020-10-29 09:33:18 -050095 * Method to create a BMC dump entry when user requests for a new BMC dump
Dhruvaraj Subhashchandranfef66a92020-09-06 13:10:59 -050096 *
Dhruvaraj Subhashchandran6ccb50e2020-10-29 09:33:18 -050097 * @return object_path - The object path of the new dump entry.
Dhruvaraj Subhashchandranfef66a92020-09-06 13:10:59 -050098 */
Dhruvaraj Subhashchandran969f9a52020-10-30 01:42:39 -050099 sdbusplus::message::object_path
Dhruvaraj Subhashchandranddc33662021-07-19 09:28:42 -0500100 createDump(phosphor::dump::DumpCreateParams params) override;
Dhruvaraj Subhashchandranfef66a92020-09-06 13:10:59 -0500101
102 private:
103 /** @brief Create Dump entry d-bus object
104 * @param[in] fullPath - Full path of the Dump file name
105 */
Jayanth Othayoth3fc6df42021-04-08 03:45:24 -0500106 void createEntry(const std::filesystem::path& fullPath);
Dhruvaraj Subhashchandranfef66a92020-09-06 13:10:59 -0500107
108 /** @brief Capture BMC Dump based on the Dump type.
109 * @param[in] type - Type of the Dump.
110 * @param[in] fullPaths - List of absolute paths to the files
111 * to be included as part of Dump package.
112 * @return id - The Dump entry id number.
113 */
114 uint32_t captureDump(Type type, const std::vector<std::string>& fullPaths);
115
Dhruvaraj Subhashchandranfef66a92020-09-06 13:10:59 -0500116 /** @brief Remove specified watch object pointer from the
117 * watch map and associated entry from the map.
118 * @param[in] path - unique identifier of the map
119 */
Jayanth Othayoth3fc6df42021-04-08 03:45:24 -0500120 void removeWatch(const std::filesystem::path& path);
Dhruvaraj Subhashchandranfef66a92020-09-06 13:10:59 -0500121
122 /** @brief Calculate per dump allowed size based on the available
123 * size in the dump location.
124 * @returns dump size in kilobytes.
125 */
126 size_t getAllowedSize();
127
128 /** @brief sdbusplus Dump event loop */
129 EventPtr eventLoop;
130
131 /** @brief Dump main watch object */
132 Watch dumpWatch;
133
134 /** @brief Path to the dump file*/
135 std::string dumpDir;
136
Marri Devender Rao73953b82022-02-15 09:15:42 -0600137 /** @brief Flag to reject user intiated dump if a dump is in progress*/
138 // TODO: https://github.com/openbmc/phosphor-debug-collector/issues/19
139 static bool fUserDumpInProgress;
140
Dhruvaraj Subhashchandranfef66a92020-09-06 13:10:59 -0500141 /** @brief Child directory path and its associated watch object map
142 * [path:watch object]
143 */
Jayanth Othayoth3fc6df42021-04-08 03:45:24 -0500144 std::map<std::filesystem::path, std::unique_ptr<Watch>> childWatchMap;
Marri Devender Rao3ed02c32022-06-28 23:12:14 -0500145
146 /** @brief map of SDEventPlus child pointer added to event loop */
147 std::map<pid_t, std::unique_ptr<Child>> childPtrMap;
Dhruvaraj Subhashchandranfef66a92020-09-06 13:10:59 -0500148};
149
150} // namespace bmc
151} // namespace dump
152} // namespace phosphor