blob: 7445c1cb9b7c3c355a422eda1ed8ac2c19dd08e0 [file] [log] [blame]
Dhruvaraj Subhashchandranfef66a92020-09-06 13:10:59 -05001#pragma once
2
Dhruvaraj Subhashchandran93f06412024-06-02 05:16:51 -05003#include "dump_entry.hpp"
Dhruvaraj Subhashchandranfef66a92020-09-06 13:10:59 -05004#include "dump_manager.hpp"
5#include "dump_utils.hpp"
6#include "watch.hpp"
Dhruvaraj Subhashchandranfef66a92020-09-06 13:10:59 -05007
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{
Dhruvaraj Subhashchandranfef66a92020-09-06 13:10:59 -050020
Patrick Williams9b18bf22022-07-22 19:26:55 -050021using CreateIface = sdbusplus::server::object_t<
Dhruvaraj Subhashchandranfef66a92020-09-06 13:10:59 -050022 sdbusplus::xyz::openbmc_project::Dump::server::Create>;
23
24using UserMap = phosphor::dump::inotify::UserMap;
25
Dhruvaraj Subhashchandranfef66a92020-09-06 13:10:59 -050026using Watch = phosphor::dump::inotify::Watch;
Marri Devender Rao3ed02c32022-06-28 23:12:14 -050027using ::sdeventplus::source::Child;
Dhruvaraj Subhashchandranfef66a92020-09-06 13:10:59 -050028
29/** @class Manager
30 * @brief OpenBMC Dump manager implementation.
31 * @details A concrete implementation for the
32 * xyz.openbmc_project.Dump.Create DBus API
33 */
Jayanth Othayoth0af74a52021-04-08 03:55:21 -050034class Manager :
35 virtual public CreateIface,
36 virtual public phosphor::dump::Manager
Dhruvaraj Subhashchandranfef66a92020-09-06 13:10:59 -050037{
Dhruvaraj Subhashchandranfef66a92020-09-06 13:10:59 -050038 public:
39 Manager() = delete;
Jayanth Othayoth4f68fc42024-11-25 10:04:07 -060040 Manager(const Manager&) = delete;
Dhruvaraj Subhashchandranfef66a92020-09-06 13:10:59 -050041 Manager& operator=(const Manager&) = delete;
42 Manager(Manager&&) = delete;
43 Manager& operator=(Manager&&) = delete;
44 virtual ~Manager() = default;
45
46 /** @brief Constructor to put object onto bus at a dbus path.
47 * @param[in] bus - Bus to attach to.
48 * @param[in] event - Dump manager sd_event loop.
49 * @param[in] path - Path to attach at.
50 * @param[in] baseEntryPath - Base path for dump entry.
51 * @param[in] filePath - Path where the dumps are stored.
52 */
Patrick Williams9b18bf22022-07-22 19:26:55 -050053 Manager(sdbusplus::bus_t& bus, const EventPtr& event, const char* path,
Dhruvaraj Subhashchandranfef66a92020-09-06 13:10:59 -050054 const std::string& baseEntryPath, const char* filePath) :
55 CreateIface(bus, path),
56 phosphor::dump::Manager(bus, path, baseEntryPath),
57 eventLoop(event.get()),
58 dumpWatch(
59 eventLoop, IN_NONBLOCK, IN_CLOSE_WRITE | IN_CREATE, EPOLLIN,
60 filePath,
61 std::bind(std::mem_fn(&phosphor::dump::bmc::Manager::watchCallback),
62 this, std::placeholders::_1)),
63 dumpDir(filePath)
Jayanth Othayoth0af74a52021-04-08 03:55:21 -050064 {}
Dhruvaraj Subhashchandranfef66a92020-09-06 13:10:59 -050065
66 /** @brief Implementation of dump watch call back
67 * @param [in] fileInfo - map of file info path:event
68 */
69 void watchCallback(const UserMap& fileInfo);
70
71 /** @brief Construct dump d-bus objects from their persisted
72 * representations.
73 */
74 void restore() override;
75
76 /** @brief Implementation for CreateDump
Dhruvaraj Subhashchandran6ccb50e2020-10-29 09:33:18 -050077 * Method to create a BMC dump entry when user requests for a new BMC dump
Dhruvaraj Subhashchandranfef66a92020-09-06 13:10:59 -050078 *
Dhruvaraj Subhashchandran6ccb50e2020-10-29 09:33:18 -050079 * @return object_path - The object path of the new dump entry.
Dhruvaraj Subhashchandranfef66a92020-09-06 13:10:59 -050080 */
Dhruvaraj Subhashchandran969f9a52020-10-30 01:42:39 -050081 sdbusplus::message::object_path
Dhruvaraj Subhashchandranddc33662021-07-19 09:28:42 -050082 createDump(phosphor::dump::DumpCreateParams params) override;
Dhruvaraj Subhashchandranfef66a92020-09-06 13:10:59 -050083
84 private:
85 /** @brief Create Dump entry d-bus object
86 * @param[in] fullPath - Full path of the Dump file name
87 */
Jayanth Othayoth3fc6df42021-04-08 03:45:24 -050088 void createEntry(const std::filesystem::path& fullPath);
Dhruvaraj Subhashchandranfef66a92020-09-06 13:10:59 -050089
Dhruvaraj Subhashchandran36047102023-06-29 03:46:25 -050090 /** @brief Capture BMC Dump based on the Dump type.
91 * @param[in] type - Type of the dump to pass to dreport
92 * @param[in] path - An absolute path to the file
93 * to be included as part of Dump package.
94 * @return id - The Dump entry id number.
95 */
96 uint32_t captureDump(DumpTypes type, const std::string& path);
97
Dhruvaraj Subhashchandranfef66a92020-09-06 13:10:59 -050098 /** @brief Remove specified watch object pointer from the
99 * watch map and associated entry from the map.
100 * @param[in] path - unique identifier of the map
101 */
Jayanth Othayoth3fc6df42021-04-08 03:45:24 -0500102 void removeWatch(const std::filesystem::path& path);
Dhruvaraj Subhashchandranfef66a92020-09-06 13:10:59 -0500103
104 /** @brief Calculate per dump allowed size based on the available
105 * size in the dump location.
106 * @returns dump size in kilobytes.
107 */
108 size_t getAllowedSize();
109
110 /** @brief sdbusplus Dump event loop */
111 EventPtr eventLoop;
112
113 /** @brief Dump main watch object */
114 Watch dumpWatch;
115
116 /** @brief Path to the dump file*/
117 std::string dumpDir;
118
Marri Devender Rao73953b82022-02-15 09:15:42 -0600119 /** @brief Flag to reject user intiated dump if a dump is in progress*/
120 // TODO: https://github.com/openbmc/phosphor-debug-collector/issues/19
121 static bool fUserDumpInProgress;
122
Dhruvaraj Subhashchandranfef66a92020-09-06 13:10:59 -0500123 /** @brief Child directory path and its associated watch object map
124 * [path:watch object]
125 */
Jayanth Othayoth3fc6df42021-04-08 03:45:24 -0500126 std::map<std::filesystem::path, std::unique_ptr<Watch>> childWatchMap;
Marri Devender Rao3ed02c32022-06-28 23:12:14 -0500127
128 /** @brief map of SDEventPlus child pointer added to event loop */
129 std::map<pid_t, std::unique_ptr<Child>> childPtrMap;
Dhruvaraj Subhashchandranfef66a92020-09-06 13:10:59 -0500130};
131
132} // namespace bmc
133} // namespace dump
134} // namespace phosphor