blob: f12d7ff4b4dc107de928bad833c31261c9da7be2 [file] [log] [blame]
Jayanth Othayotha320c7c2017-06-14 07:17:21 -05001#pragma once
2
Jayanth Othayoth671fc7f2017-06-14 08:01:41 -05003#include <experimental/filesystem>
4
Jayanth Othayotha320c7c2017-06-14 07:17:21 -05005#include <sdbusplus/bus.hpp>
6#include <sdbusplus/server/object.hpp>
7#include <xyz/openbmc_project/Dump/Create/server.hpp>
Jayanth Othayotha320c7c2017-06-14 07:17:21 -05008
9#include "xyz/openbmc_project/Dump/Internal/Create/server.hpp"
Nagaraju Goruganti3c899a42017-09-12 06:14:46 -050010#include "xyz/openbmc_project/Collection/DeleteAll/server.hpp"
Jayanth Othayotha320c7c2017-06-14 07:17:21 -050011#include "dump_entry.hpp"
Jayanth Othayoth671fc7f2017-06-14 08:01:41 -050012#include "dump_utils.hpp"
Jayanth Othayothbcb174b2017-07-02 06:29:24 -050013#include "watch.hpp"
14#include "config.h"
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
Nagaraju Goruganti3c899a42017-09-12 06:14:46 -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
Jayanth Othayotha320c7c2017-06-14 07:17:21 -050040/** @class Manager
41 * @brief OpenBMC Dump manager implementation.
42 * @details A concrete implementation for the
Nagaraju Goruganti3c899a42017-09-12 06:14:46 -050043 * xyz.openbmc_project.Dump.Create DBus API and
44 * xyz::openbmc_project::Collection::server::DeleteAll.
Jayanth Othayotha320c7c2017-06-14 07:17:21 -050045 */
46class Manager : public CreateIface
47{
48 friend class internal::Manager;
49 friend class Entry;
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 */
64 Manager(sdbusplus::bus::bus& bus,
65 const EventPtr& event, const char* path) :
66 CreateIface(bus, path),
67 bus(bus),
68 eventLoop(event.get()),
Jayanth Othayothbcb174b2017-07-02 06:29:24 -050069 lastEntryId(0),
70 dumpWatch(eventLoop,
71 IN_NONBLOCK,
Jayanth Othayothec608a52017-08-01 05:23:35 -050072 IN_CLOSE_WRITE | IN_CREATE,
Jayanth Othayothbcb174b2017-07-02 06:29:24 -050073 EPOLLIN,
Jayanth Othayoth2dccfe42017-07-12 18:20:40 -050074 BMC_DUMP_PATH,
Jayanth Othayothbcb174b2017-07-02 06:29:24 -050075 std::bind(
76 std::mem_fn(
77 &phosphor::dump::Manager::watchCallback),
78 this, std::placeholders::_1))
Jayanth Othayotha320c7c2017-06-14 07:17:21 -050079 {}
80
81 /** @brief Implementation for CreateDump
82 * Method to create Dump.
83 *
84 * @return id - The Dump entry id number.
85 */
86 uint32_t createDump() override;
87
Jayanth Othayothbcb174b2017-07-02 06:29:24 -050088 /** @brief Implementation of dump watch call back
89 * @param [in] fileInfo - map of file info path:event
90 */
91 void watchCallback(const UserMap& fileInfo);
92
Jayanth Othayoth43096592017-07-20 02:17:37 -050093 /** @brief Construct dump d-bus objects from their persisted
94 * representations.
95 */
96 void restore();
97
Jayanth Othayotha320c7c2017-06-14 07:17:21 -050098 private:
99 /** @brief Create Dump entry d-bus object
100 * @param[in] fullPath - Full path of the Dump file name
101 */
102 void createEntry(const fs::path& fullPath);
103
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(
111 Type type,
112 const std::vector<std::string>& fullPaths);
113
114 /** @brief Erase specified entry d-bus object
115 *
116 * @param[in] entryId - unique identifier of the entry
117 */
118 void erase(uint32_t entryId);
119
Nagaraju Goruganti3c899a42017-09-12 06:14:46 -0500120 /** @brief Erase all BMC dump entries and Delete all Dump files
121 * from Permanent location
122 *
123 */
124 void deleteAll() override;
125
Jayanth Othayotha320c7c2017-06-14 07:17:21 -0500126 /** @brief sd_event_add_child callback
127 *
128 * @param[in] s - event source
129 * @param[in] si - signal info
130 * @param[in] userdata - pointer to Watch object
131 *
132 * @returns 0 on success, -1 on fail
133 */
134 static int callback(sd_event_source* s,
135 const siginfo_t* si,
136 void* userdata)
137 {
138 //No specific action required in
139 //the sd_event_add_child callback.
140 return 0;
141 }
Jayanth Othayoth764d1b22017-07-12 19:14:02 -0500142 /** @brief Remove specified watch object pointer from the
143 * watch map and associated entry from the map.
144 * @param[in] path - unique identifier of the map
145 */
146 void removeWatch(const fs::path& path);
Jayanth Othayotha320c7c2017-06-14 07:17:21 -0500147
Jayanth Othayoth104f57c2017-08-09 06:19:32 -0500148 /** @brief Calculate per dump allowed size based on the available
149 * size in the dump location.
150 * @returns dump size in kilobytes.
Jayanth Othayothab7f9202017-08-02 06:24:58 -0500151 */
152 size_t getAllowedSize();
153
Jayanth Othayotha320c7c2017-06-14 07:17:21 -0500154 /** @brief sdbusplus DBus bus connection. */
155 sdbusplus::bus::bus& bus;
156
157 /** @brief sdbusplus Dump event loop */
158 EventPtr eventLoop;
159
160 /** @brief Dump Entry dbus objects map based on entry id */
161 std::map<uint32_t, std::unique_ptr<Entry>> entries;
162
163 /** @brief Id of the last Dump entry */
164 uint32_t lastEntryId;
Jayanth Othayothbcb174b2017-07-02 06:29:24 -0500165
Jayanth Othayoth764d1b22017-07-12 19:14:02 -0500166 /** @brief Dump main watch object */
167 Watch dumpWatch;
168
169 /** @brief Child directory path and its associated watch object map
170 * [path:watch object]
171 */
172 std::map<fs::path, std::unique_ptr<Watch>> childWatchMap;
Jayanth Othayotha320c7c2017-06-14 07:17:21 -0500173};
174
175} // namespace dump
176} // namespace phosphor