diff options
author | Sunitha Harish <sunharis@in.ibm.com> | 2021-09-02 13:09:49 +0300 |
---|---|---|
committer | Gunnar Mills <gmills@us.ibm.com> | 2021-09-08 16:29:53 +0300 |
commit | e62afa5995822679c0ca0ceaf7e4784e46f0b9c3 (patch) | |
tree | ac5c26c1b3a076992d5f5b8001722cab9a3e3092 /include | |
parent | abb93cdd0a49be03bf2fe95f07823686b289ecd5 (diff) | |
download | bmcweb-e62afa5995822679c0ca0ceaf7e4784e46f0b9c3.tar.xz |
IBM Management Interface: Lock Management
This commit removes the lock persistency at BMC
Initial interface design had requirements to persist the locks at BMC.
But now there is no use-case for the management console to persist them.
All required locks are re-acquired after a BMC reboot
Tested by:
1. Acquire lock and verify there is no persistency file
ibm_mc_persistent_lock_data.json
2. Validated all the lock management APIs work fine
Signed-off-by: Sunitha Harish <sunharis@in.ibm.com>
Change-Id: I55af5b256b37bcdf66727bffb5a4354b2f6f7fdf
Diffstat (limited to 'include')
-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, |