From a96de57077c888bfe9a1cee5a511dbda4ff911ab Mon Sep 17 00:00:00 2001 From: Sunny Srivastava Date: Sun, 23 Mar 2025 22:35:19 +0530 Subject: [PATCH] Back up restore design Signed-off-by: Sunny Srivastava --- vpd-manager/include/worker.hpp | 2 ++ vpd-manager/src/backup_restore.cpp | 17 +++++++++++++++++ vpd-manager/src/manager.cpp | 27 +++++++++++++++++++++------ 3 files changed, 40 insertions(+), 6 deletions(-) diff --git a/vpd-manager/include/worker.hpp b/vpd-manager/include/worker.hpp index 8aa59098d..71e06a02a 100644 --- a/vpd-manager/include/worker.hpp +++ b/vpd-manager/include/worker.hpp @@ -568,5 +568,7 @@ class Worker // List of EEPROM paths for which VPD collection thread creation has failed. std::forward_list m_failedEepromPaths; + + std::shared_ptr m_backupAndRestoreObj; }; } // namespace vpd diff --git a/vpd-manager/src/backup_restore.cpp b/vpd-manager/src/backup_restore.cpp index e275ea20b..ca644e954 100644 --- a/vpd-manager/src/backup_restore.cpp +++ b/vpd-manager/src/backup_restore.cpp @@ -394,4 +394,21 @@ void BackupAndRestore::setBackupAndRestoreStatus( { m_backupAndRestoreStatus = i_status; } + +int BackupAndRestore::perfromIndividualBackupRestore( + const types::Path i_Path, const types::WriteVpdParams i_paramsToWriteData) +{ + // check if path qualifies for back up and restore + if (!/*qualifies for B&R*/) + { + return 0; + } + + // perform back up or restore based on the path + if (/*B&R is successful*/) + { + return 1; + } + return -1; +} } // namespace vpd diff --git a/vpd-manager/src/manager.cpp b/vpd-manager/src/manager.cpp index fdc046339..ace9eb652 100644 --- a/vpd-manager/src/manager.cpp +++ b/vpd-manager/src/manager.cpp @@ -42,6 +42,13 @@ Manager::Manager( m_worker = std::make_shared(INVENTORY_JSON_DEFAULT); } + if (!m_worker->getSysCfgJsonObj().empty() && + jsonUtility::isBackupAndRestoreRequired(l_sysCfgJsonObj)) + { + m_backupAndRestoreObj = std::make_shared( + m_worker->getSysCfgJsonObj()); + } + // Set up minimal things that is needed before bus name is claimed. m_worker->performInitialSetup(); @@ -294,12 +301,9 @@ void Manager::SetTimerToDetectVpdCollectionStatus() m_interface->set_property("CollectionStatus", std::string("Completed")); - const nlohmann::json& l_sysCfgJsonObj = - m_worker->getSysCfgJsonObj(); - if (jsonUtility::isBackupAndRestoreRequired(l_sysCfgJsonObj)) + if (m_backupAndRestoreObj) { - BackupAndRestore l_backupAndRestoreObj(l_sysCfgJsonObj); - l_backupAndRestoreObj.backupAndRestore(); + m_backupAndRestoreObj->backupAndRestore(); } } else @@ -540,7 +544,18 @@ int Manager::updateKeyword(const types::Path i_vpdPath, { std::shared_ptr l_parserObj = std::make_shared(l_fruPath, l_sysCfgJsonObj); - return l_parserObj->updateVpdKeyword(i_paramsToWriteData); + int l_rc = l_parserObj->updateVpdKeyword(i_paramsToWriteData); + + if (l_rc > constants::VALUE_0 && m_backupRestoreObj) + { + if (m_backupRestoreObj->perfromIndividualBackupRestore( + l_fruPath, i_paramsToWriteData) < 0) + { + // write passed but back up and restore failed; + } + } + + return l_rc; } catch (const std::exception& l_exception) {