manojkiraneda | 0b631ae | 2019-12-03 17:54:28 +0530 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Nan Zhou | 77665bd | 2022-10-12 20:28:58 +0000 | [diff] [blame] | 3 | #include "ibm/utils.hpp" |
Ed Tanous | 3ccb3ad | 2023-01-13 17:40:03 -0800 | [diff] [blame] | 4 | #include "logging.hpp" |
Nan Zhou | 77665bd | 2022-10-12 20:28:58 +0000 | [diff] [blame] | 5 | |
manojkiraneda | 0b631ae | 2019-12-03 17:54:28 +0530 | [diff] [blame] | 6 | #include <boost/container/flat_map.hpp> |
Manojkiran Eda | 55fd1a9 | 2020-04-30 19:06:48 +0530 | [diff] [blame] | 7 | #include <boost/endian/conversion.hpp> |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 8 | #include <nlohmann/json.hpp> |
| 9 | |
manojkiraneda | 0b631ae | 2019-12-03 17:54:28 +0530 | [diff] [blame] | 10 | #include <filesystem> |
Sunitha Harish | 8a3bb71 | 2019-12-13 03:48:09 -0600 | [diff] [blame] | 11 | #include <fstream> |
Ed Tanous | 11ba397 | 2022-07-11 09:50:41 -0700 | [diff] [blame] | 12 | #include <variant> |
manojkiraneda | 0b631ae | 2019-12-03 17:54:28 +0530 | [diff] [blame] | 13 | |
| 14 | namespace crow |
| 15 | { |
| 16 | namespace ibm_mc_lock |
| 17 | { |
| 18 | |
manojkiraneda | 0b631ae | 2019-12-03 17:54:28 +0530 | [diff] [blame] | 19 | using SType = std::string; |
| 20 | |
| 21 | /*---------------------------------------- |
| 22 | |Segment flags : LockFlag | SegmentLength| |
| 23 | ------------------------------------------*/ |
| 24 | |
| 25 | using SegmentFlags = std::vector<std::pair<SType, uint32_t>>; |
| 26 | |
| 27 | // Lockrequest = session-id | hmc-id | locktype | resourceid | segmentinfo |
| 28 | using LockRequest = std::tuple<SType, SType, SType, uint64_t, SegmentFlags>; |
manojkiraneda | 0b631ae | 2019-12-03 17:54:28 +0530 | [diff] [blame] | 29 | using LockRequests = std::vector<LockRequest>; |
| 30 | using Rc = |
| 31 | std::pair<bool, std::variant<uint32_t, std::pair<uint32_t, LockRequest>>>; |
manojkiraneda | 3b6dea6 | 2019-12-13 17:05:36 +0530 | [diff] [blame] | 32 | using RcRelaseLock = std::pair<bool, std::pair<uint32_t, LockRequest>>; |
manojkiraneda | 402b571 | 2019-12-13 17:07:09 +0530 | [diff] [blame] | 33 | using RcGetLockList = |
| 34 | std::variant<std::string, std::vector<std::pair<uint32_t, LockRequests>>>; |
manojkiraneda | 3b6dea6 | 2019-12-13 17:05:36 +0530 | [diff] [blame] | 35 | using ListOfTransactionIds = std::vector<uint32_t>; |
manojkiraneda | 0b631ae | 2019-12-03 17:54:28 +0530 | [diff] [blame] | 36 | using RcAcquireLock = std::pair<bool, std::variant<Rc, std::pair<bool, int>>>; |
manojkiraneda | 3b6dea6 | 2019-12-13 17:05:36 +0530 | [diff] [blame] | 37 | using RcReleaseLockApi = std::pair<bool, std::variant<bool, RcRelaseLock>>; |
| 38 | using SessionFlags = std::pair<SType, SType>; |
manojkiraneda | 402b571 | 2019-12-13 17:07:09 +0530 | [diff] [blame] | 39 | using ListOfSessionIds = std::vector<std::string>; |
manojkiraneda | 0b631ae | 2019-12-03 17:54:28 +0530 | [diff] [blame] | 40 | |
| 41 | class Lock |
| 42 | { |
Ed Tanous | 543f440 | 2022-01-06 13:12:53 -0800 | [diff] [blame] | 43 | uint32_t transactionId = 0; |
manojkiraneda | 0b631ae | 2019-12-03 17:54:28 +0530 | [diff] [blame] | 44 | boost::container::flat_map<uint32_t, LockRequests> lockTable; |
| 45 | |
manojkiraneda | 4eaf2ee | 2019-12-13 17:10:41 +0530 | [diff] [blame] | 46 | protected: |
| 47 | /* |
| 48 | * This function implements the logic for validating an incoming |
| 49 | * lock request/requests. |
| 50 | * |
| 51 | * Returns : True (if Valid) |
| 52 | * Returns : False (if not a Valid lock request) |
| 53 | */ |
| 54 | |
Ed Tanous | 104f09c | 2022-01-25 09:56:04 -0800 | [diff] [blame] | 55 | virtual bool isValidLockRequest(const LockRequest& refLockRecord); |
manojkiraneda | 4eaf2ee | 2019-12-13 17:10:41 +0530 | [diff] [blame] | 56 | |
| 57 | /* |
| 58 | * This function implements the logic of checking if the incoming |
| 59 | * multi-lock request is not having conflicting requirements. |
| 60 | * |
| 61 | * Returns : True (if conflicting) |
| 62 | * Returns : False (if not conflicting) |
| 63 | */ |
| 64 | |
Ed Tanous | 104f09c | 2022-01-25 09:56:04 -0800 | [diff] [blame] | 65 | virtual bool isConflictRequest(const LockRequests& refLockRequestStructure); |
manojkiraneda | 4eaf2ee | 2019-12-13 17:10:41 +0530 | [diff] [blame] | 66 | /* |
| 67 | * Implements the core algorithm to find the conflicting |
| 68 | * lock requests. |
| 69 | * |
| 70 | * This functions takes two lock requests and check if both |
| 71 | * are conflicting to each other. |
| 72 | * |
| 73 | * Returns : True (if conflicting) |
| 74 | * Returns : False (if not conflicting) |
| 75 | */ |
Ed Tanous | 104f09c | 2022-01-25 09:56:04 -0800 | [diff] [blame] | 76 | virtual bool isConflictRecord(const LockRequest& refLockRecord1, |
| 77 | const LockRequest& refLockRecord2); |
manojkiraneda | 4eaf2ee | 2019-12-13 17:10:41 +0530 | [diff] [blame] | 78 | |
| 79 | /* |
| 80 | * This function implements the logic of checking the conflicting |
| 81 | * locks from a incoming single/multi lock requests with the already |
| 82 | * existing lock request in the lock table. |
| 83 | * |
| 84 | */ |
| 85 | |
Ed Tanous | 104f09c | 2022-01-25 09:56:04 -0800 | [diff] [blame] | 86 | virtual Rc isConflictWithTable(const LockRequests& refLockRequestStructure); |
manojkiraneda | 4eaf2ee | 2019-12-13 17:10:41 +0530 | [diff] [blame] | 87 | /* |
| 88 | * This function implements the logic of checking the ownership of the |
| 89 | * lock from the releaselock request. |
| 90 | * |
| 91 | * Returns : True (if the requesting HMC & Session owns the lock(s)) |
| 92 | * Returns : False (if the request HMC or Session does not own the lock(s)) |
| 93 | */ |
| 94 | |
Ed Tanous | 104f09c | 2022-01-25 09:56:04 -0800 | [diff] [blame] | 95 | virtual RcRelaseLock isItMyLock(const ListOfTransactionIds& refRids, |
| 96 | const SessionFlags& ids); |
manojkiraneda | 4eaf2ee | 2019-12-13 17:10:41 +0530 | [diff] [blame] | 97 | |
| 98 | /* |
| 99 | * This function validates the the list of transactionID's and returns false |
| 100 | * if the transaction ID is not valid & not present in the lock table |
| 101 | */ |
| 102 | |
Ed Tanous | 104f09c | 2022-01-25 09:56:04 -0800 | [diff] [blame] | 103 | virtual bool validateRids(const ListOfTransactionIds& refRids); |
manojkiraneda | 4eaf2ee | 2019-12-13 17:10:41 +0530 | [diff] [blame] | 104 | |
| 105 | /* |
| 106 | * This function releases the locks that are already obtained by the |
| 107 | * requesting Management console. |
| 108 | */ |
| 109 | |
Ed Tanous | 104f09c | 2022-01-25 09:56:04 -0800 | [diff] [blame] | 110 | void releaseLock(const ListOfTransactionIds& refRids); |
manojkiraneda | 4eaf2ee | 2019-12-13 17:10:41 +0530 | [diff] [blame] | 111 | |
| 112 | Lock() |
| 113 | { |
manojkiraneda | 4eaf2ee | 2019-12-13 17:10:41 +0530 | [diff] [blame] | 114 | transactionId = lockTable.empty() ? 0 : prev(lockTable.end())->first; |
| 115 | } |
| 116 | |
Sunitha Harish | 8a3bb71 | 2019-12-13 03:48:09 -0600 | [diff] [blame] | 117 | /* |
manojkiraneda | 0b631ae | 2019-12-03 17:54:28 +0530 | [diff] [blame] | 118 | * This function implements the algorithm for checking the respective |
| 119 | * bytes of the resource id based on the lock management algorithm. |
| 120 | */ |
| 121 | |
Ed Tanous | 104f09c | 2022-01-25 09:56:04 -0800 | [diff] [blame] | 122 | static bool checkByte(uint64_t resourceId1, uint64_t resourceId2, |
| 123 | uint32_t position); |
manojkiraneda | 0b631ae | 2019-12-03 17:54:28 +0530 | [diff] [blame] | 124 | |
| 125 | /* |
| 126 | * This functions implements a counter that generates a unique 32 bit |
| 127 | * number for every successful transaction. This number will be used by |
| 128 | * the Management Console for debug. |
| 129 | */ |
manojkiraneda | 4eaf2ee | 2019-12-13 17:10:41 +0530 | [diff] [blame] | 130 | virtual uint32_t generateTransactionId(); |
Sunitha Harish | 8a3bb71 | 2019-12-13 03:48:09 -0600 | [diff] [blame] | 131 | |
manojkiraneda | 0b631ae | 2019-12-03 17:54:28 +0530 | [diff] [blame] | 132 | public: |
| 133 | /* |
Ed Tanous | ecd6a3a | 2022-01-07 09:18:40 -0800 | [diff] [blame] | 134 | * Explicitly deleted copy and move constructors |
| 135 | */ |
| 136 | Lock(const Lock&) = delete; |
| 137 | Lock(Lock&&) = delete; |
| 138 | Lock& operator=(const Lock&) = delete; |
| 139 | Lock& operator=(Lock&&) = delete; |
| 140 | |
| 141 | /* |
manojkiraneda | 0b631ae | 2019-12-03 17:54:28 +0530 | [diff] [blame] | 142 | * This function implements the logic for acquiring a lock on a |
Manojkiran Eda | 5bb0ece | 2020-01-20 20:22:36 +0530 | [diff] [blame] | 143 | * resource if the incoming request is legitimate without any |
manojkiraneda | 0b631ae | 2019-12-03 17:54:28 +0530 | [diff] [blame] | 144 | * conflicting requirements & without any conflicting requirement |
Gunnar Mills | caa3ce3 | 2020-07-08 14:46:53 -0500 | [diff] [blame] | 145 | * with the existing locks in the lock table. |
manojkiraneda | 0b631ae | 2019-12-03 17:54:28 +0530 | [diff] [blame] | 146 | * |
| 147 | */ |
| 148 | |
Ed Tanous | 104f09c | 2022-01-25 09:56:04 -0800 | [diff] [blame] | 149 | RcAcquireLock acquireLock(const LockRequests& lockRequestStructure); |
manojkiraneda | 0b631ae | 2019-12-03 17:54:28 +0530 | [diff] [blame] | 150 | |
manojkiraneda | 3b6dea6 | 2019-12-13 17:05:36 +0530 | [diff] [blame] | 151 | /* |
| 152 | * This function implements the logic for releasing the lock that are |
| 153 | * owned by a management console session. |
| 154 | * |
| 155 | * The locks can be released by two ways |
| 156 | * - Using list of transaction ID's |
| 157 | * - Using a Session ID |
| 158 | * |
| 159 | * Client can choose either of the ways by using `Type` JSON key. |
| 160 | * |
| 161 | */ |
Ed Tanous | 104f09c | 2022-01-25 09:56:04 -0800 | [diff] [blame] | 162 | RcReleaseLockApi releaseLock(const ListOfTransactionIds& p, |
| 163 | const SessionFlags& ids); |
manojkiraneda | 3b6dea6 | 2019-12-13 17:05:36 +0530 | [diff] [blame] | 164 | |
manojkiraneda | 402b571 | 2019-12-13 17:07:09 +0530 | [diff] [blame] | 165 | /* |
| 166 | * This function implements the logic for getting the list of locks obtained |
| 167 | * by a particular management console. |
| 168 | */ |
Ed Tanous | 104f09c | 2022-01-25 09:56:04 -0800 | [diff] [blame] | 169 | RcGetLockList getLockList(const ListOfSessionIds& listSessionId); |
manojkiraneda | 402b571 | 2019-12-13 17:07:09 +0530 | [diff] [blame] | 170 | |
Ratan Gupta | 07386c6 | 2019-12-14 14:06:09 +0530 | [diff] [blame] | 171 | /* |
| 172 | * This function is releases all the locks obtained by a particular |
| 173 | * session. |
| 174 | */ |
| 175 | |
Ed Tanous | 104f09c | 2022-01-25 09:56:04 -0800 | [diff] [blame] | 176 | void releaseLock(const std::string& sessionId); |
Ratan Gupta | 07386c6 | 2019-12-14 14:06:09 +0530 | [diff] [blame] | 177 | |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 178 | static Lock& getInstance() |
Ratan Gupta | 07386c6 | 2019-12-14 14:06:09 +0530 | [diff] [blame] | 179 | { |
| 180 | static Lock lockObject; |
| 181 | return lockObject; |
| 182 | } |
manojkiraneda | 4eaf2ee | 2019-12-13 17:10:41 +0530 | [diff] [blame] | 183 | |
Ed Tanous | 4e08751 | 2020-09-28 18:41:25 -0700 | [diff] [blame] | 184 | virtual ~Lock() = default; |
Ratan Gupta | 07386c6 | 2019-12-14 14:06:09 +0530 | [diff] [blame] | 185 | }; |
manojkiraneda | 0b631ae | 2019-12-03 17:54:28 +0530 | [diff] [blame] | 186 | |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 187 | inline RcGetLockList Lock::getLockList(const ListOfSessionIds& listSessionId) |
manojkiraneda | 402b571 | 2019-12-13 17:07:09 +0530 | [diff] [blame] | 188 | { |
Ravi Teja | 9eef578 | 2023-06-13 11:55:02 +0000 | [diff] [blame] | 189 | std::vector<std::pair<uint32_t, LockRequests>> lockList{}; |
manojkiraneda | 402b571 | 2019-12-13 17:07:09 +0530 | [diff] [blame] | 190 | |
| 191 | if (!lockTable.empty()) |
| 192 | { |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 193 | for (const auto& i : listSessionId) |
manojkiraneda | 402b571 | 2019-12-13 17:07:09 +0530 | [diff] [blame] | 194 | { |
| 195 | auto it = lockTable.begin(); |
| 196 | while (it != lockTable.end()) |
| 197 | { |
| 198 | // Check if session id of this entry matches with session id |
| 199 | // given |
| 200 | if (std::get<0>(it->second[0]) == i) |
| 201 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 202 | BMCWEB_LOG_DEBUG("Session id is found in the locktable"); |
manojkiraneda | 402b571 | 2019-12-13 17:07:09 +0530 | [diff] [blame] | 203 | |
| 204 | // Push the whole lock record into a vector for returning |
| 205 | // the json |
Ed Tanous | 4e08751 | 2020-09-28 18:41:25 -0700 | [diff] [blame] | 206 | lockList.emplace_back(it->first, it->second); |
manojkiraneda | 402b571 | 2019-12-13 17:07:09 +0530 | [diff] [blame] | 207 | } |
| 208 | // Go to next entry in map |
| 209 | it++; |
| 210 | } |
| 211 | } |
| 212 | } |
| 213 | // we may have found at least one entry with the given session id |
| 214 | // return the json list of lock records pertaining to the given |
| 215 | // session id, or send an empty list if lock table is empty |
Ed Tanous | 02379d3 | 2020-09-15 21:15:44 -0700 | [diff] [blame] | 216 | return {lockList}; |
manojkiraneda | 402b571 | 2019-12-13 17:07:09 +0530 | [diff] [blame] | 217 | } |
| 218 | |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 219 | inline RcReleaseLockApi Lock::releaseLock(const ListOfTransactionIds& p, |
| 220 | const SessionFlags& ids) |
manojkiraneda | 3b6dea6 | 2019-12-13 17:05:36 +0530 | [diff] [blame] | 221 | { |
manojkiraneda | 3b6dea6 | 2019-12-13 17:05:36 +0530 | [diff] [blame] | 222 | bool status = validateRids(p); |
| 223 | |
| 224 | if (!status) |
| 225 | { |
| 226 | // Validation of rids failed |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 227 | BMCWEB_LOG_ERROR("releaseLock: Contains invalid request id"); |
manojkiraneda | 3b6dea6 | 2019-12-13 17:05:36 +0530 | [diff] [blame] | 228 | return std::make_pair(false, status); |
| 229 | } |
Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 230 | // Validation passed, check if all the locks are owned by the |
| 231 | // requesting HMC |
| 232 | auto status2 = isItMyLock(p, ids); |
Sunitha Harish | 3e7ab70 | 2022-08-08 02:08:39 -0500 | [diff] [blame] | 233 | if (!status2.first) |
manojkiraneda | 3b6dea6 | 2019-12-13 17:05:36 +0530 | [diff] [blame] | 234 | { |
Sunitha Harish | 3e7ab70 | 2022-08-08 02:08:39 -0500 | [diff] [blame] | 235 | return std::make_pair(false, status2); |
manojkiraneda | 3b6dea6 | 2019-12-13 17:05:36 +0530 | [diff] [blame] | 236 | } |
Manojkiran Eda | a1ffbb8 | 2020-10-28 17:42:21 +0530 | [diff] [blame] | 237 | return std::make_pair(true, status2); |
manojkiraneda | 3b6dea6 | 2019-12-13 17:05:36 +0530 | [diff] [blame] | 238 | } |
| 239 | |
Ed Tanous | b5a7693 | 2020-09-29 16:16:58 -0700 | [diff] [blame] | 240 | inline RcAcquireLock Lock::acquireLock(const LockRequests& lockRequestStructure) |
manojkiraneda | 0b631ae | 2019-12-03 17:54:28 +0530 | [diff] [blame] | 241 | { |
manojkiraneda | 0b631ae | 2019-12-03 17:54:28 +0530 | [diff] [blame] | 242 | // validate the lock request |
| 243 | |
Ed Tanous | 9eb808c | 2022-01-25 10:19:23 -0800 | [diff] [blame] | 244 | for (const auto& lockRecord : lockRequestStructure) |
manojkiraneda | 0b631ae | 2019-12-03 17:54:28 +0530 | [diff] [blame] | 245 | { |
| 246 | bool status = isValidLockRequest(lockRecord); |
| 247 | if (!status) |
| 248 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 249 | BMCWEB_LOG_DEBUG("Not a Valid record"); |
| 250 | BMCWEB_LOG_DEBUG("Bad json in request"); |
manojkiraneda | 0b631ae | 2019-12-03 17:54:28 +0530 | [diff] [blame] | 251 | return std::make_pair(true, std::make_pair(status, 0)); |
| 252 | } |
| 253 | } |
| 254 | // check for conflict record |
| 255 | |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 256 | const LockRequests& multiRequest = lockRequestStructure; |
manojkiraneda | 0b631ae | 2019-12-03 17:54:28 +0530 | [diff] [blame] | 257 | bool status = isConflictRequest(multiRequest); |
| 258 | |
| 259 | if (status) |
| 260 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 261 | BMCWEB_LOG_DEBUG("There is a conflict within itself"); |
manojkiraneda | 0b631ae | 2019-12-03 17:54:28 +0530 | [diff] [blame] | 262 | return std::make_pair(true, std::make_pair(status, 1)); |
| 263 | } |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 264 | BMCWEB_LOG_DEBUG("The request is not conflicting within itself"); |
manojkiraneda | 0b631ae | 2019-12-03 17:54:28 +0530 | [diff] [blame] | 265 | |
Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 266 | // Need to check for conflict with the locktable entries. |
manojkiraneda | 0b631ae | 2019-12-03 17:54:28 +0530 | [diff] [blame] | 267 | |
Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 268 | auto conflict = isConflictWithTable(multiRequest); |
manojkiraneda | 0b631ae | 2019-12-03 17:54:28 +0530 | [diff] [blame] | 269 | |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 270 | BMCWEB_LOG_DEBUG("Done with checking conflict with the locktable"); |
Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 271 | return std::make_pair(false, conflict); |
manojkiraneda | 0b631ae | 2019-12-03 17:54:28 +0530 | [diff] [blame] | 272 | } |
| 273 | |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 274 | inline void Lock::releaseLock(const std::string& sessionId) |
Ratan Gupta | 07386c6 | 2019-12-14 14:06:09 +0530 | [diff] [blame] | 275 | { |
Ratan Gupta | 07386c6 | 2019-12-14 14:06:09 +0530 | [diff] [blame] | 276 | if (!lockTable.empty()) |
| 277 | { |
| 278 | auto it = lockTable.begin(); |
| 279 | while (it != lockTable.end()) |
| 280 | { |
Ed Tanous | 26f6976 | 2022-01-25 09:49:11 -0800 | [diff] [blame] | 281 | if (!it->second.empty()) |
Ratan Gupta | 07386c6 | 2019-12-14 14:06:09 +0530 | [diff] [blame] | 282 | { |
| 283 | // Check if session id of this entry matches with session id |
| 284 | // given |
| 285 | if (std::get<0>(it->second[0]) == sessionId) |
| 286 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 287 | BMCWEB_LOG_DEBUG("Remove the lock from the locktable " |
| 288 | "having sessionID={}", |
| 289 | sessionId); |
| 290 | BMCWEB_LOG_DEBUG("TransactionID ={}", it->first); |
Ratan Gupta | 07386c6 | 2019-12-14 14:06:09 +0530 | [diff] [blame] | 291 | it = lockTable.erase(it); |
Ratan Gupta | 07386c6 | 2019-12-14 14:06:09 +0530 | [diff] [blame] | 292 | } |
| 293 | else |
| 294 | { |
| 295 | it++; |
| 296 | } |
| 297 | } |
| 298 | } |
Ratan Gupta | 07386c6 | 2019-12-14 14:06:09 +0530 | [diff] [blame] | 299 | } |
| 300 | } |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 301 | inline RcRelaseLock Lock::isItMyLock(const ListOfTransactionIds& refRids, |
| 302 | const SessionFlags& ids) |
manojkiraneda | 3b6dea6 | 2019-12-13 17:05:36 +0530 | [diff] [blame] | 303 | { |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 304 | for (const auto& id : refRids) |
manojkiraneda | 3b6dea6 | 2019-12-13 17:05:36 +0530 | [diff] [blame] | 305 | { |
| 306 | // Just need to compare the client id of the first lock records in the |
| 307 | // complete lock row(in the map), because the rest of the lock records |
| 308 | // would have the same client id |
| 309 | |
| 310 | std::string expectedClientId = std::get<1>(lockTable[id][0]); |
| 311 | std::string expectedSessionId = std::get<0>(lockTable[id][0]); |
| 312 | |
| 313 | if ((expectedClientId == ids.first) && |
| 314 | (expectedSessionId == ids.second)) |
| 315 | { |
| 316 | // It is owned by the currently request hmc |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 317 | BMCWEB_LOG_DEBUG("Lock is owned by the current hmc"); |
Sunitha Harish | 3e7ab70 | 2022-08-08 02:08:39 -0500 | [diff] [blame] | 318 | // remove the lock |
| 319 | if (lockTable.erase(id) != 0U) |
| 320 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 321 | BMCWEB_LOG_DEBUG("Removing the locks with transaction ID : {}", |
| 322 | id); |
Sunitha Harish | 3e7ab70 | 2022-08-08 02:08:39 -0500 | [diff] [blame] | 323 | } |
| 324 | else |
| 325 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 326 | BMCWEB_LOG_ERROR("Removing the locks from the lock table " |
| 327 | "failed, transaction ID: {}", |
| 328 | id); |
Sunitha Harish | 3e7ab70 | 2022-08-08 02:08:39 -0500 | [diff] [blame] | 329 | } |
manojkiraneda | 3b6dea6 | 2019-12-13 17:05:36 +0530 | [diff] [blame] | 330 | } |
| 331 | else |
| 332 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 333 | BMCWEB_LOG_DEBUG("Lock is not owned by the current hmc"); |
manojkiraneda | 3b6dea6 | 2019-12-13 17:05:36 +0530 | [diff] [blame] | 334 | return std::make_pair(false, std::make_pair(id, lockTable[id][0])); |
| 335 | } |
| 336 | } |
| 337 | return std::make_pair(true, std::make_pair(0, LockRequest())); |
| 338 | } |
| 339 | |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 340 | inline bool Lock::validateRids(const ListOfTransactionIds& refRids) |
manojkiraneda | 3b6dea6 | 2019-12-13 17:05:36 +0530 | [diff] [blame] | 341 | { |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 342 | for (const auto& id : refRids) |
manojkiraneda | 3b6dea6 | 2019-12-13 17:05:36 +0530 | [diff] [blame] | 343 | { |
| 344 | auto search = lockTable.find(id); |
| 345 | |
| 346 | if (search != lockTable.end()) |
| 347 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 348 | BMCWEB_LOG_DEBUG("Valid Transaction id"); |
manojkiraneda | 3b6dea6 | 2019-12-13 17:05:36 +0530 | [diff] [blame] | 349 | // continue for the next rid |
| 350 | } |
| 351 | else |
| 352 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 353 | BMCWEB_LOG_ERROR("validateRids: At least 1 inValid Request id: {}", |
| 354 | id); |
manojkiraneda | 3b6dea6 | 2019-12-13 17:05:36 +0530 | [diff] [blame] | 355 | return false; |
| 356 | } |
| 357 | } |
| 358 | return true; |
| 359 | } |
| 360 | |
Ed Tanous | b5a7693 | 2020-09-29 16:16:58 -0700 | [diff] [blame] | 361 | inline bool Lock::isValidLockRequest(const LockRequest& refLockRecord) |
manojkiraneda | 0b631ae | 2019-12-03 17:54:28 +0530 | [diff] [blame] | 362 | { |
manojkiraneda | 0b631ae | 2019-12-03 17:54:28 +0530 | [diff] [blame] | 363 | // validate the locktype |
| 364 | |
Ed Tanous | 18f8f60 | 2023-07-18 10:07:23 -0700 | [diff] [blame] | 365 | if (!((std::get<2>(refLockRecord) == "Read" || |
| 366 | (std::get<2>(refLockRecord) == "Write")))) |
manojkiraneda | 0b631ae | 2019-12-03 17:54:28 +0530 | [diff] [blame] | 367 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 368 | BMCWEB_LOG_DEBUG("Validation of LockType Failed"); |
| 369 | BMCWEB_LOG_DEBUG("Locktype : {}", std::get<2>(refLockRecord)); |
manojkiraneda | 0b631ae | 2019-12-03 17:54:28 +0530 | [diff] [blame] | 370 | return false; |
| 371 | } |
| 372 | |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 373 | BMCWEB_LOG_DEBUG("{}", static_cast<int>(std::get<4>(refLockRecord).size())); |
manojkiraneda | 0b631ae | 2019-12-03 17:54:28 +0530 | [diff] [blame] | 374 | |
| 375 | // validate the number of segments |
| 376 | // Allowed No of segments are between 2 and 6 |
| 377 | if ((static_cast<int>(std::get<4>(refLockRecord).size()) > 6) || |
| 378 | (static_cast<int>(std::get<4>(refLockRecord).size()) < 2)) |
| 379 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 380 | BMCWEB_LOG_DEBUG("Validation of Number of Segments Failed"); |
Ed Tanous | 8ece0e4 | 2024-01-02 13:16:50 -0800 | [diff] [blame] | 381 | BMCWEB_LOG_DEBUG("Number of Segments provided : {}", |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 382 | std::get<4>(refLockRecord).size()); |
manojkiraneda | 0b631ae | 2019-12-03 17:54:28 +0530 | [diff] [blame] | 383 | return false; |
| 384 | } |
| 385 | |
| 386 | int lockFlag = 0; |
| 387 | // validate the lockflags & segment length |
| 388 | |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 389 | for (const auto& p : std::get<4>(refLockRecord)) |
manojkiraneda | 0b631ae | 2019-12-03 17:54:28 +0530 | [diff] [blame] | 390 | { |
manojkiraneda | 0b631ae | 2019-12-03 17:54:28 +0530 | [diff] [blame] | 391 | // validate the lock flags |
| 392 | // Allowed lockflags are locksame,lockall & dontlock |
| 393 | |
Ed Tanous | 18f8f60 | 2023-07-18 10:07:23 -0700 | [diff] [blame] | 394 | if (!((p.first == "LockSame" || (p.first == "LockAll") || |
| 395 | (p.first == "DontLock")))) |
manojkiraneda | 0b631ae | 2019-12-03 17:54:28 +0530 | [diff] [blame] | 396 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 397 | BMCWEB_LOG_DEBUG("Validation of lock flags failed"); |
| 398 | BMCWEB_LOG_DEBUG("{}", p.first); |
manojkiraneda | 0b631ae | 2019-12-03 17:54:28 +0530 | [diff] [blame] | 399 | return false; |
| 400 | } |
| 401 | |
| 402 | // validate the segment length |
| 403 | // Allowed values of segment length are between 1 and 4 |
| 404 | |
| 405 | if (p.second < 1 || p.second > 4) |
| 406 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 407 | BMCWEB_LOG_DEBUG("Validation of Segment Length Failed"); |
| 408 | BMCWEB_LOG_DEBUG("{}", p.second); |
manojkiraneda | 0b631ae | 2019-12-03 17:54:28 +0530 | [diff] [blame] | 409 | return false; |
| 410 | } |
| 411 | |
Ed Tanous | 18f8f60 | 2023-07-18 10:07:23 -0700 | [diff] [blame] | 412 | if ((p.first == "LockSame" || (p.first == "LockAll"))) |
manojkiraneda | 0b631ae | 2019-12-03 17:54:28 +0530 | [diff] [blame] | 413 | { |
| 414 | ++lockFlag; |
| 415 | if (lockFlag >= 2) |
| 416 | { |
| 417 | return false; |
| 418 | } |
| 419 | } |
| 420 | } |
| 421 | |
manojkiraneda | 0b631ae | 2019-12-03 17:54:28 +0530 | [diff] [blame] | 422 | return true; |
| 423 | } |
| 424 | |
Ed Tanous | b5a7693 | 2020-09-29 16:16:58 -0700 | [diff] [blame] | 425 | inline Rc Lock::isConflictWithTable(const LockRequests& refLockRequestStructure) |
manojkiraneda | 0b631ae | 2019-12-03 17:54:28 +0530 | [diff] [blame] | 426 | { |
manojkiraneda | 0b631ae | 2019-12-03 17:54:28 +0530 | [diff] [blame] | 427 | if (lockTable.empty()) |
| 428 | { |
Ed Tanous | f8fe53e | 2022-06-30 15:55:45 -0700 | [diff] [blame] | 429 | uint32_t thisTransactionId = generateTransactionId(); |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 430 | BMCWEB_LOG_DEBUG("{}", thisTransactionId); |
manojkiraneda | 0b631ae | 2019-12-03 17:54:28 +0530 | [diff] [blame] | 431 | // Lock table is empty, so we are safe to add the lockrecords |
| 432 | // as there will be no conflict |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 433 | BMCWEB_LOG_DEBUG("Lock table is empty, so adding the lockrecords"); |
Patrick Williams | ad53954 | 2023-05-12 10:10:08 -0500 | [diff] [blame] | 434 | lockTable.emplace(thisTransactionId, refLockRequestStructure); |
manojkiraneda | 0b631ae | 2019-12-03 17:54:28 +0530 | [diff] [blame] | 435 | |
Ed Tanous | 8a59281 | 2022-06-04 09:06:59 -0700 | [diff] [blame] | 436 | return std::make_pair(false, thisTransactionId); |
manojkiraneda | 0b631ae | 2019-12-03 17:54:28 +0530 | [diff] [blame] | 437 | } |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 438 | BMCWEB_LOG_DEBUG( |
| 439 | "Lock table is not empty, check for conflict with lock table"); |
Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 440 | // Lock table is not empty, compare the lockrequest entries with |
| 441 | // the entries in the lock table |
manojkiraneda | 0b631ae | 2019-12-03 17:54:28 +0530 | [diff] [blame] | 442 | |
Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 443 | for (const auto& lockRecord1 : refLockRequestStructure) |
manojkiraneda | 0b631ae | 2019-12-03 17:54:28 +0530 | [diff] [blame] | 444 | { |
Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 445 | for (const auto& map : lockTable) |
manojkiraneda | 0b631ae | 2019-12-03 17:54:28 +0530 | [diff] [blame] | 446 | { |
Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 447 | for (const auto& lockRecord2 : map.second) |
manojkiraneda | 0b631ae | 2019-12-03 17:54:28 +0530 | [diff] [blame] | 448 | { |
Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 449 | bool status = isConflictRecord(lockRecord1, lockRecord2); |
| 450 | if (status) |
manojkiraneda | 0b631ae | 2019-12-03 17:54:28 +0530 | [diff] [blame] | 451 | { |
Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 452 | return std::make_pair( |
| 453 | true, std::make_pair(map.first, lockRecord2)); |
manojkiraneda | 0b631ae | 2019-12-03 17:54:28 +0530 | [diff] [blame] | 454 | } |
| 455 | } |
| 456 | } |
manojkiraneda | 0b631ae | 2019-12-03 17:54:28 +0530 | [diff] [blame] | 457 | } |
Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 458 | |
| 459 | // Reached here, so no conflict with the locktable, so we are safe to |
| 460 | // add the request records into the lock table |
| 461 | |
| 462 | // Lock table is empty, so we are safe to add the lockrecords |
| 463 | // as there will be no conflict |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 464 | BMCWEB_LOG_DEBUG(" Adding elements into lock table"); |
Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 465 | transactionId = generateTransactionId(); |
| 466 | lockTable.emplace(std::make_pair(transactionId, refLockRequestStructure)); |
| 467 | |
manojkiraneda | 0b631ae | 2019-12-03 17:54:28 +0530 | [diff] [blame] | 468 | return std::make_pair(false, transactionId); |
| 469 | } |
| 470 | |
Ed Tanous | b5a7693 | 2020-09-29 16:16:58 -0700 | [diff] [blame] | 471 | inline bool Lock::isConflictRequest(const LockRequests& refLockRequestStructure) |
manojkiraneda | 0b631ae | 2019-12-03 17:54:28 +0530 | [diff] [blame] | 472 | { |
| 473 | // check for all the locks coming in as a part of single request |
| 474 | // return conflict if any two lock requests are conflicting |
| 475 | |
| 476 | if (refLockRequestStructure.size() == 1) |
| 477 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 478 | BMCWEB_LOG_DEBUG("Only single lock request, so there is no conflict"); |
manojkiraneda | 0b631ae | 2019-12-03 17:54:28 +0530 | [diff] [blame] | 479 | // This means , we have only one lock request in the current |
| 480 | // request , so no conflict within the request |
| 481 | return false; |
| 482 | } |
| 483 | |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 484 | BMCWEB_LOG_DEBUG( |
| 485 | "There are multiple lock requests coming in a single request"); |
Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 486 | |
| 487 | // There are multiple requests a part of one request |
| 488 | |
| 489 | for (uint32_t i = 0; i < refLockRequestStructure.size(); i++) |
manojkiraneda | 0b631ae | 2019-12-03 17:54:28 +0530 | [diff] [blame] | 490 | { |
Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 491 | for (uint32_t j = i + 1; j < refLockRequestStructure.size(); j++) |
manojkiraneda | 0b631ae | 2019-12-03 17:54:28 +0530 | [diff] [blame] | 492 | { |
Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 493 | const LockRequest& p = refLockRequestStructure[i]; |
| 494 | const LockRequest& q = refLockRequestStructure[j]; |
| 495 | bool status = isConflictRecord(p, q); |
manojkiraneda | 0b631ae | 2019-12-03 17:54:28 +0530 | [diff] [blame] | 496 | |
Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 497 | if (status) |
| 498 | { |
| 499 | return true; |
manojkiraneda | 0b631ae | 2019-12-03 17:54:28 +0530 | [diff] [blame] | 500 | } |
| 501 | } |
| 502 | } |
| 503 | return false; |
| 504 | } |
| 505 | |
| 506 | // This function converts the provided uint64_t resource id's from the two |
Gunnar Mills | caa3ce3 | 2020-07-08 14:46:53 -0500 | [diff] [blame] | 507 | // lock requests subjected for comparison, and this function also compares |
manojkiraneda | 0b631ae | 2019-12-03 17:54:28 +0530 | [diff] [blame] | 508 | // the content by bytes mentioned by a uint32_t number. |
| 509 | |
| 510 | // If all the elements in the lock requests which are subjected for comparison |
Gunnar Mills | caa3ce3 | 2020-07-08 14:46:53 -0500 | [diff] [blame] | 511 | // are same, then the last comparison would be to check for the respective |
manojkiraneda | 0b631ae | 2019-12-03 17:54:28 +0530 | [diff] [blame] | 512 | // bytes in the resourceid based on the segment length. |
Ravi Teja | 9eef578 | 2023-06-13 11:55:02 +0000 | [diff] [blame] | 513 | inline bool Lock::checkByte(uint64_t resourceId1, uint64_t resourceId2, |
| 514 | uint32_t position) |
manojkiraneda | 0b631ae | 2019-12-03 17:54:28 +0530 | [diff] [blame] | 515 | { |
Ravi Teja | 9eef578 | 2023-06-13 11:55:02 +0000 | [diff] [blame] | 516 | if (position >= sizeof(resourceId1)) |
| 517 | { |
| 518 | return false; |
| 519 | } |
Patrick Williams | 26b3630 | 2023-05-10 17:29:00 -0500 | [diff] [blame] | 520 | |
Ravi Teja | 9eef578 | 2023-06-13 11:55:02 +0000 | [diff] [blame] | 521 | uint8_t pPosition = 0; |
| 522 | uint8_t qPosition = 0; |
| 523 | pPosition = 0xFF & (resourceId1 >> (8 * position)); |
| 524 | qPosition = 0xFF & (resourceId2 >> (8 * position)); |
manojkiraneda | 0b631ae | 2019-12-03 17:54:28 +0530 | [diff] [blame] | 525 | |
Ed Tanous | dcf2ebc | 2022-01-25 10:07:45 -0800 | [diff] [blame] | 526 | return pPosition == qPosition; |
manojkiraneda | 0b631ae | 2019-12-03 17:54:28 +0530 | [diff] [blame] | 527 | } |
| 528 | |
Ed Tanous | b5a7693 | 2020-09-29 16:16:58 -0700 | [diff] [blame] | 529 | inline bool Lock::isConflictRecord(const LockRequest& refLockRecord1, |
| 530 | const LockRequest& refLockRecord2) |
manojkiraneda | 0b631ae | 2019-12-03 17:54:28 +0530 | [diff] [blame] | 531 | { |
| 532 | // No conflict if both are read locks |
| 533 | |
Ed Tanous | 18f8f60 | 2023-07-18 10:07:23 -0700 | [diff] [blame] | 534 | if (std::get<2>(refLockRecord1) == "Read" && |
| 535 | std::get<2>(refLockRecord2) == "Read") |
manojkiraneda | 0b631ae | 2019-12-03 17:54:28 +0530 | [diff] [blame] | 536 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 537 | BMCWEB_LOG_DEBUG("Both are read locks, no conflict"); |
manojkiraneda | 0b631ae | 2019-12-03 17:54:28 +0530 | [diff] [blame] | 538 | return false; |
| 539 | } |
| 540 | |
Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 541 | uint32_t i = 0; |
| 542 | for (const auto& p : std::get<4>(refLockRecord1)) |
manojkiraneda | 0b631ae | 2019-12-03 17:54:28 +0530 | [diff] [blame] | 543 | { |
Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 544 | // return conflict when any of them is try to lock all resources |
| 545 | // under the current resource level. |
Ed Tanous | 18f8f60 | 2023-07-18 10:07:23 -0700 | [diff] [blame] | 546 | if (p.first == "LockAll" || |
| 547 | std::get<4>(refLockRecord2)[i].first == "LockAll") |
manojkiraneda | 0b631ae | 2019-12-03 17:54:28 +0530 | [diff] [blame] | 548 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 549 | BMCWEB_LOG_DEBUG( |
| 550 | "Either of the Comparing locks are trying to lock all " |
| 551 | "resources under the current resource level"); |
Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 552 | return true; |
| 553 | } |
manojkiraneda | 0b631ae | 2019-12-03 17:54:28 +0530 | [diff] [blame] | 554 | |
Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 555 | // determine if there is a lock-all-with-same-segment-size. |
| 556 | // If the current segment sizes are the same,then we should fail. |
| 557 | |
Ed Tanous | 18f8f60 | 2023-07-18 10:07:23 -0700 | [diff] [blame] | 558 | if ((p.first == "LockSame" || |
| 559 | std::get<4>(refLockRecord2)[i].first == "LockSame") && |
Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 560 | (p.second == std::get<4>(refLockRecord2)[i].second)) |
| 561 | { |
| 562 | return true; |
| 563 | } |
| 564 | |
| 565 | // if segment lengths are not the same, it means two different locks |
| 566 | // So no conflict |
| 567 | if (p.second != std::get<4>(refLockRecord2)[i].second) |
| 568 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 569 | BMCWEB_LOG_DEBUG("Segment lengths are not same"); |
| 570 | BMCWEB_LOG_DEBUG("Segment 1 length : {}", p.second); |
| 571 | BMCWEB_LOG_DEBUG("Segment 2 length : {}", |
| 572 | std::get<4>(refLockRecord2)[i].second); |
Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 573 | return false; |
| 574 | } |
| 575 | |
| 576 | // compare segment data |
| 577 | |
Ed Tanous | 8a59281 | 2022-06-04 09:06:59 -0700 | [diff] [blame] | 578 | for (uint32_t j = 0; j < p.second; j++) |
Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 579 | { |
Ali Ahmed | d3d26ba | 2021-04-30 09:13:53 -0500 | [diff] [blame] | 580 | // if the segment data is different, then the locks is on a |
| 581 | // different resource so no conflict between the lock |
Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 582 | // records. |
Ali Ahmed | d3d26ba | 2021-04-30 09:13:53 -0500 | [diff] [blame] | 583 | // BMC is little endian, but the resourceID is formed by |
Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 584 | // the Management Console in such a way that, the first byte |
| 585 | // from the MSB Position corresponds to the First Segment |
Ali Ahmed | d3d26ba | 2021-04-30 09:13:53 -0500 | [diff] [blame] | 586 | // data. Therefore we need to convert the incoming |
Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 587 | // resourceID into Big Endian before processing further. |
| 588 | if (!(checkByte( |
| 589 | boost::endian::endian_reverse(std::get<3>(refLockRecord1)), |
| 590 | boost::endian::endian_reverse(std::get<3>(refLockRecord2)), |
Ed Tanous | 8a59281 | 2022-06-04 09:06:59 -0700 | [diff] [blame] | 591 | j))) |
manojkiraneda | 0b631ae | 2019-12-03 17:54:28 +0530 | [diff] [blame] | 592 | { |
manojkiraneda | 0b631ae | 2019-12-03 17:54:28 +0530 | [diff] [blame] | 593 | return false; |
| 594 | } |
manojkiraneda | 0b631ae | 2019-12-03 17:54:28 +0530 | [diff] [blame] | 595 | } |
Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 596 | |
| 597 | ++i; |
manojkiraneda | 0b631ae | 2019-12-03 17:54:28 +0530 | [diff] [blame] | 598 | } |
| 599 | |
Sunitha Harish | 41bb02b | 2022-08-08 03:12:15 -0500 | [diff] [blame] | 600 | return true; |
manojkiraneda | 0b631ae | 2019-12-03 17:54:28 +0530 | [diff] [blame] | 601 | } |
| 602 | |
Ratan Gupta | 07386c6 | 2019-12-14 14:06:09 +0530 | [diff] [blame] | 603 | inline uint32_t Lock::generateTransactionId() |
manojkiraneda | 0b631ae | 2019-12-03 17:54:28 +0530 | [diff] [blame] | 604 | { |
| 605 | ++transactionId; |
| 606 | return transactionId; |
| 607 | } |
| 608 | |
| 609 | } // namespace ibm_mc_lock |
| 610 | } // namespace crow |