diff options
Diffstat (limited to 'include/ibm/locks.hpp')
-rw-r--r-- | include/ibm/locks.hpp | 75 |
1 files changed, 0 insertions, 75 deletions
diff --git a/include/ibm/locks.hpp b/include/ibm/locks.hpp index 0f1062a72f..800ee484e8 100644 --- a/include/ibm/locks.hpp +++ b/include/ibm/locks.hpp @@ -36,29 +36,14 @@ using RcAcquireLock = std::pair<bool, std::variant<Rc, std::pair<bool, int>>>; using RcReleaseLockApi = std::pair<bool, std::variant<bool, RcRelaseLock>>; using SessionFlags = std::pair<SType, SType>; using ListOfSessionIds = std::vector<std::string>; -static constexpr const char* fileName = - "/var/lib/bmcweb/ibm-management-console/locks/" - "ibm_mc_persistent_lock_data.json"; class Lock { uint32_t transactionId; boost::container::flat_map<uint32_t, LockRequests> lockTable; - /* - * This API implements the logic to load the locks that are present in the - * json file into the lock table. - */ - void loadLocks(); - protected: /* - * This API implements the logic to persist the locks that are contained in - * the lock table into a json file. - */ - void saveLocks(); - - /* * This function implements the logic for validating an incoming * lock request/requests. * @@ -124,7 +109,6 @@ class Lock Lock() { - loadLocks(); transactionId = lockTable.empty() ? 0 : prev(lockTable.end())->first; } @@ -189,53 +173,6 @@ class Lock virtual ~Lock() = default; }; -inline void Lock::loadLocks() -{ - std::ifstream persistentFile(fileName); - if (persistentFile.is_open()) - { - auto data = nlohmann::json::parse(persistentFile, nullptr, false); - if (data.is_discarded()) - { - BMCWEB_LOG_ERROR << "Error parsing persistent data in json file."; - return; - } - BMCWEB_LOG_DEBUG << "The persistent lock data is available"; - for (const auto& item : data.items()) - { - BMCWEB_LOG_DEBUG << item.key(); - BMCWEB_LOG_DEBUG << item.value(); - LockRequests locks = item.value(); - lockTable.emplace(std::pair<uint32_t, LockRequests>( - std::stoul(item.key()), locks)); - BMCWEB_LOG_DEBUG << "The persistent lock data loaded"; - } - } -} - -inline void Lock::saveLocks() -{ - std::error_code ec; - std::string_view path = "/var/lib/bmcweb/ibm-management-console/locks"; - if (!crow::ibm_utils::createDirectory(path)) - { - BMCWEB_LOG_DEBUG << "Failed to create lock persistent path"; - return; - } - std::ofstream persistentFile(fileName); - // set the permission of the file to 600 - std::filesystem::perms permission = std::filesystem::perms::owner_read | - std::filesystem::perms::owner_write; - std::filesystem::permissions(fileName, permission); - nlohmann::json data; - for (const auto& it : lockTable) - { - data[std::to_string(it.first)] = it.second; - } - BMCWEB_LOG_DEBUG << "data is " << data; - persistentFile << data; -} - inline RcGetLockList Lock::getLockList(const ListOfSessionIds& listSessionId) { @@ -324,9 +261,6 @@ inline RcAcquireLock Lock::acquireLock(const LockRequests& lockRequestStructure) auto conflict = isConflictWithTable(multiRequest); - // save the lock in the persistent file - saveLocks(); - BMCWEB_LOG_DEBUG << "Done with checking conflict with the locktable"; return std::make_pair(false, conflict); } @@ -348,13 +282,10 @@ inline void Lock::releaseLock(const ListOfTransactionIds& refRids) << id; } } - - saveLocks(); } inline void Lock::releaseLock(const std::string& sessionId) { - bool isErased = false; if (!lockTable.empty()) { auto it = lockTable.begin(); @@ -371,7 +302,6 @@ inline void Lock::releaseLock(const std::string& sessionId) << sessionId; BMCWEB_LOG_DEBUG << "TransactionID =" << it->first; it = lockTable.erase(it); - isErased = true; } else { @@ -379,11 +309,6 @@ inline void Lock::releaseLock(const std::string& sessionId) } } } - if (isErased) - { - // save the lock in the persistent file - saveLocks(); - } } } inline RcRelaseLock Lock::isItMyLock(const ListOfTransactionIds& refRids, |