Jason Ling | 85e54f1 | 2020-11-05 18:47:21 -0800 | [diff] [blame] | 1 | #pragma once |
William A. Kennington III | cc7f385 | 2021-01-21 19:01:56 -0800 | [diff] [blame] | 2 | #include "handler_config.hpp" |
Jason Ling | c78bfc8 | 2020-11-05 18:58:16 -0800 | [diff] [blame] | 3 | #include "image_handler.hpp" |
Jason Ling | 85e54f1 | 2020-11-05 18:47:21 -0800 | [diff] [blame] | 4 | #include "status.hpp" |
Jason Ling | c78bfc8 | 2020-11-05 18:58:16 -0800 | [diff] [blame] | 5 | #include "util.hpp" |
Jason Ling | 85e54f1 | 2020-11-05 18:47:21 -0800 | [diff] [blame] | 6 | |
| 7 | #include <blobs-ipmid/blobs.hpp> |
| 8 | |
Jason Ling | c78bfc8 | 2020-11-05 18:58:16 -0800 | [diff] [blame] | 9 | #include <cstdint> |
| 10 | #include <map> |
Jason Ling | 85e54f1 | 2020-11-05 18:47:21 -0800 | [diff] [blame] | 11 | #include <memory> |
William A. Kennington III | 9936c45 | 2020-12-23 23:31:23 -0800 | [diff] [blame] | 12 | #include <optional> |
| 13 | #include <set> |
Jason Ling | c78bfc8 | 2020-11-05 18:58:16 -0800 | [diff] [blame] | 14 | #include <string> |
William A. Kennington III | b45eb5e | 2020-12-23 11:47:05 -0800 | [diff] [blame] | 15 | #include <string_view> |
Jason Ling | c78bfc8 | 2020-11-05 18:58:16 -0800 | [diff] [blame] | 16 | #include <unordered_map> |
| 17 | #include <vector> |
William A. Kennington III | abf1735 | 2020-12-22 21:07:11 -0800 | [diff] [blame] | 18 | |
Jason Ling | 85e54f1 | 2020-11-05 18:47:21 -0800 | [diff] [blame] | 19 | namespace ipmi_flash |
| 20 | { |
Jason Ling | c78bfc8 | 2020-11-05 18:58:16 -0800 | [diff] [blame] | 21 | |
| 22 | class VersionBlobHandler : public blobs::GenericBlobInterface |
| 23 | { |
| 24 | public: |
William A. Kennington III | abf1735 | 2020-12-22 21:07:11 -0800 | [diff] [blame] | 25 | struct ActionPack |
| 26 | { |
| 27 | /** Only file operation action supported currently */ |
| 28 | std::unique_ptr<TriggerableActionInterface> onOpen; |
| 29 | }; |
| 30 | |
Jason Ling | c78bfc8 | 2020-11-05 18:58:16 -0800 | [diff] [blame] | 31 | /** |
| 32 | * Create a VersionBlobHandler. |
| 33 | * |
William A. Kennington III | abf1735 | 2020-12-22 21:07:11 -0800 | [diff] [blame] | 34 | * @param[in] configs - list of blob configurations to support |
Jason Ling | c78bfc8 | 2020-11-05 18:58:16 -0800 | [diff] [blame] | 35 | */ |
William A. Kennington III | abf1735 | 2020-12-22 21:07:11 -0800 | [diff] [blame] | 36 | VersionBlobHandler(std::vector<HandlerConfig<ActionPack>>&& configs); |
| 37 | |
Jason Ling | c78bfc8 | 2020-11-05 18:58:16 -0800 | [diff] [blame] | 38 | ~VersionBlobHandler() = default; |
| 39 | VersionBlobHandler(const VersionBlobHandler&) = delete; |
| 40 | VersionBlobHandler& operator=(const VersionBlobHandler&) = delete; |
| 41 | VersionBlobHandler(VersionBlobHandler&&) = default; |
| 42 | VersionBlobHandler& operator=(VersionBlobHandler&&) = default; |
| 43 | |
| 44 | bool canHandleBlob(const std::string& path) override; |
| 45 | std::vector<std::string> getBlobIds() override; |
| 46 | bool deleteBlob(const std::string& path) override; |
| 47 | bool stat(const std::string&, blobs::BlobMeta* meta) override; |
| 48 | bool open(uint16_t session, uint16_t flags, |
| 49 | const std::string& path) override; |
| 50 | std::vector<uint8_t> read(uint16_t session, uint32_t offset, |
| 51 | uint32_t requestedSize) override; |
Willy Tu | b487eb4 | 2021-09-16 21:44:43 -0700 | [diff] [blame] | 52 | bool write(uint16_t, uint32_t, const std::vector<uint8_t>&) override |
Jason Ling | c78bfc8 | 2020-11-05 18:58:16 -0800 | [diff] [blame] | 53 | { |
| 54 | return false; /* not supported */ |
| 55 | }; |
Willy Tu | b487eb4 | 2021-09-16 21:44:43 -0700 | [diff] [blame] | 56 | bool writeMeta(uint16_t, uint32_t, const std::vector<uint8_t>&) override |
Jason Ling | c78bfc8 | 2020-11-05 18:58:16 -0800 | [diff] [blame] | 57 | { |
| 58 | return false; /* not supported */ |
| 59 | } |
Willy Tu | b487eb4 | 2021-09-16 21:44:43 -0700 | [diff] [blame] | 60 | bool commit(uint16_t, const std::vector<uint8_t>&) override |
Jason Ling | c78bfc8 | 2020-11-05 18:58:16 -0800 | [diff] [blame] | 61 | { |
| 62 | return false; // not supported |
| 63 | } |
| 64 | bool close(uint16_t session) override; |
| 65 | bool stat(uint16_t session, blobs::BlobMeta* meta) override; |
| 66 | bool expire(uint16_t session) override; |
Jason Ling | c78bfc8 | 2020-11-05 18:58:16 -0800 | [diff] [blame] | 67 | |
| 68 | private: |
William A. Kennington III | 9936c45 | 2020-12-23 23:31:23 -0800 | [diff] [blame] | 69 | struct SessionInfo; |
| 70 | |
William A. Kennington III | abf1735 | 2020-12-22 21:07:11 -0800 | [diff] [blame] | 71 | struct BlobInfo |
| 72 | { |
William A. Kennington III | b45eb5e | 2020-12-23 11:47:05 -0800 | [diff] [blame] | 73 | Pinned<std::string> blobId; |
William A. Kennington III | abf1735 | 2020-12-22 21:07:11 -0800 | [diff] [blame] | 74 | std::unique_ptr<ActionPack> actions; |
| 75 | std::unique_ptr<ImageHandlerInterface> handler; |
William A. Kennington III | 9936c45 | 2020-12-23 23:31:23 -0800 | [diff] [blame] | 76 | std::set<SessionInfo*> sessionsToUpdate; |
| 77 | }; |
| 78 | |
| 79 | struct SessionInfo |
| 80 | { |
| 81 | BlobInfo* blob; |
| 82 | |
| 83 | // A cached copy of the version data shared by all clients for a single |
| 84 | // execution of the version retrieval action. This is is null until the |
| 85 | // TriggerableAction has completed. If the action is an error, the |
| 86 | // shared object is nullopt. Otherwise, contains a vector of the version |
| 87 | // data when successfully read. |
| 88 | std::shared_ptr<const std::optional<std::vector<uint8_t>>> data; |
William A. Kennington III | abf1735 | 2020-12-22 21:07:11 -0800 | [diff] [blame] | 89 | }; |
| 90 | |
William A. Kennington III | b45eb5e | 2020-12-23 11:47:05 -0800 | [diff] [blame] | 91 | std::unordered_map<std::string_view, std::unique_ptr<BlobInfo>> blobInfoMap; |
William A. Kennington III | 9936c45 | 2020-12-23 23:31:23 -0800 | [diff] [blame] | 92 | std::unordered_map<uint16_t, std::unique_ptr<SessionInfo>> sessionInfoMap; |
Jason Ling | c78bfc8 | 2020-11-05 18:58:16 -0800 | [diff] [blame] | 93 | }; |
William A. Kennington III | 9936c45 | 2020-12-23 23:31:23 -0800 | [diff] [blame] | 94 | |
Jason Ling | 85e54f1 | 2020-11-05 18:47:21 -0800 | [diff] [blame] | 95 | } // namespace ipmi_flash |