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