blob: f4147528b353f57b313bbaa1b31a77ace3c93a75 [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
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{
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -050048 friend class internal::Manager;
49 friend class Entry;
Jayanth Othayotha320c7c2017-06-14 07:17:21 -050050
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -050051 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;
Jayanth Othayotha320c7c2017-06-14 07:17:21 -050058
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -050059 /** @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, const EventPtr& event, const char* path) :
65 CreateIface(bus, path), bus(bus), eventLoop(event.get()),
66 lastEntryId(0),
67 dumpWatch(
68 eventLoop, IN_NONBLOCK, IN_CLOSE_WRITE | IN_CREATE, EPOLLIN,
69 BMC_DUMP_PATH,
70 std::bind(std::mem_fn(&phosphor::dump::Manager::watchCallback),
71 this, std::placeholders::_1))
72 {
73 }
Jayanth Othayotha320c7c2017-06-14 07:17:21 -050074
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -050075 /** @brief Implementation for CreateDump
76 * Method to create Dump.
77 *
78 * @return id - The Dump entry id number.
79 */
80 uint32_t createDump() override;
Jayanth Othayotha320c7c2017-06-14 07:17:21 -050081
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -050082 /** @brief Implementation of dump watch call back
83 * @param [in] fileInfo - map of file info path:event
84 */
85 void watchCallback(const UserMap& fileInfo);
Jayanth Othayothbcb174b2017-07-02 06:29:24 -050086
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -050087 /** @brief Construct dump d-bus objects from their persisted
88 * representations.
89 */
90 void restore();
Jayanth Othayoth43096592017-07-20 02:17:37 -050091
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -050092 private:
93 /** @brief Create Dump entry d-bus object
94 * @param[in] fullPath - Full path of the Dump file name
95 */
96 void createEntry(const fs::path& fullPath);
Jayanth Othayotha320c7c2017-06-14 07:17:21 -050097
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -050098 /** @brief Capture BMC Dump based on the Dump type.
99 * @param[in] type - Type of the Dump.
100 * @param[in] fullPaths - List of absolute paths to the files
101 * to be included as part of Dump package.
102 * @return id - The Dump entry id number.
103 */
104 uint32_t captureDump(Type type, const std::vector<std::string>& fullPaths);
Jayanth Othayotha320c7c2017-06-14 07:17:21 -0500105
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -0500106 /** @brief Erase specified entry d-bus object
107 *
108 * @param[in] entryId - unique identifier of the entry
109 */
110 void erase(uint32_t entryId);
Jayanth Othayotha320c7c2017-06-14 07:17:21 -0500111
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -0500112 /** @brief Erase all BMC dump entries and Delete all Dump files
113 * from Permanent location
114 *
115 */
116 void deleteAll() override;
Nagaraju Goruganti3c899a42017-09-12 06:14:46 -0500117
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -0500118 /** @brief sd_event_add_child callback
119 *
120 * @param[in] s - event source
121 * @param[in] si - signal info
122 * @param[in] userdata - pointer to Watch object
123 *
124 * @returns 0 on success, -1 on fail
125 */
126 static int callback(sd_event_source* s, const siginfo_t* si, void* userdata)
127 {
128 // No specific action required in
129 // the sd_event_add_child callback.
130 return 0;
131 }
132 /** @brief Remove specified watch object pointer from the
133 * watch map and associated entry from the map.
134 * @param[in] path - unique identifier of the map
135 */
136 void removeWatch(const fs::path& path);
Jayanth Othayotha320c7c2017-06-14 07:17:21 -0500137
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -0500138 /** @brief Calculate per dump allowed size based on the available
139 * size in the dump location.
140 * @returns dump size in kilobytes.
141 */
142 size_t getAllowedSize();
Jayanth Othayothab7f9202017-08-02 06:24:58 -0500143
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -0500144 /** @brief sdbusplus DBus bus connection. */
145 sdbusplus::bus::bus& bus;
Jayanth Othayotha320c7c2017-06-14 07:17:21 -0500146
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -0500147 /** @brief sdbusplus Dump event loop */
148 EventPtr eventLoop;
Jayanth Othayotha320c7c2017-06-14 07:17:21 -0500149
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -0500150 /** @brief Dump Entry dbus objects map based on entry id */
151 std::map<uint32_t, std::unique_ptr<Entry>> entries;
Jayanth Othayotha320c7c2017-06-14 07:17:21 -0500152
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -0500153 /** @brief Id of the last Dump entry */
154 uint32_t lastEntryId;
Jayanth Othayothbcb174b2017-07-02 06:29:24 -0500155
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -0500156 /** @brief Dump main watch object */
157 Watch dumpWatch;
Jayanth Othayoth764d1b22017-07-12 19:14:02 -0500158
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -0500159 /** @brief Child directory path and its associated watch object map
160 * [path:watch object]
161 */
162 std::map<fs::path, std::unique_ptr<Watch>> childWatchMap;
Jayanth Othayotha320c7c2017-06-14 07:17:21 -0500163};
164
165} // namespace dump
166} // namespace phosphor