Add PostCodeDataVersion to the persisted data
Commit `06b1dbe9c768adf8921e4c1cb915538486b5a7ca` changed the
serialized format of `PostCodeData` without providing backward or
forward compatibility.
Previously, persisted data was stored as a `uint64_t`, whereas the
updated code now expects a `vector<uint8_t>`. When the new code
attempts to deserialize old data, Cereal interprets the `uint64_t`
value as the vector size, resulting in excessively large allocations
and out-of-memory errors during BMC initialization.
This commit introduces a `PostCodeDataVersion` field in the serialized
file. On startup, `post-code-manager` checks this version before
deserialization and discards outdated data if the version does not
match, ensuring a clean start without triggering memory issues.
Tested:
Verified that legacy persisted data is detected and discarded, allowing
`post-code-manager` to initialize with fresh data. No out-of-memory
conditions observed.
Change-Id: I698556a1b9781d7d869daf18348bdcf6ec82d6a7
Signed-off-by: Manojkiran Eda <manojkiran.eda@gmail.com>
diff --git a/src/post_code.cpp b/src/post_code.cpp
index 23f0a4f..31bd8d1 100644
--- a/src/post_code.cpp
+++ b/src/post_code.cpp
@@ -297,6 +297,11 @@
std::ofstream osPostCodes(path / std::to_string(currentBootCycleIndex));
cereal::BinaryOutputArchive oarchivePostCodes(osPostCodes);
oarchivePostCodes(postCodes);
+
+ std::ofstream osVersion(path / PostCodeDataVersionName,
+ std::ios::binary);
+ cereal::BinaryOutputArchive versionArchive(osVersion);
+ versionArchive(PostCodeDataVersion);
}
catch (const cereal::Exception& e)
{