summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVishwanatha Subbanna <vishwa@linux.vnet.ibm.com>2017-09-28 16:33:53 +0530
committerVishwanatha Subbanna <vishwa@linux.vnet.ibm.com>2017-10-11 13:51:00 +0530
commit37af9bacea7847f8990a93fc600fad19b3194751 (patch)
tree674b625433094331830cffa371184ee88ce08989
parent9c7f03a7fd810288186fba4d86dc341c0c067716 (diff)
downloadphosphor-logging-37af9bacea7847f8990a93fc600fad19b3194751.tar.gz
phosphor-logging-37af9bacea7847f8990a93fc600fad19b3194751.zip
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 <vishwa@linux.vnet.ibm.com>
-rw-r--r--configure.ac4
-rw-r--r--elog_serialize.cpp34
-rw-r--r--log_manager.cpp5
3 files changed, 36 insertions, 7 deletions
diff --git a/configure.ac b/configure.ac
index 5cc1c2e..f912e14 100644
--- a/configure.ac
+++ b/configure.ac
@@ -93,6 +93,10 @@ AC_ARG_VAR(ERROR_CAP, [Max number of error entries allowed for commit])
AS_IF([test "x$ERROR_CAP" == "x"], [ERROR_CAP=100])
AC_DEFINE_UNQUOTED([ERROR_CAP], [$ERROR_CAP], [Max number of error entries allowed for commit])
+AC_ARG_VAR(CLASS_VERSION, [Class version to register with Cereal])
+AS_IF([test "x$CLASS_VERSION" == "x"], [CLASS_VERSION=1])
+AC_DEFINE_UNQUOTED([CLASS_VERSION], [$CLASS_VERSION], [Class version to register with Cereal])
+
AC_CONFIG_HEADERS([config.h])
AC_CONFIG_FILES([Makefile test/Makefile])
AC_CONFIG_FILES([phosphor-logging.pc])
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 <phosphor-logging/log.hpp>
+#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<class Archive>
-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<class Archive>
-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<level::ERR>(e.what());
+ fs::remove(path);
+ return false;
+ }
}
} // namespace logging
diff --git a/log_manager.cpp b/log_manager.cpp
index c1fe383..1efec9c 100644
--- a/log_manager.cpp
+++ b/log_manager.cpp
@@ -245,7 +245,10 @@ void Manager::restore()
}
}
- entryId = *(std::max_element(errorIds.begin(), errorIds.end()));
+ if (!errorIds.empty())
+ {
+ entryId = *(std::max_element(errorIds.begin(), errorIds.end()));
+ }
}
} // namespace internal
OpenPOWER on IntegriCloud