update_engine: Place enterprise rollback save marker file
- There are now two types of rollback. One that does a full powerwash
and one that save some system state.
- When an enterprise rollback powerwash is scheduled, place a marker
file to tell the shutdown process to save data before rebooting.
- This lets rollback preserve additional data over a powerwash that
can be restored later.
- Change a few places that were using is_rollback to save_rollback_data
to be explicit.
BUG=chromium:955463
TEST=unittests
Change-Id: I9f18319e711e425a6e712dd319e03bcc6ddd0a1b
Reviewed-on: https://chromium-review.googlesource.com/1414030
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Tested-by: Zentaro Kavanagh <zentaro@chromium.org>
Reviewed-by: Amin Hassani <ahassani@chromium.org>
diff --git a/hardware_chromeos.cc b/hardware_chromeos.cc
index 8ef05b2..60583e1 100644
--- a/hardware_chromeos.cc
+++ b/hardware_chromeos.cc
@@ -61,6 +61,11 @@
const char kPowerwashMarkerFile[] =
"/mnt/stateful_partition/factory_install_reset";
+// The name of the marker file used to trigger a save of rollback data
+// during the next shutdown.
+const char kRollbackSaveMarkerFile[] =
+ "/mnt/stateful_partition/.save_rollback_data";
+
// The contents of the powerwash marker file for the non-rollback case.
const char kPowerwashCommand[] = "safe fast keepimg reason=update_engine\n";
@@ -226,15 +231,25 @@
return powerwash_count;
}
-bool HardwareChromeOS::SchedulePowerwash(bool is_rollback) {
+bool HardwareChromeOS::SchedulePowerwash(bool save_rollback_data) {
+ if (save_rollback_data) {
+ if (!utils::WriteFile(kRollbackSaveMarkerFile, nullptr, 0)) {
+ PLOG(ERROR) << "Error in creating rollback save marker file: "
+ << kRollbackSaveMarkerFile << ". Rollback will not"
+ << " preserve any data.";
+ } else {
+ LOG(INFO) << "Rollback data save has been scheduled on next shutdown.";
+ }
+ }
+
const char* powerwash_command =
- is_rollback ? kRollbackPowerwashCommand : kPowerwashCommand;
+ save_rollback_data ? kRollbackPowerwashCommand : kPowerwashCommand;
bool result = utils::WriteFile(
kPowerwashMarkerFile, powerwash_command, strlen(powerwash_command));
if (result) {
LOG(INFO) << "Created " << kPowerwashMarkerFile
- << " to powerwash on next reboot (is_rollback=" << is_rollback
- << ")";
+ << " to powerwash on next reboot ("
+ << "save_rollback_data=" << save_rollback_data << ")";
} else {
PLOG(ERROR) << "Error in creating powerwash marker file: "
<< kPowerwashMarkerFile;
@@ -254,6 +269,11 @@
<< kPowerwashMarkerFile;
}
+ // Delete the rollback save marker file if it existed.
+ if (!base::DeleteFile(base::FilePath(kRollbackSaveMarkerFile), false)) {
+ PLOG(ERROR) << "Could not remove rollback save marker";
+ }
+
return result;
}