1fa5e4d32SSunny Srivastava #include "backup_restore.hpp"
2fa5e4d32SSunny Srivastava
3fa5e4d32SSunny Srivastava #include "constants.hpp"
4fa5e4d32SSunny Srivastava #include "event_logger.hpp"
5fa5e4d32SSunny Srivastava #include "exceptions.hpp"
6fa5e4d32SSunny Srivastava #include "logger.hpp"
7fa5e4d32SSunny Srivastava #include "parser.hpp"
8fa5e4d32SSunny Srivastava #include "types.hpp"
9fa5e4d32SSunny Srivastava
10fa5e4d32SSunny Srivastava #include <utility/json_utility.hpp>
11fa5e4d32SSunny Srivastava #include <utility/vpd_specific_utility.hpp>
12fa5e4d32SSunny Srivastava
13fa5e4d32SSunny Srivastava namespace vpd
14fa5e4d32SSunny Srivastava {
15fa5e4d32SSunny Srivastava BackupAndRestoreStatus BackupAndRestore::m_backupAndRestoreStatus =
16fa5e4d32SSunny Srivastava BackupAndRestoreStatus::NotStarted;
17fa5e4d32SSunny Srivastava
BackupAndRestore(const nlohmann::json & i_sysCfgJsonObj)18fa5e4d32SSunny Srivastava BackupAndRestore::BackupAndRestore(const nlohmann::json& i_sysCfgJsonObj) :
19fa5e4d32SSunny Srivastava m_sysCfgJsonObj(i_sysCfgJsonObj)
20fa5e4d32SSunny Srivastava {
21fa5e4d32SSunny Srivastava std::string l_backupAndRestoreCfgFilePath =
22fa5e4d32SSunny Srivastava i_sysCfgJsonObj.value("backupRestoreConfigPath", "");
231ef21008SRekhaAparna01
24fa5e4d32SSunny Srivastava m_backupAndRestoreCfgJsonObj =
25fa5e4d32SSunny Srivastava jsonUtility::getParsedJson(l_backupAndRestoreCfgFilePath);
261ef21008SRekhaAparna01
271ef21008SRekhaAparna01 if (m_backupAndRestoreCfgJsonObj.empty())
28fa5e4d32SSunny Srivastava {
291ef21008SRekhaAparna01 throw JsonException("JSON parsing failed",
30fa5e4d32SSunny Srivastava l_backupAndRestoreCfgFilePath);
31fa5e4d32SSunny Srivastava }
32fa5e4d32SSunny Srivastava }
33fa5e4d32SSunny Srivastava
34fa5e4d32SSunny Srivastava std::tuple<types::VPDMapVariant, types::VPDMapVariant>
backupAndRestore()35fa5e4d32SSunny Srivastava BackupAndRestore::backupAndRestore()
36fa5e4d32SSunny Srivastava {
37fa5e4d32SSunny Srivastava auto l_emptyVariantPair =
38fa5e4d32SSunny Srivastava std::make_tuple(std::monostate{}, std::monostate{});
39fa5e4d32SSunny Srivastava
40fa5e4d32SSunny Srivastava if (m_backupAndRestoreStatus >= BackupAndRestoreStatus::Invoked)
41fa5e4d32SSunny Srivastava {
42fa5e4d32SSunny Srivastava logging::logMessage("Backup and restore invoked already.");
43fa5e4d32SSunny Srivastava return l_emptyVariantPair;
44fa5e4d32SSunny Srivastava }
45fa5e4d32SSunny Srivastava
46fa5e4d32SSunny Srivastava m_backupAndRestoreStatus = BackupAndRestoreStatus::Invoked;
47fa5e4d32SSunny Srivastava try
48fa5e4d32SSunny Srivastava {
49fa5e4d32SSunny Srivastava if (m_backupAndRestoreCfgJsonObj.empty() ||
50fa5e4d32SSunny Srivastava !m_backupAndRestoreCfgJsonObj.contains("source") ||
51fa5e4d32SSunny Srivastava !m_backupAndRestoreCfgJsonObj.contains("destination") ||
52fa5e4d32SSunny Srivastava !m_backupAndRestoreCfgJsonObj.contains("type") ||
53fa5e4d32SSunny Srivastava !m_backupAndRestoreCfgJsonObj.contains("backupMap"))
54fa5e4d32SSunny Srivastava {
55fa5e4d32SSunny Srivastava logging::logMessage(
56fa5e4d32SSunny Srivastava "Backup restore config JSON is missing necessary tag(s), can't initiate backup and restore.");
57fa5e4d32SSunny Srivastava return l_emptyVariantPair;
58fa5e4d32SSunny Srivastava }
59fa5e4d32SSunny Srivastava
60fa5e4d32SSunny Srivastava std::string l_srcVpdPath;
61fa5e4d32SSunny Srivastava types::VPDMapVariant l_srcVpdVariant;
62fa5e4d32SSunny Srivastava if (l_srcVpdPath = m_backupAndRestoreCfgJsonObj["source"].value(
63fa5e4d32SSunny Srivastava "hardwarePath", "");
64fa5e4d32SSunny Srivastava !l_srcVpdPath.empty() && std::filesystem::exists(l_srcVpdPath))
65fa5e4d32SSunny Srivastava {
66fa5e4d32SSunny Srivastava std::shared_ptr<Parser> l_vpdParser =
67fa5e4d32SSunny Srivastava std::make_shared<Parser>(l_srcVpdPath, m_sysCfgJsonObj);
68fa5e4d32SSunny Srivastava l_srcVpdVariant = l_vpdParser->parse();
69fa5e4d32SSunny Srivastava }
70fa5e4d32SSunny Srivastava else if (l_srcVpdPath = m_backupAndRestoreCfgJsonObj["source"].value(
71fa5e4d32SSunny Srivastava "inventoryPath", "");
72fa5e4d32SSunny Srivastava l_srcVpdPath.empty())
73fa5e4d32SSunny Srivastava {
74fa5e4d32SSunny Srivastava logging::logMessage(
75fa5e4d32SSunny Srivastava "Couldn't extract source path, can't initiate backup and restore.");
76fa5e4d32SSunny Srivastava return l_emptyVariantPair;
77fa5e4d32SSunny Srivastava }
78fa5e4d32SSunny Srivastava
79fa5e4d32SSunny Srivastava std::string l_dstVpdPath;
80fa5e4d32SSunny Srivastava types::VPDMapVariant l_dstVpdVariant;
81fa5e4d32SSunny Srivastava if (l_dstVpdPath = m_backupAndRestoreCfgJsonObj["destination"].value(
82fa5e4d32SSunny Srivastava "hardwarePath", "");
83fa5e4d32SSunny Srivastava !l_dstVpdPath.empty() && std::filesystem::exists(l_dstVpdPath))
84fa5e4d32SSunny Srivastava {
85fa5e4d32SSunny Srivastava std::shared_ptr<Parser> l_vpdParser =
86fa5e4d32SSunny Srivastava std::make_shared<Parser>(l_dstVpdPath, m_sysCfgJsonObj);
87fa5e4d32SSunny Srivastava l_dstVpdVariant = l_vpdParser->parse();
88fa5e4d32SSunny Srivastava }
89fa5e4d32SSunny Srivastava else if (l_dstVpdPath = m_backupAndRestoreCfgJsonObj["destination"]
90fa5e4d32SSunny Srivastava .value("inventoryPath", "");
91fa5e4d32SSunny Srivastava l_dstVpdPath.empty())
92fa5e4d32SSunny Srivastava {
93fa5e4d32SSunny Srivastava logging::logMessage(
94fa5e4d32SSunny Srivastava "Couldn't extract destination path, can't initiate backup and restore.");
95fa5e4d32SSunny Srivastava return l_emptyVariantPair;
96fa5e4d32SSunny Srivastava }
97fa5e4d32SSunny Srivastava
98fa5e4d32SSunny Srivastava // Implement backup and restore for IPZ type VPD
99fa5e4d32SSunny Srivastava auto l_backupAndRestoreType =
100fa5e4d32SSunny Srivastava m_backupAndRestoreCfgJsonObj.value("type", "");
101fa5e4d32SSunny Srivastava if (l_backupAndRestoreType.compare("IPZ") == constants::STR_CMP_SUCCESS)
102fa5e4d32SSunny Srivastava {
103fa5e4d32SSunny Srivastava types::IPZVpdMap l_srcVpdMap;
104fa5e4d32SSunny Srivastava if (auto l_srcVpdPtr =
105fa5e4d32SSunny Srivastava std::get_if<types::IPZVpdMap>(&l_srcVpdVariant))
106fa5e4d32SSunny Srivastava {
107fa5e4d32SSunny Srivastava l_srcVpdMap = *l_srcVpdPtr;
108fa5e4d32SSunny Srivastava }
109fa5e4d32SSunny Srivastava else if (!std::holds_alternative<std::monostate>(l_srcVpdVariant))
110fa5e4d32SSunny Srivastava {
111fa5e4d32SSunny Srivastava logging::logMessage("Source VPD is not of IPZ type.");
112fa5e4d32SSunny Srivastava return l_emptyVariantPair;
113fa5e4d32SSunny Srivastava }
114fa5e4d32SSunny Srivastava
115fa5e4d32SSunny Srivastava types::IPZVpdMap l_dstVpdMap;
116fa5e4d32SSunny Srivastava if (auto l_dstVpdPtr =
117fa5e4d32SSunny Srivastava std::get_if<types::IPZVpdMap>(&l_dstVpdVariant))
118fa5e4d32SSunny Srivastava {
119fa5e4d32SSunny Srivastava l_dstVpdMap = *l_dstVpdPtr;
120fa5e4d32SSunny Srivastava }
121fa5e4d32SSunny Srivastava else if (!std::holds_alternative<std::monostate>(l_dstVpdVariant))
122fa5e4d32SSunny Srivastava {
123fa5e4d32SSunny Srivastava logging::logMessage("Destination VPD is not of IPZ type.");
124fa5e4d32SSunny Srivastava return l_emptyVariantPair;
125fa5e4d32SSunny Srivastava }
126fa5e4d32SSunny Srivastava
127fa5e4d32SSunny Srivastava backupAndRestoreIpzVpd(l_srcVpdMap, l_dstVpdMap, l_srcVpdPath,
128fa5e4d32SSunny Srivastava l_dstVpdPath);
129fa5e4d32SSunny Srivastava m_backupAndRestoreStatus = BackupAndRestoreStatus::Completed;
130fa5e4d32SSunny Srivastava
131fa5e4d32SSunny Srivastava return std::make_tuple(l_srcVpdMap, l_dstVpdMap);
132fa5e4d32SSunny Srivastava }
133fa5e4d32SSunny Srivastava // Note: add implementation here to support any other VPD type.
134fa5e4d32SSunny Srivastava }
135fa5e4d32SSunny Srivastava catch (const std::exception& ex)
136fa5e4d32SSunny Srivastava {
137fa5e4d32SSunny Srivastava logging::logMessage("Back up and restore failed with exception: " +
138fa5e4d32SSunny Srivastava std::string(ex.what()));
139fa5e4d32SSunny Srivastava }
140fa5e4d32SSunny Srivastava return l_emptyVariantPair;
141fa5e4d32SSunny Srivastava }
142fa5e4d32SSunny Srivastava
backupAndRestoreIpzVpd(types::IPZVpdMap & io_srcVpdMap,types::IPZVpdMap & io_dstVpdMap,const std::string & i_srcPath,const std::string & i_dstPath)143fa5e4d32SSunny Srivastava void BackupAndRestore::backupAndRestoreIpzVpd(
144fa5e4d32SSunny Srivastava types::IPZVpdMap& io_srcVpdMap, types::IPZVpdMap& io_dstVpdMap,
145fa5e4d32SSunny Srivastava const std::string& i_srcPath, const std::string& i_dstPath)
146fa5e4d32SSunny Srivastava {
147fa5e4d32SSunny Srivastava if (!m_backupAndRestoreCfgJsonObj["backupMap"].is_array())
148fa5e4d32SSunny Srivastava {
149fa5e4d32SSunny Srivastava logging::logMessage(
150fa5e4d32SSunny Srivastava "Invalid value found for tag backupMap, in backup and restore config JSON.");
151fa5e4d32SSunny Srivastava return;
152fa5e4d32SSunny Srivastava }
153fa5e4d32SSunny Srivastava
154fa5e4d32SSunny Srivastava const std::string l_srcFruPath =
155fa5e4d32SSunny Srivastava jsonUtility::getFruPathFromJson(m_sysCfgJsonObj, i_srcPath);
156fa5e4d32SSunny Srivastava const std::string l_dstFruPath =
157fa5e4d32SSunny Srivastava jsonUtility::getFruPathFromJson(m_sysCfgJsonObj, i_dstPath);
158fa5e4d32SSunny Srivastava if (l_srcFruPath.empty() || l_dstFruPath.empty())
159fa5e4d32SSunny Srivastava {
160fa5e4d32SSunny Srivastava logging::logMessage(
161fa5e4d32SSunny Srivastava "Couldn't find either source or destination FRU path.");
162fa5e4d32SSunny Srivastava return;
163fa5e4d32SSunny Srivastava }
164fa5e4d32SSunny Srivastava
165fa5e4d32SSunny Srivastava const std::string l_srcInvPath =
166fa5e4d32SSunny Srivastava jsonUtility::getInventoryObjPathFromJson(m_sysCfgJsonObj, i_srcPath);
167fa5e4d32SSunny Srivastava const std::string l_dstInvPath =
168fa5e4d32SSunny Srivastava jsonUtility::getInventoryObjPathFromJson(m_sysCfgJsonObj, i_dstPath);
169fa5e4d32SSunny Srivastava if (l_srcInvPath.empty() || l_dstInvPath.empty())
170fa5e4d32SSunny Srivastava {
171fa5e4d32SSunny Srivastava logging::logMessage(
172fa5e4d32SSunny Srivastava "Couldn't find either source or destination inventory path.");
173fa5e4d32SSunny Srivastava return;
174fa5e4d32SSunny Srivastava }
175fa5e4d32SSunny Srivastava
176fa5e4d32SSunny Srivastava const std::string l_srcServiceName =
177fa5e4d32SSunny Srivastava jsonUtility::getServiceName(m_sysCfgJsonObj, l_srcInvPath);
178fa5e4d32SSunny Srivastava const std::string l_dstServiceName =
179fa5e4d32SSunny Srivastava jsonUtility::getServiceName(m_sysCfgJsonObj, l_dstInvPath);
180fa5e4d32SSunny Srivastava if (l_srcServiceName.empty() || l_dstServiceName.empty())
181fa5e4d32SSunny Srivastava {
182fa5e4d32SSunny Srivastava logging::logMessage(
183fa5e4d32SSunny Srivastava "Couldn't find either source or destination DBus service name.");
184fa5e4d32SSunny Srivastava return;
185fa5e4d32SSunny Srivastava }
186fa5e4d32SSunny Srivastava
187fa5e4d32SSunny Srivastava for (const auto& l_aRecordKwInfo :
188fa5e4d32SSunny Srivastava m_backupAndRestoreCfgJsonObj["backupMap"])
189fa5e4d32SSunny Srivastava {
190fa5e4d32SSunny Srivastava const std::string& l_srcRecordName =
191fa5e4d32SSunny Srivastava l_aRecordKwInfo.value("sourceRecord", "");
192fa5e4d32SSunny Srivastava const std::string& l_srcKeywordName =
193fa5e4d32SSunny Srivastava l_aRecordKwInfo.value("sourceKeyword", "");
194fa5e4d32SSunny Srivastava const std::string& l_dstRecordName =
195fa5e4d32SSunny Srivastava l_aRecordKwInfo.value("destinationRecord", "");
196fa5e4d32SSunny Srivastava const std::string& l_dstKeywordName =
197fa5e4d32SSunny Srivastava l_aRecordKwInfo.value("destinationKeyword", "");
198fa5e4d32SSunny Srivastava
199fa5e4d32SSunny Srivastava if (l_srcRecordName.empty() || l_dstRecordName.empty() ||
200fa5e4d32SSunny Srivastava l_srcKeywordName.empty() || l_dstKeywordName.empty())
201fa5e4d32SSunny Srivastava {
202fa5e4d32SSunny Srivastava logging::logMessage(
203fa5e4d32SSunny Srivastava "Record or keyword not found in the backup and restore config JSON.");
204fa5e4d32SSunny Srivastava continue;
205fa5e4d32SSunny Srivastava }
206fa5e4d32SSunny Srivastava
207fa5e4d32SSunny Srivastava if (!io_srcVpdMap.empty() &&
208fa5e4d32SSunny Srivastava io_srcVpdMap.find(l_srcRecordName) == io_srcVpdMap.end())
209fa5e4d32SSunny Srivastava {
210fa5e4d32SSunny Srivastava logging::logMessage(
211fa5e4d32SSunny Srivastava "Record: " + l_srcRecordName +
212fa5e4d32SSunny Srivastava ", is not found in the source path: " + i_srcPath);
213fa5e4d32SSunny Srivastava continue;
214fa5e4d32SSunny Srivastava }
215fa5e4d32SSunny Srivastava
216fa5e4d32SSunny Srivastava if (!io_dstVpdMap.empty() &&
217fa5e4d32SSunny Srivastava io_dstVpdMap.find(l_dstRecordName) == io_dstVpdMap.end())
218fa5e4d32SSunny Srivastava {
219fa5e4d32SSunny Srivastava logging::logMessage(
220fa5e4d32SSunny Srivastava "Record: " + l_dstRecordName +
221fa5e4d32SSunny Srivastava ", is not found in the destination path: " + i_dstPath);
222fa5e4d32SSunny Srivastava continue;
223fa5e4d32SSunny Srivastava }
224fa5e4d32SSunny Srivastava
225fa5e4d32SSunny Srivastava types::BinaryVector l_defaultBinaryValue;
226fa5e4d32SSunny Srivastava if (l_aRecordKwInfo.contains("defaultValue") &&
227fa5e4d32SSunny Srivastava l_aRecordKwInfo["defaultValue"].is_array())
228fa5e4d32SSunny Srivastava {
229fa5e4d32SSunny Srivastava l_defaultBinaryValue =
230fa5e4d32SSunny Srivastava l_aRecordKwInfo["defaultValue"].get<types::BinaryVector>();
231fa5e4d32SSunny Srivastava }
232fa5e4d32SSunny Srivastava else
233fa5e4d32SSunny Srivastava {
234fa5e4d32SSunny Srivastava logging::logMessage(
235fa5e4d32SSunny Srivastava "Couldn't read default value for record name: " +
236fa5e4d32SSunny Srivastava l_srcRecordName + ", keyword name: " + l_srcKeywordName +
237fa5e4d32SSunny Srivastava " from backup and restore config JSON file.");
238fa5e4d32SSunny Srivastava continue;
239fa5e4d32SSunny Srivastava }
240fa5e4d32SSunny Srivastava
241fa5e4d32SSunny Srivastava bool l_isPelRequired = l_aRecordKwInfo.value("isPelRequired", false);
242fa5e4d32SSunny Srivastava
243fa5e4d32SSunny Srivastava types::BinaryVector l_srcBinaryValue;
244fa5e4d32SSunny Srivastava std::string l_srcStrValue;
245fa5e4d32SSunny Srivastava if (!io_srcVpdMap.empty())
246fa5e4d32SSunny Srivastava {
247*a55fcca1SSouvik Roy l_srcStrValue = vpdSpecificUtility::getKwVal(
248*a55fcca1SSouvik Roy io_srcVpdMap.at(l_srcRecordName), l_srcKeywordName);
249*a55fcca1SSouvik Roy
250*a55fcca1SSouvik Roy if (l_srcStrValue.empty())
251*a55fcca1SSouvik Roy {
252*a55fcca1SSouvik Roy std::runtime_error(
253*a55fcca1SSouvik Roy std::string("Failed to get value for keyword [") +
254*a55fcca1SSouvik Roy l_srcKeywordName + std::string("]"));
255*a55fcca1SSouvik Roy }
256*a55fcca1SSouvik Roy
257fa5e4d32SSunny Srivastava l_srcBinaryValue =
258fa5e4d32SSunny Srivastava types::BinaryVector(l_srcStrValue.begin(), l_srcStrValue.end());
259fa5e4d32SSunny Srivastava }
260fa5e4d32SSunny Srivastava else
261fa5e4d32SSunny Srivastava {
262fa5e4d32SSunny Srivastava // Read keyword value from DBus
263fa5e4d32SSunny Srivastava const auto l_value = dbusUtility::readDbusProperty(
264fa5e4d32SSunny Srivastava l_srcServiceName, l_srcInvPath,
265fa5e4d32SSunny Srivastava constants::ipzVpdInf + l_srcRecordName, l_srcKeywordName);
266fa5e4d32SSunny Srivastava if (const auto l_binaryValue =
267fa5e4d32SSunny Srivastava std::get_if<types::BinaryVector>(&l_value))
268fa5e4d32SSunny Srivastava {
269fa5e4d32SSunny Srivastava l_srcBinaryValue = *l_binaryValue;
270fa5e4d32SSunny Srivastava l_srcStrValue = std::string(l_srcBinaryValue.begin(),
271fa5e4d32SSunny Srivastava l_srcBinaryValue.end());
272fa5e4d32SSunny Srivastava }
273fa5e4d32SSunny Srivastava }
274fa5e4d32SSunny Srivastava
275fa5e4d32SSunny Srivastava types::BinaryVector l_dstBinaryValue;
276fa5e4d32SSunny Srivastava std::string l_dstStrValue;
277fa5e4d32SSunny Srivastava if (!io_dstVpdMap.empty())
278fa5e4d32SSunny Srivastava {
279*a55fcca1SSouvik Roy l_dstStrValue = vpdSpecificUtility::getKwVal(
280*a55fcca1SSouvik Roy io_dstVpdMap.at(l_dstRecordName), l_dstKeywordName);
281*a55fcca1SSouvik Roy
282*a55fcca1SSouvik Roy if (l_dstStrValue.empty())
283*a55fcca1SSouvik Roy {
284*a55fcca1SSouvik Roy std::runtime_error(
285*a55fcca1SSouvik Roy std::string("Failed to get value for keyword [") +
286*a55fcca1SSouvik Roy l_dstKeywordName + std::string("]"));
287*a55fcca1SSouvik Roy }
288*a55fcca1SSouvik Roy
289fa5e4d32SSunny Srivastava l_dstBinaryValue =
290fa5e4d32SSunny Srivastava types::BinaryVector(l_dstStrValue.begin(), l_dstStrValue.end());
291fa5e4d32SSunny Srivastava }
292fa5e4d32SSunny Srivastava else
293fa5e4d32SSunny Srivastava {
294fa5e4d32SSunny Srivastava // Read keyword value from DBus
295fa5e4d32SSunny Srivastava const auto l_value = dbusUtility::readDbusProperty(
296fa5e4d32SSunny Srivastava l_dstServiceName, l_dstInvPath,
297fa5e4d32SSunny Srivastava constants::ipzVpdInf + l_dstRecordName, l_dstKeywordName);
298fa5e4d32SSunny Srivastava if (const auto l_binaryValue =
299fa5e4d32SSunny Srivastava std::get_if<types::BinaryVector>(&l_value))
300fa5e4d32SSunny Srivastava {
301fa5e4d32SSunny Srivastava l_dstBinaryValue = *l_binaryValue;
302fa5e4d32SSunny Srivastava l_dstStrValue = std::string(l_dstBinaryValue.begin(),
303fa5e4d32SSunny Srivastava l_dstBinaryValue.end());
304fa5e4d32SSunny Srivastava }
305fa5e4d32SSunny Srivastava }
306fa5e4d32SSunny Srivastava
307fa5e4d32SSunny Srivastava if (l_srcBinaryValue != l_dstBinaryValue)
308fa5e4d32SSunny Srivastava {
309fa5e4d32SSunny Srivastava // ToDo: Handle if there is no valid default value in the backup and
310fa5e4d32SSunny Srivastava // restore config JSON.
311fa5e4d32SSunny Srivastava if (l_dstBinaryValue == l_defaultBinaryValue)
312fa5e4d32SSunny Srivastava {
313fa5e4d32SSunny Srivastava // Update keyword's value on hardware
314fa5e4d32SSunny Srivastava auto l_vpdParser =
315fa5e4d32SSunny Srivastava std::make_shared<Parser>(l_dstFruPath, m_sysCfgJsonObj);
316fa5e4d32SSunny Srivastava
317fa5e4d32SSunny Srivastava auto l_bytesUpdatedOnHardware = l_vpdParser->updateVpdKeyword(
318fa5e4d32SSunny Srivastava types::IpzData(l_dstRecordName, l_dstKeywordName,
319fa5e4d32SSunny Srivastava l_srcBinaryValue));
320fa5e4d32SSunny Srivastava
321fa5e4d32SSunny Srivastava /* To keep the data in sync between hardware and parsed map
322fa5e4d32SSunny Srivastava updating the io_dstVpdMap. This should only be done if write
323fa5e4d32SSunny Srivastava on hardware returns success.*/
324fa5e4d32SSunny Srivastava if (!io_dstVpdMap.empty() && l_bytesUpdatedOnHardware > 0)
325fa5e4d32SSunny Srivastava {
326fa5e4d32SSunny Srivastava io_dstVpdMap[l_dstRecordName][l_dstKeywordName] =
327fa5e4d32SSunny Srivastava l_srcStrValue;
328fa5e4d32SSunny Srivastava }
329fa5e4d32SSunny Srivastava continue;
330fa5e4d32SSunny Srivastava }
331fa5e4d32SSunny Srivastava
332fa5e4d32SSunny Srivastava if (l_srcBinaryValue == l_defaultBinaryValue)
333fa5e4d32SSunny Srivastava {
334fa5e4d32SSunny Srivastava // Update keyword's value on hardware
335fa5e4d32SSunny Srivastava auto l_vpdParser =
336fa5e4d32SSunny Srivastava std::make_shared<Parser>(l_srcFruPath, m_sysCfgJsonObj);
337fa5e4d32SSunny Srivastava
338fa5e4d32SSunny Srivastava auto l_bytesUpdatedOnHardware = l_vpdParser->updateVpdKeyword(
339fa5e4d32SSunny Srivastava types::IpzData(l_srcRecordName, l_srcKeywordName,
340fa5e4d32SSunny Srivastava l_dstBinaryValue));
341fa5e4d32SSunny Srivastava
342fa5e4d32SSunny Srivastava /* To keep the data in sync between hardware and parsed map
343fa5e4d32SSunny Srivastava updating the io_srcVpdMap. This should only be done if write
344fa5e4d32SSunny Srivastava on hardware returns success.*/
345fa5e4d32SSunny Srivastava if (!io_srcVpdMap.empty() && l_bytesUpdatedOnHardware > 0)
346fa5e4d32SSunny Srivastava {
347fa5e4d32SSunny Srivastava io_srcVpdMap[l_srcRecordName][l_srcKeywordName] =
348fa5e4d32SSunny Srivastava l_dstStrValue;
349fa5e4d32SSunny Srivastava }
350fa5e4d32SSunny Srivastava }
351fa5e4d32SSunny Srivastava else
352fa5e4d32SSunny Srivastava {
353fa5e4d32SSunny Srivastava /**
354fa5e4d32SSunny Srivastava * Update io_srcVpdMap to publish the same data on DBus, which
355fa5e4d32SSunny Srivastava * is already present on the DBus. Because after calling
356fa5e4d32SSunny Srivastava * backupAndRestore API the map value will get published to DBus
357fa5e4d32SSunny Srivastava * in the worker flow.
358fa5e4d32SSunny Srivastava */
359fa5e4d32SSunny Srivastava if (!io_srcVpdMap.empty() && io_dstVpdMap.empty())
360fa5e4d32SSunny Srivastava {
361fa5e4d32SSunny Srivastava io_srcVpdMap[l_srcRecordName][l_srcKeywordName] =
362fa5e4d32SSunny Srivastava l_dstStrValue;
363fa5e4d32SSunny Srivastava }
364fa5e4d32SSunny Srivastava
365fa5e4d32SSunny Srivastava std::string l_errorMsg(
366fa5e4d32SSunny Srivastava "Mismatch found between source and destination VPD for record : " +
367fa5e4d32SSunny Srivastava l_srcRecordName + " and keyword : " + l_srcKeywordName +
368fa5e4d32SSunny Srivastava " . Value read from source : " + l_srcStrValue +
369fa5e4d32SSunny Srivastava " . Value read from destination : " + l_dstStrValue);
370fa5e4d32SSunny Srivastava
371fa5e4d32SSunny Srivastava EventLogger::createSyncPel(
372fa5e4d32SSunny Srivastava types::ErrorType::VpdMismatch, types::SeverityType::Warning,
373fa5e4d32SSunny Srivastava __FILE__, __FUNCTION__, 0, l_errorMsg, std::nullopt,
374fa5e4d32SSunny Srivastava std::nullopt, std::nullopt, std::nullopt);
375fa5e4d32SSunny Srivastava }
376fa5e4d32SSunny Srivastava }
377fa5e4d32SSunny Srivastava else if (l_srcBinaryValue == l_defaultBinaryValue &&
378fa5e4d32SSunny Srivastava l_dstBinaryValue == l_defaultBinaryValue && l_isPelRequired)
379fa5e4d32SSunny Srivastava {
380fa5e4d32SSunny Srivastava std::string l_errorMsg(
381fa5e4d32SSunny Srivastava "Default value found on both source and destination VPD, for record: " +
382fa5e4d32SSunny Srivastava l_srcRecordName + " and keyword: " + l_srcKeywordName);
383fa5e4d32SSunny Srivastava
384fa5e4d32SSunny Srivastava EventLogger::createSyncPel(
385fa5e4d32SSunny Srivastava types::ErrorType::DefaultValue, types::SeverityType::Error,
386fa5e4d32SSunny Srivastava __FILE__, __FUNCTION__, 0, l_errorMsg, std::nullopt,
387fa5e4d32SSunny Srivastava std::nullopt, std::nullopt, std::nullopt);
388fa5e4d32SSunny Srivastava }
389fa5e4d32SSunny Srivastava }
390fa5e4d32SSunny Srivastava }
391fa5e4d32SSunny Srivastava
setBackupAndRestoreStatus(const BackupAndRestoreStatus & i_status)392fa5e4d32SSunny Srivastava void BackupAndRestore::setBackupAndRestoreStatus(
393fa5e4d32SSunny Srivastava const BackupAndRestoreStatus& i_status)
394fa5e4d32SSunny Srivastava {
395fa5e4d32SSunny Srivastava m_backupAndRestoreStatus = i_status;
396fa5e4d32SSunny Srivastava }
397fa5e4d32SSunny Srivastava } // namespace vpd
398