blob: 694cf7baa97ea09d83513d9c563d460b1a6277e4 [file] [log] [blame]
Jayanth Othayotha320c7c2017-06-14 07:17:21 -05001#pragma once
2
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -05003#include "config.h"
Jayanth Othayoth671fc7f2017-06-14 08:01:41 -05004
Jayanth Othayotha320c7c2017-06-14 07:17:21 -05005#include "dump_entry.hpp"
Jayanth Othayoth671fc7f2017-06-14 08:01:41 -05006#include "dump_utils.hpp"
Jayanth Othayothbcb174b2017-07-02 06:29:24 -05007#include "watch.hpp"
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -05008#include "xyz/openbmc_project/Collection/DeleteAll/server.hpp"
9#include "xyz/openbmc_project/Dump/Internal/Create/server.hpp"
10
11#include <experimental/filesystem>
12#include <sdbusplus/bus.hpp>
13#include <sdbusplus/server/object.hpp>
14#include <xyz/openbmc_project/Dump/Create/server.hpp>
Jayanth Othayotha320c7c2017-06-14 07:17:21 -050015
16namespace phosphor
17{
18namespace dump
19{
20namespace internal
21{
22
23class Manager;
24
25} // namespace internal
26
Jayanth Othayothbcb174b2017-07-02 06:29:24 -050027using UserMap = phosphor::dump::inotify::UserMap;
28
Jayanth Othayotha320c7c2017-06-14 07:17:21 -050029using Type =
30 sdbusplus::xyz::openbmc_project::Dump::Internal::server::Create::Type;
31
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -050032using CreateIface = sdbusplus::server::object::object<
33 sdbusplus::xyz::openbmc_project::Collection::server::DeleteAll,
34 sdbusplus::xyz::openbmc_project::Dump::server::Create>;
Jayanth Othayotha320c7c2017-06-14 07:17:21 -050035
Jayanth Othayoth671fc7f2017-06-14 08:01:41 -050036namespace fs = std::experimental::filesystem;
Jayanth Othayotha320c7c2017-06-14 07:17:21 -050037
Jayanth Othayoth764d1b22017-07-12 19:14:02 -050038using Watch = phosphor::dump::inotify::Watch;
39
Marri Devender Rao0deb2872018-11-12 07:45:54 -060040// Type to dreport type string map
41static const std::map<Type, std::string> TypeMap = {
42 {Type::ApplicationCored, "core"},
43 {Type::UserRequested, "user"},
44 {Type::InternalFailure, "elog"},
45 {Type::Checkstop, "checkstop"}};
46
Jayanth Othayotha320c7c2017-06-14 07:17:21 -050047/** @class Manager
48 * @brief OpenBMC Dump manager implementation.
49 * @details A concrete implementation for the
Nagaraju Goruganti3c899a42017-09-12 06:14:46 -050050 * xyz.openbmc_project.Dump.Create DBus API and
51 * xyz::openbmc_project::Collection::server::DeleteAll.
Jayanth Othayotha320c7c2017-06-14 07:17:21 -050052 */
53class Manager : public CreateIface
54{
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -050055 friend class internal::Manager;
56 friend class Entry;
Jayanth Othayotha320c7c2017-06-14 07:17:21 -050057
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -050058 public:
59 Manager() = delete;
60 Manager(const Manager&) = default;
61 Manager& operator=(const Manager&) = delete;
62 Manager(Manager&&) = delete;
63 Manager& operator=(Manager&&) = delete;
64 virtual ~Manager() = default;
Jayanth Othayotha320c7c2017-06-14 07:17:21 -050065
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -050066 /** @brief Constructor to put object onto bus at a dbus path.
67 * @param[in] bus - Bus to attach to.
68 * @param[in] event - Dump manager sd_event loop.
69 * @param[in] path - Path to attach at.
70 */
71 Manager(sdbusplus::bus::bus& bus, const EventPtr& event, const char* path) :
72 CreateIface(bus, path), bus(bus), eventLoop(event.get()),
73 lastEntryId(0),
74 dumpWatch(
75 eventLoop, IN_NONBLOCK, IN_CLOSE_WRITE | IN_CREATE, EPOLLIN,
76 BMC_DUMP_PATH,
77 std::bind(std::mem_fn(&phosphor::dump::Manager::watchCallback),
78 this, std::placeholders::_1))
79 {
80 }
Jayanth Othayotha320c7c2017-06-14 07:17:21 -050081
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -050082 /** @brief Implementation for CreateDump
83 * Method to create Dump.
84 *
85 * @return id - The Dump entry id number.
86 */
87 uint32_t createDump() override;
Jayanth Othayotha320c7c2017-06-14 07:17:21 -050088
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -050089 /** @brief Implementation of dump watch call back
90 * @param [in] fileInfo - map of file info path:event
91 */
92 void watchCallback(const UserMap& fileInfo);
Jayanth Othayothbcb174b2017-07-02 06:29:24 -050093
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -050094 /** @brief Construct dump d-bus objects from their persisted
95 * representations.
96 */
97 void restore();
Jayanth Othayoth43096592017-07-20 02:17:37 -050098
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -050099 private:
100 /** @brief Create Dump entry d-bus object
101 * @param[in] fullPath - Full path of the Dump file name
102 */
103 void createEntry(const fs::path& fullPath);
Jayanth Othayotha320c7c2017-06-14 07:17:21 -0500104
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -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);
Jayanth Othayotha320c7c2017-06-14 07:17:21 -0500112
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -0500113 /** @brief Erase specified entry d-bus object
114 *
115 * @param[in] entryId - unique identifier of the entry
116 */
117 void erase(uint32_t entryId);
Jayanth Othayotha320c7c2017-06-14 07:17:21 -0500118
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -0500119 /** @brief Erase all BMC dump entries and Delete all Dump files
120 * from Permanent location
121 *
122 */
123 void deleteAll() override;
Nagaraju Goruganti3c899a42017-09-12 06:14:46 -0500124
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -0500125 /** @brief sd_event_add_child callback
126 *
127 * @param[in] s - event source
128 * @param[in] si - signal info
129 * @param[in] userdata - pointer to Watch object
130 *
131 * @returns 0 on success, -1 on fail
132 */
133 static int callback(sd_event_source* s, const siginfo_t* si, void* userdata)
134 {
135 // No specific action required in
136 // the sd_event_add_child callback.
137 return 0;
138 }
139 /** @brief Remove specified watch object pointer from the
140 * watch map and associated entry from the map.
141 * @param[in] path - unique identifier of the map
142 */
143 void removeWatch(const fs::path& path);
Jayanth Othayotha320c7c2017-06-14 07:17:21 -0500144
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -0500145 /** @brief Calculate per dump allowed size based on the available
146 * size in the dump location.
147 * @returns dump size in kilobytes.
148 */
149 size_t getAllowedSize();
Jayanth Othayothab7f9202017-08-02 06:24:58 -0500150
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -0500151 /** @brief sdbusplus DBus bus connection. */
152 sdbusplus::bus::bus& bus;
Jayanth Othayotha320c7c2017-06-14 07:17:21 -0500153
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -0500154 /** @brief sdbusplus Dump event loop */
155 EventPtr eventLoop;
Jayanth Othayotha320c7c2017-06-14 07:17:21 -0500156
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -0500157 /** @brief Dump Entry dbus objects map based on entry id */
158 std::map<uint32_t, std::unique_ptr<Entry>> entries;
Jayanth Othayotha320c7c2017-06-14 07:17:21 -0500159
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -0500160 /** @brief Id of the last Dump entry */
161 uint32_t lastEntryId;
Jayanth Othayothbcb174b2017-07-02 06:29:24 -0500162
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -0500163 /** @brief Dump main watch object */
164 Watch dumpWatch;
Jayanth Othayoth764d1b22017-07-12 19:14:02 -0500165
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -0500166 /** @brief Child directory path and its associated watch object map
167 * [path:watch object]
168 */
169 std::map<fs::path, std::unique_ptr<Watch>> childWatchMap;
Jayanth Othayotha320c7c2017-06-14 07:17:21 -0500170};
171
172} // namespace dump
173} // namespace phosphor