safepower: Limit saved actions files to two in ping-pong fashion
This change restricts the persistent storage to use only two files:
`savedactions_0` and `savedactions_1`.
We introduce a `sequence_number` to the `SavedActions` proto. The file
with the higher sequence number is considered the active (latest) state.
When writing, we append to the active file. When it exceeds the size
limit, we compress the state and write it to the other (inactive) file
with an incremented sequence number, effectively rotating them.
We also implement migration: if neither `savedactions_0` nor
`savedactions_1` exists, but older files (with IDs > 1) exist, we find
the largest one, read it as the base state, and then delete all old
files.
If one of the files is corrupt, we fall back to the other one.
Bug: 455973485
PiperOrigin-RevId: 972087773
Change-Id: I4240b850eee1ae54f470fd239fb8bbe2a30bc449
6 files changed