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
diff --git a/include/ibm/locks.hpp b/include/ibm/locks.hpp
index 0f1062a..800ee48 100644
--- a/include/ibm/locks.hpp
+++ b/include/ibm/locks.hpp
@@ -36,29 +36,14 @@
 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 @@
 
     Lock()
     {
-        loadLocks();
         transactionId = lockTable.empty() ? 0 : prev(lockTable.end())->first;
     }
 
@@ -189,53 +173,6 @@
     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 @@
 
     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 @@
                              << id;
         }
     }
-
-    saveLocks();
 }
 
 inline void Lock::releaseLock(const std::string& sessionId)
 {
-    bool isErased = false;
     if (!lockTable.empty())
     {
         auto it = lockTable.begin();
@@ -371,7 +302,6 @@
                                      << sessionId;
                     BMCWEB_LOG_DEBUG << "TransactionID =" << it->first;
                     it = lockTable.erase(it);
-                    isErased = true;
                 }
                 else
                 {
@@ -379,11 +309,6 @@
                 }
             }
         }
-        if (isErased)
-        {
-            // save the lock in the persistent file
-            saveLocks();
-        }
     }
 }
 inline RcRelaseLock Lock::isItMyLock(const ListOfTransactionIds& refRids,