blob: a9bc8f473e9c8d51d20755c0f1bb4bb10601718b [file] [log] [blame]
Adriana Kobylak2d8fa222017-03-15 12:34:32 -05001#pragma once
2
3#include <sdbusplus/server.hpp>
4#include "activation.hpp"
Michael Tritzdd961b62017-05-17 14:07:03 -05005#include <xyz/openbmc_project/Common/FactoryReset/server.hpp>
Saqib Khance148702017-06-11 12:01:58 -05006#include "version.hpp"
Adriana Kobylak2d8fa222017-03-15 12:34:32 -05007
8namespace openpower
9{
10namespace software
11{
Adriana Kobylakbefe5ce2017-04-05 15:57:44 -050012namespace updater
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050013{
14
Michael Tritzdd961b62017-05-17 14:07:03 -050015using ItemUpdaterInherit = sdbusplus::server::object::object<
16 sdbusplus::xyz::openbmc_project::Common::server::FactoryReset>;
Patrick Williams3accb322017-05-30 16:29:52 -050017namespace MatchRules = sdbusplus::bus::match::rules;
Michael Tritzdd961b62017-05-17 14:07:03 -050018
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050019/** @class ItemUpdater
20 * @brief Manages the activation of the version items.
21 */
Michael Tritzdd961b62017-05-17 14:07:03 -050022class ItemUpdater : public ItemUpdaterInherit
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050023{
24 public:
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050025 /** @brief Constructs ItemUpdater
26 *
27 * @param[in] bus - The Dbus bus object
Michael Tritzdd961b62017-05-17 14:07:03 -050028 * @param[in] path - The Dbus path
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050029 */
Michael Tritzdd961b62017-05-17 14:07:03 -050030 ItemUpdater(sdbusplus::bus::bus& bus, const std::string& path) :
31 ItemUpdaterInherit(bus, path.c_str()),
Adriana Kobylakd6a549e2017-05-10 16:23:01 -050032 bus(bus),
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050033 versionMatch(
34 bus,
Patrick Williams3accb322017-05-30 16:29:52 -050035 MatchRules::interfacesAdded() +
36 MatchRules::path("/xyz/openbmc_project/software"),
37 std::bind(
38 std::mem_fn(&ItemUpdater::createActivation),
39 this,
40 std::placeholders::_1))
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050041 {
Saqib Khan167601b2017-06-18 23:33:46 -050042 processPNORImage();
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050043 }
44
Saqib Khan81bac882017-06-08 12:17:01 -050045 /** @brief Sets the given priority free by incrementing
46 * any existing priority with the same value by 1
47 *
48 * @param[in] value - The priority that needs to be set free.
Saqib Khanb8e7f312017-08-12 10:24:10 -050049 * @param[in] versionId - The Id of the version for which we
50 * are trying to free up the priority.
Saqib Khan81bac882017-06-08 12:17:01 -050051 * @return None
52 */
Saqib Khanb8e7f312017-08-12 10:24:10 -050053 void freePriority(uint8_t value, const std::string& versionId);
Saqib Khan81bac882017-06-08 12:17:01 -050054
Saqib Khan2af5c492017-07-17 16:15:13 -050055 /** @brief Determine is the given priority is the lowest
56 *
57 * @param[in] value - The priority that needs to be checked.
58 *
59 * @return boolean corresponding to whether the given
60 * priority is lowest.
61 */
62 bool isLowestPriority(uint8_t value);
63
Saqib Khan167601b2017-06-18 23:33:46 -050064 /**
65 * @brief Create and populate the active PNOR Version.
66 */
67 void processPNORImage();
68
Leonel Gonzalez9c8adfa2017-07-12 11:08:40 -050069 /** @brief Deletes version
70 *
71 * @param[in] entryId - Id of the version to delete
72 *
73 * @return None
74 */
75 void erase(std::string entryId);
76
Saqib Khan2cbfa032017-08-17 14:52:37 -050077 /** @brief Deletes the active pnor version with highest priority
78 if the total number of volume exceeds the threshold.
79 */
80 void freeSpace();
81
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050082 private:
83 /** @brief Callback function for Software.Version match.
84 * @details Creates an Activation dbus object.
85 *
86 * @param[in] msg - Data associated with subscribed signal
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050087 */
Patrick Williams3accb322017-05-30 16:29:52 -050088 void createActivation(sdbusplus::message::message& msg);
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050089
Saqib Khan7254f0e2017-04-10 21:45:37 -050090 /**
Saqib Khana8ade7e2017-04-12 10:27:56 -050091 * @brief Validates the presence of SquashFS iamge in the image dir.
92 *
Adriana Kobylak5ba6b102017-05-19 09:41:27 -050093 * @param[in] filePath - The path to the SquashfFS image.
Saqib Khana8ade7e2017-04-12 10:27:56 -050094 * @param[out] result - 0 --> if validation was successful
95 * - -1--> Otherwise
96 */
Adriana Kobylak5ba6b102017-05-19 09:41:27 -050097 static int validateSquashFSImage(const std::string& filePath);
Saqib Khan7254f0e2017-04-10 21:45:37 -050098
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050099 /** @brief Persistent sdbusplus DBus bus connection. */
Adriana Kobylakd6a549e2017-05-10 16:23:01 -0500100 sdbusplus::bus::bus& bus;
Adriana Kobylak2d8fa222017-03-15 12:34:32 -0500101
102 /** @brief Persistent map of Activation dbus objects and their
103 * version id */
Adriana Kobylak268616b2017-04-05 15:23:30 -0500104 std::map<std::string, std::unique_ptr<Activation>> activations;
Adriana Kobylak2d8fa222017-03-15 12:34:32 -0500105
Saqib Khance148702017-06-11 12:01:58 -0500106 /** @brief Persistent map of Version dbus objects and their
107 * version id */
108 std::map<std::string, std::unique_ptr<Version>> versions;
109
Adriana Kobylak2d8fa222017-03-15 12:34:32 -0500110 /** @brief sdbusplus signal match for Software.Version */
Patrick Williams3accb322017-05-30 16:29:52 -0500111 sdbusplus::bus::match_t versionMatch;
Michael Tritzdd961b62017-05-17 14:07:03 -0500112
Leonel Gonzalez9c8adfa2017-07-12 11:08:40 -0500113 /** @brief Clears read only PNOR partition for
114 * given Activation dbus object
115 *
116 * @param[in] versionId - The id of the ro partition to remove.
117 */
118 void removeReadOnlyPartition(std::string versionId);
119
120 /** @brief Clears read write PNOR partition for
121 * given Activation dbus object
122 *
123 * @param[in] versionId - The id of the rw partition to remove.
124 */
125 void removeReadWritePartition(std::string versionId);
126
127 /** @brief Clears preserved PNOR partition */
128 void removePreservedPartition();
129
Michael Tritzdd961b62017-05-17 14:07:03 -0500130 /** @brief Host factory reset - clears PNOR partitions for each
131 * Activation dbus object */
132 void reset() override;
Adriana Kobylak2d8fa222017-03-15 12:34:32 -0500133};
134
Adriana Kobylakbefe5ce2017-04-05 15:57:44 -0500135} // namespace updater
Adriana Kobylak2d8fa222017-03-15 12:34:32 -0500136} // namespace software
137} // namespace openpower