summaryrefslogtreecommitdiffstats
path: root/serialize.cpp
diff options
context:
space:
mode:
authorMichael Tritz <mtritz@us.ibm.com>2017-08-13 14:55:04 -0500
committerPatrick Williams <patrick@stwcx.xyz>2017-08-18 17:28:05 +0000
commit4fb952ca9bcdbb53a9e4cb1d1b181b1ae97f9083 (patch)
treeb068f4a3909698310b7b74a6e8b627daa23dc77e /serialize.cpp
parent36417922b17a15595d4fae446c3bf53c16e28ced (diff)
downloadopenpower-pnor-code-mgmt-4fb952ca9bcdbb53a9e4cb1d1b181b1ae97f9083.tar.gz
openpower-pnor-code-mgmt-4fb952ca9bcdbb53a9e4cb1d1b181b1ae97f9083.zip
PNOR: Store a redundant copy of the priority persistence file
In this commit, the priority persistence functionality is extended by storing a second copy of each persistence file in the RW volume for its version. Upon a reboot, the corresponding restoration from file checks the second location if necessary. Resolves openbmc/openbmc#2133 Change-Id: Ie1926ad8500d49e7ec7cf71bd703664ac23c6a7a Signed-off-by: Michael Tritz <mtritz@us.ibm.com>
Diffstat (limited to 'serialize.cpp')
-rw-r--r--serialize.cpp46
1 files changed, 36 insertions, 10 deletions
diff --git a/serialize.cpp b/serialize.cpp
index a499798c4..8c63264f5 100644
--- a/serialize.cpp
+++ b/serialize.cpp
@@ -19,28 +19,54 @@ void storeToFile(std::string versionId, uint8_t priority)
{
fs::create_directory(PERSIST_DIR);
}
- std::string path = PERSIST_DIR + versionId;
- std::ofstream os(path.c_str());
- cereal::JSONOutputArchive oarchive(os);
- oarchive(cereal::make_nvp("priority", priority));
+ // store one copy in /var/lib/obmc/openpower-pnor-code-mgmt/[versionId]
+ auto varPath = PERSIST_DIR + versionId;
+ std::ofstream varOutput(varPath.c_str());
+ cereal::JSONOutputArchive varArchive(varOutput);
+ varArchive(cereal::make_nvp("priority", priority));
+
+ if(fs::is_directory(PNOR_RW_PREFIX + versionId))
+ {
+ // store another copy in /media/pnor-rw-[versionId]/[versionId]
+ auto rwPath = PNOR_RW_PREFIX + versionId + "/" + versionId;
+ std::ofstream rwOutput(rwPath.c_str());
+ cereal::JSONOutputArchive rwArchive(rwOutput);
+ rwArchive(cereal::make_nvp("priority", priority));
+ }
}
bool restoreFromFile(std::string versionId, uint8_t& priority)
{
- std::string path = PERSIST_DIR + versionId;
- if (fs::exists(path))
+ auto varPath = PERSIST_DIR + versionId;
+ if (fs::exists(varPath))
+ {
+ std::ifstream varInput(varPath.c_str(), std::ios::in);
+ try
+ {
+ cereal::JSONInputArchive varArchive(varInput);
+ varArchive(cereal::make_nvp("priority", priority));
+ return true;
+ }
+ catch(cereal::RapidJSONException& e)
+ {
+ fs::remove(varPath);
+ }
+ }
+
+ auto rwPath = PNOR_RW_PREFIX + versionId + "/" + versionId;
+ if (fs::exists(rwPath))
{
- std::ifstream is(path.c_str(), std::ios::in);
+ std::ifstream rwInput(rwPath.c_str(), std::ios::in);
try
{
- cereal::JSONInputArchive iarchive(is);
- iarchive(cereal::make_nvp("priority", priority));
+ cereal::JSONInputArchive rwArchive(rwInput);
+ rwArchive(cereal::make_nvp("priority", priority));
return true;
}
catch(cereal::RapidJSONException& e)
{
- fs::remove(path);
+ fs::remove(rwPath);
}
}
return false;
OpenPOWER on IntegriCloud