blob: affbe5372926e07b521416c54f85e0d59a805c00 [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"
Gunnar Mills9741cd12017-08-28 15:09:00 -05007#include "org/openbmc/Associations/server.hpp"
Adriana Kobylak2d8fa222017-03-15 12:34:32 -05008
9namespace openpower
10{
11namespace software
12{
Adriana Kobylakbefe5ce2017-04-05 15:57:44 -050013namespace updater
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050014{
15
Michael Tritzdd961b62017-05-17 14:07:03 -050016using ItemUpdaterInherit = sdbusplus::server::object::object<
Gunnar Mills9741cd12017-08-28 15:09:00 -050017 sdbusplus::xyz::openbmc_project::Common::server::FactoryReset,
18 sdbusplus::org::openbmc::server::Associations>;
Patrick Williams3accb322017-05-30 16:29:52 -050019namespace MatchRules = sdbusplus::bus::match::rules;
Michael Tritzdd961b62017-05-17 14:07:03 -050020
Gunnar Mills9741cd12017-08-28 15:09:00 -050021using AssociationList =
22 std::vector<std::tuple<std::string, std::string, std::string>>;
23
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050024/** @class ItemUpdater
25 * @brief Manages the activation of the version items.
26 */
Michael Tritzdd961b62017-05-17 14:07:03 -050027class ItemUpdater : public ItemUpdaterInherit
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050028{
29 public:
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050030 /** @brief Constructs ItemUpdater
31 *
32 * @param[in] bus - The Dbus bus object
Michael Tritzdd961b62017-05-17 14:07:03 -050033 * @param[in] path - The Dbus path
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050034 */
Michael Tritzdd961b62017-05-17 14:07:03 -050035 ItemUpdater(sdbusplus::bus::bus& bus, const std::string& path) :
36 ItemUpdaterInherit(bus, path.c_str()),
Adriana Kobylakd6a549e2017-05-10 16:23:01 -050037 bus(bus),
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050038 versionMatch(
39 bus,
Patrick Williams3accb322017-05-30 16:29:52 -050040 MatchRules::interfacesAdded() +
41 MatchRules::path("/xyz/openbmc_project/software"),
42 std::bind(
43 std::mem_fn(&ItemUpdater::createActivation),
44 this,
45 std::placeholders::_1))
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050046 {
Saqib Khan167601b2017-06-18 23:33:46 -050047 processPNORImage();
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050048 }
49
Saqib Khan81bac882017-06-08 12:17:01 -050050 /** @brief Sets the given priority free by incrementing
51 * any existing priority with the same value by 1
52 *
53 * @param[in] value - The priority that needs to be set free.
Saqib Khanb8e7f312017-08-12 10:24:10 -050054 * @param[in] versionId - The Id of the version for which we
55 * are trying to free up the priority.
Saqib Khan81bac882017-06-08 12:17:01 -050056 * @return None
57 */
Saqib Khanb8e7f312017-08-12 10:24:10 -050058 void freePriority(uint8_t value, const std::string& versionId);
Saqib Khan81bac882017-06-08 12:17:01 -050059
Saqib Khan2af5c492017-07-17 16:15:13 -050060 /** @brief Determine is the given priority is the lowest
61 *
62 * @param[in] value - The priority that needs to be checked.
63 *
64 * @return boolean corresponding to whether the given
65 * priority is lowest.
66 */
67 bool isLowestPriority(uint8_t value);
68
Saqib Khan167601b2017-06-18 23:33:46 -050069 /**
70 * @brief Create and populate the active PNOR Version.
71 */
72 void processPNORImage();
73
Leonel Gonzalez9c8adfa2017-07-12 11:08:40 -050074 /** @brief Deletes version
75 *
76 * @param[in] entryId - Id of the version to delete
77 *
78 * @return None
79 */
80 void erase(std::string entryId);
81
Saqib Khan2cbfa032017-08-17 14:52:37 -050082 /** @brief Deletes the active pnor version with highest priority
83 if the total number of volume exceeds the threshold.
84 */
85 void freeSpace();
86
Gunnar Mills9741cd12017-08-28 15:09:00 -050087 /** @brief Creates an active association to the
88 * newly active software image
89 *
90 * @param[in] path - The path to create the association to.
91 */
92 void createActiveAssociation(std::string path);
93
94 /** @brief Removes an active association to the software image
95 *
96 * @param[in] path - The path to remove the association from.
97 */
98 void removeActiveAssociation(std::string path);
99
Adriana Kobylak2d8fa222017-03-15 12:34:32 -0500100 private:
101 /** @brief Callback function for Software.Version match.
102 * @details Creates an Activation dbus object.
103 *
104 * @param[in] msg - Data associated with subscribed signal
Adriana Kobylak2d8fa222017-03-15 12:34:32 -0500105 */
Patrick Williams3accb322017-05-30 16:29:52 -0500106 void createActivation(sdbusplus::message::message& msg);
Adriana Kobylak2d8fa222017-03-15 12:34:32 -0500107
Saqib Khan7254f0e2017-04-10 21:45:37 -0500108 /**
Saqib Khana8ade7e2017-04-12 10:27:56 -0500109 * @brief Validates the presence of SquashFS iamge in the image dir.
110 *
Adriana Kobylak5ba6b102017-05-19 09:41:27 -0500111 * @param[in] filePath - The path to the SquashfFS image.
Saqib Khana8ade7e2017-04-12 10:27:56 -0500112 * @param[out] result - 0 --> if validation was successful
113 * - -1--> Otherwise
114 */
Adriana Kobylak5ba6b102017-05-19 09:41:27 -0500115 static int validateSquashFSImage(const std::string& filePath);
Saqib Khan7254f0e2017-04-10 21:45:37 -0500116
Adriana Kobylak2d8fa222017-03-15 12:34:32 -0500117 /** @brief Persistent sdbusplus DBus bus connection. */
Adriana Kobylakd6a549e2017-05-10 16:23:01 -0500118 sdbusplus::bus::bus& bus;
Adriana Kobylak2d8fa222017-03-15 12:34:32 -0500119
120 /** @brief Persistent map of Activation dbus objects and their
121 * version id */
Adriana Kobylak268616b2017-04-05 15:23:30 -0500122 std::map<std::string, std::unique_ptr<Activation>> activations;
Adriana Kobylak2d8fa222017-03-15 12:34:32 -0500123
Saqib Khance148702017-06-11 12:01:58 -0500124 /** @brief Persistent map of Version dbus objects and their
125 * version id */
126 std::map<std::string, std::unique_ptr<Version>> versions;
127
Adriana Kobylak2d8fa222017-03-15 12:34:32 -0500128 /** @brief sdbusplus signal match for Software.Version */
Patrick Williams3accb322017-05-30 16:29:52 -0500129 sdbusplus::bus::match_t versionMatch;
Michael Tritzdd961b62017-05-17 14:07:03 -0500130
Gunnar Mills9741cd12017-08-28 15:09:00 -0500131 /** @brief This entry's associations */
132 AssociationList assocs = {};
133
Leonel Gonzalez9c8adfa2017-07-12 11:08:40 -0500134 /** @brief Clears read only PNOR partition for
135 * given Activation dbus object
136 *
137 * @param[in] versionId - The id of the ro partition to remove.
138 */
139 void removeReadOnlyPartition(std::string versionId);
140
141 /** @brief Clears read write PNOR partition for
142 * given Activation dbus object
143 *
144 * @param[in] versionId - The id of the rw partition to remove.
145 */
146 void removeReadWritePartition(std::string versionId);
147
148 /** @brief Clears preserved PNOR partition */
149 void removePreservedPartition();
150
Michael Tritzdd961b62017-05-17 14:07:03 -0500151 /** @brief Host factory reset - clears PNOR partitions for each
152 * Activation dbus object */
153 void reset() override;
Adriana Kobylak2d8fa222017-03-15 12:34:32 -0500154};
155
Adriana Kobylakbefe5ce2017-04-05 15:57:44 -0500156} // namespace updater
Adriana Kobylak2d8fa222017-03-15 12:34:32 -0500157} // namespace software
158} // namespace openpower