Jayanth Othayoth | 224882b | 2017-05-04 05:46:45 -0500 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Asmitha Karunanithi | 74a1f39 | 2021-10-27 03:23:59 -0500 | [diff] [blame] | 3 | #include "xyz/openbmc_project/Common/OriginatedBy/server.hpp" |
Dhruvaraj Subhashchandran | a6ab806 | 2020-10-29 15:29:10 -0500 | [diff] [blame] | 4 | #include "xyz/openbmc_project/Common/Progress/server.hpp" |
Jayanth Othayoth | 224882b | 2017-05-04 05:46:45 -0500 | [diff] [blame] | 5 | #include "xyz/openbmc_project/Dump/Entry/server.hpp" |
| 6 | #include "xyz/openbmc_project/Object/Delete/server.hpp" |
| 7 | #include "xyz/openbmc_project/Time/EpochTime/server.hpp" |
| 8 | |
Dhruvaraj Subhashchandran | 93f0641 | 2024-06-02 05:16:51 -0500 | [diff] [blame] | 9 | #include <phosphor-logging/lg2.hpp> |
Jayanth Othayoth | cb65ffc | 2018-10-16 08:29:32 -0500 | [diff] [blame] | 10 | #include <sdbusplus/bus.hpp> |
| 11 | #include <sdbusplus/server/object.hpp> |
Dhruvaraj Subhashchandran | 64f8da9 | 2021-12-08 03:48:23 -0600 | [diff] [blame] | 12 | #include <sdeventplus/event.hpp> |
| 13 | #include <sdeventplus/source/event.hpp> |
Jayanth Othayoth | cb65ffc | 2018-10-16 08:29:32 -0500 | [diff] [blame] | 14 | |
Jayanth Othayoth | 0af74a5 | 2021-04-08 03:55:21 -0500 | [diff] [blame] | 15 | #include <filesystem> |
Dhruvaraj Subhashchandran | 93f0641 | 2024-06-02 05:16:51 -0500 | [diff] [blame] | 16 | #include <fstream> |
Jayanth Othayoth | 0af74a5 | 2021-04-08 03:55:21 -0500 | [diff] [blame] | 17 | |
Jayanth Othayoth | 224882b | 2017-05-04 05:46:45 -0500 | [diff] [blame] | 18 | namespace phosphor |
| 19 | { |
| 20 | namespace dump |
| 21 | { |
| 22 | |
Dhruvaraj Subhashchandran | 93f0641 | 2024-06-02 05:16:51 -0500 | [diff] [blame] | 23 | // Current serialiation version of the class increment if there any change |
| 24 | // in the serialized data members |
| 25 | constexpr size_t CLASS_SERIALIZATION_VERSION = 1; |
| 26 | |
| 27 | // Folder to store serialized dump contents |
| 28 | constexpr auto PRESERVE = ".preserve"; |
| 29 | |
| 30 | // Binary file store the contents |
| 31 | constexpr auto SERIAL_FILE = "serialized_entry.json"; |
| 32 | |
Jayanth Othayoth | 224882b | 2017-05-04 05:46:45 -0500 | [diff] [blame] | 33 | template <typename T> |
Patrick Williams | 9b18bf2 | 2022-07-22 19:26:55 -0500 | [diff] [blame] | 34 | using ServerObject = typename sdbusplus::server::object_t<T>; |
Jayanth Othayoth | 224882b | 2017-05-04 05:46:45 -0500 | [diff] [blame] | 35 | |
Dhruvaraj Subhashchandran | a6ab806 | 2020-10-29 15:29:10 -0500 | [diff] [blame] | 36 | // TODO Revisit whether sdbusplus::xyz::openbmc_project::Time::server::EpochTime |
| 37 | // still needed in dump entry since start time and completed time are available |
| 38 | // from sdbusplus::xyz::openbmc_project::Common::server::Progress |
| 39 | // #ibm-openbmc/2809 |
Patrick Williams | 9b18bf2 | 2022-07-22 19:26:55 -0500 | [diff] [blame] | 40 | using EntryIfaces = sdbusplus::server::object_t< |
Asmitha Karunanithi | 74a1f39 | 2021-10-27 03:23:59 -0500 | [diff] [blame] | 41 | sdbusplus::xyz::openbmc_project::Common::server::OriginatedBy, |
Dhruvaraj Subhashchandran | a6ab806 | 2020-10-29 15:29:10 -0500 | [diff] [blame] | 42 | sdbusplus::xyz::openbmc_project::Common::server::Progress, |
Jayanth Othayoth | cb65ffc | 2018-10-16 08:29:32 -0500 | [diff] [blame] | 43 | sdbusplus::xyz::openbmc_project::Dump::server::Entry, |
| 44 | sdbusplus::xyz::openbmc_project::Object::server::Delete, |
| 45 | sdbusplus::xyz::openbmc_project::Time::server::EpochTime>; |
Jayanth Othayoth | 224882b | 2017-05-04 05:46:45 -0500 | [diff] [blame] | 46 | |
Dhruvaraj Subhashchandran | a6ab806 | 2020-10-29 15:29:10 -0500 | [diff] [blame] | 47 | using OperationStatus = |
| 48 | sdbusplus::xyz::openbmc_project::Common::server::Progress::OperationStatus; |
Jayanth Othayoth | a320c7c | 2017-06-14 07:17:21 -0500 | [diff] [blame] | 49 | |
Asmitha Karunanithi | 74a1f39 | 2021-10-27 03:23:59 -0500 | [diff] [blame] | 50 | using originatorTypes = sdbusplus::xyz::openbmc_project::Common::server:: |
| 51 | OriginatedBy::OriginatorTypes; |
| 52 | |
Jayanth Othayoth | a320c7c | 2017-06-14 07:17:21 -0500 | [diff] [blame] | 53 | class Manager; |
| 54 | |
Jayanth Othayoth | 224882b | 2017-05-04 05:46:45 -0500 | [diff] [blame] | 55 | /** @class Entry |
Dhruvaraj Subhashchandran | f140f66 | 2020-01-30 00:29:01 -0600 | [diff] [blame] | 56 | * @brief Base Dump Entry implementation. |
Jayanth Othayoth | 224882b | 2017-05-04 05:46:45 -0500 | [diff] [blame] | 57 | * @details A concrete implementation for the |
| 58 | * xyz.openbmc_project.Dump.Entry DBus API |
| 59 | */ |
| 60 | class Entry : public EntryIfaces |
| 61 | { |
Jayanth Othayoth | cb65ffc | 2018-10-16 08:29:32 -0500 | [diff] [blame] | 62 | public: |
| 63 | Entry() = delete; |
| 64 | Entry(const Entry&) = delete; |
| 65 | Entry& operator=(const Entry&) = delete; |
| 66 | Entry(Entry&&) = delete; |
| 67 | Entry& operator=(Entry&&) = delete; |
| 68 | ~Entry() = default; |
Jayanth Othayoth | 224882b | 2017-05-04 05:46:45 -0500 | [diff] [blame] | 69 | |
Jayanth Othayoth | cb65ffc | 2018-10-16 08:29:32 -0500 | [diff] [blame] | 70 | /** @brief Constructor for the Dump Entry Object |
| 71 | * @param[in] bus - Bus to attach to. |
| 72 | * @param[in] objPath - Object path to attach to |
| 73 | * @param[in] dumpId - Dump id. |
| 74 | * @param[in] timeStamp - Dump creation timestamp |
| 75 | * since the epoch. |
Dhruvaraj Subhashchandran | 4a98e8f | 2020-01-29 07:11:08 -0600 | [diff] [blame] | 76 | * @param[in] dumpSize - Dump file size in bytes. |
Asmitha Karunanithi | 74a1f39 | 2021-10-27 03:23:59 -0500 | [diff] [blame] | 77 | * @param[in] originId - Id of the originator of the dump |
| 78 | * @param[in] originType - Originator type |
Jayanth Othayoth | cb65ffc | 2018-10-16 08:29:32 -0500 | [diff] [blame] | 79 | * @param[in] parent - The dump entry's parent. |
| 80 | */ |
Patrick Williams | 9b18bf2 | 2022-07-22 19:26:55 -0500 | [diff] [blame] | 81 | Entry(sdbusplus::bus_t& bus, const std::string& objPath, uint32_t dumpId, |
Dhruvaraj Subhashchandran | 64f8da9 | 2021-12-08 03:48:23 -0600 | [diff] [blame] | 82 | uint64_t timeStamp, uint64_t dumpSize, |
| 83 | const std::filesystem::path& file, OperationStatus dumpStatus, |
Asmitha Karunanithi | 74a1f39 | 2021-10-27 03:23:59 -0500 | [diff] [blame] | 84 | std::string originId, originatorTypes originType, Manager& parent) : |
Patrick Williams | 73f6407 | 2022-04-01 17:04:47 -0500 | [diff] [blame] | 85 | EntryIfaces(bus, objPath.c_str(), EntryIfaces::action::emit_no_signals), |
Dhruvaraj Subhashchandran | 64f8da9 | 2021-12-08 03:48:23 -0600 | [diff] [blame] | 86 | parent(parent), id(dumpId), file(file) |
Jayanth Othayoth | cb65ffc | 2018-10-16 08:29:32 -0500 | [diff] [blame] | 87 | { |
Asmitha Karunanithi | 74a1f39 | 2021-10-27 03:23:59 -0500 | [diff] [blame] | 88 | originatorId(originId); |
| 89 | originatorType(originType); |
| 90 | |
Dhruvaraj Subhashchandran | 4a98e8f | 2020-01-29 07:11:08 -0600 | [diff] [blame] | 91 | size(dumpSize); |
Dhruvaraj Subhashchandran | a6ab806 | 2020-10-29 15:29:10 -0500 | [diff] [blame] | 92 | status(dumpStatus); |
| 93 | |
| 94 | // If the object is created after the dump creation keep |
| 95 | // all same as timeStamp |
| 96 | // if the object created before the dump creation, update |
| 97 | // only the start time. Completed and elapsed time will |
| 98 | // be updated once the dump is completed. |
| 99 | if (dumpStatus == OperationStatus::Completed) |
| 100 | { |
| 101 | elapsed(timeStamp); |
| 102 | startTime(timeStamp); |
| 103 | completedTime(timeStamp); |
| 104 | } |
| 105 | else |
| 106 | { |
| 107 | elapsed(0); |
| 108 | startTime(timeStamp); |
| 109 | completedTime(0); |
| 110 | } |
Jayanth Othayoth | cb65ffc | 2018-10-16 08:29:32 -0500 | [diff] [blame] | 111 | }; |
Jayanth Othayoth | 224882b | 2017-05-04 05:46:45 -0500 | [diff] [blame] | 112 | |
Jayanth Othayoth | cb65ffc | 2018-10-16 08:29:32 -0500 | [diff] [blame] | 113 | /** @brief Delete this d-bus object. |
| 114 | */ |
| 115 | void delete_() override; |
Jayanth Othayoth | 224882b | 2017-05-04 05:46:45 -0500 | [diff] [blame] | 116 | |
Dhruvaraj Subhashchandran | 4a98e8f | 2020-01-29 07:11:08 -0600 | [diff] [blame] | 117 | /** @brief Method to initiate the offload of dump |
Dhruvaraj Subhashchandran | 69e6152 | 2020-02-04 06:39:11 -0600 | [diff] [blame] | 118 | * @param[in] uri - URI to offload dump |
Dhruvaraj Subhashchandran | 4a98e8f | 2020-01-29 07:11:08 -0600 | [diff] [blame] | 119 | */ |
Dhruvaraj Subhashchandran | 69e6152 | 2020-02-04 06:39:11 -0600 | [diff] [blame] | 120 | void initiateOffload(std::string uri) override |
Dhruvaraj Subhashchandran | 4a98e8f | 2020-01-29 07:11:08 -0600 | [diff] [blame] | 121 | { |
Dhruvaraj Subhashchandran | 69e6152 | 2020-02-04 06:39:11 -0600 | [diff] [blame] | 122 | offloadUri(uri); |
Dhruvaraj Subhashchandran | 4a98e8f | 2020-01-29 07:11:08 -0600 | [diff] [blame] | 123 | } |
Jayanth Othayoth | a320c7c | 2017-06-14 07:17:21 -0500 | [diff] [blame] | 124 | |
Dhruvaraj Subhashchandran | 270355b | 2022-02-01 02:44:43 -0600 | [diff] [blame] | 125 | /** @brief Returns the dump id |
| 126 | * @return the id associated with entry |
| 127 | */ |
| 128 | uint32_t getDumpId() |
| 129 | { |
| 130 | return id; |
| 131 | } |
| 132 | |
Dhruvaraj Subhashchandran | 64f8da9 | 2021-12-08 03:48:23 -0600 | [diff] [blame] | 133 | /** @brief Method to get the file handle of the dump |
| 134 | * @returns A Unix file descriptor to the dump file |
| 135 | * @throws sdbusplus::xyz::openbmc_project::Common::File::Error::Open on |
| 136 | * failure to open the file |
| 137 | * @throws sdbusplus::xyz::openbmc_project::Common::Error::Unavailable if |
| 138 | * the file string is empty |
| 139 | */ |
| 140 | sdbusplus::message::unix_fd getFileHandle() override; |
| 141 | |
Dhruvaraj Subhashchandran | 93f0641 | 2024-06-02 05:16:51 -0500 | [diff] [blame] | 142 | /** |
| 143 | * @brief Serialize the dump entry attributes to a file. |
| 144 | * |
| 145 | */ |
| 146 | virtual void serialize(); |
| 147 | |
| 148 | /** |
| 149 | * @brief Deserialize the dump entry attributes from a file. |
| 150 | * |
| 151 | * @param[in] dumpPath - The path where the .preserve folder is located. |
| 152 | */ |
| 153 | virtual void deserialize(const std::filesystem::path& dumpPath); |
| 154 | |
Dhruvaraj Subhashchandran | 4a98e8f | 2020-01-29 07:11:08 -0600 | [diff] [blame] | 155 | protected: |
Jayanth Othayoth | cb65ffc | 2018-10-16 08:29:32 -0500 | [diff] [blame] | 156 | /** @brief This entry's parent */ |
| 157 | Manager& parent; |
Jayanth Othayoth | a320c7c | 2017-06-14 07:17:21 -0500 | [diff] [blame] | 158 | |
Jayanth Othayoth | cb65ffc | 2018-10-16 08:29:32 -0500 | [diff] [blame] | 159 | /** @brief This entry's id */ |
| 160 | uint32_t id; |
Dhruvaraj Subhashchandran | 64f8da9 | 2021-12-08 03:48:23 -0600 | [diff] [blame] | 161 | |
| 162 | /** @Dump file name */ |
| 163 | std::filesystem::path file; |
| 164 | |
| 165 | private: |
| 166 | /** @brief Closes the file descriptor and removes the corresponding event |
| 167 | * source. |
| 168 | * |
| 169 | */ |
| 170 | void closeFD() |
| 171 | { |
| 172 | if (fdCloseEventSource) |
| 173 | { |
| 174 | close(fdCloseEventSource->first); |
| 175 | fdCloseEventSource.reset(); |
| 176 | } |
| 177 | } |
| 178 | |
| 179 | /* @brief A pair of file descriptor and corresponding event source. */ |
| 180 | std::optional<std::pair<int, std::unique_ptr<sdeventplus::source::Defer>>> |
| 181 | fdCloseEventSource; |
Jayanth Othayoth | 224882b | 2017-05-04 05:46:45 -0500 | [diff] [blame] | 182 | }; |
| 183 | |
| 184 | } // namespace dump |
| 185 | } // namespace phosphor |