storage: Allow auto-checkpointing after provisioning
If a checkpoint was not created for a filesystem during provisioning, we
may still want to create a baseline checkpoint on a subsequent boot
after this change. This change adds FS_INIT_FLAGS_AUTO_CHECKPOINT to
indicate that the filesystem initialization should attempt to save the
current filesystem state to a checkpoint if one does not already exist.
This newly created checkpoint state will then be committed as part of
the next transaction to commit to that filesystem.
This change enables auto-checkpointing for the TDP filesystem if the
build system flag STORAGE_TDP_AUTO_CHECKPOINT_ENABLED is true.
Test: com.android.storage-unittest.tdp
Bug: 269180479
Change-Id: I84895579022aeef0e459fe25c4c25a107ac8f7b1
diff --git a/checkpoint.c b/checkpoint.c
index 9a86b44..29c36b1 100644
--- a/checkpoint.c
+++ b/checkpoint.c
@@ -148,3 +148,30 @@
err_block_get:
return !tr->failed;
}
+
+/**
+ * checkpoint_commit - Save the current file-system state as a checkpoint
+ * @fs: File-system to checkpoint.
+ *
+ * Create and commit a checkpoint of the current state of @fs.
+ *
+ * Returns %true if the checkpoint was created and committed successfully,
+ * %false otherwise.
+ */
+bool checkpoint_commit(struct fs* fs) {
+ struct transaction tr;
+ bool success;
+
+ assert(fs);
+ transaction_init(&tr, fs, true);
+ transaction_complete_etc(&tr, true);
+ success = !tr.failed;
+ if (success) {
+ pr_init("Automatically created a checkpoint for filesystem %s\n",
+ fs->name);
+ } else {
+ pr_err("Failed to commit checkpoint for filesystem %s\n", fs->name);
+ }
+ transaction_free(&tr);
+ return success;
+}