blob: b0b9b523e3d4cb70b4c8c212ed0f3727a4cad22c [file] [log] [blame]
Jason Ling85e54f12020-11-05 18:47:21 -08001#pragma once
William A. Kennington IIIcc7f3852021-01-21 19:01:56 -08002#include "handler_config.hpp"
Jason Lingc78bfc82020-11-05 18:58:16 -08003#include "image_handler.hpp"
Jason Ling85e54f12020-11-05 18:47:21 -08004#include "status.hpp"
Jason Lingc78bfc82020-11-05 18:58:16 -08005#include "util.hpp"
Jason Ling85e54f12020-11-05 18:47:21 -08006
7#include <blobs-ipmid/blobs.hpp>
8
Jason Lingc78bfc82020-11-05 18:58:16 -08009#include <cstdint>
10#include <map>
Jason Ling85e54f12020-11-05 18:47:21 -080011#include <memory>
William A. Kennington III9936c452020-12-23 23:31:23 -080012#include <optional>
13#include <set>
Jason Lingc78bfc82020-11-05 18:58:16 -080014#include <string>
William A. Kennington IIIb45eb5e2020-12-23 11:47:05 -080015#include <string_view>
Jason Lingc78bfc82020-11-05 18:58:16 -080016#include <unordered_map>
17#include <vector>
William A. Kennington IIIabf17352020-12-22 21:07:11 -080018
Jason Ling85e54f12020-11-05 18:47:21 -080019namespace ipmi_flash
20{
Jason Lingc78bfc82020-11-05 18:58:16 -080021
22class VersionBlobHandler : public blobs::GenericBlobInterface
23{
24 public:
William A. Kennington IIIabf17352020-12-22 21:07:11 -080025 struct ActionPack
26 {
27 /** Only file operation action supported currently */
28 std::unique_ptr<TriggerableActionInterface> onOpen;
29 };
30
Jason Lingc78bfc82020-11-05 18:58:16 -080031 /**
32 * Create a VersionBlobHandler.
33 *
William A. Kennington IIIabf17352020-12-22 21:07:11 -080034 * @param[in] configs - list of blob configurations to support
Jason Lingc78bfc82020-11-05 18:58:16 -080035 */
William A. Kennington IIIabf17352020-12-22 21:07:11 -080036 VersionBlobHandler(std::vector<HandlerConfig<ActionPack>>&& configs);
37
Jason Lingc78bfc82020-11-05 18:58:16 -080038 ~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 Tub487eb42021-09-16 21:44:43 -070052 bool write(uint16_t, uint32_t, const std::vector<uint8_t>&) override
Jason Lingc78bfc82020-11-05 18:58:16 -080053 {
54 return false; /* not supported */
55 };
Willy Tub487eb42021-09-16 21:44:43 -070056 bool writeMeta(uint16_t, uint32_t, const std::vector<uint8_t>&) override
Jason Lingc78bfc82020-11-05 18:58:16 -080057 {
58 return false; /* not supported */
59 }
Willy Tub487eb42021-09-16 21:44:43 -070060 bool commit(uint16_t, const std::vector<uint8_t>&) override
Jason Lingc78bfc82020-11-05 18:58:16 -080061 {
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 Lingc78bfc82020-11-05 18:58:16 -080067
68 private:
William A. Kennington III9936c452020-12-23 23:31:23 -080069 struct SessionInfo;
70
William A. Kennington IIIabf17352020-12-22 21:07:11 -080071 struct BlobInfo
72 {
William A. Kennington IIIb45eb5e2020-12-23 11:47:05 -080073 Pinned<std::string> blobId;
William A. Kennington IIIabf17352020-12-22 21:07:11 -080074 std::unique_ptr<ActionPack> actions;
75 std::unique_ptr<ImageHandlerInterface> handler;
William A. Kennington III9936c452020-12-23 23:31:23 -080076 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 IIIabf17352020-12-22 21:07:11 -080089 };
90
William A. Kennington IIIb45eb5e2020-12-23 11:47:05 -080091 std::unordered_map<std::string_view, std::unique_ptr<BlobInfo>> blobInfoMap;
William A. Kennington III9936c452020-12-23 23:31:23 -080092 std::unordered_map<uint16_t, std::unique_ptr<SessionInfo>> sessionInfoMap;
Jason Lingc78bfc82020-11-05 18:58:16 -080093};
William A. Kennington III9936c452020-12-23 23:31:23 -080094
Jason Ling85e54f12020-11-05 18:47:21 -080095} // namespace ipmi_flash