From 37af9bacea7847f8990a93fc600fad19b3194751 Mon Sep 17 00:00:00 2001 From: Vishwanatha Subbanna Date: Thu, 28 Sep 2017 16:33:53 +0530 Subject: Enable Cereal class versioning Cereal class versioning helps to handle data de-serialization across different class versions that differ in the way, a particular data is serialized. Change-Id: Ica01c4cb0c213e0dca8824fcfcfaa5cb43c5bc2e Signed-off-by: Vishwanatha Subbanna --- elog_serialize.cpp | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) (limited to 'elog_serialize.cpp') diff --git a/elog_serialize.cpp b/elog_serialize.cpp index f8c40e1..1af1946 100644 --- a/elog_serialize.cpp +++ b/elog_serialize.cpp @@ -6,6 +6,12 @@ #include "elog_serialize.hpp" #include +#include "config.h" + +// Register class version +// From cereal documentation; +// "This macro should be placed at global scope" +CEREAL_CLASS_VERSION(phosphor::logging::Entry, CLASS_VERSION); namespace phosphor { @@ -14,11 +20,13 @@ namespace logging /** @brief Function required by Cereal to perform serialization. * @tparam Archive - Cereal archive type (binary in our case). - * @param[in] a - reference to Cereal archive. - * @param[in] e - const reference to error entry. + * @param[in] a - reference to Cereal archive. + * @param[in] e - const reference to error entry. + * @param[in] version - Class version that enables handling + * a serialized data across code levels */ template -void save(Archive& a, const Entry& e) +void save(Archive& a, const Entry& e, const std::uint32_t version) { a(e.id(), e.severity(), e.timestamp(), e.message(), e.additionalData(), e.associations(), e.resolved()); @@ -26,11 +34,13 @@ void save(Archive& a, const Entry& e) /** @brief Function required by Cereal to perform deserialization. * @tparam Archive - Cereal archive type (binary in our case). - * @param[in] a - reference to Cereal archive. - * @param[in] e - reference to error entry. + * @param[in] a - reference to Cereal archive. + * @param[in] e - reference to error entry. + * @param[in] version - Class version that enables handling + * a serialized data across code levels */ template -void load(Archive& a, Entry& e) +void load(Archive& a, Entry& e, const std::uint32_t version) { using namespace sdbusplus::xyz::openbmc_project::Logging::server; @@ -84,6 +94,18 @@ bool deserialize(const fs::path& path, Entry& e) fs::remove(path); return false; } + catch(const std::length_error& e) + { + // Running into: USCiLab/cereal#192 + // This may be indicating some other issue in the + // way vector may have been used inside the logging. + // possibly associations ??. But handling it here for + // now since we are anyway tossing the log + // TODO: openbmc/phosphor-logging#8 + log(e.what()); + fs::remove(path); + return false; + } } } // namespace logging -- cgit v1.2.1