blob: 762f9459a899774e413254320e9cb29b16c2ef61 [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
Jayanth Othayoth3fc6df42021-04-08 03:45:24 -05008#include <filesystem>
Dhruvaraj Subhashchandranfef66a92020-09-06 13:10:59 -05009#include <xyz/openbmc_project/Dump/Create/server.hpp>
10
11namespace phosphor
12{
13namespace dump
14{
15namespace bmc
16{
17namespace internal
18{
19
20class Manager;
21
22} // namespace internal
23
24using CreateIface = sdbusplus::server::object::object<
25 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"},
39 {Type::Checkstop, "checkstop"}};
40
41/** @class Manager
42 * @brief OpenBMC Dump manager implementation.
43 * @details A concrete implementation for the
44 * xyz.openbmc_project.Dump.Create DBus API
45 */
46class Manager : virtual public CreateIface,
47 virtual public phosphor::dump::Manager
48{
49 friend class internal::Manager;
50
51 public:
52 Manager() = delete;
53 Manager(const Manager&) = default;
54 Manager& operator=(const Manager&) = delete;
55 Manager(Manager&&) = delete;
56 Manager& operator=(Manager&&) = delete;
57 virtual ~Manager() = default;
58
59 /** @brief Constructor to put object onto bus at a dbus path.
60 * @param[in] bus - Bus to attach to.
61 * @param[in] event - Dump manager sd_event loop.
62 * @param[in] path - Path to attach at.
63 * @param[in] baseEntryPath - Base path for dump entry.
64 * @param[in] filePath - Path where the dumps are stored.
65 */
66 Manager(sdbusplus::bus::bus& bus, const EventPtr& event, const char* path,
67 const std::string& baseEntryPath, const char* filePath) :
68 CreateIface(bus, path),
69 phosphor::dump::Manager(bus, path, baseEntryPath),
70 eventLoop(event.get()),
71 dumpWatch(
72 eventLoop, IN_NONBLOCK, IN_CLOSE_WRITE | IN_CREATE, EPOLLIN,
73 filePath,
74 std::bind(std::mem_fn(&phosphor::dump::bmc::Manager::watchCallback),
75 this, std::placeholders::_1)),
76 dumpDir(filePath)
77 {
78 }
79
80 /** @brief Implementation of dump watch call back
81 * @param [in] fileInfo - map of file info path:event
82 */
83 void watchCallback(const UserMap& fileInfo);
84
85 /** @brief Construct dump d-bus objects from their persisted
86 * representations.
87 */
88 void restore() override;
89
90 /** @brief Implementation for CreateDump
Dhruvaraj Subhashchandran6ccb50e2020-10-29 09:33:18 -050091 * Method to create a BMC dump entry when user requests for a new BMC dump
Dhruvaraj Subhashchandranfef66a92020-09-06 13:10:59 -050092 *
Dhruvaraj Subhashchandran6ccb50e2020-10-29 09:33:18 -050093 * @return object_path - The object path of the new dump entry.
Dhruvaraj Subhashchandranfef66a92020-09-06 13:10:59 -050094 */
Dhruvaraj Subhashchandran969f9a52020-10-30 01:42:39 -050095 sdbusplus::message::object_path
96 createDump(std::map<std::string, std::string> params) override;
Dhruvaraj Subhashchandranfef66a92020-09-06 13:10:59 -050097
98 private:
99 /** @brief Create Dump entry d-bus object
100 * @param[in] fullPath - Full path of the Dump file name
101 */
Jayanth Othayoth3fc6df42021-04-08 03:45:24 -0500102 void createEntry(const std::filesystem::path& fullPath);
Dhruvaraj Subhashchandranfef66a92020-09-06 13:10:59 -0500103
104 /** @brief Capture BMC Dump based on the Dump type.
105 * @param[in] type - Type of the Dump.
106 * @param[in] fullPaths - List of absolute paths to the files
107 * to be included as part of Dump package.
108 * @return id - The Dump entry id number.
109 */
110 uint32_t captureDump(Type type, const std::vector<std::string>& fullPaths);
111
112 /** @brief sd_event_add_child callback
113 *
114 * @param[in] s - event source
115 * @param[in] si - signal info
116 * @param[in] userdata - pointer to Watch object
117 *
118 * @returns 0 on success, -1 on fail
119 */
120 static int callback(sd_event_source*, const siginfo_t*, void*)
121 {
122 // No specific action required in
123 // the sd_event_add_child callback.
124 return 0;
125 }
126 /** @brief Remove specified watch object pointer from the
127 * watch map and associated entry from the map.
128 * @param[in] path - unique identifier of the map
129 */
Jayanth Othayoth3fc6df42021-04-08 03:45:24 -0500130 void removeWatch(const std::filesystem::path& path);
Dhruvaraj Subhashchandranfef66a92020-09-06 13:10:59 -0500131
132 /** @brief Calculate per dump allowed size based on the available
133 * size in the dump location.
134 * @returns dump size in kilobytes.
135 */
136 size_t getAllowedSize();
137
138 /** @brief sdbusplus Dump event loop */
139 EventPtr eventLoop;
140
141 /** @brief Dump main watch object */
142 Watch dumpWatch;
143
144 /** @brief Path to the dump file*/
145 std::string dumpDir;
146
147 /** @brief Child directory path and its associated watch object map
148 * [path:watch object]
149 */
Jayanth Othayoth3fc6df42021-04-08 03:45:24 -0500150 std::map<std::filesystem::path, std::unique_ptr<Watch>> childWatchMap;
Dhruvaraj Subhashchandranfef66a92020-09-06 13:10:59 -0500151};
152
153} // namespace bmc
154} // namespace dump
155} // namespace phosphor