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